[wp-trac] [WordPress Trac] #57595: Filter comments_array not called for Block comments
WordPress Trac
noreply at wordpress.org
Wed Feb 1 00:38:55 UTC 2023
#57595: Filter comments_array not called for Block comments
--------------------------+-----------------------------
Reporter: cmautner | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 6.1.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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] );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/57595>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list