Repository navigation
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
db9a951 to
cc6f785
Compare
|
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 Core Committers: Use this line as a base for the props when committing in SVN: 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)' ); |
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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>'; |
There was a problem hiding this comment.
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)' ); |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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 ); |
There was a problem hiding this comment.
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' ), |
There was a problem hiding this comment.
Should we cache the howdy above with the other variables?
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-namein their CSS, so the display name gets the scheme's color but the "Howdy, " text doesn't. This PR adds thedisplay-nameclass to the greeting wrapper (<span class="display-name howdy">).Edit Profilelink for the same reason (see https://core.trac.wordpress.org/changeset/57765).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:
aria-labelof the user menu is now updated with the new display name.Testing
.display-namein the CSS. The easiest way is to install theAdmin Color Schemesplugin.Howdy, {name}greeting has the same text color.#wp-admin-bar-user-actions), and verify that itsaria-labelmatches 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.