This has got to be simple: how do I keep one user – my-user
– logged in for a year? (I’m checking logged in cookies in the dev tools console).
Update 8/16/15
This works:
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year', 10, 3 );
function keep_me_logged_in_for_1_year( $ttl, $user_id, $remember ) {
if( 1 === $user_id )
$ttl = YEAR_IN_SECONDS;
return $ttl;
}
And with the array option, this works for multiple users:
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year', 10, 3 );
function keep_me_logged_in_for_1_year( $ttl, $user_id, $remember ) {
if( in_array( $user_id, array( 1, 2 ) ) )
$ttl = YEAR_IN_SECONDS;
return $ttl;
}
Update 8/12/15: Re: Rarst’s answer below: since get_currentuserinfo
is pluggable, how would I use apply_filters
in this context?
I’m getting a Call to undefined function get_currentuserinfo()
error with this function below used in a simple plugin:
global $user_login;
get_currentuserinfo();
if ($user_login == "my-user") {
function keep_me_logged_in_for_1_year( $expirein ) {
return 31556926; // 1 year in seconds
}
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );
}
But the Codex usage uses the global
: https://codex.wordpress.org/Function_Reference/get_currentuserinfo
This, of course, keeps all users logged in for a year:
function keep_me_logged_in_for_1_year( $expirein ) {
return 31556926; // 1 year in seconds
}
add_filter( 'auth_cookie_expiration', 'keep_me_logged_in_for_1_year' );