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

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