From 03627cb9428ee549d5ec03c4da9fcff4a940bc13 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Tue, 30 Mar 2021 01:52:42 +1100 Subject: [PATCH] Widgets: Fix warning when widgets block editor is disabled (#30318) If a core widget is unregistered then it will not be in $wp_widgets_factory->widgets which causes a PHP warning. --- lib/widgets.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/widgets.php b/lib/widgets.php index 64f76818339e5..90090b23cd687 100644 --- a/lib/widgets.php +++ b/lib/widgets.php @@ -293,7 +293,6 @@ function gutenberg_set_show_instance_in_rest_on_core_widgets() { global $wp_widget_factory; $core_widgets = array( - 'WP_Widget_Block', 'WP_Widget_Pages', 'WP_Widget_Calendar', 'WP_Widget_Archives', @@ -314,7 +313,9 @@ function gutenberg_set_show_instance_in_rest_on_core_widgets() { ); foreach ( $core_widgets as $widget ) { - $wp_widget_factory->widgets[ $widget ]->show_instance_in_rest = true; + if ( isset( $wp_widget_factory->widgets[ $widget ] ) ) { + $wp_widget_factory->widgets[ $widget ]->show_instance_in_rest = true; + } } } add_action( 'widgets_init', 'gutenberg_set_show_instance_in_rest_on_core_widgets' );