From 1cf52f07b338a5fd2778ad64ed32508702c12641 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Sep 2022 09:09:08 +0300 Subject: [PATCH] RTL fix for inlined block-styles (#41762) * RTL fix for inlined block-styles * only replace style.css * more fixes * typo fix * improve the way the vars are defined - props @SergeyBiryukov --- lib/blocks.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/blocks.php b/lib/blocks.php index e38cbdcf59ae2c..842ff6a6ec093e 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -191,21 +191,22 @@ function gutenberg_register_core_block_assets( $block_name ) { // else (for development or test) default to use the current time. $default_version = defined( 'GUTENBERG_VERSION' ) && ! ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? GUTENBERG_VERSION : time(); - $style_path = "build/block-library/blocks/$block_name/style.css"; - $editor_style_path = "build/block-library/blocks/$block_name/style-editor.css"; + $style_path = "build/block-library/blocks/$block_name/"; + $stylesheet_url = gutenberg_url( $style_path . 'style.css' ); + $stylesheet_path = gutenberg_dir_path() . $style_path . ( is_rtl() ? 'style-rtl.css' : 'style.css' ); - if ( file_exists( gutenberg_dir_path() . $style_path ) ) { + if ( file_exists( $stylesheet_path ) ) { wp_deregister_style( "wp-block-{$block_name}" ); wp_register_style( "wp-block-{$block_name}", - gutenberg_url( $style_path ), + $stylesheet_url, array(), $default_version ); wp_style_add_data( "wp-block-{$block_name}", 'rtl', 'replace' ); // Add a reference to the stylesheet's path to allow calculations for inlining styles in `wp_head`. - wp_style_add_data( "wp-block-{$block_name}", 'path', gutenberg_dir_path() . $style_path ); + wp_style_add_data( "wp-block-{$block_name}", 'path', $stylesheet_path ); } else { wp_register_style( "wp-block-{$block_name}", false, array() ); } @@ -235,7 +236,7 @@ function() { // If the file exists, enqueue it. if ( file_exists( gutenberg_dir_path() . $theme_style_path ) ) { - if ( file_exists( gutenberg_dir_path() . $style_path ) ) { + if ( file_exists( $stylesheet_path ) ) { // If there is a main stylesheet for this block, append the theme styles to main styles. wp_add_inline_style( "wp-block-{$block_name}", @@ -254,6 +255,7 @@ function() { } } + $editor_style_path = "build/block-library/blocks/$block_name/style-editor.css"; if ( file_exists( gutenberg_dir_path() . $editor_style_path ) ) { wp_deregister_style( "wp-block-{$block_name}-editor" ); wp_register_style(