From fbd8078d4ee4df78ea5b6cb2c1525cc414f53b25 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 20 Oct 2020 20:11:06 +0000 Subject: [PATCH] Comments: Add a filter for top level comments query arguments in `comments_template()`. Props hellofromTonya, Howdy_McGee, garrett-eclipse, davidbaumwald, thomaslhotta. Fixes #38074. Built from https://develop.svn.wordpress.org/trunk@49256 git-svn-id: http://core.svn.wordpress.org/trunk@49018 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 21 ++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index e3cfdef312..943113605c 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1434,6 +1434,24 @@ function comments_template( $file = '/comments.php', $separate_comments = false $top_level_args['include_unapproved'] = $comment_args['include_unapproved']; } + /** + * Filters the arguments used in the top level comments query. + * + * @since 5.6.0 + * + * @see WP_Comment_Query::__construct() + * + * @param array $top_level_args { + * The top level query arguments for the comments template. + * + * @type bool $count Whether to return a comment count. + * @type string|array $orderby The field(s) to order by. + * @type int $post_id The post ID. + * @type string|array $status The comment status to limit results by. + * } + */ + $top_level_args = apply_filters( 'comments_template_top_level_query_args', $top_level_args ); + $top_level_count = $top_level_query->query( $top_level_args ); $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page; @@ -1463,7 +1481,8 @@ function comments_template( $file = '/comments.php', $separate_comments = false * @type int $number Number of comments to fetch. * } */ - $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); + $comment_args = apply_filters( 'comments_template_query_args', $comment_args ); + $comment_query = new WP_Comment_Query( $comment_args ); $_comments = $comment_query->comments; diff --git a/wp-includes/version.php b/wp-includes/version.php index 984cdc9922..0d26f052ad 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-49255'; +$wp_version = '5.6-alpha-49256'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.