/**
  * Check if we have recipe taxonomies
  */
 public function check_recipe_taxonomies()
 {
     $taxonomies = $this->get();
     if (count($taxonomies) == 0) {
         $taxonomies = $this->add_taxonomy_to_array($taxonomies, 'ingredient', __('Ingredients', 'wp-ultimate-recipe'), __('Ingredient', 'wp-ultimate-recipe'));
         $taxonomies = $this->add_taxonomy_to_array($taxonomies, 'course', __('Courses', 'wp-ultimate-recipe'), __('Course', 'wp-ultimate-recipe'));
         $taxonomies = $this->add_taxonomy_to_array($taxonomies, 'cuisine', __('Cuisines', 'wp-ultimate-recipe'), __('Cuisine', 'wp-ultimate-recipe'));
         $this->update($taxonomies);
         update_option('wpurp_flush', '1');
         wp_insert_term(__('Breakfast', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Appetizer', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Soup', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Main Course', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Side Dish', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Salad', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Dessert', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Snack', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('Drinks', 'wp-ultimate-recipe'), 'course');
         wp_insert_term(__('French', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Italian', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Mediterranean', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Indian', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Chinese', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Japanese', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('American', 'wp-ultimate-recipe'), 'cuisine');
         wp_insert_term(__('Mexican', 'wp-ultimate-recipe'), 'cuisine');
     }
 }
Example #2
0
 public static function add_source_default()
 {
     global $wpdb;
     if (empty(self::$source_list)) {
         return false;
     }
     foreach (self::$source_list as $source) {
         if (isset($source['name'])) {
             $term = get_term_by('name', $source['name'], 'dln_source_cat');
             if (empty($term)) {
                 $term = wp_insert_term(esc_sql($source['name']), 'dln_source_cat');
             }
             if (!empty($term->term_id) && isset($source['link'])) {
                 $links = $source['link'];
                 if (is_array($links)) {
                     foreach ($links as $i => $link) {
                         $sql = $wpdb->prepare("SELECT id from {$wpdb->dln_news_source} WHERE link = %s", esc_sql($link));
                         $exists = $wpdb->get_row($sql);
                         if (empty($exists)) {
                             $result = $wpdb->insert($wpdb->dln_news_source, array('term_id' => esc_sql($term->term_id), 'link' => esc_sql($link), 'source_type' => esc_sql($source['source_type']), 'tags' => esc_sql($source['tags']), 'type' => esc_sql($source['type'])));
                         }
                         if (is_wp_error($result)) {
                             var_dump($result);
                         }
                     }
                 }
             }
         }
     }
     exit;
 }
Example #3
0
 /**
  * Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window
  *
  * Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php.
  *
  * @since 2.20
  *
  * @param string The taxonomy name, from $_POST['action']
  *
  * @return void Sends JSON response with updated HTML for the checklist
  */
 private static function _mla_ajax_add_flat_term($key)
 {
     $taxonomy = get_taxonomy($key);
     check_ajax_referer($_POST['action'], '_ajax_nonce-add-' . $key, true);
     if (!current_user_can($taxonomy->cap->edit_terms)) {
         wp_die(-1);
     }
     $new_names = explode(',', $_POST['new' . $key]);
     $new_terms_markup = '';
     foreach ($new_names as $name) {
         if ('' === sanitize_title($name)) {
             continue;
         }
         if (!($id = term_exists($name, $key))) {
             $id = wp_insert_term($name, $key);
         }
         if (is_wp_error($id)) {
             continue;
         }
         if (is_array($id)) {
             $id = absint($id['term_id']);
         } else {
             continue;
         }
         $term = get_term($id, $key);
         $name = $term->name;
         $new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n";
     }
     // foreach new_name
     $input_new_parent_name = "new{$key}_parent";
     $supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
     $add = array('what' => $key, 'id' => $id, 'data' => $new_terms_markup, 'position' => -1, 'supplemental' => array('newcat_parent' => $supplemental));
     $x = new WP_Ajax_Response($add);
     $x->send();
 }
 public function add_label()
 {
     $data = stripslashes_deep($_POST);
     $post_id = !empty($data['post_id']) ? $data['post_id'] : false;
     $post_ids = !empty($data['post_ids']) ? array_map('intval', $data['post_ids']) : array();
     if ($post_id) {
         $post_ids[] = $post_id;
     }
     $term = !empty($data['term']) ? $data['term'] : false;
     if (!$term) {
         $this->_out(new Upfront_JsonResponse_Error("No term"));
     }
     $res = wp_insert_term($term, 'media_label');
     if (is_wp_error($res)) {
         $this->_out(new Upfront_JsonResponse_Error("Something went wrong"));
     }
     if ($post_ids) {
         $result = array();
         foreach ($post_ids as $post_id) {
             $label_objs = wp_get_object_terms($post_id, 'media_label');
             $labels = array();
             foreach ($label_objs as $label) {
                 $labels[] = (int) $label->term_id;
             }
             $labels[] = (int) $res['term_id'];
             $result[$post_id] = wp_set_object_terms($post_id, $labels, 'media_label');
         }
         $this->_out(new Upfront_JsonResponse_Success($result));
     } else {
         $this->_out(new Upfront_JsonResponse_Success($res));
     }
 }
function dwqa_posttype_init()
{
    global $dwqa_options;
    extract(dwqa_get_rewrite_slugs());
    /* Question Posttype Registration */
    $question_labels = array('name' => __('Question', 'dwqa'), 'singular_name' => __('Question', 'dwqa'), 'add_new' => __('Add New', 'theme'), 'add_new_item' => __('Add New Question', 'dwqa'), 'edit_item' => __('Edit Question'), 'new_item' => __('New Question', 'dwqa'), 'all_items' => __('All Questions', 'dwqa'), 'view_item' => __('View Question', 'dwqa'), 'search_items' => __('Search Question', 'dwqa'), 'not_found' => __('No questions found', 'dwqa'), 'not_found_in_trash' => __('No questions found in Trash', 'dwqa'), 'parent_item_colon' => '', 'menu_name' => __('DW Q&A', 'dwqa'));
    $question_args = array('labels' => $question_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => $question_rewrite, 'with_front' => false), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => '', 'supports' => array('title', 'editor', 'comments', 'author', 'page-attributes'));
    register_post_type('dwqa-question', $question_args);
    /* Question Posttype Registration */
    $answer_labels = array('name' => __('Answer', 'dwqa'), 'singular_name' => __('Answer', 'dwqa'), 'add_new' => __('Add New', 'dwqa'), 'add_new_item' => __('Add new answer', 'dwqa'), 'edit_item' => __('Edit answer', 'dwqa'), 'new_item' => __('New Answer', 'dwqa'), 'all_items' => __('All Answers', 'dwqa'), 'view_item' => __('View Answer', 'dwqa'), 'search_items' => __('Search Answer', 'dwqa'), 'not_found' => __('No Answers found', 'dwqa'), 'not_found_in_trash' => __('No Answers found in Trash', 'dwqa'), 'parent_item_colon' => '', 'menu_name' => __('Answer', 'dwqa'));
    $answer = array('labels' => $answer_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => 'edit.php?post_type=dwqa-question', 'query_var' => true, 'rewrite' => true, 'has_archive' => false, 'hierarchical' => true, 'menu_icon' => '', 'supports' => array('title', 'editor', 'comments', 'custom-fields', 'author', 'page-attributes'));
    register_post_type('dwqa-answer', $answer);
    // Question Taxonomies ( Tag, Category register for Question Posttype)
    // Question Categories
    $question_category_labels = array('name' => _x('Categories', 'taxonomy general name'), 'singular_name' => _x('Category', 'taxonomy singular name'), 'search_items' => __('Search Categories', 'dwqa'), 'all_items' => __('All Categories', 'dwqa'), 'parent_item' => __('Parent Category', 'dwqa'), 'parent_item_colon' => __('Parent Category:', 'dwqa'), 'edit_item' => __('Edit Category', 'dwqa'), 'update_item' => __('Update Category', 'dwqa'), 'add_new_item' => __('Add New Category', 'dwqa'), 'new_item_name' => __('New Category Name', 'dwqa'), 'menu_name' => __('Question Categories', 'dwqa'));
    register_taxonomy('dwqa-question_category', array('dwqa-question'), array('hierarchical' => true, 'labels' => $question_category_labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $question_category_rewrite, 'with_front' => false)));
    // Question Tags
    $question_tag_labels = array('name' => _x('Tags', 'taxonomy general name'), 'singular_name' => _x('Tag', 'taxonomy singular name'), 'search_items' => __('Search Tags', 'dwqa'), 'popular_items' => __('Popular Tags', 'dwqa'), 'all_items' => __('All Tags', 'dwqa'), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __('Edit Tag', 'dwqa'), 'update_item' => __('Update Tag', 'dwqa'), 'add_new_item' => __('Add New Tag', 'dwqa'), 'new_item_name' => __('New Tag Name', 'dwqa'), 'separate_items_with_commas' => __('Separate tags with commas', 'dwqa'), 'add_or_remove_items' => __('Add or remove tags', 'dwqa'), 'choose_from_most_used' => __('Choose from the most used tags', 'dwqa'), 'menu_name' => __('Question Tags', 'dwqa'));
    register_taxonomy('dwqa-question_tag', array('dwqa-question'), array('hierarchical' => false, 'labels' => $question_tag_labels, 'show_ui' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array('slug' => $question_tag_rewrite, 'with_front' => false)));
    // Create default category for dwqa question type when dwqa plugin is actived
    $cats = get_categories(array('type' => 'dwqa-question', 'hide_empty' => 0, 'taxonomy' => 'dwqa-question_category'));
    if (empty($cats)) {
        wp_insert_term('Questions', 'dwqa-question_category');
    }
    // update term rewrite rule
    dwqa_update_term_rewrite_rules();
}
 private function processTaxonomy(&$taxonomy)
 {
     $currentTerms = get_terms($taxonomy->slug, array('hide_empty' => false));
     $done = false;
     while (!$done) {
         $deferred = 0;
         foreach ($taxonomy->terms as &$term) {
             if (!$term->done) {
                 $parentId = $this->parentId($term->term->parent, $taxonomy);
                 if ($parentId || $term->term->parent == 0) {
                     $existingTermId = $this->findExistingTerm($term, $currentTerms);
                     $args = array('description' => $term->term->description, 'parent' => $parentId, 'slug' => $term->term->slug, 'term_group' => $term->term->term_group, 'name' => $term->term->name);
                     if ($existingTermId > 0) {
                         $ret = wp_update_term($existingTermId, $taxonomy->slug, $args);
                         $term->id = $existingTermId;
                     } else {
                         $id = wp_insert_term($term->term->name, $taxonomy->slug, $args);
                         $term->id = $id['term_id'];
                     }
                     $term->done = true;
                 } else {
                     ++$deferred;
                 }
             }
             if ($deferred == 0) {
                 $done = true;
             }
         }
     }
 }
 function woocommerce_osc_run_cats($parent = 0, $parent_term_id = 0)
 {
     global $wpdb, $oscdb, $import_cat_counter;
     $categories = $oscdb->get_results("SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id='" . (int) $parent . "'", ARRAY_A);
     if (!empty($categories)) {
         foreach ($categories as $category) {
             if (!is_wp_error($category)) {
                 $term = term_exists($category['categories_name'], 'product_cat', (int) $parent_term_id);
                 // array is returned if taxonomy is given
                 if ((int) $term['term_id'] == 0) {
                     $term = wp_insert_term($category['categories_name'], 'product_cat', array('parent' => $parent_term_id));
                     delete_option('product_cat_children');
                     // clear the cache
                     $attach_id = 0;
                     if ($category['categories_image'] != '') {
                         $url = rtrim($_POST['store_url'], '/') . '/images/' . urlencode($category['categories_image']);
                         $attach_id = woocommerce_osc_import_image($url);
                     }
                     add_woocommerce_term_meta($term['term_id'], 'order', $category['sort_order']);
                     add_woocommerce_term_meta($term['term_id'], 'display_type', '');
                     add_woocommerce_term_meta($term['term_id'], 'thumbnail_id', (int) $attach_id);
                     add_woocommerce_term_meta($term['term_id'], 'osc_id', $category['categories_id']);
                     woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
                     $import_cat_counter++;
                 } else {
                     woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
                 }
             }
         }
     }
 }
Example #8
0
function un_do_db_upgrade()
{
    global $un_default_options, $wp_roles, $wpdb;
    $icons = array('idea' => 'icon-lightbulb', 'question' => 'icon-question-sign', 'problem' => 'icon-exclamation-sign', 'praise' => 'icon-heart');
    $plural = array('idea' => __('Ideas', 'usernoise'), 'question' => __('Questions', 'usernoise'), 'problem' => __('Problems', 'usernoise'), 'praise' => __('Praises', 'usernoise'));
    $index = 0;
    $wpdb->un_termmeta = $wpdb->prefix . "un_termmeta";
    if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->un_termmeta}'") != $wpdb->un_termmeta) {
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        $sql = "CREATE TABLE `{$wpdb->un_termmeta}` (\n\t\t\t`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`un_term_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t`meta_key` varchar(255) DEFAULT NULL,\n\t\t\t`meta_value` longtext,\n\t\t\tPRIMARY KEY (`meta_id`),\n\t\t\tKEY `un_term_id` (`un_term_id`),\n\t\t\tKEY `meta_key` (`meta_key`)\n\t\t);";
        dbDelta($sql);
    }
    foreach (array('idea' => __('Idea', 'usernoise'), 'question' => __('Question', 'usernoise'), 'problem' => __('Problem', 'usernoise'), 'praise' => __('Praise', 'usernoise')) as $type => $value) {
        if (null == ($term = get_term_by('slug', $type, 'feedback_type', ARRAY_A))) {
            $term = wp_insert_term($value, FEEDBACK_TYPE, array('slug' => $type));
        }
        if (null == un_get_term_meta($term['term_id'], 'icon')) {
            un_add_term_meta($term['term_id'], 'icon', $icons[$type], true);
            un_add_term_meta($term['term_id'], 'plural', $plural[$type], true);
            un_add_term_meta($term['term_id'], 'position', $index, true);
        }
        $index++;
    }
    if (!isset($wp_roles)) {
        $wp_roles = new WP_Roles();
    }
    foreach (un_get_capable_roles() as $role) {
        foreach (un_get_feedback_capabilities() as $cap) {
            $wp_roles->add_cap($role, $cap);
        }
    }
    update_option('un_db_revision', '2');
}
Example #9
0
/**
 * Post installation procedures
 */
