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


PHP wpcf_admin_fields_save_group函数代码示例

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


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

示例1: wpcf_admin_save_usermeta_groups_submit

/**
 * Saves user fields and groups.
 * 
 * If field name is changed in specific group - new one will be created,
 * otherwise old one will be updated and will appear in that way in other grups.
 * 
 * @return type 
 */
function wpcf_admin_save_usermeta_groups_submit($form)
{
    if (!isset($_POST['wpcf']['group']['name'])) {
        return false;
    }
    $_POST['wpcf']['group']['name'] = trim($_POST['wpcf']['group']['name']);
    $_POST['wpcf']['group'] = apply_filters('wpcf_group_pre_save', $_POST['wpcf']['group']);
    global $wpdb;
    $new_group = false;
    $group_slug = $_POST['wpcf']['group']['slug'] = sanitize_title($_POST['wpcf']['group']['name']);
    // Basic check
    if (isset($_REQUEST['group_id'])) {
        // Check if group exists
        $post = get_post($_REQUEST['group_id']);
        // Name changed
        if (strtolower($_POST['wpcf']['group']['name']) != strtolower($post->post_title)) {
            // Check if already exists
            $exists = get_page_by_title($_POST['wpcf']['group']['name'], 'OBJECT', 'wp-types-user-group');
            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'), $_POST['wpcf']['group']['name']), 'error');
                return $form;
            }
        }
        if (empty($post) || $post->post_type != 'wp-types-user-group') {
            $form->triggerError();
            wpcf_admin_message(sprintf(__("Wrong group ID %d", 'wpcf'), intval($_REQUEST['group_id'])), 'error');
            return $form;
        }
        $group_id = $post->ID;
    } else {
        $new_group = true;
        // Check if already exists
        $exists = get_page_by_title($_POST['wpcf']['group']['name'], 'OBJECT', 'wp-types-user-group');
        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'), $_POST['wpcf']['group']['name']), 'error');
            return $form;
        }
    }
    // Save fields for future use
    $fields = array();
    if (!empty($_POST['wpcf']['fields'])) {
        // Before anything - search unallowed characters
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['name']) || !empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['slug'])) {
                $form->triggerError();
                wpcf_admin_message(sprintf(__('Field slugs cannot contain non-English characters. Please edit this field name %s and save again.', 'wpcf'), $field['name']), 'error');
                return $form;
            }
        }
        foreach ($_POST['wpcf']['fields'] as $key => $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']), 'wp-types-user-group', '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']), 'wp-types-user-group', '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, 'wp-types-user-group', 'wpcf-usermeta');
            if (!empty($field_id)) {
                $fields[] = $field_id;
            }
        }
    }
    // Save group
    $roles = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array();
    $admin_style = $_POST['wpcf']['group']['admin_styles'];
    // Rename if needed
    if (isset($_REQUEST['group_id'])) {
        $_POST['wpcf']['group']['id'] = $_REQUEST['group_id'];
    }
    $group_id = wpcf_admin_fields_save_group($_POST['wpcf']['group'], 'wp-types-user-group');
    $_POST['wpcf']['group']['id'] = $group_id;
    // 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
//.........这里部分代码省略.........
开发者ID:sandum150,项目名称:cheltuieli,代码行数:101,代码来源:usermeta-form.php

示例2: wpcf_admin_migration_form_submit

/**
 * Adds 3rd party created types, taxonomies and fields
 */
function wpcf_admin_migration_form_submit()
{
    $cfui_types = get_option('cpt_custom_post_types', array());
    $cfui_taxonomies = get_option('cpt_custom_tax_types', array());
    $wpcf_types = get_option('wpcf-custom-types', array());
    $wpcf_taxonomies = get_option('wpcf-custom-taxonomies', array());
    $redirect_page = 'wpcf-ctt';
    if (!empty($_POST['cfui']['types'])) {
        $data = array();
        foreach ($_POST['cfui']['types'] as $key => $types_slug) {
            if (array_key_exists(sanitize_title($types_slug), $wpcf_types)) {
                continue;
            }
            foreach ($cfui_types as $cfui_type) {
                if (sanitize_title($cfui_type['name']) == $types_slug) {
                    $data[$types_slug] = wpcf_admin_migrate_get_cfui_type_data($cfui_type);
                    wpcf_admin_message_store(sprintf(__("Post Type %s added", 'wpcf'), '<em>' . $cfui_type['name'] . '</em>'));
                }
            }
        }
        $wpcf_types = array_merge($wpcf_types, $data);
        update_option('wpcf-custom-types', $wpcf_types);
    }
    if (!empty($_POST['cfui']['tax'])) {
        $data = array();
        foreach ($_POST['cfui']['tax'] as $key => $tax_slug) {
            if (array_key_exists(sanitize_title($tax_slug), $wpcf_taxonomies)) {
                continue;
            }
            foreach ($cfui_taxonomies as $cfui_tax) {
                if (sanitize_title($cfui_tax['name']) == $tax_slug) {
                    $data[$tax_slug] = wpcf_admin_migrate_get_cfui_tax_data($cfui_tax);
                    wpcf_admin_message_store(sprintf(__("Taxonomy %s added", 'wpcf'), '<em>' . $cfui_tax['name'] . '</em>'));
                }
            }
        }
        $wpcf_taxonomies = array_merge($wpcf_taxonomies, $data);
        update_option('wpcf-custom-taxonomies', $wpcf_taxonomies);
    }
    // ACF
    if (!empty($_POST['acf_posts']['migrate_groups'])) {
        foreach ($_POST['acf_posts']['migrate_groups'] as $acf_group_id) {
            if (empty($_POST['acf_posts'][$acf_group_id])) {
                continue;
            }
            global $wpdb;
            $group = $wpdb->get_row($wpdb->prepare("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_title = %s AND post_type='wp-types-group'", $_POST['acf_posts'][$acf_group_id]['post_title']));
            if (empty($group)) {
                $group = array();
                $group['name'] = $_POST['acf_posts'][$acf_group_id]['post_title'];
                $group['description'] = $_POST['acf_posts'][$acf_group_id]['post_content'];
                $group_id = wpcf_admin_fields_save_group($group);
                wpcf_admin_message_store(sprintf(__("Group %s added", 'wpcf'), '<em>' . $group['name'] . '</em>'));
            } else {
                $group_id = $group->ID;
                wpcf_admin_message_store(sprintf(__("Group %s updated", 'wpcf'), '<em>' . $group->post_title . '</em>'));
            }
            $fields_to_add = array();
            if ($group_id && !empty($_POST['acf_posts'][$acf_group_id]['fields'])) {
                foreach ($_POST['acf_posts'][$acf_group_id]['fields'] as $field_id => $field) {
                    if (!in_array($field_id, $_POST['acf_posts'][$acf_group_id]['migrate_fields'])) {
                        continue;
                    }
                    if (!wpcf_types_cf_under_control('check_exists', $field['slug']) || wpcf_types_cf_under_control('check_outsider', $field['slug'])) {
                        // save field
                        $field['controlled'] = 1;
                        $temp = wpcf_admin_fields_save_field($field);
                        $fields_to_add[] = $temp;
                        wpcf_admin_message_store(sprintf(__("Field %s added", 'wpcf'), '<em>' . $temp . '</em>'));
                    }
                }
                wpcf_admin_fields_save_group_fields($group_id, $fields_to_add, false);
            }
            wpcf_admin_fields_save_group_post_types($group_id, array());
            wpcf_admin_fields_save_group_terms($group_id, array());
        }
        $redirect_page = 'wpcf';
    }
    flush_rewrite_rules();
    // Deactivate plugins
    if (!empty($_POST['deactivate-cfui'])) {
        $active_plugins = get_option('active_plugins', array());
        foreach ($active_plugins as $key => $file) {
            if (strpos($file, 'custom-post-type-ui.php') !== false) {
                unset($active_plugins[$key]);
            }
        }
        update_option('active_plugins', array_values($active_plugins));
    }
    wp_redirect(admin_url('admin.php?page=' . $redirect_page));
    die;
}
开发者ID:adisonc,项目名称:MaineLearning,代码行数:95,代码来源:migration.php

示例3: wpv_register_typesfields_func

 /**
  * Auto-register the computed values as Types fields.
  * This method automatically creates the Woocommerce Views filter custom fields and group.
  * Hooked to wp_loaded
  * @access public
  * @return void
  */
 public function wpv_register_typesfields_func()
 {
     //Define WC Views canonical custom field array
     $wc_views_custom_fields_array = array('views_woo_price', 'views_woo_on_sale', 'views_woo_in_stock');
     //Preparation to Types control
     $wc_views_fields_array = array();
     $string_wpcf_not_controlled = md5('wpcf_not_controlled');
     foreach ($wc_views_custom_fields_array as $key => $value) {
         $wc_views_fields_array[] = $value . '_' . $string_wpcf_not_controlled;
     }
     if (defined('WPCF_INC_ABSPATH')) {
         //First, check if WC Views Types Group field does not exist
         if (!$this->check_if_types_group_exist('WooCommerce Views filter fields')) {
             require_once WPCF_INC_ABSPATH . '/fields.php';
             //Part 1: Assign to Types Control
             //Get Fields
             $fields = wpcf_admin_fields_get_fields(false, true);
             $fields_bulk = wpcf_types_cf_under_control('add', array('fields' => $wc_views_fields_array));
             foreach ($fields_bulk as $field_id) {
                 if (isset($fields[$field_id])) {
                     $fields[$field_id]['data']['disabled'] = 0;
                 }
             }
             //Save fields
             wpcf_admin_fields_save_fields($fields);
             //Retrieve updated fields
             $fields = wpcf_admin_fields_get_fields(false, false);
             //Assign names
             foreach ($fields as $key => $value) {
                 if ($key == 'views_woo_price') {
                     $fields['views_woo_price']['name'] = 'WooCommerce Product Price';
                 } elseif ($key == 'views_woo_on_sale') {
                     $fields['views_woo_on_sale']['name'] = 'Product On Sale Status';
                 } elseif ($key == 'views_woo_in_stock') {
                     $fields['views_woo_in_stock']['name'] = 'Product In Stock Status';
                 }
             }
             //Save fields
             wpcf_admin_fields_save_fields($fields);
             //Define group
             $group = array('name' => 'WooCommerce Views filter fields', 'description' => '', 'filters_association' => 'any', 'conditional_display' => array('relation' => 'AND', 'custom' => ''), 'preview' => 'edit_mode', 'admin_html_preview' => '', 'admin_styles' => '', 'slug' => 'wc-views-types-groups-fields');
             //Save group
             $group_id = wpcf_admin_fields_save_group($group);
             //Save group fields
             wpcf_admin_fields_save_group_fields($group_id, $fields_bulk);
         }
     }
 }
开发者ID:rebeccayshen,项目名称:kitlist,代码行数:55,代码来源:Class_WooCommerce_Views.php

示例4: wpcf_admin_save_fields_groups_submit

/**
 * Saves fields and groups.
 * 
 * If field name is changed in specific group - new one will be created,
 * otherwise old one will be updated and will appear in that way in other grups.
 * 
 * @return type 
 */
