Ticket #44867: fullpatch-v8-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v8-44867-image-editor-save-modified-image-as-a-new-copy.patch, 2.9 KB (added by , 9 months ago) |
---|
-
wp-admin/includes/image-edit.php
diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 739b09f9a1..accaebf806 100644
a b function wp_image_editor( $post_id, $msg = false ) { 310 310 <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> 311 311 </span> 312 312 313 <span class="imgedit-label"> 314 <input type="radio" id="imgedit-target-newfile" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> 315 <label for="imgedit-target-newfile"><?php _e('A newly created image'); ?></label> 316 </span> 317 313 318 <span class="imgedit-label"> 314 319 <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 315 320 <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> … … function wp_save_image( $post_id ) { 986 991 } 987 992 } 988 993 994 if ('new' == $target) { 995 $original_post_id = $post_id; 996 $post_id = NULL; 997 } 998 989 999 // Save the full-size file, also needed to create sub-sizes. 990 1000 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 991 1001 $return->error = esc_js( __( 'Unable to save the image.' ) ); … … function wp_save_image( $post_id ) { 1036 1046 $success = true; 1037 1047 $delete = true; 1038 1048 $nocrop = true; 1049 } elseif ( 'new' === $target ) { 1050 $size = $img->get_size(); 1051 $meta['width'] = $size['width']; // cropped and saved as a copy 1052 $meta['height'] = $size['height']; 1053 1054 $new_post = (array)$post; 1055 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 1056 $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'; 1057 1058 $wp_upload_dir = wp_upload_dir(); 1059 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 1060 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 1061 if ( is_wp_error( $post_id ) ) { 1062 $return->error = esc_js( __('Unable to create a new atachment.') ); 1063 return $return; 1064 } 1065 $return->refresh = TRUE; 1066 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 1067 $success = true; 1068 1069 update_attached_file( $post_id, $new_path ); 1070 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 1071 1072 $sizes = get_intermediate_image_sizes(); 1073 $delete = $nocrop = false; 1039 1074 } 1040 1075 1041 1076 /* -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index b41e93f55d..b804067cf4 100644
a b function( response ) { 760 760 } 761 761 762 762 if ( self._view ) { 763 if ( response.data.refresh ) { /* ToDo: refresh media view when going back. */ } 763 764 self._view.save(); 764 765 } else { 765 766 imageEdit.close(postid);