Skip to content

Don't require an email for guest authors in the Add New User form validation - #193

Merged
roborourke merged 2 commits into
humanmade:developfrom
nlemoine:fix-guest-email-js-validation
Oct 23, 2026
Merged

roborourke merged 2 commits into
humanmade:developfrom
nlemoine:fix-guest-email-js-validation

Conversation

@nlemoine

Copy link
Copy Markdown
Contributor

#138 made the email optional for guest authors, but only server-side. With JavaScript enabled, the Add New User form (#createuser, class validate) is validated by wp-ajax-response.js, which blocks the submission when a .form-required field is empty. So adding a guest author without an email only works with JavaScript disabled.

This adds a small inline script to wp-ajax-response on user-new.php only. While the guest author role is selected, it removes form-required from 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.js against 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.

…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 roborourke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.
@nlemoine

nlemoine commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

jQuery removal will not happen anytime soon IMHO but agreed on the direction :) wp-ajax-response.js requires it.

I removed any jQuery dependency from the script. It's jQuery free now.

@roborourke
roborourke merged commit 86829e5 into humanmade:develop Oct 23, 2026
10 checks passed
@roborourke roborourke mentioned this pull request Oct 23, 2026
@nlemoine

Copy link
Copy Markdown
Contributor Author

Thanks @roborourke !

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