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

389 lines 13.0 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'])) {
103 $field['options'] = [];
104 foreach (\FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings.advanced_options', []) as $option) {
105 $field['options'][$option['value']] = $option['label'];
106 }
107 }
108 if (isset($field['options'][$response])) {
109 return $field['options'][$response];
110 }
111 }
112
113 if ($element == 'input_checkbox') {
114 return \FluentForm\App\Modules\Form\FormDataParser::formatCheckBoxValues($response, $field, $isLabel);
115 }
116
117 return \FluentForm\App\Modules\Form\FormDataParser::formatValue($response);
118 }, 10, 4);
119 }
120
121 $app->addFilter('fluentform_response_render_textarea', function ($value, $field, $formId, $isHtml) {
122 if (!$isHtml || !$value) {
123 return $value;
124 }
125 return '<span style="white-space: pre-line">' . $value . '</span>';
126 }, 10, 4);
127
128 $app->addFilter('fluentform_response_render_input_file', function ($response, $field, $form_id, $isHtml = false) {
129 return \FluentForm\App\Modules\Form\FormDataParser::formatFileValues($response, $isHtml);
130 }, 10, 4);
131
132
133 $app->addFilter('fluentform_response_render_input_image', function ($response, $field, $form_id, $isHtml = false) {
134 return \FluentForm\App\Modules\Form\FormDataParser::formatImageValues($response, $isHtml);
135 }, 10, 4);
136
137 $app->addFilter('fluentform_response_render_input_repeat', function ($response, $field, $form_id) {
138 return \FluentForm\App\Modules\Form\FormDataParser::formatRepeatFieldValue($response, $field, $form_id);
139 }, 10, 3);
140
141 $app->addFilter('fluentform_response_render_tabular_grid', function ($response, $field, $form_id, $isHtml = false) {
142 return \FluentForm\App\Modules\Form\FormDataParser::formatTabularGridFieldValue($response, $field, $form_id, $isHtml);
143 }, 10, 4);
144
145 $app->addFilter('fluentform_response_render_input_name', function ($response) {
146 return \FluentForm\App\Modules\Form\FormDataParser::formatName($response);
147 }, 10, 1);
148
149 $app->addFilter('fluentform_filter_insert_data', function ($data) {
150 $settings = get_option('_fluentform_global_form_settings', false);
151 if (is_array($settings) && isset($settings['misc'])) {
152 if (isset($settings['misc']['isIpLogingDisabled'])) {
153 if ($settings['misc']['isIpLogingDisabled']) {
154 unset($data['ip']);
155 }
156 }
157 }
158 return $data;
159 });
160
161
162 // Register api response log hooks
163 $app->addAction(
164 'fluentform_after_submission_api_response_success',
165 'fluentform_after_submission_api_response_success', 10, 6
166 );
167
168 $app->addAction(
169 'fluentform_after_submission_api_response_failed',
170 'fluentform_after_submission_api_response_failed', 10, 6
171 );
172
173 function fluentform_after_submission_api_response_success($form, $entryId, $data, $feed, $res, $msg = '')
174 {
175 try {
176 $isDev = wpFluentForm()->getEnv() != 'production';
177 if (!apply_filters('fluentform_api_success_log', $isDev, $form, $feed)) return;
178
179 wpFluent()->table('fluentform_submission_meta')->insert([
180 'response_id' => $entryId,
181 'form_id' => $form->id,
182 'meta_key' => 'api_log',
183 'value' => $msg,
184 'name' => $feed->formattedValue['name'],
185 'status' => 'success',
186 'created_at' => current_time('mysql'),
187 'updated_at' => current_time('mysql')
188 ]);
189 } catch (Exception $e) {
190 error_log($e->getMessage());
191 }
192 }
193
194 function fluentform_after_submission_api_response_failed($form, $entryId, $data, $feed, $res, $msg = '')
195 {
196 try {
197
198 $isDev = wpFluentForm()->getEnv() != 'production';
199 if (!apply_filters('fluentform_api_failed_log', $isDev, $form, $feed)) return;
200
201 wpFluent()->table('fluentform_submission_meta')->insert([
202 'response_id' => $entryId,
203 'form_id' => $form->id,
204 'meta_key' => 'api_log',
205 'value' => json_encode($res),
206 'name' => $feed->formattedValue['name'],
207 'status' => 'failed',
208 'created_at' => current_time('mysql'),
209 'updated_at' => current_time('mysql'),
210 ]);
211 } catch (Exception $e) {
212 error_log($e->getMessage());
213 }
214 }
215
216 $app->bindInstance(
217 'fluentFormAsyncRequest',
218 new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest($app),
219 'FluentFormAsyncRequest',
220 'FluentForm\App\Services\WPAsync\FluentFormAsyncRequest'
221 );
222
223
224 $app->addFilter('fluentform-disabled_analytics', function ($status) {
225 $settings = get_option('_fluentform_global_form_settings');
226 if (isset($settings['misc']['isAnalyticsDisabled']) && $settings['misc']['isAnalyticsDisabled']) {
227 return true;
228 }
229 return $status;
230 });
231
232 $app->addAction('fluentform_before_form_render', function ($form) {
233 do_action('fluentform_load_form_assets', $form->id);
234 });
235
236 $app->addAction('fluentform_load_form_assets', function ($formId) {
237 // check if alreaded loaded
238 if (!in_array($formId, \FluentForm\App\Helpers\Helper::$loadedForms)) {
239 (new \FluentForm\App\Modules\Form\Settings\FormCssJs())->addCssJs($formId);
240 \FluentForm\App\Helpers\Helper::$loadedForms[] = $formId;
241 $selectedStyle = \FluentForm\App\Helpers\Helper::getFormMeta($formId, '_ff_selected_style');
242
243 if ($selectedStyle) {
244 do_action('fluentform_init_custom_stylesheet', $selectedStyle, $formId);
245 }
246 }
247 });
248
249 $app->addAction('fluentform_submission_inserted', function ($insertId, $formData, $form) use ($app) {
250 $notificationManager = new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app);
251 $notificationManager->globalNotify($insertId, $formData, $form);
252 }, 10, 3);
253
254
255 $app->addAction('init', function () use ($app) {
256 new \FluentForm\App\Services\Integrations\MailChimp\MailChimpIntegration($app);
257 });
258
259 $app->addAction('fluentform_form_element_start', function ($form) use ($app) {
260 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
261 $honeyPot->renderHoneyPot($form);
262 });
263
264 $app->addAction('fluentform_before_insert_submission', function ($insertData, $requestData, $form) use ($app) {
265 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
266 $honeyPot->verify($insertData, $requestData, $form->id);
267 }, 9, 3);
268
269 add_action('ff_log_data', function ($data) use ($app) {
270 $dataLogger = new \FluentForm\App\Modules\Logger\DataLogger($app);
271 $dataLogger->log($data);
272 });
273
274 // permision based filters
275 add_filter('fluentform_permission_callback', function ($status, $permission) {
276 return (new \FluentForm\App\Modules\Acl\RoleManager())->currentUserFormFormCapability();
277 }, 10, 2);
278
279 // widgets
280 add_action('widgets_init', function () {
281 register_widget('FluentForm\App\Modules\Widgets\SidebarWidgets');
282 });
283
284 add_action('wp', function () {
285 global $post;
286
287 if (!is_a($post, 'WP_Post')) {
288 return;
289 }
290
291 $fluentFormIds = get_post_meta($post->ID, '_has_fluentform', true);
292
293 if ($fluentFormIds && is_array($fluentFormIds)) {
294 foreach ($fluentFormIds as $formId) {
295 do_action('fluentform_load_form_assets', $formId);
296 }
297 }
298 });
299
300 add_filter('fluentform_validate_input_item_input_email', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
301 add_filter('fluentform_validate_input_item_input_text', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
302
303 add_filter('cron_schedules', function ($schedules) {
304 $schedules['ff_every_five_minutes'] = array(
305 'interval' => 300,
306 'display' => esc_html__('Every 5 minutes (FluentForm)', 'fluentform'),
307 );
308 return $schedules;
309 }, 10, 1);
310
311 add_action('fluentform_do_scheduled_tasks', 'fluentFormHandleScheduledTasks');
312 add_action('fluentform_do_email_report_scheduled_tasks', 'fluentFormHandleScheduledEmailReport');
313
314 add_action('ff_integration_action_result', function ($feed, $status, $note = '') {
315 if (!isset($feed['scheduled_action_id']) || !$status) {
316 return;
317 }
318 if (!$note) {
319 $note = $status;
320 }
321
322 if (strlen($note) > 255) {
323 if (function_exists('mb_substr')) {
324 $note = mb_substr($note, 0, 251) . '...';
325 } else {
326 $note = substr($note, 0, 251) . '...';
327 }
328 }
329
330 $actionId = intval($feed['scheduled_action_id']);
331 wpFluent()->table('ff_scheduled_actions')
332 ->where('id', $actionId)
333 ->update([
334 'status' => $status,
335 'note' => $note
336 ]);
337 }, 10, 3);
338
339 add_action('fluentform_global_notify_completed', function ($insertId, $form) use ($app) {
340 if (strpos($form->form_fields, '"element":"input_password"') && apply_filters('fluentform_truncate_password_values', true, $form)) {
341 // we have password
342 (new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app))->cleanUpPassword($insertId, $form);
343 }
344 }, 10, 2);
345
346 /*
347 * Elementor Block Init
348 */
349
350 if (defined('ELEMENTOR_VERSION')) {
351 new \FluentForm\App\Modules\Widgets\ElementorWidget($app);
352 }
353
354 (new FluentForm\App\Services\Integrations\Slack\SlackNotificationActions($app))->register();
355
356
357 /*
358 * Smartcode parser shortcodes
359 */
360
361 add_filter('ff_will_return_html', function ($result, $integration, $key) {
362 $dictionary = [
363 'notifications' => ['message']
364 ];
365
366 if (!isset($dictionary[$integration])) {
367 return $result;
368 }
369
370 if (in_array($key, $dictionary[$integration])) {
371 return true;
372 }
373
374 return $result;
375
376 }, 10, 3);
377
378
379 $app->addFilter('fluentform_response_render_input_number', function ($response, $field, $form_id, $isHtml = false) {
380 if (!$response || !$isHtml) {
381 return $response;
382 }
383 $fieldSettings = \FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings');
384 $formatter = \FluentForm\Framework\Helpers\ArrayHelper::get($fieldSettings, 'numeric_formatter');
385 if (!$formatter) {
386 return $response;
387 }
388 return \FluentForm\App\Helpers\Helper::getNumericFormatted($response, $formatter);
389 }, 10, 4);