コード例 #1
0
/**
 * Registers translation data.
 * 
 * @param type $post_type
 * @param type $data 
 */
function wpcf_custom_taxonimies_register_translation($taxonomy, $data)
{
    if (!function_exists('icl_register_string')) {
        return $data;
    }
    $default = wpcf_custom_taxonomies_default();
    if (isset($data['description'])) {
        wpcf_translate_register_string('Types-TAX', $taxonomy . ' description', $data['description']);
    }
    foreach ($data['labels'] as $label => $string) {
        if ($label == 'name' || $label == 'singular_name') {
            wpcf_translate_register_string('Types-TAX', $taxonomy . ' ' . $label, $string);
            continue;
        }
        if (!isset($default['labels'][$label]) || $string !== $default['labels'][$label]) {
            wpcf_translate_register_string('Types-TAX', $taxonomy . ' ' . $label, $string);
        }
    }
}
コード例 #2
0
ファイル: admin.php プロジェクト: sriram911/pls
/**
 * Bulk translation. 
 */
function wpcf_admin_bulk_string_translation()
{
    if (!function_exists('icl_register_string')) {
        return false;
    }
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-types.php';
    require_once WPCF_INC_ABSPATH . '/custom-types-form.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/custom-taxonomies.php';
    require_once WPCF_INC_ABSPATH . '/custom-taxonomies-form.php';
    // Register groups
    $groups = wpcf_admin_fields_get_groups();
    foreach ($groups as $group_id => $group) {
        wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' name', $group['name']);
        if (isset($group['description'])) {
            wpcf_translate_register_string('plugin Types', 'group ' . $group_id . ' description', $group['description']);
        }
    }
    // Register fields
    $fields = wpcf_admin_fields_get_fields();
    foreach ($fields as $field_id => $field) {
        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' name', $field['name']);
        if (isset($field['description'])) {
            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;
                }
                if (isset($option['title'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
                }
                if (isset($option['value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
                }
                if (isset($option['display_value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
                }
            }
        }
        if ($field['type'] == 'checkbox' && (isset($field['set_value']) && $field['set_value'] != '1')) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
        }
        // Validation message
        if (!empty($field['data']['validate'])) {
            foreach ($field['data']['validate'] as $method => $validation) {
                if (!empty($validation['message'])) {
                    // Skip if it's same as default
                    $default_message = wpcf_admin_validation_messages($method);
                    if ($validation['message'] != $default_message) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
                    }
                }
            }
        }
    }
    // Register types
    $custom_types = get_option('wpcf-custom-types', array());
    foreach ($custom_types as $post_type => $data) {
        wpcf_custom_types_register_translation($post_type, $data);
    }
    // Register taxonomies
    $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
    foreach ($custom_taxonomies as $taxonomy => $data) {
        wpcf_custom_taxonimies_register_translation($taxonomy, $data);
    }
}
コード例 #3
0
ファイル: fields.php プロジェクト: sriram911/pls
/**
 * Saves field.
 * 
 * @param type $field
 * @return type 
 */
