Skip to content

Commit

Permalink
Fix content loss for group block
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 1, 2021
1 parent a59d42d commit 69bfcee
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
* @return string Filtered block content.
*/
function gutenberg_restore_group_inner_container( $block_content, $block ) {
$group_with_inner_container_regex = '/(^(\s|\S)*<div\b[^>]*wp-block-group(\s|")[^>]*>)(([\s]|\S)*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/';
$group_with_inner_container_regex = '/(^\s*<div\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/';

if (
'core/group' !== $block['blockName'] ||
Expand All @@ -129,15 +129,14 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
return $block_content;
}

$replace_regex = '/(^(\s|\S)*<div\b[^>]*wp-block-group[^>]*>)((.|\S|\s)*)(<\/div>(\s|\S)*$)/m';
$replace_regex = '/(^\s*<div\b[^>]*wp-block-group[^>]*>)(.*)(<\/div>\s*$)/s';
$updated_content = preg_replace_callback(
$replace_regex,
function( $matches ) {
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[3] . '</div>' . $matches[5];
return $matches[1] . '<div class="wp-block-group__inner-container">' . $matches[2] . '</div>' . $matches[3];
},
$block_content
);

return $updated_content;
}

Expand Down

0 comments on commit 69bfcee

Please sign in to comment.