From 542a4bd98be41e75ceb63d2aaf699e95d263cb71 Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Sat, 14 Feb 2015 09:11:28 +0000 Subject: [PATCH] Update the descriptions for `transition_post_status()` and the `{$new_stats}_{$post->post_type}` hook with more information about the expected behavior of transitioning post statuses. In some cases, the values of `$old_status` and `$new_status` may be the same thing before and after a post status is "transitioned". An example of this would be the scenario where a published post is being updated: the status before and after the update both equal 'publish'. Further, the documentation clarifies that if the intent is to only execute code when initially transitioningto a post status from something else, the 'transition_post_status' hook should be used instead of one of the dynamic hooks to avoid confusion. Props Idealien for the initial patch. Fixes #31099. Built from https://develop.svn.wordpress.org/trunk@31461 git-svn-id: http://core.svn.wordpress.org/trunk@31442 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 24 +++++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 1e5d3a27f0..dd53326853 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3919,16 +3919,14 @@ function wp_set_post_categories( $post_ID = 0, $post_categories = array(), $appe /** * Transition the post status of a post. * - * Calls hooks to transition post status. + * When a post is saved, the post status is "transitioned" from one status to another, + * though this does not always mean the status has actually changed before and after + * the save. * - * The first is 'transition_post_status' with new status, old status, and post data. - * - * The next action called is 'OLDSTATUS_to_NEWSTATUS' the 'NEWSTATUS' is the - * $new_status parameter and the 'OLDSTATUS' is $old_status parameter; it has the - * post data. - * - * The final action is named 'NEWSTATUS_POSTTYPE', 'NEWSTATUS' is from the $new_status - * parameter and POSTTYPE is post_type post data. + * For instance: When publishing a post for the first time, the post status may transition + * from 'draft' – or some other status – to 'publish'. However, if a post is already + * published and is simply being updated, the "old" and "new" statuses may both be 'publish' + * before and after the transition. * * @since 2.3.0 * @@ -3966,6 +3964,14 @@ function wp_transition_post_status( $new_status, $old_status, $post ) { * The dynamic portions of the hook name, `$new_status` and `$post->post_type`, * refer to the new post status and post type, respectively. * + * Please note: When this action is hooked using a particular post status (like + * 'publish', as `publish_{$post->post_type}`), it will fire both when a post is + * first transitioned to that status from something else, as well as upon + * subsequent post updates (old and new status are both the same). + * + * Therefore, if you are looking to only fire a callback when a post is first + * transitioned to a status, use the {@see 'transition_post_status'} hook instead. + * * @since 2.3.0 * * @param int $post_id Post ID. diff --git a/wp-includes/version.php b/wp-includes/version.php index 89988a74ef..3228ee8310 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31460'; +$wp_version = '4.2-alpha-31461'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.