Ticket #9886: apply_filters_ref_array.2.diff
File apply_filters_ref_array.2.diff, 9.4 KB (added by , 15 years ago) |
---|
-
wp-includes/plugin.php
174 174 } 175 175 176 176 /** 177 * Execute functions hooked on a specific filter hook, specifying arguments in an array. 178 * 179 * @see apply_filters() This function is identical, but the arguments passed to the 180 * functions hooked to <tt>$tag</tt> are supplied using an array. 181 * 182 * @package WordPress 183 * @subpackage Plugin 184 * @since 3.0 185 * @global array $wp_filter Stores all of the filters 186 * @global array $merged_filters Merges the filter hooks using this function. 187 * @global array $wp_current_filter stores the list of current filters with the current one last 188 * 189 * @param string $tag The name of the filter hook. 190 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt> 191 * @return mixed The filtered value after all hooked functions are applied to it. 192 */ 193 function apply_filters_ref_array($tag, $args) { 194 global $wp_filter, $merged_filters, $wp_current_filter; 195 196 $wp_current_filter[] = $tag; 197 198 $value = $args[0]; 199 200 // Do 'all' actions first 201 if ( isset($wp_filter['all']) ) { 202 $all_args = func_get_args(); 203 _wp_call_all_hook($all_args); 204 } 205 206 if ( !isset($wp_filter[$tag]) ) { 207 array_pop($wp_current_filter); 208 return $value; 209 } 210 211 // Sort 212 if ( !isset( $merged_filters[ $tag ] ) ) { 213 ksort($wp_filter[$tag]); 214 $merged_filters[ $tag ] = true; 215 } 216 217 reset( $wp_filter[ $tag ] ); 218 219 do { 220 foreach( (array) current($wp_filter[$tag]) as $the_ ) 221 if ( !is_null($the_['function']) ) 222 $value = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); 223 224 } while ( next($wp_filter[$tag]) !== false ); 225 226 array_pop( $wp_current_filter ); 227 228 return $value; 229 } 230 231 /** 177 232 * Removes a function from a specified filter hook. 178 233 * 179 234 * This function removes a function attached to a specified filter hook. This -
wp-includes/query.php
1765 1765 $search .= " AND ($wpdb->posts.post_password = '') "; 1766 1766 } 1767 1767 } 1768 $search = apply_filters ('posts_search', $search, $this);1768 $search = apply_filters_ref_array('posts_search', array($search, &$this)); 1769 1769 1770 1770 // Category stuff 1771 1771 … … 2196 2196 // Apply filters on where and join prior to paging so that any 2197 2197 // manipulations to them are reflected in the paging by day queries. 2198 2198 if ( !$q['suppress_filters'] ) { 2199 $where = apply_filters ('posts_where', $where);2200 $join = apply_filters ('posts_join', $join);2199 $where = apply_filters_ref_array('posts_where', array($where, &$this)); 2200 $join = apply_filters_ref_array('posts_join', array($join, &$this)); 2201 2201 } 2202 2202 2203 2203 // Paging … … 2231 2231 } 2232 2232 2233 2233 if ( !$q['suppress_filters'] ) { 2234 $cjoin = apply_filters ('comment_feed_join', $cjoin);2235 $cwhere = apply_filters ('comment_feed_where', $cwhere);2236 $cgroupby = apply_filters ('comment_feed_groupby', $cgroupby);2237 $corderby = apply_filters ('comment_feed_orderby', 'comment_date_gmt DESC');2238 $climits = apply_filters ('comment_feed_limits', 'LIMIT ' . get_option('posts_per_rss'));2234 $cjoin = apply_filters_ref_array('comment_feed_join', array($cjoin, &$this)); 2235 $cwhere = apply_filters_ref_array('comment_feed_where', array($cwhere, &$this)); 2236 $cgroupby = apply_filters_ref_array('comment_feed_groupby', array($cgroupby, &$this)); 2237 $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); 2238 $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT ' . get_option('posts_per_rss'), &$this)); 2239 2239 } 2240 2240 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 2241 2241 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; … … 2261 2261 // Apply post-paging filters on where and join. Only plugins that 2262 2262 // manipulate paging queries should use these hooks. 2263 2263 if ( !$q['suppress_filters'] ) { 2264 $where = apply_filters('posts_where_paged', $where); 2265 $groupby = apply_filters('posts_groupby', $groupby); 2266 $join = apply_filters('posts_join_paged', $join); 2267 $orderby = apply_filters('posts_orderby', $orderby); 2268 $distinct = apply_filters('posts_distinct', $distinct); 2269 $limits = apply_filters( 'post_limits', $limits ); 2270 2271 $fields = apply_filters('posts_fields', $fields); 2264 $where = apply_filters_ref_array('posts_where_paged', array($where, &$this)); 2265 $groupby = apply_filters_ref_array('posts_groupby', array($groupby, &$this)); 2266 $join = apply_filters_ref_array('posts_join_paged', array($join, &$this)); 2267 $orderby = apply_filters_ref_array('posts_orderby', array($orderby, &$this)); 2268 $distinct = apply_filters_ref_array('posts_distinct', array($distinct, &$this)); 2269 $limits = apply_filters_ref_array('post_limits', array($limits , &$this)); 2270 $fields = apply_filters_ref_array('posts_fields', array($fields, &$this)); 2272 2271 } 2273 2272 2274 2273 // Announce current selection parameters. For use by caching plugins. … … 2276 2275 2277 2276 // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above. 2278 2277 if ( !$q['suppress_filters'] ) { 2279 $where = apply_filters ('posts_where_request', $where);2280 $groupby = apply_filters ('posts_groupby_request', $groupby);2281 $join = apply_filters ('posts_join_request', $join);2282 $orderby = apply_filters ('posts_orderby_request', $orderby);2283 $distinct = apply_filters ('posts_distinct_request', $distinct);2284 $fields = apply_filters ('posts_fields_request', $fields);2285 $limits = apply_filters ( 'post_limits_request', $limits);2278 $where = apply_filters_ref_array('posts_where_request', array($where, &$this)); 2279 $groupby = apply_filters_ref_array('posts_groupby_request', array($groupby, &$this)); 2280 $join = apply_filters_ref_array('posts_join_request', array($join, &$this)); 2281 $orderby = apply_filters_ref_array('posts_orderby_request', array($orderby, &$this)); 2282 $distinct = apply_filters_ref_array('posts_distinct_request', array($distinct, &$this)); 2283 $fields = apply_filters_ref_array('posts_fields_request', array($fields, &$this)); 2284 $limits = apply_filters_ref_array('post_limits_request', array($limits , &$this)); 2286 2285 } 2287 2286 2288 2287 if ( ! empty($groupby) ) … … 2295 2294 2296 2295 $this->request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; 2297 2296 if ( !$q['suppress_filters'] ) 2298 $this->request = apply_filters ('posts_request', $this->request);2297 $this->request = apply_filters_ref_array('posts_request', array($this->request, &$this)); 2299 2298 2300 2299 $this->posts = $wpdb->get_results($this->request); 2301 2300 // Raw results filter. Prior to status checks. 2302 2301 if ( !$q['suppress_filters'] ) 2303 $this->posts = apply_filters ('posts_results', $this->posts);2302 $this->posts = apply_filters_ref_array('posts_results', array($this->posts, &$this)); 2304 2303 2305 2304 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { 2306 $cjoin = apply_filters ('comment_feed_join', '');2307 $cwhere = apply_filters ('comment_feed_where', "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'");2308 $cgroupby = apply_filters ('comment_feed_groupby', '');2305 $cjoin = apply_filters_ref_array('comment_feed_join', array('', &$this)); 2306 $cwhere = apply_filters_ref_array('comment_feed_where', array("WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this)); 2307 $cgroupby = apply_filters_ref_array('comment_feed_groupby', array('', &$this)); 2309 2308 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 2310 $corderby = apply_filters ('comment_feed_orderby', 'comment_date_gmt DESC');2309 $corderby = apply_filters_ref_array('comment_feed_orderby', array('comment_date_gmt DESC', &$this)); 2311 2310 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 2312 $climits = apply_filters ('comment_feed_limits', 'LIMIT ' . get_option('posts_per_rss'));2311 $climits = apply_filters_ref_array('comment_feed_limits', array('LIMIT ' . get_option('posts_per_rss'), &$this)); 2313 2312 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits"; 2314 2313 $this->comments = $wpdb->get_results($comments_request); 2315 2314 $this->comment_count = count($this->comments); 2316 2315 } 2317 2316 2318 2317 if ( !empty($limits) ) { 2319 $found_posts_query = apply_filters ( 'found_posts_query', 'SELECT FOUND_ROWS()');2318 $found_posts_query = apply_filters_ref_array( 'found_posts_query', array('SELECT FOUND_ROWS()' , &$this)); 2320 2319 $this->found_posts = $wpdb->get_var( $found_posts_query ); 2321 $this->found_posts = apply_filters ( 'found_posts', $this->found_posts);2320 $this->found_posts = apply_filters_ref_array( 'found_posts', array($this->found_posts , &$this)); 2322 2321 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 2323 2322 } 2324 2323 … … 2351 2350 } 2352 2351 2353 2352 if ( $this->is_preview && current_user_can( $edit_cap, $this->posts[0]->ID ) ) 2354 $this->posts[0] = apply_filters ('the_preview', $this->posts[0]);2353 $this->posts[0] = apply_filters_ref_array('the_preview', array($this->posts[0], &$this)); 2355 2354 } 2356 2355 2357 2356 // Put sticky posts at the top of the posts array … … 2400 2399 } 2401 2400 2402 2401 if ( !$q['suppress_filters'] ) 2403 $this->posts = apply_filters ('the_posts', $this->posts);2402 $this->posts = apply_filters_ref_array('the_posts', array($this->posts, &$this)); 2404 2403 2405 2404 $this->post_count = count($this->posts); 2406 2405