[wp-trac] [WordPress Trac] #9928: Add filter on 'post_stati' for pages

WordPress Trac wp-trac at lists.automattic.com
Sun May 24 16:55:20 GMT 2009


#9928: Add filter on 'post_stati' for pages
----------------------------+-----------------------------------------------
 Reporter:  coffee2code     |       Owner:                  
     Type:  enhancement     |      Status:  new             
 Priority:  normal          |   Milestone:  2.8             
Component:  Administration  |     Version:  2.8             
 Severity:  normal          |    Keywords:  has-patch tested
----------------------------+-----------------------------------------------
 Currently for posts, in `wp_edit_posts_query()` (in `wp-
 admin/includes/post.php`) the various available post statuses are defined
 in an array `$post_stati` which is filterable via the `post_stati` filter.

 For pages, the `$post_stati` array is defined in `wp-admin/edit-pages.php`
 in global space, though otherwise much like how is done for posts, except
 that the array is NOT passed through a filter.

 Since the array is not filterable (or otherwise able to be intercepted)
 for pages, it is not currently possible to handle filtering pages by
 post_status in the same way other post statuses (Published, Scheduled,
 Pending Review, Drafts, Private) are handled.

 The attached patch adds this simple filter.

 There are other changes that are necessary to make custom post statuses
 easier to define and use, but this is one thing that cannot currently be
 done (at least not without breaking UI consistency).

 A sample test:

 On a 2.8 install, create a page.  Via direct access to the database,
 change the post_status of the page from 'publish' to 'reject'.  View the
 listing of pages in the WP admin.  The "All" link correctly counts that
 page, but it is not listed in the count of any of the displayed
 post_statuses along the top of the listing.

 Currently there is no way to add the new post status to that visual
 listing of post statuses.  For posts, this can be done by filtering
 `post_stati`.  If the same filter is installed for pages (i.e. applying
 the associated patch), the following example code will work to add the new
 post status for pages:

 In the theme's functions.php (or a plugin), add the following:
 {{{
 add_filter('post_stati', 'add_post_status', 10, 2);
 function add_post_status($post_stati, $type = 'post') {
         if ( 'page' == $type )
                 $post_stati['reject'] = array(_x('Rejected', 'page'),
 __('Rejected pages'), _nx_noop('Rejected <span class="count">(%s)</span>',
 'Rejected <span class="count">(%s)</span>', 'page'));
         return $post_stati;
 }
 }}}

 "Rejected" will now be displayed as one of the post statuses for pages,
 along with a count of pages that have that status.

 (Note: Clicking on the status will send the proper `post_status=reject`
 query arg/val, but the results of doing so aren't properly handled by WP
 at the moment, but at least it can be made correct by hooking into
 existing filters and actions.)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9928>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list