Created
May 14, 2025 06:23
-
-
Save mehrshaddarzi/1d67b59fd58229bedea398c6b31d52d8 to your computer and use it in GitHub Desktop.
WordPress User Auth cookie and Session Time
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 | |
// Change Session Auth Cookie | |
add_filter('auth_cookie_expiration', 'filter_auth_cookie_expiration', 99, 3); | |
function filter_auth_cookie_expiration($seconds, $user_id, $remember){ | |
$user = get_userdata($user_id); | |
if ( in_array( 'customer', (array) $user->roles ) || in_array( 'subscriber', (array) $user->roles ) ) { | |
return $seconds; | |
} | |
/* | |
define( 'MINUTE_IN_SECONDS', 60 ); | |
define( 'HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS ); | |
define( 'DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS ); | |
define( 'WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS ); | |
define( 'MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS ); | |
define( 'YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS ); | |
*/ | |
return 60 * DAY_IN_SECONDS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment