Filter hook 'rest_prepare_attachment'

in WP Core File wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php at line 970

View Source

rest_prepare_attachment

Filter Hook
Description
Filters an attachment returned from the REST API. Allows modification of the attachment right before it is returned.

Hook Information

File Location wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php View on GitHub
Hook Type Filter
Line Number 970

Hook Parameters

Type Name Description
WP_REST_Response $response The response object.
WP_Post $post The original attachment post.
WP_REST_Request $request Request used to generate the response.

Usage Examples

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

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

Source Code Context

wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:970 - How this hook is used in WordPress core
<?php
 965  		 *
 966  		 * @param WP_REST_Response $response The response object.
 967  		 * @param WP_Post          $post     The original attachment post.
 968  		 * @param WP_REST_Request  $request  Request used to generate the response.
 969  		 */
 970  		return apply_filters( 'rest_prepare_attachment', $response, $post, $request );
 971  	}
 972  
 973  	/**
 974  	 * Retrieves the attachment's schema, conforming to JSON Schema.
 975  	 *

PHP Documentation

<?php
/**
		 * Filters an attachment returned from the REST API.
		 *
		 * Allows modification of the attachment right before it is returned.
		 *
		 * @since 4.7.0
		 *
		 * @param WP_REST_Response $response The response object.
		 * @param WP_Post          $post     The original attachment post.
		 * @param WP_REST_Request  $request  Request used to generate the response.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Related Hooks

Related hooks will be displayed here in future updates.