Ticket #36904: 36904.3.patch
File 36904.3.patch, 9.6 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-comment-query.php
254 254 * Default true. 255 255 * @type bool $update_comment_post_cache Whether to prime the cache for comment posts. 256 256 * Default false. 257 * @type bool $do_comment_feed_filters Whether do comment feed filters. Default false. 257 258 * } 258 259 */ 259 260 public function __construct( $query = '' ) { … … 301 302 'hierarchical' => false, 302 303 'update_comment_meta_cache' => true, 303 304 'update_comment_post_cache' => false, 305 'do_comment_feed_filters' => false, 304 306 ); 305 307 306 308 if ( ! empty( $query ) ) { … … 482 484 * @global wpdb $wpdb WordPress database abstraction object. 483 485 */ 484 486 protected function get_comment_ids() { 485 global $wp db;487 global $wp_query, $wpdb; 486 488 487 489 // Assemble clauses related to 'comment_approved'. 488 490 $approved_clauses = array(); … … 650 652 } 651 653 } 652 654 655 if ( $this->query_vars['do_comment_feed_filters'] ) { 656 /** 657 * Filters the LIMIT clause of the comments feed query before sending. 658 * 659 * @since 2.8.0 660 * 661 * @param string $climits The JOIN clause of the query. 662 * @param WP_Query $wp_query The WP_Query global. 663 */ 664 $limits = apply_filters( 'comment_feed_limits', $limits, $wp_query ); 665 } 666 653 667 if ( $this->query_vars['count'] ) { 654 668 $fields = 'COUNT(*)'; 655 669 } else { … … 841 855 } 842 856 } 843 857 858 if ( $this->query_vars['do_comment_feed_filters'] ) { 859 /** 860 * Filters the LIMIT clause of the comments feed query before sending. 861 * 862 * @since 2.8.0 863 * 864 * @param string $climits The JOIN clause of the query. 865 * @param WP_Query $wp_query The WP_Query global. 866 */ 867 $join = apply_filters( 'comment_feed_join', $join, $wp_query ); 868 } 869 844 870 if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) { 845 871 $this->date_query = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' ); 846 872 $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() ); … … 868 894 869 895 $this->filtered_where_clause = $where; 870 896 897 if ( $this->query_vars['do_comment_feed_filters'] ) { 898 /** 899 * Filters the WHERE clause of the comments feed query before sending. 900 * 901 * @since 2.2.0 902 * 903 * @param string $cwhere The WHERE clause of the query. 904 * @param WP_Query $wp_query The WP_Query global. 905 */ 906 $where = apply_filters( 'comment_feed_where', $where, $wp_query ); 907 } 908 871 909 if ( $where ) { 872 910 $where = 'WHERE ' . $where; 873 911 } 874 912 913 if ( $this->query_vars['do_comment_feed_filters'] ) { 914 /** 915 * Filters the GROUP BY clause of the comments feed query before sending. 916 * 917 * @since 2.2.0 918 * 919 * @param string $cgroupby The GROUP BY clause of the query. 920 * @param WP_Query $wp_query The WP_Query global. 921 */ 922 $groupby = apply_filters( 'comment_feed_groupby', $groupby, $wp_query ); 923 } 924 875 925 if ( $groupby ) { 876 926 $groupby = 'GROUP BY ' . $groupby; 877 927 } 878 928 929 if ( $this->query_vars['do_comment_feed_filters'] ) { 930 /** 931 * Filters the ORDER BY clause of the comments feed query before sending. 932 * 933 * @since 2.8.0 934 * 935 * @param string $corderby The ORDER BY clause of the query. 936 * @param WP_Query $wp_query The WP_Query global. 937 */ 938 $orderby = apply_filters( 'comment_feed_orderby', $orderby, $wp_query ); 939 } 940 879 941 if ( $orderby ) { 880 942 $orderby = "ORDER BY $orderby"; 881 943 } -
src/wp-includes/query.php
3214 3214 $limits = 'LIMIT ' . $pgstrt . $q['posts_per_page']; 3215 3215 } 3216 3216 3217 // Comments feeds3218 if ( $this->is_comment_feed && ! $this->is_singular ) {3219 if ( $this->is_archive || $this->is_search ) {3220 $cjoin = "JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) $join ";3221 $cwhere = "WHERE comment_approved = '1' $where";3222 $cgroupby = "$wpdb->comments.comment_id";3223 } else { // Other non singular e.g. front3224 $cjoin = "JOIN $wpdb->posts ON ( $wpdb->comments.comment_post_ID = $wpdb->posts.ID )";3225 $cwhere = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' && post_type = 'attachment' ) ) AND comment_approved = '1'";3226 $cgroupby = '';3227 }3228 3229 if ( !$q['suppress_filters'] ) {3230 /**3231 * Filters the JOIN clause of the comments feed query before sending.3232 *3233 * @since 2.2.03234 *3235 * @param string $cjoin The JOIN clause of the query.3236 * @param WP_Query &$this The WP_Query instance (passed by reference).3237 */3238 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( $cjoin, &$this ) );3239 3240 /**3241 * Filters the WHERE clause of the comments feed query before sending.3242 *3243 * @since 2.2.03244 *3245 * @param string $cwhere The WHERE clause of the query.3246 * @param WP_Query &$this The WP_Query instance (passed by reference).3247 */3248 $cwhere = apply_filters_ref_array( 'comment_feed_where', array( $cwhere, &$this ) );3249 3250 /**3251 * Filters the GROUP BY clause of the comments feed query before sending.3252 *3253 * @since 2.2.03254 *3255 * @param string $cgroupby The GROUP BY clause of the query.3256 * @param WP_Query &$this The WP_Query instance (passed by reference).3257 */3258 $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( $cgroupby, &$this ) );3259 3260 /**3261 * Filters the ORDER BY clause of the comments feed query before sending.3262 *3263 * @since 2.8.03264 *3265 * @param string $corderby The ORDER BY clause of the query.3266 * @param WP_Query &$this The WP_Query instance (passed by reference).3267 */3268 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );3269 3270 /**3271 * Filters the LIMIT clause of the comments feed query before sending.3272 *3273 * @since 2.8.03274 *3275 * @param string $climits The JOIN clause of the query.3276 * @param WP_Query &$this The WP_Query instance (passed by reference).3277 */3278 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) );3279 }3280 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';3281 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';3282 3283 $comments = (array) $wpdb->get_results("SELECT $distinct $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits");3284 // Convert to WP_Comment3285 $this->comments = array_map( 'get_comment', $comments );3286 $this->comment_count = count($this->comments);3287 3288 $post_ids = array();3289 3290 foreach ( $this->comments as $comment )3291 $post_ids[] = (int) $comment->comment_post_ID;3292 3293 $post_ids = join(',', $post_ids);3294 $join = '';3295 if ( $post_ids )3296 $where = "AND $wpdb->posts.ID IN ($post_ids) ";3297 else3298 $where = "AND 0";3299 }3300 3301 3217 $pieces = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' ); 3302 3218 3303 3219 /* … … 3634 3550 $this->posts = apply_filters_ref_array( 'posts_results', array( $this->posts, &$this ) ); 3635 3551 } 3636 3552 3637 if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) { 3638 /** This filter is documented in wp-includes/query.php */ 3639 $cjoin = apply_filters_ref_array( 'comment_feed_join', array( '', &$this ) ); 3553 if ( ! empty( $this->posts ) && $this->is_comment_feed ) { 3640 3554 3641 /** This filter is documented in wp-includes/query.php */ 3642 $cwhere = apply_filters_ref_array( 'comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) ); 3555 $comment_args = array( 3556 'orderby' => 'comment_date_gmt', 3557 'order' => 'DESC', 3558 'status' => 'approve', 3559 'post__in' => wp_list_pluck( $this->posts, 'ID' ), 3560 'no_found_rows' => false, 3561 'number' => get_option( 'posts_per_rss' ), 3562 'update_comment_meta_cache' => false, // We lazy-load comment meta for performance. 3563 'do_comment_feed_filters' => ! $q['suppress_filters'], 3564 ); 3643 3565 3644 /** This filter is documented in wp-includes/query.php */ 3645 $cgroupby = apply_filters_ref_array( 'comment_feed_groupby', array( '', &$this ) ); 3646 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 3566 $comment_args = apply_filters( 'comments_feed_query_args', $comment_args ); 3647 3567 3648 /** This filter is documented in wp-includes/query.php */ 3649 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 3650 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 3651 3652 /** This filter is documented in wp-includes/query.php */ 3653 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option('posts_per_rss'), &$this ) ); 3654 3655 $comments_request = "SELECT $wpdb->comments.* FROM $wpdb->comments $cjoin $cwhere $cgroupby $corderby $climits"; 3656 $comments = $wpdb->get_results($comments_request); 3657 // Convert to WP_Comment 3658 $this->comments = array_map( 'get_comment', $comments ); 3659 $this->comment_count = count($this->comments); 3568 $comment_query = new WP_Comment_Query( $comment_args ); 3569 $this->comments = $comment_query->comments; 3570 $this->comment_count = count( $this->comments ); 3660 3571 } 3661 3572 3662 3573 // Check post status to determine if post should be displayed.