From fd6d18a74d20f0ef204c4cc7a2d89712c2fdbe3d Mon Sep 17 00:00:00 2001 From: Jeremy Herve Date: Mon, 23 May 2022 10:09:09 +0200 Subject: [PATCH] Widget Visibility: avoid PHP warnings when loading widgets. (#24460) --- .../jetpack/changelog/fix-notice-widget-visibility-1135 | 4 ++++ .../jetpack/modules/widget-visibility/widget-conditions.php | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 projects/plugins/jetpack/changelog/fix-notice-widget-visibility-1135 diff --git a/projects/plugins/jetpack/changelog/fix-notice-widget-visibility-1135 b/projects/plugins/jetpack/changelog/fix-notice-widget-visibility-1135 new file mode 100644 index 0000000000000..2068fa98f00e8 --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-notice-widget-visibility-1135 @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +Widget Visibility: avoid PHP warnings when loading widgets in some scenarios. diff --git a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php index 78f9da83a7443..2553f91248a7e 100644 --- a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php +++ b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php @@ -1127,6 +1127,10 @@ public static function migrate_post_type_rules() { $opts = $wp_registered_widgets[ $widget ]; $instances = get_option( $opts['callback'][0]->option_name ); + if ( ! is_array( $instances ) || empty( $instances ) ) { + continue; + } + // Going through each instance of the widget. foreach ( $instances as $number => $instance ) { if (