# Treat Gravity Forms Entries in Foreign Scripts as Spam

> Marks a Gravity Forms entry as spam when most of its text is written in Cyrillic, Chinese or another script you never receive genuine enquiries in.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, spam, language
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-non-latin-spam/

## Code

```php
$wpide_gf_blocked_scripts = array( 'Cyrillic', 'Han', 'Arabic', 'Hangul', 'Thai' );
$wpide_gf_script_share    = 0.3; // Share of letters that marks the entry as spam.

add_filter( 'gform_entry_is_spam', function ( $is_spam, $form, $entry ) use ( $wpide_gf_blocked_scripts, $wpide_gf_script_share ) {
    if ( $is_spam ) {
        return $is_spam;
    }

    $text = '';
    foreach ( $form['fields'] as $field ) {
        if ( in_array( $field->type, array( 'text', 'textarea', 'name' ), true ) ) {
            $text .= ' ' . (string) $field->get_value_export( $entry );
        }
    }

    $letters = preg_match_all( '/\p{L}/u', $text );
    if ( $letters < 10 ) {
        return false;
    }

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

    return $foreign / $letters >= $wpide_gf_script_share;
}, 10, 3 );
```

## Notes

Remove scripts from the list that your customers actually write in.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Treat Gravity Forms Entries in Foreign Scripts as 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/
