Created
February 14, 2021 12:55
-
-
Save sinebeef/37139160c79cf0013166b07cbb0b2dde to your computer and use it in GitHub Desktop.
Contact Form 7 spam block
This file contains hidden or 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 | |
// wpcf7_validate + _textarea* or _text* etc | |
add_filter( 'wpcf7_validate_textarea*', 'textarea_confirmation_validation_filter', 20, 2 ); | |
function textarea_confirmation_validation_filter( $result, $tag ) { | |
// your-message much match what the tag name has been set | |
if ( 'your-message' == $tag->name ) { | |
$your_message = isset( $_POST['your-message'] ) ? trim( $_POST['your-message'] ) : ''; | |
if ( preg_match('/href|google|lottery|seo|http|latex|gloves|youtube|instagram|monetize|invest|\$|\@|www\./i', $your_message ) ){ | |
$result->invalidate( $tag, "Your message contains invalid words that are not allowed, please rephrase. only put your email address in the email section, No website links or any of these words: href, google, seo, http, latex, gloves, youtube, instagram, monetize, invest, $" ); | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment