Filter hook 'rest_pre_echo_response'

in WP Core File wp-includes/rest-api/class-wp-rest-server.php at line 538

View Source

rest_pre_echo_response

Filter Hook
Description
Filters the REST API response. Allows modification of the response data after inserting embedded data (if any) and before echoing the response data.

Hook Information

File Location wp-includes/rest-api/class-wp-rest-server.php View on GitHub
Hook Type Filter
Line Number 538

Hook Parameters

Type Name Description
array $result Response data to send to the client.
WP_REST_Server $server Server instance.
WP_REST_Request $request Request used to generate the response.

Usage Examples

Basic Usage
<?php
// Hook into rest_pre_echo_response
add_filter('rest_pre_echo_response', 'my_custom_filter', 10, 3);

function my_custom_filter($result, $server, $request) {
    // Your custom filtering logic here
    return $result;
}

Source Code Context

wp-includes/rest-api/class-wp-rest-server.php:538 - How this hook is used in WordPress core
<?php
 533  			 *
 534  			 * @param array            $result  Response data to send to the client.
 535  			 * @param WP_REST_Server   $server  Server instance.
 536  			 * @param WP_REST_Request  $request Request used to generate the response.
 537  			 */
 538  			$result = apply_filters( 'rest_pre_echo_response', $result, $this, $request );
 539  
 540  			// The 204 response shouldn't have a body.
 541  			if ( 204 === $code || null === $result ) {
 542  				return null;
 543  			}

PHP Documentation

<?php
/**
			 * Filters the REST API response.
			 *
			 * Allows modification of the response data after inserting
			 * embedded data (if any) and before echoing the response data.
			 *
			 * @since 4.8.1
			 *
			 * @param array            $result  Response data to send to the client.
			 * @param WP_REST_Server   $server  Server instance.
			 * @param WP_REST_Request  $request Request used to generate the response.
			 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/rest-api/class-wp-rest-server.php
Related Hooks

Related hooks will be displayed here in future updates.