feat(2meet-data-optimizer-hivepress-addon): provide HivePress defaults to core via filters

- TMDO_HivePress_Entity_Groups hooks tmdo_rest_default_post_type so GET /wpdo/v1/listings keeps defaulting to hp_listing now that core defaults to 'post' (PR-020e)
- Test: TMDO_Post_Group_Reconciler::plan() over the AddOn's groups yields the 8 misrouted HivePress keys (coverage moved out of core in PR-020b)
- Verify: HP unit 148 / integration 49 OK, bootstrap smoke OK
- PR: PR-020f
This commit is contained in:
2026-09-26 00:24:43 +08:00
parent dca134b5b6
commit 69c8bf2a88
2 changed files with 40 additions and 1 deletions
@@ -32,12 +32,22 @@ if ( ! defined( 'ABSPATH' ) ) {
final class TMDO_HivePress_Entity_Groups {
/**
* Hook into WPDO entity field registration.
* Hook into WPDO entity field registration and the REST default post type.
*
* @return void
*/
public static function register(): void {
add_action( 'wpdo_register_entity_fields', array( __CLASS__, 'register_entity_fields' ) );
add_filter( 'tmdo_rest_default_post_type', array( __CLASS__, 'rest_default_post_type' ) );
}
/**
* GET /wpdo/v1/listings serves HivePress listings when no post type is given.
*
* @return string
*/
public static function rest_default_post_type(): string {
return 'hp_listing';
}
/**
+29
View File
@@ -46,6 +46,7 @@ class HivePressEntityGroupsTest extends TestCase {
protected function tearDown(): void {
unset( $GLOBALS['_wp_options'][ TMDO_Entity_Registry::SCOPED_ROUTING_OPTION ] );
unset( $GLOBALS['_wp_filter_callbacks']['tmdo_rest_default_post_type'] );
}
public function test_definitions_match_persisted_schema_hashes(): void {
@@ -74,6 +75,34 @@ class HivePressEntityGroupsTest extends TestCase {
$this->assertNull( TMDO_Entity_Registry::get_field( 'post', 'hp_rating', 'post' ), 'HivePress keys stay native on other post types' );
}
public function test_reconciler_plans_the_eight_misrouted_hivepress_keys(): void {
$moves = array();
foreach ( TMDO_Post_Group_Reconciler::plan() as $m ) {
$moves[] = "{$m['source']}>{$m['target']}:{$m['key']}";
}
sort( $moves );
$this->assertSame(
array(
'hp_request_core>hp_listing_core:hp_expired_time',
'hp_request_core>hp_listing_core:hp_status',
'hp_request_core>hp_listing_core:hp_view_count',
'hp_vendor_core>hp_listing_core:hp_hourly_rate',
'hp_vendor_core>hp_listing_core:hp_rating',
'hp_vendor_core>hp_listing_core:hp_rating_count',
'hp_vendor_core>hp_listing_core:hp_verified',
'hp_vendor_core>hp_request_core:hp_user',
),
$moves
);
}
public function test_rest_listings_default_to_hivepress_listings(): void {
TMDO_HivePress_Entity_Groups::register();
$this->assertSame( 'hp_listing', TMDO_REST_API::default_post_type() );
}
public function test_core_adapter_does_not_register_a_conflicting_group(): void {
( new TMDO_HivePress_Core_Adapter() )->on_register_entity_fields();