Skip to content

Commit

Permalink
Widgets: Fix warning when widgets block editor is disabled (#30318)
Browse files Browse the repository at this point in the history
If a core widget is unregistered then it will not be in
$wp_widgets_factory->widgets which causes a PHP warning.
  • Loading branch information
noisysocks authored and ockham committed Mar 29, 2021
1 parent e902186 commit 03627cb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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' );

0 comments on commit 03627cb

Please sign in to comment.