duplicator
Last commit date
assets
10 months ago
classes
10 months ago
ctrls
10 months ago
installer
10 months ago
languages
10 months ago
lib
10 months ago
src
10 months ago
template
10 months ago
vendor
10 months ago
views
10 months ago
deactivation.php
10 months ago
define.php
10 months ago
duplicator-main.php
10 months ago
duplicator.php
10 months ago
helper.php
10 months ago
readme.txt
10 months ago
uninstall.php
10 months ago
uninstall.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Fired when the plugin is uninstalled. |
| 5 | * |
| 6 | * Maintain PHP 5.2 compatibility, don't use namespace and don't include Duplicator Libs |
| 7 | */ |
| 8 | |
| 9 | // If uninstall not called from WordPress, then exit |
| 10 | if (!defined('WP_UNINSTALL_PLUGIN')) { |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Uninstall class |
| 16 | * Maintain PHP 5.2 compatibility, don't use namespace and don't include Duplicator Libs. |
| 17 | * This is a standalone class. |
| 18 | */ |
| 19 | class DuplicatorLiteUninstall // phpcs:ignore |
| 20 | { |
| 21 | const PACKAGES_TABLE_NAME = 'duplicator_packages'; |
| 22 | const VERSION_OPTION_KEY = 'duplicator_version_plugin'; |
| 23 | const UNINSTALL_PACKAGE_OPTION_KEY = 'duplicator_uninstall_package'; |
| 24 | const UNINSTALL_SETTINGS_OPTION_KEY = 'duplicator_uninstall_settings'; |
| 25 | const SSDIR_NAME_LEGACY = 'wp-snapshots'; |
| 26 | const SSDIR_NAME_NEW = 'backups-dup-lite'; |
| 27 | |
| 28 | /** |
| 29 | * Uninstall plugin |
| 30 | * |
| 31 | * @return void |
| 32 | */ |
| 33 | public static function uninstall() |
| 34 | { |
| 35 | try { |
| 36 | do_action('duplicator_unistall'); |
| 37 | self::removePackages(); |
| 38 | self::removeSettings(); |
| 39 | self::removePluginVersion(); |
| 40 | } catch (Exception $e) { |
| 41 | // Prevent error on uninstall |
| 42 | } catch (Error $e) { |
| 43 | // Prevent error on uninstall |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Remove plugin option version |
| 49 | * |
| 50 | * @return void |
| 51 | */ |
| 52 | private static function removePluginVersion() |
| 53 | { |
| 54 | delete_option(self::VERSION_OPTION_KEY); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Return duplicator PRO backup path legacy |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | private static function getSsdirPathLegacy() |
| 63 | { |
| 64 | return trailingslashit(wp_normalize_path(realpath(ABSPATH))) . self::SSDIR_NAME_LEGACY; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Return duplicator PRO backup path |
| 69 | * |
| 70 | * @return string |
| 71 | */ |
| 72 | private static function getSsdirPathWpCont() |
| 73 | { |
| 74 | return trailingslashit(wp_normalize_path(realpath(WP_CONTENT_DIR))) . self::SSDIR_NAME_NEW; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Remove all packages |
| 79 | * |
| 80 | * @return void |
| 81 | */ |
| 82 | private static function removePackages() |
| 83 | { |
| 84 | global $wpdb; |
| 85 | |
| 86 | if (get_option(self::UNINSTALL_PACKAGE_OPTION_KEY) != true) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | $tableName = esc_sql($wpdb->base_prefix . self::PACKAGES_TABLE_NAME); |
| 91 | $wpdb->query("DROP TABLE IF EXISTS {$tableName}"); |
| 92 | |
| 93 | $fsystem = new WP_Filesystem_Direct(true); |
| 94 | $fsystem->rmdir(self::getSsdirPathWpCont(), true); |
| 95 | $fsystem->rmdir(self::getSsdirPathLegacy(), true); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Remove plugins settings |
| 100 | * |
| 101 | * @return void |
| 102 | */ |
| 103 | private static function removeSettings() |
| 104 | { |
| 105 | if (get_option(self::UNINSTALL_SETTINGS_OPTION_KEY) != true) { |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | self::deleteUserMetaKeys(); |
| 110 | self::deleteOptions(); |
| 111 | self::deleteTransients(); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Delete all users meta key |
| 116 | * |
| 117 | * @return void |
| 118 | */ |
| 119 | private static function deleteUserMetaKeys() |
| 120 | { |
| 121 | /** @var wpdb */ |
| 122 | global $wpdb; |
| 123 | |
| 124 | $wpdb->query("DELETE FROM `{$wpdb->usermeta}` WHERE meta_key REGEXP '^duplicator_(?!pro_)'"); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Delete all options |
| 129 | * |
| 130 | * @return void |
| 131 | */ |
| 132 | private static function deleteOptions() |
| 133 | { |
| 134 | /** @var wpdb */ |
| 135 | global $wpdb; |
| 136 | |
| 137 | $optionsTableName = esc_sql($wpdb->base_prefix . "options"); |
| 138 | $dupOptionNames = $wpdb->get_col( |
| 139 | "SELECT `option_name` FROM `{$optionsTableName}` WHERE `option_name` REGEXP '^duplicator_(?!pro_)'" |
| 140 | ); |
| 141 | |
| 142 | foreach ($dupOptionNames as $dupOptionName) { |
| 143 | delete_option($dupOptionName); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Delete all transients |
| 149 | * |
| 150 | * @return void |
| 151 | */ |
| 152 | private static function deleteTransients() |
| 153 | { |
| 154 | global $wpdb; |
| 155 | |
| 156 | $optionsTableName = esc_sql($wpdb->base_prefix . "options"); |
| 157 | $dupOptionTransientNames = $wpdb->get_col( |
| 158 | "SELECT `option_name` FROM `{$optionsTableName}` WHERE `option_name` REGEXP '^_transient_duplicator_(?!pro_)'" |
| 159 | ); |
| 160 | |
| 161 | foreach ($dupOptionTransientNames as $dupOptionTransientName) { |
| 162 | delete_transient(str_replace("_transient_", "", $dupOptionTransientName)); |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | DuplicatorLiteUninstall::uninstall(); |
| 168 |