| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVFormTesting')) : |
| 5 |
|
| 6 |
class BVFormTesting { |
| 7 |
private $form_type; |
| 8 |
private $form_id; |
| 9 |
private $spam_bypass; |
| 10 |
private $bypass_params = array(); |
| 11 |
|
| 12 |
public function __construct($params) { |
| 13 |
$this->form_type = isset($params['bv_frm_typ']) ? sanitize_text_field(wp_unslash($params['bv_frm_typ'])) : null; |
| 14 |
$this->form_id = isset($params['bv_frm_id']) ? sanitize_text_field(wp_unslash($params['bv_frm_id'])) : null; |
| 15 |
$this->spam_bypass = isset($params['bv_ignr_spm_plgns']); |
| 16 |
|
| 17 |
if (isset($params['bv_ignr_frm_cptch'])) { |
| 18 |
$this->bypass_params['should_bypass_captcha'] = true; |
| 19 |
} |
| 20 |
|
| 21 |
if (isset($params['bv_ignr_eml'])) { |
| 22 |
$this->bypass_params['should_bypass_email'] = true; |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
public function init() { |
| 27 |
if ($this->spam_bypass === true) { |
| 28 |
$this->bypassSpamPlugins(); |
| 29 |
} |
| 30 |
|
| 31 |
$handler = $this->getHandler($this->form_type); |
| 32 |
if ($handler === null) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
if (empty($this->bypass_params) === false) { |
| 37 |
$handler->bypass(); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
private function getHandler($form_type) { |
| 42 |
switch ($form_type) { |
| 43 |
case 'ContactForm7': |
| 44 |
require_once dirname(__FILE__) . '/handlers/contact_form7.php'; |
| 45 |
return new BVContactForm7Handler($this->form_id, $this->bypass_params); |
| 46 |
case 'WPForm': |
| 47 |
require_once dirname(__FILE__) . '/handlers/wp_form.php'; |
| 48 |
return new BVWPFormHandler($this->form_id, $this->bypass_params); |
| 49 |
case 'NinjaForm': |
| 50 |
require_once dirname(__FILE__) . '/handlers/ninja_form.php'; |
| 51 |
return new BVNinjaFormHandler($this->form_id, $this->bypass_params); |
| 52 |
case 'ForminatorForm': |
| 53 |
require_once dirname(__FILE__) . '/handlers/forminator_form.php'; |
| 54 |
return new BVForminatorFormHandler($this->form_id, $this->bypass_params); |
| 55 |
case 'GravityForm': |
| 56 |
require_once dirname(__FILE__) . '/handlers/gravity_form.php'; |
| 57 |
return new BVGravityFormHandler($this->form_id, $this->bypass_params); |
| 58 |
case 'FormidableForm': |
| 59 |
require_once dirname(__FILE__) . '/handlers/formidable_form.php'; |
| 60 |
return new BVFormidableFormHandler($this->form_id, $this->bypass_params); |
| 61 |
default: |
| 62 |
return null; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
private function bypassSpamPlugins() { |
| 67 |
add_action('init', function() { |
| 68 |
global $apbct; |
| 69 |
if (isset($apbct) && is_object($apbct)) { |
| 70 |
$apbct->settings['forms__contact_forms_test'] = 0; |
| 71 |
} |
| 72 |
}, PHP_INT_MAX); |
| 73 |
|
| 74 |
add_filter('akismet_get_api_key', function () { |
| 75 |
return null; |
| 76 |
}, PHP_INT_MAX); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
endif; |