Title: Plugin does not clean up after itself!
Last modified: November 10, 2017

---

# Plugin does not clean up after itself!

 *  Resolved [josho493](https://wordpress.org/support/users/josho493/)
 * (@josho493)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/plugin-does-not-clean-up-after-itself/)
 * I was setting this plugin up again and changing my remote storage settings when
   I went into the database. Initially I had noticed that since all the media files
   had previously been marked as uploaded to remote storage, that now that I had
   selected a new remote storage they would not upload to the new storage even when
   selecting import.
 * When searching the database to manually remove this marking, I see that the previous
   remote URL is stored in the actual post meta. In my testing this is not removed
   even when deleting the plugin. This really frustrates me as my sites has over
   120,000 images which now is an extra 10-15MB on my database size forever.
 * Is this marking supposed to be removed when deleting the plugin? Is there a way
   for me to do this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [interfacelab](https://wordpress.org/support/users/interfacelab/)
 * (@interfacelab)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/plugin-does-not-clean-up-after-itself/#post-9672632)
 * The plugin doesn’t support changing storage providers. It also doesn’t support
   being removed because it’s a cornerstone fundamental of your architecture.
 * You can remove the S3 data from your attachments using this (back up your DB 
   first though):
 *     ```
       add_action('init', function(){
       	$attachments = new \WP_Query([
       		                             'post_type' => 'attachment',
       		                             'post_status' => ['publish', 'inherit'],
       		                             'posts_per_page'=> '-1'
       	                             ]);
   
       	foreach($attachments->posts as $attachment) {
       		$meta = wp_get_attachment_metadata($attachment->ID);
       		if (isset($meta['s3'])) {
       			unset($meta['s3']);
   
       			if (isset($meta['sizes'])) {
       				$metaSizes = $meta['sizes'];
       				foreach($meta['sizes'] as $size => $sizeData) {
       					if (isset($sizeData['s3'])) {
       						unset($sizeData['s3']);
       						$metaSizes[$size] = $sizeData;
       					}
       				}
   
       				$meta['sizes'] = $metaSizes;
       			}
       		}
   
       		wp_update_attachment_metadata($attachment->ID,$meta);
       	}
       });
       ```
   
 * Thanks,
 * Jon.
 *  Thread Starter [josho493](https://wordpress.org/support/users/josho493/)
 * (@josho493)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/plugin-does-not-clean-up-after-itself/#post-9683280)
 * Thank you for supplying this code!
 * Would love to see this integrated into the plugin

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Plugin does not clean up after itself!’ is closed to new replies.

 * ![](https://ps.w.org/ilab-media-tools/assets/icon.svg?rev=2795439)
 * [Media Cloud for Bunny CDN, Amazon S3, Cloudflare R2, Google Cloud Storage, DigitalOcean and more](https://wordpress.org/plugins/ilab-media-tools/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ilab-media-tools/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ilab-media-tools/)
 * [Active Topics](https://wordpress.org/support/plugin/ilab-media-tools/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ilab-media-tools/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ilab-media-tools/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [josho493](https://wordpress.org/support/users/josho493/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/plugin-does-not-clean-up-after-itself/#post-9683280)
 * Status: resolved