Skip to content
Docs
Get RestroPress

Filter

rpress_api_output_data

Updated
On this page

Filters the data returned by the API for a request.

Runs after the endpoint switch has built the response, before the request is logged and output. The default endpoints are stats, products, customers, sales, discounts and info; for any other endpoint the data is an empty array, which lets an extension supply its own response. The request speed is added to the data afterwards.

Parameters#

ParameterTypeDescription
$dataarrayThe response data built for the endpoint.
$endpointstringThe query mode being requested, such as products.
$apiRPRESS_APIThe API object handling the request.

Return value#

array. The response data.

Example#

function my_api_output_data( $data, $endpoint, $api ) {
	if ( 'my-endpoint' === $endpoint ) {
		$data = array( 'status' => 'ok' );
	}
	return $data;
}
add_filter( 'rpress_api_output_data', 'my_api_output_data', 10, 3 );

Notes#

A custom endpoint must also be added to the list from rpress_api_valid_query_modes.

Source#

Applied in:

  • includes/api/class-rpress-api.php (line 501), in RPRESS_API::process_query()
  • includes/class-rpress-api.php (line 312), in RPRESS_API::process_query()

See also#

Was this page helpful?