LLMS_Sessions::is_session_idle( LLMS_Event $start )

Determine if a session is idle.


Description Description

A session is considered idle if it’s open and no new events have been recorded in the last 30 minutes.


Top ↑

Parameters Parameters

$start

(LLMS_Event) (Required) Event record for the start of the session.


Top ↑

Return Return

(bool)


Top ↑

Source Source

File: includes/class-llms-sessions.php

	public function is_session_idle( $start ) {

		// Session is closed so it can't be idle.
		if ( ! $this->is_session_open( $start ) ) {
			return false;
		}

		$now = llms_current_time( 'timestamp' );

		/**
		 * Filter the time (in minutes) to allow a session to remain open before it's considered an "idle" session.
		 *
		 * @param int $minutes Number of minutes.
		 */
		$timeout = absint( apply_filters( 'llms_idle_session_timeout', 30 ) ) * MINUTE_IN_SECONDS;

		// Session has started within the idle window, so it can't have expired yet.
		if ( ( $now - strtotime( $start->get( 'date' ) ) ) < $timeout ) {
			return false;
		}

		$events = $this->get_session_events(
			$start,
			array(
				'per_page'      => 1,
				'sort'          => array(
					'date' => 'DESC',
				),
				'no_found_rows' => true,
			)
		);

		// No events, the session is idle.
		if ( ! $events ) {
			return true;
		}

		$last_event = array_shift( $events );
		return ( ( $now - strtotime( $last_event->get( 'date' ) ) ) > $timeout );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.7.0 When retrieving the last event, instantiate the events query passing no_found_rows arg as true, to improve performance.
3.36.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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