: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @global wpdb $wpdb WordPress database abstraction object.
* @param WP_Post $post Post object.
* @param array $revisions Current revisions of the post.
* @return bool true if the revisions were upgraded, false if problems.
function _wp_upgrade_revisions_of_post( $post, $revisions ) {
// Add post option exclusively.
$lock = "revision-upgrade-{$post->ID}";
$result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'off') /* LOCK */", $lock, $now ) );
// If we couldn't get a lock, see how old the previous lock is.
$locked = get_option( $lock );
* Can't write to the lock, and can't read the lock.
* Something broken has happened.
if ( $locked > $now - HOUR_IN_SECONDS ) {
// Lock is not too old: some other process may be upgrading this post. Bail.
// 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 );
$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 ) {
* 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 ) {
// Always update the revision version.
'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.
$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 ) );
wp_cache_delete( $this_revision->ID, 'posts' );
} while ( $prev_revision );
// Add a copy of the post as latest revision.
wp_save_post_revision( $post->ID );
* Filters preview post meta retrieval to get values from the autosave.
* Filters revisioned meta keys only.
* @param mixed $value Meta value to filter.
* @param int $object_id Object ID.
* @param string $meta_key Meta key to filter a value for.
* @param bool $single Whether to return a single value. Default false.
* @return mixed Original meta value if the meta key isn't revisioned, the object doesn't exist,
* the post type is a revision or the post ID doesn't match the object ID.
* Otherwise, the revisioned meta value is returned for the preview.
function _wp_preview_meta_filter( $value, $object_id, $meta_key, $single ) {
$post->ID !== $object_id ||
! in_array( $meta_key, wp_post_revision_meta_keys( $post->post_type ), true ) ||
'revision' === $post->post_type
$preview = wp_get_post_autosave( $post->ID );
if ( false === $preview ) {
return get_post_meta( $preview->ID, $meta_key, $single );