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


PHP wptoolset_form_validate_field函数代码示例

本文整理汇总了PHP中wptoolset_form_validate_field函数的典型用法代码示例。如果您正苦于以下问题:PHP wptoolset_form_validate_field函数的具体用法?PHP wptoolset_form_validate_field怎么用?PHP wptoolset_form_validate_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wptoolset_form_validate_field函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save_child


//.........这里部分代码省略.........
      *
      *
      *
      *
      *
      * UPDATE POST
      */
     $cf = new WPCF_Field();
     if (isset($_POST['wpcf_post_relationship'][$parent_id]) && isset($_POST['wpcf_post_relationship'][$parent_id][$child_id])) {
         $_POST['wpcf'] = array();
         foreach ($_POST['wpcf_post_relationship'][$parent_id][$child_id] as $slug => $value) {
             $_POST['wpcf'][$cf->__get_slug_no_prefix($slug)] = $value;
             $_POST['wpcf'][$slug] = $value;
         }
     }
     unset($cf);
     /**
     * avoid filters for children
     * /
             global $wp_filter;
             $save_post = $wp_filter['save_post'];
             $wp_filter['save_post'] = array();
     */
     $updated_id = wp_update_post($post_data);
     /*
        $wp_filter['save_post'] = $save_post;
     */
     unset($save_post);
     if (empty($updated_id)) {
         return new WP_Error('relationship-update-post-failed', 'Updating post failed');
     }
     // Save parents
     if (!empty($save_fields['parents'])) {
         foreach ($save_fields['parents'] as $parent_post_type => $parent_post_id) {
             update_post_meta($child->ID, '_wpcf_belongs_' . $parent_post_type . '_id', $parent_post_id);
         }
     }
     // Update taxonomies
     if (!empty($save_fields['taxonomies']) && is_array($save_fields['taxonomies'])) {
         $_save_data = array();
         foreach ($save_fields['taxonomies'] as $taxonomy => $t) {
             if (!is_taxonomy_hierarchical($taxonomy)) {
                 $_save_data[$taxonomy] = strval($t);
                 continue;
             }
             foreach ($t as $term_id) {
                 if ($term_id != '-1') {
                     $term = get_term($term_id, $taxonomy);
                     if (empty($term)) {
                         continue;
                     }
                     $_save_data[$taxonomy][] = $term_id;
                 }
             }
         }
         wp_delete_object_term_relationships($child->ID, array_keys($save_fields['taxonomies']));
         foreach ($_save_data as $_taxonomy => $_terms) {
             wp_set_post_terms($child->ID, $_terms, $_taxonomy, $append = false);
         }
     }
     // Unset non-types
     unset($save_fields['_wp_title'], $save_fields['_wp_body'], $save_fields['parents'], $save_fields['taxonomies']);
     /*
      *
      *
      *
      *
      *
      *
      * UPDATE Loop over fields
      */
     foreach ($save_fields as $slug => $value) {
         if (defined('WPTOOLSET_FORMS_VERSION')) {
             // Get field by slug
             $field = wpcf_fields_get_field_by_slug(str_replace(WPCF_META_PREFIX, '', $slug));
             if (empty($field)) {
                 continue;
             }
             // Set config
             $config = wptoolset_form_filter_types_field($field, $child->ID);
             // Check if valid
             $valid = wptoolset_form_validate_field('post', $config, $value);
             if (is_wp_error($valid)) {
                 $errors = $valid->get_error_data();
                 $msg = sprintf(__('Child post "%s" field "%s" not updated:', 'wpcf'), $child->post_title, $field['name']);
                 wpcf_admin_message_store($msg . ' ' . implode(', ', $errors), 'error');
                 continue;
             }
         }
         $this->cf->set($child, $field);
         $this->cf->context = 'post_relationship';
         $this->cf->save($value);
     }
     do_action('wpcf_relationship_save_child', $child, $parent);
     clean_post_cache($parent->ID);
     clean_post_cache($child->ID);
     // Added because of caching meta 1.5.4
     wp_cache_flush();
     return true;
 }
