Skip to content

Instantly share code, notes, and snippets.

@bjornjohansen

bjornjohansen/auth.php

Last active Oct 16, 2020
Embed
What would you like to do?
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