SessionHandler
extends WC_Session
in package
SessionHandler class
Token-based session handler for the Store API. Unlike WC_Session_Handler which uses browser cookies, this handler uses an HTTP_CART_TOKEN header (JWT-like) to identify sessions. It shares the same database table but has no cookie, cron, or cache layer.
Tags
Table of Contents
- $_customer_id : string|null
- Customer ID.
- $_data : array<string|int, mixed>
- Session Data.
- $_dirty : bool
- Dirty when the session needs saving.
- $session_expiration : int
- Expiration timestamp.
- $table : string
- Table name for session data.
- $token : string
- Token from HTTP headers.
- __construct() : mixed
- Constructor for the session class.
- __get() : mixed
- Magic get method.
- __isset() : bool
- Magic isset method.
- __set() : mixed
- Magic set method.
- __unset() : mixed
- Magic unset method.
- cleanup_sessions() : mixed
- Cleanup session data. Extended by child classes.
- delete_session() : void
- Delete the session from the database.
- destroy_session() : void
- Destroy all session data.
- forget_session() : void
- Forget all session data without destroying persisted storage.
- generate_customer_id() : string
- Generate a unique customer ID for guests, or return user ID if logged in.
- get() : mixed
- Get a session variable.
- get_customer_id() : string
- Get customer ID. If the session is not initialized, returns an empty string.
- get_customer_unique_id() : string
- Get session unique ID for requests if session is initialized or user ID if logged in.
- get_session() : mixed
- Returns the session.
- get_session_data() : array<string|int, mixed>
- Get session data fresh from storage.
- has_session() : bool
- Return true if the current user has an active session.
- init() : mixed
- Init hooks and session data.
- save_data() : void
- Save data and delete user session.
- set() : mixed
- Set a session variable.
- init_session_from_token() : mixed
- Process the token header to load the correct session.
Properties
$_customer_id
Customer ID.
protected
string|null
$_customer_id
$_data
Session Data.
protected
array<string|int, mixed>
$_data
= array()
$_dirty
Dirty when the session needs saving.
protected
bool
$_dirty
= alse
$session_expiration
Expiration timestamp.
protected
int
$session_expiration
= 0
$table
Table name for session data.
protected
string
$table
= ''
$token
Token from HTTP headers.
protected
string
$token
= ''
Methods
__construct()
Constructor for the session class.
public
__construct() : mixed
Return values
mixed —__get()
Magic get method.
public
__get(string $key) : mixed
Parameters
- $key : string
-
Key to get.
Return values
mixed —__isset()
Magic isset method.
public
__isset(string $key) : bool
Parameters
- $key : string
-
Key to check.
Return values
bool —__set()
Magic set method.
public
__set(string $key, mixed $value) : mixed
Parameters
- $key : string
-
Key to set.
- $value : mixed
-
Value to set.
Return values
mixed —__unset()
Magic unset method.
public
__unset(string $key) : mixed
Parameters
- $key : string
-
Key to unset.
Return values
mixed —cleanup_sessions()
Cleanup session data. Extended by child classes.
public
cleanup_sessions() : mixed
Return values
mixed —delete_session()
Delete the session from the database.
public
delete_session(string $customer_id) : void
Parameters
- $customer_id : string
-
Customer session ID.
Return values
void —destroy_session()
Destroy all session data.
public
destroy_session() : void
Return values
void —forget_session()
Forget all session data without destroying persisted storage.
public
forget_session() : void
Return values
void —generate_customer_id()
Generate a unique customer ID for guests, or return user ID if logged in.
public
generate_customer_id() : string
Return values
string —get()
Get a session variable.
public
get(string $key[, mixed $default_value = null ]) : mixed
Parameters
- $key : string
-
Key to get.
- $default_value : mixed = null
-
used if the session variable isn't set.
Return values
mixed — value of session variableget_customer_id()
Get customer ID. If the session is not initialized, returns an empty string.
public
get_customer_id() : string
Return values
string —get_customer_unique_id()
Get session unique ID for requests if session is initialized or user ID if logged in.
public
get_customer_unique_id() : string
Return values
string —get_session()
Returns the session.
public
get_session(string $customer_id[, mixed $default_value = false ]) : mixed
Parameters
- $customer_id : string
-
Customer ID.
- $default_value : mixed = false
-
Default session value.
Return values
mixed — Returns either the session data or the default value. Returns false if WP setup is in progress.get_session_data()
Get session data fresh from storage.
public
get_session_data() : array<string|int, mixed>
This re-reads session data from the database rather than returning in-memory data, ensuring the latest persisted state is returned.
Return values
array<string|int, mixed> —has_session()
Return true if the current user has an active session.
public
has_session() : bool
Return values
bool —init()
Init hooks and session data.
public
init() : mixed
Return values
mixed —save_data()
Save data and delete user session.
public
save_data() : void
Return values
void —set()
Set a session variable.
public
set(string $key, mixed $value) : mixed
Parameters
- $key : string
-
Key to set.
- $value : mixed
-
Value to set.
Return values
mixed —init_session_from_token()
Process the token header to load the correct session.
protected
init_session_from_token() : mixed
