From e8c035f25d7ad99e0e95e2a197c80481a9f9afa4 Mon Sep 17 00:00:00 2001 From: gziolo Date: Tue, 19 Jan 2021 11:50:08 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@49982 git-svn-id: http://core.svn.wordpress.org/trunk@49683 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 7 ++++++- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index ace9811f32..9cfbfdb5dc 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index aa4ec57ead..e4ffbe07d0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7-alpha-49981'; +$wp_version = '5.7-alpha-49982'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.