Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/Plugin/GravityForms/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
use AdCaptcha\Widget\Verify;
use Exception;

if (!class_exists('GF_Field')) {
// update the condition for testing environment
if (!class_exists('GF_Field') && !defined('PHPUNIT_RUNNING')) {
return;
}

class Field extends GF_Field {
public $type = 'adcaptcha';
public $type;
private $verify;

public function __construct($data = []) {
parent::__construct($data);
$this->type = 'adcaptcha';
$this->verify = new Verify();
$this->setup();
}
Expand Down Expand Up @@ -64,7 +66,7 @@ public function add_to_field_groups($field_groups): array {
}
}
$field_groups['advanced_fields']['fields'][] = [
'data-type' => $this->type,
'data-type' => (string) $this->type,
'value' => $this->get_form_editor_field_title(),
'label' => $this->get_form_editor_field_title(),
];
Expand Down Expand Up @@ -118,27 +120,18 @@ public function update_adcaptcha_label() {
if (!$forms || !is_array($forms)) {
return;
}
$errors = [];
foreach ($forms as $form) {
$updated = false;
foreach ($form['fields'] as &$field) {
if ($field->type === 'adcaptcha' && $field->label !== __('adCAPTCHA', 'adcaptcha')) {
$field->label = __('adCAPTCHA', 'adcaptcha');
$field['label'] = __('adCAPTCHA', 'adcaptcha');
$updated = true;
}
}
if ($updated) {
$result = GFAPI::update_form($form);

if (is_wp_error($result)) {
$errors[] = "Failed to update adCAPTCHA label in Form ID {$form['id']}: " . $result->get_error_message();
}
GFAPI::update_form($form);
}
}
if (!empty($errors)) {
throw new Exception(implode("\n", $errors));
}
}

public function enqueue_admin_script() {
Expand Down Expand Up @@ -199,7 +192,10 @@ public function enqueue_preview_scripts($form_id) {
}

public function get_field_input($form, $value = '', $entry = null) {
$form_id = $form['id'];
$form_id = $form['id'] ?? null;
if ($form_id === null) {
return '';
}
$field_id = (int) $this->id;
if ($this->is_form_editor()) {
return "<div class='ginput_container'>adCAPTCHA will be rendered here.</div>";
Expand Down
1 change: 0 additions & 1 deletion src/Plugin/GravityForms/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ public function register_adcaptcha_field() {
}
}
}

Loading