Make WordPress Core

Opened 7 weeks ago

Closed 4 weeks ago

Last modified 3 weeks ago

#66222 closed defect (bug) (fixed)

Toolbar: live-preview of unsaved display name change is not accurate

Reported by: fushar Owned by: mcsf
Priority: normal Milestone: 7.2
Component: Toolbar Version: 6.5
Severity: normal Keywords: has-patch has-screenshots
Cc: Focuses: accessibility, javascript

Description

On wp-admin/profile.php, whenever we update the display name, the my-account node and its dropdown is supposed to be live-previewed. However, there are a few bugs:

  1. The Edit Profile item also gets overwritten with the display name.
  2. The account submenu's aria-label is not updated with the new display name.
  3. The username line doesn't respond to the change. For example, if the new display name is no longer the same as the username, the dropdown does not show the username.

Attachments (4)

Screenshot 2026-10-01 at 10.28.39.png​ (122.7 KB ) - added by fushar 7 weeks ago.
screenshot of the broken live preview
01 howdy menu states.png​ (68.5 KB ) - added by afercia 7 weeks ago.
t66222_trunk_S1_live.png​ (9.1 KB ) - added by therssoftware 6 weeks ago.
t66222_pr_S1_live.png​ (10.7 KB ) - added by therssoftware 6 weeks ago.

Download all attachments as: .zip

Change History (14)

This ticket was mentioned in ​PR #13881 on ​WordPress/wordpress-develop by ​@hbhalodia.


7 weeks ago
#1

  • Keywords has-patch added

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

What

Fixes the toolbar account menu not updating correctly when you change the display name on wp-admin/profile.php, before saving.

Why

The live preview used one broad .display-name selector, which caused three bugs:

  1. "Edit Profile" in the dropdown was replaced with the display name.
  2. The submenu's aria-label still showed the old name.
  3. The username line didn't show or hide when the display name changed.

How

  • Target the "Howdy" greeting and the dropdown name separately, skipping .edit-profile.
  • Update the aria-label on #wp-admin-bar-user-actions using the same translatable Howdy, %s string.
  • Show the username line only when it differs from the display name, as the PHP output does.

Testing

  1. Log in as a user whose display name matches their username (e.g. admin).
  2. Go to Users → Profile, enter a First Name, and select it in Display name publicly as. Don't save.
  3. Hover over the account menu in the toolbar and check that:
    • "Edit Profile" is still shown.
    • The username appears below the new display name.
    • ul#wp-admin-bar-user-actions has aria-label="Howdy, <new name>".
  4. Switch the display name back to the username. The username line should go away.
  5. Edit another user's profile (user-edit.php). The toolbar should not change.

Use of AI Tools

  • Claude Code, Opus 5.5
  • Used for PR description, reproduction steps, and implementation.
  • It was reviwed by me.

#2 @afercia
7 weeks ago

  • Keywords has-screenshots added

Good catch. I took the liberty to prepare another screenshot to better explain the inconsistencies (there may be more flows that trigger more ones though). See screenshot below:

  1. Initial state, with 'Display name publicly as' set to 'admin'.
  2. 'Display name publicly as' changed to first and last name, live preview.
  3. After saving and page reload.

#3 @therssoftware
6 weeks ago

Test Report

Description

This report validates that the indicated patch works as expected.

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/13881 (head 6bc7e75)

Environment

  • WordPress: 7.2-alpha-63166-src (trunk f4350cd9e2; user-profile.js, admin-bar.php and class-wp-admin-bar.php are unchanged on the current trunk dcd149a95c)
  • PHP: 8.3.33
  • Server: nginx (macOS, arm64)
  • Database: MySQL 9.2.0
  • Browser: Chromium (Playwright, headless), SCRIPT_DEBUG enabled
  • Theme: Twenty Twenty-Five 1.5
  • Plugins: none

Steps taken

  1. Created an administrator tester66222 with first name Jane, last name Doe, nickname JD, display name tester66222 (same as the login).
  2. On wp-admin/profile.php, changed "Display name publicly as" and recorded the toolbar before saving (live preview): the "Howdy" name, the name in the dropdown, the username line, the "Edit Profile" label, the aria-label of #wp-admin-bar-user-actions, and the order of the spans.
  3. Clicked Update Profile and recorded the same values from the server-rendered toolbar after the reload.
  4. Compared live vs. saved for each scenario, on trunk and then with the PR applied.

Scenarios:

# Change What it checks
S1 login → Jane Doe username line must be added
S2 Jane Doe → JD username line kept
S3 JD → login username line must be removed
S4 Jane → login → Doe Jane before saving remove, then re-add, in one session
S5 Doe Jane → login removal again
S6 type first name Tom & Jerry, pick it option created live, special characters
S7 on user-edit.php?user_id=1, pick another name (not saved) another user's profile must not change the toolbar

