Title: Post Media Cleanup
Author: iftiarhossain
Published: <strong>13 Luglio 2026</strong>
Last modified: 9 Ottobre 2026

---

Ricerca i plugin

![](https://ps.w.org/post-media-cleanup/assets/banner-772x250.png?rev=3617453)

![](https://ps.w.org/post-media-cleanup/assets/icon-256x256.png?rev=3617453)

# Post Media Cleanup

 Di [iftiarhossain](https://profiles.wordpress.org/iftiarhossain/)

[Scarica](https://downloads.wordpress.org/plugin/post-media-cleanup.2.4.0.zip)

 * [Dettagli](https://it.wordpress.org/plugins/post-media-cleanup/#description)
 * [Recensioni](https://it.wordpress.org/plugins/post-media-cleanup/#reviews)
 *  [Installazione](https://it.wordpress.org/plugins/post-media-cleanup/#installation)
 * [Sviluppo](https://it.wordpress.org/plugins/post-media-cleanup/#developers)

 [Supporto](https://wordpress.org/support/plugin/post-media-cleanup/)

## Descrizione

Post Media Cleanup removes orphaned media files from your server when you permanently
delete a post.

When you permanently delete a post, this plugin automatically finds and removes:

 * Featured image
 * Images and files embedded in post content
 * PDFs and any linked files in content
 * All attachments uploaded directly to the post

#### Key Features

 * Only fires on permanent deletion — moving to trash is always safe
 * Skip Shared Media — never deletes a file used by another post
 * Works per post type — configure exactly which types trigger cleanup
 * Compatible with S3 and cloud storage
 * Multisite ready
 * Developer friendly — filter hooks to extend behaviour

#### For Developers

Add extra attachments to the deletion list:

    ```
    add_filter( 'postmediaweb_attachment_ids_to_delete', function( $ids, $post_id ) {
        $extra = get_post_meta( $post_id, 'my_custom_pdf', true );
        if ( $extra ) $ids[] = (int) $extra;
        return $ids;
    }, 10, 2 );
    ```

Prevent a specific attachment from being deleted:

    ```
    add_filter( 'postmediaweb_should_delete_attachment', function( $should, $att_id, $post_id ) {
        if ( $att_id === 999 ) return false;
        return $should;
    }, 10, 3 );
    ```

## Installazione

 1. Upload the plugin folder to /wp-content/plugins/
 2. Activate through the Plugins screen
 3. Go to Settings  Post Media Cleanup to configure

## FAQ

### Does it delete media when I move a post to trash?

No. Only permanent deletion triggers cleanup. Trash is always safe.

### What if the same image is used in two posts?

With Skip Shared Media enabled (default), the plugin checks before deleting. If 
the file is used elsewhere it is preserved.

### Does it work with WooCommerce products?

Yes. Enable Products in the Post Types setting.

### Does it work with S3 or cloud storage?

Yes. It uses wp_delete_attachment() which cloud storage plugins hook into automatically.

## Recensioni

Non ci sono recensioni per questo plugin.

## Contributi e sviluppo

“Post Media Cleanup” è un software open source. Le persone che hanno contribuito
allo sviluppo di questo plugin sono indicate di seguito.

Collaboratori

 *   [ iftiarhossain ](https://profiles.wordpress.org/iftiarhossain/)

[Traduci “Post Media Cleanup” nella tua lingua.](https://translate.wordpress.org/projects/wp-plugins/post-media-cleanup)

### Ti interessa lo sviluppo?

[Esplora il codice](https://plugins.trac.wordpress.org/browser/post-media-cleanup/)
segui il [repository SVN](https://plugins.svn.wordpress.org/post-media-cleanup/),
segui il [log delle modifiche](https://plugins.trac.wordpress.org/log/post-media-cleanup/)
tramite [RSS](https://plugins.trac.wordpress.org/log/post-media-cleanup/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### 2.4.0

 * Fixed (data loss): Elementor images inside repeaters (slides, tabs, icon lists,
   nested containers) were not recognised as “in use”, so a shared image could be
   deleted. Media controls are now found at any depth.
 * Fixed (data loss): images referenced from CSS `url(...)`, or after a domain change/
   http-https mix / CDN or S3 URL, were not recognised as “in use”. Usage is now
   matched by upload-relative path, independent of host.
 * Fixed (data loss): the Bulk Orphan Cleanup flagged files used by widgets, theme
   mods, menus, page-builder meta, user meta and ACF fields on terms/users/options
   pages. These are now checked.
 * Fixed (data loss): the scanner flagged media belonging to posts in the Trash,
   so restoring a post could lose its images. Only attachments with no existing 
   parent are now reported, and trashed posts count as references.
 * Fixed (data loss): a “scaled” image’s original file, and WebP/AVIF siblings, 
   are now treated as the same media.
 * Fixed: unchecking every post type silently re-enabled “post”; “none selected”
   now really deletes nothing.
 * Fixed: fatal error on WordPress 5.0 – 5.4 when deleting a post (hook argument
   added in 5.5).
 * Fixed: a failure inside the plugin could block a post from being deleted; errors
   are now contained.
 * Fixed: fatal error on hosts without the PHP DOM extension.
 * Fixed: bulk delete sent every ID in one request and was truncated by `max_input_vars`;
   it now runs in batches with a progress bar.
 * Fixed: the post-type warning script was never loaded; the admin CSS depended 
   on an unreliable style handle; the delete button label was built by string-replacing
   a translatable string.
 * Fixed: the WooCommerce setting was reset to “off” on each save while WooCommerce
   was inactive.
 * Fixed: ACF repeater / flexible content / group handling now reads stored references(
   any nesting depth) instead of altering ACF’s global loop state.
 * Fixed: libxml error handling is restored after parsing; video, audio, source,
   embed, object and iframe uploads are now collected from content.
 * Security: a logged-in user can only trigger deletion of media they are allowed
   to delete (filter `postmediaweb_enforce_capabilities`).
 * Security: bulk delete re-validates on the server that each ID is an attachment,
   still an orphan, still unreferenced and deletable by the user.
 * Security: hardened AJAX input handling (nested arrays no longer become ID 1, 
   request size capped, `wp_unslash` applied).
 * Security: results of the `postmediaweb_attachment_ids_to_delete` filter are validated;`
   index.php` guards added.
 * Performance: ACF, Elementor, WooCommerce-gallery and content checks use narrow,
   targeted SQL instead of loading every row that contains a digit.

#### 2.3.1

 * Fixed: shared product-description images are preserved when content uses a resized
   image URL.
 * Fixed: a product’s own variation-image references no longer prevent those variation
   images from being cleaned up.
 * Fixed: variation images are collected even when the variations have already been
   moved to the trash.

#### 2.3.0

 * Added WooCommerce product gallery image collection on product delete
 * Added WooCommerce product variation image deletion
 * Added short description media scanning for all post types
 * Added dedicated WooCommerce settings section (visible only when WooCommerce is
   active)
 * Improved post type selector UI with Built-in vs Custom grouping
 * Added post type descriptions for known third party types
 * Added warning when no post types are selected

#### 2.2.0

 * Fixed: an image shared across multiple WooCommerce product galleries (`_product_image_gallery`)
   was deleted when only one of those products was removed, even though other products
   still used it.
 * Fixed: an image referenced only inside Elementor content/templates (`_elementor_data`)
   was deleted once its original post was removed, even though Elementor still referenced
   it elsewhere.
 * Fixed: “Skip Shared Media” only ever checked the featured-image meta and a literal
   URL match in post content — it now also checks WooCommerce product galleries,
   Elementor data, ACF image/file/gallery fields (including repeater and flexible-
   content sub-fields), term meta (e.g. category thumbnails), Gutenberg image/gallery
   blocks, `[gallery ids="..."]` and WPBakery shortcodes, and known media-holding
   site options (custom logo, site icon).
 * Fixed: the Bulk Orphan Cleanup scanner used the same narrow “featured image +
   literal URL” check and could flag genuinely-used media as orphaned for all the
   reasons above.
 * Changed: media-reference detection is conservative by design — a bare numeric
   value that happens to match an attachment ID (e.g. a generic custom field) is
   never treated as a confirmed reference on its own; only meta keys/structures 
   positively identified as media storage (WooCommerce, Elementor, ACF field definitions,
   etc.) count.
 * Added: the Bulk Orphan Cleanup deletion step now re-checks each attachment immediately
   before deleting it, instead of trusting the scan result alone — anything found
   to have become referenced since the scan (e.g. the site changed while a large
   scan was running) is skipped rather than deleted, and the admin UI now reports
   how many were skipped for this reason.
 * Added: media-reference detection is now shared between the real-time “Skip Shared
   Media” check and the Bulk Orphan Cleanup scanner (`Postmediaweb_Reference_Checker`),
   so the two can no longer disagree with each other.

#### 2.1.0

 * Fixed: deleting a post with a populated ACF gallery field could crash with a 
   fatal error on PHP 8+ (missing return value in the gallery field handler).
 * Fixed: the Settings tab could not save changes due to a settings-group name mismatch.
 * Fixed: the Bulk Orphan Cleanup tab’s Scan/Delete buttons had no JavaScript attached
   and did nothing, because jQuery was never enqueued on that page.
 * Fixed: reactivating the plugin silently reset your saved settings back to defaults.
 * Fixed: the orphan scanner could exhaust available memory on large sites by loading
   all post content and all attachment records into memory at once.
 * Fixed: the orphan scanner’s content-matching was far slower than intended at 
   scale; it now uses a single indexed pass instead of a full-text scan per attachment.
 * Fixed: attachments whose parent post no longer exists were permanently hidden
   from orphan scans instead of being correctly flagged.
 * Fixed: a PHP notice could be triggered by certain Elementor widget settings during
   media detection.
 * Improved: fewer database queries when scanning ACF fields on each deleted post.

#### 2.0.0

 * Added ACF Free and Pro support
 * Added Bulk Orphan Cleanup tool with progress indicator
 * Added tabbed settings interface

#### 1.0.0

 * Initial release

## Meta

 *  Versione **2.4.0**
 *  Ultimo aggiornamento **3 giorni fa**
 *  Installazioni attive **Meno di 10**
 *  Versione WordPress ** 5.0 o superiore **
 *  Testato fino alla versione **7.0.7**
 *  Versione PHP ** 7.4 o superiore **
 *  Lingua
 * [English (US)](https://wordpress.org/plugins/post-media-cleanup/)
 * Tag
 * [attachments](https://it.wordpress.org/plugins/tags/attachments/)[cleanup](https://it.wordpress.org/plugins/tags/cleanup/)
   [delete](https://it.wordpress.org/plugins/tags/delete/)[images](https://it.wordpress.org/plugins/tags/images/)
   [media](https://it.wordpress.org/plugins/tags/media/)
 *  [Visualizzazione avanzata](https://it.wordpress.org/plugins/post-media-cleanup/advanced/)

## Valutazioni

Non sono state ancora inviate recensioni.

[La tua recensione](https://wordpress.org/support/plugin/post-media-cleanup/reviews/#new-post)

[Vedi tutte le recensioni](https://wordpress.org/support/plugin/post-media-cleanup/reviews/)

## Collaboratori

 *   [ iftiarhossain ](https://profiles.wordpress.org/iftiarhossain/)

## Supporto

Problemi risolti negli ultimi due mesi:

     1 su 1

 [Chiedi nel forum di supporto](https://wordpress.org/support/plugin/post-media-cleanup/)