Make WordPress Core

Ticket #28004: 28004.diff

File 28004.diff, 1.8 KB (added by swissspidy, 10 years ago)
  • src/wp-includes/user-functions.php

    diff --git src/wp-includes/user-functions.php src/wp-includes/user-functions.php
    index a79d1e8..e03cc17 100644
    function wp_insert_user( $userdata ) { 
    12751275        } elseif ( $userdata instanceof WP_User ) {
    12761276                $userdata = $userdata->to_array();
    12771277        }
     1278
    12781279        // Are we updating or creating?
    12791280        if ( ! empty( $userdata['ID'] ) ) {
    12801281                $ID = (int) $userdata['ID'];
    12811282                $update = true;
    1282                 $old_user_data = WP_User::get_data_by( 'id', $ID );
     1283                $old_user_data = get_userdata( $ID );
     1284
     1285                if ( ! $old_user_data ) {
     1286                        return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
     1287                }
     1288
    12831289                // hashed in wp_update_user(), plaintext if called directly
    12841290                $user_pass = $userdata['user_pass'];
    12851291        } else {
  • tests/phpunit/tests/user.php

    diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
    index f0b60d1..8faa06f 100644
    class Tests_User extends WP_UnitTestCase { 
    757757                $this->assertSame( $expected, $user->user_nicename );
    758758        }
    759759
     760        /**
     761         * @ticket 28004
     762         */
     763        public function test_wp_insert_user_with_invalid_user_id() {
     764                $user_login = str_repeat( 'a', 55 );
     765                $u = wp_insert_user( array(
     766                        'ID' => 123,
     767                        'user_login' => $user_login,
     768                        'user_email' => $user_login . '@example.com',
     769                        'user_pass' => 'password',
     770                ) );
     771
     772                $this->assertWPError( $u );
     773        }
     774
    760775        function test_changing_email_invalidates_password_reset_key() {
    761776                global $wpdb;
    762777
    class Tests_User extends WP_UnitTestCase { 
    963978                $user = get_userdata( $testuserid );
    964979                $pwd_before = $user->user_pass;
    965980                wp_update_user( $user );
    966                
     981
    967982                // Reload the data
    968983                $pwd_after = get_userdata( $testuserid )->user_pass;
    969984                $this->assertEquals( $pwd_before, $pwd_after );