keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

update cache behavior for logged in users #95

Closed coreykn closed 4 years ago

coreykn commented 4 years ago

Allow cached pages to be delivered to logged in users (#19). Remove the _is_logged_in() method and instead allow the cookies Cache Exclusion to control this. This was already the current behavior when a page had already been cached as the advanced cache is only checking the cookie names. By default the cookies Cache Exclusion setting will bypass the cache when logged in.

If a certain user role needs to be bypassed a custom cookie, such as user_admin=1, can be set. The cookies Cache Exclusion option can then be updated (e.g. /user_admin/). This can be done in many different ways, one being a custom function in the functions.php file that uses wp_get_current_user() and setcookie(), for example:

$user = wp_get_current_user();
if ( in_array( 'Administrator', (array) $user->roles ) ) {
    setcookie( 'user_admin', 1 );
}

Closes #19