rest_pre_serve_request
Filter HookDescription
Filters whether the REST API request has already been served. Allow sending the request manually - by returning true, the API result will not be sent to the client.Hook Information
File Location |
wp-includes/rest-api/class-wp-rest-server.php
View on GitHub
|
Hook Type | Filter |
Line Number | 515 |
Hook Parameters
Type | Name | Description |
---|---|---|
bool
|
$served
|
Whether the request has already been served. Default false. |
WP_HTTP_Response
|
$result
|
Result to send to the client. Usually a `WP_REST_Response`. |
WP_REST_Request
|
$request
|
Request used to generate the response. |
WP_REST_Server
|
$server
|
Server instance. |
Usage Examples
Basic Usage
<?php
// Hook into rest_pre_serve_request
add_filter('rest_pre_serve_request', 'my_custom_filter', 10, 4);
function my_custom_filter($served, $result, $request, $server) {
// Your custom filtering logic here
return $served;
}
Source Code Context
wp-includes/rest-api/class-wp-rest-server.php:515
- How this hook is used in WordPress core
<?php
510 * Default false.
511 * @param WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`.
512 * @param WP_REST_Request $request Request used to generate the response.
513 * @param WP_REST_Server $server Server instance.
514 */
515 $served = apply_filters( 'rest_pre_serve_request', false, $result, $request, $this );
516
517 if ( ! $served ) {
518 if ( 'HEAD' === $request->get_method() ) {
519 return null;
520 }
PHP Documentation
<?php
/**
* Filters whether the REST API request has already been served.
*
* Allow sending the request manually - by returning true, the API result
* will not be sent to the client.
*
* @since 4.4.0
*
* @param bool $served Whether the request has already been served.
* Default false.
* @param WP_HTTP_Response $result Result to send to the client. Usually a `WP_REST_Response`.
* @param WP_REST_Request $request Request used to generate the response.
* @param WP_REST_Server $server Server instance.
*/
Quick Info
- Hook Type: Filter
- Parameters: 4
- File: wp-includes/rest-api/class-wp-rest-server.php
Related Hooks
Related hooks will be displayed here in future updates.