From 5c4f490ea8d77ccd125518a49d6cac8753c8ed25 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Thu, 29 Jun 2017 13:16:19 +0000 Subject: [PATCH] REST API: Add a filter to allow modifying the response *after* embedded data is added. Fixes #38964. git-svn-id: https://develop.svn.wordpress.org/trunk@40961 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rest-api/class-wp-rest-server.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wp-includes/rest-api/class-wp-rest-server.php b/src/wp-includes/rest-api/class-wp-rest-server.php index 11b8897a2b..2ec8ccde23 100644 --- a/src/wp-includes/rest-api/class-wp-rest-server.php +++ b/src/wp-includes/rest-api/class-wp-rest-server.php @@ -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();