From c785c29cd17206c5a6287e57fd1040851eb9f9ae Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Sat, 23 Apr 2022 15:59:04 -0400 Subject: [PATCH 1/3] confirm query set before evaluating condition fixes #30646 --- plugins/woocommerce/includes/class-wc-cache-helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce/includes/class-wc-cache-helper.php b/plugins/woocommerce/includes/class-wc-cache-helper.php index 32500527c5e..25a8145522e 100644 --- a/plugins/woocommerce/includes/class-wc-cache-helper.php +++ b/plugins/woocommerce/includes/class-wc-cache-helper.php @@ -41,6 +41,8 @@ class WC_Cache_Helper { * @since 3.6.0 */ public static function additional_nocache_headers( $headers ) { + global $wp_cache; + $agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $set_cache = false; @@ -64,7 +66,7 @@ class WC_Cache_Helper { $set_cache = true; } - if ( false !== strpos( $agent, 'Chrome' ) && is_cart() ) { + if ( false !== strpos( $agent, 'Chrome' ) && isset( $wp_query ) && is_cart() ) { $set_cache = true; } From 03c710221fa3a1951c2ce9ce5b0c016fbe2d3f0c Mon Sep 17 00:00:00 2001 From: Caleb Stauffer Date: Sat, 23 Apr 2022 15:59:48 -0400 Subject: [PATCH 2/3] fix variable name --- plugins/woocommerce/includes/class-wc-cache-helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/includes/class-wc-cache-helper.php b/plugins/woocommerce/includes/class-wc-cache-helper.php index 25a8145522e..e80611619ae 100644 --- a/plugins/woocommerce/includes/class-wc-cache-helper.php +++ b/plugins/woocommerce/includes/class-wc-cache-helper.php @@ -41,7 +41,7 @@ class WC_Cache_Helper { * @since 3.6.0 */ public static function additional_nocache_headers( $headers ) { - global $wp_cache; + global $wp_query; $agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized From 8cba910dece5ec7f5c5ba6e79cf1afafc83e3be6 Mon Sep 17 00:00:00 2001 From: vedanshujain Date: Wed, 4 May 2022 16:41:26 +0530 Subject: [PATCH 3/3] Add changelog. --- plugins/woocommerce/changelog/pr-32747 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/woocommerce/changelog/pr-32747 diff --git a/plugins/woocommerce/changelog/pr-32747 b/plugins/woocommerce/changelog/pr-32747 new file mode 100644 index 00000000000..a91bbff2d41 --- /dev/null +++ b/plugins/woocommerce/changelog/pr-32747 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Add check for $wp_query before calling is_cart to prevent doing_it_wrong notice.