Untitled

mail@pastecode.io avatar
unknown
php
6 months ago
1.1 kB
2
Indexable
Never
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 == 'BusinessEmail') { // Only apply to fields with the form field name of "your-email"
    $the_value = $_POST[$name];
        if(!blocked_email_domain($the_value)){
            $result->invalidate( $tag, __('You need to provide an email address that isn\'t hosted by a free provider. Please contact us directly if this isn\'t possible.', 'adaptive'));   
        };
    };
    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