Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#52183 closed defect (bug) (fixed)

get_the_post_thumbnail_url function returns original url if the size didnt exist

Reported by: naveen17797's profile naveen17797 Owned by: audrasjb's profile audrasjb
Milestone: 5.7 Priority: normal
Severity: normal Version:
Component: Post Thumbnails Keywords: has-patch commit
Focuses: docs Cc:

Description

From the function description it should return false if the size does not exist.

Steps to replicate the issue

  1. I uploaded a image via featured image field on the post edit screen.
  1. I am calling this function inside the theme file like this

$medium_thumbnail_url = get_the_post_thumbnail_url( $post_id, 'medium');

But this function returns original url instead of returning false.

Attachments (3)

52183.diff (925 bytes) - added by GeekPress 4 years ago.
Update @return description
52183.2.diff (1.9 KB) - added by GeekPress 4 years ago.
More specific @return description for wp_get_attachment_image_url & get_the_post_thumbnail_url
52183.3.diff (2.0 KB) - added by audrasjb 4 years ago.
DocBlocks Coding standards fixes

Download all attachments as: .zip

Change History (11)

#1 @naveen17797
4 years ago

Additional information:

I disabled the medium size by going to settings > Media > setting the dimensions to 0x0

It wont be generated for any image, After featured image upload, the medium size image is not generated

Last edited 4 years ago by naveen17797 (previous) (diff)

#2 @SergeyBiryukov
4 years ago

  • Component changed from General to Post Thumbnails
  • Focuses docs added

#3 @GeekPress
4 years ago

@naveen17797 Your are confused because the @return description contains a mistake. It should be no image instead of no URL.

@SergeyBiryukov I attached a patch to update the @return description based on the wp_get_attachment_image_url description.

I don't know if we should be more specific in case the $size doesn't match a registered image.

e.g:

@return string|false Post thumbnail URL or false if no image is available.
                     If `$size` doesn't match a registerd image size, the original thumbnail URL
                     will be returned.

@GeekPress
4 years ago

Update @return description

#4 @audrasjb
4 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.7
  • Owner set to audrasjb
  • Status changed from new to accepted
  • Version 5.6 deleted

Hi, thanks for the patch @GeekPress,

@return string|false Post thumbnail URL or false if no image is available.
                     If `$size` doesn't match a registered image size, the original
                     thumbnail URL will be returned.

This proposal looks great to me. Can you please update the patch accordingly?

#5 @audrasjb
4 years ago

Maybe just replace "the original thumbnail URL will be returned" with "the original image URL will be returned".

@GeekPress
4 years ago

More specific @return description for wp_get_attachment_image_url & get_the_post_thumbnail_url

#6 @GeekPress
4 years ago

Thanks @audrasjb for your feedback.

I've updated the patch. I also updated the @return description of wp_get_attachment_image_url to have the same @return statement than get_the_post_thumbnail_url

@audrasjb
4 years ago

DocBlocks Coding standards fixes

#7 @audrasjb
4 years ago

  • Keywords commit added

Thanks for the second patch. I fixed few minor DocBlock issues, now I think it's ready for commit.

Last edited 4 years ago by audrasjb (previous) (diff)

#8 @SergeyBiryukov
4 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 50236:

Docs: Clarify the @return value for wp_get_attachment_image_url() and get_the_post_thumbnail_url().

Props GeekPress, audrasjb, naveen17797.
Fixes #52183.

Note: See TracTickets for help on using tickets.