WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 5 months ago

#23458 new enhancement

Implement filters on post_status, check get_post_status() instead of the object's post_status in get_post_permalink()

Reported by: misterbisson Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Posts, Post Types Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

We have some custom post types that we wanted to implement the inherit post_status on, using the pattern created by attachments that allows child posts to inherit their status from the parent. In our case we have a top-level custom post that has a number of children of a different post type, and we wanted to make it easy to publish the entire set simply by publishing the parent.

In implementing this, however, we discovered some hard coded assumptions in get_post_permalink() and get_post_status() that got in our way. Examples:

get_post_status() has specific support for inherit as a post status, but only for attachment post types. Everything else can pound sand. To work around this we added a filter to the return value, which seemed to be both the most compatible and lowest-cost way to implement such a change. It looks like this: return apply_filters( 'get_post_status', $post->post_status, $post );.

And in get_post_permalink() we found that it's checking $post->post_status, making it impossible to ascend the hierarchy and get the status of the parent. The change there was also pretty straightforward: $draft_or_pending = get_post_status( $id ) && in_array( get_post_status( $id ), array( 'draft', 'pending', 'auto-draft' ) );.

I believe this is compatible with #23169 and #23168, which seek to improve support for custom post_statuses. The only other recent ticket/changeset I found mentioning post_status was r22963, which changed from get_post_status( $id ) to $post->post_status for compatible, but opposite reasons.

Attachments (1)

better-status-handling-for-custom-posts.diff (932 bytes) - added by misterbisson 14 months ago.

Download all attachments as: .zip

Change History (4)

comment:1 misterbisson14 months ago

Props @methnen who actually implemented this for testing.

comment:2 misterbisson5 months ago

  • Keywords 2nd-opinion added
Note: See TracTickets for help on using tickets.