WordPress.org

Make WordPress Core

Opened 18 months ago

Last modified 5 months ago

#43046 assigned defect (bug)

`has_image_size()` returns false for Core image sizes

Reported by: desrosj Owned by: desrosj
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 18 months ago.
43046.2.diff (1.2 KB) - added by NathanAtmoz 17 months ago.
Introduce second parameter to has_image_size() to use core image sizes and update docs.
43046-unittests.diff (836 bytes) - added by andizer 9 months ago.
Added two simple tests

Download all attachments as: .zip

Change History (13)

#1 @subrataemfluence
18 months 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 18 months ago by subrataemfluence (previous) (diff)

@NathanAtmoz
17 months ago

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

#2 @NathanAtmoz
17 months ago

  • Keywords needs-unit-tests added

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


17 months ago

#4 @mikeschroder
17 months 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 17 months ago by mikeschroder (previous) (diff)

#5 @mikeschroder
17 months 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.


15 months ago

@andizer
9 months ago

Added two simple tests

#7 @andizer
9 months ago

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

#8 @desrosj
8 months 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.


5 months ago

#10 @desrosj
5 months 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.

Note: See TracTickets for help on using tickets.