Make WordPress Core

Changeset 59980


Ignore:
Timestamp:
03/13/2025 10:58:25 PM (13 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.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

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

    r59968 r59980  
    589589add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
    590590add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
     591add_action( 'enqueue_block_assets', 'wp_enqueue_classic_theme_styles' );
    591592add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );
    592593add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 );
     
    613614add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 );
    614615add_action( 'admin_head', 'wp_check_widget_editor_deps' );
    615 add_filter( 'block_editor_settings_all', 'wp_add_editor_classic_theme_styles' );
    616616
    617617// Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494.
  • trunk/src/wp-includes/deprecated.php

    r59832 r59980  
    64236423    return current_user_can_for_site( $blog_id, $capability, ...$args );
    64246424}
     6425
     6426/**
     6427 * Loads classic theme styles on classic themes in the editor.
     6428 *
     6429 * This is used for backwards compatibility for Button and File blocks specifically.
     6430 *
     6431 * @since 6.1.0
     6432 * @since 6.2.0 Added File block styles.
     6433 * @deprecated 6.8.0 Styles are enqueued, not printed in the body element.
     6434 *
     6435 * @param array $editor_settings The array of editor settings.
     6436 * @return array A filtered array of editor settings.
     6437 */
     6438function wp_add_editor_classic_theme_styles( $editor_settings ) {
     6439    _deprecated_function( __FUNCTION__, '6.8.0', 'wp_enqueue_classic_theme_styles' );
     6440
     6441    if ( wp_theme_has_theme_json() ) {
     6442        return $editor_settings;
     6443    }
     6444
     6445    $suffix               = wp_scripts_get_suffix();
     6446    $classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
     6447
     6448    /*
     6449     * This follows the pattern of get_block_editor_theme_styles,
     6450     * but we can't use get_block_editor_theme_styles directly as it
     6451     * only handles external files or theme files.
     6452     */
     6453    $classic_theme_styles_settings = array(
     6454        'css'            => file_get_contents( $classic_theme_styles ),
     6455        '__unstableType' => 'core',
     6456        'isGlobalStyles' => false,
     6457    );
     6458
     6459    // Add these settings to the start of the array so that themes can override them.
     6460    array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
     6461
     6462    return $editor_settings;
     6463}
  • 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.