[wp-trac] [WordPress Trac] #24415: The 'show_in_admin_all_list' argument for the 'register_post_status' function is ignored when the argument 'public' is set to 'false'

WordPress Trac noreply at wordpress.org
Fri Feb 21 19:52:40 UTC 2014


#24415: The 'show_in_admin_all_list' argument for the 'register_post_status'
function is ignored when the argument 'public' is set to 'false'
-------------------------------+------------------------------
 Reporter:  XyntaMan           |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  3.5.1
 Severity:  normal             |  Resolution:
 Keywords:  needs-patch        |     Focuses:  administration
-------------------------------+------------------------------
Changes (by jessepollak):

 * keywords:   => needs-patch


Comment:

 Thanks for the bug report janfabry (and congrats on this being your first
 one!), sorry you never got a response!

 I just confirmed that this bug is still around in trunk at revision 27076.

 To recreate:

 1. Register a new post status with {{{show_in_admin_all_list = true}}} and
 {{{public = false}}} like:

 {{{
 register_post_status( 'test_status', array(
     'label'                     => _x( 'Test Status', 'post' ),
     'public'                    => false,
     'exclude_from_search'       => false,
     'show_in_admin_all_list'    => true,
     'show_in_admin_status_list' => true,
     'label_count'               => _n_noop( 'Unread <span
 class="count">(%s)</span>', 'Unread <span class="count">(%s)</span>' ),
 ));
 }}}

 2. Give a Post that status.

 '''Expected:'''

 Post is not public, but it should show up in admin all list.

 '''Actual'''

 Post is not public and it does not show up in admin all list.

 '''Why'''

 So, when we look in {{{query.php}}} at the section that filters by post
 status, we see three cases:

 {{{
 $public_states = get_post_stati( array('public' => true) );
 foreach ( (array) $public_states as $state ) {
     if ( 'publish' == $state ) // Publish is hard-coded above.
         continue;
     $where .= " OR $wpdb->posts.post_status = '$state'";
 }

 if ( $this->is_admin ) {
     // Add protected states that should show in the admin all list.
     $admin_all_states = get_post_stati( array('protected' => true,
 'show_in_admin_all_list' => true) );

     foreach ( (array) $admin_all_states as $state )
         $where .= " OR $wpdb->posts.post_status = '$state'";
 }

 if ( is_user_logged_in() ) {
     // Add private states that are limited to viewing by the author of a
 post or someone who has caps to read private states.
     $private_states = get_post_stati( array('private' => true) );
     foreach ( (array) $private_states as $state )
         $where .= current_user_can( $read_private_cap ) ? " OR
 $wpdb->posts.post_status = '$state'" : " OR $wpdb->posts.post_author =
 $user_id AND $wpdb->posts.post_status = '$state'";
 }
 }}}

 First, we look for all public posts. There, the custom status is obviously
 excluded because public is false. Then, in the admin section, we look for
 {{{show_in_admin_all_list}}} posts, but we ''also'' filter by
 {{{'protectect' => true}}}. Since our custom post type doesn't have the
 protected option set (it's not even described as an option in the docs),
 it gets excluded here — causing the bug.

 '''Fix'''

 For a temporary fix, users can add {{{protected => true}}} to their custom
 post status.

 For a long term fix, I recommend that we make that an OR query, so we get
 posts with {{{protected}}} statuses and all posts with
 {{{show_in_admin_all_list}}} statuses.

 I'd be happy to write up a patch with this fix, just let me know.

 Thanks again XyntaMan!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/24415#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list