• Hello,

    I used this code to disable wpadverts thumbnails from generating on every wordpress image uploaded. Is it safe to use or will it have any negative effect.
    I really need to save storage space since ill be dealing with lots of images for advert listings.

    // disable generated image sizes
    function disable_image_sizes($sizes) {
    
    	unset($sizes['adverts-gallery']);
    	unset($sizes['adverts-list']);
    	unset($sizes['adverts-upload-thumbnail']);
    	
    	return $sizes;
    	
    }
    add_action('intermediate_image_sizes_advanced', 'disable_image_sizes');

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    I can’t really tell. If the [adverts_add] (specifically the gallery and image editor), [adverts_list] and Ad details pages will work fine with this code enabled then it should be ok to use it.

    Thread Starter teeboy4real

    (@teeboy4real)

    I just tested it, adverts were uploaded successfully and everything works fine but im just wondering why you added this image sizes in the first place since everything works without it. You must have your reasons but can you explain for better understanding

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    i created the custom sizes so the users could optimize the images displayed on the [adverts_list] and Ad details instead of having the full images used.

    Having the images optimized will allow saving some bandwidth and improve the website loading speed (which in theory will also somewhat benefit the website SEO score).

    Either way, if in your case the disk space is more important than the bandwidth then removing custom image sizes is a good idea i think.

    Thread Starter teeboy4real

    (@teeboy4real)

    Hmmm your reason is much appreciated but will it be possible to add those 3 image sizes for only advert images. For example when blog posts are created with featured images the 3 advert image sizes are also created for the blog post featured images which is not necessary would it be possible to restrict the creation of the 3 advert image sizes to only advert images and not blog post images.

    Plugin Author Greg Winiarski

    (@gwin)

    That might be a bit problematic but should be possible, you would need to customize your code so that the custom sizes are removed unless: user is uploading image, viewing [adverts_list], [adverts_add] or Ad details page.

    Something like the code below will do it, it first removes the WPAdverts image sizes and then registers them again if needed, just replace 100, 200 with actual IDs of the pages with [adverts_list] and [adverts_add] shortcodes.

    You would also need to test if this works properly, as i did not run any tests myself.

    
    add_action( "init", "disable_image_sizes_init", 100 );
    function disable_image_sizes_init() {
    
      remove_image_size('adverts-gallery');
      remove_image_size('adverts-list');
      remove_image_size('adverts-upload-thumbnail');
    	
      if( is_singular( "advert" ) ) {
        register_sizes_again();
      } else if( is_page( array( 100, 200 ) ) ) {
        register_sizes_again();
      } else if( adverts_request( "action" ) == "adverts_gallery_upload" ) {
        register_sizes_again();
      }	
    }
    function register_sizes_again() {
      foreach( adverts_config( "gallery.image_sizes" ) as $image_key => $image_size ) {
        if( $image_size["enabled"] ) {
          add_image_size( $image_key, $image_size["width"], $image_size["height"], $image_size["crop"] );
        }
      }
    }
    
    Thread Starter teeboy4real

    (@teeboy4real)

    OMG! I just tested your code and it worked perfectly I uploaded new images in wp admin media gallery and the image sizes were not created but when I uploaded the images through [adverts_add] page the image sizes were created.

    One last question?
    Can I remove this remove_image_size(‘adverts-gallery’); since I am not using the thumbnails slider option in the settings. My gallery pagination is set to Next and Previous Buttons option.
    So since I dont use thumbnails can I disable this remove_image_size(‘adverts-gallery’)

    Thanks a lot

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    the adverts-gallery images are used on the Ad details pages for example https://demo.wpadverts.com/lite/advert/rayman-legends/ (it is the full-content width image below the title).

    It is being used regardless of the gallery version you are using, in other words you can safely remove it only if you are using some third-party gallery.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘disable thumbnails review/question’ is closed to new replies.