From a415c29efee45520ae252d2aa28f1083a521cd7b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:56:49 +0200 Subject: Adding upstream version 6.4.3+dfsg1. Signed-off-by: Daniel Baumann --- wp-includes/blocks/legacy-widget.php | 149 +++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 wp-includes/blocks/legacy-widget.php (limited to 'wp-includes/blocks/legacy-widget.php') diff --git a/wp-includes/blocks/legacy-widget.php b/wp-includes/blocks/legacy-widget.php new file mode 100644 index 0000000..94cfb9b --- /dev/null +++ b/wp-includes/blocks/legacy-widget.php @@ -0,0 +1,149 @@ +get_widget_key( $id_base ); + $widget_object = $wp_widget_factory->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 ( ! hash_equals( wp_hash( $serialized_instance ), (string) $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'] ); + ?> +
+
+ + + +