$property, 'start_date' => $start, 'end_date' => $end ) * ); * * Passing a WP_Error as the default means a caller that runs without Optimiser * present gets a clean failure rather than a fatal or a silent empty result. * * @package AI_O_Optimiser */ if ( ! defined( 'ABSPATH' ) ) { exit; } final class AI_O_Optimiser_Hub_Bridge { /** * Hub routes a sibling plugin may reach through this bridge. * * Read-only reporting only. Deliberately excludes /register and /disconnect * (they change this site's Hub identity, which belongs to Optimiser's own * settings screens) and /business-profile/* (Optimiser's Local workspace * owns that evidence). Widen this list when a sibling has a stated need, * not in advance. */ const ALLOWED_ROUTES = array( '/status', '/properties', '/search-console/query', ); /** Register the boundary. Cheap: no client loaded until a call arrives. */ public static function boot() { add_filter( 'ai_o_optimiser_hub_request', array( __CLASS__, 'handle' ), 10, 3 ); } /** * Answer a sibling plugin's Hub request. * * @param mixed $default Value to return if this bridge does not answer. * @param string $route Hub route below /aio-connector/v1. * @param array $payload Request body. * @return array|WP_Error */ public static function handle( $default, $route = '', $payload = array() ) { $route = (string) $route; if ( ! in_array( $route, self::ALLOWED_ROUTES, true ) ) { return new WP_Error( 'ai_o_optimiser_hub_route_not_allowed', sprintf( /* translators: %s: requested Connector Hub route. */ __( 'The Connector Hub route %s is not available to other plugins through AI-O Optimiser.', 'ai-o-optimiser' ), $route ) ); } if ( ! class_exists( 'AI_O_Optimiser_Connector_Client' ) ) { if ( function_exists( 'ai_o_optimiser_guidance_load_connector_client' ) ) { ai_o_optimiser_guidance_load_connector_client(); } } if ( ! class_exists( 'AI_O_Optimiser_Connector_Client' ) ) { return new WP_Error( 'ai_o_optimiser_hub_client_missing', __( 'The AI-O Connector Hub client could not be loaded.', 'ai-o-optimiser' ) ); } unset( $default ); return AI_O_Optimiser_Connector_Client::hub_request( $route, is_array( $payload ) ? $payload : array() ); } }