| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Declare backend actions/filters/shortcodes |
| 5 |
*/ |
| 6 |
|
| 7 |
/* |
| 8 |
* Regitser All Admin Scripts but don't load it |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
add_action('admin_init', function () use ($app) { |
| 13 |
(new \FluentForm\App\Modules\Registerer\Menu($app))->reisterScripts(); |
| 14 |
}, 9); |
| 15 |
|
| 16 |
add_action('admin_enqueue_scripts', function () use ($app) { |
| 17 |
(new \FluentForm\App\Modules\Registerer\Menu($app))->enqueuePageScripts(); |
| 18 |
}, 10); |
| 19 |
|
| 20 |
// Add Entries Menu |
| 21 |
$app->addAction('ff_fluentform_form_application_view_entries', function ($form_id) use ($app) { |
| 22 |
(new \FluentForm\App\Modules\Entries\Entries())->renderEntries($form_id); |
| 23 |
}); |
| 24 |
|
| 25 |
$app->addAction('fluentform_after_form_navigation', function ($form_id) use ($app) { |
| 26 |
(new \FluentForm\App\Modules\Registerer\Menu($app))->addCopyShortcodeButton($form_id); |
| 27 |
(new \FluentForm\App\Modules\Registerer\Menu($app))->addPreviewButton($form_id); |
| 28 |
}); |
| 29 |
|
| 30 |
$app->addAction('media_buttons', function () { |
| 31 |
(new \FluentForm\App\Modules\EditorButtonModule())->addButton(); |
| 32 |
}); |
| 33 |
|
| 34 |
$app->addAction('fluentform_addons_page_render_fluentform_add_ons', function () { |
| 35 |
(new \FluentForm\App\Modules\AddOnModule())->showFluentAddOns(); |
| 36 |
}); |
| 37 |
|
| 38 |
// This is temp, we will remove this after 2-3 versions. |
| 39 |
add_filter('pre_set_site_transient_update_plugins', function ($updates) { |
| 40 |
if (!empty($updates->response['fluentformpro'])) { |
| 41 |
$updates->response['fluentformpro/fluentformpro.php'] = $updates->response['fluentformpro']; |
| 42 |
unset($updates->response['fluentformpro']); |
| 43 |
} |
| 44 |
return $updates; |
| 45 |
}, 999, 1); |
| 46 |
|
| 47 |
$app->addAction('fluentform_global_menu', function () use ($app) { |
| 48 |
$menu = new \FluentForm\App\Modules\Registerer\Menu($app); |
| 49 |
$menu->renderGlobalMenu(); |
| 50 |
if (get_option('fluentform_scheduled_actions_migrated') != 'yes') { |
| 51 |
\FluentForm\App\Databases\Migrations\ScheduledActions::migrate(); |
| 52 |
} |
| 53 |
|
| 54 |
$hookName = 'fluentform_do_scheduled_tasks'; |
| 55 |
if (!wp_next_scheduled($hookName)) { |
| 56 |
wp_schedule_event(time(), 'ff_every_five_minutes', $hookName); |
| 57 |
} |
| 58 |
|
| 59 |
$emailReportHookName = 'fluentform_do_email_report_scheduled_tasks'; |
| 60 |
if (!wp_next_scheduled($emailReportHookName)) { |
| 61 |
wp_schedule_event(time(), 'daily', $emailReportHookName); |
| 62 |
} |
| 63 |
}); |
| 64 |
|
| 65 |
$app->addAction('wp_dashboard_setup', function () { |
| 66 |
$roleManager = new \FluentForm\App\Modules\Acl\Acl(); |
| 67 |
|
| 68 |
if (!$roleManager->getCurrentUserCapability()) { |
| 69 |
return; |
| 70 |
} |
| 71 |
wp_add_dashboard_widget('fluentform_stat_widget', __('Fluent Forms Latest Form Submissions', 'fluentform'), function () { |
| 72 |
(new \FluentForm\App\Modules\DashboardWidgetModule)->showStat(); |
| 73 |
}, 10, 1); |
| 74 |
}); |
| 75 |
|
| 76 |
add_action('admin_init', function () { |
| 77 |
$disablePages = [ |
| 78 |
'fluent_forms', |
| 79 |
'fluent_forms_transfer', |
| 80 |
'fluent_forms_settings', |
| 81 |
'fluent_forms_add_ons', |
| 82 |
'fluent_forms_docs', |
| 83 |
'fluent_forms_all_entries', |
| 84 |
'msformentries' |
| 85 |
]; |
| 86 |
|
| 87 |
if (isset($_GET['page']) && in_array($_GET['page'], $disablePages)) { |
| 88 |
remove_all_actions('admin_notices'); |
| 89 |
} |
| 90 |
}); |
| 91 |
|
| 92 |
add_action('enqueue_block_editor_assets', function () use ($app) { |
| 93 |
wp_enqueue_script( |
| 94 |
'fluentform-gutenberg-block', |
| 95 |
$app->publicUrl("js/fluent_gutenblock.js"), |
| 96 |
array('wp-element', 'wp-polyfill' , 'wp-i18n', 'wp-blocks' ,'wp-components'), |
| 97 |
FLUENTFORM_VERSION |
| 98 |
); |
| 99 |
|
| 100 |
$forms = wpFluent()->table('fluentform_forms') |
| 101 |
->select(['id', 'title']) |
| 102 |
->orderBy('id', 'DESC') |
| 103 |
->get(); |
| 104 |
|
| 105 |
array_unshift($forms, (object)[ |
| 106 |
'id' => '', |
| 107 |
'title' => __('-- Select a form --', 'fluentform') |
| 108 |
]); |
| 109 |
|
| 110 |
wp_localize_script('fluentform-gutenberg-block', 'fluentform_block_vars', [ |
| 111 |
'logo' => $app->publicUrl('img/fluent_icon.png'), |
| 112 |
'forms' => $forms |
| 113 |
]); |
| 114 |
|
| 115 |
wp_enqueue_style( |
| 116 |
'fluentform-gutenberg-block', |
| 117 |
$app->publicUrl("css/fluent_gutenblock.css"), |
| 118 |
array('wp-edit-blocks') |
| 119 |
); |
| 120 |
}); |
| 121 |
|
| 122 |
add_action('wp_print_scripts', function () { |
| 123 |
if (is_admin()) { |
| 124 |
if (\FluentForm\App\Helpers\Helper::isFluentAdminPage()) { |
| 125 |
$option = get_option('_fluentform_global_form_settings'); |
| 126 |
$isSkip = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.noConflictStatus') == 'no'; |
| 127 |
$isSkip = apply_filters('fluentform_skip_no_conflict', $isSkip); |
| 128 |
|
| 129 |
if ($isSkip) { |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
global $wp_scripts; |
| 134 |
if (!$wp_scripts) { |
| 135 |
return; |
| 136 |
} |
| 137 |
|
| 138 |
$pluginUrl = plugins_url(); |
| 139 |
foreach ($wp_scripts->queue as $script) { |
| 140 |
if (!isset($wp_scripts->registered[$script])) { |
| 141 |
continue; |
| 142 |
} |
| 143 |
|
| 144 |
$src = $wp_scripts->registered[$script]->src; |
| 145 |
if (strpos($src, $pluginUrl) !== false && !strpos($src, 'fluentform') !== false) { |
| 146 |
wp_dequeue_script($wp_scripts->registered[$script]->handle); |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
}, 1); |
| 152 |
|
| 153 |
add_action('fluentform_loading_editor_assets', function ($form) { |
| 154 |
add_filter('fluentform_editor_init_element_input_name', function ($field) { |
| 155 |
if (empty($field['settings']['label_placement'])) { |
| 156 |
$field['settings']['label_placement'] = ''; |
| 157 |
} |
| 158 |
return $field; |
| 159 |
}); |
| 160 |
|
| 161 |
$upgradableCheckInputs = [ |
| 162 |
'input_radio', |
| 163 |
'select', |
| 164 |
'select_country', |
| 165 |
'input_checkbox' |
| 166 |
]; |
| 167 |
|
| 168 |
foreach ($upgradableCheckInputs as $upgradeElement) { |
| 169 |
add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) use ($upgradeElement) { |
| 170 |
if (!\FluentForm\Framework\Helpers\ArrayHelper::get($element, 'settings.advanced_options')) { |
| 171 |
$formattedOptions = []; |
| 172 |
$oldOptions = \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'options', []); |
| 173 |
foreach ($oldOptions as $value => $label) { |
| 174 |
$formattedOptions[] = [ |
| 175 |
'label' => $label, |
| 176 |
'value' => $value, |
| 177 |
'calc_value' => '', |
| 178 |
'image' => '' |
| 179 |
]; |
| 180 |
} |
| 181 |
$element['settings']['advanced_options'] = $formattedOptions; |
| 182 |
$element['settings']['enable_image_input'] = false; |
| 183 |
$element['settings']['calc_value_status'] = false; |
| 184 |
$element['settings']['calc_value_status'] = false; |
| 185 |
unset($element['options']); |
| 186 |
|
| 187 |
if ($upgradeElement == 'input_radio' || $upgradeElement == 'input_checkbox') { |
| 188 |
$element['editor_options']['template'] = 'inputCheckable'; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
if (!isset($element['settings']['layout_class']) && in_array($upgradeElement, ['input_radio', 'input_checkbox'])) { |
| 193 |
$element['settings']['layout_class'] = ''; |
| 194 |
} |
| 195 |
|
| 196 |
if (!isset($element['settings']['dynamic_default_value'])) { |
| 197 |
$element['settings']['dynamic_default_value'] = ''; |
| 198 |
} |
| 199 |
|
| 200 |
if ($upgradeElement != 'select_country' && !isset($element['settings']['randomize_options'])) { |
| 201 |
$element['settings']['randomize_options'] = 'no'; |
| 202 |
} |
| 203 |
|
| 204 |
if ($upgradeElement == 'select' && \FluentForm\Framework\Helpers\ArrayHelper::get($element, 'attributes.multiple') && empty($element['settings']['max_selection'])) { |
| 205 |
$element['settings']['max_selection'] = ''; |
| 206 |
} |
| 207 |
|
| 208 |
if (($upgradeElement == 'select' || $upgradeElement = 'select_country') && !isset($element['settings']['enable_select_2'])) { |
| 209 |
$element['settings']['enable_select_2'] = 'no'; |
| 210 |
} |
| 211 |
|
| 212 |
if ($upgradeElement != 'select_country' && !isset($element['settings']['values_visible'])) { |
| 213 |
$element['settings']['values_visible'] = false; |
| 214 |
} |
| 215 |
|
| 216 |
return $element; |
| 217 |
}); |
| 218 |
} |
| 219 |
|
| 220 |
$upgradableFileInputs = [ |
| 221 |
'input_file', |
| 222 |
'input_image', |
| 223 |
]; |
| 224 |
foreach ($upgradableFileInputs as $upgradeElement) { |
| 225 |
add_filter('fluentform_editor_init_element_' . $upgradeElement, function ($element) { |
| 226 |
if (!isset($element['settings']['upload_file_location'])) { |
| 227 |
$element['settings']['upload_file_location'] = 'default'; |
| 228 |
}; |
| 229 |
if (!isset($element['settings']['file_location_type'])) { |
| 230 |
$element['settings']['file_location_type'] = 'follow_global_settings'; |
| 231 |
}; |
| 232 |
return $element; |
| 233 |
}); |
| 234 |
} |
| 235 |
|
| 236 |
add_filter('fluentform_editor_init_element_gdpr_agreement', function ($element) { |
| 237 |
if (!isset($element['settings']['required_field_message'])) { |
| 238 |
$element['settings']['required_field_message'] = ''; |
| 239 |
} |
| 240 |
return $element; |
| 241 |
}); |
| 242 |
|
| 243 |
add_filter('fluentform_editor_init_element_input_text', function ($element) { |
| 244 |
if (!isset($element['attributes']['maxlength'])) { |
| 245 |
$element['attributes']['maxlength'] = ''; |
| 246 |
} |
| 247 |
return $element; |
| 248 |
}); |
| 249 |
|
| 250 |
add_filter('fluentform_editor_init_element_textarea', function ($element) { |
| 251 |
if (!isset($element['attributes']['maxlength'])) { |
| 252 |
$element['attributes']['maxlength'] = ''; |
| 253 |
} |
| 254 |
return $element; |
| 255 |
}); |
| 256 |
|
| 257 |
add_filter('fluentform_editor_init_element_input_date', function ($item) { |
| 258 |
if (!isset($item['settings']['date_config'])) { |
| 259 |
$item['settings']['date_config'] = ''; |
| 260 |
} |
| 261 |
return $item; |
| 262 |
}); |
| 263 |
|
| 264 |
add_filter('fluentform_editor_init_element_container', function ($item) { |
| 265 |
if (!isset($item['settings']['conditional_logics'])) { |
| 266 |
$item['settings']['conditional_logics'] = []; |
| 267 |
} |
| 268 |
|
| 269 |
if (!isset($item['settings']['container_width'])) { |
| 270 |
$item['settings']['container_width'] = ''; |
| 271 |
} |
| 272 |
|
| 273 |
$shouldSetWidth = !empty($item['columns']) && (!isset($item['columns'][0]['width']) || !$item['columns'][0]['width']); |
| 274 |
|
| 275 |
if ($shouldSetWidth) { |
| 276 |
$perColumn = round(100 / count($item['columns']), 2); |
| 277 |
|
| 278 |
foreach ($item['columns'] as &$column) { |
| 279 |
$column['width'] = $perColumn; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
return $item; |
| 284 |
}); |
| 285 |
|
| 286 |
add_filter('fluentform_editor_init_element_input_number', function ($item) { |
| 287 |
if (!isset($item['settings']['number_step'])) { |
| 288 |
$item['settings']['number_step'] = ''; |
| 289 |
} |
| 290 |
if (!isset($item['settings']['numeric_formatter'])) { |
| 291 |
$item['settings']['numeric_formatter'] = ''; |
| 292 |
} |
| 293 |
if (!isset($item['settings']['prefix_label'])) { |
| 294 |
$item['settings']['prefix_label'] = ''; |
| 295 |
} |
| 296 |
if (!isset($item['settings']['suffix_label'])) { |
| 297 |
$item['settings']['suffix_label'] = ''; |
| 298 |
} |
| 299 |
return $item; |
| 300 |
}); |
| 301 |
|
| 302 |
add_filter('fluentform_editor_init_element_input_email', function ($item) { |
| 303 |
if (!isset($item['settings']['is_unique'])) { |
| 304 |
$item['settings']['is_unique'] = 'no'; |
| 305 |
} |
| 306 |
if (!isset($item['settings']['unique_validation_message'])) { |
| 307 |
$item['settings']['unique_validation_message'] = __('Email address need to be unique.', 'fluentform'); |
| 308 |
} |
| 309 |
if (!isset($item['settings']['prefix_label'])) { |
| 310 |
$item['settings']['prefix_label'] = ''; |
| 311 |
} |
| 312 |
if (!isset($item['settings']['suffix_label'])) { |
| 313 |
$item['settings']['suffix_label'] = ''; |
| 314 |
} |
| 315 |
return $item; |
| 316 |
}); |
| 317 |
|
| 318 |
add_filter('fluentform_editor_init_element_input_text', function ($item) { |
| 319 |
if (isset($item['attributes']['data-mask'])) { |
| 320 |
if (!isset($item['settings']['data-mask-reverse'])) { |
| 321 |
$item['settings']['data-mask-reverse'] = 'no'; |
| 322 |
} |
| 323 |
if (!isset($item['settings']['data-clear-if-not-match'])) { |
| 324 |
$item['settings']['data-clear-if-not-match'] = 'no'; |
| 325 |
} |
| 326 |
} else { |
| 327 |
if (!isset($item['settings']['is_unique'])) { |
| 328 |
$item['settings']['is_unique'] = 'no'; |
| 329 |
} |
| 330 |
if (!isset($item['settings']['unique_validation_message'])) { |
| 331 |
$item['settings']['unique_validation_message'] = __('This field value need to be unique.', 'fluentform'); |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
if (!isset($item['settings']['prefix_label'])) { |
| 336 |
$item['settings']['prefix_label'] = ''; |
| 337 |
} |
| 338 |
if (!isset($item['settings']['suffix_label'])) { |
| 339 |
$item['settings']['suffix_label'] = ''; |
| 340 |
} |
| 341 |
|
| 342 |
return $item; |
| 343 |
}); |
| 344 |
|
| 345 |
add_filter('fluentform_editor_init_element_recaptcha', function ($item, $form) { |
| 346 |
$item['attributes']['name'] = 'g-recaptcha-response'; |
| 347 |
return $item; |
| 348 |
}, 10, 2); |
| 349 |
|
| 350 |
add_filter('fluentform_editor_init_element_hcaptcha', function ($item, $form) { |
| 351 |
$item['attributes']['name'] = 'h-captcha-response'; |
| 352 |
return $item; |
| 353 |
}, 10, 2); |
| 354 |
|
| 355 |
add_filter('fluentform_editor_init_element_turnstile', function ($item, $form) { |
| 356 |
$item['attributes']['name'] = 'cf-turnstile-response'; |
| 357 |
return $item; |
| 358 |
}, 10, 2); |
| 359 |
|
| 360 |
}, 10); |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
add_filter('fluentform_addons_extra_menu', function ($menus) { |
| 365 |
$menus['fluentform_pdf'] = __('Fluent Forms PDF', 'fluentform'); |
| 366 |
return $menus; |
| 367 |
}, 99, 1); |
| 368 |
|
| 369 |
add_action('fluentform_addons_page_render_fluentform_pdf', function () { |
| 370 |
$url = ''; |
| 371 |
if (!defined('FLUENTFORM_PDF_VERSION')) { |
| 372 |
$url = wp_nonce_url( |
| 373 |
self_admin_url('update.php?action=install-plugin&plugin=fluentforms-pdf'), |
| 374 |
'install-plugin_fluentforms-pdf' |
| 375 |
); |
| 376 |
} |
| 377 |
|
| 378 |
\FluentForm\View::render('admin.addons.pdf_promo', [ |
| 379 |
'install_url' => $url, |
| 380 |
'is_installed' => defined('FLUENTFORM_PDF_VERSION') |
| 381 |
]); |
| 382 |
}); |
| 383 |
|
| 384 |
//Add file upload location in global settings |
| 385 |
add_filter('fluentform_get_global_settings_values', function ($values, $key) { |
| 386 |
if (is_array($key) && in_array('_fluentform_global_form_settings', $key)) { |
| 387 |
$values['file_upload_optoins'] = FluentForm\App\Helpers\Helper::fileUploadLocations(); |
| 388 |
} |
| 389 |
return $values; |
| 390 |
}, 10, 2); |
| 391 |
|
| 392 |
add_action('ff_installed_by', function ($by) { |
| 393 |
if (is_string($by) && !get_option('_ff_ins_by')) { |
| 394 |
update_option('_ff_ins_by', sanitize_text_field($by), 'no'); |
| 395 |
} |
| 396 |
}); |
| 397 |
|
| 398 |
//Enables recaptcha validation when autoload recaptcha enabled for all forms |
| 399 |
$autoIncludeRecaptcha = [ |
| 400 |
[ |
| 401 |
'type'=>'hcaptcha', |
| 402 |
'is_disabled'=>!get_option('_fluentform_hCaptcha_keys_status', false) |
| 403 |
], |
| 404 |
[ |
| 405 |
'type'=>'recaptcha', |
| 406 |
'is_disabled'=>!get_option('_fluentform_reCaptcha_keys_status', false) |
| 407 |
], |
| 408 |
[ |
| 409 |
'type'=>'turnstile', |
| 410 |
'is_disabled'=>!get_option('_fluentform_turnstile_keys_status', false) |
| 411 |
], |
| 412 |
]; |
| 413 |
|
| 414 |
foreach ($autoIncludeRecaptcha as $input) { |
| 415 |
if ($input['is_disabled']) { |
| 416 |
continue; |
| 417 |
} |
| 418 |
add_filter('ff_has_auto_' . $input['type'], function () use ($input) { |
| 419 |
$option = get_option('_fluentform_global_form_settings'); |
| 420 |
$autoload = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.autoload_captcha'); |
| 421 |
$type = \FluentForm\Framework\Helpers\ArrayHelper::get($option, 'misc.captcha_type'); |
| 422 |
|
| 423 |
if ($autoload && $type == $input['type']) { |
| 424 |
return true; |
| 425 |
} |
| 426 |
return false; |
| 427 |
}); |
| 428 |
} |
| 429 |
|