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 +172 -23 3.5.0 → 4.7.0 View file →
@@ -35,14 +35,28 @@
35 35 '3.5.0' => array(
36 36 'update_350_move_content_of_existing_smush_logs_to_new_location',
37 37 'update_350_delete_plugin_table_list_regenerate_in_new_location',
38 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 + ),
39 53 );
40 54
41 55 /**
42 56 * See if any database schema updates are needed, and perform them if so.
43 57 * Example Usage:
44 - * public static function update_101_add_new_column() {
58 + * private static function update_101_add_new_column() {
45 59 * $wpdb = $GLOBALS['wpdb'];
46 60 * $wpdb->query('ALTER TABLE tm_tasks ADD task_expiry varchar(300) AFTER id');
47 61 * }
48 62 */
@@ -58,37 +72,58 @@
58 72 }
59 73 }
60 74 update_option('wpo_update_version', WPO_VERSION);
61 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 + }
62 90 }
63 91
64 92 /**
65 93 * Delete old semaphore locks from options database table.
66 94 */
67 - public static function delete_old_locks() {
95 + private static function delete_old_locks() {
68 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'));";
69 106
70 - // using this query we delete all rows related to locks.
71 - $query = "DELETE FROM {$wpdb->options}".
72 - " WHERE (option_name LIKE ('updraft_semaphore_%')".
73 - " OR option_name LIKE ('updraft_last_lock_time_%')".
74 - " OR option_name LIKE ('updraft_locked_%')".
75 - " OR option_name LIKE ('updraft_unlocked_%'))".
76 - " AND ".
77 - "(option_name LIKE ('%smush')".
78 - " OR option_name LIKE ('%load-url-task'));";
107 + $wpdb->query($query); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Already prepared query, uses only hardcoded strings
79 108
80 - $wpdb->query($query);
81 109 }
82 110
83 111 /**
84 112 * Disable cache directories viewing.
85 113 */
86 - 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 + }
87 122 wpo_disable_cache_directories_viewing();
88 123 }
89 -
90 - public static function reset_wpo_plugin_cron_tasks_schedule() {
124 +
125 + private static function reset_wpo_plugin_cron_tasks_schedule() {
91 126 wp_clear_scheduled_hook('wpo_plugin_cron_tasks');
92 127 }
93 128
94 129 /**
@@ -95,9 +130,9 @@
95 130 * Update Minify Defer option (The option was hidden until now, but we're changing the setting)
96 131 *
97 132 * @return void
98 133 */
99 - public static function enable_minify_defer() {
134 + private static function enable_minify_defer() {
100 135 if (!function_exists('wp_optimize_minify_config')) {
101 136 include_once WPO_PLUGIN_MAIN_PATH . 'minify/class-wp-optimize-minify-config.php';
102 137 }
103 138 $current_setting = wp_optimize_minify_config()->get('enable_defer_js');
@@ -112,10 +147,9 @@
112 147 * Update Minify default exclude options
113 148 *
114 149 * @return void
115 150 */
116 - public static function update_minify_excludes() {
117 - if (!WPO_MINIFY_PHP_VERSION_MET) return;
151 + private static function update_minify_excludes() {
118 152 if (!function_exists('wp_optimize_minify_config')) {
119 153 include_once WPO_PLUGIN_MAIN_PATH . 'minify/class-wp-optimize-minify-config.php';
120 154 }
121 155
@@ -135,9 +169,9 @@
135 169 // Get the lists as saved in the DB
136 170 $current_blacklist = wp_optimize_minify_config()->get('blacklist');
137 171 $current_ignorelist = wp_optimize_minify_config()->get('ignore_list');
138 172
139 - // 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
140 174 if (is_array($current_blacklist) && is_array($current_ignorelist)) return;
141 175
142 176 $current_blacklist = array_map('trim', explode("\n", $current_blacklist));
143 177 $current_ignorelist = array_map('trim', explode("\n", $current_ignorelist));
@@ -164,9 +198,9 @@
164 198 * Checks if it's a new installation of the plugin, as opposed to being updated.
165 199 *
166 200 * @return bool
167 201 */
168 - public static function is_new_install() {
202 + private static function is_new_install() {
169 203 $db_version = get_option('wpo_update_version');
170 204 return !$db_version;
171 205 }
172 206
@@ -172,9 +206,9 @@
172 206
173 207 /**
174 208 * Modifies the cache configuration for Windows OS by regenerating the 'uploads' path.
175 209 */
176 - public static function update_3214_modify_cache_config_in_windows() {
210 + private static function update_3214_modify_cache_config_in_windows() {
177 211
178 212 // Check if the OS is Windows and it's not a new installation.
179 213 if ('WIN' !== strtoupper(substr(PHP_OS, 0, 3)) || self::is_new_install()) {
180 214 return;
@@ -284,9 +318,9 @@
284 318 $files = glob($upload_base . 'smush-*.log');
285 319 if (false === $files) return;
286 320 foreach ($files as $file) {
287 321 if (is_file($file)) {
288 - @unlink($file); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- suppress error due to file permission issues
322 + wp_delete_file($file);
289 323 }
290 324 }
291 325 }
292 326
@@ -300,9 +334,9 @@
300 334 $upload_base = WP_Optimize_Utils::get_base_upload_dir();
301 335
302 336 $old_file = $upload_base . 'wpo-plugins-tables-list.json';
303 337 if (is_file($old_file)) {
304 - @unlink($old_file); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- suppress error due to file permission issues
338 + wp_delete_file($old_file);
305 339 }
306 340 // JSON file not present in the new location, regenerate it
307 341 $new_file = $upload_base . 'wpo/wpo-plugins-tables-list.json';
308 342 if (!is_file($new_file)) {
@@ -307,8 +341,123 @@
307 341 $new_file = $upload_base . 'wpo/wpo-plugins-tables-list.json';
308 342 if (!is_file($new_file)) {
309 343 WP_Optimize()->get_db_info()->update_plugin_json();
310 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();
311 460 }
312 461 }
313 462
314 463 endif;