From 8f6088ba6ebd1d71deb76959e9c412a3abe23375 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Thu, 29 Jun 2017 13:17:43 +0000 Subject: [PATCH] REST API: Add a filter to allow modifying the response *after* embedded data is added. Fixes #38964. Built from https://develop.svn.wordpress.org/trunk@40961 git-svn-id: http://core.svn.wordpress.org/trunk@40811 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api/class-wp-rest-server.php | 14 ++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/class-wp-rest-server.php b/wp-includes/rest-api/class-wp-rest-server.php index 11b8897a2b..2ec8ccde23 100644 --- a/wp-includes/rest-api/class-wp-rest-server.php +++ b/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(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 96ce9ac03d..d82ed1ab6b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-40960'; +$wp_version = '4.9-alpha-40961'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.