/** * @inheritdoc * * @param array $arguments */ public function process_call($arguments) { $am = $this->get_am(); $am->ajax_begin(array('nonce' => $am->get_action_js_name(Types_Ajax::CALLBACK_SETTINGS_ACTION))); $setting = sanitize_text_field(wpcf_getpost('setting')); $setting_value = wpcf_getpost('setting_value'); if (!is_array($setting_value)) { parse_str($setting_value, $setting_value); $setting_value = array_pop($setting_value); } $sanitized_value = array(); foreach ($setting_value as $key => $value) { $sanitized_key = sanitize_title($key); $sanitized_value[$sanitized_key] = sanitize_text_field($value); } // use toolset settings if available if (class_exists('Toolset_Settings') && method_exists('Toolset_Settings', 'get_instance')) { $toolset_settings = Toolset_Settings::get_instance(); if (method_exists($toolset_settings, 'save')) { $toolset_settings[$setting] = $sanitized_value; $toolset_settings->save(); $am->ajax_finish('success', true); } } else { update_option($setting, $sanitized_value); $am->ajax_finish('success', true); } // default toolset setting error will be used // todo throw specific error $am->ajax_finish(array('error'), false); }
/** * @inheritdoc * * todo document * * @param array $arguments */ public function process_call($arguments) { $am = $this->get_am(); $am->ajax_begin(array('nonce' => $am->get_action_js_name(Types_Ajax::CALLBACK_FIELD_CONTROL_ACTION))); // Read and validate input $field_action = sanitize_text_field(wpcf_getpost('field_action')); $fields = wpcf_getpost('fields'); // array of values, will be sanitized when processed $current_domain = wpcf_getpost('domain', null, Types_Field_Utils::get_domains()); if (null == $current_domain) { $am->ajax_finish(array('message' => __('Wrong field domain.', 'wpcf')), false); } if (!is_array($fields) || empty($fields)) { $am->ajax_finish(array('message' => __('No fields have been selected.', 'wpcf')), false); } // will be sanitized when/if used by the action-specific method $action_specific_data = wpcf_getpost('action_specific', array()); // Process fields one by one $errors = array(); $results = array(); foreach ($fields as $field) { $result = $this->single_field_control_action($field_action, $field, $current_domain, $action_specific_data); if (is_array($result)) { // Array of errors $errors = array_merge($errors, $result); } else { if ($result instanceof WP_Error) { // Single error $errors[] = $result; } else { if (false == $result) { // This should not happen...! $errors[] = new WP_Error(0, __('An unexpected error happened while processing the request.', 'wpcf')); } else { // Success // Save the field definition model as a result if we got a whole definition if ($result instanceof WPCF_Field_Definition) { $result = $result->to_json(); } $results[wpcf_getarr($field, 'slug')] = $result; } } } } $data = array('results' => $results); $is_success = empty($errors); if (!$is_success) { $error_messages = array(); /** @var WP_Error $error */ foreach ($errors as $error) { $error_messages[] = $error->get_error_message(); } $data['messages'] = $error_messages; } $am->ajax_finish($data, $is_success); }
/** * Read the field values from $_POST. * * @return array Values in the "intermediate" format (see WPCF_Field_DataMapper_Abstract). For non-repetitive values, * it will be an array with a single item. */ private function read_field_values() { if (null == $this->field_values) { $definition = $this->field->get_definition(); $form_data = wpcf_ensarr(wpcf_getpost('wpcf')); $values = wpcf_getarr($form_data, $definition->get_slug()); // Handle single fields. if (!$definition->get_is_repetitive()) { $values = array($values); } // Map POST values to intermediate format. $this->field_values = array(); $data_mapper = $definition->get_data_mapper(); foreach ($values as $value) { $this->field_values[] = $data_mapper->post_to_intermediate($value, $form_data); } } return wpcf_ensarr($this->field_values); }
/** * todo document * @param array $arguments Original action arguments. * @return void */ function process_call($arguments) { $this->ajax_begin(array('nonce' => Types_Ajax::CALLBACK_CHECK_SLUG_CONFLICTS)); // Read and validate input $domains = wpcf_getpost('domains'); $value = wpcf_getpost('value'); $exclude = wpcf_getpost('exclude'); $exclude_id = wpcf_getarr($exclude, 'id', 0); $exclude_domain = wpcf_getarr($exclude, 'domain'); $diff_domains = array_diff($domains, self::$supported_domains); if (!is_array($domains) || !empty($diff_domains) || !is_string($value) || !is_array($exclude) || 0 === $exclude_id || !in_array($exclude_domain, self::$supported_domains)) { $this->ajax_finish(array(), false); } $conflict = $this->check_slug_conflicts($value, $domains, $exclude_domain, $exclude_id); // Parse output (report a conflict if there is any) if (false === $conflict) { $this->ajax_finish(array('isConflict' => false), true); } else { $message = sprintf('<strong>%s</strong>: %s', __('Warning', 'wpcf'), wpcf_getarr($conflict, 'message')); $this->ajax_finish(array('isConflict' => true, 'displayMessage' => $message), true); } }
function process_bulk_action() { global $wpdb; $action = $this->current_action(); if (empty($action)) { return; } $nonce = wpcf_getpost('_wpnonce', null); if (!wp_verify_nonce($nonce, WPCF_Page_Listing_Termmeta::BULK_ACTION_NONCE)) { die('Security check'); } $selected_field_group_ids = wpcf_getpost(self::BULK_ACTION_FIELD_NAME, array()); if (empty($selected_field_group_ids)) { return; } foreach ($selected_field_group_ids as $field_group_id) { if (!WPCF_Roles::user_can_edit('term-field', array('id' => $field_group_id))) { continue; } switch ($action) { case 'delete': $wpdb->delete($wpdb->posts, array('ID' => $field_group_id, 'post_type' => WPCF_Field_Group_Term::POST_TYPE), array('%d', '%s')); break; case 'deactivate': $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $field_group_id, 'post_type' => WPCF_Field_Group_Term::POST_TYPE), array('%s'), array('%d', '%s')); break; case 'activate': $wpdb->update($wpdb->posts, array('post_status' => 'publish'), array('ID' => $field_group_id), array('%s'), array('%d')); break; } } wp_cache_delete(md5('group::_get_group' . WPCF_Field_Group_Term::POST_TYPE), 'types_cache_groups'); }
/** * Initialize admin pages. * * @todo This, also, needs a review very badly. * @since 1.9 */ function wpcf_init_admin_pages() { if (is_admin()) { WPCF_Page_Listing_Termmeta::get_instance(); } if (defined('DOING_AJAX')) { $action = wpcf_getpost('action'); $current_page = wpcf_getpost('page'); switch ($action) { case 'wpcf_edit_field_select': case 'wpcf_ajax_filter': if (WPCF_Page_Edit_Termmeta::PAGE_NAME == $current_page) { WPCF_Page_Edit_Termmeta::get_instance()->initialize_ajax_handler(); } break; } } }
private function read_group_ids() { $group_ids = wpcf_getpost('wpcf-id'); if (!is_string($group_ids) || empty($group_ids)) { return array(); } return explode(',', $group_ids); }
/** * 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 field_insert() { /** * check nonce */ if (0 || !isset($_REQUEST['_wpnonce']) || !isset($_REQUEST['type']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'fields_insert')) { $this->verification_failed_and_die(); } // We need to determine the field's meta_type because that will be eventually // passed through the wpcf_form_field filter in get_field_from_data(). // // This information is required by the Relevanssi integration. $field_kind = wpcf_getpost('field_kind', 'wpcf-postmeta', array('wpcf-postmeta', 'wpcf-usermeta', 'wpcf-termmeta')); $faux_form_data = array('meta_type' => substr($field_kind, 5)); $enlimbo_form = $this->get_field_form_data($_REQUEST['type'], $faux_form_data); echo wpcf_form_simple($enlimbo_form); die; }
/** * Imports data from XML. * * @param string $data * @param bool $redirect * @param string $context * @param array $args * * @return array */ function wpcf_admin_import_data($data = '', $redirect = true, $context = 'types', $args = array()) { global $wpdb; $data_installer = false; $return = array(); libxml_use_internal_errors(true); $data = simplexml_load_string($data); if (!$data) { $return[] = array('type' => 'error', 'content' => __('Error parsing XML: ', 'wpcf') . $error->message); libxml_clear_errors(); return $return; } $overwrite_settings = isset($_POST['overwrite-settings']); $overwrite_groups = isset($_POST['overwrite-groups']); $overwrite_fields = isset($_POST['overwrite-fields']); $overwrite_types = isset($_POST['overwrite-types']); $overwrite_tax = isset($_POST['overwrite-tax']); $delete_groups = isset($_POST['delete-groups']); $delete_fields = isset($_POST['delete-fields']); $delete_types = isset($_POST['delete-types']); $delete_tax = isset($_POST['delete-tax']); if ('wpvdemo' == $context && !empty($args)) { /** * allow overwrite */ $overwrite_groups = true; $overwrite_fields = true; $overwrite_types = true; $overwrite_tax = true; include_once dirname(__FILE__) . '/classes/class.types.data.installer.php'; $data_installer = new Types_Data_Installer($data, $args); $data = $data_installer->wpvdemo(); } /** * process settings */ if ($overwrite_settings && isset($data->settings)) { $wpcf_settings = wpcf_get_settings(); foreach (wpcf_admin_import_export_simplexml2array($data->settings) as $key => $value) { $wpcf_settings[$key] = $value; } wpcf_save_settings($wpcf_settings); $return[] = array('type' => 'success', 'content' => __('Settings are updated.', 'wpcf')); } // Process groups $groups_check = array(); if (!empty($data->groups)) { $groups = array(); // Set insert data from XML foreach ($data->groups->group as $group) { $group = wpcf_admin_import_export_simplexml2array($group); $groups[$group['ID']] = $group; } // Set insert data from POST if (!empty($_POST['groups'])) { foreach ($_POST['groups'] as $group_id => $group) { if (empty($groups[$group_id])) { continue; } $groups[$group_id]['add'] = !empty($group['add']); $groups[$group_id]['update'] = isset($group['update']) && $group['update'] == 'update' ? true : false; } } else { foreach ($groups as $group_id => $group) { $groups[$group_id]['add'] = true; $groups[$group_id]['update'] = false; } } // Insert groups $show_import_fail_version_message = true; foreach ($groups as $group_id => $group) { $post = array('post_status' => $group['post_status'], 'post_type' => TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'post_title' => $group['post_title'], 'post_content' => !empty($group['post_content']) ? $group['post_content'] : ''); /** * preserve slug */ if (array_key_exists('__types_id', $group)) { $post['post_name'] = $group['__types_id']; } if (isset($group['add']) && $group['add']) { $post_to_update = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = %s", $group['post_title'], TYPES_CUSTOM_FIELD_GROUP_CPT_NAME)); // Update (may be forced by bulk action) if ($group['update'] || $overwrite_groups && !empty($post_to_update)) { if (!empty($post_to_update)) { $post['ID'] = $post_to_update; $group_wp_id = wp_update_post($post); if (!$group_wp_id) { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" update failed', 'wpcf'), $group['post_title'])); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('Group "%s" updated', 'wpcf'), $group['post_title'])); } } else { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" update failed', 'wpcf'), $group['post_title'])); } } else { // Insert $group_wp_id = wp_insert_post($post, true); if (is_wp_error($group_wp_id)) { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" insert failed', 'wpcf'), $group['post_title'])); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('Group "%s" added', 'wpcf'), $group['post_title'])); } } // Update meta if (!empty($group['meta'])) { foreach ($group['meta'] as $meta_key => $meta_value) { if ('_wpcf_conditional_display' == $meta_key) { if (!empty($meta_value)) { $meta_value = wpcf_admin_import_export_simplexml2array($meta_value); if (!is_array($meta_value)) { $meta_value = array(); if ($show_import_fail_version_message) { $show_import_fail_version_message = false; $return[] = array('type' => 'error', 'content' => __('The Types settings were not fully imported because it contained unsecured data. You should re-export your Types settings using the latest version of Types', 'wpcf')); } } } } update_post_meta($group_wp_id, $meta_key, $meta_value); } } $groups_check[] = $group_wp_id; if (!empty($post_to_update)) { $groups_check[] = $post_to_update; } } } // Delete groups (forced, set in bulk actions) } if ($delete_groups) { $groups_to_delete = get_posts(array('post_type' => TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'post_status' => 'any', 'posts_per_page' => -1)); if (!empty($groups_to_delete)) { foreach ($groups_to_delete as $group_to_delete) { if (!in_array($group_to_delete->ID, $groups_check)) { $deleted = wp_delete_post($group_to_delete->ID, true); if (!$deleted) { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" delete failed', 'wpcf'), $group_to_delete->post_title)); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('Group "%s" deleted', 'wpcf'), $group_to_delete->post_title)); } } } } } else { // If not forced, look in POST if (!empty($_POST['groups-to-be-deleted'])) { foreach ($_POST['groups-to-be-deleted'] as $group_to_delete) { $group_to_delete_post = get_post($group_to_delete); if (!empty($group_to_delete_post) && $group_to_delete_post->post_type == TYPES_CUSTOM_FIELD_GROUP_CPT_NAME) { $deleted = wp_delete_post($group_to_delete, true); if (!$deleted) { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" delete failed', 'wpcf'), $group_to_delete_post->post_title)); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('Group "%s" deleted', 'wpcf'), $group_to_delete_post->post_title)); } } else { $return[] = array('type' => 'error', 'content' => sprintf(__('Group "%s" delete failed', 'wpcf'), $group_to_delete)); } } } } // Process fields $fields_check = array(); $fields_existing = wpcf_admin_fields_get_fields(); if (!empty($data->fields)) { $fields = array(); // Set insert data from XML foreach ($data->fields->field as $field) { $field = wpcf_admin_import_export_simplexml2array($field); // Set if submitted in 'types' context if ($context == 'types') { // Process only if marked if (isset($_POST['fields'][$field['id']])) { $fields[$field['id']] = $field; } } else { $fields[$field['id']] = $field; } } // Set insert data from POST if (!empty($_POST['fields'])) { foreach ($_POST['fields'] as $field_id => $field) { if (empty($fields[$field_id])) { continue; } $fields[$field_id]['add'] = !empty($field['add']); $fields[$field_id]['update'] = isset($field['update']) && $field['update'] == 'update' ? true : false; } } // Insert fields foreach ($fields as $field_id => $field) { if (isset($field['add']) && !$field['add'] && !$overwrite_fields) { continue; } if (empty($field['id']) || empty($field['name']) || empty($field['slug'])) { continue; } $field_data = array(); $field_data['description'] = isset($field['description']) ? $field['description'] : ''; $field_data['data'] = isset($field['data']) && is_array($field['data']) ? $field['data'] : array(); foreach (array('id', 'name', 'type', 'slug', 'meta_key', 'meta_type') as $key) { if (array_key_exists($key, $field)) { $field_data[$key] = $field[$key]; } } $fields_existing[$field_id] = $field_data; $fields_check[] = $field_id; // WPML global $iclTranslationManagement; if (!empty($iclTranslationManagement) && isset($field['wpml_action'])) { $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id] = $field['wpml_action']; $iclTranslationManagement->save_settings(); } $return[] = array('type' => 'success', 'content' => sprintf(__('Field "%s" added/updated', 'wpcf'), $field['name'])); } } // Delete fields if ($delete_fields) { foreach ($fields_existing as $k => $v) { if (!empty($v['data']['controlled'])) { continue; } if (!in_array($k, $fields_check)) { $return[] = array('type' => 'success', 'content' => sprintf(__('Field "%s" deleted', 'wpcf'), $fields_existing[$k]['name'])); unset($fields_existing[$k]); } } } else { if (!empty($_POST['fields-to-be-deleted'])) { foreach ($_POST['fields-to-be-deleted'] as $field_to_delete) { $return[] = array('type' => 'success', 'content' => sprintf(__('Field "%s" deleted', 'wpcf'), $fields_existing[$field_to_delete]['name'])); unset($fields_existing[$field_to_delete]); } } } update_option('wpcf-fields', $fields_existing); // Process user groups //print_r($data->user_groups);exit; $groups_check = array(); if (!empty($data->user_groups) && isset($data->user_groups->group)) { $groups = array(); // Set insert data from XML foreach ($data->user_groups->group as $group) { $group = wpcf_admin_import_export_simplexml2array($group); $groups[$group['ID']] = $group; } // Set insert data from POST if (!empty($_POST['user_groups'])) { foreach ($_POST['user_groups'] as $group_id => $group) { if (empty($groups[$group_id])) { continue; } $groups[$group_id]['add'] = !empty($group['add']); $groups[$group_id]['update'] = isset($group['update']) && $group['update'] == 'update' ? true : false; } } else { foreach ($groups as $group_id => $group) { $groups[$group_id]['add'] = true; $groups[$group_id]['update'] = false; } } // Insert groups foreach ($groups as $group_id => $group) { $post = array('post_status' => $group['post_status'], 'post_type' => TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'post_title' => $group['post_title'], 'post_content' => !empty($group['post_content']) ? $group['post_content'] : ''); if (isset($group['add']) && $group['add']) { $post_to_update = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = %s", $group['post_title'], TYPES_USER_META_FIELD_GROUP_CPT_NAME)); // Update (may be forced by bulk action) if ($group['update'] || $overwrite_groups && !empty($post_to_update)) { if (!empty($post_to_update)) { $post['ID'] = $post_to_update; $group_wp_id = wp_update_post($post); if (!$group_wp_id) { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" update failed', 'wpcf'), $group['post_title'])); } else { /* wpcf_admin_message_store( sprintf( __( 'User group "%s" updated', 'wpcf' ), $group['post_title'] ) ); */ $return[] = array('type' => 'success', 'content' => sprintf(__('User group "%s" updated', 'wpcf'), $group['post_title'])); } } else { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" update failed', 'wpcf'), $group['post_title'])); } } else { // Insert $group_wp_id = wp_insert_post($post, true); if (is_wp_error($group_wp_id)) { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" insert failed', 'wpcf'), $group['post_title'])); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('User group "%s" added', 'wpcf'), $group['post_title'])); } } // Update meta if (!empty($group['meta'])) { foreach ($group['meta'] as $meta_key => $meta_value) { update_post_meta($group_wp_id, $meta_key, wpcf_admin_import_export_simplexml2array($meta_value)); } } $groups_check[] = $group_wp_id; if (!empty($post_to_update)) { $groups_check[] = $post_to_update; } } } } // Delete groups (forced, set in bulk actions) if ($delete_groups) { $groups_to_delete = get_posts(array('post_type' => TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'post_status' => 'any', 'posts_per_page' => -1)); if (!empty($groups_to_delete)) { foreach ($groups_to_delete as $group_to_delete) { if (!in_array($group_to_delete->ID, $groups_check)) { $deleted = wp_delete_post($group_to_delete->ID, true); if (!$deleted) { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" delete failed', 'wpcf'), $group_to_delete->post_title)); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('User group "%s" deleted', 'wpcf'), $group_to_delete->post_title)); } } } } } else { // If not forced, look in POST if (!empty($_POST['user-groups-to-be-deleted'])) { foreach ($_POST['user-groups-to-be-deleted'] as $group_to_delete) { $group_to_delete_post = get_post($group_to_delete); if (!empty($group_to_delete_post) && $group_to_delete_post->post_type == TYPES_USER_META_FIELD_GROUP_CPT_NAME) { $deleted = wp_delete_post($group_to_delete, true); if (!$deleted) { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" delete failed', 'wpcf'), $group_to_delete_post->post_title)); } else { $return[] = array('type' => 'success', 'content' => sprintf(__('User group "%s" deleted', 'wpcf'), $group_to_delete_post->post_title)); } } else { $return[] = array('type' => 'error', 'content' => sprintf(__('User group "%s" delete failed', 'wpcf'), $group_to_delete)); } } } } // Process fields $fields_existing = wpcf_admin_fields_get_fields(false, false, false, 'wpcf-usermeta'); $fields_check = array(); if (!empty($data->user_fields)) { $fields = array(); // Set insert data from XML foreach ($data->user_fields->field as $field) { $field = wpcf_admin_import_export_simplexml2array($field); // Set if submitted in 'types' context if ($context == 'types') { // Process only if marked if (isset($_POST['user_fields'][$field['id']])) { $fields[$field['id']] = $field; } } else { $fields[$field['id']] = $field; } } // Set insert data from POST if (!empty($_POST['user_fields'])) { foreach ($_POST['user_fields'] as $field_id => $field) { if (empty($fields[$field_id])) { continue; } $fields[$field_id]['add'] = !empty($field['add']); $fields[$field_id]['update'] = isset($field['update']) && $field['update'] == 'update' ? true : false; } } // Insert fields foreach ($fields as $field_id => $field) { if (isset($field['add']) && !$field['add'] && !$overwrite_fields) { continue; } if (empty($field['id']) || empty($field['name']) || empty($field['slug'])) { continue; } $field_data = array(); $field_data['id'] = $field['id']; $field_data['name'] = $field['name']; $field_data['description'] = isset($field['description']) ? $field['description'] : ''; $field_data['type'] = $field['type']; $field_data['slug'] = $field['slug']; if (isset($field['meta_key'])) { $field_data['meta_key'] = $field['meta_key']; } $field_data['data'] = isset($field['data']) && is_array($field['data']) ? $field['data'] : array(); $fields_existing[$field_id] = $field_data; $fields_check[] = $field_id; // WPML global $iclTranslationManagement; if (!empty($iclTranslationManagement) && isset($field['wpml_action'])) { $iclTranslationManagement->settings['custom_fields_translation'][wpcf_types_get_meta_prefix($field) . $field_id] = $field['wpml_action']; $iclTranslationManagement->save_settings(); } $return[] = array('type' => 'success', 'content' => sprintf(__('User field "%s" added/updated', 'wpcf'), $field['name'])); } } // Delete fields if ($delete_fields) { foreach ($fields_existing as $k => $v) { if (!empty($v['data']['controlled'])) { continue; } if (!in_array($k, $fields_check)) { $return[] = array('type' => 'success', 'content' => sprintf(__('User field "%s" deleted', 'wpcf'), $fields_existing[$k]['name'])); unset($fields_existing[$k]); } } } else { if (!empty($_POST['user-fields-to-be-deleted'])) { foreach ($_POST['user-fields-to-be-deleted'] as $field_to_delete) { $return[] = array('type' => 'success', 'content' => sprintf(__('User field "%s" deleted', 'wpcf'), $fields_existing[$field_to_delete]['name'])); unset($fields_existing[$field_to_delete]); } } } update_option('wpcf-usermeta', $fields_existing); // Handle term field groups and field definitions outside of this mess. $ie_controller = Types_Import_Export::get_instance(); $term_group_results = $ie_controller->process_field_group_import_per_domain(Types_Field_Utils::DOMAIN_TERMS, $data, 'term_groups', $overwrite_groups, $delete_groups, wpcf_ensarr(wpcf_getpost('term_groups'))); $term_field_results = $ie_controller->process_field_definition_import_per_domain(Types_Field_Utils::DOMAIN_TERMS, $data, 'term_fields', $delete_fields, wpcf_ensarr(wpcf_getpost('term_fields'))); $return = array_merge($return, $term_group_results, $term_field_results); // Process types $types_existing = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); $types_check = array(); if (!empty($data->types) && isset($data->types->type)) { $types = array(); // Set insert data from XML foreach ($data->types->type as $type) { $type = wpcf_admin_import_export_simplexml2array($type); // Set if submitted in 'types' context if ($context == 'types') { if (isset($_POST['types'][$type['id']])) { $types[$type['id']] = $type; } } else { $types[$type['id']] = $type; } } // Set insert data from POST if (!empty($_POST['types'])) { foreach ($_POST['types'] as $type_id => $type) { if (empty($types[$type_id])) { continue; } $types[$type_id]['add'] = !empty($type['add']); $types[$type_id]['update'] = isset($type['update']) && $type['update'] == 'update' ? true : false; } } // Insert types foreach ($types as $type_id => $type) { if (isset($type['add']) && !$type['add'] && !$overwrite_types) { continue; } unset($type['add'], $type['update']); $types_existing[$type_id] = $type; $types_check[] = $type_id; $return[] = array('type' => 'success', 'content' => sprintf(__('Post Type "%s" added/updated', 'wpcf'), $type_id)); } } // Delete types if ($delete_types) { foreach ($types_existing as $k => $v) { if (!in_array($k, $types_check)) { unset($types_existing[$k]); $return[] = array('type' => 'success', 'content' => sprintf(__('Post Type "%s" deleted', 'wpcf'), esc_html($k))); } } } else { if (!empty($_POST['types-to-be-deleted'])) { foreach ($_POST['types-to-be-deleted'] as $type_to_delete) { $return[] = array('type' => 'success', 'content' => sprintf(__('Post Type "%s" deleted', 'wpcf'), $types_existing[$type_to_delete]['labels']['name'])); unset($types_existing[$type_to_delete]); } } } update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $types_existing); // Process taxonomies $taxonomies_existing = get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array()); $taxonomies_check = array(); if (!empty($data->taxonomies) && isset($data->taxonomies->taxonomy)) { $taxonomies = array(); // Set insert data from XML foreach ($data->taxonomies->taxonomy as $taxonomy) { $taxonomy = wpcf_admin_import_export_simplexml2array($taxonomy); $taxonomy = apply_filters('wpcf_filter_import_custom_taxonomy', $taxonomy); // Set if submitted in 'types' context if ($context == 'types') { if (isset($_POST['taxonomies'][$taxonomy['id']])) { $taxonomies[$taxonomy['id']] = $taxonomy; } } else { $taxonomies[$taxonomy['id']] = $taxonomy; } } // Set insert data from POST if (!empty($_POST['taxonomies'])) { foreach ($_POST['taxonomies'] as $taxonomy_id => $taxonomy) { if (empty($taxonomies[$taxonomy_id])) { continue; } $taxonomies[$taxonomy_id]['add'] = !empty($taxonomy['add']); $taxonomies[$taxonomy_id]['update'] = isset($taxonomy['update']) && $taxonomy['update'] == 'update' ? true : false; } } // Insert taxonomies foreach ($taxonomies as $taxonomy_id => $taxonomy) { if (isset($taxonomy['add']) && !$taxonomy['add'] && !$overwrite_tax) { continue; } unset($taxonomy['add'], $taxonomy['update']); $taxonomies_existing[$taxonomy_id] = $taxonomy; $taxonomies_check[] = $taxonomy_id; $return[] = array('type' => 'success', 'content' => sprintf(__('Taxonomy "%s" added/updated', 'wpcf'), $taxonomy_id)); } } /** * reset TOOLSET_EDIT_LAST */ if ($data_installer) { $data_installer->reset_toolset_edit_last(); } // Delete taxonomies if ($delete_tax) { foreach ($taxonomies_existing as $k => $v) { if (!in_array($k, $taxonomies_check)) { unset($taxonomies_existing[$k]); $return[] = array('type' => 'success', 'content' => sprintf(__('Taxonomy "%s" deleted', 'wpcf'), $k)); } } } else { if (!empty($_POST['taxonomies-to-be-deleted'])) { foreach ($_POST['taxonomies-to-be-deleted'] as $taxonomy_to_delete) { $return[] = array('type' => 'success', 'content' => sprintf(__('Taxonomy "%s" deleted', 'wpcf'), $taxonomies_existing[$taxonomy_to_delete]['labels']['name'])); unset($taxonomies_existing[$taxonomy_to_delete]); } } } update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $taxonomies_existing); // Add relationships if (!empty($data->post_relationships) && !empty($_POST['post_relationship'])) { $relationship_existing = get_option('wpcf_post_relationship', array()); /** * be sure, $relationship_existing is a array! */ if (!is_array($relationship_existing)) { $relationship_existing = array(); } $relationship = json_decode($data->post_relationships->data, true); if (is_array($relationship)) { $relationship = array_merge($relationship_existing, $relationship); update_option('wpcf_post_relationship', $relationship); $return[] = array('type' => 'success', 'content' => __('Post relationships created', 'wpcf')); } else { $return[] = array('type' => 'error', 'content' => __('Post relationships settings were not imported because it contained unsecured data. You should re-export your Types settings using the latest version of Types', 'wpcf')); } } // WPML bulk registration if (wpcf_get_settings('register_translations_on_import')) { wpcf_admin_bulk_string_translation(); } // Flush rewrite rules wpcf_init_custom_types_taxonomies(); flush_rewrite_rules(); if ($redirect) { echo '<script type="text/javascript"> <!-- window.location = "' . admin_url('admin.php?page=toolset-export-import&tab=types') . '" //--> </script>'; die; } else { return $return; } }
/** * Save field group data from $_POST to database when the form is submitted. */ protected function save() { if (!$this->is_there_something_to_save()) { return; } $wpcf_data = wpcf_getpost('wpcf', null); // check incoming $_POST data $group_id = wpcf_getnest($_POST, array('wpcf', 'group', 'id'), null); if (null === $group_id) { // probably can be 0, which is valid $this->verification_failed_and_die(1); } // nonce verification $nonce_name = $this->get_nonce_action($group_id); $nonce = wpcf_getpost('wpcf_save_group_nonce'); if (!wp_verify_nonce($nonce, $nonce_name)) { $this->verification_failed_and_die(2); } // save group data to the database $group_id = wpcf_admin_fields_save_group(wpcf_getarr($wpcf_data, 'group', array()), WPCF_Field_Group_Term::POST_TYPE, 'term'); $field_group = $this->load_field_group($group_id); if (null == $field_group) { return; } // Why are we doing this?! $_REQUEST[$this->get_id] = $group_id; // save taxonomies $taxonomies_post = wpcf_getnest($wpcf_data, array('group', 'taxonomies'), array()); $field_group->update_associated_taxonomies($taxonomies_post); $this->save_filter_fields($group_id, wpcf_getarr($wpcf_data, 'fields', array())); // promo message if (!wpcf_is_client()) { wpcf_admin_message_store(apply_filters('types_message_term_fields_saved', __('Group saved', 'wpcf'), 0, isset($_GET['group_id']) ? true : false), 'custom'); } // Redirect to edit page so we stay on it even if user reloads it // and to present admin notices wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => WPCF_Page_Edit_Termmeta::PAGE_NAME, $this->get_id => $group_id), admin_url('admin.php')))); die; }
/** * Legacy (hacky) AJAX call to get a list of term field groups on the Term Fields Control page. * * Should not be used anywhere else. */ public function termmeta_control_get_groups() { // nonce from wpcf_fields_contol_common_resources(). if (!wp_verify_nonce(wpcf_getpost('_wpnonce'), 'custom_fields_control')) { die('Verification failed.'); // todo wpv_ajax_... } require_once WPCF_INC_ABSPATH . '/classes/class.types.admin.control.fields.php'; $tacf = new Types_Admin_Control_Fields(); $form = $tacf->get_group_list(array(), WPCF_Field_Term_Definition_Factory::FIELD_DEFINITIONS_OPTION); $form = wpcf_form(__FUNCTION__, $form); echo $form->renderForm(); die; }
/** * On the Add Term page, we need to initialize the page controller WPCF_GUI_Term_Field_Editing * so that it saves term fields (if there are any). * * @since 2.1 */ public function prepare_for_term_creation() { // Takes care of the rest, mainly we're interested about the create_{$taxonomy} action which follows // immediately after create_term. // // On actions fired on the Add Term page, the action POST variable is allways add-tag and the screen is set // to edit-{$taxonomy}. When creating the term on the post edit page, for example, the screen is not set. We use // this to further limit the resource wasting. However, initializing the controller even if it's not supposed to // will not lead to any errors - it gives up gracefully. $action = wpcf_getpost('action'); $screen = wpcf_getpost('screen', null); if ('add-tag' == $action && null !== $screen) { WPCF_GUI_Term_Field_Editing::initialize(); } }