diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/blocks/comment-template.php --- a/wp/wp-includes/blocks/comment-template.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/blocks/comment-template.php Fri Sep 05 18:40:08 2025 +0200 @@ -8,6 +8,8 @@ /** * Function that recursively renders a list of nested comments. * + * @since 6.3.0 Changed render_block_context priority to `1`. + * * @global int $comment_depth * * @param WP_Comment[] $comments The array of comments. @@ -16,6 +18,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; @@ -23,13 +27,29 @@ $content = ''; foreach ( $comments as $comment ) { + $comment_id = $comment->comment_ID; + $filter_block_context = static function ( $context ) use ( $comment_id ) { + $context['commentId'] = $comment_id; + return $context; + }; - $block_content = ( new WP_Block( - $block->parsed_block, - array( - 'commentId' => $comment->comment_ID, - ) - ) )->render( array( 'dynamic' => false ) ); + /* + * We set commentId context through the `render_block_context` filter so + * that dynamically inserted blocks (at `render_block` filter stage) + * will also receive that context. + * + * Use an early priority to so that other 'render_block_context' filters + * have access to the values. + */ + add_filter( 'render_block_context', $filter_block_context, 1 ); + + /* + * We construct a new WP_Block instance from the parsed block so that + * it'll receive any changes made by the `render_block_data` filter. + */ + $block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) ); + + remove_filter( 'render_block_context', $filter_block_context, 1 ); $children = $comment->get_children(); @@ -46,26 +66,34 @@ // 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( '