Ticket #44867: fullpatch-v3-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v3-44867-image-editor-save-modified-image-as-a-new-copy.patch, 3.3 KB (added by , 6 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 740405d..186dde8 100644
a b function wp_image_editor( $post_id, $msg = false ) { 181 181 <label class="imgedit-label"> 182 182 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 183 183 <?php _e( 'All sizes except thumbnail' ); ?></label> 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 </fieldset> 185 189 </div> 186 190 </div> … … function wp_save_image( $post_id ) { 835 839 } 836 840 } 837 841 842 if ( 'new' == $target ) { 843 $original_post_id = $post_id; 844 $post_id = NULL; 845 } 846 838 847 // Save the full-size file, also needed to create sub-sizes. 839 848 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 840 849 $return->error = esc_js( __( 'Unable to save the image.' ) ); … … function wp_save_image( $post_id ) { 878 887 } elseif ( 'thumbnail' == $target ) { 879 888 $sizes = array( 'thumbnail' ); 880 889 $success = $delete = $nocrop = true; 890 } elseif ( 'new' == $target ) { 891 $size = $img->get_size(); 892 $meta['width'] = $size['width']; // cropped and saved as a copy 893 $meta['height'] = $size['height']; 894 895 $new_post = (array)$post; 896 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 897 $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'; 898 899 $wp_upload_dir = wp_upload_dir(); 900 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 901 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 902 if ( is_wp_error( $post_id ) ) { 903 $return->error = esc_js( __('Unable to create a new atachment.') ); 904 return $return; 905 } 906 $return->refresh = TRUE; 907 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 908 $success = true; 909 910 update_attached_file( $post_id, $new_path ); 911 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 912 913 $sizes = get_intermediate_image_sizes(); 914 $delete = $nocrop = false; 881 915 } 882 916 883 917 /* … … function wp_save_image( $post_id ) { 940 974 wp_update_attachment_metadata( $post_id, $meta ); 941 975 update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ); 942 976 943 if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) {977 if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' || $target == 'new' ) { 944 978 // Check if it's an image edit from attachment edit screen 945 979 if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) { 946 980 $thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true ); -
wp-admin/js/image-edit.js
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index 100f26e..d664912 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 self._view.save(); 525 526 } else { 526 527 imageEdit.close(postid);