From c5ab9537730bd3144f6fe4bf2df2b00af0bad7c7 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 22 Jan 2016 20:20:25 +0000 Subject: [PATCH] Allow comment query results to be limited to comments with comment_post_ID = 0. Previously, this was not possible due to an overly broad `empty()` check. Passing `null`, `false`, or `''` to 'post_id', or omitting 'post_id' altogether, will continue to return comments regardless of `comment_post_ID`, as before. Passing `0` or `'0'` will limit results to comments with no associated post. Props danielbachhuber. Fixes #35090. Built from https://develop.svn.wordpress.org/trunk@36381 git-svn-id: http://core.svn.wordpress.org/trunk@36348 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-comment-query.php | 9 ++++----- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/wp-includes/class-wp-comment-query.php b/wp-includes/class-wp-comment-query.php index eb6f094a5e..71cd525833 100644 --- a/wp-includes/class-wp-comment-query.php +++ b/wp-includes/class-wp-comment-query.php @@ -214,7 +214,7 @@ class WP_Comment_Query { * Default empty. * @type int $post_ID Currently unused. * @type int $post_id Limit results to those affiliated with a given post ID. - * Default 0. + * Default null. * @type array $post__in Array of post IDs to include affiliated comments for. * Default empty. * @type array $post__not_in Array of post IDs to exclude affiliated comments for. @@ -276,7 +276,7 @@ class WP_Comment_Query { 'post_author__in' => '', 'post_author__not_in' => '', 'post_ID' => '', - 'post_id' => 0, + 'post_id' => null, 'post__in' => '', 'post__not_in' => '', 'post_author' => '', @@ -645,9 +645,8 @@ class WP_Comment_Query { $fields = "$wpdb->comments.comment_ID"; } - $post_id = absint( $this->query_vars['post_id'] ); - if ( ! empty( $post_id ) ) { - $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $post_id ); + if ( strlen( $this->query_vars['post_id'] ) ) { + $this->sql_clauses['where']['post_id'] = $wpdb->prepare( 'comment_post_ID = %d', $this->query_vars['post_id'] ); } // Parse comment IDs for an IN clause. diff --git a/wp-includes/version.php b/wp-includes/version.php index fb8946c89a..578cd58b96 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36380'; +$wp_version = '4.5-alpha-36381'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.