Changeset 53327
- Timestamp:
- 05/02/2022 12:11:48 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-user-query.php
r53280 r53327 286 286 287 287 if ( is_array( $qv['fields'] ) ) { 288 $qv['fields'] = array_unique( $qv['fields'] ); 288 $qv['fields'] = array_intersect( array_unique( $qv['fields'] ), $allowed_fields ); 289 290 if ( empty( $qv['fields'] ) ) { 291 $qv['fields'] = array( 'ID' ); 292 } 289 293 290 294 $this->query_fields = array(); … … 294 298 } 295 299 $this->query_fields = implode( ',', $this->query_fields ); 300 } elseif ( 'all' === $qv['fields'] ) { 301 $this->query_fields = "$wpdb->users.*"; 296 302 } elseif ( ! in_array( $qv['fields'], $allowed_fields, true ) ) { 297 $this->query_fields = "$wpdb->users. *";303 $this->query_fields = "$wpdb->users.ID"; 298 304 } else { 299 305 $field = 'ID' === $qv['fields'] ? 'ID' : sanitize_key( $qv['fields'] ); -
trunk/tests/phpunit/tests/user/query.php
r53255 r53327 1983 1983 $q = new WP_User_Query( 1984 1984 array( 1985 'fields' 1986 'include ' => array( self::$admin_ids[0]),1985 'fields' => $field, 1986 'include' => array( '1' ), 1987 1987 ) 1988 1988 ); … … 2008 2008 public function data_returning_fields() { 2009 2009 return array( 2010 'all' => array(2010 'all' => array( 2011 2011 'field' => 'all', 2012 2012 'expected' => array( … … 2014 2014 'user_login' => 'admin', 2015 2015 'user_nicename' => 'admin', 2016 'user_email' => 'admin@example.org',2017 'user_url' => 'http://example.org',2016 'user_email' => WP_TESTS_EMAIL, 2017 'user_url' => wp_guess_url(), 2018 2018 'user_activation_key' => '', 2019 2019 'user_status' => '0', … … 2021 2021 ), 2022 2022 ), 2023 'all_with_meta' => array(2023 'all_with_meta' => array( 2024 2024 'field' => 'all_with_meta', 2025 2025 'expected' => array( … … 2027 2027 'user_login' => 'admin', 2028 2028 'user_nicename' => 'admin', 2029 'user_email' => 'admin@example.org',2030 'user_url' => 'http://example.org',2029 'user_email' => WP_TESTS_EMAIL, 2030 'user_url' => wp_guess_url(), 2031 2031 'user_activation_key' => '', 2032 2032 'user_status' => '0', … … 2034 2034 ), 2035 2035 ), 2036 'ID' => array(2036 'ID' => array( 2037 2037 'field' => 'ID', 2038 2038 'expected' => array( … … 2040 2040 ), 2041 2041 ), 2042 'display_name' => array( 2042 'id' => array( 2043 'field' => 'id', 2044 'expected' => array( 2045 'ID' => '1', 2046 ), 2047 ), 2048 'display_name' => array( 2043 2049 'field' => 'display_name', 2044 2050 'expected' => array( … … 2046 2052 ), 2047 2053 ), 2048 'user_login' => array(2054 'user_login' => array( 2049 2055 'field' => 'user_login', 2050 2056 'expected' => array( … … 2052 2058 ), 2053 2059 ), 2054 'user_nicename' => array(2060 'user_nicename' => array( 2055 2061 'field' => 'user_nicename', 2056 2062 'expected' => array( … … 2058 2064 ), 2059 2065 ), 2060 'user_email' => array(2066 'user_email' => array( 2061 2067 'field' => 'user_email', 2062 2068 'expected' => array( 2063 'user_email' => 'admin@example.org',2069 'user_email' => WP_TESTS_EMAIL, 2064 2070 ), 2065 2071 ), 2066 'invalid_field' => array(2072 'invalid_field' => array( 2067 2073 'field' => 'invalid_field', 2068 2074 'expected' => array( 2069 2075 '0' => '1', 2076 ), 2077 ), 2078 'valid_array' => array( 2079 'field' => array( 'ID', 'display_name' ), 2080 'expected' => array( 2081 'ID' => '1', 2082 'display_name' => 'admin', 2083 ), 2084 ), 2085 'semivalid_array' => array( 2086 'field' => array( 'ID', 'display_name', 'invalid_field' ), 2087 'expected' => array( 2088 'ID' => '1', 2089 'display_name' => 'admin', 2090 ), 2091 ), 2092 'invalid_array' => array( 2093 'field' => array( 'invalid_field' ), 2094 'expected' => array( 2095 'ID' => '1', 2070 2096 ), 2071 2097 ),
Note: See TracChangeset
for help on using the changeset viewer.