function podcasting_install()
{
    # Setup the default taxonomy
    wp_insert_term('Default Format', 'podcast_format');
    # Add Podcasting options to the database
    add_option('pod_title', get_option('blogname'), "The podcast's title");
    add_option('pod_tagline', get_option('blogdescription'), "The podcast's tagline");
    add_option('pod_disabled_enclose', false);
    add_option('pod_itunes_summary', '', 'iTunes summary');
    add_option('pod_itunes_author', '', 'iTunes author');
    add_option('pod_itunes_image', '', 'iTunes image');
    add_option('pod_itunes_cat1', '', 'iTunes category 1');
    add_option('pod_itunes_cat2', '', 'iTunes category 2');
    add_option('pod_itunes_cat3', '', 'iTunes category 3');
    add_option('pod_itunes_keywords', '', 'iTunes keywords');
    add_option('pod_itunes_explicit', '', 'iTunes explicit');
    add_option('pod_itunes_new-feed-url', '', 'iTunes new feed url');
    add_option('pod_itunes_ownername', '', 'iTunes owner name');
    add_option('pod_itunes_owneremail', '', 'iTunes owner email');
    add_option('pod_formats', '', 'Explict settings for podcast formats');
    add_option('pod_player_flashvars', '', 'Podcasting player flashvars');
    add_option('pod_audio_width', '290', 'Podcasting player width');
    add_option('pod_player_use_video', 'no');
    add_option('pod_player_location', '', '');
    add_option('pod_player_text_above', '', '');
    add_option('pod_player_text_before', '', '');
    add_option('pod_player_text_below', '', '');
    add_option('pod_player_text_link', '', '');
    add_option('pod_player_width', '400', 'Podcast player width');
    add_option('pod_player_height', '300', 'Podcast player height');
    add_option('pod_video_flashvars', '', 'Podcasting video flashvars');
    add_option('pod_accept_fail', 'no', 'Accept enclosure failure');
}
Example #10
0
function dt_geodir_default_taxonomies($post_type, $categories, $folder_name)
{
    global $wpdb, $dummy_image_path;
    $cat_count = count($categories);
    for ($i = 0; $i < $cat_count; $i++) {
        $parent_catid = 0;
        if (is_array($categories[$i])) {
            $cat_name_arr = $categories[$i];
            $count_cat_name_arr = count($cat_name_arr);
            for ($j = 0; $j < $count_cat_name_arr; $j++) {
                $catname = $cat_name_arr[$j];
                if (!term_exists($catname, $post_type . 'category')) {
                    $last_catid = wp_insert_term($catname, $post_type . 'category', $args = array('parent' => $parent_catid));
                    if ($j == 0) {
                        $parent_catid = $last_catid;
                    }
                    dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid);
                }
            }
        } else {
            $catname = $categories[$i];
            if (!term_exists($catname, $post_type . 'category')) {
                $last_catid = wp_insert_term($catname, $post_type . 'category');
                dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid);
            }
        }
    }
}
 private function categorize($post_id, $categories_str)
 {
     $categories_arr = explode(',', $categories_str);
     foreach ($categories_arr as $category) {
         $categories_par = explode('>', $category);
         if (!isset($categories_par[0], $categories_par[1])) {
             $this->err($category, $post_id);
         }
         $categories_par[0] = trim($categories_par[0]);
         $categories_par[1] = trim($categories_par[1]);
         $parent_term = term_exists($categories_par[0], 'venture_categories');
         if (!$parent_term) {
             $parent_term = wp_insert_term($categories_par[0], 'venture_categories');
         }
         $parent_term_id = intval($parent_term['term_id']);
         $term = term_exists($categories_par[1], 'venture_categories', $parent_term_id);
         if (!$term) {
             $term = wp_insert_term($categories_par[1], 'venture_categories', array('parent' => $parent_term_id));
         }
         if (is_wp_error($term)) {
             $this->err($category, $post_id);
         }
         $term_id = intval($term['term_id']);
         wp_set_object_terms($post_id, $parent_term_id, 'venture_categories', true);
         wp_set_object_terms($post_id, $term_id, 'venture_categories', true);
     }
 }
