Last active
June 16, 2024 09:29
-
-
Save KaineLabs/3ecbb316fb9f412e4f7b91bc165af05d to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Validate Username with Latin Characters
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 to validate username with Latin characters | |
function yzc_custom_validate_username($valid, $username) { | |
// Allow Latin characters and numbers | |
if (preg_match('/^[a-zA-Z0-9ñÑáéíóúÁÉÍÓÚüÜ]*$/', $username)) { | |
return true; | |
} | |
return $valid; | |
} | |
// Hook the custom validation function | |
add_filter('validate_username', 'yzc_custom_validate_username', 10, 2); | |
add_filter('sanitize_user', 'non_strict_login', 10, 3); | |
function non_strict_login( $username, $raw_username, $strict ) { | |
if( !$strict ) | |
return $username; | |
return sanitize_user(stripslashes($raw_username), false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment