mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Block Hooks: Respect "multiple": false
#7443
Closed
ockham
wants to merge
13
commits into
WordPress:trunk
from
ockham:update/have-block-hooks-respect-multiple-false-in-apply-block-hooks-to-content
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dcbdba9
Block Hooks: Respect `"multiple": false`
ockham 7affa65
Polish a little
ockham c1319fc
Make anonymous function static
ockham 034146f
Correctly format multi-line comment
ockham a3c1b82
Slightly rephrase comment
ockham 92d8920
Another multi-line comment
ockham 257225c
Revert "Use references instead of indices in loop"
ockham fab6700
Prune only after finishing loop
ockham 0b563b0
Optimize a bit more
ockham 05db29b
Remove unnecessary function args from filter
ockham a3d11b9
Move single_instance_blocks_present_in_content into filter, make static
ockham 95c4140
Typo
ockham 3bf035b
Rephrase comment
ockham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the only place where I'm not entirely sure what are the consequences of using the static variable. However my understanding is that
$suppress_single_instance_blocks
should be instantiated once perapply_block_hooks_to_content
call, so all the checks are applied in a specific context - a template, template part, pattern, post content or navigation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing, it works correctly as explained in #7443 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, IIUC, we're instantiating a new function here every time
apply_block_hooks_to_content()
is called, and for the lifetime of that$suppress_single_instance_blocks
, we're using$single_instance_blocks_present_in_content
as a cache. The next call toapply_block_hooks_to_content()
then creates a new$suppress_single_instance_blocks
, which in turn creates a new (empty)$single_instance_blocks_present_in_content
.(I added a
var_dump( $single_instance_blocks_present_in_content );
on the line below this one and ran tests to verify this 😅 )