| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 3.1.7 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | 8 | * @copyright Copyright © 2026 FirePlugins All Rights Reserved |
| @@ -21,13 +21,78 @@ | ||
| 21 | 21 | class PluginUninstall extends \Uninstall |
| 22 | 22 | { |
| 23 | 23 | /** |
| 24 | 24 | * Runs once we uninstall the plugin. |
| 25 | - * | |
| 25 | + * | |
| 26 | + * The uninstall hook fires once for the whole network, so on multisite this | |
| 27 | + * walks every site — each holds its own tables, campaigns, options and | |
| 28 | + * uploads — and applies the network's decision to all of them. | |
| 29 | + * | |
| 26 | 30 | * @return void |
| 27 | 31 | */ |
| 28 | 32 | public function start() |
| 29 | 33 | { |
| 34 | + if (!is_multisite()) | |
| 35 | + { | |
| 36 | + $this->uninstallCurrentSite(); | |
| 37 | + | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * One decision for the network, taken from its main site. | |
| 43 | + * | |
| 44 | + * Only a network administrator can delete a network plugin, and there | |
| 45 | + * is no screen where they can answer this for each site. Reading it per | |
| 46 | + * site sounds fairer but does not work: the setting defaults to keeping | |
| 47 | + * data, so every site that never changed it would hold on to its tables | |
| 48 | + * and the delete would leave the network littered with them. | |
| 49 | + */ | |
| 50 | + $keep_data = $this->networkKeepsData(); | |
| 51 | + | |
| 52 | + wp_raise_memory_limit('admin'); | |
| 53 | + | |
| 54 | + foreach (get_sites(['fields' => 'ids', 'number' => 0]) as $site_id) | |
| 55 | + { | |
| 56 | + /** | |
| 57 | + * Give each site its own slice of the clock rather than letting the | |
| 58 | + * whole network share one. Without this a large network walks into | |
| 59 | + * max_execution_time part way through; with it, only a single | |
| 60 | + * pathological site can. | |
| 61 | + * | |
| 62 | + * The loop is resumable either way — a site that finished no longer | |
| 63 | + * has firebox_settings, so uninstallCurrentSite() returns straight | |
| 64 | + * away and a retry carries on where this left off. | |
| 65 | + */ | |
| 66 | + if (function_exists('set_time_limit')) | |
| 67 | + { | |
| 68 | + @set_time_limit(30); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 69 | + } | |
| 70 | + | |
| 71 | + switch_to_blog($site_id); | |
| 72 | + $this->uninstallCurrentSite($keep_data); | |
| 73 | + restore_current_blog(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + $this->deleteNetworkOptions(); | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Removes FireBox from the current site. | |
| 81 | + * | |
| 82 | + * Safe to call while switched: the framework resolves the table prefix from | |
| 83 | + * the current site, and every option read below is a site option. | |
| 84 | + * | |
| 85 | + * @param bool|null $keep_data Whether to keep this site's data. Null | |
| 86 | + * reads the site's own setting, which is | |
| 87 | + * what a single site does. | |
| 88 | + * | |
| 89 | + * @return void | |
| 90 | + */ | |
| 91 | + public function uninstallCurrentSite($keep_data = null) | |
| 92 | + { | |
| 93 | + // No settings means FireBox was never set up here — nothing of ours to | |
| 94 | + // remove, and nothing to read a decision from. | |
| 30 | 95 | if (!$settings = get_option('firebox_settings')) |
| 31 | 96 | { |
| 32 | 97 | return; |
| 33 | 98 | } |
| @@ -34,11 +99,19 @@ | ||
| 34 | 99 | |
| 35 | 100 | // Disable usage tracking |
| 36 | 101 | $tracking = new \FireBox\Core\UsageTracking\SendUsage(); |
| 37 | 102 | $tracking->stop(); |
| 38 | - | |
| 39 | - if (isset($settings['keep_data_on_uninstall']) && $settings['keep_data_on_uninstall'] == '1') | |
| 103 | + | |
| 104 | + // Unschedule the log retention cleanup cron | |
| 105 | + \FireBox\Core\FB\Log::unscheduleCleanup(); | |
| 106 | + | |
| 107 | + if ($keep_data === null) | |
| 40 | 108 | { |
| 109 | + $keep_data = isset($settings['keep_data_on_uninstall']) && $settings['keep_data_on_uninstall'] == '1'; | |
| 110 | + } | |
| 111 | + | |
| 112 | + if ($keep_data) | |
| 113 | + { | |
| 41 | 114 | return; |
| 42 | 115 | } |
| 43 | 116 | |
| 44 | 117 | require_once FBOX_PLUGIN_DIR . 'Inc/Framework/Inc/Helpers/Directory.php'; |
| @@ -43,17 +116,16 @@ | ||
| 43 | 116 | |
| 44 | 117 | require_once FBOX_PLUGIN_DIR . 'Inc/Framework/Inc/Helpers/Directory.php'; |
| 45 | 118 | require_once FBOX_PLUGIN_DIR . 'Inc/Framework/Inc/Helpers/WPHelper.php'; |
| 46 | 119 | |
| 47 | - // remove all db tables | |
| 48 | - $this->pluginUninstall(); | |
| 49 | - | |
| 50 | - $this->removeCapabilities(); | |
| 51 | - | |
| 52 | - // de-register post type | |
| 53 | - unregister_post_type('firebox'); | |
| 54 | - | |
| 55 | - // remove all custom post types data | |
| 120 | + /** | |
| 121 | + * Campaigns go first, while the tables are still there. | |
| 122 | + * | |
| 123 | + * Deleting one fires delete_post, and our handler clears that campaign's | |
| 124 | + * logs and submissions. Dropping the tables first leaves that handler | |
| 125 | + * querying tables that no longer exist, which fills debug.log with | |
| 126 | + * database errors on every uninstall. | |
| 127 | + */ | |
| 56 | 128 | $items = get_posts(['post_type' => 'firebox', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids']); |
| 57 | 129 | |
| 58 | 130 | if ($items) |
| 59 | 131 | { |
| @@ -62,8 +134,16 @@ | ||
| 62 | 134 | wp_delete_post($item, true); |
| 63 | 135 | } |
| 64 | 136 | } |
| 65 | 137 | |
| 138 | + // remove all db tables | |
| 139 | + $this->pluginUninstall(); | |
| 140 | + | |
| 141 | + $this->removeCapabilities(); | |
| 142 | + | |
| 143 | + // de-register post type | |
| 144 | + unregister_post_type('firebox'); | |
| 145 | + | |
| 66 | 146 | // remove all options |
| 67 | 147 | delete_option('firebox_version'); |
| 68 | 148 | delete_option('firebox_settings'); |
| 69 | 149 | delete_option('firebox_import'); |
| @@ -70,10 +150,12 @@ | ||
| 70 | 150 | delete_option('firebox_license_status'); |
| 71 | 151 | delete_option('firebox_license_key'); |
| 72 | 152 | |
| 73 | 153 | |
| 74 | - // Remove onboarding data | |
| 75 | - $this->removeOnboardingData(); | |
| 154 | + delete_option('firebox_session_conditions_in_use'); | |
| 155 | + delete_option('firebox_boxes_cache'); | |
| 156 | + delete_option('firebox_onboarding_completed'); | |
| 157 | + delete_option('firebox_activation_redirect'); | |
| 76 | 158 | |
| 77 | 159 | // Remove first campaign timing data |
| 78 | 160 | delete_option('firebox_first_campaign_tracking_started_at'); |
| 79 | 161 | delete_option('firebox_time_to_first_campaign_draft_seconds'); |
| @@ -82,8 +164,43 @@ | ||
| 82 | 164 | // Delete /wp-content/uploads/firebox directory |
| 83 | 165 | \FPFramework\Helpers\Directory::delete(\FPFramework\Helpers\WPHelper::getPluginUploadsDirectory('firebox')); |
| 84 | 166 | } |
| 85 | 167 | |
| 168 | + /** | |
| 169 | + * Whether the network is keeping its data. | |
| 170 | + * | |
| 171 | + * Read from the main site, which is the network's own copy of the setting. | |
| 172 | + * Defaults to keeping it when there is nothing to read. | |
| 173 | + * | |
| 174 | + * @return bool | |
| 175 | + */ | |
| 176 | + private function networkKeepsData() | |
| 177 | + { | |
| 178 | + switch_to_blog(get_main_site_id()); | |
| 179 | + $settings = get_option('firebox_settings'); | |
| 180 | + restore_current_blog(); | |
| 181 | + | |
| 182 | + if (!is_array($settings) || !isset($settings['keep_data_on_uninstall'])) | |
| 183 | + { | |
| 184 | + return true; | |
| 185 | + } | |
| 186 | + | |
| 187 | + return $settings['keep_data_on_uninstall'] == '1'; | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 191 | + * Removes the options FireBox keeps at network level. | |
| 192 | + * | |
| 193 | + * @return void | |
| 194 | + */ | |
| 195 | + private function deleteNetworkOptions() | |
| 196 | + { | |
| 197 | + delete_site_option('firebox_license_key'); | |
| 198 | + delete_site_option('firebox_license_status'); | |
| 199 | + delete_site_option('firebox_network_install_offset'); | |
| 200 | + delete_site_option('firebox_usage_tracking_site'); | |
| 201 | + } | |
| 202 | + | |
| 86 | 203 | private function removeCapabilities() |
| 87 | 204 | { |
| 88 | 205 | $capabilities = \FireBox\Core\Admin\Capabilities::getCapabilities(); |
| 89 | 206 | |
| @@ -99,18 +216,6 @@ | ||
| 99 | 216 | $role->remove_cap($cap); |
| 100 | 217 | } |
| 101 | 218 | } |
| 102 | 219 | } |
| 103 | - } | |
| 104 | - | |
| 105 | - /** | |
| 106 | - * Remove all onboarding-related options | |
| 107 | - * | |
| 108 | - * @return void | |
| 109 | - */ | |
| 110 | - private function removeOnboardingData() | |
| 111 | - { | |
| 112 | - // Remove site-wide onboarding options | |
| 113 | - delete_option('firebox_onboarding_completed'); | |
| 114 | - delete_option('firebox_activation_redirect'); | |
| 115 | 220 | } |
| 116 | 221 | } |