WordPress.org

Make WordPress Core

Changeset 28740


Ignore:
Timestamp:
06/11/2014 06:20:57 PM (6 years ago)
Author:
wonderboymusic
Message:

Don't use variable variables in wp_insert_user().
Add a local array, $meta, to provide substantial disambiguation among variables.

See #27881.

File:
1 edited

Legend:

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

    r28722 r28740  
    16441644        $user_nicename = $userdata['user_nicename'];
    16451645    }
     1646
     1647    // Store values to save in user meta.
     1648    $meta = array();
     1649
    16461650    /**
    16471651     * Filter a user's nicename before the user is created or updated.
     
    16531657    $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    16541658
    1655     $user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
     1659    $raw_user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
    16561660
    16571661    /**
     
    16601664     * @since 2.0.3
    16611665     *
    1662      * @param string $user_url The user's URL.
    1663      */
    1664     $user_url = apply_filters( 'pre_user_url', $user_url );
    1665 
    1666     $user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
     1666     * @param string $raw_user_url The user's URL.
     1667     */
     1668    $user_url = apply_filters( 'pre_user_url', $raw_user_url );
     1669
     1670    $raw_user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
    16671671
    16681672    /**
     
    16711675     * @since 2.0.3
    16721676     *
    1673      * @param string $user_email The user's email.
    1674      */
    1675     $user_email = apply_filters( 'pre_user_email', $user_email );
     1677     * @param string $raw_user_email The user's email.
     1678     */
     1679    $user_email = apply_filters( 'pre_user_email', $raw_user_email );
    16761680
    16771681    if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $user_email ) ) {
     
    16791683    }
    16801684    $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname'];
     1685
    16811686    /**
    16821687     * Filter a user's nickname before the user is created or updated.
     
    16861691     * @param string $nickname The user's nickname.
    16871692     */
    1688     $nickname = apply_filters( 'pre_user_nickname', $nickname );
     1693    $meta['nickname'] = apply_filters( 'pre_user_nickname', $nickname );
    16891694
    16901695    $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name'];
     
    16971702     * @param string $first_name The user's first name.
    16981703     */
    1699     $first_name = apply_filters( 'pre_user_first_name', $first_name );
     1704    $meta['first_name'] = apply_filters( 'pre_user_first_name', $first_name );
    17001705
    17011706    $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name'];
     
    17081713     * @param string $last_name The user's last name.
    17091714     */
    1710     $last_name = apply_filters( 'pre_user_last_name', $last_name );
     1715    $meta['last_name'] = apply_filters( 'pre_user_last_name', $last_name );
    17111716
    17121717    if ( empty( $userdata['display_name'] ) ) {
    17131718        if ( $update ) {
    17141719            $display_name = $user_login;
    1715         } elseif ( $first_name && $last_name ) {
     1720        } elseif ( $meta['first_name'] && $meta['last_name'] ) {
    17161721            /* translators: 1: first name, 2: last name */
    1717             $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name );
    1718         } elseif ( $first_name ) {
    1719             $display_name = $first_name;
    1720         } elseif ( $last_name ) {
    1721             $display_name = $last_name;
     1722            $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $meta['first_name'], $meta['last_name'] );
     1723        } elseif ( $meta['first_name'] ) {
     1724            $display_name = $meta['first_name'];
     1725        } elseif ( $meta['last_name'] ) {
     1726            $display_name = $meta['last_name'];
    17221727        } else {
    17231728            $display_name = $user_login;
     
    17451750     * @param string $description The user's description.
    17461751     */
    1747     $description = apply_filters( 'pre_user_description', $description );
    1748 
    1749     $rich_editing = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
    1750 
    1751     $comment_shortcuts = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
     1752    $meta['description'] = apply_filters( 'pre_user_description', $description );
     1753
     1754    $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
     1755
     1756    $meta['comment_shortcuts'] = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
    17521757
    17531758    $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color'];
    1754     $admin_color = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
    1755 
    1756     $use_ssl = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
     1759    $meta['admin_color'] = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
     1760
     1761    $meta['use_ssl'] = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
    17571762
    17581763    $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
    17591764
    1760     $show_admin_bar_front = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
     1765    $meta['show_admin_bar_front'] = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
    17611766
    17621767    $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));
     
    17721777    }
    17731778
    1774     $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    1775     $data = wp_unslash( $data );
     1779    $compacted = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
     1780    $data = wp_unslash( $compacted );
    17761781
    17771782    if ( $update ) {
     
    17851790    $user = new WP_User( $user_id );
    17861791
    1787     foreach ( _get_additional_user_keys( $user ) as $key ) {
    1788         if ( isset( $$key ) ) {
    1789             update_user_meta( $user_id, $key, $$key );
     1792    // Update user meta.
     1793    foreach ( $meta as $key => $value ) {
     1794        update_user_meta( $user_id, $key, $value );
     1795    }
     1796
     1797    foreach ( wp_get_user_contact_methods( $user ) as $key => $value ) {
     1798        if ( isset( $userdata[ $key ] ) ) {
     1799            update_user_meta( $user_id, $key, $userdata[ $key ] );
    17901800        }
    17911801    }
Note: See TracChangeset for help on using the changeset viewer.