PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Hooks / Ajax.php

Ajax.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Hooks/Ajax.php

266 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined('ABSPATH') or die;
4
5 /**
6 * Add all ajax hooks
7 */
8
9 use FluentForm\App\Modules\Acl\Acl;
10
11 /**
12 * App instance
13 *
14 * @var $app \FluentForm\Framework\Foundation\Application
15 */
16
17 $app->addAction('wp_ajax_nopriv_fluentform_submit', function () use ($app) {
18 (new \FluentForm\App\Modules\SubmissionHandler\SubmissionHandler($app))->submit();
19 });
20
21 $app->addAction('wp_ajax_fluentform_submit', function () use ($app) {
22 // (new \FluentForm\App\Modules\Form\FormHandler($app))->onSubmit();
23 (new \FluentForm\App\Modules\SubmissionHandler\SubmissionHandler($app))->submit();
24 });
25
26 /*
27 * We are using this ajax call for updating form fields
28 * REST API seems not working for some servers with Mod Security Enabled
29 */
30 $app->addAction('wp_ajax_fluentform-form-update', function () use ($app) {
31 $formId = Acl::verifyFormId($app->request->get('form_id'));
32 Acl::verify('fluentform_forms_manager', $formId);
33 try {
34 $data = $app->request->all();
35 $data['form_id'] = $formId;
36 $isValidJson = (!empty($data['formFields'])) && json_decode($data['formFields'], true);
37
38 if (!$isValidJson) {
39 wp_send_json([
40 'message' => 'Looks like the provided JSON is invalid. Please try again or contact support',
41 'reason' => 'formFields JSON validation failed',
42 ], 422);
43 }
44
45 $formService = new \FluentForm\App\Services\Form\FormService();
46 $form = $formService->update($data);
47 wp_send_json([
48 'message' => __('The form is successfully updated.', 'fluentform'),
49 ], 200);
50 } catch (\Exception $exception) {
51 wp_send_json([
52 'message' => $exception->getMessage(),
53 ], 422);
54 }
55 });
56
57 /*
58 * This ajax endpoint is used to update form general settings
59 * Mod-Security also block this request
60 */
61 $app->addAction('wp_ajax_fluentform-save-settings-general-formSettings', function () use ($app) {
62 $formId = Acl::verifyFormId($app->request->get('form_id'));
63 Acl::verify('fluentform_forms_manager', $formId);
64 try {
65 $settingsService = new \FluentForm\App\Services\Settings\SettingsService();
66 $attributes = $app->request->all();
67 $attributes['form_id'] = $formId;
68
69 $settingsService->saveGeneral($attributes);
70 wp_send_json([
71 'message' => __('Settings has been saved.', 'fluentform'),
72 ]);
73 } catch (\FluentForm\Framework\Validator\ValidationException $exception) {
74 wp_send_json($exception->errors(), 422);
75 }
76 });
77
78 /*
79 * This ajax endpoint is used to update form email notifications settings
80 * Mod-Security also block this request
81 */
82 $app->addAction('wp_ajax_fluentform-save-form-email-notification', function () use ($app) {
83 $formId = Acl::verifyFormId($app->request->get('form_id'));
84 Acl::verify('fluentform_forms_manager', $formId);
85 try {
86 $settingsService = new \FluentForm\App\Services\Settings\SettingsService();
87 $attributes = $app->request->all();
88 $attributes['form_id'] = $formId;
89
90 [$settingsId, $settings] = $settingsService->store($attributes);
91
92 wp_send_json([
93 'message' => __('Settings has been saved.', 'fluentform'),
94 'id' => $settingsId,
95 'settings' => $settings,
96 ]);
97 } catch (\FluentForm\Framework\Validator\ValidationException $exception) {
98 wp_send_json($exception->errors(), 422);
99 }
100 });
101
102
103 // Legacy AJAX handlers removed — these routes are handled by the REST API.
104 // Kept: fluentform-form-find-shortcode-locations (still in active use)
105 $app->addAdminAjaxAction('fluentform-form-find-shortcode-locations', function () use ($app) {
106 $formId = Acl::verifyFormId($app->request->get('form_id'));
107 Acl::verify('fluentform_forms_manager', $formId);
108
109 (new \FluentForm\App\Modules\Form\Form($app))->findFormLocations();
110 });
111
112 // Legacy AJAX handlers removed — these routes are now handled by the REST API.
113
114
115
116 $resolveSubmissionFormId = function ($submissionId) {
117 if (!$submissionId) {
118 return null;
119 }
120
121 $submission = \FluentForm\App\Models\Submission::select('form_id')->find($submissionId);
122
123 return $submission ? $submission->form_id : null;
124 };
125
126 $app->addAction('wp_ajax_fluentform-form-entries-export', function () use ($app) {
127 $formId = Acl::verifyFormId($app->request->get('form_id'));
128
129 Acl::verify('fluentform_entries_viewer', $formId);
130 (new \FluentForm\App\Modules\Transfer\Transfer())->exportEntries();
131 });
132
133 $app->addAction('wp_ajax_fluentform-update-entry-user', function () use ($app, $resolveSubmissionFormId) {
134 $submissionId = absint($app->request->get('submission_id'));
135 $formId = $resolveSubmissionFormId($submissionId);
136
137 Acl::verify('fluentform_manage_entries', $formId);
138 $userId = absint($app->request->get('user_id'));
139 try {
140 $result = (new \FluentForm\App\Services\Submission\SubmissionService())->updateSubmissionUser($userId, $submissionId);
141 wp_send_json_success($result);
142 } catch (\Exception $e) {
143 wp_send_json_error(['message' => $e->getMessage()], 423);
144 }
145 });
146
147 $app->addAction('wp_ajax_fluentform-get-users', function () use ($app, $resolveSubmissionFormId) {
148 $submissionId = absint($app->request->get('submission_id'));
149 $formId = Acl::verifyFormId(
150 $resolveSubmissionFormId($submissionId),
151 'Invalid submission id.'
152 );
153
154 Acl::verify('fluentform_manage_entries', $formId);
155 $search = sanitize_text_field($app->request->get('search'));
156 $users = get_users([
157 'search' => "*{$search}*",
158 'number' => 50,
159 ]);
160 $formattedUsers = [];
161 foreach ($users as $user) {
162 $formattedUsers[] = [
163 'ID' => $user->ID,
164 'label' => $user->display_name . ' - ' . $user->user_email,
165 ];
166 }
167 wp_send_json_success(['users' => $formattedUsers]);
168 });
169
170
171 // Legacy log AJAX handlers removed — these routes are now handled by the REST API.
172
173 $app->addAction('wp_ajax_fluentform-change-entry-status', function () use ($app, $resolveSubmissionFormId) {
174 $entryId = absint($app->request->get('entry_id'));
175 $formId = $resolveSubmissionFormId($entryId);
176
177 Acl::verify('fluentform_manage_entries', $formId);
178
179 $attributes = [
180 'entry_id' => $entryId,
181 'status' => sanitize_text_field($app->request->get('status')),
182 ];
183 $newStatus = (new \FluentForm\App\Services\Submission\SubmissionService())->updateStatus($attributes);
184 wp_send_json_success([
185 // translators: %s is the submission status name
186 'message' => sprintf(__('Item has been marked as %s', 'fluentform'), $newStatus),
187 'status' => $newStatus,
188 ], 200);
189 });
190
191
192 $app->addAction('wp_ajax_fluentform_notice_action_track_yes', function () {
193 Acl::verify('fluentform_settings_manager');
194 (new FluentForm\App\Modules\Track\TrackModule())->sendInitialInfo();
195 });
196
197 $app->addAction('wp_ajax_fluentform_install_fluentsmtp', function () {
198 Acl::verify('fluentform_settings_manager');
199 (new FluentForm\App\Modules\Track\SetupModule())->installPlugin('fluent-smtp');
200 });
201
202 // Export forms
203 $app->addAction('wp_ajax_fluentform-export-forms', function () use ($app) {
204 Acl::verify('fluentform_settings_manager', $app->request->get('forms'));
205 (new \FluentForm\App\Modules\Transfer\Transfer())->exportForms();
206 });
207
208 // Import forms
209 $app->addAction('wp_ajax_fluentform-import-forms', function () use ($app) {
210 Acl::verify('fluentform_settings_manager');
211 (new \FluentForm\App\Modules\Transfer\Transfer())->importForms();
212 });
213
214 /*
215 * Background Process Receiver
216 */
217
218 // $this refers to the Application instance (included via Application::requireCommonFiles → includes.php)
219 $app->addAction('wp_ajax_fluentform_background_process', function () {
220 $this->app['fluentFormAsyncRequest']->handleBackgroundCall();
221 });
222
223 $app->addAction('wp_ajax_nopriv_fluentform_background_process', function () {
224 $this->app['fluentFormAsyncRequest']->handleBackgroundCall();
225 });
226
227 /*
228 * Background Report Data Migration
229 */
230 $app->addAction('wp_ajax_fluentform_report_data_migrate', function () {
231 if (!wp_verify_nonce(sanitize_text_field(wpFluentForm('request')->get('nonce')), 'fluentform_report_data_migrate')) {
232 die('invalid');
233 }
234 $formId = Acl::normalizeFormId(wpFluentForm('request')->get('form_id'));
235 if ($formId && Acl::hasPermission('fluentform_entries_viewer', $formId)) {
236 \FluentForm\App\Services\Report\ReportHelper::runMigrationBatch($formId);
237 }
238 die('done');
239 });
240
241 /*
242 * For REST API Nonce Renewal
243 */
244 $app->addAction('wp_ajax_fluentform_renew_rest_nonce', function () {
245 if (!Acl::getCurrentUserPermissions()) {
246 wp_send_json([
247 'error' => 'You do not have permission to do this',
248 ], 403);
249 }
250
251 wp_send_json([
252 'nonce' => wp_create_nonce('wp_rest'),
253 ], 200);
254 });
255 /*
256 * For selectGroup Component Grouped Options
257 * Use this filter to pass data to component
258 */
259
260 add_action('wp_ajax_fluentform_select_group_ajax_data', function () {
261 Acl::verify('fluentform_dashboard_access');
262 $requestData = wpFluentForm('request')->all();
263 $ajaxList = apply_filters('fluentform/select_group_component_ajax_options', [], $requestData);
264 wp_send_json_success($ajaxList);
265 });
266