PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 2.11.4
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v2.11.4
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.4, at uninstall.php

296 lines 11.0 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 }
72
73 // Remove backup directory. WP_CONTENT_DIR is shared by the whole network,
74 // so this happens once.
75 $backup_dir = WP_CONTENT_DIR . '/vigilante-backups/';
76 if ( is_dir( $backup_dir ) ) {
77 vigilante_recursive_rmdir( $backup_dir );
78 }
79
80 // Delete all user meta with vigilante_ prefix. The usermeta table is global
81 // on a network, so this also happens once.
82 // 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.
83 $wpdb->query(
84 "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'vigilante\_%'"
85 );
86
87 /*
88 * The plugin is still loaded in the request that runs this file, so
89 * whatever it does later, on shutdown or on a late hook, writes its data
90 * back after the cleanup above has finished. Measured on 22 aug 2026: an
91 * uninstall left 112 rows of plugin status transients and its last check
92 * timestamp behind, all of them written after this file had run. So the
93 * sweep is repeated at the very end of the request. The loaded plugin is
94 * the current site's instance and writes to the current site, which is
95 * why the sweep does not visit the network again.
96 */
97 add_action( 'shutdown', 'vigilante_uninstall_final_sweep', PHP_INT_MAX );
98 }
99
100 /**
101 * Remove the data of the current site (tables, options, transients, cron)
102 *
103 * Runs once on a single site and once per site on a network, after
104 * switch_to_blog().
105 *
106 * @since 2.11.0 Extracted from vigilante_uninstall() so a network can loop it.
107 */
108 function vigilante_uninstall_site() {
109 global $wpdb;
110
111 /*
112 * The scheduled events go first. WordPress can spawn wp-cron in the middle
113 * of an uninstall, and that loopback request runs in its own process with
114 * the plugin still on disk: clearing the events before anything else means
115 * it finds nothing to run.
116 */
117 // Clear scheduled hooks
118 $hooks_to_clear = array(
119 'vigilante_daily_maintenance',
120 'vigilante_hourly_check',
121 'vigilante_hourly_checks',
122 'vigilante_file_integrity_scan',
123 'vigilante_cleanup_logs',
124 'vigilante_password_expiry_reminder',
125 'vigilante_analyzer_weekly_scan',
126 'vigilante_under_attack_post_scan',
127 'vigilante_plugin_status_check',
128 );
129
130 foreach ( $hooks_to_clear as $hook ) {
131 wp_clear_scheduled_hook( $hook );
132 }
133
134 // Post-update verification events are scheduled with per-update arguments,
135 // so clear every instance regardless of args.
136 wp_unschedule_hook( 'vigilante_fi_postupdate_verify' );
137
138 // Drop custom tables
139 $tables = array(
140 $wpdb->prefix . 'vigilante_activity_log',
141 $wpdb->prefix . 'vigilante_login_attempts',
142 $wpdb->prefix . 'vigilante_file_integrity',
143 $wpdb->prefix . 'vigilante_2fa_codes',
144 $wpdb->prefix . 'vigilante_2fa_trusted_devices',
145 $wpdb->prefix . 'vigilante_2fa_notifications',
146 $wpdb->prefix . 'vigilante_2fa_totp',
147 );
148
149 foreach ( $tables as $table ) {
150 // 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.
151 $wpdb->query( "DROP TABLE IF EXISTS {$table}" );
152 }
153
154 // Delete options
155 $options_to_delete = array(
156 'vigilante_options',
157 'vigilante_db_version',
158 'vigilante_purge_2_11_0_done',
159 'vigilante_baseline_redaction',
160 'vigilante_backup_timestamp',
161 'vigilante_last_integrity_scan',
162 'vigilante_last_integrity_results',
163 'vigilante_ignored_files',
164 'vigilante_dismissed_notices',
165 'vigilante_under_attack_mode',
166 'vigilante_active_preset',
167 'vigilante_firewall_blocks',
168 'vigilante_critical_files_baseline',
169 'vigilante_activated_time',
170 'vigilante_analyzer_last_scan',
171 'vigilante_analyzer_history',
172 'vigilante_legacy_backups_cleaned',
173 'vigilante_css_exclusion_migrated',
174 'vigilante_checksum_cache_flushed_290',
175 'vigilante_server_software',
176 'vigilante_server_files_version',
177 'vigilante_server_files_pending',
178 'vigilante_server_files_retry_after',
179 // Safety copies taken before writing to the site's configuration files.
180 // The wp-config.php one holds the database credentials and the
181 // authentication salts, so leaving it behind would keep them readable in
182 // the options table long after the plugin is gone.
183 'vigilante_htaccess_backup',
184 'vigilante_wpconfig_backup',
185 'vigilante_plugin_status_state',
186 'vigilante_plugin_status_last_check',
187 'vigilante_ignored_closed_plugins',
188 );
189
190 foreach ( $options_to_delete as $option ) {
191 delete_option( $option );
192 }
193
194 // Per-backup records are named after their timestamp
195 // (vigilante_backup_info_<Y-m-d_H-i-s>), so a fixed list cannot reach them.
196 // 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.
197 $wpdb->query(
198 "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'vigilante_backup_info_%'"
199 );
200
201 // Delete all transients
202 // 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.
203 $wpdb->query(
204 "DELETE FROM {$wpdb->options}
205 WHERE option_name LIKE '_transient_vigilante_%'
206 OR option_name LIKE '_transient_timeout_vigilante_%'"
207 );
208 }
209
210 /**
211 * Second pass at the end of the request, for anything written after the first one
212 *
213 * Deliberately not a blunt "vigilante%" wildcard: other plugins live under that
214 * name too, the network sync companion among them, and deleting their options
215 * from here would be a fine way to break somebody else's site.
216 *
217 * @since 2.9.9
218 */
219 function vigilante_uninstall_final_sweep() {
220 global $wpdb;
221
222 // The scheduled events go too: they are rescheduled by the plugin that is
223 // still loaded in this request, which is how vigilante_plugin_status_check
224 // survived an uninstall until 2.9.9.
225 $hooks = array(
226 'vigilante_daily_maintenance',
227 'vigilante_hourly_check',
228 'vigilante_hourly_checks',
229 'vigilante_file_integrity_scan',
230 'vigilante_cleanup_logs',
231 'vigilante_password_expiry_reminder',
232 'vigilante_analyzer_weekly_scan',
233 'vigilante_under_attack_post_scan',
234 'vigilante_plugin_status_check',
235 'vigilante_fi_postupdate_verify',
236 );
237
238 foreach ( $hooks as $hook ) {
239 wp_unschedule_hook( $hook );
240 }
241
242 // 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.
243 $wpdb->query(
244 "DELETE FROM {$wpdb->options}
245 WHERE option_name LIKE '_transient_vigilante\_%'
246 OR option_name LIKE '_transient_timeout_vigilante\_%'
247 OR option_name LIKE 'vigilante_plugin_status\_%'
248 OR option_name LIKE 'vigilante_backup_info\_%'
249 OR option_name IN (
250 'vigilante_options',
251 'vigilante_db_version',
252 'vigilante_purge_2_11_0_done',
253 'vigilante_baseline_redaction',
254 'vigilante_critical_files_baseline',
255 'vigilante_ignored_closed_plugins',
256 'vigilante_ignored_files',
257 'vigilante_dismissed_notices',
258 'vigilante_under_attack_mode',
259 'vigilante_active_preset',
260 'vigilante_server_software',
261 'vigilante_server_files_version',
262 'vigilante_server_files_pending',
263 'vigilante_server_files_retry_after'
264 )"
265 );
266 }
267
268 /**
269 * Recursively remove directory
270 *
271 * @param string $dir Directory path.
272 * @return bool
273 */
274 function vigilante_recursive_rmdir( $dir ) {
275 if ( ! is_dir( $dir ) ) {
276 return false;
277 }
278
279 // Initialize WP_Filesystem
280 global $wp_filesystem;
281 if ( ! function_exists( 'WP_Filesystem' ) ) {
282 require_once ABSPATH . 'wp-admin/includes/file.php';
283 }
284 WP_Filesystem();
285
286 if ( ! $wp_filesystem ) {
287 return false;
288 }
289
290 // Use WP_Filesystem delete with recursive flag
291 return $wp_filesystem->delete( $dir, true );
292 }
293
294 // Run uninstall
295 vigilante_uninstall();
296