Skip to content
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

Blocks: Add filters for registration from metadata #821

Closed
wants to merge 3 commits into from
Closed

Blocks: Add filters for registration from metadata #821

wants to merge 3 commits into from

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Dec 16, 2020

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:

  • Named pre_register_block_type_from_metadata to filter the content of metadata read from block.json
  • Named post_register_block_type_from_metadata to filter the settings object determined from the metadata that is passed to register_block_type call
    I'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.

@gziolo
Copy link
Member Author

gziolo commented Jan 6, 2021

@swissspidy thank you for feedback. I will apply changes tomorrow 👍

@gziolo gziolo closed this Jan 8, 2021
@gziolo gziolo deleted the update/register-block-metadata-filters branch January 8, 2021 16:44
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