• Resolved awesomeflyingdude

    (@awesomeflyingdude)


    Hi,

    I’m sure this has been asked before, but I couldn’t find anything. I want registered users to only use their email address as their username. When signing up, I’d like them to be able to only enter their email address once, but apply it to both the “username” field and the “user_mail” field (because I assume WordPress needs that to send out account notifications and can’t just use the “username” email, correct? If not, I’ll just stick with using “username”.). Is something like this possible on the Registration form without having to manually copy and paste the “username” to “user_mail” field?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @awesomeflyingdude

    You can try this code snippet below.

    add_action("um_submit_form_register","um_092321_email_address_validation");
    function um_092321_email_address_validation( $post_form ){
      
        if(  isset( $post_form['user_email'] ) && ! empty( $post_form['user_email'] ) ){
            if( username_exists( $post_form['user_email'] ) )  {
                UM()->form()->add_error('user_email', __( 'Email address already registered as username', 'ultimate-member' ) );
    		}
    	}  
    
    }
    
    add_action("um_user_register","um_092321_after_register_complete", -1, 2 );
    function um_092321_after_register_complete( $user_id, $args ){
       
        global $wpdb;
        $wpdb->update( $wpdb->users, array('user_login' => $args['user_email'] ), array('ID' => $user_id));
    }
    

    The above code will make the user email a username. You can add the code to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code.

    Regards,

    • This reply was modified 3 years, 5 months ago by Champ Camba.
    Thread Starter awesomeflyingdude

    (@awesomeflyingdude)

    Thank you for the reply, Champ!

    Just to clarify, if I add the code, I can have a registration form with only a field for “user_email” and leave out the “username” field, correct? That is my goal.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Email Address As Username AND Email’ is closed to new replies.