{"id":6688,"date":"2026-09-24T12:18:26","date_gmt":"2026-09-24T10:18:26","guid":{"rendered":"https:\/\/wpmastertoolkit.com\/module\/poubelle-mediatique\/"},"modified":"2026-09-28T16:25:48","modified_gmt":"2026-09-28T14:25:48","slug":"poubelle-mediatique","status":"publish","type":"module","link":"https:\/\/wpmastertoolkit.com\/en\/module\/media-trash\/","title":{"rendered":"Media Trash"},"content":{"rendered":"<h1 class=\"wp-block-heading\">Media Trash: Add a Trash Can for Your WordPress Media<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Accidentally deleting an image in WordPress can quickly become a problem. Unlike posts or pages, files in the media library can be permanently deleted, resulting in the loss of the associated file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The module <strong>Media Trash by WPMasterToolKit<\/strong> allows you to add a true trash can to the WordPress media library. When a media file is deleted, it can be temporarily stored in the trash can before being permanently deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This means you have a certain amount of time to recover an image, a PDF, or another file that was accidentally deleted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"378\" src=\"https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-1024x378.webp\" alt=\"Multimedia Trash Retention Settings\" class=\"wp-image-6699\" srcset=\"https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-1024x378.webp 1024w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-300x111.webp 300w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-768x283.webp 768w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-1536x566.webp 1536w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash-18x7.webp 18w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2026\/09\/Media-Trash.webp 1812w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why add a trash can to the WordPress media library?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress natively includes a trash mechanism for content such as posts and pages. A similar feature also exists for media, but it is not enabled by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without this protection, permanently deleting an item from the media library may also result in the corresponding file being deleted from the server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Media Trash<\/strong> enables and uses the built-in mechanism provided by WordPress to offer a grace period before media files are permanently deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In particular, this makes it possible to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>recover a file that was accidentally deleted; ;<\/li>\n\n\n\n<li>have a grace period before irreversible deletion; ;<\/li>\n\n\n\n<li>choose how long deleted media should be retained; ;<\/li>\n\n\n\n<li>automatically delete old media from the trash; ;<\/li>\n\n\n\n<li>Avoid keeping unused files on the server indefinitely.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How does Media Trash work?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When the module is activated, WPMasterToolKit enables the native media trash feature by adding the constant <code data-no-auto-translation=\"\">MEDIA_TRASH<\/code> in the file <code data-no-auto-translation=\"\">wp-config.php<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once this feature is enabled, deleted media items will be moved to the Recycle Bin instead of being permanently deleted immediately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The module then adds its own retention policy to precisely control when these media files should be permanently deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This allows you to take advantage of WordPress\u2019s native features while also benefiting from additional management capabilities that are directly integrated into WPMasterToolKit.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Choose how long to retain deleted media<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the module settings, the option <strong>Media Retention<\/strong> allows you to choose how many days a file should remain in the Recycle Bin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, this duration is set to <strong>90 days<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be configured between <strong>1 and 365 days<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, with a 30-day retention period, a media file placed in the trash can remain there for 30 days. Once this period has elapsed, it becomes eligible for automatic permanent deletion.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This retention period applies specifically to media managed by the module. In particular, it allows files to be retained longer than they would otherwise be under WordPress's default trash cleanup settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A retention period independent of the global trash can<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress uses the constant <code data-no-auto-translation=\"\">EMPTY_TRASH_DAYS<\/code> to determine the general retention period for items placed in the trash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Media Trash takes this behavior into account while applying its own retention period to attachments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During the automatic WordPress cleanup, WPMasterToolKit checks how long each media file has been in the trash. If the retention period configured in Media Trash has not yet been reached, its permanent deletion is blocked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, this prevents media set to be retained for 90 days from being deleted prematurely by WordPress's general cleanup mechanism.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, for it to work properly, the WordPress global trash must be enabled: <code data-no-auto-translation=\"\">EMPTY_TRASH_DAYS<\/code> must therefore be greater than zero.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Restore a media file before it is permanently deleted<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The main benefit of a trash can is, of course, that it lets you change your mind.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As long as a media file is still in the trash, it can be restored via WordPress. When a file is removed from the trash, WPMasterToolKit also deletes the metadata that WordPress uses to track its presence in the trash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The media is thus restored to its normal state and is no longer marked for deletion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Automatic Cleanup of Old Media<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You don't need to come back regularly to manually empty the trash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Media Trash schedules a daily automatic cleanup. During this cleanup, the module searches for media items that have been in the trash for longer than the configured retention period.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These media files are then permanently deleted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To limit the amount of work done at any one time, the cleaning process handles a maximum of <strong>100 media items per run<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This approach is particularly useful for sites with a large media library: cleanup is performed gradually rather than attempting to delete a very large number of files in a single operation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What happens if a media file fails to be deleted?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In rare cases, permanent deletion may fail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this case, WPMasterToolKit does not attempt to delete the same media file every time the cleanup is run. The module temporarily records the failure and waits <strong>a week<\/strong> before allowing another attempt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This mechanism prevents the daily repetition of an operation that has just failed, while allowing the cleanup process to continue processing the other eligible media.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How do I use the Media Trash module?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In WPMasterToolKit, simply enable the module <strong>Media Trash<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When it is activated, the module attempts to automatically add <code data-no-auto-translation=\"\">MEDIA_TRASH<\/code> to your file <code data-no-auto-translation=\"\">wp-config.php<\/code>. This file must therefore be writable to allow for this automatic configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can then open the module's settings and set the desired retention period, between 1 and 365 days.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From that point on, the process is automated: deleted media files are moved to the Recycle Bin, can be restored during their retention period, and are permanently deleted once that period has expired.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If <code data-no-auto-translation=\"\">MEDIA_TRASH<\/code> cannot be enabled, or if <code data-no-auto-translation=\"\">EMPTY_TRASH_DAYS<\/code> If it is disabled, WPMasterToolKit displays a notification in the plugin settings to alert you to the issue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why rely on WordPress's built-in functionality?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For this module, we decided not to create a completely independent trash can system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress already has the necessary mechanisms to move attachments to the trash and restore them. WPMasterToolKit therefore enables this native feature via <code data-no-auto-translation=\"\">MEDIA_TRASH<\/code>, and then focuses primarily on conservation policies and automatic cleaning.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This approach allows us to stay as close as possible to how WordPress works and avoid unnecessarily duplicating mechanisms already present in the CMS.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, the module enhances this functionality with several safeguards: a retention period for media files, daily cleanup in batches of 100 items, and a delay before a retry when a deletion fails.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, when the module is disabled, WPMasterToolKit deletes the cleanup tasks it had scheduled, as well as the constant <code data-no-auto-translation=\"\">MEDIA_TRASH<\/code> which he had added.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The module <strong>Media Trash by WPMasterToolKit<\/strong> adds a particularly useful security feature to the WordPress media library.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of risking the immediate and permanent deletion of a file, media files can be temporarily moved to the Recycle Bin and restored in case of an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With a <strong>Configurable retention period ranging from 1 to 365 days<\/strong>, with daily automatic cleanup and integration based on WordPress's native features, Media Trash offers a simple way to securely delete files from your media library without adding an additional plugin dedicated solely to this feature.<\/p>","protected":false},"excerpt":{"rendered":"<p>This article introduces the \u00abMedia Trash\u00bb module of the WPMasterToolKit plugin, a solution for managing deleted media files in WordPress. This module makes it easy to restore accidentally deleted media, thanks to a time-based media retention management system. It also offers a lighter alternative to third-party plugins by integrating its features directly into the WordPress dashboard. Designed with standard hooks and a scheduled events system, Media Trash provides optimized and intuitive management of deleted files.<\/p>","protected":false},"featured_media":0,"parent":0,"template":"","meta":{"_acf_changed":false,"_seopress_titles_title":"Media Trash : s\u00e9curisez vos m\u00e9dias WordPress","_seopress_titles_desc":"Media Trash ajoute une corbeille \u00e0 votre m\u00e9diath\u00e8que WordPress pour restaurer les fichiers supprim\u00e9s et automatiser leur suppression.","_seopress_robots_index":"","_seopress_robots_follow":"","_seopress_robots_imageindex":"","_seopress_robots_snippet":"","_seopress_robots_primary_cat":"","_seopress_robots_breadcrumbs":"","_seopress_robots_freeze_modified_date":"","_seopress_robots_custom_modified_date":"","_seopress_robots_canonical":"","_seopress_social_fb_title":"","_seopress_social_fb_desc":"","_seopress_social_fb_img":"","_seopress_social_fb_img_attachment_id":0,"_seopress_social_fb_img_width":0,"_seopress_social_fb_img_height":0,"_seopress_social_twitter_title":"","_seopress_social_twitter_desc":"","_seopress_social_twitter_img":"","_seopress_social_twitter_img_attachment_id":0,"_seopress_social_twitter_img_width":0,"_seopress_social_twitter_img_height":0,"_seopress_redirections_value":"","_seopress_redirections_enabled":"","_seopress_redirections_enabled_regex":"","_seopress_redirections_logged_status":"","_seopress_redirections_param":"","_seopress_redirections_type":0,"_seopress_analysis_target_kw":"","_seopress_news_disabled":"","_seopress_video_disabled":"","_seopress_video":[],"_seopress_pro_schemas_manual":[],"_seopress_pro_rich_snippets_disable_all":"","_seopress_pro_rich_snippets_disable":[],"_seopress_pro_schemas":[],"_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true},"class_list":["post-6688","module","type-module","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module\/6688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module"}],"about":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/types\/module"}],"wp:attachment":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/media?parent=6688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}