From 9ee35e14c28925f4ae98259fa7570927a6d8e675 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Sun, 21 Nov 2021 19:28:03 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@52230 git-svn-id: http://core.svn.wordpress.org/trunk@51822 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-form-blocks.php | 18 ++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php index 969d138ecb..1ed9fb0792 100644 --- a/wp-admin/edit-form-blocks.php +++ b/wp-admin/edit-form-blocks.php @@ -77,16 +77,22 @@ wp_add_inline_script( * Assign initial edits, if applicable. These are not initially assigned to the persisted post, * but should be included in its save payload. */ -$initial_edits = null; +$initial_edits = array(); $is_new_post = false; if ( 'auto-draft' === $post->post_status ) { $is_new_post = true; // Override "(Auto Draft)" new post default title with empty string, or filtered value. - $initial_edits = array( - 'title' => $post->post_title, - 'content' => $post->post_content, - 'excerpt' => $post->post_excerpt, - ); + if ( post_type_supports( $post->post_type, 'title' ) ) { + $initial_edits['title'] = $post->post_title; + } + + if ( post_type_supports( $post->post_type, 'content' ) ) { + $initial_edits['content'] = $post->post_content; + } + + if ( post_type_supports( $post->post_type, 'excerpt' ) ) { + $initial_edits['excerpt'] = $post->post_excerpt; + } } // Preload server-registered block schemas. diff --git a/wp-includes/version.php b/wp-includes/version.php index c5812430b0..59abe8469c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52229'; +$wp_version = '5.9-alpha-52230'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.