Ticket #44867: fullpatch-v2-44867-image-editor-save-modified-image-as-a-new-copy.patch
File fullpatch-v2-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 efa9865..c026876 100644
a b function wp_image_editor($post_id, $msg = false) { 171 171 <label class="imgedit-label"> 172 172 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> 173 173 <?php _e('All sizes except thumbnail'); ?></label> 174 175 <label class="imgedit-label"> 176 <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> 177 <?php _e('A newly created image'); ?></label> 174 178 </fieldset> 175 179 </div> 176 180 </div> … … function wp_save_image( $post_id ) { 792 796 } 793 797 } 794 798 799 if ( 'new' == $target ) { 800 $original_post_id = $post_id; 801 $post_id = NULL; 802 } 803 795 804 // Save the full-size file, also needed to create sub-sizes. 796 805 if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) { 797 806 $return->error = esc_js( __('Unable to save the image.') ); … … function wp_save_image( $post_id ) { 830 839 } elseif ( 'thumbnail' == $target ) { 831 840 $sizes = array( 'thumbnail' ); 832 841 $success = $delete = $nocrop = true; 842 } elseif ( 'new' == $target ) { 843 $size = $img->get_size(); 844 $meta['width'] = $size['width']; // cropped and saved as a copy 845 $meta['height'] = $size['height']; 846 847 $new_post = (array)$post; 848 unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); 849 $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'; 850 851 $wp_upload_dir = wp_upload_dir(); 852 $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); 853 $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); 854 if ( is_wp_error( $post_id ) ) { 855 $return->error = esc_js( __('Unable to create a new atachment.') ); 856 return $return; 857 } 858 $return->refresh = TRUE; 859 $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); 860 $success = true; 861 862 update_attached_file( $post_id, $new_path ); 863 update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); 864 865 $sizes = get_intermediate_image_sizes(); 866 $delete = $nocrop = false; 833 867 } 834 868 835 869 /* … … function wp_save_image( $post_id ) { 886 920 wp_update_attachment_metadata( $post_id, $meta ); 887 921 update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes); 888 922 889 if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) {923 if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' || $target == 'new' ) { 890 924 // Check if it's an image edit from attachment edit screen 891 925 if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) { 892 926 $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 14af25e..7c23631 100644
a b function(r) { 496 496 } 497 497 498 498 if ( self._view ) { 499 if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } 499 500 self._view.save(); 500 501 } else { 501 502 imageEdit.close(postid);