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

221 lines 5.6 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 (bool) $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 'host_local_google_fonts' => false,
123 'disable_google_fonts_processing' => false,
124 'gfonts_method' => 'inherit', // inline, async, exclude
125 'fawesome_method' => 'inherit', // inline, async, exclude
126 'enable_css' => true,
127 'enable_css_minification' => true,
128 'enable_merging_of_css' => false,
129 'remove_print_mediatypes' => false,
130 'inline_css' => false,
131 'enable_js' => true,
132 'enable_js_minification' => true,
133 'enable_merging_of_js' => false,
134 'enable_defer_js' => 'individual',
135 'defer_js_type' => 'defer',
136 'defer_jquery' => true,
137 'enable_js_trycatch' => false,
138 'exclude_defer_login' => true,
139 'cdn_url' => '',
140 'cdn_force' => false,
141
142 'enable_delay_js' => false,
143 'enable_preload_js' => false,
144 'exclude_delay_js' => '',
145
146 'async_css' => '',
147 'async_js' => '',
148 'disable_css_inline_merge' => true,
149 /**
150 * UA list compiled from these resources:
151 * https://explore.whatismybrowser.com/useragents/explore/software_name/gtmetrix-analyser/
152 * https://explore.whatismybrowser.com/useragents/explore/software_name/pingdom-bot/
153 * https://explore.whatismybrowser.com/useragents/explore/software_name/google-lighthouse/
154 * https://explore.whatismybrowser.com/useragents/explore/software_name/googlebot/
155 * https://explore.whatismybrowser.com/useragents/explore/software_name/headless-chrome/
156 */
157 'ualist' => array('Googlebot', 'Chrome-Lighthouse', 'GTmetrix', 'HeadlessChrome', 'Pingdom'),
158 'exclude_js_from_page_speed_tools' => false,
159 'exclude_css_from_page_speed_tools' => false,
160 'blacklist' => array(),
161 'ignore_list' => array(),
162 'exclude_js' => '',
163 'exclude_css' => '',
164 'edit_default_exclutions' => false,
165
166 'merge_allowed_urls' => '',
167
168 // internal
169 'enabled' => false,
170 'last-cache-update' => 0,
171 'plugin_version' => '0.0.0',
172 'cache_lifespan' => 30,
173 'merge_inline_extra_css_js' => true,
174
175 'enable_analytics' => false,
176 'analytics_method' => 'gtagv4',
177 'tracking_id' => '',
178
179 'enable_unused_css' => false,
180 );
181 return apply_filters('wpo_minify_defaults', $defaults);
182 }
183
184 /**
185 * Check whether everything should be purged instead of just incremented
186 *
187 * @return boolean
188 */
189 public function always_purge_everything() {
190 /**
191 * Filters the result of always_purge_everything
192 *
193 * @return boolean
194 */
195 $filtered_value = apply_filters('wpo_minify_always_purge_everything', 0 === intval($this->get('cache_lifespan')) || (defined('WPO_ADVANCED_CACHE') && defined('WP_CACHE') && WP_CACHE));
196 return is_bool($filtered_value) ? $filtered_value : false;
197 }
198
199 /**
200 * Get the instance
201 *
202 * @return WP_Optimize_Minify_Config
203 */
204 public static function get_instance() {
205 if (!self::$_instance) {
206 self::$_instance = new self();
207 }
208 return self::$_instance;
209 }
210 }
211
212 /**
213 * Get WPO Minify instance
214 *
215 * @return WP_Optimize_Minify_Config
216 */
217 function wp_optimize_minify_config() {
218 return WP_Optimize_Minify_Config::get_instance();
219 }
220 endif;
221