Пример #1
0
/**
 * 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);
    }
}
Пример #2
0
/**
 * Submit function
 */
function wpcf_admin_custom_types_form_submit($form)
{
    global $wpcf;
    if (!isset($_POST['ct'])) {
        return false;
    }
    $data = $_POST['ct'];
    $update = false;
    // Sanitize data
    if (isset($data['wpcf-post-type'])) {
        $update = true;
        $data['wpcf-post-type'] = sanitize_title($data['wpcf-post-type']);
    }
    if (isset($data['slug'])) {
        $data['slug'] = sanitize_title($data['slug']);
    }
    if (isset($data['rewrite']['slug'])) {
        $data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
        $data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
        $data['rewrite']['slug'] = trim($data['rewrite']['slug']);
    }
    // Set post type name
    $post_type = '';
    if (!empty($data['slug'])) {
        $post_type = $data['slug'];
    } else {
        if (!empty($data['wpcf-post-type'])) {
            $post_type = $data['wpcf-post-type'];
        } else {
            if (!empty($data['labels']['singular_name'])) {
                $post_type = sanitize_title($data['labels']['singular_name']);
            }
        }
    }
    if (empty($post_type)) {
        wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
        //        $form->triggerError();
        return false;
    }
    $data['slug'] = $post_type;
    $custom_types = get_option('wpcf-custom-types', array());
    // Check reserved name
    $reserved = wpcf_is_reserved_name($post_type);
    if (is_wp_error($reserved)) {
        wpcf_admin_message($reserved->get_error_message(), 'error');
        return false;
    }
    // Check overwriting
    if (!$update && array_key_exists($post_type, $custom_types)) {
        wpcf_admin_message(__('Custom post type already exists', 'wpcf'), 'error');
        //            $form->triggerError();
        return false;
    }
    /*
     * Since Types 1.2
     * We do not allow plural and singular names to be same.
     */
    if ($wpcf->post_types->check_singular_plural_match($data)) {
        wpcf_admin_message($wpcf->post_types->message('warning_singular_plural_match'), 'error');
        return false;
    }
    // Check if renaming then rename all post entries and delete old type
    if (!empty($data['wpcf-post-type']) && $data['wpcf-post-type'] != $post_type) {
        global $wpdb;
        $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data['wpcf-post-type']), array('%s'), array('%s'));
        // Set protected data
        $protected_data_check = $custom_types[$data['wpcf-post-type']];
        // Delete old type
        unset($custom_types[$data['wpcf-post-type']]);
        $data['wpcf-post-type'] = $post_type;
    } else {
        // Set protected data
        $protected_data_check = !empty($custom_types[$post_type]) ? $custom_types[$post_type] : array();
    }
    // Check if active
    if (isset($custom_types[$post_type]['disabled'])) {
        $data['disabled'] = $custom_types[$post_type]['disabled'];
    }
    // Sync taxes with custom taxes
    if (!empty($data['taxonomies'])) {
        $taxes = get_option('wpcf-custom-taxonomies', array());
        foreach ($taxes as $id => $tax) {
            if (array_key_exists($id, $data['taxonomies'])) {
                $taxes[$id]['supports'][$data['slug']] = 1;
            } else {
                unset($taxes[$id]['supports'][$data['slug']]);
            }
        }
        update_option('wpcf-custom-taxonomies', $taxes);
    }
    // Preserve protected data
    foreach ($protected_data_check as $key => $value) {
        if (strpos($key, '_') !== 0) {
            unset($protected_data_check[$key]);
        }
    }
    // Merging protected data
    $custom_types[$post_type] = array_merge($protected_data_check, $data);
    update_option('wpcf-custom-types', $custom_types);
    // WPML register strings
    wpcf_custom_types_register_translation($post_type, $data);
    wpcf_admin_message_store(apply_filters('types_message_custom_post_type_saved', __('Custom post type saved', 'wpcf'), $data, $update), 'custom');
    // Flush rewrite rules
    flush_rewrite_rules();
    do_action('wpcf_custom_types_save', $data);
    // Redirect
    wp_redirect(admin_url('admin.php?page=wpcf-edit-type&wpcf-post-type=' . $post_type . '&wpcf-rewrite=1'));
    die;
}
Пример #3
0
/**
 * Submit function
 */
