REST API: Add a filter to allow modifying the response *after* embedded data is added.

Merges [40961] onto 4.8 branch.
Props jnylen0.
Fixes #38964 for 4.8.1.

Built from https://develop.svn.wordpress.org/branches/4.8@41093


git-svn-id: http://core.svn.wordpress.org/branches/4.8@40933 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-07-19 20:12:38 +00:00
parent aef4b48187
commit 8575d4e180
1 changed files with 14 additions and 0 deletions

View File

@ -387,6 +387,20 @@ class WP_REST_Server {
// Embed links inside the request.
$result = $this->response_to_data( $result, isset( $_GET['_embed'] ) );
/**
* Filters the 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 $this Server instance.
* @param WP_REST_Request $request Request used to generate the response.
*/
$result = apply_filters( 'rest_pre_echo_response', $result, $this, $request );
$result = wp_json_encode( $result );
$json_error_message = $this->get_json_last_error();