Skip to content

Instantly share code, notes, and snippets.

@tobiasroeder
Last active July 22, 2022 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasroeder/917283f7cf900c9fcf64a1dde44b5c5f to your computer and use it in GitHub Desktop.
Save tobiasroeder/917283f7cf900c9fcf64a1dde44b5c5f to your computer and use it in GitHub Desktop.
WordPress Contact Form 7 Spam Filter
<?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