Editor: Show comment previews in the Comment Query Loop.

Update `build_comment_query_vars_from_block()` to show previews of unmoderated comments to the original author of the comment. This duplicates the existing logic in `wp_list_comments()`.

Props darerodz, bernhard-reiter, czapla.
Fixes #55634.



git-svn-id: https://develop.svn.wordpress.org/trunk@53298 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2022-04-28 01:16:18 +00:00
parent 47e10bee2a
commit 832429e9b2
2 changed files with 56 additions and 4 deletions

View File

@@ -1287,12 +1287,22 @@ add_filter( 'block_type_metadata', '_wp_multiple_block_styles' );
function build_comment_query_vars_from_block( $block ) {
$comment_args = array(
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'no_found_rows' => false,
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'no_found_rows' => false,
);
if ( is_user_logged_in() ) {
$comment_args['include_unapproved'] = array( get_current_user_id() );
} else {
$unapproved_email = wp_get_unapproved_comment_author_email();
if ( $unapproved_email ) {
$comment_args['include_unapproved'] = array( $unapproved_email );
}
}
if ( ! empty( $block->context['postId'] ) ) {
$comment_args['post_id'] = (int) $block->context['postId'];
}

View File

@@ -250,4 +250,46 @@ class Tests_Blocks_RenderReusableCommentTemplate extends WP_UnitTestCase {
$block->render()
);
}
/**
* Test that unapproved comments are included if it is a preview.
*
* @ticket 55634
* @covers ::build_comment_query_vars_from_block
*/
function test_build_comment_query_vars_from_block_with_comment_preview() {
$parsed_blocks = parse_blocks(
'<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->'
);
$block = new WP_Block(
$parsed_blocks[0],
array(
'postId' => self::$custom_post->ID,
)
);
$commenter_filter = function () {
return array(
'comment_author_email' => 'unapproved@example.org',
);
};
add_filter( 'wp_get_current_commenter', $commenter_filter );
$this->assertEquals(
build_comment_query_vars_from_block( $block ),
array(
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'no_found_rows' => false,
'include_unapproved' => array( 'unapproved@example.org' ),
'post_id' => self::$custom_post->ID,
'hierarchical' => 'threaded',
'number' => 5,
'paged' => 1,
)
);
}
}