From 877668d19f934d39b25ac351751620207f727b18 Mon Sep 17 00:00:00 2001 From: Ramon Date: Wed, 8 Jun 2022 08:32:43 +1000 Subject: [PATCH] Webfonts: increase priority of init hook to account for block reregistration (#41569) * `gutenberg_register_webfonts_from_theme_json()` calls `WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()`, which instantiates `WP_Theme_JSON_Gutenberg()`; Gutenberg server-side blocks are registered via the init hook with a priority value of `20`. E.g., `add_action( 'init', 'register_block_core_image', 20 )`; This priority value is added dynamically during the build. See: tools/webpack/blocks.js. 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. * Remove evil space --- lib/experimental/register-webfonts-from-theme-json.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/experimental/register-webfonts-from-theme-json.php b/lib/experimental/register-webfonts-from-theme-json.php index 576d74ab0c56b..f0a37677eb063 100644 --- a/lib/experimental/register-webfonts-from-theme-json.php +++ b/lib/experimental/register-webfonts-from-theme-json.php @@ -174,4 +174,9 @@ function gutenberg_add_registered_webfonts_to_theme_json( $data ) { return $data; } -add_action( 'init', 'gutenberg_register_webfonts_from_theme_json' ); +// `gutenberg_register_webfonts_from_theme_json()` calls `WP_Theme_JSON_Resolver_Gutenberg::get_merged_data()`, which instantiates `WP_Theme_JSON_Gutenberg()`; +// Gutenberg server-side blocks are registered via the init hook with a priority value of `20`. E.g., `add_action( 'init', 'register_block_core_image', 20 )`; +// This priority value is added dynamically during the build. See: tools/webpack/blocks.js. +// 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. +add_action( 'init', 'gutenberg_register_webfonts_from_theme_json', 21 );