Support » Plugin: WooCommerce » Woocommerce created 75,000+ images

  • Resolved zimbo000

    (@zimbo000)


    My original post of this over a week ago has been ignored.

    Please can someone respond.

    The website in question is not a shop nor does it sell anything. However I installed Woocommerce because an add-on plugin to it had some functionality that we wanted to test & trial. Hence we needed Woocommerce to allow the add-on to work even though we’re not using it.

    Testing was going fine until a few days later I received an email from my hosting company telling me the site database was now over 14 GB in size and exceeded their Acceptable Use Policy. If I didn’t do something about it immediately, my site might be taken down.

    How did that happen I thought? To cut a long story short, after install Woocommerce retrospectively went through the Media Library and created 3 additional images – woocommerce_thumbnail, woocommerce_single and woocommerce_gallery_thumbnail – for EVERY single image in the Library.

    The problem? The Media Library had over 25,000 images in it. From the creation dates of these new images I could see that it took Woocommerce over 3 days working non-stop to add these unwanted images. We wondered why the site was running slow. 🙁

    Having discovered this, it then took me the best part of a day – after deleting the plugin – to remove all these Woocommerce images from the Uploads directory. The Uploads directory is now back where it was, just over 7 GB. Woocommerce DOUBLED the size of Uploads without any warnings.

    I have better things to do with my time than spend a day deleting files. To say I am EXTREMELY annoyed at Woocommerce is an understatement. I consider this hidden “functionality” of the plugin to be highly irresponsible.

    Question 1 – I could understand (but not agree with) Woocommerce creating its images for any new image upload, but why on earth does it go back in the Library and retrospectively – without ANY warnings or options to prevent it happening that I can find – and create unwanted images? Please explain.

    Question 2 – Testing indicated that the add-on can do the job we wanted. If I install Woocommerce again – yes, you might think I’m mad – how do I stop it generating those 3 extra images, both retrospectively after install and for future image uploads?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    Hi @zimbo000,

    Sorry again that you haven’t received a response here yet – this is not something I had personally seen before but I can confirm this behavior when testing locally.

    The explanation for what you’re seeing lies with the fact that WooCommerce registers new image sizes with WordPress. These image sizes are used for products in order to render product images and thumbnails properly on Shop pages and product pages.

    The quirk with this WordPress function is that there isn’t a way to add a “context” to registering a new image size. Basically, you can just register a new size but you can’t say that it only applies to specific post types(pages, posts, products, etc).

    https://developer.wordpress.org/reference/functions/add_image_size/

    So, the short answer is that this is indeed expected behavior. Since you intend to utilize WooCommerce again I would make sure that your hosting provider allocates enough space for the regeneration of thumbnails.

    If you are proficient with PHP you could remove some of the image size declarations to generate fewer thumbnails, however, you run the risk of not having the images necessary to display product images.

    https://developer.wordpress.org/reference/functions/remove_image_size/

    Hope that helps!

    Hi @shellbeezy,

    Thank you for a reply.

    We don’t want to utilise Woocommerce for its e-commerce function. It’s an add-on that hooks into Woocommerce that gives us the functionality we need. But to get this, we need Woocommerce installed.

    Hence we actively don’t want ANY product images generated by Woocommerce.

    I’m not a PHP developer but am proficient in adding code segments to my child theme functions.php and have hacked many a plugin to alter code lines to change plugin behaviour where this is not possible via functions.php or other means.

    Is there some PHP code you can suggest that I can add to my functions.php that will, if I then re-install Woocommerce, will stop it generating any of those images?

    I do this for my theme, which by default creates 17 additional images in addition to the WordPress defaults (yes, 17!!!). The theme developer provided the following function so that I now only create & keep the sizes I actually need for the site:

    function ava_image_sizes() {
    remove_image_size(‘widget’);
    remove_image_size(‘portfolio_small’);
    remove_image_size(‘portfolio’);
    remove_image_size(‘featured’);
    remove_image_size(‘featured_large’);
    remove_image_size(‘extra_large’);
    remove_image_size(‘gallery’);
    remove_image_size(‘magazine’);
    remove_image_size(‘masonry’);
    remove_image_size(‘entry_without_sidebar’);
    remove_image_size(‘shop_thumbnail’);
    remove_image_size(‘shop_catalog’);
    remove_image_size(‘shop_single’);
    }
    add_action( ‘after_setup_theme’, ‘ava_image_sizes’, 13 );

    Can you help?

    Plugin Support Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    We don’t want to utilise Woocommerce for its e-commerce function. It’s an add-on that hooks into Woocommerce that gives us the functionality we need.

    I see. That seems like overkill to utilize WooCommerce if you don’t need any eCommerce functionality. Before going further, are you sure there aren’t any alternatives to the add-on you need? Perhaps one that doesn’t require WooCommerce as a dependency?

    Anyways, you would pretty much do the exact same thing as you mentioned; create a custom function with calls to remove_image_size and pass in the string representing the image sizes added by WooCommerce. You can find them here:

    https://github.com/woocommerce/woocommerce/blob/0ffd7f10e950d0d9bec94dab034e44f040a2275d/includes/class-woocommerce.php#L639

    • woocommerce_thumbnail
    • woocommerce_single
    • woocommerce_gallery_thumbnail

    Hope that helps!

    Thanks. Don’t disagree about using Woocommerce but I’m just the tech guy and the site editor claims they can’t find another plugin to do what they want, only this Woocommerce add-on. Maybe we’ll have a another look around.

    Just FYI, if I did create another custom function, would the add_action line still use ‘after_setup_theme’ or would another function be required?

    Plugin Support Thomas Shellberg

    (@shellbeezy)

    Automattic Happiness Engineer

    Just FYI, if I did create another custom function, would the add_action line still use ‘after_setup_theme’ or would another function be required?

    WooCommerce adds its image size declarations using the ‘init’ hook with a default priority of 10. Thus, you’d have to hook into either a hook run after ‘init’ or use ‘init’ with a priority higher than 10. You won’t be able to prevent WooCommerce adding custom image sizes if a hook is used before init with 10 as the priority.

    The following works and actually removes all image sizes other than the default WordPress sizes:

    function remove_extra_image_sizes() {
    	write_log('removing extra images');
        foreach ( get_intermediate_image_sizes() as $size ) {
            if ( !in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
                remove_image_size( $size );
            }
        }
    }
     
    add_action('init', 'remove_extra_image_sizes', 20);

    Cheers!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce created 75,000+ images’ is closed to new replies.