Title: _wp_upgrade_revisions_of_post
Published: April 25, 2014
Last modified: August 20, 2026

---

# _wp_upgrade_revisions_of_post( WP_Post $post, array $revisions ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Upgrades the revisions author, adds the current post as a revision and sets the 
revisions version to 1.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#parameters)󠁿

 `$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)required

Post object.

`$revisions`arrayrequired

Current revisions of the post.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#return)󠁿

 bool true if the revisions were upgraded, false if problems.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#source)󠁿

    ```php
    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 );

    	delete_option( $lock );

    	// Add a copy of the post as latest revision.
    	if ( $add_last ) {
    		wp_save_post_revision( $post->ID );
    	}

    	return true;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/revision.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/revision.php#L1015)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/revision.php#L1015-L1104)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_cache_delete()](https://developer.wordpress.org/reference/functions/wp_cache_delete/)`wp-includes/cache.php` |

Removes the cache contents matching key and group.

  | 
| [delete_option()](https://developer.wordpress.org/reference/functions/delete_option/)`wp-includes/option.php` |

Removes an option by name. Prevents removal of protected WordPress options.

  | 
| [_wp_get_post_revision_version()](https://developer.wordpress.org/reference/functions/_wp_get_post_revision_version/)`wp-includes/revision.php` |

Gets the post revision version.

  | 
| [wp_save_post_revision()](https://developer.wordpress.org/reference/functions/wp_save_post_revision/)`wp-includes/revision.php` |

Creates a revision for the current version of a post.

  | 
| [wpdb::query()](https://developer.wordpress.org/reference/classes/wpdb/query/)`wp-includes/class-wpdb.php` |

Performs a database query, using current database connection.

  | 
| [wpdb::update()](https://developer.wordpress.org/reference/classes/wpdb/update/)`wp-includes/class-wpdb.php` |

Updates a row in the table.

  | 
| [update_option()](https://developer.wordpress.org/reference/functions/update_option/)`wp-includes/option.php` |

Updates the value of an option that was already added.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  | 
| [wpdb::prepare()](https://developer.wordpress.org/reference/classes/wpdb/prepare/)`wp-includes/class-wpdb.php` |

Prepares a SQL query for safe execution.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#)

| Used by | Description | 
| [edit_post()](https://developer.wordpress.org/reference/functions/edit_post/)`wp-admin/includes/post.php` |

Updates an existing post with values provided in `$_POST`.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_wp_upgrade_revisions_of_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_wp_upgrade_revisions_of_post%2F)
before being able to contribute a note or feedback.