Make WordPress Core

Opened 16 months ago

Last modified 16 months ago

#57595 new enhancement

Filter comments_array not called for Block comments

Reported by: cmautner's profile cmautner Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Editor Keywords: reporter-feedback
Focuses: Cc:


This is the code for render_block_core_comment_template():

	// Get an array of comments for the current post.
	$comments = $comment_query->get_comments();
	if ( count( $comments ) === 0 ) {
		return '';

	$comment_order = get_option( 'comment_order' );

	if ( 'desc' === $comment_order ) {
		$comments = array_reverse( $comments );

	$wrapper_attributes = get_block_wrapper_attributes();

	return sprintf(
		'<ol %1$s>%2$s</ol>',
		block_core_comment_template_render_comments( $comments, $block )

But that doesn't allow a plugin author to provide a custom ordering. In my case I am adding comment voting and we want to reorder comments by their up/down votes. I believe that the following line should be inserted prior to the $wrapper_attributes assignment:

	$comments = apply_filters( 'comments_array', $comments, $block->context[postId] );

Change History (2)

#1 @cmautner
16 months ago

$block->context[postId] should be $block->context['postId']

#2 @audrasjb
16 months ago

  • Component changed from General to Editor
  • Keywords reporter-feedback added
  • Type changed from defect (bug) to enhancement
  • Version 6.1.1 deleted

Hello and welcome to WordPress Core Trac and thanks for the suggestion!

Worth noting that this issue needs to be addressed in Gutenberg side, as this core file belongs to Gutenberg repository.

Would you mind opening an issue in Gutenberg GitHub repository, please?


Note: See TracTickets for help on using tickets.