Skip to content

Commit

Permalink
Extract get_hooked_block_markup function
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Nov 28, 2023
1 parent 5f2f5f6 commit d530ec9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ function get_hooked_blocks() {
return $hooked_blocks;
}

function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) {
return get_comment_delimited_block_content( $hooked_block_type, array(), '' );
}

/**
* Returns a function that injects the theme attribute into, and hooked blocks before, a given block.
*
Expand Down Expand Up @@ -813,7 +817,7 @@ function make_before_block_visitor( $hooked_blocks, $context ) {
*/
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
foreach ( $hooked_block_types as $hooked_block_type ) {
$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
$markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type );
}
}

Expand All @@ -826,7 +830,7 @@ function make_before_block_visitor( $hooked_blocks, $context ) {
/** This filter is documented in wp-includes/blocks.php */
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
foreach ( $hooked_block_types as $hooked_block_type ) {
$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
$markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type );
}

return $markup;
Expand Down Expand Up @@ -874,7 +878,7 @@ function make_after_block_visitor( $hooked_blocks, $context ) {
/** This filter is documented in wp-includes/blocks.php */
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
foreach ( $hooked_block_types as $hooked_block_type ) {
$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
$markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type );
}

if ( $parent_block && ! $next ) {
Expand All @@ -888,7 +892,7 @@ function make_after_block_visitor( $hooked_blocks, $context ) {
/** This filter is documented in wp-includes/blocks.php */
$hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
foreach ( $hooked_block_types as $hooked_block_type ) {
$markup .= get_comment_delimited_block_content( $hooked_block_type, array(), '' );
$markup .= get_hooked_block_markup( $anchor_block, $hooked_block_type );
}
}

Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/blocks/getHookedBlockMarkup
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Tests for the get_hooked_block_markup function.
*
* @package WordPress
* @subpackage Blocks
*
* @since 6.5.0
*
* @group blocks
* @group block-hooks
*/
class Tests_Blocks_InsertHookedBlock extends WP_UnitTestCase {
/**
* @covers ::get_hooked_block_markup
*/
public function test_get_hooked_block_markup() {
$anchor_block = array(
'blockName' => 'tests/anchor-block',
);

$actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' );
$this->assertSame( '<!-- wp:tests/hooked-block /-->', $actual );
}
}

0 comments on commit d530ec9

Please sign in to comment.