Ticket #44867: fullpatch-v7-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v7-44867-image-editor-save-modified-image-as-a-new-copy.patch, 2.9 KB (added by , 2 years ago) |
---|
-
wp-admin/includes/image-edit.php
diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 4cb0dc23d7..dec4b8ea08 100644
a b function wp_image_editor( $post_id, $msg = false ) { 243 243 <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> 244 244 </span> 245 245 246 247 <label class="imgedit-label"> 248 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> 249 <?php _e('A newly created image'); ?></label> 246 250 <span class="imgedit-label"> 247 251 <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 248 252 <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> … … function wp_save_image( $post_id ) { 902 906 } 903 907 } 904 908 909 if ( 'new' == $target ) { 910 $original_post_id = $post_id; 911 $post_id = NULL; 912 } 913 905 914 // Save the full-size file, also needed to create sub-sizes. 906 915 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 907 916 $return->error = esc_js( __( 'Unable to save the image.' ) ); … … function wp_save_image( $post_id ) { 951 960 $success = true; 952 961 $delete = true; 953 962 $nocrop = true; 963 } elseif ( 'new' === $target ) { 964 $size = $img->get_size(); 965 $meta['width'] = $size['width']; // cropped and saved as a copy 966 $meta['height'] = $size['height']; 967 968 $new_post = (array)$post; 969 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 970 $new_post['post_title'] = preg_match('/\.[a-z]{3}$/', $new_post['post_title']) ? preg_replace('/(\.[a-z]{3})/', '-media-copy\1', $new_post['post_title']) : $new_post['post_title'] . '-mediacopy'; 971 972 $wp_upload_dir = wp_upload_dir(); 973 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 974 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 975 if ( is_wp_error( $post_id ) ) { 976 $return->error = esc_js( __('Unable to create a new atachment.') ); 977 return $return; 978 } 979 $return->refresh = TRUE; 980 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 981 $success = true; 982 983 update_attached_file( $post_id, $new_path ); 984 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 985 986 $sizes = get_intermediate_image_sizes(); 987 $delete = $nocrop = false; 954 988 } else { 955 989 $sizes = array( $target ); 956 990 $success = true; -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index 18d3099f62..4fc90544e3 100644
a b function( response ) { 561 561 } 562 562 563 563 if ( self._view ) { 564 if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } 564 565 self._view.save(); 565 566 } else { 566 567 imageEdit.close(postid);