WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: WP Super Cache] Avoid caching if certain cookie is present (4 posts)

  1. tomgf
    Member
    Posted 6 years ago #

    How would it be the best solution to avoid caching if a cookie is present?

    I'm running an archive of documents which can be downloaded by registered users and serving caching pages to non-authenticated visitors. Once you login (not as an WP author but as a ‘subscriber’ via an special plugin), there is an extra cookie on your browser. Therefore, you have to receive dynamic pages (not cached at all).

    So far I've solved this changing the line 24 of wp-cache-phase1.php:

    - if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST')
    + if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST' || $_COOKIE['mycookie'])

    But I am wondering if this can be also done by a wp-super-cache plugin… Any thoughts?

  2. Donncha O Caoimh
    Member
    Posted 6 years ago #

    Yes, you can use a the "wp_cache_get_cookies_values" cache_action to modify the cookie. Look at plugins/searchengine.php as an example of how to do it.

  3. Maciej Ku? (maciekkus)
    Member
    Posted 6 years ago #

    Hello Donncha,

    Could you describe it with details?
    On my site I have two different views of posts (depending on a cookie) and would like to have cached both versions of page.

    I thought about creating separate htaccess rules set for these views, but I would need to modify wp-super-cache somehow to generate two types of cache files.. and additionaly I would like to have it future-versions-proof..

  4. Donncha O Caoimh
    Member
    Posted 6 years ago #

    You can't cache both pages, at least with the static cache. If you change the plugin to "half on" it'll work fine though.

Topic Closed

This topic has been closed to new replies.

About this Topic