Files
2meet-data-optimizer-hivepr…/includes/class-tmdo-hivepress-bootstrap.php
T
wpdev b96b041445 fix(hivepress): detector active-plugin 偵測 + 4 個 interceptor 改繼承核心基底(F2/F3/F4)
F3 detector(A v3.4.5):HivePress addon 不暴露任何 per-addon class/const,
   它們是透過 add_filter('hivepress/v1/extensions') 註冊目錄,所以原本的
   class_exists / defined 偵測永遠只認得 core → 反 EAV 覆蓋率卡在 1/13。
   改以 get_option('active_plugins') 為第一級訊號(新增 active_plugin_files()),
   version_for() 對 addon 改讀其主檔 Version: header。覆蓋率回到 7/13。

F2 interceptor:reviews / messages / memberships / requests 改繼承核心的
   TMDO_Standard_Post_Interceptor,573 → 344 行。FIELD_MAP 由 private
   提升為 public(late static binding 從基底讀取)。
   bootstrap 的 require 迴圈加核心版本守衛:這 4 個檔案在舊核心下會於
   parse 階段就 fatal,class_exists 守衛來不及。

F4 listing-stats:view 計數改用 Zone_Warm::increment() 原子遞增,
   flush 改原子 UPDATE,消除 get()+set() 的 lost-update race。

F5:主檔補 TablePrefix header(打包終檢 §10 schema drift 主路徑)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
2026-07-31 06:07:39 +08:00

186 lines
6.1 KiB
PHP

