• Resolved Pacotole

    (@pacotole)


    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;
            }
        }
    }
    • This topic was modified 6 years, 8 months ago by Pacotole.
    • This topic was modified 6 years, 8 months ago by Pacotole.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Currently, the bypass_cache filter is the only method for achieving this but I will run it by the developers to look into this.

    Thread Starter Pacotole

    (@pacotole)

    Thanks for your response and congratulations for the plugin.

    I’ll wait the option to customize cookies ??

    Thread Starter Pacotole

    (@pacotole)

    Please, update plugin to v1.2.3.

    The changes to customize bypass cookies are included in your changelog on v1.2.3 and are in the repository on trunk but the tag 1.2.3 with this changes isn’t released.

    This is part of our normal release cycle. We first want to see if there are any issues creeping up with new installations before rolling out the upgrade to everyone.

    If you want the changes right away you can get them by removing and then re-installing the plugin.

    Cheers!

    Hello again!

    We are getting closer to releasing 1.2.3 but have decided to change how this feature is implemented. Instead of using a constant in wp-config.php we will introduce fields to specify regular expressions in the plugins settings.
    (Because we added a bunch of similar settings that would become quite cumbersome and also to make this work nicely with multisite installations.)

    So you’ll need to keep that in mind in case you are already using the previous incarnation of this.

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom cookies to bypass cache’ is closed to new replies.