• Resolved Eusebiu Oprinoiu

    (@eusebiuoprinoiu)


    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 function getAllThumbnailSizes() (line 3979), you merge the value of get_intermediate_image_sizes() with the value of wp_get_additional_image_sizes().
    get_intermediate_image_sizes() already uses wp_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 by wp_get_registered_image_subsizes().
    To fix the issue, all you have to do is call wp_get_registered_image_subsizes() instead of getAllThumbnailSizes() 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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Gerard Blanco

    (@sixaxis)

    Hi, Eusebiu,

    Thanks for the suggestion, we’ll forward it to our devs and if we have any question we will get back to you 🙂

    Best,

    Thread Starter Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Thank you, Gerard!
    I’m here if you need more details or help with testing.

    Plugin Support Gerard Blanco

    (@sixaxis)

    Hi, Eusebiu,

    I’m back with some answers.

    • If we use a filter like yours and we apply your patch, indeed those sizes would not appear anymore in the list in settings (that’s the only place that function is being used).
    • In the same time, newer images won’t get those thumbnail sizes and obviously, they won’t be optimized.
    • However, if one runs a bulk optimization on a Media Library that contains images with those thumbnails filtered out, then ShortPixel will optimize those thumbnails when it finds them, no matter if those thumbnail sizes are active or not.
    • With the current implementation, one has the possibility to exclude those thumbnail sizes from being processed by the Bulk Optimization for older images too

    Therefore we can rather consider this as a feature and not necessarily a bug 😉 I hope my explanation is clear!

    Best,

    Thread Starter Eusebiu Oprinoiu

    (@eusebiuoprinoiu)

    Hello, Gerard!

    I understand the logic behind this, but I still believe you should use the native WP function. The filter exists for a reason: to provide flexibility. When you overwrite the filtered value, you are taking away our choices.
    What you’re saying only applies to the 3 default hidden image sizes: medium_large, 1536×1536, and 2048×2048. If someone deliberately removes or modifies them, it’s usually for a good reason.

    If you really don’t want to use the native WP function, at least add a filter for the returned value of your custom getAllThumbnailSizes() function.
    return apply_filters( 'shortpixel_all_thumbnail_sizes', $sizes ); instead of return $sizes;.

    Plugin Support Gerard Blanco

    (@sixaxis)

    Hi, Eusebiu,

    Version 4.21.2 has the filter added 🙂

    I hope that helps!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Issue with Unregistered Image Sizes’ is closed to new replies.