Title: Autoremove Attachments
Author: Polygon Themes
Published: <strong>2015 年 7 月 10 日</strong>
Last modified: 2026 年 5 月 10 日

---

搜尋外掛

![](https://ps.w.org/autoremove-attachments/assets/banner-772x250.png?rev=2348966)

![](https://ps.w.org/autoremove-attachments/assets/icon-256x256.png?rev=2348966)

# Autoremove Attachments

 由 [Polygon Themes](https://profiles.wordpress.org/polygonthemes/) 開發

[下載](https://downloads.wordpress.org/plugin/autoremove-attachments.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/autoremove-attachments/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/autoremove-attachments/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/autoremove-attachments/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/autoremove-attachments/#developers)

 [技術支援](https://wordpress.org/support/plugin/autoremove-attachments/)

## 外掛說明

Autoremove Attachments helps you keep the Media Library clean by deleting all media
files attached as child attachments to a post, page, or custom post type when the
parent is deleted.

By default, when you delete content from your website, regardless if it’s a post,
a page, a product, or any kind of post type, WordPress keeps the media files previously
associated with it, even if after the removal of your content they are not used 
anywhere else.

Autoremove Attachments tries to solve this problem by automating the removal of 
all media files that have a child-parent relationship with the removed content. (
so you don’t have to manually track and remove orphan files left on your server)

### Important Considerations

 * A soft delete that places your post, page, or custom post type in Trash will 
   not trigger the removal of its child attachments. The purge happens when you 
   empty your trash.
 * When you delete a post, page or custom post type, we try to determine if its 
   child attachments are used anywhere else on your website. If they are, we do 
   not remove them, to prevent broken links.
 * The additional checks before the automatic removal can be disabled from the Media
   Settings for improved performance on large websites with thousands of posts and
   media files.
 * The plugin only removes files tracked by WordPress. Some poorly coded themes 
   generate additional thumbnail sizes that are not tracked by WordPress and this
   always leads to orphan files left on your server.

### Compatibility and Third-Party Support

 * [WooCommerce](https://wordpress.org/plugins/woocommerce)
 * [Easy Digital Downloads](https://wordpress.org/plugins/easy-digital-downloads)
 * All themes and plugins that do things the WordPress way

If you use a plugin to optimize and clean your database of revisions, trashed posts,
etc, make sure you use one that relies on native WordPress functions to perform 
the maintenance tasks. We recommend [WP-Sweep](https://wordpress.org/plugins/wp-sweep).

## 安裝方式

### Automatic Installation

The automatic installation is the easiest option to install a plugin as WordPress
handles the file transfers itself. To do an automatic install, log in to your WordPress
dashboard and follow the steps below:

 1. Navigate to the Plugins menu and click “Add New”
 2. In the search field type “Autoremove Attachments” and click “Search Plugins”
 3. Once you have found the plugin install it by clicking “Install Now”
 4. Activate “Autoremove Attachments” from the “Plugins” menu

### Manual Installation

The manual installation method involves downloading the plugin and uploading it 
on your server via SFTP. To do a manual install follow the steps below:

 1. Download the plugin to your local computer
 2. If downloaded as a zip archive extract it to your Desktop
 3. Upload the plugin folder to the /wp-content/plugins/ directory
 4. Activate “Autoremove Attachments” from the “Plugins” menu

## 常見問題集

### Does it work with custom post types?

Yes, it does. It works with posts, pages and custom post types. All child attachments
are removed when the parent is deleted.

### When are the attachments removed?

The files are removed when the parent post, page, or custom post type is permanently
removed. A soft delete that places it in Trash will not trigger the removal of your
attachments.

The purge happens when you empty your trash.

### Can I control what attachments are removed?

Yes, you can. By default, all media files attached to a post, page or custom post
type are removed automatically. If you need granular control you can use the filter`
autoremove_attachments_allowed` to define custom rules for controlling when the 
child attachments should be removed automatically.

Here is an example on how you can remove the attachments only for specific custom
post types:

    ```
    function autoremove_attachments_custom_rule() {
        // Global variables.
        global $post_id;

        // Variables.
        $post_type          = get_post_type( $post_id );
        $allowed_post_types = array(
            'project',
            'product',
        );

        // Default return value.
        $allowed_to_remove = false;



        // Custom rules for removing attachments.
        if ( in_array( $post_type, $allowed_post_types ) ) {
            $allowed_to_remove = true;
        }



        // Return.
        return $allowed_to_remove;
    }
    add_filter( 'autoremove_attachments_allowed', 'autoremove_attachments_custom_rule' );
    ```

The returned value should be true for the cases in which you want the attachments
removed. (false otherwise)

### Are there any restrictions on how I can use my attachments?

Depending on how you use the plugin, the answer can be either yes, or no.

If you keep the plugin running with the additional checks enabled, you have no restrictions
on how you can use your attachments. (you can use your media files in multiple locations,
without the fear of broken links caused by their removal)

If you disable the additional checks, you need to make sure you don’t reuse your
media files between posts. If you do and the parent is deleted, you will end up 
with broken links in all the other locations where the removed attachments were 
used.

Regardless of how you use the plugin, if you need to use an attachment over and 
over again, upload it from the global Media Library menu. ( Media > Add New ) This
way, it won’t be attached as a child to a specific post, page, or custom post type
and you will be able to use it without restrictions.

## 使用者評論

![](https://secure.gravatar.com/avatar/fb31f647f8ab53a18cdca8f7c13b5329bba9c2ac5525279b17331d9a80e426b5?
s=60&d=retro&r=g)

### 󠀁[It autoremoves the attachments!](https://wordpress.org/support/topic/it-autoremoves-the-attachments/)󠁿

 [MaryMak](https://profiles.wordpress.org/maxms/) 2025 年 1 月 9 日

Simple, straightforward and does what it claims to do. Really useful and easy as
this task should be.

![](https://secure.gravatar.com/avatar/5b5180fb8b0568deed53b2a638f3575ef5e06bc82aa3a86b24bb48535052608e?
s=60&d=retro&r=g)

### 󠀁[Solved my use case!](https://wordpress.org/support/topic/solved-my-problem-65/)󠁿

 [jemcbade](https://profiles.wordpress.org/jemcbade/) 2021 年 9 月 26 日

I have clients that create attachments for a CPT, delete the post but leave the 
Media in the library. “Why is my site getting so big? The backups are HUGE now!”*
facepalm* Thank you for the code for the filter to only effect certain post types
so they don’t break the site 😛 Very well thought out use case and code. So far 
works with WP 5.8.1 and Metabox CPTs.

![](https://secure.gravatar.com/avatar/b05e6f39c8f7fedfd06a70c479350447aa8b5c95ce6df62325ff7b11e9c6e5ca?
s=60&d=retro&r=g)

### 󠀁[Simple and easy to use.](https://wordpress.org/support/topic/simple-and-easy-to-use-362/)󠁿

 [Weiching](https://profiles.wordpress.org/weiching-lin/) 2021 年 5 月 14 日

I provide the user front-end to publish articles, and I need to delete them frequently,
which saves me a lot of time. Thank you.

![](https://secure.gravatar.com/avatar/e308915395c38fd65e72310d4669824eb5ce361abeae326ac5b7010a2ffda6fb?
s=60&d=retro&r=g)

### 󠀁[Perfect](https://wordpress.org/support/topic/perfect-7056/)󠁿

 [doulou](https://profiles.wordpress.org/doulou/) 2020 年 4 月 7 日 1 則留言

I wish I’d discovered this plugin a while back! My client has a website with 2 custom
post types and constant posts being added and removed. The plugin works perfectly(
I was worried about the galleries). Thanks for a great time-saving plugin!

![](https://secure.gravatar.com/avatar/ec7ff96b9b925959c646c09743ff95ffc2ca772b6850cba45566b7cdc0256dab?
s=60&d=retro&r=g)

### 󠀁[Worked](https://wordpress.org/support/topic/worked-69/)󠁿

 [Mohsin Alam](https://profiles.wordpress.org/mohsinworld/) 2020 年 3 月 9 日 1 
則留言

This plugin worked when the image is featured image to the post, but can’t delete
which is uploaded in the middle of post.

![](https://secure.gravatar.com/avatar/329bb45f08785c2a516dee73ac02f4a578cfaebffa09048b85c088c673a6eab8?
s=60&d=retro&r=g)

### 󠀁[Saves tons of time & server resources](https://wordpress.org/support/topic/saves-tons-of-time-server-resources/)󠁿

 [wordmax](https://profiles.wordpress.org/wordmax/) 2019 年 12 月 11 日 1 則留言

Had a blog with 3000 posts w/ images that I wanted to delete. I installed and activated
this plugin and then used Bulk Delete plugin to delete all 3000 old articles. This
plugin did a great job and there were no old images left in the uploads folder. 
Sooo much faster than doing this manually or using two separate plugins to get rid
of posts and then media. It took less than 1 minute to delete 3000 posts and the
attached media with the combo Bulk Delete/Autoremove Attachments plugins together.
Well done dev!

 [ 閱讀全部 15 則使用者評論 ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈Autoremove Attachments〉的開發相關工作。

參與者

 *   [ Polygon Themes ](https://profiles.wordpress.org/polygonthemes/)
 *   [ Eusebiu Oprinoiu ](https://profiles.wordpress.org/eusebiuoprinoiu/)

〈Autoremove Attachments〉外掛目前已有 1 個本地化語言版本。 感謝[全部譯者](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments/contributors)
為這個外掛做出的貢獻。

[將〈Autoremove Attachments〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/autoremove-attachments/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/autoremove-attachments/)，或
透過 [RSS](https://plugins.trac.wordpress.org/log/autoremove-attachments/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/autoremove-attachments/)。

## 變更記錄

#### Version 1.3.1

 * Minor improvements to admin notices

#### Version 1.3.0

 * Minor code refactoring
 * Language files updated

#### Version 1.2.1

 * Fixed a bug that blocked changes to image sizes under Settings > Media

#### Version 1.2.0

 * Minor code refactoring
 * Extended support for WooCommerce and Easy Digital Downloads.
 * New safety checks when you empty your trash – We now try to determine if the 
   child attachments marked for removal are used anywhere else on your website. 
   If they are, we do not remove them, to prevent broken links.
 * New option under Settings > Media to disable the extra checks for improved performance
   on large websites with thousands of posts and media files. (where you might experience
   slow queries and timeouts when you empty your trash)

**Other important considerations**

 * With the new safety checks enabled it’s fairly safe to reuse attachments between
   posts. But please, keep in mind, they are not fool-proof, especially if you store
   media file IDs or URLs in custom fields. That’s why we recommend you avoid reusing
   your attachments between posts, if possible.
 * If you need to use an attachment over and over again, upload it from the global
   Media Library menu ( Media > Add New ). This way, it won’t be attached as a child
   to a specific post, page, or custom post type.

#### Version 1.1.2

 * New filter added to allow developers define custom rules for controlling when
   the child attachments should be removed automatically
 * Removed the old ‘autoremove_attachments_post_types’ filter in favor of the new
   one – instructions available in FAQ

#### Version 1.1.1

 * New filter added to allow developers to change for what post types the child 
   attachments should be removed automatically ( see FAQ for instructions )
 * Fixed a minor incompatibility with WP-Sweep

#### Version 1.1.0

 * Minor improvements for the admin notice

#### Version 1.0.9

 * Performance improvements on websites with a large number of posts and attachments

#### Version 1.0.8

 * Added extra security checks before the removal of attachments
 * Added an admin notice with a warning about the limitations of this plugin and
   the consequences of its improper usage. ( for new users only )

#### Version 1.0.7

 * Minor code refactoring
 * Added full support for WordPress Multisite

#### Version 1.0.6

 * Code refactored using wpcs

#### Version 1.0.5

 * Improved the warning displayed when very old PHP versions are used

#### Version 1.0.4

 * Remove all options on uninstall, even for multisite

#### Version 1.0.3

 * Added a security check to avoid deleting attachments when the ID of the parent
   post is invalid

#### Version 1.0.2

 * Fixed a bug that was causing media files to be removed when revisions were deleted
   with wp-cron

#### Version 1.0.1

 * Minimum required version of PHP set to 5.3

#### Version 1.0.0

 * First release

## 中繼資料

 *  版本 **1.3.1**
 *  最後更新 **2 個月前**
 *  啟用安裝數 **3,000+**
 *  WordPress 版本需求 ** 5.8 或更新版本 **
 *  已測試相容的 WordPress 版本 **6.9.4**
 *  PHP 版本需求 ** 7.4 或更新版本 **
 *  語言
 * [English (US)](https://wordpress.org/plugins/autoremove-attachments/) 及 [Spanish (Spain)](https://es.wordpress.org/plugins/autoremove-attachments/).
 *  [將這個外掛本地化為你的母語版本](https://translate.wordpress.org/projects/wp-plugins/autoremove-attachments)
 * 標籤:
 * [attachment](https://tw.wordpress.org/plugins/tags/attachment/)[custom post type](https://tw.wordpress.org/plugins/tags/custom-post-type/)
   [media](https://tw.wordpress.org/plugins/tags/media/)[page](https://tw.wordpress.org/plugins/tags/page/)
   [post](https://tw.wordpress.org/plugins/tags/post/)
 *  [進階檢視](https://tw.wordpress.org/plugins/autoremove-attachments/advanced/)

## 評分

 5 星，滿分為 5 星

 *  [  15 個 5 星使用者評論     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=2)
 *  [  0 個 1 星使用者評論     ](https://wordpress.org/support/plugin/autoremove-attachments/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/autoremove-attachments/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/autoremove-attachments/reviews/)

## 參與者

 *   [ Polygon Themes ](https://profiles.wordpress.org/polygonthemes/)
 *   [ Eusebiu Oprinoiu ](https://profiles.wordpress.org/eusebiuoprinoiu/)

## 技術支援

最近 2 個月解決的問題:

     總計 1 個問題，已解決 1 個

 [檢視技術支援論壇](https://wordpress.org/support/plugin/autoremove-attachments/)

## 贊助

想要支援這個外掛的發展嗎？

 [ 贊助這個外掛 ](https://paypal.me/EusebiuOprinoiu)