From af1dce35446e6b3fbdf3006d25f9730bb85e1e01 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 7 Aug 2017 11:01:38 +0100 Subject: [PATCH] Set nocache constants on all nocache_headers --- includes/class-wc-cache-helper.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/class-wc-cache-helper.php b/includes/class-wc-cache-helper.php index 790b3fdd907..0ff66f88add 100644 --- a/includes/class-wc-cache-helper.php +++ b/includes/class-wc-cache-helper.php @@ -21,6 +21,7 @@ class WC_Cache_Helper { public static function init() { add_action( 'template_redirect', array( __CLASS__, 'geolocation_ajax_redirect' ) ); add_action( 'wp', array( __CLASS__, 'prevent_caching' ) ); + add_filter( 'nocache_headers', array( __CLASS__, 'set_nocache_constants' ) ); add_action( 'admin_notices', array( __CLASS__, 'notices' ) ); add_action( 'delete_version_transients', array( __CLASS__, 'delete_version_transients' ) ); } @@ -158,16 +159,20 @@ class WC_Cache_Helper { $page_ids = array_filter( array( wc_get_page_id( 'cart' ), wc_get_page_id( 'checkout' ), wc_get_page_id( 'myaccount' ) ) ); $current_page_id = get_queried_object_id(); - if ( isset( $_GET['download_file'] ) || in_array( $current_page_id, $page_ids ) ) { - self::nocache(); + if ( isset( $_GET['download_file'] ) || isset( $_GET['add-to-cart'] ) || in_array( $current_page_id, $page_ids ) ) { + nocache_headers(); } } /** - * Set nocache constants and headers. - * @access private + * Set constants to prevent caching by some plugins. + * + * Hooked into nocache_headers filter but does not change headers. + * + * @param array $value + * @return array */ - private static function nocache() { + public static function set_nocache_constants( $value ) { if ( ! defined( 'DONOTCACHEPAGE' ) ) { define( "DONOTCACHEPAGE", true ); } @@ -177,7 +182,7 @@ class WC_Cache_Helper { if ( ! defined( 'DONOTCACHEDB' ) ) { define( "DONOTCACHEDB", true ); } - nocache_headers(); + return $value; } /**