• Hi guys,

    I’m using WPForms (lite) on my page and wrote a costum code in my functions.php for a blacklist because of spam:

    function wpf_dev_profanity_filter_paragraph( $field_id, $field_submit, $form_data ) {
     
             $blocked_words = array( 
             	'bad word 1',
                    'bad word 2'
        );
     
        foreach( $blocked_words as $word ) {
            if(preg_match( '/\b' .$word. '\b/i', $field_submit )) {
                wpforms()->process->errors[ $form_data[ 'id' ] ][ $field_id ] = esc_html__( '', 'plugin-domain' );
                return;
            }
        }
     
    }
     
    add_action( 'wpforms_process_validate_textarea', 'wpf_dev_profanity_filter_paragraph', 10, 3 );
    

    It works fine, but only with latin letters and we’re getting plenty of spam from Russia, so I tried putting words with cyrillic letters in it and tested it, but it doen’t block these word.

    I read that it may have to do with character encoding, but the file is encoded in UTF-8, just as my WordPress-Page and I’ve read that this should work for cyrillic letters.

    Does anyone know what could be the problem and how I can solve it?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Regexp in preg_match() by default only works on single byte UTF-8 encodings. Cyrillic chars are all multi-byte encoding. I believe you can simply add the u modifier (the lower case one near the bottom of the linked page) to your regexp to get it to work with multi-byte.
    '/\b' .$word. '\b/iu'
    (untested)

Viewing 1 replies (of 1 total)
  • The topic ‘Using cyrillic words in my code for a blacklist’ is closed to new replies.