Skip to content

Instantly share code, notes, and snippets.

@bjornjohansen
Last active October 16, 2020 12:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjornjohansen/a1f18faf1dda955763966f0a96a580a9 to your computer and use it in GitHub Desktop.
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.
<?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