Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass reference to callback
  • Loading branch information
ockham committed Oct 31, 2023
commit 6f4d0439a2a4da0a784ee34df93dad9c811ff8c6
5 changes: 3 additions & 2 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ function traverse_and_serialize_block( $block, $pre_callback = null, $post_callb
*/
function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_callback = null ) {
$result = '';
$parent = null; // At the top level, there is no parent block to pass to the callback; yet the callback expects a reference.
foreach ( $blocks as $index => $block ) {
if ( is_callable( $pre_callback ) ) {
$prev = 0 === $index
Expand All @@ -1140,7 +1141,7 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal

$result .= call_user_func_array(
$pre_callback,
array( &$block, null, $prev ) // At the top level, there is no parent block to pass to the callback.
array( &$block, $parent, $prev )
);
}

Expand All @@ -1151,7 +1152,7 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal

$post_markup = call_user_func_array(
$post_callback,
array( &$block, null, $next ) // At the top level, there is no parent block to pass to the callback.
array( &$block, $parent, $next )
);
}

Expand Down