WordPress User Registration Without Username Requirement
We’ve had a number of requests from our customers asking if it’s possible to create a WordPress registration form where users can register without a username. Technically, this is impossible because WordPress requires all users to have a username.
In this tutorial, I will be showing us a fool-proof way on how to create a user registration form without a username field that just works.
Building the Registration Form
* Open up the edit screen of the ProfilePress registration form you are using by clicking on its title in the WordPress backend.
* Remove the username block or shortcode (if you are using the advanced form builder).
* Go to the form settings and check the Disable Username Requirement checkbox.
With the above steps done, users signing up via the registration form will automatically have a username generated for them from their email address.
For example, say a user registered with [email protected]
, johndoe
automatically becomes his username. And if the username already exists, it becomes “johndoe1”.
Modifying Registration Errors
Note: all code snippet in this post should go into your theme’s functions.php
file or a site-specific plugin.
Below are the username generated error messages of a WordPress registration form.
- Username may not be longer than 60 characters.
- Sorry, that username already exists!
- Sorry, that username is not allowed.
The code below replaces “username” in these error messages with “email address”.
add_filter( 'gettext', 'change_registration_username_errors', 10, 3 );
function change_registration_username_errors( $translations, $text, $domain ) {
if ( $domain == 'default' ) {
if ( $text == 'Username may not be longer than 60 characters.' ) {
$translations = 'Email address may not be longer than 60 characters.';
} elseif ( $text == 'Sorry, that username already exists!' ) {
$translations = 'Sorry, that email address already exists!';
} elseif ( $text == 'Sorry, that username is not allowed.' ) {
$translations = 'Sorry, that email address is not allowed.';
}
}
return $translations;
}
Modifying Login Errors
We should be done by now, but we still need to modify username generated errors in the WordPress login form to make it fool-proof.
The code below does that excellently well.
add_filter( 'gettext', 'change_login_username_errors', 10, 3 );
function change_login_username_errors( $translations, $text, $domain ) {
if ( $domain == 'default' ) {
if ( $text == '<strong>ERROR</strong>: Invalid username.' ) {
$translations = '<strong>ERROR</strong>: Invalid email.';
} elseif ( $text == '<strong>ERROR</strong>: The password you entered for the username %s is incorrect.' ) {
$translations = '<strong>ERROR</strong>: The password you entered for the email address %s is incorrect.';
} elseif ( $text == '<strong>ERROR</strong>: The username field is empty.' ) {
$translations = '<strong>ERROR</strong>: The email field is empty.';
} elseif ( $text == '<strong>ERROR</strong>: Invalid username or incorrect password.' ) {
$translations = '<strong>ERROR</strong>: Invalid email address or incorrect password.';
}
}
return $translations;
}
Conclusion
We hope we’ve been able to teach you how to build a WordPress (custom) registration form where users can sign up without asking for their username.