WordPress.org

Make WordPress Core

Changeset 52433


Ignore:
Timestamp:
01/04/2022 12:18:11 AM (3 weeks ago)
Author:
audrasjb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/revision.php

    r52095 r52433  
    639639
    640640    $preview = wp_get_post_autosave( $post->ID );
    641     if ( ! is_object( $preview ) ) {
    642         return $post;
    643     }
    644 
    645     $preview = sanitize_post( $preview );
    646 
    647     $post->post_content = $preview->post_content;
    648     $post->post_title   = $preview->post_title;
    649     $post->post_excerpt = $preview->post_excerpt;
     641
     642    if ( is_object( $preview ) ) {
     643        $preview = sanitize_post( $preview );
     644
     645        $post->post_content = $preview->post_content;
     646        $post->post_title   = $preview->post_title;
     647        $post->post_excerpt = $preview->post_excerpt;
     648    }
    650649
    651650    add_filter( 'get_the_terms', '_wp_preview_terms_filter', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.