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
This commit is contained in:
hellofromTonya 2022-10-11 18:46:13 +00:00
parent b0a8a8b46e
commit 76b784ca9a
2 changed files with 6 additions and 3 deletions

View File

@ -94,7 +94,6 @@ 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(
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'] ) ) {

View File

@ -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.