From f9299148b7b7e94ac2742f5e249dd7f342ca6669 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 25 Sep 2023 11:46:08 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@56677 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 02114cf4cc..31baf119ff 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -749,10 +749,10 @@ function get_dynamic_block_names() { * @return array Associative array of `$block_type_name => $position` pairs. */ function get_hooked_blocks( $name, $relative_position = '' ) { - $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered(); + $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered(); $hooked_blocks = array(); foreach ( $block_types as $block_type ) { - if ( ! property_exists( $block_type, 'block_hooks' ) || ! is_array( $block_type->block_hooks ) ) { + if ( ! ( $block_type instanceof WP_Block_Type ) || ! is_array( $block_type->block_hooks ) ) { continue; } foreach ( $block_type->block_hooks as $anchor_block_type => $position ) {