Hooks - Filters

pc_add_user_form_validation

Add fields to validate and save in "add user" page.
Additional fields must be inserted into form framework through pc_form_fields_filter filter.

Parameters

First parameter (array) passes form structure (array of fields key).

Must comply with used structure. Example

$form_structure = array(
	'include' => array('name', 'surname', 'username'),
	'require' => array('surname', 'username')
);
Usage
<?php
// add a new field in 'add user' page
function foo($fields) {
	$fields['include'][] = 'field1';
	$fields['include'][] = 'field2';
	
	$fields['require'][] = 'field1';
	
	return $fields;
}
add_filter('pc_add_user_form_validation', 'foo');
?>
pc_complete_lock_exceptions

Add pages to be excluded from "complete site lock". Use only pages ID.

Parameters
  1. (array) array containing excluded page ids
Usage
<?php
// exclude page 100 from lock
function foo($pages) {
	$pages[] = 100;
	return $pages;
}
add_filter('pc_complete_lock_exceptions', 'foo');
?>
pc_custom_restriction

Add specific URLs to be restricted following user categories. Supports also regular expressions, so you can target multiple pages at once.
Users not having correct permissions will be moved to main redirect target.

Parameters
  1. (array) associative array having URL as key and restriction pattern as value
Usage
<?php
// restrict an URL or URLs matching a regular expression, allowing only users belonging to categories 2 and 4 - blocking 3
function foo($restrictet_urls) {
	$restrictet_urls['http://www.lcweb.it/privatecontent/public-api'] = array(
		'allowed' => '2,4'
		'blocked' => 3
	);
	
	return $restrictet_urls;
}
add_filter('pc_custom_restriction', 'foo');
?>
pc_customize_message

Customize a specific plugin message, overriding previously declared customizations in settings.

Parameters
  1. (string) message that would be returned normally
  2. (string) message key, check list here
Usage
<?php
// customize message for logged in users
function foo($mess, $subj) {
	if($subj == 'pc_login_ok_mex') {
		return 'Custom message!';	
	}
}
add_filter('pc_customize_message', 'foo', 10, 2);
?>
pc_data_to_human

Customize how fetched database data is returned through data_to_human() method.
Be careful: once you use it, default data management is overrided.

Parameters
  1. (string) data as returned by database query (serialized data is unmanaged)
  2. (string) field index
Usage
<?php
// costomize how name is returned, capitalizing it
function foo($data, $subj) {
	if($subj == 'name') {
		return strtoupper($data);	
	}
}
add_filter('pc_data_to_human', 'foo', 10, 2);
?>
pc_export_fields

Add fields to be included in exported data.
Passes through get_users method, then must be stored in meta data table.

Parameters
  1. (array) fields key array to be fetched
Usage
<?php
// export also "test_field" - contained in meta-data table
function foo($to_get) {
	$to_get[] = 'test_field';
	return $to_get;
}
add_filter('pc_export_fields', 'foo');
?>
pc_form_fields_filter

Extend PrivateContent fields adding new ones.
New fields automatically setup also validations.

Parameters

Only one parameter: associative array of associative array(field-key => values array) containing existing fields.
Each array element defines a specific field aspect and validation parameters. Here's a guideline for indexes and possible values

keydescription
(string) (mandatory) labelfield label, used alo in forms
(string) (mandatory) type field type. Choose among:

texttext field (cases may be specified in subtype)
selectdropdown field
textarea
checkboxmulti-option checkbox
single_checkboxsingle-option checkbox
(string) subtype text fields subtype.
Leave empty to use a normal text input or choose among:

emailinserted data have to match e-mail format
intinserted data must be an integer number
floatinserted data must be a floating number (international format)
eu_dateinserted data must be an european date DD/MM/YYYY
us_dateinserted data must be an american date MM/DD/YYYY
us_telinserted data must be an american telephone number
zipcodeinserted data must be an american ZIP code
urlinserted data must be a valid URL
(int) maxlentextual fields characters limitation
(string) regextextual fields advanced validation. Will be used with preg_match() function
(int) range_fromnumeric fields limit, defines minimum accepted value.
Could be a floating number according to chosen subytpe
(int) range_tonumeric fields limit, defines maximum accepted value.
Could be a floating number according to chosen subytpe
(string) optionsselect field options. They must be comma split
(string) placehtextual fields placeholder
(bool) multipleselect field switch: true to allow multi-option selection
(string) check_txtsingle-option checkbox parameter, defining text shown on check's side
(bool) disclaimersingle-option checkbox switch: true if field must be shown in disclaimers box
Usage
<?php
// add a new integer text field with specific limitations and a dropdown field
function foo($fields) {
	
	$fields['new_field1'] = array(
		'label' 	=> 'Field 1 Label',
		'type' 		=> 'text',
		'subtype' 	=> 'int',
		'range_from'=> 10,
		'range_to'	=> 50,
		'placeh'	=> 'insert a number between 10 and 50',
		'note' 		=> 'internal note',
	); 
	
	$fields['new_field2'] = array(
		'label' 	=> 'Field 2 Label'
		'type' 		=> 'select',
		'opt'		=> 'opt 1, opt 2, opt 3'
		'note' 		=> 'internal note'
		'multiple'	=> false
	);
	
	return $fields;
}
add_filter('pc_form_fields_filter', 'foo');
?>
pc_form_valid_errors

