Make WordPress Core

Ticket #16731: 16731.2.diff

File 16731.2.diff, 1.6 KB (added by garyc40, 12 years ago)

also return a WP_Error object if an invalid user ID is passed

  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index cd4b01d..8eea83d 100644
    function wp_insert_user($userdata) { 
    15431543 * @return int The updated user's ID.
    15441544 */
    15451545function wp_update_user($userdata) {
    1546         $ID = (int) $userdata['ID'];
    1547 
    1548         // First, get all of the original fields
    1549         $user = get_userdata($ID);
    1550 
    1551         // Escape data pulled from DB.
    1552         $user = add_magic_quotes(get_object_vars($user));
     1546        if ( empty( $userdata['ID'] ) ) {
     1547                $user = array();
     1548        } else {
     1549                $user = get_userdata((int) $userdata['ID']);
     1550               
     1551                if ( ! $user )
     1552                        return new WP_Error( 'invalid_user_id', sprintf( __( 'Invalid User ID: %s' ), $userdata['ID'] ) );
     1553               
     1554                // Escape data pulled from DB.
     1555                $user = add_magic_quotes(get_object_vars($user));
     1556                wp_cache_delete($user[ 'user_email' ], 'useremail');
     1557        }
    15531558
    15541559        // If password is changing, hash it now.
    15551560        if ( ! empty($userdata['user_pass']) ) {
    function wp_update_user($userdata) { 
    15571562                $userdata['user_pass'] = wp_hash_password($userdata['user_pass']);
    15581563        }
    15591564
    1560         wp_cache_delete($user[ 'user_email' ], 'useremail');
    1561 
    15621565        // Merge old and new fields with new fields overwriting old ones.
    15631566        $userdata = array_merge($user, $userdata);
    15641567        $user_id = wp_insert_user($userdata);
    15651568
    15661569        // Update the cookies if the password changed.
    15671570        $current_user = wp_get_current_user();
    1568         if ( $current_user->id == $ID ) {
     1571        if ( $current_user->id == $user_id ) {
    15691572                if ( isset($plaintext_pass) ) {
    15701573                        wp_clear_auth_cookie();
    1571                         wp_set_auth_cookie($ID);
     1574                        wp_set_auth_cookie($user_id);
    15721575                }
    15731576        }
    15741577