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

Use lower priority for block context filters #4780

Closed
wants to merge 1 commit into from
Closed
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 src/wp-includes/blocks/comment-template.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, 0 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor note: The docs say that

priorities are positive integers, typically between 1 and 20

Suggested change
add_filter( 'render_block_context', $filter_block_context, 0 );
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, 0 );

$children = $comment->get_children();

Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/blocks/post-template.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, 0 );
// 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, 0 );

// 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