Make WordPress Core

Opened 9 years ago

Closed 3 years ago

Last modified 3 years ago

#36180 closed enhancement (fixed)

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

Reported by: sebastianpisula's profile sebastian.pisula Owned by: hellofromtonya's profile 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)

36180.patch (810 bytes) - added by sebastian.pisula 9 years ago.
36180.1.diff (811 bytes) - added by audrasjb 3 years ago.
Posts, Post Types: Add $old_status parameter to {$new_status}_{$post->post_type} action
36180.2.diff (811 bytes) - added by audrasjb 3 years ago.
Posts, Post Types: Add $old_status parameter to {$new_status}_{$post->post_type} action.

Download all attachments as: .zip

Change History (17)

#1 @sebastian.pisula
9 years ago

  • Keywords has-patch added

#2 @swissspidy
9 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
8 years ago

  • Keywords close added

#4 @johnbillion
8 years ago

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

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

#6 @desrosj
3 years ago

  • Keywords close removed
  • Milestone set to 5.9

@audrasjb
3 years ago

Posts, Post Types: Add $old_status parameter to {$new_status}_{$post->post_type} action

#7 @audrasjb
3 years ago

36180.1.diff refreshes the previous patch.

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


3 years ago

#9 @hellofromTonya
3 years ago

  • Keywords needs-refresh added

Needs refresh and then should be ready for commit.

#10 @hellofromTonya
3 years ago

  • Owner set to hellofromTonya
  • Status changed from reopened to reviewing

@audrasjb
3 years ago

Posts, Post Types: Add $old_status parameter to {$new_status}_{$post->post_type} action.

#11 @audrasjb
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.

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


3 years ago

#13 @hellofromTonya
3 years ago

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

In 52067:

Posts, Post Types: Add $old_status parameter to {$new_status}_{$post->post_type} action.

Follow-up to [5797], [28106], [31461].

Props aaroncampbell, audrasjb, desrosj, johnbillion, sebastianpisula, swissspidy.
Fixes #36180.

#14 @hellofromTonya
3 years ago

Thank you everyone for your contributions! $old_status will now pass with the action in 5.9.

Note: See TracTickets for help on using tickets.