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


PHP wpcf_sanitize_field函数代码示例

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


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

示例1: wpcf_admin_fields_save_field

/**
 * Saves field.
 * 
 * @param type $field
 * @return type 
 */
function wpcf_admin_fields_save_field($field)
{
    if (!isset($field['name']) || !isset($field['type'])) {
        return new WP_Error('wpcf_save_field_no_name_or_type', __("Error saving field", 'wpcf'));
    }
    $field = wpcf_sanitize_field($field);
    if (empty($field['name']) || empty($field['slug'])) {
        return new WP_Error('wpcf_save_field_no_name', __("Please set name for field", 'wpcf'));
    }
    $field['id'] = $field['slug'];
    // Set field specific data
    // NOTE: This was $field['data'] = $field and seemed to work on most systems.
    // I changed it to asign via a temporary variable to fix on one system.
    $temp_field = $field;
    $field['data'] = $temp_field;
    // Unset default fields
    unset($field['data']['type'], $field['data']['slug'], $field['data']['name'], $field['data']['description'], $field['data']['user_id'], $field['data']['id'], $field['data']['data']);
    // Merge previous data (added because of outside fields)
    // @TODO Remember why
    if (wpcf_types_cf_under_control('check_outsider', $field['id'])) {
        $field_previous_data = wpcf_admin_fields_get_field($field['id']);
        if (!empty($field_previous_data['data'])) {
            $field['data'] = array_merge($field_previous_data['data'], $field['data']);
        }
    }
    $field['data'] = apply_filters('wpcf_fields_' . $field['type'] . '_meta_data', $field['data'], $field);
    // Check validation
    if (isset($field['data']['validate'])) {
        foreach ($field['data']['validate'] as $method => $data) {
            if (!isset($data['active'])) {
                unset($field['data']['validate'][$method]);
            }
        }
        if (empty($field['data']['validate'])) {
            unset($field['data']['validate']);
        }
    }
    $save_data = array();
    $save_data['id'] = $field['id'];
    $save_data['slug'] = $field['slug'];
    $save_data['type'] = $field['type'];
    $save_data['name'] = $field['name'];
    $save_data['description'] = $field['description'];
    $save_data['data'] = $field['data'];
    $save_data['data']['disabled_by_type'] = 0;
    // For radios or select
    if (!empty($field['data']['options'])) {
        foreach ($field['data']['options'] as $name => $option) {
            if (isset($option['title'])) {
                $option['title'] = $field['data']['options'][$name]['title'] = htmlspecialchars_decode($option['title']);
            }
            if (isset($option['value'])) {
                $option['value'] = $field['data']['options'][$name]['value'] = htmlspecialchars_decode($option['value']);
            }
            if (isset($option['display_value'])) {
                $option['display_value'] = $field['data']['options'][$name]['display_value'] = htmlspecialchars_decode($option['display_value']);
            }
            // For checkboxes
            if ($field['type'] == 'checkboxes' && isset($option['set_value']) && $option['set_value'] != '1') {
                $option['set_value'] = $field['data']['options'][$name]['set_value'] = htmlspecialchars_decode($option['set_value']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_selected'])) {
                $option['display_value_selected'] = $field['data']['options'][$name]['display_value_selected'] = htmlspecialchars_decode($option['display_value_selected']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_not_selected'])) {
                $option['display_value_not_selected'] = $field['data']['options'][$name]['display_value_not_selected'] = htmlspecialchars_decode($option['display_value_not_selected']);
            }
        }
    }
    // For checkboxes
    if ($field['type'] == 'checkbox' && $field['set_value'] != '1') {
        $field['set_value'] = htmlspecialchars_decode($field['set_value']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
        $field['display_value_selected'] = htmlspecialchars_decode($field['display_value_selected']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
        $field['display_value_not_selected'] = htmlspecialchars_decode($field['display_value_not_selected']);
    }
    // Save field
    $fields = get_option('wpcf-fields', array());
    $fields[$field['slug']] = $save_data;
    update_option('wpcf-fields', $fields);
    $field_id = $field['slug'];
    // WPML register strings
    if (function_exists('icl_register_string')) {
        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' name', $field['name']);
        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' description', $field['description']);
        // For radios or select
        if (!empty($field['data']['options'])) {
            foreach ($field['data']['options'] as $name => $option) {
                if ($name == 'default') {
                    continue;
                }
//.........这里部分代码省略.........
开发者ID:pwillems,项目名称:mimosa-contents,代码行数:101,代码来源:fields.php

示例2: save

 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  * @return type Description.
  */
 public function save()
 {
     if (!isset($_POST['wpcf']) || !isset($_POST['wpcf']['group']) || !isset($_POST['wpcf']['group']['name'])) {
         return false;
     }
     $_POST['wpcf']['group'] = apply_filters('wpcf_group_pre_save', $_POST['wpcf']['group']);
     $group_name = wp_kses_post($_POST['wpcf']['group']['name']);
     require_once WPCF_EMBEDDED_ABSPATH . '/classes/forms.php';
     $form = new Enlimbo_Forms_Wpcf();
     if (empty($group_name)) {
         $form->triggerError();
         wpcf_admin_message(__('Group name can not be empty.', 'wpcf'), 'error');
         return $form;
     }
     $new_group = false;
     $group_slug = sanitize_title($group_name);
     // Basic check
     if (isset($_REQUEST[$this->get_id])) {
         // Check if group exists
         $post = get_post(intval($_REQUEST[$this->get_id]));
         // Name changed
         if (strtolower($group_name) != strtolower($post->post_title)) {
             // Check if already exists
             $exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME);
             if (!empty($exists)) {
                 $form->triggerError();
                 wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error');
                 return $form;
             }
         }
         if (empty($post) || $post->post_type != TYPES_USER_META_FIELD_GROUP_CPT_NAME) {
             $form->triggerError();
             wpcf_admin_message(sprintf(__("Wrong group ID %d", 'wpcf'), intval($_REQUEST[$this->get_id])), 'error');
             return $form;
         }
         $group_id = $post->ID;
     } else {
         $new_group = true;
         // Check if already exists
         $exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME);
         if (!empty($exists)) {
             $form->triggerError();
             wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error');
             return $form;
         }
     }
     // Save fields for future use
     $fields = array();
     if (!empty($_POST['wpcf']['fields'])) {
         foreach ($_POST['wpcf']['fields'] as $key => $field) {
             $field = wpcf_sanitize_field($field);
             $field = apply_filters('wpcf_field_pre_save', $field);
             if (!empty($field['is_new'])) {
                 // Check name and slug
                 if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
                     $form->triggerError();
                     wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error');
                     return $form;
                 }
                 if (isset($field['slug']) && wpcf_types_cf_under_control('check_exists', sanitize_title($field['slug']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) {
                     $form->triggerError();
                     wpcf_admin_message(sprintf(__('Field with slug "%s" already exists', 'wpcf'), $field['slug']), 'error');
                     return $form;
                 }
             }
             // Field ID and slug are same thing
             $field_id = wpcf_admin_fields_save_field($field, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta');
             if (!empty($field_id)) {
                 $fields[] = $field_id;
             }
         }
     }
     // Save group
     $roles = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array();
     /**
      * Admin styles
      */
     if (isset($_POST['wpcf']['group']['admin_styles'])) {
         $admin_style = esc_html($_POST['wpcf']['group']['admin_styles']);
     }
     // Rename if needed
     if (isset($_REQUEST[$this->get_id])) {
         $_POST['wpcf']['group']['id'] = intval($_REQUEST[$this->get_id]);
//.........这里部分代码省略.........
开发者ID:phuocdungit,项目名称:fundy,代码行数:101,代码来源:class.types.admin.edit.meta.fields.group.php

示例3: wpcf_admin_fields_get_fields

/**
 * Gets all fields.
 *
 * @todo Move to WPCF_Fields
 * @param bool $only_active
 * @param bool $disabled_by_type
 * @param bool $strictly_active
 * @param string $option_name
 * @param bool $use_cache
 * @param bool $clear_cache
 * @return array
 *
 * added param $use_cache by Gen (used when adding new fields to group)
 * added param $use_cache by Gen (used when adding new fields to group)
 */
function wpcf_admin_fields_get_fields($only_active = false, $disabled_by_type = false, $strictly_active = false, $option_name = 'wpcf-fields', $use_cache = true, $clear_cache = false)
{
    static $cache = array();
    if ($clear_cache) {
        $cache = array();
    }
    /**
     * Sanitize option name
     */
    switch ($option_name) {
        case 'wpcf-usermeta':
        case 'wpcf-fields':
        case WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION:
            break;
        default:
            $option_name = 'wpcf-fields';
            break;
    }
    $cache_key = md5($only_active . $disabled_by_type . $strictly_active . $option_name . $use_cache);
    if (isset($cache[$cache_key]) && $use_cache == true) {
        return $cache[$cache_key];
    }
    $required_data = array('id', 'name', 'type', 'slug');
    $fields = (array) get_option($option_name, array());
    foreach ($fields as $k => $v) {
        $failed = false;
        foreach ($required_data as $required) {
            if (!isset($v[$required])) {
                $failed = true;
                continue;
            }
            if (is_numeric($v[$required]) === true) {
                $failed = true;
                continue;
            }
        }
        if (is_numeric($k) === true || $failed) {
            unset($fields[$k]);
            continue;
        }
        // This call loads config file
        $data = wpcf_fields_type_action($v['type']);
        if (empty($data)) {
            unset($fields[$k]);
            continue;
        }
        if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], '<')) {
            unset($fields[$k]);
            continue;
        }
        if ($strictly_active) {
            if (!empty($v['data']['disabled']) || !empty($v['data']['disabled_by_type'])) {
                unset($fields[$k]);
                continue;
            }
        } else {
            if ($only_active && !empty($v['data']['disabled'])) {
                unset($fields[$k]);
                continue;
            }
            if (!$disabled_by_type && !empty($v['data']['disabled_by_type'])) {
                unset($fields[$k]);
                continue;
            }
        }
        $v['id'] = $k;
        $v['meta_key'] = wpcf_types_get_meta_prefix($v) . $k;
        $option_name_to_meta_type = array('wpcf-fields' => 'postmeta', 'wpcf-usermeta' => 'usermeta', WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION => 'termmeta');
        $v['meta_type'] = $option_name_to_meta_type[$option_name];
        $fields[$k] = wpcf_sanitize_field($v);
    }
    $cache[$cache_key] = apply_filters('types_fields', $fields);
    return $cache[$cache_key];
}
开发者ID:lytranuit,项目名称:wordpress,代码行数:89,代码来源:fields.php

示例4: get_field_form_data

 /**
  * @param $type
  * @param array $form_data
  *
  * @return array
  */
 protected function get_field_form_data($type, $form_data = array())
 {
     /**
      * this function replace: wpcf_fields_get_field_form_data()
      */
     require_once WPCF_ABSPATH . '/includes/conditional-display.php';
     $form = array();
     /**
      * row fir field data
      */
     $table_row_typeproof = '<tr class="js-wpcf-fields-typeproof"><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
     $table_row = '<tr><td><LABEL></td><td><ERROR><BEFORE><ELEMENT><AFTER></td></tr>';
     // Get field type data
     if (empty($field_data)) {
         $field_data = wpcf_fields_type_action($type);
         if (empty($field_data)) {
             return $form;
         }
     }
     // Set right ID if existing field
     if (isset($form_data['submitted_key'])) {
         $id = $form_data['submitted_key'];
     } else {
         $id = $type . '-' . rand();
     }
     // Sanitize
     $form_data = wpcf_sanitize_field($form_data);
     $required = isset($form_data['data']['validate']['required']['active']) && $form_data['data']['validate']['required']['active'] === "1" ? __('- required', 'wpcf') : '';
     $form_data['id'] = $id;
     /**
      *  Set title
      */
     $title = !empty($form_data['name']) ? $form_data['name'] : __('Untitled', 'wpcf');
     $title = sprintf('<span class="wpcf-legend-update">%s</span> <span class="description">(%s)</span> <span class="wpcf_required_data">%s</span>', $title, $field_data['title'], $required);
     // Get init data
     $field_init_data = wpcf_fields_type_action($type);
     // See if field inherits some other
     $inherited_field_data = false;
     if (isset($field_init_data['inherited_field_type'])) {
         $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
     }
     $form_field = array();
     /**
      * Font Awesome Icon
      */
     $icon = '';
     $icon = $this->render_field_icon($field_init_data);
     /**
      * box id & class
      */
     $closed_postboxes = $this->get_closed_postboxes();
     $clasess = array('postbox');
     // close all elements except new added fields
     if (!isset($_REQUEST['type'])) {
         $clasess[] = 'closed';
     }
     $box_id = sprintf('types-custom-field-%s', $id);
     /* Only close boxes which user closed manually
           if ( !empty($closed_postboxes) ) {
        if ( in_array($box_id, $closed_postboxes) ) {
     	   $clasess[] = 'closed';
        }
        }
        */
     /**
      * box title
      */
     $form_field['box-open'] = array('#type' => 'markup', '#markup' => sprintf('<div id="%s" class="%s"><div class="handlediv" title="%s"><br></div><h3 class="hndle ui-sortable-handle">%s%s</h3>', esc_attr($box_id), esc_attr(implode(' ', $clasess)), esc_attr__('Click to toggle', 'wpcf'), $icon, $title));
     $form_field['table-open'] = array('#type' => 'markup', '#markup' => '<table class="widefat inside js-wpcf-slugize-container">');
     // Force name and description
     $form_field['name'] = array('#type' => 'textfield', '#name' => 'name', '#attributes' => array('class' => 'widefat wpcf-forms-set-legend wpcf-forms-field-name js-wpcf-slugize-source', 'placeholder' => __('Enter field name', 'wpcf'), 'tooltip' => __('This will be the label for the field in the post editor.', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#inline' => true, '#pattern' => $table_row_typeproof, '#title' => __('Field name', 'wpcf'));
     $form_field['slug'] = array('#type' => 'textfield', '#name' => 'slug', '#attributes' => array('class' => 'widefat wpcf-forms-field-slug js-wpcf-slugize', 'maxlength' => 255, 'placeholder' => __('Enter field slug', 'wpcf'), 'tooltip' => __('This is the machine name of the field.', 'wpcf')), '#validate' => array('nospecialchars' => array('value' => true)), '#inline' => true, '#pattern' => $table_row_typeproof, '#title' => __('Field slug', 'wpcf'));
     // existing field
     if (isset($form_data['submitted_key'])) {
         $form_field['slug-pre-save'] = array('#type' => 'hidden', '#name' => 'slug-pre-save');
     }
     $options = $this->get_available_types($type);
     if (empty($options)) {
         $form_field['type'] = array('#type' => 'markup', '#markup' => wpautop($type));
     } else {
         $form_field['type'] = array('#type' => 'select', '#name' => 'type', '#options' => $options, '#default_value' => $type, '#description' => __('Options for this filed will be available after group save.', 'wpcf'), '#attributes' => array('class' => 'js-wpcf-fields-type', 'data-message-after-change' => esc_attr__('Field options will be available after you save this group.', 'wpcf')));
     }
     $form_field['type']['#title'] = __('Field type', 'wpcf');
     $form_field['type']['#inline'] = true;
     $form_field['type']['#pattern'] = $table_row_typeproof;
     // If insert form callback is not provided, use generic form data
     if (function_exists('wpcf_fields_' . $type . '_insert_form')) {
         $form_field_temp = call_user_func('wpcf_fields_' . $type . '_insert_form', $form_data, 'wpcf[fields][' . $id . ']');
         if (is_array($form_field_temp)) {
             unset($form_field_temp['name'], $form_field_temp['slug']);
             /**
              * add default patter
              */
             foreach ($form_field_temp as $key => $data) {
//.........这里部分代码省略.........
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:101,代码来源:class.types.admin.edit.fields.php

示例5: wpcf_admin_fields_get_fields

/**
 * Gets all fields.
 *
 * @todo Move to WPCF_Fields
 * @param bool $only_active
 * @param bool $disabled_by_type
 * @param bool $strictly_active
 * @param string $option_name
 * @param bool $use_cache
 * @param bool $clear_cache
 * @return type
 *
 * added param $use_cache by Gen (used when adding new fields to group)
 * added param $use_cache by Gen (used when adding new fields to group)
 */
function wpcf_admin_fields_get_fields($only_active = false, $disabled_by_type = false, $strictly_active = false, $option_name = 'wpcf-fields', $use_cache = true, $clear_cache = false)
{
    static $cache = array();
    if ($clear_cache) {
        $cache = array();
    }
    $cache_key = md5($only_active . $disabled_by_type . $strictly_active . $option_name . $use_cache);
    if (isset($cache[$cache_key]) && $use_cache == true) {
        return $cache[$cache_key];
    }
    $required_data = array('id', 'name', 'type', 'slug');
    $fields = (array) get_option($option_name, array());
    foreach ($fields as $k => $v) {
        $failed = false;
        foreach ($required_data as $required) {
            if (!isset($v[$required])) {
                $failed = true;
                continue;
            }
            if (is_numeric($v[$required]) === true) {
                $failed = true;
                continue;
            }
        }
        if (is_numeric($k) === true || $failed) {
            unset($fields[$k]);
            continue;
        }
        // This call loads config file
        $data = wpcf_fields_type_action($v['type']);
        if (empty($data)) {
            unset($fields[$k]);
            continue;
        }
        if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], '<')) {
            unset($fields[$k]);
            continue;
        }
        if ($strictly_active) {
            if (!empty($v['data']['disabled']) || !empty($v['data']['disabled_by_type'])) {
                unset($fields[$k]);
                continue;
            }
        } else {
            if ($only_active && !empty($v['data']['disabled'])) {
                unset($fields[$k]);
                continue;
            }
            if (!$disabled_by_type && !empty($v['data']['disabled_by_type'])) {
                unset($fields[$k]);
                continue;
            }
        }
        $v['id'] = $k;
        $v['meta_key'] = wpcf_types_get_meta_prefix($v) . $k;
        $v['meta_type'] = $option_name == 'wpcf-fields' ? 'postmeta' : 'usermeta';
        $fields[$k] = wpcf_sanitize_field($v);
    }
    $cache[$cache_key] = apply_filters('types_fields', $fields);
    return $cache[$cache_key];
}
开发者ID:KryvunRoman,项目名称:yobko,代码行数:76,代码来源:fields.php

示例6: wpcf_fields_get_field_form_data

/**
 * Processes field form data.
 *
 * @param type $type
 * @param type $form_data
 * @return type
 */
function wpcf_fields_get_field_form_data($type, $form_data = array())
{
    // Get field type data
    $field_data = wpcf_fields_type_action($type);
    if (!empty($field_data)) {
        $form = array();
        // Set right ID if existing field
        if (isset($form_data['submitted_key'])) {
            $id = $form_data['submitted_key'];
        } else {
            $id = $type . '-' . rand();
        }
        // Sanitize
        $form_data = wpcf_sanitize_field($form_data);
        // Set remove link
        $remove_link = isset($form_data['group_id']) ? admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '&amp;action=wpcf_ajax&amp;wpcf_action=remove_field_from_group' . '&amp;group_id=' . intval($form_data['group_id']) . '&amp;field_id=' . $form_data['id']) . '&amp;_wpnonce=' . wp_create_nonce('remove_field_from_group') : admin_url('admin-ajax.php?' . 'wpcf_ajax_callback=wpcfFieldsFormDeleteElement&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '&amp;action=wpcf_ajax&amp;wpcf_action=remove_field_from_group') . '&amp;_wpnonce=' . wp_create_nonce('remove_field_from_group');
        // Set move button
        $form['wpcf-' . $id . '-control'] = array('#type' => 'markup', '#markup' => '<img src="' . WPCF_RES_RELPATH . '/images/move.png" class="wpcf-fields-form-move-field" alt="' . __('Move this field', 'wpcf') . '" /><a href="' . $remove_link . '" ' . 'class="wpcf-form-fields-delete wpcf-ajax-link">' . '<img src="' . WPCF_RES_RELPATH . '/images/delete-2.png" alt="' . __('Delete this field', 'wpcf') . '" /></a>');
        // Set fieldset
        $collapsed = wpcf_admin_fields_form_fieldset_is_collapsed('fieldset-' . $id);
        // Set collapsed on AJAX call (insert)
        $collapsed = defined('DOING_AJAX') ? false : $collapsed;
        // Set title
        $title = !empty($form_data['name']) ? $form_data['name'] : __('Untitled', 'wpcf');
        $title = '<span class="wpcf-legend-update">' . $title . '</span> - ' . sprintf(__('%s field', 'wpcf'), $field_data['title']);
        // Do not display on Usermeta Group edit screen
        if (!isset($_GET['page']) || $_GET['page'] != 'wpcf-edit-usermeta') {
            if (!empty($form_data['data']['conditional_display']['conditions'])) {
                $title .= ' ' . __('(conditional)', 'wpcf');
            }
        }
        $form['wpcf-' . $id] = array('#type' => 'fieldset', '#title' => $title, '#id' => 'fieldset-' . $id, '#collapsible' => true, '#collapsed' => $collapsed);
        // Get init data
        $field_init_data = wpcf_fields_type_action($type);
        // See if field inherits some other
        $inherited_field_data = false;
        if (isset($field_init_data['inherited_field_type'])) {
            $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
        }
        $form_field = array();
        // Force name and description
        $form_field['name'] = array('#type' => 'textfield', '#name' => 'name', '#attributes' => array('class' => 'wpcf-forms-set-legend wpcf-forms-field-name', 'style' => 'width:100%;margin:10px 0 10px 0;', 'placeholder' => __('Enter field name', 'wpcf')), '#validate' => array('required' => array('value' => true)), '#inline' => true);
        $form_field['slug'] = array('#type' => 'textfield', '#name' => 'slug', '#attributes' => array('class' => 'wpcf-forms-field-slug', 'style' => 'width:100%;margin:0 0 10px 0;', 'maxlength' => 255, 'placeholder' => __('Enter field slug', 'wpcf')), '#validate' => array('nospecialchars' => array('value' => true)), '#inline' => true);
        // If insert form callback is not provided, use generic form data
        if (function_exists('wpcf_fields_' . $type . '_insert_form')) {
            $form_field_temp = call_user_func('wpcf_fields_' . $type . '_insert_form', $form_data, 'wpcf[fields][' . $id . ']');
            if (is_array($form_field_temp)) {
                unset($form_field_temp['name'], $form_field_temp['slug']);
                $form_field = $form_field + $form_field_temp;
            }
        }
        $form_field['description'] = array('#type' => 'textarea', '#name' => 'description', '#attributes' => array('rows' => 5, 'cols' => 1, 'style' => 'margin:0 0 10px 0;', 'placeholder' => __('Describe this field', 'wpcf')), '#inline' => true);
        /**
         * add placeholder field
         */
        switch ($type) {
            case 'audio':
            case 'colorpicker':
            case 'date':
            case 'email':
            case 'embed':
            case 'file':
            case 'image':
            case 'numeric':
            case 'phone':
            case 'skype':
            case 'textarea':
            case 'textfield':
            case 'url':
            case 'video':
                $form_field['placeholder'] = array('#type' => 'textfield', '#name' => 'placeholder', '#inline' => true, '#title' => __('Placeholder', 'wpcf'), '#attributes' => array('style' => 'width:100%;margin:0 0 10px 0;', 'placeholder' => __('Enter placeholder', 'wpcf')));
                break;
        }
        if (wpcf_admin_can_be_repetitive($type)) {
            $temp_warning_message = '';
            $form_field['repetitive'] = array('#type' => 'radios', '#name' => 'repetitive', '#title' => __('Single or repeating field?', 'wpcf'), '#options' => array('repeat' => array('#title' => __('Allow multiple-instances of this field', 'wpcf'), '#value' => '1', '#attributes' => array('onclick' => 'jQuery(this).parent().parent().find(\'.wpcf-cd-warning\').hide(); jQuery(this).parent().find(\'.wpcf-cd-repetitive-warning\').show();')), 'norepeat' => array('#title' => __('This field can have only one value', 'wpcf'), '#value' => '0', '#attributes' => array('onclick' => 'jQuery(this).parent().parent().find(\'.wpcf-cd-warning\').show(); jQuery(this).parent().find(\'.wpcf-cd-repetitive-warning\').hide();'))), '#default_value' => isset($form_data['data']['repetitive']) ? $form_data['data']['repetitive'] : '0', '#after' => wpcf_admin_is_repetitive($form_data) ? '<div class="wpcf-message wpcf-cd-warning wpcf-error" style="display:none;"><p>' . __("There may be multiple instances of this field already. When you switch back to single-field mode, all values of this field will be updated when it's edited.", 'wpcf') . '</p></div>' . $temp_warning_message : $temp_warning_message);
        }
        // Process all form fields
        foreach ($form_field as $k => $field) {
            $form['wpcf-' . $id][$k] = $field;
            // Check if nested
            if (isset($field['#name']) && strpos($field['#name'], '[') === false) {
                $form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . '][' . $field['#name'] . ']';
            } else {
                if (isset($field['#name'])) {
                    $form['wpcf-' . $id][$k]['#name'] = 'wpcf[fields][' . $id . ']' . $field['#name'];
                }
            }
            if (!isset($field['#id'])) {
                $form['wpcf-' . $id][$k]['#id'] = $type . '-' . $field['#type'] . '-' . rand();
            }
            if (isset($field['#name']) && isset($form_data[$field['#name']])) {
                $form['wpcf-' . $id][$k]['#value'] = $form_data[$field['#name']];
//.........这里部分代码省略.........
开发者ID:chrismathers,项目名称:premierplacement,代码行数:101,代码来源:fields-form.php

示例7: save_group_fields

 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  *
  * @return type Description.
  */
 private function save_group_fields($group_id)
 {
     if (empty($_POST['wpcf']['fields'])) {
         delete_post_meta($group_id, '_wp_types_group_fields');
         return;
     }
     $fields = array();
     // First check all fields
     foreach ($_POST['wpcf']['fields'] as $key => $field) {
         $field = wpcf_sanitize_field($field);
         $field = apply_filters('wpcf_field_pre_save', $field);
         if (!empty($field['is_new'])) {
             // Check name and slug
             if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']))) {
                 $this->triggerError();
                 wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error');
                 return $form;
             }
             if (isset($field['slug']) && wpcf_types_cf_under_control('check_exists', sanitize_title($field['slug']))) {
                 $this->triggerError();
                 wpcf_admin_message(sprintf(__('Field with slug "%s" already exists', 'wpcf'), $field['slug']), 'error');
                 return $form;
             }
         }
         $field['submit-key'] = $key;
         // Field ID and slug are same thing
         $field_id = wpcf_admin_fields_save_field($field);
         if (is_wp_error($field_id)) {
             $this->triggerError();
             wpcf_admin_message($field_id->get_error_message(), 'error');
             return;
         }
         if (!empty($field_id)) {
             $fields[] = $field_id;
         }
         // WPML
         /** @var string $field_id */
         if (defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<')) {
             if (function_exists('wpml_cf_translation_preferences_store')) {
                 $real_custom_field_name = wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_id)) . $field_id;
                 wpml_cf_translation_preferences_store($key, $real_custom_field_name);
             }
         }
     }
     wpcf_admin_fields_save_group_fields($group_id, $fields);
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:64,代码来源:class.types.admin.edit.custom.fields.group.php

示例8: save_filter_fields

 private function save_filter_fields($group_id, $fields_data)
 {
     if (empty($fields_data)) {
         delete_post_meta($group_id, '_wp_types_group_fields');
         return;
     }
     $fields = array();
     // First check all fields
     foreach ($fields_data as $field_key => $field) {
         $field = wpcf_sanitize_field($field);
         $field = apply_filters('wpcf_field_pre_save', $field);
         if (!empty($field['is_new'])) {
             // Check name and slug
             if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']), WPCF_Field_Group_Term::POST_TYPE, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION)) {
                 $this->triggerError();
                 wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error');
                 return;
             }
             if (isset($field['slug']) && wpcf_types_cf_under_control('check_exists', sanitize_title($field['slug']), WPCF_Field_Group_Term::POST_TYPE, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION)) {
                 $this->triggerError();
                 wpcf_admin_message(sprintf(__('Field with slug "%s" already exists', 'wpcf'), $field['slug']), 'error');
                 return;
             }
         }
         $field['submit-key'] = $field_key;
         // Field ID and slug are same thing
         $field_slug = wpcf_admin_fields_save_field($field, WPCF_Field_Group_Term::POST_TYPE, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION);
         if (is_wp_error($field_slug)) {
             $this->triggerError();
             wpcf_admin_message($field_slug->get_error_message(), 'error');
             return;
         }
         if (!empty($field_slug)) {
             $fields[] = $field_slug;
         }
         // WPML
         if (defined('ICL_SITEPRESS_VERSION') && version_compare(ICL_SITEPRESS_VERSION, '3.2', '<')) {
             if (function_exists('wpml_cf_translation_preferences_store')) {
                 $real_custom_field_name = wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_slug, false, false, false, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION)) . $field_slug;
                 wpml_cf_translation_preferences_store($field_key, $real_custom_field_name);
             }
         }
     }
     wpcf_admin_fields_save_group_fields($group_id, $fields, false, WPCF_Field_Group_Term::POST_TYPE, WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION);
 }
开发者ID:phuocdungit,项目名称:fundy,代码行数:45,代码来源:termmeta_form.php

示例9: wpcf_admin_fields_save_field

/**
 * Saves field.
 * Modified by Gen, 13.02.2013
 *
 * @param array $field Field data
 * @param string $post_type
 * @param string $option_name
 *
 * @return string|WP_Error Field slug or an error object.
 */
function wpcf_admin_fields_save_field($field, $post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, $option_name = 'wpcf-fields')
{
    if (!isset($field['name']) || !isset($field['type'])) {
        return new WP_Error('wpcf_save_field_no_name_or_type', __("Error saving field", 'wpcf'));
    }
    $field = wpcf_sanitize_field($field);
    if (empty($field['name']) || empty($field['slug'])) {
        return new WP_Error('wpcf_save_field_no_name', __("Please set name for field", 'wpcf'));
    }
    $field['id'] = $field['slug'];
    // Set field specific data
    // NOTE: This was $field['data'] = $field and seemed to work on most systems.
    // I changed it to asign via a temporary variable to fix on one system.
    $temp_field = $field;
    $field['data'] = $temp_field;
    // Unset default fields
    unset($field['data']['type'], $field['data']['slug'], $field['data']['name'], $field['data']['description'], $field['data']['user_id'], $field['data']['id'], $field['data']['data']);
    // Merge previous data (added because of outside fields)
    // @TODO Remember why
    if (wpcf_types_cf_under_control('check_outsider', $field['id'], $post_type, $option_name)) {
        $field_previous_data = wpcf_admin_fields_get_field($field['id'], false, true, false, $option_name);
        if (!empty($field_previous_data['data'])) {
            $field['data'] = array_merge($field_previous_data['data'], $field['data']);
        }
    }
    $field['data'] = apply_filters('wpcf_fields_' . $field['type'] . '_meta_data', $field['data'], $field);
    // Check validation
    if (isset($field['data']['validate'])) {
        foreach ($field['data']['validate'] as $method => $data) {
            if (!isset($data['active'])) {
                unset($field['data']['validate'][$method]);
            }
        }
        if (empty($field['data']['validate'])) {
            unset($field['data']['validate']);
        }
    }
    $save_data = array();
    $save_data['id'] = $field['id'];
    $save_data['slug'] = $field['slug'];
    $save_data['type'] = $field['type'];
    $save_data['name'] = $field['name'];
    $save_data['description'] = $field['description'];
    $save_data['data'] = $field['data'];
    $save_data['data']['disabled_by_type'] = 0;
    // For radios or select
    if (!empty($field['data']['options'])) {
        foreach ($field['data']['options'] as $name => $option) {
            if (isset($option['title'])) {
                $option['title'] = $field['data']['options'][$name]['title'] = htmlspecialchars_decode($option['title']);
            }
            if (isset($option['value'])) {
                $option['value'] = $field['data']['options'][$name]['value'] = htmlspecialchars_decode($option['value']);
            }
            if (isset($option['display_value'])) {
                $option['display_value'] = $field['data']['options'][$name]['display_value'] = htmlspecialchars_decode($option['display_value']);
            }
            // For checkboxes
            if ($field['type'] == 'checkboxes' && isset($option['set_value']) && $option['set_value'] != '1') {
                $option['set_value'] = $field['data']['options'][$name]['set_value'] = htmlspecialchars_decode($option['set_value']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_selected'])) {
                $option['display_value_selected'] = $field['data']['options'][$name]['display_value_selected'] = htmlspecialchars_decode($option['display_value_selected']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_not_selected'])) {
                $option['display_value_not_selected'] = $field['data']['options'][$name]['display_value_not_selected'] = htmlspecialchars_decode($option['display_value_not_selected']);
            }
        }
    }
    // For checkboxes
    if ('checkbox' == $field['type'] && isset($field['set_value']) && $field['set_value'] != '1') {
        $field['set_value'] = htmlspecialchars_decode($field['set_value']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
        $field['display_value_selected'] = htmlspecialchars_decode($field['display_value_selected']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
        $field['display_value_not_selected'] = htmlspecialchars_decode($field['display_value_not_selected']);
    }
    // Save field
    $fields = get_option($option_name, array());
    // prevent erasing saved conditional display data (it's controlled via ajax)
    if (isset($fields[$field['slug']]['data']['conditional_display']) && !empty($fields[$field['slug']]['data']['conditional_display'])) {
        $save_data['data']['conditional_display'] = $fields[$field['slug']]['data']['conditional_display'];
    }
    $fields[$field['slug']] = $save_data;
    update_option($option_name, $fields);
    $field_id = $field['slug'];
    // WPML register strings
    if (function_exists('icl_register_string')) {
//.........这里部分代码省略.........
开发者ID:otkinsey,项目名称:wp-nsds,代码行数:101,代码来源:fields.php

示例10: wpcf_admin_fields_save_field

/**
 * Saves field.
 *
 * Note: This is (probably) intended only for saving field definition data on the Edit Field Group pages.
 * 
 * @param array $field Field data
 * @param string $post_type
 * @param string $option_name
 *
 * @return string|WP_Error Field slug or an error object.
 */
function wpcf_admin_fields_save_field($field, $post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, $option_name = 'wpcf-fields')
{
    if (!isset($field['name']) || !isset($field['type'])) {
        return new WP_Error('wpcf_save_field_no_name_or_type', __("Error saving field", 'wpcf'));
    }
    $field = wpcf_sanitize_field($field);
    if (empty($field['name']) || empty($field['slug'])) {
        return new WP_Error('wpcf_save_field_no_name', __("Please set name for field", 'wpcf'));
    }
    $field['id'] = $field['slug'];
    // Set field specific data
    // NOTE: This was $field['data'] = $field and seemed to work on most systems.
    // I changed it to asign via a temporary variable to fix on one system.
    $temp_field = $field;
    $field['data'] = $temp_field;
    // Unset default fields
    // fixme These lines effectively erases all new values in "data", does anyone know why?
    // fixme This function needs SERIOUS review.
    unset($field['data']['type'], $field['data']['slug'], $field['data']['name'], $field['data']['description'], $field['data']['user_id'], $field['data']['id'], $field['data']['data']);
    // Merge previous data (added because of outside fields)
    // @TODO Remember why
    if (wpcf_types_cf_under_control('check_outsider', $field['id'], $post_type, $option_name)) {
        $field_previous_data = wpcf_admin_fields_get_field($field['id'], false, true, false, $option_name);
        if (!empty($field_previous_data['data'])) {
            $field['data'] = array_merge($field_previous_data['data'], $field['data']);
        }
    }
    $field['data'] = apply_filters('wpcf_fields_' . $field['type'] . '_meta_data', $field['data'], $field);
    // Check validation
    if (isset($field['data']['validate'])) {
        foreach ($field['data']['validate'] as $method => $data) {
            if (!isset($data['active'])) {
                unset($field['data']['validate'][$method]);
            }
        }
        if (empty($field['data']['validate'])) {
            unset($field['data']['validate']);
        }
    }
    $save_data = array();
    $save_data['id'] = $field['id'];
    $save_data['slug'] = $field['slug'];
    $save_data['type'] = $field['type'];
    $save_data['name'] = $field['name'];
    $save_data['description'] = $field['description'];
    $save_data['data'] = $field['data'];
    $save_data['data']['disabled_by_type'] = 0;
    // For radios or select
    if (!empty($field['data']['options'])) {
        foreach ($field['data']['options'] as $name => $option) {
            if (isset($option['title'])) {
                $option['title'] = $field['data']['options'][$name]['title'] = htmlspecialchars_decode($option['title']);
            }
            if (isset($option['value'])) {
                $option['value'] = $field['data']['options'][$name]['value'] = htmlspecialchars_decode($option['value']);
            }
            if (isset($option['display_value'])) {
                $option['display_value'] = $field['data']['options'][$name]['display_value'] = htmlspecialchars_decode($option['display_value']);
            }
            // For checkboxes
            if ($field['type'] == 'checkboxes' && isset($option['set_value']) && $option['set_value'] != '1') {
                $option['set_value'] = $field['data']['options'][$name]['set_value'] = htmlspecialchars_decode($option['set_value']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_selected'])) {
                $option['display_value_selected'] = $field['data']['options'][$name]['display_value_selected'] = htmlspecialchars_decode($option['display_value_selected']);
            }
            if ($field['type'] == 'checkboxes' && !empty($option['display_value_not_selected'])) {
                $option['display_value_not_selected'] = $field['data']['options'][$name]['display_value_not_selected'] = htmlspecialchars_decode($option['display_value_not_selected']);
            }
        }
    }
    // For checkboxes
    if ('checkbox' == $field['type'] && isset($field['set_value']) && $field['set_value'] != '1') {
        $field['set_value'] = htmlspecialchars_decode($field['set_value']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
        $field['display_value_selected'] = htmlspecialchars_decode($field['display_value_selected']);
    }
    if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
        $field['display_value_not_selected'] = htmlspecialchars_decode($field['display_value_not_selected']);
    }
    // Save field
    $fields = get_option($option_name, array());
    // prevent erasing saved conditional display data (it's controlled via ajax)
    if (isset($fields[$field['slug']]['data']['conditional_display']) && !empty($fields[$field['slug']]['data']['conditional_display'])) {
        $save_data['data']['conditional_display'] = $fields[$field['slug']]['data']['conditional_display'];
    }
    // on changing a field slug
    if (isset($field['slug-pre-save']) && $field['slug'] != $field['slug-pre-save']) {
//.........这里部分代码省略.........
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:101,代码来源:fields.php

示例11: wpcf_admin_fields_get_field

/**
 * Gets field by ID.
 * 
 * @global type $wpdb
 * @param type $field_id
 * @param type $only_active
 * @return type 
 */
function wpcf_admin_fields_get_field($field_id, $only_active = false, $disabled_by_type = false, $strictly_active = false)
{
    $fields = wpcf_admin_fields_get_fields($only_active, $disabled_by_type, $strictly_active);
    if (!empty($fields[$field_id])) {
        $data = wpcf_fields_type_action($fields[$field_id]['type']);
        if (isset($data['wp_version']) && wpcf_compare_wp_version($data['wp_version'], '<')) {
            return array();
        }
        $fields[$field_id]['id'] = $field_id;
        return wpcf_sanitize_field($fields[$field_id]);
    }
    return array();
}
开发者ID:pwillems,项目名称:mimosa-contents,代码行数:21,代码来源:fields.php


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