function wpcf_admin_custom_types_form_submit($form)
{
    global $wpcf;
    if (!isset($_POST['ct'])) {
        return false;
    }
    $data = $_POST['ct'];
    $update = false;
    // Sanitize data
    if (isset($data['wpcf-post-type'])) {
        $update = true;
        $data['wpcf-post-type'] = sanitize_title($data['wpcf-post-type']);
    } else {
        $data['wpcf-post-type'] = null;
    }
    if (isset($data['slug'])) {
        $data['slug'] = sanitize_title($data['slug']);
    } else {
        $data['slug'] = null;
    }
    if (isset($data['rewrite']['slug'])) {
        $data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
        $data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
        $data['rewrite']['slug'] = trim($data['rewrite']['slug']);
    }
    // Set post type name
    $post_type = null;
    if (!empty($data['slug'])) {
        $post_type = $data['slug'];
    } elseif (!empty($data['wpcf-post-type'])) {
        $post_type = $data['wpcf-post-type'];
    } elseif (!empty($data['labels']['singular_name'])) {
        $post_type = sanitize_title($data['labels']['singular_name']);
    }
    if (empty($post_type)) {
        wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
        return false;
    }
    $data['slug'] = $post_type;
    $custom_types = get_option('wpcf-custom-types', array());
    // Check reserved name
    $reserved = wpcf_is_reserved_name($post_type, 'post_type');
    if (is_wp_error($reserved)) {
        wpcf_admin_message($reserved->get_error_message(), 'error');
        return false;
    }
    // Check overwriting
    if ((!array_key_exists('wpcf-post-type', $data) || $data['wpcf-post-type'] != $post_type) && array_key_exists($post_type, $custom_types)) {
        wpcf_admin_message(__('Custom post type already exists', 'wpcf'), 'error');
        return false;
    }
    /*
     * Since Types 1.2
     * We do not allow plural and singular names to be same.
     */
    if ($wpcf->post_types->check_singular_plural_match($data)) {
        wpcf_admin_message($wpcf->post_types->message('warning_singular_plural_match'), 'error');
        return false;
    }
    // Check if renaming then rename all post entries and delete old type
    if (!empty($data['wpcf-post-type']) && $data['wpcf-post-type'] != $post_type) {
        global $wpdb;
        $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data['wpcf-post-type']), array('%s'), array('%s'));
        /**
         * update post meta "_wp_types_group_post_types"
         */
        $sql = sprintf('select meta_id, meta_value from %s where meta_key = \'%s\'', $wpdb->postmeta, '_wp_types_group_post_types');
        $all_meta = $wpdb->get_results($sql, OBJECT_K);
        $re = sprintf('/,%s,/', $data['wpcf-post-type']);
        foreach ($all_meta as $meta) {
            if (!preg_match($re, $meta->meta_value)) {
                continue;
            }
            $wpdb->update($wpdb->postmeta, array('meta_value' => preg_replace($re, ',' . $post_type . ',', $meta->meta_value)), array('meta_id' => $meta->meta_id), array('%s'), array('%d'));
        }
        /**
         * update _wpcf_belongs_{$data['wpcf-post-type']}_id
         */
        $wpdb->update($wpdb->postmeta, array('meta_key' => sprintf('_wpcf_belongs_%s_id', $post_type)), array('meta_key' => sprintf('_wpcf_belongs_%s_id', $data['wpcf-post-type'])), array('%s'), array('%s'));
        /**
         * update options "wpv_options"
         */
        $wpv_options = get_option('wpv_options', true);
        if (is_array($wpv_options)) {
            $re = sprintf('/(views_template_(archive_)?for_)%s/', $data['wpcf-post-type']);
            foreach ($wpv_options as $key => $value) {
                if (!preg_match($re, $key)) {
                    continue;
                }
                unset($wpv_options[$key]);
                $key = preg_replace($re, "\$1" . $post_type, $key);
                $wpv_options[$key] = $value;
            }
            update_option('wpv_options', $wpv_options);
        }
        /**
         * update option "wpcf-custom-taxonomies"
         */
        $wpcf_custom_taxonomies = get_option('wpcf-custom-taxonomies', true);
        if (is_array($wpcf_custom_taxonomies)) {
            $update_wpcf_custom_taxonomies = false;
            foreach ($wpcf_custom_taxonomies as $key => $value) {
                if (array_key_exists('supports', $value) && array_key_exists($data['wpcf-post-type'], $value['supports'])) {
                    unset($wpcf_custom_taxonomies[$key]['supports'][$data['wpcf-post-type']]);
                    $update_wpcf_custom_taxonomies = true;
                }
            }
            if ($update_wpcf_custom_taxonomies) {
                update_option('wpcf-custom-taxonomies', $wpcf_custom_taxonomies);
            }
        }
        // Sync action
        do_action('wpcf_post_type_renamed', $post_type, $data['wpcf-post-type']);
        // Set protected data
        $protected_data_check = $custom_types[$data['wpcf-post-type']];
        // Delete old type
        unset($custom_types[$data['wpcf-post-type']]);
        $data['wpcf-post-type'] = $post_type;
    } else {
        // Set protected data
        $protected_data_check = !empty($custom_types[$post_type]) ? $custom_types[$post_type] : array();
    }
    // Check if active
    if (isset($custom_types[$post_type]['disabled'])) {
        $data['disabled'] = $custom_types[$post_type]['disabled'];
    }
    // Sync taxes with custom taxes
    if (!empty($data['taxonomies'])) {
        $taxes = get_option('wpcf-custom-taxonomies', array());
        foreach ($taxes as $id => $tax) {
            if (array_key_exists($id, $data['taxonomies'])) {
                $taxes[$id]['supports'][$data['slug']] = 1;
            } else {
                unset($taxes[$id]['supports'][$data['slug']]);
            }
        }
        update_option('wpcf-custom-taxonomies', $taxes);
    }
    // Preserve protected data
    foreach ($protected_data_check as $key => $value) {
        if (strpos($key, '_') !== 0) {
            unset($protected_data_check[$key]);
        }
    }
    // Merging protected data
    $custom_types[$post_type] = array_merge($protected_data_check, $data);
    update_option('wpcf-custom-types', $custom_types);
    // WPML register strings
    wpcf_custom_types_register_translation($post_type, $data);
    wpcf_admin_message_store(apply_filters('types_message_custom_post_type_saved', __('Custom post type saved', 'wpcf'), $data, $update), 'custom');
    // Flush rewrite rules
    flush_rewrite_rules();
    do_action('wpcf_custom_types_save', $data);
    // Redirect
    wp_redirect(add_query_arg(array('page' => 'wpcf-edit-type', 'wpcf-post-type' => $post_type, 'wpcf-rewrite' => 1, 'wpcf-message' => 'view'), admin_url('admin.php')));
    die;
}
 /**
  * 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()
 {
     global $wpcf;
     if (!isset($_POST['ct'])) {
         return false;
     }
     $data = $_POST['ct'];
     $update = false;
     // Sanitize data
     if (isset($data[$this->get_id])) {
         $update = true;
         $data[$this->get_id] = sanitize_title($data[$this->get_id]);
     } else {
         $data[$this->get_id] = null;
     }
     if (isset($data['slug'])) {
         $data['slug'] = sanitize_title($data['slug']);
     } elseif ($_GET['wpcf-post-type'] == 'post' || $_GET['wpcf-post-type'] == 'page' || $_GET['wpcf-post-type'] == 'attachment') {
         $data['slug'] = $_GET['wpcf-post-type'];
     } else {
         $data['slug'] = null;
     }
     if (isset($data['rewrite']['slug'])) {
         $data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
         $data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
         $data['rewrite']['slug'] = trim($data['rewrite']['slug']);
     }
     $data['_builtin'] = false;
     // Set post type name
     $post_type = null;
     if (!empty($data['slug'])) {
         $post_type = $data['slug'];
     } elseif (!empty($data[$this->get_id])) {
         $post_type = $data[$this->get_id];
     } elseif (!empty($data['labels']['singular_name'])) {
         $post_type = sanitize_title($data['labels']['singular_name']);
     }
     if (empty($post_type)) {
         wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
         return false;
     }
     $data['slug'] = $post_type;
     $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
     $protected_data_check = array();
     if (wpcf_is_builtin_post_types($data['slug'])) {
         $data['_builtin'] = true;
         $update = true;
     } else {
         // Check reserved name
         $reserved = wpcf_is_reserved_name($post_type, 'post_type');
         if (is_wp_error($reserved)) {
             wpcf_admin_message($reserved->get_error_message(), 'error');
             return false;
         }
         // Check overwriting
         if ((!array_key_exists($this->get_id, $data) || $data[$this->get_id] != $post_type) && array_key_exists($post_type, $custom_types)) {
             wpcf_admin_message(__('Post Type already exists', 'wpcf'), 'error');
             return false;
         }
         /*
          * Since Types 1.2
          * We do not allow plural and singular names to be same.
          */
         if ($wpcf->post_types->check_singular_plural_match($data)) {
             wpcf_admin_message($wpcf->post_types->message('warning_singular_plural_match'), 'error');
             return false;
         }
         // Check if renaming then rename all post entries and delete old type
         if (!empty($data[$this->get_id]) && $data[$this->get_id] != $post_type) {
             global $wpdb;
             $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data[$this->get_id]), array('%s'), array('%s'));
             /**
              * update post meta "_wp_types_group_post_types"
              */
             $sql = $wpdb->prepare(sprintf('select meta_id, meta_value from %s where meta_key = %%s', $wpdb->postmeta), '_wp_types_group_post_types');
             $all_meta = $wpdb->get_results($sql, OBJECT_K);
             $re = sprintf('/,%s,/', $data[$this->get_id]);
             foreach ($all_meta as $meta) {
                 if (!preg_match($re, $meta->meta_value)) {
                     continue;
                 }
                 $wpdb->update($wpdb->postmeta, array('meta_value' => preg_replace($re, ',' . $post_type . ',', $meta->meta_value)), array('meta_id' => $meta->meta_id), array('%s'), array('%d'));
             }
             /**
              * update _wpcf_belongs_{$data[$this->get_id]}_id
              */
             $wpdb->update($wpdb->postmeta, array('meta_key' => sprintf('_wpcf_belongs_%s_id', $post_type)), array('meta_key' => sprintf('_wpcf_belongs_%s_id', $data[$this->get_id])), array('%s'), array('%s'));
             /**
              * update options "wpv_options"
              */
             $wpv_options = get_option('wpv_options', true);
             if (is_array($wpv_options)) {
                 $re = sprintf('/(views_template_(archive_)?for_)%s/', $data[$this->get_id]);
                 foreach ($wpv_options as $key => $value) {
                     if (!preg_match($re, $key)) {
                         continue;
                     }
                     unset($wpv_options[$key]);
                     $key = preg_replace($re, "\$1" . $post_type, $key);
                     $wpv_options[$key] = $value;
                 }
                 update_option('wpv_options', $wpv_options);
             }
             /**
              * update option "wpcf-custom-taxonomies"
              */
             $wpcf_custom_taxonomies = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, true);
             if (is_array($wpcf_custom_taxonomies)) {
                 $update_wpcf_custom_taxonomies = false;
                 foreach ($wpcf_custom_taxonomies as $key => $value) {
                     if (array_key_exists('supports', $value) && array_key_exists($data[$this->get_id], $value['supports'])) {
                         unset($wpcf_custom_taxonomies[$key]['supports'][$data[$this->get_id]]);
                         $update_wpcf_custom_taxonomies = true;
                     }
                 }
                 if ($update_wpcf_custom_taxonomies) {
                     update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $wpcf_custom_taxonomies);
                 }
             }
             // Sync action
             do_action('wpcf_post_type_renamed', $post_type, $data[$this->get_id]);
             // Set protected data
             $protected_data_check = $custom_types[$data[$this->get_id]];
             // Delete old type
             unset($custom_types[$data[$this->get_id]]);
             $data[$this->get_id] = $post_type;
         } else {
             // Set protected data
             $protected_data_check = !empty($custom_types[$post_type]) ? $custom_types[$post_type] : array();
         }
         // Check if active
         if (isset($custom_types[$post_type]['disabled'])) {
             $data['disabled'] = $custom_types[$post_type]['disabled'];
         }
     }
     // Sync taxes with custom taxes
     $taxes = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array());
     foreach ($taxes as $id => $tax) {
         if (isset($data['taxonomies']) && !empty($data['taxonomies']) && array_key_exists($id, $data['taxonomies'])) {
             $taxes[$id]['supports'][$data['slug']] = 1;
         } else {
             if (isset($taxes[$id]['supports'][$data['slug']])) {
                 unset($taxes[$id]['supports'][$data['slug']]);
             }
         }
     }
     update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $taxes);
     // Preserve protected data
     foreach ($protected_data_check as $key => $value) {
         if (strpos($key, '_') !== 0) {
             unset($protected_data_check[$key]);
         }
     }
     /**
      * save custom field group
      */
     /* removed types-608
        $post_to_groups = isset($_POST['ct']['custom-field-group'])?$_POST['ct']['custom-field-group']:array();
        $groups = $this->fields->get_groups_with_post_types();
        foreach( $groups as $group) {
            $post_types_to_save = $group['_wp_types_group_post_types'];
            // save
            if ( array_key_exists($group['id'], $post_to_groups)) {
                $post_types_to_save[] = $data['slug'];
            } else {
                if(($key = array_search($data['slug'], $post_types_to_save)) !== false) {
                    unset($post_types_to_save[$key]);
                }
                if (
                    false
                    || empty($post_types_to_save)
                    || (
                        true
                        && 1 == sizeof($post_types_to_save)
                        && 'all' == current($post_types_to_save)
                    )
                ) {
                    $post_types_to_save = array();
                    foreach( get_post_types() as $key => $value ) {
                        if ( $data['slug'] == $value) {
                            continue;
                        }
                        if ( in_array($value, $wpcf->excluded_post_types) ) {
                            continue;
                        }
                        $post_types_to_save[] = $value;
                    }
                }
            }
            wpcf_admin_fields_save_group_post_types($group['id'], $post_types_to_save);
        }
        */
     /**
      * set last edit time
      */
     $data[TOOLSET_EDIT_LAST] = time();
     /**
      * set last edit author
      */
     $data[WPCF_AUTHOR] = get_current_user_id();
     /**
      * add builid in
      */
     if ($data['_builtin'] && !isset($protected_data_check[$data['slug']])) {
         $protected_data_check[$data['slug']] = array();
     }
     // Merging protected data
     $custom_types[$post_type] = array_merge($protected_data_check, $data);
     update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $custom_types);
     // WPML register strings
     if (!$data['_builtin']) {
         wpcf_custom_types_register_translation($post_type, $data);
     }
     // success message
     $msg = $update ? __('Post Type saved.', 'wpcf') : __('New Post Type created.', 'wpcf');
     wpcf_admin_message_store($msg, 'updated notice notice-success is-dismissible');
     flush_rewrite_rules();
     if (!$data['_builtin']) {
         do_action('wpcf_custom_types_save', $data);
     }
     // Redirect
     wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => 'wpcf-edit-type', $this->get_id => $post_type, 'wpcf-message' => 'view', 'flush' => '1'), admin_url('admin.php'))));
     die;
 }
