PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.21
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.21
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / cache / class-wp-optimize-detect-cache-plugins.php

class-wp-optimize-detect-cache-plugins.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.21, at cache/class-wp-optimize-detect-cache-plugins.php

107 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) die('No direct access allowed');
4
5 class WP_Optimize_Detect_Cache_Plugins {
6
7 private static $instance;
8
9 /**
10 * WP_Optimize_Detect_Cache_Plugins constructor.
11 */
12 protected function __construct() {
13 }
14
15 /**
16 * Detect list of active most popular WordPress cache plugins.
17 *
18 * @return array
19 */
20 public function get_active_cache_plugins() {
21 // The index is the plugin's slug
22
23 $active_cache_plugins = array();
24
25 foreach ($this->get_plugins() as $plugin_slug => $plugin_title) {
26
27 $function_name = 'is_'.str_replace('-', '_', $plugin_slug).'_plugin_active';
28
29 if (is_callable(array($this, $function_name))) {
30 if (call_user_func(array($this, $function_name))) {
31 $active_cache_plugins[$plugin_slug] = $plugin_title;
32 }
33 } else {
34 if ($this->is_plugin_active($plugin_slug)) {
35 $active_cache_plugins[$plugin_slug] = $plugin_title;
36 }
37 }
38 }
39
40 return $active_cache_plugins;
41 }
42
43 /**
44 * Get the plugins list
45 *
46 * @return array
47 */
48 protected function get_plugins() {
49 return array(
50 'w3-total-cache' => 'W3 Total Cache',
51 'wp-super-cache' => 'WP Super Cache',
52 'wp-rocket' => 'WP Rocket',
53 'wp-fastest-cache' => 'WP Fastest Cache',
54 'litespeed-cache' => 'LiteSpeed Cache',
55 'cache-enabler' => 'Cache Enabler',
56 'comet-cache' => 'Comet Cache',
57 'hummingbird-performance' => 'Hummingbird',
58 'hyper-cache' => 'Hyper Cache',
59 );
60 }
61
62 /**
63 * Check if W3 Total Cache active.
64 *
65 * @return bool
66 */
67 public function is_w3_total_cache_plugin_active() {
68 return defined('W3TC_VERSION') || $this->is_plugin_active('w3-total-cache');
69 }
70
71 /**
72 * Check if WP Rocket active.
73 *
74 * @return bool
75 */
76 public function is_wp_rocket_plugin_active() {
77 return defined('WP_ROCKET_VERSION') || $this->is_plugin_active('wp-rocket');
78 }
79
80 /**
81 * Check if $plugin is active.
82 *
83 * @param string $plugin - plugin slug
84 *
85 * @return bool
86 */
87 private function is_plugin_active($plugin) {
88 $status = WP_Optimize()->get_db_info()->get_plugin_status($plugin);
89
90 return $status['active'];
91 }
92
93 /**
94 * Instance of WP_Optimize_Detect_Cache_Plugins.
95 *
96 * @return WP_Optimize_Detect_Cache_Plugins
97 */
98 static public function instance() {
99 static $instance;
100 if (empty($instance)) {
101 $instance = new self();
102 }
103
104 return $instance;
105 }
106 }
107