Changes between Initial Version and Version 1 of Ticket #24631
- Timestamp:
- 06/24/2013 10:11:33 AM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #24631
-
Property
Version
changed from
3.5.2
to2.8
-
Property
Summary
changed from
transition_post_status activated also when there's no tarnsition?
totransition_post_status activated also when there's no transition?
-
Property
Version
changed from
-
Ticket #24631 – Description
initial v1 5 5 [http://codex.wordpress.org/Post_Status_Transitions] 6 6 7 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.7 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. 8 8 9 9 My question is, is that a bug or is that how it's supposed to be? … … 14 14 15 15 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: 16 16 {{{ 17 17 if ($new_status == $old_status) return; 18 18 }}} 19 19 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: 20 20 {{{ 21 21 if ($new_status == $old_status) { update X } 22 22 elseif ($new_status = 'publish') { update X & move X to 'show' } 23 23 elseif ($old_status = 'publish') { update X & move X to 'hide' } 24 24 }}} 25 25 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.