{"id":333880,"date":"2026-07-13T10:09:47","date_gmt":"2026-07-13T10:09:47","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/post-media-cleanup\/"},"modified":"2026-07-13T10:09:15","modified_gmt":"2026-07-13T10:09:15","slug":"post-media-cleanup","status":"publish","type":"plugin","link":"https:\/\/wordpress.org\/plugins\/post-media-cleanup\/","author":23503550,"comment_status":"closed","ping_status":"closed","template":"","meta":{"version":"1.0.0","stable_tag":"1.0.0","tested":"7.0.1","requires":"5.0","requires_php":"7.4","requires_plugins":null,"header_name":"Post Media Cleanup","header_author":"Iftiar Hossain","header_description":"Automatically deletes all associated media files when a post is permanently deleted.","assets_banners_color":"","last_updated":"2026-07-13 10:09:15","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/wordpress.org\/plugins\/post-media-cleanup\/","header_author_uri":"https:\/\/iftiarhossain.com","rating":0,"author_block_rating":0,"active_installs":0,"downloads":16,"num_ratings":0,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","faq","changelog"],"tags":{"1.0.0":{"tag":"1.0.0","author":"iftiarhossain","date":"2026-07-13 10:09:15"}},"upgrade_notice":{"1.0.0":"<p>Initial release<\/p>"},"ratings":[],"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0.0"],"block_files":[],"assets_screenshots":[],"screenshots":{"1":"Settings page under Settings \u2192 Post Media Cleanup"}},"plugin_section":[],"plugin_tags":[1346,3786,2872,163,84],"plugin_category":[50],"plugin_contributors":[264156],"plugin_business_model":[],"class_list":["post-333880","plugin","type-plugin","status-publish","hentry","plugin_tags-attachments","plugin_tags-cleanup","plugin_tags-delete","plugin_tags-images","plugin_tags-media","plugin_category-media","plugin_contributors-iftiarhossain","plugin_committers-iftiarhossain"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/post-media-cleanup.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>Post Media Cleanup removes orphaned media files from your server when you permanently delete a post.<\/p>\n\n<p>When you permanently delete a post, this plugin automatically finds and removes:<\/p>\n\n<ul>\n<li>Featured image<\/li>\n<li>Images and files embedded in post content<\/li>\n<li>PDFs and any linked files in content<\/li>\n<li>All attachments uploaded directly to the post<\/li>\n<\/ul>\n\n<h4>Key Features<\/h4>\n\n<ul>\n<li>Only fires on permanent deletion \u2014 moving to trash is always safe<\/li>\n<li>Skip Shared Media \u2014 never deletes a file used by another post<\/li>\n<li>Works per post type \u2014 configure exactly which types trigger cleanup<\/li>\n<li>Compatible with S3 and cloud storage<\/li>\n<li>Multisite ready<\/li>\n<li>Developer friendly \u2014 filter hooks to extend behaviour<\/li>\n<\/ul>\n\n<h4>For Developers<\/h4>\n\n<p>Add extra attachments to the deletion list:<\/p>\n\n<pre><code>add_filter( 'postmediaweb_attachment_ids_to_delete', function( $ids, $post_id ) {\n    $extra = get_post_meta( $post_id, 'my_custom_pdf', true );\n    if ( $extra ) $ids[] = (int) $extra;\n    return $ids;\n}, 10, 2 );\n<\/code><\/pre>\n\n<p>Prevent a specific attachment from being deleted:<\/p>\n\n<pre><code>add_filter( 'postmediaweb_should_delete_attachment', function( $should, $att_id, $post_id ) {\n    if ( $att_id === 999 ) return false;\n    return $should;\n}, 10, 3 );\n<\/code><\/pre>\n\n<!--section=installation-->\n<ol>\n<li>Upload the plugin folder to \/wp-content\/plugins\/<\/li>\n<li>Activate through the Plugins screen<\/li>\n<li>Go to Settings \u2192 Post Media Cleanup to configure<\/li>\n<\/ol>\n\n<!--section=faq-->\n<dl>\n<dt id=\"does%20it%20delete%20media%20when%20i%20move%20a%20post%20to%20trash%3F\"><h3>Does it delete media when I move a post to trash?<\/h3><\/dt>\n<dd><p>No. Only permanent deletion triggers cleanup. Trash is always safe.<\/p><\/dd>\n<dt id=\"what%20if%20the%20same%20image%20is%20used%20in%20two%20posts%3F\"><h3>What if the same image is used in two posts?<\/h3><\/dt>\n<dd><p>With Skip Shared Media enabled (default), the plugin checks before deleting. If the file is used elsewhere it is preserved.<\/p><\/dd>\n<dt id=\"does%20it%20work%20with%20woocommerce%20products%3F\"><h3>Does it work with WooCommerce products?<\/h3><\/dt>\n<dd><p>Yes. Enable Products in the Post Types setting.<\/p><\/dd>\n<dt id=\"does%20it%20work%20with%20s3%20or%20cloud%20storage%3F\"><h3>Does it work with S3 or cloud storage?<\/h3><\/dt>\n<dd><p>Yes. It uses wp_delete_attachment() which cloud storage plugins hook into automatically.<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<h4>1.0.0<\/h4>\n\n<ul>\n<li>Initial release<\/li>\n<\/ul>","raw_excerpt":"Automatically deletes all associated media files when a post is permanently deleted.","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/333880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=333880"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/iftiarhossain"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=333880"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=333880"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=333880"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=333880"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=333880"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=333880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}