protected function register_post_types()
 {
     global $wp_rewrite;
     $wp_rewrite->init();
     $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     $this->args['hello'] = array('site_sortables' => array('test_site_sortables_post_meta' => array('meta_key' => 'test_meta_key'), 'test_site_sortables_post_field' => array('post_field' => 'name'), 'test_site_sortables_taxonomy' => array('taxonomy' => 'hello_category')), 'admin_cols' => array('test_admin_cols_post_meta' => array('meta_key' => 'test_meta_key'), 'test_admin_cols_post_field' => array('post_field' => 'name'), 'test_admin_cols_taxonomy' => array('taxonomy' => 'hello_category')), 'site_filters' => array('test_site_filters_post_meta_key' => array('meta_key' => 'test_meta_key'), 'test_site_filters_post_meta_search' => array('meta_search_key' => 'test_meta_key'), 'test_site_filters_post_meta_exists' => array('meta_exists' => array('test_meta_key')), 'test_site_filters_with_cap' => array('meta_key' => 'test_meta_key', 'cap' => 'have_kittens'), 'test_site_filters_post_meta_query' => array('meta_key' => 'test_meta_key', 'meta_query' => array('compare' => '>=', 'value' => 'B', 'type' => 'CHAR')), 'test_site_filters_post_meta_query_deprecated' => array('meta_key' => 'test_meta_key', 'meta_compare' => '>=', 'meta_value' => 'B', 'meta_type' => 'CHAR'), 'test_site_filters_invalid' => array('meta_query' => array('key' => 'foo', 'value' => 'bar'))), 'archive' => array('orderby' => 'post_title'), 'query_var' => 'hi');
     $this->cpts['hello'] = register_extended_post_type('hello', $this->args['hello']);
     $this->cpts['hello']->add_taxonomy('hello_category');
     $this->cpts['person'] = register_extended_post_type('person', array('has_archive' => 'team', 'show_in_feed' => true, 'site_sortables' => array('test_site_sortables_post_name' => array('post_field' => 'post_name', 'default' => 'asc')), 'admin_cols' => array('test_admin_cols_post_name' => array('post_field' => 'post_name', 'default' => 'asc'), 'test_admin_cols_unsortable' => array('meta_key' => 'test_meta_key', 'sortable' => false), 'test_admin_cols_test_meta_key' => array('meta_key' => 'test_meta_key'), 'test_admin_cols_person_category' => array('taxonomy' => 'person_category'))), array('plural' => 'People'));
     $this->cpts['person']->add_taxonomy('person_category');
     $this->cpts['nice-thing'] = register_extended_post_type('nice-thing', array(), array('slug' => 'Things'));
     $this->cpts['foo'] = register_extended_post_type('foo', array('rewrite' => array('permastruct' => 'foo/%author%/%foo_category%/%foo%'), 'show_in_feed' => true), array('singular' => 'Bar'));
     $this->cpts['foo']->add_taxonomy('foo_category');
     $this->cpts['bar'] = register_extended_post_type('bar', array('public' => false, 'featured_image' => 'Icon'), array('plural' => 'Plural', 'singular' => 'Singular', 'slug' => 'Slug'));
     $this->cpts['baz'] = register_extended_post_type('baz', array('rewrite' => array('permastruct' => 'baz/%postname%'), 'has_archive' => false));
     $this->cpts['post'] = register_extended_post_type('post', array('labels' => array('remove_featured_image' => 'Remove!')));
     $wp_rewrite->flush_rules();
     foreach (array('Alpha', 'Beta', 'Gamma', 'Delta') as $slug) {
         wp_insert_term($slug, 'hello_category');
         wp_insert_term($slug, 'foo_category');
     }
     // Post
     $this->posts['post'][] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'post', 'post_date' => '1984-02-25 00:05:00'));
     // Hello 0
     $this->posts['hello'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'hello', 'post_name' => 'Alpha', 'post_date' => '1984-02-25 00:04:00'));
     add_post_meta($this->posts['hello'][0], 'test_meta_key', 'Delta');
     wp_add_object_terms($this->posts['hello'][0], 'Beta', 'hello_category');
     // Hello 1
     $this->posts['hello'][1] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'hello', 'post_name' => 'Delta', 'post_date' => '1984-02-25 00:03:00'));
     add_post_meta($this->posts['hello'][1], 'test_meta_key', 'Alpha');
     // Hello 2
     $this->posts['hello'][2] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'hello', 'post_name' => 'Beta', 'post_date' => '1984-02-25 00:02:00'));
     add_post_meta($this->posts['hello'][2], 'test_meta_key', 'Beta');
     wp_add_object_terms($this->posts['hello'][2], 'Alpha', 'hello_category');
     // Hello 3
     $this->posts['hello'][3] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'hello', 'post_name' => 'Gamma', 'post_date' => '1984-02-25 00:01:00'));
     wp_add_object_terms($this->posts['hello'][3], 'Gamma', 'hello_category');
     $this->posts['person'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'person', 'post_name' => 'Beta', 'post_date' => '1984-02-25 00:01:00'));
     $this->posts['person'][1] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'person', 'post_name' => 'Alpha', 'post_date' => '1984-02-25 00:02:00'));
     $this->posts['nice-thing'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'nice-thing'));
     $this->posts['foo'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'foo', 'post_author' => 1));
     wp_add_object_terms($this->posts['foo'][0], array('Gamma', 'Delta'), 'foo_category');
     $this->posts['bar'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'bar'));
     $this->posts['baz'][0] = $this->factory->post->create(array('guid' => 'guid', 'post_type' => 'baz'));
 }
 function setUp()
 {
     global $wp_rewrite;
     parent::setUp();
     $wp_rewrite->init();
     $wp_rewrite->set_permalink_structure('/%year%/%monthnum%/%day%/%postname%/');
     $this->args['hello'] = array('site_sortables' => array('test_site_sortables_post_meta' => array('meta_key' => 'test_meta_key'), 'test_site_sortables_post_field' => array('post_field' => 'name'), 'test_site_sortables_taxonomy' => array('taxonomy' => 'hello_category')), 'site_filters' => array('test_site_filters_post_meta_key' => array('meta_key' => 'test_meta_key'), 'test_site_filters_post_meta_search' => array('meta_search_key' => 'test_meta_key'), 'test_site_filters_post_meta_exists' => array('meta_exists' => array('test_meta_key'))));
     $this->cpts['hello'] = register_extended_post_type('hello', $this->args['hello']);
     $this->cpts['hello']->add_taxonomy('hello_category');
     $this->cpts['person'] = register_extended_post_type('person', array('has_archive' => 'team'), array('plural' => 'People'));
     $this->cpts['nice-thing'] = register_extended_post_type('nice-thing', array(), array('slug' => 'Things'));
     $this->cpts['foo'] = register_extended_post_type('foo', array('rewrite' => array('permastruct' => 'foo/%author%/%foo_category%/%foo%')), array('singular' => 'Bar'));
     $this->cpts['foo']->add_taxonomy('foo_category');
     $wp_rewrite->flush_rules();
     foreach (array('Alpha', 'Beta', 'Gamma', 'Delta') as $slug) {
         wp_insert_term($slug, 'hello_category');
         wp_insert_term($slug, 'foo_category');
     }
     // Post
     $this->posts['post'][] = $this->factory->post->create(array('post_type' => 'post', 'post_date' => '1984-02-25 00:05:00'));
     // Hello 0
     $this->posts['hello'][0] = $this->factory->post->create(array('post_type' => 'hello', 'post_name' => 'Alpha', 'post_date' => '1984-02-25 00:04:00'));
     add_post_meta($this->posts['hello'][0], 'test_meta_key', 'Delta');
     wp_add_object_terms($this->posts['hello'][0], 'Beta', 'hello_category');
     // Hello 1
     $this->posts['hello'][1] = $this->factory->post->create(array('post_type' => 'hello', 'post_name' => 'Delta', 'post_date' => '1984-02-25 00:03:00'));
     add_post_meta($this->posts['hello'][1], 'test_meta_key', 'Alpha');
     // Hello 2
     $this->posts['hello'][2] = $this->factory->post->create(array('post_type' => 'hello', 'post_name' => 'Beta', 'post_date' => '1984-02-25 00:02:00'));
     add_post_meta($this->posts['hello'][2], 'test_meta_key', 'Beta');
     wp_add_object_terms($this->posts['hello'][2], 'Alpha', 'hello_category');
     // Hello 3
     $this->posts['hello'][3] = $this->factory->post->create(array('post_type' => 'hello', 'post_name' => 'Gamma', 'post_date' => '1984-02-25 00:01:00'));
     wp_add_object_terms($this->posts['hello'][3], 'Gamma', 'hello_category');
     $this->posts['person'][0] = $this->factory->post->create(array('post_type' => 'person'));
     $this->posts['nice-thing'][0] = $this->factory->post->create(array('post_type' => 'nice-thing'));
     $this->posts['foo'][0] = $this->factory->post->create(array('post_type' => 'foo', 'post_author' => 1));
     wp_add_object_terms($this->posts['foo'][0], array('Gamma', 'Delta'), 'foo_category');
 }
