WC_Post_types::register_taxonomies PHP Метод

register_taxonomies() публичный статический Метод

Register core taxonomies.
public static register_taxonomies ( )
    public static function register_taxonomies()
    {
        if (!is_blog_installed()) {
            return;
        }
        if (taxonomy_exists('product_type')) {
            return;
        }
        do_action('woocommerce_register_taxonomy');
        $permalinks = get_option('woocommerce_permalinks');
        register_taxonomy('product_type', apply_filters('woocommerce_taxonomy_objects_product_type', array('product')), apply_filters('woocommerce_taxonomy_args_product_type', array('hierarchical' => false, 'show_ui' => false, 'show_in_nav_menus' => false, 'query_var' => is_admin(), 'rewrite' => false, 'public' => false)));
        register_taxonomy('product_cat', apply_filters('woocommerce_taxonomy_objects_product_cat', array('product')), apply_filters('woocommerce_taxonomy_args_product_cat', array('hierarchical' => true, 'update_count_callback' => '_wc_term_recount', 'label' => __('Categories', 'woocommerce'), 'labels' => array('name' => __('Product categories', 'woocommerce'), 'singular_name' => __('Category', 'woocommerce'), 'menu_name' => _x('Categories', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search categories', 'woocommerce'), 'all_items' => __('All categories', 'woocommerce'), 'parent_item' => __('Parent category', 'woocommerce'), 'parent_item_colon' => __('Parent category:', 'woocommerce'), 'edit_item' => __('Edit category', 'woocommerce'), 'update_item' => __('Update category', 'woocommerce'), 'add_new_item' => __('Add new category', 'woocommerce'), 'new_item_name' => __('New category name', 'woocommerce'), 'not_found' => __('No categories found', 'woocommerce')), 'show_ui' => true, 'query_var' => true, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => array('slug' => empty($permalinks['category_base']) ? _x('product-category', 'slug', 'woocommerce') : $permalinks['category_base'], 'with_front' => false, 'hierarchical' => true))));
        register_taxonomy('product_tag', apply_filters('woocommerce_taxonomy_objects_product_tag', array('product')), apply_filters('woocommerce_taxonomy_args_product_tag', array('hierarchical' => false, 'update_count_callback' => '_wc_term_recount', 'label' => __('Product tags', 'woocommerce'), 'labels' => array('name' => __('Product tags', 'woocommerce'), 'singular_name' => __('Tag', 'woocommerce'), 'menu_name' => _x('Tags', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search tags', 'woocommerce'), 'all_items' => __('All tags', 'woocommerce'), 'edit_item' => __('Edit tag', 'woocommerce'), 'update_item' => __('Update tag', 'woocommerce'), 'add_new_item' => __('Add new tag', 'woocommerce'), 'new_item_name' => __('New tag name', 'woocommerce'), 'popular_items' => __('Popular tags', 'woocommerce'), 'separate_items_with_commas' => __('Separate tags with commas', 'woocommerce'), 'add_or_remove_items' => __('Add or remove tags', 'woocommerce'), 'choose_from_most_used' => __('Choose from the most used tags', 'woocommerce'), 'not_found' => __('No tags found', 'woocommerce')), 'show_ui' => true, 'query_var' => true, 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => array('slug' => empty($permalinks['tag_base']) ? _x('product-tag', 'slug', 'woocommerce') : $permalinks['tag_base'], 'with_front' => false))));
        register_taxonomy('product_shipping_class', apply_filters('woocommerce_taxonomy_objects_product_shipping_class', array('product', 'product_variation')), apply_filters('woocommerce_taxonomy_args_product_shipping_class', array('hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => __('Shipping classes', 'woocommerce'), 'labels' => array('name' => __('Product shipping classes', 'woocommerce'), 'singular_name' => __('Shipping class', 'woocommerce'), 'menu_name' => _x('Shipping classes', 'Admin menu name', 'woocommerce'), 'search_items' => __('Search shipping classes', 'woocommerce'), 'all_items' => __('All shipping classes', 'woocommerce'), 'parent_item' => __('Parent shipping class', 'woocommerce'), 'parent_item_colon' => __('Parent shipping class:', 'woocommerce'), 'edit_item' => __('Edit shipping class', 'woocommerce'), 'update_item' => __('Update shipping class', 'woocommerce'), 'add_new_item' => __('Add new shipping class', 'woocommerce'), 'new_item_name' => __('New shipping class Name', 'woocommerce')), 'show_ui' => false, 'show_in_quick_edit' => false, 'show_in_nav_menus' => false, 'query_var' => is_admin(), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'), 'rewrite' => false)));
        global $wc_product_attributes;
        $wc_product_attributes = array();
        if ($attribute_taxonomies = wc_get_attribute_taxonomies()) {
            foreach ($attribute_taxonomies as $tax) {
                if ($name = wc_attribute_taxonomy_name($tax->attribute_name)) {
                    $tax->attribute_public = absint(isset($tax->attribute_public) ? $tax->attribute_public : 1);
                    $label = !empty($tax->attribute_label) ? $tax->attribute_label : $tax->attribute_name;
                    $wc_product_attributes[$name] = $tax;
                    $taxonomy_data = array('hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'labels' => array('name' => sprintf(_x('Product %s', 'Product Attribute', 'woocommerce'), $label), 'singular_name' => $label, 'search_items' => sprintf(__('Search %s', 'woocommerce'), $label), 'all_items' => sprintf(__('All %s', 'woocommerce'), $label), 'parent_item' => sprintf(__('Parent %s', 'woocommerce'), $label), 'parent_item_colon' => sprintf(__('Parent %s:', 'woocommerce'), $label), 'edit_item' => sprintf(__('Edit %s', 'woocommerce'), $label), 'update_item' => sprintf(__('Update %s', 'woocommerce'), $label), 'add_new_item' => sprintf(__('Add new %s', 'woocommerce'), $label), 'new_item_name' => sprintf(__('New %s', 'woocommerce'), $label), 'not_found' => sprintf(__('No "%s" found', 'woocommerce'), $label)), 'show_ui' => true, 'show_in_quick_edit' => false, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'meta_box_cb' => false, 'query_var' => 1 === $tax->attribute_public, 'rewrite' => false, 'sort' => false, 'public' => 1 === $tax->attribute_public, 'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters('woocommerce_attribute_show_in_nav_menus', false, $name), 'capabilities' => array('manage_terms' => 'manage_product_terms', 'edit_terms' => 'edit_product_terms', 'delete_terms' => 'delete_product_terms', 'assign_terms' => 'assign_product_terms'));
                    if (1 === $tax->attribute_public) {
                        $taxonomy_data['rewrite'] = array('slug' => empty($permalinks['attribute_base']) ? '' : trailingslashit($permalinks['attribute_base']) . sanitize_title($tax->attribute_name), 'with_front' => false, 'hierarchical' => true);
                    }
                    register_taxonomy($name, apply_filters("woocommerce_taxonomy_objects_{$name}", array('product')), apply_filters("woocommerce_taxonomy_args_{$name}", $taxonomy_data));
                }
            }
        }
        do_action('woocommerce_after_register_taxonomy');
    }

Usage Example

Пример #1
0
 /**
  * Install WC
  */
 public static function install()
 {
     global $wpdb;
     if (!defined('WC_INSTALLING')) {
         define('WC_INSTALLING', true);
     }
     // Ensure needed classes are loaded
     include_once 'admin/class-wc-admin-notices.php';
     self::create_options();
     self::create_tables();
     self::create_roles();
     // Register post types
     WC_Post_types::register_post_types();
     WC_Post_types::register_taxonomies();
     // Also register endpoints - this needs to be done prior to rewrite rule flush
     WC()->query->init_query_vars();
     WC()->query->add_endpoints();
     WC_API::add_endpoint();
     WC_Auth::add_endpoint();
     WC_AJAX::add_endpoint();
     self::create_terms();
     self::create_cron_jobs();
     self::create_files();
     // Queue upgrades/setup wizard
     $current_wc_version = get_option('woocommerce_version', null);
     $current_db_version = get_option('woocommerce_db_version', null);
     $major_wc_version = substr(WC()->version, 0, strrpos(WC()->version, '.'));
     WC_Admin_Notices::remove_all_notices();
     // No versions? This is a new install :)
     if (is_null($current_wc_version) && is_null($current_db_version) && apply_filters('woocommerce_enable_setup_wizard', true)) {
         WC_Admin_Notices::add_notice('install');
         set_transient('_wc_activation_redirect', 1, 30);
         // No page? Let user run wizard again..
     } elseif (!get_option('woocommerce_cart_page_id')) {
         WC_Admin_Notices::add_notice('install');
         // Show welcome screen for major updates only
     } elseif (version_compare($current_wc_version, $major_wc_version, '<')) {
         set_transient('_wc_activation_redirect', 1, 30);
     }
     if (!is_null($current_db_version) && version_compare($current_db_version, max(array_keys(self::$db_updates)), '<')) {
         WC_Admin_Notices::add_notice('update');
     } else {
         self::update_db_version();
     }
     self::update_wc_version();
     // Flush rules after install
     flush_rewrite_rules();
     delete_transient('wc_attribute_taxonomies');
     /*
      * Deletes all expired transients. The multi-table delete syntax is used
      * to delete the transient record from table a, and the corresponding
      * transient_timeout record from table b.
      *
      * Based on code inside core's upgrade_network() function.
      */
     $sql = "DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b\n\t\t\tWHERE a.option_name LIKE %s\n\t\t\tAND a.option_name NOT LIKE %s\n\t\t\tAND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )\n\t\t\tAND b.option_value < %d";
     $wpdb->query($wpdb->prepare($sql, $wpdb->esc_like('_transient_') . '%', $wpdb->esc_like('_transient_timeout_') . '%', time()));
     // Trigger action
     do_action('woocommerce_installed');
 }
All Usage Examples Of WC_Post_types::register_taxonomies