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.

git-svn-id: https://develop.svn.wordpress.org/trunk@54330 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-09-27 15:41:15 +00:00
parent 717c00fcfe
commit d145c50e14
+3 -4
View File
@@ -251,14 +251,13 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
}
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 );
$rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $style_path_norm );
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 );
}
}