Filter hook 'rest_request_after_callbacks'

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

View Source

rest_request_after_callbacks

Filter Hook
Description
Filters the response immediately after executing any REST API callbacks. Allows plugins to perform any needed cleanup, for example, to undo changes made during the {@see 'rest_request_before_callbacks'} filter. Note that this filter will not be called for requests that fail to authenticate or match to a registered route. Note that an endpoint's `permission_callback` can still be called after this filter - see `rest_send_allow_header()`.

Hook Information

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

Hook Parameters

Type Name Description
WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. Usually a WP_REST_Response or WP_Error.
array $handler Route handler used for the request.
WP_REST_Request $request Request used to generate the response.

Usage Examples

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

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

Source Code Context

wp-includes/rest-api/class-wp-rest-server.php:1317 - How this hook is used in WordPress core
<?php
1312  		 * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client.
1313  		 *                                                                   Usually a WP_REST_Response or WP_Error.
1314  		 * @param array                                            $handler  Route handler used for the request.
1315  		 * @param WP_REST_Request                                  $request  Request used to generate the response.
1316  		 */
1317  		$response = apply_filters( 'rest_request_after_callbacks', $response, $handler, $request );
1318  
1319  		if ( is_wp_error( $response ) ) {
1320  			$response = $this->error_to_response( $response );
1321  		} else {
1322  			$response = rest_ensure_response( $response );

PHP Documentation

<?php
/**
		 * Filters the response immediately after executing any REST API
		 * callbacks.
		 *
		 * Allows plugins to perform any needed cleanup, for example,
		 * to undo changes made during the {@see 'rest_request_before_callbacks'}
		 * filter.
		 *
		 * Note that this filter will not be called for requests that
		 * fail to authenticate or match to a registered route.
		 *
		 * Note that an endpoint's `permission_callback` can still be
		 * called after this filter - see `rest_send_allow_header()`.
		 *
		 * @since 4.7.0
		 *
		 * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client.
		 *                                                                   Usually a WP_REST_Response or WP_Error.
		 * @param array                                            $handler  Route handler used for the request.
		 * @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.