output_guard = new OutputGuard(); } /** * Registering the REST hooks. */ public function register(): void { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); // Late, so the guard only steps in when nothing else has handled the request. add_filter( 'rest_dispatch_request', array( $this->output_guard, 'dispatch' ), 999, 4 ); } /** * Registering every controller's routes. * * Controllers are built here because WP_REST_Controller may not exist at plugins_loaded. */ public function register_routes(): void { foreach ( $this->controllers() as $controller ) { $controller->register_routes(); } } /** * Listing the controllers making up the REST surface. * * @return AbstractController[] Controllers. */ private function controllers(): array { return array( new AuthController(), new PublicationController(), new StatusController(), new FileController(), new MatchingScreenController(), ); } }