If you own a WordPress site or manage sites for clients, you can set up an audit log of who changed what, and keep a copy where an attacker cannot erase it. Sooner or later someone will ask who changed something on the site. It might be a deleted page, a new administrator nobody recognises, or a plugin that appeared overnight. A WordPress audit log, also called an activity log, answers that question with a record of each change, the account that made it and the time. WordPress does not keep one by itself, so you add a plugin, decide which events matter, and send a copy of the log off the server. That last step is what makes the record trustworthy, because anyone who gets admin access can also delete a log stored inside WordPress.
What you’ll accomplish
- Know which of your three WordPress-related logs answers which question, so you look in the right place first.
- Run an audit-log plugin that records logins, user and role changes, plugin and theme changes, settings changes and content deletions.
- Set a retention period and check how fast the log tables grow.
- Ship new log entries to a separate log host every 15 minutes, where a WordPress administrator cannot reach them.
- Answer “who did this, and when?” with one WP-CLI command or one SQL query.
Prerequisites
- WordPress 6.x with SSH access and WP-CLI, the command-line interface for managing WordPress, installed (
wp --infoshould print a version). - Permission to install plugins on the site.
- For the off-site copy, root access on the server to configure rsyslog, plus a log host or log service that accepts syslog over TCP. On shared hosting without root, use a plugin edition that forwards logs itself, covered in the plugin section below.
- Commands below assume the default
wp_table prefix in prose. The commands read the real prefix withwp db prefix, so they work either way.
How it works
A WordPress site produces three kinds of logs, and they answer different questions.
The access log is written by the web server (Apache, Nginx or LiteSpeed). It has one line per HTTP request, with the visitor’s IP address, the URL, the status code and the browser. It shows that someone sent a POST request to /wp-login.php from a given IP. It cannot tell you which WordPress user that was, or what they changed once inside. On cPanel servers each domain’s access log sits in /usr/local/apache/domlogs/. On a plain Nginx install it is usually /var/log/nginx/access.log.
The PHP error log records warnings and fatal errors. With WP_DEBUG_LOG turned on, WordPress writes it to wp-content/debug.log. It tells you what broke, not who caused it. Reading WordPress error logs covers that log in depth.
The audit log is the one this page is about. A plugin hooks into WordPress events and writes a row to its own database tables each time something changes. Each row names the user, the action, the object and the time. It is the only one of the three that knows WordPress usernames.
The weak point is where the audit log lives. It sits in the same database the attacker can now reach. An attacker with an administrator account can deactivate the plugin, or install a file manager or SQL plugin and delete rows. A copy already sent to another machine survives that, which is why the off-site step is part of the setup and not an extra.
Which events to record
Record events that change who can do what, or what the site runs. Those are the questions you will be asked after an incident or by a client.
- Logins. Successful logins, failed logins and password resets. Failed logins against real usernames matter more than attempts on usernames that do not exist.
- Users and roles. New users, deleted users, and every role change, especially any promotion to administrator.
- Plugins and themes. Install, activate, deactivate, update and delete. A plugin installed at 3 a.m. by an account that never installs plugins is a classic sign of a break-in.
- Settings. Changes to the site address (
siteurlandhome), the admin email address, the default role for new users and whether anyone can register. - Content. Publishing, moving to trash and permanent deletion. Edits to pages that carry legal or pricing text are worth keeping too.
- Files edited from wp-admin. Changes made through the built-in theme and plugin file editors.
Leave out page views by visitors, cron runs and cache purges. The access log and your monitoring already cover traffic, and that noise buries the rows you need.
File changes made outside WordPress, through SFTP or a web shell, never pass through WordPress hooks. Audit plugins cannot see them. Use wp core verify-checksums and a file-scanning security plugin for that part.
Choosing a plugin
Three plugins cover most needs. Pick one. Running two doubles database writes and leaves you with two records that slowly disagree.
Simple History is free on WordPress.org and quick to read. It stores events in wp_simple_history and their details in wp_simple_history_contexts. It ships its own WP-CLI commands (wp simple-history list, wp simple-history db stats). It keeps 30 days of history by default on new installs, and 60 days on sites that installed it before version 5.25.0. The examples below use it.
WP Activity Log, from Melapress, has a free edition on WordPress.org and paid editions. Every event type has a numeric ID, which makes queries precise. Events land in wp_wsal_occurrences, one row per event, with extra details in wp_wsal_metadata. Paid editions add features such as email notifications, and Melapress documents external database storage and log mirroring to services like AWS CloudWatch for its higher editions. If you need the plugin itself to ship logs off the server, this is the one to look at.
Stream, maintained by XWP, is free and stores records in wp_stream and wp_stream_meta. It has a setting for how many days to keep records and works across a multisite network.
Step-by-step
1. Check what is already installed. An inherited site may already have a log you can use.
wp plugin list --fields=name,status,version | grep -iE 'simple-history|wp-security-audit-log|stream'
No output means no audit plugin is installed. wp-security-audit-log is the WordPress.org slug of WP Activity Log. If one is installed and active, skip to step 3 and use it.
2. Install Simple History.
wp plugin install simple-history --activate
Expected output ends with:
Plugin 'simple-history' activated.
Success: Installed 1 of 1 plugins.
An error such as “Could not create directory” means the user running WP-CLI cannot write to wp-content/plugins. Run the command as the account that owns the site files.
3. Create test events and confirm they are recorded. Use a throwaway user so nothing real changes.
wp user create audit-test audit-test@example.com --role=editor
wp user set-role audit-test administrator
wp user delete audit-test --reassign=1
wp simple-history list --count=5
The first three commands each print a Success: line. --reassign=1 hands any content the test user owns to user ID 1; if that ID does not exist on your site, use the ID of another administrator. The last one should list three new events: the user created, the role changed to administrator and the user deleted. Then open a private browser window and log in with a wrong password once. Run wp simple-history list --count=5 again and a failed login should appear. If any event is missing, check that the plugin is active with wp plugin list --status=active.
4. Set the retention period. Keep at least 90 days in the database, so you can still look back after a slow-to-notice incident. Simple History reads its retention from the simple_history/db_purge_days_interval filter. Put the filter in a must-use plugin, a PHP file in wp-content/mu-plugins/ that WordPress always loads and admins cannot deactivate from the dashboard.
mkdir -p wp-content/mu-plugins
cat > wp-content/mu-plugins/audit-retention.php <<'PHP'
<?php
// Keep Simple History events for 90 days
add_filter( 'simple_history/db_purge_days_interval', function () { return 90; } );
PHP
wp eval 'echo apply_filters( "simple_history/db_purge_days_interval", 30 ), PHP_EOL;'
Expected output is 90. If you see 30, the file is in the wrong folder or has a syntax error. Run php -l wp-content/mu-plugins/audit-retention.php to check.
If a contract or regulator names a longer period, keep that period on the off-site copy, not in the WordPress database. In Québec, Law 25 requires organisations to keep a register of confidentiality incidents. An audit log is often how you find out what an incident touched.
5. Measure how fast the tables grow.
wp simple-history db stats
wp db size --tables | grep -i history
Both commands print a table. The first lists each Simple History table with its size in megabytes and its row count.
Example output:
+-----------------------------+------------+----------+
| table_name | size_in_mb | num_rows |
+-----------------------------+------------+----------+
| wp_simple_history | 0.52 | 2318 |
| wp_simple_history_contexts | 4.81 | 27406 |
+-----------------------------+------------+----------+
Run both again a week later and compare. Growth that keeps climbing usually points to one noisy source, such as a plugin that saves an option on every request. Find it by counting events per logger:
wp db query "SELECT logger, COUNT(*) AS events FROM $(wp db prefix)simple_history WHERE date > UTC_TIMESTAMP() - INTERVAL 7 DAY GROUP BY logger ORDER BY events DESC LIMIT 10;"
Simple History stores dates in UTC, which is why the query uses UTC_TIMESTAMP().
6. Ship new entries off the server. This script sends every row added since its last run to syslog, the standard Linux logging service. Save it as /home/example/bin/ship-audit.sh and replace example and example.com with your own account and domain.
#!/bin/bash
# Send new Simple History rows to syslog (facility local5)
set -euo pipefail
WP="/usr/local/bin/wp --path=/home/example/public_html"
STATE=/home/example/.audit-last-id
LAST=$(cat "$STATE" 2>/dev/null || echo 0)
P=$($WP db prefix)
$WP db query "SELECT h.id, h.date, h.logger, h.message, GROUP_CONCAT(CONCAT(c.key, '=', c.value) SEPARATOR ' ') FROM ${P}simple_history h LEFT JOIN ${P}simple_history_contexts c ON c.history_id = h.id WHERE h.id > ${LAST} GROUP BY h.id ORDER BY h.id" --skip-column-names |
while IFS=$'\t' read -r id date logger message context; do
logger -t wp-audit -p local5.info "site=example.com id=$id date=$date logger=$logger msg=$message $context"
echo "$id" > "$STATE"
done
Messages contain placeholders such as {plugin_name}. The details that fill them come from the contexts table, which is why the query joins it. As the site user, make the script executable and open your crontab, the per-user list of scheduled jobs:
chmod 700 /home/example/bin/ship-audit.sh
crontab -e
In the editor that opens, add this line to run the script every 15 minutes, then save:
*/15 * * * * /home/example/bin/ship-audit.sh
Then, as root, tell rsyslog to forward that facility to your log host over TCP:
echo 'local5.* @@logs.example.net:514' > /etc/rsyslog.d/60-wp-audit.conf
systemctl restart rsyslog
@@ means TCP, and a single @ would mean UDP. On the log host, give the WordPress server write-only access. Nobody with a WordPress login should be able to delete anything there.
Validate it works
Send a marker line and look for it on the log host.
logger -t wp-audit -p local5.info "audit pipeline test from $(hostname)"
The line should appear on the log host within seconds. Then run the full chain. Create and delete the audit-test user again as in step 3, run /home/example/bin/ship-audit.sh by hand, and search the log host for audit-test. You should find the creation, the role change and the deletion, Because you ran those from WP-CLI, Simple History credits them to WP-CLI rather than to a named account. Changes made in wp-admin carry a _user_login= value naming the person who made them.
To answer a real question, such as everything a given account did in September, query the database directly:
wp db query "SELECT h.date, h.logger, h.message FROM $(wp db prefix)simple_history h JOIN $(wp db prefix)simple_history_contexts c ON c.history_id = h.id WHERE c.key = '_user_login' AND c.value = 'jdoe' AND h.date >= '2026-09-01' ORDER BY h.date;"
If you already run WP Activity Log
Confirm its tables exist and see which events are most frequent this week. created_on holds a Unix timestamp, a count of seconds since 1970, so convert it with FROM_UNIXTIME().
wp db query "SHOW TABLES LIKE '%wsal%';"
wp db query "SELECT alert_id, COUNT(*) AS events FROM $(wp db prefix)wsal_occurrences WHERE created_on > UNIX_TIMESTAMP() - 7*86400 GROUP BY alert_id ORDER BY events DESC LIMIT 10;"
To list recent user creations, role changes and plugin installs or activations, filter on their event IDs. In Melapress’s list, 4000 and 4001 are new users, 4002 is a role change, and 5000 and 5001 are a plugin install and activation.
wp db query "SELECT FROM_UNIXTIME(created_on) AS at, username, client_ip, alert_id FROM $(wp db prefix)wsal_occurrences WHERE alert_id IN (4000, 4001, 4002, 5000, 5001) ORDER BY created_on DESC LIMIT 20;"
If SHOW TABLES returns nothing while the plugin is active, its data is stored in an external database set up in the plugin’s settings.
Troubleshooting
wp simple-history is not a registered wp command. The plugin is inactive, or it is an old version from before its WP-CLI commands existed. Run wp plugin update simple-history, then wp plugin list --status=active and confirm simple-history is in the list.
The shipping script sends the same rows twice. The state file is not writable, so LAST stays at 0. Check that /home/example/.audit-last-id exists, belongs to the site user and holds the last ID shipped.
Nothing reaches the log host. Run the logger test above. If it arrives, the problem is the cron job, so check the user’s mail or grep CRON /var/log/cron on RHEL-family systems. If it does not arrive, test the port from the web server with nc -vz logs.example.net 514 and check the log host’s firewall.
The tables are huge. Lower the retention, then confirm the purge ran with wp simple-history db stats. Simple History purges on a schedule through WP-Cron, so a site with DISABLE_WP_CRON set and no real cron job never purges.
Times look off by a few hours. Simple History stores UTC and WP Activity Log stores Unix timestamps. Your site’s timezone in Settings > General only affects display, so convert before you compare with access-log times.
When this is the wrong approach
An audit log records what happened. It does not stop anything. If the site is compromised right now, contain it first with the first 60 minutes of WordPress incident response, and copy the log tables before you clean anything.
A plugin log is also the wrong tool for proving what a web shell did. Requests to a dropped PHP file show up in the access log, and file changes in a file-integrity scan. Neither shows up in an audit plugin. Keep the access log on the same off-site host so you can line the two up.
Finally, if nobody reads the log or the alerts, it only helps after the fact. That still has value, but decide who looks at it and how often before you count it as a control. The WP-CLI command reference documents every wp command used here, and the Simple History plugin page lists what it records.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.