PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.6
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.6
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.6, at app/Hooks/Backend.php

367 lines 12.7 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
12 add_action('admin_init', function () use ($app) {
13 (new \FluentForm\App\Modules\Registerer\Menu($app))->reisterScripts();
14 }, 9);
15
16 add_action('admin_enqueue_scripts', function () use ($app) {
17 (new \FluentForm\App\Modules\Registerer\Menu($app))->enqueuePageScripts();
18 }, 10);
19
20 // Add Entries Menu
21 $app->addAction('ff_fluentform_form_application_view_entries', function ($form_id) use ($app) {
22 (new \FluentForm\App\Modules\Entries\Entries())->renderEntries($form_id);
23 });
24
25 $app->addAction('fluentform_after_form_navigation', function ($form_id) use ($app) {
26 (new \FluentForm\App\Modules\Registerer\Menu($app))->addCopyShortcodeButton($form_id);
27 (new \FluentForm\App\Modules\Registerer\Menu($app))->addPreviewButton($form_id);
28 });
29
30 $app->addAction('media_buttons', function () {
31 (new \FluentForm\App\Modules\EditorButtonModule())->addButton();
32 });
33
34 $app->addAction('fluentform_addons_page_render_fluentform_add_ons', function () {
35 (new \FluentForm\App\Modules\AddOnModule())->showFluentAddOns();
36 });
37
38 // This is temp, we will remove this after 2-3 versions.
39 add_filter('pre_set_site_transient_update_plugins', function ($updates) {
40 if (!empty($updates->response['fluentformpro'])) {
41 $updates->response['fluentformpro/fluentformpro.php'] = $updates->response['fluentformpro'];
42 unset($updates->response['fluentformpro']);
43 }
44 return $updates;
45 }, 999, 1);
46
47 $app->addAction('fluentform_global_menu', function () use ($app) {
48 $menu = new \FluentForm\App\Modules\Registerer\Menu($app);
49 $menu->renderGlobalMenu();
50 if (get_option('fluentform_scheduled_actions_migrated') != 'yes') {
51 \FluentForm\App\Databases\Migrations\ScheduledActions::migrate();
52 }
53
54 $hookName = 'fluentform_do_scheduled_tasks';
55 if (!wp_next_scheduled($hookName)) {
56 wp_schedule_event(time(), 'ff_every_five_minutes', $hookName);
57 }
58
59 $emailReportHookName = 'fluentform_do_email_report_scheduled_tasks';
60 if (!wp_next_scheduled($emailReportHookName)) {
61 wp_schedule_event(time(), 'daily', $emailReportHookName);
62 }
63
64 });
65
66 $app->addAction('wp_dashboard_setup', function () {
67 $roleManager = new \FluentForm\App\Modules\Acl\Acl();
68
69 if (!$roleManager->getCurrentUserCapability()) {
70 return;
71 }
72 wp_add_dashboard_widget('fluentform_stat_widget', __('Fluent Forms Latest Form Submissions', 'fluentform'), function () {
73 (new \FluentForm\App\Modules\DashboardWidgetModule)->showStat();
74 }, 10, 1);
75 });
76
77 add_action('admin_init', function () {
78 $disablePages = [
79 'fluent_forms',
80 'fluent_forms_transfer',
81 'fluent_forms_settings',
82 'fluent_forms_add_ons',
83 'fluent_forms_docs',
84 'fluent_forms_all_entries',
85 'msformentries'
86 ];
87
88 if (isset($_GET['page']) && in_array($_GET['page'], $disablePages)) {
89 remove_all_actions('admin_notices');
90 }
91 });
92
93
94 add_filter('fluentform_editor_init_element_container', function ($item) {
95 if (!isset($item['settings']['container_class'])) {
96 $item['settings']['container_class'] = '';
97 }
98 return $item;
99 });
100
101 add_action('enqueue_block_editor_assets', function () use ($app) {
102 wp_enqueue_script(
103 'fluentform-gutenberg-block',
104 $app->publicUrl("js/fluent_gutenblock.js"),
105 array('wp-element', 'wp-polyfill' , 'wp-i18n', 'wp-blocks' ,'wp-components'),
106 FLUENTFORM_VERSION
107 );
108
109 $forms = wpFluent()->table('fluentform_forms')
110 ->select(['id', 'title'])
111 ->orderBy('id', 'DESC')
112 ->get();
113
114 array_unshift($forms, (object)[
115 'id' => '',
116 'title' => __('-- Select a form --', 'fluentform')
117 ]);
118
119 wp_localize_script('fluentform-gutenberg-block', 'fluentform_block_vars', [
120 'logo' => $app->publicUrl('img/fluent_icon.png'),
121 'forms' => $forms
122 ]);
123
124 wp_enqueue_style(
125 'fluentform-gutenberg-block',
126 $app->publicUrl("css/fluent_gutenblock.css"),
127 array('wp-edit-blocks')
128 );
129
130 });
131
132 add_action('wp_print_scripts', function () {
133 if (is_admin()) {
134 if (\FluentForm\App\Helpers\Helper::isFluentAdminPage()) {
135 $option = get_option('_fluentform_global_form_settings');
136 $isSkip = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.noConflictStatus') == 'no';
137 $isSkip = apply_filters('fluentform_skip_no_conflict', $isSkip);
138
139 if ($isSkip) {
140 return;
141 }
142
143 global $wp_scripts;
144 if (!$wp_scripts) {
145 return;
146 }
147
148 $pluginUrl = plugins_url();
149 foreach ($wp_scripts->queue as $script) {
150
151 if (!isset($wp_scripts->registered[$script])) {
152 continue;
153 }
154
155 $src = $wp_scripts->registered[$script]->src;
156 if (strpos($src, $pluginUrl) !== false && !strpos($src, 'fluentform') !== false) {
157 wp_dequeue_script($wp_scripts->registered[$script]->handle);
158 }
159 }
160 }
161 }
162 }, 1);
163
164 add_action('fluentform_loading_editor_assets', function ($form) {
165
166 add_filter('fluentform_editor_init_element_input_name', function ($field) {
167 if (empty($field['settings']['label_placement'])) {
168 $field['settings']['label_placement'] = '';
169 }
170 return $field;
171 });
172
173 $upgradableCheckInputs = [
174 'input_radio',
175 'select',
176 'select_country',
177 'input_checkbox'
178 ];
179
180 foreach ($upgradableCheckInputs as $upgradeElement) {
181 add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) use ($upgradeElement) {
182 if (!\FluentForm\Framework\Helpers\ArrayHelper::get($element, 'settings.advanced_options')) {
183 $formattedOptions = [];
184 $oldOptions = \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'options', []);
185 foreach ($oldOptions as $value => $label) {
186 $formattedOptions[] = [
187 'label' => $label,
188 'value' => $value,
189 'calc_value' => '',
190 'image' => ''
191 ];
192 }
193 $element['settings']['advanced_options'] = $formattedOptions;
194 $element['settings']['enable_image_input'] = false;
195 $element['settings']['calc_value_status'] = false;
196 $element['settings']['calc_value_status'] = false;
197 unset($element['options']);
198
199 if ($upgradeElement == 'input_radio' || $upgradeElement == 'input_checkbox') {
200 $element['editor_options']['template'] = 'inputCheckable';
201 }
202 }
203
204 if (!isset($element['settings']['layout_class']) && in_array($upgradeElement, ['input_radio', 'input_checkbox'])) {
205 $element['settings']['layout_class'] = '';
206 }
207
208 if (!isset($element['settings']['dynamic_default_value'])) {
209 $element['settings']['dynamic_default_value'] = '';
210 }
211
212 if ($upgradeElement != 'select_country' && !isset($element['settings']['randomize_options'])) {
213 $element['settings']['randomize_options'] = 'no';
214 }
215
216 if ($upgradeElement == 'select' && \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'attributes.multiple') && empty($element['settings']['max_selection'])) {
217 $element['settings']['max_selection'] = '';
218 }
219
220 if (($upgradeElement == 'select' || $upgradeElement = 'select_country') && !isset($element['settings']['enable_select_2'])) {
221 $element['settings']['enable_select_2'] = 'no';
222 }
223
224 if ($upgradeElement != 'select_country' && !isset($element['settings']['values_visible'])) {
225 $element['settings']['values_visible'] = false;
226 }
227
228 return $element;
229 });
230 }
231
232 $upgradableFileInputs = [
233 'input_file',
234 'input_image',
235 ];
236 foreach ($upgradableFileInputs as $upgradeElement) {
237 add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) {
238 $element['settings']['upload_file_location'] = 'default';
239 $element['settings']['file_location_type'] = 'follow_global_settings';
240 return $element;
241 });
242 }
243
244 add_filter('fluentform_editor_init_element_gdpr_agreement', function ($element) {
245 if (!isset($element['settings']['required_field_message'])) {
246 $element['settings']['required_field_message'] = '';
247 }
248 return $element;
249 });
250
251 add_filter('fluentform_editor_init_element_input_text', function ($element) {
252 if (!isset($element['attributes']['maxlength'])) {
253 $element['attributes']['maxlength'] = '';
254 }
255 return $element;
256 });
257
258 add_filter('fluentform_editor_init_element_textarea', function ($element) {
259 if (!isset($element['attributes']['maxlength'])) {
260 $element['attributes']['maxlength'] = '';
261 }
262 return $element;
263 });
264
265 add_filter('fluentform_editor_init_element_input_date', function ($item) {
266 if (!isset($item['settings']['date_config'])) {
267 $item['settings']['date_config'] = '';
268 }
269 return $item;
270 });
271
272 add_filter('fluentform_editor_init_element_container', function ($item) {
273 if (!isset($item['settings']['conditional_logics'])) {
274 $item['settings']['conditional_logics'] = [];
275 }
276 return $item;
277 });
278
279 add_filter('fluentform_editor_init_element_input_number', function ($item) {
280 if (!isset($item['settings']['number_step'])) {
281 $item['settings']['number_step'] = '';
282 }
283 if (!isset($item['settings']['numeric_formatter'])) {
284 $item['settings']['numeric_formatter'] = '';
285 }
286 if (!isset($item['settings']['prefix_label'])) {
287 $item['settings']['prefix_label'] = '';
288 }
289 if (!isset($item['settings']['suffix_label'])) {
290 $item['settings']['suffix_label'] = '';
291 }
292 return $item;
293 });
294
295 add_filter('fluentform_editor_init_element_input_email', function ($item) {
296 if (!isset($item['settings']['is_unique'])) {
297 $item['settings']['is_unique'] = 'no';
298 }
299 if (!isset($item['settings']['unique_validation_message'])) {
300 $item['settings']['unique_validation_message'] = __('Email address need to be unique.', 'fluentform');
301 }
302 if (!isset($item['settings']['prefix_label'])) {
303 $item['settings']['prefix_label'] = '';
304 }
305 if (!isset($item['settings']['suffix_label'])) {
306 $item['settings']['suffix_label'] = '';
307 }
308 return $item;
309 });
310
311 add_filter('fluentform_editor_init_element_input_text', function ($item) {
312 if (isset($item['attributes']['data-mask'])) {
313 if (!isset($item['settings']['data-mask-reverse'])) {
314 $item['settings']['data-mask-reverse'] = 'no';
315 }
316 if (!isset($item['settings']['data-clear-if-not-match'])) {
317 $item['settings']['data-clear-if-not-match'] = 'no';
318 }
319 } else {
320 if (!isset($item['settings']['is_unique'])) {
321 $item['settings']['is_unique'] = 'no';
322 }
323 if (!isset($item['settings']['unique_validation_message'])) {
324 $item['settings']['unique_validation_message'] = __('This field value need to be unique.', 'fluentform');
325 }
326 }
327
328 if (!isset($item['settings']['prefix_label'])) {
329 $item['settings']['prefix_label'] = '';
330 }
331 if (!isset($item['settings']['suffix_label'])) {
332 $item['settings']['suffix_label'] = '';
333 }
334
335 return $item;
336 });
337
338 }, 10);
339
340
341 add_filter('fluentform_addons_extra_menu', function ($menus) {
342 $menus['fluentform_pdf'] = __('Fluent Forms PDF', 'fluentform');
343 return $menus;
344 }, 99, 1);
345
346 add_action('fluentform_addons_page_render_fluentform_pdf', function () {
347 $url = '';
348 if (!defined('FLUENTFORM_PDF_VERSION')) {
349 $url = wp_nonce_url(
350 self_admin_url('update.php?action=install-plugin&plugin=fluentforms-pdf'),
351 'install-plugin_fluentforms-pdf'
352 );
353 }
354
355 \FluentForm\View::render('admin.addons.pdf_promo', [
356 'install_url' => $url,
357 'is_installed' => defined('FLUENTFORM_PDF_VERSION')
358 ]);
359 });
360
361 //Add file upload location in global settings
362 add_filter('fluentform_get_global_settings_values', function ($value) {
363 $value['file_upload_optoins'] = FluentForm\App\Helpers\Helper::fileUploadLocations();
364 return $value;
365 }, 10, 1);
366
367