Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter comments_array not called in render_block_core_comment_template() #47655

Open
cmautner opened this issue Feb 1, 2023 · 1 comment
Open
Labels
[Block] Comment Template Affects the Comment Template Block [Type] Enhancement A suggestion for improvement.

Comments

@cmautner
Copy link

cmautner commented Feb 1, 2023

Description

This is the code for render_block_core_comment_template() in block_library/comment_template/index.php:

	// 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 )
	);

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. The following line should be inserted prior to the $wrapper_attributes assignment:

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

Step-by-step reproduction instructions

  1. In any blocks-based theme create a plugin with a comments ordering filter using add_filter( 'comments_array', function ( $comments, $post_id ) { return array_reverse( $comments ); }, 10, 2 );
  2. Create a post and add two or more comments
  3. Load the post. Expected result: is comments in reverse order; Actual result: comments in original order

Screenshots, screen recording, code snippet

No response

Environment info

Wordpress version: 6.1.1, Gutenberg version: Unknown but it matches git, Theme: Twenty TwentyThree
Browser: Chrome, but not pertinent
Device: Host is linux, viewed on linux, Windows, and Android

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@kathrynwp kathrynwp added [Block] Comment Template Affects the Comment Template Block [Type] Bug An existing feature does not function as intended [Type] Enhancement A suggestion for improvement. and removed [Type] Bug An existing feature does not function as intended labels Feb 2, 2023
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

Hi,
This issue has gone 180 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comment Template Affects the Comment Template Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants