Make WordPress Core

Ticket #28277: 28277.2.diff

File 28277.2.diff, 2.6 KB (added by joedolson, 18 months ago)

Update & refresh patch.

  • src/wp-admin/includes/image-edit.php

     
    4343                        $note = "<div class='notice notice-success' tabindex='-1' role='alert'><p>$msg->msg</p></div>";
    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">
    4957        <div id="imgedit-panel-<?php echo $post_id; ?>">
     
    239247                        <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
    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>
    244272        </div>
     
    905933                $meta['width']  = $size['width'];
    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                }
    914946
     
    919951                $success = true;
    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
    924961        /*