Shorter Login Sessions for Administrators
Makes administrator logins expire sooner than everyone else's, limiting the damage of a forgotten logged-in browser.
Opens WPIDE on
Code
// Session length for administrators, with and without "Remember Me".
$wpide_admin_session = 8 * HOUR_IN_SECONDS;
$wpide_admin_session_remember = 2 * DAY_IN_SECONDS;
add_filter( 'auth_cookie_expiration', function ( $length, $user_id, $remember ) use ( $wpide_admin_session, $wpide_admin_session_remember ) {
if ( user_can( $user_id, 'manage_options' ) ) {
return $remember ? $wpide_admin_session_remember : $wpide_admin_session;
}
return $length;
}, 20, 3 );
Notes
Applies from the next login; current sessions keep their expiry.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.