function wpcf_admin_save_fields_groups_submit($form)
{
    if (!isset($_POST['wpcf']['group']['name'])) {
        return false;
    }
    global $wpdb;
    $new_group = false;
    $group_slug = $_POST['wpcf']['group']['slug'] = sanitize_title($_POST['wpcf']['group']['name']);
    // Basic check
    if (isset($_REQUEST['group_id'])) {
        // Check if group exists
        $post = get_post($_REQUEST['group_id']);
        if (empty($post) || $post->post_type != 'wp-types-group') {
            $form->triggerError();
            wpcf_admin_message(sprintf(__("Wrong group ID %d", 'wpcf'), intval($_REQUEST['group_id'])), 'error');
            return false;
        }
        $group_id = $post->ID;
    } else {
        $new_group = true;
    }
    // Save fields for future use
    $fields = array();
    if (!empty($_POST['wpcf']['fields'])) {
        // Before anything - search unallowed characters
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['name']) || !empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['slug'])) {
                $form->triggerError();
                wpcf_admin_message(sprintf(__('Field slugs cannot contain non-English characters. Please edit this field name %s and save again.', 'wpcf'), $field['name']), 'error');
                return false;
            }
        }
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (!empty($field['is_new'])) {
                if (wpcf_types_cf_under_control('check_exists', sanitize_title($field['name']))) {
                    $form->triggerError();
                    wpcf_admin_message(sprintf(__('Field with name "%s" already exists', 'wpcf'), $field['name']), 'error');
                    return false;
                }
            }
            // Field ID and slug are same thing
            //            $slug = $_POST['wpcf']['fields'][$key]['slug'] = sanitize_title($field['name']);
            $field_id = wpcf_admin_fields_save_field($field);
            if (!empty($field_id)) {
                $fields[] = $field_id;
            }
            // WPML
            if (function_exists('wpml_cf_translation_preferences_store')) {
                $wpml_save_cf = wpml_cf_translation_preferences_store($key, wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_id)) . $field_id);
            }
        }
    }
    // Save group
    $post_types = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array();
    $taxonomies_post = isset($_POST['wpcf']['group']['taxonomies']) ? $_POST['wpcf']['group']['taxonomies'] : array();
    $terms = array();
    foreach ($taxonomies_post as $taxonomy) {
        foreach ($taxonomy as $tax => $term) {
            $terms[] = $term;
        }
    }
    // Rename if needed
    if (isset($_REQUEST['group_id'])) {
        $_POST['wpcf']['group']['id'] = $_REQUEST['group_id'];
    }
    $group_id = wpcf_admin_fields_save_group($_POST['wpcf']['group']);
    // 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);
        wpcf_admin_fields_save_group_post_types($group_id, $post_types);
        wpcf_admin_fields_save_group_terms($group_id, $terms);
        if (!empty($_POST['wpcf']['group']['templates'])) {
            wpcf_admin_fields_save_group_templates($group_id, $_POST['wpcf']['group']['templates']);
        }
        $_POST['wpcf']['group']['fields'] = isset($_POST['wpcf']['fields']) ? $_POST['wpcf']['fields'] : array();
        do_action('wpcf_save_group', $_POST['wpcf']['group']);
        wpcf_admin_message_store(__('Group saved', 'wpcf'));
        wp_redirect(admin_url('admin.php?page=wpcf-edit&group_id=' . $group_id));
        die;
    } else {
        wpcf_admin_message_store(__('Error saving group', 'wpcf'), 'error');
    }
}
开发者ID:nuevomediagroup,项目名称:nmg-code,代码行数:100,代码来源:fields-form.php

示例5: save


//.........这里部分代码省略.........
     // 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');
     }
 }
开发者ID:phuocdungit,项目名称:fundy,代码行数:101,代码来源:class.types.admin.edit.meta.fields.group.php

示例6: wpcf_admin_save_fields_groups_submit


