From 8502ee003fafa8cf05d800c12a8c7ade626e3d4f Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Thu, 22 Sep 2022 10:06:34 +0200 Subject: [PATCH 1/2] Support nested comments settings in the new blocks --- .../src/comment-template/index.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index 49ca8561e2d47a..346ec25d453aa1 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -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; @@ -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( '
    %1$s
', $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( '
    %1$s
', $inner_content ); + $comment_depth -= 1; + } else { + $inner_content = block_core_comment_template_render_comments( + $children, + $block + ); + $block_content .= sprintf( $inner_content ); + } } $content .= sprintf( '
  • %3$s
  • ', $comment->comment_ID, $comment_classes, $block_content ); From 5dc76c3a8bf5d82a7268e96cac05de28a42918c6 Mon Sep 17 00:00:00 2001 From: Mario Santos Date: Thu, 22 Sep 2022 11:33:41 +0200 Subject: [PATCH 2/2] Fix linting issues --- packages/block-library/src/comment-template/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index 346ec25d453aa1..770959854b58ad 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -16,8 +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'); + $thread_comments = get_option( 'thread_comments' ); + $thread_comments_depth = get_option( 'thread_comments_depth' ); if ( empty( $comment_depth ) ) { $comment_depth = 1; @@ -48,7 +48,7 @@ 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 ) && !empty( $thread_comments ) ) { + if ( ! empty( $children ) && ! empty( $thread_comments ) ) { if ( $comment_depth < $thread_comments_depth ) { $comment_depth += 1; $inner_content = block_core_comment_template_render_comments(