diff --git a/lib/blocks.php b/lib/blocks.php index b92a656513714..b5ce0a11cf80b 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -5,6 +5,24 @@ * @package gutenberg */ +/* + * Fixes the priority of register_block_core_legacy_widget(). + * + * This hook was incorrectly added to Core with priority 20. #32300 fixes this + * but causes block registration warnings in the Gutenberg plugin until the + * changes are made in Core. + * + * This temporary fix can be removed after the changes to + * @wordpress/block-library in #32300 have been published to npm and updated in + * Core. + * + * See https://github.com/WordPress/gutenberg/pull/32300. + */ +if ( 20 === has_action( 'init', 'register_block_core_legacy_widget' ) ) { + remove_action( 'init', 'register_block_core_legacy_widget', 20 ); + add_action( 'init', 'register_block_core_legacy_widget', 10 ); +} + /** * Substitutes the implementation of a core-registered block type, if exists, * with the built result from the plugin. diff --git a/packages/block-library/src/legacy-widget/index.php b/packages/block-library/src/legacy-widget/index.php index 6a49111b8e692..f8b64ab5c138c 100644 --- a/packages/block-library/src/legacy-widget/index.php +++ b/packages/block-library/src/legacy-widget/index.php @@ -50,21 +50,25 @@ function render_block_core_legacy_widget( $attributes ) { } /** - * On application init this does two things: - * - * - Registers the 'core/legacy-widget' block. - * - Intercepts any request with legacy-widget-preview in the query param and, - * if set, renders a page containing a preview of the requested Legacy Widget - * block. + * Registers the 'core/legacy-widget' block. */ -function init_legacy_widget_block() { +function register_block_core_legacy_widget() { register_block_type_from_metadata( __DIR__ . '/legacy-widget', array( 'render_callback' => 'render_block_core_legacy_widget', ) ); +} + +add_action( 'init', 'register_block_core_legacy_widget' ); +/** + * Intercepts any request with legacy-widget-preview in the query param and, if + * set, renders a page containing a preview of the requested Legacy Widget + * block. + */ +function handle_legacy_widget_preview_iframe() { if ( empty( $_GET['legacy-widget-preview'] ) ) { return; } @@ -110,4 +114,7 @@ function init_legacy_widget_block() { exit; } -add_action( 'init', 'init_legacy_widget_block' ); +// Ensure handle_legacy_widget_preview_iframe() is called after Core's +// register_block_core_legacy_widget() (priority = 10) and after Gutenberg's +// register_block_core_legacy_widget() (priority = 20). +add_action( 'init', 'handle_legacy_widget_preview_iframe', 21 );