Skip to content

Commit 3f2520c

Browse files
author
Antoine Greuzard
committed
Update plugin version to 1.2.1 and refactor throw exceptions
Bumped up the version of the Influactive Forms plugin from 1.2 to 1.2.1 across all related script and style enqueues. Formatted the indented InvalidArgumentException messages to a consistent style as well. These changes are essential for proper version traceability and improving readability of the code.
1 parent 192c5f6 commit 3f2520c

File tree

2 files changed

+65
-65
lines changed

2 files changed

+65
-65
lines changed

front-end/shortcode.php

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function influactive_form_shortcode_handler(array $atts): bool|string
3434
$form_id = (int)$atts['id'];
3535

3636
if (!$form_id) {
37-
throw new RuntimeException("Form ID not found. Exiting...");
37+
throw new RuntimeException("Form ID not found. Exiting...");
3838
}
3939

4040
// Showing the form if it exists
@@ -121,16 +121,16 @@ function influactive_form_shortcode_handler(array $atts): bool|string
121121
function enqueue_form_dynamic_style(): void
122122
{
123123
if (is_admin()) {
124-
throw new RuntimeException("WordPress environment not loaded. Exiting...");
124+
throw new RuntimeException("WordPress environment not loaded. Exiting...");
125125
}
126126

127127
$form_id = get_post_meta(get_the_ID(), 'influactive_form_id', true) ?? 0;
128128
if (!$form_id) {
129-
throw new RuntimeException("Form ID not found. Exiting...");
129+
throw new RuntimeException("Form ID not found. Exiting...");
130130
}
131131

132132
// Enqueue du fichier dynamic-style.php
133-
wp_enqueue_style('influactive-form-dynamic-style', plugin_dir_url(__FILE__) . '/dynamic-style.php?post_id=' . $form_id, [], '1.2');
133+
wp_enqueue_style('influactive-form-dynamic-style', plugin_dir_url(__FILE__) . '/dynamic-style.php?post_id=' . $form_id, [], '1.2.1');
134134
}
135135

136136
add_action('wp_enqueue_scripts', 'enqueue_form_dynamic_style');
@@ -155,7 +155,7 @@ function influactive_send_email(): void
155155
if (empty($_POST['form_id'])) {
156156
wp_send_json_error(['message' => __('Form ID is required', 'influactive-forms')]);
157157

158-
exit;
158+
exit;
159159
}
160160

161161
$form_id = (int)$_POST['form_id'];
@@ -170,7 +170,7 @@ function influactive_send_email(): void
170170
$message = sprintf(__('The field %s is required', 'influactive-forms'), $name);
171171
wp_send_json_error(['message' => $message]);
172172

173-
exit;
173+
exit;
174174
}
175175
}
176176

@@ -182,51 +182,51 @@ function influactive_send_email(): void
182182
$secret_site_key = $options_captcha['google-captcha']['secret-site-key'] ?? '';
183183
$public_site_key = $_POST['recaptcha_site_key'] ?? '';
184184

