PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.18
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.18
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 / Backend.php

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

445 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Declare backend actions/filters/shortcodes
5 */
6
7 /*
8 * Regitser All Admin Scripts but don't load it
9 */
10
11 add_action('admin_init', function () use ($app) {
12 (new \FluentForm\App\Modules\Registerer\Menu($app))->reisterScripts();
13 }, 9);
14
15 add_action('admin_enqueue_scripts', function () use ($app) {
16 (new \FluentForm\App\Modules\Registerer\Menu($app))->enqueuePageScripts();
17 }, 10);
18
19 // Add Entries Menu
20 $app->addAction('ff_fluentform_form_application_view_entries', function ($form_id) use ($app) {
21 (new \FluentForm\App\Modules\Entries\Entries())->renderEntries($form_id);
22 });
23
24 $app->addAction('fluentform_after_form_navigation', function ($form_id) use ($app) {
25 (new \FluentForm\App\Modules\Registerer\Menu($app))->addCopyShortcodeButton($form_id);
26 (new \FluentForm\App\Modules\Registerer\Menu($app))->addPreviewButton($form_id);
27 });
28
29 $app->addAction('media_buttons', function () {
30 (new \FluentForm\App\Modules\EditorButtonModule())->addButton();
31 });
32
33 $app->addAction('fluentform_addons_page_render_fluentform_add_ons', function () {
34 (new \FluentForm\App\Modules\AddOnModule())->showFluentAddOns();
35 });
36
37 // This is temp, we will remove this after 2-3 versions.
38 add_filter('pre_set_site_transient_update_plugins', function ($updates) {
39 if (!empty($updates->response['fluentformpro'])) {
40 $updates->response['fluentformpro/fluentformpro.php'] = $updates->response['fluentformpro'];
41 unset($updates->response['fluentformpro']);
42 }
43 return $updates;
44 }, 999, 1);
45
46 $app->addAction('fluentform_global_menu', function () use ($app) {
47 $menu = new \FluentForm\App\Modules\Registerer\Menu($app);
48 $menu->renderGlobalMenu();
49 if ('yes' != get_option('fluentform_scheduled_actions_migrated')) {
50 \FluentForm\App\Databases\Migrations\ScheduledActions::migrate();
51 }
52
53 $hookName = 'fluentform_do_scheduled_tasks';
54 if (!wp_next_scheduled($hookName)) {
55 wp_schedule_event(time(), 'ff_every_five_minutes', $hookName);
56 }
57
58 $emailReportHookName = 'fluentform_do_email_report_scheduled_tasks';
59 if (!wp_next_scheduled($emailReportHookName)) {
60 wp_schedule_event(time(), 'daily', $emailReportHookName);
61 }
62 });
63
64 $app->addAction('wp_dashboard_setup', function () {
65 $roleManager = new \FluentForm\App\Modules\Acl\Acl();
66
67 if (!$roleManager->getCurrentUserCapability()) {
68 return;
69 }
70 wp_add_dashboard_widget('fluentform_stat_widget', __('Fluent Forms Latest Form Submissions', 'fluentform'), function () {
71 (new \FluentForm\App\Modules\DashboardWidgetModule())->showStat();
72 }, 10, 1);
73 });
74
75 add_action('admin_init', function () {
76 $disablePages = [
77 'fluent_forms',
78 'fluent_forms_transfer',
79 'fluent_forms_settings',
80 'fluent_forms_add_ons',
81 'fluent_forms_docs',
82 'fluent_forms_all_entries',
83 'msformentries',
84 ];
85
86 $page = wpFluentForm('request')->get('page');
87
88 if ($page && in_array($page, $disablePages)) {
89 remove_all_actions('admin_notices');
90 }
91 });
92
93 add_action('enqueue_block_editor_assets', function () use ($app) {
94 wp_enqueue_script(
95 'fluentform-gutenberg-block',
96 $app->publicUrl('js/fluent_gutenblock.js'),
97 ['wp-element', 'wp-polyfill', 'wp-i18n', 'wp-blocks', 'wp-components'],
98 FLUENTFORM_VERSION
99 );
100
101 $forms = wpFluent()->table('fluentform_forms')
102 ->select(['id', 'title'])
103 ->orderBy('id', 'DESC')
104 ->get();
105
106 array_unshift($forms, (object) [
107 'id' => '',
108 'title' => __('-- Select a form --', 'fluentform'),
109 ]);
110
111 wp_localize_script('fluentform-gutenberg-block', 'fluentform_block_vars', [
112 'logo' => $app->publicUrl('img/fluent_icon.png'),
113 'forms' => $forms,
114 ]);
115
116 wp_enqueue_style(
117 'fluentform-gutenberg-block',
118 $app->publicUrl('css/fluent_gutenblock.css'),
119 ['wp-edit-blocks']
120 );
121 });
122
123 add_action('wp_print_scripts', function () {
124 if (is_admin()) {
125 if (\FluentForm\App\Helpers\Helper::isFluentAdminPage()) {
126 $option = get_option('_fluentform_global_form_settings');
127 $isSkip = 'no' == \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.noConflictStatus');
128 $isSkip = apply_filters('fluentform_skip_no_conflict', $isSkip);
129
130 if ($isSkip) {
131 return;
132 }
133
134 global $wp_scripts;
135 if (!$wp_scripts) {
136 return;
137 }
138
139 $pluginUrl = plugins_url();
140 foreach ($wp_scripts->queue as $script) {
141 if (!isset($wp_scripts->registered[$script])) {
142 continue;
143 }
144
145 $src = $wp_scripts->registered[$script]->src;
146 if (false !== strpos($src, $pluginUrl) && false !== !strpos($src, 'fluentform')) {
147 wp_dequeue_script($wp_scripts->registered[$script]->handle);
148 }
149 }
150 }
151 }
152 }, 1);
153
154 add_action('fluentform_loading_editor_assets', function ($form) {
155 add_filter('fluentform_editor_init_element_input_name', function ($field) {
156 if (empty($field['settings']['label_placement'])) {
157 $field['settings']['label_placement'] = '';
158 }
159 return $field;
160 });
161
162 $upgradableCheckInputs = [
163 'input_radio',
164 'select',
165 'select_country',
166 'input_checkbox',
167 ];
168
169 foreach ($upgradableCheckInputs as $upgradeElement) {
170 add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) use ($upgradeElement) {
171 if (!\FluentForm\Framework\Helpers\ArrayHelper::get($element, 'settings.advanced_options')) {
172 $formattedOptions = [];
173 $oldOptions = \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'options', []);
174 foreach ($oldOptions as $value => $label) {
175 $formattedOptions[] = [
176 'label' => $label,
177 'value' => $value,
178 'calc_value' => '',
179 'image' => '',
180 ];
181 }
182 $element['settings']['advanced_options'] = $formattedOptions;
183 $element['settings']['enable_image_input'] = false;
184 $element['settings']['calc_value_status'] = false;
185 unset($element['options']);
186
187 if ('input_radio' == $upgradeElement || 'input_checkbox' == $upgradeElement) {
188 $element['editor_options']['template'] = 'inputCheckable';
189 }
190 }
191
192 if (!isset($element['settings']['layout_class']) && in_array($upgradeElement, ['input_radio', 'input_checkbox'])) {
193 $element['settings']['layout_class'] = '';
194 }
195
196 if (!isset($element['settings']['dynamic_default_value'])) {
197 $element['settings']['dynamic_default_value'] = '';
198 }
199
200 if ('select_country' != $upgradeElement && !isset($element['settings']['randomize_options'])) {
201 $element['settings']['randomize_options'] = 'no';
202 }
203
204 if ('select' == $upgradeElement && \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'attributes.multiple')) {
205 if (empty($element['settings']['max_selection'])) {
206 $element['settings']['max_selection'] = '';
207 }
208 if (isset($element['settings']['enable_select_2'])) {
209 \FluentForm\Framework\Helpers\ArrayHelper::forget($element, 'settings.enable_select_2');
210 }
211 }
212
213 if (
214 (
215 (
216 'select' == $upgradeElement &&
217 ! \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'attributes.multiple')
218 ) ||
219 'select_country' == $upgradeElement
220 ) &&
221 ! isset($element['settings']['enable_select_2'])
222 ) {
223 $element['settings']['enable_select_2'] = 'no';
224 }
225
226 if ('select_country' != $upgradeElement && !isset($element['settings']['values_visible'])) {
227 $element['settings']['values_visible'] = false;
228 }
229
230 return $element;
231 });
232 }
233
234 $upgradableFileInputs = [
235 'input_file',
236 'input_image',
237 ];
238 foreach ($upgradableFileInputs as $upgradeElement) {
239 add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) {
240 if (!isset($element['settings']['upload_file_location'])) {
241 $element['settings']['upload_file_location'] = 'default';
242 };
243 if (!isset($element['settings']['file_location_type'])) {
244 $element['settings']['file_location_type'] = 'follow_global_settings';
245 };
246 return $element;
247 });
248 }
249
250 add_filter('fluentform_editor_init_element_gdpr_agreement', function ($element) {
251 if (!isset($element['settings']['required_field_message'])) {
252 $element['settings']['required_field_message'] = '';
253 }
254 return $element;
255 });
256
257 add_filter('fluentform_editor_init_element_input_text', function ($element) {
258 if (!isset($element['attributes']['maxlength'])) {
259 $element['attributes']['maxlength'] = '';
260 }
261 return $element;
262 });
263
264 add_filter('fluentform_editor_init_element_textarea', function ($element) {
265 if (!isset($element['attributes']['maxlength'])) {
266 $element['attributes']['maxlength'] = '';
267 }
268 return $element;
269 });
270
271 add_filter('fluentform_editor_init_element_input_date', function ($item) {
272 if (!isset($item['settings']['date_config'])) {
273 $item['settings']['date_config'] = '';
274 }
275 return $item;
276 });
277
278 add_filter('fluentform_editor_init_element_container', function ($item) {
279 if (!isset($item['settings']['conditional_logics'])) {
280 $item['settings']['conditional_logics'] = [];
281 }
282
283 if (!isset($item['settings']['container_width'])) {
284 $item['settings']['container_width'] = '';
285 }
286
287 $shouldSetWidth = !empty($item['columns']) && (!isset($item['columns'][0]['width']) || !$item['columns'][0]['width']);
288
289 if ($shouldSetWidth) {
290 $perColumn = round(100 / count($item['columns']), 2);
291
292 foreach ($item['columns'] as &$column) {
293 $column['width'] = $perColumn;
294 }
295 }
296
297 return $item;
298 });
299
300 add_filter('fluentform_editor_init_element_input_number', function ($item) {
301 if (!isset($item['settings']['number_step'])) {
302 $item['settings']['number_step'] = '';
303 }
304 if (!isset($item['settings']['numeric_formatter'])) {
305 $item['settings']['numeric_formatter'] = '';
306 }
307 if (!isset($item['settings']['prefix_label'])) {
308 $item['settings']['prefix_label'] = '';
309 }
310 if (!isset($item['settings']['suffix_label'])) {
311 $item['settings']['suffix_label'] = '';
312 }
313 return $item;
314 });
315
316 add_filter('fluentform_editor_init_element_input_email', function ($item) {
317 if (!isset($item['settings']['is_unique'])) {
318 $item['settings']['is_unique'] = 'no';
319 }
320 if (!isset($item['settings']['unique_validation_message'])) {
321 $item['settings']['unique_validation_message'] = __('Email address need to be unique.', 'fluentform');
322 }
323 if (!isset($item['settings']['prefix_label'])) {
324 $item['settings']['prefix_label'] = '';
325 }
326 if (!isset($item['settings']['suffix_label'])) {
327 $item['settings']['suffix_label'] = '';
328 }
329 return $item;
330 });
331
332 add_filter('fluentform_editor_init_element_input_text', function ($item) {
333 if (isset($item['attributes']['data-mask'])) {
334 if (!isset($item['settings']['data-mask-reverse'])) {
335 $item['settings']['data-mask-reverse'] = 'no';
336 }
337 if (!isset($item['settings']['data-clear-if-not-match'])) {
338 $item['settings']['data-clear-if-not-match'] = 'no';
339 }
340 } else {
341 if (!isset($item['settings']['is_unique'])) {
342 $item['settings']['is_unique'] = 'no';
343 }
344 if (!isset($item['settings']['unique_validation_message'])) {
345 $item['settings']['unique_validation_message'] = __('This field value need to be unique.', 'fluentform');
346 }
347 }
348
349 if (!isset($item['settings']['prefix_label'])) {
350 $item['settings']['prefix_label'] = '';
351 }
352 if (!isset($item['settings']['suffix_label'])) {
353 $item['settings']['suffix_label'] = '';
354 }
355
356 return $item;
357 });
358
359 add_filter('fluentform_editor_init_element_recaptcha', function ($item, $form) {
360 $item['attributes']['name'] = 'g-recaptcha-response';
361 return $item;
362 }, 10, 2);
363
364 add_filter('fluentform_editor_init_element_hcaptcha', function ($item, $form) {
365 $item['attributes']['name'] = 'h-captcha-response';
366 return $item;
367 }, 10, 2);
368
369 add_filter('fluentform_editor_init_element_turnstile', function ($item, $form) {
370 $item['attributes']['name'] = 'cf-turnstile-response';
371 return $item;
372 }, 10, 2);
373 }, 10);
374
375 add_filter('fluentform_addons_extra_menu', function ($menus) {
376 $menus['fluentform_pdf'] = __('Fluent Forms PDF', 'fluentform');
377 return $menus;
378 }, 99, 1);
379
380 add_action('fluentform_addons_page_render_fluentform_pdf', function () {
381 $url = '';
382 if (!defined('FLUENTFORM_PDF_VERSION')) {
383 $url = wp_nonce_url(
384 self_admin_url('update.php?action=install-plugin&plugin=fluentforms-pdf'),
385 'install-plugin_fluentforms-pdf'
386 );
387 }
388
389 \FluentForm\View::render('admin.addons.pdf_promo', [
390 'install_url' => $url,
391 'is_installed' => defined('FLUENTFORM_PDF_VERSION'),
392 ]);
393 });
394
395 //Add file upload location in global settings
396 add_filter('fluentform_get_global_settings_values', function ($values, $key) {
397 if (is_array($key)) {
398 if (in_array('_fluentform_global_form_settings', $key)) {
399 $values['file_upload_optoins'] = FluentForm\App\Helpers\Helper::fileUploadLocations();
400 }
401
402 if (in_array('_fluentform_turnstile_details', $key)) {
403 $values = FluentForm\App\Modules\Turnstile\Turnstile::ensureSettings($values);
404 }
405 }
406 return $values;
407 }, 10, 2);
408
409 add_action('ff_installed_by', function ($by) {
410 if (is_string($by) && !get_option('_ff_ins_by')) {
411 update_option('_ff_ins_by', sanitize_text_field($by), 'no');
412 }
413 });
414
415 //Enables recaptcha validation when autoload recaptcha enabled for all forms
416 $autoIncludeRecaptcha = [
417 [
418 'type' => 'hcaptcha',
419 'is_disabled' => !get_option('_fluentform_hCaptcha_keys_status', false),
420 ],
421 [
422 'type' => 'recaptcha',
423 'is_disabled' => !get_option('_fluentform_reCaptcha_keys_status', false),
424 ],
425 [
426 'type' => 'turnstile',
427 'is_disabled' => !get_option('_fluentform_turnstile_keys_status', false),
428 ],
429 ];
430
431 foreach ($autoIncludeRecaptcha as $input) {
432 if ($input['is_disabled']) {
433 continue;
434 }
435 add_filter('ff_has_auto_' . $input['type'], function () use ($input) {
436 $option = get_option('_fluentform_global_form_settings');
437 $autoload = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.autoload_captcha');
438 $type = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.captcha_type');
439
440 if ($autoload && $type == $input['type']) {
441 return true;
442 }
443 return false;
444 });
445 }