/** * Render the field. * * @param array $args { * Optional. Arguments to adjust the rendering behavior. * * @type mixed $data The existing data to display with the field. If * absent, data will be loaded using * Fieldmanager_Context::_load(). * @type boolean $echo Output if true, return if false. Default is true. * } * @return string if $args['echo'] == false. */ protected function render_field($args = array()) { $data = array_key_exists('data', $args) ? $args['data'] : null; $echo = isset($args['echo']) ? $args['echo'] : true; $nonce = wp_nonce_field('fieldmanager-save-' . $this->fm->name, 'fieldmanager-' . $this->fm->name . '-nonce', true, false); $field = $this->fm->element_markup($data); if ($echo) { echo $nonce . $field; } else { return $nonce . $field; } }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = true; $this->post = $this->factory->post->create_and_get(array('post_status' => 'draft', 'post_content' => rand_str(), 'post_title' => rand_str())); $this->post_id = $this->post->ID; }
/** * Construct default attributes; 50x10 textarea * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { $this->attributes = array('cols' => '50', 'rows' => '10'); // Sanitize the textarea to preserve newlines. Could be overriden. $this->sanitize = 'fm_sanitize_textarea'; parent::__construct($label, $options); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = true; // insert a post $this->post = $this->factory->post->create_and_get(array('post_title' => rand_str(), 'post_date' => '2009-07-01 00:00:00')); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = true; $this->user_id = wp_create_user(rand_str(), rand_str(), '*****@*****.**'); $this->user = get_user_by('id', $this->user_id); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = TRUE; $this->post = array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str()); // insert a post $this->post_id = wp_insert_post($this->post); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = true; $this->post_id = $this->factory->post->create(array('post_title' => rand_str(), 'post_date' => '2009-07-01 00:00:00')); $this->post = get_post($this->post_id); $this->custom_datasource = new Fieldmanager_Datasource(array('options' => array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))); }
public function setUp() { parent::setUp(); add_filter('user_can_richedit', '__return_true'); Fieldmanager_Field::$debug = TRUE; $this->post = array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str()); // insert a post $this->post_id = wp_insert_post($this->post); $this->post = get_post($this->post_id); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = true; $this->post = array('post_status' => 'publish', 'post_content' => rand_str(), 'post_title' => rand_str()); // insert a post $this->post_id = wp_insert_post($this->post); // reload as proper object $this->post = get_post($this->post_id); }
/** * Construct default attributes and enqueue javascript * @param array $options */ public function __construct($label, $options = array()) { wp_enqueue_script('jquery-ui-datepicker'); fm_add_style('fm-jquery-ui', 'css/jquery-ui/jquery-ui-1.10.2.custom.min.css'); fm_add_script('fm_datepicker', 'js/fieldmanager-datepicker.js'); parent::__construct($label, $options); if (empty($this->js_opts)) { $this->js_opts = array('showButtonPanel' => True, 'showOtherMonths' => True, 'selectOtherMonths' => True, 'dateFormat' => 'd M yy'); } }
/** * Add CSS, construct parent * @param string $label * @param mixed $options */ public function __construct($label = '', $options = array()) { parent::__construct($label, $options); if (!empty($this->options)) { $this->add_options($this->options); } // Add the options CSS fm_add_style('fm_options_css', 'css/fieldmanager-options.css'); // Sanitization $this->sanitize = array($this, 'sanitize'); }
/** * Add scripts and styles and other setup tasks. * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { parent::__construct($label, $options); // Refuse to allow more than one instance of this field type. $this->limit = 1; wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script('jquery-ui-sortable'); fm_add_script('fm_draggablepost_js', 'js/fieldmanager-draggablepost.js'); fm_add_style('fm_draggablepost_css', 'css/fieldmanager-draggablepost.css'); }
/** * Build the colorpicker object and enqueue assets. * * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { if (!self::$has_registered_statics) { add_action('admin_enqueue_scripts', function () { wp_enqueue_style('wp-color-picker'); }); fm_add_script('fm_colorpicker', 'js/fieldmanager-colorpicker.js', array('jquery', 'wp-color-picker'), '1.0', true); self::$has_registered_statics = true; } $this->sanitize = array($this, 'sanitize_hex_color'); parent::__construct($label, $options); }
/** * Construct default attributes * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { $this->button_label = __('Attach a File', 'fieldmanager'); $this->modal_button_label = __('Select Attachment', 'fieldmanager'); $this->modal_title = __('Choose an Attachment', 'fieldmanager'); add_action('admin_print_scripts', array($this, 'admin_print_scripts')); if (!self::$has_registered_media) { fm_add_script('fm_media', 'js/media/fieldmanager-media.js', array('jquery'), '1.0.4'); self::$has_registered_media = true; } parent::__construct($label, $options); }
public function setUp() { parent::setUp(); Fieldmanager_Field::$debug = TRUE; $this->current_user = get_current_user_id(); wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); $this->taxonomy = 'category'; $term = wp_insert_term('test', $this->taxonomy); $this->term_id = $term['term_id']; $this->tt_id = $term['term_taxonomy_id']; // reload as proper object $this->term = get_term($this->term_id, $this->taxonomy); }
/** * Constructor which adds several scrips and CSS * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { $this->attributes = array('size' => '50'); parent::__construct($label, $options); $this->sanitize = function ($row, $col, $values) { foreach ($values as $k => $val) { $values[$k] = sanitize_text_field($val); } return $values; }; fm_add_script('handsontable', 'js/grid/jquery.handsontable.js'); fm_add_script('contextmenu', 'js/grid/lib/jQuery-contextMenu/jquery.contextMenu.js'); fm_add_script('ui_position', 'js/grid/lib/jQuery-contextMenu/jquery.ui.position.js'); fm_add_script('grid', 'js/grid.js'); fm_add_style('context_menu_css', 'js/grid/lib/jQuery-contextMenu/jquery.contextMenu.css'); fm_add_style('handsontable_css', 'js/grid/jquery.handsontable.css'); }
/** * Build the colorpicker object and enqueue assets. * * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { if (!self::$has_registered_statics) { add_action('admin_enqueue_scripts', function () { wp_enqueue_style('wp-color-picker'); }); fm_add_script('fm_colorpicker', 'js/fieldmanager-colorpicker.js', array('jquery', 'wp-color-picker'), '1.0', true); self::$has_registered_statics = true; } $this->sanitize = array($this, 'sanitize_hex_color'); parent::__construct($label, $options); // If we have a default_value and default_color was not explicitly set // to be empty, set default_color to default_value. if (!isset($this->default_color) && !empty($this->default_value)) { $this->default_color = $this->default_value; } }
/** * Add CSS, construct parent * @param string $label * @param mixed $options */ public function __construct($label = '', $options = array()) { parent::__construct($label, $options); if (!empty($this->options)) { $this->add_options($this->options); } // Add the options CSS fm_add_style('fm_options_css', 'css/fieldmanager-options.css'); // Sanitization $this->sanitize = function ($value) { if (isset($value) && is_array($value) && !empty($value)) { return array_map('sanitize_text_field', $value); } else { return sanitize_text_field($value); } }; }
/** * Add libraries for autocomplete * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { $this->attributes = array('size' => '50'); parent::__construct($label, $options); // Enqueue required scripts in the proper context add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts')); add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); fm_add_script('fm_autocomplete_js', 'js/fieldmanager-autocomplete.js', array('fieldmanager_script'), '1.0.5', false, 'fm_search', array('nonce' => wp_create_nonce('fm_search_nonce'))); if (empty($this->datasource)) { $message = esc_html__('You must supply a datasource for the autocomplete field', 'fieldmanager'); if (Fieldmanager_Field::$debug) { throw new FM_Developer_Exception($message); } else { wp_die($message, esc_html__('No Datasource', 'fieldmanager')); } } $this->datasource->allow_optgroups = False; }
/** * Saves custom term fields * @access public * @param int $term_id * @param int $tt_id * @param string $taxonomy * @return void */ public function save_term_fields($term_id, $tt_id, $taxonomy) { // Make sure this field is attached to the taxonomy being saved and this is the appropriate action if (!in_array($taxonomy, $this->taxonomies)) { return; } // Make sure that our nonce field arrived intact if (!$this->is_valid_nonce()) { return; } // Make sure the current user can save this post $tax_obj = get_taxonomy($taxonomy); if (!current_user_can($tax_obj->cap->manage_terms)) { $this->fm->_unauthorized_access(__('User cannot edit this term', 'fieldmanager')); return; } // Save the data $this->save_to_term_meta($term_id, $taxonomy); }
/** * Construct default attributes * @param string $label * @param array $options */ public function __construct($label, $options = array()) { $this->button_label = __('Attach a File', 'fieldmanager'); $this->modal_button_label = __('Select Attachment', 'fieldmanager'); $this->modal_title = __('Choose an Attachment', 'fieldmanager'); add_action('admin_print_scripts', function () { $post = get_post(); $args = array(); if (isset($post) && $post->ID) { $args['post'] = $post->ID; } wp_enqueue_media($args); // generally on post pages this will not have an impact. }); if (!self::$has_registered_media) { fm_add_script('fm_media', 'js/media/fieldmanager-media.js', array('jquery'), '1.0.1'); self::$has_registered_media = True; } parent::__construct($label, $options); }
/** * Groups have their own drag and remove tools in the label. * @param string $html * @return string */ public function wrap_with_multi_tools($html, $classes = array()) { if (empty($this->label) || !$this->one_label_per_item) { return parent::wrap_with_multi_tools($html, $classes); } return $html; }
/** * Construct default attributes * * @param string $label * @param array $options */ public function __construct($label, $options = array()) { $this->plugin_dir = FM_GALLERY_PATH; $this->plugin_url = FM_GALLERY_URL; if (!empty($options['collection'])) { $this->button_label = __('Attach Gallery', 'fieldmanager'); $this->modal_button_label = __('Select Attachments', 'fieldmanager'); $this->modal_title = __('Choose Attachments', 'fieldmanager'); } else { $this->button_label = __('Attach a File', 'fieldmanager'); $this->modal_button_label = __('Select Attachment', 'fieldmanager'); $this->modal_title = __('Choose an Attachment', 'fieldmanager'); } add_action('admin_print_scripts', function () { $post = get_post(); $args = array(); if (isset($post) && $post->ID) { $args['post'] = $post->ID; } wp_enqueue_media($args); // generally on post pages this will not have an impact. }); if (!self::$has_registered_gallery) { add_action('admin_enqueue_scripts', function () { wp_enqueue_style('fm_gallery', $this->plugin_url . 'css/fieldmanager-gallery.css', array()); wp_enqueue_script('fm_gallery', $this->plugin_url . 'js/fieldmanager-gallery.js', array('jquery')); wp_localize_script('fm_gallery', 'fm_gallery', array('uploaded_file' => __('Uploaded file', 'fieldmanager'), 'remove' => __('remove', 'fieldmanager'), 'create_gallery' => __('Create Gallery', 'fieldmanager'))); self::$has_registered_gallery = true; }); } parent::__construct($label, $options); }
/** * Save the data. * * @param Fieldmanager_Field $field * @param WP_Post $post * @param mixed $values */ public function save_values($field, $post, $values) { $field->add_meta_box($field->name, $post->post_type)->save_to_post_meta($post->ID, $values); }
/** * Set up the request environment values and save the data. * * @param Fieldmanager_Field $field * @param WP_Post $post * @param mixed $values */ public function save_values($field, $term, $values) { $field->add_term_form($field->name, $term->taxonomy)->save_to_term_meta($term->term_id, $term->taxonomy, $values); }
/** * Construct defaults for this field. * * @param string $label title of form field * @param array $options with keys matching vars of the field in use. */ public function __construct($label = '', $options = array()) { $this->sanitize = array($this, 'sanitize'); fm_add_script('fm_richtext', 'js/richtext.js', array('jquery', 'fieldmanager_script'), '1.0.8'); parent::__construct($label, $options); }
/** * Override constructor to set default size. * @param string $label * @param array $options */ public function __construct($label = '', $options = array()) { $this->attributes = array('size' => '50'); parent::__construct($label, $options); }
/** * Set up the request environment values and save the data. * * @param Fieldmanager_Field $field * @param WP_Post $post * @param mixed $values */ public function save_values($field, $post, $values) { $_POST = array('post_ID' => $post->ID, 'action' => 'editpost', 'post_type' => $post->post_type, "fieldmanager-{$field->name}-nonce" => wp_create_nonce("fieldmanager-save-{$field->name}"), $field->name => $values); $field->add_meta_box($field->name, $post->post_type)->save_to_post_meta($post->ID, $values); }
/** * Test that using an option not listed in the base or extended class will * throw an exception when debug mode is enabled. * * @expectedException FM_Developer_Exception */ public function test_invalid_option_debug() { Fieldmanager_Field::$debug = true; $base = new Fieldmanager_Group(array('name' => 'base_group', 'fake' => 'field', 'meta_box_actions_added' => 'foobar')); }
/** * Are we in the middle of generating a prototype element for repeatable fields? * @return boolean */ protected function has_proto() { if ($this->is_proto) { return True; } if ($this->parent) { return $this->parent->has_proto(); } return False; }