Created
July 13, 2016 11:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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