# Send Comments in Foreign Scripts to Spam

> Sends comments written mostly in Cyrillic, Chinese, Arabic or another script your readers do not use to the spam queue, where most of them belong.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: comments, spam, language
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/comment-foreign-script-spam/

## Code

```php
$wpide_comment_scripts = array( 'Cyrillic', 'Han', 'Arabic', 'Hangul', 'Thai' );
$wpide_comment_share   = 0.3; // Share of letters that marks a comment as spam.

add_filter( 'pre_comment_approved', function ( $approved, $commentdata ) use ( $wpide_comment_scripts, $wpide_comment_share ) {
    if ( 'spam' === $approved || empty( $commentdata['comment_content'] ) ) {
        return $approved;
    }

    $text    = $commentdata['comment_content'] . ' ' . ( isset( $commentdata['comment_author'] ) ? $commentdata['comment_author'] : '' );
    $letters = preg_match_all( '/\p{L}/u', $text );

    if ( $letters < 10 ) {
        return $approved;
    }

    $foreign = 0;
    foreach ( $wpide_comment_scripts as $script ) {
        $foreign += (int) preg_match_all( '/\p{' . $script . '}/u', $text );
    }

    return $foreign / $letters >= $wpide_comment_share ? 'spam' : $approved;
}, 20, 2 );
```

## Notes

Remove scripts from the list if your community writes in them.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Comments in Foreign Scripts to Spam" 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/
