• Hello,

    Currently, my WordPress install sets the username as the first part of the email address entered into the registration form—this is WPUF Registration Form, with just First Name, Last Name, and email address for sign-up (with some custom fields).

    Using the first part of the email address doesn’t make sense as some people have very odd email addresses that are not instantly recognisable as the person, eg 123gorgeous@ ….

    My question. I am able to set up the Display name to use the first and Last Name. Is there anyway to hook into the registration process and ask it to use firstname-lastname instead. Or some form of initial from first name followed by last name.
    Before you ask, I did ask WPUF Support as I have the Pro version, but they responded as follows:

    “By default, there is no way to do this. You will need customization in the core file for this. WPUF designed this feature in most generalized way. …. I would suggest you to hire a developer for this ?? ”

    So I thought I’d have a go myself ??

    Thanks for any pointers.

    Cheers,
    Tracy

    • This topic was modified 3 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, Freelancealot, you can try hooking into the user_register hook.

    Here is the developer page for that: https://developer.www.ads-software.com/reference/hooks/user_register/

    By using that hook with the wp_update_user – here is a developer page for that function: https://developer.www.ads-software.com/reference/functions/wp_update_user/ – you should be able to adjust the display name with something like this:

    add_action( 'user_register', 'display_name_first_last', 999 );
    
    function display_name_first_last( $user_id ) {
       
        $user = get_user_by( 'id', $user_id );
        
        wp_update_user(
            array( 
                'ID'         => $user_id, 
                'display_name' => $user->first_name . "-" .  $user->last_name
            )
        );
    
    }
    Thread Starter Freelancealot

    (@freelancealot)

    Hi @plantprogrammer Thanks, but as per the title of the topic,’How to set First and Last Name as username‘. Perhaps I didn’t make the main text clear enough. I have already dealt with using First and Last Name for the Display Name. I need to hook into the Username to use those as well.

    Thread Starter Freelancealot

    (@freelancealot)

    Hi, Surprised more WordPress experts have not come back on this one. Is it too obvious or not possible?

    Need to hook into the user creation process and add something like

    user_login = first_name-last_name

    But I am not a coder and really do need some help on this support forum if possible.

    Cheers,
    Tracy

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set First and Last Name as username instead of first part of email’ is closed to new replies.