Make WordPress Core

Opened 3 years ago

Last modified 2 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 close
Focuses: Cc:

Description

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>',
		$wrapper_attributes,
		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 (3)

#1 @cmautner
3 years ago

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

#2 @audrasjb
3 years 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?
https://github.com/WordPress/gutenberg/issues

Thanks!

#3 @callumbw95
2 months ago

  • Keywords close added

Hi @cmautner,

As has already been pointed out, this issue is related to Gutenberg and there isn't much we can do about that issue here. As of such I am going to mark this ticket with the close tag. However please feel free to continue the conversation further if you feel this is incorrect. 😃

Note: See TracTickets for help on using tickets.