Custom Blacklist Contact Form 7

Colby Fayock
Colbyashi Maru
Published in
1 min readMar 11, 2016

Easily set up a blacklist for those marketing lists that somehow get around Akismet. Throw the below in your functions.php file and customize the $blacklist array to filter by email address to your liking.

function contactFilterBlacklist( $result, $tag ) {    $valid = true;
$tag = new WPCF7_Shortcode( $tag );
$blacklist = array(
‘filterme’
);
$yourEmail = isset( $_POST[‘your-email’] ) ? trim( $_POST[‘your-email’] ) : false;
if ( !$yourEmail ) return $result;
foreach ( $blacklist as $keyword ) {
if ( strpos($yourEmail, $keyword) !== false ) {
$valid = false;
}
}
if ( !$valid ) {
$result->invalidate( $tag, “Uh oh. Something’s wrong here…”);
}
return $result;}add_filter( ‘wpcf7_validate_email*’, ‘contactFilterBlacklist’, 20, 2 );

Head over to this Contact Form 7 post or their documentation to learn more.

--

--