Auto-Delete Old Messages
Better Messages can automatically purge old messages and attachments to manage database size and comply with data-retention policies. Set a retention period in days; a daily WP-Cron job removes anything older. Attachments have their own retention setting (often shorter than text). Useful for sites with GDPR obligations, large message volumes, or simply a policy of "no message older than 90 days."
What it adds#
- Auto-delete messages older than N days (configurable)
- Separate, optional attachment retention — typically shorter than text retention
- Cleanup of messages from deleted user accounts (no orphaned data)
- Daily cron job — runs in the background, no manual triggers needed
- Useful for database size management on busy sites
- Useful for data-retention compliance (GDPR, sector-specific regulations)
How it works#
The plugin registers a daily WP-Cron task. On each run, it queries the messages table for any message older than the configured threshold, deletes them in batches (so very large purges don't time out), and removes any orphaned attachment files.
| Action | Outcome |
|---|---|
| Cron fires | Messages older than N days are deleted in batches of 100 per tick |
| User account is deleted | All of that user's messages are removed (if Delete messages on user delete is on) |
| Attachment is older than its retention | File is removed from storage; the message stub remains saying "Attachment removed" |
| Cron is disabled on the site | No auto-delete happens — wire up a real OS cron hitting wp-cron.php, or run wp cron event run --all from WP-CLI |
Deleted messages are permanently removed — no soft-delete, no admin trash. Plan retention windows accordingly.
When to enable auto-delete#
| Use case | Suggested setup |
|---|---|
| GDPR-strict community | 90-day text retention, 30-day attachment retention |
| Large active community | 6-12 month retention to keep DB size manageable |
| Customer support | 1-2 year retention for compliance + audit |
| Casual social DMs | Disabled (users expect history to persist) |
| Health / regulated industry | Per-regulation retention (HIPAA, etc.) — usually 6-7 years |
How to enable#
Navigate to WP Admin → Better Messages → Settings → Messaging.
- Auto-Delete Messages — Delete messages older than N days (0 = disabled)
- Delete messages on user delete — Wipe all of a user's messages when their WordPress account is removed
For attachments: WP Admin → Better Messages → Settings → Attachments.
- Attachment Retention — Delete attachments older than N days (0 = disabled)
Set retention windows thoughtfully — deletion is permanent. Communicate the retention policy to users so they don't expect indefinite history.
Frequently asked questions#
Can users export their messages before they're deleted?#
Not in the default UI. The REST API endpoint GET /threads/{id}/messages returns full thread history — users (or admins) can build a custom export with a script.
Are pinned or favorited messages exempt from auto-delete?#
No — auto-delete is unconditional. A pinned message older than the retention window is deleted, and the pin is removed.
Does auto-delete trigger notifications to users?#
No — deletion is silent. Users don't get a notification that old messages have been purged. The thread just shows newer messages going forward.
What happens to a thread where all messages are deleted?#
The thread record itself is kept (so it can show up in the inbox empty, or be deleted manually).
Can different chat rooms have different retention?#
Not in the default UI — retention is site-wide. To raise or lower the per-tick batch size, hook better_messages_delete_old_messages_batch_size (default 100).
See also#
- Privacy & GDPR — broader data-protection guide
- User-to-user block — different privacy mechanism
- End-to-end encryption — content-level privacy (WebSocket version)
- Pre-moderation — control content quality