From cc7036189d2ad69c39281e8f1674c820a4f168e6 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Sun, 4 Jul 2021 23:15:50 +0100 Subject: [PATCH] Widget Block: widget_id is undefined when a widget is placed (#33152) * Fix notice error * Fix lint --- .../widgets/src/blocks/legacy-widget/index.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/widgets/src/blocks/legacy-widget/index.php b/packages/widgets/src/blocks/legacy-widget/index.php index 030aa88f56b63..8a326056816c9 100644 --- a/packages/widgets/src/blocks/legacy-widget/index.php +++ b/packages/widgets/src/blocks/legacy-widget/index.php @@ -25,13 +25,15 @@ function render_block_core_legacy_widget( $attributes ) { } $id_base = $attributes['idBase']; - if ( method_exists( $wp_widget_factory, 'get_widget_key' ) ) { - $widget_key = $wp_widget_factory->get_widget_key( $id_base ); + if ( method_exists( $wp_widget_factory, 'get_widget_key' ) && method_exists( $wp_widget_factory, 'get_widget_object' ) ) { + $widget_key = $wp_widget_factory->get_widget_key( $id_base ); + $widget_object = $wp_widget_factory->get_widget_object( $id_base ); } else { - $widget_key = gutenberg_get_widget_key( $id_base ); + $widget_key = gutenberg_get_widget_key( $id_base ); + $widget_object = gutenberg_get_widget_object( $id_base ); } - if ( ! $widget_key ) { + if ( ! $widget_key || ! $widget_object ) { return ''; } @@ -45,8 +47,13 @@ function render_block_core_legacy_widget( $attributes ) { $instance = array(); } + $args = array( + 'widget_id' => $widget_object->id, + 'widget_name' => $widget_object->name, + ); + ob_start(); - the_widget( $widget_key, $instance ); + the_widget( $widget_key, $instance, $args ); return ob_get_clean(); }