Пример #5
0
/**
 * Submit function
 */
function wpcf_admin_custom_types_form_submit($form)
{
    if (!isset($_POST['ct'])) {
        return false;
    }
    $data = $_POST['ct'];
    $update = false;
    // Sanitize data
    if (isset($data['wpcf-post-type'])) {
        $update = true;
        $data['wpcf-post-type'] = sanitize_title($data['wpcf-post-type']);
    }
    if (isset($data['slug'])) {
        $data['slug'] = sanitize_title($data['slug']);
    }
    if (isset($data['rewrite']['slug'])) {
        $data['rewrite']['slug'] = remove_accents($data['rewrite']['slug']);
        $data['rewrite']['slug'] = strtolower($data['rewrite']['slug']);
        $data['rewrite']['slug'] = trim($data['rewrite']['slug']);
    }
    // Set post type name
    $post_type = '';
    if (!empty($data['slug'])) {
        $post_type = $data['slug'];
    } else {
        if (!empty($data['wpcf-post-type'])) {
            $post_type = $data['wpcf-post-type'];
        } else {
            if (!empty($data['labels']['singular_name'])) {
                $post_type = sanitize_title($data['labels']['singular_name']);
            }
        }
    }
    if (empty($post_type)) {
        wpcf_admin_message(__('Please set post type name', 'wpcf'), 'error');
        //        $form->triggerError();
        return false;
    }
    $data['slug'] = $post_type;
    $custom_types = get_option('wpcf-custom-types', array());
    // Check overwriting
    if (!$update && array_key_exists($post_type, $custom_types)) {
        wpcf_admin_message(__('Custom post type already exists', 'wpcf'), 'error');
        //            $form->triggerError();
        return false;
    }
    // Check if renaming then rename all post entries and delete old type
    if (!empty($data['wpcf-post-type']) && $data['wpcf-post-type'] != $post_type) {
        global $wpdb;
        $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('post_type' => $data['wpcf-post-type']), array('%s'), array('%s'));
        // Delete old type
        unset($custom_types[$data['wpcf-post-type']]);
    }
    // Check if active
    if (isset($custom_types[$post_type]['disabled'])) {
        $data['disabled'] = $custom_types[$post_type]['disabled'];
    }
    // Sync taxes with custom taxes
    if (!empty($data['taxonomies'])) {
        $taxes = get_option('wpcf-custom-taxonomies', array());
        foreach ($taxes as $id => $tax) {
            if (array_key_exists($id, $data['taxonomies'])) {
                $taxes[$id]['supports'][$data['slug']] = 1;
            } else {
                unset($taxes[$id]['supports'][$data['slug']]);
            }
        }
        update_option('wpcf-custom-taxonomies', $taxes);
    }
    $custom_types[$post_type] = $data;
    update_option('wpcf-custom-types', $custom_types);
    // WPML register strings
    wpcf_custom_types_register_translation($post_type, $data);
    wpcf_admin_message_store(__('Custom post type saved', 'wpcf'));
    // Flush rewrite rules
    flush_rewrite_rules();
    do_action('wpcf_custom_types_save', $data);
    // Redirect
    wp_redirect(admin_url('admin.php?page=wpcf-edit-type&wpcf-post-type=' . $post_type . '&wpcf-rewrite=1'));
    die;
}