suggestions_api = $controller->get_parsely()->get_suggestions_api(); } /** * Returns the name of the endpoint. * * @since 3.19.0 * * @return string The endpoint's name. */ public static function get_endpoint_name(): string { return 'check-auth'; } /** * Returns the name of the feature associated with the current endpoint. * * @since 3.19.0 * * @return string */ public function get_pch_feature_name(): string { return 'check_auth'; } /** * Registers the routes for the endpoint. * * @since 3.19.0 */ public function register_routes(): void { /** * POST /check-auth * Returns whether the Site ID has the authorization to use the * Suggestions API or Suggestions API feature. */ $this->register_rest_route( '/', array( 'POST' ), array( $this, 'get_check_auth' ), array( 'auth_scope' => array( 'description' => __( 'The scope for which to authorize.', 'wp-parsely' ), 'type' => 'string', 'required' => true, ), ) ); } /** * API Endpoint: POST /check-auth * * Returns whether the Site ID has the authorization to use the Suggestions * API or Suggestions API feature. * * @since 3.19.0 * * @param WP_REST_Request $request The request object. * @return WP_REST_Response|WP_Error The response object or a WP_Error object on failure. */ public function get_check_auth( WP_REST_Request $request ) { $auth_scope = $request->get_param( 'auth_scope' ); $response = $this->suggestions_api->get_check_auth( array( 'auth_scope' => $auth_scope ) ); if ( is_wp_error( $response ) ) { return $response; } return new WP_REST_Response( array( 'data' => $response ), 200 ); } }