WordPress.org

Make WordPress Core

Ticket #14746: 14746.5.diff

File 14746.5.diff, 2.0 KB (added by ryan, 8 years ago)

Reduce to the essentials

  • wp-includes/taxonomy.php

     
    7070                'show_ui' => false,
    7171                '_builtin' => true,
    7272        ) ) ;
     73
     74        register_taxonomy( 'post_mode', array('post', 'page', 'attachment'), array(
     75                'hierarchical' => false,
     76                'labels' => array(
     77                        'name' => '',
     78                        'singular_name' => '',
     79                ),
     80                'query_var' => false,
     81                'rewrite' => false,
     82                'show_ui' => false,
     83                '_builtin' => true,
     84                'show_in_nav_menus' => false,
     85        ) ) ;
    7386}
    7487add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    7588
  • wp-includes/post.php

     
    471471}
    472472
    473473/**
     474 * Retrieve the mode for a post
     475 *
     476 * @param int|object $post A post
     477 *
     478 * @return mixed The mode if successful. False if no mode is set.  WP_Error if errors.
     479 */
     480function get_post_mode( $post ) {
     481        $post = get_post($post);
     482
     483        $mode = wp_get_object_terms( $post->ID, 'post_mode', array('order' => 'none', 'fields' => 'names') );
     484
     485        if ( is_wp_error($mode) )
     486                return $mode;
     487
     488        if ( empty($mode) )
     489                return false;
     490
     491        return ( str_replace('mode-', '', $mode[0]) );
     492}
     493
     494/**
     495 * Assign a mode to a post
     496 *
     497 * @param int|object $post The post for which to assign a mode
     498 * @param string $mode  A mode to assign.  The mode must have already been registered with register_post_mode().
     499 * @return mixed WP_Error on error. Array of affected term IDs on success.
     500 */
     501function set_post_mode( $post, $mode ) {
     502        global $wp_post_modes;
     503
     504        $post = get_post($post);
     505
     506        if ( empty($post) )
     507                return new WP_Error('invalid_post', __('Invalid post'));
     508
     509        return wp_set_post_terms($post_id, array('mode-' . $mode), 'post_mode');
     510}
     511
     512/**
    474513 * Retrieve the post status based on the Post ID.
    475514 *
    476515 * If the post ID is of an attachment, then the parent post status will be given