Title: Replace Media
Last modified: April 21, 2022

---

# Replace Media

 *  Resolved [bonumaster](https://wordpress.org/support/users/bonumaster/)
 * (@bonumaster)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/replace-media/)
 * Hello. Thank you for this wonderful plugin. It works! But I have some questions
   and clarifications that only you can help me to understand.
 * 1. When medias are already offloaded/served through CDN(DigitalOcean) and it 
   works perfectly with the Rewrite Media URLs, If we try to modify the attachment/
   media. (We are watermarking the media’s even it is offloaded because we didn’t
   delete the file in our server after offloading). Will it replace the file uploaded
   in the CDN? or It will ignore in offloading? Will this plugin replace existing
   files if media is modified or we need to manually delete it in our DigitalOcean
   space? Thanks!

Viewing 1 replies (of 1 total)

 *  Plugin Author [Delicious Brains](https://wordpress.org/support/users/deliciousbrains/)
 * (@deliciousbrains)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/replace-media/#post-15587729)
 * Hi [@bonumaster](https://wordpress.org/support/users/bonumaster/), thanks for
   the kind words, much appreciated.
 * > Will it replace the file uploaded in the CDN? or It will ignore in offloading?
   Will this plugin replace existing files if media is modified or we need to manually
   delete it in our DigitalOcean space?
 * WP Offload Media should re-offload the images after they have been processed,
   but it does depend on whether the watermarking process calls one of the functions
   that triggers the re-offload.
 * If it’s your own custom code that does the watermarking, then please ensure that
   after the files for a Media Library item have been processed that your code does
   something like the following…
 * `wp_update_attachment_metadata( $item->ID, wp_generate_attachment_metadata( $
   item->ID, $file ) );`
 * The important call there is `wp_update_attachment_metadata()`, if you already
   have the attachment’s metadata you don’t need to regenerate it, just pass it 
   in.
 * WP Offload Media will see the `wp_update_attachment_metadata` filter fired by
   the function of the same name, and copy the attachment’s file to the bucket, 
   overwriting the previous versions if already offloaded.
 * I would recommend using the `as3cf_pre_upload_attachment` filter to cancel the
   original offload though, and then remove that filter before doing the final `
   wp_update_attachment_metadata`. That way you don’t waste time offloading to the
   bucket and re-offloading again, and it ensures CDNs only see the final watermarked
   files.
 * [https://deliciousbrains.com/wp-offload-media/doc/developer-guide/#automatic-offload-hooks-wp-update-attachment-metadata](https://deliciousbrains.com/wp-offload-media/doc/developer-guide/#automatic-offload-hooks-wp-update-attachment-metadata)
 * [https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/beb2e0f1bba71be7b462a60209e5ff630a57437e/amazon-s3-and-cloudfront-tweaks.php#L528](https://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks/blob/beb2e0f1bba71be7b462a60209e5ff630a57437e/amazon-s3-and-cloudfront-tweaks.php#L528)
 * If you’re using a watermarking plugin, might be worth passing the above info 
   onto the author if you’re seeing issues.
 * -IJ

Viewing 1 replies (of 1 total)

The topic ‘Replace Media’ is closed to new replies.

 * ![](https://ps.w.org/amazon-s3-and-cloudfront/assets/icon-256x256.jpg?rev=1809890)
 * [WP Offload Media Lite for Amazon S3, DigitalOcean Spaces, and Google Cloud Storage](https://wordpress.org/plugins/amazon-s3-and-cloudfront/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amazon-s3-and-cloudfront/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amazon-s3-and-cloudfront/)
 * [Active Topics](https://wordpress.org/support/plugin/amazon-s3-and-cloudfront/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amazon-s3-and-cloudfront/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amazon-s3-and-cloudfront/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Delicious Brains](https://wordpress.org/support/users/deliciousbrains/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/replace-media/#post-15587729)
 * Status: resolved