Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travislima/ac1d81cde09eca7f201223cc0a7c0877 to your computer and use it in GitHub Desktop.
Save travislima/ac1d81cde09eca7f201223cc0a7c0877 to your computer and use it in GitHub Desktop.
Stop users from setting their username to an email address with Paid Memberships Pro
/*
Stop users from setting their username to an email address
Add this code to a custom plugin.
*/
function pmpro_registration_checks_no_email_user_login($continue) {
//if there are earlier problems, don't bother checking
if(!$continue)
return;
//make sure the username passed in doesn't look like an email address (contains a @)
global $username;
if(!empty($username) && strpos($username, "@") !== false) {
$continue = false;
pmpro_setMessage( 'Your username must not be an email address', 'pmpro_error' );
}
return $continue;
}
add_filter('pmpro_registration_checks', 'pmpro_registration_checks_no_email_user_login');
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Prevent users from using an email address as their username." at Paid Memberships Pro here: https://www.paidmembershipspro.com/prevent-users-from-using-an-email-address-as-username/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment