Changeset 55935
- Timestamp:
- 06/18/2023 02:22:40 PM (21 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 * Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image. 49 49 * 50 * @since 6. 0.050 * @since 6.3.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 Whether to show the settings in the Image Editor. Default false. 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 ( $edit_thumbnails_separately && $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 /** This filter is documented in wp-admin/includes/image-edit.php */ 903 $edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false ); 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 ( $edit_thumbnails_separately && '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 && ( 'nothumb' === $target || 'all' === $target ) ) { 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 ( $edit_thumbnails_separately && '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 * Tests that `wp_image_editor()` applies 'image_edit_thumbnails_separately' filters. 355 * 356 * @ticket 53161 357 * 358 * @covers ::wp_image_editor 359 */ 360 public function test_wp_image_editor_should_apply_image_edit_thumbnails_separately_filters() { 361 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; 362 363 $filename = DIR_TESTDATA . '/images/canola.jpg'; 364 $contents = file_get_contents( $filename ); 365 $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); 366 $id = $this->_make_attachment( $upload ); 367 368 $filter = new MockAction(); 369 add_filter( 'image_edit_thumbnails_separately', array( &$filter, 'filter' ) ); 370 371 ob_start(); 372 wp_image_editor( $id ); 373 ob_end_clean(); 374 375 $this->assertSame( 1, $filter->get_call_count() ); 376 } 377 378 /** 379 * Tests that `wp_image_editor()` conditionally outputs markup for editing thumbnails separately 380 * based on the result of applying 'image_edit_thumbnails_separately' filters. 381 * 382 * @ticket 53161 383 * 384 * @covers ::wp_image_editor 385 * 386 * @dataProvider data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters 387 * 388 * @param string $callback The name of the callback for the 'image_edit_thumbnails_separately' hook. 389 * @param bool $expected Whether the markup should be output. 390 */ 391 public function test_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters( $callback, $expected ) { 392 require_once ABSPATH . 'wp-admin/includes/image-edit.php'; 393 394 $filename = DIR_TESTDATA . '/images/canola.jpg'; 395 $contents = file_get_contents( $filename ); 396 $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); 397 $id = $this->_make_attachment( $upload ); 398 399 add_filter( 'image_edit_thumbnails_separately', $callback ); 400 401 ob_start(); 402 wp_image_editor( $id ); 403 $actual = ob_get_clean(); 404 405 if ( $expected ) { 406 $this->assertStringContainsString( 407 'imgedit-applyto', 408 $actual, 409 'The markup should have been output.' 410 ); 411 } else { 412 $this->assertStringNotContainsString( 413 'imgedit-applyto', 414 $actual, 415 'The markup should not have been output.' 416 ); 417 } 418 } 419 420 /** 421 * Data provider. 422 * 423 * @return array[] 424 */ 425 public function data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters() { 426 return array( 427 'true' => array( 428 'callback' => '__return_true', 429 'expected' => true, 430 ), 431 'false' => array( 432 'callback' => '__return_false', 433 'expected' => false, 434 ), 435 ); 351 436 } 352 437
Note: See TracChangeset
for help on using the changeset viewer.