This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * WP Requirements |
||
4 | * |
||
5 | * Utility to check current PHP version, WordPress version and PHP extensions. |
||
6 | * |
||
7 | * @package WP_Requirements |
||
8 | * @version 1.4.0 |
||
9 | * @author Fulvio Notarstefano <[email protected]> |
||
10 | * @link https://github.com/nekojira/wp-requirements |
||
11 | * @license GPL2+ |
||
12 | */ |
||
13 | |||
14 | if ( ! class_exists( 'SimCal_WP_Requirements' ) ) { |
||
15 | |||
16 | class SimCal_WP_Requirements { |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | /** |
||
19 | * Plugin name. |
||
20 | * |
||
21 | * @access private |
||
22 | * @var string |
||
23 | */ |
||
24 | private $name = ''; |
||
25 | |||
26 | /** |
||
27 | * Plugin main file. |
||
28 | * |
||
29 | * plugin_basename( __FILE__ ) |
||
30 | * |
||
31 | * @access private |
||
32 | * @var string |
||
33 | */ |
||
34 | private $plugin = ''; |
||
35 | |||
36 | /** |
||
37 | * WordPress. |
||
38 | * |
||
39 | * @access private |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $wp = true; |
||
43 | |||
44 | /** |
||
45 | * PHP. |
||
46 | * |
||
47 | * @access private |
||
48 | * @var bool |
||
49 | */ |
||
50 | private $php = true; |
||
51 | |||
52 | /** |
||
53 | * PHP Extensions. |
||
54 | * |
||
55 | * @access private |
||
56 | * @var bool |
||
57 | */ |
||
58 | private $extensions = true; |
||
59 | |||
60 | /** |
||
61 | * Requirements to check. |
||
62 | * |
||
63 | * @access private |
||
64 | * @var array |
||
65 | */ |
||
66 | private $requirements = array(); |
||
67 | |||
68 | /** |
||
69 | * Results failures. |
||
70 | * |
||
71 | * Associative array with requirements results. |
||
72 | * |
||
73 | * @access private |
||
74 | * @var array |
||
75 | */ |
||
76 | private $failures = array(); |
||
77 | |||
78 | /** |
||
79 | * Admin notice. |
||
80 | * |
||
81 | * @access private |
||
82 | * @var string |
||
83 | */ |
||
84 | private $notice = ''; |
||
85 | |||
86 | /** |
||
87 | * Run checks. |
||
88 | * |
||
89 | * @param string $name The plugin name. |
||
90 | * @param string $plugin Output of `plugin_basename( __FILE__ )`. |
||
91 | * @param array $requirements Associative array with requirements. |
||
92 | */ |
||
93 | public function __construct( $name, $plugin, $requirements ) { |
||
94 | |||
95 | $this->name = htmlspecialchars( strip_tags( $name ) ); |
||
96 | $this->plugin = $plugin; |
||
97 | $this->requirements = $requirements; |
||
98 | |||
99 | if ( ! empty( $requirements ) && is_array( $requirements ) ) { |
||
100 | |||
101 | $failures = $extensions = array(); |
||
102 | |||
103 | $requirements = array_merge( |
||
104 | array( |
||
105 | 'WordPress' => '', |
||
106 | 'PHP' => '', |
||
107 | 'Extensions' => '', |
||
108 | ), $requirements |
||
109 | ); |
||
110 | |||
111 | // Check for WordPress version. |
||
112 | if ( $requirements['WordPress'] && is_string( $requirements['WordPress'] ) ) { |
||
113 | if ( function_exists( 'get_bloginfo' ) ) { |
||
114 | $wp_version = get_bloginfo( 'version' ); |
||
115 | if ( version_compare( $wp_version, $requirements['WordPress'] ) === - 1 ) { |
||
116 | $failures['WordPress'] = $wp_version; |
||
117 | $this->wp = false; |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | // Check fo PHP version. |
||
123 | if ( $requirements['PHP'] && is_string( $requirements['PHP'] ) ) { |
||
124 | if ( version_compare( PHP_VERSION, $requirements['PHP'] ) === -1 ) { |
||
125 | $failures['PHP'] = PHP_VERSION; |
||
126 | $this->php = false; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | // Check fo PHP Extensions. |
||
131 | if ( $requirements['Extensions'] && is_array( $requirements['Extensions'] ) ) { |
||
132 | foreach ( $requirements['Extensions'] as $extension ) { |
||
133 | if ( $extension && is_string( $extension ) ) { |
||
134 | $extensions[ $extension ] = extension_loaded( $extension ); |
||
135 | } |
||
136 | } |
||
137 | if ( in_array( false, $extensions ) ) { |
||
138 | foreach ( $extensions as $extension_name => $found ) { |
||
139 | if ( $found === false ) { |
||
140 | $failures['Extensions'][ $extension_name ] = $extension_name; |
||
141 | } |
||
142 | } |
||
143 | $this->extensions = false; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | $this->failures = $failures; |
||
148 | |||
149 | } else { |
||
150 | |||
151 | trigger_error( 'WP Requirements: the requirements are invalid.', E_USER_ERROR ); |
||
152 | |||
153 | } |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Get requirements results. |
||
158 | * |
||
159 | * @return array |
||
160 | */ |
||
161 | public function failures() { |
||
162 | return $this->failures; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * Check if versions check pass. |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function pass() { |
||
171 | if ( in_array( false, array( |
||
172 | $this->wp, |
||
173 | $this->php, |
||
174 | $this->extensions, |
||
175 | ) ) ) { |
||
176 | return false; |
||
177 | } |
||
178 | return true; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Notice message. |
||
183 | * |
||
184 | * @param string $message An additional message. |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | public function get_notice( $message = '' ) { |
||
189 | |||
190 | $notice = ''; |
||
191 | $name = $this->name; |
||
192 | $failures = $this->failures; |
||
193 | |||
194 | if ( ! empty( $failures ) && is_array( $failures ) ) { |
||
195 | |||
196 | $notice = '<div class="error">' . "\n"; |
||
197 | $notice .= "\t" . '<p>' . "\n"; |
||
198 | $notice .= '<strong>' . sprintf( '%s could not be activated.', $name ) . '</strong><br>'; |
||
199 | |||
200 | foreach ( $failures as $requirement => $found ) { |
||
201 | |||
202 | $required = $this->requirements[ $requirement ]; |
||
203 | |||
204 | if ( 'Extensions' == $requirement ) { |
||
205 | if ( is_array( $found ) ) { |
||
206 | $notice .= sprintf( |
||
207 | 'Required PHP Extension(s) not found: %s.', |
||
208 | join( ', ', $found ) |
||
209 | ) . '<br>'; |
||
210 | } |
||
211 | } else { |
||
212 | $notice .= sprintf( |
||
213 | 'Required %1$s version: %2$s - Version found: %3$s', |
||
214 | $requirement, |
||
215 | $required, |
||
216 | $found |
||
217 | ) . '<br>'; |
||
218 | } |
||
219 | |||
220 | } |
||
221 | |||
222 | $notice .= '<em>' . sprintf( 'Please update to meet %s requirements.', $name ) . '</em>' . "\n"; |
||
223 | $notice .= "\t" . '</p>' . "\n"; |
||
224 | if ( $message ) { |
||
225 | $notice .= $message; |
||
226 | } |
||
227 | $notice .= '</div>'; |
||
228 | } |
||
229 | |||
230 | return $notice; |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * Print notice. |
||
235 | */ |
||
236 | public function print_notice() { |
||
237 | echo $this->notice; |
||
238 | } |
||
239 | |||
240 | /** |
||
241 | * Deactivate plugin. |
||
242 | */ |
||
243 | public function deactivate_plugin() { |
||
244 | if ( function_exists( 'deactivate_plugins' ) && function_exists( 'plugin_basename' ) ) { |
||
245 | deactivate_plugins( $this->plugin ); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * Deactivate plugin and display admin notice. |
||
251 | * |
||
252 | * @param string $message An additional message in notice. |
||
253 | */ |
||
254 | public function halt( $message = '' ) { |
||
0 ignored issues
–
show
halt uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
255 | |||
256 | $this->notice = $this->get_notice( $message ); |
||
257 | |||
258 | if ( $this->notice && function_exists( 'add_action' ) ) { |
||
259 | |||
260 | add_action( 'admin_notices', array( $this, 'print_notice' ) ); |
||
261 | add_action( 'admin_init', array( $this, 'deactivate_plugin' ) ); |
||
262 | |||
263 | if ( isset( $_GET['activate'] ) ) { |
||
264 | unset( $_GET['activate'] ); |
||
265 | } |
||
266 | } |
||
267 | } |
||
268 | |||
269 | } |
||
270 | |||
271 | } |
||
272 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.