WC_Post_types::register_post_types PHP Méthode

register_post_types() public static méthode

Register core post types.
public static register_post_types ( )
    public static function register_post_types()
    {
        if (!is_blog_installed()) {
            return;
        }
        if (post_type_exists('product')) {
            return;
        }
        do_action('woocommerce_register_post_type');
        $permalinks = get_option('woocommerce_permalinks');
        $product_permalink = empty($permalinks['product_base']) ? _x('product', 'slug', 'woocommerce') : $permalinks['product_base'];
        register_post_type('product', apply_filters('woocommerce_register_post_type_product', array('labels' => array('name' => __('Products', 'woocommerce'), 'singular_name' => __('Product', 'woocommerce'), 'menu_name' => _x('Products', 'Admin menu name', 'woocommerce'), 'add_new' => __('Add product', 'woocommerce'), 'add_new_item' => __('Add new product', 'woocommerce'), 'edit' => __('Edit', 'woocommerce'), 'edit_item' => __('Edit product', 'woocommerce'), 'new_item' => __('New product', 'woocommerce'), 'view' => __('View product', 'woocommerce'), 'view_item' => __('View product', 'woocommerce'), 'search_items' => __('Search products', 'woocommerce'), 'not_found' => __('No products found', 'woocommerce'), 'not_found_in_trash' => __('No products found in trash', 'woocommerce'), 'parent' => __('Parent product', 'woocommerce'), 'featured_image' => __('Product image', 'woocommerce'), 'set_featured_image' => __('Set product image', 'woocommerce'), 'remove_featured_image' => __('Remove product image', 'woocommerce'), 'use_featured_image' => __('Use as product image', 'woocommerce'), 'insert_into_item' => __('Insert into product', 'woocommerce'), 'uploaded_to_this_item' => __('Uploaded to this product', 'woocommerce'), 'filter_items_list' => __('Filter products', 'woocommerce'), 'items_list_navigation' => __('Products navigation', 'woocommerce'), 'items_list' => __('Products list', 'woocommerce')), 'description' => __('This is where you can add new products to your store.', 'woocommerce'), 'public' => true, 'show_ui' => true, 'capability_type' => 'product', 'map_meta_cap' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'hierarchical' => false, 'rewrite' => $product_permalink ? array('slug' => untrailingslashit($product_permalink), 'with_front' => false, 'feeds' => true) : false, 'query_var' => true, 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'publicize', 'wpcom-markdown'), 'has_archive' => ($shop_page_id = wc_get_page_id('shop')) && get_post($shop_page_id) ? get_page_uri($shop_page_id) : 'shop', 'show_in_nav_menus' => true, 'show_in_rest' => true)));
        register_post_type('product_variation', apply_filters('woocommerce_register_post_type_product_variation', array('label' => __('Variations', 'woocommerce'), 'public' => false, 'hierarchical' => false, 'supports' => false, 'capability_type' => 'product')));
        wc_register_order_type('shop_order', apply_filters('woocommerce_register_post_type_shop_order', array('labels' => array('name' => __('Orders', 'woocommerce'), 'singular_name' => _x('Order', 'shop_order post type singular name', 'woocommerce'), 'add_new' => __('Add order', 'woocommerce'), 'add_new_item' => __('Add new order', 'woocommerce'), 'edit' => __('Edit', 'woocommerce'), 'edit_item' => __('Edit order', 'woocommerce'), 'new_item' => __('New order', 'woocommerce'), 'view' => __('View order', 'woocommerce'), 'view_item' => __('View order', 'woocommerce'), 'search_items' => __('Search orders', 'woocommerce'), 'not_found' => __('No orders found', 'woocommerce'), 'not_found_in_trash' => __('No orders found in trash', 'woocommerce'), 'parent' => __('Parent orders', 'woocommerce'), 'menu_name' => _x('Orders', 'Admin menu name', 'woocommerce'), 'filter_items_list' => __('Filter orders', 'woocommerce'), 'items_list_navigation' => __('Orders navigation', 'woocommerce'), 'items_list' => __('Orders list', 'woocommerce')), 'description' => __('This is where store orders are stored.', 'woocommerce'), 'public' => false, 'show_ui' => true, 'capability_type' => 'shop_order', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => current_user_can('manage_woocommerce') ? 'woocommerce' : true, 'hierarchical' => false, 'show_in_nav_menus' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title', 'comments', 'custom-fields'), 'has_archive' => false)));
        wc_register_order_type('shop_order_refund', apply_filters('woocommerce_register_post_type_shop_order_refund', array('label' => __('Refunds', 'woocommerce'), 'capability_type' => 'shop_order', 'public' => false, 'hierarchical' => false, 'supports' => false, 'exclude_from_orders_screen' => false, 'add_order_meta_boxes' => false, 'exclude_from_order_count' => true, 'exclude_from_order_views' => false, 'exclude_from_order_reports' => false, 'exclude_from_order_sales_reports' => true, 'class_name' => 'WC_Order_Refund')));
        if ('yes' == get_option('woocommerce_enable_coupons')) {
            register_post_type('shop_coupon', apply_filters('woocommerce_register_post_type_shop_coupon', array('labels' => array('name' => __('Coupons', 'woocommerce'), 'singular_name' => __('Coupon', 'woocommerce'), 'menu_name' => _x('Coupons', 'Admin menu name', 'woocommerce'), 'add_new' => __('Add coupon', 'woocommerce'), 'add_new_item' => __('Add new coupon', 'woocommerce'), 'edit' => __('Edit', 'woocommerce'), 'edit_item' => __('Edit coupon', 'woocommerce'), 'new_item' => __('New coupon', 'woocommerce'), 'view' => __('View coupons', 'woocommerce'), 'view_item' => __('View coupon', 'woocommerce'), 'search_items' => __('Search coupons', 'woocommerce'), 'not_found' => __('No coupons found', 'woocommerce'), 'not_found_in_trash' => __('No coupons found in trash', 'woocommerce'), 'parent' => __('Parent coupon', 'woocommerce'), 'filter_items_list' => __('Filter coupons', 'woocommerce'), 'items_list_navigation' => __('Coupons navigation', 'woocommerce'), 'items_list' => __('Coupons list', 'woocommerce')), 'description' => __('This is where you can add new coupons that customers can use in your store.', 'woocommerce'), 'public' => false, 'show_ui' => true, 'capability_type' => 'shop_coupon', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => current_user_can('manage_woocommerce') ? 'woocommerce' : true, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title'), 'show_in_nav_menus' => false, 'show_in_admin_bar' => true)));
        }
        register_post_type('shop_webhook', apply_filters('woocommerce_register_post_type_shop_webhook', array('labels' => array('name' => __('Webhooks', 'woocommerce'), 'singular_name' => __('Webhook', 'woocommerce'), 'menu_name' => _x('Webhooks', 'Admin menu name', 'woocommerce'), 'add_new' => __('Add webhook', 'woocommerce'), 'add_new_item' => __('Add new webhook', 'woocommerce'), 'edit' => __('Edit', 'woocommerce'), 'edit_item' => __('Edit webhook', 'woocommerce'), 'new_item' => __('New webhook', 'woocommerce'), 'view' => __('View webhooks', 'woocommerce'), 'view_item' => __('View webhook', 'woocommerce'), 'search_items' => __('Search webhooks', 'woocommerce'), 'not_found' => __('No webhooks found', 'woocommerce'), 'not_found_in_trash' => __('No webhooks found in trash', 'woocommerce'), 'parent' => __('Parent webhook', 'woocommerce')), 'public' => false, 'show_ui' => true, 'capability_type' => 'shop_webhook', 'map_meta_cap' => true, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => false, 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => false, 'show_in_nav_menus' => false, 'show_in_admin_bar' => false)));
    }

Usage Example

 /**
  * 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_post_types