Skip to content

Commit

Permalink
Cache is_callable checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwelcher committed Sep 17, 2024
1 parent 4dafd58 commit 8cadba1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand All @@ -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 ];
Expand Down

0 comments on commit 8cadba1

Please sign in to comment.