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.


Top ↑

Source Source

File: wp-includes/pluggable.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content

    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;
    }
    
  2. Skip to note content
    Contributed by polev

    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;
    }

You must log in before being able to contribute a note or feedback.