Created
April 16, 2021 05:46
-
-
Save genesis16/14f7de2671e346de4c1553a12f81c8ef to your computer and use it in GitHub Desktop.
email whitelist
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
/* | |
* Whitelist email domains from your WPForms. | |
* | |
* @link https://wpforms.com/developers/how-to-restrict-email-domains/ | |
* | |
*/ | |
function wpf_whitelist_domains( $field_id, $field_submit, $form_data ) { | |
$domain = substr( strrchr( $field_submit, "@" ), 1 ); | |
$whitelist = array( 'icloud.com', 'me.com' ); | |
if( ! in_array( $domain, $whitelist ) ) { | |
wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( 'Email domain not accepted!', 'wpforms' ); | |
return; | |
} | |
} | |
add_action('wpforms_process_validate_email', 'wpf_whitelist_domains', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment