https://github.com/humanmade/replace-files
upload a replacement for an existing attachment
https://github.com/humanmade/replace-files
Last synced: 15 days ago
JSON representation
upload a replacement for an existing attachment
- Host: GitHub
- URL: https://github.com/humanmade/replace-files
- Owner: humanmade
- Created: 2017-07-07T01:36:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T14:49:11.000Z (almost 2 years ago)
- Last Synced: 2025-06-30T16:14:53.844Z (15 days ago)
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 7
- Watchers: 24
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Replace Files
This plugin allows you to upload a replacement for an existing attachment.
## Cache Busting
Replacements use the same filename as the original, allowing existing links to continue working. However, this may require busting the cache to expose the new image. You can use the `replace_files.merge_replacement.replaced` action to handle this:
```php
add_action( 'replace_files.merge_replacement.replaced', function ( $post_id ) {
// Purge the server's cache.
wp_remote_request( wp_get_attachment_url( $post_id ), [
'method' => 'PURGE',
]);
});
```