Skip to content

Instantly share code, notes, and snippets.

@dknauss
Last active December 30, 2024 17:04
Show Gist options
  • Select an option

  • Save dknauss/595ef53fc331e01341de3877d06846f2 to your computer and use it in GitHub Desktop.

Select an option

Save dknauss/595ef53fc331e01341de3877d06846f2 to your computer and use it in GitHub Desktop.
Every time a WordPress Admin user refreshes a page, reset their session cookie expiration to five minutes.
add_filter('auth_cookie_expiration', function (int $default_duration, int $user_id) {
if (user_can($user_id, 'manage_options')) {
return 5 * MINUTE_IN_SECONDS;
}
return $default_duration;
}, 10, 2);
// Note: This filter expires sessions that are idle for more than five minutes and keeps active admin user sessions
// alive continuously as long as there has been activity (page loads/GET requests) within the last five minutes.
// Combined with reasonably low default session expiration times, this code can be used to keep an active admin
// from being frequently logged out. Keep in mind, it is a choice for convenience over security and would benefit
// an attacker who has breached an admin user account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment