PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.4.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.4.2
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-minify-config.php

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

208 lines 5.2 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 /**
6 * Handles cache configuration and related I/O
7 */
8
9 if (!class_exists('WP_Optimize_Minify_Config')) :
10
11 class WP_Optimize_Minify_Config {
12
13 static protected $_instance = null;
14
15 private $_options = array();
16
17 /**
18 * Construct
19 *
20 * @return void
21 */
22 private function __construct() {
23 }
24
25 /**
26 * Getter to see if Minify is enabled
27 *
28 * @return bool
29 */
30 public function is_enabled() {
31 return $this->get('enabled');
32 }
33
34 /**
35 * Removes all Minify settings from the Database if 'preserve_settings_on_uninstall' is false
36 *
37 * @return void
38 */
39 public function purge() {
40 if (!$this->get('preserve_settings_on_uninstall')) {
41 if (is_multisite()) {
42 delete_site_option('wpo_minify_config');
43 } else {
44 delete_option('wpo_minify_config');
45 }
46 }
47 }
48
49 /**
50 * Get config from file or cache
51 *
52 * @param string $option - An option name
53 * @param mixed $default - A default for the option
54 * @return array|string
55 */
56 public function get($option = null, $default = false) {
57 if (empty($this->_options)) {
58 if (is_multisite()) {
59 $config = get_site_option('wpo_minify_config', array());
60 } else {
61 $config = get_option('wpo_minify_config', array());
62 }
63 $this->_options = wp_parse_args($config, $this->get_defaults());
64 }
65
66 if ($option && isset($this->_options[$option])) {
67 return $this->_options[$option];
68 } elseif ($option) {
69 return $default;
70 }
71 return $this->_options;
72 }
73
74 /**
75 * Update the config
76 *
77 * @param array $config - The new configuration array
78 * @return boolean
79 */
80 public function update($config) {
81 $prev_settings = $this->get();
82 $prev_settings = wp_parse_args($prev_settings, $this->get_defaults());
83 $new_settings = wp_parse_args($config, $prev_settings);
84 $this->_options = $new_settings;
85
86 if (is_multisite()) {
87 update_site_option('wpo_minify_config', $new_settings);
88 } else {
89 update_option('wpo_minify_config', $new_settings);
90 }
91
92 return true;
93 }
94
95 /**
96 * Return defaults
97 *
98 * @return array
99 */
100 public function get_defaults() {
101 $defaults = array(
102 // dev tab checkboxes
103 'debug' => false,
104 'enabled_css_preload' => false,
105 'enabled_js_preload' => false,
106 'hpreconnect' => '',
107 'hpreload' => '',
108 'loadcss' => false,
109 'remove_css' => false,
110 'critical_path_css' => '',
111 'critical_path_css_is_front_page' => '',
112 // settings tab checkboxes
113 'preserve_settings_on_uninstall' => true,
114 'disable_when_logged_in' => false,
115 'default_protocol' => 'dynamic', // dynamic, http, https
116 'html_minification' => true,
117 'clean_header_one' => false,
118 'emoji_removal' => true,
119 'merge_google_fonts' => true,
120 'enable_display_swap' => true,
121 'remove_googlefonts' => false,
122 'gfonts_method' => 'inherit', // inline, async, exclude
123 'fawesome_method' => 'inherit', // inline, async, exclude
124 'enable_css' => true,
125 'enable_css_minification' => true,
126 'enable_merging_of_css' => true,
127 'remove_print_mediatypes' => false,
128 'inline_css' => false,
129 'enable_js' => true,
130 'enable_js_minification' => true,
131 'enable_merging_of_js' => true,
132 'enable_defer_js' => 'individual',
133 'defer_js_type' => 'defer',
134 'defer_jquery' => true,
135 'enable_js_trycatch' => false,
136 'exclude_defer_login' => true,
137 'cdn_url' => '',
138 'cdn_force' => false,
139
140 'async_css' => '',
141 'async_js' => '',
142 'disable_css_inline_merge' => true,
143 /**
144 * UA list compiled from these resources:
145 * https://explore.whatismybrowser.com/useragents/explore/software_name/gtmetrix-analyser/
146 * https://explore.whatismybrowser.com/useragents/explore/software_name/pingdom-bot/
147 * https://explore.whatismybrowser.com/useragents/explore/software_name/google-lighthouse/
148 * https://explore.whatismybrowser.com/useragents/explore/software_name/googlebot/
149 * https://explore.whatismybrowser.com/useragents/explore/software_name/headless-chrome/
150 */
151 'ualist' => array('Googlebot', 'Chrome-Lighthouse', 'GTmetrix', 'HeadlessChrome', 'Pingdom'),
152 'exclude_js_from_page_speed_tools' => false,
153 'exclude_css_from_page_speed_tools' => false,
154 'blacklist' => array(),
155 'ignore_list' => array(),
156 'exclude_js' => '',
157 'exclude_css' => '',
158 'edit_default_exclutions' => false,
159
160 'merge_allowed_urls' => '',
161
162 // internal
163 'enabled' => false,
164 'last-cache-update' => 0,
165 'plugin_version' => '0.0.0',
166 'cache_lifespan' => 30,
167 'merge_inline_extra_css_js' => true,
168 );
169 return apply_filters('wpo_minify_defaults', $defaults);
170 }
171
172 /**
173 * Check whether everything should be purged instead of just incremented
174 *
175 * @return boolean
176 */
177 public function always_purge_everything() {
178 /**
179 * Filters the result of always_purge_everything
180 *
181 * @return boolean
182 */
183 return apply_filters('wpo_minify_always_purge_everything', 0 === intval($this->get('cache_lifespan')) || (defined('WPO_ADVANCED_CACHE') && defined('WP_CACHE') && WP_CACHE));
184 }
185
186 /**
187 * Get the instance
188 *
189 * @return WP_Optimize_Minify_Config
190 */
191 public static function get_instance() {
192 if (!self::$_instance) {
193 self::$_instance = new self();
194 }
195 return self::$_instance;
196 }
197 }
198
199 /**
200 * Get WPO Minify instance
201 *
202 * @return WP_Optimize_Minify_Config
203 */
204 function wp_optimize_minify_config() {
205 return WP_Optimize_Minify_Config::get_instance();
206 }
207 endif;
208