Make WordPress Core

Opened 11 years ago

Closed 9 years ago

Last modified 9 years ago

#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's profile misterbisson Owned by: jorbin's profile jorbin
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.5
Component: Posts, Post Types Keywords: has-patch 2nd-opinion dev-feedback
Focuses: Cc:


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 (3)

better-status-handling-for-custom-posts.diff (932 bytes) - added by misterbisson 11 years ago.
23458-2.patch (916 bytes) - added by antpb 9 years ago.
23458.diff (1.1 KB) - added by iamfriendly 9 years ago.
Refreshed the patch and added docs

Download all attachments as: .zip

Change History (19)

#1 @misterbisson
11 years ago

Props @methnen who actually implemented this for testing.

#2 @misterbisson
10 years ago

  • Keywords 2nd-opinion added

#4 @antpb
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...

9 years ago

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 @jorbin
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.

#8 @wonderboymusic
9 years ago

  • Keywords needs-docs added; commit removed

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

9 years ago

#10 @obenland
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 @obenland
9 years ago

  • Milestone changed from 4.3 to Future Release

Let's continue this in a future release.

9 years ago

Refreshed the patch and added docs

#13 @iamfriendly
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.

#14 @antpb
9 years ago

  • Keywords dev-feedback added
  • Milestone changed from Future Release to 4.4

Thank you! @obenland how should this move forward?

#15 @jorbin
9 years ago

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

In 35233:

Improve get_post_permalink compatibility with non standard post status

This adds a new filter named get_post_status to the function named get_post_status which can be used to make additional post types behave like unpublished post status in get_post_permalink.

Props misterbisson, antpb, iamfriendly
Fixes #23458

#16 @DrewAPicture
9 years ago

In 35240:

Docs: Improve the hook doc for the get_post_status filter, introduced in [35233].

Also adds a missing parameter description for $post.

See #23458. See #32246.

Note: See TracTickets for help on using tickets.