PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.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
← All changes | includes/class-wp-optimize-updates.php +238 -21 3.2.20 → 4.7.0 View file →
@@ -30,14 +30,33 @@
30 30 '3.2.15' => array('update_3215_modify_cache_config_for_webp'),
31 31 '3.2.17' => array('update_3217_remove_htaccess_capability_tester_files'),
32 32 '3.2.18' => array('update_3218_reset_webp_serving_method'),
33 33 '3.2.19' => array('update_3219_modify_cache_config_for_cache_time'),
34 + '3.3.0' => array('update_330_ua_async_exclusion_list'),
35 + '3.5.0' => array(
36 + 'update_350_move_content_of_existing_smush_logs_to_new_location',
37 + 'update_350_delete_plugin_table_list_regenerate_in_new_location',
38 + ),
39 + '3.7.0' => array('update_370_disable_auto_preload_after_purge_feature'),
40 + '3.8.0' => array('update_380_404_detector_table_create'),
41 + '4.3.1' => array(
42 + 'update_431_db_table_analysis_wipe_usage_data',
43 + ),
44 + '4.4.0' => array(
45 + 'update_440_change_plugin_json_permissions',
46 + ),
47 + '4.6.1' => array(
48 + 'update_461_update_post_meta_keys',
49 + ),
50 + '4.7.0' => array(
51 + 'update_470_update_browser_cache_htaccess_config',
52 + ),
34 53 );
35 54
36 55 /**
37 56 * See if any database schema updates are needed, and perform them if so.
38 57 * Example Usage:
39 - * public static function update_101_add_new_column() {
58 + * private static function update_101_add_new_column() {
40 59 * $wpdb = $GLOBALS['wpdb'];
41 60 * $wpdb->query('ALTER TABLE tm_tasks ADD task_expiry varchar(300) AFTER id');
42 61 * }
43 62 */
@@ -53,37 +72,58 @@
53 72 }
54 73 }
55 74 update_option('wpo_update_version', WPO_VERSION);
56 75 }
76 +
77 + $wpo_version = get_option('wpo_version');
78 +
79 + // If the wpo_version option is not set, but the db_version is, we assume that the wpo_version should be set to the db_version.
80 + if (!$wpo_version) {
81 + $wpo_version = $db_version ?: WPO_VERSION;
82 + update_option('wpo_version', $wpo_version);
83 + }
84 +
85 + if ($wpo_version && version_compare($our_version, $wpo_version, '!=')) {
86 + update_option('wpo_version', WPO_VERSION);
87 + // Trigger the activation actions to ensure that any necessary setup is performed when the version changes.
88 + WPO_Activation::silence_activation_actions();
89 + }
57 90 }
58 91
59 92 /**
60 93 * Delete old semaphore locks from options database table.
61 94 */
62 - public static function delete_old_locks() {
95 + private static function delete_old_locks() {
63 96 global $wpdb;
97 +
98 + $query = "DELETE FROM `{$wpdb->options}`".
99 + " WHERE (option_name LIKE ('updraft_semaphore_%')".
100 + " OR option_name LIKE ('updraft_last_lock_time_%')".
101 + " OR option_name LIKE ('updraft_locked_%')".
102 + " OR option_name LIKE ('updraft_unlocked_%'))".
103 + " AND ".
104 + "(option_name LIKE ('%smush')".
105 + " OR option_name LIKE ('%load-url-task'));";
64 106
65 - // using this query we delete all rows related to locks.
66 - $query = "DELETE FROM {$wpdb->options}".
67 - " WHERE (option_name LIKE ('updraft_semaphore_%')".
68 - " OR option_name LIKE ('updraft_last_lock_time_%')".
69 - " OR option_name LIKE ('updraft_locked_%')".
70 - " OR option_name LIKE ('updraft_unlocked_%'))".
71 - " AND ".
72 - "(option_name LIKE ('%smush')".
73 - " OR option_name LIKE ('%load-url-task'));";
107 + $wpdb->query($query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Already prepared query, uses only hardcoded strings
74 108
75 - $wpdb->query($query);
76 109 }
77 110
78 111 /**
79 112 * Disable cache directories viewing.
80 113 */
81 - public static function disable_cache_directories_viewing() {
114 + private static function disable_cache_directories_viewing() {
115 + if (!function_exists('wpo_disable_cache_directories_viewing')) {
116 + include_once WPO_PLUGIN_MAIN_PATH . 'cache/file-based-page-cache-functions.php';
117 + }
118 + // Check if it's not a new installation
119 + if (self::is_new_install()) {
120 + return;
121 + }
82 122 wpo_disable_cache_directories_viewing();
83 123 }
84 -
85 - public static function reset_wpo_plugin_cron_tasks_schedule() {
124 +
125 + private static function reset_wpo_plugin_cron_tasks_schedule() {
86 126 wp_clear_scheduled_hook('wpo_plugin_cron_tasks');
87 127 }
88 128
89 129 /**
@@ -90,9 +130,9 @@
90 130 * Update Minify Defer option (The option was hidden until now, but we're changing the setting)
91 131 *
92 132 * @return void
93 133 */
94 - public static function enable_minify_defer() {
134 + private static function enable_minify_defer() {
95 135 if (!function_exists('wp_optimize_minify_config')) {
96 136 include_once WPO_PLUGIN_MAIN_PATH . 'minify/class-wp-optimize-minify-config.php';
97 137 }
98 138 $current_setting = wp_optimize_minify_config()->get('enable_defer_js');
@@ -107,10 +147,9 @@
107 147 * Update Minify default exclude options
108 148 *
109 149 * @return void
110 150 */
111 - public static function update_minify_excludes() {
112 - if (!WPO_MINIFY_PHP_VERSION_MET) return;
151 + private static function update_minify_excludes() {
113 152 if (!function_exists('wp_optimize_minify_config')) {
114 153 include_once WPO_PLUGIN_MAIN_PATH . 'minify/class-wp-optimize-minify-config.php';
115 154 }
116 155
@@ -130,9 +169,9 @@
130 169 // Get the lists as saved in the DB
131 170 $current_blacklist = wp_optimize_minify_config()->get('blacklist');
132 171 $current_ignorelist = wp_optimize_minify_config()->get('ignore_list');
133 172
134 - // Only proceed if the the upgrade hasn't been done yet, i.e. the values aren't arrays
173 + // Only proceed if the upgrade hasn't been done yet, i.e. the values aren't arrays
135 174 if (is_array($current_blacklist) && is_array($current_ignorelist)) return;
136 175
137 176 $current_blacklist = array_map('trim', explode("\n", $current_blacklist));
138 177 $current_ignorelist = array_map('trim', explode("\n", $current_ignorelist));
@@ -159,9 +198,9 @@
159 198 * Checks if it's a new installation of the plugin, as opposed to being updated.
160 199 *
161 200 * @return bool
162 201 */
163 - public static function is_new_install() {
202 + private static function is_new_install() {
164 203 $db_version = get_option('wpo_update_version');
165 204 return !$db_version;
166 205 }
167 206
@@ -167,9 +206,9 @@
167 206
168 207 /**
169 208 * Modifies the cache configuration for Windows OS by regenerating the 'uploads' path.
170 209 */
171 - public static function update_3214_modify_cache_config_in_windows() {
210 + private static function update_3214_modify_cache_config_in_windows() {
172 211
173 212 // Check if the OS is Windows and it's not a new installation.
174 213 if ('WIN' !== strtoupper(substr(PHP_OS, 0, 3)) || self::is_new_install()) {
175 214 return;
@@ -239,8 +278,186 @@
239 278 $cache_enabled = $config['enable_page_caching'];
240 279 if ($cache_enabled) {
241 280 WPO_Cache_Config::instance()->update($config);
242 281 }
282 + }
283 +
284 + /**
285 + * Update async loading exclusion UA list
286 + */
287 + private static function update_330_ua_async_exclusion_list() {
288 + if (self::is_new_install()) return;
289 +
290 + $config = wp_optimize_minify_config();
291 + $defaults = $config->get_defaults();
292 + $new_list = $defaults['ualist'];
293 +
294 + $config->update(array(
295 + 'ualist' => $new_list
296 + ));
297 + }
298 +
299 + /**
300 + * Move existing smush log content in old path (uploads/smush-*) to new path (uploads/wpo/logs/smush-*)
301 + */
302 + private static function update_350_move_content_of_existing_smush_logs_to_new_location() {
303 + if (self::is_new_install()) return;
304 +
305 + $upload_base = WP_Optimize_Utils::get_base_upload_dir();
306 +
307 + $old_file = $upload_base . 'smush-' . substr(md5(wp_salt()), 0, 20) . '.log';
308 + $new_file = WP_Optimize_Utils::get_log_file_path('smush');
309 +
310 + // Check if only old file exists, if new file exists no need to overwrite its content
311 + if (is_file($old_file) && !is_file($new_file)) {
312 + $old_file_content = file_get_contents($old_file);
313 + file_put_contents($new_file, $old_file_content);
314 + }
315 +
316 + // Delete all smush log files in the old path (uploads/smush-*)
317 + if (!function_exists('glob')) return;
318 + $files = glob($upload_base . 'smush-*.log');
319 + if (false === $files) return;
320 + foreach ($files as $file) {
321 + if (is_file($file)) {
322 + wp_delete_file($file);
323 + }
324 + }
325 + }
326 +
327 + /**
328 + * Delete wpo-plugins-tables-list.json file from old location and regenerate in new location
329 + */
330 + private static function update_350_delete_plugin_table_list_regenerate_in_new_location() {
331 + if (self::is_new_install()) return;
332 +
333 + // JSON file was moved to /wpo/ subfolder. Delete old files.
334 + $upload_base = WP_Optimize_Utils::get_base_upload_dir();
335 +
336 + $old_file = $upload_base . 'wpo-plugins-tables-list.json';
337 + if (is_file($old_file)) {
338 + wp_delete_file($old_file);
339 + }
340 + // JSON file not present in the new location, regenerate it
341 + $new_file = $upload_base . 'wpo/wpo-plugins-tables-list.json';
342 + if (!is_file($new_file)) {
343 + WP_Optimize()->get_db_info()->update_plugin_json();
344 + }
345 + }
346 +
347 + /**
348 + * Disable auto preloading after purge feature for existing users
349 + */
350 + private static function update_370_disable_auto_preload_after_purge_feature() {
351 + if (self::is_new_install()) return;
352 + $config = WPO_Cache_Config::instance()->get();
353 + $cache_enabled = $config['enable_page_caching'];
354 + if ($cache_enabled) {
355 + $config['auto_preload_purged_contents'] = false;
356 + WPO_Cache_Config::instance()->update($config);
357 + }
358 + }
359 +
360 + /**
361 + * Iterate over plugin utils tables creation, using WP_Optimize_Table_Management
362 + */
363 + private static function update_380_404_detector_table_create() {
364 + if (self::is_new_install()) return;
365 + WP_Optimize()->get_table_management()->create_plugin_tables();
366 + }
367 +
368 + /**
369 + * Wipe WPO_DB_Table_Analysis usage data
370 + */
371 + private static function update_431_db_table_analysis_wipe_usage_data() {
372 + if (self::is_new_install()) return;
373 +
374 + if (class_exists('WPO_DB_Table_Analysis')) {
375 + WPO_DB_Table_Analysis::wipe_usage_data();
376 + }
377 + }
378 +
379 + /**
380 + * Change permission for wpo-plugins-tables-list.json file
381 + */
382 + private static function update_440_change_plugin_json_permissions() {
383 + if (self::is_new_install()) return;
384 +
385 + WP_Optimize()->get_db_info()->change_plugin_json_permissions();
386 + }
387 +
388 + /**
389 + * Prefix WPO specific post meta keys with `_` to make it private.
390 + */
391 + private static function update_461_update_post_meta_keys() {
392 + if (self::is_new_install()) return;
393 +
394 + $keys_to_convert = array(
395 + 'smush-complete',
396 + 'smush-marked',
397 + 'smush-info',
398 + 'smush-stats',
399 + 'original-file',
400 + 'wpo-webp-conversion-complete',
401 + );
402 +
403 + if (is_multisite()) {
404 + $sites = WP_Optimize()->get_sites();
405 + foreach ($sites as $site) {
406 + $blog_id = $site->blog_id;
407 + switch_to_blog($blog_id);
408 + self::update_461_convert_post_meta_keys($keys_to_convert);
409 + restore_current_blog();
410 + }
411 + } else {
412 + self::update_461_convert_post_meta_keys($keys_to_convert);
413 + }
414 +
415 + }
416 +
417 + /**
418 + * Perform the post meta key renaming for the current blog.
419 + *
420 + * @param array $keys_to_convert List of meta keys to prefix.
421 + */
422 + private static function update_461_convert_post_meta_keys(array $keys_to_convert) {
423 + global $wpdb;
424 +
425 + foreach ($keys_to_convert as $old_key) {
426 + if ('wpo-webp-conversion-complete' !== $old_key) {
427 + $new_key = '_wpo-' . $old_key;
428 + } else {
429 + $new_key = '_' . $old_key;
430 + }
431 +
432 + $result = $wpdb->query($wpdb->prepare(
433 + "UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s",
434 + $new_key,
435 + $old_key
436 + ));
437 +
438 + if (false === $result) {
439 + WP_Optimize()->log(
440 + sprintf(
441 + 'Update 4.6.1: Failed to rename post meta key "%s" to "%s" on blog %d. DB error: %s',
442 + $old_key,
443 + $new_key,
444 + get_current_blog_id(),
445 + $wpdb->last_error
446 + )
447 + );
448 + }
449 + }
450 + }
451 +
452 + /**
453 + * Update the browser cache htaccess config due to updated rules.
454 + */
455 + private static function update_470_update_browser_cache_htaccess_config() {
456 + if (self::is_new_install()) return;
457 + if (!WP_Optimize()->get_options()->get_option('enable_browser_cache')) return;
458 +
459 + WP_Optimize()->get_browser_cache()->restore();
243 460 }
244 461 }
245 462
246 463 endif;