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
Add Block Hooks (a.k.a. Auto-inserting Blocks) #5158
Closed
Closed
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b926b86
Add callback arg to serialize_blocks
ockham f7465b9
Inject theme attribute during serialization
ockham 7fda6f5
Add callback arg to serialize_blocks (plural)
ockham 3ad1fd7
Add block_hooks property
ockham cdcfbcc
Implement get_hooked_blocks()
ockham c897d86
Implement insert_hooked_block and insert_hooked_blocks
ockham 5013547
Insert hooked blocks during serialization
ockham c8115dc
Remove stray echo
ockham 37496a0
Map camelCased position string to snake_case
ockham 600e55d
Auto-insert into block pattern
ockham b1a82fe
Also apply to get_all_registered (needed for REST API)
ockham 25b1ed4
Use third-person singular verb in PHPDoc
ockham ea1f53f
Use multiline comment format for inline comment
ockham 8fc29bc
Adjust alignment and add Default value to PHPDoc for `serialize_block`
ockham 5cd2ded
Adjust alignment and add Default value to PHPDoc for `serialize_blocks`.
ockham 0267cc9
Don't allow null value for block_hooks
ockham 67e6a34
Placate linter
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
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.
The idea is to change this to a more general function (e.g. called
_visit_block
) that is called for each block during serialization (see below).We can then extend that function to also take care of automatic insertion:
Pending implementation
insert_hooked_blocks
(and adapting theWP_Block_Type
class and friends to include a new$block_hooks
field etc), this should give us parity with what we're currently doing in Gutenberg through some filter magic.We can then introduce a way to limit automatic insertion to certain template types; off-the-cuff, I'd say this should be possible via binding inside of
_build_block_template_result_from_file
(but maybe we can make it more elegant).This should allow us to preserve separation of concerns (e.g.
serialize_blocks
doesn't know about auto-inserted blocks or templates;insert_block_hooks
doesn't know about templates).