Skip to content

Instantly share code, notes, and snippets.

@DumahX
Created November 11, 2021 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DumahX/a2c9a8c93d34d423f25514f0b2459620 to your computer and use it in GitHub Desktop.
Save DumahX/a2c9a8c93d34d423f25514f0b2459620 to your computer and use it in GitHub Desktop.
<?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