Editor: Correctly load RTL stylesheets in register_block_style_handle().

When setting an RTL language under Settings → General, some RTL stylesheets were not loaded, with LTR stylesheets being loaded instead, meaning that some blocks were not displayed correctly.

This commit ensures that all appropriate RTL stylesheets are loaded when selecting an RTL language.

Additionally, this commit improves performance by only running a `file_exists()` check for an RTL stylesheet if `is_rtl()` returns true, i.e. an RTL locale is selected.

Follow-up to [49982], [50836].

Props zoonini, sabernhardt, maahrokh, ankit-k-gupta, aristath, poena, SergeyBiryukov.
See #56325.
Built from https://develop.svn.wordpress.org/trunk@54330


git-svn-id: http://core.svn.wordpress.org/trunk@53889 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2022-09-27 15:43:09 +00:00
parent abf66fa018
commit 12b190eb17
2 changed files with 4 additions and 5 deletions

View File

@ -251,14 +251,13 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
} }
if ( $has_style_file ) { if ( $has_style_file ) {
if ( file_exists( str_replace( '.css', '-rtl.css', $style_path_norm ) ) ) {
wp_style_add_data( $style_handle, 'rtl', 'replace' );
}
wp_style_add_data( $style_handle, 'path', $style_path_norm ); wp_style_add_data( $style_handle, 'path', $style_path_norm );
$rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $style_path_norm ); $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $style_path_norm );
if ( is_rtl() && file_exists( $rtl_file ) ) { if ( is_rtl() && file_exists( $rtl_file ) ) {
wp_style_add_data( $style_handle, 'rtl', 'replace' );
wp_style_add_data( $style_handle, 'suffix', $suffix );
wp_style_add_data( $style_handle, 'path', $rtl_file ); wp_style_add_data( $style_handle, 'path', $rtl_file );
} }
} }

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-beta1-54329'; $wp_version = '6.1-beta1-54330';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.