Sébastien Laframboise

Monitor file changes on a WordPress site

Monitor file changes on a WordPress site

The WordPress file monitoring helps you spot an unexpected change before it goes unnoticed. It doesn’t stop an attack by itself. However, it gives you a useful signal when a core file, plugin, or sensitive folder differs from the expected state.

An alert does not automatically prove a hack. An update, a deployment, or a theme change can also alter files. The goal is therefore to detect the discrepancy, then quickly check what changed and why.

What integrity monitoring can detect

An integrity check compares the files on the server to a known reference. That reference can be the checksums published for WordPress. It can also be an approved version of your custom files.

For the WordPress core, the WP-CLI command wp core verify-checksums compares the installed files to the checksums provided by WordPress.org. This verification runs before WordPress is loaded. See the wp core verify-checksums documentation for its options.

This approach can reveal a modified, missing, or unexpected core file. However, it does not automatically cover all content in the wp-content. directory. That directory contains plugins, themes, uploads, and often site-specific files.

Monitoring therefore does not replace backups or updates. Instead, it complements preventative measures by telling you when a discrepancy deserves your attention.

What changes are normal on a WordPress site?

Start by recognizing legitimate events. Otherwise, alerts will become too numerous and eventually ignored.

Core, plugin, and theme updates

A WordPress update replaces core files. It can also add or remove certain files depending on the installed version. The official WordPress update documentation notes that this operation affects the files and folders of the main installation.

Similarly, activating, updating, or removing a plugin changes its folder. Schedule your checks after these operations. Then accept the new reference only after verifying the site functions normally. A cautious WordPress update reduces false positives and makes investigation easier.

Files created during site operation

Some directories change frequently without being suspicious. This is especially the case for wp-content/uploads, which receives media. Cache, backup, or form plugins can also create their own folders.

Do not place these active areas under the same rule as a core PHP file. Instead, monitor them according to appropriate expectations. For example, a media file created after an upload is normal. An unknown PHP file in that folder, however, warrants investigation.

Set up useful monitoring

A good setup stays simple. It checks critical areas, keeps a record of expected changes, and sends alerts to someone able to review them.

1. Check the WordPress core

If you have WP-CLI access, first run this command from the installation directory:

wp core verify-checksums --include-root --version=$(wp core version)

The option --include-root extends the check to the root folder. It can therefore flag items that shouldn’t be there. The WordPress guide on security checks with WP-CLI notes, however, that a valid result does not rule out a new malicious file elsewhere in the installation.

Log the result, the date, the WordPress version, and the context. Do this check after an approved update. Repeat it at a frequency compatible with your actual capacity to handle alerts.

2. Check WordPress.org plugins

For plugins distributed in the official directory, WP-CLI also provides wp plugin verify-checksums --all --strict. The option --strict flags even minor changes, including in a readme.txt. The wp plugin verify-checksums documentation confirms that this command compares plugin files to the checksums on WordPress.org.

A premium, custom, or otherwise installed plugin may not have public checksums. In that case, the warning mainly indicates that WP-CLI cannot perform this comparison. It is not, by itself, proof of malicious code.

3. Create a baseline for your custom files

Custom themes, in-house plugins, and configuration files require a separate baseline. After a validated deployment, keep a trusted copy of the delivered files. Also record planned changes so you can compare production to that approved version.

Pay special protection to directories that contain code. Recommendations on the WordPress hardening indicate that core files, of wp-admin, of wp-includes and plugins should be editable only by the appropriate account. Write needs should instead be focused on the necessary locations of wp-content.

How to interpret an alert without acting too quickly

Treat an alert as a case to investigate. Avoid deleting the file immediately. You might erase a useful clue or break a legitimate site function.

Alert typeFirst checkCautious response
Modified core fileVersion, language and update dateCompare checksums, then replace core files with an official copy if the discrepancy remains unexplained.
New PHP file in wp-admin or wp-includesDeployment log and recent technical interventionTreat it as a priority and verify its origin before deleting.
Unverifiable pluginSource, version and installation methodCompare with the archive provided by the vendor or with your approved copy.
Change in uploads or the cacheRecent action or known automated taskCheck the file type and context before concluding compromise.

Clues that require prioritized investigation

Escalate analysis if an unknown PHP file appears in a folder that should contain only media. Do the same if core files fail verification without a recent update. Multiple changes outside your intervention windows are also an important signal.

An alert gains severity when it coincides with other signals. Look specifically for an unknown admin account, unusual logins, redirects or emails sent for no reason. Preserve logs and a copy of the affected files.

Then follow a structured plan to responding after a WordPress hack, rather than fixing only the visible file.

Cut unnecessary alerts without creating blind spots

Avoid overly broad exclusions. Excluding everything wp-content would make monitoring far less useful. Conversely, monitoring every cache file will generate noise that’s hard to manage.

Instead, document dynamic folders, scheduled tasks, and deployments. Keep a a full backup before major changes. Also ensure it can be restored. A tested backup restore gives you a concrete option if the investigation confirms a compromise.

Also review installed plugins at regular intervals. An abandoned plugin complicates updates, patches, and interpreting the files it adds. Learn to spot abandoned WordPress plugins before they become hard to track.

Monitoring becomes truly useful when you can answer three questions: which file changed, when did it change, and what authorized action explains that change? If no reliable answer exists, treat the variance as a potential incident. Preserve evidence before acting.