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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
<?php /** * Manages activation/deactivation and upgrades of Hummingbird * * @author: WPMUDEV, Ignacio Cruz (igmoweb) * @package Hummingbird\Core */
namespace Hummingbird\Core;
use Hummingbird\WP_Hummingbird;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * Class Installer */ class Installer {
/** * Plugin activation */ public static function activate() { if ( ! defined( 'WPHB_ACTIVATING' ) ) { define( 'WPHB_ACTIVATING', true ); }
update_site_option( 'wphb_version', WPHB_VERSION ); update_site_option( 'wphb-notice-uptime-info-show', 'yes' ); // Add uptime notice. update_site_option( 'wphb_run_onboarding', true ); }
/** * Plugin activation in a blog (if the site is a multisite) */ public static function activate_blog() { update_option( 'wphb_version', WPHB_VERSION ); update_option( 'wphb_run_onboarding', true ); do_action( 'wphb_activate' ); }
/** * Plugin deactivation */ public static function deactivate() { // Avoid to execute this over an over in same thread execution. if ( defined( 'WPHB_SWITCHING_VERSION' ) ) { return; }
$settings = Settings::get_settings( 'settings' ); WP_Hummingbird::flush_cache( $settings['remove_data'], $settings['remove_settings'] );
Utils::get_module( 'page_cache' )->toggle_service( false );
if ( $settings['remove_settings'] ) { // Completely remove hummingbird-asset folder. Filesystem::instance()->purge( '', true ); } do_action( 'wphb_deactivate' ); }
/** * Plugin upgrades */ public static function maybe_upgrade() { // Avoid to execute this over an over in same thread execution. if ( defined( 'WPHB_ACTIVATING' ) ) { return; }
if ( defined( 'WPHB_UPGRADING' ) && WPHB_UPGRADING ) { return; }
self::upgrade(); }
/** * Upgrade */ public static function upgrade() { $version = get_site_option( 'wphb_version' );
if ( false === $version ) { self::activate(); }
if ( is_multisite() ) { $blog_version = get_option( 'wphb_version' ); if ( false === $blog_version ) { self::activate_blog(); }
if ( false !== $blog_version && WPHB_VERSION !== $blog_version ) { if ( version_compare( $blog_version, '2.6.0', '<' ) ) { self::upgrade_2_6_0_multi(); }
if ( version_compare( $version, '2.6.2', '<' ) ) { self::upgrade_2_6_2_multi(); } } }
if ( false !== $version && WPHB_VERSION !== $version ) { if ( ! defined( 'WPHB_UPGRADING' ) ) { define( 'WPHB_UPGRADING', true ); }
if ( version_compare( $version, '2.5.0', '<' ) ) { self::upgrade_2_5_0(); }
if ( version_compare( $version, '2.5.1', '<' ) ) { self::upgrade_2_5_1(); }
if ( version_compare( $version, '2.5.2', '<' ) ) { self::upgrade_2_5_2(); }
if ( version_compare( $version, '2.6.0', '<' ) ) { self::upgrade_2_6_0(); }
if ( version_compare( $version, '2.6.2', '<' ) ) { self::upgrade_2_6_2(); }
update_site_option( 'wphb_version', WPHB_VERSION ); } }
/** * Upgrades a single blog in a multisite */ public static function maybe_upgrade_blog() { $version = get_option( 'wphb_version' );
if ( WPHB_VERSION === $version ) { return; }
update_option( 'wphb_version', WPHB_VERSION ); }
/** * Upgrade to 2.5.0 * * Update advanced-cache.php file. * * @since 2.5.0 */ private static function upgrade_2_5_0() { // Force new quick setup (with tracking option). delete_option( 'wphb-quick-setup' );
$adv_cache_file = dirname( get_theme_root() ) . '/advanced-cache.php'; if ( Settings::get_settings( 'page_cache' ) && file_exists( $adv_cache_file ) ) { unlink( $adv_cache_file ); } }
/** * Upgrade to 2.5.1 * * Remove possible cron schedule loop. * * @since 2.5.1 */ private static function upgrade_2_5_1() { if ( ! function_exists( 'wp_unschedule_hook' ) ) { return; }
wp_unschedule_hook( 'wphb_performance_fetch_report' ); }
/** * Upgrade to 2.5.2 * * Change default value for "File change detection". * * @since 2.5.2 */ private static function upgrade_2_5_2() { Settings::update_setting( 'detection', 'auto', 'page_cache' ); }
/** * This is a fixed up mechanism for only updating the required stuff. * * Common for both subsites and single sites. * * @since 2.6.0 */ private static function upgrade_2_6_0_multi() { add_option( 'wphb-minification-show-config_modal', true );
// Add AO upgrade modal. if ( Settings::get_setting( 'minify_blog', 'minify' ) ) { add_option( 'wphb_do_minification_upgrade', true ); self::upgrade_minification_structure(); } }
/** * Upgrade to 2.6.0 * * @since 2.6.0 */ private static function upgrade_2_6_0() { // Show upgrade summary, Currently only for v2.6.0. add_site_option( 'wphb_show_upgrade_summary', true ); add_option( 'wphb-minification-show-config_modal', true );
// Add AO upgrade modal. if ( Settings::get_setting( 'enabled', 'minify' ) ) { add_option( 'wphb_do_minification_upgrade', true ); self::upgrade_minification_structure(); }
// Change default value for "File change detection". Settings::update_setting( 'detection', 'auto', 'page_cache' );
if ( ! Settings::get_setting( 'enabled', 'page_cache' ) ) { return; }
// Update Page Cache exclusion rule for split sitemap. $settings = Utils::get_module( 'page_cache' )->get_settings(); if ( is_array( $settings['exclude']['url_strings'] ) && ! in_array( 'sitemap[0-9]*\.xml', $settings['exclude']['url_strings'], true ) ) { // Remove old value. $key = array_search( 'sitemap.xml', $settings['exclude']['url_strings'], true ); if ( false !== $key && isset( $settings['exclude']['url_strings'][ $key ] ) ) { unset( $settings['exclude']['url_strings'][ $key ] ); }
// Add new one. $settings['exclude']['url_strings'][] = 'sitemap[0-9]*\.xml'; Utils::get_module( 'page_cache' )->save_settings( $settings ); } }
/** * Upgrade the pre 2.5 settings to new 2.6 format. * * @since 2.6.0 */ private static function upgrade_minification_structure() { $options = Settings::get_settings( 'minify' );
$collections = Modules\Minify\Sources_Collector::get_collection();
foreach ( array( 'scripts', 'styles' ) as $type ) { $keys = array_keys( $collections[ $type ] );
if ( ! isset( $options['minify'] ) || ! isset( $options['minify'][ $type ] ) ) { continue; }
$options['dont_minify'][ $type ] = array_diff( $keys, $options['minify'][ $type ] ); $options['dont_combine'][ $type ] = array_diff( $keys, $options['combine'][ $type ] ); }
unset( $options['minify'] ); unset( $options['combine'] );
Settings::update_settings( $options, 'minify' ); }
/** * Upgrade sub sites to 2.6.2 * * @since 2.6.2 */ private static function upgrade_2_6_2_multi() { // Remove AO upgrade modal for sub sites that do not have AO enabled. if ( ! Settings::get_setting( 'minify_blog', 'minify' ) ) { delete_option( 'wphb_do_minification_upgrade' ); } }
/** * Upgrade to 2.6.2 * * @since 2.6.2 */ private static function upgrade_2_6_2() { Logger::cleanup();
// Remove unused database entries. delete_option( 'wphb-new-user-tour' );
// Enhance page cache sitemaps support. if ( Settings::get_setting( 'enabled', 'page_cache' ) ) { $settings = Utils::get_module( 'page_cache' )->get_settings(); if ( isset( $settings['exclude']['url_strings'] ) && is_array( $settings['exclude']['url_strings'] ) ) { // Remove old value. $key = array_search( 'sitemap[0-9]*\.xml', $settings['exclude']['url_strings'], true ); if ( false !== $key && isset( $settings['exclude']['url_strings'][ $key ] ) ) { unset( $settings['exclude']['url_strings'][ $key ] ); }
// We double search, one of the previous updates, added an extra value. $key = array_search( 'sitemap[0-9]*.xml', $settings['exclude']['url_strings'], true ); if ( false !== $key && isset( $settings['exclude']['url_strings'][ $key ] ) ) { unset( $settings['exclude']['url_strings'][ $key ] ); }
$key = array_search( 'sitemap[0-9]*.xml', $settings['exclude']['url_strings'], true ); if ( false !== $key && isset( $settings['exclude']['url_strings'][ $key ] ) ) { unset( $settings['exclude']['url_strings'][ $key ] ); }
// Add new one. $settings['exclude']['url_strings'][] = 'sitemap[^\/.]*\.(?:xml|xsl)'; Utils::get_module( 'page_cache' )->save_settings( $settings ); } } }
}
|