Skip to content

Instantly share code, notes, and snippets.

@sinebeef
Created February 14, 2021 12:55
Show Gist options
  • Save sinebeef/37139160c79cf0013166b07cbb0b2dde to your computer and use it in GitHub Desktop.
Save sinebeef/37139160c79cf0013166b07cbb0b2dde to your computer and use it in GitHub Desktop.
Contact Form 7 spam block
<?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