Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with WP Rocket logged-in user cache #126

Open
JoryHogeveen opened this issue Feb 21, 2022 · 13 comments
Open

Compatibility with WP Rocket logged-in user cache #126

JoryHogeveen opened this issue Feb 21, 2022 · 13 comments
Assignees
Projects
Milestone

Comments

@JoryHogeveen
Copy link
Owner

More info: https://wordpress.org/support/topic/compatibility-with-wp-rocket-11/

Basically, when cache is enabled for logged in users it prevents View Admin As from working correctly.
I'll have to check if there are some filters available to bypass cache or find some other solution.

@JoryHogeveen JoryHogeveen self-assigned this Feb 21, 2022
@JoryHogeveen JoryHogeveen added this to Ideas in Core via automation Feb 21, 2022
@lucspe
Copy link

lucspe commented Feb 21, 2022

Hi Jory,

Following up on the discussion on wp.org, may I ask how does View Admin As keeps track of the current role it is emulating?

So that I can see if there is any exclusion option in WP-Rocket that could work.

@JoryHogeveen
Copy link
Owner Author

Hi @lucspe

I store the view in the user metadata and at a very early stage in the plugins_loaded hook I switch the user.
https://github.com/JoryHogeveen/view-admin-as/blob/master/includes/class-vaa.php#L163

The view class handles all switching:
https://github.com/JoryHogeveen/view-admin-as/blob/master/includes/class-view.php
For each view there is a module which sets the view data:
https://github.com/JoryHogeveen/view-admin-as/blob/master/modules/class-users.php#L132-L152

@JoryHogeveen
Copy link
Owner Author

JoryHogeveen commented Mar 1, 2022

Hi @lucspe

I was just wondering is you might have found a solution. Let me know!
One option I could imagine is that I could disable cache entirely once a view is selected..

@lucspe
Copy link

lucspe commented Mar 2, 2022

HI @JoryHogeveen

So this is definetely an issue that manifests if WP-Rocket is enabled and cache is enabled for logged in users.

As a temporary workaround, I simply add a bogus variable to the URL (i,e, "?whatever") before doing the switch. This way, when the page reloads with the new role it will bypass the cache.
To switch back to admin (reset to default) or change to another role, I then need to do this again adding the variable to the URL.

I was looking into WP-Rocket documentation and it seems that is possible to to exclude admins from cache even when it is enabled for logged in users:

https://docs.wp-rocket.me/article/919-disable-cache-for-logged-in-administrators

However I am not sure if this approach could be useful for compatibility with VAA.

@JoryHogeveen
Copy link
Owner Author

JoryHogeveen commented Mar 2, 2022

Hi @lucspe

Thank you for this resource. I've created a patch that I think might help in your case:
https://github.com/JoryHogeveen/view-admin-as/blob/hotfix/126/includes/class-compat.php#L108-L116

Could you try this?

@lucspe
Copy link

lucspe commented Mar 2, 2022

Hi @JoryHogeveen

Thanks.

It doesn't work unfortunately.

@JoryHogeveen
Copy link
Owner Author

Did you clear your cache before testing?

@lucspe
Copy link

lucspe commented Mar 3, 2022

Hi @JoryHogeveen,

I tried once again to be sure.

I have cleared the cache several times and it doesn't work unfortunately.

Specifically, clearing the cache makes it work once (just like adding a non existing variable to the URL).

@joncon62
Copy link

I'm getting the same problem but with Litespeed cache, did you solve this for WP Rocket? Adding a query parameter while VAA is active may work as I can then exclude the view from being cached. I can also exclude via cookies.

@lucspe
Copy link

lucspe commented Oct 12, 2022

hi @joncon62 , nope.

Currently in the only site where I need cache active also for logged in users I bypass the cache adding a query variable to the URL.

@JoryHogeveen
Copy link
Owner Author

Hi @lucspe and @joncon62

Unfortunately, it seems cache plugins run their code even before plugins are loaded. This of course greatly enhances speed but results in a plugin like this not being able to function.

I could of course always add a refresh param when switching but that still won't work with browsing though the site.

Ideas on how to properly address this are very welcome!

@CloundNine
Copy link

Also having issues when using Litespeed. I don't have private cache enabled and caching is turned off for all roles. I did discover that it's only "broken" when I view as site visitor. If I view as subscriber, I can change the view back or reset to default properly. I'm happy to make my site available to Jory for testing if that would be helpful. Thank again Jory for a great plugin.

@JoryHogeveen
Copy link
Owner Author

When viewing as a visitor the page cache would be enabled.
I'm still searching for a way to fix this as most caching plugins are enabled before WordPress is loaded, making my code quite useless.

@JoryHogeveen JoryHogeveen moved this from Ideas to In progress in Core Feb 13, 2023
@JoryHogeveen JoryHogeveen modified the milestones: 1.8.8, 1.8.9 Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Core
  
In progress
Development

No branches or pull requests

4 participants