Bad Words / Profanity Filter
Better Messages includes a server-side bad-words filter that rejects messages containing any term on a configurable banned list. The block happens before the message is delivered — recipients never see it, and the sender gets a clear error message you can customize. Useful for family-friendly communities, paid memberships, support channels, and any site where moderation reduces friction.
What it adds#
- Admin-managed banned-word list (one term per line)
- Case-insensitive matching across the entire message text, in any script, Cyrillic and Greek included
- Checks the names of conversations and edited messages too (3.3.0)
- Configurable error message shown to the sender on blocked attempts
- Optional bypass for administrator accounts (other roles through a hook, see below)
- Works pre-send — blocked messages never reach the recipient or the database
How it works#
When a user submits a message, the filter looks for each entry of the banned-word list in the message text, as a whole word or phrase. If any term matches, the send is rejected and the configured error message is returned. The blocked message is not stored anywhere — there's no trail, no recipient notification, no database record.
Each line is matched as written: a sign such as + or . in a line is a sign, so c++ blocks "c++" and nothing else, and an empty line in the list blocks nothing. Letters are compared without their case, and invisible characters put between letters to get past the filter, such as a zero-width space, are ignored.
| Match scenario | Outcome |
|---|---|
| Message contains an exact banned word as a standalone token | Blocked, error shown |
| Banned word appears inside a larger word (e.g. "ass" inside "class") | Allowed — matching is word-boundary, not substring |
| Word in a different case | Blocked (case-insensitive) |
| Word in Cyrillic, Greek or another script with spaces between words | Blocked when it stands as a word |
| Word in Chinese, Japanese or Thai, written without spaces | Blocked wherever it appears in the text |
| Banned word inside an attached file's name | Allowed (only message text is scanned) |
Sender has manage_options and Skip Administrators is on | Allowed |
| Banned word in the name of a new conversation, or a group renamed to one (3.3.0) | Blocked, error shown |
| Sender edits an existing message to add a banned word (3.3.0) | Blocked, the message keeps its earlier text |
| Message in an end-to-end encrypted conversation | Allowed — the server cannot read it |
If you need substring matching for a specific term, type it with a leading or trailing fragment (e.g. viagra already matches Viagra, viagra! etc., but cialis will not match cialispharma). Multi-word phrases (e.g. click here) also work — the word-boundary regex treats the whole phrase as the token.
When to use#
| Site type | Recommended setup |
|---|---|
| Family / kid-friendly community | Aggressive list, no admin bypass, friendly error message |
| General community / forum | Standard profanity list + competitor brand names |
| Marketplace | Block contact-info attempts: "WhatsApp", "Telegram", external emails, phone formats |
| LMS | Block academic dishonesty terms ("answer key", paid-essay services) |
| Support / commercial | Block spam keywords + common phishing terms |
How to enable#
Navigate to WP Admin → Better Messages → Settings → Moderation → Content → Bad Words Filter (Settings → Restrictions before 3.3.0).
- Bad Words List — Enter banned words or phrases, one per line (case doesn't matter)
- Skip Administrators — Let accounts with the
manage_optionscapability bypass the filter. Everyone else goes through it, trusted accounts included - Filter Message — Custom message shown to the sender when their message is rejected
Frequently asked questions#
Can I bypass the filter for moderators, not just admins?#
The built-in Skip Administrators toggle covers only accounts with the manage_options capability. For a broader bypass (a custom Moderator role, say), hook the same two actions the filter itself uses at a later priority and clear its error — the $errors array is passed by reference:
add_action( 'better_messages_before_message_send', function ( &$args, &$errors ) {
if ( current_user_can( 'moderate_comments' ) ) {
unset( $errors['restrictBadWord'] );
}
}, 20, 2 );
add_action( 'better_messages_before_new_thread', function ( &$args, &$errors ) {
if ( current_user_can( 'moderate_comments' ) ) {
unset( $errors['restrictBadWord'] );
}
}, 20, 2 );
better_messages_can_send_message will not do it — that filter decides whether the user may post in the thread at all, and runs separately from the bad-words check.
Does the filter run on edited messages?#
Yes, since 3.3.0. An edit with a word from the list is refused with the same error, and the message keeps the text it had. The same goes for renaming a group conversation. Before 3.3.0 the filter ran only when a message was sent, so an edit could add a banned word.
The filter uses better_messages_before_message_edit and better_messages_before_subject_change for this, so a bypass for moderators, as in the answer above, unsets restrictBadWord on those two actions too.
Are message attachments scanned?#
No — only the message text is scanned. Attached file names and contents are not. For images that may contain text, an image moderation service (or AI content moderation on the WebSocket version) is more appropriate.
What happens to a user who keeps trying to send banned words?#
Nothing automatic — each attempt is just rejected with the same error. For tiered escalation (e.g. temp-ban after N attempts), pair this with pre-moderation so a moderator sees the pattern.
How big can the banned-word list be?#
Since 3.3.0 the list is checked in groups of 200 lines at a time, so a list of a few thousand lines still adds little to each send. Before 3.3.0 every line was a test of its own, and more than a few hundred lines slowed sending down.
See also#
- Spam Protection — catches what looks like spam by what an account does, not by the words
- Pre-moderation — admin reviews messages before delivery (stronger than word-based blocking)
- AI content moderation — AI-driven moderation for nuanced content (WebSocket version)
- User-to-user block — let users block each other
- Role-based access — gate messaging entirely by user role