Make WordPress Core


Ignore:
Timestamp:
10/25/2022 01:43:49 PM (4 years ago)
Author:
Bernhard Reiter
Message:

Editor: Correctly apply Button block styles for classic themes

In [54358], styling for Button blocks that had been removed from classic themes was reintroduced. However, it was added with a global scope, whereas editor styles are usually added with a .editor-styles-wrapper selector, which makes them more specific.

This change modifies the way that classic theme styles are added so that they also get wrapped in an .editor-styles-wrapper selector to match specificity.

Furthermore, adjust specificity for some Button block related styling in the editor for the Twenty Twelve and Twenty Twenty themes.

Merges ​Gutenberg PR 44731 into trunk.

Follow-up to [54358].
Props scruffian, cbravobernal, sabernhardt, audrasjb.
Merges [54687] to the 6.1 branch.
See #56467.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1/src/wp-includes/script-loader.php

    r54501 r54688  
    36593659
    36603660/**
    3661  * Loads classic theme styles on classic themes.
     3661 * Loads classic theme styles on classic themes in the frontend.
    36623662 *
    36633663 * This is needed for backwards compatibility for button blocks specifically.
    … …  
    36663666 */
    36673667function wp_enqueue_classic_theme_styles() {
    3668         if ( ! wp_is_block_theme() ) {
     3668        if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
    36693669                $suffix = wp_scripts_get_suffix();
    3670                 wp_register_style( 'classic-theme-styles', "/wp-includes/css/dist/block-library/classic$suffix.css", array(), true );
     3670                wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css", array(), true );
    36713671                wp_enqueue_style( 'classic-theme-styles' );
    36723672        }
    36733673}
     3674
     3675/**
     3676 * Loads classic theme styles on classic themes in the editor.
     3677 *
     3678 * This is needed for backwards compatibility for button blocks specifically.
     3679 *
     3680 * @since 6.1.0
     3681 *
     3682 * @param array $editor_settings The array of editor settings.
     3683 * @return array A filtered array of editor settings.
     3684 */
     3685function wp_add_editor_classic_theme_styles( $editor_settings ) {
     3686        if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
     3687                return $editor_settings;
     3688        }
     3689        $suffix = wp_scripts_get_suffix();
     3690        $classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
     3691
     3692        // This follows the pattern of get_block_editor_theme_styles,
     3693        // but we can't use get_block_editor_theme_styles directly as it
     3694        // only handles external files or theme files.
     3695        $classic_theme_styles_settings = array(
     3696                'css'            => file_get_contents( $classic_theme_styles ),
     3697                '__unstableType' => 'core',
     3698                'isGlobalStyles' => false,
     3699        );
     3700
     3701        // Add these settings to the start of the array so that themes can override them.
     3702        array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
     3703
     3704        return $editor_settings;
     3705}
Note: See TracChangeset for help on using the changeset viewer.