| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
if (!class_exists('BVGravityFormHandler')) : |
| 5 |
|
| 6 |
class BVGravityFormHandler { |
| 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 |
if ($this->form_id === null) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
add_filter('gform_pre_validation_' . $this->form_id, function($form) { |
| 31 |
foreach ($form['fields'] as &$field) { |
| 32 |
if ($field->type === 'captcha') { |
| 33 |
$field->visibility = 'hidden'; |
| 34 |
} |
| 35 |
} |
| 36 |
return $form; |
| 37 |
}, PHP_INT_MAX); |
| 38 |
} |
| 39 |
|
| 40 |
public function bypassEmail() { |
| 41 |
add_filter('gform_pre_send_email', function ($email_data) { |
| 42 |
$email_data['abort_email'] = true; |
| 43 |
return $email_data; |
| 44 |
}, PHP_INT_MAX); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
endif; |