Created
December 4, 2018 13:32
-
-
Save mrsize/b1f8b33dc3b6ea4d8eabc1378c0c52ba to your computer and use it in GitHub Desktop.
WPCF7 Check spam before Sending email
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 | |
// Untested : Detect spam before sending, in CF7 Plugin | |
// source : https://newburynew.media/contact-form-7-before-send-mail-example/ | |
function wpcf7_register_user($wpcf7){ | |
$formid = 1; | |
$submission = WPCF7_Submission::get_instance(); | |
if ( $submission ) { | |
$posted_data = $submission->get_posted_data(); | |
} | |
if($wpcf7->id() == $formid) { | |
$message = sanitize_textarea_field($posted_data['your-message']); | |
if( !empty($message) ) { | |
// ok : sned email ? | |
} else { | |
// Include a spam detector here ? | |
$error = true; | |
$err_msg = 'Message error'; | |
} | |
} // if wpcf7 id | |
if(isset($error) && $error === true) { | |
$msgs = $wpcf7->prop('messages'); | |
$msgs['mail_sent_ok'] = $err_msg; | |
$wpcf7->set_properties(array('messages' => $msgs)); | |
add_filter('wpcf7_skip_mail', 'abort_mail_sending'); | |
} | |
return $wpcf7; | |
} | |
add_action('wpcf7_before_send_mail','wpcf7_register_user'); | |
function abort_mail_sending($contact_form){ | |
return true; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment