chore: initial snapshot of 2meet-data-optimizer-hivepress-addon 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
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Marketplace adapter — `hivepress-marketplace` (DETECT-ONLY in v3.0.0).
|
||||
*
|
||||
* The marketplace addon turns listings into purchasable items, integrating
|
||||
* with WooCommerce. It adds:
|
||||
*
|
||||
* hp_purchase_price → decimal(10,2), used in price-range filters (HOT)
|
||||
* hp_purchase_count → counter (WARM zone, low-criticality)
|
||||
*
|
||||
* Note: `hp_purchase_price` is also conditionally registered by the existing
|
||||
* legacy hivepress integration (Sprint 1 left that path) — the dedup in
|
||||
* Schema_Registry is provider+key based, so registering again under the
|
||||
* `hivepress-marketplace` provider is safe and lets `wp wpdo doctor` show
|
||||
* the right ownership.
|
||||
*
|
||||
* Detect-only: not installed in dev environment. Schema reserved for the
|
||||
* day the addon ships.
|
||||
*
|
||||
* @package WP_Data_Optimizer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'TMDO_HivePress_Marketplace_Adapter' ) ) {
|
||||
|
||||
/**
|
||||
* Marketplace addon adapter (detect-only).
|
||||
*/
|
||||
final class TMDO_HivePress_Marketplace_Adapter implements TMDO_HivePress_Adapter {
|
||||
|
||||
use TMDO_HivePress_Adapter_Trait;
|
||||
|
||||
/**
|
||||
* Constructor — bind register hooks via inherited trait.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->bind_anti_eav_hooks();
|
||||
}
|
||||
|
||||
/** Adapter slug (matches wp.org plugin slug). */
|
||||
public function plugin_slug(): string {
|
||||
return 'hivepress-marketplace';
|
||||
}
|
||||
|
||||
/** Class probed for addon presence. */
|
||||
public function detection_class(): string {
|
||||
return 'HivePress\\Marketplace\\Plugin';
|
||||
}
|
||||
|
||||
/** Version constant probed for addon presence. */
|
||||
public function detection_const(): string {
|
||||
return 'HIVEPRESS_MARKETPLACE_VERSION';
|
||||
}
|
||||
|
||||
/** Minimum addon version supported. */
|
||||
public function minimum_addon_version(): string {
|
||||
return '1.0.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Register marketplace hot fields on the listing post type.
|
||||
*
|
||||
* @param TMDO_Schema_Registry $registry Schema registry singleton.
|
||||
*/
|
||||
public function on_register_fields( TMDO_Schema_Registry $registry ): void {
|
||||
$registry->register_many(
|
||||
$this->plugin_slug(),
|
||||
array(
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_purchase_price',
|
||||
'zone' => 'hot',
|
||||
'data_type' => 'decimal(10,2) DEFAULT NULL',
|
||||
'column' => 'hp_purchase_price',
|
||||
'indexed' => true,
|
||||
),
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_purchase_count',
|
||||
'zone' => 'warm',
|
||||
'ttl' => null,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doctor probe — verify hot column exists on listing hot table.
|
||||
*
|
||||
* @return array{ok:bool, message:string}
|
||||
*/
|
||||
public function doctor_check(): array {
|
||||
global $wpdb;
|
||||
if ( ! isset( $wpdb ) || ! is_object( $wpdb ) ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => 'wpdb global not available',
|
||||
);
|
||||
}
|
||||
$table = $wpdb->prefix . 'wpdo_hot_hp_listing';
|
||||
try {
|
||||
$exists = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
|
||||
return array(
|
||||
'ok' => $exists,
|
||||
'message' => $exists
|
||||
? 'hivepress-marketplace: shares wp_wpdo_hot_hp_listing'
|
||||
: 'hivepress-marketplace: hot listing table missing',
|
||||
);
|
||||
} catch ( \Throwable $e ) {
|
||||
return array(
|
||||
'ok' => false,
|
||||
'message' => sprintf( 'hivepress-marketplace doctor failed: %s', $e->getMessage() ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 8-D self-score.
|
||||
*
|
||||
* D8 reduced to 0.9 — index assumption is best-effort until addon installs.
|
||||
*/
|
||||
public function suitability_score(): array {
|
||||
return $this->compose_score(
|
||||
array(
|
||||
'd8_perf' => 0.9,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} // end if ( ! class_exists )
|
||||
Reference in New Issue
Block a user