WordPress.org

Make WordPress Core

Changeset 15794


Ignore:
Timestamp:
10/13/2010 03:49:26 PM (8 years ago)
Author:
scribu
Message:

Add posts_clauses_request filter too. Props hakre. See #14997

File:
1 edited

Legend:

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

    r15791 r15794  
    21872187        // manipulate paging queries should use these hooks.
    21882188        if ( !$q['suppress_filters'] ) {
    2189             $where      = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
    2190             $groupby    = apply_filters_ref_array( 'posts_groupby',     array( $groupby, &$this ) );
    2191             $join       = apply_filters_ref_array( 'posts_join_paged',  array( $join, &$this ) );
    2192             $orderby    = apply_filters_ref_array( 'posts_orderby',     array( $orderby, &$this ) );
    2193             $distinct   = apply_filters_ref_array( 'posts_distinct',    array( $distinct, &$this ) );
    2194             $limits     = apply_filters_ref_array( 'post_limits',       array( $limits, &$this ) );
    2195             $fields     = apply_filters_ref_array( 'posts_fields',      array( $fields, &$this ) );
    2196 
    2197             // Also apply a filter on all clauses at once, for convenience
    2198             $clauses = array();
    2199             foreach ( array('distinct', 'fields', 'where', 'join', 'groupby', 'orderby', 'limits') as $var ) {
    2200                 $clauses[ $var ] = $$var;
    2201                 unset( $$var ); // so we can use EXTR_SKIP below
    2202             }
    2203 
    2204             $clauses = apply_filters_ref_array( 'wp_query_clauses', array( $clauses, &$this ) );
    2205 
    2206             extract( $clauses, EXTR_SKIP );
    2207             unset( $clauses );
     2189            $var_config = array(
     2190                'where'    => 'posts_where_paged',
     2191                'groupby'  => 'posts_groupby',
     2192                'join'     => 'posts_join_paged',
     2193                'orderby'  => 'posts_orderby',
     2194                'distinct' => 'posts_distinct',
     2195                'limits'   => 'post_limits',
     2196                'fields'   => 'posts_fields',
     2197            );
     2198            $var_values = compact( array_keys( $var_config ) );
     2199            $result = $this->_filter_clause_variables( $var_config, $var_values, 'posts_clauses' );
     2200            extract( $result );
    22082201        }
    22092202
     
    22132206        // Filter again for the benefit of caching plugins.  Regular plugins should use the hooks above.
    22142207        if ( !$q['suppress_filters'] ) {
    2215             $where      = apply_filters_ref_array( 'posts_where_request',       array( $where, &$this ) );
    2216             $groupby    = apply_filters_ref_array( 'posts_groupby_request',     array( $groupby, &$this ) );
    2217             $join       = apply_filters_ref_array( 'posts_join_request',        array( $join, &$this ) );
    2218             $orderby    = apply_filters_ref_array( 'posts_orderby_request',     array( $orderby, &$this ) );
    2219             $distinct   = apply_filters_ref_array( 'posts_distinct_request',    array( $distinct, &$this ) );
    2220             $fields     = apply_filters_ref_array( 'posts_fields_request',      array( $fields, &$this ) );
    2221             $limits     = apply_filters_ref_array( 'post_limits_request',       array( $limits, &$this ) );
     2208            $var_config = array(
     2209                'where'    => 'posts_where_request',
     2210                'groupby'  => 'posts_groupby_request',
     2211                'join'     => 'posts_join_request',
     2212                'orderby'  => 'posts_orderby_request',
     2213                'distinct' => 'posts_distinct_request',
     2214                'fields'   => 'posts_fields_request',
     2215                'limits'   => 'post_limits_request',
     2216            );
     2217            $var_values = compact( array_keys( $var_config ) );
     2218            $result = $this->_filter_clause_variables( $var_config, $var_values, 'posts_clauses_request' );
     2219            extract( $result );
    22222220        }
    22232221
     
    23602358        return $this->posts;
    23612359    }
     2360   
     2361    /**
     2362     * Filter clause variables based on configuration. Once per clause and
     2363     * then all clauses at once.
     2364     *
     2365     * @access private
     2366     * @param array $config filternames keyed with their variable names
     2367     * @param array $values values keyed with their variable names
     2368     * @param string $all_filter_name for the "single filter"
     2369     * @return array filtered values keyed with their names
     2370     */
     2371    function _filter_clause_variables( $config, $values, $all_filter_name ) {
     2372        $clauses = array();
     2373        foreach ( $config as $variable_name => $filter ) {
     2374            $clauses[$variable_name] = apply_filters_ref_array( $filter, array( $values[$variable_name], &$this ) );
     2375        }
     2376        // run filter for all clauses at once
     2377        $clauses = apply_filters_ref_array( $all_filter_name, array( $clauses, &$this ) );
     2378        $is_array = is_array( $clauses );
     2379        $filtered = array();
     2380        foreach ( $config as $variable_name => $filter ) {
     2381            if ( $is_array && isset( $clauses[$variable_name] ) ) {
     2382                $filtered[$variable_name] = $clauses[$variable_name];
     2383            } else {
     2384                $filtered[$variable_name] = '';
     2385            }
     2386        }
     2387        return $filtered;
     2388    }
    23622389
    23632390    /**
Note: See TracChangeset for help on using the changeset viewer.