function wpcf_admin_fields_save_field($field)
{
    if (!isset($field['name']) || !isset($field['type'])) {
        return false;
    }
    if (empty($field['slug'])) {
        $field['slug'] = sanitize_title($field['name']);
    } else {
        $field['slug'] = sanitize_title($field['slug']);
    }
    $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;
                }
                if (isset($option['title'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
                }
                if (isset($option['value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
                }
                if (isset($option['display_value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
                }
                // For checkboxes
                if (isset($option['set_value']) && $option['set_value'] != '1') {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['set_value']);
                }
                if (!empty($option['display_value_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value selected', $option['display_value_selected']);
                }
                if (!empty($option['display_value_not_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value not selected', $option['display_value_not_selected']);
                }
            }
        }
        if ($field['type'] == 'checkbox' && $field['set_value'] != '1') {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
        }
        // Validation message
        if (!empty($field['data']['validate'])) {
            foreach ($field['data']['validate'] as $method => $validation) {
                if (!empty($validation['message'])) {
                    // Skip if it's same as default
                    $default_message = wpcf_admin_validation_messages($method);
                    if ($validation['message'] != $default_message) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
                    }
                }
            }
        }
    }
    return $field_id;
}
コード例 #4
0
ファイル: wpml.php プロジェクト: evdant/firstwp
/**
 * Registers labels.
 *
 * @param type $prefix
 * @param type $data
 * @param type $context
 */
function wpcf_wpml_register_labels($prefix, $data, $context = 'post')
{
    foreach ($data['labels'] as $label => $string) {
        switch ($context) {
            case 'taxonomies':
            case 'taxonomy':
            case 'tax':
                $default = wpcf_custom_taxonomies_default();
                if ($label == 'name' || $label == 'singular_name') {
                    wpcf_translate_register_string('Types-TAX', $prefix . ' ' . $label, $string);
                    continue;
                }
                if (isset($default['labels'][$label]) && $string == $default['labels'][$label]) {
                    wpcf_translate_register_string('Types-TAX', $label, $string);
                } else {
                    wpcf_translate_register_string('Types-TAX', $prefix . ' ' . $label, $string);
                }
                break;
            default:
                $default = wpcf_custom_types_default();
                // Name and singular_name
                if ($label == 'name' || $label == 'singular_name') {
                    wpcf_translate_register_string('Types-CPT', $prefix . ' ' . $label, $string);
                    continue;
                }
                // Check others for defaults
                if (isset($default['labels'][$label]) && $string == $default['labels'][$label]) {
                    // Register default translation
                    wpcf_translate_register_string('Types-CPT', $label, $string);
                } else {
                    wpcf_translate_register_string('Types-CPT', $prefix . ' ' . $label, $string);
                }
                break;
        }
    }
}
コード例 #5
0
ファイル: fields.php プロジェクト: aarongillett/B22-151217
/**
 * Saves field.
 * Modified by Gen, 13.02.2013
 *
 * @param type $field
 * @return type
 */
function wpcf_admin_fields_save_field($field, $post_type = TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, $meta_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, $meta_name)) {
        $field_previous_data = wpcf_admin_fields_get_field($field['id'], false, true, false, $meta_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 ($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($meta_name, array());
    $fields[$field['slug']] = $save_data;
    update_option($meta_name, $fields);
    $field_id = $field['slug'];
    // WPML register strings
    if (function_exists('icl_register_string')) {
        if (isset($_POST['wpml_cf_translation_preferences'][$field_id])) {
            $__wpml_action = intval($_POST['wpml_cf_translation_preferences'][$field_id]);
        } else {
            $__wpml_action = wpcf_wpml_get_action_by_type($field['type']);
        }
        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;
                }
                if (isset($option['title'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
                }
                if ($__wpml_action === 2) {
                    if (isset($option['value'])) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
                    }
                }
                if (isset($option['display_value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
                }
                // For checkboxes
                if (isset($option['set_value']) && $option['set_value'] != '1') {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['set_value']);
                }
                if (!empty($option['display_value_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value selected', $option['display_value_selected']);
                }
                if (!empty($option['display_value_not_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value not selected', $option['display_value_not_selected']);
                }
            }
        }
        if ($field['type'] == 'checkbox' && $field['set_value'] != '1') {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
        }
        // Validation message
        if (!empty($field['data']['validate'])) {
            foreach ($field['data']['validate'] as $method => $validation) {
                if (!empty($validation['message'])) {
                    // Skip if it's same as default
                    $default_message = wpcf_admin_validation_messages($method);
                    if ($validation['message'] != $default_message) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
                    }
                }
            }
        }
    }
    /**
     * WPML update translation status
     */
    if (isset($save_data['data']) && isset($save_data['data']['submit-key'])) {
        if (isset($_POST['wpml_cf_translation_preferences'][$save_data['data']['submit-key']])) {
            do_action('wpml_config', array('section' => 'custom-fields', 'key' => wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($save_data['slug'])) . $save_data['slug'], 'value' => intval($_POST['wpml_cf_translation_preferences'][$save_data['data']['submit-key']]), 'read_only' => true));
        }
    }
    return $field_id;
}
コード例 #6
0
ファイル: fields.php プロジェクト: studiopengpeng/ASCOMETAL
/**
 * 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']) {
        // takeover conditions on renamed slug
        if (isset($fields[$field['slug-pre-save']]['data']['conditional_display']) && !empty($fields[$field['slug-pre-save']]['data']['conditional_display'])) {
            $save_data['data']['conditional_display'] = $fields[$field['slug-pre-save']]['data']['conditional_display'];
        }
        // field is assigned ONLY to current group
        $belongs_to_groups = wpcf_admin_fields_get_groups_by_field($field['slug-pre-save'], $post_type);
        if (isset($_GET['group_id']) && isset($fields[$field['slug-pre-save']]) && count($belongs_to_groups) == 1 && isset($belongs_to_groups[$_GET['group_id']])) {
            global $wpdb;
            // as it's the only group with this field we can update the slug for all items
            $wpdb->update($wpdb->postmeta, array('meta_key' => 'wpcf-' . $field['slug']), array('meta_key' => 'wpcf-' . $field['slug-pre-save']), array('%s'), array('%s'));
            // change slug in field conditions
            foreach ($fields as $key => &$single_field) {
                if (isset($single_field['data']['conditional_display']['conditions'])) {
                    foreach ($single_field['data']['conditional_display']['conditions'] as &$single_condition) {
                        if ($single_condition['field'] == $field['slug-pre-save']) {
                            $single_condition['field'] = $field['slug'];
                        }
                    }
                }
            }
            // get all group conditions which contain the old slug
            $groups_conditions = $wpdb->get_results("\n                SELECT post_id, meta_value\n                FROM   {$wpdb->postmeta}\n                WHERE  meta_key = '_wpcf_conditional_display'\n                AND    meta_value LIKE '%" . $field['slug-pre-save'] . "%'\n\t        ");
            if ($groups_conditions) {
                foreach ($groups_conditions as $group_condition) {
                    $meta_value = unserialize($group_condition->meta_value);
                    // proper proof for slug
                    if (isset($meta_value['conditions'])) {
                        foreach ($meta_value['conditions'] as &$single_condition) {
                            if ($single_condition['field'] == $field['slug-pre-save']) {
                                // update conditions slug
                                $single_condition['field'] = $field['slug'];
                                update_post_meta($group_condition->post_id, '_wpcf_conditional_display', $meta_value);
                                break;
                            }
                        }
                    }
                }
            }
            // delete field
            wpcf_admin_fields_delete_field($field['slug-pre-save'], $post_type, $option_name);
            unset($fields[$field['slug-pre-save']]);
            // update items by post type
        } elseif (isset($_GET['group_id'])) {
            switch ($post_type) {
                case 'wp-types-group':
                    $group = Types_Field_Group_Post_Factory::load($_GET['group_id']);
                    break;
                case 'wp-types-term-group':
                    $group = Types_Field_Group_Term_Factory::load($_GET['group_id']);
                    break;
                case 'wp-types-user-group':
                    $group = Types_Field_Group_User_Factory::load($_GET['group_id']);
                    break;
            }
            if (null != $group) {
                $assigned_types = $group->get_assigned_to_types();
                if (!empty($assigned_types)) {
                    $items = $group->get_assigned_to_items();
                    if (is_array($items) && !empty($items)) {
                        global $wpdb;
                        foreach ($items as $item) {
                            $wpdb->update($wpdb->postmeta, array('meta_key' => 'wpcf-' . $field['slug']), array('meta_key' => 'wpcf-' . $field['slug-pre-save'], 'post_id' => $item->ID), array('%s', '%d'), array('%s'));
                        }
                    }
                }
            }
        }
    }
    $fields[$field['slug']] = $save_data;
    update_option($option_name, $fields);
    $field_id = $field['slug'];
    // WPML register strings
    if (function_exists('icl_register_string')) {
        if (isset($_POST['wpml_cf_translation_preferences'][$field_id])) {
            $__wpml_action = intval($_POST['wpml_cf_translation_preferences'][$field_id]);
        } else {
            $__wpml_action = wpcf_wpml_get_action_by_type($field['type']);
        }
        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;
                }
                if (isset($option['title'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' title', $option['title']);
                }
                if ($__wpml_action === 2) {
                    if (isset($option['value'])) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['value']);
                    }
                }
                if (isset($option['display_value'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value', $option['display_value']);
                }
                // For checkboxes
                if (isset($option['set_value']) && $option['set_value'] != '1') {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' value', $option['set_value']);
                }
                if (!empty($option['display_value_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value selected', $option['display_value_selected']);
                }
                if (!empty($option['display_value_not_selected'])) {
                    wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' option ' . $name . ' display value not selected', $option['display_value_not_selected']);
                }
            }
        }
        if ($field['type'] == 'checkbox' && $field['set_value'] != '1') {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value', $field['set_value']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value selected', $field['display_value_selected']);
        }
        if ($field['type'] == 'checkbox' && !empty($field['display_value_not_selected'])) {
            // we need to translate the check box value to store
            wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' checkbox value not selected', $field['display_value_not_selected']);
        }
        // Validation message
        if (!empty($field['data']['validate'])) {
            foreach ($field['data']['validate'] as $method => $validation) {
                if (!empty($validation['message'])) {
                    // Skip if it's same as default
                    $default_message = wpcf_admin_validation_messages($method);
                    if ($validation['message'] != $default_message) {
                        wpcf_translate_register_string('plugin Types', 'field ' . $field_id . ' validation message ' . $method, $validation['message']);
                    }
                }
            }
        }
    }
    /**
     * WPML update translation status
     */
    if (isset($save_data['data']) && isset($save_data['data']['submit-key'])) {
        if (isset($_POST['wpml_cf_translation_preferences'][$save_data['data']['submit-key']])) {
            do_action('wpml_config', array('section' => 'custom-fields', 'key' => wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($save_data['slug'])) . $save_data['slug'], 'value' => intval($_POST['wpml_cf_translation_preferences'][$save_data['data']['submit-key']]), 'read_only' => true));
        }
    }
    return $field_id;
}