When a WordPress site gets hacked, the fastest-looking action is often the most dangerous one: deleting files before understanding what happened. A cleanup should protect the real business data first, then remove the infection.
Evidence before deletion
Malware can hide in uploads, fake plugins, modified theme files, cron jobs, database options, spam posts, form submissions or injected JavaScript. Some suspicious functions are also used by legitimate plugins. That is why I separate confirmed malware from suspicious code before deleting anything.
The workflow I use
- Isolate the site and stop public damage where possible.
- Snapshot files and database before cleanup.
- Verify core with checksums.
- Scan plugins, themes, mu-plugins and uploads.
- Inspect database for spam links, redirects, injected scripts and fake users.
- Confirm malware vs false positives.
- Clean safely by replacing, removing or repairing only confirmed items.
- Harden and monitor with WAF, 2FA, update discipline and logs.
No cleanup can guarantee a site will never be attacked again. A serious cleanup reduces risk, preserves legitimate data and gives the owner a clear recovery path.
Related implementation
See how the ideas map to working code.
The public repository connects the article’s architecture, security, REST, blocks, CLI, privacy, testing and CI concepts to working code.