Make WordPress Core


Ignore:
Timestamp:
02/16/2010 09:13:44 PM (16 years ago)
Author:
ryan
Message:

Flag post statuses as public, private, protected, or internal. Add flags for showing the type in the admin all query and the admin status list. see #9674

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r13101 r13172  
    7171
    7272    register_post_status( 'future', array(  'label' => _x('Scheduled', 'post'),
    73                                             'public' => true,
     73                                            'protected' => true,
    7474                                            '_builtin' => true,
    7575                                            'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>')
     
    7777
    7878    register_post_status( 'draft', array(   'label' => _x('Draft', 'post'),
    79                                             'public' => true,
     79                                            'protected' => true,
    8080                                            '_builtin' => true,
    8181                                            'label_count' => _n_noop('Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>')
    8282                                        ) );
    8383
     84    register_post_status( 'pending', array( 'label' => _x('Pending', 'post'),
     85                                            'protected' => true,
     86                                            '_builtin' => true,
     87                                            'label_count' => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>')
     88                                        ) );
     89
    8490    register_post_status( 'private', array( 'label' => _x('Private', 'post'),
    85                                             'public' => true,
     91                                            'private' => true,
    8692                                            '_builtin' => true,
    8793                                            'label_count' => _n_noop('Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>')
     
    8995
    9096    register_post_status( 'trash', array(   'label' => _x('Trash', 'post'),
    91                                             'public' => true,
    92                                             'exclude_from_search' => true,
     97                                            'internal' => true,
     98                                            'show_in_admin_status_list' => true,
    9399                                            '_builtin' => true,
    94100                                            'label_count' => _n_noop('Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>')
     
    96102
    97103    register_post_status( 'auto-draft', array(  'label' => _x('Auto-Draft', 'post'),
    98                                             'public' => false,
    99                                             'exclude_from_search' => true,
     104                                            'internal' => true,
    100105                                            '_builtin' => true,
    101106                                            'label_count' => _n_noop('Auto-Draft <span class="count">(%s)</span>', 'Auto-Drafts <span class="count">(%s)</span>')
     
    527532
    528533    // Args prefixed with an underscore are reserved for internal use.
    529     $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => false, 'publicly_queryable' => null, 'show_in_admin_edit' => null);
     534    $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null);
    530535    $args = wp_parse_args($args, $defaults);
    531536    $args = (object) $args;
     
    534539    $args->name = $post_status;
    535540
    536     // If not set, default to the setting for public.
     541    if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
     542        $args->internal = true;
     543
     544    if ( null === $args->public  )
     545        $args->public = false;
     546
     547    if ( null === $args->private  )
     548        $args->private = false;
     549
     550    if ( null === $args->protected  )
     551        $args->protected = false;
     552
     553    if ( null === $args->internal  )
     554        $args->internal = false;
     555
    537556    if ( null === $args->publicly_queryable )
    538557        $args->publicly_queryable = $args->public;
    539558
    540     // If not set, default to true if not public, false if public.
    541559    if ( null === $args->exclude_from_search )
    542         $args->exclude_from_search = !$args->public;
    543 
    544     // If not set, default to the setting for public.
    545     if ( null === $args->show_in_admin_edit )
    546         $args->show_in_admin_edit = $args->public;
     560        $args->exclude_from_search = $args->internal;
     561
     562    if ( null === $args->show_in_admin_all_list )
     563        $args->show_in_admin_all_list = !$args->internal;
     564
     565    if ( null === $args->show_in_admin_status_list )
     566            $args->show_in_admin_status_list = !$args->internal;
     567
     568    if ( null === $args->single_view_cap )
     569        $args->single_view_cap = $args->public ? '' : 'edit';
    547570
    548571    if ( false === $args->label )
     
    592615 *  Only post statuses having attributes that match all arguments are returned.
    593616 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default.
     617 * @param string $operator Whether the elements in $args should be logicallly 'or'ed or 'and'ed together. 'or' means only one element from the array needs to match. 'and' means all elements must match. The default is 'or'.
    594618 * @return array A list of post type names or objects
    595619 */
    596 function get_post_stati( $args = array(), $output = 'names' ) {
     620function get_post_stati( $args = array(), $output = 'names', $operator = 'or' ) {
    597621    global $wp_post_statuses;
    598622
     
    600624    if ( 'names' == $output )
    601625        $do_names = true;
     626
     627    if ( 'and' == $operator )
     628        $arg_count = count($args);
     629    else
     630        $arg_count = 0;
    602631
    603632    $post_statuses = array();
     
    608637            else
    609638                $post_statuses[] = $post_status;
    610         } elseif ( array_intersect_assoc((array) $post_status, $args) ) {
     639        } elseif ( $intersect = array_intersect_assoc((array) $post_status, $args) ) {
     640            if ( $arg_count && ( $arg_count != count($intersect) ) )
     641                continue;
    611642            if ( $do_names )
    612643                $post_statuses[] = $post_status->name;
     
    788819    if ( empty($args->read_cap) )
    789820        $args->read_cap = 'read_' . $args->capability_type;
     821    if ( empty($args->read_private_cap) )
     822        $args->read_private_cap = 'read_private_' . $args->capability_type . 's';
    790823    if ( empty($args->delete_cap) )
    791824        $args->delete_cap = 'delete_' . $args->capability_type;
Note: See TracChangeset for help on using the changeset viewer.