PluginProbe ʕ •ᴥ•ʔ
Email Validator for Contact Form 7 / 1.2.1
Email Validator for Contact Form 7 v1.2.1
1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.8.0 1.8.1 1.8.2 1.8.3 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.5.0 1.5.1
email-validator-for-contact-form-7 / email-validator-for-contact-form-7.php
email-validator-for-contact-form-7 Last commit date
assets 5 years ago email-validator-for-contact-form-7.php 5 years ago license.txt 5 years ago readme.txt 5 years ago uninstall.php 5 years ago
email-validator-for-contact-form-7.php
599 lines
1 <?php
2
3 /*
4
5 Plugin Name: Email Validator for Contact Form 7
6
7 Plugin URI: https://developer.wordpress.org/plugins/email-validator-for-contact-form-7
8
9 Description: Enables Contact Form 7 users to validate their client’s email address before accepting their messages for sending using MailboxValidator. <strong>Before get started, install and activate the Contact Form 7 plugin first.</strong>
10
11 Version: 1.2.1
12
13 Author: MailboxValidator
14
15 Author URI: https://mailboxvalidator.com
16
17 License: GNU General Public License (GPL) version 3
18
19 License URI: https://www.gnu.org/licenses/gpl-2.0.html
20
21 */
22
23
24
25 // Check if Contact Form 7 is been installed or not
26
27 add_action('admin_init', 'mbv_wpcf7_check_wpcf7_installed');
28
29 function mbv_wpcf7_check_wpcf7_installed () {
30
31 if ( is_admin() && current_user_can( "activate_plugins" ) && ! is_plugin_active( "contact-form-7/wp-contact-form-7.php" ) ) {
32
33 add_action( 'admin_notices', 'mbv_wpcf7_nocf7_notice' );
34
35 deactivate_plugins( plugin_basename( __FILE__ ) );
36
37 remove_submenu_page( 'options-general.php', 'email-validator-for-contact-form-7' );
38
39 $flag = (int) $_GET['activate'];
40
41 if ( isset( $flag ) ) {
42
43 unset( $_GET['activate'] );
44
45 }
46
47 }
48
49 }
50
51 function mbv_wpcf7_nocf7_notice () {
52
53 $plugin_url = esc_url( admin_url( 'plugin-install.php?tab=search&s=contact+form+7' ) );
54
55 echo '<div class="notice notice-warning is-dismissible">
56
57 <p>Contact Form 7 must be installed and activated before using the MailboxValidator plugin. You can click <a href="' . $plugin_url . '">here</a> to install the Contact Form 7 plugin.</p>
58
59 </div>';
60
61 }
62
63 // Show notice if the MBV API key not been saved yet
64
65 function mbv_wpcf7_general_admin_notice(){
66
67 global $pagenow;
68
69 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
70
71 if ( $options['api_key'] == '' || $options['api_key'] == ' ' ) {
72
73 echo '<div class="notice notice-warning is-dismissible">
74
75 <p>Please get your MailboxValidator API key from <a href="https://www.mailboxvalidator.com/plans#api">here</a> and save in <a href="options-general.php?page=email-validator-for-contact-form-7">setting page</a>.</p>
76
77 </div>';
78
79 }
80
81 // else if ( $pagenow == 'plugins.php' && ( $options['api_key'] == '' || $options['api_key'] == ' ' ) ) {
82
83 // echo '<div class="notice notice-warning is-dismissible">
84
85 // <p>Please get your MailboxValidator API key from <a href="https://www.mailboxvalidator.com/plans#api">here</a> and save in <a href="options-general.php?page=email-validator-for-contact-form-7">setting page</a>.</p>
86
87 // </div>';
88
89 // }
90
91 }
92
93 add_action( 'admin_notices', 'mbv_wpcf7_general_admin_notice' );
94
95 // add the admin options page
96
97 add_action( 'admin_menu', 'mbv_wpcf7_plugin_admin_add_page' );
98
99 function mbv_wpcf7_plugin_admin_add_page() {
100
101 add_options_page( 'Email Validator for Contact Form 7', 'Email Validator for Contact Form 7', 'manage_options', 'email-validator-for-contact-form-7', 'mbv_wpcf7_plugin_options_page' );
102
103 wp_register_script( 'mailboxvalidator_email_validator_script', plugins_url( '/assets/js/mbv.js', __FILE__ ), array( 'jquery' ) );
104 wp_enqueue_script( 'mailboxvalidator_email_validator_script' );
105
106 }
107
108 // display the admin options page
109
110 function mbv_wpcf7_plugin_options_page() {
111
112 ?>
113
114 <div>
115
116 <h2>Email Validator for Contact Form 7 by MailboxValidator</h2>
117
118 <p>This plugin enables Contact Form 7 users to validate their client’s email address before accepting their messages for sending. It uses MailboxValidator service for email validation. Please get your free MailboxValidator API key from <a href="https://www.mailboxvalidator.com/plans#api">here</a>. Once you save the settings by clicking "Save Changes", your settings will be saved and Contact Form 7 will automatically detect the changes.</p>
119
120 <!--<p>At here you can edit your MailboxValidator API key and switch on or off disposable or free email validator.</p>-->
121 <?php
122 $mbv_options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
123 $api_key = isset( $mbv_options['api_key'] ) ? $mbv_options['api_key'] : '';
124 if ( $api_key != '' ) {
125 $url = 'https://api.mailboxvalidator.com/plan?key=' . $api_key;
126 $results = wp_remote_get( $url );
127 if ( !is_wp_error( $results ) ) {
128 $body = wp_remote_retrieve_body( $results );
129
130 // Decode the return json results and return the data.
131 $data = json_decode( $body, true );
132
133 if ( $data['plan_name'] != '' ) {
134 if ( $data['plan_name'] == 'API-FREE' ) {
135 $is_low_credit = ( $data['credits_available'] < 100 ) ? true : false ;
136 } else {
137 $is_low_credit = ( $data['credits_available'] < ( $data['credits_limit'] * 0.1 ) ) ? true : false ;
138 }
139 // Now print the plan info
140 echo '<h2>Plan Information</h2><table class="form-table">';
141 echo '<tr><th scope="row"><label>Plan Name</label></th><td><p>' . $data['plan_name'] . '</p></td></tr>';
142 // echo '<tr><th scope="row"><label>Credits Available</label></th><td><p>' . $data['credits_available'] . ' ' . ( $is_low_credit ? '<button class="button"><a href="https://www.mailboxvalidator.com/plans#api" target="_blank">Get More Credits</a></button>' : '' ) . '</p></td></tr>';
143 echo '<tr><th scope="row"><label>Credits Available</label></th><td><p>' . $data['credits_available'] . '<span style="margin-left: 20px"></span>' . ( $is_low_credit ? '<a href="https://www.mailboxvalidator.com/plans#api" target="_blank" class="button">Get More Credits</a>' : '' ) . '</p></td></tr>';
144 echo '<tr><th scope="row"><label>Next Renewal Date</label></th><td><p>' . $data['next_renewal_date'] . '</p></td></tr>';
145 echo '</table>';
146 }
147 }
148 }
149 ?>
150
151 <form action="options.php" method="post">
152
153 <?php settings_fields( 'mbv_wpcf7_email_validator_for_contact_form_7' ); ?>
154
155 <?php do_settings_sections( 'mbv_wpcf7_plugin' ); ?>
156
157 <input name="Submit" type="submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" />
158
159 </form>
160
161 </div>
162
163
164
165 <?php
166
167 }
168
169 // add the admin settings and such
170
171 add_action( 'admin_init', 'mbv_wpcf7_plugin_admin_init' );
172
173 function mbv_wpcf7_plugin_admin_init(){
174
175 register_setting( 'mbv_wpcf7_email_validator_for_contact_form_7', 'mbv_wpcf7_email_validator_for_contact_form_7' );
176
177 add_settings_section( 'mbv_wpcf7_plugin_main', 'Main Settings', 'mbv_wpcf7_plugin_section_text', 'mbv_wpcf7_plugin' );
178
179 add_settings_field( 'mbv_wpcf7_api_key', 'MailboxValidator API Key', 'mbv_wpcf7_api_key_setting', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
180
181 add_settings_field( 'mbv_wpcf7_invalid_option', 'Invalid Email Validation', 'mbv_wpcf7_invalid_setting_option', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
182
183 add_settings_field( 'mbv_wpcf7_invalid_error_message', 'Error Message for Invalid Email', 'mbv_wpcf7_invalid_error_message_setting', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
184
185 add_settings_field( 'mbv_wpcf7_disposable_option', 'Disposable Email Validation', 'mbv_wpcf7_disposable_setting_option', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
186
187 add_settings_field( 'mbv_wpcf7_disposable_error_message', 'Error Message for Disposable Email', 'mbv_wpcf7_disposable_error_message_setting', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
188
189 add_settings_field( 'mbv_wpcf7_free_option', 'Free Email Validation', 'mbv_wpcf7_free_setting_option', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
190
191 add_settings_field( 'mbv_wpcf7_free_error_message', 'Error Message for Free Email', 'mbv_wpcf7_free_error_message_setting', 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
192
193 }
194
195 function mbv_wpcf7_plugin_section_text() {
196
197 echo '<p>At here you can edit your MailboxValidator API key, switch on or off disposable or free email validator and design custom error message for disposable and free email.</p>';
198
199 }
200
201 function mbv_wpcf7_api_key_setting() {
202
203 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
204
205 $api_key = $options['api_key'] ?? ' ';
206
207 echo '<input id="api_key" name="mbv_wpcf7_email_validator_for_contact_form_7[api_key]" size="40" type="text" value="' . esc_attr( $api_key ). '" />';
208
209 }
210
211 function mbv_wpcf7_invalid_setting_option() {
212
213 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
214
215 $invalid_on_off = $options['invalid_on_off'] ?? 'on';
216
217 echo '<div id="radio1"><label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[invalid_on_off]" id="invalid_option" value="on"' . ( ( $invalid_on_off == 'on' ) ? ' checked' : '' ) . ' /> On</label>
218 <label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[invalid_on_off]" id="invalid_option" value="off"' . ( ( $invalid_on_off == 'off' ) ? ' checked' : '' ) . ' /> Off</label></div><br />';
219
220 }
221
222 function mbv_wpcf7_disposable_setting_option() {
223
224 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
225
226 $disposable_on_off = $options['disposable_on_off'] ?? 'on';
227
228 echo '<div id="radio2"><label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[disposable_on_off]" id="disposable_option" value="on"' . ( ( $disposable_on_off == 'on' ) ? ' checked' : '' ) . ' /> On</label>
229 <label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[disposable_on_off]" id="disposable_option" value="off"' . ( ( $disposable_on_off == 'off' ) ? ' checked' : '' ) . ' /> Off</label></div><br />';
230
231 }
232
233 function mbv_wpcf7_free_setting_option() {
234
235 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
236
237 $free_on_off = $options['free_on_off'] ?? 'on';
238
239 echo '<div id="radio3"><label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[free_on_off]" id="free_option" value="on"' . ( ( $free_on_off == 'on' ) ? ' checked' : '' ) . ' /> On</label>
240 <label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[free_on_off]" id="free_option" value="off"' . ( ( $free_on_off == 'off' ) ? ' checked' : '' ) . ' /> Off</label></div><br />';
241
242 }
243
244 function mbv_wpcf7_invalid_error_message_setting() {
245
246 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
247
248 $invalid_error_message = $options['invalid_error_message'] ?? 'Invalid email address. Please enter a valid email address.';
249
250 $invalid_on_off = $options['invalid_on_off'] ?? 'on';
251
252 echo '<input id="invalid_error_message" name="mbv_wpcf7_email_validator_for_contact_form_7[invalid_error_message]" style="width:100%" type="text" value="' . $invalid_error_message . '" ' . ( $invalid_on_off == 'off' ? 'disabled="disabled" ' : '' ) . '/>';
253
254 }
255
256 function mbv_wpcf7_disposable_error_message_setting() {
257
258 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
259
260 $disposable_error_message = $options['disposable_error_message'] ?? 'Invalid email address. Please enter a non-disposable email address.';
261
262 $disposable_on_off = $options['disposable_on_off'] ?? 'on';
263
264 echo '<input id="disposable_error_message" name="mbv_wpcf7_email_validator_for_contact_form_7[disposable_error_message]" style="width:100%" type="text" value="' . $disposable_error_message . '" ' . ( $disposable_on_off == 'off' ? 'disabled="disabled" ' : '' ) . '/>';
265
266 }
267
268 function mbv_wpcf7_free_error_message_setting() {
269
270 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
271
272 $free_error_message = $options['free_error_message'] ?? 'Invalid email address. Please enter a non-free email address.';
273
274 $free_on_off = $options['free_on_off'] ?? 'on';
275
276 echo '<input id="free_error_message" name="mbv_wpcf7_email_validator_for_contact_form_7[free_error_message]" style="width:100%" type="text" value="' . $free_error_message . '" ' . ( $free_on_off == 'off' ? 'disabled="disabled" ' : '' ) . '/>';
277
278 }
279
280 // function mbv_wpcf7_string_length( $string ){
281
282 // return mb_strlen( $string );
283
284 // }
285
286 add_action( 'admin_enqueue_scripts', 'plugin_enqueues' );
287
288 add_action( 'wp_ajax_email_validator_for_contact_form_7_submit_feedback', 'submit_feedback' );
289 add_action( 'admin_footer_text', 'admin_footer_text' );
290
291 // Enqueue the script.
292 function plugin_enqueues( $hook ) {
293
294 // if ( $hook == 'options-general.php' ) {
295 // wp_enqueue_script( 'email_validator_for_contact_form_7_admin_setting_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true );
296 // }
297
298 if ( $hook == 'plugins.php' ) {
299 // Add in required libraries for feedback modal
300 wp_enqueue_script( 'jquery-ui-dialog' );
301 wp_enqueue_style( 'wp-jquery-ui-dialog' );
302
303 wp_enqueue_script( 'email_validator_for_contact_form_7_admin_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true );
304 }
305 }
306
307 function admin_footer_text( $footer_text ) {
308 // $plugin_name = substr( basename( __FILE__ ), 0, strpos( basename( __FILE__ ), '.' ) );
309 $plugin_name = 'email-validator-for-contact-form-7';
310 $current_screen = get_current_screen();
311
312 if ( ( $current_screen && strpos( $current_screen->id, $plugin_name ) !== false ) ) {
313 $footer_text .= sprintf(
314 __( 'Enjoyed %1$s? Please leave us a %2$s rating. A huge thanks in advance!', $plugin_name ),
315 '<strong>' . __( 'MailboxValidator Email Validator', $plugin_name ) . '</strong>',
316 '<a href="https://wordpress.org/support/plugin/' . $plugin_name . '/reviews/?filter=5/#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
317 );
318 }
319
320 if ( $current_screen->id == 'plugins' ) {
321 return $footer_text . '
322 <div id="email-validator-for-contact-form-7-feedback-modal" class="hidden" style="max-width:800px">
323 <span id="email-validator-for-contact-form-7-feedback-response"></span>
324 <p>
325 <strong>Would you mind sharing with us the reason to deactivate the plugin?</strong>
326 </p>
327 <p>
328 <label>
329 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="1"> I no longer need the plugin
330 </label>
331 </p>
332 <p>
333 <label>
334 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="2"> I couldn\'t get the plugin to work
335 </label>
336 </p>
337 <p>
338 <label>
339 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="3"> The plugin doesn\'t meet my requirements
340 </label>
341 </p>
342 <p>
343 <label>
344 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="4"> Other concerns
345 <br><br>
346 <textarea id="email-validator-for-contact-form-7-feedback-other" style="display:none;width:100%"></textarea>
347 </label>
348 </p>
349 <p>
350 <div style="float:left">
351 <input type="button" id="email-validator-for-contact-form-7-submit-feedback-button" class="button button-danger" value="Submit & Deactivate" />
352 </div>
353 <div style="float:right">
354 <a href="#">Skip & Deactivate</a>
355 </div>
356 </p>
357 </div>';
358 }
359
360 return $footer_text;
361 }
362
363 function submit_feedback() {
364 $feedback = ( isset( $_POST['feedback'] ) ) ? $_POST['feedback'] : '';
365 $others = sanitize_text_field (( isset( $_POST['others'] ) ) ? $_POST['others'] : '' );
366
367 $options = [
368 1 => 'I no longer need the plugin',
369 2 => 'I couldn\'t get the plugin to work',
370 3 => 'The plugin doesn\'t meet my requirements',
371 4 => 'Other concerns' . ( ( $others ) ? ( ' - ' . $others ) : '' ),
372 ];
373
374 $url = 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( ['name' => 'email-validator-for-contact-form-7', 'message' => $options[$feedback],] );
375 // file_put_contents ( __DIR__ . '/mbv_plugin_logs.log' , $url . PHP_EOL, FILE_APPEND );
376
377 if ( isset( $options[$feedback] ) ) {
378 if ( !class_exists( 'WP_Http' ) ) {
379 include_once ABSPATH . WPINC . '/class-http.php';
380 }
381
382 $request = new WP_Http();
383 $response = $request->request( 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( [
384 'name' => 'email-validator-for-contact-form-7',
385 'message' => $options[$feedback],
386 ] ), ['timeout' => 5] );
387 }
388 }
389
390 function mbv_wpcf7_single( $emailAddress, $api_key ) {
391
392 try{
393 // Now we need to send the data to MBV API Key and return back the result.
394 $url = 'https://api.mailboxvalidator.com/v1/validation/single?key=' . str_replace( ' ', '', $api_key ) . '&email=' . str_replace( ' ', '', $emailAddress ) . '&source=wordpress';
395
396 // Now we used WordPress custom HTTP API method to get the result from MBV API.
397 $results = wp_remote_get( $url );
398
399 if ( !is_wp_error( $results ) ) {
400 $body = wp_remote_retrieve_body( $results );
401
402 // Decode the return json results and return the data.
403 $data = json_decode( $body, true );
404
405 // update remaining_credits
406 // $mbv_options = get_option( 'mbv_email_validator' );
407 // $mbv_options['remaining_credits'] = $data['credits_available'];
408 // update_option('mbv_email_validator', $mbv_options );
409
410 return $data;
411 } else {
412 // if connection error, let it pass
413 return true;
414 }
415 }
416 catch( Exception $e ) {
417 return true;
418 }
419 }
420
421 function mbv_wpcf7_is_valid_email( $api_result ) {
422 if ( $api_result != '' ) {
423 // mbv_wpcf7_mailboxvalidator_api_log( 'is_valid', $api_result['email_address'], $api_result['status'], $api_result['credits_available'], $api_result['error_code'], $api_result['error_message'] );
424 if ( $api_result['error_message'] == '' ) {
425 if ( $api_result['status'] == 'False' ) {
426 return false;
427 } else {
428 return true;
429 }
430 } else {
431 // If error message occured, let it pass first.
432 return true;
433 }
434 } else {
435 // If error message occured, let it pass first.
436 return true;
437 }
438 }
439
440 function mbv_wpcf7_validate_email_check_free( $emailAddress, $api_key ) {
441
442 // Now we need to send the data to MBV API Key and return back the result.
443
444 $url = 'https://api.mailboxvalidator.com/v1/email/free?key=' . str_replace( ' ', '', $api_key ) . '&email=' . str_replace( ' ', '', $emailAddress ) . '&source=wordpress_7';
445
446 $results = file_get_contents( $url );
447
448
449
450 // Decode the return json results and return the data.
451
452 $data = json_decode( $results, true );
453
454 // mbv_wpcf7_mailboxvalidator_api_log( 'is_free', $data['email_address'], $data['is_free'], $data['credits_available'], $data['error_code'], $data['error_message'] );
455
456 if ( $data['error_message'] == '' ) {
457
458 if ( $data['is_free'] == 'False' ) {
459
460 return false;
461
462 } else {
463
464 return true;
465
466 }
467
468 }
469
470 }
471
472 function mbv_wpcf7_validate_email_check_disposable( $emailAddress, $api_key ) {
473
474 // Now we need to send the data to MBV API Key and return back the result.
475
476 $url = 'https://api.mailboxvalidator.com/v1/email/disposable?key=' . str_replace( ' ', '', $api_key ) . '&email=' . str_replace( ' ', '', $emailAddress ) . '&source=wordpress_7';
477
478 $results = file_get_contents( $url );
479
480
481
482 // Decode the return json results and return the data.
483
484 $data = json_decode( $results, true );
485
486 // mbv_wpcf7_mailboxvalidator_api_log( 'is_disposable', $data['email_address'], $data['is_disposable'], $data['credits_available'], $data['error_code'], $data['error_message'] );
487
488 if ( $data['error_message'] == '' ) {
489
490 if ( $data['is_disposable'] == 'False' ) {
491
492 return false;
493
494 } else {
495
496 return true;
497
498 }
499
500 }
501
502 }
503
504 function mbv_wpcf7_custom_email_validator_filter( $result, $tags ) {
505
506 // Get option settings to know which validator is been called
507
508 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
509
510 $tags = new WPCF7_FormTag( $tags );
511
512 $type = $tags->type;
513
514 $name = $tags->name;
515
516 if ( ( 'email' == $type || 'email*' == $type ) && !( $options['api_key'] == '' ) ) {
517
518 // do validation for disposable and free
519
520 /*
521 if( $options['disposable_on_off'] == 'on' ){
522
523 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'mbv_wpcf7_validate_email_check_disposable result: ' . mbv_wpcf7_validate_email_check_disposable( sanitize_email ( $_POST[$name] ), $options['api_key'] ) . PHP_EOL, FILE_APPEND );
524 if( ( mbv_wpcf7_validate_email_check_disposable( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true){
525
526 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Invalid email address. Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
527
528 }elseif ( $options['free_on_off'] == 'on' ){
529
530 if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){
531
532 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Invalid email address. Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
533
534 }
535
536 }
537
538 } elseif ( $options['free_on_off'] == 'on' ){
539
540 if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){
541
542 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Invalid email address. Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
543
544 }
545
546 }*/
547 $single_result = $options['invalid_on_off'] == 'on' ? mbv_wpcf7_single( $_POST[$name], $options['api_key'] ) : '';
548 $is_valid_email = $options['invalid_on_off'] == 'on' && $single_result != '' ? mbv_wpcf7_is_valid_email( $single_result ) : true;
549 $is_disposable = $options['disposable_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_disposable( $_POST[$name] , $options['api_key'] ) : false;
550 $is_free = $options['free_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_free( $_POST[$name] , $options['api_key'] ) : false;
551
552 if( $is_valid_email == false ){
553 if ( ($options['disposable_on_off'] == 'on') && ( $is_disposable == true ) ) {
554 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Invalid email address. Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
555 } else {
556 $result->invalidate( $tags, __( $options['invalid_error_message'] ?? 'Invalid email address. Please enter a valid email address.', 'email-validator-for-contact-form-7' ) );
557 }
558 } elseif( $is_disposable == true ){
559 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Invalid email address. Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
560 } elseif( $is_free == true ){
561 // $mbv_validation_result['status'] = false;
562 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Invalid email address. Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
563 }
564
565 }
566
567 return $result;
568
569 }
570
571 add_filter( 'wpcf7_validate_email', 'mbv_wpcf7_custom_email_validator_filter', 20, 2 ); // Email field
572
573 add_filter( 'wpcf7_validate_email*', 'mbv_wpcf7_custom_email_validator_filter', 20, 2 ); // Req. Email field
574
575 function mbv_wpcf7_mailboxvalidator_api_log ( $mode, $api_result1, $api_result2, $api_result3, $api_result4, $api_result5 ) {
576
577 // Log all the MBV api usage to the log file
578
579 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Email Address: ' . $api_result1 . PHP_EOL, FILE_APPEND );
580
581 /*
582 if ( $mode == 'disposable' ) {
583 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_disposable: ' . $api_result2 . PHP_EOL, FILE_APPEND );
584 } else {
585 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_free: ' . $api_result2 . PHP_EOL, FILE_APPEND );
586 }
587 */
588
589 file_put_contents( __DIR__ . '/mbv_api_logs.log', $mode . ': ' . $api_result2 . PHP_EOL, FILE_APPEND );
590
591 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Credits Available: ' . $api_result3 . PHP_EOL, FILE_APPEND );
592
593 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Code: ' . $api_result4 == '' ?: '-' . PHP_EOL, FILE_APPEND );
594
595 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Message: ' . $api_result5 == '' ?: '-' . PHP_EOL, FILE_APPEND );
596
597 file_put_contents( __DIR__ . '/mbv_api_logs.log', str_repeat( '-', 120 ) . PHP_EOL, FILE_APPEND );
598
599 }