Skip to content

Commit

Permalink
Comment Reply: Fix SSR for some cases
Browse files Browse the repository at this point in the history
The cases are:
- The comment ID passed is invalid
- The comment doesn't have any parents
- There is no link to render
  • Loading branch information
DAreRodz committed Oct 27, 2021
1 parent d01d825 commit 676a954
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/block-library/src/post-comment-reply-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ function render_block_core_post_comment_reply_link( $attributes, $content, $bloc
}

$comment = get_comment( $block->context['commentId'] );
if ( empty( $comment ) ) {
return '';
}

$depth = 1;
$max_depth = get_option( 'thread_comments_depth' );
$parent_id = $comment->comment_parent;

// Compute comment's depth iterating over its ancestors.
while ( 0 !== $parent_id ) {
while ( ! empty( $parent_id ) ) {
$depth++;
$parent_id = get_comment( $parent_id )->comment_parent;
}
Expand All @@ -43,6 +46,11 @@ function render_block_core_post_comment_reply_link( $attributes, $content, $bloc
$comment
);

// Render nothing if the generated reply link is empty.
if ( empty( $comment_reply_link ) ) {
return;
}

$classes = '';
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
Expand Down

0 comments on commit 676a954

Please sign in to comment.