diff --git a/src/wp-includes/block-supports/layout.php b/src/wp-includes/block-supports/layout.php index 67d6a3f1b77ac..4da4f24b23be9 100644 --- a/src/wp-includes/block-supports/layout.php +++ b/src/wp-includes/block-supports/layout.php @@ -615,6 +615,9 @@ function wp_render_layout_support_flag( $block_content, $block ) { $processor->add_class( $class_name ); } return $processor->get_updated_html(); + } elseif ( ! $block_supports_layout ) { + // Ensure layout classnames are not injected if there is no layout support. + return $block_content; } $global_settings = wp_get_global_settings(); diff --git a/tests/phpunit/tests/block-supports/layout.php b/tests/phpunit/tests/block-supports/layout.php index 379c10fe2b566..a5f67f50f9b11 100644 --- a/tests/phpunit/tests/block-supports/layout.php +++ b/tests/phpunit/tests/block-supports/layout.php @@ -171,6 +171,7 @@ public function test_outer_container_not_restored_for_aligned_image_block_with_t /** * @ticket 57584 * @ticket 58548 + * @ticket 60292 * * @dataProvider data_layout_support_flag_renders_classnames_on_wrapper * @@ -250,6 +251,25 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() { ), 'expected_output' => '
', ), + 'skip classname output if block does not support layout and there are no child layout classes to be output' => array( + 'args' => array( + 'block_content' => '

A paragraph

', + 'block' => array( + 'blockName' => 'core/paragraph', + 'attrs' => array( + 'style' => array( + 'layout' => array( + 'selfStretch' => 'fit', + ), + ), + ), + 'innerBlocks' => array(), + 'innerHTML' => '

A paragraph

', + 'innerContent' => array( '

A paragraph

' ), + ), + ), + 'expected_output' => '

A paragraph

', + ), ); }