rest_prepare_attachment filter-hookWP 4.7.0

Filters the post data for a REST API response.

This is one of the variants of the dynamic hook rest_prepare_(post_type)

Usage

add_filter( 'rest_prepare_attachment', 'wp_kama_rest_prepare_attachment_filter', 10, 3 );

/**
 * Function for `rest_prepare_attachment` filter-hook.
 * 
 * @param WP_REST_Response $response The response object.
 * @param WP_Post          $post     Post object.
 * @param WP_REST_Request  $request  Request object.
 *
 * @return WP_REST_Response
 */
function wp_kama_rest_prepare_attachment_filter( $response, $post, $request ){

	// filter...
	return $response;
}
$response(WP_REST_Response)
The response object.
$post(WP_Post)
Post object.
$request(WP_REST_Request)
Request object.

Changelog

Since 4.7.0 Introduced.

Where the hook is called

WP_REST_Posts_Controller::prepare_item_for_response()
rest_prepare_attachment
WP_REST_Attachments_Controller::prepare_item_for_response()
rest_prepare_attachment
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php 2013
return apply_filters( "rest_prepare_{$this->post_type}", $response, $post, $request );
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php 852
return apply_filters( 'rest_prepare_attachment', $response, $post, $request );

Where the hook is used in WordPress

Usage not found.