mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Editor: Correctly load RTL stylesheets in register_core_block_style_handles().
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. Follow-up to [56524]. Props mukesh27, maahrokh, hellofromTonya, joemcgill, huzaifaalmesbah, rajinsharwar, devmuhib, swissspidy. Fixes #59715. git-svn-id: https://develop.svn.wordpress.org/trunk@57028 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ffcf5fb38a
commit
63a4ae98ee
@ -106,11 +106,11 @@ function register_core_block_style_handles() {
|
||||
$wp_styles->add( $style_handle, $blocks_url . $style_path );
|
||||
$wp_styles->add_data( $style_handle, 'path', $path );
|
||||
|
||||
$rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path );
|
||||
$rtl_file = "{$name}/{$filename}-rtl{$suffix}.css";
|
||||
if ( is_rtl() && in_array( $rtl_file, $files, true ) ) {
|
||||
$wp_styles->add_data( $style_handle, 'rtl', 'replace' );
|
||||
$wp_styles->add_data( $style_handle, 'suffix', $suffix );
|
||||
$wp_styles->add_data( $style_handle, 'path', $rtl_file );
|
||||
$wp_styles->add_data( $style_handle, 'path', str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ class Tests_Blocks_registerCoreBlockStyleHandles extends WP_UnitTestCase {
|
||||
|
||||
$this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
|
||||
if ( false === $wp_styles->registered[ $style_handle ]->src ) {
|
||||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' );
|
||||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
|
||||
} else {
|
||||
$this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
|
||||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' );
|
||||
@ -123,7 +123,7 @@ class Tests_Blocks_registerCoreBlockStyleHandles extends WP_UnitTestCase {
|
||||
|
||||
$this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
|
||||
if ( false === $wp_styles->registered[ $style_handle ]->src ) {
|
||||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' );
|
||||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
|
||||
} else {
|
||||
$this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
|
||||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' );
|
||||
@ -132,6 +132,40 @@ class Tests_Blocks_registerCoreBlockStyleHandles extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 59715
|
||||
*
|
||||
* @dataProvider data_block_data
|
||||
*
|
||||
* @param string $name The block name.
|
||||
*/
|
||||
public function test_register_core_block_style_handles_should_load_rtl_stylesheets_for_rtl_text_direction( $name ) {
|
||||
global $wp_locale;
|
||||
|
||||
$orig_text_dir = $wp_locale->text_direction;
|
||||
$wp_locale->text_direction = 'rtl';
|
||||
|
||||
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
|
||||
register_core_block_style_handles();
|
||||
|
||||
$wp_styles = $GLOBALS['wp_styles'];
|
||||
|
||||
$style_handle = "wp-block-{$name}-theme";
|
||||
|
||||
$wp_locale->text_direction = $orig_text_dir;
|
||||
|
||||
$this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
|
||||
if ( false === $wp_styles->registered[ $style_handle ]->src ) {
|
||||
$this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
|
||||
} else {
|
||||
$this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
|
||||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' );
|
||||
$this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' );
|
||||
$this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' );
|
||||
$this->assertArrayHasKey( 'rtl', $wp_styles->registered[ $style_handle ]->extra, 'The rtl key of the style should exist in extra array' );
|
||||
}
|
||||
}
|
||||
|
||||
public function data_block_data() {
|
||||
$core_blocks_meta = require ABSPATH . WPINC . '/blocks/blocks-json.php';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user