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
This commit is contained in:
Sergey Biryukov 2020-10-20 20:11:06 +00:00
parent 5b4d643d60
commit fbd8078d4e
2 changed files with 21 additions and 2 deletions

View File

@ -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;

View File

@ -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.