mirror of
git://develop.git.wordpress.org/
synced 2025-04-21 04:31:55 +02:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@49982 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
edd77c0791
commit
f84ebe3fe7
@ -169,12 +169,17 @@ function register_block_style_handle( $metadata, $field_name ) {
|
||||
|
||||
$style_handle = generate_block_asset_handle( $metadata['name'], $field_name );
|
||||
$block_dir = dirname( $metadata['file'] );
|
||||
$style_file = realpath( "$block_dir/$style_path" );
|
||||
$result = wp_register_style(
|
||||
$style_handle,
|
||||
plugins_url( $style_path, $metadata['file'] ),
|
||||
array(),
|
||||
filemtime( realpath( "$block_dir/$style_path" ) )
|
||||
filemtime( $style_file )
|
||||
);
|
||||
if ( file_exists( str_replace( '.css', '-rtl.css', $style_file ) ) ) {
|
||||
wp_style_add_data( $style_handle, 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
return $result ? $style_handle : false;
|
||||
}
|
||||
|
||||
|
1
tests/phpunit/data/blocks/notice/block-rtl.css
Normal file
1
tests/phpunit/data/blocks/notice/block-rtl.css
Normal file
@ -0,0 +1 @@
|
||||
/* Test CSS file - RTL version */
|
@ -269,6 +269,7 @@ class WP_Test_Block_Register extends WP_UnitTestCase {
|
||||
$result = register_block_style_handle( $metadata, 'style' );
|
||||
|
||||
$this->assertSame( 'unit-tests-test-block-style', $result );
|
||||
$this->assertSame( 'replace', wp_styles()->get_data( 'unit-tests-test-block-style', 'rtl' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user