PrivateContent Plugin
Hooks - Filters
pc_complete_lock_exceptions
Add pages to be excluded from "complete site lock". Use only pages ID.
Parameters
- (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
- (string) the field code
- (string) field type
- (string) field identifier
- (array) field structure
- (bool) whether the field is required or not/li>
- (int) logged user ID (to pre-populate field)
- (array) extra HTML field classes
- (array) extra HTML field attributes array(attr_name => attr_val)
- (object) the form framework class instance
Usage
<?php // inject custom field inside the form function foo($code, $f_type, $field_id, $structure, $is_required, $user_id, $extra_classes, $extra_atts, $class) { if($f_type != 'my custom field') { return $code; } $code = ''; return $code; } add_filter('pc_custom_field_type', 'foo', 10, 9); ?> // custom field code
pc_custom_redirect_url
Allow custom redirect url return when pc_man_redirects() API function is called.
Parameters
- (string) the redirect URL
- (string) the redirect key
- (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
- (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
- (string) message that would be returned normally
- (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
- (string) data as returned by database query (serialized data is unmanaged)
- (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
- (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
- (int) this filter must return a proper value: 1 == ok or 2 == blocked
- (array) User categories
- (array) $allowed pc_user_check() parameter
- (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
- (array) attributes array having attribute name as index: array(name => myFieldName)
- (string) field id
- (array) form fields structure
- (false|int) user ID eventually passed or false
- (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
- (array) classes array
- (string) field id
- (array) form fields structure
- (false|int) user ID eventually passed or false
- (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
- (mixed) field value to filter
- (string) field id
- (array) form fields structure
- (false|int) user ID eventually passed or false
- (false|array) user data fetched for the form fields filling (if user_id parameter is not false), or false
- (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
key | description | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
(string) (mandatory) label | field label, used alo in forms | ||||||||||||||||||||||
(string) (mandatory) type | field type. Choose among:
| ||||||||||||||||||||||
(string) subtype | text fields subtype. Leave empty to use a normal text input or choose among:
| ||||||||||||||||||||||
(int) maxlen | textual fields characters limitation | ||||||||||||||||||||||
(string) regex | textual fields advanced validation. Will be used with preg_match() function | ||||||||||||||||||||||
(int) range_from | numeric fields limit, defines minimum accepted value. Could be a floating number according to chosen subytpe | ||||||||||||||||||||||
(int) range_to | numeric fields limit, defines maximum accepted value. Could be a floating number according to chosen subytpe | ||||||||||||||||||||||
(array) opt | select 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) placeh | textual fields placeholder | ||||||||||||||||||||||
(string) icon | FontAwesome 5 icon class | ||||||||||||||||||||||
(string) group | Optionally define a group name for the field, for a better usage in backend systems | ||||||||||||||||||||||
(bool) multiple | select fields switch: true to allow multi-option selection | ||||||||||||||||||||||
(array) def_choice | default values selected for select and checkboxes fields | ||||||||||||||||||||||
(string) check_txt | single-option checkbox parameter, defining text shown on check's side | ||||||||||||||||||||||
(bool) disclaimer | single-option checkbox switch: true if field must be shown in disclaimers box | ||||||||||||||||||||||
(string) helper | Optionally define a text to be shown under field name | ||||||||||||||||||||||
(bool) fullw_f | Whether 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' => array( 'opt1' => 'option 1', 'opt2' => 'option 2', 'opt3' => 'option 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
- (array) array of errors already found, HTML ready to be printed
- (array) associative array of fetched value (field_name => field_value)
- (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
- (array) form fields validation indexes. Structure must comply with the validator class
- (array) fetched form field values (index => value)
- (int|false) form term ID (where available)
- (string) form term's taxonomy (where available) (eg. pc_reg_form_ct for registration forms)
- (false|int) user ID eventually passed or false
- (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
- (array) user data
- (bool) whether import shall be aborted if a data error is found
- (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
- (string) the code (ready to be placed in the HTML structure)
- (array) form fields structure
- (false|int) user ID eventually passed or false
- (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
- (string) errors already found, HTML readyto be printed
- (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
- (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
- (bool/text) by default is false and allow login. Return text to abort login
- (int) user ID - useful to perform database checks
pc_meta_val
Additional data management for fetched meta values
Parameters
- (mixed) fetched meta value (array and objects already unserialized)
- (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
- (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
- (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
- (array) associative array having this structure array('include' => included fields array, 'require' => included fields array)
- (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
- (array) form fields data fetched (index => value)
- (int) the user ID
- (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
- (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
- (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
- (string) errors already found, HTML readyto be printed
- (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
- (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
- (array) array of included and required fields array (must comply with the framework structure)
- (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
- (array) query arguments. Please check the class method documentation to know more