Skip to content

Commit 594a577

Browse files
authored
Gutenberg tweaks: Remove suffix from RTL styles (#638)
1 parent 0ad5629 commit 594a577

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

mu-plugins/plugin-tweaks/gutenberg.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
add_filter( 'render_block_core/post-title', __NAMESPACE__ . '\swap_h0_for_paragraph', 20 );
1111
add_filter( 'render_block_core/query-title', __NAMESPACE__ . '\swap_h0_for_paragraph', 20 );
1212
add_filter( 'wp_script_attributes', __NAMESPACE__ . '\inject_module_cachebuster' );
13+
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\fix_rtl_style_includes', 1 );
1314

1415
// Remove duplicate elements generation, can be removed after GB18.3+ is active.
1516
// See https://github.com/WordPress/wporg-parent-2021/issues/135.
@@ -68,3 +69,24 @@ function inject_module_cachebuster( $attributes ) {
6869
$attributes['src'] = $source;
6970
return $attributes;
7071
}
72+
73+
/**
74+
* Remove the suffix from RTL files.
75+
*
76+
* CSS registered from block.json are incorrectly configured with a suffix for
77+
* RTL sites, but the files don't use a suffix. This prevents the files from
78+
* being replaced correctly, causing visual issues on RTL sites.
79+
*
80+
* See https://core.trac.wordpress.org/ticket/61625.
81+
*/
82+
function fix_rtl_style_includes() {
83+
$wp_styles = wp_styles();
84+
85+
foreach ( $wp_styles->registered as $handle => $data ) {
86+
// Filter out the wporg-* styles, and only adjust styles with rtl data.
87+
if ( \str_starts_with( $handle, 'wporg-' ) && isset( $data->extra['rtl'] ) ) {
88+
// Remove the suffix data.
89+
wp_style_add_data( $handle, 'suffix', '' );
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)