This commit is contained in:
Denis Bunevich
2025-11-26 10:24:11 +01:00
parent 15f6f8ce0d
commit 3697f851f5
2 changed files with 40 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -397,3 +397,41 @@ function old_post_url_redirect(){
} }
} }
add_action( "template_redirect", "old_post_url_redirect" ); add_action( "template_redirect", "old_post_url_redirect" );
/**
* Add custom validation for CF7 form fields
*/
function is_business_email($email){
if(
preg_match('/@gmail.com/i', $email) ||
preg_match('/@hotmail.com/i', $email) ||
preg_match('/@outlook.com/i', $email) ||
preg_match('/@yahoo.com/i', $email) ||
preg_match('/@protonmail.com/i', $email) ||
preg_match('/@icloud.com/i', $email) ||
preg_match('/@me.com/i', $email) ||
preg_match('/@aol.com/i', $email) ||
preg_match('/@mail.com/i', $email) ||
preg_match('/@tutanota.com/i', $email) ||
preg_match('/@tuta.com/i', $email) ||
preg_match('/@live.com/i', $email) ||
preg_match('/@msn.com/i', $email) ||
preg_match('/@inbox.com/i', $email)
){
return false; // It's a publicly available email address
}else{
return true; // It's probably a company email address
}
}
function custom_email_company_validation_filter( $result, $tag ) {
if ( 'company-email' == $tag->name ) {
$the_value = isset( $_POST['company-email'] ) ? trim( $_POST['company-email'] ) : '';
if (!is_business_email($the_value)) {
$result->invalidate($tag, "This form only accepts business emails. Please provide your work address.");
}
}
return $result;
}
add_filter( 'wpcf7_validate_email*', 'custom_email_company_validation_filter', 20, 2 );