Skip to content

Commit

Permalink
Set ignoredHookedBlocks metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Nov 28, 2023
1 parent 74b38af commit 5950747
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,20 @@ function get_hooked_blocks() {
}

function get_hooked_block_markup( &$anchor_block, $hooked_block_type ) {
if (
isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) &&
in_array( $hooked_block_type, $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] )
) {
return '';
}

// The following is only needed for the REST API endpoint.
// However, its presence does not affect the frontend.
if ( ! isset( $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] ) ) {
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'] = array();
}
$anchor_block['attrs']['metadata']['ignoredHookedBlocks'][] = $hooked_block_type;

return get_comment_delimited_block_content( $hooked_block_type, array(), '' );
}

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/tests/blocks/getHookedBlockMarkup
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Tests_Blocks_GetHookedBlockMarkup extends WP_UnitTestCase
);

$actual = get_hooked_block_markup( $anchor_block, 'tests/hooked-block' );
$this->assertSame( array( 'tests/hooked-block' ), $anchor_block['attrs']['metadata']['ignoredHookedBlocks'] );
$this->assertSame( '<!-- wp:tests/hooked-block /-->', $actual );
}
}

0 comments on commit 5950747

Please sign in to comment.