WordPress.org

Make WordPress Core

Ticket #21429: 21429.2.diff

File 21429.2.diff, 4.0 KB (added by ryan, 6 years ago)
  • wp-includes/user.php

     
    12431243 * @uses do_action() Calls 'profile_update' hook when updating giving the user's ID
    12441244 * @uses do_action() Calls 'user_register' hook when creating a new user giving the user's ID
    12451245 *
    1246  * @param array $userdata An array of user data.
     1246 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
    12471247 * @return int|WP_Error The newly created user's ID or a WP_Error object if the user could not be created.
    12481248 */
    1249 function wp_insert_user($userdata) {
     1249function wp_insert_user( $userdata ) {
    12501250        global $wpdb;
    12511251
    1252         extract($userdata, EXTR_SKIP);
     1252        if ( is_a( $userdata, 'stdClass' ) )
     1253                $userdata = get_object_vars( $userdata );
     1254        elseif ( is_a( $userdata, 'WP_User' ) )
     1255                $userdata = $userdata->to_array();
    12531256
     1257        extract( $userdata, EXTR_SKIP );
     1258
    12541259        // Are we updating or creating?
    12551260        if ( !empty($ID) ) {
    12561261                $ID = (int) $ID;
     
    13901395 * @see wp_insert_user() For what fields can be set in $userdata
    13911396 * @uses wp_insert_user() Used to update existing user or add new one if user doesn't exist already
    13921397 *
    1393  * @param array $userdata An array of user data.
     1398 * @param mixed $userdata An array of user data or a user object of type stdClass or WP_User.
    13941399 * @return int The updated user's ID.
    13951400 */
    13961401function wp_update_user($userdata) {
     1402        if ( is_a( $userdata, 'stdClass' ) )
     1403                $userdata = get_object_vars( $userdata );
     1404        elseif ( is_a( $userdata, 'WP_User' ) )
     1405                $userdata = $userdata->to_array();
     1406
    13971407        $ID = (int) $userdata['ID'];
    13981408
    13991409        // First, get all of the original fields
    14001410        $user_obj = get_userdata( $ID );
    14011411
    1402         $user = get_object_vars( $user_obj->data );
     1412        $user = $user_obj->to_array();
    14031413
    14041414        // Add additional custom fields
    14051415        foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
  • wp-includes/capabilities.php

     
    636636                return $this->__isset( $key );
    637637        }
    638638
     639        /*
     640         * Return an array representation.
     641         *
     642         * @since 3.5.0
     643         *
     644         * @return array Array representation.
     645         */
     646        function to_array() {
     647                return get_object_vars( $this->data );
     648        }
     649
    639650        /**
    640651         * Set up capability object properties.
    641652         *
  • wp-admin/includes/user.php

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

     
    8282if ( is_multisite() && IS_PROFILE_PAGE && isset( $_GET[ 'newuseremail' ] ) && $current_user->ID ) {
    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' ) ) );
    9293                die();