WordPress.org

Make WordPress Core

Opened 6 weeks ago

Last modified 2 weeks ago

#43046 assigned defect (bug)

`has_image_size()` returns false for Core image sizes

Reported by: desrosj Owned by: desrosj
Milestone: 5.0 Priority: normal
Severity: minor Version: 3.9
Component: Media Keywords: has-patch needs-unit-tests dev-feedback
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 (2)

43046.diff (664 bytes) - added by subrataemfluence 6 weeks ago.
43046.2.diff (1.2 KB) - added by NathanAtmoz 4 weeks ago.
Introduce second parameter to has_image_size() to use core image sizes and update docs.

Download all attachments as: .zip

Change History (7)

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

@NathanAtmoz
4 weeks ago

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

#2 @NathanAtmoz
4 weeks ago

  • Keywords needs-unit-tests added

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


2 weeks ago

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

#5 @mikeschroder
2 weeks 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.

Note: See TracTickets for help on using tickets.