<?php
/**
* Bootstrap for 2meet Data Optimizer HivePress AddOn.
*
* 載入 13 adapter + 7 interceptor + 5 query interceptor + 補助組件 +
* admin tab + CLI namespace。
*
* 注意:HP 的 V3.0.0 family bootstrap 內部也有一個 class TMDO_HivePress_Bootstrap
* (在 includes/hivepress/class-tmdo-hivepress-bootstrap.php)。為避免衝突,本
* AddOn outer bootstrap 改名為 TMDO_HP_Bootstrap。
*
* @package TMDO_HIVEPRESS
* @since 0.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
final class TMDO_HP_Bootstrap {
public static function init(): void {
if ( ! class_exists( 'TMDO_API' ) && ! class_exists( 'WPDO_API' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'missing_core_notice' ) );
return;
}
load_plugin_textdomain(
'tmdo-hivepress',
false,
dirname( plugin_basename( TMDO_HIVEPRESS_FILE ) ) . '/languages'
);
self::require_files();
self::register_hooks();
}
private static function require_files(): void {
$base = TMDO_HIVEPRESS_PATH;
// HivePress family bootstrap framework
require_once $base . 'includes/hivepress/interface-tmdo-hp-adapter.php';
require_once $base . 'includes/hivepress/trait-tmdo-hp-adapter.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-detector.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-conflict-guard.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-bootstrap.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-comment-router.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-cron-optimizer.php';
// 13 adapters
foreach ( array(
'core', 'reviews', 'favorites', 'messages', 'memberships',
'requests', 'tags', 'seo', 'social-links', 'blocks',
'bookings', 'marketplace', 'statistics',
) as $adapter_slug ) {
$file = $base . "includes/hivepress/adapters/class-tmdo-hivepress-{$adapter_slug}-adapter.php";
if ( file_exists( $file ) ) {
require_once $file;
}
}
// HP misc components
require_once $base . 'includes/hivepress/class-tmdo-hivepress-attribute-bridge.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-suitability-scorer.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-benchmark.php';
require_once $base . 'includes/hivepress/class-tmdo-hivepress-rest.php';
// 7 HPCT interceptors.
// reviews / messages / memberships / requests extend the core's
// TMDO_Standard_Post_Interceptor — requiring them against a core older than
// v0.2.0 would fatal at parse time, so gate those four on the base class.
$has_standard_base = class_exists( 'TMDO_Standard_Post_Interceptor' );
foreach ( array(
'reviews', 'messages', 'favorites', 'memberships',
'statistics', 'requests', 'listing-meta',
) as $intslug ) {
$needs_base = in_array( $intslug, array( 'reviews', 'messages', 'memberships', 'requests' ), true );
if ( $needs_base && ! $has_standard_base ) {
continue;
}
$file = $base . "includes/interceptors/class-tmdo-{$intslug}-interceptor.php";
if ( file_exists( $file ) ) {
require_once $file;
}
}
// 5 query interceptors
foreach ( array(
'reviews', 'messages', 'memberships', 'requests', 'listing-meta',
) as $qslug ) {
$file = $base . "includes/query/class-tmdo-{$qslug}-query.php";
if ( file_exists( $file ) ) {
require_once $file;
}
}
// Misc HP integration files
require_once $base . 'includes/class-tmdo-hivepress.php';
require_once $base . 'includes/class-tmdo-hivepress-transient-filter.php';
require_once $base . 'includes/class-tmdo-hpct-import.php';
require_once $base . 'includes/class-tmdo-hivepress-term-comment-fields.php';
require_once $base . 'includes/class-tmdo-listing-stats.php';
}
private static function register_hooks(): void {
// HP family v3.0.0 per-addon adapter bootstrap
// (TMDO_HivePress_Bootstrap is the inner family bootstrap class
// from includes/hivepress/class-tmdo-hivepress-bootstrap.php)
if ( class_exists( 'TMDO_HivePress_Bootstrap' )
&& method_exists( 'TMDO_HivePress_Bootstrap', 'boot' ) ) {
TMDO_HivePress_Bootstrap::boot();
}
// 7 HPCT interceptors
foreach ( array(
'TMDO_Reviews_Interceptor',
'TMDO_Messages_Interceptor',
'TMDO_Favorites_Interceptor',
'TMDO_Memberships_Interceptor',
'TMDO_Statistics_Interceptor',
'TMDO_Requests_Interceptor',
'TMDO_Listing_Meta_Interceptor',
) as $cls ) {
if ( class_exists( $cls ) ) {
( new $cls() )->register_hooks();
}
}
// 5 query interceptors
foreach ( array(
'TMDO_Reviews_Query',
'TMDO_Messages_Query',
'TMDO_Memberships_Query',
'TMDO_Requests_Query',
'TMDO_Listing_Meta_Query',
) as $cls ) {
if ( class_exists( $cls ) ) {
( new $cls() )->register_hooks();
}
}
// HP transient filter (init:5)
if ( class_exists( 'TMDO_Hivepress_Transient_Filter' ) ) {
add_action( 'init', array( 'TMDO_Hivepress_Transient_Filter', 'init' ), 5 );
}
// Listing Stats hooks + cron
if ( class_exists( 'TMDO_Listing_Stats' ) ) {
TMDO_Listing_Stats::register_hooks();
TMDO_Listing_Stats::schedule_cron();
}
// Term/Comment fields
if ( class_exists( 'TMDO_Hivepress_Term_Comment_Fields' )
&& method_exists( 'TMDO_Hivepress_Term_Comment_Fields', 'register' ) ) {
TMDO_Hivepress_Term_Comment_Fields::register();
}
// Admin tab
if ( is_admin() ) {
$admin_file = TMDO_HIVEPRESS_PATH . 'admin/class-tmdo-admin-hivepress.php';
if ( file_exists( $admin_file ) ) {
require_once $admin_file;
}
}
// CLI namespace
if ( defined( 'WP_CLI' ) && WP_CLI ) {
$cli_file = TMDO_HIVEPRESS_PATH . 'cli/class-tmdo-cli-hivepress.php';
if ( file_exists( $cli_file ) ) {
require_once $cli_file;
if ( class_exists( 'TMDO_CLI_HivePress' ) ) {
\WP_CLI::add_command( 'tmdo hivepress', 'TMDO_CLI_HivePress' );
\WP_CLI::add_command( 'wpdo hivepress', 'TMDO_CLI_HivePress' );
}
}
}
}
public static function missing_core_notice(): void {
echo '<div class="notice notice-error"><p>';
echo esc_html__( '2meet Data Optimizer HivePress AddOn 需要 2meet-data-optimizer 核心外掛,請先安裝並啟用。', 'tmdo-hivepress' );
echo '</p></div>';
}
}