WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 5 weeks ago

#23458 assigned 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: jorbin
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5
Component: Posts, Post Types Keywords: has-patch 2nd-opinion needs-docs
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 (2)

better-status-handling-for-custom-posts.diff (932 bytes) - added by misterbisson 2 years ago.
23458-2.patch (916 bytes) - added by antpb 7 weeks ago.

Download all attachments as: .zip

Change History (14)

comment:1 @misterbisson2 years ago

Props @methnen who actually implemented this for testing.

comment:2 @misterbisson20 months ago

  • Keywords 2nd-opinion added

comment:4 @antpb7 weeks ago

This looks to have a good use case for inherited custom post type status however the current patch does not include 'future' in the array. I've adjusted the patch to have the future status included. Would like to get a second set of eyes on this as I think it would be useful. Updated patch to follow...

@antpb7 weeks ago

comment:5 @slackbot7 weeks ago

This ticket was mentioned in Slack in #core by antpb. View the logs.

comment:6 @slackbot7 weeks ago

This ticket was mentioned in Slack in #core by antpb. View the logs.

comment:7 @jorbin7 weeks ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 4.3

I like this filter. It helps improve support for custom status, while also being something that is easy to maintain for backwards compatibility.

comment:8 @wonderboymusic6 weeks ago

  • Keywords needs-docs added; commit removed

comment:9 @slackbot6 weeks ago

This ticket was mentioned in Slack in #core by antpb. View the logs.

comment:10 @obenland6 weeks ago

  • Owner set to jorbin
  • Status changed from new to assigned

@jorbin, could you get this committed/punted until beta1 hits next week?

comment:11 @slackbot5 weeks ago

This ticket was mentioned in Slack in #core by obenland. View the logs.

comment:12 @obenland5 weeks ago

  • Milestone changed from 4.3 to Future Release

Let's continue this in a future release.

Note: See TracTickets for help on using tickets.