Plugins > Delete. * Performs a 100% clean teardown leaving zero orphaned database tables, files, or .htaccess rules. */ if (!defined('WP_UNINSTALL_PLUGIN')) { exit; } // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals call_user_func(function() { global $wpdb; // 1. Clean up root .htaccess hardening block - remove only plugin rules $htaccess_file = wp_normalize_path(ABSPATH . '.htaccess'); // phpcs:ignore PluginCheck.CodeAnalysis.WriteFile.ABSPATHDetected if (file_exists($htaccess_file) && wp_is_writable($htaccess_file)) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $content = @file_get_contents($htaccess_file); if ($content !== false) { $cleaned = preg_replace('/# BEGIN (?:WP ShieldX|ArlenGuard) Hardening.*?# END (?:WP ShieldX|ArlenGuard) Hardening\s*/s', '', $content); if ($cleaned !== $content) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, PluginCheck.CodeAnalysis.WriteFile.ABSPATHDetected @file_put_contents($htaccess_file, $cleaned); } } } // 2. Clean up uploads lockdown .htaccess - preserve existing rules and remove only plugin's block $upload_dir = wp_upload_dir(); $uploads_htaccess = trailingslashit($upload_dir['basedir']) . '.htaccess'; if (file_exists($uploads_htaccess) && wp_is_writable($uploads_htaccess)) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $content = @file_get_contents($uploads_htaccess); if ($content !== false) { // Remove modern delimited block $cleaned = preg_replace('/# BEGIN (?:WP ShieldX|ArlenGuard) Uploads Lockdown.*?# END (?:WP ShieldX|ArlenGuard) Uploads Lockdown\s*/s', '', $content); // Also remove legacy block if present $cleaned = preg_replace('/# WP ShieldX Security Uploads Lockdown\s*\s*/s', '', $cleaned); if ($cleaned !== $content) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents @file_put_contents($uploads_htaccess, $cleaned); } } } // 3. Drop all custom database tables $tables = [ $wpdb->prefix . 'arlenguard_file_baseline', $wpdb->prefix . 'arlenguard_scan_results', $wpdb->prefix . 'arlenguard_firewall_logs', $wpdb->prefix . 'arlenguard_quarantine', $wpdb->prefix . 'arlenguard_backups', ]; foreach ($tables as $table) { $escaped_table = esc_sql($table); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is escaped and cannot use query placeholders. $wpdb->query("DROP TABLE IF EXISTS `{$escaped_table}`"); } // 4. Delete plugin settings & options safely via Options API delete_option('arlenguard_settings'); delete_option('arlenguard_db_version'); delete_option('arlenguard_settings'); delete_option('arlenguard_vault_key'); // 5. Clean plugin transients without touching serialized site options // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_arlenguard_%' OR option_name LIKE '_transient_timeout_arlenguard_%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_arlenguard_%' OR option_name LIKE '_transient_timeout_arlenguard_%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_arlenguard_%' OR option_name LIKE '_transient_timeout_arlenguard_%'"); // 6. Recursively remove quarantine and backup vault directories global $wp_filesystem; if (empty($wp_filesystem)) { require_once ABSPATH . 'wp-admin/includes/file.php'; WP_Filesystem(); } if ($wp_filesystem) { $plugin_uploads_dir = trailingslashit($upload_dir['basedir']) . 'arlenguard/'; if (file_exists($plugin_uploads_dir) && is_dir($plugin_uploads_dir)) { $wp_filesystem->delete($plugin_uploads_dir, true); } $quarantine_dir = trailingslashit($upload_dir['basedir']) . 'arlenguard-quarantine/'; if (file_exists($quarantine_dir) && is_dir($quarantine_dir)) { $wp_filesystem->delete($quarantine_dir, true); } // Clean any arlenguard-backups-* directories $backup_pattern = trailingslashit($upload_dir['basedir']) . 'arlenguard-backups-*'; $backup_dirs = glob($backup_pattern, GLOB_ONLYDIR); if (is_array($backup_dirs)) { foreach ($backup_dirs as $b_dir) { if (file_exists($b_dir) && is_dir($b_dir)) { $wp_filesystem->delete($b_dir, true); } } } } // 7. Clear any lingering scheduled cron events $timestamp = wp_next_scheduled('arlenguard_scheduled_scan'); if ($timestamp) { wp_unschedule_event($timestamp, 'arlenguard_scheduled_scan'); } }); // phpcs:enable WordPress.NamingConventions.PrefixAllGlobals