Themes: Enqueue classic-theme-styles in enqueue_block_assets.
Some checks failed
Cleanup Pull Requests / Clean up pull requests (push) Waiting to run
Coding Standards / PHP coding standards (push) Waiting to run
Coding Standards / JavaScript coding standards (push) Waiting to run
Coding Standards / Slack Notifications (push) Blocked by required conditions
Coding Standards / Failed workflow tasks (push) Blocked by required conditions
End-to-end Tests / Test with SCRIPT_DEBUG disabled (push) Waiting to run
End-to-end Tests / Test with SCRIPT_DEBUG enabled (push) Waiting to run
End-to-end Tests / Slack Notifications (push) Blocked by required conditions
End-to-end Tests / Failed workflow tasks (push) Blocked by required conditions
JavaScript Tests / QUnit Tests (push) Waiting to run
JavaScript Tests / Slack Notifications (push) Blocked by required conditions
JavaScript Tests / Failed workflow tasks (push) Blocked by required conditions
Performance Tests / Determine Matrix (push) Waiting to run
Performance Tests / ${{ matrix.multisite && 'Multisite' || 'Single Site' }} ${{ matrix.memcached && 'Memcached' || 'Default' }} (push) Blocked by required conditions
Performance Tests / Compare (push) Blocked by required conditions
Performance Tests / Slack Notifications (push) Blocked by required conditions
Performance Tests / Failed workflow tasks (push) Blocked by required conditions
PHP Compatibility / Check PHP compatibility (push) Waiting to run
PHP Compatibility / Slack Notifications (push) Blocked by required conditions
PHP Compatibility / Failed workflow tasks (push) Blocked by required conditions
PHPUnit Tests / PHP 7.2 (push) Waiting to run
PHPUnit Tests / PHP 7.3 (push) Waiting to run
PHPUnit Tests / PHP 7.4 (push) Waiting to run
PHPUnit Tests / PHP 8.0 (push) Waiting to run
PHPUnit Tests / PHP 8.1 (push) Waiting to run
PHPUnit Tests / PHP 8.2 (push) Waiting to run
PHPUnit Tests / PHP 8.3 (push) Waiting to run
PHPUnit Tests / PHP 8.4 (push) Waiting to run
PHPUnit Tests / html-api-html5lib-tests (push) Waiting to run
PHPUnit Tests / Slack Notifications (push) Blocked by required conditions
PHPUnit Tests / Failed workflow tasks (push) Blocked by required conditions
Test Build Processes / Core running from build (push) Waiting to run
Test Build Processes / Core running from src (push) Waiting to run
Test Build Processes / Gutenberg running from build (push) Waiting to run
Test Build Processes / Gutenberg running from src (push) Waiting to run
Test Build Processes / Slack Notifications (push) Blocked by required conditions
Test Build Processes / Failed workflow tasks (push) Blocked by required conditions
Upgrade Develop Version Tests / Build (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 4.9 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.5 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.6 (push) Has been cancelled
Upgrade Develop Version Tests / Upgrade from 6.7 (push) Has been cancelled
Upgrade Develop Version Tests / Slack Notifications (push) Has been cancelled
Upgrade Develop Version Tests / Failed workflow tasks (push) Has been cancelled

[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
This commit is contained in:
Jb Audras 2025-03-13 22:58:25 +00:00
parent dbdeb3ccdd
commit 32fe6af9c3
3 changed files with 47 additions and 40 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.
*