Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active June 16, 2024 09:29
Show Gist options
  • Save KaineLabs/3ecbb316fb9f412e4f7b91bc165af05d to your computer and use it in GitHub Desktop.
Save KaineLabs/3ecbb316fb9f412e4f7b91bc165af05d to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Validate Username with Latin 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