_transition_post_status( string $new_status, string $old_status, WP_Post $post )
- Since
- 2.3.0
- Source
wp-includes/post.php:8154
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
- Scaling
- Scales with input
- Instructions
- 19–73
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 93.
Third-party callbacks on 'private_to_published' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action_deprecated()called directly - cacheobject cache
wp_cache_delete()called directly - querycontent query
get_post()one call below _transition_post_status() - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
$new_status === false | 19–24 | none |
$old_status !== "publish" && $new_status === "publish" && $new_status === false | 36–39 | get_the_guid() |
$new_status !== false | 38–43 | _count_posts_cache_key(), wp_cache_delete(), _count_posts_cache_key(), wp_cache_delete() |
$old_status !== "publish" && $new_status === "publish" && $new_status === false | 51–54 | get_the_guid(), get_permalink(), ID() |
$old_status !== "publish" && $new_status === "publish" && $new_status !== false | 55–58 | get_the_guid(), _count_posts_cache_key(), wp_cache_delete(), _count_posts_cache_key(), wp_cache_delete() |
$old_status !== "publish" && $new_status === "publish" && $new_status !== false | 70–73 | get_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:
- 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
- get_the_guid()Retrieves the Post Global Unique Identifier (guid).
- get_permalink()Retrieves the full permalink for the current post or post ID.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- wp_cache_delete()Removes the cache contents matching key and group.
- _count_posts_cache_key()Returns the cache key for wp_count_posts() based on the passed arguments.
- wp_clear_scheduled_hook()Unschedules all events attached to the hook with the specified arguments.
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.
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.