当前位置: 首页>>代码示例>>PHP>>正文


PHP acf_validate_value函数代码示例

本文整理汇总了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;
 }
开发者ID:Aqro,项目名称:NewDWM,代码行数:45,代码来源:flexible-content.php

示例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;
}
开发者ID:TMBR,项目名称:johnjohn,代码行数:32,代码来源:input.php

示例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;
 }
开发者ID:developmentDM2,项目名称:Whohaha,代码行数:25,代码来源:clone.php

示例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;
 }
开发者ID:quangnpd,项目名称:jobshop_web,代码行数:28,代码来源:repeater.php

示例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]");
    }
}
开发者ID:de190909,项目名称:WPTest,代码行数:10,代码来源:api-template.php

示例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);
     }
 }
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:19,代码来源:validation.php

示例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;
 }
开发者ID:silasakk,项目名称:pht,代码行数:39,代码来源:validation.php

示例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'));
    }
}
开发者ID:gecugamo,项目名称:customledgers,代码行数:14,代码来源:api-template.php

示例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;
 }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:84,代码来源:flexible-content.php


注:本文中的acf_validate_value函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。