Multisite: First and Last Name when Add New User

Hi there,
I noticed that for some reason, when adding a new user in wp-admin, it does not contain all the regular fields of a single site installation. I require the First and Last Name fields when I am creating new users. Why does it disappear in multisite installs? And how do I get it back?
Thanks!

  • Adam Czajczyk

    Hello damiko

    I hope you're well today and thank you for your question!

    The registration/signup form on Multisite is different than then one on single installs, indeed. It only requires username and an e-mail address as it's more like "an invitation to join the network" so user gets an e-mail with a link and after clicking on it they're "activated" and can set their own profile data.

    You, as a super admin, can edit that data (e.g. first and last name) anyway but that means first adding the user and then editing her/his profile separately.

    That said, I've asked our developers if they could help with "adding back" that data to the back-end user registration page. They'll look into it and let us know here so please keep an eye on this ticket for further information.

    Best regards,
    Adam

  • Konstantinos Xenos

    Hi damiko !

    WordPress does provide a hook for the Network -> Add User but unfortunately not for the Subsite -> Add User forms.

    In any case you can try adding this code into your functions.php ( preferably the child-themes ) and it will show 2 additional fields when adding a user via your Network interface if that's ok with you.

    // Adds the extra fields on the Network Registration
    add_action( 'network_user_new_form', 'add_name_lastname_in_ms' );
    function add_name_lastname_in_ms() {
    	?>
    	<style>
    	form#adduser table:first-child tr:nth-child(3) {
    		display: none;
    	}
    	</style>
    	<table class="form-table">
    		<tr class="form-field">
    			<th scope="row"><label for="first_name"><?php _e( 'First Name' ) ?></label></th>
    			<td><input type="text" class="regular-text" name="user[first_name]" id="first_name"/></td>
    		</tr>
    		<tr class="form-field">
    			<th scope="row"><label for="last_name"><?php _e( 'Last Name' ) ?></label></th>
    			<td><input type="text" class="regular-text" name="user[last_name]" id="last_name"/></td>
    		</tr>
    		<tr class="form-field">
    			<td colspan="2"><?php _e( 'A password reset link will be sent to the user via email.' ) ?></td>
    		</tr>
    	</table>
    	<?php
    }
    
    // Inserts the fields into the database from Network Registration
    add_action( 'network_user_new_created_user', 'update_name_lastname_in_ms' );
    function update_name_lastname_in_ms( $user_id ) {
    	if ( ! empty( $_POST['user']['first_name'] ) ) {
    		update_user_meta( $user_id, 'first_name', sanitize_text_field( $_POST['user']['first_name'] ) );
    	}
    	if ( ! empty( $_POST['user']['last_name'] ) ) {
    		update_user_meta( $user_id, 'last_name', sanitize_text_field( $_POST['user']['last_name'] ) );
    	}
    }

    I hope this helps a bit!

    Regards,
    Konstantinos

  • damiko

    Hi Konstantinos,

    Unfortunately, that code didn't seem to work. Either way, that's not going to work for us anyways, as we need the functionality within sub-sites.

    Is there perhaps a front-end plugin that you are aware of that will allow admins to create users from there? I am using buddypress, so I could integrate it into the existing dashboard. Ideally, a front-end plugin would contain the additional fields.

    Any ideas?

    Thanks for you help!

  • Predrag Dubajic

    Hi damiko,

    Sorry to hear above solution doesn't work for you :slight_frown:

    I did some research but I'm afraid that I don't see any out of the box solution that would do this for you.
    Something like this might help https://wordpress.org/plugins/profile-builder/ but I'm not if it will completely fit your needs.

    This will most likely require custom development to get it working in such a specific way, you can check for custom development with Codeable:
    https://premium.wpmudev.org/partners/#wpmud-hg-discounts-services

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.