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 / Common.php

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

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