Skip to content

Commit

Permalink
Deprecate param in visitor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcafferkey committed Jun 26, 2024
1 parent 937c667 commit dda337c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/wp-includes/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ function _build_block_template_result_from_file( $template_file, $template_type
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
$after_block_visitor = null;
if ( maybe_has_hooked_blocks() ) {
$before_block_visitor = make_before_block_visitor( $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$before_block_visitor = make_before_block_visitor( null, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( null, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
}
$blocks = parse_blocks( $template->content );
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
Expand Down Expand Up @@ -994,8 +994,8 @@ function _build_block_template_result_from_post( $post ) {
}

if ( maybe_has_hooked_blocks() ) {
$before_block_visitor = make_before_block_visitor( $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$before_block_visitor = make_before_block_visitor( null, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( null, $template, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$blocks = parse_blocks( $template->content );
$template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}
Expand Down
28 changes: 18 additions & 10 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,8 +1063,8 @@ function apply_block_hooks_to_content( $content, $context, $callback = 'insert_h

$blocks = parse_blocks( $content );

$before_block_visitor = make_before_block_visitor( $context, $callback );
$after_block_visitor = make_after_block_visitor( $context, $callback );
$before_block_visitor = make_before_block_visitor( null, $context, $callback );
$after_block_visitor = make_after_block_visitor( null, $context, $callback );

return traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
}
Expand Down Expand Up @@ -1236,6 +1236,7 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
* @since 6.5.0 Added $callback argument.
* @access private
*
* @param mixed $deprecated Deprecated. Not used.
* @param WP_Block_Template|WP_Post|array $context A block template, template part, `wp_navigation` post object,
* or pattern that the blocks belong to.
* @param callable $callback A function that will be called for each block to generate
Expand All @@ -1244,7 +1245,10 @@ function insert_hooked_blocks_into_rest_response( $response, $post ) {
* @return callable A function that returns the serialized markup for the given block,
* including the markup for any hooked blocks before it.
*/
function make_before_block_visitor( $context, $callback = 'insert_hooked_blocks' ) {
function make_before_block_visitor( $deprecated = null, $context, $callback = 'insert_hooked_blocks' ) {
if ( null !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '6.7.0' );
}
/**
* Injects hooked blocks before the given block, injects the `theme` attribute into Template Part blocks, and returns the serialized markup.
*
Expand All @@ -1257,7 +1261,7 @@ function make_before_block_visitor( $context, $callback = 'insert_hooked_blocks'
* @param array $prev The previous sibling block of the given block. Default null.
* @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it.
*/
return function ( &$block, &$parent_block = null, $prev = null ) use ( $context, $callback ) {
return function ( &$block, &$parent_block = null, $prev = null ) use ( $deprecated, $context, $callback ) {
_inject_theme_attribute_in_template_part_block( $block );

$markup = '';
Expand All @@ -1266,13 +1270,13 @@ function make_before_block_visitor( $context, $callback = 'insert_hooked_blocks'
// Candidate for first-child insertion.
$markup .= call_user_func_array(
$callback,
array( &$parent_block, 'first_child', $context )
array( &$parent_block, 'first_child', $deprecated, $context )
);
}

$markup .= call_user_func_array(
$callback,
array( &$block, 'before', $context )
array( &$block, 'before', $deprecated, $context )
);

return $markup;
Expand All @@ -1292,6 +1296,7 @@ function make_before_block_visitor( $context, $callback = 'insert_hooked_blocks'
* @since 6.5.0 Added $callback argument.
* @access private
*
* @param mixed $deprecated Deprecated. Not used.
* @param WP_Block_Template|WP_Post|array $context A block template, template part, `wp_navigation` post object,
* or pattern that the blocks belong to.
* @param callable $callback A function that will be called for each block to generate
Expand All @@ -1300,7 +1305,10 @@ function make_before_block_visitor( $context, $callback = 'insert_hooked_blocks'
* @return callable A function that returns the serialized markup for the given block,
* including the markup for any hooked blocks after it.
*/
function make_after_block_visitor( $context, $callback = 'insert_hooked_blocks' ) {
function make_after_block_visitor( $deprecated = null, $context, $callback = 'insert_hooked_blocks' ) {
if ( null !== $deprecated ) {
_deprecated_argument( __FUNCTION__, '6.7.0' );
}
/**
* Injects hooked blocks after the given block, and returns the serialized markup.
*
Expand All @@ -1312,17 +1320,17 @@ function make_after_block_visitor( $context, $callback = 'insert_hooked_blocks'
* @param array $next The next sibling block of the given block. Default null.
* @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it.
*/
return function ( &$block, &$parent_block = null, $next = null ) use ( $context, $callback ) {
return function ( &$block, &$parent_block = null, $next = null ) use ( $deprecated, $context, $callback ) {
$markup = call_user_func_array(
$callback,
array( &$block, 'after', $context )
array( &$block, 'after', $deprecated, $context )
);

if ( $parent_block && ! $next ) {
// Candidate for last-child insertion.
$markup .= call_user_func_array(
$callback,
array( &$parent_block, 'last_child', $context )
array( &$parent_block, 'last_child', $deprecated, $context )
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private function prepare_content( $pattern ) {
$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
$after_block_visitor = null;
if ( maybe_has_hooked_blocks() ) {
$before_block_visitor = make_before_block_visitor( $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$before_block_visitor = make_before_block_visitor( null, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
$after_block_visitor = make_after_block_visitor( null, $pattern, 'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata' );
}
$blocks = parse_blocks( $content );
$content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );
Expand Down

0 comments on commit dda337c

Please sign in to comment.