Skip to content

Instantly share code, notes, and snippets.

@genesis16
Created April 16, 2021 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genesis16/14f7de2671e346de4c1553a12f81c8ef to your computer and use it in GitHub Desktop.
Save genesis16/14f7de2671e346de4c1553a12f81c8ef to your computer and use it in GitHub Desktop.
email whitelist
/*
* 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