When writing field code, whether with Piklist or not, you should be extra cautious of how you handle data coming into WordPress and how it’s presented to the end user. Piklist makes validating your data easy with the validate
parameter.
You can also create your own custom validation rules using the piklist_validation_rules filter.
Choose the appropriate type of validation for each of your fields.
Verifies that the input is in the proper format for an email address.
Uses the standard WordPress function is_email
'validate' => array(
array(
'type' => 'email'
)
)
Verifies that the input is a valid email domain.
Uses the standard PHP function checkdnsrr
'validate' => array(
array(
'type' => 'email_domain'
)
)
Checks that the entered email is not already registered to another user.
Uses the standard WordPress function email_exists
'validate' => array(
array(
'type' => 'email_exists'
)
)
Verifies that the file path entered leads to an actual file.
'validate' => array(
array(
'type' => 'file_exists'
)
)
Verifies that the data entered is a valid hex color.
'validate' => array(
array(
'type' => 'hex_color'
)
)
Verifies that the file path entered leads to an image file.
Uses the standard PHP function exif_imagetype
'validate' => array(
array(
'type' => 'image'
)
)
Verifies that the data entered is a valid IP Address.
'validate' => array(
array(
'type' => 'ip_address'
)
)
Verifies that the number of items are within the defined limit.
The minimum allowed value. default: 1
The maximum allowed value default: infinite
Determines what you want to count: words, characters, files, images, add-more’s
values: words, characters
default: false (files, images, add-more’s)
,'validate' => array(
array(
'type' => 'limit'
,'options' => array(
'min' => 2
,'max' => 2
)
)
)
,'validate' => array(
array(
'type' => 'limit'
,'options' => array(
'min' => 2
,'max' => 6
,'count' => 'characters'
)
)
)
Checks to see if two fields match.
The field name to match
piklist('field', array(
'type' => 'password'
,'scope' => 'user'
,'field' => 'user_pass_repeat'
,'label' => 'Repeat New Password'
,'value' => false // Setting to false forces no value to show in form.
,'validate' => array(
array(
'type' => 'match'
,'options' => array(
'field' => 'user_pass' // does this match the field user_pass_repeat
)
)
)
));
Verifies that the data entered is within the defined range.
The minimum allowed value. default: 1
The maximum allowed value default: 10
,'validate' => array(
array(
'type' => 'range'
,'options' => array(
'min' => 2
,'max' => 8
)
)
)
Verifies that the data entered is alphanumeric.
,'validate' => array(
array(
'type' => 'safe_text'
)
)
Verifies that the data entered is a valid URL.
,'validate' => array(
array(
'type' => 'url'
)
)
Checks that the entered username does not already exist.
Uses the standard WordPress function username_exists
,'validate' => array(
array(
'type' => 'username_exists'
)
)
This documentation is a community effort. Please create an issue or pull request to help!