PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.5.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.5.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 / includes / class-wpo-uninstall.php

class-wpo-uninstall.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.5.3, at includes/class-wpo-uninstall.php

139 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) die('Access denied.');
3
4 if (!class_exists('WPO_Uninstall')) :
5
6 class WPO_Uninstall {
7
8 /**
9 * Actions to be performed upon plugin uninstallation
10 */
11 public static function actions() {
12 $is_premium_active = WP_Optimize()->is_active('premium');
13 $is_free_active = WP_Optimize()->is_active();
14
15 if (!$is_premium_active) {
16 self::delete_premium_cache_data();
17 }
18
19 if ($is_premium_active || $is_free_active) {
20 return;
21 }
22
23 WP_Optimize()->get_gzip_compression()->disable();
24 WP_Optimize()->get_browser_cache()->disable();
25 WP_Optimize()->get_options()->delete_all_options();
26 WP_Optimize()->get_minify()->plugin_uninstall();
27 WP_Optimize()->get_options()->wipe_settings();
28 WP_Optimize()->delete_transients_and_semaphores();
29 WP_Optimize()->get_table_management()->delete_plugin_tables();
30 Updraft_Tasks_Activation::uninstall(WPO_PLUGIN_SLUG);
31 self::delete_wpo_folder();
32
33 $htaccess_file = self::get_upload_basedir() . '.htaccess';
34 if (is_file($htaccess_file) && 0 === filesize($htaccess_file)) {
35 wp_delete_file($htaccess_file);
36 }
37
38 wp_clear_scheduled_hook('process_smush_tasks');
39 WP_Optimize()->wpo_cron_deactivate();
40 }
41
42 /**
43 * Delete cache data created by premium-only features.
44 *
45 * Only runs when premium is not active, to avoid wiping premium data
46 * while the premium version is still installed.
47 */
48 private static function delete_premium_cache_data() {
49 if (class_exists('WPO_Gravatar_Data')) {
50 wpo_delete_files(WPO_Gravatar_Data::WPO_CACHE_GRAVATAR_DIR);
51 }
52
53 if (class_exists('WP_Optimize_Minify_Analytics')) {
54 wpo_delete_files(WP_Optimize_Minify_Analytics::WPO_CACHE_GTAG_DIR);
55 }
56
57 if (class_exists('WP_Optimize_Lazy_Load')) {
58 WP_Optimize_Lazy_Load::instance()->delete_image_cache();
59 }
60 }
61
62 /**
63 * Returns absolute path to uploads folder
64 *
65 * @return string
66 */
67 private static function get_upload_basedir() {
68 $upload_dir = wp_get_upload_dir();
69 return trailingslashit($upload_dir['basedir']);
70 }
71
72 /**
73 * Returns an array of sub folders in `uploads/wpo` folder
74 *
75 * @return array
76 */
77 private static function get_wpo_sub_folders() {
78 $sub_folders = array(
79 'add-type',
80 'content-digest',
81 'crash-tester',
82 'directory-index',
83 'header-set',
84 'images',
85 'module-loaded',
86 'rewrite',
87 'server-signature',
88 'logs',
89 );
90 $filtered_sub_folders = apply_filters('wpo_uploads_sub_folders', $sub_folders);
91 return is_array($filtered_sub_folders) ? $filtered_sub_folders : $sub_folders;
92 }
93
94 /**
95 * Returns an array of known files in `uploads/wpo` root folder
96 *
97 * @return array
98 */
99 private static function get_wpo_root_files() {
100 return array(
101 'wpo-plugins-tables-list.json'
102 );
103 }
104
105 /**
106 * Delete `uploads/wpo` folder, its known sub folders, and known files
107 */
108 public static function delete_wpo_folder() {
109 $wpo_folder = self::get_upload_basedir() . trailingslashit('wpo');
110 require_once WPO_PLUGIN_MAIN_PATH . 'cache/file-based-page-cache-functions.php';
111
112 if (!is_dir($wpo_folder)) {
113 return;
114 }
115
116 $wpo_sub_folders = self::get_wpo_sub_folders();
117 foreach ($wpo_sub_folders as $folder) {
118 wpo_delete_files($wpo_folder . $folder);
119 }
120
121 // Delete known root-level files
122 $wpo_root_files = self::get_wpo_root_files();
123 foreach ($wpo_root_files as $file) {
124 wpo_delete_files($wpo_folder . $file, false);
125 }
126
127 // phpcs:disable
128 // Generic.PHP.NoSilencedErrors.Discouraged -- suppress warning if it arises due to race condition
129 // WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- Not applicable in this context
130 $files = @scandir($wpo_folder);
131 if (false !== $files && 2 === count($files)) {
132 @rmdir($wpo_folder);
133 }
134 // phpcs:enable
135 }
136 }
137
138 endif;
139