Ticket #32171: 32171.2.2.diff
| File 32171.2.2.diff, 3.9 KB (added by , 10 years ago) |
|---|
-
src/wp-admin/includes/image-edit.php
68 68 </label> 69 69 <span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>">!</span> 70 70 <input id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary" value="<?php esc_attr_e( 'Scale' ); ?>" /> 71 </div>71 </div> 72 72 </fieldset> 73 73 74 74 </div> … … 520 520 * @since 3.5.0 521 521 * 522 522 * @param WP_Image_Editor $image WP_Image_Editor instance. 523 * @param array $changes Array of change operations.523 * @param array $changes Array of change operations. 524 524 */ 525 525 $image = apply_filters( 'wp_image_editor_before_change', $image, $changes ); 526 526 } elseif ( is_resource( $image ) ) { … … 532 532 * @deprecated 3.5.0 Use wp_image_editor_before_change instead. 533 533 * 534 534 * @param resource $image GD image resource. 535 * @param array $changes Array of change operations.535 * @param array $changes Array of change operations. 536 536 */ 537 537 $image = apply_filters( 'image_edit_before_change', $image, $changes ); 538 538 } … … 827 827 $success = $delete = $nocrop = true; 828 828 } 829 829 830 /* 831 * We need to remove any existing resized image files because 832 * a new crop could generate different image file sizes and so 833 * different file names, and so the new resized images won't 834 * necessarily overwrite the existing resized image files 835 * https://core.trac.wordpress.org/ticket/32171 836 */ 837 if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) { 838 foreach ( $meta['sizes'] as $size ) { 839 if ( ! empty( $size['file'] ) && preg_match('/-e[0-9]{13}-/', $size['file'] ) ) { 840 $delete_file = path_join( dirname( $new_path ), $size['file'] ); 841 wp_delete_file( $delete_file ); 842 } 843 } 844 } 845 830 846 if ( isset( $sizes ) ) { 831 847 $_sizes = array(); 832 848 -
tests/phpunit/tests/ajax/MediaEdit.php
51 51 $this->assertArrayHasKey('sizes', $media_meta, 'cropped attachment should have size data'); 52 52 $this->assertArrayHasKey('medium', $media_meta['sizes'], 'cropped attachment should have data for medium size'); 53 53 } 54 55 /** 56 * @ticket 32171 57 */ 58 public function testImageEditOverwriteConstant() { 59 define( 'IMAGE_EDIT_OVERWRITE', true ); 60 61 include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); 62 63 $filename = DIR_TESTDATA . '/images/canola.jpg'; 64 $contents = file_get_contents( $filename ); 65 66 $upload = wp_upload_bits( basename( $filename ), null, $contents ); 67 $id = $this->_make_attachment( $upload ); 68 69 $_REQUEST['action'] = 'image-editor'; 70 $_REQUEST['context'] = 'edit-attachment'; 71 $_REQUEST['postid'] = $id; 72 $_REQUEST['target'] = 'all'; 73 $_REQUEST['do'] = 'save'; 74 $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":289,"h":322}}]'; 75 76 $ret = wp_save_image( $id ); 77 78 $media_meta = wp_get_attachment_metadata( $id ); 79 $sizes1 = $media_meta['sizes']; 80 81 $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":189,"h":322}}]'; 82 83 $ret = wp_save_image( $id ); 84 85 $media_meta = wp_get_attachment_metadata( $id ); 86 $sizes2 = $media_meta['sizes']; 87 88 $file_path = dirname( get_attached_file( $id ) ); 89 90 foreach ( $sizes1 as $key => $size ) { 91 if ( $sizes2[ $key ]['file'] !== $size['file'] ) { 92 $files_that_shouldnt_exist[] = $file_path . '/' . $size['file']; 93 } 94 } 95 96 foreach ( $files_that_shouldnt_exist as $file ) { 97 $this->assertFalse( file_exists( $file ), 'IMAGE_EDIT_OVERWRITE is leaving garbage image files behind.' ); 98 } 99 } 54 100 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)