Search_Api implements Registerable, Standard_Service Uses Api_Can_Send_Error
REST API endpoint for the search functionality.
Tags
Interfaces, Classes and Traits
- Registerable
- Standard_Service
Table of Contents
- API_NAMESPACE = 'wcf/v1'
- allow_anonymous_access() : mixed
- Allow unauthenticated access to specific public routes.
- get_filters() : array<string|int, Filter>
- Get the filters for the search.
- get_groups() : array<string|int, mixed>
- Returns the list of group IDs that should be used for the search.
- get_integrations() : array<string|int, mixed>
- Get the integrations from the request.
- get_order_by() : string|null
- Get the order_by parameter from the request.
- get_page() : int
- Get the page number from the request.
- get_parameters() : array<string|int, mixed>
- Get the parameters for the search.
- get_query_args() : array<string|int, mixed>
- Get the query arguments from the request.
- get_reset() : bool
- Get the reset flag from the request.
- register() : void
- Hook into WP.
- register_routes() : void
- Register the routes for the search functionality.
- requires_rendering() : bool
- Check if the search requires rendering.
- retrieve_groups() : array<string|int, Group>
- Retrieves the groups for the search.
- search() : WP_REST_Response
- Search the products.
- send_error() : WP_REST_Response
- Send an error response.
Constants
API_NAMESPACE
public
mixed
API_NAMESPACE
= 'wcf/v1'
Methods
allow_anonymous_access()
Allow unauthenticated access to specific public routes.
public
allow_anonymous_access(mixed $result) : mixed
@wordpress/api-fetch
is incredibly strict about authentication, so we need to allow
anonymous access to these routes.
Parameters
- $result : mixed
-
The result of the authentication check.
Return values
mixed —The result of the authentication check.
get_filters()
Get the filters for the search.
public
get_filters(array<string|int, Group> $groups) : array<string|int, Filter>
Parameters
- $groups : array<string|int, Group>
-
The list of groups.
Return values
array<string|int, Filter> —get_groups()
Returns the list of group IDs that should be used for the search.
public
get_groups(WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $request : WP_REST_Request
-
The REST request object.
Return values
array<string|int, mixed> —get_integrations()
Get the integrations from the request.
public
get_integrations(WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $request : WP_REST_Request
Return values
array<string|int, mixed> —The integrations array.
get_order_by()
Get the order_by parameter from the request.
public
get_order_by(WP_REST_Request $request) : string|null
Parameters
- $request : WP_REST_Request
-
The REST request object.
Return values
string|null —The order_by value or null if not set.
get_page()
Get the page number from the request.
public
get_page(WP_REST_Request $request) : int
Parameters
- $request : WP_REST_Request
Return values
int —get_parameters()
Get the parameters for the search.
public
get_parameters(WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $request : WP_REST_Request
Return values
array<string|int, mixed> —get_query_args()
Get the query arguments from the request.
public
get_query_args(WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $request : WP_REST_Request
Return values
array<string|int, mixed> —The query arguments.
get_reset()
Get the reset flag from the request.
public
get_reset(WP_REST_Request $request) : bool
Parameters
- $request : WP_REST_Request
Return values
bool —Whether this is a reset request.
register()
Hook into WP.
public
register() : void
Return values
void —register_routes()
Register the routes for the search functionality.
public
register_routes() : void
Return values
void —requires_rendering()
Check if the search requires rendering.
public
requires_rendering(WP_REST_Request $request) : bool
Parameters
- $request : WP_REST_Request
Return values
bool —retrieve_groups()
Retrieves the groups for the search.
public
retrieve_groups(array<string|int, mixed> $groups) : array<string|int, Group>
Parameters
- $groups : array<string|int, mixed>
-
The list of group IDs.
Return values
array<string|int, Group> —search()
Search the products.
public
search(WP_REST_Request $request) : WP_REST_Response
Parameters
- $request : WP_REST_Request
Return values
WP_REST_Response —send_error()
Send an error response.
protected
send_error(string $message[, int $code = 400 ]) : WP_REST_Response
Parameters
- $message : string
-
The error message.
- $code : int = 400
-
The error code.