WordPress.org

Make WordPress Core

Ticket #7326: 7326.diff

File 7326.diff, 5.0 KB (added by ryan, 10 years ago)

Suppress filters for get_posts()

  • wp-includes/post.php

     
    451451                'order' => 'DESC', 'include' => '',
    452452                'exclude' => '', 'meta_key' => '',
    453453                'meta_value' =>'', 'post_type' => 'post',
    454                 'post_parent' => 0
     454                'post_parent' => 0, 'suppress_filters' => true
    455455        );
    456456
    457457        $r = wp_parse_args( $args, $defaults );
  • wp-includes/query.php

     
    837837                if ( !isset($q['caller_get_posts']) )
    838838                        $q['caller_get_posts'] = false;
    839839
     840                if ( !isset($q['suppress_filters']) )
     841                        $q['suppress_filters'] = false;
     842
    840843                if ( !isset($q['post_type']) ) {
    841844                        if ( $this->is_search )
    842845                                $q['post_type'] = 'any';
     
    13671370
    13681371                // Apply filters on where and join prior to paging so that any
    13691372                // manipulations to them are reflected in the paging by day queries.
    1370                 $where = apply_filters('posts_where', $where);
    1371                 $join = apply_filters('posts_join', $join);
     1373                if ( !$q['suppress_filters'] ) {
     1374                        $where = apply_filters('posts_where', $where);
     1375                        $join = apply_filters('posts_join', $join);
     1376                }
    13721377
    13731378                // Paging
    13741379                if ( empty($q['nopaging']) && !$this->is_singular ) {
     
    14001405                                $cgroupby = '';
    14011406                        }
    14021407
    1403                         $cjoin = apply_filters('comment_feed_join', $cjoin);
    1404                         $cwhere = apply_filters('comment_feed_where', $cwhere);
    1405                         $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
     1408                        if ( !$q['suppress_filters'] ) {
     1409                                $cjoin = apply_filters('comment_feed_join', $cjoin);
     1410                                $cwhere = apply_filters('comment_feed_where', $cwhere);
     1411                                $cgroupby = apply_filters('comment_feed_groupby', $cgroupby);
     1412                        }
    14061413
    14071414                        $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'));
    14081415                        $this->comment_count = count($this->comments);
     
    14221429
    14231430                // Apply post-paging filters on where and join.  Only plugins that
    14241431                // manipulate paging queries should use these hooks.
     1432                if ( !$q['suppress_filters'] ) {
     1433                        $where = apply_filters('posts_where_paged', $where);
     1434                        $groupby = apply_filters('posts_groupby', $groupby);
     1435                        $join = apply_filters('posts_join_paged', $join);
     1436                        $orderby = apply_filters('posts_orderby', $q['orderby']);
     1437                        $distinct = apply_filters('posts_distinct', $distinct);
     1438                        $fields = apply_filters('posts_fields', "$wpdb->posts.*");
     1439                        $limits = apply_filters( 'post_limits', $limits );
     1440                }
    14251441
    1426                 $where = apply_filters('posts_where_paged', $where);
    1427                 $groupby = apply_filters('posts_groupby', $groupby);
    1428                 $join = apply_filters('posts_join_paged', $join);
    1429                 $orderby = apply_filters('posts_orderby', $q['orderby']);
    1430                 $distinct = apply_filters('posts_distinct', $distinct);
    1431                 $fields = apply_filters('posts_fields', "$wpdb->posts.*");
    1432                 $limits = apply_filters( 'post_limits', $limits );
    1433 
    14341442                // Announce current selection parameters.  For use by caching plugins.
    14351443                do_action( 'posts_selection', $where . $groupby . $orderby . $limits . $join );
    14361444
    14371445                // Filter again for the benefit of caching plugins.  Regular plugins should use the hooks above.
    1438                 $where = apply_filters('posts_where_request', $where);
    1439                 $groupby = apply_filters('posts_groupby_request', $groupby);
    1440                 $join = apply_filters('posts_join_request', $join);
    1441                 $orderby = apply_filters('posts_orderby_request', $orderby);
    1442                 $distinct = apply_filters('posts_distinct_request', $distinct);
    1443                 $fields = apply_filters('posts_fields_request', $fields);
    1444                 $limits = apply_filters( 'post_limits_request', $limits );
     1446                if ( !$q['suppress_filters'] ) {
     1447                        $where = apply_filters('posts_where_request', $where);
     1448                        $groupby = apply_filters('posts_groupby_request', $groupby);
     1449                        $join = apply_filters('posts_join_request', $join);
     1450                        $orderby = apply_filters('posts_orderby_request', $orderby);
     1451                        $distinct = apply_filters('posts_distinct_request', $distinct);
     1452                        $fields = apply_filters('posts_fields_request', $fields);
     1453                        $limits = apply_filters( 'post_limits_request', $limits );
     1454                }
    14451455
    14461456                if ( ! empty($groupby) )
    14471457                        $groupby = 'GROUP BY ' . $groupby;
     
    14521462                        $found_rows = 'SQL_CALC_FOUND_ROWS';
    14531463
    14541464                $request = " SELECT $found_rows $distinct $fields FROM $wpdb->posts $join WHERE 1=1 $where $groupby $orderby $limits";
    1455                 $this->request = apply_filters('posts_request', $request);
     1465                if ( !$q['suppress_filters'] )
     1466                        $this->request = apply_filters('posts_request', $request);
    14561467
    14571468                $this->posts = $wpdb->get_results($this->request);
    14581469                // Raw results filter.  Prior to status checks.
    1459                 $this->posts = apply_filters('posts_results', $this->posts);
     1470                if ( !$q['suppress_filters'] )
     1471                        $this->posts = apply_filters('posts_results', $this->posts);
    14601472
    14611473                if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
    14621474                        $cjoin = apply_filters('comment_feed_join', '');