Example #12
0
 public function vtprd_add_dummy_rule_category()
 {
     $category_list = get_terms('vtprd_rule_category', 'hide_empty=0&parent=0');
     if (count($category_list) == 0) {
         wp_insert_term(__('Pricing Deals Category', 'vtprd'), 'vtprd_rule_category', "parent=0");
     }
 }
Example #13
0
 public function vtwpr_add_dummy_rule_category()
 {
     $category_list = get_terms('vtwpr_rule_category', 'hide_empty=0&parent=0');
     if (count($category_list) == 0) {
         wp_insert_term(__('Wholesale Pricing Category', 'vtwpr'), 'vtwpr_rule_category', "parent=0");
     }
 }
 public function vtmin_add_dummy_rule_category()
 {
     $category_list = get_terms('vtmin_rule_category', 'hide_empty=0&parent=0');
     if (count($category_list) == 0) {
         wp_insert_term(__('Minimum Purchase Category', 'vtmin'), 'vtmin_rule_category', "parent=0");
     }
 }
Example #15
0
 function set_up_0_4_0_test_posts()
 {
     update_option('wp_gistpen_version', '0.3.1');
     register_post_type('gistpens', array());
     register_taxonomy('language', array('gistpens'));
     foreach (Language::$supported as $lang => $slug) {
         $result = wp_insert_term($lang, 'language', array('slug' => $slug));
         if (is_wp_error($result)) {
             throw new Exception("Failed to insert term.");
         }
     }
     $terms = get_terms('language', 'hide_empty=0');
     foreach ($terms as $term) {
         $languages[] = $term->slug;
     }
     $num_posts = count($languages);
     $this->gistpens = $this->factory->post->create_many($num_posts, array('post_type' => 'gistpens', 'post_status' => 'publish'), array('post_title' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_name' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_content' => new WP_UnitTest_Generator_Sequence('Post content %s')));
     foreach ($this->gistpens as $gistpen_id) {
         // Pick a random language
         $num_posts = $num_posts - 1;
         $lang_num = rand(0, $num_posts);
         // Get the language's id
         $lang_slug = $languages[$lang_num];
         // Remove the language and reindex the languages array
         unset($languages[$lang_num]);
         $languages = array_values($languages);
         // Give the post a description
         update_post_meta($gistpen_id, '_wpgp_gistpen_description', 'This is a description of the Gistpen.');
         // Give the post the language
         wp_set_object_terms($gistpen_id, $lang_slug, 'language', false);
         // Create and set up the user
         $user_id = $this->factory->user->create(array('role' => 'administrator'));
         wp_set_current_user($user_id);
     }
 }
