-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMentorStarter.php
172 lines (154 loc) · 4.63 KB
/
MentorStarter.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
<?php
declare(strict_types=1);
/**
* MentorStarter.
* Main plugin class that holds entire plugin.
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
*/
// If this file is called firectly, abort!!!
defined('ABSPATH') or die('This is not the place you deserve!');
class MentorStarter
{
/**
* Plugin version
*
* @var string
*/
public $version = '1.0.0';
/**
* __construct.
* Constructor function
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
* @return void
*/
public function __construct()
{
// set the constants first
$this->setConstants();
// check & load the autoloader
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once dirname(__FILE__) . '/vendor/autoload.php';
}
// register the activation
register_activation_hook(__FILE__, [$this, 'activate']);
// registser the deactivation
register_deactivation_hook(__FILE__, [$this, 'deactivate']);
// init plugin on loaded
add_action('plugins_loaded', [$this, 'init'], 11);
}
/**
* setConstants.
* define default constants
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
* @return void
*/
public function setConstants()
{
define('MENTORSTARTER_VERSION', $this->version);
define('MENTORSTARTER_TEXTDOMAIN', 'metnorstarter');
define('MENTORSTARTER_FILE', __FILE__);
define('MENTORSTARTER_NAME', 'Mentor Starter');
define('MENTORSTARTER_PATH', dirname(MENTORSTARTER_FILE));
define('MENTORSTARTER_INC', MENTORSTARTER_PATH . '/inc');
define('MENTORSTARTER_URL', plugins_url('', MENTORSTARTER_FILE));
define('MENTORSTARTER_ASSETS', MENTORSTARTER_URL . '/assets');
}
/**
* activate.
* function that runs on plugin activation
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
* @return void
*/
public function activate()
{
// flush rewrite rules
flush_rewrite_rules();
$isInstalled = get_option('mentorstarter_installed');
if (!$isInstalled) {
update_option('mentorstarter_installed', time());
}
update_option('mentorstarter_version', MENTORSTARTER_VERSION);
}
/**
* deactivate.
* function that runs on plugin deactivation
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
* @return void
*/
public function deactivate()
{
// Flush reqrite rules
flush_rewrite_rules();
}
/**
* init.
* Initialize various classes
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
* @return void
*/
public function init()
{
/**
* Check if elementor installed & active already.
*/
if (!did_action('elementor/loaded')) {
add_action('admin_notices', [$this, 'adminNoticeMissingElementor']);
}
/**
* Initialize all the core classes of the plugin
*/
if (class_exists("Inc\\Core")) {
Inc\Core::registerServices();
}
}
/* adminNoticeMissingElementor
* Show admin notice if paranet plugin is missing.
* @author Arif Pavel
* @since 31 Mar 21
* @version v1.0.0
* @param mixed
* @return null
*/
public function adminNoticeMissingElementor()
{
if (isset($_GET['activate'])) {
unset($_GET['activate']);
}
$message = sprintf(
/* translators: 1: Plugin Name 2: Elementor */
esc_html__('"%1$s" requires "%2$s" to be installed and activated.', 'text-domain'),
'<strong>' . esc_html__(MENTORSTARTER_NAME, MENTORSTARTER_TEXTDOMAIN) . '</strong>',
'<strong>' . esc_html__('Elementor', MENTORSTARTER_TEXTDOMAIN) . '</strong>'
);
printf('<div class="notice notice-warning is-dismissible"><p>%1$s</p></div>', $message);
}
/**
* initiateMentorStarter.
* Return an instance if not intiated yet
* @author Arif Pavel
* @since v0.0.1
* @version v1.0.0 Wednesday, Mar 31th, 2021.
* @access public
*/
public static function initiateMentorStarter()
{
return new MentorStarter();
}
}