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 3 times in this file.

Line Code
445            * Allows modification of the response before returning.
446            *
447            * @since 4.4.0
448            * @since 4.5.0 Applied to embedded responses.
449            *
450            * @param WP_HTTP_Response $result  Result to send to the client. Usually a `WP_REST_Response`.
451            * @param WP_REST_Server   $server  Server instance.
452            * @param WP_REST_Request  $request Request used to generate the response.
453            */
454           $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $request );
455
456           // Wrap the response in an envelope if asked for.
457           if ( isset( $_GET['_envelope'] ) ) {
458                $embed  = isset( $_GET['_embed'] ) ? rest_parse_embed_param( $_GET['_embed'] ) : false;
459                $result = $this->envelope_response( $result, $embed );
460           }
461
462           // Send extra data from response objects.
463           $headers = $result->get_headers();
 
Line Code
735
736                          // Embedded resources get passed context=embed.
737                          if ( empty( $request['context'] ) ) {
738                               $request['context'] = 'embed';
739                          }
740
741                          $response = $this->dispatch( $request );
742
743                          /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
744                          $response = apply_filters( 'rest_post_dispatch', rest_ensure_response( $response ), $this, $request );
745
746                          $this->embed_cache[ $item['href'] ] = $this->response_to_data( $response, false );
747                     }
748
749                     $embeds[] = $this->embed_cache[ $item['href'] ];
750                }
751
752                // Determine if any real links were found.
753                $has_links = count( array_filter( $embeds ) );
 
Line Code
1742                                    array( 'status' => 500 )
1743                               );
1744                          }
1745
1746                          $result = $this->respond_to_request( $single_request, $route, $handler, $error );
1747                     }
1748                }
1749
1750                /** This filter is documented in wp-includes/rest-api/class-wp-rest-server.php */
1751                $result = apply_filters( 'rest_post_dispatch', rest_ensure_response( $result ), $this, $single_request );
1752
1753                $responses[] = $this->envelope_response( $result, false )->get_data();
1754           }
1755
1756           return new WP_REST_Response( array( 'responses' => $responses ), WP_Http::MULTI_STATUS );
1757      }
1758
1759      /**
1760       * Sends an HTTP status code.