Title: rest_pre_dispatch
Published: December 9, 2015
Last modified: April 28, 2025

---

# apply_filters( ‘rest_pre_dispatch’, mixed $result, WP_REST_Server $server, WP_REST_Request $request )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#wp--skip-link--target)

Filters the pre-calculated result of a REST API dispatch request.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#description)󠁿

Allow hijacking the request before dispatching by returning a non-empty. The returned
value will be used to serve the request instead.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#parameters)󠁿

 `$result`mixed

Response to replace the requested version with. Can be anything a normal endpoint
can return, or null to not hijack the request.

`$server`[WP_REST_Server](https://developer.wordpress.org/reference/classes/wp_rest_server/)

Server instance.

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)

Request used to generate the response.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#source)󠁿

    ```php
    $result = apply_filters( 'rest_pre_dispatch', null, $this, $request );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-server.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/class-wp-rest-server.php#L1078)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/class-wp-rest-server.php#L1078-L1078)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Server::serve_batch_request_v1()](https://developer.wordpress.org/reference/classes/wp_rest_server/serve_batch_request_v1/)`wp-includes/rest-api/class-wp-rest-server.php` |

Serves the batch/v1 request.

  | 
| [WP_REST_Server::dispatch()](https://developer.wordpress.org/reference/classes/wp_rest_server/dispatch/)`wp-includes/rest-api/class-wp-rest-server.php` |

Matches the request to a callback and call it.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/rest_pre_dispatch/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frest_pre_dispatch%2F)
before being able to contribute a note or feedback.