I’m trying to extend the lifespan of the authentication cookie, but only for administrators.
My code in functions.php is:
add_filter( 'auth_cookie_expiration', 'change_admin_cookie_logout' );
function change_admin_cookie_logout( $expirein ) {
if ($user_id == current_user_can('promote_users')) {
return 60; // yes, I know this is 1 minute
} return 20;
}
The problem I’m having is twofold:
-
When I leave off the else statement, then login fails. In other words, I seem to have to define the expiration time for admins & non-admins, rather than singularly modifying the admin expiration time.
-
the above formula ignores “remember me” and applies it globally. I’d like it to apply only when “Remember Me” is checked.
I’ve tried tweaking wp_set_auth_cookie but hit some walls and came back to this method. Any help is greatly appreciated!