| 开发者 | kristoffbertram |
|---|---|
| 更新时间 | 2026年9月16日 14:01 |
| PHP版本: | 8.1 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPL-2.0-or-later |
| 版权网址: | 版权信息 |
wp-image-N classes[gallery] and [playlist] shortcodes, page-builder shortcodes holding an ID (image="123"), and raw file URLs, including resized variants like photo-300x200.jpg, -scaled files and percent-encoded filenameswp-image-1234.freshet_unusedmedia_detectors filter; freshet_unusedmedia_is_used gets the final say on any status; freshet_unusedmedia_batch_size and freshet_unusedmedia_batch_seconds tune scan batches; freshet_unusedmedia_upload_grace sets the recent-upload window in seconds (0 disables it).
Part of the Freshet plugin suite. Full documentation: freshet.studio/docs.
define( 'MEDIA_TRASH', true ); to wp-config.php so deletions go to trash instead of being permanent.Detection is deliberately conservative: filename and structural matches are boundary-checked (attachment 123 never matches wp-image-1234), ambiguous ID matches count as used, and every file is re-verified right before deletion.
What it cannot see is anything outside the tables it reads — posts, postmeta, options, term descriptions, term meta, user meta, comments and comment meta. The blind spot most worth knowing about is inside your database, not outside it: references stored in a plugin's own custom database tables — form entries, slider or page-builder records, any plugin that keeps attachment IDs or file URLs in a table of its own. No query-based scanner can find a reference in a table whose shape it has never seen. The same applies to references hard-coded in theme or plugin files, references held by an external service, references on other sites of a multisite network (network-wide options included), and the legacy Links manager.
Two deliberate choices are worth knowing too. Old post revisions are not counted as usage — a file removed from a post is meant to be found — but autosaves are, because they hold edits nobody has saved yet. And the re-check before deletion is not atomic: a reference written in the instant between the re-check and the deletion is not seen. That window is a fraction of a second; the recent-upload grace period covers the realistic case (a file placed in the editor before its post is saved), and MEDIA_TRASH covers the rest.
So: if a plugin on your site stores media in its own tables, check what it holds before deleting — and add define( 'MEDIA_TRASH', true ); (see Installation) so a deletion can be undone.
Longer than a scanner that only looks at the "Uploaded to" column, because it looks everywhere else as well. On a large library the first full scan is measured in hours, not minutes. It runs in batches from the Media → Usage screen, each batch stops before the PHP time limit and the next one resumes from the last completed file, so the scan always makes progress and can be stopped and picked up later. Nothing runs on a schedule — a scan happens when you start one.
No. A trashed post or comment can be restored, so a reference from one keeps the file — it is reported as a possible reference rather than a confirmed one, and possible still counts as used.
A file whose every library entry is in the trash is listed in its own "In trash" section under the unused list, and can be erased from there once the scan has found every entry unused — it never joins the unused list or its count, and a copy still in use is held back there too.
Per site, yes. Cross-site references (another site embedding this site's file URL) are not detected.
Never. Scanning only reads and caches results. Deletion happens exclusively when you click a delete action, after re-verification. Opening the page deletes nothing.
2026/09 and 2026/09 as one folder the same files could be read under two scopes — and a file's own claim could be missed. One scope per folder now, however it is spelled.HERO.JPG against a file stored hero.jpg, or markup carrying DATA-ID="123", kept nothing in use and the file was offered for deletion. Both halves agree now, accented filenames included.Hero-Banner.jpg and HERO-BANNER.jpg were one group in the count and two in the list. Each is its own file now, and where the server's filesystem would treat them as the same file a deletion refuses it rather than removing a file the other entry still stands on.wp freshet-unusedmedia scan ends on an error instead of a success line, leaving --resume to carry on from the last completed batch.class="wp-image-123"), where only a plain file URL or an attachment-page link was read before.logo-300x200.png, uploaded as it is), nor a size the entry's own metadata still names.[12,34] — in post content, meta and options alike.data key: a file referenced as {"imageId":123} by a custom block used to scan as unused.[gallery] — [playlist] and page-builder shortcodes included.freshet_unusedmedia_upload_grace to tune).freshet_unusedmedia_batch_seconds to tune).