• Resolved ahmedmz

    (@ahmedmz)


    Hello
    WordPress don’t accept member registration with special characters in username.

    I used the following simple plugin to resolve this issue , it is OK but the issue that the maximum number of special characters is limited , member can use is 8 only.

    How can I increase it?
    thanks

    <?php
    
    /*
    
    Plugin Name: WordPress Special Characters in Usernames
    
    Plugin URI: https://www.oneall.com/
    
    Description: Enables usernames containing special characters (russian, cyrillic, arabic) on your WordPress Blog
    
    Version: 1.2
    
    Author: Claude Schlesser
    
    Author URI: https://www.oneall.com/
    
    License: GPL2
    
    */
    
    /**
    
     * Overrides the WordPress sanitize_user filter to allow special characters
    
     */
    
    function wscu_sanitize_user ($username, $raw_username, $strict)
    
    {
    
        //Strip HTML Tags
    
        $username = wp_strip_all_tags ($raw_username);
    
        //Remove Accents
    
        $username = remove_accents ($username);
    
        //Kill octets
    
        $username = preg_replace ('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
    
        //Kill entities
    
        $username = preg_replace ('/&.+?;/', '', $username);
    
        //If strict, reduce to ASCII, Cyrillic and Arabic characters for max portability.
    
        if ($strict)
    
        {
    
            //Read settings
    
            $settings = get_option ('wscu_settings');
    
            //Replace
    
            $username = preg_replace ('|[^a-z\p{Arabic}\p{Cyrillic}0-9 _.\-@]|iu', '', $username);
    
        }
    
        //Remove Whitespaces
    
        $username = trim ($username);
    
        // Consolidate contiguous Whitespaces
    
        $username = preg_replace ('|\s+|', ' ', $username);
    
        //Done
    
        return $username;
    
    }
    
    add_filter ('sanitize_user', 'wscu_sanitize_user', 10, 3);

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Wow! This is an odd one indeed. I had trouble tracking down the cause, but eventually found it ??

    The problem is how WP automatically creates a “nice name” from the supplied login name. When supplying a Cyrillic name, you end up with a nice name that is something like this: %d0%b9%d1%86%d0%ba%d0%b5%d0%bf%d0 (url encoded)

    It doesn’t take long for the length to exceed the maximum length of 50 characters. Long nice names are correctly trimmed to less than 50 original characters (why shorter names are OK), but the %xx format still exceeds the maximum url encoded length and breaks the user creation process.

    The solution is to hook the ‘pre_user_nicename’ filter and convert the %xx format back to the original UTF-8 characters with urldecode(). I’m not sure if doing so creates other adverse effects, but you can at least register the users.

    Thread Starter ahmedmz

    (@ahmedmz)

    ohh thanks brother ?? , appreciated your reply ,

    finally found person facing the Troublesome problem ?? .
    the plugin author also replied me now with the same solution ,i increased the value to 255 , and it’s OK now
    the issue was that it reads the Arabic and Russian usernames same as is the case with %d0%b9%d1%86%d0%ba%d0%b5%d0%bf%d0 !

    thanks dear ??
    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘increase number of special characters in member registration in WordPress’ is closed to new replies.