| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVNinjaFormHandler')) : |
| 5 |
|
| 6 |
class BVNinjaFormHandler { |
| 7 |
private $form_id; |
| 8 |
private $bypass_params = array(); |
| 9 |
|
| 10 |
public function __construct($form_id, $bypass_params) { |
| 11 |
$this->form_id = $form_id; |
| 12 |
$this->bypass_params = $bypass_params; |
| 13 |
} |
| 14 |
|
| 15 |
public function bypass() { |
| 16 |
if (array_key_exists('should_bypass_captcha', $this->bypass_params)) { |
| 17 |
$this->bypassCaptcha(); |
| 18 |
} |
| 19 |
|
| 20 |
if (array_key_exists('should_bypass_email', $this->bypass_params)) { |
| 21 |
$this->bypassEmail(); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function bypassCaptcha() { |
| 26 |
add_filter('ninja_forms_pre_validate_field_settings', function ($field_settings) { |
| 27 |
if (isset($field_settings['type']) && in_array($field_settings['type'], ['recaptcha', 'spam'], true)) { |
| 28 |
$field_settings['type'] = null; |
| 29 |
} |
| 30 |
return $field_settings; |
| 31 |
}, PHP_INT_MAX); |
| 32 |
|
| 33 |
add_filter('ninja_forms_run_action_type_recaptcha', '__return_false', PHP_INT_MAX); |
| 34 |
} |
| 35 |
|
| 36 |
public function bypassEmail() { |
| 37 |
add_filter('ninja_forms_action_email_send', '__return_true', PHP_INT_MAX); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
endif; |