wppaste
WordPress

_transition_post_status( string $new_status, string $old_status, WP_Post $post )

Since
2.3.0
Source
wp-includes/post.php:8154
Hook for managing future post transitions to published.

Compatibility

WordPress
since 2.3.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$new_statusstring
New post status.
$old_statusstring
Previous post status.
$postWP_Post
Post object.

Performance profile

How much work a call to _transition_post_status() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via get_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
19–73

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 93.

Plugin surface
1 hook

Third-party callbacks on 'private_to_published' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksdo_action_deprecated()called directly
  • cacheobject cachewp_cache_delete()called directly
  • querycontent queryget_post()one call below _transition_post_status()
  • optionoption read or writeget_option()one call below _transition_post_status()

Further down the call graph this can also reach serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 6 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _transition_post_status() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$new_status === false19–24none
$old_status !== "publish" && $new_status === "publish" && $new_status === false36–39get_the_guid()
$new_status !== false38–43_count_posts_cache_key(), wp_cache_delete(), _count_posts_cache_key(), wp_cache_delete()
$old_status !== "publish" && $new_status === "publish" && $new_status === false51–54get_the_guid(), get_permalink(), ID()
$old_status !== "publish" && $new_status === "publish" && $new_status !== false55–58get_the_guid(), _count_posts_cache_key(), wp_cache_delete(), _count_posts_cache_key(), wp_cache_delete()
$old_status !== "publish" && $new_status === "publish" && $new_status !== false70–73get_the_guid(), get_permalink(), ID(), _count_posts_cache_key(), wp_cache_delete(), _count_posts_cache_key(), wp_cache_delete()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 93 instructions, 19–73 executed per call, 8 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while _transition_post_status() runs, in this order:

  1. do_action( private_to_published )action_deprecatedline 8171 (+17 into the body)

    Fires when a post's status is transitioned from private to published.

Uses · 6

Source code

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 ) );}

Changelog

Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.