PrivateContent

API Documentation

Users Meta Manag. class

Introduction

PHP class used to manage users meta data: insertion, editing, deletion.
Is instantiated in website and reachable through php global pc_meta.

Extends main pc_users class.
Located in classes folder.

has_meta()

Method used to know if user has got a meta data in database

Usage
has_meta($subj, $meta_name, $get = array('meta_id'))
Parameters
(int/string) $subjuser id or username
(string) $meta_namemeta data key to match
(array) $getfields to return. Could be: meta_id and/or meta_value
Return Values
(mixed)what you requested (meta_id or value)
(bool)false if user doesn't have the meta
get_meta()

Method used to get single user's meta data

Usage
get_meta($subj, $meta_name)
Parameters
(int/string) $subjuser id or username
(string) $meta_namemeta data key to match
Return Values
(mixed)meta value (in case, already unserialized)
(bool)false if user doesn't have the meta
Example
<?php
// print meta data 'test' for user #5
global $pc_meta;
echo $pc_meta->get_meta(5, 'test');
?>
add_meta()

Method used to add a user's meta.
If it already exists in database, will be updated.

Usage
add_meta($subj, $meta_name, $value)
Parameters
(int/string) $subjuser id or username
(string) $meta_namemeta data key to add - max 255 characters long
(mixed) $valuemeta data value. Could be anything, also an array or an object
Return Values
(int)meta data ID if has been successfully created
(bool)false if an error occurred
Example
<?php
// add meta data 'test' for user #5
global $pc_meta;

$data = array('something' => 'else', 'yet some data', 2);
$result = $pc_meta->add_meta(5, 'test', $data);

if($result) {
	// meta added	
} else {
	// error occurred	
}
?>
update_meta()

Method used to update a user's meta.
If it doesn't exist in database, will be added.

Usage
update_meta($subj, $meta_name, $value)
Parameters
(int/string) $subjuser id or username
(string) $meta_namemeta data key to update
(mixed) $valuemeta data value. Could be anything, also an array or an object
Return Values
(int)meta data ID if has been successfully created
(bool)false if an error occurred
delete_meta()

Method used to delete a user's meta.

Usage
delete_meta($subj, $meta_name)
Parameters
(int/string) $subjuser id or username
(string) $meta_namemeta data key to delete
Return Values
(bool)true if data has been deleted, otherwise false
bulk_meta_action()

Method used to perform a bulk meta action for one or multiple users.

Usage
bulk_meta_action($users, $action, $meta_name, $value = '', $data_type = 'id')
Parameters
(int/string/array) $users single user ID/username or array containing usernames or IDs but must be uniform
(string) $actionbulk action to perform (add / update / delete)
(string) $meta_namemeta data key to add/update/delete - max 255 characters long
(mixed) $valuemeta data value to add/update. Could be anything, also an array or an object
(string) $data_typedeclares the data type passed in $users array (id / username)
Return Values
(bool)true if operation is complete, otherwise false
Example
<?php
// add meta 'test' for multiple users
global $pc_meta;

$data = array('something' => 'else', 'yet some data', 2);
$users = array(5,7,9,10); // users ID array

$result = $pc_meta->bulk_meta_action($users, 'add', 'test', $data);

if($result) {
	// meta added	
} else {
	// error occurred	
}
?>