Changeset 48510
- Timestamp:
- 07/19/2020 09:17:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r48498 r48510 546 546 547 547 // Create new attachment post. 548 $ attachment_post = array(548 $new_attachment_post = array( 549 549 'post_mime_type' => $saved['mime-type'], 550 550 'guid' => $uploads['url'] . "/$filename", 551 'post_title' => $ filename,551 'post_title' => $image_name, 552 552 'post_content' => '', 553 553 ); 554 554 555 $new_attachment_id = wp_insert_attachment( wp_slash( $attachment_post ), $saved['path'], 0, true ); 555 // Copy post_content, post_excerpt, and post_title from the edited image's attachment post. 556 $attachment_post = get_post( $attachment_id ); 557 558 if ( $attachment_post ) { 559 $new_attachment_post['post_content'] = $attachment_post->post_content; 560 $new_attachment_post['post_excerpt'] = $attachment_post->post_excerpt; 561 $new_attachment_post['post_title'] = $attachment_post->post_title; 562 } 563 564 $new_attachment_id = wp_insert_attachment( wp_slash( $new_attachment_post ), $saved['path'], 0, true ); 556 565 557 566 if ( is_wp_error( $new_attachment_id ) ) { … … 565 574 } 566 575 576 // Copy the image alt text from the edited image. 577 $image_alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); 578 579 if ( ! empty( $image_alt ) ) { 580 // update_post_meta() expects slashed. 581 update_post_meta( $new_attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); 582 } 583 567 584 // Generate image sub-sizes and meta. 568 585 $new_image_meta = wp_generate_attachment_metadata( $new_attachment_id, $saved['path'] ); 569 586 570 587 // Copy the EXIF metadata from the original attachment if not generated for the edited image. 571 if ( ! empty( $image_meta['image_meta'] ) ) { 572 $empty_image_meta = true; 573 574 if ( isset( $new_image_meta['image_meta'] ) && is_array( $new_image_meta['image_meta'] ) ) { 575 $empty_image_meta = empty( array_filter( array_values( $new_image_meta['image_meta'] ) ) ); 576 } 577 578 if ( $empty_image_meta ) { 579 $new_image_meta['image_meta'] = $image_meta['image_meta']; 588 if ( isset( $image_meta['image_meta'] ) && isset( $new_image_meta['image_meta'] ) && is_array( $new_image_meta['image_meta'] ) ) { 589 // Merge but skip empty values. 590 foreach ( (array) $image_meta['image_meta'] as $key => $value ) { 591 if ( empty( $new_image_meta['image_meta'][ $key ] ) && ! empty( $value ) ) { 592 $new_image_meta['image_meta'][ $key ] = $value; 593 } 580 594 } 581 595 }
Note: See TracChangeset
for help on using the changeset viewer.