[wp-trac] [WordPress Trac] #36180: Add new param to {$new_status}_{$post->post_type} action

WordPress Trac noreply at wordpress.org
Tue Jun 22 17:21:41 UTC 2021


#36180: Add new param to {$new_status}_{$post->post_type} action
-------------------------------+-----------------------
 Reporter:  sebastian.pisula   |       Owner:  (none)
     Type:  enhancement        |      Status:  reopened
 Priority:  normal             |   Milestone:
Component:  Posts, Post Types  |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  has-patch close    |     Focuses:
-------------------------------+-----------------------
Changes (by aaroncampbell):

 * status:  closed => reopened
 * resolution:  wontfix =>


Comment:

 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:
 {{{
 #!php
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/36180#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list