Suppress query filters when called from get_posts(). see #7326 #7547

git-svn-id: http://svn.automattic.com/wordpress/trunk@8766 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-28 22:30:27 +00:00
parent c4919d8603
commit d927db8f2d
2 changed files with 37 additions and 24 deletions

View File

@ -453,7 +453,7 @@ function get_posts($args = null) {
'order' => 'DESC', 'include' => '', 'order' => 'DESC', 'include' => '',
'exclude' => '', 'meta_key' => '', 'exclude' => '', 'meta_key' => '',
'meta_value' =>'', 'post_type' => 'post', 'meta_value' =>'', 'post_type' => 'post',
'post_parent' => 0 'post_parent' => 0, 'suppress_filters' => true
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );

View File

@ -837,6 +837,9 @@ class WP_Query {
if ( !isset($q['caller_get_posts']) ) if ( !isset($q['caller_get_posts']) )
$q['caller_get_posts'] = false; $q['caller_get_posts'] = false;
if ( !isset($q['suppress_filters']) )
$q['suppress_filters'] = false;
if ( !isset($q['post_type']) ) { if ( !isset($q['post_type']) ) {
if ( $this->is_search ) if ( $this->is_search )
$q['post_type'] = 'any'; $q['post_type'] = 'any';
@ -1372,8 +1375,10 @@ class WP_Query {
// Apply filters on where and join prior to paging so that any // Apply filters on where and join prior to paging so that any
// manipulations to them are reflected in the paging by day queries. // manipulations to them are reflected in the paging by day queries.
$where = apply_filters('posts_where', $where); if ( !$q['suppress_filters'] ) {
$join = apply_filters('posts_join', $join); $where = apply_filters('posts_where', $where);
$join = apply_filters('posts_join', $join);
}
// Paging // Paging
if ( empty($q['nopaging']) && !$this->is_singular ) { if ( empty($q['nopaging']) && !$this->is_singular ) {
@ -1405,9 +1410,11 @@ class WP_Query {
$cgroupby = ''; $cgroupby = '';
} }
$cjoin = apply_filters('comment_feed_join', $cjoin); if ( !$q['suppress_filters'] ) {
$cwhere = apply_filters('comment_feed_where', $cwhere); $cjoin = apply_filters('comment_feed_join', $cjoin);
$cgroupby = apply_filters('comment_feed_groupby', $cgroupby); $cwhere = apply_filters('comment_feed_where', $cwhere);
$cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
}
$this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss')); $this->comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby ORDER BY comment_date_gmt DESC LIMIT " . get_option('posts_per_rss'));
$this->comment_count = count($this->comments); $this->comment_count = count($this->comments);
@ -1427,26 +1434,29 @@ class WP_Query {
// Apply post-paging filters on where and join. Only plugins that // Apply post-paging filters on where and join. Only plugins that
// manipulate paging queries should use these hooks. // manipulate paging queries should use these hooks.
if ( !$q['suppress_filters'] ) {
$where = apply_filters('posts_where_paged', $where); $where = apply_filters('posts_where_paged', $where);
$groupby = apply_filters('posts_groupby', $groupby); $groupby = apply_filters('posts_groupby', $groupby);
$join = apply_filters('posts_join_paged', $join); $join = apply_filters('posts_join_paged', $join);
$orderby = apply_filters('posts_orderby', $q['orderby']); $orderby = apply_filters('posts_orderby', $q['orderby']);
$distinct = apply_filters('posts_distinct', $distinct); $distinct = apply_filters('posts_distinct', $distinct);
$fields = apply_filters('posts_fields', "$wpdb->posts.*"); $fields = apply_filters('posts_fields', "$wpdb->posts.*");
$limits = apply_filters( 'post_limits', $limits ); $limits = apply_filters( 'post_limits', $limits );
}
// Announce current selection parameters. For use by caching plugins. // Announce current selection parameters. For use by caching plugins.
do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join ); do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
// Filter again for the benefit of caching plugins. Regular plugins should use the hooks above. // Filter again for the benefit of caching plugins. Regular plugins should use the hooks above.
$where = apply_filters('posts_where_request', $where); if ( !$q['suppress_filters'] ) {
$groupby = apply_filters('posts_groupby_request', $groupby); $where = apply_filters('posts_where_request', $where);
$join = apply_filters('posts_join_request', $join); $groupby = apply_filters('posts_groupby_request', $groupby);
$orderby = apply_filters('posts_orderby_request', $orderby); $join = apply_filters('posts_join_request', $join);
$distinct = apply_filters('posts_distinct_request', $distinct); $orderby = apply_filters('posts_orderby_request', $orderby);
$fields = apply_filters('posts_fields_request', $fields); $distinct = apply_filters('posts_distinct_request', $distinct);
$limits = apply_filters( 'post_limits_request', $limits ); $fields = apply_filters('posts_fields_request', $fields);
$limits = apply_filters( 'post_limits_request', $limits );
}
if ( ! empty($groupby) ) if ( ! empty($groupby) )
$groupby = 'GROUP BY ' . $groupby; $groupby = 'GROUP BY ' . $groupby;
@ -1457,11 +1467,13 @@ class WP_Query {
$found_rows = 'SQL_CALC_FOUND_ROWS'; $found_rows = 'SQL_CALC_FOUND_ROWS';
$request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits"; $request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
$this->request = apply_filters('posts_request', $request); if ( !$q['suppress_filters'] )
$this->request = apply_filters('posts_request', $request);
$this->posts = $wpdb->get_results($this->request); $this->posts = $wpdb->get_results($this->request);
// Raw results filter. Prior to status checks. // Raw results filter. Prior to status checks.
$this->posts = apply_filters('posts_results', $this->posts); if ( !$q['suppress_filters'] )
$this->posts = apply_filters('posts_results', $this->posts);
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
$cjoin = apply_filters('comment_feed_join', ''); $cjoin = apply_filters('comment_feed_join', '');
@ -1543,7 +1555,8 @@ class WP_Query {
} }
} }
$this->posts = apply_filters('the_posts', $this->posts); if ( !$q['suppress_filters'] )
$this->posts = apply_filters('the_posts', $this->posts);
update_post_caches($this->posts); update_post_caches($this->posts);