Actual Results

Trunk: ❌ bug reproduced (S1–S6 fail, S7 passes)

  • The "Edit Profile" label in the dropdown is replaced with the display name. Trunk's .find( '.display-name' ) also matches <span class="display-name edit-profile">.
  • The username line is never added or removed, so the dropdown keeps the old state until reload.
  • The aria-label of the account menu (Howdy, …) keeps the old name.

Example (S1, login → Jane Doe):

Field Live preview (trunk) After save
Dropdown lines Jane Doe / Jane Doe Jane Doe / tester66222 / Edit Profile
Username line missing tester66222
"Edit Profile" label Jane Doe Edit Profile
Menu aria-label Howdy, tester66222 Howdy, Jane Doe


With PR #13881: ✅ all scenarios pass

  • In S1–S6 the live preview matches the saved toolbar for every field: greeting, dropdown name, username line (added, kept, removed, and re-added in the right position), "Edit Profile" label, and menu aria-label.
  • S7: editing another user's profile does not change the toolbar.
  • No JavaScript errors from the patched code.


Additional Notes

  • The new __( 'Howdy, %s' ) in JS is the same string as the server-side greeting, and user-profile already calls set_translations(). Translated sites should therefore get a matching label.
  • The username check mirrors the server's display_name !== user_login comparison in wp_admin_bar_my_account_menu().
  • One trunk run hit an intermittent Cannot read properties of undefined (reading 'serialize') from the existing unsaved-changes handler (user-profile.js, $form.serialize()) while the browser was closing. It didn't happen on re-runs and is in code this PR doesn't touch.
  • I didn't test the case afercia mentioned where other flows may cause more mismatches, beyond the 7 scenarios above. If there are specific flows in mind, I'm happy to test them.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Used for: Writing the Playwright script that compares the live and saved toolbar, running it, and drafting this report. I reviewed the results and screenshots.

Last edited 6 weeks ago by therssoftware (previous) (diff)

This ticket was mentioned in ​PR #14275 on ​WordPress/wordpress-develop by ​@fushar.


5 weeks ago
#4

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

Summary

This PR contains two follow-ups to moving "Howdy" into the user menu (​https://github.com/WordPress/wordpress-develop/pull/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.

#5 @mcsf
4 weeks ago

  • Owner set to mcsf
  • Resolution → fixed
  • Status new → closed

In 64502:

Toolbar: Fix display name live preview and "Howdy" color

When the selected display name is changed on the profile page, correctly update the user menu in the admin bar: don't overwrite the "Edit Profile" item, do update the aria-label attribute, and of course update the rendered username.

Add class display-name to the greeting wrapper to better preserve back-compat with custom admin color schemes that only target #wp-admin-bar-user-info .display-name.

Props fushar, tyxla.

Fixes #66222.

#6 @mcsf
4 weeks ago

In 64504:

Toolbar: Undo partial changes to user menu

Reverts r64502, which was missing some files for some reason.

Follow-up to r64502.

See #66222.

#7 @mcsf
4 weeks ago

In 64519:

Toolbar: Fix display name live preview and "Howdy" color.

When the display name is changed on the profile page, correctly update the user menu in the admin bar: don't overwrite the "Edit Profile" item, do update the aria-label attribute, and of course update the rendered username.

Add class display-name to the greeting wrapper to better preserve back-compat with custom admin color schemes that only target #wp-admin-bar-user-info .display-name.

Follow-up to r64502 and its revert, r64504.

Props fushar, tyxla.

Fixes #66222.

#8 follow-up: @hbhalodia
4 weeks ago

Hi @mcsf, Sorry but I guess you might have missed some props giving here to @therssoftware for testing the PRs that were attached to the ticket. Also to the PR authors :)

Thanks,

#9 in reply to: ↑ 8 @mcsf
4 weeks ago

Replying to hbhalodia:

Hi @mcsf, Sorry but I guess you might have missed some props giving here to @therssoftware for testing the PRs that were attached to the ticket

I'll be very honest: I seriously question the props-worthiness of these automated and verbose "test reports".

Also to the PR authors :)

The changeset is based on ​https://github.com/WordPress/wordpress-develop/pull/14275, for which the author and reviewer were indeed attributed. Though I appreciate your willingness to contribute, ​https://github.com/WordPress/wordpress-develop/pull/13881 didn't materialise into a patch with reviewer validation, and so props may or may not be due.


That said, I do concede that it's easy to miss props in our hybrid Trac-GitHub setup. @desrosj, do you know if there's ever been a discussion about making the GitHub props bot also consider participants in the original Trac ticket?

#10 @sabernhardt
3 weeks ago

  • Milestone Awaiting Review → 7.2
Note: See TracTickets for help on using tickets.