185-
if (!empty($secret_site_key) && !empty($public_site_key) && isset($_POST['recaptcha_response'])) {
186-
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
187-
$recaptcha_response = $_POST['recaptcha_response'];
188-
189-
$url = $recaptcha_url . '?secret=' . urlencode($secret_site_key) . '&response=' . urlencode($recaptcha_response);
190-
191-
$ch = curl_init();
192-
curl_setopt($ch, CURLOPT_URL, $url);
193-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
194-
try {
195-
$response = curl_exec($ch);
196-
if (curl_errno($ch)) {
197-
throw new RuntimeException(curl_error($ch));
198-
}
199-
} catch (Exception $e) {
200-
wp_send_json_error([
201-
'message' => __('Failed to verify reCAPTCHA', 'influactive-forms'),
202-
'error' => $e->getMessage(),
203-
]);
204-
curl_close($ch);
205-
exit;
206-
}
207-
curl_close($ch);
208-
209-
try {
210-
$recaptcha = json_decode($response, false, 512, JSON_THROW_ON_ERROR);
211-
212-
if ($recaptcha->score < 0.5) {
213-
// Not likely to be a human
214-
wp_send_json_error([
215-
'message' => __('Bot detected', 'influactive-forms'),
216-
'score' => $recaptcha->score,
217-
]);
218-
219-
exit;
220-
}
221-
} catch (JsonException $e) {
222-
wp_send_json_error([
223-
'message' => __('Failed to verify reCAPTCHA', 'influactive-forms'),
224-
'error' => $e->getMessage(),
225-
]);
226-
227-
exit;
228-
}
229-
}
185+
if (!empty($secret_site_key) && !empty($public_site_key) && isset($_POST['recaptcha_response'])) {
186+
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
187+
$recaptcha_response = $_POST['recaptcha_response'];
188+
189+
$url = $recaptcha_url . '?secret=' . urlencode($secret_site_key) . '&response=' . urlencode($recaptcha_response);
190+
191+
$ch = curl_init();
192+
curl_setopt($ch, CURLOPT_URL, $url);
193+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
194+
try {
195+
$response = curl_exec($ch);
196+
if (curl_errno($ch)) {
197+
throw new RuntimeException(curl_error($ch));
198+
}
199+
} catch (Exception $e) {
200+
wp_send_json_error([
201+
'message' => __('Failed to verify reCAPTCHA', 'influactive-forms'),
202+
'error' => $e->getMessage(),
203+
]);
204+
curl_close($ch);
205+
exit;
206+
}
207+
curl_close($ch);
208+
209+
try {
210+
$recaptcha = json_decode($response, false, 512, JSON_THROW_ON_ERROR);
211+
212+
if ($recaptcha->score < 0.5) {
213+
// Not likely to be a human
214+
wp_send_json_error([
215+
'message' => __('Bot detected', 'influactive-forms'),
216+
'score' => $recaptcha->score,
217+
]);
218+
219+
exit;
220+
}
221+
} catch (JsonException $e) {
222+
wp_send_json_error([
223+
'message' => __('Failed to verify reCAPTCHA', 'influactive-forms'),
224+
'error' => $e->getMessage(),
225+
]);
226+
227+
exit;
228+
}
229+
}
230230

231231
$layouts = $email_layout ?? [];
232232
$error = 0;
@@ -324,7 +324,7 @@ function influactive_send_email(): void
324324
'message' => __('Failed to send email', 'influactive-forms'),
325325
]);
326326

327-
exit;
327+
exit;
328328
}
329329

330330
exit;

functions.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: Forms everywhere by Influactive
44
* Description: A plugin to create custom forms and display them anywhere on your website.
5-
* Version: 1.2
5+
* Version: 1.2.1
66
* Author: Influactive
77
* Author URI: https://influactive.com
88
* Text Domain: influactive-forms
@@ -56,7 +56,7 @@ function influactive_form_edit(string $hook): void
5656
'wp-tinymce',
5757
'influactive-tabs',
5858
'influactive-form-layout'
59-
), '1.2', true);
59+
), '1.2.1', true);
6060
wp_localize_script('influactive-form', 'influactiveFormsTranslations', array(
6161
'addOptionText' => __('Add option', 'influactive-forms'),
6262
'removeOptionText' => __('Remove option', 'influactive-forms'),
@@ -78,27 +78,27 @@ function influactive_form_edit(string $hook): void
7878
'Number' => __('Number', 'influactive-forms'),
7979
'Freetext' => __('Free text', 'influactive-forms'),
8080
));
81-
wp_enqueue_script('influactive-form-sortable', 'https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.25.0/Sortable.min.js', array(), '1.2', true);
82-
wp_enqueue_style('influactive-form', plugin_dir_url(__FILE__) . 'back-end/post-type/form/form.min.css', array(), '1.2');
81+
wp_enqueue_script('influactive-form-sortable', 'https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.2.15.0/Sortable.min.js', array(), '1.2.1', true);
82+
wp_enqueue_style('influactive-form', plugin_dir_url(__FILE__) . 'back-end/post-type/form/form.min.css', array(), '1.2.1');
8383

