• Resolved mikewpdev

    (@mikewpdev)


    Hi, this is my way to allow WP Super Cache to split cache between users using a specific cookie and other users:

    if ( is_plugin_active( ‘wp-super-cache/wp-cache.php’ ) ) {

    /*
    * Tell WP Super Cache to cache requests with the cookie “Cookies and Content Security Policy” separately from other visitors.
    */

    function add_wpsc_cookie_banner() {
    do_action( ‘wpsc_add_cookie’, ‘cookies_and_content_security_policy’ );
    }
    add_action( ‘init’, ‘add_wpsc_cookie_banner’ );

    }

    Could you please consider adding this code or similar to this plugin, so WP Super Cache users don’t have to install custom code with this great plugin? Whenever I activate this plugin to a user, I need to add this code too.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    Thanks for the suggestion, I’ll look into it.

    On a sidenote, doesn’t WP Super Cache have a way to exclude a cookie in their settings like some cache plugins do? Read more under I’m using a cache plugin, and it seems to be interfere with this plugin

    Thread Starter mikewpdev

    (@mikewpdev)

    Hi Johan,

    yes you can exclude caching when specific cookie is used, but whats would be the point of caching plugin then?

    This code that I shared caches separately, creates two copies of static cache, one for visitors with specific cookie set and other for visitors without the cookie. This way even when cookies_and_content_security_policy is set, the site will be cached. I personally think this is much better solution compared to exclusion.

    With WP Super Cache being the most popular caching plugin with 2+ million installs, this I think is nice feature.

    • This reply was modified 3 years ago by mikewpdev.
    • This reply was modified 3 years ago by mikewpdev.
    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    In the examples, it still caches, but it doesn’t cache the cookie.

    I have tested a bit already and adding is_plugin_active() gives me Uncaught Error: Call to undefined function is_plugin_active(), so running it in a plugin seems too early for WordPress. You could run include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); but that would mess up custom paths that for example Bedrock uses. But I’ll do some more testing and see if I can get it to run properly.

    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    It seems better to add it in the plugin like this:

    if ( in_array( 'wp-super-cache/wp-cache.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { 
        // Tell WP Super Cache to cache requests with the cookie “Cookies and Content Security Policy” separately from other visitors.
        function cacsp_add_wpsc_cookie_banner() {
            do_action( 'wpsc_add_cookie', 'cookies_and_content_security_policy' );
        }
        add_action( 'init', 'cacsp_add_wpsc_cookie_banner' );
    }

    If you get a preview version of 2.05, would you like to test it so that it works as expected @mikewpdev?

    Thread Starter mikewpdev

    (@mikewpdev)

    Hi, I was calling it after admin_init in my messy code, that is why I did not get the error, thanks for this.

    Yes I will gladly test it.

    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    Great! Send me a mail to [email protected] and I’ll send you a beta when I think I’m ready for release.

    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    @mikewpdev, don’t forget to sen me that mail. ??

    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    This will be in the next release (2.0.5)

    Thread Starter mikewpdev

    (@mikewpdev)

    Thanks for this!

    Plugin Author Johan Jonk Stenstr?m

    (@jonkastonka)

    It is release now ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add WP Super Cache support’ is closed to new replies.