Skip to content

Commit

Permalink
Post and Comment Template blocks: Change render_block_context priorit…
Browse files Browse the repository at this point in the history
…y to 1 (#52364)
  • Loading branch information
ockham authored and tellthemachines committed Jul 10, 2023
1 parent 3eeb607 commit 69236dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/block-library/src/comment-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ function block_core_comment_template_render_comments( $comments, $block ) {
* 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 );
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 );
remove_filter( 'render_block_context', $filter_block_context, 1 );

$children = $comment->get_children();

Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ function render_block_core_post_template( $attributes, $content, $block ) {
$context['postId'] = $post_id;
return $context;
};
add_filter( 'render_block_context', $filter_block_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 );
// Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling
// `render_callback` and ensure that no wrapper markup is included.
$block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
remove_filter( 'render_block_context', $filter_block_context );
remove_filter( 'render_block_context', $filter_block_context, 1 );

// Wrap the render inner blocks in a `li` element with the appropriate post classes.
$post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
Expand Down

0 comments on commit 69236dc

Please sign in to comment.