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:||jorbin|
|Component:||Posts, Post Types||Keywords:||has-patch 2nd-opinion needs-docs|
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.
Change History (14)
- Keywords commit added
- Milestone changed from Awaiting Review to 4.3