PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.5.8
Shortcodes and extra features for Phlox theme v2.5.8
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxin-plugin-requirements.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 6 years ago class-auxels-archive-menu-links.php 6 years ago class-auxels-import-parser.php 8 years ago class-auxels-import.php 6 years ago class-auxels-search-post-type.php 6 years ago class-auxin-admin-dashboard.php 6 years ago class-auxin-demo-importer.php 6 years ago class-auxin-dependency-sorting.php 8 years ago class-auxin-import.php 6 years ago class-auxin-install.php 6 years ago class-auxin-master-nav-menu-admin.php 6 years ago class-auxin-page-template.php 6 years ago class-auxin-permalink.php 6 years ago class-auxin-plugin-requirements.php 6 years ago class-auxin-post-type-base.php 6 years ago class-auxin-siteorigin-widget.php 6 years ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 7 years ago class-auxin-walker-nav-menu-back.php 6 years ago class-auxin-welcome-sections.php 6 years ago class-auxin-welcome.php 6 years ago class-auxin-whitelabel.php 6 years ago class-auxin-widget-indie.php 6 years ago class-auxin-widget-shortcode-map.php 6 years ago class-auxin-widget.php 6 years ago
class-auxin-plugin-requirements.php
439 lines
1 <?php
2
3 if( ! class_exists( 'Auxin_Plugin_Requirements' ) ){
4
5 /**
6 * Checks the requirements for a plugin
7 *
8 */
9 class Auxin_Plugin_Requirements {
10
11 /**
12 * An array containing the list of requirements
13 *
14 * @var array
15 */
16 public $requirements = array();
17
18 /**
19 * Whether the requirements are available or not
20 *
21 * @var boolean
22 */
23 private $requirements_passed = true;
24
25 /**
26 * Collects error notices
27 *
28 * @var array
29 */
30 public $admin_notices = array();
31
32
33
34 function __construct(){
35 global $auxin_plugins_dependency_map;
36
37 if( empty( $auxin_plugins_dependency_map ) ){
38 $auxin_plugins_dependency_map = array();
39 }
40
41 if( is_admin() ){
42 add_action( 'admin_notices' , array( $this, 'admin_notices' ) );
43 add_action( 'activated_plugin' , array( $this, 'update_plugins_dependencies' ) );
44 } else {
45 add_action( 'auxin_after_inner_body_open', array( $this, 'front_notices' ) );
46 }
47
48 }
49
50 /**
51 * Make sure the client has the requirements, otherwise, throw a notice in admin
52 *
53 * @return void
54 */
55 public function admin_notices( $pop_notice = '' ){
56 if( $this->admin_notices = array_filter( $this->admin_notices ) ) {
57 echo '<div class="error aux-admin-error">';
58 echo $this->get_notices( $pop_notice );
59 echo '</div>';
60 }
61 }
62
63 /**
64 * Make sure the client has the requirements, otherwise, throw a notice
65 *
66 * @return void
67 */
68 public function get_notices( $pop_notice = '' ){
69 $the_notice = '';
70
71 if( $this->admin_notices && $notices = implode( '</li><li>', $this->admin_notices ) ) {
72 $the_notice .= '<p>' . $pop_notice;
73 $the_notice .= sprintf(
74 __( '%s plugin has been disabled automatically due to following reason:', 'auxin-elements' ),
75 '<strong>'. $this->requirements['config']['plugin_name'] . '</strong>'
76 );
77 $the_notice .= '<ul><li>'. $notices . '</li></ul></p>';
78 }
79
80 if( $this->requirements['config']['debug'] || ( defined( 'AUXIN_DEBUG' ) && AUXIN_DEBUG ) ){
81 $active_plugins = get_option( 'active_plugins' );
82 $the_notice .= "<pre>"; $the_notice .= print_r( $active_plugins, true ); $the_notice .= "</pre>";
83 }
84
85 return $the_notice;
86 }
87
88 /**
89 * Make sure the client has the requirements, otherwise, throw a notice in frontend for administrator
90 *
91 * @return void
92 */
93 public function front_notices(){
94 $this->admin_notices = array_filter( $this->admin_notices );
95
96 if( $this->admin_notices && current_user_can( 'edit_theme_options' ) ) {
97 $pop_notice = '<strong>' . __( 'Note for admin', 'auxin-elements' ) . '</strong>: ';
98 echo '<div class="aux-front-error aux-front-notice aux-fold">';
99 echo $this->get_notices( $pop_notice );
100 echo '</div>';
101 }
102 }
103
104 /**
105 * Wrapper around the core WP get_plugins function, making sure it's actually available.
106 *
107 * @return array Array of installed plugins with plugin information.
108 */
109 public function get_plugins() {
110 if ( ! function_exists( 'get_plugins' ) ) {
111 require_once ABSPATH . 'wp-admin/includes/plugin.php';
112 }
113
114 return get_plugins();
115 }
116
117 /**
118 * Check whether a plugin is active.
119 *
120 * @param string $plugin Base plugin path from plugins directory.
121 *
122 * @return bool True, if in the active plugins list. False, not in the list.
123 */
124 function is_plugin_active( $plugin ) {
125
126 if ( ! function_exists( 'is_plugin_active' ) ) {
127 require_once ABSPATH . 'wp-admin/includes/plugin.php';
128 }
129 return is_plugin_active( $plugin );
130
131 }
132
133 /**
134 * Load the dependency plugins before the current plugin
135 *
136 * @return void
137 */
138 function update_plugins_dependencies(){
139
140 // Flush the rewrite rules on plugin activation
141 flush_rewrite_rules();
142
143 if( empty( $this->requirements['plugins'] ) ){
144 return;
145 }
146
147 if( $plugin_requirements = $this->requirements['plugins'] ){
148
149 global $auxin_plugins_dependency_map;
150
151 if( ! class_exists( 'Auxin_Dependency_Sorting' ) ){
152 require_once( 'class-auxin-dependency-sorting.php' );
153 }
154
155 // Whether new dependency to dependency graph added or not
156 $has_new_dependency = false;
157
158 // Walk through the plugins and collect the dependencies
159 foreach ( $plugin_requirements as $plugin_requirement ) {
160
161 // Make sure if the plugin is expected to be loaded prior to our main plugin
162 if( ! empty( $plugin_requirement['dependency'] ) && true == $plugin_requirement['dependency'] && $this->is_plugin_active( $plugin_requirement['basename'] ) ){
163 // Add current plugin dependencies to main plugins dependency graph
164 $auxin_plugins_dependency_map[ $this->requirements['config']['plugin_basename'] ][] = $plugin_requirement['basename'];
165 // If at least one plugin with required dependency detected
166 $has_new_dependency = true;
167 }
168
169 }
170
171
172 if( $has_new_dependency ){
173
174 // Sort the plugins based on the dependencies
175 $dependency_resolver = new Auxin_Dependency_Sorting();
176 $resolved_plugins_load_order = $dependency_resolver->resolve( $auxin_plugins_dependency_map );
177
178 // Get all activated plugins
179 $active_plugins = get_option( 'active_plugins' );
180
181 // Change the plugins load order
182 foreach ( $resolved_plugins_load_order as $plugin_basename ) {
183
184 if( ( $key = array_search( $plugin_basename, $active_plugins ) ) !== false ) {
185 unset( $active_plugins[ $key ] );
186 }
187 $active_plugins[] = $plugin_basename;
188 }
189
190 update_option( 'active_plugins', $active_plugins );
191 }
192
193 }
194
195 }
196
197
198 /**
199 * Check plugin requirements
200 *
201 * @return void
202 */
203 function check_plugins_requirement(){
204
205 if( empty( $this->requirements['plugins'] ) ){
206 return;
207 }
208
209 if( $plugin_requirements = $this->requirements['plugins'] ){
210 if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
211
212 // Walk through the plugins
213 foreach ( $plugin_requirements as $plugin_requirement ) {
214
215 // check if the plugin is active
216 $is_plugin_active = $this->is_plugin_active( $plugin_requirement['basename'] );
217
218 // if activating the plugin is required
219 if(
220 ( ! empty( $plugin_requirement['required'] ) && true == $plugin_requirement['required'] && ! $is_plugin_active ) ||
221 ( ! empty( $plugin_requirement['is_callable'] ) && ! function_exists( $plugin_requirement['is_callable'] ) )
222 ){
223
224 $this->admin_notices[] = sprintf(
225 __( '%s plugin is required in order to use this plugin. Please install and activate the plugin.', 'auxin-elements' ).
226 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
227 '<strong>'. $plugin_requirement['name'] . '</strong>'
228 );
229
230 $this->requirements_passed = false;
231
232 // if minimum plugin version was specified
233 } elseif( ! empty( $plugin_requirement['version'] ) && $is_plugin_active ){
234
235 $all_plugins = $this->get_plugins();
236
237 if( empty( $all_plugins[ $plugin_requirement['basename'] ]['Version'] ) ){
238 continue;
239 }
240
241 $current_plugin_version = $all_plugins[ $plugin_requirement['basename'] ]['Version'];
242
243 if ( version_compare( $current_plugin_version, $plugin_requirement['version'], '<' ) ) {
244
245 $this->admin_notices[] = sprintf(
246 __( 'The plugin requires %s plugin version %s or higher (current version is %s). Please update it to the latest version.', 'auxin-elements' ),
247 '<strong>'. $plugin_requirement['name'] . '</strong>',
248 '<strong>'. $plugin_requirement['version'] . '</strong>',
249 '<strong>'. $current_plugin_version . '</strong>'
250 );
251
252 $this->requirements_passed = false;
253 }
254
255 }
256
257 }
258
259 }
260
261 }
262
263 }
264
265 /**
266 * Check them requirements
267 *
268 * @return void
269 */
270 function check_theme_requirement(){
271
272 if( empty( $this->requirements['themes'] ) ){
273 return;
274 }
275
276 $this->admin_notices['theme'] = '';
277
278 if( $theme_requirements = $this->requirements['themes'] ){
279
280 // Walk through the themes
281 foreach ( $theme_requirements as $theme_requirement ) {
282
283 if( ! isset( $theme_requirement['id'] ) ){
284 $theme_requirement['id'] = str_replace( ' ', '-', strtolower( $theme_requirement['name'] ) );
285 }
286 $theme_requirement = apply_filters( 'auxin_plugin_requirements_theme_dependency', $theme_requirement, $theme_requirement['id'] );
287
288 if ( ! empty( $theme_requirement['file_required'] ) ){
289 if( is_array( $theme_requirement['file_required'] ) ){
290
291 foreach ( $theme_requirement['file_required'] as $the_required_file_path ) {
292
293 if( file_exists( $the_required_file_path ) ){
294 require_once( $the_required_file_path );
295 } else {
296 $this->requirements_passed = false;
297 continue 2;
298 }
299 }
300
301 } elseif( file_exists( $theme_requirement['file_required'] ) ){
302 require_once( $theme_requirement['file_required'] );
303 } else {
304 $this->requirements_passed = false;
305 continue;
306 }
307 } else {
308 $this->requirements_passed = false;
309 continue;
310 }
311
312 if( THEME_ID !== $theme_requirement['id'] ){
313 $this->requirements_passed = false;
314 continue;
315 }
316
317 if( ! empty( $theme_requirement['theme_requires_const'] ) && defined( $theme_requirement['theme_requires_const'] ) ){
318
319 $all_plugins = $this->get_plugins();
320
321 if( ! empty( $all_plugins[ $this->requirements['config']['plugin_basename'] ]['Version'] ) ){
322 $plugin_info = $all_plugins[ $this->requirements['config']['plugin_basename'] ];
323
324 if( version_compare( $plugin_info['Version'], constant( $theme_requirement['theme_requires_const'] ), '<' ) ){
325 $this->admin_notices['theme'] .= sprintf(
326 __( '%s theme requires %s plugin version %s or higher in order to function property. Your current plugin version is %s, please update it to latest version.', 'auxin-elements' ).
327 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
328 THEME_NAME_I18N,
329 '<strong>'. $plugin_info['Name'] . '</strong>',
330 '<strong>'. constant( $theme_requirement['theme_requires_const'] ) . '</strong>',
331 '<strong>'. $plugin_info['Version'] . '</strong>'
332 );
333
334 $this->requirements_passed = false;
335 continue;
336 }
337 }
338 }
339
340 if ( $theme_requirement['version'] ){
341
342 $theme_data = wp_get_theme();
343 $theme_data = $theme_data->parent() ? $theme_data->parent() : $theme_data;
344
345 if ( version_compare( $theme_data->Version, $theme_requirement['version'], '<' ) ) {
346
347 $theme_requirement['update_anchor_start'] = ! empty( $theme_requirement['update_link'] ) ? '<a target="_blank" href="'. admin_url( $theme_requirement['update_link'] ).'">' : '';
348 $theme_requirement['update_anchor_end'] = ! empty( $theme_requirement['update_link'] ) ? '</a>' : '';
349
350 $this->admin_notices['theme'] .= sprintf(
351 __( 'The plugin requires %s theme version %s or higher in order to function property. Your current theme version is %s, please %s update to latest version %s.', 'auxin-elements' ).
352 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
353 '<strong>'. $theme_requirement['name'] . '</strong>',
354 '<strong>'. $theme_requirement['version'] . '</strong>',
355 '<strong>'. $theme_data->Version . '</strong>',
356 $theme_requirement['update_anchor_start'],
357 $theme_requirement['update_anchor_end']
358 );
359
360 if( defined( 'AUXIN_DEBUG' ) && AUXIN_DEBUG ){
361 if( ! empty( $theme_requirement['file_exists'] ) ){
362 $this->admin_notices['theme'] .= sprintf(
363 __( '%s path while checking the availability of theme not found.', 'auxin-elements' ),
364 '<code>'. $theme_requirement['file_exists'] . '</code>'
365 );
366 } elseif( ! empty( $theme_requirement['is_callable'] ) ){
367 $this->admin_notices['theme'] .= sprintf(
368 __( '%s function callback while checking the availability of theme not found.', 'auxin-elements' ),
369 '<code>'. $theme_requirement['file_exists'] . '</code>'
370 );
371 }
372 }
373
374 $this->requirements_passed = false;
375 continue;
376 }
377
378 }
379
380 unset( $this->admin_notices['theme'] );
381 $this->requirements_passed = true;
382 return;
383 }
384
385 $this->requirements_passed = false;
386 return;
387 }
388
389 }
390
391 /**
392 * Check PHP requirements
393 *
394 * @return void
395 */
396 function check_php_requirement(){
397
398 if( empty( $this->requirements['php']['version'] ) ){
399 return;
400 }
401
402 if ( version_compare( PHP_VERSION, $this->requirements['php']['version'], '<' ) ) {
403
404 $this->admin_notices[] = sprintf(
405 __( 'PHP version %s or above is required for this plugin while your the current PHP version is %s.', 'auxin-elements' ),
406 '<strong>'. $this->requirements['php']['version'] . '</strong>',
407 '<strong>'. PHP_VERSION . '</strong>'
408 );
409
410 $this->requirements_passed = false;
411 return;
412 }
413
414 }
415
416 /**
417 * Checks all requirements
418 *
419 * @return string|boolean True if all requirements are passed, false or error message on failure
420 */
421 public function validate(){
422
423 $this->check_php_requirement();
424
425 if( true !== $this->requirements_passed ){ return $this->requirements_passed; }
426
427 $this->check_theme_requirement();
428
429 if( true !== $this->requirements_passed ){ return $this->requirements_passed; }
430
431 $this->check_plugins_requirement();
432
433 return $this->requirements_passed;
434 }
435
436 }
437
438 }
439