Files
2meet-data-optimizer/includes/class-tmdo-compatibility.php
T
wpdev d36bb954d1 chore: initial snapshot of 2meet-data-optimizer v0.1.0
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6.

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

134 lines
3.3 KiB
PHP

<?php
/**
* Plugin coexistence manager for WP Data Optimizer.
*
* @package WP_Data_Optimizer
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Plugin coexistence manager.
*
* Detects active plugins and determines whether WPDO should register
* its interceptors or defer to existing plugins.
*/
class TMDO_Compatibility {
/**
* Cached detection results.
*
* @var array
*/
private static array $detected = array();
/**
* Run all compatibility checks. Called once during TMDO_Core::run().
*
* @return array Detection results.
*/
public static function check(): array {
if ( ! empty( self::$detected ) ) {
return self::$detected;
}
self::$detected = array(
'hpct_active' => self::is_hpct_active(),
'hpct_imported' => self::is_hpct_imported(),
'hivepress' => self::is_hivepress_active(),
'woocommerce' => self::is_woocommerce_active(),
);
return self::$detected;
}
/**
* Can WPDO register its HPCT-inherited module interceptors?
*
* True when:
* - hp-custom-tables is NOT active, OR
* - hp-custom-tables IS active but already imported into WPDO.
*/
public static function can_register_hpct_hooks(): bool {
$compat = self::check();
// HPCT not active → WPDO can freely register.
if ( ! $compat['hpct_active'] ) {
return true;
}
// HPCT is active but already imported → WPDO takes over.
if ( $compat['hpct_imported'] ) {
return true;
}
// HPCT is active and NOT imported → defer to HPCT.
return false;
}
/**
* Can WPDO register zone-specific interceptors (hot/warm/cold/archive)?
*
* Zone interceptors are always safe to register — they operate on
* WPDO's own tables and do not conflict with HPCT.
*/
public static function can_register_zone_hooks(): bool {
return true;
}
/**
* Should WPDO show an admin notice about HPCT import?
*/
public static function should_show_hpct_notice(): bool {
$compat = self::check();
return $compat['hpct_active'] && ! $compat['hpct_imported'];
}
/**
* Is HivePress core active?
*/
public static function is_hivepress_active(): bool {
return class_exists( 'HivePress\Core' );
}
/**
* Is WooCommerce active?
*/
public static function is_woocommerce_active(): bool {
return class_exists( 'WooCommerce' );
}
/**
* Is LatePoint plugin active? (v2.5.0 M16 polish — for module detector.)
*
* LatePoint exposes the OsBookingHelper class and `latepoint_*` action
* hooks. Detect via either the helper class or the version constant.
*/
public static function is_latepoint_active(): bool {
return class_exists( 'OsBookingHelper' )
|| defined( 'LATEPOINT_VERSION' )
|| function_exists( 'latepoint_get_settings' );
}
// ── Detection Methods ────────────────────────────────────────────────
/**
* Is HP Custom Tables plugin active (loaded)?
*
* Checks for the HPCT_Loader class, which is always loaded
* when hp-custom-tables is active.
*/
public static function is_hpct_active(): bool {
return class_exists( 'HPCT_Loader' ) || defined( 'HPCT_VERSION' );
}
/**
* Has HPCT been imported into WPDO?
*/
private static function is_hpct_imported(): bool {
return (bool) get_option( 'wpdo_hpct_imported', false );
}
}