Skip to content

Commit 32fe6af

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59980 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dbdeb3c commit 32fe6af

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

src/wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@
588588
add_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' );
589589
add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
590590
add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
591+
add_action( 'enqueue_block_assets', 'wp_enqueue_classic_theme_styles' );
591592
add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );
592593
add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 );
593594
/*
@@ -612,7 +613,6 @@
612613
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
613614
add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 );
614615
add_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.
618618
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );

src/wp-includes/deprecated.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6422,3 +6422,42 @@ function wp_create_block_style_variation_instance_name( $block, $variation ) {
64226422
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
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+
*/
6438+
function 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+
}

src/wp-includes/script-loader.php

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,10 @@ function wp_default_styles( $styles ) {
16621662
$styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
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',
16671671
"/wp-includes/css/dist/block-library/reset$suffix.css",
@@ -3351,54 +3355,18 @@ function wp_enqueue_block_style( $block_name, $args ) {
33513355
/**
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
*/
33583364
function 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
}
33653368
}
33663369

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;
3400-
}
3401-
34023370
/**
34033371
* Removes leading and trailing _empty_ script tags.
34043372
*

0 commit comments

Comments
 (0)