WordPress.org

Make WordPress Core

Changeset 28454


Ignore:
Timestamp:
05/16/2014 06:15:00 PM (7 years ago)
Author:
wonderboymusic
Message:

Eliminate use of extract() in wp_insert_user().

See #22400.

File:
1 edited

Legend:

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

    r28420 r28454  
    15361536    global $wpdb;
    15371537
    1538     if ( is_a( $userdata, 'stdClass' ) )
     1538    if ( is_a( $userdata, 'stdClass' ) ) {
    15391539        $userdata = get_object_vars( $userdata );
    1540     elseif ( is_a( $userdata, 'WP_User' ) )
     1540    } elseif ( is_a( $userdata, 'WP_User' ) ) {
    15411541        $userdata = $userdata->to_array();
    1542 
    1543     extract( $userdata, EXTR_SKIP );
    1544 
     1542    }
    15451543    // Are we updating or creating?
    1546     if ( !empty($ID) ) {
    1547         $ID = (int) $ID;
     1544    if ( ! empty( $userdata['ID'] ) ) {
     1545        $ID = (int) $userdata['ID'];
    15481546        $update = true;
    15491547        $old_user_data = WP_User::get_data_by( 'id', $ID );
     1548        // hashed in wp_update_user(), plaintext if called directly
     1549        $user_pass = $userdata['user_pass'];
    15501550    } else {
    15511551        $update = false;
    15521552        // Hash the password
    1553         $user_pass = wp_hash_password($user_pass);
    1554     }
    1555 
    1556     $user_login = sanitize_user($user_login, true);
     1553        $user_pass = wp_hash_password( $userdata['user_pass'] );
     1554    }
     1555
     1556    $sanitized_user_login = sanitize_user( $userdata['user_login'], true );
    15571557
    15581558    /**
     
    15631563     * @since 2.0.3
    15641564     *
    1565      * @param string $user_login Username after it has been sanitized.
    1566      */
    1567     $user_login = apply_filters( 'pre_user_login', $user_login );
     1565     * @param string $sanitized_user_login Username after it has been sanitized.
     1566     */
     1567    $pre_user_login = apply_filters( 'pre_user_login', $sanitized_user_login );
    15681568
    15691569    //Remove any non-printable chars from the login string to see if we have ended up with an empty username
    1570     $user_login = trim($user_login);
    1571 
    1572     if ( empty($user_login) )
     1570    $user_login = trim( $pre_user_login );
     1571
     1572    if ( empty( $user_login ) ) {
    15731573        return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
    1574 
    1575     if ( !$update && username_exists( $user_login ) )
     1574    }
     1575    if ( ! $update && username_exists( $user_login ) ) {
    15761576        return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
    1577 
    1578     if ( empty($user_nicename) )
     1577    }
     1578    if ( empty( $userdata['user_nicename'] ) ) {
    15791579        $user_nicename = sanitize_title( $user_login );
    1580 
     1580    } else {
     1581        $user_nicename = $userdata['user_nicename'];
     1582    }
    15811583    /**
    15821584     * Filter a user's nicename before the user is created or updated.
     
    15881590    $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
    15891591
    1590     if ( empty($user_url) )
    1591         $user_url = '';
     1592    $user_url = empty( $userdata['user_url'] ) ? '' : $userdata['user_url'];
    15921593
    15931594    /**
     
    16001601    $user_url = apply_filters( 'pre_user_url', $user_url );
    16011602
    1602     if ( empty($user_email) )
    1603         $user_email = '';
     1603    $user_email = empty( $userdata['user_email'] ) ? '' : $userdata['user_email'];
    16041604
    16051605    /**
     
    16121612    $user_email = apply_filters( 'pre_user_email', $user_email );
    16131613
    1614     if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
     1614    if ( ! $update && ! defined( 'WP_IMPORTING' ) && email_exists( $user_email ) ) {
    16151615        return new WP_Error( 'existing_user_email', __( 'Sorry, that email address is already used!' ) );
    1616 
    1617     if ( empty($nickname) )
    1618         $nickname = $user_login;
    1619 
     1616    }
     1617    $nickname = empty( $userdata['nickname'] ) ? $user_login : $userdata['nickname'];
    16201618    /**
    16211619     * Filter a user's nickname before the user is created or updated.
     
    16271625    $nickname = apply_filters( 'pre_user_nickname', $nickname );
    16281626
    1629     if ( empty($first_name) )
    1630         $first_name = '';
     1627    $first_name = empty( $userdata['first_name'] ) ? '' : $userdata['first_name'];
    16311628
    16321629    /**
     
    16391636    $first_name = apply_filters( 'pre_user_first_name', $first_name );
    16401637
    1641     if ( empty($last_name) )
    1642         $last_name = '';
     1638    $last_name = empty( $userdata['last_name'] ) ? '' : $userdata['last_name'];
    16431639
    16441640    /**
     
    16511647    $last_name = apply_filters( 'pre_user_last_name', $last_name );
    16521648
    1653     if ( empty( $display_name ) ) {
    1654         if ( $update )
     1649    if ( empty( $userdata['display_name'] ) ) {
     1650        if ( $update ) {
    16551651            $display_name = $user_login;
    1656         elseif ( $first_name && $last_name )
     1652        } elseif ( $first_name && $last_name ) {
    16571653            /* translators: 1: first name, 2: last name */
    16581654            $display_name = sprintf( _x( '%1$s %2$s', 'Display name based on first name and last name' ), $first_name, $last_name );
    1659         elseif ( $first_name )
     1655        } elseif ( $first_name ) {
    16601656            $display_name = $first_name;
    1661         elseif ( $last_name )
     1657        } elseif ( $last_name ) {
    16621658            $display_name = $last_name;
    1663         else
     1659        } else {
    16641660            $display_name = $user_login;
     1661        }
     1662    } else {
     1663        $display_name = $userdata['display_name'];
    16651664    }
    16661665
     
    16741673    $display_name = apply_filters( 'pre_user_display_name', $display_name );
    16751674
    1676     if ( empty($description) )
    1677         $description = '';
     1675    $description = empty( $userdata['description'] ) ? '' : $userdata['description'];
    16781676
    16791677    /**
     
    16861684    $description = apply_filters( 'pre_user_description', $description );
    16871685
    1688     if ( empty($rich_editing) )
    1689         $rich_editing = 'true';
    1690 
    1691     if ( empty($comment_shortcuts) )
    1692         $comment_shortcuts = 'false';
    1693 
    1694     if ( empty($admin_color) )
    1695         $admin_color = 'fresh';
    1696     $admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color);
    1697 
    1698     if ( empty($use_ssl) )
    1699         $use_ssl = 0;
    1700 
    1701     if ( empty($user_registered) )
    1702         $user_registered = gmdate('Y-m-d H:i:s');
    1703 
    1704     if ( empty($show_admin_bar_front) )
    1705         $show_admin_bar_front = 'true';
     1686    $rich_editing = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing'];
     1687
     1688    $comment_shortcuts = empty( $userdata['comment_shortcuts'] ) ? 'false' : $userdata['comment_shortcuts'];
     1689
     1690    $admin_color = empty( $userdata['admin_color'] ) ? 'fresh' : $userdata['admin_color'];
     1691    $admin_color = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $admin_color );
     1692
     1693    $use_ssl = empty( $userdata['use_ssl'] ) ? 0 : $userdata['use_ssl'];
     1694
     1695    $user_registered = empty( $userdata['user_registered'] ) ? gmdate( 'Y-m-d H:i:s' ) : $userdata['user_registered'];
     1696
     1697    $show_admin_bar_front = empty( $userdata['show_admin_bar_front'] ) ? 'true' : $userdata['show_admin_bar_front'];
    17061698
    17071699    $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));
     
    17311723
    17321724    foreach ( _get_additional_user_keys( $user ) as $key ) {
    1733         if ( isset( $$key ) )
     1725        if ( isset( $$key ) ) {
    17341726            update_user_meta( $user_id, $key, $$key );
    1735     }
    1736 
    1737     if ( isset($role) )
    1738         $user->set_role($role);
    1739     elseif ( !$update )
     1727        }
     1728    }
     1729
     1730    if ( isset( $userdata['role'] ) ) {
     1731        $user->set_role( $userdata['role'] );
     1732    } elseif ( ! $update ) {
    17401733        $user->set_role(get_option('default_role'));
    1741 
    1742     wp_cache_delete($user_id, 'users');
    1743     wp_cache_delete($user_login, 'userlogins');
     1734    }
     1735    wp_cache_delete( $user_id, 'users' );
     1736    wp_cache_delete( $user_login, 'userlogins' );
    17441737
    17451738    if ( $update ) {
Note: See TracChangeset for help on using the changeset viewer.