PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.9.21
Shortcodes and extra features for Phlox theme v2.9.21
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 3 years ago class-auxels-archive-menu-links.php 3 years ago class-auxels-envato-elements.php 3 years ago class-auxels-import-parser.php 3 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 3 years ago class-auxels-wc-attribute-nav-menu.php 4 years ago class-auxin-admin-dashboard.php 3 years ago class-auxin-demo-importer.php 3 years ago class-auxin-dependency-sorting.php 3 years ago class-auxin-import.php 3 years ago class-auxin-install.php 3 years ago class-auxin-master-nav-menu-admin.php 3 years ago class-auxin-page-template.php 4 years ago class-auxin-permalink.php 3 years ago class-auxin-plugin-requirements.php 3 years ago class-auxin-post-type-base.php 3 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 3 years ago class-auxin-walker-nav-menu-back.php 3 years ago class-auxin-welcome-sections.php 3 years ago class-auxin-welcome.php 3 years ago class-auxin-whitelabel.php 3 years ago class-auxin-widget-indie.php 3 years ago class-auxin-widget-shortcode-map.php 3 years ago class-auxin-widget.php 3 years ago
class-auxin-plugin-requirements.php
438 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 public 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 esc_html__( '%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 public 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 public 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 $active_plugins_reordered = $resolved_plugins_load_order;
183 foreach( $active_plugins as $plugin_basename ) {
184 if ( !in_array( $plugin_basename, $active_plugins_reordered ) ) {
185 $active_plugins_reordered[] = $plugin_basename;
186 }
187 }
188
189 update_option( 'active_plugins', $active_plugins_reordered );
190 }
191
192 }
193
194 }
195
196
197 /**
198 * Check plugin requirements
199 *
200 * @return void
201 */
202 public function check_plugins_requirement(){
203
204 if( empty( $this->requirements['plugins'] ) ){
205 return;
206 }
207
208 if( $plugin_requirements = $this->requirements['plugins'] ){
209 if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
210
211 // Walk through the plugins
212 foreach ( $plugin_requirements as $plugin_requirement ) {
213
214 // check if the plugin is active
215 $is_plugin_active = $this->is_plugin_active( $plugin_requirement['basename'] );
216
217 // if activating the plugin is required
218 if(
219 ( ! empty( $plugin_requirement['required'] ) && true == $plugin_requirement['required'] && ! $is_plugin_active ) ||
220 ( ! empty( $plugin_requirement['is_callable'] ) && ! function_exists( $plugin_requirement['is_callable'] ) )
221 ){
222
223 $this->admin_notices[] = sprintf(
224 __( '%s plugin is required in order to use this plugin. Please install and activate the plugin.', 'auxin-elements' ).
225 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
226 '<strong>'. $plugin_requirement['name'] . '</strong>'
227 );
228
229 $this->requirements_passed = false;
230
231 // if minimum plugin version was specified
232 } elseif( ! empty( $plugin_requirement['version'] ) && $is_plugin_active ){
233
234 $all_plugins = $this->get_plugins();
235
236 if( empty( $all_plugins[ $plugin_requirement['basename'] ]['Version'] ) ){
237 continue;
238 }
239
240 $current_plugin_version = $all_plugins[ $plugin_requirement['basename'] ]['Version'];
241
242 if ( version_compare( $current_plugin_version, $plugin_requirement['version'], '<' ) ) {
243
244 $this->admin_notices[] = sprintf(
245 __( 'The plugin requires %s plugin version %s or higher (current version is %s). Please update it to the latest version.', 'auxin-elements' ),
246 '<strong>'. $plugin_requirement['name'] . '</strong>',
247 '<strong>'. $plugin_requirement['version'] . '</strong>',
248 '<strong>'. $current_plugin_version . '</strong>'
249 );
250
251 $this->requirements_passed = false;
252 }
253
254 }
255
256 }
257
258 }
259
260 }
261
262 }
263
264 /**
265 * Check them requirements
266 *
267 * @return void
268 */
269 public function check_theme_requirement(){
270
271 if( empty( $this->requirements['themes'] ) ){
272 return;
273 }
274
275 $this->admin_notices['theme'] = '';
276
277 if( $theme_requirements = $this->requirements['themes'] ){
278
279 // Walk through the themes
280 foreach ( $theme_requirements as $theme_requirement ) {
281
282 if( ! isset( $theme_requirement['id'] ) ){
283 $theme_requirement['id'] = str_replace( ' ', '-', strtolower( $theme_requirement['name'] ) );
284 }
285 $theme_requirement = apply_filters( 'auxin_plugin_requirements_theme_dependency', $theme_requirement, $theme_requirement['id'] );
286
287 if ( ! empty( $theme_requirement['file_required'] ) ){
288 if( is_array( $theme_requirement['file_required'] ) ){
289
290 foreach ( $theme_requirement['file_required'] as $the_required_file_path ) {
291
292 if( file_exists( $the_required_file_path ) ){
293 require_once( $the_required_file_path );
294 } else {
295 $this->requirements_passed = false;
296 continue 2;
297 }
298 }
299
300 } elseif( file_exists( $theme_requirement['file_required'] ) ){
301 require_once( $theme_requirement['file_required'] );
302 } else {
303 $this->requirements_passed = false;
304 continue;
305 }
306 } else {
307 $this->requirements_passed = false;
308 continue;
309 }
310
311 if( THEME_ID !== $theme_requirement['id'] ){
312 $this->requirements_passed = false;
313 continue;
314 }
315
316 if( ! empty( $theme_requirement['theme_requires_const'] ) && defined( $theme_requirement['theme_requires_const'] ) ){
317
318 $all_plugins = $this->get_plugins();
319
320 if( ! empty( $all_plugins[ $this->requirements['config']['plugin_basename'] ]['Version'] ) ){
321 $plugin_info = $all_plugins[ $this->requirements['config']['plugin_basename'] ];
322
323 if( version_compare( $plugin_info['Version'], constant( $theme_requirement['theme_requires_const'] ), '<' ) ){
324 $this->admin_notices['theme'] .= sprintf(
325 __( '%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' ).
326 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
327 THEME_NAME_I18N,
328 '<strong>'. $plugin_info['Name'] . '</strong>',
329 '<strong>'. constant( $theme_requirement['theme_requires_const'] ) . '</strong>',
330 '<strong>'. $plugin_info['Version'] . '</strong>'
331 );
332
333 $this->requirements_passed = false;
334 continue;
335 }
336 }
337 }
338
339 if ( $theme_requirement['version'] ){
340
341 $theme_data = wp_get_theme();
342 $theme_data = $theme_data->parent() ? $theme_data->parent() : $theme_data;
343
344 if ( version_compare( $theme_data->Version, $theme_requirement['version'], '<' ) ) {
345
346 $theme_requirement['update_anchor_start'] = ! empty( $theme_requirement['update_link'] ) ? '<a target="_blank" href="'. admin_url( $theme_requirement['update_link'] ).'">' : '';
347 $theme_requirement['update_anchor_end'] = ! empty( $theme_requirement['update_link'] ) ? '</a>' : '';
348
349 $this->admin_notices['theme'] .= sprintf(
350 __( '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' ).
351 ' <a href="https://docs.phlox.pro/article/210-update-phlox-pro/" target="_blank">'. __('How to upgrade', 'auxin-elements') . '</a>',
352 '<strong>'. $theme_requirement['name'] . '</strong>',
353 '<strong>'. $theme_requirement['version'] . '</strong>',
354 '<strong>'. $theme_data->Version . '</strong>',
355 $theme_requirement['update_anchor_start'],
356 $theme_requirement['update_anchor_end']
357 );
358
359 if( defined( 'AUXIN_DEBUG' ) && AUXIN_DEBUG ){
360 if( ! empty( $theme_requirement['file_exists'] ) ){
361 $this->admin_notices['theme'] .= sprintf(
362 __( '%s path while checking the availability of theme not found.', 'auxin-elements' ),
363 '<code>'. $theme_requirement['file_exists'] . '</code>'
364 );
365 } elseif( ! empty( $theme_requirement['is_callable'] ) ){
366 $this->admin_notices['theme'] .= sprintf(
367 __( '%s function callback while checking the availability of theme not found.', 'auxin-elements' ),
368 '<code>'. $theme_requirement['file_exists'] . '</code>'
369 );
370 }
371 }
372
373 $this->requirements_passed = false;
374 continue;
375 }
376
377 }
378
379 unset( $this->admin_notices['theme'] );
380 $this->requirements_passed = true;
381 return;
382 }
383
384 $this->requirements_passed = false;
385 return;
386 }
387
388 }
389
390 /**
391 * Check PHP requirements
392 *
393 * @return void
394 */
395 function check_php_requirement(){
396
397 if( empty( $this->requirements['php']['version'] ) ){
398 return;
399 }
400
401 if ( version_compare( PHP_VERSION, $this->requirements['php']['version'], '<' ) ) {
402
403 $this->admin_notices[] = sprintf(
404 __( 'PHP version %s or above is required for this plugin while your the current PHP version is %s.', 'auxin-elements' ),
405 '<strong>'. $this->requirements['php']['version'] . '</strong>',
406 '<strong>'. PHP_VERSION . '</strong>'
407 );
408
409 $this->requirements_passed = false;
410 return;
411 }
412
413 }
414
415 /**
416 * Checks all requirements
417 *
418 * @return string|boolean True if all requirements are passed, false or error message on failure
419 */
420 public function validate(){
421
422 $this->check_php_requirement();
423
424 if( true !== $this->requirements_passed ){ return $this->requirements_passed; }
425
426 $this->check_theme_requirement();
427
428 if( true !== $this->requirements_passed ){ return $this->requirements_passed; }
429
430 $this->check_plugins_requirement();
431
432 return $this->requirements_passed;
433 }
434
435 }
436
437 }
438