-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextensions-for-elementor-form.php
More file actions
592 lines (490 loc) · 19.1 KB
/
Copy pathextensions-for-elementor-form.php
File metadata and controls
592 lines (490 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<?php
/**
* Plugin Name: Cool FormKit Lite - Elementor Form Builder
* Plugin URI: https://coolplugins.net/
* Description: Build advanced forms in Elementor Free using Cool FormKit Lite. It also enhances Elementor Pro and Hello Plus Form Widget with conditional logic and advanced field options.
* Author: Cool Plugins
* Author URI: https://coolplugins.net/?utm_source=cfkl_plugin&utm_medium=inside&utm_campaign=author_page&utm_content=plugins_list
* Text Domain: extensions-for-elementor-form
* Version: 2.7.6
* Requires at least: 6.2
* Requires PHP: 7.4
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Requires Plugins: elementor
* Elementor tested up to: 4.2.0
* Elementor Pro tested up to: 4.2.0
*/
namespace Cool_FormKit;
use Cool_FormKit\Includes\CFL_Loader;
use Cool_FormKit\Widgets\CoolForm_Addons_Loader;
use Cool_FormKit\Widgets\HelloPlus_Addons_Loader;
use Cool_FormKit\Widgets\Atomic_Form_Addon_Loader;
if (! defined('ABSPATH')) {
header('Status: 403 Forbidden');
header('HTTP/1.1 403 Forbidden');
exit();
}
define('CFL_VERSION', '2.7.6');
define('PHP_MINIMUM_VERSION', '7.4');
define('WP_MINIMUM_VERSION', '5.5');
define('CFL_PLUGIN_MAIN_FILE', __FILE__);
define('CFL_PLUGIN_PATH', plugin_dir_path(CFL_PLUGIN_MAIN_FILE));
define('CFL_PLUGIN_URL', plugin_dir_url(CFL_PLUGIN_MAIN_FILE));
define('CFL_ASSETS_PATH', CFL_PLUGIN_PATH . 'build/');
define('CFL_ASSETS_URL', CFL_PLUGIN_URL . '/build/');
define('CFL_SCRIPTS_PATH', CFL_ASSETS_PATH . 'js/');
define('CFL_SCRIPTS_URL', CFL_ASSETS_URL . 'js/');
define('CFL_STYLE_PATH', CFL_ASSETS_PATH . 'css/');
define('CFL_STYLE_URL', CFL_ASSETS_URL . 'css/');
define('CFL_IMAGES_PATH', CFL_ASSETS_PATH . 'images/');
define('CFL_IMAGES_URL', CFL_ASSETS_URL . 'images/');
define('CFL__MIN_ELEMENTOR_VERSION', '3.26.4');
define('CFL_MIN_ELEMENTOR_ATOMIC_FORM_VERSION', '4.0');
define('CFL_FEEDBACK_URL', 'https://feedback.coolplugins.net/');
if (! function_exists('is_plugin_active')) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
class Cool_Formkit_Lite_For_Elementor_Form
{
/**
* Plugin instance
*/
public static $instance = null;
/**
* Constructor.
*/
public function __construct()
{
static $autoloader_registered = false;
if ($this->check_requirements()) {
if (! $autoloader_registered) {
$autoloader_registered = spl_autoload_register([$this, 'autoload']);
}
if (get_option('cfkef_enable_formkit_builder', true)) {
$this->initialize_modules();
}
$this->initialize_plugin();
$this->deactivate_child_plugins();
add_action('activated_plugin', array($this, 'EEF_plugin_redirection'));
add_action('wp_enqueue_scripts', array($this, 'my_enqueue_scripts'));
add_action('elementor/editor/before_enqueue_scripts', array($this, 'add_global_editor_js'));
add_action('wp_head', array($this, 'stop_format_detection_in_safari'));
add_action('elementor_pro/forms/actions/register', array($this, 'cfl_register_new_form_actions'));
add_action( 'plugins_loaded',array($this,'formdb_elementor_marketing'));
add_filter( 'elementor-pro/editor/v2/packages', array( $this, 'filter_elementor_pro_editor_packages' ) );
add_action( 'elementor/editor/v2/scripts/enqueue', array( $this, 'enqueue_editor_templates_extended_stub' ), 20 );
}
}
public function formdb_elementor_marketing() {
if ( did_action( 'elementor/loaded' ) && class_exists( '\Elementor\Plugin' ) ) {
require_once CFL_PLUGIN_PATH . '/admin/marketing/cfl-marketing-common.php';
}
}
public function cfl_register_new_form_actions($form_actions_registrar)
{
if (!is_plugin_active('sb-elementor-contact-form-db/sb_elementor_contact_form_db.php') && !defined("formdb_elementor_marketing_editor")) {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
define("formdb_elementor_marketing_editor", true);
include_once(__DIR__ . '/includes/class-form-to-sheet.php');
$form_actions_registrar->register(new \Sheet_Action());
}
}
public function stop_format_detection_in_safari()
{
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated
$ua = sanitize_text_field(wp_unslash($_SERVER['HTTP_USER_AGENT']));
$is_safari = strpos($ua, 'Safari') !== false
&& strpos($ua, 'Mobile') !== false // ensures mobile Safari
&& (strpos($ua, 'iPhone') !== false
|| strpos($ua, 'iPad') !== false
|| strpos($ua, 'iPod') !== false)
&& !preg_match('/Chrome|CriOS|Chromium|OPR|Edg/i', $ua);
if ($is_safari) {
echo '<meta name="format-detection" content="telephone=no">' . "\n";
}
}
public function my_enqueue_scripts()
{
wp_register_script('handle-date-pickr', CFL_PLUGIN_URL . 'assets/js/flatpickr/handle-date-pickr.js', array('elementor-frontend', 'jquery'), CFL_VERSION, true);
wp_register_script('handle-time-pickr', CFL_PLUGIN_URL . 'assets/js/flatpickr/handle-time-pickr.js', array('elementor-frontend', 'jquery'), CFL_VERSION, true);
}
/**
* Singleton instance.
*
* @return self
*/
public static function instance()
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Add hooks for plugin initialization.
*/
public function initialize_plugin()
{
// Include main plugin class.
require_once CFL_PLUGIN_PATH . 'includes/class-cfl-loader.php';
require_once CFL_PLUGIN_PATH . 'admin/feedback/cron/cfl-class-cron.php';
CFL_Loader::get_instance();
if (get_option('cfkef_enable_formkit_builder', true)) {
require_once CFL_PLUGIN_PATH . 'widgets/coolform-addons-loader.php';
CoolForm_Addons_Loader::get_instance();
}
if (get_option('cfkef_enable_hello_plus', true)) {
require_once CFL_PLUGIN_PATH . 'widgets/helloplus-addons-loader.php';
HelloPlus_Addons_Loader::get_instance();
}
if (get_option('cfkef_enable_atomic_form', true)) {
if ( is_plugin_active( 'elementor-pro/elementor-pro.php' ) || is_plugin_active( 'pro-elements/pro-elements.php' ) ) {
// After `elementor/init`, core services (e.g. experiments) are initialized; on `elementor/loaded` they are often still null.
if ( did_action( 'elementor/init' ) ) {
$this->load_atomic_form_addon();
} else {
add_action( 'elementor/init', array( $this, 'load_atomic_form_addon' ), 20 );
}
}
}
if (is_admin()) {
require_once CFL_PLUGIN_PATH . 'admin/review-notice.php';
new Review_notice();
require_once CFL_PLUGIN_PATH . 'admin/feedback/admin-feedback-form.php';
if (!class_exists('CPFM_Feedback_Notice')) {
require_once CFL_PLUGIN_PATH . 'admin/feedback/cpfm-feedback-notice.php';
}
if (!get_option('CFL_initial_save_version')) {
add_option('CFL_initial_save_version', CFL_VERSION);
}
if (!get_option('cfl-install-date')) {
add_option('cfl-install-date', gmdate('Y-m-d h:i:s'));
}
}
add_filter('plugin_action_links_' . plugin_basename(CFL_PLUGIN_MAIN_FILE), array($this, 'EEF_plugin_dashboard_link'));
add_filter('plugin_action_links_' . plugin_basename(CFL_PLUGIN_MAIN_FILE), array(
$this,
'EEF_get_pro_link'
));
add_filter('plugin_row_meta', array($this, 'cfkef_plugin_row_meta'), 10, 2);
}
public function load_atomic_form_addon() {
if ( ! is_plugin_active( 'elementor-pro/elementor-pro.php' ) && ! is_plugin_active( 'pro-elements/pro-elements.php' ) ) {
return;
}
if ( ! did_action( 'elementor/init' ) || ! class_exists( '\Elementor\Plugin' ) ) {
return;
}
if ( ! self::is_elementor_atomic_form_supported() ) {
if ( is_admin() && get_option( 'cfkef_enable_atomic_form', true ) ) {
add_action( 'admin_notices', array( $this, 'admin_notice_elementor_atomic_form_version' ) );
}
return;
}
$elementor = \Elementor\Plugin::$instance;
if ( ! $elementor ) {
return;
}
$experiments = isset( $elementor->experiments ) ? $elementor->experiments : null;
if ( ! self::are_elementor_atomic_form_experiments_active( $experiments ) ) {
return;
}
require_once CFL_PLUGIN_PATH . 'widgets/atomic-form-addon-loader.php';
Atomic_Form_Addon_Loader::get_instance();
}
/**
* Atomic Form extensions require Elementor 4.0+ (matches Elementor Pro atomic-form module).
*/
public static function is_elementor_atomic_form_supported(): bool {
return defined( 'ELEMENTOR_VERSION' )
&& version_compare( ELEMENTOR_VERSION, CFL_MIN_ELEMENTOR_ATOMIC_FORM_VERSION, '>=' );
}
/**
* @param mixed $experiments \Elementor\Core\Experiments\Manager|null.
*/
private static function are_elementor_atomic_form_experiments_active( $experiments ): bool {
if ( ! self::is_elementor_atomic_form_supported() ) {
return false;
}
if ( ! $experiments || ! is_object( $experiments ) || ! method_exists( $experiments, 'is_feature_active' ) ) {
return false;
}
return $experiments->is_feature_active( 'e_atomic_elements' )
&& $experiments->is_feature_active( 'e_pro_atomic_form' );
}
public function admin_notice_elementor_atomic_form_version() {
if ( ! current_user_can( 'update_plugins' ) ) {
return;
}
$file_path = 'elementor/elementor.php';
$upgrade_link = wp_nonce_url(
self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file_path,
'upgrade-plugin_' . $file_path
);
printf(
'<div class="notice notice-warning is-dismissible"><p><strong>%1$s</strong> %2$s <a href="%3$s">%4$s</a></p></div>',
esc_html__( 'Cool FormKit:', 'extensions-for-elementor-form' ),
esc_html__(
'Atomic Form extensions require Elementor 4.0 or newer. Update Elementor to use this feature, or disable Atomic Form in Cool FormKit settings.',
'extensions-for-elementor-form'
),
esc_url( $upgrade_link ),
esc_html__( 'Update Elementor', 'extensions-for-elementor-form' )
);
}
public function cfkef_plugin_row_meta($plugin_meta, $plugin_file)
{
if (plugin_basename(CFL_PLUGIN_MAIN_FILE) === $plugin_file) {
$row_meta = array(
'docs' => '<a href="' . esc_url('https://docs.coolplugins.net/plugin/cool-formkit-for-elementor-form/?utm_source=cfkl_plugin&utm_medium=inside&utm_campaign=docs&utm_content=plugins_list') . '" aria-label="' . esc_attr(esc_html__('View CoolFomkit Documentation', 'extensions-for-elementor-form')) . '" target="_blank">' . esc_html__('View Documentation', 'extensions-for-elementor-form') . '</a>',
);
$plugin_meta = array_merge($plugin_meta, $row_meta);
}
return $plugin_meta;
}
public function EEF_get_pro_link($links)
{
$get_pro = '<a target="_blank" style="font-weight:bold;color:green;" href="https://coolformkit.com/pricing/?utm_source=cfkl_plugin&utm_medium=inside&utm_campaign=get_pro&utm_content=plugins_list">Get Pro</a>';
array_push($links, $get_pro);
return $links;
}
public function EEF_plugin_redirection($plugin)
{
if (is_plugin_active('cool-formkit-for-elementor-forms/cool-formkit-for-elementor-forms.php')) {
return false;
}
if ($plugin == plugin_basename(CFL_PLUGIN_MAIN_FILE)) {
wp_safe_redirect( admin_url( 'admin.php?page=cool-formkit' ) );
exit;
}
}
/**
* Check PHP and WordPress version compatibility.
*
* @return bool
*/
public function check_requirements()
{
if (! version_compare(PHP_VERSION, PHP_MINIMUM_VERSION, '>=')) {
add_action('admin_notices', [$this, 'admin_notice_php_version_fail']);
return false;
}
if (! version_compare(get_bloginfo('version'), WP_MINIMUM_VERSION, '>=')) {
add_action('admin_notices', [$this, 'admin_notice_wp_version_fail']);
return false;
}
if (is_plugin_active('cool-formkit-for-elementor-forms/cool-formkit-for-elementor-forms.php')) {
add_action('admin_notices', array($this, 'cool_formkit_active_notice'));
return false;
}
if (! is_plugin_active('elementor/elementor.php')) {
add_action('admin_notices', array($this, 'admin_notice_missing_main_plugin'));
return false;
}
return true;
}
public function add_global_editor_js()
{
wp_enqueue_script('cfl-global-editor-script', CFL_PLUGIN_URL . 'assets/addons/js/global.js', array('jquery'), CFL_VERSION, true);
}
/**
* Skips Elementor Pro's editor-templates-extended package (crashes editor with nested form controls).
*
* @param mixed $packages Editor v2 packages.
* @return mixed
*/
public function filter_elementor_pro_editor_packages( $packages ) {
if ( ! is_array( $packages ) ) {
return $packages;
}
return array_values( array_diff( $packages, array( 'editor-templates-extended' ) ) );
}
/**
* Stub the removed package handle for other Pro packages that depend on it.
*/
public function enqueue_editor_templates_extended_stub() {
wp_register_script(
'elementor-v2-editor-templates-extended',
CFL_PLUGIN_URL . 'assets/js/cfl-editor-templates-extended-stub.js',
array(),
CFL_VERSION,
true
);
wp_enqueue_script( 'elementor-v2-editor-templates-extended' );
}
public function EEF_plugin_dashboard_link($links)
{
$settings_link = '<a href="' . admin_url('admin.php?page=cool-formkit') . '">Settings</a>';
array_unshift($links, $settings_link);
return $links;
}
// Define a helper function for plugin deactivation and admin notice
private function deactivate_plugin_with_notice($plugin_path, $plugin_name)
{
if (file_exists(plugin_dir_path(__DIR__) . $plugin_path)) {
if (is_plugin_active($plugin_path)) {
deactivate_plugins($plugin_path);
add_action(
'admin_notices',
function () use ($plugin_name) {
$this->admin_notice_deactivating_conditional_field_plugin($plugin_name);
}
);
}
}
}
// Method to deactivate child plugins
public function deactivate_child_plugins()
{
// Array of plugins to deactivate
$plugins_to_deactivate = array(
'conditional-fields-for-elementor-form/class-conditional-fields-for-elementor-form.php' => 'Conditional Fields for Elementor Form',
'country-code-field-for-elementor-form/country-code-field-for-elementor-form.php' => 'Country Code Field For Elementor Form',
'country-code-field-for-elementor-form/country-code-field-for-elementor-form-pro.php' => 'Country Code Field For Elementor Form Pro',
'form-masks-for-elementor/form-masks-for-elementor.php' => 'Form Input Masks for Elementor Form',
'mask-form-elementor/index.php' => 'Input Mask Elementor Form Fields',
);
// Loop through the plugins and deactivate them if necessary
foreach ($plugins_to_deactivate as $plugin_path => $plugin_name) {
$this->deactivate_plugin_with_notice($plugin_path, $plugin_name);
}
}
public function admin_notice_deactivating_conditional_field_plugin($plugin_name)
{
?>
<div class="notice notice-error">
<p><?php echo esc_html("{$plugin_name} is deactivated because Cool FormKit is installed and activated."); ?></p>
</div>
<?php
}
/**
* Show notice to enable elementor pro
*/
public function admin_notice_missing_main_plugin()
{
$message = sprintf(
// translators: %1$s replace with Conditional Fields for Elementor Form & %2$s replace with Elementor Pro.
esc_html__(
'%1$s requires %2$s to be installed and activated.',
'extensions-for-elementor-form'
),
esc_html__('Cool Formkit Lite', 'extensions-for-elementor-form'),
esc_html__('Elementor', 'extensions-for-elementor-form'),
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', esc_html($message));
deactivate_plugins(plugin_basename(CFL_PLUGIN_MAIN_FILE));
}
public function cool_formkit_active_notice()
{
$message = sprintf(
esc_html__('Cool Formkit Lite for Elementor Free now you are using Elementor Pro so please deactivate Cool Formkit Lite and use Cool Formkit instead.', 'extensions-for-elementor-form'),
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', esc_html($message));
}
/**
* Display admin notice for PHP version failure.
*/
public function admin_notice_php_version_fail()
{
$message = sprintf(
/* translators: 1: Plugin name, 2: Required PHP version */
esc_html__('%1$s requires PHP version %2$s or greater.', 'extensions-for-elementor-form'),
'<strong>Cool Formkit Lite</strong>',
PHP_MINIMUM_VERSION
);
echo wp_kses_post(sprintf('<div class="notice notice-error"><p>%1$s</p></div>', $message));
}
/**
* Display admin notice for WordPress version failure.
*/
public function admin_notice_wp_version_fail()
{
$message = sprintf(
/* translators: 1: Plugin name, 2: Required WordPress version */
esc_html__('%1$s requires WordPress version %2$s or greater.', 'extensions-for-elementor-form'),
'<strong>Cool Formkit Lite</strong>',
WP_MINIMUM_VERSION
);
echo wp_kses_post(sprintf('<div class="notice notice-error"><p>%1$s</p></div>', $message));
}
private function initialize_modules()
{
$modules_list = [
'Forms', // Add additional module names as needed.
];
foreach ($modules_list as $module_name) {
// Convert the module name to match the folder structure.
// "Forms" becomes "Forms", but our autoloader expects lower-case folder names.
// Therefore, if your file is in "modules/forms/module.php", adjust accordingly:
$module_folder = strtolower($module_name);
$class_name = __NAMESPACE__ . '\\Modules\\' . $module_name . '\\Module';
if (class_exists($class_name) && $class_name::is_active()) {
// Initialize the module by calling its singleton instance.
$class_name::instance();
}
}
}
public function autoload($class_name)
{
if (0 !== strpos($class_name, __NAMESPACE__)) {
return;
}
$has_class_alias = isset($this->classes_aliases[$class_name]);
// Backward Compatibility: Save old class name for set an alias after the new class is loaded
if ($has_class_alias) {
$class_alias_name = $this->classes_aliases[$class_name];
$class_to_load = $class_alias_name;
} else {
$class_to_load = $class_name;
}
if (! class_exists($class_to_load)) {
$filename = strtolower(
preg_replace(
['/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/'],
['', '$1-$2', '-', DIRECTORY_SEPARATOR],
$class_to_load
)
);
$filename = trailingslashit(CFL_PLUGIN_PATH) . $filename . '.php';
if (is_readable($filename)) {
include $filename;
}
}
if ($has_class_alias) {
class_alias($class_alias_name, $class_name);
}
}
public static function eef_activate()
{
update_option('eef-v', CFL_VERSION);
update_option('eef-type', 'FREE');
update_option('eef-installDate', gmdate('Y-m-d h:i:s'));
if (!get_option('CFL_initial_save_version')) {
add_option('CFL_initial_save_version', CFL_VERSION);
}
if (!get_option('cfl-install-date')) {
add_option('cfl-install-date', gmdate('Y-m-d h:i:s'));
}
$settings = get_option('cfef_usage_share_data');
if (!empty($settings) || $settings === 'on') {
self::cfl_cron_job_init();
}
}
public static function cfl_cron_job_init()
{
if (!wp_next_scheduled('cfl_extra_data_update')) {
wp_schedule_event(time(), 'every_30_days', 'cfl_extra_data_update');
}
}
public static function eef_deactivate()
{
if (wp_next_scheduled('cfl_extra_data_update')) {
wp_clear_scheduled_hook('cfl_extra_data_update');
}
}
}
// Initialize the plugin.
Cool_Formkit_Lite_For_Elementor_Form::instance();
register_activation_hook(CFL_PLUGIN_MAIN_FILE, array('Cool_FormKit\Cool_Formkit_Lite_For_Elementor_Form', 'eef_activate'));
register_deactivation_hook(CFL_PLUGIN_MAIN_FILE, array('Cool_FormKit\Cool_Formkit_Lite_For_Elementor_Form', 'eef_deactivate'));