Skip to content

Commit

Permalink
Comments block: Support nested comments settings in the comments bloc…
Browse files Browse the repository at this point in the history
…ks (#44351)

* Support nested comments settings in the new blocks
  • Loading branch information
SantosGuillamot authored Sep 26, 2022
1 parent ace58e4 commit df7cdc9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/block-library/src/comment-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
function block_core_comment_template_render_comments( $comments, $block ) {
global $comment_depth;
$thread_comments = get_option( 'thread_comments' );
$thread_comments_depth = get_option( 'thread_comments_depth' );

if ( empty( $comment_depth ) ) {
$comment_depth = 1;
Expand Down Expand Up @@ -46,14 +48,22 @@ function block_core_comment_template_render_comments( $comments, $block ) {

// If the comment has children, recurse to create the HTML for the nested
// comments.
if ( ! empty( $children ) ) {
$comment_depth += 1;
$inner_content = block_core_comment_template_render_comments(
$children,
$block
);
$block_content .= sprintf( '<ol>%1$s</ol>', $inner_content );
$comment_depth -= 1;
if ( ! empty( $children ) && ! empty( $thread_comments ) ) {
if ( $comment_depth < $thread_comments_depth ) {
$comment_depth += 1;
$inner_content = block_core_comment_template_render_comments(
$children,
$block
);
$block_content .= sprintf( '<ol>%1$s</ol>', $inner_content );
$comment_depth -= 1;
} else {
$inner_content = block_core_comment_template_render_comments(
$children,
$block
);
$block_content .= sprintf( $inner_content );
}
}

$content .= sprintf( '<li id="comment-%1$s" %2$s>%3$s</li>', $comment->comment_ID, $comment_classes, $block_content );
Expand Down

0 comments on commit df7cdc9

Please sign in to comment.