From 8cadba13e3101e6f4379f637b49ab64afef64cc8 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 17 Sep 2024 11:54:42 -0700 Subject: [PATCH 1/2] Cache is_callable checks. --- src/wp-includes/blocks.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 1a8f3459c5632..2c67c73a8d6d5 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1689,9 +1689,10 @@ function resolve_pattern_blocks( $blocks ) { function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_callback = null ) { $result = ''; $parent_block = null; // At the top level, there is no parent block to pass to the callbacks; yet the callbacks expect a reference. - + $pre_callback_is_callable = is_callable( $pre_callback ); + $post_callback_is_callable = is_callable( $post_callback ); foreach ( $blocks as $index => $block ) { - if ( is_callable( $pre_callback ) ) { + if ( $pre_callback_is_callable ) { $prev = 0 === $index ? null : $blocks[ $index - 1 ]; @@ -1702,7 +1703,7 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal ); } - if ( is_callable( $post_callback ) ) { + if ( $post_callback_is_callable ) { $next = count( $blocks ) - 1 === $index ? null : $blocks[ $index + 1 ]; From 92b8493aacbeeb757531a823462a95680fe1dc99 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Tue, 17 Sep 2024 15:54:16 -0700 Subject: [PATCH 2/2] Move variable definitions. --- src/wp-includes/blocks.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 2c67c73a8d6d5..0c09852434087 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1687,10 +1687,11 @@ function resolve_pattern_blocks( $blocks ) { * @return string Serialized block markup. */ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_callback = null ) { - $result = ''; - $parent_block = null; // At the top level, there is no parent block to pass to the callbacks; yet the callbacks expect a reference. - $pre_callback_is_callable = is_callable( $pre_callback ); + $pre_callback_is_callable = is_callable( $pre_callback ); $post_callback_is_callable = is_callable( $post_callback ); + $result = ''; + $parent_block = null; // At the top level, there is no parent block to pass to the callbacks; yet the callbacks expect a reference. + foreach ( $blocks as $index => $block ) { if ( $pre_callback_is_callable ) { $prev = 0 === $index