예제 #3
0
 /**
  * @ticket 15475
  */
 function test_wp_add_remove_object_terms()
 {
     $posts = self::$post_ids;
     $tags = self::factory()->tag->create_many(5);
     $tt = wp_add_object_terms($posts[0], $tags[1], 'post_tag');
     $this->assertEquals(1, count($tt));
     $this->assertEquals(array($tags[1]), wp_get_object_terms($posts[0], 'post_tag', array('fields' => 'ids')));
     $three_tags = array($tags[0], $tags[1], $tags[2]);
     $tt = wp_add_object_terms($posts[1], $three_tags, 'post_tag');
     $this->assertEquals(3, count($tt));
     $this->assertEquals($three_tags, wp_get_object_terms($posts[1], 'post_tag', array('fields' => 'ids')));
     $this->assertTrue(wp_remove_object_terms($posts[0], $tags[1], 'post_tag'));
     $this->assertFalse(wp_remove_object_terms($posts[0], $tags[0], 'post_tag'));
     $this->assertInstanceOf('WP_Error', wp_remove_object_terms($posts[0], $tags[1], 'non_existing_taxonomy'));
     $this->assertTrue(wp_remove_object_terms($posts[1], $three_tags, 'post_tag'));
     $this->assertEquals(0, count(wp_get_object_terms($posts[1], 'post_tag')));
     foreach ($tags as $term_id) {
         $this->assertTrue(wp_delete_term($term_id, 'post_tag'));
     }
     foreach ($posts as $post_id) {
         $this->assertTrue((bool) wp_delete_post($post_id));
     }
 }
 /**
  * Add an update to an existing post.
  *
  * @param int|WP_Post $parent   Either the ID or object for the post which you are updating.
  * @param string      $content  Post content.
  * @param string      @livetags Live update tags for this update.
  *
  * @return int|WP_Error
  *
  * @uses wp_insert_post() Uses the WordPress API to create a new child post.
  */
 public function add_update($parent, $content, $livetags, $update_meta)
 {
     global $current_user, $post;
     get_currentuserinfo();
     if (!is_object($parent)) {
         $parent = get_post($parent);
     }
     $save_post = $post;
     $post = $parent;
     if (empty($content)) {
         $response = false;
     } else {
         $plugin_options = get_option(livepress_administration::$options_name);
         if ($plugin_options['feed_order'] == 'top') {
             $append = 'prepend';
         } else {
             $append = 'append';
         }
         $piece_id = mt_rand(10000000, 26242537);
         $piece_gen = 0;
         $update = wp_insert_post(array('post_author' => $current_user->ID, 'post_content' => $content, 'post_parent' => $post->ID, 'post_title' => 'livepress_update__' . $piece_id . '__' . $piece_gen, 'post_name' => 'livepress_update__' . $piece_id, 'post_type' => 'post', 'post_status' => 'inherit'), true);
         if (is_wp_error($update)) {
             $response = false;
         } else {
             set_post_format($update, 'aside');
             // Associate any livetags with this update
             if (!empty($livetags)) {
                 wp_add_object_terms($update, $livetags, 'livetags');
             }
             $response = $this::send_to_livepress_incremental_post_update($append, $post, $update, $update_meta);
         }
     }
     $post = $save_post;
     return $response;
 }
