PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
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 / minify / class-wp-optimize-detect-minify-plugins.php

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

82 lines 1.8 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_Minify_Plugins {
6
7 /**
8 * Detect list of active most popular WordPress minify plugins.
9 *
10 * @return array
11 */
12 public function get_active_minify_plugins() {
13
14 $active_minify_plugins = array();
15
16 foreach ($this->get_plugins() as $plugin_slug => $plugin_title) {
17 if ($this->is_plugin_active($plugin_slug) && $this->is_minify_active($plugin_slug)) {
18 $active_minify_plugins[$plugin_slug] = $plugin_title;
19 }
20 }
21
22 return $active_minify_plugins;
23 }
24
25 /**
26 * Get the plugins list
27 *
28 * @return array
29 */
30 protected function get_plugins() {
31 return array(
32 'w3-total-cache' => 'W3 Total Cache',
33 'autoptimize' => 'Autoptimize',
34 'fast-velocity-minify' => 'Fast Velocity Minify',
35 );
36 }
37
38 /**
39 * Check if $plugin is active.
40 *
41 * @param string $plugin - plugin slug
42 *
43 * @return bool
44 */
45 private function is_plugin_active($plugin) {
46 $status = WP_Optimize()->get_db_info()->get_plugin_status($plugin);
47
48 return $status['active'];
49 }
50
51 /**
52 * Check if minify feature is active
53 *
54 * @param string $plugin_slug Slug of the plugin
55 * @return bool
56 */
57 public function is_minify_active($plugin_slug) {
58 switch ($plugin_slug) {
59 case 'w3-total-cache':
60 return (function_exists('w3tc_config') && w3tc_config()->get_boolean('minify.enabled'));
61 case 'autoptimize':
62 return ('on' === get_option('autoptimize_js', false) || 'on' === get_option('autoptimize_css', false) || 'on' === get_option('autoptimize_html', false));
63 case 'fast-velocity-minify':
64 return true;
65 }
66 return false;
67 }
68
69 /**
70 * Instance of WP_Optimize_Detect_Minify_Plugins.
71 *
72 * @return WP_Optimize_Detect_Minify_Plugins
73 */
74 public static function get_instance() {
75 static $instance = null;
76 if (null === $instance) {
77 $instance = new self();
78 }
79 return $instance;
80 }
81 }
82