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.
Built from https://develop.svn.wordpress.org/trunk@56677


git-svn-id: http://core.svn.wordpress.org/trunk@56189 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-09-25 11:48:17 +00:00
parent 158f4a8fcc
commit 73c8507a84
2 changed files with 3 additions and 3 deletions

View File

@ -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 ) {

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-alpha-56676';
$wp_version = '6.4-alpha-56677';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.