WC_Session_Handler::set_session_expiration
Set session expiration.
Метод класса: WC_Session_Handler{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WC_Session_Handler = new WC_Session_Handler(); $WC_Session_Handler->set_session_expiration();
Код WC_Session_Handler::set_session_expiration() WC Session Handler::set session expiration WC 10.4.3
public function set_session_expiration() {
$default_expiring_seconds = DAY_IN_SECONDS;
$default_expiration_seconds = is_user_logged_in() ? WEEK_IN_SECONDS : 2 * DAY_IN_SECONDS;
$max_expiration_seconds = MONTH_IN_SECONDS;
$max_expiring_seconds = $max_expiration_seconds - DAY_IN_SECONDS;
$session_limit_exceeded = false;
/**
* Filters the session expiration.
*
* @since 5.0.0
* @param int $expiration_seconds The expiration time in seconds.
*/
$expiring_seconds = intval( apply_filters( 'wc_session_expiring', $default_expiring_seconds ) ) ?: $default_expiring_seconds; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
if ( $expiring_seconds > $max_expiring_seconds ) {
$session_limit_exceeded = true;
}
/**
* Filters the session expiration.
*
* @since 5.0.0
* @param int $expiration_seconds The expiration time in seconds.
*/
$expiration_seconds = intval( apply_filters( 'wc_session_expiration', $default_expiration_seconds ) ) ?: $default_expiration_seconds; // phpcs:ignore Universal.Operators.DisallowShortTernary.Found
// We limit the expiration time to 30 days to avoid performance issues and the session table growing too large.
if ( $expiration_seconds > $max_expiration_seconds ) {
$session_limit_exceeded = true;
}
if ( $session_limit_exceeded ) {
$transient_key = 'wc_session_handler_warning';
if ( false === get_transient( $transient_key ) ) {
wc_get_logger()->warning(
sprintf(
'Keeping sessions for longer than %d days can cause performance issues and larger session tables. Monitor usage and adjust lifetimes via the wc_session_expiring and wc_session_expiration filters as needed.',
$max_expiration_seconds / DAY_IN_SECONDS
),
array( 'source' => 'wc_session_handler' )
);
set_transient( $transient_key, true, $max_expiration_seconds );
}
}
// If the expiring time is greater than the expiration time, set the expiring time to 90% of the expiration time.
if ( $expiring_seconds > $expiration_seconds ) {
$expiring_seconds = $expiration_seconds * 0.9;
}
$this->_session_expiring = time() + $expiring_seconds;
$this->_session_expiration = time() + $expiration_seconds;
}