PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.6
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.6
2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 2.9.4 2.9.3 All 86 releases
vigilante / uninstall.php

uninstall.php in Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… 2.11.6, at uninstall.php

304 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall Vigilante AyudaWP
4 *
5 * This file runs when the plugin is deleted via WordPress admin.
6 * It removes all plugin data including database tables and options.
7 *
8 * On a network it visits every site: tables, options, transients and cron
9 * events are per site, so cleaning only the site that runs the uninstall
10 * left everything else behind until 2.11.0 (S13 of the 28 Aug 2026 audit).
11 *
12 * @package Vigilante
13 */
14
15 // Exit if not called by WordPress
16 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
17 exit;
18 }
19
20 // Load required files
21 require_once plugin_dir_path( __FILE__ ) . 'includes/class-settings.php';
22 require_once plugin_dir_path( __FILE__ ) . 'includes/class-database.php';
23 require_once plugin_dir_path( __FILE__ ) . 'includes/class-backup-manager.php';
24 require_once plugin_dir_path( __FILE__ ) . 'includes/class-deactivator.php';
25
26 // Define constants if not already defined
27 if ( ! defined( 'VIGILANTE_BACKUP_DIR' ) ) {
28 define( 'VIGILANTE_BACKUP_DIR', WP_CONTENT_DIR . '/vigilante-backups/' );
29 }
30
31 /**
32 * Uninstall function
33 */
34 function vigilante_uninstall() {
35 global $wpdb;
36
37 /*
38 * Per-site data. switch_to_blog() repoints $wpdb->prefix, $wpdb->options
39 * and the cron option, so the same routine serves every site of a network.
40 * 'number' => 0 lifts the default cap of 100 sites: an uninstall that
41 * cleaned the first hundred sites and left the rest would be the same bug
42 * with a bigger threshold.
43 */
44 if ( is_multisite() ) {
45 $site_ids = get_sites(
46 array(
47 'fields' => 'ids',
48 'number' => 0,
49 )
50 );
51
52 foreach ( $site_ids as $site_id ) {
53 switch_to_blog( $site_id );
54 vigilante_uninstall_site();
55 restore_current_blog();
56 }
57 } else {
58 vigilante_uninstall_site();
59 }
60
61 /*
62 * Network options. Since 2.11.3 the baseline of the critical files lives in
63 * a single network option, because both files it watches, wp-config.php and
64 * the root .htaccess, belong to the installation and not to any one site.
65 * It is stored redacted, but it is still a copy of the configuration and it
66 * goes when the plugin goes. Once, not per site.
67 */
68 if ( is_multisite() ) {
69 delete_site_option( 'vigilante_critical_files_baseline' );
70 delete_site_option( 'vigilante_baseline_sweep' );
71 delete_site_option( 'vigilante_owned_blocks' );
72 delete_site_option( 'vigilante_owned_blocks_claim' );
73 delete_site_option( 'vigilante_config_copies_sweep' );
74 }
75
76 // Remove backup directory. WP_CONTENT_DIR is shared by the whole network,
77 // so this happens once.
78 $backup_dir = WP_CONTENT_DIR . '/vigilante-backups/';
79 if ( is_dir( $backup_dir ) ) {
80 vigilante_recursive_rmdir( $backup_dir );
81 }
82
83 // Delete all user meta with vigilante_ prefix. The usermeta table is global
84 // on a network, so this also happens once.
85 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own user meta (prefix vigilante_) swept by pattern at uninstall; no cache to invalidate once the plugin is gone.
86 $wpdb->query(
87 "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'vigilante\_%'"
88 );
89
90 /*
91 * The plugin is still loaded in the request that runs this file, so
92 * whatever it does later, on shutdown or on a late hook, writes its data
93 * back after the cleanup above has finished. Measured on 22 aug 2026: an
94 * uninstall left 112 rows of plugin status transients and its last check
95 * timestamp behind, all of them written after this file had run. So the
96 * sweep is repeated at the very end of the request. The loaded plugin is
97 * the current site's instance and writes to the current site, which is
98 * why the sweep does not visit the network again.
99 */
100 add_action( 'shutdown', 'vigilante_uninstall_final_sweep', PHP_INT_MAX );
101 }
102
103 /**
104 * Remove the data of the current site (tables, options, transients, cron)
105 *
106 * Runs once on a single site and once per site on a network, after
107 * switch_to_blog().
108 *
109 * @since 2.11.0 Extracted from vigilante_uninstall() so a network can loop it.
110 */
111 function vigilante_uninstall_site() {
112 global $wpdb;
113
114 /*
115 * The scheduled events go first. WordPress can spawn wp-cron in the middle
116 * of an uninstall, and that loopback request runs in its own process with
117 * the plugin still on disk: clearing the events before anything else means
118 * it finds nothing to run.
119 */
120 // Clear scheduled hooks
121 $hooks_to_clear = array(
122 'vigilante_daily_maintenance',
123 'vigilante_hourly_check',
124 'vigilante_hourly_checks',
125 'vigilante_file_integrity_scan',
126 'vigilante_cleanup_logs',
127 'vigilante_password_expiry_reminder',
128 'vigilante_analyzer_weekly_scan',
129 'vigilante_under_attack_post_scan',
130 'vigilante_plugin_status_check',
131 );
132
133 foreach ( $hooks_to_clear as $hook ) {
134 wp_clear_scheduled_hook( $hook );
135 }
136
137 // Post-update verification events are scheduled with per-update arguments,
138 // so clear every instance regardless of args.
139 wp_unschedule_hook( 'vigilante_fi_postupdate_verify' );
140
141 // Drop custom tables
142 $tables = array(
143 $wpdb->prefix . 'vigilante_activity_log',
144 $wpdb->prefix . 'vigilante_login_attempts',
145 $wpdb->prefix . 'vigilante_file_integrity',
146 $wpdb->prefix . 'vigilante_2fa_codes',
147 $wpdb->prefix . 'vigilante_2fa_trusted_devices',
148 $wpdb->prefix . 'vigilante_2fa_notifications',
149 $wpdb->prefix . 'vigilante_2fa_totp',
150 );
151
152 foreach ( $tables as $table ) {
153 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Dropping the plugin's own tables at uninstall; the name comes from $wpdb->prefix and a literal, never from input.
154 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
155 }
156
157 // Delete options
158 $options_to_delete = array(
159 'vigilante_options',
160 'vigilante_db_version',
161 'vigilante_purge_2_11_0_done',
162 'vigilante_baseline_redaction',
163 'vigilante_owned_blocks',
164 'vigilante_owned_blocks_claim',
165 'vigilante_backup_timestamp',
166 'vigilante_last_integrity_scan',
167 'vigilante_last_integrity_results',
168 'vigilante_ignored_files',
169 'vigilante_dismissed_notices',
170 'vigilante_under_attack_mode',
171 'vigilante_active_preset',
172 'vigilante_firewall_blocks',
173 'vigilante_critical_files_baseline',
174 'vigilante_activated_time',
175 'vigilante_analyzer_last_scan',
176 'vigilante_analyzer_history',
177 'vigilante_legacy_backups_cleaned',
178 'vigilante_css_exclusion_migrated',
179 'vigilante_checksum_cache_flushed_290',
180 'vigilante_server_software',
181 'vigilante_server_files_version',
182 'vigilante_server_files_pending',
183 'vigilante_server_files_retry_after',
184 // Safety copies taken before writing to the site's configuration files.
185 // The wp-config.php one holds the database credentials and the
186 // authentication salts, so leaving it behind would keep them readable in
187 // the options table long after the plugin is gone.
188 'vigilante_htaccess_backup',
189 'vigilante_wpconfig_backup',
190 'vigilante_config_copies_purged',
191 'vigilante_plugin_status_state',
192 'vigilante_plugin_status_last_check',
193 'vigilante_ignored_closed_plugins',
194 );
195
196 foreach ( $options_to_delete as $option ) {
197 delete_option( $option );
198 }
199
200 // Per-backup records are named after their timestamp
201 // (vigilante_backup_info_<Y-m-d_H-i-s>), so a fixed list cannot reach them.
202 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own options swept by pattern at uninstall; the options API has no LIKE.
203 $wpdb->query(
204 "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'vigilante_backup_info_%'"
205 );
206
207 // Delete all transients
208 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Plugin's own transients swept by pattern at uninstall; the transients API has no LIKE.
209 $wpdb->query(
210 "DELETE FROM {$wpdb->options}
211 WHERE option_name LIKE '_transient_vigilante_%'
212 OR option_name LIKE '_transient_timeout_vigilante_%'"
213 );
214 }
215
216 /**
217 * Second pass at the end of the request, for anything written after the first one
218 *
219 * Deliberately not a blunt "vigilante%" wildcard: other plugins live under that
220 * name too, the network sync companion among them, and deleting their options
221 * from here would be a fine way to break somebody else's site.
222 *
223 * @since 2.9.9
224 */
225 function vigilante_uninstall_final_sweep() {
226 global $wpdb;
227
228 // The scheduled events go too: they are rescheduled by the plugin that is
229 // still loaded in this request, which is how vigilante_plugin_status_check
230 // survived an uninstall until 2.9.9.
231 $hooks = array(
232 'vigilante_daily_maintenance',
233 'vigilante_hourly_check',
234 'vigilante_hourly_checks',
235 'vigilante_file_integrity_scan',
236 'vigilante_cleanup_logs',
237 'vigilante_password_expiry_reminder',
238 'vigilante_analyzer_weekly_scan',
239 'vigilante_under_attack_post_scan',
240 'vigilante_plugin_status_check',
241 'vigilante_fi_postupdate_verify',
242 );
243
244 foreach ( $hooks as $hook ) {
245 wp_unschedule_hook( $hook );
246 }
247
248 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Same sweep as vigilante_uninstall_site(), repeated at shutdown for rows the still-loaded plugin wrote back after the first pass.
249 $wpdb->query(
250 "DELETE FROM {$wpdb->options}
251 WHERE option_name LIKE '_transient_vigilante\_%'
252 OR option_name LIKE '_transient_timeout_vigilante\_%'
253 OR option_name LIKE 'vigilante_plugin_status\_%'
254 OR option_name LIKE 'vigilante_backup_info\_%'
255 OR option_name IN (
256 'vigilante_options',
257 'vigilante_db_version',
258 'vigilante_purge_2_11_0_done',
259 'vigilante_baseline_redaction',
260 'vigilante_critical_files_baseline',
261 'vigilante_owned_blocks',
262 'vigilante_owned_blocks_claim',
263 'vigilante_ignored_closed_plugins',
264 'vigilante_ignored_files',
265 'vigilante_dismissed_notices',
266 'vigilante_under_attack_mode',
267 'vigilante_active_preset',
268 'vigilante_server_software',
269 'vigilante_server_files_version',
270 'vigilante_server_files_pending',
271 'vigilante_server_files_retry_after'
272 )"
273 );
274 }
275
276 /**
277 * Recursively remove directory
278 *
279 * @param string $dir Directory path.
280 * @return bool
281 */
282 function vigilante_recursive_rmdir( $dir ) {
283 if ( ! is_dir( $dir ) ) {
284 return false;
285 }
286
287 // Initialize WP_Filesystem
288 global $wp_filesystem;
289 if ( ! function_exists( 'WP_Filesystem' ) ) {
290 require_once ABSPATH . 'wp-admin/includes/file.php';
291 }
292 WP_Filesystem();
293
294 if ( ! $wp_filesystem ) {
295 return false;
296 }
297
298 // Use WP_Filesystem delete with recursive flag
299 return $wp_filesystem->delete( $dir, true );
300 }
301
302 // Run uninstall
303 vigilante_uninstall();
304