下面是我最后做的:
// Set disable cache for certain roles
add_action(\'init\', \'add_custom_cookie_admin\');
function add_custom_cookie_admin() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$thisrole = $current_user->roles[0];
if($thisrole !== \'subscriber\') {
setcookie("disable_cache", $current_user->user_login, time()+43200, COOKIEPATH, COOKIE_DOMAIN);
}
}
}
// and then remove the cookie on logout
function clear_custom_cookie_on_logout() {
unset($_COOKIE["disable_cache"]);
setcookie( "disable_cache", \'\', time() - ( 15 * 60 ) );
}
add_action(\'wp_logout\', \'clear_custom_cookie_on_logout\');
然后我将其添加到我的nginx缓存中:
if ($http_cookie ~* "disable_cache") {
set $skip_cache 1;
}