-
Notifications
You must be signed in to change notification settings - Fork 7
/
CheckReady.php
117 lines (96 loc) · 3.19 KB
/
CheckReady.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
<?php
if ( !class_exists('bbPMCheckReady') ) :
/**
* Compares PHP versions
* Making sure this blog is running enough required PHP software for
* this plugin, currently requiring 5.3 at least for namespaces
*/
Class bbPMCheckReady
{
public $min, $ver, $errors, $plugin;
public function __construct( $minVersion='5.3', $plugins=array(), $name='' )
{
$this->min = $minVersion;
$this->ver = PHP_VERSION;
$this->errors = array();
$this->plugin = trim($name) ? $name : '';
if ( !version_compare($this->ver, $this->min, '>=') ) {
$this->errors[] = sprintf(
'%s plugin requires at least PHP %s (You have %s).',
$this->plugin ? $this->plugin : 'This plugin',
$this->min,
$this->ver
);
}
if ( $plugins ) {
$this->getPlugins();
foreach ( (array) $plugins as $name=>$plugin ) {
if ( !in_array($plugin, $this->plugins) ) {
$error = sprintf(
'%s plugin is required!',
strlen($name) > 2 ? $name : $plugin
);
$this->errors[] = $error;
}
}
}
if ( $this->hasErrors() ) {
$prefix = is_multisite() && is_network_admin() ? 'network_' : '';
add_action($prefix . 'admin_notices', array($this, "notice"), 999);
} else if ( 'cli' != php_sapi_name() ) {
add_action('activated_plugin', array($this, 'redirect'));
}
}
public function notice()
{
if ( !$this->errors )
return;
$this->errors = array_merge(array("<strong>$this->plugin notices</strong>:"), $this->errors);
printf(
'<div class="error notice is-dismissible"><p>%s</p></div>',
implode('<br/> — ', $this->errors)
);
printf(
'<div class="error notice is-dismissible"><p>%s</p></div>',
__('Deactivating plugin..')
);
}
public function hasErrors()
{
return (bool) $this->errors;
}
public function getPlugins()
{
$this->plugins = apply_filters('active_plugins', get_option('active_plugins'));
if ( is_multisite() ) {
$network_plugins = get_site_option('active_sitewide_plugins');
if ( $network_plugins ) {
$network_plugins = array_keys($network_plugins);
$this->plugins = array_merge($this->plugins, $network_plugins);
}
}
return $this;
}
public function check()
{
if ( $this->hasErrors() ) {
update_site_option('bbpm_force_deactivate', true);
} else {
delete_site_option('bbpm_force_deactivate');
}
}
public function redirect( $plugin ) {
switch ( $plugin ) {
case plugin_basename(BBP_MESSAGES_FILE):
wp_redirect('index.php?page=bbpm-about');
exit;
break;
}
}
}
return new bbPMCheckReady(
'5.3',
array('bbPress (parent plugin)' => 'bbpress/bbpress.php'),
'bbPress Messages'
);
endif;