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)); }
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')); }
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); }
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); }