Repository navigation
Don't require an email for guest authors in the Add New User form validation - #193
Merged
roborourke merged 2 commits intoOct 23, 2026
Merged
Conversation
…idation The Add New User form is validated client-side, which rejects an empty email before the server-side guest author handling is reached. Drop the requirement from the email row while the guest author role is selected.
roborourke
requested changes
Oct 23, 2026
roborourke
left a comment
Contributor
There was a problem hiding this comment.
Good catch, can you remove the jQuery dependency though. In general core is removing it and its use has been deprecated for a while.
Core is moving away from jQuery, so the script now uses plain DOM APIs. It checks document.readyState before waiting for DOMContentLoaded, like @wordpress/dom-ready, so it still runs if the script is deferred or delayed past that event. wp-ajax-response, which validates the form, still depends on jQuery in core.
Contributor
Author
|
jQuery removal will not happen anytime soon IMHO but agreed on the direction :) I removed any jQuery dependency from the script. It's jQuery free now. |
roborourke
approved these changes
Oct 23, 2026
Merged
Contributor
Author
|
Thanks @roborourke ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#138 made the email optional for guest authors, but only server-side. With JavaScript enabled, the Add New User form (
#createuser, classvalidate) is validated bywp-ajax-response.js, which blocks the submission when a.form-requiredfield is empty. So adding a guest author without an email only works with JavaScript disabled.This adds a small inline script to
wp-ajax-responseonuser-new.phponly. While the guest author role is selected, it removesform-requiredfrom the email row and hides its "(required)" label, and restores both when another role is selected. The server-side validation from #138 still applies.The password doesn't need the same treatment, as core prefills it when JavaScript is enabled.
Tested by running core's
wp-ajax-response.jsagainst a copy of the form in jsdom: an empty email still blocks other roles, and no longer blocks guest authors. PHPUnit tests check that the script is only added on the Add New User screen.