| 开发者 | kodlo |
|---|---|
| 更新时间 | 2026年10月12日 04:55 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
In the Media Library list view, hover over a file and click "Replace file". In the grid view, open a file and click "Replace file". Both lead to the edit screen of the file, where the "Replace file" box is in the right column.
No. The file is overwritten in place. The ID, file name, URL, title, alt text, caption and description stay as they are.
No. Changing the type would change the file extension and therefore the URL, which is exactly what this plugin avoids. Convert the new file to the same type first.
Reload the page once without the browser cache (Ctrl+F5 or Cmd+Shift+R). Pages rendered by WordPress get the new version parameter automatically. Files opened by a direct link (for example a PDF link sent by email), or images referenced in external CSS files, can still be served from a CDN until its cache expires. For Cloudflare, set up the automatic purge described below.
Create an API token in Cloudflare (My Profile > API Tokens > Create Custom Token) with the permission Zone > Cache Purge > Purge for your domain. Then add this to wp-config.php:
define( 'KODLO_MR_CF_ZONE_ID', 'your-zone-id' );
define( 'KODLO_MR_CF_API_TOKEN', 'your-api-token' );
If Cloudflare also caches your HTML pages (APO or a "Cache Everything" rule), add:
define( 'KODLO_MR_CF_PURGE_EVERYTHING', true );
No. The plugin replaces files in the local uploads folder. Media offloaded to external storage is not supported.
Yes, on each site of the network.
Yes:
Kodlo_Media_Replace::replace( $attachment_id, '/path/to/new-file.jpg' );
The new file is moved into place. The function returns an array on success or a WP_Error object.
kodlo_mr_replaced (action): fires after a replacement with the attachment ID and the list of file URLs. Use it to purge other caches.kodlo_mr_purge_page_cache (filter): return false to skip clearing page caches.kodlo_mr_rewrite_html (filter): return false to stop adding version parameters to the front-end HTML.