Skip to content

Toolbar color schemes on front end without global variable - #11354

Closed
sabernhardt wants to merge 12 commits into
WordPress:trunkfrom
sabernhardt:toolbar-sass-front-end
Closed

sabernhardt wants to merge 12 commits into
WordPress:trunkfrom
sabernhardt:toolbar-sass-front-end

Conversation

@sabernhardt

Copy link
Copy Markdown

Alternative option to #11267 that uses the same Sass and built stylesheets but avoids using the $_wp_admin_css_colors global variable.

  • Reverts the unit test to its original code.
  • Does not enqueue a stylesheet for the Fresh color scheme.
  • Enqueues an external stylesheet for the other 8 core schemes on the front end.
  • Does not attempt to support plugins' color schemes on the front.

Trac 64762

Use of AI Tools

@johnbillion shared these details:

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.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Mar 25, 2026 •

Copy link
Copy Markdown

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, sabernhardt, westonruter, wildworks, softglaze, fushar.

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.

Comment on lines +1461 to 1463
if ( ! $admin_bar_url ) {
return;
}

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.

Is this here in case someone filters admin_url to return an empty string for some reason?

#wpadminbar:not(.mobile) .ab-top-menu > #wp-admin-bar-recovery-mode > .ab-item:focus {
color: variables.$adminbar-recovery-exit-text;
background-color: variables.$adminbar-recovery-exit-background-alt;
}

@westonruter westonruter Apr 30, 2026 •

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.

The recovery mode CSS is removed here but isn't added to src/wp-admin/css/colors/_admin-bar.scss. Is that intentional?

(Props Claude.)


global $_wp_admin_css_colors;
$color_scheme = get_user_option( 'admin_color' );
$core_list = array( 'modern', 'light', 'blue', 'coffee', 'ectoplasm', 'midnight', 'ocean', 'sunrise' );

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.

Suggested change
$core_list = array( 'modern', 'light', 'blue', 'coffee', 'ectoplasm', 'midnight', 'ocean', 'sunrise' );
/** Refer to {@see register_admin_color_schemes()} for this list, omitting 'fresh'. */
$core_list = array( 'modern', 'light', 'blue', 'coffee', 'ectoplasm', 'midnight', 'ocean', 'sunrise' );

@@ -0,0 +1,140 @@
@forward 'variables' show $scheme-name, $base-color, $body-background, $button-color, $custom-welcome-panel, $dashboard-accent-1, $dashboard-accent-2, $dashboard-icon-background, $form-checked, $highlight-color, $icon-color, $link, $link-focus, $low-contrast-theme, $menu-bubble-text, $menu-collapse-focus-icon, $menu-collapse-text, $menu-highlight-background, $menu-highlight-icon, $menu-highlight-text, $menu-submenu-text, $menu-submenu-focus-text, $menu-submenu-background, $notification-color, $text-color;

@westonruter westonruter Apr 30, 2026 •

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.

According to Claude, this list is overly broad. It can be reduced to be more truthful about what is being used.

Suggested change
@forward 'variables' show $scheme-name, $base-color, $body-background, $button-color, $custom-welcome-panel, $dashboard-accent-1, $dashboard-accent-2, $dashboard-icon-background, $form-checked, $highlight-color, $icon-color, $link, $link-focus, $low-contrast-theme, $menu-bubble-text, $menu-collapse-focus-icon, $menu-collapse-text, $menu-highlight-background, $menu-highlight-icon, $menu-highlight-text, $menu-submenu-text, $menu-submenu-focus-text, $menu-submenu-background, $notification-color, $text-color;
@forward 'variables' show $base-color, $icon-color, $highlight-color, $text-color, $menu-submenu-text, $menu-submenu-focus-text, $menu-submenu-background;

(Props Claude.)

Comment on lines +25 to +24
if ( is_admin() ) {
$this->assertFalse( wp_style_loader_src( '', 'colors' ) );
} else {
$this->assertStringContainsString( '/colors.css', wp_style_loader_src( '', 'colors' ) );
}
$this->assertFalse( wp_style_loader_src( '', 'colors' ) );

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.

Ideally there'd be two tests, one which sets the global state so that is_admin() returns true and another test where is_admin() is false. This would ensure the code in wp_admin_bar_add_color_scheme_to_front_end() is actually tested.

Comment on lines +98 to +106
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: variables.$menu-submenu-focus-text;
}

#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: variables.$menu-icon;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: variables.$menu-submenu-focus-text;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: variables.$menu-icon;
}
#wpadminbar.mobile .quicklinks .hover .ab-icon:before,
#wpadminbar.mobile .quicklinks .hover .ab-item:before {
color: variables.$menu-submenu-focus-text;
}
#wpadminbar.mobile .quicklinks .ab-icon:before,
#wpadminbar.mobile .quicklinks .ab-item:before {
color: variables.$menu-icon;
}

See #11665

@softglazee

Copy link
Copy Markdown

I have tested this branch locally at commit 794875760a. Here is the detailed breakdown of the behavior:

  • Core Schemes: Modern, Light, Blue, Coffee, Ectoplasm, Midnight, Ocean, and Sunrise all correctly enqueue their respective colors/{scheme}/admin-bar.css on the front end. Fresh enqueues no stylesheet, as expected.
  • Production Path (SCRIPT_DEBUG off): The Grunt task successfully builds both variants. When SCRIPT_DEBUG is false, the source correctly requests admin-bar.min.css, which returns a 200 OK (4.2 kB transferred).
  • Plugin Schemes (Fallback Behavior): I tested this against the "Grey Admin Color Schemes" plugin. For plugin-registered schemes, no stylesheet is enqueued on the front end, and the toolbar safely falls back to the default dark style without any breakage. Core schemes remain unaffected and continue to work while the plugin is active.
  • Site Editor: The function correctly returns early on is_admin(), so the stylesheet is not loaded in site-editor.php.

Full test report and screenshots have been posted on Trac #64762.

@fushar

fushar commented Sep 24, 2026

Copy link
Copy Markdown

Let's get this to the finish line for 7.2! @sabernhardt, would you like to continue working on this? I have spare bandwidth to help if not.

@t-hamano

Copy link
Copy Markdown
Contributor

@fushar, if you have the bandwidth, please feel free to go ahead with this. We only have a month left until 7.2 Beta 1, which might seem like a long time, but it really isn't much time at all 😄

@fushar

fushar commented Sep 29, 2026

Copy link
Copy Markdown

Since I can't push to the fork, I opened a new PR instead. Rebased and continued the improvements here: #13806

@t-hamano

Copy link
Copy Markdown
Contributor

Closing this in favor of #13806

@t-hamano t-hamano closed this Sep 29, 2026
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