PrivateContent

API Documentation

Hooks - Filters

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_field_type

Allows custom field types injection inside frontend forms.

Parameters
  1. (string) the field code
  2. (string) field type
  3. (string) field identifier
  4. (array) field structure
  5. (bool) whether the field is required or not/li>
  6. (int) logged user ID (to pre-populate field)
Usage
<?php
// inject custom field inside the form
function foo($code, $f_type, $field_id, $structure, $is_required, $user_id) {
	if($f_type != 'my custom field') {
		return $code;	
	}

	$code = '
	
// custom field code
'; return $code; } add_filter('pc_custom_field_type', 'foo', 10, 6); ?>
pc_custom_redirect_url

Allow custom redirect url return when pc_man_redirects() API function is called.

Parameters
  1. (string) the redirect URL
  2. (string) the redirect key
  3. (false|int) user ID eventually passed or false
Usage
<?php
// set a custom URL on logged user redirect if user ID = 5
function foo($url, $key, $user_id) {
	
    if($key == 'pc_logged_user_redirect' && $user_id == 5) {
        $url = 'the-url';    
    }
	return $url;
}
add_filter('pc_custom_redirect_url', 'foo', 10, 3);
?>
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['https://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_extra_user_check

Gives a chance to perform a further check over the pc_user_check() API function.
NB: user is logged then its ID can be retrieved through $GLOBALS['pc_user_id'].

Parameters
  1. (int) this filter must return a proper value: 1 == ok or 2 == blocked
  2. (array) User categories
  3. (array) $allowed pc_user_check() parameter
  4. (array) $blocked pc_user_check() parameter
Usage
<?php
// block user assigned to category #3
function foo($response, $user_cats, $allowed, $blocked) {
	if(in_array(3, $user_cats)) {
		$response = 2;
	}

	return $response;
}
add_filter('pc_extra_user_check', 'foo', 10, 4);
?>
pc_field_atts

Frontend form field attributes filter. To add new attributes or manage existing ones

Parameters
  1. (array) attributes array having attribute name as index: array(name => myFieldName)
  2. (string) field id
  3. (array) form fields structure
  4. (false|int) user ID eventually passed or false
  5. (object) form framework class instance
Usage
<?php
// let's add a new attribute to the username field
function foo($attributes, $field_id, $form_fields, $user_id, $class) {
	
    if($field_id == 'username') {
        $attributes['data-myattr'] = 'myval';
    }
    
	return $attributes;
}
add_filter('pc_field_atts', 'foo', 10, 5);
?>
pc_field_classes

Allows extra HTML classes to be associated on specific frontend form fields

Parameters
  1. (array) classes array
  2. (string) field id
  3. (array) form fields structure
  4. (false|int) user ID eventually passed or false
  5. (object) form framework class instance
Usage
<?php
// let's add a new class to the surname field only if name field is in thee form
function foo($classes, $field_id, $form_fields, $user_id, $class) {
	
    if(in_array('name', $form_fields['include'])) {
        $classes[] = 'myclass';
    }
    
	return $classes;
}
add_filter('pc_field_classes', 'foo', 10, 5);
?>
pc_form_field_val

Allow form field value filter before frontend form output

Parameters
  1. (mixed) field value to filter
  2. (string) field id
  3. (array) form fields structure
  4. (false|int) user ID eventually passed or false
  5. (false|array) user data fetched for the form fields filling (if user_id parameter is not false), or false
  6. (object) form framework class instance
Usage
<?php
// turn the surname into uppercase letters for a data-edit form
function foo($f_val, $field_id, $form_structure, $user_id, $user_data, $class) {
	
    if($user_id && $field_id == 'username') {
        $f_val = strtoupper($f_val);    
    }
    
	return $f_val;
}
add_filter('pc_form_field_val', 'foo', 10, 6);
?>
pc_form_fields_filter

Extend PrivateContent fields adding new ones or tanaging existing fields data.
New fields automatically setup also validations, tuned on the field structure.

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
(array) optselect and multi-checkbox field options.
Must be an associative array having the option value as index and the label as array value: array(index1 => val1, index2 => val2)
(string) placehtextual fields placeholder
(string) iconFontAwesome 5 icon class
(string) groupOptionally define a group name for the field, for a better usage in backend systems
(bool) multipleselect fields switch: true to allow multi-option selection
(array) def_choicedefault values selected for select and checkboxes fields
(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
(string) helperOptionally define a text to be shown under field name
(bool) fullw_fWhether to use the "fullwidth" field layout (eg. useful if you expect long texts)
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',
        'group'     => 'my fields',
	); 
	
	$fields['new_field2'] = array(
		'label' 	=> 'Field 2 Label'
		'type' 		=> 'select',
		'opt'		=> 'opt 1, opt 2, opt 3'
		'note' 		=> 'internal note'
		'multiple'	=> false,
        'group'     => 'my fields',
        'helper'    => 'the helper text'
	);
	
	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. (array) array of errors already found, HTML ready to be printed
  2. (array) associative array of fetched value (field_name => field_value)
  3. (false|int) user ID eventually passed or false
Usage
<?php
// return an error if e-mail field doesn't contain @lcweb.it
function foo($errors, $fdata, $user_id) {
	if(isset($fdata['email']) && strpos($fdata['email'], '@lcweb.it') === false) {
		$errors[] = 'E-mail must be of @lcweb.it domain!';	
	}

	return $errors;
}
add_filter('pc_form_valid_errors', 'foo', 10, 2);
?>
pc_form_validator_indexes

Allows extra control over form validation rules

Parameters
  1. (array) form fields validation indexes. Structure must comply with the validator class
  2. (array) fetched form field values (index => value)
  3. (int|false) form term ID (where available)
  4. (string) form term's taxonomy (where available) (eg. pc_reg_form_ct for registration forms)
  5. (false|int) user ID eventually passed or false
  6. (object) form framework class instance
Usage
<?php
// supposing to have injected through "pc_form_fields_filter" a field code composed by two HTML number fields, validate them
function foo($indexes, $form_vals, $form_id, $taxonomy, $user_id, $class) {
	
    $indexes[] = array('index'=>'my_num1', 'label'=>'Number one', 'required'=>true, 'min_val'=>5, 'max_val'=>50);
    $indexes[] = array('index'=>'my_num2', 'label'=>'Number two', 'required'=>true, 'min_val'=>50, 'max_val'=>800);
    
	return $indexes;
}
add_filter('pc_form_validator_indexes', 'foo', 10, 6);
?>
pc_import_data

Allows import data filter for each user. Return an error message to abort the user import

Parameters
  1. (array) user data
  2. (bool) whether import shall be aborted if a data error is found
  3. (bool) whether import shall be aborted if an existing user is found
Usage
<?php
// abort import if email is not .org
function foo($user_data, $abort_on_error, $abort_on_duplicate) {
	
    if(substr($user_data['email'], -4) != '.org' && $abort_on_error) {
        return 'E-mail must be .org';    
    }
    
	return $user_data;
}
add_filter('pc_import_data', 'foo', 9999, 3);
?>
pc_inline_form_js

Allows extra javascript to be outputted right after forms closing (requires the <script></script> tag)

Parameters
  1. (string) the code (ready to be placed in the HTML structure)
  2. (array) form fields structure
  3. (false|int) user ID eventually passed or false
  4. (object) form framework class instance
Usage
<?php
// add some code if name field is in thee form
function foo($code, $form_fields, $user_id, $class) {
	
    if(in_array('name', $form_fields['include'])) {
        $code .= ;
    }
    
	return $code;
}
add_filter('pc_inline_form_js', 'foo', 10, 4);
?>
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'], '@lcweb.it') === 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_pvt_page_preset_contents

Allows user private pages preset contents customization

Parameters
  1. (string) HTML contents
Usage
<?php
// appending a paragraph
function foo($preset) {
	
    $preset .= '

custom contents

'; return $preset; } add_filter('pc_pvt_page_preset_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_save_meta_fields

Allow extra control over meta fields saved during user insert/update operations

Parameters
  1. (array) form fields data fetched (index => value)
  2. (int) the user ID
  3. (array) field IDs included in the submitted form
Usage
<?php
// assuming to have a "my_meta" meta value, let's uppercase it for user #5
function foo($fields_val, $user_id, $fields) {
	
    if($user_id == 5 && isset($fields_val['my_meta'])) {
        $fields_val['my_meta'] = strtoupper($fields_val['my_meta']);   
    }
    
	return $fields_val;
}
add_filter('pc_save_meta_fields', 'foo', 10, 3);
?>
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_ulist_adv_search_user_atts

Manage user attributes to be included in the advanced search form and to be queried as user meta key (eg. premium plans status)

Parameters
  1. (array) attributes array (check the example to know more about the structure)
Usage
<?php
// add Premium Plan add-on statuses
function foo($atts) {
    $to_add = array();
    
    $statuses = array(
        'active'    => 'Active', 
        'disabled'  => 'Disabled', 
        'pending'   => 'Pending',
    );

    foreach($statuses as $key => $name) {
        $to_add['pcpp_'. $key .'_status'] = array(
            'name'      => 'Premium Plans add-on - '. $name .' status', // dropdown option label
            'db_key'    => 'pcpp_subscr_status', // meta data name as stored in the database
            'db_val'    => $key, // meta data value stored in the database
        );
    }
    
    return array_merge($atts, $to_add);
}
add_filter('pc_ulist_adv_search_user_atts', 'foo');
?>
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'], '@lcweb.it') === 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
pc_user_dashboard_validation

Inject extra fields to be validated and saved in user dashboard page

Parameters
  1. (array) array of included and required fields array (must comply with the framework structure)
  2. (false|int) user ID eventually passed or false
Usage
<?php
// Assuming you have a field named "my_field", the code set it to be saved
function foo($structure, $user_id) {
	
    $structure['include'][] = 'my_field'; 
	return $structure;
}
add_filter('pc_user_dashboard_validation', 'foo', 10, 2);
?>
pc_users_list_query_args

Allows users query parameters tweak in users list page

Parameters
  1. (array) query arguments. Please check the class method documentation to know more