WordPress.org

Make WordPress Core

Changeset 49982


Ignore:
Timestamp:
01/19/2021 11:48:59 AM (9 months ago)
Author:
gziolo
Message:

Blocks: Add automatic RTL handlind for block styles registered from metadata

Related Gutenberg issue: https://github.com/WordPress/gutenberg/pull/28274

With this change it is going to be possible to use the same pattern that wp_style_add_data uses for RTL handling. If the block style file with "-rtl.css" is included in addition to the regular style referenced in "block.json" file then it is going to be automatically registered.

Props swisspidy, aristath.
See #52301.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r49981 r49982  
    170170    $style_handle = generate_block_asset_handle( $metadata['name'], $field_name );
    171171    $block_dir    = dirname( $metadata['file'] );
     172    $style_file   = realpath( "$block_dir/$style_path" );
    172173    $result       = wp_register_style(
    173174        $style_handle,
    174175        plugins_url( $style_path, $metadata['file'] ),
    175176        array(),
    176         filemtime( realpath( "$block_dir/$style_path" ) )
    177     );
     177        filemtime( $style_file )
     178    );
     179    if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) {
     180        wp_style_add_data( $style_handle, 'rtl', 'replace' );
     181    }
     182
    178183    return $result ? $style_handle : false;
    179184}
  • trunk/tests/phpunit/tests/blocks/register.php

    r49981 r49982  
    270270
    271271        $this->assertSame( 'unit-tests-test-block-style', $result );
     272        $this->assertSame( 'replace', wp_styles()->get_data( 'unit-tests-test-block-style', 'rtl' ) );
    272273    }
    273274
Note: See TracChangeset for help on using the changeset viewer.