Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,16 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {

if ( is_rtl() && file_exists( $rtl_file ) ) {
wp_style_add_data( $style_handle_name, 'rtl', 'replace' );
wp_style_add_data( $style_handle_name, 'suffix', $suffix );
/*
* Core block files use a '.min' suffix (e.g. style.min.css) when
* SCRIPT_DEBUG is false, so the suffix must be stored so that
* WP_Styles::do_item() can construct the correct RTL URL via str_replace.
* Non-core block files registered from block.json never use a '.min'
* suffix, so storing a non-empty suffix would cause str_replace() to
* search for '.min.css' in a filename that only contains '.css',
* silently failing to rewrite the URL to its RTL counterpart.
*/
wp_style_add_data( $style_handle_name, 'suffix', $is_core_block ? $suffix : '' );
wp_style_add_data( $style_handle_name, 'path', $rtl_file );
}
}
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ public function test_success_register_block_style_handle() {
*
* @ticket 56325
* @ticket 56797
* @ticket 61625
*
* @covers ::register_block_style_handle
*/
Expand Down Expand Up @@ -890,6 +891,44 @@ public function test_register_block_style_handle_should_load_rtl_stylesheets_for
);
}

/**
* Tests that register_block_style_handle() always stores an empty suffix for
* non-core blocks, so that WP_Styles::do_item() can correctly rewrite the
* stylesheet URL to its RTL counterpart.
*
* Non-core block files registered via block.json never use a '.min' suffix,
* so storing a non-empty suffix causes str_replace() to search for '.min.css'
* in a filename that only contains '.css', silently leaving the LTR URL
* unchanged on RTL sites.
*
* @ticket 61625
*
* @covers ::register_block_style_handle
*/
public function test_register_block_style_handle_rtl_suffix_is_empty_for_non_core_blocks() {
global $wp_locale;

$metadata = array(
'file' => DIR_TESTDATA . '/blocks/notice/block.json',
'name' => 'tests/test-block-rtl-suffix',
'style' => 'file:./block.css',
);

$orig_text_dir = $wp_locale->text_direction;
$wp_locale->text_direction = 'rtl';

register_block_style_handle( $metadata, 'style' );
$extra_suffix = wp_styles()->get_data( 'tests-test-block-rtl-suffix-style', 'suffix' );

$wp_locale->text_direction = $orig_text_dir;

$this->assertSame(
'',
$extra_suffix,
'Non-core block RTL styles must have an empty suffix so the LTR URL is correctly rewritten to the RTL URL, regardless of SCRIPT_DEBUG.'
);
}

/**
* @ticket 56664
*/
Expand Down
Loading