Changeset 47261
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r47122 r47261 142 142 } 143 143 144 $schema = $this->get_item_schema(); 145 144 146 // Extract by name. 145 147 $attachment_id = $insert['attachment_id']; … … 148 150 if ( isset( $request['alt_text'] ) ) { 149 151 update_post_meta( $attachment_id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) ); 152 } 153 154 if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { 155 $meta_update = $this->meta->update_value( $request['meta'], $attachment_id ); 156 157 if ( is_wp_error( $meta_update ) ) { 158 return $meta_update; 159 } 150 160 } 151 161 -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r47122 r47261 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 'best_cannoli', 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=cannoli.jpg' ); 1762 $request->set_param( 'meta', array( 'best_cannoli' => 'Chocolate-dipped, no filling' ) ); 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( 'Chocolate-dipped, no filling', get_post_meta( $response->get_data()['id'], 'best_cannoli', true ) ); 1770 } 1771 1743 1772 public function filter_rest_insert_attachment( $attachment ) { 1744 1773 self::$rest_insert_attachment_count++;
Note: See TracChangeset
for help on using the changeset viewer.