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

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

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