Make WordPress Core

Changeset 54498

Timestamp:
10/11/2022 06:43:52 PM (22 months ago)
Author:
hellofromTonya
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-supports.php

    r54133 r54498  
    9595     */
    9696    public function apply_block_supports() {
    97         $block_attributes = self::$block_to_render['attrs'];
    98         $block_type       = WP_Block_Type_Registry::get_instance()->get_registered(
     97        $block_type = WP_Block_Type_Registry::get_instance()->get_registered(
    9998            self::$block_to_render['blockName']
    10099        );
     
    104103            return array();
    105104        }
     105
     106
     107
     108
    106109
    107110        $output = array();
Note: See TracChangeset for help on using the changeset viewer.