$meta
$meta :
__construct(\TriTan\Interfaces\MetaDataInterface $meta, \TriTan\Interfaces\UtilsInterface $util)
\TriTan\Interfaces\MetaDataInterface | $meta | |
\TriTan\Interfaces\UtilsInterface | $util |
create(integer $user_id, string $meta_key, mixed $meta_value, boolean $unique = false) : integer|false
Add meta data field to a user.
integer | $user_id | User ID. |
string | $meta_key | Metadata name. |
mixed | $meta_value | Metadata value. Must be serializable if non-scalar. |
boolean | $unique | Optional. Whether the same key should not be added. Default false. |
Meta ID on success, false on failure.
read(integer $user_id, string $key = '', boolean $single = false) : mixed
Retrieve user meta field for a user.
integer | $user_id | User ID. |
string | $key | Optional. The meta key to retrieve. By default, returns data for all keys. Default empty. |
boolean | $single | Optional. Whether to return a single value. Default false. |
Will be an array if $single is false. Will be value of meta data field if $single is true.
update(integer $user_id, string $meta_key, mixed $meta_value, mixed $prev_value = '') : integer|boolean
Update user meta field based on user ID.
Use the $prev_value parameter to differentiate between meta fields with the same key and user ID.
If the meta field for the user does not exist, it will be added.
integer | $user_id | User ID. |
string | $meta_key | Metadata key. |
mixed | $meta_value | Metadata value. Must be serializable if non-scalar. |
mixed | $prev_value | Optional. Previous value to check before removing. Default empty. |
Meta ID if the key didn't exist, true on successful update, false on failure.
delete(integer $user_id, string $meta_key, mixed $meta_value = '') : boolean
Remove metadata matching criteria from a user.
You can match based on the key, or key and value. Removing based on key and value, will keep from removing duplicate metadata with the same key. It also allows removing all metadata matching key, if needed.
integer | $user_id | User ID. |
string | $meta_key | Metadata name. |
mixed | $meta_value | Optional. Metadata value. Must be serializable if non-scalar. Default empty. |
True on success, false on failure.