WordPress.org

Make WordPress Core

Changeset 31665


Ignore:
Timestamp:
03/07/2015 04:34:42 PM (6 years ago)
Author:
boonebgorges
Message:

In WP_User_Query, $meta_query should be a class property rather than a local variable.

This provides better parity with other query classes, and makes it possible to
write more direct unit tests.

See #31265.

File:
1 edited

Legend:

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

    r31664 r31665  
    473473     */
    474474    private $total_users = 0;
     475
     476    /**
     477     * Metadata query container.
     478     *
     479     * @since 4.2.0
     480     * @access public
     481     * @var object WP_Meta_Query
     482     */
     483    public $meta_query = false;
    475484
    476485    private $compat_fields = array( 'results', 'total_users' );
     
    731740        }
    732741
    733         $meta_query = new WP_Meta_Query();
    734         $meta_query->parse_query_vars( $qv );
     742        $this->meta_query = new WP_Meta_Query();
     743        $this->meta_query->parse_query_vars( $qv );
    735744
    736745        $role = '';
     
    747756            }
    748757
    749             if ( empty( $meta_query->queries ) ) {
    750                 $meta_query->queries = array( $cap_meta_query );
    751             } elseif ( ! in_array( $cap_meta_query, $meta_query->queries, true ) ) {
     758            if ( empty( $this->meta_query->queries ) ) {
     759                $this->meta_query->queries = array( $cap_meta_query );
     760            } elseif ( ! in_array( $cap_meta_query, $this->meta_query->queries, true ) ) {
    752761                // Append the cap query to the original queries and reparse the query.
    753                 $meta_query->queries = array(
     762                $this->meta_query->queries = array(
    754763                    'relation' => 'AND',
    755                     array( $meta_query->queries, $cap_meta_query ),
     764                    array( $this->meta_query->queries, $cap_meta_query ),
    756765                );
    757766            }
    758767
    759             $meta_query->parse_query_vars( $meta_query->queries );
    760         }
    761 
    762         if ( !empty( $meta_query->queries ) ) {
    763             $clauses = $meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
     768            $this->meta_query->parse_query_vars( $this->meta_query->queries );
     769        }
     770
     771        if ( !empty( $this->meta_query->queries ) ) {
     772            $clauses = $this->meta_query->get_sql( 'user', $wpdb->users, 'ID', $this );
    764773            $this->query_from .= $clauses['join'];
    765774            $this->query_where .= $clauses['where'];
    766775
    767             if ( 'OR' == $meta_query->relation )
     776            if ( 'OR' == $this->meta_query->relation )
    768777                $this->query_fields = 'DISTINCT ' . $this->query_fields;
    769778        }
Note: See TracChangeset for help on using the changeset viewer.