diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 1c8de2e2c34121..cb9f1573e4e056 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -301,23 +301,6 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support return ''; } -/** - * Gets classname from last tag in a string of HTML. - * - * @param string $html markup to be processed. - * @return string String of inner wrapper classnames. - */ -function gutenberg_get_classnames_from_last_tag( $html ) { - $tags = new WP_HTML_Tag_Processor( $html ); - $last_classnames = ''; - - while ( $tags->next_tag() ) { - $last_classnames = $tags->get_attribute( 'class' ); - } - - return (string) $last_classnames; -} - /** * Renders the layout config to the block wrapper. * @@ -502,7 +485,17 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { * The first chunk of innerContent contains the block markup up until the inner blocks start. * We want to target the opening tag of the inner blocks wrapper, which is the last tag in that chunk. */ - $inner_content_classnames = isset( $block['innerContent'][0] ) && 'string' === gettype( $block['innerContent'][0] ) ? gutenberg_get_classnames_from_last_tag( $block['innerContent'][0] ) : ''; + $inner_content_classnames = ''; + + if ( isset( $block['innerContent'][0] ) && 'string' === gettype( $block['innerContent'][0] ) && count( $block['innerContent'] ) > 1 ) { + $tags = new WP_HTML_Tag_Processor( $block['innerContent'][0] ); + $last_classnames = ''; + while ( $tags->next_tag() ) { + $last_classnames = $tags->get_attribute( 'class' ); + } + + $inner_content_classnames = (string) $last_classnames; + } $content = $content_with_outer_classnames ? new WP_HTML_Tag_Processor( $content_with_outer_classnames ) : new WP_HTML_Tag_Processor( $block_content );