Custom cookies to bypass cache
-
It would be great to be able to customize cookies to bypass cache.
For example, I want to add Woocommerce cookies to prevent minicart glitches out of store pages (I think_bypass_cache()
also need to check cookies).I do that with
bypass_cache
filter:function bypass_cache_when_cookie_match($skip) { if ( !empty($_COOKIE) ) { foreach ( $_COOKIE as $k => $v) { if ( preg_match('/comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_cart_hash|woocommerce_items_in_cart|wp_woocommerce_session_[a-f0-9]*/', $k) ) { return true; } } } return false; } add_filter ('bypass_cache', 'bypass_cache_when_cookie_match');
But on advanced-cache.php I need to override the file to change cookies. I would like to can define some constant on wp-config.php like
BYPASS_CACHE_COOKIES
:// check cookie values $cookies_regex = defined('BYPASS_CACHE_COOKIES') ? BYPASS_CACHE_COOKIES : '/^(wp-postpass|wordpress_logged_in|comment_author)_/'; if ( !empty($_COOKIE) ) { foreach ( $_COOKIE as $k => $v) { if ( preg_match($cookies_regex, $k) ) { return false; } } }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Custom cookies to bypass cache’ is closed to new replies.