Este plugin no ha sido probado con ninguna las 3 últimas versiones principales de WordPress. Puede que ya no se mantenga o no tenga soporte, y puede que tenga problemas de compatibilidad cuando se utiliza con versiones más recientes de WordPress.

Autoremove Attachments

Descripción

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

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.

Instalación

Instalación automática

La instalación automática es la opción más sencilla para instalar un plugin, ya que WordPress se encarga de las transferencias de archivos por sí mismo. Para realizar una instalación automática, inicia una sesión en tu escritorio de WordPress y sigue los pasos siguientes:

  1. Ve al menú de plugins y haz clic en “Agregar nuevo”.
  2. En el campo de búsqueda escribe “Autoremove Attachments” y haz clic en “Buscar plugins”
  3. Una vez que hayas encontrado el plugin, instálalo haciendo clic en “Instalar ahora”.
  4. Activa “Autoremove Attachments” desde el menú “Plugins”

Instalación manual

El método de instalación manual consiste en descargar el plugin y subirlo a tu servidor mediante SFTP. Para hacer una instalación manual sigue los pasos siguientes:

  1. Descarga el plugin en tu computador local
  2. Si se ha descargado como archivo zip, extráelo a tu escritorio
  3. Sube la carpeta del plugin al directorio “/wp-content/plugins/”
  4. Activa “Autoremove Attachments” desde el menú “Plugins”

FAQ

¿Funciona con tipos de contenido personalizado?

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

¿Cuándo se eliminan los adjuntos?

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.

El vaciado se produce cuando se vacía la papelera.

¿Puedo controlar qué adjuntos se eliminan?

Sí, es posible. Por defecto, todos los archivos multimedia adjuntos a una entrada, página o tipo de contenido personalizado se eliminan automáticamente. Si necesitas un control granular, puedes usar el filtro autoremove_attachments_allowed para definir reglas personalizadas para controlar cuándo se deben eliminar los adjuntos hijos automáticamente.

Aquí hay un ejemplo de cómo puedes eliminar los adjuntos sólo para tipos de contenido personalizado específicos:

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' );

El valor devuelto debe ser verdadero para los casos en los que se desea eliminar los adjuntos. (falso en caso contrario)

¿Hay alguna restricción en el uso de mis adjuntos?

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.

Reseñas

26 de Septiembre de 2021
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.
14 de Mayo de 2021
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.
7 de Abril de 2020 1 respuesta
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!
9 de Marzo de 2020 1 respuesta
This plugin worked when the image is featured image to the post, but can’t delete which is uploaded in the middle of post.
11 de Diciembre de 2019 1 respuesta
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!
Leer los 15 comentarios

Colaboradores & Desarrolladores

“Autoremove Attachments” es software de código abierto. Las siguientes personas han contribuido a este plugin.

Colaboradores

“Autoremove Attachments” ha sido traducido en 1 idioma. Gracias a los traductores por sus contribuciones.

Traduce “Autoremove Attachments” a tu idioma.

¿Interesado en el desarrollo?

Revisa el código, echa un vistazo al repositorio SVN, o suscríbete al registro de desarrollo por RSS .

Historial de cambios

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