/**
  * 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_Textfield(array('name' => 'text_field', 'label' => 'Text Field'));
     $fm->add_term_form('Standalone Text Field', 'demo-context-term');
     $fm = new Fieldmanager_Textfield(array('name' => 'repeating_text_field', 'label' => 'Text Field', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true));
     $fm->add_term_form('Standalone Repeating Text Field', 'demo-context-term');
     $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_term_form('Meta Fields', 'demo-context-term');
     $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_term_form('Meta Boxes', 'demo-context-term');
     $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_term_form('Meta Boxes of Meta Boxes', 'demo-context-term');
 }
 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 test_zero_in_repeating_field()
 {
     $save_data = array('1', '0', '', '2');
     $stored_data = array('1', '0', '2');
     $fm = new Fieldmanager_Textfield(array('name' => 'repeating_text_field', 'limit' => 0));
     $fm->add_meta_box('Repeating Text Field', 'post')->save_to_post_meta($this->post_id, $save_data);
     $this->assertSame($stored_data, get_post_meta($this->post_id, 'repeating_text_field', true));
 }
 public function test_removing_item_from_repeatable()
 {
     $field = new Fieldmanager_Textfield(array('name' => 'removing_items_testing', 'sortable' => true, 'extra_elements' => 0, 'limit' => 0));
     $context = $field->add_meta_box('removing_items_testing', $this->post);
     $to_remove = rand_str();
     $to_save = array($to_remove, rand_str(), rand_str());
     $context->save_to_post_meta($this->post_id, $to_save);
     $data = get_post_meta($this->post_id, 'removing_items_testing', true);
     $this->assertEquals(3, count($data));
     $to_save[0] = '';
     $context->save_to_post_meta($this->post_id, $to_save);
     $data = get_post_meta($this->post_id, 'removing_items_testing', true);
     $this->assertEquals(2, count($data));
     ob_start();
     $context->render_meta_box($this->post, array());
     $html = ob_get_clean();
     $this->assertNotContains("value=\"{$to_remove}\"", $html);
     $this->assertContains("value=\"{$to_save[1]}\"", $html);
     $this->assertContains("value=\"{$to_save[2]}\"", $html);
 }
Exemple #6
0
function alfath_post_metabox()
{
    $fm = new Fieldmanager_Textfield(__('Alias', 'alfath'), array('name' => 'alfath_author_alias'));
    $fm->add_meta_box(__('Penulis Alias', 'alfath'), array('post', 'page', 'agenda'));
}
 /**
  * Add the custom variables management page.
  *
  * @access public
  */
 public function add_custom_variables_settings()
 {
     $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->activate_submenu_page();
 }
 public function test_attachment_detection()
 {
     $fm_1 = new Fieldmanager_Textfield(array('name' => 'test_attachment_detection'));
     $context_1 = $fm_1->add_meta_box('Test Attachment Detection', 'post');
     $this->assertFalse($fm_1->is_attachment);
     // Ensure attachment sets $is_attachment
     $fm_2 = new Fieldmanager_Textfield(array('name' => 'test_attachment_detection'));
     $context_2 = $fm_2->add_meta_box('Test Attachment Detection', 'attachment');
     $this->assertEquals(10, has_filter('attachment_fields_to_save', array($context_2, 'save_fields_for_attachment')));
     remove_filter('attachment_fields_to_save', array($context_2, 'save_fields_for_attachment'));
     $this->assertTrue($fm_2->is_attachment);
     // Ensure attachment is read from an array
     $fm_3 = new Fieldmanager_Textfield(array('name' => 'test_attachment_detection'));
     $context_3 = $fm_3->add_meta_box('Test Attachment Detection', array('post', 'attachment'));
     $this->assertEquals(10, has_filter('attachment_fields_to_save', array($context_3, 'save_fields_for_attachment')));
     remove_filter('attachment_fields_to_save', array($context_3, 'save_fields_for_attachment'));
     $this->assertTrue($fm_3->is_attachment);
 }
 /**
  * Construct default attributes, set link sanitizer
  * @param string $label
  * @param array $options
  */
 public function __construct($label = '', $options = array())
 {
     $this->sanitize = 'esc_url_raw';
     $this->template = fieldmanager_get_template('textfield');
     parent::__construct($label, $options);
 }