Make WordPress Core

Changeset 52230


Ignore:
Timestamp:
11/21/2021 07:26:08 PM (3 years ago)
Author:
audrasjb
Message:

Editor: Do not provide initial_edits for properties that are not supported by the current post type.

Previously, the block editor initialization always provided "title", "content" and "excerpt" initial edits in the initializeEditor call even though these properties might not be supported by the current post type being edited. This leads to a bug in the post editor where as soon as one would open a "new post", the editor considers the content "dirty", meaning changes are applied and it is not possible to leave the editor without encountering an "unsaved changes" notice.

This change updates the $initial_edits variable declaration to only provide the properties that are supported by the current post type.

Props youknowriad, h71.
Fixes #53813.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-blocks.php

    r51962 r52230  
    7878 * but should be included in its save payload.
    7979 */
    80 $initial_edits = null;
     80$initial_edits = array();
    8181$is_new_post   = false;
    8282if ( 'auto-draft' === $post->post_status ) {
    8383    $is_new_post = true;
    8484    // Override "(Auto Draft)" new post default title with empty string, or filtered value.
    85     $initial_edits = array(
    86         'title'   => $post->post_title,
    87         'content' => $post->post_content,
    88         'excerpt' => $post->post_excerpt,
    89     );
     85    if ( post_type_supports( $post->post_type, 'title' ) ) {
     86        $initial_edits['title'] = $post->post_title;
     87    }
     88
     89    if ( post_type_supports( $post->post_type, 'content' ) ) {
     90        $initial_edits['content'] = $post->post_content;
     91    }
     92
     93    if ( post_type_supports( $post->post_type, 'excerpt' ) ) {
     94        $initial_edits['excerpt'] = $post->post_excerpt;
     95    }
    9096}
    9197
Note: See TracChangeset for help on using the changeset viewer.