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

198 lines 4.7 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 'ualist' => array('x11.*fox\/54', 'oid\s4.*xus.*ome\/62', 'x11.*ome\/62', 'oobot', 'ighth', 'tmetr', 'eadles', 'ingdo'),
144 'blacklist' => array(),
145 'ignore_list' => array(),
146 'exclude_js' => '',
147 'exclude_css' => '',
148 'edit_default_exclutions' => false,
149
150 'merge_allowed_urls' => '',
151
152 // internal
153 'enabled' => false,
154 'last-cache-update' => 0,
155 'plugin_version' => '0.0.0',
156 'cache_lifespan' => 30,
157 'merge_inline_extra_css_js' => true,
158 );
159 return apply_filters('wpo_minify_defaults', $defaults);
160 }
161
162 /**
163 * Check whether everything should be purged instead of just incremented
164 *
165 * @return boolean
166 */
167 public function always_purge_everything() {
168 /**
169 * Filters the result of always_purge_everything
170 *
171 * @return boolean
172 */
173 return apply_filters('wpo_minify_always_purge_everything', 0 === intval($this->get('cache_lifespan')) || (defined('WPO_ADVANCED_CACHE') && defined('WP_CACHE') && WP_CACHE));
174 }
175
176 /**
177 * Get the instance
178 *
179 * @return WP_Optimize_Minify_Config
180 */
181 public static function get_instance() {
182 if (!self::$_instance) {
183 self::$_instance = new self();
184 }
185 return self::$_instance;
186 }
187 }
188
189 /**
190 * Get WPO Minify instance
191 *
192 * @return WP_Optimize_Minify_Config
193 */
194 function wp_optimize_minify_config() {
195 return WP_Optimize_Minify_Config::get_instance();
196 }
197 endif;
198