开发者ID:Kilbourne,项目名称:restart,代码行数:101,代码来源:relationship.php

示例2: wpcf_admin_post_save_post_hook

/**
 * Important save_post hook.
 *
 * Core function. Works and stable. Do not move or change.
 * If required, add hooks only.
 *
 * @internal breakpoint
 * @param type $post_ID
 * @param type $post
 */
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
    if (defined('WPTOOLSET_FORMS_VERSION')) {
        global $wpcf;
        $errors = false;
        // Do not save post if is type of
        if (in_array($post->post_type, array('revision', 'view', 'view-template', 'cred-form', 'nav_menu_item', 'mediapage'))) {
            return false;
        }
        $_post_wpcf = array();
        if (!empty($_POST['wpcf'])) {
            $_post_wpcf = $_POST['wpcf'];
        }
        /**
         * handle checkbox
         */
        if (array_key_exists('_wptoolset_checkbox', $_POST) && is_array($_POST['_wptoolset_checkbox'])) {
            foreach ($_POST['_wptoolset_checkbox'] as $key => $field_value) {
                $field_slug = preg_replace('/^wpcf\\-/', '', $key);
                if (array_key_exists($field_slug, $_post_wpcf)) {
                    continue;
                }
                $_post_wpcf[$field_slug] = false;
            }
        }
        if (count($_post_wpcf)) {
            /**
             * check some attachment to delete
             */
            $delete_attachments = apply_filters('wpcf_delete_attachments', true);
            $images_to_delete = array();
            if ($delete_attachments && isset($_POST['wpcf']) && array_key_exists('delete-image', $_POST['wpcf']) && is_array($_POST['wpcf']['delete-image'])) {
                foreach ($_POST['wpcf']['delete-image'] as $image) {
                    $images_to_delete[$image] = 1;
                }
            }
            foreach ($_post_wpcf as $field_slug => $field_value) {
                // Get field by slug
                $field = wpcf_fields_get_field_by_slug($field_slug);
                if (empty($field)) {
                    continue;
                }
                // Skip copied fields
                if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                    continue;
                }
                $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
                // Set config
                $config = wptoolset_form_filter_types_field($field, $post_ID, $_post_wpcf);
                /**
                 * remove from images_to_delete if user add again
                 */
                if ($delete_attachments && 'image' == $config['type']) {
                    $images = $_field_value;
                    if (!is_array($images)) {
                        $images = array($images);
                    }
                    foreach ($images as $image) {
                        if (array_key_exists($image, $images_to_delete)) {
                            unset($images_to_delete[$image]);
                        }
                    }
                }
                foreach ($_field_value as $_k => $_val) {
                    // Check if valid
                    $validation = wptoolset_form_validate_field('post', $config, $_val);
                    $conditional = wptoolset_form_conditional_check($config);
                    $not_valid = is_wp_error($validation) || !$conditional;
                    if (is_wp_error($validation)) {
                        $errors = true;
                        $_errors = $validation->get_error_data();
                        $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
                        wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
                    }
                    if ($not_valid) {
                        if (types_is_repetitive($field)) {
                            unset($field_value[$_k]);
                        } else {
                            break;
                        }
                    }
                }
                // Save field
                if (types_is_repetitive($field)) {
                    $wpcf->repeater->set($post_ID, $field);
                    $wpcf->repeater->save($field_value);
                } else {
                    if (!$not_valid) {
                        $wpcf->field->set($post_ID, $field);
                        $wpcf->field->save($field_value);
//.........这里部分代码省略.........
开发者ID:SpencerNeitzke,项目名称:types,代码行数:101,代码来源:fields-post.php

示例3: wpcf_admin_userprofilesave_init

function wpcf_admin_userprofilesave_init($user_id)
{
    if (defined('WPTOOLSET_FORMS_VERSION')) {
        global $wpcf;
        $errors = false;
        /**
         * check checkbox type fields to delete or save empty if needed
         */
        $groups = wpcf_admin_usermeta_get_groups_fields();
        foreach ($groups as $group) {
            if (!array_key_exists('fields', $group) || empty($group['fields'])) {
                continue;
            }
            foreach ($group['fields'] as $field) {
                switch ($field['type']) {
                    case 'checkboxes':
                        if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) {
                            delete_user_meta($user_id, $field['meta_key']);
                        }
                        break;
                    case 'checkbox':
                        if (!array_key_exists('wpcf', $_POST) || !array_key_exists($field['slug'], $_POST['wpcf'])) {
                            if ('yes' == $field['data']['save_empty']) {
                                $_POST['wpcf'][$field['slug']] = 0;
                            } else {
                                delete_user_meta($user_id, $field['meta_key']);
                            }
                        }
                        break;
                }
            }
        }
        // Save meta fields
        if (!empty($_POST['wpcf'])) {
            foreach ($_POST['wpcf'] as $field_slug => $field_value) {
                // Get field by slug
                $field = wpcf_fields_get_field_by_slug($field_slug, 'wpcf-usermeta');
                if (empty($field)) {
                    continue;
                }
                // Skip copied fields
                if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                    continue;
                }
                $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
                // Set config
                $config = wptoolset_form_filter_types_field($field, $user_id);
                foreach ($_field_value as $_k => $_val) {
                    // Check if valid
                    $valid = wptoolset_form_validate_field('your-profile', $config, $_val);
                    if (is_wp_error($valid)) {
                        $errors = true;
                        $_errors = $valid->get_error_data();
                        $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
                        wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
                        if (types_is_repetitive($field)) {
                            unset($field_value[$_k]);
                        } else {
                            break;
                        }
                    }
                }
                // Save field
                if (types_is_repetitive($field)) {
                    $wpcf->usermeta_repeater->set($user_id, $field);
                    $wpcf->usermeta_repeater->save($field_value);
                } else {
                    $wpcf->usermeta_field->set($user_id, $field);
                    $wpcf->usermeta_field->usermeta_save($field_value);
                }
                do_action('wpcf_user_field_saved', $user_id, $field);
                // TODO Move to checkboxes
                if ($field['type'] == 'checkboxes') {
                    $field_data = wpcf_admin_fields_get_field($field['id'], false, false, false, 'wpcf-usermeta');
                    if (!empty($field_data['data']['options'])) {
                        $update_data = array();
                        foreach ($field_data['data']['options'] as $option_id => $option_data) {
                            if (!isset($_POST['wpcf'][$field['id']][$option_id])) {
                                if (isset($field_data['data']['save_empty']) && $field_data['data']['save_empty'] == 'yes') {
                                    $update_data[$option_id] = 0;
                                }
                            } else {
                                $update_data[$option_id] = $_POST['wpcf'][$field['id']][$option_id];
                            }
                        }
                        update_user_meta($user_id, $field['meta_key'], $update_data);
                    }
                }
            }
        }
        if ($errors) {
            update_post_meta($user_id, '__wpcf-invalid-fields', true);
        }
        do_action('wpcf_user_saved', $user_id);
        return;
    }
    global $wpcf;
    $all_fields = array();
    $_not_valid = array();
    $_error = false;
//.........这里部分代码省略.........
开发者ID:sonvq,项目名称:passioninvestment,代码行数:101,代码来源:usermeta-post.php

示例4: validate_single_field_value

 /**
  * @param $field_config
  * @param $value
  *
  * @return true|WP_Error
  */
 private function validate_single_field_value($field_config, $value)
 {
     return wptoolset_form_validate_field($this->form_id, $field_config, $value);
 }
开发者ID:phuocdungit,项目名称:fundy,代码行数:10,代码来源:data_saver.php

示例5: wpcf_admin_post_save_post_hook

/**
 * The save_post hook.
 *
 * @param int $post_ID
 * @param WP_Post $post
 * @since unknown
 */
function wpcf_admin_post_save_post_hook($post_ID, $post)
{
    // Apparently, some things are *slightly* different when saving a child post in the Post relationships metabox.
    // Ugly hack that will go away with m2m.
    //
    // Note: The types_updating_child_post filter is needed for a situation when user clicks on the Update button
    // for the parent post. In that case we don't get enough information to determine if a child post is being updated.
    $is_child_post_update = 'wpcf_ajax' == wpcf_getget('action') && 'pr_save_child_post' == wpcf_getget('wpcf_action') || apply_filters('types_updating_child_post', false);
    global $wpcf;
    $errors = false;
    // Do not save post if is type of
    if (in_array($post->post_type, array('revision', 'view', 'view-template', 'cred-form', 'cred-user-form', 'nav_menu_item', 'mediapage'))) {
        return;
    }
    $_post_wpcf = array();
    if (!empty($_POST['wpcf'])) {
        $_post_wpcf = $_POST['wpcf'];
    }
    // handle checkbox
    if (array_key_exists('_wptoolset_checkbox', $_POST) && is_array($_POST['_wptoolset_checkbox'])) {
        foreach ($_POST['_wptoolset_checkbox'] as $key => $field_value) {
            $field_slug = preg_replace('/^wpcf\\-/', '', $key);
            if (array_key_exists($field_slug, $_post_wpcf)) {
                continue;
            }
            $_post_wpcf[$field_slug] = false;
        }
    }
    // handle radios
    if (array_key_exists('_wptoolset_radios', $_POST) && is_array($_POST['_wptoolset_radios'])) {
        foreach ($_POST['_wptoolset_radios'] as $key => $field_value) {
            $field_slug = preg_replace('/^wpcf\\-/', '', $key);
            if (array_key_exists($field_slug, $_post_wpcf)) {
                continue;
            }
            $_post_wpcf[$field_slug] = false;
        }
    }
    if (count($_post_wpcf)) {
        $add_error_message = true;
        if (isset($_POST['post_id']) && $_POST['post_id'] != $post_ID) {
            $add_error_message = false;
        }
        // check some attachment to delete
        $delete_attachments = apply_filters('wpcf_delete_attachments', true);
        $images_to_delete = array();
        if ($delete_attachments && isset($_POST['wpcf']) && array_key_exists('delete-image', $_POST['wpcf']) && is_array($_POST['wpcf']['delete-image'])) {
            foreach ($_POST['wpcf']['delete-image'] as $image) {
                $images_to_delete[$image] = 1;
            }
        }
        foreach ($_post_wpcf as $field_slug => $field_value) {
            // Get field by slug
            $field = wpcf_fields_get_field_by_slug($field_slug);
            if (empty($field)) {
                continue;
            }
            // Skip copied fields
            if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                continue;
            }
            // This is (apparently) expected for repetitive fields...
            if ($is_child_post_update && types_is_repetitive($field)) {
                $field_value = array($field_value);
            }
            $_field_value = !types_is_repetitive($field) ? array($field_value) : $field_value;
            // Set config
            $config = wptoolset_form_filter_types_field($field, $post_ID, $_post_wpcf);
            // remove from images_to_delete if user add again
            if ($delete_attachments && 'image' == $config['type']) {
                $images = $_field_value;
                if (!is_array($images)) {
                    $images = array($images);
                }
                foreach ($images as $image) {
                    if (array_key_exists($image, $images_to_delete)) {
                        unset($images_to_delete[$image]);
                    }
                }
            }
            // add filter to remove field name from error message
            // This filter is toolset-common/toolset-forms/classes/class.validation.php
            add_filter('toolset_common_validation_add_field_name_to_error', '__return_false', 1234, 1);
            foreach ($_field_value as $_k => $_val) {
                // Check if valid
                $validation = wptoolset_form_validate_field('post', $config, $_val);
                $conditional = wptoolset_form_conditional_check($config);
                $not_valid = is_wp_error($validation) || !$conditional;
                if ($add_error_message && is_wp_error($validation)) {
                    $errors = true;
                    $_errors = $validation->get_error_data();
                    $_msg = sprintf(__('Field "%s" not updated:', 'wpcf'), $field['name']);
                    wpcf_admin_message_store($_msg . ' ' . implode(', ', $_errors), 'error');
//.........这里部分代码省略.........
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:101,代码来源:fields-post.php

示例6: validate

 /**
  * New validation using API calls from toolset-forms.
  *
  * Uses API cals
  * @uses wptoolset_form_validate_field()
  * @uses wptoolset_form_conditional_check()
  *
  * @todo Make it work with other fields (generic)
  *
  * @param type $post_id
  * @param type $values
  * @return boolean
  */
 function validate($post_id, $values)
 {
     $form_id = $this->form_id;
     $valid = true;
     // Loop over fields
     $form_source_data = $this->_formData->getForm()->post_content;
     preg_match_all("/\\[cred_show_group.*cred_show_group\\]/Uism", $form_source_data, $res);
     $conditional_group_fields = array();
     if (count($res[0]) > 0) {
         for ($i = 0, $res_limit = count($res[0]); $i < $res_limit; $i++) {
             preg_match_all("/field=\"([^\"]+)\"/Uism", $res[0][$i], $parsed_fields);
             if (count($parsed_fields[1]) > 0) {
                 for ($j = 0, $count_parsed_fields = count($parsed_fields); $j < $count_parsed_fields; $j++) {
                     if (!empty($parsed_fields[1][$j])) {
                         $conditional_group_fields[] = trim($parsed_fields[1][$j]);
                     }
                 }
             }
         }
     }
     foreach ($this->form_properties['fields'] as $field) {
         if (in_array(str_replace('wpcf-', '', $field['name']), $conditional_group_fields)) {
             continue;
         }
         // If Types field
         if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') {
             $field_name = $field['name'];
             if (!isset($_POST[$field_name])) {
                 continue;
             }
             /* 	
                               // Adjust field ID
                               $field['id'] = strpos( $field['name'], 'wpcf-' ) === 0 ? substr( $field['name'], 5 ) : $field['name'];
                               // CRED have synonym 'text' for textfield
                               if ( $field['type'] == 'text' ) {
                               $field['type'] = 'textfield';
                               } */
             $field = wpcf_fields_get_field_by_slug(str_replace('wpcf-', '', $field['name']));
             if (empty($field)) {
                 continue;
             }
             // Skip copied fields
             if (isset($_POST['wpcf_repetitive_copy'][$field['slug']])) {
                 continue;
             }
             // Set field config
             $config = wptoolset_form_filter_types_field($field, $post_id);
             //Add custom colorpicer hexadecimal backend validator
             //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/193712665/comments
             //Todo in future add hexadecimal check in types
             if ($field['type'] == 'colorpicker') {
                 $config['validation']['hexadecimal'] = array('args' => array('$value', '1'), 'message' => 'Enter valid hexadecimal value');
             }
             if (isset($config['conditional']['values'])) {
                 foreach ($config['conditional']['values'] as $post_key => $post_value) {
                     if (isset($this->form_properties['fields'][$post_key])) {
                         $config['conditional']['values'][$post_key] = $this->form_properties['fields'][$post_key]['value'];
                     }
                 }
             }
             // Set values to loop over
             $_values = !empty($values[$field_name]) ? $values[$field_name]['value'] : null;
             if (empty($config['repetitive'])) {
                 $_values = array($_values);
             }
             // Loop over each value
             if (is_array($_values)) {
                 foreach ($_values as $value) {
                     $validation = wptoolset_form_validate_field($form_id, $config, $value);
                     $conditional = wptoolset_form_conditional_check($config);
                     /**
                      * add form_errors messages
                      */
                     if (is_wp_error($validation) && $conditional) {
                         $error_data = $validation->get_error_data();
                         if (isset($error_data[0])) {
                             $this->add_top_message($error_data[0], $config['id']);
                         } else {
                             $this->add_top_message($validation->get_error_message(), $config['id']);
                         }
                         $valid = false;
                         if (empty($ret_validation)) {
                             continue;
                         }
                         //                            foreach( $errors as $error ) {
                         //                                $error = explode( ' ', $error );
                         //                                $key = array_shift($error);
//.........这里部分代码省略.........
开发者ID:rebeccayshen,项目名称:kitlist,代码行数:101,代码来源:CredForm.php


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