@@ -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