*/ private const WC_CORE_TABLES = array( 'wc_admin_note_actions' => array( 'primary_key' => 'action_id', 'post_type_link' => null, 'description' => 'WC admin notes — action buttons', 'since' => 'WC 4.0', ), 'wc_admin_notes' => array( 'primary_key' => 'note_id', 'post_type_link' => null, 'description' => 'WC admin notes', 'since' => 'WC 4.0', ), 'wc_category_lookup' => array( 'primary_key' => 'category_tree_id', 'post_type_link' => null, 'description' => 'Product category hierarchy lookup', 'since' => 'WC 4.6', ), 'wc_customer_lookup' => array( 'primary_key' => 'customer_id', 'post_type_link' => null, 'description' => 'Customer aggregate (anti-EAV by WC core)', 'since' => 'WC 4.0', ), 'wc_download_log' => array( 'primary_key' => 'download_log_id', 'post_type_link' => null, 'description' => 'Downloadable product access log', 'since' => 'WC 3.3', ), 'wc_order_addresses' => array( 'primary_key' => 'id', 'post_type_link' => 'shop_order', 'description' => 'Order billing/shipping addresses (HPOS)', 'since' => 'WC 8.2', ), 'wc_order_coupon_lookup' => array( 'primary_key' => 'order_id', 'post_type_link' => 'shop_order', 'description' => 'Order coupon analytics lookup', 'since' => 'WC 4.0', ), 'wc_order_operational_data' => array( 'primary_key' => 'id', 'post_type_link' => 'shop_order', 'description' => 'Order operational data (HPOS)', 'since' => 'WC 8.2', ), 'wc_order_product_lookup' => array( 'primary_key' => 'order_item_id', 'post_type_link' => 'shop_order', 'description' => 'Order product analytics lookup', 'since' => 'WC 4.0', ), 'wc_order_stats' => array( 'primary_key' => 'order_id', 'post_type_link' => 'shop_order', 'description' => 'Order statistics (anti-EAV by WC core)', 'since' => 'WC 4.0', ), 'wc_order_tax_lookup' => array( 'primary_key' => null, 'post_type_link' => 'shop_order', 'description' => 'Order tax analytics lookup', 'since' => 'WC 4.0', ), 'wc_orders' => array( 'primary_key' => 'id', 'post_type_link' => 'shop_order', 'description' => 'Orders main table (HPOS)', 'since' => 'WC 8.2', ), 'wc_orders_meta' => array( 'primary_key' => 'id', 'post_type_link' => 'shop_order', 'description' => 'Order meta (HPOS replacement for postmeta)', 'since' => 'WC 8.2', ), 'wc_product_attributes_lookup' => array( 'primary_key' => null, 'post_type_link' => 'product', 'description' => 'Product attributes lookup (faceted search)', 'since' => 'WC 4.9', ), 'wc_product_download_directories' => array( 'primary_key' => 'url_id', 'post_type_link' => null, 'description' => 'Approved download directories', 'since' => 'WC 6.5', ), 'wc_product_meta_lookup' => array( 'primary_key' => 'product_id', 'post_type_link' => 'product', 'description' => 'Product meta lookup (anti-EAV by WC core)', 'since' => 'WC 3.6', ), 'wc_rate_limits' => array( 'primary_key' => 'rate_limit_id', 'post_type_link' => null, 'description' => 'API rate limits', 'since' => 'WC 5.6', ), 'wc_reserved_stock' => array( 'primary_key' => null, 'post_type_link' => 'product', 'description' => 'Reserved stock (cart hold)', 'since' => 'WC 4.5', ), 'wc_tax_rate_classes' => array( 'primary_key' => 'tax_rate_class_id', 'post_type_link' => null, 'description' => 'Tax rate classes', 'since' => 'WC 3.7', ), 'wc_webhooks' => array( 'primary_key' => 'webhook_id', 'post_type_link' => null, 'description' => 'Webhooks subscriptions', 'since' => 'WC 2.6', ), ); /** * Wire integration. No-op when WC not detected. * * @return void */ public static function register(): void { if ( ! self::is_active() ) { return; } add_action( 'wpdo_register_custom_tables', array( __CLASS__, 'register_custom_tables' ) ); // 0.2.0: no product / order / subscription zone fields and no user hot group. // WooCommerce reads its meta directly and writes stock by SQL, so a flat // copy drifts; its meta stays native only (core 1.2.0 dropped wc_product too). // HPOS recommendation notice — only on WC admin pages, only when: // (a) HPOS is OFF, (b) the threshold of legacy orders has been crossed. if ( is_admin() ) { add_action( 'admin_notices', array( __CLASS__, 'maybe_render_hpos_notice' ) ); } } /** * Threshold of legacy `shop_order` posts above which we recommend HPOS. * Below this, the HPOS migration overhead isn't justified. */ private const HPOS_RECOMMEND_THRESHOLD = 100; /** * Option name used to permanently dismiss the notice. */ private const HPOS_NOTICE_DISMISSED_OPT = 'wpdo_hpos_notice_dismissed'; /** * Conditionally render the HPOS recommendation admin notice. * * @return void */ public static function maybe_render_hpos_notice(): void { // Already enabled or already dismissed. if ( self::is_hpos_enabled() ) { return; } if ( '1' === (string) get_option( self::HPOS_NOTICE_DISMISSED_OPT, '' ) ) { return; } if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } // Handle dismiss action (lightweight, no separate AJAX endpoint). // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only nonce check below. if ( ! empty( $_GET['wpdo_hpos_dismiss'] ) ) { $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( (string) $_GET['_wpnonce'] ) ) : ''; if ( wp_verify_nonce( $nonce, 'wpdo_hpos_dismiss' ) ) { update_option( self::HPOS_NOTICE_DISMISSED_OPT, '1', false ); return; } } $legacy_count = self::count_legacy_orders(); if ( $legacy_count < self::HPOS_RECOMMEND_THRESHOLD ) { return; } $dismiss_url = wp_nonce_url( add_query_arg( 'wpdo_hpos_dismiss', '1' ), 'wpdo_hpos_dismiss' ); $settings_url = admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=features' ); ?>
WP Data Optimizer: WooCommerce → 進階 → 功能', '關閉' ); ?>