Make WordPress Core

Ticket #14997: 14997-extract-if-complete.patch

File 14997-extract-if-complete.patch, 4.3 KB (added by hakre, 15 years ago)
  • wp-includes/query.php

     
    21862186                // Apply post-paging filters on where and join.  Only plugins that
    21872187                // manipulate paging queries should use these hooks.
    21882188                if ( !$q['suppress_filters'] ) {
    2189                         $distinct       = apply_filters_ref_array( 'posts_distinct',    array( $distinct, &$this ) );
    2190                         $fields         = apply_filters_ref_array( 'posts_fields',              array( $fields, &$this ) );
    2191                         $where          = apply_filters_ref_array( 'posts_where_paged', array( $where, &$this ) );
    2192                         $join           = apply_filters_ref_array( 'posts_join_paged',  array( $join, &$this ) );
    2193                         $groupby        = apply_filters_ref_array( 'posts_groupby',             array( $groupby, &$this ) );
    2194                         $orderby        = apply_filters_ref_array( 'posts_orderby',             array( $orderby, &$this ) );
    2195                         $limits         = apply_filters_ref_array( 'post_limits',               array( $limits, &$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
    22102203                // Announce current selection parameters.  For use by caching plugins.
     
    22122205
    22132206                // Filter again for the benefit of caching plugins.  Regular plugins should use the hooks above.
    22142207                if ( !$q['suppress_filters'] ) {
    2215                         $distinct       = apply_filters_ref_array( 'posts_distinct_request',array( $distinct, &$this ) );
    2216                         $fields         = apply_filters_ref_array( 'posts_fields_request',      array( $fields, &$this ) );
    2217                         $where          = apply_filters_ref_array( 'posts_where_request',       array( $where, &$this ) );
    2218                         $join           = apply_filters_ref_array( 'posts_join_request',        array( $join, &$this ) );
    2219                         $groupby        = apply_filters_ref_array( 'posts_groupby_request',     array( $groupby, &$this ) );
    2220                         $orderby        = apply_filters_ref_array( 'posts_orderby_request',     array( $orderby, &$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
    22242222                if ( ! empty($groupby) )
     
    23612359        }
    23622360
    23632361        /**
     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                if ( is_array( $clauses ) && array_keys( $clauses ) === array_keys( $values ) ) {
     2379                        $values = $clauses;
     2380                }
     2381                return $values;
     2382        }
     2383
     2384        /**
    23642385         * Set up the next post and iterate current post index.
    23652386         *
    23662387         * @since 1.5.0