PluginProbe ʕ •ᴥ•ʔ
Email Validator for Contact Form 7 / 1.7.1
Email Validator for Contact Form 7 v1.7.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 4 years ago languages 5 years ago vendor 2 years ago email-validator-for-contact-form-7.php 2 years ago license.txt 7 years ago readme.txt 2 years ago uninstall.php 4 years ago
email-validator-for-contact-form-7.php
924 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.7.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 Text Domain: email-validator-for-contact-form-7
22
23 */
24
25 require_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
26
27 $emailvalidatorforcontactform7 = new EmailValidatorContactForm7();
28
29 // Check if Contact Form 7 is been installed or not
30 add_action('admin_init', [$emailvalidatorforcontactform7, 'mbv_wpcf7_check_wpcf7_installed']);
31
32 add_action( 'admin_enqueue_scripts', [$emailvalidatorforcontactform7, 'plugin_enqueues'] );
33
34 add_action( 'wp_ajax_email_validator_for_contact_form_7_submit_feedback', [$emailvalidatorforcontactform7, 'submit_feedback'] );
35 add_action( 'admin_footer_text', [$emailvalidatorforcontactform7, 'admin_footer_text'] );
36
37 add_filter( 'wpcf7_validate_email', [$emailvalidatorforcontactform7, 'mbv_wpcf7_custom_email_validator_filter'], 20, 2 ); // Email field
38
39 add_filter( 'wpcf7_validate_email*', [$emailvalidatorforcontactform7, 'mbv_wpcf7_custom_email_validator_filter'], 20, 2 ); // Req. Email field
40
41 class EmailValidatorContactForm7
42 {
43 protected $global_status = '';
44
45
46 public function __construct()
47 {
48 // add_action ( 'init', 'mbv_localization');
49 add_action ( 'admin_init', [$this, 'mbv_localization']);
50 add_action( 'admin_notices', [$this, 'mbv_wpcf7_general_admin_notice'] );
51 // add the admin options page
52 add_action( 'admin_menu', [$this, 'mbv_wpcf7_plugin_admin_add_page'] );
53 // add the admin settings and such
54 add_action( 'admin_init', [$this, 'mbv_wpcf7_plugin_admin_init'] );
55 }
56
57 public function mbv_wpcf7_check_wpcf7_installed ()
58 {
59
60 if ( is_admin() && current_user_can( "activate_plugins" ) && ! is_plugin_active( "contact-form-7/wp-contact-form-7.php" ) ) {
61
62 add_action( 'admin_notices', [$this, 'mbv_wpcf7_nocf7_notice'] );
63
64 deactivate_plugins( plugin_basename( __FILE__ ) );
65
66 remove_submenu_page( 'options-general.php', 'email-validator-for-contact-form-7' );
67
68 $flag = (int) $_GET['activate'];
69
70 if ( isset( $flag ) ) {
71
72 unset( $_GET['activate'] );
73
74 }
75
76 }
77
78 }
79
80 /*
81 * Localization
82 */
83 public function mbv_localization()
84 {
85 // load_plugin_textdomain( 'email-validator-for-contact-form-7', false, dirname( plugin_basename( __FILE__ ) ) . '/langs' );
86 load_plugin_textdomain( 'email-validator-for-contact-form-7', false, plugins_url( '/languages' ) );
87 }
88
89 public function mbv_wpcf7_nocf7_notice ()
90 {
91
92 $plugin_url = esc_url( admin_url( 'plugin-install.php?tab=search&s=contact+form+7' ) );
93
94 echo '<div class="notice notice-warning is-dismissible"><p>';
95 printf( __( 'You must <a href="%s">install</a> and activate the Contact Form 7 before using the MailboxValidator plugin.', 'email-validator-for-contact-form-7' ), $plugin_url );
96 echo '</p></div>';
97
98 }
99
100 // Show notice if the MBV API key not been saved yet
101 public function mbv_wpcf7_general_admin_notice()
102 {
103
104 global $pagenow;
105
106 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
107
108 if ( !(isset($options['api_key'])) || $options['api_key'] == '' || $options['api_key'] == ' ' ) {
109
110 echo '<div class="notice notice-warning is-dismissible"><p>';
111
112 printf( __( 'Please sign up for a <a href="%1$s">free MailboxValidator API key</a> to enable the email blocking.', 'email-validator-for-contact-form-7' ), 'https://www.mailboxvalidator.com/plans#api' );
113
114 echo '</p></div>';
115
116 }
117
118 // else if ( $pagenow == 'plugins.php' && ( $options['api_key'] == '' || $options['api_key'] == ' ' ) ) {
119
120 // echo '<div class="notice notice-warning is-dismissible">
121
122 // <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>
123
124 // </div>';
125
126 // }
127
128 }
129
130 public function mbv_wpcf7_plugin_admin_add_page()
131 {
132
133 add_options_page( 'Email Validator for Contact Form 7', 'Email Validator for Contact Form 7', 'manage_options', 'email-validator-for-contact-form-7', [$this, 'mbv_wpcf7_plugin_options_page'] );
134
135 // wp_register_script( 'mailboxvalidator_email_validator_script', plugins_url( '/assets/js/mbv.js', __FILE__ ), array( 'jquery' ), filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/mbv.js' ) , true );
136 wp_enqueue_script('mailboxvalidator_email_validator_chart_js', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js', [], null, true);
137 // wp_enqueue_script( 'mailboxvalidator_email_validator_script' );
138
139 $this->create_table();
140
141 }
142
143 // display the admin options page
144 public function mbv_wpcf7_plugin_options_page()
145 {
146
147 $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'settings';
148
149
150 echo '
151 <div class="wrap">
152
153 <h2>Email Validator for Contact Form 7 by MailboxValidator</h2>
154
155 <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>
156
157 <!--<p>At here you can edit your MailboxValidator API key and switch on or off disposable or free email validator.</p>-->' . $this->admin_tabs() . '';
158
159 switch ($tab) {
160 // Statistic
161 case 'statistic':
162 global $wpdb;
163
164 $table_name = $wpdb->prefix . 'email_validator_for_contact_form_7_log';
165
166 if (isset($_POST['purge'])) {
167 $wpdb->query('TRUNCATE TABLE ' . $table_name);
168 }
169
170 // Remove logs older than 30 days.
171 $wpdb->query('DELETE FROM ' . $table_name . ' WHERE date_created <="' . date('Y-m-d H:i:s', strtotime('-30 days')) . '"');
172
173 // Prepare logs for last 30 days.
174 $results = $wpdb->get_results('SELECT DATE_FORMAT(date_created, "%Y-%m-%d") AS date, COUNT(*) AS total FROM ' . $table_name . ' GROUP BY date ORDER BY date', OBJECT);
175
176 $lines = [];
177 for ($d = 30; $d > 0; --$d) {
178 $lines[date('Y-m-d', strtotime('-' . $d . ' days'))] = 0;
179 }
180
181 foreach ($results as $result) {
182 $lines[$result->date] = $result->total;
183 }
184
185 ksort($lines);
186
187 $labels = [];
188 $total_emails_blocked = [];
189
190 foreach ($lines as $date => $value) {
191 $labels[] = $date;
192 $total_emails_blocked[] = ($value) ? $value : 0;
193 }
194
195 // Add index to table id not exist.
196 $results = $wpdb->get_results('SELECT COUNT(*) AS total FROM information_schema.statistics WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = "' . $table_name . '" AND INDEX_NAME = "idx_email_address"', OBJECT);
197
198 if ($results[0]->total == 0) {
199 $wpdb->query('ALTER TABLE `' . $table_name . '` ADD INDEX `idx_email_address` (`email_address`);');
200 }
201 echo '<h3>Block Statistics For The Past 30 Days</h3>
202
203 <p>
204 <canvas id="line_chart" style="width:100%;height:400px"></canvas>
205 </p>
206
207 <div class="clear"></div>
208
209 <p>
210 <form id="form-purge" method="post">
211 <input type="hidden" name="purge" value="true">
212 <input type="submit" name="submit" id="btn-purge" class="button button-primary" value="Purge All Logs" />
213 </form>
214 </p>
215
216 </div>
217 <script>
218 jQuery(document).ready(function($){
219 function get_color(){
220 var r = Math.floor(Math.random() * 200);
221 var g = Math.floor(Math.random() * 200);
222 var b = Math.floor(Math.random() * 200);
223
224 return \'rgb(\' + r + \', \' + g + \', \' + b + \', 0.4)\';
225 }
226
227 var ctx = document.getElementById(\'line_chart\').getContext(\'2d\');
228 var line = new Chart(ctx, {
229 type: \'line\',
230 data: {
231 labels: [\'' . implode('\', \'', $labels) . '\'],
232 datasets: [{
233 label: \'Total Email Blocked\',
234 data: [' . implode(', ', $total_emails_blocked) . '],
235 backgroundColor: get_color()
236 }]
237 },
238 options: {
239 title: {
240 display: true,
241 text: \'Total Email Blocked\'
242 },
243 scales: {
244 yAxes: [{
245 ticks: {
246 beginAtZero:true
247 }
248 }]
249 }
250 }
251 });
252 });
253 </script>';
254 break;
255 case 'settings':
256 default:
257 $mbv_options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
258 $api_key = isset( $mbv_options['api_key'] ) ? $mbv_options['api_key'] : '';
259 if ( $api_key != '' ) {
260 $url = 'https://api.mailboxvalidator.com/plan?key=' . $api_key;
261 $results = wp_remote_get( $url );
262 if ( !is_wp_error( $results ) ) {
263 $body = wp_remote_retrieve_body( $results );
264
265 // Decode the return json results and return the data.
266 $data = json_decode( $body, true );
267
268 if ( $data['plan_name'] != '' ) {
269 if ( $data['plan_name'] == 'API-FREE' ) {
270 $is_low_credit = ( $data['credits_available'] < 100 ) ? true : false ;
271 } else {
272 $is_low_credit = ( $data['credits_available'] < ( $data['credits_limit'] * 0.1 ) ) ? true : false ;
273 }
274 // Now print the plan info
275 echo '<h2>'. __('Plan Information', 'email-validator-for-contact-form-7' ) . '</h2><table class="form-table">';
276 echo '<tr><th scope="row"><label>'. __('Plan Name', 'email-validator-for-contact-form-7' ) . '</label></th><td><p>' . $data['plan_name'] . '</p></td></tr>';
277 // 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>';
278 echo '<tr><th scope="row"><label>'. __('Credits Available', 'email-validator-for-contact-form-7' ) . '</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>';
279 echo '<tr><th scope="row"><label>'. __('Next Renewal Date', 'email-validator-for-contact-form-7' ) . '</label></th><td><p>' . $data['next_renewal_date'] . '</p></td></tr>';
280 echo '</table>';
281 echo '<a href="https://www.mailboxvalidator.com/login" target="_blank" class="button">Login to Account Area</a>';
282 }
283 }
284 }
285
286 echo '<form action="options.php" method="post">';
287
288 settings_fields( 'mbv_wpcf7_email_validator_for_contact_form_7' );
289
290 do_settings_sections( 'mbv_wpcf7_plugin' );
291 echo '<br>
292 <hr>
293 <br>';
294 do_settings_sections( 'mbv_wpcf7_plugin1' );
295 echo '<br>
296 <hr>
297 <br>';
298 do_settings_sections( 'mbv_wpcf7_plugin2' );
299 echo '<br>
300 <hr>
301 <br>';
302 do_settings_sections( 'mbv_wpcf7_plugin3' );
303 echo '<br>
304 <hr>
305 <br>';
306 do_settings_sections( 'mbv_wpcf7_plugin4' );
307
308 echo '<input name="Submit" type="submit" value="' . __( 'Save Changes' ) . '" class="button button-primary" />
309 </form>
310 </div>';
311 break;
312
313 }
314 }
315
316 private function admin_tabs()
317 {
318 $disable_tabs = false;
319
320 $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'settings';
321
322 return '
323 ' . $this->global_status . '
324 <h2 class="nav-tab-wrapper">
325 <a href="' . (($disable_tabs) ? 'javascript:;' : admin_url('options-general.php?page=email-validator-for-contact-form-7&tab=settings')) . '" class="nav-tab' . (($tab == 'settings') ? ' nav-tab-active' : '') . '">Settings</a>
326 <a href="' . (($disable_tabs) ? 'javascript:;' : admin_url('options-general.php?page=email-validator-for-contact-form-7&tab=statistic')) . '" class="nav-tab' . (($tab == 'statistic') ? ' nav-tab-active' : '') . '">Statistics</a>
327 </h2>';
328 }
329
330 public function mbv_wpcf7_plugin_admin_init()
331 {
332
333 register_setting( 'mbv_wpcf7_email_validator_for_contact_form_7', 'mbv_wpcf7_email_validator_for_contact_form_7', [$this, 'mbv_wpcf7_sanitize_settings_input'] );
334
335 add_settings_section( 'mbv_wpcf7_plugin_main', __('Main Settings', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_plugin_section_text'], 'mbv_wpcf7_plugin' );
336 add_settings_section( 'mbv_wpcf7_plugin_main1', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin1' );
337 add_settings_section( 'mbv_wpcf7_plugin_main2', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin2' );
338 add_settings_section( 'mbv_wpcf7_plugin_main3', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin3' );
339 add_settings_section( 'mbv_wpcf7_plugin_main4', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin4' );
340
341 add_settings_field( 'mbv_wpcf7_api_key', __('MailboxValidator API Key', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_api_key_setting'], 'mbv_wpcf7_plugin', 'mbv_wpcf7_plugin_main' );
342
343 add_settings_field( 'mbv_wpcf7_invalid_option', __('Block Invalid Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_invalid_setting_option'], 'mbv_wpcf7_plugin1', 'mbv_wpcf7_plugin_main1' );
344
345 add_settings_field( 'mbv_wpcf7_invalid_error_message', __('Error Message for Invalid Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_invalid_error_message_setting'], 'mbv_wpcf7_plugin1', 'mbv_wpcf7_plugin_main1' );
346
347 add_settings_field( 'mbv_wpcf7_disposable_option', __('Block Disposable Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_disposable_setting_option'], 'mbv_wpcf7_plugin2', 'mbv_wpcf7_plugin_main2' );
348
349 add_settings_field( 'mbv_wpcf7_disposable_error_message', __('Error Message for Disposable Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_disposable_error_message_setting'], 'mbv_wpcf7_plugin2', 'mbv_wpcf7_plugin_main2' );
350
351 add_settings_field( 'mbv_wpcf7_free_option', __('Block Free Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_free_setting_option'], 'mbv_wpcf7_plugin3', 'mbv_wpcf7_plugin_main3' );
352
353 add_settings_field( 'mbv_wpcf7_free_error_message', __('Error Message for Free Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_free_error_message_setting'], 'mbv_wpcf7_plugin3', 'mbv_wpcf7_plugin_main3' );
354
355 add_settings_field( 'mbv_wpcf7_role_option', __('Block Role-Based Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_role_setting_option'], 'mbv_wpcf7_plugin4', 'mbv_wpcf7_plugin_main4' );
356
357 add_settings_field( 'mbv_wpcf7_role_error_message', __('Error Message for Role-based Email', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_role_error_message_setting'], 'mbv_wpcf7_plugin4', 'mbv_wpcf7_plugin_main4' );
358
359 }
360
361 public function mbv_wpcf7_sanitize_settings_input($input){
362 // Check the values of radio buttons
363 if (! in_array($input['invalid_on_off'], array('on', 'off'))) {
364 add_settings_error(
365 'mbv_wpcf7_invalid_error_message', // setting title
366 'mbv_wpcf7_optionerror', // error ID
367 'Invalid option value detected.', // error message
368 'error' // type of message
369 );
370 $input['invalid_on_off'] = 'on';
371 }
372 if (! in_array($input['disposable_on_off'], array('on', 'off'))) {
373 add_settings_error(
374 'mbv_wpcf7_disposable_on_off', // setting title
375 'mbv_wpcf7_optionerror', // error ID
376 'Invalid option value detected.', // error message
377 'error' // type of message
378 );
379 $input['disposable_on_off'] = 'on';
380 }
381 if (! in_array($input['free_on_off'], array('on', 'off'))) {
382 add_settings_error(
383 'mbv_wpcf7_free_on_off', // setting title
384 'mbv_wpcf7_optionerror', // error ID
385 'Invalid option value detected.', // error message
386 'error' // type of message
387 );
388 $input['free_on_off'] = 'on';
389 }
390 if (! in_array($input['role_on_off'], array('on', 'off'))) {
391 add_settings_error(
392 'mbv_wpcf7_role_on_off', // setting title
393 'mbv_wpcf7_optionerror', // error ID
394 'Invalid option value detected.', // error message
395 'error' // type of message
396 );
397 $input['role_on_off'] = 'on';
398 }
399 // Sanitize inputs
400 $input['api_key'] = strip_tags(stripslashes( $input['api_key'] ));
401 $input['invalid_on_off'] = strip_tags(stripslashes( $input['invalid_on_off'] ));
402 $input['disposable_on_off'] = strip_tags(stripslashes( $input['disposable_on_off'] ));
403 $input['free_on_off'] = strip_tags(stripslashes( $input['free_on_off'] ));
404 $input['role_on_off'] = strip_tags(stripslashes( $input['role_on_off'] ));
405 $input['invalid_error_message'] = strip_tags(stripslashes( $input['invalid_error_message'] ));
406 $input['disposable_error_message'] = strip_tags(stripslashes( $input['disposable_error_message'] ));
407 $input['free_error_message'] = strip_tags(stripslashes( $input['free_error_message'] ));
408 $input['role_error_message'] = strip_tags(stripslashes( $input['role_error_message'] ));
409 return $input;
410 }
411
412 public function mbv_wpcf7_plugin_section_text()
413 {
414
415 echo '<p>'. __('Please enter a MailboxValidator API key to enable the email blocking.', 'email-validator-for-contact-form-7' ) . '</p>';
416
417 }
418
419 public function mbv_wpcf7_api_key_setting()
420 {
421
422 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
423
424 $api_key = $options['api_key'] ?? ' ';
425
426 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 ). '" />';
427
428 }
429
430 public function mbv_wpcf7_invalid_setting_option()
431 {
432
433 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
434
435 $invalid_on_off = $options['invalid_on_off'] ?? 'on';
436
437 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', 'email-validator-for-contact-form-7' ) . '</label>
438 <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', 'email-validator-for-contact-form-7' ) . '</label></div><br />';
439
440 }
441
442 public function mbv_wpcf7_disposable_setting_option()
443 {
444
445 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
446
447 $disposable_on_off = $options['disposable_on_off'] ?? 'on';
448
449 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', 'email-validator-for-contact-form-7' ) . '</label>
450 <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', 'email-validator-for-contact-form-7' ) . '</label></div><br />';
451
452 }
453
454 public function mbv_wpcf7_free_setting_option()
455 {
456
457 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
458
459 $free_on_off = $options['free_on_off'] ?? 'on';
460
461 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', 'email-validator-for-contact-form-7' ) . '</label>
462 <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', 'email-validator-for-contact-form-7' ) . '</label></div><br />';
463
464 }
465
466 public function mbv_wpcf7_role_setting_option()
467 {
468
469 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
470
471 $role_on_off = $options['role_on_off'] ?? 'on';
472
473 echo '<div id="radio4"><label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[role_on_off]" id="free_option" value="on"' . ( ( $role_on_off == 'on' ) ? ' checked' : '' ) . ' /> '. __('On', 'email-validator-for-contact-form-7' ) . '</label>
474 <label><input type="radio" name="mbv_wpcf7_email_validator_for_contact_form_7[role_on_off]" id="free_option" value="off"' . ( ( $role_on_off == 'off' ) ? ' checked' : '' ) . ' /> '. __('Off', 'email-validator-for-contact-form-7' ) . '</label></div><br />';
475
476 }
477
478 public function mbv_wpcf7_invalid_error_message_setting()
479 {
480
481 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
482
483 $invalid_error_message = $options['invalid_error_message'] ?? __('Please enter a valid email address.', 'email-validator-for-contact-form-7' );
484
485 $invalid_on_off = $options['invalid_on_off'] ?? 'on';
486
487 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 . '" aria-describedby="errormessage-hint" max="255" maxlength="255"/>';
488 echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>';
489
490 }
491
492 public function mbv_wpcf7_disposable_error_message_setting()
493 {
494
495 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
496
497 $disposable_error_message = $options['disposable_error_message'] ?? __('Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' );
498
499 $disposable_on_off = $options['disposable_on_off'] ?? 'on';
500
501 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 . '" aria-describedby="errormessage-hint" max="255" maxlength="255"/>';
502 echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>';
503
504 }
505
506 public function mbv_wpcf7_free_error_message_setting()
507 {
508
509 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
510
511 $free_error_message = $options['free_error_message'] ?? __('Please enter a non-free email address.', 'email-validator-for-contact-form-7' );
512
513 $free_on_off = $options['free_on_off'] ?? 'on';
514
515 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 . '" aria-describedby="errormessage-hint" max="255" maxlength="255"/>';
516 echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>';
517
518 }
519
520 public function mbv_wpcf7_role_error_message_setting()
521 {
522
523 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
524
525 $role_error_message = $options['role_error_message'] ?? __('Please enter a non-role based email address.', 'email-validator-for-contact-form-7' );
526
527 $role_on_off = $options['role_on_off'] ?? 'on';
528
529 echo '<input id="role_error_message" name="mbv_wpcf7_email_validator_for_contact_form_7[role_error_message]" style="width:100%" type="text" value="' . $role_error_message . '" aria-describedby="errormessage-hint" max="255" maxlength="255"/>';
530 echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>';
531
532 }
533
534 // function mbv_wpcf7_string_length( $string ){
535
536 // return mb_strlen( $string );
537
538 // }
539
540 // Enqueue the script.
541 public function plugin_enqueues( $hook )
542 {
543
544 // if ( $hook == 'options-general.php' ) {
545 // wp_enqueue_script( 'email_validator_for_contact_form_7_admin_setting_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true );
546 // }
547
548 if ( $hook == 'plugins.php' ) {
549 // Add in required libraries for feedback modal
550 wp_enqueue_script( 'jquery-ui-dialog' );
551 wp_enqueue_style( 'wp-jquery-ui-dialog' );
552
553 wp_enqueue_script( 'email_validator_for_contact_form_7_admin_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true );
554 }
555 }
556
557 public function admin_footer_text( $footer_text )
558 {
559 // $plugin_name = substr( basename( __FILE__ ), 0, strpos( basename( __FILE__ ), '.' ) );
560 $plugin_name = 'email-validator-for-contact-form-7';
561 $current_screen = get_current_screen();
562
563 if ( ( $current_screen && strpos( $current_screen->id, $plugin_name ) !== false ) ) {
564 $footer_text .= sprintf(
565 __( 'Love our plugin? Please leave us a %1$s rating. A huge thanks in advance!', $plugin_name ),
566 '<a href="https://wordpress.org/support/plugin/' . $plugin_name . '/reviews/?filter=5/#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
567 );
568 }
569
570 if ( $current_screen->id == 'plugins' ) {
571 return $footer_text . '
572 <div id="email-validator-for-contact-form-7-feedback-modal" class="hidden" style="max-width:800px">
573 <span id="email-validator-for-contact-form-7-feedback-response"></span>
574 <p>
575 <strong>'. __('Would you mind sharing with us the reason to deactivate the plugin', 'email-validator-for-contact-form-7' ) . '?</strong>
576 </p>
577 <p>
578 <label>
579 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="1"> '. __('I no longer need the plugin', 'email-validator-for-contact-form-7' ) . '
580 </label>
581 </p>
582 <p>
583 <label>
584 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="2"> '. __('I couldn\'t get the plugin to work', 'email-validator-for-contact-form-7' ) . '
585 </label>
586 </p>
587 <p>
588 <label>
589 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="3"> '. __('The plugin doesn\'t meet my requirements', 'email-validator-for-contact-form-7' ) . '
590 </label>
591 </p>
592 <p>
593 <label>
594 <input type="radio" name="email-validator-for-contact-form-7-feedback" value="4"> '. __('Other concerns', 'email-validator-for-contact-form-7' ) . '
595 <br><br>
596 <textarea id="email-validator-for-contact-form-7-feedback-other" style="display:none;width:100%"></textarea>
597 </label>
598 </p>
599 <p>
600 <div style="float:left">
601 <input type="button" id="email-validator-for-contact-form-7-submit-feedback-button" class="button button-danger" value="'. esc_attr__('Submit & Deactivate', 'email-validator-for-contact-form-7' ) . '" />
602 </div>
603 <div style="float:right">
604 <a href="#">'. __('Skip & Deactivate', 'email-validator-for-contact-form-7' ) . '</a>
605 </div>
606 </p>
607 </div>';
608 }
609
610 return $footer_text;
611 }
612
613 public function submit_feedback()
614 {
615
616 $feedback = ( isset( $_POST['feedback'] ) ) ? $_POST['feedback'] : '';
617 $others = sanitize_text_field (( isset( $_POST['others'] ) ) ? $_POST['others'] : '' );
618
619 $options = [
620 1 => 'I no longer need the plugin',
621 2 => 'I couldn\'t get the plugin to work',
622 3 => 'The plugin doesn\'t meet my requirements',
623 4 => 'Other concerns' . ( ( $others ) ? ( ' - ' . $others ) : '' ),
624 ];
625
626 $url = 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( ['name' => 'email-validator-for-contact-form-7', 'message' => $options[$feedback],] );
627 // file_put_contents ( __DIR__ . '/mbv_plugin_logs.log' , $url . PHP_EOL, FILE_APPEND );
628
629 if ( isset( $options[$feedback] ) ) {
630 if ( !class_exists( 'WP_Http' ) ) {
631 include_once ABSPATH . WPINC . '/class-http.php';
632 }
633
634 $request = new WP_Http();
635 $response = $request->request( 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( [
636 'name' => 'email-validator-for-contact-form-7',
637 'message' => $options[$feedback],
638 ] ), ['timeout' => 5] );
639 }
640 }
641
642 function mbv_wpcf7_single( $emailAddress, $api_key ) {
643
644 try{
645
646 $mbv = new \MailboxValidator\EmailValidation ($api_key);
647 $results = $mbv->validateEmail(str_replace( ' ', '', $emailAddress ));
648
649 if ($results != null) {
650 foreach ($results as $key => $value) {
651 $data[$key] = $value;
652 }
653 return $data;
654 } else {
655 return true;
656 }
657 }
658 catch( Exception $e ) {
659 return true;
660 }
661 }
662
663 private function mbv_wpcf7_is_valid_email( $api_result ) {
664
665 if ( $api_result != '' ) {
666 if ( !isset( $api_result['error_code'] ) ) {
667 if ( $api_result['status'] ) {
668 return true;
669 } else {
670 return false;
671 }
672 } else {
673 // If error message occured, let it pass first.
674 return true;
675 }
676 } else {
677 // If error message occured, let it pass first.
678 return true;
679 }
680 }
681
682 private function mbv_wpcf7_is_role_email( $api_result ) {
683
684 if ( $api_result != '' ) {
685 if ( !isset( $api_result['error_code'] ) ) {
686 if ( $api_result['is_role'] ) {
687 return true;
688 } else {
689 return false;
690 }
691 } else {
692 // If error message occured, let it pass first.
693 return false;
694 }
695 } else {
696 // If error message occured, let it pass first.
697 return false;
698 }
699 }
700
701 private function mbv_wpcf7_validate_email_check_free( $emailAddress, $api_key ) {
702
703 $mbv = new \MailboxValidator\EmailValidation ($api_key);
704 $results = $mbv->isFreeEmail(str_replace( ' ', '', $emailAddress ));
705
706 // if ( $data['error_message'] == '' ) {
707 if ($results != null) {
708 if ( !isset( $results->error_code ) ) {
709
710 // if ( $data['is_free'] == 'False' ) {
711 if ( $results->is_free ) {
712
713 return true;
714
715 } else {
716
717 return false;
718
719 }
720
721 } else {
722 return false;
723 }
724 } else {
725 return false;
726 }
727
728 }
729
730 private function mbv_wpcf7_validate_email_check_disposable( $emailAddress, $api_key ) {
731
732 $mbv = new \MailboxValidator\EmailValidation ($api_key);
733 $results = $mbv->isDisposableEmail(str_replace( ' ', '', $emailAddress ));
734
735 // if ( $data['error_message'] == '' ) {
736 if ($results != null) {
737 if ( !isset( $results->error_code ) ) {
738
739 // if ( $data['is_disposable'] == 'False' ) {
740 if ( $results->is_disposable ) {
741
742 return true;
743
744 } else {
745
746 return false;
747
748 }
749
750 } else {
751 return false;
752 }
753 } else {
754 return false;
755 }
756
757 }
758
759 public function mbv_wpcf7_custom_email_validator_filter( $result, $tags ) {
760 global $wpdb;
761
762 $datetime_started = date('Y-m-d H:i:s');
763
764 $user_apikey = trim($options['api_key']);
765
766 $table_name = $wpdb->prefix . 'email_validator_for_contact_form_7_log';
767
768 // Get option settings to know which validator is been called
769
770 $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' );
771
772 $tags = new WPCF7_FormTag( $tags );
773
774 $type = $tags->type;
775
776 $name = $tags->name;
777
778 $email = $_POST[$name];
779
780
781 $email_parts = explode( '@', $email );
782
783 // 20240122: Check for email syntax to prevent pen test
784 if ( ( 'email' === $type || 'email*' === $type ) && (filter_var(trim($_POST[$name]), FILTER_VALIDATE_EMAIL)) && !( $user_apikey === '' ) && (preg_match('/^[A-Z\d]+$/', $user_apikey)) ) {
785
786 // do validation for disposable and free
787
788 /*
789 if( $options['disposable_on_off'] == 'on' ){
790
791 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 );
792 if( ( mbv_wpcf7_validate_email_check_disposable( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true){
793
794 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
795
796 }elseif ( $options['free_on_off'] == 'on' ){
797
798 if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){
799
800 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
801
802 }
803
804 }
805
806 } elseif ( $options['free_on_off'] == 'on' ){
807
808 if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){
809
810 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
811
812 }
813
814 }*/
815 $single_result = $options['invalid_on_off'] == 'on' || $options['role_on_off'] == 'on' ? $this->mbv_wpcf7_single( $_POST[$name], $user_apikey ) : '';
816 $is_valid_email = $options['invalid_on_off'] == 'on' && $single_result != '' ? $this->mbv_wpcf7_is_valid_email( $single_result ) : true;
817 $is_role = $options['role_on_off'] == 'on' && $single_result != '' ? $this->mbv_wpcf7_is_role_email( $single_result ) : false;
818 // $is_disposable = $options['disposable_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_disposable( $_POST[$name] , $options['api_key'] ) : false;
819 // $is_free = $options['free_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_free( $_POST[$name] , $options['api_key'] ) : false;
820 if ($options['disposable_on_off'] === 'on') {
821 if ($single_result != '' && !(array_key_exists('error_message', $single_result))) {
822 $is_disposable = ($single_result['is_disposable']) ? true : false;
823 } else {
824 $is_disposable = $this->mbv_wpcf7_validate_email_check_disposable( $_POST[$name] , $user_apikey );
825 }
826 } else {
827 $is_disposable = false;
828 }
829 if ($options['free_on_off'] === 'on') {
830 if ($single_result != '' && !(array_key_exists('error_message', $single_result))) {
831 $is_free = ($single_result['is_free']) ? true : false;
832 } else {
833 $is_free = $this->mbv_wpcf7_validate_email_check_free( $_POST[$name] , $user_apikey );
834 }
835 } else {
836 $is_free = false;
837 }
838
839
840 if( $is_valid_email === false ){
841 if ( ($options['disposable_on_off'] === 'on') && ( $is_disposable === true ) ) {
842 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
843 } else {
844 $result->invalidate( $tags, __( $options['invalid_error_message'] ?? 'Please enter a valid email address.', 'email-validator-for-contact-form-7' ) );
845 }
846 // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
847 $wpdb->query('INSERT INTO ' . $table_name . ' (email_address, email_domain, status, is_disposable, is_free, is_role, is_blacklisted, date_created) VALUES ("' . $email . '", "' . $email_parts[1] . '", "' .$single_result['status']. '", "' .$single_result['is_disposable']. '", "' .$single_result['is_free']. '", "' .$single_result['is_role']. '", "False", "' . $datetime_started . '")');
848 // }
849 } elseif( $is_disposable === true ){
850 $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) );
851 // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
852 $wpdb->query('INSERT INTO ' . $table_name . ' (email_address, email_domain, status, is_disposable, is_free, is_role, is_blacklisted, date_created) VALUES ("' . $email . '", "' . $email_parts[1] . '", "-", "True", "-", "-", "False", "' . $datetime_started . '")');
853 // }
854 } elseif( $is_free === true ){
855 // $mbv_validation_result['status'] = false;
856 $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) );
857 // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
858 $wpdb->query('INSERT INTO ' . $table_name . ' (email_address, email_domain, status, is_disposable, is_free, is_role, is_blacklisted, date_created) VALUES ("' . $email . '", "' . $email_parts[1] . '", "-", "-", "True", "-", "False", "' . $datetime_started . '")');
859 // }
860 } elseif( $is_role === true ){
861 $result->invalidate( $tags, __( $options['role_error_message'] ?? 'Please enter a non-role email address.', 'email-validator-for-contact-form-7' ) );
862 // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) {
863 $wpdb->query('INSERT INTO ' . $table_name . ' (email_address, email_domain, status, is_disposable, is_free, is_role, is_blacklisted, date_created) VALUES ("' . $email . '", "' . $email_parts[1] . '", "' .$single_result['status']. '", "' .$single_result['is_disposable']. '", "' .$single_result['is_free']. '", "' .$single_result['is_role']. '", "False", "' . $datetime_started . '")');
864 // }
865 }
866
867 }
868
869 return $result;
870
871 }
872
873 private function mbv_wpcf7_mailboxvalidator_api_log ( $mode, $api_result1, $api_result2, $api_result3, $api_result4, $api_result5 ) {
874
875 // Log all the MBV api usage to the log file
876
877 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Email Address: ' . $api_result1 . PHP_EOL, FILE_APPEND );
878
879 /*
880 if ( $mode == 'disposable' ) {
881 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_disposable: ' . $api_result2 . PHP_EOL, FILE_APPEND );
882 } else {
883 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_free: ' . $api_result2 . PHP_EOL, FILE_APPEND );
884 }
885 */
886
887 file_put_contents( __DIR__ . '/mbv_api_logs.log', $mode . ': ' . $api_result2 . PHP_EOL, FILE_APPEND );
888
889 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Credits Available: ' . $api_result3 . PHP_EOL, FILE_APPEND );
890
891 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Code: ' . $api_result4 == '' ? $api_result4 : '-' . PHP_EOL, FILE_APPEND );
892
893 file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Message: ' . $api_result5 == '' ? $api_result5 : '-' . PHP_EOL, FILE_APPEND );
894
895 file_put_contents( __DIR__ . '/mbv_api_logs.log', str_repeat( '-', 120 ) . PHP_EOL, FILE_APPEND );
896
897 }
898
899 private function create_table()
900 {
901 $GLOBALS['wpdb']->query('
902 CREATE TABLE IF NOT EXISTS ' . $GLOBALS['wpdb']->prefix . 'email_validator_for_contact_form_7_log (
903 `log_id` INT(11) NOT NULL AUTO_INCREMENT,
904 `email_address` VARCHAR(255) NOT NULL COLLATE \'utf8_bin\',
905 `email_domain` VARCHAR(255) NOT NULL COLLATE \'utf8_bin\',
906 `status` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\',
907 `is_disposable` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\',
908 `is_free` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\',
909 `is_role` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\',
910 `is_blacklisted` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\',
911 `date_created` DATETIME NOT NULL,
912 PRIMARY KEY (`log_id`),
913 INDEX `idx_email_address` (`email_address`),
914 INDEX `idx_email_domain` (`email_domain`),
915 INDEX `idx_status` (`status`),
916 INDEX `idx_is_disposable` (`is_disposable`),
917 INDEX `idx_date_created` (`date_created`),
918 INDEX `idx_is_free` (`is_free`),
919 INDEX `idx_is_role` (`is_role`),
920 INDEX `idx_is_blacklisted` (`is_blacklisted`)
921 ) COLLATE=\'utf8_bin\'');
922 }
923 }
924