rest_request_after_callbacks filter-hookWP 4.7.0

Filters the response immediately after executing any REST API callbacks.

Allows plugins to perform any needed cleanup, for example, to undo changes made during the rest_request_before_callbacks filter.

Note that this filter will not be called for requests that fail to authenticate or match to a registered route.

Note that an endpoint's permission_callback can still be called after this filter - see rest_send_allow_header().

Usage

add_filter( 'rest_request_after_callbacks', 'wp_kama_rest_request_after_callbacks_filter', 10, 3 );

/**
 * Function for `rest_request_after_callbacks` filter-hook.
 * 
 * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. Usually a WP_REST_Response or WP_Error.
 * @param array                                            $handler  Route handler used for the request.
 * @param WP_REST_Request                                  $request  Request used to generate the response.
 *
 * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed
 */
function wp_kama_rest_request_after_callbacks_filter( $response, $handler, $request ){

	// filter...
	return $response;
}
$response(WP_REST_Response|WP_HTTP_Response|WP_Error|mixed)
Result to send to the client. Usually a WP_REST_Response or WP_Error.
$handler(array)
Route handler used for the request.
$request(WP_REST_Request)
Request used to generate the response.

Changelog

Since 4.7.0 Introduced.

Where the hook is called

WP_REST_Server::respond_to_request()
rest_request_after_callbacks
wp-includes/rest-api/class-wp-rest-server.php 1218
$response = apply_filters( 'rest_request_after_callbacks', $response, $handler, $request );

Where the hook is used in WordPress

Usage not found.