_transition_post_status

The timeline below displays how wordpress function _transition_post_status has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.5

//
// Hooks.
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ('publish' !== $old_status && 'publish' === $new_status) {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' === get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use {@see 'private_to_publish'} instead.
         *
         * @param int $post_id Post ID.
         */
        do_action_deprecated('private_to_published', array($post->ID), '2.3.0', 'private_to_publish');
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' === $new_status || 'publish' === $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}:{$post->post_type}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 5.4

//
// Hooks.
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ('publish' !== $old_status && 'publish' === $new_status) {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use {@see 'private_to_publish'} instead.
         *
         * @param int $post_id Post ID.
         */
        do_action_deprecated('private_to_published', array($post->ID), '2.3.0', 'private_to_publish');
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}:{$post->post_type}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 4.4

//
// Hooks
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use 'private_to_publish' instead.
         *
         * @param int $post_id Post ID.
         */
        do_action('private_to_published', $post->ID);
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}:{$post->post_type}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 4.1

//
// Hooks
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use 'private_to_publish' instead.
         *
         * @param int $post_id Post ID.
         */
        do_action('private_to_published', $post->ID);
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 4.0

//
// Hooks
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 *
 * @see wp_clear_scheduled_hook()
 * @global wpdb $wpdb WordPress database access abstraction object.
 *
 * @param string  $new_status New post status.
 * @param string  $old_status Previous post status.
 * @param WP_Post $post       Post object.
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty.
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use 'private_to_publish' instead.
         *
         * @param int $post_id Post ID.
         */
        do_action('private_to_published', $post->ID);
    }
    // If published posts changed clear the lastpostmodified cache.
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 3.9

//
// Hooks
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 * @uses $wpdb
 * @uses wp_clear_scheduled_hook() with 'publish_future_post' and post ID.
 *
 * @param string $new_status New post status
 * @param string $old_status Previous post status
 * @param object $post Object type containing the post information
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        /**
         * Fires when a post's status is transitioned from private to published.
         *
         * @since 1.5.0
         * @deprecated 2.3.0 Use 'private_to_publish' instead.
         *
         * @param int $post_id Post ID.
         */
        do_action('private_to_published', $post->ID);
    }
    // If published posts changed clear the lastpostmodified cache
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
        }
    }
    if ($new_status !== $old_status) {
        wp_cache_delete(_count_posts_cache_key($post->post_type), 'counts');
        wp_cache_delete(_count_posts_cache_key($post->post_type, 'readable'), 'counts');
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}

WordPress Version: 3.7

//
// Hooks
//
/**
 * Hook for managing future post transitions to published.
 *
 * @since 2.3.0
 * @access private
 * @uses $wpdb
 * @uses do_action() Calls 'private_to_published' on post ID if this is a 'private_to_published' call.
 * @uses wp_clear_scheduled_hook() with 'publish_future_post' and post ID.
 *
 * @param string $new_status New post status
 * @param string $old_status Previous post status
 * @param object $post Object type containing the post information
 */
function _transition_post_status($new_status, $old_status, $post)
{
    global $wpdb;
    if ($old_status != 'publish' && $new_status == 'publish') {
        // Reset GUID if transitioning to publish and it is empty
        if ('' == get_the_guid($post->ID)) {
            $wpdb->update($wpdb->posts, array('guid' => get_permalink($post->ID)), array('ID' => $post->ID));
        }
        do_action('private_to_published', $post->ID);
        // Deprecated, use private_to_publish
    }
    // If published posts changed clear the lastpostmodified cache
    if ('publish' == $new_status || 'publish' == $old_status) {
        foreach (array('server', 'gmt', 'blog') as $timezone) {
            wp_cache_delete("lastpostmodified:{$timezone}", 'timeinfo');
            wp_cache_delete("lastpostdate:{$timezone}", 'timeinfo');
        }
    }
    // Always clears the hook in case the post status bounced from future to draft.
    wp_clear_scheduled_hook('publish_future_post', array($post->ID));
}