WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #24631


Ignore:
Timestamp:
06/24/13 10:11:33 (21 months ago)
Author:
SergeyBiryukov
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24631

    • Property Version changed from 3.5.2 to 2.8
    • Property Summary changed from transition_post_status activated also when there's no tarnsition? to transition_post_status activated also when there's no transition?
  • Ticket #24631 – Description

    initial v1  
    55[http://codex.wordpress.org/Post_Status_Transitions] 
    66 
    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. 
     7According 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. 
    88 
    99My question is, is that a bug or is that how it's supposed to be? 
     
    1414 
    1515Personally, 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{{{ 
    1717if ($new_status == $old_status) return; 
    18  
     18}}} 
    1919But 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{{{ 
    2121if ($new_status == $old_status) { update X } 
    2222elseif ($new_status = 'publish') { update X & move X to 'show' } 
    2323elseif ($old_status = 'publish') { update X & move X to 'hide' } 
    24  
     24}}} 
    2525So 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.