Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  Campi  >  Before Register

apply_filters_ref_array( 'vikappointments_before_register_custom_fields', bool $status, array &$rows, array $options )

Fires before registering the available custom fields.


Description

Trigger hook to allow external plugins to manipulate the list of supported custom fields at runtime.

Here it is possible to detach certain fields, append new fields and rearrange their ordering.

When registering a new custom field, it is possible to specify all the following attributes:

id

(int|string)  A unique identifier for the custom field (required).

name

(string)  The label of the custom field, as short as possible (required).

formname

(string)  The form name of the custom field (required only for the custom fields of the employees).

description

(string)  A long description to be displayed inside a tooltip (optional).

type

(string)  The type of the custom field (required). The system supports by default the following types: text, textarea, checkbox, select, date, number, file and separator.

choose

(string)  A configuration JSON/string depending on the specified custom field type (optional).

multiple

(bool)  True in case the field supports the selection of multiple values (optional). Available only for file and select types.

required

(bool)  True in case the field requires a selection (optional).

rule

(string)  An optional rule to dispatch when loading the entered value for this custom field (optional). The system supports by default the following rules: nominative, email, phone, state, city, address, zip, company and vatnum.

poplink

(string)  A URL/query string to reach (optional). Available only for checkbox type.

repeat

(bool)  True to repeat the field for each participant, false to display it only once (optional).


Parameters

$status

(bool)  True on success, false otherwise.

$rows

(array)  An array containing all the supported custom fields (arrays).

$options

(array)  An associative array containing the query filters.

  • group - the group to which the custom fields should belong (0 for customers, 1 for employees);
  • employee - when specified, only the custom fields belonging to the specified employee will be loaded;
  • services - when specified, only the custom fields belonging to the specified services will be loaded;
  • filter - bitwise mask used to filter the custom fields (0 for no filtering, 1 to exclude the required checkboxes, 2 to exclude separators and 4 for exclude the file inputs).

Example

The example below explains how to register a new "Privacy Policy" checkbox without having to create it as a custom field.

/**
 * Trigger hook to allow external plugins to manipulate the list of
 * supported custom fields through this helper class.
 *
 * @param  boolean  $status   True on success, false otherwise.
 * @param  array    &$rows    An array of custom fields.
 * @param  array    $options  An array of query options.
 */
add_filter('vikappointments_before_register_custom_fields', function($status, &$rows, $options)
{
    // make sure we are loading the custom fields for the customers
    if ($options['group'] != VAPCustomFieldsLoader::CUSTOMERS)
    {
        // wrong group, do not go ahead
        return $status;
    }

    // make sure the required checkboxes shouldn't be included
    if ($options['filter'] & VAPCustomFields::EXCLUDE_REQUIRED_CHECKBOX)
    {
        // required checkboxes should be skipped, do not go ahead
        return $status;
    }

    // register a new checkbox
    $rows[] = [
        'id'          => 'privacypolicy',
        'name'        => 'I hereby authorize the use of my personal data',
        'description' => '<p>A tooltip description goes here</p>',
        'type'        => 'checkbox',
        'multiple'    => false,
        'required'    => true,
        'rule'        => '',
        'poplink'     => 'https://domain.com/privacy-policy',
        'repeat'      => false,
    ];

    return $status;
}, 10, 3);

Changelog

Version Description
1.2 Introduced.
Ultimo aggiornamento: 2021-08-19
Utile?
Potrebbe interessarti:
This site uses cookies. By continuing to browse you accept their use. Further information