Adds the ability to perform custom validations in forms managed by form framework class (registration, insertion, update).

Parameters
  1. (string) errors already found, HTML readyto be printed
  2. (array) associative array of fetched value (field_name => field_value)
Usage
<?php
// return an error if e-mail field doesn't contain @lcweb.it
function foo($errors, $fdata) {
	if(isset($fdata['email']) && strpos($fdata['email'], [email protected]') === false) {
		$errors .= '
E-mail must be of @lcweb.it domain!'; } return $errors; } add_filter('pc_form_valid_errors', 'foo', 10, 2); ?>
pc_insert_user_data_check

Performs custom data validation before user is inserted into database

Parameters
  1. (string) errors already found, HTML readyto be printed
  2. (array) associative array of fetched value (field_name => field_value)
Usage
<?php
// return an error if e-mail field doesn't contain @lcweb.it
function foo($errors, $fdata) {
	if(isset($fdata['email']) && strpos($fdata['email'], [email protected]') === false) {
		$errors .= '
E-mail must be of @lcweb.it domain!'; } return $errors; } add_filter('pc_insert_user_data_check', 'foo', 10, 2); ?>
pc_insert_user_required_fields

Set additional required fields for user insertion

Parameters
  1. (array) array containing field names. Values must be registered in form framework
Usage
<?php
// set name field as mandatory
function foo($fields) {
	$fields['name'];
	return $fields;
}
add_filter('pc_insert_user_required_fields', 'foo');
?>
pc_login_custom_check

Allows custom checks before allowing user to log in

Parameters
  1. (bool/text) by default is false and allow login. Return text to abort login
  2. (int) user ID - useful to perform database checks
pc_meta_val

Additional data management for fetched meta values

Parameters
  1. (mixed) fetched meta value (array and objects already unserialized)
  2. (string) meta key
Usage
<?php
// use strtoupper on fetched meta "test"
function foo($val, $meta_key) {
	if($meta_key == 'test') {
		$val = strtoupper($val);	
	}
	return $val;
}
add_filter('pc_insert_user_required_fields', 'foo', 10, 2);
?>
pc_pvt_page_contents

Manage users private page contents. Useful to prepend or append elements

Parameters
  1. (string) private page contents
Usage
<?php
// print 'lorem ipsum' paragraph before contents
function foo($contents) {
	return '

lorem ipsum

' . $contents; } add_filter('pc_pvt_page_contents', 'foo'); ?>
pc_registration_form

Manage registration forms structure. Set included and required fields.
Fields must be registered in form framework.

Parameters
  1. (array) associative array having this structure array('include' => included fields array, 'require' => included fields array)
  2. (int) registration form ID
Usage
<?php
// add 'test' field into registation form and set it as required
function foo($structure) {
	
	$structure['include'][] = 'test';
	$structure['require'][] = 'test';
	
	return $structure;
}
add_filter('pc_registration_form', 'foo', 10, 2);
?>
pc_settings_validations

Add validation indexes to settings page. Must comply with Simple Form Validator format.
For every succcessfully validated index will be created a Wordpress option

Parameters
  1. (array) associative array containing validation indexes
Usage
<?php
// add 'pc_test' field into validated fields
function foo($indexes) {
	$indexes[] = array('index'=>'pc_test', 'label'=>'Test', 'type'=>'int');
	return $indexes;
}
add_filter('pc_settings_validations', 'foo');

// if successfully validated - you can get that through get_option('pc_test');
?>
pc_update_user_data_check

Performs custom data validation before user is updated

Parameters
  1. (string) errors already found, HTML readyto be printed
  2. (array) associative array of fetched value (field_name => field_value)
Usage
<?php
// return an error if e-mail field doesn't contain @lcweb.it
function foo($errors, $fdata) {
	if(isset($fdata['email']) && strpos($fdata['email'], [email protected]') === false) {
		$errors .= '
E-mail must be of @lcweb.it domain!'; } return $errors; } add_filter('pc_update_user_data_check', 'foo', 10, 2); ?>
pc_update_user_required_fields

Customize required fields for user update

Parameters
  1. (array) required fields array. Fields must be registered in form framework
lcwebPrivateContent – API documentation