WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#9928 closed enhancement (fixed)

Add filter on 'post_stati' for pages

Reported by: coffee2code Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Administration Keywords: has-patch tested
Focuses: Cc:

Description

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.)

Attachments (3)

9928.diff (600 bytes) - added by coffee2code 5 years ago.
Patch mentioned in ticket.
9928-current.png (17.2 KB) - added by coffee2code 5 years ago.
UI listing of post statuses (prior to applying patch) (note that count reflects existence of page with custom post_status, but we can a link to it to the listing)
9928-after-patch.png (18.0 KB) - added by coffee2code 5 years ago.
UI listing of post statuses for pages after applying patch. "Rejected" (a sample new post_status) can now be listed alongside the others.

Download all attachments as: .zip

Change History (5)

coffee2code5 years ago

Patch mentioned in ticket.

coffee2code5 years ago

UI listing of post statuses (prior to applying patch) (note that count reflects existence of page with custom post_status, but we can a link to it to the listing)

coffee2code5 years ago

UI listing of post statuses for pages after applying patch. "Rejected" (a sample new post_status) can now be listed alongside the others.

comment:1 coffee2code5 years ago

Oops, in my comment for 9928-current.png, I meant to say we currently *can't* create a link to a listing of the new post status.

comment:2 westi5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [11458].

Changed the filter name to page_stati rather than reusing the existing one.

Note: See TracTickets for help on using tickets.