Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_pre_dispatch

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
982            * will be used to serve the request instead.
983            *
984            * @since 4.4.0
985            *
986            * @param mixed           $result  Response to replace the requested version with. Can be anything
987            *                                 a normal endpoint can return, or null to not hijack the request.
988            * @param WP_REST_Server  $server  Server instance.
989            * @param WP_REST_Request $request Request used to generate the response.
990            */
991           $result = apply_filters( 'rest_pre_dispatch', null, $this, $request );
992
993           if ( ! empty( $result ) ) {
994
995                // Normalize to either WP_Error or WP_REST_Response...
996                $result = rest_ensure_response( $result );
997
998                // ...then convert WP_Error across.
999                if ( is_wp_error( $result ) ) {
1000                     $result = $this->error_to_response( $result );
 
Line Code
1696           }
1697
1698           foreach ( $requests as $i => $single_request ) {
1699                $clean_request = clone $single_request;
1700                $clean_request->set_url_params( array() );
1701                $clean_request->set_attributes( array() );
1702                $clean_request->set_default_params( array() );
1703
1704                /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
1705                $result = apply_filters( 'rest_pre_dispatch', null, $this, $clean_request );
1706
1707                if ( empty( $result ) ) {
1708                     $match = $matches[ $i ];
1709                     $error = null;
1710
1711                     if ( is_wp_error( $validation[ $i ] ) ) {
1712                          $error = $validation[ $i ];
1713                     }
1714