PrivateContent

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
false to return only a boolean value
fields array to return only them

Return Values
false if user is not logged
true if user is logged and no data must be returned
associative array in case of multiple data to return (key => val)

mixed if 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
unlogged only unlogged users
user categories id string eg. (2, 10, 45)

(array) $blocked user categories blocked in this match. By default empty
(bool) $wp_user_pass whether to count logged WP users checking permission (check 'testing mode' in settings). By default false
(bool) $allow_filter whether to apply filters if "all" and "unlogged" options are selected. By default true
Return Values
false user is not logged
1 user has got right permissions
2 user 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) $redirect forces 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) $redirect forces 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) $username login username (you may pass also user e-mail if related option is enabled in settings)
(string) $psw login password
(bool) $remember_me whether to use extended cookies (6 months)
Return Values
false user not found
true user successfully logged
(int) 2 or 3 value 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_id Registration form ID
(string) $layout

Registration form layout. Options

empty string (default) - uses global form layout
one_col force one-column layout
fluid force fluid layout
(int) $forced_cats Optionally set custom categories assigned to new users. Option discarded if category field is used in the form.
Use user categories ID (comma split)
(string) $redirect forces 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_page main redirect for restricted areas
pc_logged_user_redirect redirect for logged in users
pc_logout_user_redirect redirect for logged out users
pc_registered_user_redirect redirect 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_mex Message for not logged users
pc_default_uca_mex Message if user doesn't have right permissions
pc_default_hc_mex Message if user can't post comments
pc_default_hcwp_mex Message if user doesn't have permissions to post comments
pc_default_nhpa_mex Message if user doesn't have reserved area
pc_login_ok_mex Message for successful login
pc_default_pu_mex Message for pending users trying to login
pc_default_sr_mex Message if successfully registered
(string) $custom_txt optionally forces a new text
Return Values
(string) message requested

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