From d145c50e144088cad5f2c8859d4601caa1739a27 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 27 Sep 2022 15:41:15 +0000 Subject: [PATCH] Editor: Correctly load RTL stylesheets in `register_block_style_handle()`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/wp-includes/blocks.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 261394bb65..d6db591bc6 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -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 ); } }