Revisions: Improve `_set_preview` for case when autosave is missing.

This change fixes an issue where autosaves are deleted when a new autosave is sent with the same data. In the block editor, this causes the preview data to be missing on post previews. The end result of this is that if one set a preview image using a block theme on a published post and preview it, the featured image is not displayed correctly. Skipping deleting the previous autosave fixes the issue.

Props adamsilverstein, walbo, audrasjb, Mamaduka, hellofromTonya.
Fixes #54708.

Built from https://develop.svn.wordpress.org/trunk@52433


git-svn-id: http://core.svn.wordpress.org/trunk@52025 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2022-01-04 00:20:01 +00:00
parent 4f16b910f3
commit 15b614acc3
2 changed files with 8 additions and 9 deletions

View File

@ -638,16 +638,15 @@ function _set_preview( $post ) {
}
$preview = wp_get_post_autosave( $post->ID );
if ( ! is_object( $preview ) ) {
return $post;
if ( is_object( $preview ) ) {
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
}
$preview = sanitize_post( $preview );
$post->post_content = $preview->post_content;
$post->post_title = $preview->post_title;
$post->post_excerpt = $preview->post_excerpt;
add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
add_filter( 'get_post_metadata', '_wp_preview_post_thumbnail_filter', 10, 3 );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-beta4-52432';
$wp_version = '5.9-beta4-52433';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.