Skip to content

Commit 354fc0e

Browse files
committed
Create single processor on outside of various checks.
1 parent 1787f75 commit 354fc0e

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/wp-includes/block-supports/layout.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,26 @@ function wp_render_layout_support_flag( $block_content, $block ) {
589589
$outer_class_names[] = $container_content_class;
590590
}
591591

592-
// Return early if only child layout exists.
592+
// Prep the processor for modifying the block output.
593+
$processor = new WP_HTML_Tag_Processor( $block_content );
594+
595+
// Having no tags implies there are no tags onto which to add class names.
596+
if ( ! $processor->next_tag() ) {
597+
return $block_content;
598+
}
599+
600+
/*
601+
* Return early if only child layout exists.
602+
*
603+
* In other words, if there is nothing more complicated, add
604+
* the wrapper class names to the first HTML tag inside the
605+
* block's rendered HTML.
606+
*/
593607
if ( ! $support_layout && ! empty( $outer_class_names ) ) {
594-
$content = new WP_HTML_Tag_Processor( $block_content );
595-
$content->next_tag();
596608
foreach ( $outer_class_names as $class_name ) {
597-
$content->add_class( $class_name );
609+
$processor->add_class( $class_name );
598610
}
599-
return $content->get_updated_html();
611+
return $processor->get_updated_html();
600612
}
601613

602614
$global_settings = wp_get_global_settings();

0 commit comments

Comments
 (0)