Merge pull request #32747 from crstauf/patch-1

Fix `is_page()` and `is_singular()` called incorrectly
This commit is contained in:
Vedanshu Jain 2022-05-04 19:06:11 +05:30 committed by GitHub
commit e74a106fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Add check for $wp_query before calling is_cart to prevent doing_it_wrong notice.

View File

@ -41,6 +41,8 @@ class WC_Cache_Helper {
* @since 3.6.0 * @since 3.6.0
*/ */
public static function additional_nocache_headers( $headers ) { public static function additional_nocache_headers( $headers ) {
global $wp_query;
$agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$set_cache = false; $set_cache = false;
@ -64,7 +66,7 @@ class WC_Cache_Helper {
$set_cache = true; $set_cache = true;
} }
if ( false !== strpos( $agent, 'Chrome' ) && is_cart() ) { if ( false !== strpos( $agent, 'Chrome' ) && isset( $wp_query ) && is_cart() ) {
$set_cache = true; $set_cache = true;
} }