email-validator-for-contact-form-7
Last commit date
assets
7 months ago
languages
5 years ago
vendor
2 years ago
email-validator-for-contact-form-7.php
1 week ago
license.txt
7 years ago
readme.txt
1 week ago
uninstall.php
4 years ago
email-validator-for-contact-form-7.php
1068 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.8.3 |
| 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 | wp_enqueue_script( 'mbv_tagsinput_js', plugins_url( '/assets/js/jquery.tagsinput.min.js', __FILE__ ), [], null, true); |
| 139 | wp_enqueue_style( 'mbv_tagsinput_css', esc_url_raw( 'https://cdnjs.cloudflare.com/ajax/libs/jquery-tagsinput/1.3.6/jquery.tagsinput.min.css' ), [], null ); |
| 140 | |
| 141 | $this->create_table(); |
| 142 | |
| 143 | } |
| 144 | |
| 145 | // display the admin options page |
| 146 | public function mbv_wpcf7_plugin_options_page() |
| 147 | { |
| 148 | |
| 149 | $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'settings'; |
| 150 | |
| 151 | |
| 152 | echo ' |
| 153 | <div class="wrap"> |
| 154 | |
| 155 | <h2>Email Validator for Contact Form 7 by MailboxValidator</h2> |
| 156 | |
| 157 | <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> |
| 158 | |
| 159 | <!--<p>At here you can edit your MailboxValidator API key and switch on or off disposable or free email validator.</p>-->' . $this->admin_tabs() . ''; |
| 160 | |
| 161 | switch ($tab) { |
| 162 | // Statistic |
| 163 | case 'statistic': |
| 164 | global $wpdb; |
| 165 | |
| 166 | $table_name = $wpdb->prefix . 'email_validator_for_contact_form_7_log'; |
| 167 | |
| 168 | if (isset($_POST['purge'])) { |
| 169 | $wpdb->query('TRUNCATE TABLE ' . $table_name); |
| 170 | } |
| 171 | |
| 172 | // Remove logs older than 30 days. |
| 173 | $wpdb->query('DELETE FROM ' . $table_name . ' WHERE date_created <="' . date('Y-m-d H:i:s', strtotime('-30 days')) . '"'); |
| 174 | |
| 175 | // Prepare logs for last 30 days. |
| 176 | $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); |
| 177 | |
| 178 | $lines = []; |
| 179 | for ($d = 30; $d > 0; --$d) { |
| 180 | $lines[date('Y-m-d', strtotime('-' . $d . ' days'))] = 0; |
| 181 | } |
| 182 | |
| 183 | foreach ($results as $result) { |
| 184 | $lines[$result->date] = $result->total; |
| 185 | } |
| 186 | |
| 187 | ksort($lines); |
| 188 | |
| 189 | $labels = []; |
| 190 | $total_emails_blocked = []; |
| 191 | |
| 192 | foreach ($lines as $date => $value) { |
| 193 | $labels[] = $date; |
| 194 | $total_emails_blocked[] = ($value) ? $value : 0; |
| 195 | } |
| 196 | |
| 197 | // Add index to table id not exist. |
| 198 | $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); |
| 199 | |
| 200 | if ($results[0]->total == 0) { |
| 201 | $wpdb->query('ALTER TABLE `' . $table_name . '` ADD INDEX `idx_email_address` (`email_address`);'); |
| 202 | } |
| 203 | echo '<h3>Block Statistics For The Past 30 Days</h3> |
| 204 | |
| 205 | <p> |
| 206 | <canvas id="line_chart" style="width:100%;height:400px"></canvas> |
| 207 | </p> |
| 208 | |
| 209 | <div class="clear"></div> |
| 210 | |
| 211 | <p> |
| 212 | <form id="form-purge" method="post"> |
| 213 | <input type="hidden" name="purge" value="true"> |
| 214 | <input type="submit" name="submit" id="btn-purge" class="button button-primary" value="Purge All Logs" /> |
| 215 | </form> |
| 216 | </p> |
| 217 | |
| 218 | </div> |
| 219 | <script> |
| 220 | jQuery(document).ready(function($){ |
| 221 | function get_color(){ |
| 222 | var r = Math.floor(Math.random() * 200); |
| 223 | var g = Math.floor(Math.random() * 200); |
| 224 | var b = Math.floor(Math.random() * 200); |
| 225 | |
| 226 | return \'rgb(\' + r + \', \' + g + \', \' + b + \', 0.4)\'; |
| 227 | } |
| 228 | |
| 229 | var ctx = document.getElementById(\'line_chart\').getContext(\'2d\'); |
| 230 | var line = new Chart(ctx, { |
| 231 | type: \'line\', |
| 232 | data: { |
| 233 | labels: [\'' . implode('\', \'', $labels) . '\'], |
| 234 | datasets: [{ |
| 235 | label: \'Total Email Blocked\', |
| 236 | data: [' . implode(', ', $total_emails_blocked) . '], |
| 237 | backgroundColor: get_color() |
| 238 | }] |
| 239 | }, |
| 240 | options: { |
| 241 | title: { |
| 242 | display: true, |
| 243 | text: \'Total Email Blocked\' |
| 244 | }, |
| 245 | scales: { |
| 246 | yAxes: [{ |
| 247 | ticks: { |
| 248 | beginAtZero:true |
| 249 | } |
| 250 | }] |
| 251 | } |
| 252 | } |
| 253 | }); |
| 254 | }); |
| 255 | </script>'; |
| 256 | break; |
| 257 | case 'settings': |
| 258 | default: |
| 259 | $mbv_options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 260 | $api_key = isset( $mbv_options['api_key'] ) ? $mbv_options['api_key'] : ''; |
| 261 | if ( $api_key != '' ) { |
| 262 | $url = 'https://api.mailboxvalidator.com/plan?key=' . $api_key; |
| 263 | $results = wp_remote_get( $url ); |
| 264 | if ( !is_wp_error( $results ) ) { |
| 265 | $body = wp_remote_retrieve_body( $results ); |
| 266 | |
| 267 | // Decode the return json results and return the data. |
| 268 | $data = json_decode( $body, true ); |
| 269 | |
| 270 | if ( $data['plan_name'] != '' ) { |
| 271 | if ( $data['plan_name'] == 'API-FREE' ) { |
| 272 | $is_low_credit = ( $data['credits_available'] < 100 ) ? true : false ; |
| 273 | } else { |
| 274 | $is_low_credit = ( $data['credits_available'] < ( $data['credits_limit'] * 0.1 ) ) ? true : false ; |
| 275 | } |
| 276 | // Now print the plan info |
| 277 | echo '<h2>'. __('Plan Information', 'email-validator-for-contact-form-7' ) . '</h2><table class="form-table">'; |
| 278 | echo '<tr><th scope="row"><label>'. __('Plan Name', 'email-validator-for-contact-form-7' ) . '</label></th><td><p>' . $data['plan_name'] . '</p></td></tr>'; |
| 279 | // 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>'; |
| 280 | 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>'; |
| 281 | 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>'; |
| 282 | echo '</table>'; |
| 283 | echo '<a href="https://www.mailboxvalidator.com/login" target="_blank" class="button">Login to Account Area</a>'; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | echo '<form action="options.php" method="post">'; |
| 289 | |
| 290 | settings_fields( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 291 | |
| 292 | do_settings_sections( 'mbv_wpcf7_plugin' ); |
| 293 | echo '<br> |
| 294 | <hr> |
| 295 | <br>'; |
| 296 | do_settings_sections( 'mbv_wpcf7_plugin1' ); |
| 297 | echo '<br> |
| 298 | <hr> |
| 299 | <br>'; |
| 300 | do_settings_sections( 'mbv_wpcf7_plugin2' ); |
| 301 | echo '<br> |
| 302 | <hr> |
| 303 | <br>'; |
| 304 | do_settings_sections( 'mbv_wpcf7_plugin3' ); |
| 305 | echo '<br> |
| 306 | <hr> |
| 307 | <br>'; |
| 308 | do_settings_sections( 'mbv_wpcf7_plugin4' ); |
| 309 | echo '<br> |
| 310 | <hr> |
| 311 | <br>'; |
| 312 | do_settings_sections( 'mbv_wpcf7_plugin5' ); |
| 313 | echo '<br> |
| 314 | <hr> |
| 315 | <br>'; |
| 316 | do_settings_sections( 'mbv_wpcf7_plugin6' ); |
| 317 | |
| 318 | echo '<input name="Submit" type="submit" value="' . __( 'Save Changes' ) . '" class="button button-primary" /> |
| 319 | </form> |
| 320 | </div>'; |
| 321 | break; |
| 322 | |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | private function admin_tabs() |
| 327 | { |
| 328 | $disable_tabs = false; |
| 329 | |
| 330 | $tab = (isset($_GET['tab'])) ? $_GET['tab'] : 'settings'; |
| 331 | |
| 332 | return ' |
| 333 | ' . $this->global_status . ' |
| 334 | <h2 class="nav-tab-wrapper"> |
| 335 | <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> |
| 336 | <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> |
| 337 | </h2>'; |
| 338 | } |
| 339 | |
| 340 | public function mbv_wpcf7_plugin_admin_init() |
| 341 | { |
| 342 | |
| 343 | register_setting( 'mbv_wpcf7_email_validator_for_contact_form_7', 'mbv_wpcf7_email_validator_for_contact_form_7', [$this, 'mbv_wpcf7_sanitize_settings_input'] ); |
| 344 | |
| 345 | add_settings_section( 'mbv_wpcf7_plugin_main', __('Main Settings', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_plugin_section_text'], 'mbv_wpcf7_plugin' ); |
| 346 | add_settings_section( 'mbv_wpcf7_plugin_main1', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin1' ); |
| 347 | add_settings_section( 'mbv_wpcf7_plugin_main2', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin2' ); |
| 348 | add_settings_section( 'mbv_wpcf7_plugin_main3', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin3' ); |
| 349 | add_settings_section( 'mbv_wpcf7_plugin_main4', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin4' ); |
| 350 | add_settings_section( 'mbv_wpcf7_plugin_main5', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin5' ); |
| 351 | add_settings_section( 'mbv_wpcf7_plugin_main6', __('', 'email-validator-for-contact-form-7' ), '', 'mbv_wpcf7_plugin6' ); |
| 352 | |
| 353 | 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' ); |
| 354 | |
| 355 | 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' ); |
| 356 | |
| 357 | 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' ); |
| 358 | |
| 359 | 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' ); |
| 360 | |
| 361 | 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' ); |
| 362 | |
| 363 | 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' ); |
| 364 | |
| 365 | 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' ); |
| 366 | |
| 367 | 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' ); |
| 368 | |
| 369 | 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' ); |
| 370 | |
| 371 | add_settings_field( 'mbv_wpcf7_custom_domain_blacklist', __('Block Custom Email Domains', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_custom_domain_blacklist_option'], 'mbv_wpcf7_plugin5', 'mbv_wpcf7_plugin_main5' ); |
| 372 | |
| 373 | add_settings_field( 'mbv_wpcf7_custom_domain_error_message', __('Error Message for Custom Email Domain', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_custom_domain_error_message_setting'], 'mbv_wpcf7_plugin5', 'mbv_wpcf7_plugin_main5' ); |
| 374 | |
| 375 | add_settings_field( 'mbv_wpcf7_trusted_domain', __('Add Trusted Email Domain', 'email-validator-for-contact-form-7' ), [$this, 'mbv_wpcf7_trusted_domain_option'], 'mbv_wpcf7_plugin6', 'mbv_wpcf7_plugin_main6' ); |
| 376 | |
| 377 | } |
| 378 | |
| 379 | public function mbv_wpcf7_sanitize_settings_input($input){ |
| 380 | // Check the values of radio buttons |
| 381 | if (! in_array($input['invalid_on_off'], array('on', 'off'))) { |
| 382 | add_settings_error( |
| 383 | 'mbv_wpcf7_invalid_error_message', // setting title |
| 384 | 'mbv_wpcf7_optionerror', // error ID |
| 385 | 'Invalid option value detected.', // error message |
| 386 | 'error' // type of message |
| 387 | ); |
| 388 | $input['invalid_on_off'] = 'on'; |
| 389 | } |
| 390 | if (! in_array($input['disposable_on_off'], array('on', 'off'))) { |
| 391 | add_settings_error( |
| 392 | 'mbv_wpcf7_disposable_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['disposable_on_off'] = 'on'; |
| 398 | } |
| 399 | if (! in_array($input['free_on_off'], array('on', 'off'))) { |
| 400 | add_settings_error( |
| 401 | 'mbv_wpcf7_free_on_off', // setting title |
| 402 | 'mbv_wpcf7_optionerror', // error ID |
| 403 | 'Invalid option value detected.', // error message |
| 404 | 'error' // type of message |
| 405 | ); |
| 406 | $input['free_on_off'] = 'on'; |
| 407 | } |
| 408 | if (! in_array($input['role_on_off'], array('on', 'off'))) { |
| 409 | add_settings_error( |
| 410 | 'mbv_wpcf7_role_on_off', // setting title |
| 411 | 'mbv_wpcf7_optionerror', // error ID |
| 412 | 'Invalid option value detected.', // error message |
| 413 | 'error' // type of message |
| 414 | ); |
| 415 | $input['role_on_off'] = 'on'; |
| 416 | } |
| 417 | // Check for blacklisted_domains input |
| 418 | if (isset($input['blacklisted_domains'])) { |
| 419 | if (empty($input['blacklisted_domains'])) { |
| 420 | // empty, let it pass |
| 421 | } else if (strpos(';', $input['blacklisted_domains']) == False) { |
| 422 | // one domain |
| 423 | if (filter_var($input['blacklisted_domains'], FILTER_VALIDATE_DOMAIN) == False) { |
| 424 | add_settings_error( |
| 425 | 'mbv_wpcf7_blacklisted_domains', // setting title |
| 426 | 'mbv_wpcf7_optionerror', // error ID |
| 427 | 'Invalid domain name detected.', // error message |
| 428 | 'error' // type of message |
| 429 | ); |
| 430 | } |
| 431 | } else if (strpos(';', $input['blacklisted_domains']) != False){ |
| 432 | // multiple domains(seperated by ;) |
| 433 | $blacklisted_domains_array = explode( ';', $input['blacklisted_domains'] ); |
| 434 | foreach ($blacklisted_domains_array as $array_key => $domain) { |
| 435 | if (filter_var($domain, FILTER_VALIDATE_DOMAIN) == False) { |
| 436 | add_settings_error( |
| 437 | 'mbv_wpcf7_blacklisted_domains', // setting title |
| 438 | 'mbv_wpcf7_optionerror', // error ID |
| 439 | 'Invalid domain name detected.', // error message |
| 440 | 'error' // type of message |
| 441 | ); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | // Check for trusted_domains input |
| 447 | if (isset($input['trusted_domains'])) { |
| 448 | if (empty($input['trusted_domains'])) { |
| 449 | // empty, let it pass |
| 450 | } else if (strpos(';', $input['trusted_domains']) == False) { |
| 451 | // one domain |
| 452 | if (filter_var($input['trusted_domains'], FILTER_VALIDATE_DOMAIN) == False) { |
| 453 | add_settings_error( |
| 454 | 'mbv_wpcf7_blacklisted_domains', // setting title |
| 455 | 'mbv_wpcf7_optionerror', // error ID |
| 456 | 'Invalid domain name detected.', // error message |
| 457 | 'error' // type of message |
| 458 | ); |
| 459 | } |
| 460 | } else if (strpos(';', $input['trusted_domains']) != False){ |
| 461 | // multiple domains(seperated by ;) |
| 462 | $trusted_domains_array = explode( ';', $input['trusted_domains'] ); |
| 463 | foreach ($trusted_domains_array as $array_key => $domain) { |
| 464 | if (filter_var($domain, FILTER_VALIDATE_DOMAIN) == False) { |
| 465 | add_settings_error( |
| 466 | 'mbv_wpcf7_blacklisted_domains', // setting title |
| 467 | 'mbv_wpcf7_optionerror', // error ID |
| 468 | 'Invalid domain name detected.', // error message |
| 469 | 'error' // type of message |
| 470 | ); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | // Sanitize inputs |
| 476 | $input['api_key'] = strip_tags(stripslashes( $input['api_key'] )); |
| 477 | $input['invalid_on_off'] = strip_tags(stripslashes( $input['invalid_on_off'] )); |
| 478 | $input['disposable_on_off'] = strip_tags(stripslashes( $input['disposable_on_off'] )); |
| 479 | $input['free_on_off'] = strip_tags(stripslashes( $input['free_on_off'] )); |
| 480 | $input['role_on_off'] = strip_tags(stripslashes( $input['role_on_off'] )); |
| 481 | $input['invalid_error_message'] = strip_tags(stripslashes( $input['invalid_error_message'] )); |
| 482 | $input['disposable_error_message'] = strip_tags(stripslashes( $input['disposable_error_message'] )); |
| 483 | $input['free_error_message'] = strip_tags(stripslashes( $input['free_error_message'] )); |
| 484 | $input['role_error_message'] = strip_tags(stripslashes( $input['role_error_message'] )); |
| 485 | $input['custom_domain_error_message'] = strip_tags(stripslashes( $input['custom_domain_error_message'] )); |
| 486 | $input['blacklisted_domains'] = strip_tags(stripslashes( $input['blacklisted_domains'] )); |
| 487 | $input['trusted_domains'] = strip_tags(stripslashes( $input['trusted_domains'] )); |
| 488 | return $input; |
| 489 | } |
| 490 | |
| 491 | public function mbv_wpcf7_plugin_section_text() |
| 492 | { |
| 493 | |
| 494 | echo '<p>'. __('Please enter a MailboxValidator API key to enable the email blocking.', 'email-validator-for-contact-form-7' ) . '</p>'; |
| 495 | |
| 496 | } |
| 497 | |
| 498 | public function mbv_wpcf7_api_key_setting() |
| 499 | { |
| 500 | |
| 501 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 502 | |
| 503 | $api_key = $options['api_key'] ?? ' '; |
| 504 | |
| 505 | 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 ). '" />'; |
| 506 | |
| 507 | } |
| 508 | |
| 509 | public function mbv_wpcf7_invalid_setting_option() |
| 510 | { |
| 511 | |
| 512 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 513 | |
| 514 | $invalid_on_off = $options['invalid_on_off'] ?? 'on'; |
| 515 | |
| 516 | 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> |
| 517 | <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 />'; |
| 518 | |
| 519 | } |
| 520 | |
| 521 | public function mbv_wpcf7_disposable_setting_option() |
| 522 | { |
| 523 | |
| 524 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 525 | |
| 526 | $disposable_on_off = $options['disposable_on_off'] ?? 'on'; |
| 527 | |
| 528 | 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> |
| 529 | <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 />'; |
| 530 | |
| 531 | } |
| 532 | |
| 533 | public function mbv_wpcf7_free_setting_option() |
| 534 | { |
| 535 | |
| 536 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 537 | |
| 538 | $free_on_off = $options['free_on_off'] ?? 'on'; |
| 539 | |
| 540 | 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> |
| 541 | <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 />'; |
| 542 | |
| 543 | } |
| 544 | |
| 545 | public function mbv_wpcf7_role_setting_option() |
| 546 | { |
| 547 | |
| 548 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 549 | |
| 550 | $role_on_off = $options['role_on_off'] ?? 'on'; |
| 551 | |
| 552 | 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> |
| 553 | <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 />'; |
| 554 | |
| 555 | } |
| 556 | |
| 557 | public function mbv_wpcf7_custom_domain_blacklist_option() |
| 558 | { |
| 559 | |
| 560 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 561 | $blacklisted_domains = isset( $options['blacklisted_domains'] ) ? $options['blacklisted_domains'] : ''; |
| 562 | echo '<input id="blacklist_domain" name="mbv_wpcf7_email_validator_for_contact_form_7[blacklisted_domains]" size="40" type="text" value="' . $blacklisted_domains . '" style="margin-bottom: 5px;"/><br />'; |
| 563 | // echo '<textarea id="blacklist_domain" name="mbv_wpcf7_email_validator_for_contact_form_7[blacklisted_domains]" rows="10" cols="70">' . $blacklisted_domains. '</textarea>'; |
| 564 | echo '<label>'; |
| 565 | _e( 'Block email domains from registering for your service. Please enter one domain name in each row.', 'email-validator-for-contact-form-7' ); |
| 566 | echo '</label>'; |
| 567 | } |
| 568 | |
| 569 | public function mbv_wpcf7_trusted_domain_option() |
| 570 | { |
| 571 | |
| 572 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 573 | $trusted_domains = isset( $options['trusted_domains'] ) ? $options['trusted_domains'] : ''; |
| 574 | echo '<input id="trusted_domain" name="mbv_wpcf7_email_validator_for_contact_form_7[trusted_domains]" size="40" type="text" value="' . $trusted_domains . '" style="margin-bottom: 5px;"/><br />'; |
| 575 | // echo '<textarea id="whitelist_domain" name="mbv_wpcf7_email_validator_for_contact_form_7[trusted_domains]" rows="10" cols="70">' . $trusted_domains. '</textarea>'; |
| 576 | echo '<label>'; |
| 577 | _e( 'Email addresses from these domains will be treated as safe and will skip further validation checks. Please enter one domain name in each row.', 'email-validator-for-contact-form-7' ); |
| 578 | echo '</label>'; |
| 579 | } |
| 580 | |
| 581 | public function mbv_wpcf7_invalid_error_message_setting() |
| 582 | { |
| 583 | |
| 584 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 585 | |
| 586 | $invalid_error_message = $options['invalid_error_message'] ?? __('Please enter a valid email address.', 'email-validator-for-contact-form-7' ); |
| 587 | |
| 588 | $invalid_on_off = $options['invalid_on_off'] ?? 'on'; |
| 589 | |
| 590 | 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"/>'; |
| 591 | echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>'; |
| 592 | |
| 593 | } |
| 594 | |
| 595 | public function mbv_wpcf7_disposable_error_message_setting() |
| 596 | { |
| 597 | |
| 598 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 599 | |
| 600 | $disposable_error_message = $options['disposable_error_message'] ?? __('Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ); |
| 601 | |
| 602 | $disposable_on_off = $options['disposable_on_off'] ?? 'on'; |
| 603 | |
| 604 | 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"/>'; |
| 605 | echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>'; |
| 606 | |
| 607 | } |
| 608 | |
| 609 | public function mbv_wpcf7_free_error_message_setting() |
| 610 | { |
| 611 | |
| 612 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 613 | |
| 614 | $free_error_message = $options['free_error_message'] ?? __('Please enter a non-free email address.', 'email-validator-for-contact-form-7' ); |
| 615 | |
| 616 | $free_on_off = $options['free_on_off'] ?? 'on'; |
| 617 | |
| 618 | 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"/>'; |
| 619 | echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>'; |
| 620 | |
| 621 | } |
| 622 | |
| 623 | public function mbv_wpcf7_role_error_message_setting() |
| 624 | { |
| 625 | |
| 626 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 627 | |
| 628 | $role_error_message = $options['role_error_message'] ?? __('Please enter a non-role based email address.', 'email-validator-for-contact-form-7' ); |
| 629 | |
| 630 | $role_on_off = $options['role_on_off'] ?? 'on'; |
| 631 | |
| 632 | 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"/>'; |
| 633 | echo '<p id="errormessage-hint" style="color:#666666;font-style: italic;" >Your error message should be not more than 255 characters.</p>'; |
| 634 | |
| 635 | } |
| 636 | |
| 637 | public function mbv_wpcf7_custom_domain_error_message_setting() |
| 638 | { |
| 639 | |
| 640 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 641 | $custom_domain_error_message = $options['custom_domain_error_message'] ?? 'This email address domain has been denied access.'; |
| 642 | echo '<input id="custom_domain_error_message" name="mbv_wpcf7_email_validator_for_contact_form_7[custom_domain_error_message]" style="width:100%" type="text" value="' . $custom_domain_error_message . '" maxlength="255" />'; |
| 643 | echo '<label>Design your custom error message for blocked email domain(s).</label>'; |
| 644 | |
| 645 | } |
| 646 | |
| 647 | // function mbv_wpcf7_string_length( $string ){ |
| 648 | |
| 649 | // return mb_strlen( $string ); |
| 650 | |
| 651 | // } |
| 652 | |
| 653 | // Enqueue the script. |
| 654 | public function plugin_enqueues( $hook ) |
| 655 | { |
| 656 | |
| 657 | // if ( $hook == 'options-general.php' ) { |
| 658 | // wp_enqueue_script( 'email_validator_for_contact_form_7_admin_setting_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true ); |
| 659 | // } |
| 660 | |
| 661 | if ( $hook == 'plugins.php' ) { |
| 662 | // Add in required libraries for feedback modal |
| 663 | wp_enqueue_script( 'jquery-ui-dialog' ); |
| 664 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 665 | |
| 666 | wp_enqueue_script( 'email_validator_for_contact_form_7_admin_script', plugins_url( '/assets/js/feedback.js', __FILE__ ), ['jquery'], null, true ); |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | public function admin_footer_text( $footer_text ) |
| 671 | { |
| 672 | // $plugin_name = substr( basename( __FILE__ ), 0, strpos( basename( __FILE__ ), '.' ) ); |
| 673 | $plugin_name = 'email-validator-for-contact-form-7'; |
| 674 | $current_screen = get_current_screen(); |
| 675 | |
| 676 | if ( ( $current_screen && strpos( $current_screen->id, $plugin_name ) !== false ) ) { |
| 677 | $footer_text .= sprintf( |
| 678 | __( 'Love our plugin? Please leave us a %1$s rating. A huge thanks in advance!', $plugin_name ), |
| 679 | '<a href="https://wordpress.org/support/plugin/' . $plugin_name . '/reviews/?filter=5/#new-post" target="_blank">★★★★★</a>' |
| 680 | ); |
| 681 | } |
| 682 | |
| 683 | if ( $current_screen->id == 'plugins' ) { |
| 684 | return $footer_text . ' |
| 685 | <div id="email-validator-for-contact-form-7-feedback-modal" class="hidden" style="max-width:800px"> |
| 686 | <span id="email-validator-for-contact-form-7-feedback-response"></span> |
| 687 | <p> |
| 688 | <strong>'. __('Would you mind sharing with us the reason to deactivate the plugin', 'email-validator-for-contact-form-7' ) . '?</strong> |
| 689 | </p> |
| 690 | <p> |
| 691 | <label> |
| 692 | <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' ) . ' |
| 693 | </label> |
| 694 | </p> |
| 695 | <p> |
| 696 | <label> |
| 697 | <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' ) . ' |
| 698 | </label> |
| 699 | </p> |
| 700 | <p> |
| 701 | <label> |
| 702 | <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' ) . ' |
| 703 | </label> |
| 704 | </p> |
| 705 | <p> |
| 706 | <label> |
| 707 | <input type="radio" name="email-validator-for-contact-form-7-feedback" value="4"> '. __('Other concerns', 'email-validator-for-contact-form-7' ) . ' |
| 708 | <br><br> |
| 709 | <textarea id="email-validator-for-contact-form-7-feedback-other" style="display:none;width:100%"></textarea> |
| 710 | </label> |
| 711 | </p> |
| 712 | <p> |
| 713 | <div style="float:left"> |
| 714 | <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' ) . '" /> |
| 715 | </div> |
| 716 | <div style="float:right"> |
| 717 | <a href="#">'. __('Skip & Deactivate', 'email-validator-for-contact-form-7' ) . '</a> |
| 718 | </div> |
| 719 | </p> |
| 720 | </div>'; |
| 721 | } |
| 722 | |
| 723 | return $footer_text; |
| 724 | } |
| 725 | |
| 726 | public function submit_feedback() |
| 727 | { |
| 728 | |
| 729 | $feedback = ( isset( $_POST['feedback'] ) ) ? $_POST['feedback'] : ''; |
| 730 | $others = sanitize_text_field (( isset( $_POST['others'] ) ) ? $_POST['others'] : '' ); |
| 731 | |
| 732 | $options = [ |
| 733 | 1 => 'I no longer need the plugin', |
| 734 | 2 => 'I couldn\'t get the plugin to work', |
| 735 | 3 => 'The plugin doesn\'t meet my requirements', |
| 736 | 4 => 'Other concerns' . ( ( $others ) ? ( ' - ' . $others ) : '' ), |
| 737 | ]; |
| 738 | |
| 739 | $url = 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( ['name' => 'email-validator-for-contact-form-7', 'message' => $options[$feedback],] ); |
| 740 | // file_put_contents ( __DIR__ . '/mbv_plugin_logs.log' , $url . PHP_EOL, FILE_APPEND ); |
| 741 | |
| 742 | if ( isset( $options[$feedback] ) ) { |
| 743 | if ( !class_exists( 'WP_Http' ) ) { |
| 744 | include_once ABSPATH . WPINC . '/class-http.php'; |
| 745 | } |
| 746 | |
| 747 | $request = new WP_Http(); |
| 748 | $response = $request->request( 'https://www.mailboxvalidator.com/wp-plugin-feedback?' . http_build_query( [ |
| 749 | 'name' => 'email-validator-for-contact-form-7', |
| 750 | 'message' => $options[$feedback], |
| 751 | ] ), ['timeout' => 5] ); |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | function mbv_wpcf7_single( $emailAddress, $api_key ) { |
| 756 | |
| 757 | try{ |
| 758 | |
| 759 | $mbv = new \MailboxValidator\EmailValidation ($api_key); |
| 760 | $results = $mbv->validateEmail(str_replace( ' ', '', $emailAddress )); |
| 761 | |
| 762 | if ($results != null) { |
| 763 | foreach ($results as $key => $value) { |
| 764 | $data[$key] = $value; |
| 765 | } |
| 766 | return $data; |
| 767 | } else { |
| 768 | return true; |
| 769 | } |
| 770 | } |
| 771 | catch( Exception $e ) { |
| 772 | return true; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | private function mbv_wpcf7_is_valid_email( $api_result ) { |
| 777 | |
| 778 | if ( $api_result != '' ) { |
| 779 | if ( !isset( $api_result['error_code'] ) ) { |
| 780 | if ( $api_result['status'] ) { |
| 781 | return true; |
| 782 | } else { |
| 783 | return false; |
| 784 | } |
| 785 | } else { |
| 786 | // If error message occured, let it pass first. |
| 787 | return true; |
| 788 | } |
| 789 | } else { |
| 790 | // If error message occured, let it pass first. |
| 791 | return true; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | private function mbv_wpcf7_is_role_email( $api_result ) { |
| 796 | |
| 797 | if ( $api_result != '' ) { |
| 798 | if ( !isset( $api_result['error_code'] ) ) { |
| 799 | if ( $api_result['is_role'] ) { |
| 800 | return true; |
| 801 | } else { |
| 802 | return false; |
| 803 | } |
| 804 | } else { |
| 805 | // If error message occured, let it pass first. |
| 806 | return false; |
| 807 | } |
| 808 | } else { |
| 809 | // If error message occured, let it pass first. |
| 810 | return false; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | private function mbv_wpcf7_validate_email_check_free( $emailAddress, $api_key ) { |
| 815 | |
| 816 | $mbv = new \MailboxValidator\EmailValidation ($api_key); |
| 817 | $results = $mbv->isFreeEmail(str_replace( ' ', '', $emailAddress )); |
| 818 | |
| 819 | // if ( $data['error_message'] == '' ) { |
| 820 | if ($results != null) { |
| 821 | if ( !isset( $results->error_code ) ) { |
| 822 | |
| 823 | // if ( $data['is_free'] == 'False' ) { |
| 824 | if ( $results->is_free ) { |
| 825 | |
| 826 | return true; |
| 827 | |
| 828 | } else { |
| 829 | |
| 830 | return false; |
| 831 | |
| 832 | } |
| 833 | |
| 834 | } else { |
| 835 | return false; |
| 836 | } |
| 837 | } else { |
| 838 | return false; |
| 839 | } |
| 840 | |
| 841 | } |
| 842 | |
| 843 | private function mbv_wpcf7_validate_email_check_disposable( $emailAddress, $api_key ) { |
| 844 | |
| 845 | $mbv = new \MailboxValidator\EmailValidation ($api_key); |
| 846 | $results = $mbv->isDisposableEmail(str_replace( ' ', '', $emailAddress )); |
| 847 | |
| 848 | // if ( $data['error_message'] == '' ) { |
| 849 | if ($results != null) { |
| 850 | if ( !isset( $results->error_code ) ) { |
| 851 | |
| 852 | // if ( $data['is_disposable'] == 'False' ) { |
| 853 | if ( $results->is_disposable ) { |
| 854 | |
| 855 | return true; |
| 856 | |
| 857 | } else { |
| 858 | |
| 859 | return false; |
| 860 | |
| 861 | } |
| 862 | |
| 863 | } else { |
| 864 | return false; |
| 865 | } |
| 866 | } else { |
| 867 | return false; |
| 868 | } |
| 869 | |
| 870 | } |
| 871 | |
| 872 | public function mbv_wpcf7_custom_email_validator_filter( $result, $tags ) { |
| 873 | global $wpdb; |
| 874 | |
| 875 | $datetime_started = date('Y-m-d H:i:s'); |
| 876 | |
| 877 | $table_name = $wpdb->prefix . 'email_validator_for_contact_form_7_log'; |
| 878 | |
| 879 | // Get option settings to know which validator is been called |
| 880 | |
| 881 | $options = get_option( 'mbv_wpcf7_email_validator_for_contact_form_7' ); |
| 882 | |
| 883 | $user_apikey = trim($options['api_key']); |
| 884 | |
| 885 | $tags = new WPCF7_FormTag( $tags ); |
| 886 | |
| 887 | $type = $tags->type; |
| 888 | |
| 889 | $name = $tags->name; |
| 890 | |
| 891 | $email = $_POST[$name]; |
| 892 | |
| 893 | |
| 894 | $email_parts = explode( '@', $email ); |
| 895 | |
| 896 | // 20240122: Check for email syntax to prevent pen test |
| 897 | if ( ( 'email' === $type || 'email*' === $type ) && (filter_var(trim($_POST[$name]), FILTER_VALIDATE_EMAIL)) && !( $user_apikey === '' ) && (preg_match('/^[A-Z\d]+$/', $user_apikey)) ) { |
| 898 | |
| 899 | // do validation for disposable and free |
| 900 | |
| 901 | /* |
| 902 | if( $options['disposable_on_off'] == 'on' ){ |
| 903 | |
| 904 | 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 ); |
| 905 | if( ( mbv_wpcf7_validate_email_check_disposable( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true){ |
| 906 | |
| 907 | $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) ); |
| 908 | |
| 909 | }elseif ( $options['free_on_off'] == 'on' ){ |
| 910 | |
| 911 | if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){ |
| 912 | |
| 913 | $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) ); |
| 914 | |
| 915 | } |
| 916 | |
| 917 | } |
| 918 | |
| 919 | } elseif ( $options['free_on_off'] == 'on' ){ |
| 920 | |
| 921 | if( ( mbv_wpcf7_validate_email_check_free( sanitize_email ( $_POST[$name] ), $options['api_key'] ) ) == true ){ |
| 922 | |
| 923 | $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) ); |
| 924 | |
| 925 | } |
| 926 | |
| 927 | }*/ |
| 928 | if ( ! empty( $options['trusted_domains'] ) ) { |
| 929 | $trusted_domains_array = explode( ';', $options['trusted_domains'] ); |
| 930 | if ( ( isset( $email_parts[1] ) ) && ( in_array( $email_parts[1], $trusted_domains_array ) ) ) { |
| 931 | // Immediately skip the rest of the validation |
| 932 | return $result; |
| 933 | } |
| 934 | } |
| 935 | // First check the domain blacklisted list, if the domain is in the list, straight return false |
| 936 | $is_domain_blacklisted = false; |
| 937 | if ( ! empty( $options['blacklisted_domains'] ) ) { |
| 938 | $blacklisted_domains_array = explode( ';', $options['blacklisted_domains'] ); |
| 939 | |
| 940 | // $email_parts = explode( '@', $email ); |
| 941 | |
| 942 | if ( ( isset( $email_parts[1] ) ) && ( in_array( $email_parts[1], $blacklisted_domains_array ) ) ) { |
| 943 | |
| 944 | // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { |
| 945 | $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", "' . $datetime_started . '")'); |
| 946 | // } |
| 947 | |
| 948 | // return false; |
| 949 | // $mbv_validation_result['status'] = false; |
| 950 | // $mbv_validation_result['reason'] = 'blacklisted_domains'; |
| 951 | // return $mbv_validation_result; |
| 952 | $is_domain_blacklisted = true; |
| 953 | } |
| 954 | } |
| 955 | if ($is_domain_blacklisted) { |
| 956 | $result->invalidate( $tags, __( $options['custom_domain_error_message'] ?? 'This email address domain has been denied access.', 'email-validator-for-contact-form-7' ) ); |
| 957 | } else { |
| 958 | $single_result = $options['invalid_on_off'] == 'on' || $options['role_on_off'] == 'on' ? $this->mbv_wpcf7_single( $_POST[$name], $user_apikey ) : ''; |
| 959 | $is_valid_email = $options['invalid_on_off'] == 'on' && $single_result != '' ? $this->mbv_wpcf7_is_valid_email( $single_result ) : true; |
| 960 | $is_role = $options['role_on_off'] == 'on' && $single_result != '' ? $this->mbv_wpcf7_is_role_email( $single_result ) : false; |
| 961 | // $is_disposable = $options['disposable_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_disposable( $_POST[$name] , $options['api_key'] ) : false; |
| 962 | // $is_free = $options['free_on_off'] == 'on' ? mbv_wpcf7_validate_email_check_free( $_POST[$name] , $options['api_key'] ) : false; |
| 963 | if ($options['disposable_on_off'] === 'on') { |
| 964 | if ($single_result != '' && !(array_key_exists('error_message', $single_result))) { |
| 965 | $is_disposable = ($single_result['is_disposable']) ? true : false; |
| 966 | } else { |
| 967 | $is_disposable = $this->mbv_wpcf7_validate_email_check_disposable( $_POST[$name] , $user_apikey ); |
| 968 | } |
| 969 | } else { |
| 970 | $is_disposable = false; |
| 971 | } |
| 972 | if ($options['free_on_off'] === 'on') { |
| 973 | if ($single_result != '' && !(array_key_exists('error_message', $single_result))) { |
| 974 | $is_free = ($single_result['is_free']) ? true : false; |
| 975 | } else { |
| 976 | $is_free = $this->mbv_wpcf7_validate_email_check_free( $_POST[$name] , $user_apikey ); |
| 977 | } |
| 978 | } else { |
| 979 | $is_free = false; |
| 980 | } |
| 981 | |
| 982 | |
| 983 | if( $is_valid_email === false ){ |
| 984 | if ( ($options['disposable_on_off'] === 'on') && ( $is_disposable === true ) ) { |
| 985 | $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) ); |
| 986 | } else { |
| 987 | $result->invalidate( $tags, __( $options['invalid_error_message'] ?? 'Please enter a valid email address.', 'email-validator-for-contact-form-7' ) ); |
| 988 | } |
| 989 | // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { |
| 990 | $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 . '")'); |
| 991 | // } |
| 992 | } elseif( $is_disposable === true ){ |
| 993 | $result->invalidate( $tags, __( $options['disposable_error_message'] ?? 'Please enter a non-disposable email address.', 'email-validator-for-contact-form-7' ) ); |
| 994 | // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { |
| 995 | $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 . '")'); |
| 996 | // } |
| 997 | } elseif( $is_free === true ){ |
| 998 | // $mbv_validation_result['status'] = false; |
| 999 | $result->invalidate( $tags, __( $options['free_error_message'] ?? 'Please enter a non-free email address.', 'email-validator-for-contact-form-7' ) ); |
| 1000 | // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { |
| 1001 | $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 . '")'); |
| 1002 | // } |
| 1003 | } elseif( $is_role === true ){ |
| 1004 | $result->invalidate( $tags, __( $options['role_error_message'] ?? 'Please enter a non-role email address.', 'email-validator-for-contact-form-7' ) ); |
| 1005 | // if (get_option('ip2location_country_blocker_log_enabled') && $wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { |
| 1006 | $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 . '")'); |
| 1007 | // } |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | } |
| 1012 | |
| 1013 | return $result; |
| 1014 | |
| 1015 | } |
| 1016 | |
| 1017 | private function mbv_wpcf7_mailboxvalidator_api_log ( $mode, $api_result1, $api_result2, $api_result3, $api_result4, $api_result5 ) { |
| 1018 | |
| 1019 | // Log all the MBV api usage to the log file |
| 1020 | |
| 1021 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Email Address: ' . $api_result1 . PHP_EOL, FILE_APPEND ); |
| 1022 | |
| 1023 | /* |
| 1024 | if ( $mode == 'disposable' ) { |
| 1025 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_disposable: ' . $api_result2 . PHP_EOL, FILE_APPEND ); |
| 1026 | } else { |
| 1027 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'is_free: ' . $api_result2 . PHP_EOL, FILE_APPEND ); |
| 1028 | } |
| 1029 | */ |
| 1030 | |
| 1031 | file_put_contents( __DIR__ . '/mbv_api_logs.log', $mode . ': ' . $api_result2 . PHP_EOL, FILE_APPEND ); |
| 1032 | |
| 1033 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Credits Available: ' . $api_result3 . PHP_EOL, FILE_APPEND ); |
| 1034 | |
| 1035 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Code: ' . $api_result4 == '' ? $api_result4 : '-' . PHP_EOL, FILE_APPEND ); |
| 1036 | |
| 1037 | file_put_contents( __DIR__ . '/mbv_api_logs.log', 'Error Message: ' . $api_result5 == '' ? $api_result5 : '-' . PHP_EOL, FILE_APPEND ); |
| 1038 | |
| 1039 | file_put_contents( __DIR__ . '/mbv_api_logs.log', str_repeat( '-', 120 ) . PHP_EOL, FILE_APPEND ); |
| 1040 | |
| 1041 | } |
| 1042 | |
| 1043 | private function create_table() |
| 1044 | { |
| 1045 | $GLOBALS['wpdb']->query(' |
| 1046 | CREATE TABLE IF NOT EXISTS ' . $GLOBALS['wpdb']->prefix . 'email_validator_for_contact_form_7_log ( |
| 1047 | `log_id` INT(11) NOT NULL AUTO_INCREMENT, |
| 1048 | `email_address` VARCHAR(255) NOT NULL COLLATE \'utf8_bin\', |
| 1049 | `email_domain` VARCHAR(255) NOT NULL COLLATE \'utf8_bin\', |
| 1050 | `status` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\', |
| 1051 | `is_disposable` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\', |
| 1052 | `is_free` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\', |
| 1053 | `is_role` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\', |
| 1054 | `is_blacklisted` VARCHAR(10) NOT NULL COLLATE \'utf8_bin\', |
| 1055 | `date_created` DATETIME NOT NULL, |
| 1056 | PRIMARY KEY (`log_id`), |
| 1057 | INDEX `idx_email_address` (`email_address`), |
| 1058 | INDEX `idx_email_domain` (`email_domain`), |
| 1059 | INDEX `idx_status` (`status`), |
| 1060 | INDEX `idx_is_disposable` (`is_disposable`), |
| 1061 | INDEX `idx_date_created` (`date_created`), |
| 1062 | INDEX `idx_is_free` (`is_free`), |
| 1063 | INDEX `idx_is_role` (`is_role`), |
| 1064 | INDEX `idx_is_blacklisted` (`is_blacklisted`) |
| 1065 | ) COLLATE=\'utf8_bin\''); |
| 1066 | } |
| 1067 | } |
| 1068 |