コード例 #1
0
 public function init()
 {
     $fm = new Fieldmanager_Checkbox('Basic Checkbox', array('name' => 'basic_checkbox'));
     $fm->add_meta_box('Basic Checkbox Field', 'demo-checkbox');
     $fm = new Fieldmanager_Checkbox('Checked Checkbox', array('name' => 'checkbox_options', 'default_value' => 'checked'));
     $fm->add_meta_box('Checkbox field with options', 'demo-checkbox');
     $fm = new Fieldmanager_Checkboxes('Checkboxes', array('name' => 'checkbox_group', 'options' => array('One', 'Two', 'Three')));
     $fm->add_meta_box('Group of Checkboxes', 'demo-checkbox');
     /*
     $fm = new Fieldmanager_Group( array(
     	'name'           => 'repeatable_checkbox',
     	'limit'          => 0,
     	'add_more_label' => 'Add another field',
     	'sortable'       => true,
     	'label'          => 'Field',
     	'children'       => array(
     		'checkbox_field' => new Fieldmanager_Checkbox( 'Repeatable Field' )
     	)
     ) );
     $fm->add_meta_box( 'Repeatable Checkbox Fields', 'demo-checkbox' );
     */
     $fm = new Fieldmanager_Checkbox('Basic Checkbox', array('name' => 'sidebar_checkbox'));
     $fm->add_meta_box('Sidebar Checkbox Field', 'demo-checkbox', 'side');
     /*
     $fm = new Fieldmanager_Group( array(
     	'name'           => 'sidebar_repeatable_checkbox',
     	'limit'          => 0,
     	'add_more_label' => 'Add another field',
     	'sortable'       => true,
     	'label'          => 'Field',
     	'children'       => array(
     		'checkbox_field' => new Fieldmanager_Checkbox( 'Repeatable Field' )
     	)
     ) );
     $fm->add_meta_box( 'Sidebar Repeatable Checkbox Fields', 'demo-checkbox', 'side' );
     */
 }
 public function test_repeatable_checkboxes_save()
 {
     $fm = new Fieldmanager_Checkboxes(array('name' => 'base_field', 'multiple' => true, 'limit' => 0, 'options' => array('one', 'two', 'three')));
     $fm->add_meta_box('base_field', $this->post->post_type)->save_to_post_meta($this->post->ID, array('two'));
     $saved_value = get_post_meta($this->post->ID, 'base_field', true);
     $this->assertSame(array('two'), $saved_value);
     $fm->add_meta_box('base_field', $this->post->post_type)->save_to_post_meta($this->post->ID, array('two', 'three'));
     $saved_value = get_post_meta($this->post->ID, 'base_field', true);
     $this->assertSame(array('two', 'three'), $saved_value);
     $fm->add_meta_box('base_field', $this->post->post_type)->save_to_post_meta($this->post->ID, '');
     $saved_value = get_post_meta($this->post->ID, 'base_field', true);
     $this->assertEquals(null, $saved_value);
 }