From 9699ef2e412cc22e80ecd85ecf7ad21d716cb3a7 Mon Sep 17 00:00:00 2001 From: isabel_brison Date: Wed, 20 Sep 2023 01:26:19 +0000 Subject: [PATCH] Editor: Fix post editor layout when Post Content has no attributes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes output of `wp_get_post_content_block_attributes` to return null if Post Content block doesn’t exist or empty array if it has no attributes. Props flixos90, mukesh27. Fixes #59358. Built from https://develop.svn.wordpress.org/trunk@56629 git-svn-id: http://core.svn.wordpress.org/trunk@56141 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-editor.php | 11 ++++++----- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/wp-includes/block-editor.php b/wp-includes/block-editor.php index 05bcd4e7c2..ba92c0ec3f 100644 --- a/wp-includes/block-editor.php +++ b/wp-includes/block-editor.php @@ -409,11 +409,12 @@ function wp_get_first_block( $blocks, $block_name ) { * Retrieves Post Content block attributes from the current post template. * * @since 6.3.0 + * @since 6.4.0 Return null if there is no post content block. * @access private * * @global int $post_ID * - * @return array Post Content block attributes or empty array if they don't exist. + * @return array|null Post Content block attributes array or null if Post Content block doesn't exist. */ function wp_get_post_content_block_attributes() { global $post_ID; @@ -421,7 +422,7 @@ function wp_get_post_content_block_attributes() { $is_block_theme = wp_is_block_theme(); if ( ! $is_block_theme || ! $post_ID ) { - return array(); + return null; } $template_slug = get_page_template_slug( $post_ID ); @@ -457,12 +458,12 @@ function wp_get_post_content_block_attributes() { $template_blocks = parse_blocks( $current_template[0]->content ); $post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' ); - if ( ! empty( $post_content_block['attrs'] ) ) { + if ( isset( $post_content_block['attrs'] ) ) { return $post_content_block['attrs']; } } - return array(); + return null; } /** @@ -635,7 +636,7 @@ function get_block_editor_settings( array $custom_settings, $block_editor_contex $post_content_block_attributes = wp_get_post_content_block_attributes(); - if ( ! empty( $post_content_block_attributes ) ) { + if ( isset( $post_content_block_attributes ) ) { $editor_settings['postContentAttributes'] = $post_content_block_attributes; } diff --git a/wp-includes/version.php b/wp-includes/version.php index f2b2a7d18a..236f16c87e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56628'; +$wp_version = '6.4-alpha-56629'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.