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.


Built from https://develop.svn.wordpress.org/trunk@59980


git-svn-id: http://core.svn.wordpress.org/trunk@59322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb
2025-03-13 23:00:31 +00:00
parent 594fb8f0a0
commit c033b97894
4 changed files with 48 additions and 41 deletions

View File

@@ -588,6 +588,7 @@ add_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
add_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' );
add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
add_action( 'enqueue_block_assets', 'wp_enqueue_classic_theme_styles' );
add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );
add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 );
/*
@@ -612,7 +613,6 @@ add_action( 'wp_print_scripts', 'wp_just_in_time_script_localization' );
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
add_action( 'customize_controls_print_styles', 'wp_resource_hints', 1 );
add_action( 'admin_head', 'wp_check_widget_editor_deps' );
add_filter( 'block_editor_settings_all', 'wp_add_editor_classic_theme_styles' );
// Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494.
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );

View File

@@ -6422,3 +6422,42 @@ function wp_create_block_style_variation_instance_name( $block, $variation ) {
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
return current_user_can_for_site( $blog_id, $capability, ...$args );
}
/**
* Loads classic theme styles on classic themes in the editor.
*
* This is used for backwards compatibility for Button and File blocks specifically.
*
* @since 6.1.0
* @since 6.2.0 Added File block styles.
* @deprecated 6.8.0 Styles are enqueued, not printed in the body element.
*
* @param array $editor_settings The array of editor settings.
* @return array A filtered array of editor settings.
*/
function wp_add_editor_classic_theme_styles( $editor_settings ) {
_deprecated_function( __FUNCTION__, '6.8.0', 'wp_enqueue_classic_theme_styles' );
if ( wp_theme_has_theme_json() ) {
return $editor_settings;
}
$suffix = wp_scripts_get_suffix();
$classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
/*
* This follows the pattern of get_block_editor_theme_styles,
* but we can't use get_block_editor_theme_styles directly as it
* only handles external files or theme files.
*/
$classic_theme_styles_settings = array(
'css' => file_get_contents( $classic_theme_styles ),
'__unstableType' => 'core',
'isGlobalStyles' => false,
);
// Add these settings to the start of the array so that themes can override them.
array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
return $editor_settings;
}

View File

@@ -1662,6 +1662,10 @@ function wp_default_styles( $styles ) {
$styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
$styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
$classic_theme_styles_path = WPINC . "/css/classic-themes$suffix.css";
$styles->add( 'classic-theme-styles', "/$classic_theme_styles_path" );
$styles->add_data( 'classic-theme-styles', 'path', ABSPATH . $classic_theme_styles_path );
$styles->add(
'wp-reset-editor-styles',
"/wp-includes/css/dist/block-library/reset$suffix.css",
@@ -3351,54 +3355,18 @@ function wp_enqueue_block_style( $block_name, $args ) {
/**
* Loads classic theme styles on classic themes in the frontend.
*
* This is needed for backwards compatibility for button blocks specifically.
* This is used for backwards compatibility for Button and File blocks specifically.
*
* @since 6.1.0
* @since 6.2.0 Added File block styles.
* @since 6.8.0 Moved stylesheet registration outside of this function.
*/
function wp_enqueue_classic_theme_styles() {
if ( ! wp_theme_has_theme_json() ) {
$suffix = wp_scripts_get_suffix();
wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css" );
wp_style_add_data( 'classic-theme-styles', 'path', ABSPATH . WPINC . "/css/classic-themes$suffix.css" );
wp_enqueue_style( 'classic-theme-styles' );
}
}
/**
* Loads classic theme styles on classic themes in the editor.
*
* This is needed for backwards compatibility for button blocks specifically.
*
* @since 6.1.0
*
* @param array $editor_settings The array of editor settings.
* @return array A filtered array of editor settings.
*/
function wp_add_editor_classic_theme_styles( $editor_settings ) {
if ( wp_theme_has_theme_json() ) {
return $editor_settings;
}
$suffix = wp_scripts_get_suffix();
$classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
/*
* This follows the pattern of get_block_editor_theme_styles,
* but we can't use get_block_editor_theme_styles directly as it
* only handles external files or theme files.
*/
$classic_theme_styles_settings = array(
'css' => file_get_contents( $classic_theme_styles ),
'__unstableType' => 'core',
'isGlobalStyles' => false,
);
// Add these settings to the start of the array so that themes can override them.
array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
return $editor_settings;
}
/**
* Removes leading and trailing _empty_ script tags.
*

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.8-beta2-59979';
$wp_version = '6.8-beta2-59980';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.