WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/04/2016 06:56:58 PM (6 years ago)
Author:
boonebgorges
Message:

Users: The 'who' parameter should not interfere with 'meta_key' + 'meta_value' in WP_User_Query.

Props adrianosilvaferreira.
Fixes #36724.

File:
1 edited

Legend:

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

    r36417 r37360  
    256256        }
    257257
    258         if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
    259             $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
    260             $qv['meta_value'] = 0;
    261             $qv['meta_compare'] = '!=';
    262             $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
    263         }
    264 
    265258        if ( $qv['has_published_posts'] && $blog_id ) {
    266259            if ( true === $qv['has_published_posts'] ) {
     
    281274        $this->meta_query = new WP_Meta_Query();
    282275        $this->meta_query->parse_query_vars( $qv );
     276
     277        if ( isset( $qv['who'] ) && 'authors' == $qv['who'] && $blog_id ) {
     278            $who_query = array(
     279                'key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level',
     280                'value' => 0,
     281                'compare' => '!=',
     282            );
     283
     284            // Prevent extra meta query.
     285            $qv['blog_id'] = $blog_id = 0;
     286
     287            if ( empty( $this->meta_query->queries ) ) {
     288                $this->meta_query->queries = array( $who_query );
     289            } else {
     290                // Append the cap query to the original queries and reparse the query.
     291                $this->meta_query->queries = array(
     292                    'relation' => 'AND',
     293                    array( $this->meta_query->queries, $who_query ),
     294                );
     295            }
     296
     297            $this->meta_query->parse_query_vars( $this->meta_query->queries );
     298        }
    283299
    284300        $roles = array();
Note: See TracChangeset for help on using the changeset viewer.