//.........这里部分代码省略.........
        // Check if already exists
        $exists = get_page_by_title($_POST['wpcf']['group']['name'], 'OBJECT', 'wp-types-group');
        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'), htmlspecialchars($_POST['wpcf']['group']['name'])), 'error');
            return $form;
        }
    }
    // Save fields for future use
    $fields = array();
    if (!empty($_POST['wpcf']['fields'])) {
        // Before anything - search unallowed characters
        foreach ($_POST['wpcf']['fields'] as $key => $field) {
            if (empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['name']) || !empty($field['slug']) && preg_match('#[^a-zA-Z0-9\\s\\_\\-]#', $field['slug'])) {
                $form->triggerError();
                wpcf_admin_message(sprintf(__('Field slugs cannot contain non-English characters. Please edit this field name %s and save again.', 'wpcf'), $field['name']), 'error');
                return $form;
            }
            if (!empty($field['name']) && is_numeric($field['name']) || !empty($field['slug']) && is_numeric($field['slug'])) {
                $form->triggerError();
                wpcf_admin_message(sprintf(__('Field names or slugs cannot contain only numbers.', 'wpcf'), $field['name']), 'error');
                return $form;
            }
        }
        // First check all fields
        foreach ($_POST['wpcf']['fields'] as $key => $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']))) {
                    $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']))) {
                    $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);
            if (is_wp_error($field_id)) {
                $form->triggerError();
                wpcf_admin_message($field_id->get_error_message(), 'error');
                return $form;
            }
            if (!empty($field_id)) {
                $fields[] = $field_id;
            }
            // WPML
            if (function_exists('wpml_cf_translation_preferences_store')) {
                $wpml_save_cf = wpml_cf_translation_preferences_store($key, wpcf_types_get_meta_prefix(wpcf_admin_fields_get_field($field_id)) . $field_id);
            }
        }
    }
    // Save group
    $post_types = isset($_POST['wpcf']['group']['supports']) ? $_POST['wpcf']['group']['supports'] : array();
    $taxonomies_post = isset($_POST['wpcf']['group']['taxonomies']) ? $_POST['wpcf']['group']['taxonomies'] : array();
    $admin_style = $_POST['wpcf']['group']['admin_styles'];
    $terms = array();
    foreach ($taxonomies_post as $taxonomy) {
        foreach ($taxonomy as $tax => $term) {
            $terms[] = $term;
        }
    }
    // Rename if needed
    if (isset($_REQUEST['group_id'])) {
        $_POST['wpcf']['group']['id'] = intval($_REQUEST['group_id']);
    }
    $group_id = wpcf_admin_fields_save_group($_POST['wpcf']['group']);
    $_POST['wpcf']['group']['id'] = $group_id;
    // 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);
        wpcf_admin_fields_save_group_post_types($group_id, $post_types);
        wpcf_admin_fields_save_group_terms($group_id, $terms);
        wpcf_admin_fields_save_group_admin_styles($group_id, $admin_style);
        if (empty($_POST['wpcf']['group']['templates'])) {
            $_POST['wpcf']['group']['templates'] = array();
        }
        wpcf_admin_fields_save_group_templates($group_id, $_POST['wpcf']['group']['templates']);
        $_POST['wpcf']['group']['fields'] = isset($_POST['wpcf']['fields']) ? $_POST['wpcf']['fields'] : array();
        do_action('wpcf_save_group', $_POST['wpcf']['group']);
        wpcf_admin_message_store(apply_filters('types_message_custom_fields_saved', __('Group saved', 'wpcf'), $_POST['wpcf']['group']['name'], $new_group ? false : true), 'custom');
        wp_redirect(admin_url('admin.php?page=wpcf-edit&group_id=' . $group_id));
        die;
    } else {
        wpcf_admin_message_store(__('Error saving group', 'wpcf'), 'error');
    }
}
开发者ID:chrismathers,项目名称:premierplacement,代码行数:101,代码来源:fields-form.php

示例7: save

 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  *
  * @return type Description.
  */
 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);
     do_action('types_fields_group_saved', $group_id);
     do_action('types_fields_group_post_saved', $group_id);
     // do not use these hooks anymore
     do_action('wpcf_fields_group_saved', $group_id);
     do_action('wpcf_postmeta_fields_group_saved', $group_id);
     // redirect
     $args = array('page' => 'wpcf-edit', $this->get_id => $group_id);
     if (isset($_GET['ref'])) {
         $args['ref'] = $_GET['ref'];
     }
     wp_safe_redirect(esc_url_raw(add_query_arg($args, admin_url('admin.php'))));
     die;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:58,代码来源:class.types.admin.edit.custom.fields.group.php

示例8: save

 /**
  * Summary.
  *
  * Description.
  *
  * @since x.x.x
  * @access (for functions: only use if private)
  *
  * @see Function/method/class relied on
  * @link URL
  * @global type $varname Description.
  * @global type $varname Description.
  *
  * @param type $var Description.
  * @param type $var Optional. Description.
  *
  * @return type Description.
  */
 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;
 }
开发者ID:torch2424,项目名称:Team-No-Comply-Games-Wordpress,代码行数:52,代码来源:class.types.admin.edit.custom.fields.group.php

示例9: save

 /**
  * 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;
 }
开发者ID:phuocdungit,项目名称:fundy,代码行数:42,代码来源:termmeta_form.php


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