Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post and Comment Template blocks: Change render_block_context priority to 1 #52364

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading