1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
<?php
if (!defined('ABSPATH')) die('No direct access allowed');
/** * Handles cache configuration and related I/O */
if (!class_exists('WP_Optimize_Minify_Config')) :
class WP_Optimize_Minify_Config {
static protected $_instance = null;
private $_options = array();
/** * Construct * * @return void */ private function __construct() { }
/** * Getter to see if Minify is enabled * * @return bool */ public function is_enabled() { return $this->get('enabled'); }
/** * Removes all Minify settings from the Database if 'preserve_settings_on_uninstall' is false * * @return void */ public function purge() { if (!$this->get('preserve_settings_on_uninstall')) { if (is_multisite()) { delete_site_option('wpo_minify_config'); } else { delete_option('wpo_minify_config'); } } }
/** * Get config from file or cache * * @param string $option - An option name * @param mixed $default - A default for the option * @return array|string */ public function get($option = null, $default = false) { if (empty($this->_options)) { if (is_multisite()) { $config = get_site_option('wpo_minify_config', array()); } else { $config = get_option('wpo_minify_config', array()); } $this->_options = wp_parse_args($config, $this->get_defaults()); } if ($option && isset($this->_options[$option])) { return $this->_options[$option]; } elseif ($option) { return $default; } return $this->_options; }
/** * Update the config * * @param array $config - The new configuration array * @return boolean */ public function update($config) { $prev_settings = $this->get(); $prev_settings = wp_parse_args($prev_settings, $this->get_defaults()); $new_settings = wp_parse_args($config, $prev_settings); $this->_options = $new_settings;
if (is_multisite()) { update_site_option('wpo_minify_config', $new_settings); } else { update_option('wpo_minify_config', $new_settings); }
return true; }
/** * Return defaults * * @return array */ public function get_defaults() { $defaults = array( // dev tab checkboxes 'debug' => false, 'enabled_css_preload' => false, 'enabled_js_preload' => false, 'hpreconnect' => '', 'hpreload' => '', 'loadcss' => false, 'remove_css' => false, 'critical_path_css' => '', 'critical_path_css_is_front_page' => '', // settings tab checkboxes 'preserve_settings_on_uninstall' => true, 'disable_when_logged_in' => false, 'default_protocol' => 'dynamic', // dynamic, http, https 'html_minification' => true, 'clean_header_one' => false, 'emoji_removal' => true, 'merge_google_fonts' => true, 'enable_display_swap' => true, 'remove_googlefonts' => false, 'gfonts_method' => 'inline', // inline, async, exclude 'fawesome_method' => 'inherit', // inline, async, exclude 'enable_css' => true, 'enable_css_minification' => true, 'enable_merging_of_css' => true, 'remove_print_mediatypes' => false, 'inline_css' => false, 'enable_js' => true, 'enable_js_minification' => true, 'enable_merging_of_js' => true, 'enable_defer_js' => 'individual', 'defer_js_type' => 'defer', 'defer_jquery' => true, 'enable_js_trycatch' => false, 'exclude_defer_login' => true, 'cdn_url' => '', 'cdn_force' => false,
'async_css' => '', 'async_js' => '', 'disable_css_inline_merge' => true, 'ualist' => array('x11.*fox\/54', 'oid\s4.*xus.*ome\/62', 'x11.*ome\/62', 'oobot', 'ighth', 'tmetr', 'eadles', 'ingdo'), 'blacklist' => array(), 'ignore_list' => array(), 'exclude_js' => '', 'exclude_css' => '', 'edit_default_exclutions' => false, 'merge_allowed_urls' => '',
// internal 'enabled' => false, 'last-cache-update' => 0, 'plugin_version' => '0.0.0' ); return apply_filters('wpo_minify_defaults', $defaults); }
/** * Get the instance * * @return WP_Optimize_Minify_Config */ public static function get_instance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; } }
/** * Get WPO Minify instance * * @return WP_Optimize_Minify_Config */ function wp_optimize_minify_config() { return WP_Optimize_Minify_Config::get_instance(); } endif;
|