Ticket #14997: 14997-notices.patch

File 14997-notices.patch, 2.9 KB (added by hakre, 3 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 
     2189                        // clause filter variables 
     2190                        $variables = array( 
     2191                                'distinct' => 'posts_distinct',  
     2192                                'fields'   => 'posts_fields',  
     2193                                'where'    => 'posts_where_paged',  
     2194                                'join'     => 'posts_join_paged',  
     2195                                'groupby'  => 'posts_groupby',  
     2196                                'orderby'  => 'posts_orderby',  
     2197                                'limits'   => 'post_limits',  
     2198                        ); 
     2199                        // build clauses array and run filters once per clause 
    21982200                        $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 
     2201                        foreach ( $variables as $variable_name => $filter_name ) { 
     2202                                $clauses[ $variable_name ] = apply_filters_ref_array( $filter_name, array( $$variable_name, &$this ) ); 
     2203                                unset( $$variable_name ); // for extract() with EXTR_SKIP parameter 
    22022204                        } 
    2203  
     2205                        // run filter for all clauses at once 
    22042206                        $clauses = apply_filters_ref_array( 'wp_query_clauses', array( $clauses, &$this ) ); 
    2205  
    2206                         extract( $clauses, EXTR_SKIP ); 
     2207                        if ( is_array( $clauses ) ) { 
     2208                                extract( $clauses, EXTR_SKIP ); 
     2209                        } 
    22072210                        unset( $clauses ); 
     2211                        // prevent notices in case a filter removed clause variable(s) 
     2212                        foreach ( $variables as $variable_name => $filter_name ) { 
     2213                                if ( !isset( ${$variable_name} ) ) { 
     2214                                        $$variable_name = ''; 
     2215                                } 
     2216                        } 
    22082217                } 
    22092218 
    22102219                // Announce current selection parameters.  For use by caching plugins. 
     
    22232232 
    22242233                if ( ! empty($groupby) ) 
    22252234                        $groupby = 'GROUP BY ' . $groupby; 
    2226                 if ( !empty( $orderby ) ) 
     2235                if ( ! empty( $orderby ) ) 
    22272236                        $orderby = 'ORDER BY ' . $orderby; 
    22282237                $found_rows = ''; 
    2229                 if ( !$q['no_found_rows'] && !empty($limits) ) 
     2238                if ( !$q['no_found_rows'] && ! empty( $limits ) ) 
    22302239                        $found_rows = 'SQL_CALC_FOUND_ROWS'; 
    22312240 
    22322241                $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";