• Hi there,

    thanks for developing this plugin. I spent some time implementing this plugin on my rather complex website.

    To get the desired behavior I had to change some things in the plugin code and add some custom methods. As I think this feedback could be valuable, I’ll summarize the changes here.

    1. I had to implement a custom WooCommere Product Image handling method. Because somehow the in-built method didn’t catch the gallery images. When looking at the source code I realized, that you directly access the meta data from the post id. I didn’t check if woocommerce changed meta keys lately, but I solved the problem by adding my own method which loads the WC_Product instance of each product and uses the woocommerce getters and setters. See my snippet below: (The Method GBWC_WPS_Cleaner::whitelist_attachment_id() is a custom method, which whitelists ids by interacting with the WPS Cleaner database.

    public static function link_images_to_product( WC_Product $product ) {
    
    	$image_ids   = $product->get_gallery_image_ids();
    	$image_ids[] = $product->get_image_id();
    	$image_ids   = array_filter( $image_ids );
    
    	if ( $image_ids ) {
    		foreach ( $image_ids as $image_id ) {
    			GBWC_WPS_Cleaner::whitelist_attachment_id(
    				$image_id,
    				'woocommerce_product_image',
    				$product->get_id(),
    			);
    		}
    	}
    
    }

    I also implemented a similar method, to whitelist product category images when saving them. (I know at the momemnt there’s no way to remove the link, when the category is deleted, but I don’t expect category images to bloat my website).

    
    		add_action( 'created_term', array( $this, 'save_fields' ), 10, 3 );
    		add_action( 'edit_term', array( $this, 'save_fields' ), 10, 3 );
    

    and

    public function save_fields( $term_id, $tt_id = '', $taxonomy = '' ) {
    		// quick fix to also whitelist product category images
    		if ( isset( $_POST['product_cat_thumbnail_id'] ) && 'product_cat' === $taxonomy ) {
    			if ( $thumbnail_id = absint( $_POST['product_cat_thumbnail_id'] ) ) {
    				GBWC_WPS_Cleaner::whitelist_attachment_id( $thumbnail_id, 'woocommerce_product_cat' );
    			}
    		}

    Then more technical aspect regarding the handling of the plugin.
    My website generates post ids pretty much every couple minutes (orders, emails etc)., hence when I look at the media tool tab it is always waiting for the data to sync, which is triggered by a scheduled hourly event. My suggestion to fix this, is also to fire the hook (‘wps_cleaner_indexation_medias’) everytime the page loads, as it will only take a couple ms to update the small number of posts in the queue.

    Lastly I had the problem, that when I manually whitelisted some attachments and had the whitelist button and table showing on the media screen, I couldn’t use the pagination anymore. The only way to solve this, was by commenting out the whitelist table. I think this requires some urgent attention from the developers.

    I hope this post was helpful and once again thanks for developing this plugin. It allowed me to reduce the size of my wordpress installation by more than 50%, something which wouldn’t have been possible manually.

  • The topic ‘Suggestions’ is closed to new replies.