Make WordPress Core


Ignore:
Timestamp:
06/18/2023 02:22:40 PM (20 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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     * Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image.
    4949     *
    50      * @since 6.0.0
     50     * @since 6.3.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 Whether to show the settings in the Image Editor. Default false.
    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 ( $edit_thumbnails_separately && $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    /** This filter is documented in wp-admin/includes/image-edit.php */
     903    $edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false );
     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 ( $edit_thumbnails_separately && 'thumbnail' === $target ) {
    981965            $new_path = "{$dirname}/{$filename}-temp.{$ext}";
    982966        } else {
     
    10281012        $meta['height'] = $size['height'];
    10291013
    1030         if ( $success ) {
     1014        if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
    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 ( $edit_thumbnails_separately && '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
Note: See TracChangeset for help on using the changeset viewer.