Forked from dparker1005/my_pmpro_registration_checks_no_email_in_username.php
Last active
March 31, 2023 01:52
-
-
Save kimwhite/c5ece54b3b382a56544e202f00e1ddd7 to your computer and use it in GitHub Desktop.
Do not allow users to use an email as their username
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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