Make WordPress Core

Changeset 55935

Timestamp:
06/18/2023 02:22:40 PM (14 months ago)
Author:
azaozz
Message:

Media: Deprecate the 'edit_custom_thumbnail_sizes' filter and disable the "Apply changes to [Thumbnail|All|All except thumbnail]" UI in the image editor. Add a (boolean) filter to reenable that UI.

Props peterwilsoncc, costdev, azaozz.
See: #57685.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/image-edit.js

    r55919 r55935  
    359359     *
    360360     * @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';
    365371    },
    366372
  • trunk/src/wp-admin/includes/image-edit.php

    r55919 r55935  
    4444        }
    4545    }
    46     $edit_custom_sizes = false;
     46
    4747    /**
    48      * Filters whether custom sizes are available options for image editing.
     48     * .
    4949     *
    50      * @since 6.0.0
     50     * @since 6..0
    5151     *
    52      * @param bool|string[] $edit_custom_sizes True if custom sizes can be edited or array of custom size names.
     52     * @param bool.
    5353     */
    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
    5556    ?>
    5657    <div class="imgedit-wrap wp-clearfix">
     
    273274
    274275    <?php
    275     if ( $thumb && $sub_sizes ) {
     276    if ( $thumb && $sub_sizes ) {
    276277        $thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
    277278        ?>
     
    308309                    <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label>
    309310                </span>
    310  
     311
    311312                <span class="imgedit-label">
    312313                    <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
     
    314315                </span>
    315316
    316                 <?php
    317                 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                             <?php
    332                         }
    333                     }
    334                 }
    335                 ?>
    336317                </fieldset>
    337318            </div>
     
    919900    $scale   = ! empty( $_REQUEST['do'] ) && 'scale' === $_REQUEST['do'];
    920901
     902
     903
     904
    921905    if ( $scale ) {
    922906        $size = $img->get_size();
     
    978962        isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] != $basename ) {
    979963
    980         if ( 'thumbnail' === $target ) {
     964        if ( 'thumbnail' === $target ) {
    981965            $new_path = "{$dirname}/{$filename}-temp.{$ext}";
    982966        } else {
     
    10281012        $meta['height'] = $size['height'];
    10291013
    1030         if ( $success ) {
     1014        if ( $success ) {
    10311015            $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' ) );
    10381019            }
    10391020        }
     
    10411022        $return->fw = $meta['width'];
    10421023        $return->fh = $meta['height'];
    1043     } elseif ( 'thumbnail' === $target ) {
     1024    } elseif ( 'thumbnail' === $target ) {
    10441025        $sizes   = array( 'thumbnail' );
    10451026        $success = true;
    10461027        $delete  = true;
    10471028        $nocrop  = true;
    1048     } else {
    1049         $sizes   = array( $target );
    1050         $success = true;
    1051         $delete  = true;
    1052         $nocrop  = $_wp_additional_image_sizes[ $size ]['crop'];
    10531029    }
    10541030
  • trunk/tests/phpunit/tests/ajax/wpAjaxImageEditor.php

    r55859 r55935  
    2727        $this->remove_added_uploads();
    2828        parent::tear_down();
    29     }
    30 
    31     /**
    32      * @ticket 22985
    33      * @requires function imagejpeg
    34      *
    35      * @covers ::wp_insert_attachment
    36      * @covers ::wp_save_image
    37      */
    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' );
    6229    }
    6330
  • trunk/tests/phpunit/tests/image/functions.php

    r55070 r55935  
    349349
    350350        $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
    351436    }
    352437
Note: See TracChangeset for help on using the changeset viewer.