Notice: Undefined variable: result in /home/liberaco/public_html/lcweb.it/wp-content/plugins/private-content-api-doc/sub_texts/wp_sync_class.php on line 239

Notice: Trying to get property of non-object in /home/liberaco/public_html/lcweb.it/wp-content/plugins/private-content-api-doc/sub_texts/wp_sync_class.php on line 239

WP User Sync Class

Introduction

PHP class used to manage relationsips between PrivateContent users and their Wordpress mirrors: sync, unsync, checks.
Is instantiated in website and reachable through php global pc_wp_user.

Extends main pc_users class.
Located in classes folder.

Properties
(bool/array) $wps_rolesarray of custom roles assigned to mirror WP users.
By default is false, filled only using get_wps_custom_roles() or set_wps_custom_roles() methods
(string) $pwu_sync_errorstatic resource for WP sync errors printing - contains a string
global_sync()

Method used to sync whole privateContent users database.
Obviosly users must have an unique e-mail to be synced.

Usage
global_sync()
Parameters

no parameters

Return Values
(string)message containing how many users have been synced and how many failed because of their username or e-mail
Example
<?php
// perform a global sync and print results
global $pc_wp_user;
echo $pc_wp_user->global_sync();
?>
sync_wp_user()

Method used to sync a single user.
Used also to update synced WP user's data.

Usage
sync_wp_user($user_data, $existing_id = 0, $save_in_db = false)
Parameters
(array) $user_dataassociative array containing data to use for new WP user. Indexes:

  • username (required if not updating)
  • email (required)
  • psw (required if not updating)
  • name
  • surname
(int) $existing_idexisting, synced, WP user to update
(bool) $save_in_dbwhether to save the created WP user ID in pvtContent database
Return Values
(bool/int)created/updated user ID or false
Example
<?php
// sync a single user and save into database
global $pc_wp_user;

$data = array(
	'username'	=> 'test',
	'email'		=> [email protected]',
	'psw'		=> 'test',
);
$result = $pc_wp_user->sync_wp_user($data, 0, true);

if($result) {
	// user added successfully	
} else {
	// print errors
	echo $pc_wp_user->pwu_sync_error;
}
?>
search_and_sync_matches()

Method used to search matches between unsynced PrivateContent users and WP ones.
Matching uesrs will be synced (be careful, WP users will become PrivateContent mirrors).

Usage
search_and_sync_matches()
Parameters

no parameters

Return Values
(string)message containing how many users have been synced
global_detach()

Method used to globally detach synced users. Wordpress mirror users will be deleted.

Usage
global_detach()
Parameters

no parameters

Return Values
(string)message confirming successful detach
detach_wp_user()

Method used to sync a single user.
Used also to update synced WP user's data.

Usage
detach_wp_user($user_id, $save_in_db = true, $wp_user_id = false)
Parameters
(int) $user_idPrivateContent user ID to detach
(bool) $save_in_dbwhether to update user records in pvtContent database
(bool) $wp_user_iddirectly pass synced wp user ID to delete (avoid one query)
Return Values
(bool)true
Example
<?php
// detach user #5 and save into database
global $pc_wp_user;
$pc_wp_user->detach_wp_user(5, true);
?>
wp_user_is_linked()

Method used to know if a Wordpress user is synced

Usage
wp_user_is_linked($user_id)
Parameters
(int) $user_idWordpress user ID
Return Values
(bool/obj)false if user is not synced otherwise the query object.
Object contains ID, (serialized) categories and status of synced Privatecontent user
Example
<?php
// know if WP user #5 is synced and get related privatecontent user ID
global $pc_wp_user;
$result = $pc_wp_user->wp_user_is_linked(5);

if($result) {
	echo ; 	
}
?>
pvtc_is_synced()

Method used to know if a PrivateContent user is synced

Usage
pvtc_is_synced($user_id, $return_id = false)
Parameters
(int) $user_idPrivateContent user ID
(bool) $return_idwhether to return found WP user id directly
Return Values
(bool/obj)false if user is not synced otherwise user data got through get_userdata()
update_nicename()

Method used to update Wordpress user nicename

Usage
update_nicename($wp_user_id)
Parameters
(int) $wp_user_idWordpress user ID
Return Values

no data returned

new_mail_is_ok()

Method used to know if a new e-mail is ok for a Wordpress user

Usage
new_mail_is_ok($wp_user_id, $email)
Parameters
(int) $wp_user_idWordpress user ID
(string) $emailnew e-mail
Return Values
(bool)true or false
wp_user_exists()

Method used to know if username or e-mail are already used by another WP user

Usage
wp_user_exists($username, $email)
Parameters
(string) $usernameusername to match
(string) $emaile-mail to match
Return Values
(bool)true if is used, otherwise false
get_wps_custom_roles()

Method used to get custom roles applied to synced users (set in PrivateContent settings)

Usage
get_wps_custom_roles()
Parameters

no parameters

Return Values
(array)array containing roles
set_wps_custom_roles()

Method used to get custom roles applied to synced users (set in PrivateContent settings)

Usage
set_wps_custom_roles($user_id = false, $is_new_user = false)
Parameters
(int/array) $wp_user_idsingle WP user ID to update or multiple IDs - by default updates any synced user
(bool) $is_new_userif true, avoid update when role is only pvtcontent
Return Values
(bool)true if operation ended successfully, otherwise false
lcwebPrivateContent – API documentation