diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 066e4181d6..7a89a594ca 100644
a
|
b
|
class WP_REST_Posts_Controller extends WP_REST_Controller { |
1849 | 1849 | } |
1850 | 1850 | } |
1851 | 1851 | |
| 1852 | if ( 'attachment' === $this->post_type ) { |
| 1853 | return $response; |
| 1854 | } |
| 1855 | |
1852 | 1856 | /** |
1853 | 1857 | * Filters the post data for a REST API response. |
1854 | 1858 | * |
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index c023033369..181aaa873b 100644
a
|
b
|
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control |
2154 | 2154 | $this->assertErrorResponse( 'rest_image_not_edited', $response_3, 400 ); |
2155 | 2155 | } |
2156 | 2156 | |
| 2157 | public function test_rest_prepare_attachment_hook_runs_once() { |
| 2158 | $attachment_id = $this->factory->attachment->create_object( |
| 2159 | $this->test_file, |
| 2160 | 0, |
| 2161 | array( |
| 2162 | 'post_mime_type' => 'image/jpeg', |
| 2163 | 'post_excerpt' => 'A sample caption', |
| 2164 | ) |
| 2165 | ); |
| 2166 | |
| 2167 | $filter = new MockAction(); |
| 2168 | add_filter( 'rest_prepare_attachment', array( $filter, 'filter' ) ); |
| 2169 | |
| 2170 | $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); |
| 2171 | rest_get_server()->dispatch( $request ); |
| 2172 | |
| 2173 | $this->assertSame( 1, $filter->get_call_count() ); |
| 2174 | } |
| 2175 | |
2157 | 2176 | /** |
2158 | 2177 | * Sets up the mock image editor. |
2159 | 2178 | * |