Make WordPress Core


Ignore:
Timestamp:
03/13/2025 10:58:25 PM (11 months ago)
Author:
audrasjb
Message:

Themes: Enqueue classic-theme-styles in enqueue_block_assets.

[54687] introduced a fallback stylesheet for Button block styles (and later File blocks) for both the front end and the editor. In the editor, that has been added within the body, after the theme's block styles. That commit had quick fixes for Twenty Twelve and Twenty Twenty, but raising the specificity for those colors should have been unnecessary. Also, themes such as Twenty Fourteen — and non-bundled themes — still have had a similar problem with the incorrect order.

Thus, this changeset:

  • Registers the stylesheet outside wp_enqueue_classic_theme_styles().
  • Enqueues classic styles in the enqueue_block_assets action instead of adding them in the block_editor_settings_all filter.
  • Deprecates the wp_add_editor_classic_theme_styles() function.

Follow-up to [54687].

Props sabernhardt, mukesh27.
Fixes #61892.

File:
1 edited

Legend:

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

    r59896 r59980  
    16631663    $styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
    16641664
     1665    $classic_theme_styles_path = WPINC . "/css/classic-themes$suffix.css";
     1666    $styles->add( 'classic-theme-styles', "/$classic_theme_styles_path" );
     1667    $styles->add_data( 'classic-theme-styles', 'path', ABSPATH . $classic_theme_styles_path );
     1668
    16651669    $styles->add(
    16661670        'wp-reset-editor-styles',
     
    33523356 * Loads classic theme styles on classic themes in the frontend.
    33533357 *
    3354  * This is needed for backwards compatibility for button blocks specifically.
     3358 * This is used for backwards compatibility for Button and File blocks specifically.
    33553359 *
    33563360 * @since 6.1.0
     3361 * @since 6.2.0 Added File block styles.
     3362 * @since 6.8.0 Moved stylesheet registration outside of this function.
    33573363 */
    33583364function wp_enqueue_classic_theme_styles() {
    33593365    if ( ! wp_theme_has_theme_json() ) {
    3360         $suffix = wp_scripts_get_suffix();
    3361         wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css" );
    3362         wp_style_add_data( 'classic-theme-styles', 'path', ABSPATH . WPINC . "/css/classic-themes$suffix.css" );
    33633366        wp_enqueue_style( 'classic-theme-styles' );
    33643367    }
    3365 }
    3366 
    3367 /**
    3368  * Loads classic theme styles on classic themes in the editor.
    3369  *
    3370  * This is needed for backwards compatibility for button blocks specifically.
    3371  *
    3372  * @since 6.1.0
    3373  *
    3374  * @param array $editor_settings The array of editor settings.
    3375  * @return array A filtered array of editor settings.
    3376  */
    3377 function wp_add_editor_classic_theme_styles( $editor_settings ) {
    3378     if ( wp_theme_has_theme_json() ) {
    3379         return $editor_settings;
    3380     }
    3381 
    3382     $suffix               = wp_scripts_get_suffix();
    3383     $classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
    3384 
    3385     /*
    3386      * This follows the pattern of get_block_editor_theme_styles,
    3387      * but we can't use get_block_editor_theme_styles directly as it
    3388      * only handles external files or theme files.
    3389      */
    3390     $classic_theme_styles_settings = array(
    3391         'css'            => file_get_contents( $classic_theme_styles ),
    3392         '__unstableType' => 'core',
    3393         'isGlobalStyles' => false,
    3394     );
    3395 
    3396     // Add these settings to the start of the array so that themes can override them.
    3397     array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
    3398 
    3399     return $editor_settings;
    34003368}
    34013369
Note: See TracChangeset for help on using the changeset viewer.