Skip to content

Instantly share code, notes, and snippets.

@chuckreynolds
Created July 13, 2016 11:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckreynolds/498cc563d74b69f7f47ed82aea05cc21 to your computer and use it in GitHub Desktop.
Save chuckreynolds/498cc563d74b69f7f47ed82aea05cc21 to your computer and use it in GitHub Desktop.
This will extend the user login session auth cookie (session_tokens row in wp_usermeta) when the user is an Administrator and checks the Remember Me checkbox on login. Needed this for admins only, and all posts out there I found only did it for all users, and current_user_can didn't work so used user_can with ID.
<?php
/**
* Extend expiration length of the auth cookie for Administrators when hey check Remember Me
*
* @param int $expiration Cookie expiration passed by auth_cookie_expiration() hook
* @return int 90 days in seconds
*/
function chuck_extend_admins_login_session( $expiration, $user_id, $remember ) {
if ( $remember && user_can( $user_id, 'manage_options' ) ) {
$expiration = 7776000; // 90 days in seconds
}
return $expiration;
}
add_filter( 'auth_cookie_expiration','chuck_extend_admins_login_session', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment