Skip to content

Commit

Permalink
Use WP_HTML_Tag_Processor to add layout classnames
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Oct 26, 2022
1 parent d291f82 commit 1315784
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,13 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {

$inner_content_classnames = gutenberg_identify_inner_block_wrapper_classnames( $block['innerContent'] );

$content = new WP_HTML_Tag_Processor( $block_content );
if ( $inner_content_classnames ) {
$content = preg_replace(
'/' . $inner_content_classnames . '/',
$inner_content_classnames . ' ' . esc_attr( implode( ' ', $class_names ) ),
$block_content,
1
);
$content->next_tag( array( 'class_name' => $inner_content_classnames ) );
$content->add_class( esc_attr( implode( ' ', $class_names ) ) );
} else {
$content = preg_replace(
'/' . preg_quote( 'class="', '/' ) . '/',
'class="' . esc_attr( implode( ' ', $class_names ) ) . ' ',
$block_content,
1
);
$content->next_tag();
$content->add_class( esc_attr( implode( ' ', $class_names ) ) );
}

return $content;
Expand Down

0 comments on commit 1315784

Please sign in to comment.