Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey all,

    Yes, you can do it but you will need to add a code snippet to your functions.php file which is inside your theme’s folder. Here is the code:

    
    add_action( 'user_registration_after_register_user_action', 'ur_insert_username', 1, 3 );
    function ur_insert_username( $valid_form_data, $form_id, $user_id ) {
        global $wpdb;
        $user_login = $valid_form_data['user_email']->value;
        $wpdb->update( $wpdb->users, array( 'user_login' => $user_login ), array( 'ID' => $user_id ) );
    }
    
    add_filter( 'user_registration_before_register_user_filter', 'ur_set_email_as_username', 10, 2 );
    function ur_set_email_as_username( $valid_form_data, $form_id ) {
        $valid_form_data['user_login'] = $valid_form_data['user_email'];
        return $valid_form_data;
    }
    

    Now everyone who registers through our plugin will have their email set as their username.

    Thanks!

    • This reply was modified 6 years, 11 months ago by abhashdc.
    • This reply was modified 6 years, 11 months ago by abhashdc.
    • This reply was modified 6 years, 11 months ago by Jan Dembowski.
    Thread Starter teolives

    (@teolives)

    Thanks!

    If I add this code, and a user signs up, under their account page there is a user name of the start of the email without the “@gmail.com” etc. Yet in WP admin under users, the username is the whole email. Why is this?

    e.g. under frontend account: username is xyz, under wp admin: username is xyz@gmail.com

    • This reply was modified 6 years, 11 months ago by jmccx.

    Hi @jmccx

    That is the display name that you are seeing. The above code will set your username as your email. User name and display name are two different things. You can change your display name but your username will stay as it is. That is extracted from the email.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘E-mail address as username?’ is closed to new replies.