rest_post_dispatch
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
rest_post_dispatch
rest_post_dispatch
rest_post_dispatch
rest_post_dispatch
wp-includes/rest-api/class-wp-rest-server.php 458
$result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request );
wp-includes/rest-api.php 2989
$response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $server, $request );
wp-includes/rest-api/class-wp-rest-server.php 818
$response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request );
wp-includes/rest-api/class-wp-rest-server.php 1861
$result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $single_request );
Where the hook is used in WordPress
wp-includes/connectors.php 566
add_filter( 'rest_post_dispatch', '_wp_connectors_rest_settings_dispatch', 10, 3 );
wp-includes/rest-api.php 253
add_filter( 'rest_post_dispatch', 'rest_send_allow_header', 10, 3 );
wp-includes/rest-api.php 254
add_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10, 3 );