<?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.