diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index ace9811f32e1b..9cfbfdb5dcaec 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -169,12 +169,17 @@ function register_block_style_handle( $metadata, $field_name ) { $style_handle = generate_block_asset_handle( $metadata['name'], $field_name ); $block_dir = dirname( $metadata['file'] ); + $style_file = realpath( "$block_dir/$style_path" ); $result = wp_register_style( $style_handle, plugins_url( $style_path, $metadata['file'] ), array(), - filemtime( realpath( "$block_dir/$style_path" ) ) + filemtime( $style_file ) ); + if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) { + wp_style_add_data( $style_handle, 'rtl', 'replace' ); + } + return $result ? $style_handle : false; } diff --git a/tests/phpunit/data/blocks/notice/block-rtl.css b/tests/phpunit/data/blocks/notice/block-rtl.css new file mode 100644 index 0000000000000..2572f27aaf2d9 --- /dev/null +++ b/tests/phpunit/data/blocks/notice/block-rtl.css @@ -0,0 +1 @@ +/* Test CSS file - RTL version */ diff --git a/tests/phpunit/tests/blocks/register.php b/tests/phpunit/tests/blocks/register.php index 5ea58af398acc..1d6e845d6f7c2 100644 --- a/tests/phpunit/tests/blocks/register.php +++ b/tests/phpunit/tests/blocks/register.php @@ -269,6 +269,7 @@ function test_success_register_block_style_handle() { $result = register_block_style_handle( $metadata, 'style' ); $this->assertSame( 'unit-tests-test-block-style', $result ); + $this->assertSame( 'replace', wp_styles()->get_data( 'unit-tests-test-block-style', 'rtl' ) ); } /**