Skip to content
Docs
Get RestroPress

Filter

rpress_api_products

Updated
On this page

Filters the products data returned by the products API endpoint.

Runs at the end of the products request after the product list or single product has been built. The array has a products key holding a list of product data arrays. It is applied for both API versions.

Parameters#

ParameterTypeDescription
$productsarrayAPI response data containing the products list.
$apiRPRESS_APIThe API object handling the request.

Return value#

array. The products response data.

Example#

function my_api_products( $products, $api = null ) {
	if ( ! empty( $products['products'] ) ) {
		foreach ( $products['products'] as $key => $product ) {
			$products['products'][ $key ]['source'] = 'restropress';
		}
	}
	return $products;
}
add_filter( 'rpress_api_products', 'my_api_products', 10, 2 );

Notes#

The v2 handler passes only $products; the base handler also passes the API object, so give the second callback argument a default value.

Source#

Applied in:

  • includes/api/class-rpress-api-v2.php (line 114), in RPRESS_API_V2::get_products()
  • includes/api/class-rpress-api.php (line 879), in RPRESS_API::get_products()

See also#

Was this page helpful?