예제 #5
0
 /**
  * Associate the passed Object ID with this taxonomy term.
  *
  * @param int $object_id Likely a Post ID but can be other things
  *
  * @return int[]|WP_Error
  */
 function assign($object_id)
 {
     return $this->has_term() ? wp_add_object_terms($object_id, $this->term()->term_id, $this->taxonomy()) : false;
 }
/**
 * Generic function for saving Post Meta for Actions.
 *
 * @since 1.0.0
 *
 * @param This function accepts no parameters.
 *
 * @return This function does not return any data.
 */
function bbconnect_save_action_meta($args = null)
{
    // SET THE DEFAULTS TO BE OVERRIDDEN AS DESIRED
    $defaults = array('override' => false, 'verified' => false, 'post_data' => $_POST);
    // PARSE THE INCOMING ARGS
    $args = wp_parse_args($args, $defaults);
    // EXTRACT THE VARIABLES
    extract($args, EXTR_SKIP);
    // SET THE LOCAL VARIABLE
    if (isset($post_data['post_ID'])) {
        $id = $post_data['post_ID'];
    }
    if (!isset($id)) {
        return false;
    }
    if (isset($post_data['post_type'])) {
        $post_type = $post_data['post_type'];
    }
    // MAKE SURE THIS CAME FROM A VALID PAGE
    // YOU MUST OVERRIDE THIS MANUALLY AND ONLY IF A NONCE HAS BEEN PREVIOUSLY VERIFIED
    if (false != $override) {
    } else {
        if (!isset($post_type) || !isset($post_data['bbconnect-' . $post_type . '-nonce']) || !wp_verify_nonce($post_data['bbconnect-' . $post_type . '-nonce'], 'bbconnect-' . $post_type . '-meta')) {
            return false;
        }
    }
    // MAKE SURE THE USER HAS THE CORRECT PRIVILEGE
    // YOU MUST OVERRIDE THIS MANUALLY AND ONLY IF A USER HAS BEEN PREVIOUSLY VERIFIED
    if (false != $verified) {
    } else {
        // MAKE SURE THEY HAVE ACCESS TO EDIT
        if ('page' == $post_type) {
            if (!current_user_can('edit_page', $id)) {
                return $id;
            }
        } else {
            if (!current_user_can('edit_post', $id)) {
                return $id;
            }
        }
    }
    // ALLOW PLUGINS TO MODIFY THE POST DATA
    if (isset($post_data['_bbc_post'])) {
        $bbconnect_data = apply_filters('bbconnect_modify_action_meta', $post_data['_bbc_post'], $id, $post_type, $post_data);
        // First grab the tax items out of the array
        if (isset($bbconnect_data['bb_note_type_parent'])) {
            $note_type = $bbconnect_data['bb_note_type_parent'];
            $term = get_term_by('slug', $note_type, 'bb_note_type');
            wp_add_object_terms($id, $term->term_id, 'bb_note_type');
            unset($bbconnect_data['bb_note_type_parent']);
        }
        if (isset($bbconnect_data['bb_note_type'])) {
            $note_type = $bbconnect_data['bb_note_type'];
            $term = get_term_by('slug', $note_type, 'bb_note_type');
            wp_add_object_terms($id, $term->term_id, 'bb_note_type');
            unset($bbconnect_data['bb_note_type']);
        }
        // LOOP THROUGH THE POSTDATA AND SAVE THE VALUES
        foreach ($bbconnect_data as $key => $value) {
            if (get_post_meta($id, $key) == '') {
                add_post_meta($id, $key, $value, true);
            } elseif ($value != get_post_meta($id, $key, true)) {
                update_post_meta($id, $key, $value);
            } elseif ($value == '') {
                delete_post_meta($id, $key, get_post_meta($id, $key, true));
            }
        }
    }
    do_action('bbconnect_process_action_meta', $id, $post_type);
}
예제 #7
0
     $association_fullname = $ns->get_association_fullname($post_type, $association);
     $taxonomy = $ns->get_association_taxonomy($association_fullname);
     $ns->register_taxonomy($taxonomy, $post_type);
     if (empty($associated_models)) {
         $terms = null;
     } else {
         $terms = array();
     }
     if (!is_array($associated_models)) {
         $associated_models = array($associated_models);
     }
     foreach ($associated_models as $associated_model) {
         $term = $ns->get_term_slug($associated_model, $taxonomy);
         $terms[] = $term;
     }
     wp_add_object_terms($model_id, $terms, $taxonomy);
 };
 $ns->add_associated_models = function ($model_id, $association, $associated_models) use($ns) {
     $model = $ns->get($model_id, array());
     if (!$model) {
         return;
     }
     $post_type = $model['post_type'];
     $association_fullname = $ns->get_association_fullname($post_type, $association);
     $association_def = $ns->get_association_definition($association_fullname);
     $reverse_fullname = $association_def['reverse'];
     $reverse = $ns->get_association_definition($reverse_fullname);
     $reverse_association = $reverse['association'];
     if (!is_array($associated_models)) {
         $associated_models = array($associated_models);
     }
예제 #8
0
function set_object_terms($object_id, $terms, $tt_ids, $taxonomy)
{
    if ($taxonomy == 'business-type') {
        $value = array();
        if (has_term('Farm Gate Sales', 'business-type', $object_id)) {
            $value[] = 'On Farm';
        }
        if (has_term('Farmers\' Market Vendor', 'business-type', $object_id)) {
            $value[] = 'Farmers\' Market';
        }
        if ($value) {
            wp_add_object_terms($object_id, $value, 'available-at');
        }
    }
}