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.


git-svn-id: https://develop.svn.wordpress.org/trunk@52433 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras 2022-01-04 00:18:11 +00:00
parent 12621e0228
commit 568bef0985

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