rest_post_dispatch filter-hookWP 4.4.0

Filters the REST API response.

Allows modification of the response before returning.

Usage

add_filter( 'rest_post_dispatch', 'wp_kama_rest_post_dispatch_filter', 10, 3 );

/**
 * Function for `rest_post_dispatch` filter-hook.
 * 
 * @param WP_HTTP_Response $result  Result to send to the client. Usually a `WP_REST_Response`.
 * @param WP_REST_Server   $server  Server instance.
 * @param WP_REST_Request  $request Request used to generate the response.
 *
 * @return WP_HTTP_Response
 */
function wp_kama_rest_post_dispatch_filter( $result, $server, $request ){

	// filter...
	return $result;
}
$result(WP_HTTP_Response)
Result to send to the client. Usually a WP_REST_Response.
$server(WP_REST_Server)
Server instance.
$request(WP_REST_Request)
Request used to generate the response.

Changelog

Since 4.4.0 Introduced.
Since 4.5.0 Applied to embedded responses.

Where the hook is called

WP_REST_Server::serve_request()
rest_post_dispatch
rest_preload_api_request()
rest_post_dispatch
WP_REST_Server::embed_links()
rest_post_dispatch
WP_REST_Server::serve_batch_request_v1()
rest_post_dispatch
wp-includes/rest-api/class-wp-rest-server.php 462
$result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request );
wp-includes/rest-api.php 2926
$response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $server, $request );
wp-includes/rest-api/class-wp-rest-server.php 761
$response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request );
wp-includes/rest-api/class-wp-rest-server.php 1795
$result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $single_request );

Where the hook is used in WordPress

wp-includes/rest-api.php 224
add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
wp-includes/rest-api.php 225
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );