protected function init_hooks() { if (defined('DOING_AJAX')) { return; } add_action('add_meta_boxes', array($this, 'add_meta_boxes')); // add promotional message if not client if (!wpcf_is_client()) { add_filter('wpcf_meta_box_post_type', array($this, 'add_box_howto')); add_filter('wpcf_meta_box_taxonomy', array($this, 'add_box_howto')); add_filter('wpcf_meta_box_custom_field', array($this, 'add_box_howto')); add_filter('wpcf_meta_box_user_meta', array($this, 'add_box_howto')); } }
/** * 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() { 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]); } 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 tax name $tax = ''; if (!empty($data['slug'])) { $tax = $data['slug']; } else { if (!empty($data[$this->get_id])) { $tax = $data[$this->get_id]; } else { if (!empty($data['labels']['singular_name'])) { $tax = sanitize_title($data['labels']['singular_name']); } } } if (empty($tax)) { wpcf_admin_message(__('Please set taxonomy name', 'wpcf'), 'error'); return false; } if (empty($data['labels']['singular_name'])) { $data['labels']['singular_name'] = $tax; } $data['slug'] = $tax; $taxonomies = $this->taxonomies->get(); /** * is built-in? */ $tax_is_built_in = wpcf_is_builtin_taxonomy($tax); // Check reserved name $reserved = wpcf_is_reserved_name($tax, 'taxonomy') && !$tax_is_built_in; if (is_wp_error($reserved)) { wpcf_admin_message($reserved->get_error_message(), 'error'); return false; } // Check if exists if ($update && !array_key_exists($data[$this->get_id], $taxonomies)) { wpcf_admin_message(__("Taxonomy do not exist", 'wpcf'), 'error'); return false; } // Check overwriting if (!$update && array_key_exists($tax, $taxonomies)) { /** * set last edit author */ $data[WPCF_AUTHOR] = get_current_user_id(); wpcf_admin_message(__('Taxonomy already exists', 'wpcf'), 'error'); return false; } // Check if our tax overwrites some tax outside $tax_exists = get_taxonomy($tax); if (!$update && !empty($tax_exists)) { wpcf_admin_message(__('Taxonomy already exists', 'wpcf'), 'error'); return false; } // Check if renaming if (!$tax_is_built_in && $update && $data[$this->get_id] != $tax) { global $wpdb; $wpdb->update($wpdb->term_taxonomy, array('taxonomy' => esc_sql($tax)), array('taxonomy' => esc_sql($data[$this->get_id])), array('%s'), array('%s')); // Sync action do_action('wpcf_taxonomy_renamed', $tax, $data[$this->get_id]); // Delete old type unset($taxonomies[$data[$this->get_id]]); } // Check if active if (isset($taxonomies[$tax]['disabled'])) { $data['disabled'] = $taxonomies[$tax]['disabled']; } /** * Sync with post types */ $post_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); foreach ($post_types as $id => $type) { if (!empty($data['supports']) && array_key_exists($id, $data['supports'])) { if (empty($post_types[$id]['taxonomies'][$data['slug']])) { $post_types[$id][TOOLSET_EDIT_LAST] = time(); } $post_types[$id]['taxonomies'][$data['slug']] = 1; } else { if (!empty($post_types[$id]['taxonomies'][$data['slug']])) { $post_types[$id][TOOLSET_EDIT_LAST] = time(); } unset($post_types[$id]['taxonomies'][$data['slug']]); } } update_option(WPCF_OPTION_NAME_CUSTOM_TYPES, $post_types); /** * fix built-in */ if ($tax_is_built_in) { $data['_builtin'] = true; unset($data['icon']); // make sure default labels are used for the built-in taxonomies // for the case a smart user enables disabled="disabled" inputs $data['labels'] = $taxonomies[$tax]['labels']; unset($data['wpcf-tax']); } $taxonomies[$tax] = $data; $taxonomies[$tax][TOOLSET_EDIT_LAST] = time(); // set last edit author $taxonomies[$tax][WPCF_AUTHOR] = get_current_user_id(); foreach ($taxonomies as $id => $taxonomy) { // make sure "supports" field is saved for ALL taxonomies if (!isset($taxonomy['supports']) && isset($taxonomy['object_type'])) { if (!empty($taxonomy['object_type'])) { foreach ($taxonomy['object_type'] as $supported_post) { $taxonomy['supports'][$supported_post] = 1; } } } // make sure "slug" field is set if (!isset($taxonomy['slug'])) { $taxonomy['slug'] = isset($taxonomy['name']) ? $taxonomy['name'] : $id; } // make sure "name" field is set if (!isset($taxonomy['name'])) { $taxonomy['name'] = isset($taxonomy['slug ']); } // make sure "supports" field is set if (!isset($taxonomy['supports'])) { $taxonomy['supports'] = array(); } $taxonomies[$id] = $taxonomy; } /** * save */ update_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, $taxonomies); // WPML register strings wpcf_custom_taxonimies_register_translation($tax, $data); if (wpcf_is_client()) { $msg = $update ? __('Taxonomy saved.', 'wpcf') : __('New Taxonomy created.', 'wpcf'); wpcf_admin_message_store($msg, 'updated notice notice-success is-dismissible'); } else { wpcf_admin_message_store(apply_filters('types_message_custom_taxonomy_saved', __('Taxonomy saved.', 'wpcf'), $data, $update), 'custom'); } // Flush rewrite rules flush_rewrite_rules(); // Redirect wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => 'wpcf-edit-tax', $this->get_id => $tax, 'wpcf-message' => get_user_option('types-modal')), 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. */ public function save() { if (!isset($_POST['wpcf']) || !isset($_POST['wpcf']['group']) || !isset($_POST['wpcf']['group']['name'])) { return false; } $_POST['wpcf']['group'] = apply_filters('wpcf_group_pre_save', $_POST['wpcf']['group']); $group_name = wp_kses_post($_POST['wpcf']['group']['name']); require_once WPCF_EMBEDDED_ABSPATH . '/classes/forms.php'; $form = new Enlimbo_Forms_Wpcf(); if (empty($group_name)) { $form->triggerError(); wpcf_admin_message(__('Group name can not be empty.', 'wpcf'), 'error'); return $form; } $new_group = false; $group_slug = sanitize_title($group_name); // Basic check if (isset($_REQUEST[$this->get_id])) { // Check if group exists $post = get_post(intval($_REQUEST[$this->get_id])); // Name changed if (strtolower($group_name) != strtolower($post->post_title)) { // Check if already exists $exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME); if (!empty($exists)) { $form->triggerError(); wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error'); return $form; } } if (empty($post) || $post->post_type != TYPES_USER_META_FIELD_GROUP_CPT_NAME) { $form->triggerError(); wpcf_admin_message(sprintf(__("Wrong group ID %d", 'wpcf'), intval($_REQUEST[$this->get_id])), 'error'); return $form; } $group_id = $post->ID; } else { $new_group = true; // Check if already exists $exists = get_page_by_title($group_name, 'OBJECT', TYPES_USER_META_FIELD_GROUP_CPT_NAME); if (!empty($exists)) { $form->triggerError(); wpcf_admin_message(sprintf(__("A group by name <em>%s</em> already exists. Please use a different name and save again.", 'wpcf'), apply_filters('the_title', $exists->post_title)), 'error'); return $form; } } // Save fields for future use $fields = array(); if (!empty($_POST['wpcf']['fields'])) { foreach ($_POST['wpcf']['fields'] as $key => $field) { $field = wpcf_sanitize_field($field); $field = apply_filters('wpcf_field_pre_save', $field); if (!empty($field['is_new'])) { // Check name and slug if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) { $form->triggerError(); wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error'); return $form; } if (isset($field['slug']) && wpcf_types_cf_under_control('check_exists', sanitize_title($field['slug']), TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta')) { $form->triggerError(); wpcf_admin_message(sprintf(__('Field with slug "%s" already exists', 'wpcf'), $field['slug']), 'error'); return $form; } } // Field ID and slug are same thing $field_id = wpcf_admin_fields_save_field($field, TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'wpcf-usermeta'); if (!empty($field_id)) { $fields[] = $field_id; } } } // Save group $roles = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array(); /** * Admin styles */ if (isset($_POST['wpcf']['group']['admin_styles'])) { $admin_style = esc_html($_POST['wpcf']['group']['admin_styles']); } // Rename if needed if (isset($_REQUEST[$this->get_id])) { $_POST['wpcf']['group']['id'] = intval($_REQUEST[$this->get_id]); } $group_id = wpcf_admin_fields_save_group($_POST['wpcf']['group'], TYPES_USER_META_FIELD_GROUP_CPT_NAME, 'user'); // Set open fieldsets if ($new_group && !empty($group_id)) { $open_fieldsets = get_user_meta(get_current_user_id(), 'wpcf-group-form-toggle', true); if (isset($open_fieldsets[-1])) { $open_fieldsets[$group_id] = $open_fieldsets[-1]; unset($open_fieldsets[-1]); update_user_meta(get_current_user_id(), 'wpcf-group-form-toggle', $open_fieldsets); } } // Rest of processes if (!empty($group_id)) { wpcf_admin_fields_save_group_fields($group_id, $fields, false, TYPES_USER_META_FIELD_GROUP_CPT_NAME); $this->save_group_showfor($group_id, $roles); /** * Admin styles */ if (defined('TYPES_USE_STYLING_EDITOR') && TYPES_USE_STYLING_EDITOR && isset($admin_style)) { wpcf_admin_fields_save_group_admin_styles($group_id, $admin_style); } $_POST['wpcf']['group']['fields'] = isset($_POST['wpcf']['fields']) ? $_POST['wpcf']['fields'] : array(); do_action('wpcf_save_group', $_POST['wpcf']['group']); // admin message if (!wpcf_is_client()) { wpcf_admin_message_store(apply_filters('types_message_usermeta_saved', __('Group saved', 'wpcf'), $group_name, $new_group ? false : true), 'custom'); } wp_safe_redirect(admin_url(sprintf('admin.php?page=wpcf-edit-usermeta&group_id=%d', $group_id))); exit; } else { wpcf_admin_message_store(__('Error saving group', 'wpcf'), 'error'); } }
/** * Init functions for post edit pages. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @param type $post */ function wpcf_admin_post_init($post) { add_action('admin_footer', 'wpcf_admin_fields_postfields_styles'); wpcf_admin_add_js_settings('wpcf_nonce_toggle_group', '\'' . wp_create_nonce('group_form_collapsed') . '\''); wpcf_admin_add_js_settings('wpcf_nonce_toggle_fieldset', '\'' . wp_create_nonce('form_fieldset_toggle') . '\''); // Get post_type $post_type = wpcf_admin_get_edited_post_type($post); /* * * This is left to maintain compatibility with older versions * TODO Remove */ // Add items to View dropdown if (in_array($post_type, array('view', 'view-template', 'cred-form', 'cred-user-form'))) { add_filter('editor_addon_menus_wpv-views', 'wpcf_admin_post_editor_addon_menus_filter'); add_action('admin_footer', 'wpcf_admin_post_js_validation'); wpcf_enqueue_scripts(); wp_enqueue_script('toolset-colorbox'); wp_enqueue_style('toolset-colorbox'); } // Never show on 'Views' and 'Content Templates' if (in_array($post_type, array('view', 'view-template'))) { return false; } /** * remove custom field WordPress metabox */ if ('hide' == wpcf_get_settings('hide_standard_custom_fields_metabox')) { foreach (array('normal', 'advanced', 'side') as $context) { remove_meta_box('postcustom', $post_type, $context); } } // Add marketing box if (!wpcf_is_client() && !in_array($post_type, array('post', 'page', 'cred-form', 'cred-user-form')) && !defined('WPCF_RUNNING_EMBEDDED')) { $settings_help_box = wpcf_get_settings('help_box'); $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); if ($settings_help_box == 'all' || array_key_exists($post_type, $custom_types)) { $displaying_custom_content = (include WPCF_ABSPATH . '/marketing/displaying-custom-content/title-content.php'); add_meta_box('add_box_howto', $displaying_custom_content['title'], 'wpcf_admin_post_marketing_displaying_custom_content', $post_type, 'side', 'high'); } } // Are Types active? $wpcf_active = false; // Get groups $groups = wpcf_admin_post_get_post_groups_fields($post); foreach ($groups as $group) { $only_preview = ''; //If Access plugin activated if (function_exists('wpcf_access_register_caps')) { //If user can't view own profile fields if (!current_user_can('view_fields_in_edit_page_' . $group['slug'])) { continue; } //If user can modify current group in own profile if (!current_user_can('modify_fields_in_edit_page_' . $group['slug'])) { $only_preview = 1; } } if (!empty($group['fields']) && empty($only_preview)) { $wpcf_active = true; break; } } // Activate scripts if ($wpcf_active) { add_action('admin_head', 'wpcf_post_preview_warning'); wpcf_edit_post_screen_scripts(); } // Add validation add_action('admin_footer', 'wpcf_admin_post_js_validation'); /* * TODO Review * This is forced because of various Child cases * and when field are rendered via AJAX but not registered yet. * * Basically all fields that require additional JS should be added here. * * This is a must for now. * These fields need init JS in various cases. */ wpcf_field_enqueue_scripts('date'); wpcf_field_enqueue_scripts('image'); wpcf_field_enqueue_scripts('file'); wpcf_field_enqueue_scripts('skype'); wpcf_field_enqueue_scripts('numeric'); do_action('wpcf_admin_post_init', $post_type, $post, $groups, $wpcf_active); }
/** * 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. */ protected function save() { // abort if no post data if (!isset($_POST['wpcf'])) { return; } // abort when no group id isset if (!isset($_POST['wpcf']['group']['id'])) { $this->verification_failed_and_die(1); } // nonce verification $nonce_name = $this->get_nonce_action($_POST['wpcf']['group']['id']); if (!wp_verify_nonce($_REQUEST['wpcf_save_group_nonce'], $nonce_name)) { $this->verification_failed_and_die(2); } // get group_id $group_id = wpcf_admin_fields_save_group($_POST['wpcf']['group'], TYPES_CUSTOM_FIELD_GROUP_CPT_NAME, 'custom'); // abort if does not exist if (empty($group_id)) { return; } $_REQUEST[$this->get_id] = $group_id; // save $this->save_group_fields($group_id); $this->save_condition_post_types($group_id); $this->save_condition_templates($group_id); $this->save_condition_taxonomies($group_id); if (!wpcf_is_client()) { wpcf_admin_message_store(apply_filters('types_message_custom_fields_saved', __('Group saved', 'wpcf'), 0, isset($_GET['group_id']) ? true : false), 'custom'); } // redirect wp_safe_redirect(esc_url_raw(add_query_arg(array('page' => 'wpcf-edit', $this->get_id => $group_id), 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 if (wpcf_is_client()) { $msg = $update ? __('Post Type saved.', 'wpcf') : __('New Post Type created.', 'wpcf'); wpcf_admin_message_store($msg, 'updated notice notice-success is-dismissible'); } else { wpcf_admin_message_store(apply_filters('types_message_custom_post_type_saved', __('Post Type saved', 'wpcf'), $data, $update), 'custom'); } if (!$data['_builtin']) { // Flush rewrite rules flush_rewrite_rules(); 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'), admin_url('admin.php')))); die; }
/** * 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; }
function wpcf_admin_fields_save_message($updated = false, $which_fields = 'none') { // these messages are only for paying clients if (!wpcf_is_client()) { return; } switch ($which_fields) { case 'custom': $msg = $updated ? __('Post Field Group saved.', 'wpcf') : __('New Post Field Group created.', 'wpcf'); break; case 'user': $msg = $updated ? __('User Field Group saved.', 'wpcf') : __('New User Field Group created.', 'wpcf'); break; case 'term': $msg = $updated ? __('Term Field Group saved.', 'wpcf') : __('New Term Field Group created.', 'wpcf'); break; } if (isset($msg)) { wpcf_admin_message_store($msg, 'updated notice notice-success is-dismissible'); } }