Skip to content

Toolbar: Fix the display name live preview and "Howdy" color - #14275

Open
fushar wants to merge 1 commit into
WordPress:trunkfrom
fushar:howdy-fix-color
Open

fushar wants to merge 1 commit into
WordPress:trunkfrom
fushar:howdy-fix-color

Conversation

@fushar

@fushar fushar commented Oct 14, 2026 •

Copy link
Copy Markdown

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

Summary

This PR contains two follow-ups to moving "Howdy" into the user menu (#13681). The fixes are very closely related so I'm making both changes in this single PR.

  • "Howdy" color: I just found out that some custom plugins' admin color schemes only color #wp-admin-bar-user-info .display-name in their CSS, so the display name gets the scheme's color but the "Howdy, " text doesn't. This PR adds the display-name class to the greeting wrapper (<span class="display-name howdy">).

  • Display name live preview: when the display name dropdown is changed on the profile page, the admin bar is live-updated. This PR fixes the bugs mentioned in the linked Trac ticket, so that now:

    • The "Edit Profile" item is no longer overwritten.
    • The aria-label of the user menu is now updated with the new display name.
    • The username line now reacts to the change. For example, if the new display name is no longer the same as the username, the menu won't show the username line.

Testing

  1. Activate an admin color scheme that only colors .display-name in the CSS. The easiest way is to install the Admin Color Schemes plugin.
  2. Hover the avatar menu, and verify that the whole Howdy, {name} greeting has the same text color.
  3. Go to Users -> Profile, and change the "Display name publicly as" field. Don't save.
  4. Verify that the display name in the admin bar and in the dropdown is live-updated, and that "Edit Profile" stays the same.
  5. Select your username as the display name, and verify that the username line below the greeting disappears. Select another name, and verify that it appears again.
  6. Inspect the user menu (#wp-admin-bar-user-actions), and verify that its aria-label matches the selected display name.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 5.5
Used for: Code generation. Verified and tested by me.


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

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.

Adds the `display-name` class to the "Howdy" greeting in the user menu, the same way as the "Edit Profile" item, so that admin color schemes that only style `.display-name` color the whole greeting and not only the name.

Fixes the live preview of the display name on the profile screen, which overwrote the "Edit Profile" item, did not update the `aria-label` of the user menu, and did not show or hide the username line.
@fushar
fushar marked this pull request as ready for review October 14, 2026 13:53
@github-actions

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 fushar.

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

select = $( '#display_name' ),
username = $( '#user_login' ).val(),
myAccount = $( '#wp-admin-bar-my-account' ),
greeting = myAccount.find( '.display-name:not(.howdy):not(.edit-profile)' );

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note: I know that we discussed in the original PR that a better way is to add a test-only attribute or class to the actual display name span so that we can target it more cleanly.

But now I don't think it's worth it. This live-update is not the most common daily user flow. And it seems any additional class or markup change could theoretically break consumers 😅

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.

Well, this selector seems a bit smelly. Would have loved something cleaner like .howdy .display-name. Having to be so specific and exclusive here is a sign that we're doing something wrong.


$user_info = get_avatar( $user_id, 64 );
$user_info .= '<span class="howdy">' . $howdy . '</span>';
$user_info .= '<span class="display-name howdy">' . $howdy . '</span>';

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.

Are we now adding a .display-name inside .display-name? That seems unintentional.

select = $( '#display_name' ),
username = $( '#user_login' ).val(),
myAccount = $( '#wp-admin-bar-my-account' ),
greeting = myAccount.find( '.display-name:not(.howdy):not(.edit-profile)' );

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.

Well, this selector seems a bit smelly. Would have loved something cleaner like .howdy .display-name. Having to be so specific and exclusive here is a sign that we're doing something wrong.

usernameLine = howdy.siblings( '.username' );

greeting.text( display_name );
myAccount.children( '.ab-sub-wrapper' ).children( '[aria-label]' ).attr( 'aria-label', display_name );

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.

Might make sense improving our selection here a bit. If for some reason the aria-label attribute was removed, it won't match.

myAccount.children( '.ab-sub-wrapper' ).children( '[aria-label]' ).attr( 'aria-label', display_name );

// Only show the username when it differs from the display name.
if ( display_name === username ) {

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.

Theoretically, this can behave differently with the same comparison on the PHP side, where we are not trimming the display name.

if ( display_name === username ) {
usernameLine.remove();
} else if ( ! usernameLine.length && howdy.length ) {
$( '<span class="username"></span>' ).text( username ).insertAfter( howdy );

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.

Theoretically, if someone was removing the "howdy" (we already know some plugins are doing it), this wouldn't work and the username would just be removed.


var display_name = this.value.trim() || username;
var display_name = this.value.trim() || username,
howdy = myAccount.find( '#wp-admin-bar-user-info .howdy' ),

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.

Should we cache the howdy above with the other variables?

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.

2 participants