Make WordPress Core


Ignore:
Timestamp:
06/23/2023 06:59:53 PM (2 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r55988 r56005  
    220220    $suffix = SCRIPT_DEBUG ? '' : '.min';
    221221    if ( $is_core_block ) {
    222         $style_path = "style$suffix.css";
     222        $style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
    223223    }
    224224
     
    240240            $style_uri = get_theme_file_uri( str_replace( $theme_path_norm, '', $style_path_norm ) );
    241241        } elseif ( $is_core_block ) {
    242             $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . "/style$suffix.css" );
     242            // All possible $style_path variants for core blocks are hard-coded above.
     243            $style_uri = includes_url( 'blocks/' . str_replace( 'core/', '', $metadata['name'] ) . '/' . $style_path );
    243244        }
    244245    } else {
Note: See TracChangeset for help on using the changeset viewer.