Last active
October 16, 2020 12:33
-
-
Save bjornjohansen/a1f18faf1dda955763966f0a96a580a9 to your computer and use it in GitHub Desktop.
Changes the expiration of the WordPress authentication cookie to 365 days if the user ticks the “Remember Me” checkbox.
This file contains hidden or 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 | |
/** | |
* Authentication customizations. | |
* | |
* @package BJ\Auth | |
*/ | |
/** | |
* Filters the duration of the authentication cookie expiration period. | |
* | |
* @param int $length Duration of the expiration period in seconds. | |
* @param int $user_id User ID. | |
* @param bool $remember Whether to remember the user login. Default false. | |
* @return int Duration of the expiration period in seconds. | |
*/ | |
function bj_set_auth_cookie_expiration( $length, $user_id, $remember ) { | |
if ( $remember ) { | |
$length = max( $length, 365 * DAY_IN_SECONDS ); | |
} | |
return $length; | |
} | |
add_filter( 'auth_cookie_expiration', 'bj_set_auth_cookie_expiration', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment