Blocks: Add filters for registration from metadata #821
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.
Trac ticket: https://core.trac.wordpress.org/ticket/52138
Related: WordPress/gutenberg#25220, https://core.trac.wordpress.org/ticket/49615
With changes added in https://core.trac.wordpress.org/ticket/49615, it is possible to filter the settings of a block type during its registration with
register_block_type_args
. However, when working WordPress/gutenberg#25220, we discovered that it is still not enough for the case when blocks are registered with block.json metadata. As of today, all core blocks are registered this way and it's impossible to customize the way their styles and scripts are registered or i18n support is handled. The idea here is to add more filters to give more options for plugin authors in the future and account for the needs that Gutenberg has in the constant work to improve the experience around block registration.The attached patch seeks to follow with 2 new hooks:
pre_register_block_type_from_metadata
to filter the content of metadata read from block.jsonpost_register_block_type_from_metadata
to filter the settings object determined from the metadata that is passed toregister_block_type
callI'm 100% sure we need the first one. In terms of adding the second one, I'm open to discussion since it might duplicate the scope of
register_block_type_args
with the only difference that it contains also the metadata object as an argument passed for processing.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.