Editor: Fix block editor styles being registered with frontend stylesheets.

This changeset fixes a bug where WordPress core's own block editor styles (`wp-block-{$block_name}-editor`) were referencing the same CSS files as their frontend equivalents (`wp-block-{$block_name}`). This would result in incorrect frontend styles potentially being loaded in the block editor.

Tests for the related logic have been added.

Props flixos90, joemcgill, mukesh27, spacedmonkey.
Fixes #58605.


git-svn-id: https://develop.svn.wordpress.org/trunk@56005 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz
2023-06-23 18:59:53 +00:00
parent 15a9bcad35
commit 915db312ab
2 changed files with 73 additions and 2 deletions

View File

@@ -219,7 +219,7 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
// Check whether styles should have a ".min" suffix or not.
$suffix = SCRIPT_DEBUG ? '' : '.min';
if ( $is_core_block ) {
$style_path = "style$suffix.css";
$style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
}
$style_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $style_path ) );
@@ -239,7 +239,8 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) {
if ( $is_theme_block ) {
$style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) );
} elseif ( $is_core_block ) {
$style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" );
// All possible $style_path variants for core blocks are hard-coded above.
$style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . '/' . $style_path );
}
} else {
$style_uri = false;