Make WordPress Core

Changeset 57028


Ignore:
Timestamp:
10/30/2023 12:52:44 PM (8 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/index.php

    r56785 r57028  
    107107        $wp_styles->add_data( $style_handle, 'path', $path );
    108108
    109         $rtl_file = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path );
     109        $rtl_file = "{$name}/{$filename}-rtl{$suffix}.css";
    110110        if ( is_rtl() && in_array( $rtl_file, $files, true ) ) {
    111111            $wp_styles->add_data( $style_handle, 'rtl', 'replace' );
    112112            $wp_styles->add_data( $style_handle, 'suffix', $suffix );
    113             $wp_styles->add_data( $style_handle, 'path', $rtl_file );
     113            $wp_styles->add_data( $style_handle, 'path', str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $path ) );
    114114        }
    115115    };
  • trunk/tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php

    r56064 r57028  
    9696            $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
    9797            if ( false === $wp_styles->registered[ $style_handle ]->src ) {
    98                 $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' );
     98                $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
    9999            } else {
    100100                $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
     
    124124        $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
    125125        if ( false === $wp_styles->registered[ $style_handle ]->src ) {
    126             $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, not style path should be set' );
     126            $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
    127127        } else {
    128128            $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
     
    130130            $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' );
    131131            $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' );
     132        }
     133    }
     134
     135    /**
     136     * @ticket 59715
     137     *
     138     * @dataProvider data_block_data
     139     *
     140     * @param string $name The block name.
     141     */
     142    public function test_register_core_block_style_handles_should_load_rtl_stylesheets_for_rtl_text_direction( $name ) {
     143        global $wp_locale;
     144
     145        $orig_text_dir             = $wp_locale->text_direction;
     146        $wp_locale->text_direction = 'rtl';
     147
     148        add_filter( 'should_load_separate_core_block_assets', '__return_true' );
     149        register_core_block_style_handles();
     150
     151        $wp_styles = $GLOBALS['wp_styles'];
     152
     153        $style_handle = "wp-block-{$name}-theme";
     154
     155        $wp_locale->text_direction = $orig_text_dir;
     156
     157        $this->assertArrayHasKey( $style_handle, $wp_styles->registered, 'The key should exist, as this style should be registered' );
     158        if ( false === $wp_styles->registered[ $style_handle ]->src ) {
     159            $this->assertEmpty( $wp_styles->registered[ $style_handle ]->extra, 'If source is false, style path should not be set' );
     160        } else {
     161            $this->assertStringContainsString( $this->includes_url, $wp_styles->registered[ $style_handle ]->src, 'Source of style should contain the includes url' );
     162            $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra, 'The path of the style should exist' );
     163            $this->assertArrayHasKey( 'path', $wp_styles->registered[ $style_handle ]->extra, 'The path key of the style should exist in extra array' );
     164            $this->assertNotEmpty( $wp_styles->registered[ $style_handle ]->extra['path'], 'The path key of the style should not be empty' );
     165            $this->assertArrayHasKey( 'rtl', $wp_styles->registered[ $style_handle ]->extra, 'The rtl key of the style should exist in extra array' );
    132166        }
    133167    }
Note: See TracChangeset for help on using the changeset viewer.