From 988bafb3ee2136de2ec9d1672cf286502c5448fb Mon Sep 17 00:00:00 2001 From: Nate Weller Date: Wed, 18 Dec 2024 13:20:32 -0700 Subject: [PATCH] Protect Status: prevent undefined extension warning (#40622) --- .../changelog/fix-php-undefined-array-key-warning | 4 ++++ projects/packages/protect-status/src/class-scan-status.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 projects/packages/protect-status/changelog/fix-php-undefined-array-key-warning diff --git a/projects/packages/protect-status/changelog/fix-php-undefined-array-key-warning b/projects/packages/protect-status/changelog/fix-php-undefined-array-key-warning new file mode 100644 index 0000000000000..72562089ff171 --- /dev/null +++ b/projects/packages/protect-status/changelog/fix-php-undefined-array-key-warning @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix PHP warnings caused by uninstalled extensions. diff --git a/projects/packages/protect-status/src/class-scan-status.php b/projects/packages/protect-status/src/class-scan-status.php index 32deca2eba526..6f743cc397b63 100644 --- a/projects/packages/protect-status/src/class-scan-status.php +++ b/projects/packages/protect-status/src/class-scan-status.php @@ -243,7 +243,7 @@ private static function normalize_api_data( $scan_data ) { // Theme and Plugin Threats if ( ! empty( $scan_threat->extension ) && in_array( $scan_threat->extension->type, array( 'plugin', 'theme' ), true ) ) { - $installed_extension = 'plugin' === $scan_threat->extension->type ? $plugins[ $scan_threat->extension->slug ] : $themes[ $scan_threat->extension->slug ]; + $installed_extension = 'plugin' === $scan_threat->extension->type ? ( $plugins[ $scan_threat->extension->slug ] ?? null ) : ( $themes[ $scan_threat->extension->slug ] ?? null ); // If the extension is no longer installed, skip this threat. // todo: use version_compare()