From fc4e28b33e09eae239cd8dfb1389a067b3bb30ad Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Thu, 8 Dec 2022 09:40:12 +0100 Subject: [PATCH] array_key_exists shall not be called on non array (#35598) --- plugins/woocommerce/changelog/fix-35513 | 4 ++++ .../includes/admin/helper/class-wc-helper-options.php | 2 +- .../class-wc-rest-system-status-v2-controller.php | 10 ++-------- .../src/Internal/WCCom/ConnectionHelper.php | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-35513 diff --git a/plugins/woocommerce/changelog/fix-35513 b/plugins/woocommerce/changelog/fix-35513 new file mode 100644 index 00000000000..18a403a3a01 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-35513 @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +Fix call of array_key_exists in SSR. diff --git a/plugins/woocommerce/includes/admin/helper/class-wc-helper-options.php b/plugins/woocommerce/includes/admin/helper/class-wc-helper-options.php index 4f1611cf671..1b329ca5408 100644 --- a/plugins/woocommerce/includes/admin/helper/class-wc-helper-options.php +++ b/plugins/woocommerce/includes/admin/helper/class-wc-helper-options.php @@ -51,7 +51,7 @@ class WC_Helper_Options { */ public static function get( $key, $default = false ) { $options = get_option( self::$option_name, array() ); - if ( array_key_exists( $key, $options ) ) { + if ( is_array( $options ) && array_key_exists( $key, $options ) ) { return $options[ $key ]; } diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php index ac718627dea..18c6f8df46b 100644 --- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php +++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php @@ -10,6 +10,7 @@ defined( 'ABSPATH' ) || exit; +use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper; /** * System status controller class. * @@ -1235,13 +1236,6 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller { $product_visibility_terms[ $term->slug ] = strtolower( $term->name ); } - // Check if WooCommerce.com account is connected. - $woo_com_connected = 'no'; - $helper_options = get_option( 'woocommerce_helper_data', array() ); - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { - $woo_com_connected = 'yes'; - } - // Return array of useful settings for debugging. return array( 'api_enabled' => 'yes' === get_option( 'woocommerce_api_enabled' ), @@ -1255,7 +1249,7 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller { 'geolocation_enabled' => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ), true ), 'taxonomies' => $term_response, 'product_visibility_terms' => $product_visibility_terms, - 'woocommerce_com_connected' => $woo_com_connected, + 'woocommerce_com_connected' => ConnectionHelper::is_connected() ? 'yes' : 'no', ); } diff --git a/plugins/woocommerce/src/Internal/WCCom/ConnectionHelper.php b/plugins/woocommerce/src/Internal/WCCom/ConnectionHelper.php index d3c771da628..fb8ae1a28b8 100644 --- a/plugins/woocommerce/src/Internal/WCCom/ConnectionHelper.php +++ b/plugins/woocommerce/src/Internal/WCCom/ConnectionHelper.php @@ -21,7 +21,7 @@ final class ConnectionHelper { */ public static function is_connected() { $helper_options = get_option( 'woocommerce_helper_data', array() ); - if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { + if ( is_array( $helper_options ) && array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) { return true; } return false;