Skip to content

Commit 3edb8fa

Browse files
committed
Editor: Correctly apply Button block styles for classic themes
In [54358], styling for Button blocks that had been removed from classic themes was reintroduced. However, it was added with a global scope, whereas editor styles are usually added with a `.editor-styles-wrapper` selector, which makes them more specific. This change modifies the way that classic theme styles are added so that they also get wrapped in an `.editor-styles-wrapper` selector to match specificity. Furthermore, adjust specificity for some Button block related styling in the editor for the Twenty Twelve and Twenty Twenty themes. Merges [WordPress/gutenberg#44731 Gutenberg PR 44731] into trunk. Follow-up to [54358]. Props scruffian, cbravobernal, sabernhardt, audrasjb. See #56467. Built from https://develop.svn.wordpress.org/trunk@54687 git-svn-id: https://core.svn.wordpress.org/trunk@54239 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent bf2e3f2 commit 3edb8fa

File tree

8 files changed

+76
-13
lines changed

8 files changed

+76
-13
lines changed

wp-content/themes/twentytwelve/css/editor-blocks.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ p.has-drop-cap:not(:focus)::first-letter {
369369
background-image: -o-linear-gradient(top, #f4f4f4, #e6e6e6);
370370
background-image: linear-gradient(to bottom, #f4f4f4, #e6e6e6);
371371
background-repeat: repeat-x;
372+
color: #7c7c7c;
372373
}
373374

374375
/* Separator */

wp-content/themes/twentytwenty/assets/css/editor-style-block-rtl.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,8 @@ hr.wp-block-separator.is-style-dots::before {
920920

921921
/* Block: Button ----------------------------- */
922922

923-
.editor-styles-wrapper .wp-block-button__link,
924-
.editor-styles-wrapper .wp-block-file__button {
923+
:root .editor-styles-wrapper .wp-block-button__link,
924+
:root .editor-styles-wrapper .wp-block-file__button {
925925
background: #cd2653;
926926
border-radius: 0;
927927
color: #fff;
@@ -937,6 +937,11 @@ hr.wp-block-separator.is-style-dots::before {
937937
line-height: 1.1;
938938
}
939939

940+
.editor-styles-wrapper .wp-block-button__link:hover,
941+
.editor-styles-wrapper .wp-block-file__button:hover {
942+
text-decoration: underline;
943+
}
944+
940945
/* BUTTON STYLE: OUTLINE */
941946

942947
.editor-styles-wrapper .is-style-outline .wp-block-button__link,
@@ -1301,8 +1306,8 @@ hr.wp-block-separator.is-style-dots::before {
13011306

13021307
/* BLOCK: BUTTON */
13031308

1304-
.editor-styles-wrapper .wp-block-button__link,
1305-
.editor-styles-wrapper .wp-block-file__button {
1309+
:root .editor-styles-wrapper .wp-block-button__link,
1310+
:root .editor-styles-wrapper .wp-block-file__button {
13061311
font-size: 17px;
13071312
}
13081313

wp-content/themes/twentytwenty/assets/css/editor-style-block.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,8 +924,8 @@ hr.wp-block-separator.is-style-dots::before {
924924

925925
/* Block: Button ----------------------------- */
926926

927-
.editor-styles-wrapper .wp-block-button__link,
928-
.editor-styles-wrapper .wp-block-file__button {
927+
:root .editor-styles-wrapper .wp-block-button__link,
928+
:root .editor-styles-wrapper .wp-block-file__button {
929929
background: #cd2653;
930930
border-radius: 0;
931931
color: #fff;
@@ -941,6 +941,11 @@ hr.wp-block-separator.is-style-dots::before {
941941
line-height: 1.1;
942942
}
943943

944+
.editor-styles-wrapper .wp-block-button__link:hover,
945+
.editor-styles-wrapper .wp-block-file__button:hover {
946+
text-decoration: underline;
947+
}
948+
944949
/* BUTTON STYLE: OUTLINE */
945950

946951
.editor-styles-wrapper .is-style-outline .wp-block-button__link,
@@ -1305,8 +1310,8 @@ hr.wp-block-separator.is-style-dots::before {
13051310

13061311
/* BLOCK: BUTTON */
13071312

1308-
.editor-styles-wrapper .wp-block-button__link,
1309-
.editor-styles-wrapper .wp-block-file__button {
1313+
:root .editor-styles-wrapper .wp-block-button__link,
1314+
:root .editor-styles-wrapper .wp-block-file__button {
13101315
font-size: 17px;
13111316
}
13121317

wp-includes/css/classic-themes.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* These rules are needed for backwards compatibility.
3+
* They should match the button element rules in the base theme.json file.
4+
*/
5+
.wp-block-button__link {
6+
color: #ffffff;
7+
background-color: #32373c;
8+
border-radius: 9999px; /* 100% causes an oval, but any explicit but really high value retains the pill shape. */
9+
10+
/* This needs a low specificity so it won't override the rules from the button element if defined in theme.json. */
11+
box-shadow: none;
12+
text-decoration: none;
13+
14+
/* The extra 2px are added to size solids the same as the outline versions.*/
15+
padding: calc(0.667em + 2px) calc(1.333em + 2px);
16+
17+
font-size: 1.125em;
18+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*! This file is auto-generated */
2+
.wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}

wp-includes/default-filters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@
560560
add_action( 'wp_enqueue_scripts', 'wp_enqueue_classic_theme_styles' );
561561
add_action( 'admin_enqueue_scripts', 'wp_localize_jquery_ui_datepicker', 1000 );
562562
add_action( 'admin_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
563-
add_action( 'admin_enqueue_scripts', 'wp_enqueue_classic_theme_styles' );
564563
add_action( 'enqueue_block_assets', 'wp_enqueue_registered_block_scripts_and_styles' );
565564
add_action( 'enqueue_block_assets', 'enqueue_block_styles_assets', 30 );
566565
add_action( 'enqueue_block_editor_assets', 'wp_enqueue_registered_block_scripts_and_styles' );
@@ -572,6 +571,7 @@
572571
add_filter( 'print_scripts_array', 'wp_prototype_before_jquery' );
573572
add_filter( 'customize_controls_print_styles', 'wp_resource_hints', 1 );
574573
add_action( 'admin_head', 'wp_check_widget_editor_deps' );
574+
add_filter( 'block_editor_settings_all', 'wp_add_editor_classic_theme_styles' );
575575

576576
// Global styles can be enqueued in both the header and the footer. See https://core.trac.wordpress.org/ticket/53494.
577577
add_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );

wp-includes/script-loader.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3658,16 +3658,48 @@ function _wp_theme_json_webfonts_handler() {
36583658
}
36593659

36603660
/**
3661-
* Loads classic theme styles on classic themes.
3661+
* Loads classic theme styles on classic themes in the frontend.
36623662
*
36633663
* This is needed for backwards compatibility for button blocks specifically.
36643664
*
36653665
* @since 6.1.0
36663666
*/
36673667
function wp_enqueue_classic_theme_styles() {
3668-
if ( ! wp_is_block_theme() ) {
3668+
if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
36693669
$suffix = wp_scripts_get_suffix();
3670-
wp_register_style( 'classic-theme-styles', "/wp-includes/css/dist/block-library/classic$suffix.css", array(), true );
3670+
wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css", array(), true );
36713671
wp_enqueue_style( 'classic-theme-styles' );
36723672
}
36733673
}
3674+
3675+
/**
3676+
* Loads classic theme styles on classic themes in the editor.
3677+
*
3678+
* This is needed for backwards compatibility for button blocks specifically.
3679+
*
3680+
* @since 6.1.0
3681+
*
3682+
* @param array $editor_settings The array of editor settings.
3683+
* @return array A filtered array of editor settings.
3684+
*/
3685+
function wp_add_editor_classic_theme_styles( $editor_settings ) {
3686+
if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
3687+
return $editor_settings;
3688+
}
3689+
$suffix = wp_scripts_get_suffix();
3690+
$classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
3691+
3692+
// This follows the pattern of get_block_editor_theme_styles,
3693+
// but we can't use get_block_editor_theme_styles directly as it
3694+
// only handles external files or theme files.
3695+
$classic_theme_styles_settings = array(
3696+
'css' => file_get_contents( $classic_theme_styles ),
3697+
'__unstableType' => 'core',
3698+
'isGlobalStyles' => false,
3699+
);
3700+
3701+
// Add these settings to the start of the array so that themes can override them.
3702+
array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
3703+
3704+
return $editor_settings;
3705+
}

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.2-alpha-54686';
19+
$wp_version = '6.2-alpha-54687';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)