LLMS_Sessions::start( int $user_id = null )

Start a new session for the current user.


Parameters Parameters

$user_id

(int) (Optional) WP_User ID of a student. Default null If not provided, or a falsy is provided, will fall back on the current user id.

Default value: null


Top ↑

Return Return

(false|LLMS_Event|WP_Error)


Top ↑

Source Source

File: includes/class-llms-sessions.php

	public function start( $user_id = null ) {

		$user_id = $user_id ? $user_id : get_current_user_id();
		if ( ! $user_id ) {
			return false;
		}

		$start = llms()->events()->record(
			array(
				'actor_id'     => $user_id,
				'object_type'  => 'session',
				'object_id'    => $this->get_new_id( $user_id ),
				'event_type'   => 'session',
				'event_action' => 'start',
			)
		);

		if ( ! is_wp_error( $start ) ) {
			global $wpdb;
			$wpdb->query( // db call ok; no-cache ok.
				$wpdb->prepare(
					"
					INSERT INTO {$wpdb->prefix}lifterlms_events_open_sessions ( `event_id` ) VALUES ( %d )
					",
					$start->get( 'id' )
				)
			);
		}

		return $start;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.5.0 Create open session entry in the wp_lifterlms_events_open_sessions table. Added optional $user_id parameter.
3.36.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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