Make WordPress Core

Ticket #34384: 34384.diff

File 34384.diff, 2.2 KB (added by flixos90, 8 years ago)

use a new parameter to disable forcing the thumbnail

  • src/wp-includes/media.php

     
    612612 *
    613613 * @since 2.5.0
    614614 *
    615  * @param int          $post_id Attachment ID.
    616  * @param array|string $size    Optional. Image size. Accepts any valid image size, or an array
    617  *                              of width and height values in pixels (in that order).
    618  *                              Default 'thumbnail'.
     615 * @param int          $post_id     Attachment ID.
     616 * @param array|string $size        Optional. Image size. Accepts any valid image size, or an array
     617 *                                  of width and height values in pixels (in that order).
     618 *                                  Default 'thumbnail'.
     619 * @param bool         $force_thumb Optional. Whether to force the thumbnail image to be used if is
     620 *                                  larger than the requested size. Default true.
    619621 * @return false|array $data {
    620622 *     Array of file relative path, width, and height on success. Additionally includes absolute
    621623 *     path and URL if registered size is passed to $size parameter. False on failure.
     
    629631 *                          parameter.
    630632 * }
    631633 */
    632 function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
     634function image_get_intermediate_size( $post_id, $size = 'thumbnail', $force_thumb = true ) {
    633635        if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
    634636                return false;
    635637
     
    661663                                // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
    662664                                $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false );
    663665                                // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
    664                                 if ( 'thumbnail' != $_size &&
     666                                if ( ( 'thumbnail' != $_size || ! $force_thumb ) &&
    665667                                  ( ! $maybe_cropped
    666668                                    || ( $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] )
    667669                                    || ( $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'] )