st = 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; } /** * Filters preview post meta retrieval to get values from the autosave. * * Filters revisioned meta keys only. * * @since 6.4.0 * * @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 = get_post(); if ( empty( $post ) || $post->ID !== $object_id || ! in_array( $meta_key, wp_post_revision_meta_keys( $post->post_type ), true ) || 'revision' === $post->post_type ) { return $value; } $preview = wp_get_post_autosave( $post->ID ); if ( false === $preview ) { return $value; } return get_post_meta( $preview->ID, $meta_key, $single ); }