# bbPress: Reject Posts With Blocked Words

> Refuses forum topics and replies that contain words or phrases from your blocklist, showing the member a polite error instead of publishing them.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: bbpress, moderation, spam
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/bbpress-blocked-words/

## Code

```php
if ( ! function_exists( 'bbp_add_error' ) ) {
    return;
}

// Words or phrases to block.
$wpide_bbp_blocked = array( 'casino', 'cheap pills', 'crypto giveaway' );

$wpide_bbp_scan = function ( $text ) use ( $wpide_bbp_blocked ) {
    if ( current_user_can( 'moderate' ) ) {
        return $text;
    }

    $plain = wp_strip_all_tags( (string) $text );

    foreach ( $wpide_bbp_blocked as $word ) {
        if ( preg_match( '/\b' . preg_quote( $word, '/' ) . '\b/iu', $plain ) ) {
            bbp_add_error( 'wpide_bbp_blocked', '<strong>Error:</strong> Your post contains words that are not allowed in these forums.' );
            break;
        }
    }

    return $text;
};

add_filter( 'bbp_new_topic_pre_title', $wpide_bbp_scan );
add_filter( 'bbp_new_topic_pre_content', $wpide_bbp_scan );
add_filter( 'bbp_new_reply_pre_content', $wpide_bbp_scan );
```

## Notes

Matching ignores case and checks both the title and the content. Moderators are not checked.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "bbPress: Reject Posts With Blocked Words" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
