-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathclient-dash-bootstrapper.php
More file actions
181 lines (154 loc) · 4.13 KB
/
client-dash-bootstrapper.php
File metadata and controls
181 lines (154 loc) · 4.13 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
<?php
/**
* Bootstrapper for the plugin.
*
* Makes sure everything is good to go for loading the plugin, and then loads it.
*
* @since 2.0.0
*
* @package ClientDash
*/
defined( 'ABSPATH' ) || die;
/**
* Class ClientDash_Bootstrapper
*
* Bootstrapper for the plugin.
*
* Makes sure everything is good to go for loading the plugin, and then loads it.
*
* @since 2.0.0
*/
class ClientDash_Bootstrapper {
/**
* Notices to show if cannot load.
*
* @since 2.0.0
* @access private
*
* @var array
*/
private $notices = array();
/**
* ClientDash_Bootstrapper constructor.
*
* @since 2.0.0
*/
function __construct() {
add_action( 'client_dash_loaded', array( $this, 'maybe_nag_client_dash_pro' ), 10 );
add_action( 'plugins_loaded', array( $this, 'maybe_load' ), 1 );
}
/**
* Potentially nag to upgrade Pro.
*
* @since 2.0.0
* @access private
*/
function maybe_nag_client_dash_pro() {
// Don't disable if active and past version 1.1
if ( ! defined( 'CLIENTDASH_PRO_VERSION' ) ) {
return;
}
if ( version_compare( CLIENTDASH_PRO_VERSION, '1.1' ) !== - 1 ) {
return;
}
add_action( 'admin_notices', array( $this, 'cd_pro_admin_notice' ) );
// Some disabling
remove_action( 'admin_init', array( ClientDash_Pro()->admin, 'register_settings' ) );
remove_action( 'admin_notices', array( ClientDash_Pro()->admin, 'licensing_notice' ) );
remove_action( 'cd_sidebar', array( 'CD_Pro_Admin', 'sidebar_support' ) );
remove_action( 'admin_init', array( ClientDash_Pro()->admin, 'send_support_email' ) );
remove_filter( 'parent_file', array( ClientDash_Pro()->admin_pages->admin, 'activate_settings_menu' ) );
remove_filter( 'submenu_file', array( ClientDash_Pro()->admin_pages->admin, 'activate_clientdash_submenu' ) );
remove_action( 'all_admin_notices', array( ClientDash_Pro()->admin_pages->admin, 'output_clientdash_menu' ) );
remove_action( 'admin_init', array( ClientDash_Pro()->admin_pages->admin, 'redirect_cd_tab' ) );
}
/**
* Maybe loads the plugin.
*
* @since 2.0.0
* @access private
*/
function maybe_load() {
$php_version = phpversion();
$wp_version = get_bloginfo( 'version' );
// Minimum PHP version
if ( version_compare( $php_version, '5.3.0' ) === - 1 ) {
$this->notices[] = sprintf(
__( 'Minimum PHP version of 5.3.0 required. Current version is %s. Please contact your system administrator to upgrade PHP to its latest version.', 'client-dash' ),
$php_version
);
}
// Minimum WordPress version
if ( version_compare( $wp_version, '4.8.0' ) === - 1 ) {
$this->notices[] = sprintf(
__( 'Minimum WordPress version of 4.0.0 required. Current version is %s. Please contact your system administrator to upgrade WordPress to its latest version.', 'client-dash' ),
$wp_version
);
}
// Don't load and show errors if incompatible environment.
if ( ! empty( $this->notices ) ) {
add_action( 'admin_notices', array( $this, 'notices' ) );
return;
}
$this->load();
}
/**
* Loads the plugin.
*
* @since 2.0.0
* @access private
*/
private function load() {
ClientDash();
do_action( 'client_dash_loaded' );
}
/**
* Shows notices on failure to load.
*
* @since 2.0.0
* @access private
*/
function notices() {
?>
<div class="notice error">
<p>
<?php
printf(
__( '%sClient Dash%s could not load because of the following errors:', 'client-dash' ),
'<strong>',
'</strong>'
);
?>
</p>
<ul>
<?php foreach ( $this->notices as $notice ) : ?>
<li>
<?php echo $notice; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
/**
* Shows notice on upgrading of CD Pro.
*
* @since 2.0.0
* @access private
*/
function cd_pro_admin_notice() {
?>
<div class="notice error">
<p>
<?php
printf(
__( '%sClient Dash Pro%s needs to be updated to version 1.1 or it will not perform properly. Please update Client Dash Pro immediately.', 'client-dash' ),
'<strong>',
'</strong>'
);
?>
</p>
</div>
<?php
}
}