PrivateContent Plugin

API Documentation

API Functions

Introduction

Global PHP functions, used to perform essential operations. Reachable from any page or context.
Source code in public_api.php file.

pc_user_logged()

Function used to check wheter user is logged and eventually to retrieve specific data

Usage
pc_user_logged($get_data = true)
Parameters
(mixed) $get_data
true(default) to return full user data + meta
falseto return only a boolean value
fields arrayto return only them

Return Values
falseif user is not logged
trueif user is logged and no data must be returned
associative arrayin case of multiple data to return (key => val)

mixedif want to get only one value (directly returns value)

Example
<?php
// print currently logged user's username
if(($data = pc_user_logged('username')) !== false) {
	echo $data;		
}
else {
	// user isn't logged	
}
?>
pc_user_check()

Function used to check wheter user has got required permissions

Usage
pc_user_check($allowed = 'all', $blocked = '', $wp_user_pass = false, $allow_filter = true)
Parameters
(array) $allowed

Allowed user categories

all(default) - any logged user
unloggedonly unlogged users
user categories id stringeg. (2, 10, 45)

(array) $blockeduser categories blocked in this match. By default empty
(bool) $wp_user_passwhether to count logged WP users checking permission (check 'testing mode' in settings). By default false
(bool) $allow_filterwhether to apply filters if "all" and "unlogged" options are selected. By default true
Return Values
falseuser is not logged
1user has got right permissions
2user has got wrong permissions

Example
<?php
// allow only user categories 1 and 3 - block 2 and allow WP users
$check = pc_user_check(array(1, 3), array(2), true, true);

if($check === 1) {
	// user has got permissions
}
elseif($check === 2) {
	// user has got wrong permissions
}
else {
	// user isn't logged	
}
?>
pc_login_form()

Function used to get login form code

Usage
pc_login_form($redirect = '')
Parameters
(string) $redirectforces a specific redirect after login - must be a valid URL
Return Values
(string) form code ready to be printed. Will be empty if user is already logged
Example
<?php
// print login form using a custom redirect after login
echo pc_login_form('http://www.lcweb.it/');
?>
pc_logout_btn()

Function used to get logout box code

Usage
pc_logout_btn($redirect = '')
Parameters
(string) $redirectforces a specific redirect after login - must be a valid URL
Return Values
(string) box code ready to be printed. Will be empty if user is not logged
Example
<?php
// print logout box using a custom redirect after logout
echo pc_logout_btn('http://www.lcweb.it/');
?>
pc_login()

Function used to log in users

Usage
pc_login($username, $psw, $remember_me = false)
Parameters
(string) $usernamelogin username (you may pass also user e-mail if related option is enabled in settings)
(string) $pswlogin password
(bool) $remember_mewhether to use extended cookies (6 months)
Return Values
falseuser not found
trueuser successfully logged
(int) 2 or 3value related to user's status (2 => disabled, 3 => pending)

(string)custom message returned by custom check

Example
<?php
// login user using remember-me
if( pc_login('test', 'test-psw', true) === true) {
	// user is logged now	
}
?>
pc_logout()

Function used to logout the user - deleting session and cookies

Usage
pc_logout()

Alternatively remember you can use any site URL + ?pc_logout parameter.
Example: http://www.lcweb.it/?pc_logout

pc_registration_form()

Function used to print registration form

Usage
pc_registration_form($form_id, $layout = '', $forced_cats = false, $redirect = false)
Parameters
(int) $form_idRegistration form ID
(string) $layout

Registration form layout. Options

empty string(default) - uses global form layout
one_colforce one-column layout
fluidforce fluid layout
(int) $forced_catsOptionally set custom categories assigned to new users. Option discarded if category field is used in the form.
Use user categories ID (comma split)
(string) $redirectforces a specific redirect after login - must be a valid URL
Return Values
(string) form code ready to be printed.
Example
<?php
// print registration form #150 with fluid layout and assigning users to cats 2 and 3
echo pc_registration_form(150, 'fluid', '2,3');
?>
pc_man_redirects()

Function used to return redirect URL in specific contexts.
Considers settings custom redirects and already uses WPML/Polylang translations.

Usage
pc_man_redirects($key)
Parameters
(string) $key

redirect id. Currently available ones:

pc_redirect_pagemain redirect for restricted areas
pc_logged_user_redirectredirect for logged in users
pc_logout_user_redirectredirect for logged out users
pc_registered_user_redirectredirect for registered users
Return Values
(string)redirect URL requested
Example
<?php
// use proper WP hook to move users to main redirect target 
function pc_test_redirect() {
	header('location: '. pc_man_redirects('pc_redirect_page') );
}	
add_action('template_redirect', 'pc_test_redirect', 1);
?>
pc_get_message()

Function used to return specific plugin message, considering Settings customization.
Already uses WPML/Polylang translations.

Usage
pc_get_message($subj, $custom_txt = '')
Parameters
(string) $subj

Message id. Currently available ones:

pc_default_nl_mexMessage for not logged users
pc_default_uca_mexMessage if user doesn't have right permissions
pc_default_hc_mexMessage if user can't post comments
pc_default_hcwp_mexMessage if user doesn't have permissions to post comments
pc_default_nhpa_mexMessage if user doesn't have reserved area
pc_login_ok_mexMessage for successful login
pc_default_pu_mexMessage for pending users trying to login
pc_default_sr_mexMessage if successfully registered
(string) $custom_txtoptionally forces a new text
Return Values
(string)message requested

Example
<?php
// getting message for unlogged users
$message = pc_get_message('pc_default_nl_mex');
?>

Let's get in touch!

Features list