Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter bryceholland

    (@bryceholland)

    Hi There, Happy New Year! Any update on this thread? Thanks!

    Thread Starter bryceholland

    (@bryceholland)

    Hi There. I’m just wondering if there was a solution to this issue or if you could help point me in the right direction here. Thank you!

    Plugin Author adispiac

    (@adispiac)

    Hi Bryce,
    You’re right, in version 2 we’re generating the username based on email.
    However, the same filter is available here: wppb_generated_random_username.

    So you can still use the code below to generate random usernames in case Login with Email is enabled.

    add_filter('wppb_generated_random_username', 'wppbc_rand_username', 10, 2);
    function wppbc_rand_username( $username, $user_email ){
        $username = wppbc_rand_based_on_charset();
        while ( username_exists( $username ) ){
            $username = wppbc_rand_based_on_charset();
        }
    
        return $username;
    }
    function wppbc_rand_based_on_charset(){
        $characters = '0123456789ABCDEFGHJKLMNPQRSTUVWXYZ';
        $length = strlen( $characters ) - 1;
        $result = '';
        for ($i = 0; $i < 8; $i++)
            $result .= $characters[mt_rand(0, $length)];
    
        return $result;
    }

    Place this in an empty plugin or your theme’s functions.php file.
    I’ve tested it and it works as expected. Can you confirm?

    Thread Starter bryceholland

    (@bryceholland)

    Thank you very much! This works. I appreciate your help.

    Plugin Author adispiac

    (@adispiac)

    Glad it works Bryce! You can always support our work by leaving a review.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Random User Name’ is closed to new replies.