我想从联系表7中阻止一般的电子邮件ID帐户。我在function.php文件中添加了以下代码,但它不起作用。
我正在使用wordpress 4.6.1,请联系表格7版本4.6和21个主题。请帮助我解决此问题。
function blocked_email_domain($email) {
$blocked = array("@gmail.com", "@hotmail.com", "@yahoo.com", "@yahoo.in","@msn.com", "@live.com", "@outlook.com", "@microsoft.com", "@zoho.com", "@rediff.com");
$email = strstr($email, '@');
if(in_array($email, $blocked))
return false;
else
return true;
}
function custom_email_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
if($name == 'your-email') { // Only apply to fields with the form field name of "your-email"
$the_value = $_POST[$name];
if(!blocked_email_domain($the_value)){
$result['valid'] = false;
$result->invalidate( $tag, 'You need to provide an email address that isn\'t hosted by a free provider.<br />Please contact us directly if this isn\'t possible.');
};
};
return $result;
}
add_filter('wpcf7_validate_email','custom_email_validation_filter', 10, 2); // Email field
add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2); // Required Email field
这里是易于使用的插件,可轻松用于多个字段和表单。
联系表7 –不需要的黑名单电子邮件->https://wordpress.org/plugins/block-email-cf7/