Make WordPress Core

Ticket #18163: 18163.1.patch

File 18163.1.patch, 6.7 KB (added by Mista-Flo, 8 years ago)

Add firstname and lastname fields in add new user (multisite)

  • wp-admin/user-new.php

    diff --git wp-admin/user-new.php wp-admin/user-new.php
    index 38b78dd..bde57ab 100644
    Please click the following link to confirm the invite: 
    144144                                add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
    145145                                add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
    146146                        }
    147                         wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) );
     147                        $first_name = ( isset( $_REQUEST['first_name'] ) && ! empty( $_REQUEST['first_name'] ) ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '';
     148                        $last_name = ( isset( $_REQUEST['last_name'] ) && ! empty( $_REQUEST['last_name'] ) ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '';
     149                        wpmu_signup_user( $new_user_login, $new_user_email, array(
     150                                'add_to_blog' => $wpdb->blogid,
     151                                'new_role' => $_REQUEST['role'],
     152                                'first_name' => $first_name,
     153                                'last_name' => $last_name,
     154                        ));
    148155                        if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
    149156                                $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) );
    150157                                $new_user = wpmu_activate_signup( $key );
    $new_user_ignore_pass = $creating && isset( $_POST['noconfirmation'] ) ? wp_unsl 
    399406                <th scope="row"><label for="email"><?php _e('Email'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
    400407                <td><input name="email" type="email" id="email" value="<?php echo esc_attr( $new_user_email ); ?>" /></td>
    401408        </tr>
    402 <?php if ( !is_multisite() ) { ?>
    403409        <tr class="form-field">
    404410                <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th>
    405                 <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td>
     411                <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr( $new_user_firstname ); ?>" /></td>
    406412        </tr>
    407413        <tr class="form-field">
    408414                <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th>
    409                 <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td>
     415                <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr( $new_user_lastname ); ?>" /></td>
    410416        </tr>
     417<?php if ( ! is_multisite() ) { ?>
    411418        <tr class="form-field">
    412419                <th scope="row"><label for="url"><?php _e('Website') ?></label></th>
    413420                <td><input name="url" type="url" id="url" class="code" value="<?php echo esc_attr( $new_user_uri ); ?>" /></td>
  • wp-includes/ms-functions.php

    diff --git wp-includes/ms-functions.php wp-includes/ms-functions.php
    index ca81761..c119bc8 100644
    function wpmu_activate_signup($key) { 
    988988                if ( isset( $user_already_exists ) )
    989989                        return new WP_Error( 'user_already_exists', __( 'That username is already activated.' ), $signup);
    990990
     991                if ( ! empty( $meta['first_name'] ) ) {
     992                        update_user_meta( $user_id, 'first_name', $meta['first_name'] );
     993                }
     994
     995                if ( ! empty( $meta['last_name'] ) ) {
     996                        update_user_meta( $user_id, 'last_name', $meta['last_name'] );
     997                }
     998               
    991999                /**
    9921000                 * Fires immediately after a new user is activated.
    9931001                 *