Skip to content

Commit 1c7337e

Browse files
noisysocksyouknowriad
authored andcommitted
Fix legacy widget block preview iframe in plugin (#32300)
1 parent f4d704f commit 1c7337e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

lib/blocks.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
* @package gutenberg
66
*/
77

8+
/*
9+
* Fixes the priority of register_block_core_legacy_widget().
10+
*
11+
* This hook was incorrectly added to Core with priority 20. #32300 fixes this
12+
* but causes block registration warnings in the Gutenberg plugin until the
13+
* changes are made in Core.
14+
*
15+
* This temporary fix can be removed after the changes to
16+
* @wordpress/block-library in #32300 have been published to npm and updated in
17+
* Core.
18+
*
19+
* See https://github.com/WordPress/gutenberg/pull/32300.
20+
*/
21+
if ( 20 === has_action( 'init', 'register_block_core_legacy_widget' ) ) {
22+
remove_action( 'init', 'register_block_core_legacy_widget', 20 );
23+
add_action( 'init', 'register_block_core_legacy_widget', 10 );
24+
}
25+
826
/**
927
* Substitutes the implementation of a core-registered block type, if exists,
1028
* with the built result from the plugin.

packages/block-library/src/legacy-widget/index.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,25 @@ function render_block_core_legacy_widget( $attributes ) {
5050
}
5151

5252
/**
53-
* On application init this does two things:
54-
*
55-
* - Registers the 'core/legacy-widget' block.
56-
* - Intercepts any request with legacy-widget-preview in the query param and,
57-
* if set, renders a page containing a preview of the requested Legacy Widget
58-
* block.
53+
* Registers the 'core/legacy-widget' block.
5954
*/
60-
function init_legacy_widget_block() {
55+
function register_block_core_legacy_widget() {
6156
register_block_type_from_metadata(
6257
__DIR__ . '/legacy-widget',
6358
array(
6459
'render_callback' => 'render_block_core_legacy_widget',
6560
)
6661
);
62+
}
63+
64+
add_action( 'init', 'register_block_core_legacy_widget' );
6765

66+
/**
67+
* Intercepts any request with legacy-widget-preview in the query param and, if
68+
* set, renders a page containing a preview of the requested Legacy Widget
69+
* block.
70+
*/
71+
function handle_legacy_widget_preview_iframe() {
6872
if ( empty( $_GET['legacy-widget-preview'] ) ) {
6973
return;
7074
}
@@ -110,4 +114,7 @@ function init_legacy_widget_block() {
110114
exit;
111115
}
112116

113-
add_action( 'init', 'init_legacy_widget_block' );
117+
// Ensure handle_legacy_widget_preview_iframe() is called after Core's
118+
// register_block_core_legacy_widget() (priority = 10) and after Gutenberg's
119+
// register_block_core_legacy_widget() (priority = 20).
120+
add_action( 'init', 'handle_legacy_widget_preview_iframe', 21 );

0 commit comments

Comments
 (0)