<?php /** * WordPress register with email only, make it possible to register with email * as username in a multisite installation * @param Array $result Result array of the wpmu_validate_user_signup-function * @return Array Altered result array */ function custom_register_with_email($result) { if ( $result['user_name'] != '' && is_email( $result['user_name'] ) ) { unset( $result['errors']->errors['user_name'] ); } return $result; } add_filter('wpmu_validate_user_signup','custom_register_with_email'); ?>
The snippets story
Some days ago I’ve implemented a custom user registration with WordPress. I used Gravity Forms with the User Registration add-on, which worked fine when the user had to choose an username manually. But we wanted even a quick-registration option on the startsite, which we wanted to work with only one form-field asking for an email-address. So I built a Gravity Form with just a email field and added a User Registration with the email-field linked both as the required users email and username.
Works fine with a single install, but with a multi-site installation the wpmu_validate_user_signup-function is used and we got an “Only lowercase letters (a-z) and numbers are allowed.” error-message. The above filter fixes this issue by undoing this validation error and forcing WordPress to accept an email address as username.
Thank you for this! It was driving me nuts.
Hi, This is exactly what I need, but what file do I add this code to? Very new at this stuff. Thanks, Sherry
Hi Sherry,
this goes to your themes functions.php file.
Good luck
Daniel
Great fix… worked like a champ.
Thank you thank you thank you!!!! Worked like a charm!!!
Thanks for posting this — really helped!
Has WP 4 changed something fundamental. I was using this snippet in my functions.php and everything worked just fine and dandy.
Yup. Something changed in 4.0. The errors array in WP_Error is now private. See https://core.trac.wordpress.org/changeset/28511
In version 4.1 a new method remove() will be added which should do the trick.
Willem
How would one use the new method? Now that 4.1 is out, I’d like to get this working.
Thanks.
Could you elaborate on how to use that now that 4.1 is out? I’m lost on how to utilize that new method.
Thanks for putting this together. So amazingly simple when you know how 🙂
Couple of quick questions / clarification:
1. Does this work with the current version of WP (4.1.1) then?
2. Does this only work for multiuser or for single install too?
3. Do you have a demo of the registration page?
All the best.
Marc
Is there any news about how to solve the problem “only lower case letter” in WordPress 4.1 Multi site and Gravity forms?? This snippet don’t work now.
Excellent code, I have been searching online for a solution since 2 days, and I dont want to install a plugin to do this, again thank you for the code.
This can be fixed in 4.x with
$result['errors']->remove('user_name');
instead of the unset.My bows sir!
Thanks a lot!
3 years after the post … this was a life saver! Thank you!
Put it in my functions.php but users are not created using my form.
That was another issue, solved it. Working as expected, thanks!
Thanks for sharing very useful information.
I am not using gravity forms. I have default WordPress registration process. How can i achieve the same result.
Let me know.
Thanks
That was SUPER helpful! And from a post 5 years old, I didn’t expect to find a multisite-specific answer! Well done.
THANK YOU!
In 2020 you saved my life from the past 🙂