rest_request_before_callbacks
Filter HookDescription
Filters the response before executing any REST API callbacks. Allows plugins to perform additional validation after a request is initialized and matched to a registered route, but before it is executed. Note that this filter will not be called for requests that fail to authenticate or match to a registered route.Hook Information
File Location |
wp-includes/rest-api/class-wp-rest-server.php
View on GitHub
|
Hook Type | Filter |
Line Number | 1255 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_REST_Response|WP_HTTP_Response|WP_Error|mixed
|
$response
|
Result to send to the client. Usually a WP_REST_Response or WP_Error. |
array
|
$handler
|
Route handler used for the request. |
WP_REST_Request
|
$request
|
Request used to generate the response. |
Usage Examples
Basic Usage
<?php
// Hook into rest_request_before_callbacks
add_filter('rest_request_before_callbacks', 'my_custom_filter', 10, 3);
function my_custom_filter($response, $handler, $request) {
// Your custom filtering logic here
return $response;
}
Source Code Context
wp-includes/rest-api/class-wp-rest-server.php:1255
- How this hook is used in WordPress core
<?php
1250 * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client.
1251 * Usually a WP_REST_Response or WP_Error.
1252 * @param array $handler Route handler used for the request.
1253 * @param WP_REST_Request $request Request used to generate the response.
1254 */
1255 $response = apply_filters( 'rest_request_before_callbacks', $response, $handler, $request );
1256
1257 // Check permission specified on the route.
1258 if ( ! is_wp_error( $response ) && ! empty( $handler['permission_callback'] ) ) {
1259 $permission = call_user_func( $handler['permission_callback'], $request );
1260
PHP Documentation
<?php
/**
* Filters the response before executing any REST API callbacks.
*
* Allows plugins to perform additional validation after a
* request is initialized and matched to a registered route,
* but before it is executed.
*
* Note that this filter will not be called for requests that
* fail to authenticate or match to a registered route.
*
* @since 4.7.0
*
* @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.
*/
Quick Info
- Hook Type: Filter
- Parameters: 3
- File: wp-includes/rest-api/class-wp-rest-server.php
Related Hooks
Related hooks will be displayed here in future updates.