The infinite_uploads_delete_files_from_cloud action allows developers to run custom logic whenever an attachment’s files are removed from Infinite Uploads’ cloud storage. This is especially useful for plugins that need to synchronize deletion events — for example, clearing cached versions, purging CDNs, or integrating with image-processing services like ShortPixel.
This hook fires after Infinite Uploads has deleted all cloud-stored variants for the given attachment ID.
Usage
add_action( 'infinite_uploads_delete_files_from_cloud', 'myplugin_after_cloud_delete' );
/**
* Runs after Infinite Uploads deletes the cloud-stored files for an attachment.
*
* @param int $attachment_id The ID of the attachment whose files were deleted.
*/
function myplugin_after_cloud_delete( $attachment_id ) {
// Your custom cleanup logic here.
}
Parameters
| Parameter | Type | Description |
|---|---|---|
$attachment_id | int | The ID of the attachment whose cloud assets were removed. This includes all Infinite Uploads–managed paths, thumbnails, and generated sizes. |
When This Hook Fires
This action is triggered whenever Infinite Uploads deletes cloud files for an attachment, including (but not limited to):
- Media Library deletion
- Regeneration events that remove existing cloud files
- Manual or programmatic cleanup operations
It is not triggered when only local files are modified or when metadata is updated without removing cloud files.
Example: Clearing Third-Party Optimized Assets
If you integrate with an image optimization service that stores its own versions (e.g., ShortPixel, Imagify, EWWW), you may want to clear those optimized copies when the original cloud asset is deleted:
add_action( 'infinite_uploads_delete_files_from_cloud', 'myplugin_cleanup_optimizer_metadata' );
function myplugin_cleanup_optimizer_metadata( $attachment_id ) {
// Example: remove custom metadata your plugin stores.
delete_post_meta( $attachment_id, '_myplugin_optimizer_data' );
// If integrating with an image optimizer, clear its stored metadata or records.
// ShortPixel example (fictional API call; replace with the real one if needed):
if ( class_exists( 'ShortPixelAI' ) ) {
ShortPixelAI::deleteAttachmentRecord( $attachment_id );
}
}