Search code examples
wordpressutf-8registrationbuddypresstr

Wordpress Registry Error: Usernames can only contain letters, numbers, - and @


I used wordpress, buddpress plugin for user account. But an error occurs with the username during registration:

Usernames can only contain letters, numbers, - and @.

For example: Rustu (OK) / Rüştü (Not OK)

May be add a filter for Turkish characters (utf-8), to be able to use 'I ğ ü' etc in the username...


Solution

  • Add this piece of code in your theme's functions.php or you can use this in a plugin if you want. This will enable users to register using non-ansi characters.

    add_filter( 'sanitize_user', 'sanitize_user_username', 3, 3);
    
    function sanitize_user_username($username, $raw_username, $strict) {
        $username = $raw_username;
        $username = strip_tags($username);
        $username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
        $username = preg_replace('/&.+?;/', '', $username);
    
        if ( $strict )
            $username = preg_replace('|[^a-z0-9 _.\-@\x80-\xFF]|i', '', $username);
        $username = preg_replace('|\s+|', ' ', $username);
    
        return $username;
    }