{"id":10734,"date":"2025-12-01T16:28:24","date_gmt":"2025-12-01T22:28:24","guid":{"rendered":"https:\/\/infiniteuploads.com\/?post_type=docs&#038;p=10734"},"modified":"2025-12-01T16:46:55","modified_gmt":"2025-12-01T22:46:55","password":"","slug":"deleting-files-from-cloud-storage-with-infinite_uploads_delete_files_from_cloud","status":"publish","type":"docs","link":"https:\/\/infiniteuploads.com\/docs\/developers\/deleting-files-from-cloud-storage-with-infinite_uploads_delete_files_from_cloud\/","title":{"rendered":"Deleting Files from Cloud Storage with infinite_uploads_delete_files_from_cloud"},"content":{"rendered":"<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN\" \"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\">\n<html><body><p>The <code>infinite_uploads_delete_files_from_cloud<\/code> action allows developers to run custom logic whenever an attachment&rsquo;s files are removed from Infinite Uploads&rsquo; cloud storage. This is especially useful for plugins that need to synchronize deletion events &mdash; for example, clearing cached versions, purging CDNs, or integrating with image-processing services like ShortPixel.<\/p>\n\n\n\n<p>This hook fires <strong>after Infinite Uploads has deleted all cloud-stored variants for the given attachment ID<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"usage\">Usage<\/h2>\n\n\n\n<div class=\"betterdocs-code-snippet-wrapper theme-light betterdocs-code-snippet-4d3078ba\" id=\"betterdocs-code-snippet-4d3078ba\" data-language=\"php\" data-copy-button=\"true\">\n\n            <div class=\"betterdocs-code-snippet-header betterdocs-file-preview-header\">\n        <div class=\"betterdocs-file-preview-left\">\n                            <div class=\"betterdocs-traffic-lights\">\n                    <span class=\"traffic-light traffic-light-red\"><\/span>\n                    <span class=\"traffic-light traffic-light-yellow\"><\/span>\n                    <span class=\"traffic-light traffic-light-green\"><\/span>\n                <\/div>\n            \n            <div class=\"betterdocs-file-info\">\n                                    <div class=\"betterdocs-file-icon\">\n                                                    <span class=\"betterdocs-file-icon-emoji\">&#128024;<\/span>\n                                            <\/div>\n                \n                            <\/div>\n        <\/div>\n\n        <div class=\"betterdocs-file-preview-right\">\n                            <div class=\"betterdocs-code-snippet-copy-container\">\n                    <button class=\"betterdocs-code-snippet-copy-button\" type=\"button\" data-clipboard-target=\"#betterdocs-code-snippet-4d3078ba .betterdocs-code-snippet-code code\" aria-label=\"Copy code to clipboard\">\n                        <svg width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM19 21H8V7H19V21Z\" fill=\"currentColor\"><\/path>\n                        <\/svg>\n                    <\/button>\n                                    <\/div>\n                    <\/div>\n        <\/div>\n    \n    <div class=\"betterdocs-code-snippet-content\">\n        \n        <pre class=\"betterdocs-code-snippet-code language-php\"><code>add_action( 'infinite_uploads_delete_files_from_cloud', 'myplugin_after_cloud_delete' );\n\n\/**\n * Runs after Infinite Uploads deletes the cloud-stored files for an attachment.\n *\n * @param int $attachment_id The ID of the attachment whose files were deleted.\n *\/\nfunction myplugin_after_cloud_delete( $attachment_id ) {\n    \/\/ Your custom cleanup logic here.\n}\n<\/code><\/pre>\n    <\/div>\n<\/div>\n\n<script type=\"text\/javascript\">\ndocument.addEventListener('DOMContentLoaded', function() {\n    \/\/ Initialize copy functionality for this specific snippet\n    const snippet = document.getElementById('betterdocs-code-snippet-4d3078ba');\n    if (snippet && window.BetterDocsCodeSnippet) {\n        window.BetterDocsCodeSnippet.initCopyButton(snippet);\n    }\n});\n<\/script>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"parameters\">Parameters<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Parameter<\/th><th>Type<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><code>$attachment_id<\/code><\/td><td>int<\/td><td>The ID of the attachment whose cloud assets were removed. This includes all Infinite Uploads&ndash;managed paths, thumbnails, and generated sizes.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"when-this-hook-fires\">When This Hook Fires<\/h2>\n\n\n\n<p>This action is triggered whenever Infinite Uploads deletes cloud files for an attachment, including (but not limited to):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Media Library deletion<\/li>\n\n\n\n<li>Regeneration events that remove existing cloud files<\/li>\n\n\n\n<li>Manual or programmatic cleanup operations<\/li>\n<\/ul>\n\n\n\n<p>It is <strong>not<\/strong> triggered when only local files are modified or when metadata is updated without removing cloud files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-clearing-third-party-optimized-assets\">Example: Clearing Third-Party Optimized Assets<\/h3>\n\n\n\n<p>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:<\/p>\n\n\n\n<div class=\"betterdocs-code-snippet-wrapper theme-light betterdocs-code-snippet-f5ae1b26\" id=\"betterdocs-code-snippet-f5ae1b26\" data-language=\"php\" data-copy-button=\"true\">\n\n            <div class=\"betterdocs-code-snippet-header betterdocs-file-preview-header\">\n        <div class=\"betterdocs-file-preview-left\">\n                            <div class=\"betterdocs-traffic-lights\">\n                    <span class=\"traffic-light traffic-light-red\"><\/span>\n                    <span class=\"traffic-light traffic-light-yellow\"><\/span>\n                    <span class=\"traffic-light traffic-light-green\"><\/span>\n                <\/div>\n            \n            <div class=\"betterdocs-file-info\">\n                                    <div class=\"betterdocs-file-icon\">\n                                                    <span class=\"betterdocs-file-icon-emoji\">&#128024;<\/span>\n                                            <\/div>\n                \n                            <\/div>\n        <\/div>\n\n        <div class=\"betterdocs-file-preview-right\">\n                            <div class=\"betterdocs-code-snippet-copy-container\">\n                    <button class=\"betterdocs-code-snippet-copy-button\" type=\"button\" data-clipboard-target=\"#betterdocs-code-snippet-f5ae1b26 .betterdocs-code-snippet-code code\" aria-label=\"Copy code to clipboard\">\n                        <svg width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1ZM19 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H19C20.1 23 21 22.1 21 21V7C21 5.9 20.1 5 19 5ZM19 21H8V7H19V21Z\" fill=\"currentColor\"><\/path>\n                        <\/svg>\n                    <\/button>\n                                    <\/div>\n                    <\/div>\n        <\/div>\n    \n    <div class=\"betterdocs-code-snippet-content\">\n        \n        <pre class=\"betterdocs-code-snippet-code language-php\"><code>add_action( 'infinite_uploads_delete_files_from_cloud', 'myplugin_cleanup_optimizer_metadata' );\n\nfunction myplugin_cleanup_optimizer_metadata( $attachment_id ) {\n\n    \/\/ Example: remove custom metadata your plugin stores.\n    delete_post_meta( $attachment_id, '_myplugin_optimizer_data' );\n\n    \/\/ If integrating with an image optimizer, clear its stored metadata or records.\n    \/\/ ShortPixel example (fictional API call; replace with the real one if needed):\n    if ( class_exists( 'ShortPixelAI' ) ) {\n        ShortPixelAI::deleteAttachmentRecord( $attachment_id );\n    }\n}\n<\/code><\/pre>\n    <\/div>\n<\/div>\n\n<script type=\"text\/javascript\">\ndocument.addEventListener('DOMContentLoaded', function() {\n    \/\/ Initialize copy functionality for this specific snippet\n    const snippet = document.getElementById('betterdocs-code-snippet-f5ae1b26');\n    if (snippet && window.BetterDocsCodeSnippet) {\n        window.BetterDocsCodeSnippet.initCopyButton(snippet);\n    }\n});\n<\/script>\n<\/body><\/html>\n","protected":false},"excerpt":{"rendered":"<p>The infinite_uploads_delete_files_from_cloud action allows developers to run custom logic whenever an attachment&rsquo;s files are removed from Infinite Uploads&rsquo; cloud storage. This is especially useful for plugins that need to synchronize deletion events &mdash; for example, clearing cached versions, purging CDNs, or integrating with image-processing services like ShortPixel. This hook fires after Infinite Uploads has deleted [&hellip;]<\/p>\n","protected":false},"author":3787,"featured_media":10761,"template":"","meta":{"_acf_changed":false,"wds_primary_doc_category":0,"wds_primary_doc_tag":0,"footnotes":""},"doc_category":[147],"doc_tag":[],"class_list":["post-10734","docs","type-docs","status-publish","has-post-thumbnail","hentry","doc_category-developers"],"acf":[],"year_month":"2026-04","word_count":187,"total_views":"312","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Blake Whittle","author_nicename":"blakew","author_url":"https:\/\/infiniteuploads.com\/blog\/author\/blakew\/"},"doc_category_info":[{"term_name":"Developers","term_url":"https:\/\/infiniteuploads.com\/docs-category\/developers\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/docs\/10734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/users\/3787"}],"version-history":[{"count":0,"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/docs\/10734\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/media\/10761"}],"wp:attachment":[{"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/media?parent=10734"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/doc_category?post=10734"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/infiniteuploads.com\/api\/wp\/v2\/doc_tag?post=10734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}