How to allow Non-Latin or Special characters in the registration form

In some cases, you may need to compromise WordPress native sanitization to allow users to use non-Latin or special characters usernames to make it more complex. Here are the essential code snippets to make it work on the site.

add_filter('sanitize_user', 'non_strict_mode_in_login_reg', 10, 3);
function non_strict_mode_in_login_reg( $username, $raw_username, $strict ) {

    if( !$strict )
        return $username;

    return sanitize_user(stripslashes($raw_username), false);
}

Note: You need to inject this snippet into your theme/child theme’s functions.php file. Else you can use a third-party plugin like “Code Snippets.”

Additionally, you can use the below snippets to allow the plus (+) symbol during the WPUF registration form.

/** Use below filter to allow plus symbol during registration **/

function allow_plus_sign($username, $raw_username, $strict) {
    $new_username = strip_tags($raw_username);
    // Kill octets
    $new_username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $new_username);
    $new_username = preg_replace('/&.?;/', '', $new_username); // Kill entities

   // If strict, reduce to ASCII for max portability.
   if ( $strict )
        $new_username = preg_replace('|[^a-z0-9 _.\[email protected]+]|i', '', $new_username);

    return $new_username;
}
add_filter( 'sanitize_user', 'allow_plus_sign', 10, 3);
add_action( 'wpuf_after_register', 'allow_plus_sign', 10, 3 );
MM Aurangajeb
MM Aurangajeb

Spreading Happiness. Support Engineer, WordPress Enthusiast, Blogger.

Articles: 18

Newsletter Updates

Enter your email address below to subscribe to our newsletter