本文整理汇总了PHP中acf_validate_value函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_validate_value函数的具体用法?PHP acf_validate_value怎么用?PHP acf_validate_value使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_validate_value函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_value
function validate_value($valid, $value, $field, $input)
{
// remove acfcloneindex
if (isset($value['acfcloneindex'])) {
unset($value['acfcloneindex']);
}
// valid
if ($field['required'] && empty($value)) {
$valid = false;
}
// populate $layouts
$layouts = array();
foreach (array_keys($field['layouts']) as $i) {
$layout = acf_extract_var($field['layouts'], $i);
// append to $layouts
$layouts[$layout['name']] = $layout['sub_fields'];
}
// check sub fields
if (!empty($value)) {
// loop through rows
foreach ($value as $i => $row) {
// get layout
$l = $row['acf_fc_layout'];
// loop through sub fields
if (!empty($layouts[$l])) {
foreach ($layouts[$l] as $sub_field) {
// get sub field key
$k = $sub_field['key'];
// exists?
if (!isset($value[$i][$k])) {
continue;
}
// validate
acf_validate_value($value[$i][$k], $sub_field, "{$input}[{$i}][{$k}]");
}
// foreach
}
// if
}
// foreach
}
// if
// return
return $valid;
}
示例2: acf_validate_save_post
function acf_validate_save_post($show_errors = false)
{
// validate required fields
if (!empty($_POST['acf'])) {
$keys = array_keys($_POST['acf']);
// loop through and save $_POST data
foreach ($keys as $key) {
// get field
$field = acf_get_field($key);
// validate
acf_validate_value($_POST['acf'][$key], $field, "acf[{$key}]");
}
// foreach($fields as $key => $value)
}
// if($fields)
// hook for 3rd party customization
do_action('acf/validate_save_post');
// check errors
if ($errors = acf_get_validation_errors()) {
if ($show_errors) {
$message = '<h2>Validation failed</h2><ul>';
foreach ($errors as $error) {
$message .= '<li>' . $error['message'] . '</li>';
}
$message .= '</ul>';
wp_die($message, 'Validation failed');
}
return false;
}
// return
return true;
}
示例3: validate_value
function validate_value($valid, $value, $field, $input)
{
// bail early if no $value
if (empty($value)) {
return $valid;
}
// bail early if no sub fields
if (empty($field['sub_fields'])) {
return $valid;
}
// loop
foreach (array_keys($field['sub_fields']) as $i) {
// get sub field
$sub_field = $field['sub_fields'][$i];
$k = $sub_field['key'];
// bail early if valu enot set (conditional logic?)
if (!isset($value[$k])) {
continue;
}
// validate
acf_validate_value($value[$k], $sub_field, "{$input}[{$k}]");
}
// return
return $valid;
}
示例4: validate_value
function validate_value($valid, $value, $field, $input)
{
// remove acfcloneindex
if (isset($value['acfcloneindex'])) {
unset($value['acfcloneindex']);
}
// valid
if ($field['required'] && empty($value)) {
$valid = false;
}
// check sub fields
if (!empty($field['sub_fields']) && !empty($value)) {
$keys = array_keys($value);
foreach ($keys as $i) {
foreach ($field['sub_fields'] as $sub_field) {
// vars
$k = $sub_field['key'];
// test sub field exists
if (!isset($value[$i][$k])) {
continue;
}
// validate
acf_validate_value($value[$i][$k], $sub_field, "{$input}[{$i}][{$k}]");
}
}
}
return $valid;
}
示例5: _validate_save_post
function _validate_save_post()
{
// save post_title
if (isset($_POST['acf']['_post_title'])) {
// get field
$field = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'required' => true));
// validate
acf_validate_value($_POST['acf']['_post_title'], $field, "acf[_post_title]");
}
}
示例6: acf_validate_save_post
function acf_validate_save_post()
{
// bail early if no $_POST
if (empty($_POST['acf'])) {
return;
}
// loop
foreach ($_POST['acf'] as $field_key => $value) {
// get field
$field = acf_get_field($field_key);
$input = 'acf[' . $field_key . ']';
// bail early if not found
if (!$field) {
continue;
}
// validate
acf_validate_value($value, $field, $input);
}
}
示例7: validate_save_post
function validate_save_post($show_errors = false)
{
// validate fields
if (!empty($_POST['acf'])) {
// loop
foreach ($_POST['acf'] as $field_key => $value) {
// get field
$field = acf_get_field($field_key);
$input = 'acf[' . $field_key . ']';
// bail early if not found
if (!$field) {
continue;
}
// validate
acf_validate_value($value, $field, $input);
}
}
// action for 3rd party customization
do_action('acf/validate_save_post');
// vars
$errors = acf_get_validation_errors();
// bail ealry if no errors
if (!$errors) {
return true;
}
// show errors
if ($show_errors) {
$message = '<h2>Validation failed</h2>';
$message .= '<ul>';
foreach ($errors as $error) {
$message .= '<li>' . $error['message'] . '</li>';
}
$message .= '</ul>';
// die
wp_die($message, 'Validation failed');
}
// return
return false;
}
示例8: _validate_save_post
function _validate_save_post()
{
// save post_title
if (isset($_POST['acf']['_post_title'])) {
// get field
$field = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'required' => true));
// validate
acf_validate_value($_POST['acf']['_post_title'], $field, "acf[_post_title]");
}
// honeypot
if (!empty($_POST['acf']['_validate_email'])) {
acf_add_validation_error('', __('Spam Detected', 'acf'));
}
}
示例9: validate_value
function validate_value($valid, $value, $field, $input)
{
// remove acfcloneindex
if (isset($value['acfcloneindex'])) {
unset($value['acfcloneindex']);
}
// check if no value
if ($field['required'] && empty($value)) {
return false;
}
// vars
$count = 0;
$layouts = array();
// populate $layouts
foreach (array_keys($field['layouts']) as $i) {
// vars
$layout = $field['layouts'][$i];
// add count
$layout['count'] = 0;
// append
$layouts[$layout['name']] = $layout;
}
// check sub fields
if (!empty($value)) {
// set count
$count = count($value);
// loop through rows
foreach ($value as $i => $row) {
// get layout
$l = $row['acf_fc_layout'];
// bail if layout doesn't exist
if (!isset($layouts[$l])) {
continue;
}
// increase count
$layouts[$l]['count']++;
// bail if no sub fields
if (empty($layouts[$l]['sub_fields'])) {
continue;
}
// loop
foreach ($layouts[$l]['sub_fields'] as $sub_field) {
// get sub field key
$k = $sub_field['key'];
// bail if no value
if (!isset($value[$i][$k])) {
continue;
}
// validate
acf_validate_value($value[$i][$k], $sub_field, "{$input}[{$i}][{$k}]");
}
}
}
// validate min / max
$min = (int) $field['min'];
if ($min && $min > $count) {
// vars
$error = $this->l10n['min'];
$identifier = $min == 1 ? $this->l10n['layout'] : $this->l10n['layouts'];
// replace
$error = str_replace('{min}', $min, $error);
$error = str_replace('{identifier}', $identifier, $error);
// return
return $error;
}
foreach ($layouts as $layout) {
// validate min / max
$min = (int) $layout['min'];
$count = $layout['count'];
if ($min && $min > $count) {
// vars
$error = $this->l10n['min_layout'];
$identifier = $min == 1 ? $this->l10n['layout'] : $this->l10n['layouts'];
// replace
$error = str_replace('{min}', $min, $error);
$error = str_replace('{label}', '"' . $layout['label'] . '"', $error);
$error = str_replace('{identifier}', $identifier, $error);
// return
return $error;
}
}
// return
return $valid;
}