#23458 closed enhancement (fixed)
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: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 3.5 |
Component: | Posts, Post Types | Keywords: | has-patch 2nd-opinion dev-feedback |
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_status
es. 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 (3)
Change History (19)
#4
@
9 years 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...
This ticket was mentioned in Slack in #core by antpb. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by antpb. View the logs.
9 years ago
#7
@
9 years 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.
This ticket was mentioned in Slack in #core by antpb. View the logs.
9 years ago
#10
@
9 years ago
- Owner set to jorbin
- Status changed from new to assigned
@jorbin, could you get this committed/punted until beta1 hits next week?
This ticket was mentioned in Slack in #core by obenland. View the logs.
9 years ago
#12
@
9 years ago
- Milestone changed from 4.3 to Future Release
Let's continue this in a future release.
#13
@
9 years ago
- Keywords needs-docs removed
Refreshed the patch because of the movement of get_post_status()
to post-functions.php and added docs for the new filter.
Props @methnen who actually implemented this for testing.