refactor(2meet-data-optimizer): resolve post_type/group/table mappings through the registry

- TMDO_Post_Fields::post_type_for_group() / groups_for_post_type() derive HivePress-style groups from their registry post_type scope (core keeps its own attachment / wc_product / nav_menu_item map); the three copy-pasted switches and the query router's POST_TYPE_GROUP_MAP use them
- Term/comment backfill, shadow verifier and CLI take their groups from the registry (TMDO_Term_Comment_Backfill::registered_groups()); installer drops the hp_* entries already covered by its table patterns; REST listings default post type is filterable (tmdo_rest_default_post_type, default 'post')
- Verify: NoHpMappingsTest guard + mapping/default tests; core unit 640 / integration 449, HP 146/49, WC 10/22 OK
- PR: PR-020e
This commit is contained in:
2026-09-26 00:22:20 +08:00
parent 8a1c9c0353
commit 0603537f0a
13 changed files with 196 additions and 130 deletions
@@ -43,23 +43,6 @@ class TMDO_Post_Query_Router {
/** Query var key for capturing routed clauses (consumed by posts_join/where). */
private const QUERY_VAR = 'wpdo_post_clauses';
/**
* Map post_type → entity group (mirror of TMDO_Post_Migration::group_post_type
* but inverted; a post_type may map to multiple groups eventually, currently
* we route to the most-specific *_core group plus the cross-cutting wp_core
* group when the key is in wp_core).
*
* @var array<string,string>
*/
private const POST_TYPE_GROUP_MAP = array(
'product' => 'wc_product',
'hp_listing' => 'hp_listing_core',
'hp_request' => 'hp_request_core',
'hp_vendor' => 'hp_vendor_core',
'attachment' => 'attachment',
'nav_menu_item' => 'nav_menu_item',
);
/**
* Register all WP_Query hooks.
*
@@ -117,8 +100,7 @@ class TMDO_Post_Query_Router {
// Confirm the field's group is appropriate for this post_type:
// either cross-cutting wp_core (any) or the post_type-specific group.
$group = $field['group'] ?? '';
$expected_grp = self::POST_TYPE_GROUP_MAP[ $pt ] ?? null;
$is_appropriate = ( 'wp_core' === $group ) || ( null !== $expected_grp && $expected_grp === $group );
$is_appropriate = ( 'wp_core' === $group ) || in_array( $group, TMDO_Post_Fields::groups_for_post_type( (string) $pt ), true );
if ( ! $is_appropriate ) {
continue;
}