LLMS_Abstract_Session_Database_Handler::read( string $key, array $default = array() )

Retrieve session data from the database


Parameters Parameters

$key

(string) (Required) Session key.

$default

(array) (Optional) Default value used when no data exists.

Default value: array()


Top ↑

Return Return

(string|array)


Top ↑

Source Source

File: includes/abstracts/llms-abstract-session-database-handler.php

	public function read( $key, $default = array() ) {

		$cache_key = $this->get_cache_key( $key );
		$data      = wp_cache_get( $cache_key, $this->cache_group );

		if ( false === $data ) {

			global $wpdb;

			$data = $wpdb->get_var( $wpdb->prepare( "SELECT `data` FROM {$wpdb->prefix}lifterlms_sessions WHERE `session_key` = %s", $key ) );  // phpcs:ignore: WordPress.DB.DirectDatabaseQuery.DirectQuery

			if ( is_null( $data ) ) {
				$data = $default;
			}

			$duration = $this->expires - time();
			if ( 0 < $duration ) {
				wp_cache_set( $cache_key, $data, $this->cache_group, $duration );
			}
		}

		return maybe_unserialize( $data );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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