Last active
October 31, 2024 14:08
-
-
Save ipokkel/18216639d6ac1e8f3d035426743ade3a to your computer and use it in GitHub Desktop.
Extend the user's login period if the remember me option was checked at login so users stay logged in for longer periods.
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 | |
/** | |
* This recipe extends the user login period if remember me was checked. | |
* | |
* @link https://developer.wordpress.org/reference/hooks/auth_cookie_expiration/ | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_user_persistent_login( $expiration, $user_id, $remember ) { | |
// Adjust login period if user selected remember me. | |
if ( $remember ) { | |
// login is valid for a year. | |
return YEAR_IN_SECONDS; // Can multiply this for multiple years, e.g. YEAR_IN_SECONDS * 2 | |
// return MONTH_IN_SECONDS; | |
// return DAY_IN_SECONDS; | |
// return HOUR_IN_SECONDS; | |
} | |
// default | |
return $expiration; | |
} | |
add_filter( 'auth_cookie_expiration', 'my_user_persistent_login', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment