Webfonts: increase priority of init hook to account for block reregistration #41569
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.
Fixes #41296 (I think)
What?
Webfonts are registered via the
init
hook at the highest priority.Gutenberg server-side blocks are registered via the
init
hook with a priority value of20
. E.g.,add_action( 'init', 'register_block_core_image', 20 )
;This priority value is added dynamically during the build. See: tools/webpack/blocks.js.
gutenberg_register_webfonts_from_theme_json()
callsWP_Theme_JSON_Resolver_Gutenberg::get_merged_data()
,which instantiates
WP_Theme_JSON_Gutenberg()
;Unfortunately this happens before Gutenberg server-side blocks are re-registered, therefore any plugin-only updates to block.json for example do not appear in the theme.json merged data.
Why?
We want to make sure Gutenberg blocks are re-registered before any Theme_JSON operations take place so that we have access to updated merged data.
How?
Bumping priority from
20
to21
:add_action( 'init', 'gutenberg_register_webfonts_from_theme_json', 21 );
Testing Instructions
Add an
__experimentalSelector
property to a block in its block.json file:Check that the selector is registered in get_blocks_metadata
And that blocks load as per normal 😄
Go through the test steps on the original webfonts PR: