Make WordPress Core

Changeset 17552


Ignore:
Timestamp:
03/24/2011 04:07:24 PM (13 years ago)
Author:
ryan
Message:

Parse the meta query again if query vars change. Set a global query_vars_changed flag instead of doing multiple hash creation calls. Props greuben. see #16742 for trunk

File:
1 edited

Legend:

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

    r17528 r17552  
    12391239     */
    12401240    var $query_vars_hash = false;
     1241
     1242    /**
     1243     * Whether query vars have changed since the initial parse_query() call.  Used to catch modifications to query vars made
     1244     * via pre_get_posts hooks.
     1245     *
     1246     * @since 3.1.1
     1247     * @access private
     1248     */
     1249    var $query_vars_changed = true;
    12411250
    12421251    /**
     
    13961405        $this->query_vars = $this->fill_query_vars($this->query_vars);
    13971406        $qv = &$this->query_vars;
     1407        $this->query_vars_changed = true;
    13981408
    13991409        if ( ! empty($qv['robots']) )
     
    16281638            $this->set_404();
    16291639
     1640        $this->query_vars_hash = md5( serialize( $this->query_vars ) );
     1641        $this->query_vars_changed = false;
     1642
    16301643        do_action_ref_array('parse_query', array(&$this));
    16311644    }
     
    16861699
    16871700        // Category stuff
    1688         if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular && md5(serialize( $this->query_vars ) ) != $this->query_vars_hash ) {
     1701        if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular && $this->query_vars_changed ) {
    16891702            $q['cat'] = ''.urldecode($q['cat']).'';
    16901703            $q['cat'] = addslashes_gpc($q['cat']);
     
    17401753
    17411754        // Tag stuff
    1742         if ( '' != $q['tag'] && !$this->is_singular && md5(serialize( $this->query_vars ) ) != $this->query_vars_hash ) {
     1755        if ( '' != $q['tag'] && !$this->is_singular && $this->query_vars_changed ) {
    17431756            if ( strpos($q['tag'], ',') !== false ) {
    17441757                $tags = preg_split('/[,\s]+/', $q['tag']);
     
    18121825        }
    18131826
    1814         $this->query_vars_hash = md5(serialize( $this->query_vars ) );
    1815 
    18161827        $this->tax_query = new WP_Tax_Query( $tax_query );
    18171828    }
     
    18831894        $q = &$this->query_vars;
    18841895
     1896        // Fill again in case pre_get_posts unset some vars.
    18851897        $q = $this->fill_query_vars($q);
     1898
     1899        // Set a flag if a pre_get_posts hook changed the query vars.
     1900        $hash = md5( serialize( $this->query_vars ) );
     1901        if ( $hash != $this->query_vars_hash ) {
     1902            $this->query_vars_changed = true;
     1903            $this->query_vars_hash = $hash;
     1904        }
     1905        unset($hash);
    18861906
    18871907        // First let's clear some variables
     
    24432463
    24442464            $where .= ')';
     2465        }
     2466
     2467        // Parse the meta query again if query vars have changed.
     2468        if ( $this->query_vars_changed ) {
     2469            $meta_query_hash = md5( serialize( $q['meta_query'] ) );
     2470            $_meta_query = $q['meta_query'];
     2471            unset( $q['meta_query'] );
     2472            _parse_meta_query( $q );
     2473            if ( md5( serialize( $q['meta_query'] ) ) != $meta_query_hash && is_array( $_meta_query ) )
     2474                $q['meta_query'] = array_merge( $_meta_query, $q['meta_query'] );
    24452475        }
    24462476
Note: See TracChangeset for help on using the changeset viewer.