apply_filters( 'auth_cookie_expiration', int $length , int $user_id , bool $remember )
Filters the duration of the authentication cookie expiration period.
Description Description
Parameters Parameters
- $length
-
(int) Duration of the expiration period in seconds.
- $user_id
-
(int) User ID.
- $remember
-
(bool) Whether to remember the user login. Default false.
Source Source
Changelog Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
An example of how to extend time in your WordPress session by a year, simply enter this code into your `functions.php` or plugin. Other durations have been added to show different times hat can be set.
add_filter ( 'auth_cookie_expiration', 'wpdev_login_session' ); function wpdev_login_session( $expire ) { // Set login session limit in seconds return YEAR_IN_SECONDS; // return MONTH_IN_SECONDS; // return DAY_IN_SECONDS; // return HOUR_IN_SECONDS; }Extension of the example, only extending expiration if $remember and low privelege.
add_filter('auth_cookie_expiration', 'auth_cookie_expiration_filter_5587', 10, 3); function auth_cookie_expiration_filter_5587($expiration, $user_id, $remember) { if ($remember && !user_can($user_id, 'edit_others_posts')) { return YEAR_IN_SECONDS; // return MONTH_IN_SECONDS; // return DAY_IN_SECONDS; // return HOUR_IN_SECONDS; } // default return $expiration; }function wp_homework_change_cookie_logout( $expiration){ $user = wp_get_current_user(); $allowed_roles = array('administrator', 'scholar'); if( array_intersect($allowed_roles, $user->roles ) ) { $expiration = 31557600; } return $expiration; } add_filter( 'auth_cookie_expiration','wpse108399_change_cookie_logout', 10, 3 );