array_key_exists shall not be called on non array (#35598)

This commit is contained in:
Peter Fabian 2022-12-08 09:40:12 +01:00 committed by GitHub
parent 084abd9908
commit fc4e28b33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 10 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
Fix call of array_key_exists in SSR.

View File

@ -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 ];
}

View File

@ -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',
);
}

View File

@ -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;