Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/c5ece54b3b382a56544e202f00e1ddd7 to your computer and use it in GitHub Desktop.
Save kimwhite/c5ece54b3b382a56544e202f00e1ddd7 to your computer and use it in GitHub Desktop.
Do not allow users to use an email as their username
<?php // do not copy this line.
/**
* This recipe does will check to to make sure an email address is not used for the username.
* Please be aware this is a "use-at-own-risk" option.
* If assistance with the implementation or further customizations is required you
* may reach out to a local WordPress developer
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/*
* Do not allow users to use an email as their username
*/
function my_pmpro_registration_checks_no_email_in_username($okay)
{
if(!$okay)
return $okay; //there are other errors to handle
global $pmpro_msg, $pmpro_msgt;
$username = $_REQUEST['username'];
//make sure they entered any birthday
if( ! empty($username) && strpos( $username, '@') !== false )
{
$pmpro_msg = "You cannot use an email address as your username.";
$pmpro_msgt = "pmpro_error";
return false;
}
return $okay;
}
add_filter("pmpro_registration_checks", "my_pmpro_registration_checks_no_email_in_username");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment