• This is related to my last problem, but I think I’ve narrowed down what needs to be done better, so perhaps now I can ask a smarter question.

    I need to exclude users based on a cookie, kind of like how “known users” are excluded, but I need to look at different cookie, and in this case they should only be excluded if the cookie has the content “true”, not if it just exists. Any ideas how I could do this?

    I’m not exactly skilled in PHP, but I’m brave enough to poke around in there if someone can point me in the right direction and there’s no a better way.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You should write WPSC plugin (PHP code can’t be added in plugins or theme because it should be executed early before loading plugins) and set “Simple” delivery method. You can read more on https://odd.blog/2017/10/25/writing-wp-super-cache-plugins/.

    There is similar example related to GDPR plugins. You don’t need to exclude caching when “value of cookie” is true because WPSC could store wp cache file (wp-cache-…). WP super cache file (index.html) serves when value is false (or cookie doesn’t exist).

    Thread Starter nudeworldorder

    (@nudeworldorder)

    Thanks. So it looks like wpsc_add_cookie is what I need. I didn’t know about this feature. That will indeed be a better solution than excluding people based on the cookie. I’m not quite sure I understand where to put code to use that fuction, but I guess I’ll just start trying things.

    If you add cookie then visitor is recognized as “known user”. You can find more details here and on github. There is PR which should fix it – Improves logic for logged in users. If you just add cookie then you will exclude caching if option “Don’t cache pages for known users” is checked. Regarding that plugins often set cookies (if they aren’t exists) it’s similar as disabling caching for entire website. I’m not sure that I’ve explained everything and I hope that you will understand it.

    You can add this code in functions.php because WPSC stores cookies in configuration file, but I’m afraid that it can’t work as should without applying changes from #631.

    Thread Starter nudeworldorder

    (@nudeworldorder)

    Thank you. I sounds like they’re actively working that, so maybe I’ll just wait until the cookie functionality is improved.

    In the mean time I’m using a “hack” solution, based on something else I found online. I just edited WP Night Mode so that its cookie is named wordpress_logged_in_DarkMode and is deleted when it’s turned off (instead of just set to false). So WP Super Cache is fooled into thinking anyone in Night Mode is logged in. It’s not elegant, but it seems to work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can I exclude users based on a cookie?’ is closed to new replies.