From 6ec84be5ef76d6a44bd71f8a777b2a8b8198e849 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 May 2023 14:52:27 +0600 Subject: [PATCH] Comment Template Block: Set commentId context via filter --- .../block-library/src/comment-template/index.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/comment-template/index.php b/packages/block-library/src/comment-template/index.php index 45fd993adbdeba..6a8698f60f0ec1 100644 --- a/packages/block-library/src/comment-template/index.php +++ b/packages/block-library/src/comment-template/index.php @@ -25,13 +25,14 @@ function block_core_comment_template_render_comments( $comments, $block ) { $content = ''; foreach ( $comments as $comment ) { - - $block_content = ( new WP_Block( - $block->parsed_block, - array( - 'commentId' => $comment->comment_ID, - ) - ) )->render( array( 'dynamic' => false ) ); + $comment_id = $comment->comment_ID; + $filter_block_context = static function( $context ) use ( $comment_id ) { + $context['commentId'] = $comment_id; + return $context; + }; + add_filter( 'render_block_context', $filter_block_context ); + $block_content = $block->render( array( 'dynamic' => false ) ); + remove_filter( 'render_block_context', $filter_block_context ); $children = $comment->get_children();