Make WordPress Core


Ignore:
Timestamp:
08/01/2019 05:12:42 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Users: Reorganize user_nicename, user_url, user_registered setting in wp_insert_user() for consistency with the order or fields in the database.

See #45746.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r45708 r45713  
    16031603    $user_nicename = sanitize_title( $user_nicename );
    16041604
    1605     // Store values to save in user meta.
    1606     $meta = array();
    1607 
    16081605    /**
    16091606     * Filters a user's nicename before the user is created or updated.
     
    16151612    $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    16161613
    1617     $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
    1618 
    1619     /**
    1620      * Filters a user's URL before the user is created or updated.
    1621      *
    1622      * @since 2.0.3
    1623      *
    1624      * @param string $raw_user_url The user's URL.
    1625      */
    1626     $user_url = apply_filters( 'pre_user_url', $raw_user_url );
     1614    $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) );
     1615
     1616    if ( $user_nicename_check ) {
     1617        $suffix = 2;
     1618        while ( $user_nicename_check ) {
     1619            // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix.
     1620            $base_length         = 49 - mb_strlen( $suffix );
     1621            $alt_user_nicename   = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix";
     1622            $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login ) );
     1623            $suffix++;
     1624        }
     1625        $user_nicename = $alt_user_nicename;
     1626    }
    16271627
    16281628    $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
     
    16491649    }
    16501650
     1651    $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
     1652
     1653    /**
     1654     * Filters a user's URL before the user is created or updated.
     1655     *
     1656     * @since 2.0.3
     1657     *
     1658     * @param string $raw_user_url The user's URL.
     1659     */
     1660    $user_url = apply_filters( 'pre_user_url', $raw_user_url );
     1661
     1662    $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
     1663
    16511664    if ( isset( $userdata['spam'] ) && ! is_multisite() ) {
    16521665        return new WP_Error( 'no_spam', __( 'Sorry, marking a user as spam is only supported on Multisite.' ) );
     
    16541667
    16551668    $spam = empty( $userdata['spam'] ) ? 0 : (bool) $userdata['spam'];
     1669
     1670    // Store values to save in user meta.
     1671    $meta = array();
    16561672
    16571673    $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname'];
     
    17361752    $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : (bool) $userdata['use_ssl'];
    17371753
    1738     $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
    1739 
    17401754    $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
    17411755
    17421756    $meta['locale'] = isset( $userdata['locale'] ) ? $userdata['locale'] : '';
    17431757
    1744     $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) );
    1745 
    1746     if ( $user_nicename_check ) {
    1747         $suffix = 2;
    1748         while ( $user_nicename_check ) {
    1749             // user_nicename allows 50 chars. Subtract one for a hyphen, plus the length of the suffix.
    1750             $base_length         = 49 - mb_strlen( $suffix );
    1751             $alt_user_nicename   = mb_substr( $user_nicename, 0, $base_length ) . "-$suffix";
    1752             $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $alt_user_nicename, $user_login ) );
    1753             $suffix++;
    1754         }
    1755         $user_nicename = $alt_user_nicename;
    1756     }
    1757 
    1758     $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     1758    $compacted = compact( 'user_pass', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'display_name' );
    17591759    $data      = wp_unslash( $compacted );
    17601760
Note: See TracChangeset for help on using the changeset viewer.