Support » Plugins » [Plugin: WP Super Cache] Exclude cache for some visitors, with a SESSION variable

  • Hi all,

    I have a menu in the blog displaying some links and I would like that some visitors can activate additional links in the menu adding a parameter in the url of the page they are visiting, something like:

    The query string ?new saves a value in a $_SESSION variable, so the visitor sees the additional links in all pages of the blog, until he make a sort of logout adding ?out to the end of the URL and everything return back like before.
    I understand that is a sort of login, but I don’t want that my visitors have to register. Is a temporary solution, that works good for me and I need it for the next two or three months.

    The problem is that in my site I use WP Super Cache (version 0.7.1). It’s a very good plugin, and I want to use it, but I would like to know if it is possible to exclude some visitors if exists a certain SESSION variable (or a cookie).
    I gave a look to the No advert for friends plugin, but I don’t understand exactly how it works – I tried also to use Super cache hooks, but no way to make them work.

    I’ve found a quick and dirty solution: I added an if statement in wp-cache-config.php to check if my SESSION variable is set and in this case the Super cache Plugin is deactivated. It works, but I’m looking for a more elegant solution… so, any help would be very very appreciated.

    In addition, it seems that the cache is active also when logged users visit the sites… is that correct or there’s something wrong?

    Thanks in advance!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Look in wp-cache-phase1.php at the wp_cache_get_cookies_values() function. You can use a “cacheaction” function to hook into the value returned by that function to manipulate the cache key.

    Just add your cookie variable to that string with the hook. Don’t modify wp-cache-phase1.php because it’ll make upgrading harder.

    thanks donncha,
    I’ll try to write a plugin based on searchengine.php included in wp-super-cache without any modifications.

    Just 2 questions: to test this new plugin, 1) both WP Cache and Super Cache can be enabled or I need to disable Super Cache?
    and 2) I need to delete the cache every time I test the script?
    I have the impression that once a page is cached, the wp-cache-phase1.php is not loaded more…

    I think that a brief tutorial about cacheaction functions will be very useful. I’ve read your readme.txt but a working example would be great 😉 if I get it to work, I’ll write something about.
    Anyway, your plugin is very good and thank you very much for the help.

    You could have supercache on, but only if you add a RewriteCond (in the .htaccess file) to detect the session cookie so the supercache files aren’t served to those users. Copy the existing check for the “wordpress_” cookie.

    Yeah, you probably need to delete the cache when testing. alt-ctrl-tab reload is what I do to go back to the admin page where I cleared the cache ..

    Ok, I think it finally works! These are the steps:

    – Added two lines in .htaccess:
    RewriteCond %{HTTP:Cookie} !^.*(my_cookie_key_).*$
    just after
    RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$

    – I made a copy of searchengine.php, changing some function names to avoid conflicts with the original plugin, and saved it in the /wp-super-cache/plugin/ folder;

    – I made no changes to the file wp-cache-phase1.php. The wp_cache_get_cookies_values() function is the original (I don’t know if I need to replace / modify the wp-cache-phase1.php file as you wrote here, but I noticed that in the original function there’s the do_cacheaction hook, not present in the other one)

    – activated both WP Cache and Super Cache
    – activated my new Cache Plugin

    OK, now when I set my custom cookie active, I can see additional links while I visit my pages. This is OK.
    When I delete the cookie, I can’t see additional links. This is very OK.

    But, I noticed that cache files are yet created also if I have the cookie active. It seems a sort of “personal” cache that works only for me. I see additional links while other users don’t. Is this correct, or the cookie should exclude me totally from the caching?

    Thank you for all the patience

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WP Super Cache] Exclude cache for some visitors, with a SESSION variable’ is closed to new replies.