Example #16
0
function avia_temp_products()
{
    if (post_type_exists('product')) {
        return false;
    }
    $product_base = $base_slug = $category_base = "";
    register_taxonomy('product_cat', array('product'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Categories', 'woothemes'), 'labels' => array('name' => __('Categories', 'woothemes'), 'singular_name' => __('Product Category', 'woothemes'), 'search_items' => __('Search Product Categories', 'woothemes'), 'all_items' => __('All Product Categories', 'woothemes'), 'parent_item' => __('Parent Product Category', 'woothemes'), 'parent_item_colon' => __('Parent Product Category:', 'woothemes'), 'edit_item' => __('Edit Product Category', 'woothemes'), 'update_item' => __('Update Product Category', 'woothemes'), 'add_new_item' => __('Add New Product Category', 'woothemes'), 'new_item_name' => __('New Product Category Name', 'woothemes')), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . _x('product-category', 'slug', 'woothemes'), 'with_front' => false)));
    register_taxonomy('product_tag', array('product'), array('hierarchical' => false, 'label' => __('Tags', 'woothemes'), 'labels' => array('name' => __('Tags', 'woothemes'), 'singular_name' => __('Product Tag', 'woothemes'), 'search_items' => __('Search Product Tags', 'woothemes'), 'all_items' => __('All Product Tags', 'woothemes'), 'parent_item' => __('Parent Product Tag', 'woothemes'), 'parent_item_colon' => __('Parent Product Tag:', 'woothemes'), 'edit_item' => __('Edit Product Tag', 'woothemes'), 'update_item' => __('Update Product Tag', 'woothemes'), 'add_new_item' => __('Add New Product Tag', 'woothemes'), 'new_item_name' => __('New Product Tag Name', 'woothemes')), 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $category_base . _x('product-tag', 'slug', 'woothemes'), 'with_front' => false)));
    register_post_type("product", array('labels' => array('name' => __('Products', 'woothemes'), 'singular_name' => __('Product', 'woothemes'), 'add_new' => __('Add Product', 'woothemes'), 'add_new_item' => __('Add New Product', 'woothemes'), 'edit' => __('Edit', 'woothemes'), 'edit_item' => __('Edit Product', 'woothemes'), 'new_item' => __('New Product', 'woothemes'), 'view' => __('View Product', 'woothemes'), 'view_item' => __('View Product', 'woothemes'), 'search_items' => __('Search Products', 'woothemes'), 'not_found' => __('No Products found', 'woothemes'), 'not_found_in_trash' => __('No Products found in trash', 'woothemes'), 'parent' => __('Parent Product', 'woothemes')), 'description' => __('This is where you can add new products to your store.', 'woothemes'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => true, 'rewrite' => array('slug' => $product_base, 'with_front' => false), 'query_var' => true, 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments'), 'has_archive' => $base_slug, 'show_in_nav_menus' => false));
    register_post_type("product_variation", array('labels' => array('name' => __('Variations', 'woothemes'), 'singular_name' => __('Variation', 'woothemes'), 'add_new' => __('Add Variation', 'woothemes'), 'add_new_item' => __('Add New Variation', 'woothemes'), 'edit' => __('Edit', 'woothemes'), 'edit_item' => __('Edit Variation', 'woothemes'), 'new_item' => __('New Variation', 'woothemes'), 'view' => __('View Variation', 'woothemes'), 'view_item' => __('View Variation', 'woothemes'), 'search_items' => __('Search Variations', 'woothemes'), 'not_found' => __('No Variations found', 'woothemes'), 'not_found_in_trash' => __('No Variations found in trash', 'woothemes'), 'parent' => __('Parent Variation', 'woothemes')), 'public' => true, 'show_ui' => false, 'capability_type' => 'post', 'publicly_queryable' => true, 'exclude_from_search' => true, 'hierarchical' => true, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail'), 'show_in_nav_menus' => false));
    register_taxonomy('product_type', array('product'), array('hierarchical' => false, 'show_ui' => false, 'query_var' => true, 'show_in_nav_menus' => false));
    register_post_type("shop_order", array('labels' => array('name' => __('Orders', 'woothemes'), 'singular_name' => __('Order', 'woothemes'), 'add_new' => __('Add Order', 'woothemes'), 'add_new_item' => __('Add New Order', 'woothemes'), 'edit' => __('Edit', 'woothemes'), 'edit_item' => __('Edit Order', 'woothemes'), 'new_item' => __('New Order', 'woothemes'), 'view' => __('View Order', 'woothemes'), 'view_item' => __('View Order', 'woothemes'), 'search_items' => __('Search Orders', 'woothemes'), 'not_found' => __('No Orders found', 'woothemes'), 'not_found_in_trash' => __('No Orders found in trash', 'woothemes'), 'parent' => __('Parent Orders', 'woothemes')), 'description' => __('This is where store orders are stored.', 'woothemes'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => 'woocommerce', 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => true, 'supports' => array('title', 'comments', 'custom-fields'), 'has_archive' => false));
    register_taxonomy('shop_order_status', array('shop_order'), array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => __('Order statuses', 'woothemes'), 'singular_name' => __('Order status', 'woothemes'), 'search_items' => __('Search Order statuses', 'woothemes'), 'all_items' => __('All  Order statuses', 'woothemes'), 'parent_item' => __('Parent Order status', 'woothemes'), 'parent_item_colon' => __('Parent Order status:', 'woothemes'), 'edit_item' => __('Edit Order status', 'woothemes'), 'update_item' => __('Update Order status', 'woothemes'), 'add_new_item' => __('Add New Order status', 'woothemes'), 'new_item_name' => __('New Order status Name', 'woothemes')), 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => true, 'rewrite' => false));
    register_post_type("shop_coupon", array('labels' => array('name' => __('Coupons', 'woothemes'), 'singular_name' => __('Coupon', 'woothemes'), 'add_new' => __('Add Coupon', 'woothemes'), 'add_new_item' => __('Add New Coupon', 'woothemes'), 'edit' => __('Edit', 'woothemes'), 'edit_item' => __('Edit Coupon', 'woothemes'), 'new_item' => __('New Coupon', 'woothemes'), 'view' => __('View Coupons', 'woothemes'), 'view_item' => __('View Coupon', 'woothemes'), 'search_items' => __('Search Coupons', 'woothemes'), 'not_found' => __('No Coupons found', 'woothemes'), 'not_found_in_trash' => __('No Coupons found in trash', 'woothemes'), 'parent' => __('Parent Coupon', 'woothemes')), 'description' => __('This is where you can add new coupons that customers can use in your store.', 'woothemes'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'publicly_queryable' => true, 'exclude_from_search' => true, 'show_in_menu' => 'woocommerce', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title'), 'show_in_nav_menus' => false));
    if (!taxonomy_exists('product_type')) {
        register_taxonomy('product_type', array('post'));
        register_taxonomy('shop_order_status', array('post'));
    }
    $product_types = array('simple', 'grouped', 'variable', 'downloadable', 'virtual');
    foreach ($product_types as $type) {
        if (!get_term_by('slug', sanitize_title($type), 'product_type')) {
            wp_insert_term($type, 'product_type');
        }
    }
    $order_status = array('pending', 'failed', 'on-hold', 'processing', 'completed', 'refunded', 'cancelled');
    foreach ($order_status as $status) {
        if (!get_term_by('slug', sanitize_title($status), 'shop_order_status')) {
            wp_insert_term($status, 'shop_order_status');
        }
    }
}
Example #17
0
 public function createCategoryTaxonomy()
 {
     $labels = array('name' => "Category", 'singular_name' => "Category", 'update_item' => "Update Category", 'add_new_item' => "Add a new Category", 'new_item_name' => "New Category Name");
     register_taxonomy(self::TAXONOMY, array(self::DIRECTOR_POST_TYPE), array('hierarchical' => true, 'labels' => $labels, 'query_var' => self::TAXONOMY, 'rewrite' => array('slug' => self::TAXONOMY_URL)));
     wp_insert_term("Board", self::TAXONOMY, array("description" => "this is for board entries", "slug" => "board"));
     wp_insert_term("Media", self::TAXONOMY, array("description" => "this is for media releases", "slug" => "media"));
 }
Example #18
0
function create_term_type_coat()
{
    // T-shirt
    wp_insert_term('t-shirt', 'type', array('description' => 'Just t-shirt', 'slug' => 't-shirt'));
    // Pull
    wp_insert_term('pull', 'type', array('description' => 'Just pull', 'slug' => 'pull'));
}
 /**
  * Set installed option and default settings / terms
  *
  * @since 1.0
  */
 private function maybe_install()
 {
     global $woocommerce;
     $installed_version = get_option('wc_pre_orders_version');
     // install
     if (!$installed_version) {
         // add 'pre-order' shop order status term
         $woocommerce->init_taxonomy();
         if (!get_term_by('slug', 'pre-ordered', 'shop_order_status')) {
             wp_insert_term('pre-ordered', 'shop_order_status');
         }
         // install default settings
         foreach ($this->get_settings() as $setting) {
             if (isset($setting['default'])) {
                 update_option($setting['id'], $setting['default']);
             }
         }
     }
     // upgrade - installed version lower than plugin version?
     if (-1 === version_compare($installed_version, WC_Pre_Orders::VERSION)) {
         $this->upgrade($installed_version);
         // new version number
         update_option('wc_pre_orders_version', WC_Pre_Orders::VERSION);
     }
 }
 function new_term($path, $blog_id, $taxonomy)
 {
     $args = $this->query_args();
     $input = $this->input();
     if (!is_array($input) || !$input || !strlen($input['name'])) {
         return new WP_Error('invalid_input', 'Unknown data passed', 400);
     }
     $tax = get_taxonomy($taxonomy);
     if (!current_user_can($tax->cap->manage_terms)) {
         return new WP_Error('unauthorized', 'User cannot edit taxonomy', 403);
     }
     if (!isset($input['parent']) || !is_taxonomy_hierarchical($taxonomy)) {
         $input['parent'] = 0;
     }
     if ($term = get_term_by('name', $input['name'], $taxonomy)) {
         // get_term_by is not case-sensitive, but a name with different casing is allowed
         // also, the exact same name is allowed as long as the parents are different
         if ($input['name'] === $term->name && $input['parent'] === $term->parent) {
             return new WP_Error('duplicate', 'A taxonomy with that name already exists', 409);
         }
     }
     $data = wp_insert_term(addslashes($input['name']), $taxonomy, array('description' => addslashes($input['description']), 'parent' => $input['parent']));
     if (is_wp_error($data)) {
         return $data;
     }
     $term = get_term_by('id', $data['term_id'], $taxonomy);
     $return = $this->get_taxonomy($term->slug, $taxonomy, $args['context']);
     if (!$return || is_wp_error($return)) {
         return $return;
     }
     /** This action is documented in json-endpoints/class.wpcom-json-api-site-settings-endpoint.php */
     do_action('wpcom_json_api_objects', 'terms');
     return $return;
 }
 function new_taxonomy($path, $blog_id, $taxonomy_type)
 {
     $args = $this->query_args();
     $input = $this->input();
     if (!is_array($input) || !$input || !strlen($input['name'])) {
         return new WP_Error('unknown_taxonomy', 'Unknown data passed', 404);
     }
     $user = wp_get_current_user();
     if (!$user || is_wp_error($user) || !$user->ID) {
         return new WP_Error('authorization_required', 'An active access token must be used to manage taxonomies.', 403);
     }
     $tax = get_taxonomy($taxonomy_type);
     if (!current_user_can($tax->cap->edit_terms)) {
         return new WP_Error('unauthorized', 'User cannot edit taxonomy', 403);
     }
     if (term_exists($input['name'], $taxonomy_type)) {
         return new WP_Error('unknown_taxonomy', 'A taxonomy with that name already exists', 404);
     }
     if ('category' !== $taxonomy_type) {
         $input['parent'] = 0;
     }
     $data = wp_insert_term(addslashes($input['name']), $taxonomy_type, array('description' => addslashes($input['description']), 'parent' => $input['parent']));
     if (is_wp_error($data)) {
         return $data;
     }
     $taxonomy = get_term_by('id', $data['term_id'], $taxonomy_type);
     $return = $this->get_taxonomy($taxonomy->slug, $taxonomy_type, $args['context']);
     if (!$return || is_wp_error($return)) {
         return $return;
     }
     do_action('wpcom_json_api_objects', 'taxonomies');
     return $return;
 }
Example #22
0
 /**
  * Testing Sensei_Core_Modules::get_term_author
  */
 public function testGetTermAuthor()
 {
     // setup assertions
     $test_user_id = wp_create_user('teacherGetTermAuthor', 'teacherGetTermAuthor', '*****@*****.**');
     //insert a general term
     wp_insert_term('Get Started', 'module');
     //insert a term as if from the user
     wp_insert_term('Get Started Today', 'module', array('description' => 'A yummy apple.', 'slug' => $test_user_id . '-get-started-today'));
     // does the function exist?
     $this->assertTrue(method_exists('Sensei_Core_Modules', 'get_term_authors'), 'The function Sensei_Core_Modules::get_term_author does not exist ');
     // does the taxonomy exist
     $module_taxonomy = get_taxonomy('module');
     $this->assertTrue($module_taxonomy->public, 'The module taxonomy is not loaded');
     // does it return empty array id for bogus term nam?
     $term_authors = Sensei_Core_Modules::get_term_authors('bogusnonexistan');
     $this->assertTrue(empty($term_authors), 'The function should return false for an invalid term');
     //does it return the admin user for a valid term ?
     $admin = get_user_by('email', get_bloginfo('admin_email'));
     $term_authors = Sensei_Core_Modules::get_term_authors('Get Started');
     $this->assertTrue($admin == $term_authors[0], 'The function should return admin user for normal module term.');
     // does it return the expected new user for the given term registered with that id in front of the slug?
     $term_authors = Sensei_Core_Modules::get_term_authors('Get Started Today');
     $this->assertTrue(get_userdata($test_user_id) == $term_authors[0], 'The function should admin user for normal module term.');
     // what about terms with the same name but different slug?
     // It should return 2 authors as we've created 2 with the same name
     // insert a term that is the same as the first one
     wp_insert_term('Get Started', 'module', array('description' => 'A yummy apple.', 'slug' => $test_user_id . '-get-started'));
     $term_authors = Sensei_Core_Modules::get_term_authors('Get Started');
     $this->assertTrue(2 == count($term_authors), 'The function should admin user for normal module term.');
 }
 function setUp()
 {
     parent::setUp();
     $this->parent_term = wp_insert_term('parent' . rand_str(), 'category');
     $this->assertInternalType('array', $this->parent_term);
     $this->parent_term = $this->parent_term['term_id'];
 }
function add_new_category()
{
    if (is_user_logged_in()) {
        if (isset($_POST['cat_name']) && !empty($_POST['cat_name']) && isset($_POST['parent_id']) && !empty($_POST['parent_id'])) {
            $cat_name = esc_html($_POST['cat_name']);
            $parent_id = esc_html($_POST['parent_id']);
            $new_cat_args = array($cat_name, 'bookmark-category');
            if ($parent_id == -1) {
                // Add Term to Bookmark Category
                $new_category = wp_insert_term($cat_name, 'bookmark-category');
            } else {
                // Add Term to Bookmark Category
                $new_category = wp_insert_term($cat_name, 'bookmark-category', array('parent' => $parent_id));
            }
            if (!is_wp_error($new_category)) {
                $term = get_term_by('id', $new_category['term_id'], 'bookmark-category');
                // Add Term to User
                wp_set_object_terms($current_user->ID, array($term->slug), 'bookmark-category', true);
                $returner = array('success' => true, 'cat_id' => $new_category['term_id'], 'cat_slug' => $term->slug, 'cat_link' => get_term_link($term, 'bookmark-category'));
            } else {
                $returner = array('success' => false, 'reason' => 'WP Error on term creation.');
            }
        } else {
            $returner = array('success' => false, 'reason' => 'Post values not set.');
        }
    } else {
        $returner = array('success' => false, 'reason' => 'User not logged in.');
    }
    echo json_encode($returner);
    exit;
}
function rcl_update_grouppost_meta($post_id, $postdata, $action)
{
    if ($postdata['post_type'] != 'post-group') {
        return false;
    }
    if (isset($_POST['term_id'])) {
        $term_id = intval(base64_decode($_POST['term_id']));
    }
    if (isset($term_id)) {
        wp_set_object_terms($post_id, (int) $term_id, 'groups');
    }
    $gr_tag = sanitize_text_field($_POST['group-tag']);
    if ($gr_tag) {
        if (!$term_id) {
            $groups = get_the_terms($post_id, 'groups');
            foreach ($groups as $group) {
                if ($group->parent != 0) {
                    continue;
                }
                $group_id = $group->term_id;
            }
        } else {
            $group_id = $term_id;
        }
        $term = term_exists($gr_tag, 'groups', $group_id);
        if (!$term) {
            $term = wp_insert_term($gr_tag, 'groups', array('description' => '', 'slug' => '', 'parent' => $group_id));
        }
        wp_set_object_terms($post_id, array((int) $term['term_id'], (int) $group_id), 'groups');
    }
}
Example #26
0
function create_defualt_taxonomy()
{
    if (!DEFAULT_VIDEO_CATEGORY) {
        $defaultTaxonomy = wp_insert_term('All videos', DEFAULT_VIDEO_TAXONOMY, array('description' => 'All videos', 'slug' => 'all'));
        update_option('default_video_category', $defaultTaxonomy["term_id"]);
    }
}
 public function setUp()
 {
     global $wpdb;
     parent::setUp();
     register_taxonomy('edu_test_tax_1', 'post');
     register_taxonomy('edu_test_tax_2', 'post');
     $t1 = wp_insert_term('Edu', 'edu_test_tax_1');
     $t2 = wp_insert_term('Edu', 'edu_test_tax_2');
     $t3 = wp_insert_term('Edu', 'ib_educator_category');
     $t4 = wp_insert_term('Mathematics', 'ib_educator_category');
     // Arbitrary term.
     $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t2['term_taxonomy_id']), array('%d'), array('%d'));
     $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t3['term_taxonomy_id']), array('%d'), array('%d'));
     $t2['term_id'] = $t1['term_id'];
     $t3['term_id'] = $t1['term_id'];
     // Create membership.
     $post_id = wp_insert_post(array('post_type' => 'ib_edu_membership', 'post_name' => 'edu-membership-1', 'post_title' => 'edu membership 1', 'post_status' => 'publish'));
     $ms = Edr_Memberships::get_instance();
     $meta = $ms->get_membership_meta();
     $meta['price'] = '10.05';
     $meta['period'] = '';
     $meta['duration'] = '';
     $meta['categories'] = array($t3['term_id'], $t4['term_id']);
     update_post_meta($post_id, '_ib_educator_membership', $meta);
     $this->posts[] = $post_id;
     $this->terms = array('term1' => $t1, 'term2' => $t2, 'term3' => $t3, 'term4' => $t4);
 }
Example #28
0
/**
 * Register the prominence and series custom taxonomies
 * Insert the default terms
 *
 * @uses  largo_is_series_enabled
 * @since 1.0
 */
function largo_custom_taxonomies()
{
    if (!taxonomy_exists('prominence')) {
        register_taxonomy('prominence', 'post', array('hierarchical' => true, 'labels' => array('name' => _x('Post Prominence', 'taxonomy general name'), 'singular_name' => _x('Post Prominence', 'taxonomy singular name'), 'search_items' => __('Search Post Prominences'), 'all_items' => __('All Post Prominences'), 'parent_item' => __('Parent Post Prominence'), 'parent_item_colon' => __('Parent Post Prominence:'), 'edit_item' => __('Edit Post Prominence'), 'view_item' => __('View Post Prominence'), 'update_item' => __('Update Post Prominence'), 'add_new_item' => __('Add New Post Prominence'), 'new_item_name' => __('New Post Prominence Name'), 'menu_name' => __('Post Prominence')), 'query_var' => true, 'rewrite' => true));
    }
    $termsDefinitions = array(array('name' => __('Sidebar Featured Widget', 'largo'), 'description' => __('If you are using the Featured Posts widget in a sidebar, add this label to posts to determine which to display in the widget.', 'largo'), 'slug' => 'sidebar-featured'), array('name' => __('Footer Featured Widget', 'largo'), 'description' => __('If you are using the Featured Posts widget in the footer, add this label to posts to determine which to display in the widget.', 'largo'), 'slug' => 'footer-featured'), array('name' => __('Featured in Category', 'largo'), 'description' => __('This will allow you to designate a story to appear more prominently on category archive pages.', 'largo'), 'slug' => 'category-featured'), array('name' => __('Homepage Featured', 'largo'), 'description' => __('Add this label to posts to display them in the featured area on the homepage.', 'largo'), 'slug' => 'homepage-featured'));
    if (largo_is_series_enabled()) {
        $termsDefinitions[] = array('name' => __('Featured in Series', 'largo'), 'description' => __('Select this option to allow this post to float to the top of any/all series landing pages sorting by Featured first.', 'largo'), 'slug' => 'series-featured');
    }
    $largoProminenceTerms = apply_filters('largo_prominence_terms', $termsDefinitions);
    $changed = false;
    $terms = get_terms('prominence', array('hide_empty' => false, 'fields' => 'all'));
    $names = array_map(function ($arg) {
        return $arg->name;
    }, $terms);
    $term_ids = array();
    foreach ($largoProminenceTerms as $term) {
        if (!in_array($term['name'], $names)) {
            wp_insert_term($term['name'], 'prominence', array('description' => $term['description'], 'slug' => $term['slug']));
            $changed = true;
        }
    }
    if ($changed) {
        delete_option('prominence_children');
    }
    do_action('largo_after_create_prominence_taxonomy', $largoProminenceTerms);
    if (!taxonomy_exists('series')) {
        register_taxonomy('series', 'post', array('hierarchical' => true, 'labels' => array('name' => _x('Series', 'taxonomy general name'), 'singular_name' => _x('Series', 'taxonomy singular name'), 'search_items' => __('Search Series'), 'all_items' => __('All Series'), 'parent_item' => __('Parent Series'), 'parent_item_colon' => __('Parent Series:'), 'edit_item' => __('Edit Series'), 'view_item' => __('View Series'), 'update_item' => __('Update Series'), 'add_new_item' => __('Add New Series'), 'new_item_name' => __('New Series Name'), 'menu_name' => __('Series')), 'query_var' => true, 'rewrite' => true));
    }
}
Example #29
0
 /**
  *
  * Assigns random terms to all posts in a taxonomy.
  *
  * By default all objects of the 'post' post type will be randomized, use the
  * --post_type flag to target pages or a custom post type. Use the --include 
  * and --exclude flags to filter or ignore specific object IDs and the --before
  * and --after flags to specify a date range. Also, optionally pass --terms as
  * a list of terms you want to use for the randomization. If terms exist in the
  * target taxonomy, those terms will be used. If not, a string of 6 words 
  * generated randomly will be used for the randomization.
  * 
  * ## Options
  *
  * <taxonomy>
  * : The taxonomy that should get randomized
  *
  * ## Exmples
  *
  *     wp randomize category
  *     
  * @synopsis <taxonomy> [--include=<bar>] [--exclude=<foo>] [--post_type=<foo>] 
  * [--before=<bar>] [--after=<date>] [--terms=<terms>]
  * 
  **/
 public function taxonomy($args, $assoc_args)
 {
     $taxonomy = $args[0];
     $get_posts = $this->get_specified_posts($assoc_args);
     $message = $get_posts['message'];
     $posts = $get_posts['posts'];
     $args = $get_posts['args'];
     $preamble = "Will assign random {$taxonomy} terms";
     print_r("{$preamble} {$message}.\n");
     if (isset($assoc_args['terms'])) {
         $terms = explode(',', $assoc_args['terms']);
         \WP_CLI::log('Using terms ' . $assoc_args['terms']);
     } else {
         \WP_CLI::log('Gathering and processing random terms.');
         $terms = $this->get_random_terms();
         \WP_CLI::log('No term list given, using random terms.');
     }
     foreach ($posts as $p) {
         $index = array_rand($terms);
         $term = $terms[$index];
         \WP_CLI::log("Assigning {$term} to taxonomy {$taxonomy} for {$p->post_type} {$p->ID}");
         if (!term_exists($term, $taxonomy)) {
             wp_insert_term($term, $taxonomy);
         }
         wp_set_object_terms($p->ID, $term, $taxonomy, $append = false);
     }
 }
function pmxi_recursion_taxes($parent, $tx_name, $txes, $key)
{
    if (is_array($parent)) {
        $parent['name'] = sanitize_text_field($parent['name']);
        if (empty($parent['parent'])) {
            $term = is_exists_term($tx_name, $parent['name']);
            if (empty($term) and !is_wp_error($term)) {
                $term = wp_insert_term($parent['name'], $tx_name);
            }
            return !is_wp_error($term) ? $term['term_id'] : 0;
        } else {
            $parent_id = pmxi_recursion_taxes($parent['parent'], $tx_name, $txes, $key);
            $term = is_exists_term($tx_name, $parent['name'], (int) $parent_id);
            if (empty($term) and !is_wp_error($term)) {
                $term = wp_insert_term($parent, $tx_name, array('parent' => !empty($parent_id) ? (int) $parent_id : 0));
            }
            return !is_wp_error($term) ? $term['term_id'] : 0;
        }
    } else {
        if (!empty($txes[$key - 1]) and !empty($txes[$key - 1]['parent']) and $parent != $txes[$key - 1]['parent']) {
            $parent_id = pmxi_recursion_taxes($txes[$key - 1]['parent'], $tx_name, $txes, $key - 1);
            $term = is_exists_term($tx_name, $parent, (int) $parent_id);
            if (empty($term) and !is_wp_error($term)) {
                $term = wp_insert_term($parent, $tx_name, array('parent' => !empty($parent_id) ? (int) $parent_id : 0));
            }
            return !is_wp_error($term) ? $term['term_id'] : 0;
        } else {
            $term = is_exists_term($tx_name, $parent);
            if (empty($term) and !is_wp_error($term)) {
                $term = wp_insert_term($parent, $tx_name);
            }
            return !is_wp_error($term) ? $term['term_id'] : 0;
        }
    }
}