Issue with Unregistered Image Sizes
-
Hello!
I am removing a few custom image sizes using the code snippet below:
https://pastebin.com/yfPBZdd5
Even though they are successfully removed, ShortPixel displays those image sizes in the list of “Exclude thumbnail sizes”.I took a look at your code and I noticed in
/class/wp-short-pixel.php
, in the functiongetAllThumbnailSizes()
(line 3979), you merge the value ofget_intermediate_image_sizes()
with the value ofwp_get_additional_image_sizes()
.
get_intermediate_image_sizes()
already useswp_get_additional_image_sizes()
to build the list of all available image sizes. And once that list is built, it allows developers to filter it. And that’s exactly what I did to deregister unwanted image sizes.
Merging the 2 values again after the final result was filtered makes the filter worthless.The good news is the entire functionality of your
getAllThumbnailSizes()
function is already provided bywp_get_registered_image_subsizes()
.
To fix the issue, all you have to do is callwp_get_registered_image_subsizes()
instead ofgetAllThumbnailSizes()
or to simply use your custom function as a wrapper for the WP function:function getAllThumbnailSizes() { return wp_get_registered_image_subsizes(); }
Check WP code here:
https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/media.php#L852
https://core.trac.wordpress.org/browser/tags/5.6/src/wp-includes/media.php#L878
- The topic ‘Issue with Unregistered Image Sizes’ is closed to new replies.