I am building sites where I secretly give authoring role capability to visitors by auto-logging them into a generic account; they never see the admin bar, and are prevented from seeing the dashboard (with Remove Dashboard Access plugin).
Everything works fine except I would like to have the site automatically log out after a short time frame, like an hour. I have been trying the approach here https://wordpress.stackexchange.com/a/51887/14945 This and others work by changing the auth_cookie_expiration for all users, not what I want (admins and editors need regular settings).
I call a function I use elsewhere to verify the current user is the generic account (login name = 'collector')
function trucollector_check_user( $allowed='collector' ) {
// checks if the current logged in user is who we expect
global $current_user;
get_currentuserinfo();
// return check of match
return ( $current_user->user_login == $allowed );
}
and this is my cookie changing function
function trucollector_change_cookie_logout( $expiration, $user_id, $remember ) {
return $remember ? $expiration : 3600;
}
What I am stuck on is where to call the add_filter where I can check for the correct user; I have tried putting in a function called on an action of after_setup_theme
add_action('after_setup_theme', 'trucollector_shorten_cookie');
function trucollector_shorten_cookie() {
// change to short auto logout time
if ( trucollector_check_user() ) {
add_filter( 'auth_cookie_expiration', 'trucollector_change_cookie_logout', 99, 3 );
}
}
It looks like when I inspect the cookies in my browser that there is a shorter one set, but it does not seem to be logging out my guest user.
Most likely my logic here is missing something....