Ticket #44867: fullpatch-v9-44867-image-editor-save-modified-image-as-a-new-copy.patch
| File fullpatch-v9-44867-image-editor-save-modified-image-as-a-new-copy.patch, 2.8 KB (added by , 15 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 7f9ebf7f9f..9037bcb34d 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 ) { 1006 1011 } 1007 1012 } 1008 1013 1014 if ('new' == $target) { 1015 $original_post_id = $post_id; 1016 $post_id = NULL; 1017 } 1018 1009 1019 $saved_image = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ); 1010 1020 // Save the full-size file, also needed to create sub-sizes. 1011 1021 if ( ! $saved_image ) { … … function wp_save_image( $post_id ) { 1059 1069 $success = true; 1060 1070 $delete = true; 1061 1071 $nocrop = true; 1072 } elseif ( 'new' === $target ) { 1073 $size = $img->get_size(); 1074 $meta['width'] = $size['width']; // cropped and saved as a copy 1075 $meta['height'] = $size['height']; 1076 1077 $new_post = (array)$post; 1078 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 1079 $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'; 1080 1081 $wp_upload_dir = wp_upload_dir(); 1082 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 1083 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 1084 if ( is_wp_error( $post_id ) ) { 1085 $return->error = esc_js( __('Unable to create a new atachment.') ); 1086 return $return; 1087 } 1088 $return->refresh = TRUE; 1089 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 1090 $success = true; 1091 1092 update_attached_file( $post_id, $new_path ); 1093 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 1094 1095 $sizes = get_intermediate_image_sizes(); 1096 $delete = $nocrop = false; 1062 1097 } 1063 1098 1064 1099 /* -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index d1603051d7..8c87418a21 100644
a b 780 780 } 781 781 782 782 if ( self._view ) { 783 if ( response.data.refresh ) { /* ToDo: refresh media view when going back. */ } 783 784 self._view.save(); 784 785 } else { 785 786 imageEdit.close(postid);