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

326 lines 11.3 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 (get_option('fluentform_scheduled_actions_migrated') != 'yes') {
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
65 $app->addAction('wp_dashboard_setup', function () {
66 $roleManager = new \FluentForm\App\Modules\Acl\RoleManager();
67 if (!$roleManager->currentUserFormFormCapability()) {
68 return;
69 }
70 wp_add_dashboard_widget('fluenform_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_form_add_ons',
81 'fluent_forms_docs',
82 'fluent_forms_all_entries',
83 'msformentries'
84 ];
85
86 if (isset($_GET['page']) && in_array($_GET['page'], $disablePages)) {
87 remove_all_actions('admin_notices');
88 }
89 });
90
91
92 add_filter('fluentform_editor_init_element_container', function ($item) {
93 if (!isset($item['settings']['container_class'])) {
94 $item['settings']['container_class'] = '';
95 }
96 return $item;
97 });
98
99 add_action('enqueue_block_editor_assets', function () use ($app) {
100 wp_enqueue_script(
101 'fluentform-gutenberg-block',
102 $app->publicUrl("js/fluent_gutenblock.js"),
103 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor')
104 );
105
106 $forms = wpFluent()->table('fluentform_forms')
107 ->select(['id', 'title'])
108 ->orderBy('id', 'DESC')
109 ->get();
110
111 array_unshift($forms, (object)[
112 'id' => '',
113 'title' => __('-- Select a form --', 'fluentform')
114 ]);
115
116 wp_localize_script('fluentform-gutenberg-block', 'fluentform_block_vars', [
117 'logo' => $app->publicUrl('img/fluent_icon.png'),
118 'forms' => $forms
119 ]);
120
121 wp_enqueue_style(
122 'fluentform-gutenberg-block',
123 $app->publicUrl("css/fluent_gutenblock.css"),
124 array('wp-edit-blocks')
125 );
126
127 });
128
129 add_action('wp_print_scripts', function () {
130 if (is_admin()) {
131 if (\FluentForm\App\Helpers\Helper::isFluentAdminPage()) {
132 $option = get_option('_fluentform_global_form_settings');
133 $isSkip = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.noConflictStatus') == 'no';
134 $isSkip = apply_filters('fluentform_skip_no_conflict', $isSkip);
135
136 if ($isSkip) {
137 return;
138 }
139
140 global $wp_scripts;
141 if (!$wp_scripts) {
142 return;
143 }
144
145 $pluginUrl = plugins_url();
146 foreach ($wp_scripts->queue as $script) {
147 $src = $wp_scripts->registered[$script]->src;
148 if (strpos($src, $pluginUrl) !== false && !strpos($src, 'fluentform') !== false) {
149 wp_dequeue_script($wp_scripts->registered[$script]->handle);
150 }
151 }
152
153 }
154 }
155 }, 1);
156
157 add_action('fluentform_loading_editor_assets', function ($form) {
158
159 add_filter('fluentform_editor_init_element_input_name', function ($field) {
160 if (empty($field['settings']['label_placement'])) {
161 $field['settings']['label_placement'] = '';
162 }
163 return $field;
164 });
165
166 $upgradableCheckInputs = [
167 'input_radio',
168 'select',
169 'select_country',
170 'input_checkbox'
171 ];
172
173 foreach ($upgradableCheckInputs as $upgradeElement) {
174 add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) use ($upgradeElement) {
175 if (!\FluentForm\Framework\Helpers\ArrayHelper::get($element, 'settings.advanced_options')) {
176 $formattedOptions = [];
177 $oldOptions = \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'options', []);
178 foreach ($oldOptions as $value => $label) {
179 $formattedOptions[] = [
180 'label' => $label,
181 'value' => $value,
182 'calc_value' => '',
183 'image' => ''
184 ];
185 }
186 $element['settings']['advanced_options'] = $formattedOptions;
187 $element['settings']['enable_image_input'] = false;
188 $element['settings']['calc_value_status'] = false;
189 $element['settings']['calc_value_status'] = false;
190 unset($element['options']);
191
192 if ($upgradeElement == 'input_radio' || $upgradeElement == 'input_checkbox') {
193 $element['editor_options']['template'] = 'inputCheckable';
194 }
195 }
196
197 if (!isset($element['settings']['layout_class']) && in_array($upgradeElement, ['input_radio', 'input_checkbox'])) {
198 $element['settings']['layout_class'] = '';
199 }
200
201 if (!isset($element['settings']['dynamic_default_value'])) {
202 $element['settings']['dynamic_default_value'] = '';
203 }
204
205 if ($upgradeElement != 'select_country' && !isset($element['settings']['randomize_options'])) {
206 $element['settings']['randomize_options'] = 'no';
207 }
208
209 if($upgradeElement == 'select' && \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'attributes.multiple') && empty($element['settings']['max_selection'])) {
210 $element['settings']['max_selection'] = '';
211 }
212
213 if($upgradeElement == 'select' || $upgradeElement = 'select_country' && !isset($element['settings']['enable_select_2'])) {
214 $element['settings']['enable_select_2'] = 'no';
215 }
216
217 return $element;
218 });
219 }
220
221 add_filter('fluentform_editor_init_element_gdpr_agreement', function ($element) {
222 if (!isset($element['settings']['required_field_message'])) {
223 $element['settings']['required_field_message'] = '';
224 }
225 return $element;
226 });
227
228 add_filter('fluentform_editor_init_element_input_text', function ($element) {
229 if (!isset($element['attributes']['maxlength'])) {
230 $element['settings']['maxlength'] = '';
231 }
232 return $element;
233 });
234
235 add_filter('fluentform_editor_init_element_textarea', function ($element) {
236 if (!isset($element['attributes']['maxlength'])) {
237 $element['settings']['maxlength'] = '';
238 }
239 return $element;
240 });
241
242 add_filter('fluentform_editor_init_element_input_date', function ($item) {
243 if (!isset($item['settings']['date_config'])) {
244 $item['settings']['date_config'] = '';
245 }
246 return $item;
247 });
248
249 add_filter('fluentform_editor_init_element_container', function ($item) {
250 if (!isset($item['settings']['conditional_logics'])) {
251 $item['settings']['conditional_logics'] = [];
252 }
253 return $item;
254 });
255
256 add_filter('fluentform_editor_init_element_input_number', function ($item) {
257 if (!isset($item['settings']['number_step'])) {
258 $item['settings']['number_step'] = '';
259 }
260 if (!isset($item['settings']['prefix_label'])) {
261 $item['settings']['prefix_label'] = '';
262 }
263 if (!isset($item['settings']['numeric_formatter'])) {
264 $item['settings']['numeric_formatter'] = '';
265 }
266 if (!isset($item['settings']['suffix_label'])) {
267 $item['settings']['suffix_label'] = '';
268 }
269 return $item;
270 });
271
272 add_filter('fluentform_editor_init_element_input_email', function ($item) {
273 if (!isset($item['settings']['is_unique'])) {
274 $item['settings']['is_unique'] = 'no';
275 }
276 if (!isset($item['settings']['unique_validation_message'])) {
277 $item['settings']['unique_validation_message'] = __('Email address need to be unique.', 'fluentform');
278 }
279 return $item;
280 });
281
282 add_filter('fluentform_editor_init_element_input_text', function ($item) {
283 if(isset($item['attributes']['data-mask'])) {
284 if (!isset($item['settings']['data-mask-reverse'])) {
285 $item['settings']['data-mask-reverse'] = 'no';
286 }
287 if (!isset($item['settings']['data-clear-if-not-match'])) {
288 $item['settings']['data-clear-if-not-match'] = 'no';
289 }
290 } else {
291 if (!isset($item['settings']['is_unique'])) {
292 $item['settings']['is_unique'] = 'no';
293 }
294 if (!isset($item['settings']['unique_validation_message'])) {
295 $item['settings']['unique_validation_message'] = __('This field value need to be unique.', 'fluentform');
296 }
297 }
298
299 return $item;
300 });
301
302 }, 10);
303
304
305 add_filter('fluentform_addons_extra_menu', function ($menus) {
306 $menus['fluentform_pdf'] = __('Fluent Forms PDF', 'fluentform');
307 return $menus;
308 }, 99, 1);
309
310 add_action('fluentform_addons_page_render_fluentform_pdf', function () {
311 $url = '';
312 if (!defined('FLUENTFORM_PDF_VERSION')) {
313 $url = wp_nonce_url(
314 self_admin_url('update.php?action=install-plugin&plugin=fluentforms-pdf'),
315 'install-plugin_fluentforms-pdf'
316 );
317 }
318
319 echo \FluentForm\View::make('admin.addons.pdf_promo', [
320 'install_url' => $url,
321 'is_installed' => defined('FLUENTFORM_PDF_VERSION')
322 ]);
323 });
324
325
326