Skip to content

Commit c9f04d4

Browse files
Editor: fix classname output on blocks without layout.
Prevents layout classnames from being output on blocks with no layout support and no child layout classnames by returning early from `wp_render_layout_support_flag`. Props andrewserong. Fixes #60292. git-svn-id: https://develop.svn.wordpress.org/trunk@57328 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3c4fbc3 commit c9f04d4

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,9 @@ function wp_render_layout_support_flag( $block_content, $block ) {
615615
$processor->add_class( $class_name );
616616
}
617617
return $processor->get_updated_html();
618+
} elseif ( ! $block_supports_layout ) {
619+
// Ensure layout classnames are not injected if there is no layout support.
620+
return $block_content;
618621
}
619622

620623
$global_settings = wp_get_global_settings();

tests/phpunit/tests/block-supports/layout.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ public function test_outer_container_not_restored_for_aligned_image_block_with_t
171171
/**
172172
* @ticket 57584
173173
* @ticket 58548
174+
* @ticket 60292
174175
*
175176
* @dataProvider data_layout_support_flag_renders_classnames_on_wrapper
176177
*
@@ -250,6 +251,25 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() {
250251
),
251252
'expected_output' => '<div class="wp-block-group"><div class="wp-block-group__inner-wrapper is-layout-flow wp-block-group-is-layout-flow"></div></div>',
252253
),
254+
'skip classname output if block does not support layout and there are no child layout classes to be output' => array(
255+
'args' => array(
256+
'block_content' => '<p>A paragraph</p>',
257+
'block' => array(
258+
'blockName' => 'core/paragraph',
259+
'attrs' => array(
260+
'style' => array(
261+
'layout' => array(
262+
'selfStretch' => 'fit',
263+
),
264+
),
265+
),
266+
'innerBlocks' => array(),
267+
'innerHTML' => '<p>A paragraph</p>',
268+
'innerContent' => array( '<p>A paragraph</p>' ),
269+
),
270+
),
271+
'expected_output' => '<p>A paragraph</p>',
272+
),
253273
);
254274
}
255275

0 commit comments

Comments
 (0)