Do you want to stop WordPress from emptying trash items?
By default, WordPress automatically deletes trash items after 30 days. You can either disable or change this interval as per your needs.
Why Stop WordPress from Emptying Trash?
There are many scenarios where you want to stop WordPress from automatically emptying the trash. Here are some common scenarios:
1. Accidental Deletion Recovery
- Avoid Permanent Loss: This is beneficial, especially if you have a multi-author website. You can always recover accidentally deleted posts, pages, or media items without the risk of them being permanently deleted after a set period
- Extended Recovery Period: Extending the trash retention period gives you more time to realize a mistake and restore deleted items.
2. Content Management
- Review Deleted Content: Keeping deleted items in the trash allows you to periodically review and decide if they should be permanently deleted or restored.
- Audit Trail: Maintaining items in the trash can serve as a record of what has been deleted, which can be useful for content management and auditing purposes.
3. Data Retention Policies
- Compliance: Preventing automatic trash emptying helps comply with data retention policies, as some companies have data retention policies, that require keeping data, even deleted data, up to a certain period.
- Regulatory Requirements: Some industries have regulatory requirements to retain records, even those marked for deletion, for a specific time.
5. Performance Considerations
- Resource Management: In some cases, it might be beneficial to control when trash is emptied to manage server resources more efficiently, rather than having WordPress perform this task automatically, potentially during peak usage times.
6. Custom Workflow Needs
- Customized Content Workflows: Custom content workflows sometimes need to keep deleted items for longer periods to fit into specific review and approval processes.
- User Training: In environments where multiple users manage content, extending the trash retention period can reduce the risk of losing important data due to user errors while they are still learning the system.
Stopping WordPress from automatically emptying the trash or extending the trash retention period can provide greater control over content management, improve data recovery options, and help meet compliance or performance requirements. It’s a valuable customization for many site administrators who need to manage their content more carefully.
How to Limit Automatic Empty Trash in WordPress?
Add the following line of code to the wp-config.php file to set a different interval (in days) for trash deletion. For example, to set it to 60 days:
// Change interval to limit Automatic Empty Trash in WordPress
define('EMPTY_TRASH_DAYS', 60);
How to Stop WordPress from Emptying Trash?
Add the following line of code to the wp-config.php to disable the trash auto-emptying feature entirely:
// Change interval to 0 to disable Automatic Empty Trash in WordPress
define('EMPTY_TRASH_DAYS', 0);