Last active
July 22, 2022 09:41
-
-
Save tobiasroeder/917283f7cf900c9fcf64a1dde44b5c5f to your computer and use it in GitHub Desktop.
WordPress Contact Form 7 Spam Filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Contact Form 7 Spam Filter | |
*/ | |
add_filter( 'wpcf7_spam', function( $spam ) { | |
if ( $spam ) | |
return $spam; | |
$spam_key_words = [ | |
'demo' | |
]; | |
$found_spam_key_word = function ( $string, $spam_key_words ) { | |
foreach ( $spam_key_words as $spam_key_word ) | |
if ( stripos( $string, $spam_key_word ) !== false ) | |
return true; | |
return false; | |
}; | |
return ( | |
$found_spam_key_word( $_POST['subject'], $spam_key_words ) | |
|| | |
$found_spam_key_word( $_POST['message'], $spam_key_words ) | |
); | |
}, 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment