Make WordPress Core

Changeset 34125


Ignore:
Timestamp:
09/14/2015 06:57:15 PM (11 years ago)
Author:
boonebgorges
Message:

Accept 'ID' as a valid $field in get_user_by().

We already accept 'id'. ID more closely matches the database and
WP_User schemas.

Props Shelob9.
Fixes #33869.

Location:
trunk
Files:
3 edited

Legend:

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

    r33967 r34125  
    166166         *
    167167         * @since 3.3.0
     168         * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
    168169         *
    169170         * @static
    … …  
    171172         * @global wpdb $wpdb
    172173         *
    173          * @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
     174         * @param string $field The field to query against: 'id', 'ID', 'slug', 'email' or 'login'.
    174175         * @param string|int $value The field value
    175176         * @return object|false Raw user object
    … …  
    177178        public static function get_data_by( $field, $value ) {
    178179                global $wpdb;
     180
     181                // 'ID' is an alias of 'id'.
     182                if ( 'ID' === $field ) {
     183                        $field = 'id';
     184                }
    179185
    180186                if ( 'id' == $field ) {
  • trunk/src/wp-includes/pluggable.php

    r34116 r34125  
    146146 *
    147147 * @since 2.8.0
    148  *
    149  * @param string     $field The field to retrieve the user with. id | slug | email | login
     148 * @since 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
     149 *
     150 * @param string     $field The field to retrieve the user with. id | ID | slug | email | login.
    150151 * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
    151152 * @return WP_User|false WP_User object on success, false on failure.
  • trunk/tests/phpunit/tests/user.php

    r34116 r34125  
    444444                $user = WP_User::get_data_by( 'id', 99999 );
    445445                $this->assertEquals( false, $user );
     446        }
     447
     448        /**
     449         * @ticket 33869
     450         */
     451        public function test_user_get_data_by_ID_should_alias_to_id() {
     452                $u = $this->factory->user->create();
     453
     454                $user = WP_User::get_data_by( 'ID', $u );
     455                $this->assertEquals( $u, $user->ID );
    446456        }
    447457
Note: See TracChangeset for help on using the changeset viewer.