Files
2meet-data-optimizer-hivepr…/includes/class-tmdo-hivepress-term-comment-fields.php
wpdev b4400a68e5 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
2026-07-31 05:06:36 +08:00

134 lines
4.2 KiB
PHP

<?php
/**
* HivePress term + comment entity field registration (v2.12.2 Phase 2).
*
* Registers two entity groups so the corresponding meta keys are routed
* through Hook Bus to flat tables instead of wp_termmeta / wp_commentmeta:
*
* term:hp_taxonomy → wp_wpdo_term_hp_taxonomy
* - hp_sort_order (int, indexed)
* - hp_default (tinyint, indexed)
* - hp_icon (varchar, hp icon class name)
*
* comment:hp_review → wp_wpdo_comment_hp_review
* - hp_rating (tinyint, indexed)
*
* dev10 inventory match (v2.12.0 size check):
* wp_termmeta keys: hp_sort_order(25), hp_default(20), hp_icon(8) → 53 rows, 100% covered
* wp_commentmeta keys: hp_rating(63) → 63 rows, 100% covered
*
* After Phase 5 mode promote:
* - mode=disabled — registry inert, writes go to wp_termmeta/commentmeta as before
* - mode=dual_write — writes go to BOTH (flat + wp_*meta) for safety
* - mode=shadow_read — writes BOTH, reads come from flat (verification phase)
* - mode=aeav_only — writes only flat, wp_*meta untouched
*
* Pattern mirrors TMDO_Post_Fields::register(). Schema_Manager picks up the
* new groups via TMDO_Entity_Registry::get_pending_schemas() on init:1 and
* creates flat tables idempotently (schema_hash compare, no DDL when
* unchanged).
*
* Keys not registered here (`note_group`, `_2meet_demo_*`, etc.) pass through
* to wp_*meta unchanged — same fall-back behavior as user/post entity bridge.
* Garbage patterns are dropped by TMDO_Term_Comment_Garbage_Filter (v2.12.1).
*
* 🔒 Frozen contract: this class never registers post / user fields. Those
* are owned by TMDO_Post_Fields / TMDO_Member_Fields respectively.
*
* @package WP_Data_Optimizer
* @since 2.12.2
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Registers HivePress term + comment entity groups.
*/
final class TMDO_Hivepress_Term_Comment_Fields {
/**
* Hook into WPDO entity field registration. Called from TMDO_Core::run()
* via the $partner_integrations bootstrap loop.
*
* @return void
*/
public static function register(): void {
add_action( 'wpdo_register_entity_fields', array( __CLASS__, 'register_entity_fields' ) );
}
/**
* Register both entity groups.
*
* @return void
*/
public static function register_entity_fields(): void {
if ( ! class_exists( 'TMDO_Entity_Registry' ) ) {
return;
}
self::register_term_hp_taxonomy_group();
self::register_comment_hp_review_group();
}
// ── Group definitions ────────────────────────────────────────────────────
/**
* HivePress term taxonomy meta (taxonomies: listing_category, listing_tag,
* listing_warranty, listing_availability, etc.).
*
* @return void
*/
private static function register_term_hp_taxonomy_group(): void {
TMDO_Entity_Registry::register_group(
'term',
'hp_taxonomy',
array(
array(
'key' => 'hp_sort_order',
'type' => 'integer',
'searchable' => true,
'label' => 'HivePress term sort order (used by listing facets)',
),
array(
'key' => 'hp_default',
'type' => 'enum',
'options' => array( '0', '1' ),
'searchable' => true,
'label' => 'HivePress default flag (1 = is the default term)',
),
array(
'key' => 'hp_icon',
'type' => 'text',
'label' => 'HivePress term icon class (e.g. fa-star)',
),
)
);
}
/**
* HivePress comment review meta (review type comments left on hp_listing).
*
* Currently single-key; deliberately register as its own group so future
* review-related keys (hp_review_*, hp_review_visibility, etc.) can be
* added without splitting the schema.
*
* @return void
*/
private static function register_comment_hp_review_group(): void {
TMDO_Entity_Registry::register_group(
'comment',
'hp_review',
array(
array(
'key' => 'hp_rating',
'type' => 'integer',
'searchable' => true,
'label' => 'HivePress 1-5 star rating attached to a review comment',
),
)
);
}
}