Make WordPress Core

Changeset 56677


Ignore:
Timestamp:
09/25/2023 11:46:08 AM (2 months ago)
Author:
spacedmonkey
Message:

Themes: Use instanceof in get_hooked_blocks.

In [56610], the get_hooked_blocks function was introduced. However, using property_exists within this function negatively impacted its performance. This commit replaces the property_exists function call with instanceof WP_Block_Type, resulting in improved performance.

Props gziolo, spacedmonkey.
See #59383.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r56674 r56677  
    750750 */
    751751function get_hooked_blocks( $name, $relative_position = '' ) {
    752     $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
     752    $block_types   = WP_Block_Type_Registry::get_instance()->get_all_registered();
    753753    $hooked_blocks = array();
    754754    foreach ( $block_types as $block_type ) {
    755         if ( ! property_exists( $block_type, 'block_hooks' ) || ! is_array( $block_type->block_hooks ) ) {
     755        if ( ! ( $block_type instanceof WP_Block_Type ) || ! is_array( $block_type->block_hooks ) ) {
    756756            continue;
    757757        }
Note: See TracChangeset for help on using the changeset viewer.