UserMetaService
in package
Provides service to store user meta
Tags
Table of Contents
Properties
- $user : mixed
- $user_data : mixed
- $user_meta : mixed
Methods
- __construct() : mixed
- This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.
- find() : mixed
- Retrieve a meta value for a given user.
- save() : void
- Save a user meta key-value pair.
Properties
$user
protected
mixed
$user
$user_data
protected
mixed
$user_data
$user_meta
protected
mixed
$user_meta
Methods
__construct()
This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.
public
__construct() : mixed
If the user is not valid, the process is halted with an error message.
It also initializes the appropriate user_meta
Tags
find()
Retrieve a meta value for a given user.
public
find(string $name[, int|null $user_id = null ]) : mixed
This method fetches the stored value associated with a specific key (name) for the given user. If no user ID is provided, it defaults to the current user session.
Parameters
- $name : string
-
The name of the key whose value is to be retrieved.
- $user_id : int|null = null
-
(Optional) The ID of the user. Defaults to NULL (current user session).
Return values
mixed —The stored value associated with the specified key, or NULL if not found.
save()
Save a user meta key-value pair.
public
save(string $name, string $value[, int|null $user_id = null ]) : void
Stores a value associated with a specific key. If a user ID is provided, the value is saved for that user. If no user ID is provided, the value is associated with the current user session.
Parameters
- $name : string
-
The name under which the value will be stored.
- $value : string
-
The value to be stored (preferably in JSON format).
- $user_id : int|null = null
-
(Optional) The ID of the user. Defaults to NULL (current user session).