PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.61
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.61
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 / Common.php

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

383 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 use FluentForm\App\Modules\Component\Component;
4
5 /**
6 * Declare common actions/filters/shortcodes
7 */
8
9
10 /**
11 * @var $app \FluentForm\Framework\Foundation\Application
12 */
13
14 add_action('save_post', function ($post_id) {
15 if (isset($_POST['post_content'])) {
16 $post_content = $_POST['post_content'];
17 } else {
18 $post = get_post($post_id);
19 $post_content = $post->post_content;
20 }
21
22 $shortcodeIds = \FluentForm\App\Helpers\Helper::getShortCodeIds(
23 $post_content, 'fluentform', 'id'
24 );
25
26 $shortcodeModalIds = \FluentForm\App\Helpers\Helper::getShortCodeIds(
27 $post_content, 'fluentform_modal', 'form_id'
28 );
29
30 if ($shortcodeModalIds) {
31 $shortcodeIds = array_merge($shortcodeIds, $shortcodeModalIds);
32 }
33
34 if ($shortcodeIds) {
35 update_post_meta($post_id, '_has_fluentform', $shortcodeIds);
36 } elseif (get_post_meta($post_id, '_has_fluentform', true)) {
37 update_post_meta($post_id, '_has_fluentform', []);
38 }
39 });
40
41 $component = new Component($app);
42 $component->addRendererActions();
43 $component->addFluentFormShortCode();
44 $component->addFluentFormDefaultValueParser();
45
46 $component->addFluentformSubmissionInsertedFilter();
47 $component->addIsRenderableFilter();
48 $component->registerInputSanitizers();
49
50 add_action('wp', function () use ($app) {
51 if (isset($_GET['fluentform_pages']) && $_GET['fluentform_pages'] == 1) {
52
53 add_action('wp_enqueue_scripts', function () use ($app) {
54 wp_enqueue_script('jquery');
55 wp_enqueue_style('fluent-form-styles');
56 $form = wpFluent()->table('fluentform_forms')->find(intval($_REQUEST['preview_id']));
57 if (apply_filters('fluentform_load_default_public', true, $form)) {
58 wp_enqueue_style('fluentform-public-default');
59 }
60 wp_enqueue_script('fluent-form-submission');
61 wp_enqueue_style('fluent-form-preview', $app->publicUrl('css/preview.css'));
62 });
63
64 (new \FluentForm\App\Modules\ProcessExteriorModule())->handleExteriorPages($app);
65 }
66 }, 1);
67
68 $elements = [
69 'select',
70 'input_checkbox',
71 'input_radio',
72 'address',
73 'select_country',
74 'gdpr_agreement',
75 'terms_and_condition',
76 ];
77
78 foreach ($elements as $element) {
79 $event = 'fluentform_response_render_' . $element;
80 $app->addFilter($event, function ($response, $field, $form_id, $isLabel = false) {
81 $element = $field['element'];
82
83 if ($element == 'address' && !empty($response->country)) {
84 $countryList = getFluentFormCountryList();
85 if (isset($countryList[$response->country])) {
86 $response->country = $countryList[$response->country];
87 }
88 }
89
90 if ($element == 'select_country') {
91 $countryList = getFluentFormCountryList();
92 if (isset($countryList[$response])) {
93 $response = $countryList[$response];
94 }
95 }
96
97 if (in_array($field['element'], array('gdpr_agreement', 'terms_and_condition'))) {
98 $response = __('Accepted', 'fluentform');
99 }
100
101 if ($response && $isLabel && in_array($element, ['select', 'input_radio'])) {
102 if (isset($field['options'][$response])) {
103 return $field['options'][$response];
104 }
105 }
106
107 if ($element == 'input_checkbox') {
108 return \FluentForm\App\Modules\Form\FormDataParser::formatCheckBoxValues($response, $field, $isLabel);
109 }
110
111 return \FluentForm\App\Modules\Form\FormDataParser::formatValue($response);
112 }, 10, 4);
113 }
114
115 $app->addFilter('fluentform_response_render_textarea', function ($value, $field, $formId, $isHtml) {
116 if (!$isHtml || !$value) {
117 return $value;
118 }
119 return '<span style="white-space: pre-line">' . $value . '</span>';
120 }, 10, 4);
121
122 $app->addFilter('fluentform_response_render_input_file', function ($response, $field, $form_id, $isHtml = false) {
123 return \FluentForm\App\Modules\Form\FormDataParser::formatFileValues($response, $isHtml);
124 }, 10, 4);
125
126
127 $app->addFilter('fluentform_response_render_input_image', function ($response, $field, $form_id, $isHtml = false) {
128 return \FluentForm\App\Modules\Form\FormDataParser::formatImageValues($response, $isHtml);
129 }, 10, 4);
130
131 $app->addFilter('fluentform_response_render_input_repeat', function ($response, $field, $form_id) {
132 return \FluentForm\App\Modules\Form\FormDataParser::formatRepeatFieldValue($response, $field, $form_id);
133 }, 10, 3);
134
135 $app->addFilter('fluentform_response_render_tabular_grid', function ($response, $field, $form_id, $isHtml = false) {
136 return \FluentForm\App\Modules\Form\FormDataParser::formatTabularGridFieldValue($response, $field, $form_id, $isHtml);
137 }, 10, 4);
138
139 $app->addFilter('fluentform_response_render_input_name', function ($response) {
140 return \FluentForm\App\Modules\Form\FormDataParser::formatName($response);
141 }, 10, 1);
142
143 $app->addFilter('fluentform_filter_insert_data', function ($data) {
144 $settings = get_option('_fluentform_global_form_settings', false);
145 if (is_array($settings) && isset($settings['misc'])) {
146 if (isset($settings['misc']['isIpLogingDisabled'])) {
147 if ($settings['misc']['isIpLogingDisabled']) {
148 unset($data['ip']);
149 }
150 }
151 }
152 return $data;
153 });
154
155
156 // Register api response log hooks
157 $app->addAction(
158 'fluentform_after_submission_api_response_success',
159 'fluentform_after_submission_api_response_success', 10, 6
160 );
161
162 $app->addAction(
163 'fluentform_after_submission_api_response_failed',
164 'fluentform_after_submission_api_response_failed', 10, 6
165 );
166
167 function fluentform_after_submission_api_response_success($form, $entryId, $data, $feed, $res, $msg = '')
168 {
169 try {
170 $isDev = wpFluentForm()->getEnv() != 'production';
171 if (!apply_filters('fluentform_api_success_log', $isDev, $form, $feed)) return;
172
173 wpFluent()->table('fluentform_submission_meta')->insert([
174 'response_id' => $entryId,
175 'form_id' => $form->id,
176 'meta_key' => 'api_log',
177 'value' => $msg,
178 'name' => $feed->formattedValue['name'],
179 'status' => 'success',
180 'created_at' => current_time('mysql'),
181 'updated_at' => current_time('mysql')
182 ]);
183 } catch (Exception $e) {
184 error_log($e->getMessage());
185 }
186 }
187
188 function fluentform_after_submission_api_response_failed($form, $entryId, $data, $feed, $res, $msg = '')
189 {
190 try {
191
192 $isDev = wpFluentForm()->getEnv() != 'production';
193 if (!apply_filters('fluentform_api_failed_log', $isDev, $form, $feed)) return;
194
195 wpFluent()->table('fluentform_submission_meta')->insert([
196 'response_id' => $entryId,
197 'form_id' => $form->id,
198 'meta_key' => 'api_log',
199 'value' => json_encode($res),
200 'name' => $feed->formattedValue['name'],
201 'status' => 'failed',
202 'created_at' => current_time('mysql'),
203 'updated_at' => current_time('mysql'),
204 ]);
205 } catch (Exception $e) {
206 error_log($e->getMessage());
207 }
208 }
209
210 $app->bindInstance(
211 'fluentFormAsyncRequest',
212 new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest($app),
213 'FluentFormAsyncRequest',
214 'FluentForm\App\Services\WPAsync\FluentFormAsyncRequest'
215 );
216
217
218 $app->addFilter('fluentform-disabled_analytics', function ($status) {
219 $settings = get_option('_fluentform_global_form_settings');
220 if (isset($settings['misc']['isAnalyticsDisabled']) && $settings['misc']['isAnalyticsDisabled']) {
221 return true;
222 }
223 return $status;
224 });
225
226 $app->addAction('fluentform_before_form_render', function ($form) {
227 do_action('fluentform_load_form_assets', $form->id);
228 });
229
230 $app->addAction('fluentform_load_form_assets', function ($formId) {
231 // check if alreaded loaded
232 if (!in_array($formId, \FluentForm\App\Helpers\Helper::$loadedForms)) {
233 (new \FluentForm\App\Modules\Form\Settings\FormCssJs())->addCssJs($formId);
234 \FluentForm\App\Helpers\Helper::$loadedForms[] = $formId;
235 $selectedStyle = \FluentForm\App\Helpers\Helper::getFormMeta($formId, '_ff_selected_style');
236
237 if ($selectedStyle) {
238 do_action('fluentform_init_custom_stylesheet', $selectedStyle, $formId);
239 }
240 }
241 });
242
243 $app->addAction('fluentform_submission_inserted', function ($insertId, $formData, $form) use ($app) {
244 $notificationManager = new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app);
245 $notificationManager->globalNotify($insertId, $formData, $form);
246 }, 10, 3);
247
248
249 $app->addAction('init', function () use ($app) {
250 new \FluentForm\App\Services\Integrations\MailChimp\MailChimpIntegration($app);
251 });
252
253 $app->addAction('fluentform_form_element_start', function ($form) use ($app) {
254 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
255 $honeyPot->renderHoneyPot($form);
256 });
257
258 $app->addAction('fluentform_before_insert_submission', function ($insertData, $requestData, $form) use ($app) {
259 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
260 $honeyPot->verify($insertData, $requestData, $form->id);
261 }, 9, 3);
262
263 add_action('ff_log_data', function ($data) use ($app) {
264 $dataLogger = new \FluentForm\App\Modules\Logger\DataLogger($app);
265 $dataLogger->log($data);
266 });
267
268 // permision based filters
269 add_filter('fluentform_permission_callback', function ($status, $permission) {
270 return (new \FluentForm\App\Modules\Acl\RoleManager())->currentUserFormFormCapability();
271 }, 10, 2);
272
273 // widgets
274 add_action('widgets_init', function () {
275 register_widget('FluentForm\App\Modules\Widgets\SidebarWidgets');
276 });
277
278 add_action('wp', function () {
279 global $post;
280
281 if (!is_a($post, 'WP_Post')) {
282 return;
283 }
284
285 $fluentFormIds = get_post_meta($post->ID, '_has_fluentform', true);
286
287 if ($fluentFormIds && is_array($fluentFormIds)) {
288 foreach ($fluentFormIds as $formId) {
289 do_action('fluentform_load_form_assets', $formId);
290 }
291 }
292 });
293
294 add_filter('fluentform_validate_input_item_input_email', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
295 add_filter('fluentform_validate_input_item_input_text', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
296
297 add_filter('cron_schedules', function ($schedules) {
298 $schedules['ff_every_five_minutes'] = array(
299 'interval' => 300,
300 'display' => esc_html__('Every 5 minutes (FluentForm)', 'fluentform'),
301 );
302 return $schedules;
303 }, 10, 1);
304
305 add_action('fluentform_do_scheduled_tasks', 'fluentFormHandleScheduledTasks');
306 add_action('fluentform_do_email_report_scheduled_tasks', 'fluentFormHandleScheduledEmailReport');
307
308 add_action('ff_integration_action_result', function ($feed, $status, $note = '') {
309 if (!isset($feed['scheduled_action_id']) || !$status) {
310 return;
311 }
312 if (!$note) {
313 $note = $status;
314 }
315
316 if (strlen($note) > 255) {
317 if (function_exists('mb_substr')) {
318 $note = mb_substr($note, 0, 251) . '...';
319 } else {
320 $note = substr($note, 0, 251) . '...';
321 }
322 }
323
324 $actionId = intval($feed['scheduled_action_id']);
325 wpFluent()->table('ff_scheduled_actions')
326 ->where('id', $actionId)
327 ->update([
328 'status' => $status,
329 'note' => $note
330 ]);
331 }, 10, 3);
332
333 add_action('fluentform_global_notify_completed', function ($insertId, $form) use ($app) {
334 if (strpos($form->form_fields, '"element":"input_password"') && apply_filters('fluentform_truncate_password_values', true, $form)) {
335 // we have password
336 (new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app))->cleanUpPassword($insertId, $form);
337 }
338 }, 10, 2);
339
340 /*
341 * Elementor Block Init
342 */
343
344 if (defined('ELEMENTOR_VERSION')) {
345 new \FluentForm\App\Modules\Widgets\ElementorWidget($app);
346 }
347
348 (new FluentForm\App\Services\Integrations\Slack\SlackNotificationActions($app))->register();
349
350
351 /*
352 * Smartcode parser shortcodes
353 */
354
355 add_filter('ff_will_return_html', function ($result, $integration, $key) {
356 $dictionary = [
357 'notifications' => ['message']
358 ];
359
360 if (!isset($dictionary[$integration])) {
361 return $result;
362 }
363
364 if (in_array($key, $dictionary[$integration])) {
365 return true;
366 }
367
368 return $result;
369
370 }, 10, 3);
371
372
373 $app->addFilter('fluentform_response_render_input_number', function ($response, $field, $form_id, $isHtml = false) {
374 if (!$response || !$isHtml) {
375 return $response;
376 }
377 $fieldSettings = \FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings');
378 $formatter = \FluentForm\Framework\Helpers\ArrayHelper::get($fieldSettings, 'numeric_formatter');
379 if (!$formatter) {
380 return $response;
381 }
382 return \FluentForm\App\Helpers\Helper::getNumericFormatted($response, $formatter);
383 }, 10, 4);