Ticket #44867: fullpatch-v4-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v4-44867-image-editor-save-modified-image-as-a-new-copy.patch, 2.8 KB (added by , 5 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 4605aa4..a719adc 100644
a b function wp_image_editor( $post_id, $msg = false ) { 181 181 <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> 182 182 </span> 183 183 184 185 <label class="imgedit-label"> 186 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> 187 <?php _e('A newly created image'); ?></label> 184 188 <span class="imgedit-label"> 185 189 <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 186 190 <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> … … function wp_save_image( $post_id ) { 852 856 $post_id = NULL; 853 857 } 854 858 859 if ( 'new' == $target ) { 860 $original_post_id = $post_id; 861 $post_id = NULL; 862 } 863 855 864 // Save the full-size file, also needed to create sub-sizes. 856 865 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 857 866 $return->error = esc_js( __( 'Unable to save the image.' ) ); … … function wp_save_image( $post_id ) { 897 906 $success = true; 898 907 $delete = true; 899 908 $nocrop = true; 909 } elseif ( 'new' == $target ) { 910 $size = $img->get_size(); 911 $meta['width'] = $size['width']; // cropped and saved as a copy 912 $meta['height'] = $size['height']; 913 914 $new_post = (array)$post; 915 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 916 $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'; 917 918 $wp_upload_dir = wp_upload_dir(); 919 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 920 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 921 if ( is_wp_error( $post_id ) ) { 922 $return->error = esc_js( __('Unable to create a new atachment.') ); 923 return $return; 924 } 925 $return->refresh = TRUE; 926 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 927 $success = true; 928 929 update_attached_file( $post_id, $new_path ); 930 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 931 932 $sizes = get_intermediate_image_sizes(); 933 $delete = $nocrop = false; 900 934 } 901 935 902 936 /* -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index d664912..35addc0 100644
a b function(r) { 521 521 } 522 522 523 523 if ( self._view ) { 524 if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } 524 525 if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } 525 526 self._view.save(); 526 527 } else {