[wp-trac] [WordPress Trac] #33742: Menu Customizer: Adding draft items?

WordPress Trac noreply at wordpress.org
Mon Sep 5 02:45:37 UTC 2016


#33742: Menu Customizer: Adding draft items?
--------------------------+-----------------------------
 Reporter:  pavelevap     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.7
Component:  Menus         |     Version:  4.3
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  administration
--------------------------+-----------------------------

Comment (by welcher):

 I did some digging on this and it seems that when `WP_Query` is run
 without a `post_status` parameter in the admin, all post types that are
 available to the admin are queried:

 `class-wp-query` ~ line 2345
 {{{
 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 {$this->db->posts}.post_status = '$state'";
     }
 }
 }}}


 The above generates SQL like the following:

 `AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future'
 OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR
 wp_posts.post_status = 'private')`

 As such , the query is exhibiting expected behaviour - just the wrong
 behaviour for this use case.

 At the end of the day, both patches are adding `'post_status' =>
 'publish'` to the query but @westonruter 's is a more standardized
 approach. I'd go with it.

 I do wonder now however if this needs a filter to allow this behaviour? I
 can imagine someone out in the wild is using this bug as a feature.

 At any rate we should get some unit tests on this too.

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


More information about the wp-trac mailing list