Make WordPress Core

Changeset 53161


Ignore:
Timestamp:
04/12/2022 04:14:01 PM (3 years ago)
Author:
joedolson
Message:

Media: Enable edits to custom image sizes.

Add a filter edit_custom_thumbnail_sizes to allow users to enable editing individual custom image sizes.

Props silb3r, joedolson, costdev.
Fixes #28277.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image-edit.php

    r51303 r53161  
    4444        }
    4545    }
    46 
     46    $edit_custom_sizes = false;
     47    /**
     48     * Filters whether custom sizes are available options for image editing.
     49     *
     50     * @since 6.0.0
     51     *
     52     * @param bool|array $edit_custom_sizes True if custom sizes can be edited or array of custom sizes.
     53     */
     54    $edit_custom_sizes = apply_filters( 'edit_custom_thumbnail_sizes', $edit_custom_sizes );
    4755    ?>
    4856    <div class="imgedit-wrap wp-clearfix">
     
    240248            <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label>
    241249        </span>
     250        <?php
     251        if ( $edit_custom_sizes ) {
     252            if ( ! is_array( $edit_custom_sizes ) ) {
     253                $edit_custom_sizes = get_intermediate_image_sizes();
     254            }
     255            foreach ( array_unique( $edit_custom_sizes ) as $key => $size ) {
     256                if ( array_key_exists( $size, $meta['sizes'] ) ) {
     257                    if ( 'thumbnail' === $size ) {
     258                        continue;
     259                    }
     260                    ?>
     261                    <span class="imgedit-label">
     262                        <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 ); ?>" />
     263                        <label for="imgedit-target-custom<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $size ); ?></label>
     264                    </span>
     265                    <?php
     266                }
     267            }
     268        }
     269        ?>
    242270    </fieldset>
    243271    </div>
     
    906934        $meta['height'] = $size['height'];
    907935
    908         if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
     936        if ( $success ) {
    909937            $sizes = get_intermediate_image_sizes();
    910             if ( 'nothumb' === $target ) {
    911                 $sizes = array_diff( $sizes, array( 'thumbnail' ) );
     938            if ( 'nothumb' === $target || 'all' === $target ) {
     939                if ( 'nothumb' === $target ) {
     940                    $sizes = array_diff( $sizes, array( 'thumbnail' ) );
     941                }
     942            } elseif ( 'thumbnail' !== $target ) {
     943                $sizes = array_diff( $sizes, array( $target ) );
    912944            }
    913945        }
     
    920952        $delete  = true;
    921953        $nocrop  = true;
     954    } else {
     955        $sizes   = array( $target );
     956        $success = true;
     957        $delete  = true;
     958        $nocrop  = $_wp_additional_image_sizes[ $size ]['crop'];
    922959    }
    923960
Note: See TracChangeset for help on using the changeset viewer.