-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin.php
executable file
·152 lines (128 loc) · 4.98 KB
/
plugin.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
<?php
namespace Custom_Css_FEle;
// If this file is called directly, abort.
defined('ABSPATH') || exit;
/**
* Plugin base class to initialize plugin
*
*/
final class Plugin {
/**
* @var Singleton The reference the *Singleton* instance of this class
*/
public static $instance;
/**
* elementor required version
*/
const CCFE_MINIMUM_ELE_VER = '3.9.0';
/**
* php required version
*/
const CCFE_MINIMUM_PHP_VER = '5.6';
/**
* class constructor function
*/
public function __construct() {
$this->define_constants();
}
/**
* constent declare function
*
* @return void
*/
public function define_constants() {
define('CUSTOM_CSS_FELE_VERSION', '2.0.0');
define('CUSTOM_CSS_FELE_PACKAGE', 'free');
define('CUSTOM_CSS_FELE_PLUGIN_URL', plugin_dir_url(__FILE__));
define('CUSTOM_CSS_FELE_PLUGIN_DIR', plugin_dir_path(__FILE__));
}
/**
* init function of plugin
*
* @return void
*/
public function init() {
// Check if Elementor installed and activated
if (!did_action('elementor/loaded')) {
add_action('admin_notices', [$this, 'admin_notice_missing_main_plugin']);
return;
}
// Check for required Elementor version
if (!version_compare(ELEMENTOR_VERSION, self::CCFE_MINIMUM_ELE_VER, '>=')) {
add_action('admin_notices', [$this, 'admin_notice_minimum_elementor_version']);
return;
}
// Check for required PHP version
if (version_compare(PHP_VERSION, self::CCFE_MINIMUM_PHP_VER, '<')) {
add_action('admin_notices', [$this, 'admin_notice_minimum_php_version']);
return;
}
if (!class_exists('Custom_Css_FEle\Inc\Hook_Action')) {
include_once CUSTOM_CSS_FELE_PLUGIN_DIR . 'inc/hook-action.php';
}
Inc\Hook_Action::instance()->init();
}
/**
* admin notice for missing depended plugin function
*
* @return void
*/
public function admin_notice_missing_main_plugin() {
if (file_exists(WP_PLUGIN_DIR . '/elementor/elementor.php')) {
$notice_title = esc_html__('Activate Elementor', 'custom-css-for-elementor');
$notice_url = wp_nonce_url('plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php');
} else {
$notice_title = esc_html__('Install Elementor', 'custom-css-for-elementor');
$notice_url = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=elementor'), 'install-plugin_elementor');
}
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor */
esc_html__('"%1$s" requires "%2$s" to be installed and activated. %3$s', 'custom-css-for-elementor'),
'<strong>' . esc_html__('Custom CSS for Elementor', 'custom-css-for-elementor') . '</strong>',
'<strong>' . esc_html__('Elementor', 'custom-css-for-elementor') . '</strong>',
'<a href="' . esc_url($notice_url) . '">' . $notice_title . '</a>'
);
printf('<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* admin notice for minimum version required plugin function
*
* @return void
*/
public function admin_notice_minimum_elementor_version() {
$message = sprintf(
/* translators: 1: Plugin name 2: Elementor 3: Required Elementor version */
esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'custom-css-for-elementor'),
'<strong>' . esc_html__('Custom CSS for Elementor', 'custom-css-for-elementor') . '</strong>',
'<strong>' . esc_html__('Elementor', 'custom-css-for-elementor') . '</strong>',
self::CCFE_MINIMUM_ELE_VER
);
printf('<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* admin notice for minimum version php required function
*
* @return void
*/
public function admin_notice_minimum_php_version() {
$message = sprintf(
/* translators: 1: Plugin name 2: PHP 3: Required PHP version */
esc_html__('"%1$s" requires "%2$s" version %3$s or greater.', 'custom-css-for-elementor'),
'<strong>' . esc_html__('Custom CSS for Elementor', 'custom-css-for-elementor') . '</strong>',
'<strong>' . esc_html__('PHP', 'custom-css-for-elementor') . '</strong>',
self::CCFE_MINIMUM_PHP_VER
);
printf('<div class="notice notice-error is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* Returns the *Singleton* instance of this class.
*
* @return Singleton The *Singleton* instance.
*/
public static function instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
}