_wp_upgrade_revisions_of_post( WP_Post $post, array $revisions ): bool
- Since
- 3.6.0
- Source
wp-includes/revision.php:1001
Compatibility
- WordPress
- since 3.6.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
$postWP_Post- Post object.
$revisionsarray- Current revisions of the post.
Return value
bool- true if the revisions were upgraded, false if problems.
Performance profile
How much work a call to _wp_upgrade_revisions_of_post() 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
- 27–97
- Plugin surface
- None
- Called by
- 1
Reaches the database via ->query().
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 101.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_delete()called directly - sqldatabase query
->query()called directly - hookthird-party callbacks
apply_filters()one call below _wp_upgrade_revisions_of_post() - serializeserialisation
maybe_unserialize()one call below _wp_upgrade_revisions_of_post() - querycontent query
get_post()one call below _wp_upgrade_revisions_of_post()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_upgrade_revisions_of_post() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 27–31 | time(), ->prepare(), ->query(), get_option() |
| always | 49–53 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), delete_option() |
| always | 54–58 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), delete_option(), wp_save_post_revision() |
!$locked | 58–62 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), delete_option() |
!$locked | 63–67 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), delete_option(), wp_save_post_revision() |
$this_revision_version !== false && !$this_revision_version | 68 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), delete_option() |
$this_revision_version !== false && !$this_revision_version | 73 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), delete_option(), wp_save_post_revision() |
$this_revision_version !== false && !$this_revision_version | 74 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option() |
$this_revision_version !== false && !$this_revision_version | 74–77 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), delete_option() |
!$locked && $this_revision_version !== false && !$this_revision_version | 77 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), delete_option() |
$this_revision_version !== false && !$this_revision_version | 79 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option(), wp_save_post_revision() |
$this_revision_version !== false && !$this_revision_version | 79–82 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), delete_option(), wp_save_post_revision() |
9 further outcomes, up to 97 instructions
$this_revision_version !== false && !$this_revision_version | 80–83 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option() |
!$locked && $this_revision_version !== false && !$this_revision_version | 82 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), delete_option(), wp_save_post_revision() |
!$locked && $this_revision_version !== false && !$this_revision_version | 83 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option() |
!$locked && $this_revision_version !== false && !$this_revision_version | 83–86 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), delete_option() |
$this_revision_version !== false && !$this_revision_version | 85–88 | time(), ->prepare(), ->query(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option(), wp_save_post_revision() |
!$locked && $this_revision_version !== false && !$this_revision_version | 88 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option(), wp_save_post_revision() |
!$locked && $this_revision_version !== false && !$this_revision_version | 88–91 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), delete_option(), wp_save_post_revision() |
!$locked && $this_revision_version !== false && !$this_revision_version | 89–92 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option() |
!$locked && $this_revision_version !== false && !$this_revision_version | 94–97 | time(), ->prepare(), ->query(), get_option(), update_option(), reset(), current(), next(), _wp_get_post_revision_version(), _wp_get_post_revision_version(), ID(), wp_cache_delete(), delete_option(), wp_save_post_revision() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 101 | 27–97 | 10 | |
| 8.5 | 101 | 27–97 | 10 | |
| 8.4 | 101 | 27–97 | 10 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 104 | 27–100 | 10 | |
| 8.2 | 104 | 27–100 | 10 | |
| 8.1 | 104 | 27–100 | 10 | |
| 7.4 | 104 | 27–100 | 10 |
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.
Uses · 6
- get_option()Retrieves an option value based on an option name.
- update_option()Updates the value of an option that was already added.
- _wp_get_post_revision_version()Gets the post revision version.
- wp_cache_delete()Removes the cache contents matching key and group.
- delete_option()Removes an option by name. Prevents removal of protected WordPress options.
- wp_save_post_revision()Creates a revision for the current version of a post.
Used by · 1
- edit_post()Updates an existing post with values provided in `$_POST`.
Source code
function _wp_upgrade_revisions_of_post( $post, $revisions ) { global $wpdb; // Add post option exclusively. $lock = "revision-upgrade-{$post->ID}"; $now = time(); $result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'off') /* LOCK */", $lock, $now ) ); if ( ! $result ) { // If we couldn't get a lock, see how old the previous lock is. $locked = get_option( $lock ); if ( ! $locked ) { /* * Can't write to the lock, and can't read the lock. * Something broken has happened. */ return false; } if ( $locked > $now - HOUR_IN_SECONDS ) { // Lock is not too old: some other process may be upgrading this post. Bail. return false; } // Lock is too old - update it (below) and continue. } // If we could get a lock, re-"add" the option to fire all the correct filters. update_option( $lock, $now ); reset( $revisions ); $add_last = true; do { $this_revision = current( $revisions ); $prev_revision = next( $revisions ); $this_revision_version = _wp_get_post_revision_version( $this_revision ); // Something terrible happened. if ( false === $this_revision_version ) { continue; } /* * 1 is the latest revision version, so we're already up to date. * No need to add a copy of the post as latest revision. */ if ( 0 < $this_revision_version ) { $add_last = false; continue; } // Always update the revision version. $update = array( 'post_name' => preg_replace( '/^(\d+-(?:autosave|revision))[\d-]*$/', '$1-v1', $this_revision->post_name ), ); /* * If this revision is the oldest revision of the post, i.e. no $prev_revision, * the correct post_author is probably $post->post_author, but that's only a good guess. * Update the revision version only and Leave the author as-is. */ if ( $prev_revision ) { $prev_revision_version = _wp_get_post_revision_version( $prev_revision ); // If the previous revision is already up to date, it no longer has the information we need :( if ( $prev_revision_version < 1 ) { $update['post_author'] = $prev_revision->post_author; } } // Upgrade this revision. $result = $wpdb->update( $wpdb->posts, $update, array( 'ID' => $this_revision->ID ) ); if ( $result ) { wp_cache_delete( $this_revision->ID, 'posts' ); } } while ( $prev_revision );Changelog
Introduced in 3.6.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 6.9.7 tag, from
src/wp-includes/revision.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.