Make WordPress Core

Opened 4 years ago

Last modified 12 months ago

#57595 new enhancement

Filter comments_array not called for Block comments

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

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
4 years ago

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

#2 @audrasjb
4 years ago

  • Component General → Editor
  • Keywords reporter-feedback added
  • Type defect (bug) → enhancement
  • Version 6.1.1

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