Skip to content

Commit

Permalink
Widget Block: widget_id is undefined when a widget is placed (#33152)
Browse files Browse the repository at this point in the history
* Fix notice error

* Fix lint
  • Loading branch information
spacedmonkey authored Jul 4, 2021
1 parent 8f0259a commit cc70361
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/widgets/src/blocks/legacy-widget/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
}

Expand All @@ -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();
}

Expand Down

0 comments on commit cc70361

Please sign in to comment.