Add filters when rendering inner blocks#1684
Add filters when rendering inner blocks#1684azaozz wants to merge 6 commits intoWordPress:masterfrom azaozz:fix/apply-filters-on-inner-blocks
Conversation
|
This patch is similar to the original idea by @noisysocks b04425a only the filters are in The filters have |
Clever! That addresses the main criticism of my original approach which was that the filters were being called in
I do not like this. It creates extra work for plugin developers as they'll have to define two filters instead of one. Blocks should work the same way regardless of whether they’re nested inside another block or not. |
… existing filters. Add `$parent_block` ref.
|
Hmm, tests seem to fail globally at the moment, something about mismatched cert. 80695cf should be fine, tests pass locally. |
Right, to get to the inner blocks you'll need to render the top/parent block. However there's a
Yeah, devs will have to use both "top" and "inner" filters. Having a different name makes it very clear the currently filtered block is inner. Blocks should work the same way but they don't, and most look very differently when nested. Also was thinking it may be useful to pass some more context to the inner filters, but may be redundant. Updated the PR and changed the filter names to match. Context is provided by adding another param: |
I think this point is valid, maybe "some" not "most", but it's a little inconvenience that I think adds more control IMO. |
|
Yes but often the reason a block looks different when nested is only due to styling. The HTML will be the same. The most common use case for these filters is to slightly change the HTML. I think that plugin developers and theme developers will expect that the filters do this regardless of whether the block is nested or not.
I agree. Perfect 🙂 |
noisysocks
left a comment
There was a problem hiding this comment.
Code and approach LGTM and this tests well locally 👍
Might want to consider adding a unit test to tests/phpunit/tests/blocks/wpBlock.php.
Add
pre_render_inner_block,render_inner_block_data, andrender_inner_block_contextfilters that run before an inner block is rendered.Trac ticket: https://core.trac.wordpress.org/ticket/51612
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.