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)
- Runs on the plugin's own WP-Cron job 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 its own WP-Cron task, better_messages_cleaner_job, on a five-minute interval. On each run it queries the messages table for any message older than the configured threshold and deletes a batch of them, so a very large backlog is worked through over successive runs instead of timing out in one. The same job handles expired attachments, voice and video messages, and the per-room chat-room cleanup.
| Action | Outcome |
|---|---|
| Cron fires | Up to 100 messages older than N days are deleted per run — filter better_messages_delete_old_messages_batch_size to change it |
| User account is deleted | All of that user's messages are removed (if Delete Messages on Account Deletion is on) |
| Attachment is older than its retention | The file is deleted and its markup is stripped from the message. If nothing else was in that message, the message row is deleted too — there is no "attachment removed" placeholder |
| 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 Old Messages → Auto-Delete After — permanently delete messages older than this many days.
0keeps all messages. - Delete Messages on Account Deletion — wipe all of a user's messages when their WordPress account is removed
For attachments: WP Admin → Better Messages → Settings → Attachments.
- Auto-Delete Attachments — delete attachments after this many days.
0keeps them indefinitely.
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 from the messenger itself. Since 2.15.32 an administrator can export a full transcript as plain text, a web page or a CSV spreadsheet from the conversations screen in the admin area. For anything scripted, the REST API returns thread history — POST /thread/{id} for a thread with its recent messages, and POST /thread/{id}/loadMore to page back through the rest.
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?#
Age-based retention is site-wide, but chat rooms have their own per-room Automatic Message Cleanup — each room can be wiped on a daily or weekly schedule, or capped at the latest N messages, independently of the global setting. To raise or lower the per-run batch size, hook better_messages_delete_old_messages_batch_size (default 100, in inc/cleaner.php).
See also#
- Chat rooms → Automatic message cleanup — per-room scheduled wipes and message caps
- 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
- Export transcripts — keep a copy of a conversation before retention removes it