-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Block Bindings: Allow filtering supported block attributes #9392
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 Bindings: Allow filtering supported block attributes #9392
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * @param string[] $supported_block_attributes The block's attributes that are supported by block bindings. | ||
| */ | ||
| $supported_block_attributes = apply_filters( | ||
| "block_bindings_supported_attributes_{$block_type}", |
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.
We can start with that and see if plugin authors raise the need to add a general filter, too.
gziolo
left a 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.
I like this new filter. It's flexible enough so we could relocate it in the future when we decide to extend Block API with a way to annotate bindable attributes. It will still serve a purpose to offer customization to the list of attributes annotated as bindable whatever the mechanism becomes.
This has been discussed in https://core.trac.wordpress.org/ticket/62090.
Alternatives considered include:
block.json, e.g."role": "content"set:I agree that the latter is probably a good idea in the long run. However, there are currently 83 block attributes with
"role": "content"in Gutenberg, and it's not a trivial feat to make all of them bindable. (There are some complications, e.g. attributes such as an image block'scaptionwhich is only rendered conditionally.)In the meantime, the absence of an extensibility mechanism for the list of supported block attributes means that each block has to manually invoke block bindings to ensure backwards compatibility, as seen e.g. here for the Date block. This is required so the block doesn't erroneously receive the fallback value for the bound attribute if the GB plugin is run on a WP version that doesn't have that block attribute added to
$supported_block_attributesinWP_Block::process_block_bindings(). On a WP version that does support the block attribute, it means that the relevant code is needlessly run twice.This is suboptimal. It also puts undue burden on block developers to include the back-compat code in their blocks, instead of being able to mark their bindable block attributes as such; it thus can hamper adoption of Block Bindings, as it makes it much more difficult to update a block to make some of its attributes bindable.
Note that this solution isn't meant to be mutually exclusive with the long-term perspective of having
"role": "content"determine if a block attribute is bindable or not, as the initial value of$supported_block_attributescould be computed by iterating over blocks and including all attributes with that criterion in the list.Closes #7404.
Trac ticket: https://core.trac.wordpress.org/ticket/62090
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.