/**
  * Adds the meta boxes required to manage ad layers on posts.
  * @access public
  */
 public function add_meta_boxes()
 {
     // Get the post type name
     $post_type = str_replace('fm_post_', '', current_filter());
     // Add ad units
     $fm_ad_layer = new Fieldmanager_Autocomplete(array('name' => 'ad_layer', 'description' => __('Select a specific custom ad layer to use with this post.', 'ad-layers'), 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => array(Ad_Layers_Post_Type::instance()->get_post_type()), 'post_status' => 'publish', 'order_by' => 'title')))));
     $fm_ad_layer->add_meta_box(__('Ad Layer', 'ad-layers'), $post_type, 'side', 'core');
 }
 public function test_exact_match()
 {
     $args = array('name' => 'test_autocomplete', 'datasource' => $this->custom_datasource, 'default_value' => rand_str());
     $fm = new Fieldmanager_Autocomplete($args);
     ob_start();
     $fm->add_meta_box('Test Autocomplete', 'post')->render_meta_box($this->post, array());
     $html = ob_get_clean();
     $this->assertRegExp('/<input[^>]+type=[\'"]text[\'"][^>]+value=[\'"]{2}/', $html);
     $args['exact_match'] = false;
     $fm = new Fieldmanager_Autocomplete($args);
     ob_start();
     $fm->add_meta_box('Test Autocomplete', 'post')->render_meta_box($this->post, array());
     $html = ob_get_clean();
     $this->assertRegExp('/<input[^>]+type=[\'"]text[\'"][^>]+value=[\'"]' . $args['default_value'] . '[\'"]/', $html);
 }
 /**
  * Adds custom meta boxes for this post type.
  *
  * @access public
  * @return void
  */
 public function add_meta_boxes()
 {
     // Names.
     $name_types = array('first_name' => __('First Name', 'fm_bylines'), 'last_name' => __('Last Name', 'fm_bylines'));
     $fm_name_children = array();
     foreach ($name_types as $slug => $label) {
         $fm_name_children[$slug] = new Fieldmanager_Textfield($label, array());
     }
     $fm_name_children = apply_filters('fm_bylines_filter_name_fields', $fm_name_children);
     $fm_names = new Fieldmanager_Group(array('name' => 'fm_bylines_names', 'children' => $fm_name_children));
     $fm_names->add_meta_box(__('Additional Name Info', 'fm_bylines'), array($this->name));
     // Contact Info.
     $contact_types = array('email' => __('E-mail', 'fm_bylines'), 'website' => __('Website', 'fm_bylines'), 'twitter' => __('Twitter', 'fm_bylines'));
     $fm_contact_children = array();
     foreach ($contact_types as $slug => $label) {
         $fm_contact_children[$slug] = new Fieldmanager_Textfield($label, array());
     }
     $fm_contact_children = apply_filters('fm_bylines_filter_contact_info_fields', $fm_contact_children);
     $fm_contact_info = new Fieldmanager_Group(array('name' => 'fm_bylines_contact_info', 'children' => $fm_contact_children));
     $fm_contact_info->add_meta_box(__('Contact Info', 'fm_bylines'), array($this->name));
     // About.
     $fm_about_children = array();
     $fm_about_children['bio'] = new Fieldmanager_Textarea(__('Bio', 'fm_bylines'), array());
     $fm_about_children = apply_filters('fm_bylines_filter_about_fields', $fm_about_children);
     $fm_about = new Fieldmanager_Group(array('name' => 'fm_bylines_about', 'children' => $fm_about_children));
     $fm_about->add_meta_box(__('About', 'fm_bylines'), array($this->name));
     //  User Mapping.
     $fm_user_mapping = new Fieldmanager_Autocomplete(array('name' => 'fm_bylines_user_mapping', 'label' => __('WordPress User Login', 'fm_bylines'), 'description' => __('This mapping will populate byline meta boxes with this byline by default when this user is logged in.  Users without a mapping will default to byline metaboxes being empty.', 'fm_bylines'), 'datasource' => new Fieldmanager_Datasource_User(array('reciprocal' => 'fm_bylines_user_mapping', 'query_callback' => 'FM_Bylines::get_user_list')), 'attributes' => array('style' => 'width: 100%')));
     $fm_user_mapping->add_meta_box(__('WordPress User Mapping', 'fm_bylines'), array($this->name), 'side', 'default');
 }
 public function test_post_parent_render()
 {
     $fm = new Fieldmanager_Autocomplete(array('name' => 'test_parent', 'datasource' => new Fieldmanager_Datasource_Post(array('only_save_to_post_parent' => true, 'query_args' => array('post_type' => 'post')))));
     ob_start();
     $fm->add_meta_box('Test Autocomplete', 'post')->render_meta_box($this->child_post_a, array());
     $html = ob_get_clean();
     $this->assertRegExp('/<input[^>]+type=[\'"]hidden[\'"][^>]+value=[\'"]{2}/', $html);
     $this->save_values($fm, $this->child_post_a, $this->parent_post->ID);
     $child = get_post($this->child_post_a->ID);
     $this->assertEquals($this->parent_post->ID, $child->post_parent);
     $this->assertEquals('', get_post_meta($this->child_post_a->ID, 'test_parent', true));
     ob_start();
     $fm->add_meta_box('Test Autocomplete', 'post')->render_meta_box($this->child_post_a, array());
     $html = ob_get_clean();
     $this->assertRegExp("/<input[^>]+type=['\"]hidden['\"][^>]+value=['\"]{$this->parent_post->ID}['\"]/", $html);
 }
 /**
  * Test behavior when only saving to taxonomy within a single repeating
  * field set to not use serialized meta.
  *
  * @group serialize_data
  */
 public function test_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_autocomplete', 'serialize_data' => false, 'sortable' => true, 'limit' => 0, 'datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => $this->term->taxonomy, 'only_save_to_taxonomy' => true)));
     $base = new Fieldmanager_Autocomplete($args);
     $base->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, array($this->term->term_id, $this->term_2->term_id));
     $this->assertSame('', get_post_meta($this->post->ID, 'base_autocomplete', true));
     $this->assertSame(array($this->term->term_id, $this->term_2->term_id), wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'ids', 'orderby' => 'term_order', 'order' => 'ASC')));
     $base->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, array($this->term->term_id));
     $this->assertSame('', get_post_meta($this->post->ID, 'base_autocomplete', true));
     $this->assertSame(array($this->term->term_id), wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'ids')));
     $base->add_meta_box('test meta box', 'post')->save_to_post_meta($this->post->ID, array($this->term_2->term_id, $this->term->term_id));
     $this->assertSame('', get_post_meta($this->post->ID, 'base_autocomplete', true));
     $this->assertSame(array($this->term_2->term_id, $this->term->term_id), wp_get_post_terms($this->post->ID, $this->term->taxonomy, array('fields' => 'ids', 'orderby' => 'term_order', 'order' => 'ASC')));
 }
 /**
  * Test saving term relationships to users.
  */
 public function test_saving_taxonomies_to_users()
 {
     // Create a new taxonomy and add a term to it
     register_taxonomy('user-tax', 'user');
     $term = wp_insert_term('test-term', 'user-tax');
     // Create a user to which we'll save this data
     $user_id = wp_create_user(rand_str(), rand_str(), '*****@*****.**');
     $user = get_user_by('id', $user_id);
     // Create the field and save the data
     $field = new Fieldmanager_Autocomplete(array('name' => 'test_terms', 'datasource' => new Fieldmanager_Datasource_Term(array('taxonomy' => 'user-tax', 'only_save_to_taxonomy' => true))));
     $field->add_user_form('test')->save_to_user_meta($user_id, array('test_terms' => $term['term_id']));
     $this->assertSame('', get_user_meta($user_id, 'test_terms', true));
     $this->assertSame(array($term['term_id']), wp_get_object_terms($user_id, 'user-tax', array('fields' => 'ids')));
 }