WordPress.org

Make WordPress Core

Changeset 12719


Ignore:
Timestamp:
01/13/10 18:49:56 (4 years ago)
Author:
ryan
Message:

register_post_type(). see #9674

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin

    • Property svn:ignore deleted
  • trunk/wp-admin/edit.php

    r12706 r12719  
    138138} 
    139139 
    140 list($post_stati, $avail_post_stati) = wp_edit_posts_query(); 
     140$avail_post_stati = wp_edit_posts_query(); 
    141141 
    142142require_once('admin-header.php'); 
     
    221221$status_links[] = "<li><a href='edit.php{$allposts}'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_posts, 'posts' ), number_format_i18n( $total_posts ) ) . '</a>'; 
    222222 
    223 foreach ( $post_stati as $status => $label ) { 
     223foreach ( get_post_stati(array(), 'objects') as $status ) { 
    224224    $class = ''; 
    225225 
    226     if ( !in_array( $status, $avail_post_stati ) ) 
     226    $status_name = $status->name; 
     227 
     228    if ( !in_array( $status_name, $avail_post_stati ) ) 
    227229        continue; 
    228230 
    229     if ( empty( $num_posts->$status ) ) 
     231    if ( empty( $num_posts->$status_name ) ) 
    230232        continue; 
    231233 
    232     if ( isset($_GET['post_status']) && $status == $_GET['post_status'] ) 
     234    if ( isset($_GET['post_status']) && $status_name == $_GET['post_status'] ) 
    233235        $class = ' class="current"'; 
    234236 
    235     $status_links[] = "<li><a href='edit.php?post_status=$status&amp;post_type=$post_type'$class>" . sprintf( _n( $label[2][0], $label[2][1], $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>'; 
     237    $status_links[] = "<li><a href='edit.php?post_status=$status_name&amp;post_type=$post_type'$class>" . sprintf( _n( $status->label_count[0], $status->label_count[1], $num_posts->$status_name ), number_format_i18n( $num_posts->$status_name ) ) . '</a>'; 
    236238} 
    237239echo implode( " |</li>\n", $status_links ) . '</li>'; 
  • trunk/wp-admin/includes/post.php

    r12707 r12719  
    818818    $q['m'] = isset($q['m']) ? (int) $q['m'] : 0; 
    819819    $q['cat'] = isset($q['cat']) ? (int) $q['cat'] : 0; 
    820     $post_stati  = array(   //  array( adj, noun ) 
    821                 'publish' => array(_x('Published', 'post'), __('Published posts'), _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')), 
    822                 'future' => array(_x('Scheduled', 'post'), __('Scheduled posts'), _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')), 
    823                 'pending' => array(_x('Pending Review', 'post'), __('Pending posts'), _n_noop('Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>')), 
    824                 'draft' => array(_x('Draft', 'post'), _x('Drafts', 'manage posts header'), _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')), 
    825                 'private' => array(_x('Private', 'post'), __('Private posts'), _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')), 
    826                 'trash' => array(_x('Trash', 'post'), __('Trash posts'), _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')), 
    827             ); 
    828  
    829     $post_stati = apply_filters('post_stati', $post_stati); 
     820    $post_stati  = get_post_stati(); 
    830821 
    831822    if ( isset($q['post_type']) && in_array( $q['post_type'], get_post_types( array('_show' => true) ) ) ) 
     
    836827    $avail_post_stati = get_available_post_statuses($post_type); 
    837828 
    838     if ( isset($q['post_status']) && in_array( $q['post_status'], array_keys($post_stati) ) ) { 
     829    if ( isset($q['post_status']) && in_array( $q['post_status'], $post_stati ) ) { 
    839830        $post_status = $q['post_status']; 
    840831        $perm = 'readable'; 
     
    863854    wp( compact('post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page') ); 
    864855 
    865     return array($post_stati, $avail_post_stati); 
     856    return $avail_post_stati; 
    866857} 
    867858 
  • trunk/wp-includes/post.php

    r12708 r12719  
    2222    add_post_type_support('post', array('post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments') ); 
    2323    add_post_type_support('page', array('post-thumbnails', 'page-attributes', 'custom-fields', 'comments') ); 
     24 
     25    register_post_status( 'publish', array('label' => _x('Published', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>')) ); 
     26    register_post_status( 'future', array('label' => _x('Scheduled', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')) ); 
     27    register_post_status( 'draft', array('label' => _x('Draft', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')) ); 
     28    register_post_status( 'private', array('label' => _x('Private', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')) ); 
     29    register_post_status( 'trash', array('label' => _x('Trash', 'post'), 'exclude_from_search' => false, '_builtin' => true, 'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')) ); 
    2430} 
    2531add_action( 'init', 'create_initial_post_types', 0 ); // highest priority 
     
    417423 
    418424    return $status; 
     425} 
     426 
     427/** 
     428 * Register a post type. Do not use before init. 
     429 * 
     430 * A simple function for creating or modifying a post status based on the 
     431 * parameters given. The function will accept an array (second optional 
     432 * parameter), along with a string for the post status name. 
     433 * 
     434 * 
     435 * Optional $args contents: 
     436 * 
     437 * label - A descriptive name for the post status marked for translation. Defaults to $post_status. 
     438 * public - Whether posts of this status should be shown in the admin UI. Defaults to true. 
     439 * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true. 
     440 * 
     441 * @package WordPress 
     442 * @subpackage Post 
     443 * @since 3.0 
     444 * @uses $wp_post_statuses Inserts new post status object into the list 
     445 * 
     446 * @param string $post_status Name of the post status. 
     447 * @param array|string $args See above description. 
     448 */ 
     449function register_post_status($post_status, $args = array()) { 
     450    global $wp_post_statuses; 
     451 
     452    if (!is_array($wp_post_statuses)) 
     453        $wp_post_statuses = array(); 
     454 
     455    // Args prefixed with an underscore are reserved for internal use. 
     456    $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => true, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, '_show' => false); 
     457    $args = wp_parse_args($args, $defaults); 
     458    $args = (object) $args; 
     459 
     460    $post_status = sanitize_user($post_status, true); 
     461    $args->name = $post_status; 
     462 
     463    if ( false === $args->label ) 
     464        $args->label = $post_status; 
     465 
     466    if ( false === $args->label_count ) 
     467        $args->label_count = $args->label; 
     468 
     469    if ( !$args->_builtin && $args->public ) 
     470        $args->_show = true; 
     471 
     472    $wp_post_statuses[$post_status] = $args; 
     473 
     474    return $args; 
     475} 
     476 
     477/** 
     478 * Retrieve a post status object by name 
     479 * 
     480 * @package WordPress 
     481 * @subpackage Post 
     482 * @since 3.0 
     483 * @uses $wp_post_statuses 
     484 * @see register_post_status 
     485 * @see get_post_statuses 
     486 * 
     487 * @param string $post_type The name of a registered post status 
     488 * @return object A post status object 
     489 */ 
     490function get_post_status_object( $post_status ) { 
     491    global $wp_post_statuses; 
     492 
     493    if ( empty($wp_post_statuses[$post_status]) ) 
     494        return null; 
     495 
     496    return $wp_post_statuses[$post_status]; 
     497} 
     498 
     499/** 
     500 * Get a list of all registered post status objects. 
     501 * 
     502 * @package WordPress 
     503 * @subpackage Post 
     504 * @since 3.0 
     505 * @uses $wp_post_statuses 
     506 * @see register_post_status 
     507 * @see get_post_status_object 
     508 * 
     509 * @param array|string $args An array of key => value arguments to match against the post statuses. 
     510 *  Only post statuses having attributes that match all arguments are returned. 
     511 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default. 
     512 * @return array A list of post type names or objects 
     513 */ 
     514function get_post_stati( $args = array(), $output = 'names' ) { 
     515    global $wp_post_statuses; 
     516 
     517    $do_names = false; 
     518    if ( 'names' == $output ) 
     519        $do_names = true; 
     520 
     521    $post_statuses = array(); 
     522    foreach ( (array) $wp_post_statuses as $post_status ) { 
     523        if ( empty($args) ) { 
     524            if ( $do_names ) 
     525                $post_statuses[] = $post_status->name; 
     526            else 
     527                $post_statuses[] = $post_status; 
     528        } elseif ( array_intersect_assoc((array) $post_status, $args) ) { 
     529            if ( $do_names ) 
     530                $post_statuses[] = $post_status->name; 
     531            else 
     532                $post_statuses[] = $post_status; 
     533        } 
     534    } 
     535 
     536    return $post_statuses; 
    419537} 
    420538 
Note: See TracChangeset for help on using the changeset viewer.