/** * Test behavior when using the time support for datepicker * * @group 1111 */ public function test_time_feature() { $base = new Fieldmanager_Group(array('name' => 'test_datetime_group', 'children' => array('test_datetime_field' => new Fieldmanager_Datepicker(false, array('use_time' => true))))); // No time fields set $test_data = array('test_datetime_group' => array('test_datetime_field' => array('date' => '', 'hour' => '', 'minute' => '', 'ampm' => 'am'))); $base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data['test_datetime_group']); $saved_data = get_post_meta($this->post_id, 'test_datetime_group', true); $this->assertEmpty($saved_data['test_datetime_field']); // Date set, but no time $test_data = array('test_datetime_group' => array('test_datetime_field' => array('date' => '13 Mar 2014', 'hour' => '', 'minute' => '', 'ampm' => 'am'))); $base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data['test_datetime_group']); $saved_data = get_post_meta($this->post_id, 'test_datetime_group', true); $this->assertEquals(strtotime('13 Mar 2014'), $saved_data['test_datetime_field']); // Time set, but no date $test_data = array('test_datetime_group' => array('test_datetime_field' => array('date' => '', 'hour' => '2', 'minute' => '37', 'ampm' => 'am'))); $base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data['test_datetime_group']); $saved_data = get_post_meta($this->post_id, 'test_datetime_group', true); $this->assertEquals(strtotime('2:37 am'), $saved_data['test_datetime_field']); // Date and time set // Time set, but no date $test_data = array('test_datetime_group' => array('test_datetime_field' => array('date' => '13 Mar 2014', 'hour' => '2', 'minute' => '37', 'ampm' => 'am'))); $base->add_meta_box('test meta box', $this->post)->save_to_post_meta($this->post_id, $test_data['test_datetime_group']); $saved_data = get_post_meta($this->post_id, 'test_datetime_group', true); $this->assertEquals(strtotime('13 Mar 2014 2:37am'), $saved_data['test_datetime_field']); }
public function init() { $fm = new Fieldmanager_Grid(array('name' => 'grid')); $fm->add_meta_box('Basic Grid', 'demo-grid'); $fm = new Fieldmanager_Grid(array('name' => 'sidebar_grid')); $fm->add_meta_box('Basic Sidebar Grid', 'demo-grid', 'side'); $fm = new Fieldmanager_Grid(array('name' => 'grid_options', 'js_options' => array('startRows' => 20, 'startCols' => 20, 'colHeaders' => true, 'rowHeaders' => true, 'minSpareCols' => 1, 'minSpareRows' => 1, 'contextMenu' => true))); $fm->add_meta_box('Grid with Options', 'demo-grid'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_grid', 'limit' => 0, 'add_more_label' => 'Add another grid', 'sortable' => true, 'label' => 'Grid', 'children' => array('grid' => new Fieldmanager_Grid(array('js_options' => array('startRows' => 20, 'startCols' => 20, 'colHeaders' => true, 'rowHeaders' => true, 'minSpareCols' => 1, 'minSpareRows' => 1, 'contextMenu' => true)))))); $fm->add_meta_box('Repeatable Grids', 'demo-grid'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_sidebar_grid', 'limit' => 0, 'add_more_label' => 'Add another grid', 'sortable' => true, 'collapsible' => true, 'label' => 'Grid', 'children' => array('grid' => new Fieldmanager_Grid()))); $fm->add_meta_box('Repeatable Sidebar Grids', 'demo-grid'); // $fm = new Fieldmanager_Textfield( false, array( 'name' => 'sidebar_text' ) ); // $fm->add_meta_box( 'Sidebar Text Field', 'demo-grid', 'side' ); // $fm = new Fieldmanager_Group( array( // 'name' => 'sidebar_repeatable_text', // 'limit' => 0, // 'add_more_label' => 'Add another field', // 'sortable' => true, // 'label' => 'Field', // 'children' => array( // 'text_field' => new Fieldmanager_Textfield( 'Repeatable Field' ) // ) // ) ); // $fm->add_meta_box( 'Sidebar Repeatable Text Fields', 'demo-grid', 'side' ); }
/** * Handles adding meta boxes for a given post type * * @access protected * @return void */ public function add_meta_boxes() { if (class_exists('Fieldmanager_Field')) { $fm_property = new Fieldmanager_Group(array('name' => 'property-meta', 'children' => array('name' => new Fieldmanager_Textfield(array('description' => __('The name of the property.', 'ahny'), 'label' => __('Property Name', 'ahny'))), 'architect' => new Fieldmanager_Textfield(array('description' => __('The name of the architect.', 'ahny'), 'label' => __('Architect', 'ahny'))), 'address' => new Fieldmanager_Textarea(array('description' => __('The property address.', 'ahny'), 'label' => __('Property Address', 'ahny'))), 'price' => new Fieldmanager_Textfield(array('description' => __('The price of the property.', 'ahny'), 'label' => __('Property Price', 'ahny'))), 'status' => new Fieldmanager_Select(array('label' => __('Property Status', 'ahny'), 'first_empty' => false, 'options' => array(__('Active', 'ahny'), __('Inactive', 'ahny')))), 'listing-number' => new Fieldmanager_Textfield(array('description' => __('The property listing number.', 'ahny'), 'label' => __('Listing Number', 'ahny'))), 'listing-provided-by' => new Fieldmanager_Textfield(array('description' => __('Who provided the listing?.', 'ahny'), 'label' => __('Listing Provided By', 'ahny'))), 'type' => new Fieldmanager_Textfield(array('description' => __('The property type.', 'ahny'), 'label' => __('Property Type', 'ahny'))), 'bedrooms' => new Fieldmanager_Textfield(array('description' => __('The number of bedrooms.', 'ahny'), 'label' => __('Number of Bedrooms', 'ahny'))), 'bathrooms' => new Fieldmanager_Textfield(array('description' => __('The number of bathrooms.', 'ahny'), 'label' => __('Number of Bathrooms', 'ahny'))), 'square-footage' => new Fieldmanager_Textfield(array('description' => __('The square footage of the property.', 'ahny'), 'label' => __('Square Footage', 'ahny'))), 'lot-size' => new Fieldmanager_Textfield(array('description' => __('The property lot size.', 'ahny'), 'label' => __('Lot Size', 'ahny'))), 'year-built' => new Fieldmanager_Textfield(array('description' => __('The year the property was built.', 'ahny'), 'label' => __('Year Built', 'ahny'))), 'parking' => new Fieldmanager_Textfield(array('description' => __('The property parking amenities.', 'ahny'), 'label' => __('Parking', 'ahny'))), 'fireplaces' => new Fieldmanager_Textfield(array('description' => __('Fireplaces on the property.', 'ahny'), 'label' => __('Fireplaces', 'ahny'))), 'amenities' => new Fieldmanager_Textarea(array('description' => __('The property amenities.', 'ahny'), 'label' => __('Property Amenities', 'ahny'))), 'appliances' => new Fieldmanager_Textarea(array('description' => __('Available appliances.', 'ahny'), 'label' => __('Appliances', 'ahny'))), 'features' => new Fieldmanager_Textarea(array('description' => __('Property features.', 'ahny'), 'label' => __('Features', 'ahny'))), 'slideshow' => new Fieldmanager_Group(array('limit' => 0, 'add_more_label' => __('Add another image', 'ahny'), 'sortable' => true, 'label' => __('Gallery Images', 'ahny'), 'children' => array('image_id' => new Fieldmanager_Media(array('preview_size' => 'medium', 'label' => __('Select an image for the gallery', 'ahny'), 'button_label' => __('Select Image', 'ahny'), 'modal_button_label' => __('Use Image', 'ahny'), 'modal_title' => __('Select an image for the gallery', 'ahny'))))))))); $fm_property->add_meta_box(__('Property Data', 'ahny'), 'property', 'normal', 'default'); } }
public function init() { $fm = new Fieldmanager_Group(array('name' => 'meta_fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'text2' => new Fieldmanager_Select('Dropdown', array('options' => array('first', 'second', 'third', 'fourth')))))); $fm->add_quickedit_box('Custom Text Field', 'post', function ($post_id, $data) { return !empty($data['text']) ? $data['text'] : 'not set'; }, 'Custom Column Column'); }
public function init() { $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $fm = new Fieldmanager_Group(array('name' => 'autocomplete', 'children' => array('datasource_post' => new Fieldmanager_Autocomplete(array('label' => 'Datasource Post', 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'))))), 'datasource_post_edit' => new Fieldmanager_Autocomplete(array('label' => 'Datasource Post with Edit Link', 'show_edit_link' => true, 'description' => 'You must save the post to see this', 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'))))), 'datasource_custom' => new Fieldmanager_Autocomplete(array('label' => 'Custom Datasource, non-ajax', 'description' => 'Start typing a month of the year', 'datasource' => new Fieldmanager_Datasource(array('options' => $months))))))); $fm->add_meta_box('Autocomplete Fields', 'demo-autocomplete'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_autocomplete', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('datasource_post' => new Fieldmanager_Autocomplete(array('label' => 'Datasource Post', 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'))))), 'datasource_custom' => new Fieldmanager_Autocomplete(array('label' => 'Enter a month', 'datasource' => new Fieldmanager_Datasource(array('options' => $months))))))); $fm->add_meta_box('Repeatable Text Fields', 'demo-autocomplete'); }
public function add_meta_box() { $fm = new Fieldmanager_Group(array('name' => 'alfath_slide', 'limit' => 0, 'add_more_label' => __('Add another slide', 'alfath'), 'sortable' => true, 'collapsible' => true, 'label' => 'Slide image', 'children' => array('media' => new Fieldmanager_Media(false, array('thumbnail_class' => 'fm-thumbnail', 'label' => 'Select Image', 'button_label' => 'Select Image', 'modal_button_label' => 'Select Image', 'modal_title' => 'Select Image')), 'textarea' => new Fieldmanager_TextArea('Carousel Text', array('attributes' => array('style' => 'width:100%'))), 'url' => new Fieldmanager_Link(__('Slide Url', 'alfath'), array('description' => __('optional - leave blank for no link', 'alfath'))), 'url_openblank' => new Fieldmanager_Checkbox(false, array('description' => 'Open link in new window/tab'))))); $screens = array('bs_slide'); foreach ($screens as $screen) { $fm->add_meta_box('Add Slides', $screen, 'normal'); } }
public function add_meta_box() { $fm = new Fieldmanager_Group(array('name' => 'agenda_date', 'children' => array('lokasi' => new Fieldmanager_TextArea('Lokasi', array('attributes' => array('style' => 'width:100%'))), 'mulai' => new Fieldmanager_Datepicker(array('label' => 'Tanggal dan waktu Mulai', 'use_time' => true, 'use_am_pm' => false, 'js_opts' => array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'd M yy'))), 'selesai' => new Fieldmanager_Datepicker(array('label' => 'Tanggal dan waktu Selesai', 'use_time' => true, 'use_am_pm' => false, 'js_opts' => array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'd M yy')))))); $screens = array('agenda'); foreach ($screens as $screen) { $fm->add_meta_box('Detail Agenda', $screen, 'side'); } }
/** * Adds the meta boxes required to manage an overlay. */ public function add_meta_boxes() { // Main Content $fm = new Fieldmanager_Group(array('name' => 'fm_overlays_content', 'children' => array('content_type_select' => new Fieldmanager_Select(array('label' => __('Select content type', 'fm-overlays'), 'first_empty' => true, 'options' => array('richtext' => __('Rich Text Editor'), 'image' => __('Image', 'fm-overlays')))), 'richtext_content' => new Fieldmanager_RichTextArea(array('label' => __('Rich Text Content', 'fm-overlays'), 'display_if' => array('src' => 'content_type_select', 'value' => 'richtext'))), 'image_link' => new Fieldmanager_Link(array('label' => __('Image Link', 'fm-overlays'), 'display_if' => array('src' => 'content_type_select', 'value' => 'image'))), 'image_link_target' => new Fieldmanager_Checkbox(array('label' => __('Open in New Window', 'fm-overlays'), 'display_if' => array('src' => 'content_type_select', 'value' => 'image'))), 'image_id' => new Fieldmanager_Media(array('label' => __('Image Content', 'fm-overlays'), 'display_if' => array('src' => 'content_type_select', 'value' => 'image')))))); $fm->add_meta_box(__('Overlay content', 'fm-overlays'), $this->post_type, 'normal', 'high'); // Conditionals $fm = new Fieldmanager_Group(array('name' => 'fm_overlays_conditionals', 'collapsible' => true, 'sortable' => true, 'limit' => 0, 'label' => __('Condition', 'fm-overlays'), 'add_more_label' => __('Add another condition', 'fm-overlays'), 'extra_elements' => 0, 'children' => array('condition_select' => new Fieldmanager_Select(array('attributes' => array('conditional' => 'labels'), 'options' => array('is_home' => __('Is Home', 'fm-overlays'), 'is_front_page' => __('Is Front Page', 'fm-overlays'), 'is_category' => __('Is Category', 'fm-overlays'), 'has_category' => __('Has Category', 'fm-overlays'), 'is_single' => __('Is Single', 'fm-overlays'), 'is_page' => __('Is Page', 'fm-overlays'), 'is_tag' => __('Is Tag', 'fm-overlays'), 'has_tag' => __('Has Tag', 'fm-overlays')))), 'condition_argument_category' => new Fieldmanager_Autocomplete(array('display_if' => array('src' => 'condition_select', 'value' => 'is_category,has_category'), 'label' => __('Specific Category (Leave blank for any category)', 'fm-overlays'), 'datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => 'category')))), 'condition_argument_tag' => new Fieldmanager_Autocomplete(array('display_if' => array('src' => 'condition_select', 'value' => 'is_tag,has_tag'), 'label' => __('Specific tag (Leave blank for any tag)', 'fm-overlays'), 'datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => 'post_tag')))), 'condition_argument_single' => new Fieldmanager_Autocomplete(array('display_if' => array('src' => 'condition_select', 'value' => 'is_single'), 'label' => __('Specific post (Leave blank for any single post)', 'fm-overlays'), 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'))))), 'condition_argument_page' => new Fieldmanager_Autocomplete(array('display_if' => array('src' => 'condition_select', 'value' => 'is_page'), 'label' => __('Specific page (Leave blank for any WP page)', 'fm-overlays'), 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'page'))))), 'condition_negation' => new Fieldmanager_Checkbox(array('label_after_element' => false, 'label' => __('Not this condition', 'fm-overlays'), 'checked_value' => 'negated', 'default_value' => '0'))))); $fm->add_meta_box(__('Use these fields to determine on which pages this overlay will appear.', 'fm-overlays'), $this->post_type, 'normal', 'high'); }
/** * Add the ad layer priority management page. * * @access public */ public function add_settings_pages() { if (!class_exists('Fieldmanager_Field')) { return; } $fm_priority = new Fieldmanager_Group(array('name' => 'ad_layers', 'sortable' => true, 'collapsible' => true, 'collapsed' => true, 'limit' => 0, 'extra_elements' => 0, 'label' => __('Ad Layer', 'ad-layers'), 'label_macro' => array(__('%s', 'ad-layers'), 'title'), 'children' => array('post_id' => new Fieldmanager_Hidden(), 'title' => new Fieldmanager_Textfield(array('label' => __('Title', 'ad-layers'), 'attributes' => array('readonly' => 'readonly')))))); $fm_priority->add_submenu_page(Ad_Layers::instance()->get_edit_link(), __('Layer Priority', 'ad-layers')); $fm_custom = new Fieldmanager_Textfield(array('name' => 'ad_layers_custom_variables', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Add one or more custom variables for targeting.', 'ad-layers'), 'add_more_label' => __('Add a custom variable', 'ad-layers'))); $fm_custom->add_submenu_page(Ad_Layers::instance()->get_edit_link(), __('Custom Variables', 'ad-layers')); }
public function init() { $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $fm = new Fieldmanager_Group(array('name' => 'meta_fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_user_form('Meta Fields'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_meta_fields', 'limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_user_form('Meta Boxes'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_meta_boxes', 'limit' => 0, 'add_more_label' => 'Add another Meta Box', 'sortable' => true, 'label' => 'Meta Box', 'children' => array('repeatable_group' => new Fieldmanager_Group(array('limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->add_user_form('Meta Boxes of Met aBoxes'); }
/** * Activate stuff and options. * * Create tables, register options, import templates. * * @since 1.0.0 */ public static function create_types() { /* * map_list custom post type */ register_post_type('map_list', array('labels' => array('name' => __('Map List'), 'singular_name' => __('Map List'), 'edit_item' => __('Edit Map List'), 'add_new_item' => __('Add Map List'), 'new_item' => __('New Map List'), 'add_new' => __('Add new Map List')), 'public' => true, 'has_archive' => true, 'menu_icon' => 'dashicons-location-alt', 'rewrite' => array('slug' => 'map_list'), 'supports' => array('title'))); $fm = new Fieldmanager_Group(array('name' => 'contact_information', 'children' => array('name' => new Fieldmanager_Textfield('Name'), 'street' => new Fieldmanager_Textfield('Street'), 'city' => new Fieldmanager_Textfield('City'), 'county' => new Fieldmanager_Textfield('County'), 'stateprovince' => new Fieldmanager_Textfield('State Province'), 'postalcode' => new Fieldmanager_Textfield('Postal Code'), 'country' => new Fieldmanager_Textfield('Country'), 'phone' => new Fieldmanager_Textfield('Phone'), 'fax' => new Fieldmanager_Textfield('Fax'), 'email' => new Fieldmanager_Textfield('E-Mail'), 'url' => new Fieldmanager_Textfield('Url'), 'contact' => new Fieldmanager_Textfield('Contact Name'), 'areas' => new Fieldmanager_Textfield('Practice Areas')))); $fm->add_meta_box('Contact Information', array('map_list')); $fmc = new Fieldmanager_Group(array('name' => 'map_coordinates', 'children' => array('latitude' => new Fieldmanager_Textfield('Latitude'), 'longitude' => new Fieldmanager_Textfield('Longitude')))); $fmc->add_meta_box('Map Coordinates', array('map_list')); }
public function init() { $fm = new Fieldmanager_Media(false, array('name' => 'basic_media')); $fm->add_meta_box('Basic Media Field', 'demo-media'); $fm = new Fieldmanager_Media(false, array('name' => 'media_options', 'description' => 'This field has four customizations: the button text above, the modal title, modal button label, and the preview image size', 'preview_size' => 'medium', 'label' => 'Modified Media Popup', 'button_label' => 'Modified Button Label', 'modal_button_label' => 'Modified Modal Button', 'modal_title' => 'Modified Modal Title')); $fm->add_meta_box('Media field with options', 'demo-media'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_media', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('media_field' => new Fieldmanager_Media('Repeatable Field')))); $fm->add_meta_box('Repeatable Media Fields', 'demo-media'); $fm = new Fieldmanager_Media(false, array('name' => 'sidebar_media')); $fm->add_meta_box('Sidebar Media Field', 'demo-media', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_media', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('media_field' => new Fieldmanager_Media('Repeatable Field')))); $fm->add_meta_box('Sidebar Repeatable Media Fields', 'demo-media', 'side'); }
public function init() { $fm = new Fieldmanager_Radios(false, array('name' => 'basic_radios', 'options' => array('One', 'Two', 'Three'))); $fm->add_meta_box('Basic Radio Field', 'demo-radio'); $fm = new Fieldmanager_Radios(false, array('name' => 'radio_options', 'default_value' => '2', 'options' => array(1 => 'One', 2 => 'Two', 3 => 'Three'))); $fm->add_meta_box('Radio field with options', 'demo-radio'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_radios', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('radio_field' => new Fieldmanager_Radios('Repeatable Field', array('options' => array('One', 'Two', 'Three')))))); $fm->add_meta_box('Repeatable Radio Fields', 'demo-radio'); $fm = new Fieldmanager_Radios(false, array('name' => 'sidebar_radios', 'options' => array('One', 'Two', 'Three'))); $fm->add_meta_box('Sidebar Radio Field', 'demo-radio', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_radios', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('radio_field' => new Fieldmanager_Radios('Repeatable Field', array('options' => array('One', 'Two', 'Three')))))); $fm->add_meta_box('Sidebar Repeatable Radio Fields', 'demo-radio', 'side'); }
public function init() { $fm = new Fieldmanager_TextArea(false, array('name' => 'basic_textarea')); $fm->add_meta_box('Basic TextArea Field', 'demo-textarea'); $fm = new Fieldmanager_TextArea(false, array('name' => 'textarea_options', 'default_value' => 'Some default text', 'attributes' => array('style' => 'width:100%'))); $fm->add_meta_box('TextArea field with options', 'demo-textarea'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_textarea', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('textarea_field' => new Fieldmanager_TextArea('Repeatable Field')))); $fm->add_meta_box('Repeatable TextArea Fields', 'demo-textarea'); $fm = new Fieldmanager_TextArea(false, array('name' => 'sidebar_textarea')); $fm->add_meta_box('Sidebar TextArea Field', 'demo-textarea', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_textarea', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('textarea_field' => new Fieldmanager_TextArea('Repeatable Field')))); $fm->add_meta_box('Sidebar Repeatable TextArea Fields', 'demo-textarea', 'side'); }
public function init() { $fm = new Fieldmanager_Select('Basic Select', array('name' => 'basic_select', 'options' => array('One', 'Two', 'Three'))); $fm->add_meta_box('Basic Select Field', 'demo-select'); $fm = new Fieldmanager_Group(array('name' => 'select_assorted', 'children' => array('first_empty' => new Fieldmanager_Select(array('label' => 'First Empty', 'first_empty' => true, 'options' => array(1 => 'One', 2 => 'Two', 3 => 'Three'), 'attributes' => array('style' => 'width:150px'))), 'first_instruct' => new Fieldmanager_Select(array('label' => 'First Instruction', 'options' => array('' => 'Choose one', 1 => 'One', 2 => 'Two', 3 => 'Three'), 'attributes' => array('style' => 'width:150px'))), 'default_set' => new Fieldmanager_Select(array('label' => 'Default Set', 'default_value' => '2', 'options' => array(1 => 'One', 2 => 'Two', 3 => 'Three'), 'attributes' => array('style' => 'width:150px'))), 'multiple' => new Fieldmanager_Select(array('label' => 'Multiple Select', 'options' => array(1 => 'One', 2 => 'Two', 3 => 'Three'), 'attributes' => array('multiple' => 'mutliple', 'style' => 'width:150px')))))); $fm->add_meta_box('Select Fields with Assorted Options', 'demo-select'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_select', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('select_field' => new Fieldmanager_Select('Repeatable Field', array('options' => array('One', 'Two', 'Three')))))); $fm->add_meta_box('Repeatable Select Fields', 'demo-select'); $fm = new Fieldmanager_Select('Basic Select', array('name' => 'sidebar_select', 'options' => array('One', 'Two', 'Three'))); $fm->add_meta_box('Sidebar Select Field', 'demo-select', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_select', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('select_field' => new Fieldmanager_Select('Repeatable Field', array('options' => array('One', 'Two', 'Three')))))); $fm->add_meta_box('Sidebar Repeatable Select Fields', 'demo-select', 'side'); }
public function init() { $fm = new Fieldmanager_Textfield(array('name' => 'basic_text')); $fm->add_meta_box('Basic Text Field', 'demo-text'); $fm = new Fieldmanager_Textfield(array('name' => 'repeating_text_field', 'label' => 'Text Field', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true)); $fm->add_meta_box('Repeating Standalone Text Field', 'demo-text'); $fm = new Fieldmanager_Textfield(array('name' => 'text_options', 'default_value' => 'Some default text', 'attributes' => array('style' => 'width:100%'))); $fm->add_meta_box('Text field with options', 'demo-text'); $fm = new Fieldmanager_Textfield(array('name' => 'repeatable_text', 'limit' => 0, 'add_more_label' => 'Add another field', 'add_more_position' => 'top', 'sortable' => true, 'label' => 'Text Field')); $fm->add_meta_box('Repeatable text fields with new items at the top', 'demo-text'); $fm = new Fieldmanager_Textfield(array('name' => 'sidebar_text')); $fm->add_meta_box('Sidebar Text Field', 'demo-text', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_text', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('text_field' => new Fieldmanager_Textfield('Repeatable Field')))); $fm->add_meta_box('Sidebar Repeatable Text Fields', 'demo-text', 'side'); }
public function init() { $fm = new Fieldmanager_RichTextArea(false, array('name' => 'basic_richtextarea')); $fm->add_meta_box('Basic RichTextArea', 'demo-richtextarea'); $fm = new Fieldmanager_RichTextArea(false, array('name' => 'richtextarea_options', 'default_value' => '<h1>Some default text</h1>')); $fm->add_meta_box('RichTextArea with options', 'demo-richtextarea'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_richtextarea', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'collapsible' => true, 'label' => 'Field', 'children' => array('richtextarea_field' => new Fieldmanager_RichTextArea('Repeatable Field')))); $fm->add_meta_box('Repeatable RichTextAreas', 'demo-richtextarea'); $fm = new Fieldmanager_Group(array('name' => 'collapsed_repeatable_richtextarea', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'collapsible' => true, 'collapsed' => true, 'label' => 'Field', 'children' => array('richtextarea_field' => new Fieldmanager_RichTextArea('Repeatable Field')))); $fm->add_meta_box('Collapsed Repeatable RichTextAreas', 'demo-richtextarea'); $fm = new Fieldmanager_RichTextArea(false, array('name' => 'sidebar_richtextarea')); $fm->add_meta_box('Sidebar RichTextArea', 'demo-richtextarea', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_richtextarea', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'collapsible' => true, 'label' => 'Field', 'children' => array('richtextarea_field' => new Fieldmanager_RichTextArea('Repeatable Field')))); $fm->add_meta_box('Sidebar Repeatable RichTextAreas', 'demo-richtextarea', 'side'); }
public function init() { $datasource_post = new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'), 'use_ajax' => false)); $fm = new Fieldmanager_Group(array('name' => 'datasource_post', 'children' => array('autocomplete' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => $datasource_post)), 'ajax' => new Fieldmanager_Autocomplete(array('label' => 'Autocomplete with ajax', 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => 'post'))))), 'select' => new Fieldmanager_Select('Select', array('datasource' => $datasource_post)), 'radio' => new Fieldmanager_Radios('Radio', array('datasource' => $datasource_post)), 'checkboxes' => new Fieldmanager_Checkboxes('Checkboxes', array('datasource' => $datasource_post))))); $fm->add_meta_box('Post Datasource', 'demo-datasource'); $datasource_term = new Fieldmanager_Datasource_Term(array('taxonomy' => 'category', 'taxonomy_save_to_terms' => false, 'use_ajax' => false)); $fm = new Fieldmanager_Group(array('name' => 'datasource_term', 'children' => array('autocomplete' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => $datasource_term)), 'ajax' => new Fieldmanager_Autocomplete(array('label' => 'Autocomplete with ajax', 'datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => 'category', 'taxonomy_save_to_terms' => false)))), 'select' => new Fieldmanager_Select('Select', array('datasource' => $datasource_term)), 'radio' => new Fieldmanager_Radios('Radio', array('datasource' => $datasource_term)), 'checkboxes' => new Fieldmanager_Checkboxes('Checkboxes', array('datasource' => $datasource_term))))); $fm->add_meta_box('Term Datasource', 'demo-datasource'); $datasource_user = new Fieldmanager_Datasource_User(array('use_ajax' => false)); $fm = new Fieldmanager_Group(array('name' => 'datasource_user', 'children' => array('autocomplete' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => $datasource_user, 'description' => 'Search users by email address, URL, ID or username (this does not currently include display name)')), 'ajax' => new Fieldmanager_Autocomplete(array('label' => 'Autocomplete with ajax', 'datasource' => new Fieldmanager_Datasource_User())), 'select' => new Fieldmanager_Select('Select', array('datasource' => $datasource_user)), 'radio' => new Fieldmanager_Radios('Radio', array('datasource' => $datasource_user)), 'checkboxes' => new Fieldmanager_Checkboxes('Checkboxes', array('datasource' => $datasource_user))))); $fm->add_meta_box('User Datasource', 'demo-datasource'); $datasource_custom = new Fieldmanager_Datasource(array('options' => array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'))); $fm = new Fieldmanager_Group(array('name' => 'datasource_custom', 'children' => array('autocomplete' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => $datasource_custom)), 'ajax' => new Fieldmanager_Autocomplete(array('label' => 'Autocomplete with ajax', 'datasource' => new Fieldmanager_Datasource(array('options' => array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), 'use_ajax' => true)))), 'select' => new Fieldmanager_Select('Select', array('datasource' => $datasource_custom)), 'radio' => new Fieldmanager_Radios('Radio', array('datasource' => $datasource_custom)), 'checkboxes' => new Fieldmanager_Checkboxes('Checkboxes', array('datasource' => $datasource_custom))))); $fm->add_meta_box('Custom Datasource', 'demo-datasource'); }
/** * Takes $_POST data and saves it to, calling save_to_post_meta() once validation is passed * When using Fieldmanager as an API, do not call this function directly, call save_to_post_meta() * @param int $post_id * @return void */ public function save_fields_for_quickedit($post_id) { // Make sure this field is attached to the post type being saved. if (!isset($_POST['post_type']) || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || $_POST['action'] != 'inline-save') { return; } $use_this_post_type = false; foreach ($this->post_types as $type) { if ($type == $_POST['post_type']) { $use_this_post_type = true; break; } } if (!$use_this_post_type) { return; } // Ensure that the nonce is set and valid if (!$this->is_valid_nonce()) { return; } // Make sure the current user can save this post if ($_POST['post_type'] == 'post') { if (!current_user_can('edit_post', $post_id)) { $this->fm->_unauthorized_access(__('User cannot edit this post', 'fieldmanager')); return; } } $this->save_to_post_meta($post_id); }
public function init() { $months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $fm = new Fieldmanager_Group(array('name' => 'meta_fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_meta_box('Single-Level Group', 'demo-group'); $fm = new Fieldmanager_Group(array('name' => 'tabbed_meta_fields', 'tabbed' => true, 'children' => array('tab-1' => new Fieldmanager_Group(array('label' => 'Tab One', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months))))))), 'tab-2' => new Fieldmanager_Group(array('label' => 'Tab Two', 'children' => array('textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File')))), 'tab-3' => new Fieldmanager_Group(array('label' => 'Tab Three', 'children' => array('checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three')))))), 'tab-4' => new Fieldmanager_Group(array('label' => 'Tab Four', 'children' => array('richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->add_meta_box('Tabbed Group', 'demo-group'); $fm = new Fieldmanager_Group(array('name' => 'vertical_tabbed_meta_fields', 'tabbed' => 'vertical', 'children' => array('tab-1' => new Fieldmanager_Group(array('label' => 'Tab One', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months))))))), 'tab-2' => new Fieldmanager_Group(array('label' => 'Tab Two', 'children' => array('textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File')))), 'tab-3' => new Fieldmanager_Group(array('label' => 'Tab Three', 'children' => array('checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three')))))), 'tab-4' => new Fieldmanager_Group(array('label' => 'Tab Four', 'children' => array('richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->add_meta_box('Vertical Tabbed Group', 'demo-group'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_meta_fields', 'limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'collapsible' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_meta_box('Two-Level Group', 'demo-group'); $fm = new Fieldmanager_Group(array('name' => 'repeatable_meta_boxes', 'limit' => 0, 'add_more_label' => 'Add another Meta Box', 'sortable' => true, 'collapsible' => true, 'label' => 'Meta Box', 'children' => array('repeatable_group' => new Fieldmanager_Group(array('limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'collapsible' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->add_meta_box('Three-Level Group', 'demo-group'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_meta_fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_meta_box('Sidebar Single-Level Group', 'demo-group', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_meta_fields', 'limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'collapsible' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area')))); $fm->add_meta_box('Sidebar Two-Level Group', 'demo-group', 'side'); $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_meta_boxes', 'limit' => 0, 'add_more_label' => 'Add another Meta Box', 'sortable' => true, 'collapsible' => true, 'label' => 'Meta Box', 'children' => array('repeatable_group' => new Fieldmanager_Group(array('limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'collapsible' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->add_meta_box('Sidebar Three-Level Group', 'demo-group', 'side'); }
/** * 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); }
/** * Takes $_POST data and saves it to, calling save_to_post_meta() once validation is passed * When using Fieldmanager as an API, do not call this function directly, call save_to_post_meta() * @param int $post_id * @return void */ public function save_fields_for_post($post_id) { // Make sure this field is attached to the post type being saved. if (empty($_POST['post_ID']) || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || $_POST['action'] != 'editpost') { return; } // Make sure this hook fired on the post being saved, not a side-effect post for which the $_POST context is invalid. if ($post_id !== absint($_POST['post_ID'])) { return; } // Prevent saving the same post twice; FM does not yet use revisions. if (get_post_type($post_id) == 'revision') { return; } // Make sure this post type is intended for handling by this FM context. if (!in_array(get_post_type($post_id), $this->post_types)) { return; } // Do not handle quickedit in this context. if ($_POST['action'] == 'inline-save') { return; } // Verify nonce is present and valid. If present but not valid, this // throws an exception, but if it's absent we can assume our data is // not present. if (!$this->is_valid_nonce()) { return; } // Make sure the current user is authorized to save this post. if ($_POST['post_type'] == 'post') { if (!current_user_can('edit_post', $post_id)) { $this->fm->_unauthorized_access(__('User cannot edit this post', 'fieldmanager')); return; } } $this->save_to_post_meta($post_id); }
public function options_init() { $fm = new Fieldmanager_Group(array('name' => 'option_fields', 'limit' => 0, 'add_more_label' => 'Add another Meta Box', 'sortable' => true, 'collapsible' => true, 'label' => 'Meta Box', 'children' => array('repeatable_group' => new Fieldmanager_Group(array('limit' => 0, 'add_more_label' => 'Add another set of fields', 'sortable' => true, 'label' => 'Fields', 'children' => array('text' => new Fieldmanager_Textfield('Text Field'), 'autocomplete' => new Fieldmanager_Autocomplete('Autocomplete', array('datasource' => new Fieldmanager_Datasource_Post())), 'local_data' => new Fieldmanager_Autocomplete('Autocomplete without ajax', array('datasource' => new Fieldmanager_Datasource(array('options' => $this->months)))), 'textarea' => new Fieldmanager_TextArea('TextArea'), 'media' => new Fieldmanager_Media('Media File'), 'checkbox' => new Fieldmanager_Checkbox('Checkbox'), 'radios' => new Fieldmanager_Radios('Radio Buttons', array('options' => array('One', 'Two', 'Three'))), 'select' => new Fieldmanager_Select('Select Dropdown', array('options' => array('One', 'Two', 'Three'))), 'richtextarea' => new Fieldmanager_RichTextArea('Rich Text Area'))))))); $fm->activate_submenu_page(); }
/** * Add in a FM_Byline meta box w/ all it's bells and whistles * @param string $type * @param string. Optional label * @param array $args */ function add_byline_meta_box($type = 'author', $label = null, $args = array()) { if (is_admin()) { $context = fm_get_context(); $fm_context = $context[0]; $fm_context_type = $context[1]; $label = empty($label) ? fm_bylines_wordify_slug($type) : $label; $defaults = array('name' => 'fm_bylines_' . sanitize_title_with_dashes($type), 'limit' => 0, 'add_more_label' => __('Add another', 'fm_bylines'), 'sortable' => true, 'label' => __('Name', 'fm_bylines'), 'children' => array('byline_id' => new Fieldmanager_Autocomplete(array('default_value' => null, 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => $this->name, 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'post_status' => 'publish', 'suppress_filters' => false))))), 'fm_byline_type' => new Fieldmanager_Hidden(array('default_value' => sanitize_title_with_dashes($type))))); $fm_byline_box = new Fieldmanager_Group(wp_parse_args($args, $defaults)); if ('post' == $fm_context) { $fm_byline_box->add_meta_box($label, $fm_context_type, apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_post_metabox_context', 'normal'), apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_post_metabox_priority', 'default')); } elseif ('term' == $fm_context) { $fm_byline_box->add_term_form($label, $fm_context_type); } elseif ('submenu' == $fm_context) { fm_register_submenu_page('fm_bylines_' . sanitize_title_with_dashes($type), apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_metabox_submenu', 'tools.php'), $label); $fm_byline_box->activate_submenu_page(); } elseif ('user' == $fm_context) { $fm_byline_box->add_user_form($label); } elseif ('quickedit' == $fm_context) { $fm_byline_box->add_quickedit_box($label, $fm_context_type, function ($post_id, $data) { return !empty($data['fm_bylines_' . sanitize_title_with_dashes($type)]) ? $data['fm_bylines_' . sanitize_title_with_dashes($type)] : 'not set'; }); } } }
/** * @expectedException FM_Exception * @expectedExceptionMessage submitted 5 values against a limit of 3 */ public function test_limit_exceeded_exceptions() { $test_data_too_many = array('test_element' => array(array('text' => 'a'), array('text' => 'b'), array('text' => 'c'), array('text' => 'd'), array('text' => 'e'))); $field = new Fieldmanager_Group(array('name' => 'base_group', 'children' => array('test_element' => new Fieldmanager_Group(array('limit' => 3, 'children' => array('text' => new Fieldmanager_TextField(false))))))); $context = $field->add_meta_box('test meta box', $this->post); $context->save_to_post_meta($this->post_id, $test_data_too_many); }
/** * Adds the meta boxes required to manage an ad layer. * * @param string|array $post_types * @param string $context * @param string $priority */ public function add_meta_boxes() { if (!class_exists('Fieldmanager_Field')) { return; } // Add ad units $ad_unit_args = array('name' => 'ad_layer_ad_units', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'sortable' => true, 'label' => __('Select one or more ad units.', 'ad-layers'), 'add_more_label' => __('Add an ad unit', 'ad-layers'), 'children' => array('ad_unit' => new Fieldmanager_Select(array('label' => __('Ad Unit', 'ad-layers'), 'options' => Ad_Layers_Ad_Server::instance()->get_ad_units())), 'do_not_render' => new Fieldmanager_Checkbox(__('Do not render the ad on load', 'ad-layers')))); $targeting_args = Ad_Layers_Ad_Server::instance()->get_custom_targeting_args('custom_targeting'); if (!empty($targeting_args)) { $ad_unit_args['children']['custom_targeting'] = new Fieldmanager_Group(apply_filters('ad_layers_custom_targeting_ad_unit_args', $targeting_args)); } $fm_ad_units = new Fieldmanager_Group(apply_filters('ad_layers_ad_units_field_args', $ad_unit_args)); $fm_ad_units->add_meta_box(__('Ad Units', 'ad-layers'), $this->post_type, 'normal', 'high'); // Add page types $fm_page_types = new Fieldmanager_Select(apply_filters('ad_layers_page_types_field_args', array('name' => 'ad_layer_page_types', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more page types to be targeted with this ad layer.', 'ad-layers'), 'add_more_label' => __('Add a page type', 'ad-layers'), 'options' => Ad_Layers::instance()->get_page_types()))); $fm_page_types->add_meta_box(__('Page Types', 'ad-layers'), $this->post_type, 'normal', 'high'); // Add taxonomies $fm_taxonomies = new Fieldmanager_Select(apply_filters('ad_layers_taxonomies_field_args', array('name' => 'ad_layer_taxonomies', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more optional taxonomies for targeting. Posts with any term in these taxonomies will get the ad layer.', 'ad-layers'), 'add_more_label' => __('Add a taxonomy', 'ad-layers'), 'options' => Ad_Layers::instance()->get_taxonomies()))); $fm_taxonomies->add_meta_box(__('Taxonomies', 'ad-layers'), $this->post_type, 'normal', 'high'); // Add post types $fm_post_types = new Fieldmanager_Select(apply_filters('ad_layers_post_types_field_args', array('name' => 'ad_layer_post_types', 'limit' => 0, 'extra_elements' => 0, 'one_label_per_item' => false, 'label' => __('Select one or more optional post types for targeting. Any post of this type will get the ad layer.', 'ad-layers'), 'add_more_label' => __('Add a post type', 'ad-layers'), 'options' => Ad_Layers::instance()->get_post_types()))); $fm_post_types->add_meta_box(__('Post Types', 'ad-layers'), $this->post_type, 'normal', 'high'); // Custom targeting variables $targeting_args = Ad_Layers_Ad_Server::instance()->get_custom_targeting_args(); if (!empty($targeting_args)) { $fm_custom = new Fieldmanager_Group(apply_filters('ad_layers_custom_targeting_field_args', $targeting_args)); $fm_custom->add_meta_box(__('Page Level Custom Targeting', 'ad-layers'), $this->post_type, 'normal', 'low'); } }
/** * Test behavior when only saving to taxonomy within a group set to not use * serialized meta. * * @group serialize_data */ public function test_group_datasource_term_save_only_tax_with_unseriaized_data() { $this->assertCount(0, wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'names'))); $args = array('name' => 'base_group', 'serialize_data' => false, 'children' => array('test_basic' => new Fieldmanager_TextField(), 'test_datasource' => new Fieldmanager_Autocomplete(array('datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => $this->term->taxonomy, 'only_save_to_taxonomy' => true)))))); $data = array('test_basic' => rand_str(), 'test_datasource' => $this->term->term_id); $base = new Fieldmanager_Group($args); $base->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, $data); $this->assertSame($data['test_basic'], get_post_meta($this->post->ID, 'base_group_test_basic', true)); $this->assertSame(array(), get_post_meta($this->post->ID, 'base_group_test_datasource', true)); $this->assertSame(array($this->term->term_id), wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'ids'))); wp_set_object_terms($this->post->ID, null, 'post_tag'); $base = new Fieldmanager_Group(array_merge($args, array('add_to_prefix' => false))); $base->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, $data); $this->assertSame($data['test_basic'], get_post_meta($this->post->ID, 'test_basic', true)); $this->assertSame(array(), get_post_meta($this->post->ID, 'test_datasource', true)); $this->assertSame(array($this->term->term_id), wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'ids'))); }
public function init() { $fm = new Fieldmanager_Group(array('name' => 'repeatable_text', 'description' => '<hr />Psst... There is also a hidden field in this meta box with a set value.', 'children' => array('password_field' => new Fieldmanager_Password('Password Field'), 'hidden_field' => new Fieldmanager_Hidden('Hidden Field', array('default_value' => 'Fieldmanager was here')), 'link_field' => new Fieldmanager_Link('Link Field', array('description' => 'This is a text field that sanitizes the value as a URL')), 'date_field' => new Fieldmanager_Datepicker('Datepicker Field'), 'date_customized_field' => new Fieldmanager_Datepicker(array('label' => 'Datepicker Field with Options', 'date_format' => 'Y-m-d', 'use_time' => true, 'js_opts' => array('dateFormat' => 'yy-mm-dd', 'changeMonth' => true, 'changeYear' => true, 'minDate' => '2010-01-01', 'maxDate' => '2015-12-31')))))); $fm->add_meta_box('Miscellaneous Fields', 'demo-misc'); }
public function test_textfield_zero_input_in_repeating_group() { $save_data = array(array('a' => '1'), array('a' => '0'), array('a' => ''), array('a' => '2')); $stored_data = array(array('a' => '1'), array('a' => '0'), array('a' => '2')); $group = new Fieldmanager_Group(array('name' => 'group', 'limit' => 0, 'children' => array('a' => new Fieldmanager_Textfield()))); $group->add_meta_box('group', $this->post->ID)->save_to_post_meta($this->post->ID, $save_data); $this->assertEquals($stored_data, get_post_meta($this->post->ID, 'group', true)); }
function hsinsider_fm_school_info() { $fm = new Fieldmanager_Group(array('name' => 'school_info', 'children' => array('address' => new Fieldmanager_Textfield('Address', array('name' => 'address', 'attributes' => array('placeholder' => '202 W 1st St. Los Angeles, CA 90012'))), 'logo' => new Fieldmanager_Media('Logo')))); $fm->add_term_form('School Info', 'school'); }