Action
rpress_api_output_{$format}
On this page
Fires when an API response is requested in a format other than JSON or XML.
Runs in the default branch of the format switch in RPRESS_API::output(), so a callback hooked to rpress_api_output_{$format} is responsible for printing the whole response in that format. rpress_api_output_after fires afterwards, followed by rpress_die(). Combine with rpress_api_output_format to accept the extra format name.
Parameters#
| Parameter | Type | Description |
|---|---|---|
$arg1 | array | The response data to render. |
$this | RPRESS_API | The API instance. |
Example#
function my_api_output_csv( $data, $api ) {
header( 'Content-Type: text/csv; charset=utf-8' );
$out = fopen( 'php://output', 'w' );
foreach ( $data as $key => $value ) {
fputcsv( $out, array( $key, wp_json_encode( $value ) ) );
}
fclose( $out );
}
add_action( 'rpress_api_output_csv', 'my_api_output_csv', 10, 2 );
Notes#
The hook name is built from the format string, for example rpress_api_output_csv. Not fired for 'json' or 'xml'.
Source#
Fired from:
includes/api/class-rpress-api.php(line 1523), inRPRESS_API::output()includes/class-rpress-api.php(line 1124), inRPRESS_API::output()
See also#
Was this page helpful?