84-
wp_enqueue_script('influactive-tabs', plugin_dir_url(__FILE__) . 'back-end/post-type/tab/tab.min.js', array(), '1.2', true);
85-
wp_enqueue_style('influactive-tabs', plugin_dir_url(__FILE__) . 'back-end/post-type/tab/tab.min.css', array(), '1.2');
84+
wp_enqueue_script('influactive-tabs', plugin_dir_url(__FILE__) . 'back-end/post-type/tab/tab.min.js', array(), '1.2.1', true);
85+
wp_enqueue_style('influactive-tabs', plugin_dir_url(__FILE__) . 'back-end/post-type/tab/tab.min.css', array(), '1.2.1');
8686

87-
wp_enqueue_style('influactive-form-layout', plugin_dir_url(__FILE__) . 'back-end/post-type/layout/layout.min.css', array(), '1.2');
88-
wp_enqueue_script('influactive-form-layout', plugin_dir_url(__FILE__) . 'back-end/post-type/layout/layout.min.js', array(), '1.2', true);
87+
wp_enqueue_style('influactive-form-layout', plugin_dir_url(__FILE__) . 'back-end/post-type/layout/layout.min.css', array(), '1.2.1');
88+
wp_enqueue_script('influactive-form-layout', plugin_dir_url(__FILE__) . 'back-end/post-type/layout/layout.min.js', array(), '1.2.1', true);
8989
wp_localize_script('influactive-form-layout', 'influactiveFormsTranslations', array(
9090
'delete_layout' => __('Delete layout', 'influactive-forms'),
9191
));
9292

93-
wp_enqueue_style('influactive-form-style', plugin_dir_url(__FILE__) . 'back-end/post-type/style.min.css', array(), '1.2');
93+
wp_enqueue_style('influactive-form-style', plugin_dir_url(__FILE__) . 'back-end/post-type/style.min.css', array(), '1.2.1');
9494

95-
wp_enqueue_style('influactive-form-preview', plugin_dir_url(__FILE__) . 'front-end/form.min.css', array(), '1.2');
95+
wp_enqueue_style('influactive-form-preview', plugin_dir_url(__FILE__) . 'front-end/form.min.css', array(), '1.2.1');
9696

9797
$form_id = get_post_meta(get_the_ID(), 'influactive_form_id', true);
9898
if (!$form_id) {
9999
throw new RuntimeException("Form ID not found. Exiting...");
100100
}
101-
wp_enqueue_style('influactive-form-dynamic-style', plugin_dir_url(__FILE__) . 'front-end/dynamic-style.php?post_id=' . $form_id, array(), '1.2');
101+
wp_enqueue_style('influactive-form-dynamic-style', plugin_dir_url(__FILE__) . 'front-end/dynamic-style.php?post_id=' . $form_id, array(), '1.2.1');
102102
}
103103

104104
add_action('admin_enqueue_scripts', 'influactive_form_edit');
@@ -130,8 +130,8 @@ function influactive_form_shortcode_enqueue(): void
130130
$script_handle = [];
131131
}
132132

133-
wp_enqueue_script('influactive-form', plugin_dir_url(__FILE__) . 'front-end/form.min.js', $script_handle, '1.2', true);
134-
wp_enqueue_style('influactive-form', plugin_dir_url(__FILE__) . 'front-end/form.min.css', [], '1.2');
133+
wp_enqueue_script('influactive-form', plugin_dir_url(__FILE__) . 'front-end/form.min.js', $script_handle, '1.2.1', true);
134+
wp_enqueue_style('influactive-form', plugin_dir_url(__FILE__) . 'front-end/form.min.css', [], '1.2.1');
135135

136136
wp_localize_script('influactive-form', 'ajax_object', ['ajaxurl' => admin_url('admin-ajax.php')]);
137137
}

0 commit comments

Comments
 (0)