Media Cleanup WP-CLI Commands and Filters

Media Cleanup includes WP-CLI commands for running scans and exports from the command line, plus filters for changing who can use it. These require the site to be connected and Media Cleanup to be turned on.

WP-CLI commands

Run a full scan in a single process. This is the most reliable option on large libraries or sites where WP-Cron doesn't run:

wp infinite-uploads media-usage scan

Rescan a single file by its attachment ID:

wp infinite-uploads media-usage scan --attachment_id=123

Export the results as CSV. Without a file name, the CSV is printed to the terminal:

wp infinite-uploads media-usage export media-usage.csv

Delete all stored scan results (your media files are not touched):

wp infinite-uploads media-usage clear

See WP-CLI Commands and Usage for the other Infinite Uploads commands.

Filters

  • infinite_uploads_media_cleanup_capability: the capability needed to use the Media Cleanup screen, the Usage column, and scans. Defaults to manage_options. The Possible Duplicates tab always requires manage_options.
  • infinite_uploads_media_usage_path_map_max: how many attachments the scan keeps in memory for fast matching. Defaults to 50000. Larger libraries use a slower lookup.

This example lets Editors use Media Cleanup:

add_filter( 'infinite_uploads_media_cleanup_capability', function () {
	return 'edit_others_posts';
} );

Background processing

Scans started from the dashboard run through Action Scheduler with the hook infinite-uploads-media-usage-scan in the infinite-uploads group. If your site has the Tools > Scheduled Actions screen, you can see them there.

Get Support

Need help with Media Cleanup or have questions? Submit a support request and a member of our team will get back to you within 24 hours. If you are having a problem, we would love the opportunity to resolve any issues. Create a ticket at https://infiniteuploads.com/support/