From 76b784ca9aae7b3cab3c6d8b49756af830d6c16f Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 11 Oct 2022 18:46:13 +0000 Subject: [PATCH] Editor: Fix PHP notice in `WP_Block_Supports` when no attributes declared. A check is added to verify if the block's `'attrs'` key exists before accessing it. If no, it defaults to an empty array. How was this found? WP 6.1 removed the attributes from the `core/page-list` block. When this block is being processed by `WP_Block_Supports::apply_block_supports()`, the key `'attrs'` does not exist in `self::$block_to_render`. This commit includes a tiny micro-optimization by moving this line of code after the existing guard clause. Why? If the guard clause is triggered, the method bails out early, meaning the attributes code is not used. By moving it after the guard clause, it saves a tiny bit of memory and processing if this happens. Follow-up to [49310], [54399]. Props petitphp, spacedmonkey, hellofromTonya. Fixes #56799. Built from https://develop.svn.wordpress.org/trunk@54498 git-svn-id: http://core.svn.wordpress.org/trunk@54057 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-block-supports.php | 7 +++++-- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-block-supports.php b/wp-includes/class-wp-block-supports.php index a8e2ecb36b..d6ef909af5 100644 --- a/wp-includes/class-wp-block-supports.php +++ b/wp-includes/class-wp-block-supports.php @@ -94,8 +94,7 @@ class WP_Block_Supports { * @return string[] Array of HTML attributes. */ public function apply_block_supports() { - $block_attributes = self::$block_to_render['attrs']; - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( self::$block_to_render['blockName'] ); @@ -104,6 +103,10 @@ class WP_Block_Supports { return array(); } + $block_attributes = array_key_exists( 'attrs', self::$block_to_render ) + ? self::$block_to_render['attrs'] + : array(); + $output = array(); foreach ( $this->block_supports as $block_support_config ) { if ( ! isset( $block_support_config['apply'] ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index e9fe6a5875..71bbc89eee 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta3-54497'; +$wp_version = '6.1-beta3-54498'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.