Skip to content
Draft
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
Next Next commit
Block Hooks: Issue warning about child insertion into semi-incompatib…
…le blocks
  • Loading branch information
ockham committed Dec 21, 2023
commit c64798e14518bfbbf34143eaef47ac84d6b1519d
15 changes: 15 additions & 0 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ function make_before_block_visitor( $hooked_blocks, $context ) {
// Candidate for first-child insertion.
$relative_position = 'first_child';
$anchor_block_type = $parent_block['blockName'];

$hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
: array();
Expand All @@ -847,6 +848,20 @@ function make_before_block_visitor( $hooked_blocks, $context ) {
foreach ( $hooked_block_types as $hooked_block_type ) {
$markup .= get_hooked_block_markup( $parent_block, $hooked_block_type );
}

$problematic_anchor_blocks_for_child_insertion = array(
'core/post-content',
'core/template-part',
);
if ( in_array( $anchor_block_type, $problematic_anchor_blocks_for_child_insertion, true ) ) {
// Display warning:
// The following block(s) are being inserted into the `first_child` position of $anchor_block_type:
// $hooked_block_types
// Note that due to the nature of the $anchor_block_type block, the hooked block(s) cannot be displayed in the
// Site Editor. Consider using `before` insertion instead.

// Inserting $hooked_block_types into `first_child` position of $anchor_block_type.
}
}

$relative_position = 'before';
Expand Down