LLMS_Session::set( string $key, mixed $value )

Store a piece of data on the session.


Description Description

Overrides the abstract setter so a deferred session cookie is emitted the moment data is first written to a brand-new session. Anonymous visitors who never write session data never receive the cookie, which keeps their page views eligible for full-page caching. Every first-party write path (coupons, notices, gift and group checkout) runs during request processing, before any output, so the cookie is emitted in time to take effect, the same way the cookie was previously emitted from the constructor.


Top ↑

Parameters Parameters

$key

(string) (Required) Session data key.

$value

(mixed) (Required) Session data value.


Top ↑

Return Return

(mixed) The stored value.


Top ↑

Source Source

File: includes/class.llms.session.php

	public function set( $key, $value ) {

		$value = parent::set( $key, $value );

		// A brand-new session now has data: emit the deferred cookie —
		// but only if the data is actually non-empty. An empty write
		// (e.g. llms_clear_notices storing []) should not trigger cookie
		// emission or a database row.
		if ( $this->is_new && ! $this->is_clean ) {
			if ( $this->session_has_data() ) {
				$this->set_cookie();
				$this->is_new = false;
			} else {
				// All values are empty — reset so shutdown won't write a useless DB row.
				$this->is_clean = true;
			}
		}

		return $value;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
10.0.7 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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