Skip to content

#64762 Use sass to generate admin toolbar colours#11267

Open
johnbillion wants to merge 2 commits intoWordPress:trunkfrom
johnbillion:64762-sass-colours
Open

#64762 Use sass to generate admin toolbar colours#11267
johnbillion wants to merge 2 commits intoWordPress:trunkfrom
johnbillion:64762-sass-colours

Conversation

@johnbillion
Copy link
Copy Markdown
Member

@johnbillion johnbillion commented Mar 16, 2026

This extracts the admin toolbar styles into a mixin so a standalone admin-bar.css file can be generated for each colour scheme. Facilitates custom colour schemes registering their own admin toolbar CSS file too.

Trac ticket: https://core.trac.wordpress.org/ticket/64762

Use of AI Tools

Claude Code was used to initialise the separate admin bar color Sass files for each colour scheme. Worked ok-ish, I subsequently manually adjusted a lot of it.

Screenshots

combined

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props johnbillion, mukesh27, huzaifaalmesbah, sabernhardt, westonruter, audrasjb.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Copy Markdown
Member

@huzaifaalmesbah huzaifaalmesbah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

trac-64762-pr-11267.mp4

Copy link
Copy Markdown

@sabernhardt sabernhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ✅ The Fresh scheme does not have a separate stylesheet.
  • ✅ The other 8 Core schemes properly fetch their small, external stylesheet on the front end.
  • ✅ Plugins such as Contextual Adminbar Color and Dark Mode Toggle continue to show their colors because they set colors without wp_admin_css_color(). The admin-bar-color-scheme-css stylesheet can be enqueued unnecessarily, but the plugins' CSS would override that.
  • The new Sass partial removes #wp-admin-bar-recovery-mode styles. Is that intentional?
  • 😢 I have trouble trying to add a new stylesheet with wp_admin_css_color() in plugins such as bbPress. The front end continues to enqueue the Modern stylesheet instead of the plugin's stylesheet.
// Mint
wp_admin_css_color(
	'bbp-mint',
	esc_html_x( 'Mint', 'admin color scheme', 'bbpress' ),
	$this->styles_url . 'mint/colors' . $suffix . '.css',
	array( '#4f6d59', '#33834e', '#5FB37C', '#81c498' ),
	array( 'base' => '#f1f3f2', 'focus' => '#fff', 'current' => '#fff' ),
	$this->styles_url . 'mint/admin-bar.css' // trimmed copy of colors.css in the same directory
);

Unless I just made a silly mistake editing the plugin, the toolbar function might check the $_wp_admin_css_colors global variable too early, before the plugin modifies it. I started another PR draft—using this Sass—to investigate a way to support the core schemes without reading or changing the global variable (though I have not tested it with plugins yet). That PR also restores the unit test to its original code.

@westonruter westonruter requested a review from karmatosed March 23, 2026 10:36
Comment on lines +1474 to +1475
array( 'admin-bar' ),
false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: false is the default value for the $ver param.

Suggested change
array( 'admin-bar' ),
false
array( 'admin-bar' )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a habit due to WPSC enforcing an explicit value for $in_footer 😄

Comment on lines +4869 to +4870
* @param string|false $admin_bar_url Optional. The URL of the CSS file containing admin bar color
* overrides for use on the front end. Default false.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this introduced, the params are no longer aligned. If that is intended to be maintained, like so:

 * @param string       $key           The unique key for this theme.
 * @param string       $name          The name of the theme.
 * @param string       $url           The URL of the CSS file containing the color scheme.
 * @param array        $colors        Optional. An array of CSS color definition strings which are used
 *                                    to give the user a feel for the theme.
 * @param array        $icons {
 *     Optional. CSS color definitions used to color any SVG icons.
 *
 *     @type string $base    SVG icon base color.
 *     @type string $focus   SVG icon color on focus.
 *     @type string $current SVG icon color of current admin menu link.
 * }
 * @param string|false $admin_bar_url Optional. The URL of the CSS file containing admin bar color
 *                                    overrides for use on the front end. Default false.

Then:

diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index b16caf989d..70e186144c 100644
--- a/src/wp-includes/general-template.php
+++ b/src/wp-includes/general-template.php
@@ -4854,12 +4854,12 @@ function paginate_links( $args = '' ) {
  *
  * @global array $_wp_admin_css_colors
  *
- * @param string $key    The unique key for this theme.
- * @param string $name   The name of the theme.
- * @param string $url    The URL of the CSS file containing the color scheme.
- * @param array  $colors Optional. An array of CSS color definition strings which are used
- *                       to give the user a feel for the theme.
- * @param array  $icons {
+ * @param string       $key           The unique key for this theme.
+ * @param string       $name          The name of the theme.
+ * @param string       $url           The URL of the CSS file containing the color scheme.
+ * @param array        $colors        Optional. An array of CSS color definition strings which are used
+ *                                    to give the user a feel for the theme.
+ * @param array        $icons {
  *     Optional. CSS color definitions used to color any SVG icons.
  *
  *     @type string $base    SVG icon base color.

@audrasjb
Copy link
Copy Markdown
Contributor

Thanks for putting together this PR @johnbillion! It looks fairly better than the current implementation.
I tested the PR on my side, and admin bar styles are correctly implemented on front end when we switch admin color schemes.

@sabernhardt
Copy link
Copy Markdown

sabernhardt commented Mar 25, 2026

I was having trouble with the registered schemes for bbPress and Grey Admin Color Schemes mainly because both plugins use wp_admin_css_color() within the admin_init hook.

  • Switching the hook to init works for me on the front and back with Grey Admin Color Schemes and adding the fifth and sixth arguments.
    wp_admin_css_color( 'postmodern', __('Post Modern Grey', 'grey-admin-color-schemes'), plugins_url("postmodern/colors$rtl.css", __FILE__ ), array( '#464646', '#6D6D6D', '#D6D6D6', '#F1F1F1' ), array(), plugins_url("postmodern/admin-bar.css", __FILE__ ) );
  • bbPress would need more editing, and I have not solved that on the front.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants