WordPress.org

Make WordPress Core

Changeset 49036


Ignore:
Timestamp:
09/23/2020 12:25:47 AM (11 months ago)
Author:
SergeyBiryukov
Message:

Users: Check if the user ID passed as selected to wp_dropdown_users() corresponds to an existing user.

This avoids a few PHP notices if the include_selected parameter was specified and a non-existing user ID was passed.

Props campusboy1987.
Fixes #51370.

Location:
trunk
Files:
2 edited

Legend:

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

    r49028 r49036  
    11921192            $found_selected          = false;
    11931193            $parsed_args['selected'] = (int) $parsed_args['selected'];
     1194
    11941195            foreach ( (array) $users as $user ) {
    11951196                $user->ID = (int) $user->ID;
     
    12001201
    12011202            if ( ! $found_selected ) {
    1202                 $users[] = get_userdata( $parsed_args['selected'] );
     1203                $selected_user = get_userdata( $parsed_args['selected'] );
     1204                if ( $selected_user ) {
     1205                    $users[] = $selected_user;
     1206                }
    12031207            }
    12041208        }
  • trunk/tests/phpunit/tests/user/wpDropdownUsers.php

    r47122 r49036  
    131131
    132132    /**
     133     * @ticket 51370
     134     */
     135    public function test_include_selected_with_non_existing_user_id() {
     136        $found = wp_dropdown_users(
     137            array(
     138                'echo'             => false,
     139                'selected'         => PHP_INT_MAX,
     140                'include_selected' => true,
     141                'show'             => 'user_login',
     142            )
     143        );
     144
     145        $this->assertNotContains( (string) PHP_INT_MAX, $found );
     146    }
     147
     148    /**
    133149     * @ticket 38135
    134150     */
Note: See TracChangeset for help on using the changeset viewer.