@@ -1008,10 +1008,29 @@ function wp_render_layout_support_flag( $block_content, $block ) {
10081008 $ first_chunk = $ block ['innerContent ' ][0 ] ?? null ;
10091009 if ( is_string ( $ first_chunk ) && count ( $ block ['innerContent ' ] ) > 1 ) {
10101010 $ first_chunk_processor = new WP_HTML_Tag_Processor ( $ first_chunk );
1011- while ( $ first_chunk_processor ->next_tag () ) {
1012- $ class_attribute = $ first_chunk_processor ->get_attribute ( 'class ' );
1011+ /*
1012+ * Use a stack to track open elements as tags are visited. Void elements
1013+ * (those without a matching closing tag) are excluded so they don't
1014+ * accumulate on the stack. At the end of the chunk, every element still
1015+ * on the stack is unclosed — meaning its closing tag lives in a later
1016+ * innerContent entry alongside the inner blocks, which makes it the
1017+ * inner-block container. Elements that open and close within this chunk
1018+ * are siblings that precede the inner blocks and should be ignored.
1019+ * The last unclosed element with a class attribute is the best candidate
1020+ * for the inner-block wrapper.
1021+ */
1022+ $ tag_stack = array ();
1023+ while ( $ first_chunk_processor ->next_tag ( array ( 'tag_closers ' => 'visit ' ) ) ) {
1024+ if ( $ first_chunk_processor ->is_tag_closer () ) {
1025+ array_pop ( $ tag_stack );
1026+ } elseif ( ! WP_HTML_Processor::is_void ( $ first_chunk_processor ->get_tag () ) ) {
1027+ $ tag_stack [] = $ first_chunk_processor ->get_attribute ( 'class ' );
1028+ }
1029+ }
1030+ foreach ( array_reverse ( $ tag_stack ) as $ class_attribute ) {
10131031 if ( is_string ( $ class_attribute ) && ! empty ( $ class_attribute ) ) {
10141032 $ inner_block_wrapper_classes = $ class_attribute ;
1033+ break ;
10151034 }
10161035 }
10171036 }
0 commit comments