Ticket #50675: 50675.diff
File 50675.diff, 2.4 KB (added by , 4 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
541 541 } 542 542 543 543 // Create new attachment post. 544 $ attachment_post = array(544 $new_attachment_post = array( 545 545 'post_mime_type' => $saved['mime-type'], 546 546 'guid' => $uploads['url'] . "/$filename", 547 547 'post_title' => $filename, … … 548 548 'post_content' => '', 549 549 ); 550 550 551 $new_attachment_id = wp_insert_attachment( wp_slash( $attachment_post ), $saved['path'], 0, true ); 551 // Copy post_content and post_excerps from the edited image's attachment post. 552 $attachment_post = get_post( $attachment_id ); 552 553 554 if ( $attachment_post ) { 555 $new_attachment_post['post_content'] = $attachment_post->post_content; 556 $new_attachment_post['post_excerpt'] = $attachment_post->post_excerpt; 557 } 558 559 $new_attachment_id = wp_insert_attachment( wp_slash( $new_attachment_post ), $saved['path'], 0, true ); 560 553 561 if ( is_wp_error( $new_attachment_id ) ) { 554 562 if ( 'db_update_error' === $new_attachment_id->get_error_code() ) { 555 563 $new_attachment_id->add_data( array( 'status' => 500 ) ); … … 564 572 $new_image_meta = wp_generate_attachment_metadata( $new_attachment_id, $saved['path'] ); 565 573 566 574 // Copy the EXIF metadata from the original attachment if not generated for the edited image. 567 if ( ! empty( $image_meta['image_meta'] ) ) { 568 $empty_image_meta = true; 569 570 if ( isset( $new_image_meta['image_meta'] ) && is_array( $new_image_meta['image_meta'] ) ) { 571 $empty_image_meta = empty( array_filter( array_values( $new_image_meta['image_meta'] ) ) ); 575 if ( isset( $image_meta['image_meta'] ) && isset( $new_image_meta['image_meta'] ) && is_array( $new_image_meta['image_meta'] ) ) { 576 // Merge but skip empty values. 577 foreach( (array) $image_meta['image_meta'] as $key => $value ) { 578 if ( empty( $new_image_meta['image_meta'][ $key ] ) && ! empty( $value ) ) { 579 $new_image_meta['image_meta'][ $key ] = $value; 580 } 572 581 } 573 574 if ( $empty_image_meta ) {575 $new_image_meta['image_meta'] = $image_meta['image_meta'];576 }577 582 } 578 583 579 584 // Reset orientation. At this point the image is edited and orientation is correct.