Created
November 11, 2021 15:20
-
-
Save DumahX/a2c9a8c93d34d423f25514f0b2459620 to your computer and use it in GitHub Desktop.
This file contains 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 | |
function mepr_validate_username($errors) { | |
$username = isset($_POST['user_login']) ? trim($_POST['user_login']) : ''; | |
$first_name = isset($_POST['user_first_name']) ? trim($_POST['user_first_name']) : ''; | |
$last_name = isset($_POST['user_last_name']) ? trim($_POST['user_last_name']) : ''; | |
// If username is empty, don't run any validations. | |
if(empty($username)) { | |
return $errors; | |
} | |
// Make sure username doesn't include an @ symbol. | |
if(strpos(strtolower($username), '@') !== false) { | |
$errors[] = 'Your username can\'t include an @.'; | |
} | |
// Make sure first name or last name isn't included in the username. | |
if(!empty($first_name) && strpos(strtolower($username), strtolower($first_name)) !== false) { | |
$errors[] = 'Your username can\'t include your first name.'; | |
} | |
if(!empty($last_name) && strpos(strtolower($username), strtolower($last_name)) !== false) { | |
$errors[] = 'Your username can\'t include your last name.'; | |
} | |
return $errors; | |
} | |
add_filter('mepr-validate-signup', 'mepr_validate_username'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment