Make WordPress Core

Opened 6 years ago

Last modified 3 months ago

#36180 reopened enhancement

Add new param to {$new_status}_{$post->post_type} action

Reported by: sebastian.pisula Owned by:
Milestone: 5.9 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:


I think, that $old_status is useful in this action.

Attachments (1)

36180.patch (810 bytes) - added by sebastian.pisula 6 years ago.

Download all attachments as: .zip

Change History (7)

#1 @sebastian.pisula
6 years ago

  • Keywords has-patch added

#2 @swissspidy
6 years ago

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.

#3 @swissspidy
5 years ago

  • Keywords close added

#4 @johnbillion
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

#5 @aaroncampbell
3 months 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.

#6 @desrosj
3 months ago

  • Keywords close removed
  • Milestone set to 5.9
Note: See TracTickets for help on using tickets.