Changeset 55935
- Timestamp:
- 06/18/2023 02:22:40 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/lib/image-edit.js
r55919 r55935 359 359 * 360 360 * @return {string} The value from the imagedit-save-target input field when available, 361 * or 'full' when not available. 362 */ 363 getTarget : function(postid) { 364 return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full'; 361 * 'full' when not selected, or 'all' if it doesn't exist. 362 */ 363 getTarget : function( postid ) { 364 var element = $( '#imgedit-save-target-' + postid ); 365 366 if ( element.length ) { 367 return element.find( 'input[name="imgedit-target-' + postid + '"]:checked' ).val() || 'full'; 368 } 369 370 return 'all'; 365 371 }, 366 372 -
trunk/src/wp-admin/includes/image-edit.php
r55919 r55935 44 44 } 45 45 } 46 $edit_custom_sizes = false; 46 47 47 /** 48 * Filters whether custom sizes are available options for image editing.48 * . 49 49 * 50 * @since 6. 0.050 * @since 6..0 51 51 * 52 * @param bool |string[] $edit_custom_sizes True if custom sizes can be edited or array of custom size names.52 * @param bool. 53 53 */ 54 $edit_custom_sizes = apply_filters( 'edit_custom_thumbnail_sizes', $edit_custom_sizes ); 54 $edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false ); 55 55 56 ?> 56 57 <div class="imgedit-wrap wp-clearfix"> … … 273 274 274 275 <?php 275 if ( $ thumb && $sub_sizes ) {276 if ( $thumb && $sub_sizes ) { 276 277 $thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 ); 277 278 ?> … … 308 309 <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> 309 310 </span> 310 311 311 312 <span class="imgedit-label"> 312 313 <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> … … 314 315 </span> 315 316 316 <?php317 if ( $edit_custom_sizes ) {318 if ( ! is_array( $edit_custom_sizes ) ) {319 $edit_custom_sizes = get_intermediate_image_sizes();320 }321 foreach ( array_unique( $edit_custom_sizes ) as $key => $size ) {322 if ( array_key_exists( $size, $meta['sizes'] ) ) {323 if ( 'thumbnail' === $size ) {324 continue;325 }326 ?>327 <span class="imgedit-label">328 <input type="radio" id="imgedit-target-custom<?php echo esc_attr( $key ); ?>" name="imgedit-target-<?php echo $post_id; ?>" value="<?php echo esc_attr( $size ); ?>" />329 <label for="imgedit-target-custom<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $size ); ?></label>330 </span>331 <?php332 }333 }334 }335 ?>336 317 </fieldset> 337 318 </div> … … 919 900 $scale = ! empty( $_REQUEST['do'] ) && 'scale' === $_REQUEST['do']; 920 901 902 903 904 921 905 if ( $scale ) { 922 906 $size = $img->get_size(); … … 978 962 isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] != $basename ) { 979 963 980 if ( 'thumbnail' === $target ) {964 if ( 'thumbnail' === $target ) { 981 965 $new_path = "{$dirname}/{$filename}-temp.{$ext}"; 982 966 } else { … … 1028 1012 $meta['height'] = $size['height']; 1029 1013 1030 if ( $success ) {1014 if ( $success ) { 1031 1015 $sizes = get_intermediate_image_sizes(); 1032 if ( 'nothumb' === $target || 'all' === $target ) { 1033 if ( 'nothumb' === $target ) { 1034 $sizes = array_diff( $sizes, array( 'thumbnail' ) ); 1035 } 1036 } elseif ( 'thumbnail' !== $target ) { 1037 $sizes = array_diff( $sizes, array( $target ) ); 1016 1017 if ( $edit_thumbnails_separately && 'nothumb' === $target ) { 1018 $sizes = array_diff( $sizes, array( 'thumbnail' ) ); 1038 1019 } 1039 1020 } … … 1041 1022 $return->fw = $meta['width']; 1042 1023 $return->fh = $meta['height']; 1043 } elseif ( 'thumbnail' === $target ) {1024 } elseif ( 'thumbnail' === $target ) { 1044 1025 $sizes = array( 'thumbnail' ); 1045 1026 $success = true; 1046 1027 $delete = true; 1047 1028 $nocrop = true; 1048 } else {1049 $sizes = array( $target );1050 $success = true;1051 $delete = true;1052 $nocrop = $_wp_additional_image_sizes[ $size ]['crop'];1053 1029 } 1054 1030 -
trunk/tests/phpunit/tests/ajax/wpAjaxImageEditor.php
r55859 r55935 27 27 $this->remove_added_uploads(); 28 28 parent::tear_down(); 29 }30 31 /**32 * @ticket 2298533 * @requires function imagejpeg34 *35 * @covers ::wp_insert_attachment36 * @covers ::wp_save_image37 */38 public function testCropImageThumbnail() {39 require_once ABSPATH . 'wp-admin/includes/image-edit.php';40 41 $filename = DIR_TESTDATA . '/images/canola.jpg';42 $contents = file_get_contents( $filename );43 44 $upload = wp_upload_bits( wp_basename( $filename ), null, $contents );45 $id = $this->_make_attachment( $upload );46 47 $_REQUEST['action'] = 'image-editor';48 $_REQUEST['context'] = 'edit-attachment';49 $_REQUEST['postid'] = $id;50 $_REQUEST['target'] = 'thumbnail';51 $_REQUEST['do'] = 'save';52 $_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":289,"h":322}}]';53 54 $media_meta = wp_get_attachment_metadata( $id );55 $this->assertArrayHasKey( 'sizes', $media_meta, 'attachment should have size data' );56 $this->assertArrayHasKey( 'medium', $media_meta['sizes'], 'attachment should have data for medium size' );57 $ret = wp_save_image( $id );58 59 $media_meta = wp_get_attachment_metadata( $id );60 $this->assertArrayHasKey( 'sizes', $media_meta, 'cropped attachment should have size data' );61 $this->assertArrayHasKey( 'medium', $media_meta['sizes'], 'cropped attachment should have data for medium size' );62 29 } 63 30 -
trunk/tests/phpunit/tests/image/functions.php
r55070 r55935 349 349 350 350 $this->assertTrue( $ret, 'Image failed to save.' ); 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 351 436 } 352 437
Note: See TracChangeset
for help on using the changeset viewer.