-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 API: Stabilize Block Hooks feature #54293
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7ac2149
Block API: Stabilize Block Hooks feature
gziolo 7221cee
Improve the API handling for block patterns REST API endpoing
gziolo e350a17
Add the default value for `blockHooks` during block registration
gziolo 316d01b
Explain when Block Hooks get wired with the site
gziolo 20c6e72
Update docs/reference-guides/block-api/block-metadata.md
gziolo 4de6ad5
Update the explanation which parts of the site are impacted by the Bl…
gziolo 02fd527
Rephrase the description of Block Hooks in the docs
gziolo d8e7b0d
Add tests for polyfilling blockHooks when not exposed on the server
gziolo c3b2ab2
Extend block.json schema to include block hooks
gziolo 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,8 @@ function render_block_core_pattern( $attributes ) { | |
$pattern = $registry->get_registered( $slug ); | ||
$content = _inject_theme_attribute_in_block_template_content( $pattern['content'] ); | ||
|
||
$gutenberg_experiments = get_option( 'gutenberg-experiments' ); | ||
if ( $gutenberg_experiments && ! empty( $gutenberg_experiments['gutenberg-block-hooks'] ) ) { | ||
// This can be removed when the minimum supported WordPress is >= 6.4. | ||
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's very likely that we will have to refactor this code once the final solution is fleshed out in WordPress/wordpress-develop#5158. |
||
// TODO: In the long run, we'd likely want to have a filter in the `WP_Block_Patterns_Registry` class | ||
// instead to allow us plugging in code like this. | ||
$blocks = parse_blocks( $content ); | ||
|
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.
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.
@gziolo I love these docs :)
The only thing that I'm confused about is that the docs as written here make it sound like the filters can be used for any blocks answhere. Which is not correct if I understand things correctly. Hooks only get applied for blocks inside non modified block templates of a block based theme 🤔
Is that so or do these hooks also fire for any block just anywhere saved in post content?
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.
Great catch. We definitely need to cover it, as communication is critical here. It only applies to block patterns (not generated by the user), template parts, and templates loaded from the block theme files. Essentially, the feature never changes the content created/modified by the user on the website, which I think is very intuitive once you wrap your head around how it all works. The only challenge I encountered myself is that it's difficult to tell where to clear modifications to see the blocks automatically hooked. Sometimes it's the template you work within the site editor, but sometimes it might be the template part. We can further improve the UI to make it more evident in the future.
By the way, I believe that we will also need a How-to Guide covering it all, a lengthy dev note, and a detailed blog post at https://developer.wordpress.org/news/ 😅 .
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.
It looks like @ndiego already has it on his radar for the Developer Blog 🎉 WordPress/developer-blog-content#168
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.
I added a section to the block registration document with 7c0c3a0. I'm happy to apply some edits, but we should plan extending that part in a follow-up PR so we have time to stabilize the API before the next Gutenberg plugin release.
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.
For now, this Trac ticket has some information on the feature and the architectural decisions (and tradeoffs) that went into it 😄