diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/blocks/legacy-widget.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wp/wp-includes/blocks/legacy-widget.php Wed Sep 21 18:19:35 2022 +0200 @@ -0,0 +1,134 @@ +get_widget_key( $id_base ); + $widget_object = $wp_widget_factory->get_widget_object( $id_base ); + } else { + /* + * This file is copied from the published @wordpress/widgets package when WordPress + * Core is built. Because the package is a dependency of both WordPress Core and the + * Gutenberg plugin where the block editor is developed, this fallback condition is + * required until the minimum required version of WordPress for the plugin is raised + * to 5.8. + */ + $widget_key = gutenberg_get_widget_key( $id_base ); + $widget_object = gutenberg_get_widget_object( $id_base ); + } + + if ( ! $widget_key || ! $widget_object ) { + return ''; + } + + if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) { + $serialized_instance = base64_decode( $attributes['instance']['encoded'] ); + if ( wp_hash( $serialized_instance ) !== $attributes['instance']['hash'] ) { + return ''; + } + $instance = unserialize( $serialized_instance ); + } else { + $instance = array(); + } + + $args = array( + 'widget_id' => $widget_object->id, + 'widget_name' => $widget_object->name, + ); + + ob_start(); + the_widget( $widget_key, $instance, $args ); + return ob_get_clean(); +} + +/** + * Registers the 'core/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; + } + + if ( ! current_user_can( 'edit_theme_options' ) ) { + return; + } + + define( 'IFRAME_REQUEST', true ); + + ?> + + > + + + + + + + + > +
+
+ get_registered( 'core/legacy-widget' ); + echo $block->render( $_GET['legacy-widget-preview'] ); + ?> +
+
+ + + +