Make WordPress Core

Opened 7 years ago

Last modified 5 years ago

#43046 assigned defect (bug)

`has_image_size()` returns false for Core image sizes

Reported by: desrosj's profile desrosj Owned by:
Milestone: Future Release Priority: normal
Severity: minor Version: 3.9
Component: Media Keywords: has-patch dev-feedback has-unit-tests needs-refresh
Focuses: Cc:

Description

has_image_size() returns false (does not exist) for the four core image sizes (thumbnail, medium, medium_large, large).

get_intermediate_image_sizes() returns these core image sizes merged with custom registered sizes through add_image_size().

has_image_size() should return true for the core image sizes, or the function docs should note that the core image sizes are not checked in the function.

Attachments (3)

43046.diff (664 bytes) - added by subrataemfluence 7 years ago.
43046.2.diff (1.2 KB) - added by NathanAtmoz 7 years ago.
Introduce second parameter to has_image_size() to use core image sizes and update docs.
43046-unittests.diff (836 bytes) - added by andizer 6 years ago.
Added two simple tests

Download all attachments as: .zip

Change History (14)

#1 @subrataemfluence
7 years ago

  • Keywords has-patch added; needs-patch removed

has_image_size() function is specifically used for image sizes that are registered via add_image_size() function. It is actually using wp_get_additional_image_sizes() function, which does not consider core image sizes.

On the other hand get_intermediate_image_sizes() uses the same function (wp_get_additional_image_sizes()) but it forcefully defines an array of core image sizes and merges it with the array returned by wp_get_additional_image_sizes() function.

I agree with @desrosj that the documentation has to be more clear about the limitation.

I have edited description at https://codex.wordpress.org/Function_Reference/has_image_size

Last edited 7 years ago by subrataemfluence (previous) (diff)

@NathanAtmoz
7 years ago

Introduce second parameter to has_image_size() to use core image sizes and update docs.

#2 @NathanAtmoz
7 years ago

  • Keywords needs-unit-tests added

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


7 years ago

#4 @kirasong
7 years ago

  • Keywords dev-feedback added
  • Milestone changed from Awaiting Review to 5.0
  • Owner set to desrosj
  • Status changed from new to assigned
Last edited 7 years ago by kirasong (previous) (diff)

#5 @kirasong
7 years ago

I suspect this will need some research to find out the effects for backcompat on each way of fixing this, and how much a param will help. After a chat in #core-media about it, @desrosj offered to do some digging.

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


7 years ago

@andizer
6 years ago

Added two simple tests

#7 @andizer
6 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

#8 @desrosj
6 years ago

  • Milestone changed from 5.0 to 5.1

This still needs some research and falls outside of the 5.0 focus. Punting to 5.1.

This ticket was mentioned in Slack in #core-media by desrosj. View the logs.


6 years ago

#10 @desrosj
6 years ago

  • Keywords needs-refresh added
  • Milestone changed from 5.1 to Future Release

@andizer thanks for those tests! More code would need to be added for the second one to be accurate, though, as has_image_size() does not currently accept a second parameter.

I am going to punt this to Future Release. This could just be a simple docs change to indicate core image sizes are excluded, or an added parameter. But the implications of the second option are not yet clear.

#11 @desrosj
5 years ago

  • Owner desrosj deleted
Note: See TracTickets for help on using tickets.