diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index 5d046dd646..ebb24d059f 100644
|
a
|
b
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
| 130 | 130 | return $insert; |
| 131 | 131 | } |
| 132 | 132 | |
| | 133 | $schema = $this->get_item_schema(); |
| | 134 | |
| 133 | 135 | // Extract by name. |
| 134 | 136 | $attachment_id = $insert['attachment_id']; |
| 135 | 137 | $file = $insert['file']; |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
| 138 | 140 | update_post_meta( $attachment_id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) ); |
| 139 | 141 | } |
| 140 | 142 | |
| | 143 | if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { |
| | 144 | $meta_update = $this->meta->update_value( $request['meta'], $attachment_id ); |
| | 145 | |
| | 146 | if ( is_wp_error( $meta_update ) ) { |
| | 147 | return $meta_update; |
| | 148 | } |
| | 149 | } |
| | 150 | |
| 141 | 151 | $attachment = get_post( $attachment_id ); |
| 142 | 152 | $fields_update = $this->update_additional_fields_for_object( $attachment, $request ); |
| 143 | 153 | |
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index 60686523fd..11fe0bc184 100644
|
a
|
b
|
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | public function test_search_item_by_filename() { |
| 1454 | | $id1 = $this->factory->attachment->create_object( |
| | 1454 | $id = $this->factory->attachment->create_object( |
| 1455 | 1455 | $this->test_file, |
| 1456 | 1456 | 0, |
| 1457 | 1457 | array( |
| … |
… |
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
| 1740 | 1740 | $this->assertSame( 1, self::$rest_after_insert_attachment_count ); |
| 1741 | 1741 | } |
| 1742 | 1742 | |
| | 1743 | /** |
| | 1744 | * @ticket 44567 |
| | 1745 | */ |
| | 1746 | public function test_create_item_with_meta_values() { |
| | 1747 | register_post_meta( |
| | 1748 | 'attachment', |
| | 1749 | 'canola_status', |
| | 1750 | array( |
| | 1751 | 'type' => 'string', |
| | 1752 | 'single' => true, |
| | 1753 | 'show_in_rest' => true, |
| | 1754 | ) |
| | 1755 | ); |
| | 1756 | |
| | 1757 | wp_set_current_user( self::$author_id ); |
| | 1758 | |
| | 1759 | $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); |
| | 1760 | $request->set_header( 'Content-Type', 'image/jpeg' ); |
| | 1761 | $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); |
| | 1762 | $request->set_param( 'meta', array( 'canola_status' => 'Canola is awesome' ) ); |
| | 1763 | |
| | 1764 | $request->set_body( file_get_contents( $this->test_file ) ); |
| | 1765 | $response = rest_get_server()->dispatch( $request ); |
| | 1766 | $data = $response->get_data(); |
| | 1767 | |
| | 1768 | $this->assertEquals( 201, $response->get_status() ); |
| | 1769 | $this->assertEquals( 'Canola is awesome', get_post_meta( $response->get_data()['id'], 'canola_status', true ) ); |
| | 1770 | } |
| | 1771 | |
| 1743 | 1772 | public function filter_rest_insert_attachment( $attachment ) { |
| 1744 | 1773 | self::$rest_insert_attachment_count++; |
| 1745 | 1774 | } |