#36180 closed enhancement (fixed)
Add new param to {$new_status}_{$post->post_type} action
Reported by: | sebastian.pisula | Owned by: | hellofromTonya |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
I think, that $old_status is useful in this action.
Attachments (3)
Change History (17)
#4
@
8 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
#5
@
3 years ago
- Resolution wontfix deleted
- Status changed from closed to reopened
I came up against this again recently, so I'm reopening the discussion. I do see that what @swissspidy says about using transition_post_status
is accurate, but that fires for EVERY transitioned post of any type. There end up being a lot of calls to a function that basically starts with something like:
if (
( 'publish' === $new_status && 'publish' !== $old_status ) // first published
&& 'my-post-type' === $post->post_type // my-post-type post type
) {...}
It seems like being able to use the action that fires only for a specific post type (in this case publish_my-post-type
) would be a lot more efficient and would only require that the old status be passed to the action, like it is to the other two (transition_post_status
as another parameter and {$old_status}_to_{$new_status}
as part of the dynamic name)
A big part of WHY this is a common use case where $old_status
is needed, is that updating a post that's currently published will trigger these status transition actions, even though the status isn't really transitioning at all (publish -> publish). We're obviously a long way down that road, but another option that was brought up is that we could potentially add a new action that only fires if the old and new statuses are different.
It seems like passing the old status to the existing action is the easiest fix and basically gives it access to the same info that we supply to the other two.
@
3 years ago
Posts, Post Types: Add $old_status
parameter to {$new_status}_{$post->post_type}
action
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
3 years ago
@
3 years ago
Posts, Post Types: Add $old_status
parameter to {$new_status}_{$post->post_type}
action.
#11
@
3 years ago
- Keywords commit added; needs-refresh removed
Patch refreshed against trunk.
As per today's bug scrub, I'm marking this as ready for commit
.
Note that the DocBlock of that action recommends using the
transition_post_status
hook when needing to check the old and the new status.{$new_status}_{$post->post_type}
can be called multiple times without the status having really changed.