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

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

463 lines 15.5 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 // @todo: We will remove the fluentform_pages check from April 2021
52 if ((isset($_GET['fluent_forms_pages']) || isset($_GET['fluentform_pages']))) {
53
54 if (empty(isset($_GET['fluent_forms_pages'])) && empty($_GET['fluentform_pages'])) {
55 return;
56 }
57
58 add_action('wp_enqueue_scripts', function () use ($app) {
59 wp_enqueue_script('jquery');
60 wp_enqueue_script(
61 'fluent_forms_global',
62 $app->publicUrl('js/fluent_forms_global.js'),
63 array('jquery'),
64 FLUENTFORM_VERSION,
65 true
66 );
67 wp_localize_script('fluent_forms_global', 'fluent_forms_global_var', [
68 'fluent_forms_admin_nonce' => wp_create_nonce('fluent_forms_admin_nonce'),
69 'ajaxurl' => admin_url('admin-ajax.php')
70 ]);
71 wp_enqueue_style('fluent-form-styles');
72 $form = wpFluent()->table('fluentform_forms')->find(intval($_REQUEST['preview_id']));
73 if (apply_filters('fluentform_load_default_public', true, $form)) {
74 wp_enqueue_style('fluentform-public-default');
75 }
76 wp_enqueue_script('fluent-form-submission');
77 wp_enqueue_style('fluent-form-preview', $app->publicUrl('css/preview.css'));
78 });
79
80 (new \FluentForm\App\Modules\ProcessExteriorModule())->handleExteriorPages();
81 }
82 }, 1);
83
84 $elements = [
85 'select',
86 'input_checkbox',
87 'input_radio',
88 'address',
89 'select_country',
90 'gdpr_agreement',
91 'terms_and_condition',
92 ];
93
94 foreach ($elements as $element) {
95 $event = 'fluentform_response_render_' . $element;
96 $app->addFilter($event, function ($response, $field, $form_id, $isLabel = false) {
97 $element = $field['element'];
98
99 if ($element == 'address' && !empty($response->country)) {
100 $countryList = getFluentFormCountryList();
101 if (isset($countryList[$response->country])) {
102 $response->country = $countryList[$response->country];
103 }
104 }
105
106 if ($element == 'select_country') {
107 $countryList = getFluentFormCountryList();
108 if (isset($countryList[$response])) {
109 $response = $countryList[$response];
110 }
111 }
112
113 if (in_array($field['element'], array('gdpr_agreement', 'terms_and_condition'))) {
114 if (!empty($response)) {
115 $response = __('Accepted', 'fluentform');
116 }
117 }
118
119 if ($response && $isLabel && in_array($element, ['select', 'input_radio']) && !is_array($response)) {
120 if (!isset($field['options'])) {
121 $field['options'] = [];
122 foreach (\FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings.advanced_options', []) as $option) {
123 $field['options'][$option['value']] = $option['label'];
124 }
125 }
126 if (isset($field['options'][$response])) {
127 return $field['options'][$response];
128 }
129 }
130
131 if (in_array($element, ['select', 'input_checkbox']) && is_array($response)) {
132 return \FluentForm\App\Modules\Form\FormDataParser::formatCheckBoxValues($response, $field, $isLabel);
133 }
134
135 return \FluentForm\App\Modules\Form\FormDataParser::formatValue($response);
136 }, 10, 4);
137 }
138
139 $app->addFilter('fluentform_response_render_textarea', function ($value, $field, $formId, $isHtml) {
140 $value = $value ? nl2br($value) : $value;
141
142 if (!$isHtml || !$value) {
143 return $value;
144 }
145 return '<span style="white-space: pre-line">' . $value . '</span>';
146 }, 10, 4);
147
148 $app->addFilter('fluentform_response_render_input_file', function ($response, $field, $form_id, $isHtml = false) {
149 return \FluentForm\App\Modules\Form\FormDataParser::formatFileValues($response, $isHtml, $form_id);
150 }, 10, 4);
151
152
153 $app->addFilter('fluentform_response_render_input_image', function ($response, $field, $form_id, $isHtml = false) {
154 return \FluentForm\App\Modules\Form\FormDataParser::formatImageValues($response, $isHtml, $form_id);
155 }, 10, 4);
156
157 $app->addFilter('fluentform_response_render_input_repeat', function ($response, $field, $form_id) {
158 return \FluentForm\App\Modules\Form\FormDataParser::formatRepeatFieldValue($response, $field, $form_id);
159 }, 10, 3);
160
161 $app->addFilter('fluentform_response_render_tabular_grid', function ($response, $field, $form_id, $isHtml = false) {
162 return \FluentForm\App\Modules\Form\FormDataParser::formatTabularGridFieldValue($response, $field, $form_id, $isHtml);
163 }, 10, 4);
164
165 $app->addFilter('fluentform_response_render_input_name', function ($response) {
166 return \FluentForm\App\Modules\Form\FormDataParser::formatName($response);
167 }, 10, 1);
168
169 $app->addFilter('fluentform_filter_insert_data', function ($data) {
170 $settings = get_option('_fluentform_global_form_settings', false);
171 if (is_array($settings) && isset($settings['misc'])) {
172 if (isset($settings['misc']['isIpLogingDisabled'])) {
173 if ($settings['misc']['isIpLogingDisabled']) {
174 unset($data['ip']);
175 }
176 }
177 }
178 return $data;
179 });
180
181
182 // Register api response log hooks
183 $app->addAction(
184 'fluentform_after_submission_api_response_success',
185 'fluentform_after_submission_api_response_success', 10, 6
186 );
187
188 $app->addAction(
189 'fluentform_after_submission_api_response_failed',
190 'fluentform_after_submission_api_response_failed', 10, 6
191 );
192
193 function fluentform_after_submission_api_response_success($form, $entryId, $data, $feed, $res, $msg = '')
194 {
195 try {
196 $isDev = wpFluentForm()->getEnv() != 'production';
197 if (!apply_filters('fluentform_api_success_log', $isDev, $form, $feed)) return;
198
199 wpFluent()->table('fluentform_submission_meta')->insert([
200 'response_id' => $entryId,
201 'form_id' => $form->id,
202 'meta_key' => 'api_log',
203 'value' => $msg,
204 'name' => $feed->formattedValue['name'],
205 'status' => 'success',
206 'created_at' => current_time('mysql'),
207 'updated_at' => current_time('mysql')
208 ]);
209 } catch (Exception $e) {
210 error_log($e->getMessage());
211 }
212 }
213
214 function fluentform_after_submission_api_response_failed($form, $entryId, $data, $feed, $res, $msg = '')
215 {
216 try {
217
218 $isDev = wpFluentForm()->getEnv() != 'production';
219 if (!apply_filters('fluentform_api_failed_log', $isDev, $form, $feed)) return;
220
221 wpFluent()->table('fluentform_submission_meta')->insert([
222 'response_id' => $entryId,
223 'form_id' => $form->id,
224 'meta_key' => 'api_log',
225 'value' => json_encode($res),
226 'name' => $feed->formattedValue['name'],
227 'status' => 'failed',
228 'created_at' => current_time('mysql'),
229 'updated_at' => current_time('mysql'),
230 ]);
231 } catch (Exception $e) {
232 error_log($e->getMessage());
233 }
234 }
235
236 $app->bindInstance(
237 'fluentFormAsyncRequest',
238 new \FluentForm\App\Services\WPAsync\FluentFormAsyncRequest($app),
239 'FluentFormAsyncRequest',
240 'FluentForm\App\Services\WPAsync\FluentFormAsyncRequest'
241 );
242
243
244 $app->addFilter('fluentform-disabled_analytics', function ($status) {
245 $settings = get_option('_fluentform_global_form_settings');
246 if (isset($settings['misc']['isAnalyticsDisabled']) && $settings['misc']['isAnalyticsDisabled']) {
247 return true;
248 }
249 return $status;
250 });
251
252 $app->addAction('fluentform_before_form_render', function ($form) {
253 do_action('fluentform_load_form_assets', $form->id);
254 });
255
256 $app->addAction('fluentform_load_form_assets', function ($formId) {
257 // check if alreaded loaded
258 if (!in_array($formId, \FluentForm\App\Helpers\Helper::$loadedForms)) {
259 (new \FluentForm\App\Modules\Form\Settings\FormCssJs())->addCssJs($formId);
260 \FluentForm\App\Helpers\Helper::$loadedForms[] = $formId;
261 $selectedStyle = \FluentForm\App\Helpers\Helper::getFormMeta($formId, '_ff_selected_style');
262
263 if ($selectedStyle) {
264 do_action('fluentform_init_custom_stylesheet', $selectedStyle, $formId);
265 }
266 }
267 });
268
269 $app->addAction('fluentform_submission_inserted', function ($insertId, $formData, $form) use ($app) {
270 $notificationManager = new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app);
271 $notificationManager->globalNotify($insertId, $formData, $form);
272 }, 10, 3);
273
274
275 $app->addAction('init', function () use ($app) {
276 new \FluentForm\App\Services\Integrations\MailChimp\MailChimpIntegration($app);
277 });
278
279 $app->addAction('fluentform_form_element_start', function ($form) use ($app) {
280 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
281 $honeyPot->renderHoneyPot($form);
282 });
283
284 $app->addAction('fluentform_before_insert_submission', function ($insertData, $requestData, $form) use ($app) {
285 $honeyPot = new \FluentForm\App\Modules\Form\HoneyPot($app);
286 $honeyPot->verify($insertData, $requestData, $form->id);
287 }, 9, 3);
288
289 add_action('ff_log_data', function ($data) use ($app) {
290 $dataLogger = new \FluentForm\App\Modules\Logger\DataLogger($app);
291 $dataLogger->log($data);
292 });
293
294 // permision based filters
295 add_filter('fluentform_permission_callback', function ($status, $permission) {
296 return (new \FluentForm\App\Modules\Acl\RoleManager())->currentUserFormFormCapability();
297 }, 10, 2);
298
299 // widgets
300 add_action('widgets_init', function () {
301 register_widget('FluentForm\App\Modules\Widgets\SidebarWidgets');
302 });
303
304 add_action('wp', function () {
305 global $post;
306
307 if (!is_a($post, 'WP_Post')) {
308 return;
309 }
310
311 $fluentFormIds = get_post_meta($post->ID, '_has_fluentform', true);
312
313 if ($fluentFormIds && is_array($fluentFormIds)) {
314 foreach ($fluentFormIds as $formId) {
315 do_action('fluentform_load_form_assets', $formId);
316 }
317 }
318 });
319
320 add_filter('fluentform_validate_input_item_input_email', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
321 add_filter('fluentform_validate_input_item_input_text', ['\FluentForm\App\Helpers\Helper', 'isUniqueValidation'], 10, 5);
322
323 add_filter('cron_schedules', function ($schedules) {
324 $schedules['ff_every_five_minutes'] = array(
325 'interval' => 300,
326 'display' => esc_html__('Every 5 minutes (FluentForm)', 'fluentform'),
327 );
328 return $schedules;
329 }, 10, 1);
330
331 add_action('fluentform_do_scheduled_tasks', 'fluentFormHandleScheduledTasks');
332 add_action('fluentform_do_email_report_scheduled_tasks', 'fluentFormHandleScheduledEmailReport');
333
334 add_action('ff_integration_action_result', function ($feed, $status, $note = '') {
335 if (!isset($feed['scheduled_action_id']) || !$status) {
336 return;
337 }
338 if (!$note) {
339 $note = $status;
340 }
341
342 if (strlen($note) > 255) {
343 if (function_exists('mb_substr')) {
344 $note = mb_substr($note, 0, 251) . '...';
345 } else {
346 $note = substr($note, 0, 251) . '...';
347 }
348 }
349
350 $actionId = intval($feed['scheduled_action_id']);
351 wpFluent()->table('ff_scheduled_actions')
352 ->where('id', $actionId)
353 ->update([
354 'status' => $status,
355 'note' => $note
356 ]);
357 }, 10, 3);
358
359 add_action('fluentform_global_notify_completed', function ($insertId, $form) use ($app) {
360 if (strpos($form->form_fields, '"element":"input_password"') && apply_filters('fluentform_truncate_password_values', true, $form)) {
361 // we have password
362 (new \FluentForm\App\Services\Integrations\GlobalNotificationManager($app))->cleanUpPassword($insertId, $form);
363 }
364 }, 10, 2);
365
366 /*
367 * Elementor Block Init
368 */
369
370 if (defined('ELEMENTOR_VERSION')) {
371 new \FluentForm\App\Modules\Widgets\ElementorWidget($app);
372 }
373 /*
374 * Oxygen Widget Init
375 */
376
377 add_action('init', function (){
378 if (class_exists('OxyEl')) {
379 if ( file_exists( FLUENTFORM_DIR_PATH.'app/Modules/Widgets/OxygenWidget.php' ) ) {
380 new FluentForm\App\Modules\Widgets\OxygenWidget();
381 }
382 }
383 });
384
385 (new FluentForm\App\Services\Integrations\Slack\SlackNotificationActions($app))->register();
386
387
388 /*
389 * Smartcode parser shortcodes
390 */
391
392 add_filter('ff_will_return_html', function ($result, $integration, $key) {
393 $dictionary = [
394 'notifications' => ['message']
395 ];
396
397 if (!isset($dictionary[$integration])) {
398 return $result;
399 }
400
401 if (in_array($key, $dictionary[$integration])) {
402 return true;
403 }
404
405 return $result;
406
407 }, 10, 3);
408
409
410 $app->addFilter('fluentform_response_render_input_number', function ($response, $field, $form_id, $isHtml = false) {
411 if (!$response || !$isHtml) {
412 return $response;
413 }
414 $fieldSettings = \FluentForm\Framework\Helpers\ArrayHelper::get($field, 'raw.settings');
415 $formatter = \FluentForm\Framework\Helpers\ArrayHelper::get($fieldSettings, 'numeric_formatter');
416 if (!$formatter) {
417 return $response;
418 }
419 return \FluentForm\App\Helpers\Helper::getNumericFormatted($response, $formatter);
420 }, 10, 4);
421
422
423 new \FluentForm\App\Services\FormBuilder\Components\CustomSubmitButton();
424
425 if (function_exists('register_block_type')) {
426 register_block_type('fluentfom/guten-block', array(
427 'render_callback' => function ($atts) {
428
429 if (empty($atts['formId'])) {
430 return '';
431 }
432
433 $className = \FluentForm\Framework\Helpers\ArrayHelper::get($atts, 'className');
434
435 if ($className) {
436 $classes = explode(' ', $className);
437 $className = '';
438 if (!empty($classes)) {
439 foreach ($classes as $class) {
440 $className .= sanitize_html_class($class) . " ";
441 }
442 }
443 }
444 $type= \FluentForm\App\Helpers\Helper::isConversionForm($atts['formId']) ? 'conversational' : '';
445 return do_shortcode('[fluentform css_classes="' . $className . ' ff_guten_block" id="' . $atts['formId'] . '" type="' .$type .'"]');
446 },
447 'attributes' => array(
448 'formId' => array(
449 'type' => 'string'
450 ),
451 'className' => array(
452 'type' => 'string'
453 )
454 )
455 ));
456 }
457
458
459 // require the CLI
460 if (defined('WP_CLI') && WP_CLI) {
461 \WP_CLI::add_command('fluentform', '\FluentForm\App\Modules\CLI\Commands');
462 }
463