| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 4 |
|
| 5 |
function wppb_toolbox_check_email_domain( $message, $field, $request_data, $form_location ) { |
| 6 |
|
| 7 |
if( empty( $request_data['email'] ) ) |
| 8 |
return $message; |
| 9 |
|
| 10 |
$type = wppb_toolbox_get_settings( 'forms', 'restricted-email-domains-type' ); |
| 11 |
|
| 12 |
if ( $type == false ) return $message; |
| 13 |
|
| 14 |
$restricted_domains = wppb_toolbox_get_settings( 'forms', 'restricted-email-domains-data' ); |
| 15 |
|
| 16 |
if ( $restricted_domains == false ) return $message; |
| 17 |
|
| 18 |
$domain = strtolower( substr( strrchr( trim( $request_data['email'] ), '@' ), 1 ) ); |
| 19 |
$validation_message = wppb_toolbox_get_settings( 'forms', 'restricted-email-domains-message' ); |
| 20 |
$validation_message = wppb_icl_t( 'plugin profile-builder-pro', 'restricted_email_domains_message_translation', $validation_message, true ); |
| 21 |
|
| 22 |
if ( $type == 'allow' ) { |
| 23 |
|
| 24 |
if ( !in_array( $domain, $restricted_domains ) ) |
| 25 |
return $validation_message; |
| 26 |
|
| 27 |
} else if ( $type == 'deny' ) { |
| 28 |
|
| 29 |
if ( in_array( $domain, $restricted_domains ) ) |
| 30 |
return $validation_message; |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
return $message; |
| 35 |
} |
| 36 |
add_filter( 'wppb_check_form_field_default-e-mail', 'wppb_toolbox_check_email_domain', 20, 4 ); |
| 37 |
|