Skip to content

Commit a25d4a7

Browse files
committed
Move logic out of foreach loop
1 parent 8f53c8b commit a25d4a7

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

src/wp-includes/blocks.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,24 +1130,24 @@ function apply_block_hooks_to_content( $content, $context = null, $callback = 'i
11301130
* `$content` at first and we're allowed to insert it once -- but not again.
11311131
*/
11321132
$suppress_single_instance_blocks = static function ( $hooked_block_types, $relative_position, $anchor_block_type ) use ( &$block_allows_multiple_instances, $content, $context ) {
1133-
static $single_instance_blocks_present_in_content = array();
1134-
foreach ( $hooked_block_types as $index => $hooked_block_type ) {
1135-
if ( $context instanceof WP_Post ) {
1136-
$wrapper_block_type = 'core/post-content';
1137-
if ( 'wp_navigation' === $context->post_type ) {
1138-
$wrapper_block_type = 'core/navigation';
1139-
} elseif ( 'wp_block' === $context->post_type ) {
1140-
$wrapper_block_type = 'core/block';
1141-
}
1133+
if ( $context instanceof WP_Post ) {
1134+
$wrapper_block_type = 'core/post-content';
1135+
if ( 'wp_navigation' === $context->post_type ) {
1136+
$wrapper_block_type = 'core/navigation';
1137+
} elseif ( 'wp_block' === $context->post_type ) {
1138+
$wrapper_block_type = 'core/block';
1139+
}
11421140

1143-
if (
1144-
$wrapper_block_type === $anchor_block_type &&
1145-
in_array( $relative_position, array( 'before', 'after' ), true )
1146-
) {
1147-
$hooked_block_types = array();
1148-
}
1141+
if (
1142+
$wrapper_block_type === $anchor_block_type &&
1143+
in_array( $relative_position, array( 'before', 'after' ), true )
1144+
) {
1145+
return array();
11491146
}
1147+
}
11501148

1149+
static $single_instance_blocks_present_in_content = array();
1150+
foreach ( $hooked_block_types as $index => $hooked_block_type ) {
11511151
if ( ! isset( $block_allows_multiple_instances[ $hooked_block_type ] ) ) {
11521152
$hooked_block_type_definition =
11531153
WP_Block_Type_Registry::get_instance()->get_registered( $hooked_block_type );

0 commit comments

Comments
 (0)