[wp-trac] [WordPress Trac] #24631: transition_post_status activated also when there's no transition? (was: transition_post_status activated also when there's no tarnsition?)

WordPress Trac noreply at wordpress.org
Mon Jun 24 10:11:34 UTC 2013


#24631: transition_post_status activated also when there's no transition?
--------------------------+------------------------------
 Reporter:  hooknose      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  2.8
 Severity:  normal        |  Resolution:
 Keywords:  dev-feedback  |
--------------------------+------------------------------
Changes (by SergeyBiryukov):

 * version:  3.5.2 => 2.8


Old description:

> I'm not sure where I should post this because I don't know if it's a bug
> or a feature.
>
> It's about the action hook transition_post_status:
>
> [http://codex.wordpress.org/Post_Status_Transitions]
>
> According to the above page, "A generic transition_post_status action is
> also emitted for every status change." That description implies that this
> action hook is only activated when there's a post status change, but when
> I experimented with it I've discovered it's activated also when there is
> no status change, when $new_status is the same as $old_status. Looking at
> the code, the function wp_transition_post_status() (in wp-
> includes/post.php) is activating it and is called from wp_insert_post()
> without conditioning it on a post status change.
>
> My question is, is that a bug or is that how it's supposed to be?
>
> If that's how it's suppose to be the description in the documentation
> should change to reflect what this action hook really does, which is just
> to offer the *possibility* to detect a status transition, because
> otherwise people think it's enough to check just one of the statuses to
> detect a specific change - for instance, if the old status is 'publish'
> the new status can't be 'publish', so the post is 'unpublished', while in
> reality both the old and new status can be 'publish' - this can cause a
> critical mistake. See here, for instance:
>
> [http://blog.joshschumacher.com/2011/10/11/wordpress-
> transition_post_status-action/]
>
> Personally, I don't think the code itself should change to be activated
> only for post status transitions. It offers more flexibility and options
> the way it is, and if one needs to use it only for status transitions
> they can simply add one line of code to the top of their callback
> function:
>
> if ($new_status == $old_status) return;
>
> But I'd like an authoritative answer from someone in the development team
> to the question if it's a bug because my code currently relies on it to
> do something like that:
>
> if ($new_status == $old_status) { update X }
> elseif ($new_status = 'publish') { update X & move X to 'show' }
> elseif ($old_status = 'publish') { update X & move X to 'hide' }
>
> So if it's a bug and it's fixed in the future to be activated only for
> post status transitions my website will break. I don't want to rely on a
> bug, I want it to be a feature.

New description:

 I'm not sure where I should post this because I don't know if it's a bug
 or a feature.

 It's about the action hook transition_post_status:

 [http://codex.wordpress.org/Post_Status_Transitions]

 According to the above page, "A generic transition_post_status action is
 also emitted for every status change." That description implies that this
 action hook is only activated when there's a post status change, but when
 I experimented with it I've discovered it's activated also when there is
 no status change, when `$new_status` is the same as `$old_status`. Looking
 at the code, the function `wp_transition_post_status()` (in wp-
 includes/post.php) is activating it and is called from `wp_insert_post()`
 without conditioning it on a post status change.

 My question is, is that a bug or is that how it's supposed to be?

 If that's how it's suppose to be the description in the documentation
 should change to reflect what this action hook really does, which is just
 to offer the *possibility* to detect a status transition, because
 otherwise people think it's enough to check just one of the statuses to
 detect a specific change - for instance, if the old status is 'publish'
 the new status can't be 'publish', so the post is 'unpublished', while in
 reality both the old and new status can be 'publish' - this can cause a
 critical mistake. See here, for instance:

 [http://blog.joshschumacher.com/2011/10/11/wordpress-
 transition_post_status-action/]

 Personally, I don't think the code itself should change to be activated
 only for post status transitions. It offers more flexibility and options
 the way it is, and if one needs to use it only for status transitions they
 can simply add one line of code to the top of their callback function:
 {{{
 if ($new_status == $old_status) return;
 }}}
 But I'd like an authoritative answer from someone in the development team
 to the question if it's a bug because my code currently relies on it to do
 something like that:
 {{{
 if ($new_status == $old_status) { update X }
 elseif ($new_status = 'publish') { update X & move X to 'show' }
 elseif ($old_status = 'publish') { update X & move X to 'hide' }
 }}}
 So if it's a bug and it's fixed in the future to be activated only for
 post status transitions my website will break. I don't want to rely on a
 bug, I want it to be a feature.

--

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24631#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list