Make WordPress Core

Ticket #39123: 39123.patch

File 39123.patch, 3.4 KB (added by neelpatel7295, 7 years ago)

Provision for change user name for those particular user who had 'edit_users' caps.

  • wp-admin/includes/user.php

     
    3939                $update = false;
    4040        }
    4141
    42         if ( !$update && isset( $_POST['user_login'] ) )
     42        if ( isset( $_POST['user_login'] ) )
    4343                $user->user_login = sanitize_user($_POST['user_login'], true);
    4444
    4545        $pass1 = $pass2 = '';
  • wp-admin/user-edit.php

     
    368368<table class="form-table">
    369369        <tr class="user-user-login-wrap">
    370370                <th><label for="user_login"><?php _e('Username'); ?></label></th>
    371                 <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e('Usernames cannot be changed.'); ?></span></td>
     371                <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr($profileuser->user_login); ?>" class="regular-text" <?php echo (current_user_can( 'edit_users')) ? '' : 'disabled'; ?>/></td>
    372372        </tr>
    373373
    374374<?php if ( !IS_PROFILE_PAGE && !is_network_admin() ) : ?>
  • wp-includes/user.php

     
    14811481        } elseif ( mb_strlen( $user_login ) > 60 ) {
    14821482                return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
    14831483        }
    1484 
    1485         if ( ! $update && username_exists( $user_login ) ) {
     1484        /*
     1485         * If there is no update, just check for `username_exists`. If there is an update,
     1486         * check if current email and new email are the same, or not, and check `username_exists`
     1487         * accordingly.
     1488         */
     1489        if ( ( ! $update || ( ! empty( $old_user_data ) && 0 !== strcasecmp( $user_login, $old_user_data->user_login ) ) )
     1490                && ! defined( 'WP_IMPORTING' )
     1491                && username_exists( $user_login )
     1492        ) {
    14861493                return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
    14871494        }
     1495       
    14881496
    14891497        /**
    14901498         * Filters the list of blacklisted usernames.
     
    15001508        }
    15011509
    15021510        /*
    1503          * If a nicename is provided, remove unsafe user characters before using it.
    1504          * Otherwise build a nicename from the user_login.
     1511         * Evertime build a nicename from the user_login.
    15051512         */
    1506         if ( ! empty( $userdata['user_nicename'] ) ) {
    1507                 $user_nicename = sanitize_user( $userdata['user_nicename'], true );
    1508                 if ( mb_strlen( $user_nicename ) > 50 ) {
    1509                         return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) );
    1510                 }
    1511         } else {
    1512                 $user_nicename = mb_substr( $user_login, 0, 50 );
    1513         }
     1513        $user_nicename = mb_substr( $user_login, 0, 50 );
    15141514
    15151515        $user_nicename = sanitize_title( $user_nicename );
    15161516
     
    16621662
    16631663        $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    16641664        $data = wp_unslash( $compacted );
    1665 
    1666         if ( ! $update ) {
    1667                 $data = $data + compact( 'user_login' );
     1665       
     1666        if(current_user_can( 'edit_users')){
     1667                $data = $data + compact( 'user_login');
    16681668        }
    16691669
    16701670        /**
     
    18611861
    18621862        // Merge old and new fields with new fields overwriting old ones.
    18631863        $userdata = array_merge( $user, $userdata );
     1864
    18641865        $user_id = wp_insert_user( $userdata );
    18651866
    18661867        if ( ! is_wp_error( $user_id ) ) {