Skip to content

Conversation

@ockham
Copy link
Contributor

@ockham ockham commented Aug 5, 2025

This has been discussed in https://core.trac.wordpress.org/ticket/62090.

Alternatives considered include:

  1. A dedicated property to denote a block attribute as bindable in block.json, e.g.
"attributes": {
	"datetime": {
		"type": "string",
		"bindable": true
	},
}
  1. Inferring that an attribute is bindable if it has "role": "content" set:
"attributes": {
	"datetime": {
		"type": "string",
		"role": "content"
	},
}

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's caption which 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_attributes in WP_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_attributes could 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.

@ockham ockham self-assigned this Aug 5, 2025
@ockham ockham requested a review from gziolo August 5, 2025 15:14
@ockham ockham marked this pull request as ready for review August 5, 2025 15:14
@github-actions
Copy link

github-actions bot commented Aug 5, 2025

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props bernhard-reiter, gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Aug 5, 2025

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

* @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}",
Copy link
Member

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.

Copy link
Member

@gziolo gziolo left a 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.

@ockham
Copy link
Contributor Author

ockham commented Aug 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants