Changeset 43530
- Timestamp:
- 07/24/2018 04:53:17 PM (6 years ago)
- Location:
- branches/4.9
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
-
branches/4.9/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r43489 r43530 137 137 138 138 $attachment = $this->prepare_item_for_database( $request ); 139 $attachment->file = $file;140 139 $attachment->post_mime_type = $type; 141 140 $attachment->guid = $url; … … 145 144 } 146 145 147 $id = wp_insert_post( wp_slash( (array) $attachment ), true ); 146 // $post_parent is inherited from $attachment['post_parent']. 147 $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true ); 148 148 149 149 if ( is_wp_error( $id ) ) { -
branches/4.9/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r43489 r43530 696 696 $attachment = $response->get_data(); 697 697 $this->assertEquals( '', $attachment['alt_text'] ); 698 } 699 700 /** 701 * @ticket 40861 702 */ 703 public function test_create_item_ensure_relative_path() { 704 wp_set_current_user( self::$author_id ); 705 $request = new WP_REST_Request( 'POST', '/wp/v2/media' ); 706 $request->set_header( 'Content-Type', 'image/jpeg' ); 707 $request->set_header( 'Content-Disposition', 'attachment; filename=canola.jpg' ); 708 $request->set_body( file_get_contents( $this->test_file ) ); 709 $response = rest_get_server()->dispatch( $request ); 710 $attachment = $response->get_data(); 711 $this->assertNotContains( ABSPATH, get_post_meta( $attachment['id'], '_wp_attached_file', true ) ); 698 712 } 699 713
Note: See TracChangeset
for help on using the changeset viewer.