| 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 |
WP_Optimize()->get_gzip_compression()->disable(); |
| 13 |
WP_Optimize()->get_browser_cache()->disable(); |
| 14 |
WP_Optimize()->get_options()->delete_all_options(); |
| 15 |
WP_Optimize()->get_minify()->plugin_uninstall(); |
| 16 |
WP_Optimize()->get_options()->wipe_settings(); |
| 17 |
WP_Optimize()->delete_transients_and_semaphores(); |
| 18 |
// Using Updraft_Smush_Manager() throws `Call to undefined function` fatal error |
| 19 |
Updraft_Smush_Manager::instance()->delete_log_files(); |
| 20 |
Updraft_Tasks_Activation::uninstall(WPO_PLUGIN_SLUG); |
| 21 |
self::delete_wpo_folder(); |
| 22 |
|
| 23 |
$wpo_plugins_table_list = self::get_upload_basedir() . 'wpo-plugins-tables-list.json'; |
| 24 |
if (is_file($wpo_plugins_table_list)) { |
| 25 |
unlink($wpo_plugins_table_list); |
| 26 |
} |
| 27 |
|
| 28 |
$htaccess_file = self::get_upload_basedir() . '.htaccess'; |
| 29 |
if (is_file($htaccess_file) && 0 === filesize($htaccess_file)) { |
| 30 |
unlink($htaccess_file); |
| 31 |
} |
| 32 |
|
| 33 |
wp_clear_scheduled_hook('process_smush_tasks'); |
| 34 |
WP_Optimize()->wpo_cron_deactivate(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Returns absolute path to uploads folder |
| 39 |
* |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
private static function get_upload_basedir() { |
| 43 |
$upload_dir = wp_get_upload_dir(); |
| 44 |
return trailingslashit($upload_dir['basedir']); |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Returns an array of sub folders in `uploads/wpo` folder |
| 49 |
* |
| 50 |
* @return array |
| 51 |
*/ |
| 52 |
private static function get_wpo_sub_folders() { |
| 53 |
$sub_folders = array( |
| 54 |
'add-type', |
| 55 |
'content-digest', |
| 56 |
'crash-tester', |
| 57 |
'directory-index', |
| 58 |
'header-set', |
| 59 |
'images', |
| 60 |
'module-loaded', |
| 61 |
'rewrite', |
| 62 |
'server-signature', |
| 63 |
'logs', |
| 64 |
); |
| 65 |
return apply_filters('wpo_uploads_sub_folders', $sub_folders); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Delete `uploads/wpo` sub folders and if it is empty delete the folder itself |
| 70 |
*/ |
| 71 |
public static function delete_wpo_folder() { |
| 72 |
$wpo_folder = self::get_upload_basedir() . trailingslashit('wpo'); |
| 73 |
require_once WPO_PLUGIN_MAIN_PATH . 'cache/file-based-page-cache-functions.php'; |
| 74 |
if (is_dir($wpo_folder)) { |
| 75 |
$wpo_sub_folders = self::get_wpo_sub_folders(); |
| 76 |
foreach ($wpo_sub_folders as $folder) { |
| 77 |
wpo_delete_files($wpo_folder . $folder); |
| 78 |
} |
| 79 |
|
| 80 |
$files = @scandir($wpo_folder); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- suppress warning if it arises due to race condition |
| 81 |
if (false === $files) return; |
| 82 |
if (2 === count($files)) { |
| 83 |
@rmdir($wpo_folder); // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- suppress error due to file permission issues |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
endif; |
| 90 |
|