Skip to content

#17793 - Name the allowed characters in the invalid username error - #13532

Open
skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/17793-invalid-username-message
Open

skikken wants to merge 2 commits into
WordPress:trunkfrom
skikken:fix/17793-invalid-username-message

Conversation

@skikken

@skikken skikken commented Sep 15, 2026

Copy link
Copy Markdown

When a username is rejected for containing disallowed characters, the error only said the username was invalid and asked for "a valid username". That does not tell the person registering which characters are actually accepted, so the message did not help them correct the problem.

The message now names the allowed characters. This matches what multisite already reports through wpmu_validate_user_signup() ("Usernames can only contain lowercase letters (a-z) and numbers."), so single site registration was the outlier rather than this being a new direction.

The string appears in three places and all three were updated: register_new_user(), edit_user() in wp-admin, and the users REST controller. The REST copy is the same message without the "Error:" prefix, since REST errors are not rendered as admin notices.

A username can also contain a space or an @, because both survive sanitize_user(). Listing those was raised on the ticket and deliberately left out: the recommendation there was to avoid encouraging them, and advertising them as valid would need sanitize_user() tightened first, which is a much larger change than this ticket.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet
Used for: test cases, code review


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.

The error shown when a username contains disallowed characters only
asked for "a valid username" without saying what is valid. Multisite
already names the allowed characters in wpmu_validate_user_signup(),
so single site was the outlier.

Update the message in register_new_user(), edit_user(), and the REST
users controller. The REST copy deliberately keeps no HTML prefix,
since REST error messages are plain text.

Refs #17793
The REST users controller test pinned the old string with assertSame(),
so it needed updating. Add coverage for the registration path, for an
accented username and for a disallowed symbol.

Refs #17793
@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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @skikken.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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.

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.

1 participant