Skip to content

Instantly share code, notes, and snippets.

@sbruner
Last active December 9, 2016 04:48
Show Gist options
  • Save sbruner/d5d52d9a2fc1ae26968ea40231fb3228 to your computer and use it in GitHub Desktop.
Save sbruner/d5d52d9a2fc1ae26968ea40231fb3228 to your computer and use it in GitHub Desktop.
<?php
// Create a validation rule called "my_file_exists"
add_filter('piklist_validation_rules', 'check_file_exists', 11);
function check_file_exists($validation_rules)
{
$validation_rules['my_file_exists'] = array(
'callback' => 'my_validate_file_exists'
);
return $validation_rules;
}
/**
* @param int $index The field index being checked.
* @param mixed $value The value of the field.
* @param array $options The options.
* @param array $field The field object.
* @param array $fields Collection of fields.
*/
function my_validate_file_exists($index, $value, $options, $field, $fields)
{
return @file_get_contents($value) ? true : 'contains a file that does not exist.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment