-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathform-masks-for-elementor.php
191 lines (163 loc) · 6.09 KB
/
form-masks-for-elementor.php
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
<?php
/**
* Plugin Name: Form Input Masks for Elementor Form
* Plugin URI: https://coolplugins.net/
* Description: Form Input Masks for Elementor Form creates a custom control in the field advanced tab for customizing your fields with masks. This plugin requires Elementor Pro (Form Widget).
* Author: Cool Plugins
* Author URI: https://coolplugins.net/
* Version: 2.4.0
* Requires at least: 5.5
* Requires PHP: 7.4
* Text Domain: form-masks-for-elementor
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Requires Plugins: elementor
*/
if ( ! defined( 'ABSPATH' ) ) {
header( 'Status: 403 Forbidden' );
header( 'HTTP/1.1 403 Forbidden' );
exit();
}
define( 'FME_VERSION', '2.4.0' );
define( 'FME_PHP_MINIMUM_VERSION', '7.4' );
define( 'FME_WP_MINIMUM_VERSION', '5.5' );
define( 'FME_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'FME_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
register_activation_hook( __FILE__, array( 'Form_Masks_For_Elementor', 'fme_activate' ) );
register_deactivation_hook( __FILE__, array( 'Form_Masks_For_Elementor', 'fme_deactivate' ) );
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
class Form_Masks_For_Elementor {
/**
* Plugin instance.
*/
private static $instance = null;
/**
* Constructor.
*/
private function __construct() {
if ( $this->check_requirements() ) {
$this->initialize_plugin();
add_action( 'init', array( $this, 'text_domain_path_set' ) );
add_action( 'activated_plugin', array( $this, 'fme_plugin_redirection' ) );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'fme_pro_plugin_demo_link' ) );
}
}
/**
* Singleton instance.
*
* @return self
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function fme_plugin_redirection($plugin){
if ( ! is_plugin_active( 'elementor-pro/elementor-pro.php' )) {
return false;
}
if ( is_plugin_active( 'cool-formkit-for-elementor-forms/cool-formkit-for-elementor-forms.php' ) ) {
return false;
}
if ( $plugin == plugin_basename( __FILE__ ) ) {
exit( wp_redirect( admin_url( 'admin.php?page=cool-formkit' ) ) );
}
}
public function text_domain_path_set(){
load_plugin_textdomain( 'form-masks-for-elementor', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
public function fme_pro_plugin_demo_link($link){
$settings_link = '<a href="' . admin_url( 'admin.php?page=cool-formkit' ) . '">Cool FormKit</a>';
array_unshift( $link, $settings_link );
return $link;
}
/**
* Check requirements for PHP and WordPress versions.
*
* @return bool
*/
private function check_requirements() {
if ( ! version_compare( PHP_VERSION, FME_PHP_MINIMUM_VERSION, '>=' ) ) {
add_action( 'admin_notices', [ $this, 'admin_notice_php_version_fail' ] );
return false;
}
if ( ! version_compare( get_bloginfo( 'version' ), FME_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' ) ) {
return false;
}
if ( ! is_plugin_active( 'elementor-pro/elementor-pro.php' ) ) {
add_action('admin_notices', array($this, 'admin_notice_missing_main_plugin'));
return false;
}
return true;
}
/**
* 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.',
'form-masks-for-elementor'
),
esc_html__( 'Form Input Masks for Elementor Form', 'form-masks-for-elementor' ),
esc_html__( 'Elementor Pro', 'form-masks-for-elementor' ),
);
printf( '<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', esc_html( $message ) );
deactivate_plugins( plugin_basename( __FILE__ ) );
}
/**
* Initialize the plugin.
*/
private function initialize_plugin() {
require_once FME_PLUGIN_PATH . 'includes/class-fme-plugin.php';
FME\Includes\FME_Plugin::instance();
if(!is_plugin_active( 'extensions-for-elementor-form/extensions-for-elementor-form.php' )){
require_once FME_PLUGIN_PATH . '/includes/class-fme-elementor-page.php';
new FME_Elementor_Page();
}
if ( is_admin() ) {
require_once FME_PLUGIN_PATH . 'admin/feedback/admin-feedback-form.php';
}
}
/**
* Admin notice for PHP version failure.
*/
public function admin_notice_php_version_fail() {
$message = sprintf(
esc_html__( '%1$s requires PHP version %2$s or greater.', 'form-masks-for-elementor' ),
'<strong>Form Input Masks for Elementor Form</strong>',
FME_PHP_MINIMUM_VERSION
);
$html_message = sprintf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
echo wp_kses_post( $html_message );
}
/**
* Admin notice for WordPress version failure.
*/
public function admin_notice_wp_version_fail() {
$message = sprintf(
esc_html__( '%1$s requires WordPress version %2$s or greater.', 'form-masks-for-elementor' ),
'<strong>Form Input Masks for Elementor Form</strong>',
FME_WP_MINIMUM_VERSION
);
$html_message = sprintf( '<div class="notice notice-error"><p>%1$s</p></div>', $message );
echo wp_kses_post( $html_message );
}
public static function fme_activate(){
update_option( 'fme-v', FME_VERSION );
update_option( 'fme-type', 'FREE' );
update_option( 'fme-installDate', gmdate( 'Y-m-d h:i:s' ) );
}
public static function fme_deactivate(){
}
}
// Initialize the plugin.
Form_Masks_For_Elementor::instance();