Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_post_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
390            * Allows modification of the response before returning.
391            *
392            * @since 4.4.0
393            * @since 4.5.0 Applied to embedded responses.
394            *
395            * @param WP_HTTP_Response $result  Result to send to the client. Usually a WP_REST_Response.
396            * @param WP_REST_Server   $this    Server instance.
397            * @param WP_REST_Request  $request Request used to generate the response.
398            */
399           $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request );
400
401           // Wrap the response in an envelope if asked for.
402           if ( isset( $_GET['_envelope'] ) ) {
403                $result = $this->envelope_response( $result, isset( $_GET['_embed'] ) );
404           }
405
406           // Send extra data from response objects.
407           $headers = $result->get_headers();
408           $this->send_headers( $headers );
 
Line Code
654
655                          // Embedded resources get passed context=embed.
656                          if ( empty( $request['context'] ) ) {
657                               $request['context'] = 'embed';
658                          }
659
660                          $response = $this->dispatch( $request );
661
662                          /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
663                          $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request );
664
665                          $this->embed_cache[ $item['href'] ] = $this->response_to_data( $response, false );
666                     }
667
668                     $embeds[] = $this->embed_cache[ $item['href'] ];
669                }
670
671                // Determine if any real links were found.
672                $has_links = count( array_filter( $embeds ) );