WordPress.org

Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#24815 new defect (bug)

get_the_post_thumbnail() fetches full sized image if 'post-thumbnail' custom size not defined in theme

Reported by: Jonnyauk Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.9
Component: Media Keywords: has-patch needs-codex 2nd-opinion
Focuses: Cc:

Description

In wp-includes/post-thumbnail-template.php the $size default value is set as 'post-thumbnail' in the following function:

  • get_the_post_thumbnail()

Expected behaviour
Expected behaviour would be to return the image at 'post-thumbnail' dimensions - however, if this is not set in the theme via:

  • set_post_thumbnail_size() function
  • add_image_size() function

it returns the full sized sized image begin displayed. I'd expect this to return the image at standard 'thumbnail' size, as some people will just add add_theme_support( 'post-thumbnails' ) and not set (or even need) custom dimensions.

Proposal and patch
$size default value should default back to 'thumbnail' for normal expected function behaviour if 'post-thumbnail' specific dimensions have not been set.

I'm not sure if it would be more efficient to test against the global variable that holds these values, or use get_intermediate_image_sizes() as I've used in the patch attached - 2nd opinion please?

Attachments (1)

v1.patch (886 bytes) - added by Jonnyauk 9 months ago.
Patch v1 - uses get_intermediate_image_sizes()

Download all attachments as: .zip

Change History (4)

Jonnyauk9 months ago

Patch v1 - uses get_intermediate_image_sizes()

comment:1 Jonnyauk9 months ago

I think the alternative approach would use the global $_wp_additional_image_sizes

comment:2 nacin9 months ago

  • Version changed from trunk to 2.9

Originally post-thumbnail-template.php was only included if the theme actually supported post thumbnails. The only reason why it isn't is because the conditional loading of the file was silly for opcode caching purposes. I'm not sure there is anything we should do here. 'post-thumbnail' is realistically required for these functions.

comment:3 Jonnyauk9 months ago

I understand where you are coming from on this, thank you for your feedback. However, in the patch I still check against 'post-thumbnail', so there won't be any compatibility issues.

It seems a-little strange behaviour to me to have to define another image size for 'post-thumbnail' for this to function correctly, I'd expect it to default to standard thumbnail dimensions (due to the name of the function?)

Note: See TracTickets for help on using tickets.