Make WordPress Core

Changeset 21496


Ignore:
Timestamp:
08/10/2012 03:36:54 PM (12 years ago)
Author:
ryan
Message:

Allow passing stdClass and WP_User to wp_insert_user() and wp_update_user(). Introduce WP_User::to_array(). Eliminate uses of get_object_vars() when passing to wp_*_user(). fixes #21429

Location:
trunk
Files:
4 edited

Legend:

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

    r21413 r21496  
    157157
    158158    if ( $update ) {
    159         $user_id = wp_update_user( get_object_vars( $user ) );
    160     } else {
    161         $user_id = wp_insert_user( get_object_vars( $user ) );
     159        $user_id = wp_update_user( $user );
     160    } else {
     161        $user_id = wp_insert_user( $user );
    162162        wp_new_user_notification( $user_id, isset($_POST['send_password']) ? $pass1 : '' );
    163163    }
  • trunk/wp-admin/user-edit.php

    r21364 r21496  
    8383    $new_email = get_option( $current_user->ID . '_new_email' );
    8484    if ( $new_email[ 'hash' ] == $_GET[ 'newuseremail' ] ) {
     85        $user = new stdClass;
    8586        $user->ID = $current_user->ID;
    8687        $user->user_email = esc_html( trim( $new_email[ 'newemail' ] ) );
    8788        if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) )
    8889            $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
    89         wp_update_user( get_object_vars( $user ) );
     90        wp_update_user( $user );
    9091        delete_option( $current_user->ID . '_new_email' );
    9192        wp_redirect( add_query_arg( array('updated' => 'true'), self_admin_url( 'profile.php' ) ) );
  • trunk/wp-includes/capabilities.php

    r21485 r21496  
    664664    function has_prop( $key ) {
    665665        return $this->__isset( $key );
     666    }
     667
     668    /*
     669     * Return an array representation.
     670     *
     671     * @since 3.5.0
     672     *
     673     * @return array Array representation.
     674     */
     675    function to_array() {
     676        return get_object_vars( $this->data );
    666677    }
    667678
  • trunk/wp-includes/user.php

    r21413 r21496  
    12411241 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
    12421242 *
    1243  * @param array $userdata An array of user data.
     1243 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
    12441244 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
    12451245 */
    1246 function wp_insert_user($userdata) {
     1246function wp_insert_user( $userdata ) {
    12471247    global $wpdb;
    12481248
    1249     extract($userdata, EXTR_SKIP);
     1249    if ( is_a( $userdata, 'stdClass' ) )
     1250        $userdata = get_object_vars( $userdata );
     1251    elseif ( is_a( $userdata, 'WP_User' ) )
     1252        $userdata = $userdata->to_array();
     1253
     1254    extract( $userdata, EXTR_SKIP );
    12501255
    12511256    // Are we updating or creating?
     
    13881393 * @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
    13891394 *
    1390  * @param array $userdata An array of user data.
     1395 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
    13911396 * @return int The updated user's ID.
    13921397 */
    13931398function wp_update_user($userdata) {
     1399    if ( is_a( $userdata, 'stdClass' ) )
     1400        $userdata = get_object_vars( $userdata );
     1401    elseif ( is_a( $userdata, 'WP_User' ) )
     1402        $userdata = $userdata->to_array();
     1403
    13941404    $ID = (int) $userdata['ID'];
    13951405
     
    13971407    $user_obj = get_userdata( $ID );
    13981408
    1399     $user = get_object_vars( $user_obj->data );
     1409    $user = $user_obj->to_array();
    14001410
    14011411    // Add additional custom fields
Note: See TracChangeset for help on using the changeset viewer.