Created
April 5, 2018 15:49
-
-
Save ajskelton/402c3c0c1da5edbbf7e4022d982810c5 to your computer and use it in GitHub Desktop.
Gravity Forms email blacklist
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
add_filter( 'gform_field_validation', 'PREFIX_gravity_forms_blacklist', 10, 4 ); | |
/** | |
* Added Validation check for email vs blacklist of free email accounts. | |
* | |
* @param $result array The validation result to be filtered | |
* @param $value string|array The field value to be validated | |
* @param $form object Current Form object | |
* @param $field object Current Field object | |
* | |
* @return mixed | |
*/ | |
function PREFIX_gravity_forms_blacklist( $result, $value, $form, $field ) { | |
if ( $field->get_input_type() === 'email' && $result['is_valid'] ) { | |
$domain = explode( '@', $value ); | |
$blacklist = array( | |
'gmail.com', | |
'yahoo.com', | |
'hotmail.com' | |
); | |
if ( in_array( $domain[1], $blacklist ) ) { | |
$result['is_valid'] = false; | |
$result['message'] = 'Please use a work email.'; | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment