• Resolved sweeperr

    (@sweeperr)


    We’re getting false positives on spam due to the g-recaptcha-response field being checked against the disallowed word list in WordPress’s discussion settings.
    How can I exclude this field from CF7’s spam detection?

    It looks like the spam detection happens in contact-form-7/modules/disallowed-list.php with add_filter( ‘wpcf7_spam’, ‘wpcf7_disallowed_list’, 10, 2 ) and
    $word = apply_filters(
    ‘wpcf7_submission_has_disallowed_words’,
    $word,
    $submission
    );

Viewing 1 replies (of 1 total)
  • Thread Starter sweeperr

    (@sweeperr)

    I’ve got a solution. I added this code to a custom plugin:

    
    function remove_cf7_spam_filter(){
        remove_filter('wpcf7_spam', 'wpcf7_disallowed_list', 10);
    }
    add_action( 'after_setup_theme', 'remove_cf7_spam_filter' );
    
    add_filter( 'wpcf7_spam', 'wpcf7_disallowed_list2', 10, 2 );
    
    function wpcf7_disallowed_list2( $spam, $submission ) {
    	if ( $spam ) {
    		return $spam;
    	}
    
    	$target = $submission->get_posted_data();
    
    	// Don't spam check these fields:
    	if(array_key_exists('g-recaptcha-response', $target)) unset ($target['g-recaptcha-response']);
    		
    	$target = wpcf7_array_flatten( $target );
    	$target[] = $submission->get_meta( 'remote_ip' );
    	$target[] = $submission->get_meta( 'user_agent' );
    	$target = implode( "\n", $target );
    
    	$word = wpcf7_check_disallowed_list( $target );
    
    	$word = wpcf7_apply_filters_deprecated(
    		'wpcf7_submission_is_blacklisted',
    		array( $word, $submission ),
    		'5.3',
    		'wpcf7_submission_has_disallowed_words'
    	);
    
    	$word = apply_filters(
    		'wpcf7_submission_has_disallowed_words',
    		$word,
    		$submission
    	);
    
    	if ( $word ) {
    		if ( is_bool( $word ) ) {
    			$reason = __( "Disallowed words are used.", 'contact-form-7' );
    		} else {
    			$reason = sprintf(
    				__( "Disallowed words (%s) are used.", 'contact-form-7' ),
    				implode( ', ', (array) $word )
    			);
    		}
    
    		$submission->add_spam_log( array(
    			'agent' => 'disallowed_list',
    			'reason' => $reason,
    		) );
    	}
    
    	$spam = (bool) $word;
    
    	return $spam;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Exclude g-recaptcha-response field from spam filter?’ is closed to new replies.