Using WP-CLI with the Activity Log
Wondering how to export or clean up your activity log without opening wp-admin? The Activity Log plugin includes WP-CLI commands for exporting log data, reading events, and purging entries straight from the command line.
This guide covers using WP-CLI with the Activity Log plugin, including every available export, event, and purge flag.
Requirements
WP-CLI must be installed on your server, with access to run it from the command line. The Activity Log plugin must be installed and activated. Run all commands from the root of your WordPress installation.
Export Command
The export command outputs activity log entries to the terminal or a file. Combine any of the flags below to filter the results.
wp duplicator-activity-log export
By default, this outputs all log entries as a formatted table. Add flags to filter the entries and change the output format.
Export Flags
The following flags are available. All of them are optional, and they work in any combination:
--format=
Output format. Acceptstable(default),csv, orjson.--category_l1=
Filter by top-level event category. Accepted values:user,content,media,plugin,theme,core,appearance,taxonomy,settings,activity_log. Plugin integrations add their own categories, such asbackupsandrestoresfor Duplicator.--severity=
Filter by severity level. Accepted values:info,low,medium,high,critical.--user_id=
Filter events by a specific WordPress user ID.--event_type=
Filter by a specific event type code, for example:user_login_failed,plugin_activated,content_post_published.--search=
Search across event messages, usernames, and object names. Equivalent to the Search Events field in the admin. A whole IP address, for example--search=203.0.113.5, also finds the events recorded from that IP.--date_from=
Show events from this date onward. Use theYYYY-MM-DDorYYYY-MM-DD HH:MM:SSformat. Dates and times are in UTC.--date_to=
Show events up to this date and time. Uses the same format as--date_from=. A date on its own includes that whole day, for example--date_to=2026-01-07.--since_last_backup
Export only the entries at or after the last Duplicator backup or restore recorded in the log. You can’t combine this flag with--date_from=. If the log holds no Duplicator backup, the command stops with the messageNo Duplicator backup is in the activity log.A backup whose deletion is logged no longer counts. Duplicator backups are logged by the Duplicator integration, which is on by default.--via=
Filter by how the change came in. Acceptsai_agent(an AI agent),app(any other application password), orcron(WP-Cron).--site_id=
On WordPress Multisite, filter events for a specific site by its blog ID. Defaults to the current site.--fields=
Comma-separated list of fields to display. This flag only applies totableformat. CSV and JSON exports always include every field.
Available fields for--fields=:
id, date_gmt, severity, event_type, event_label, category_l1, category_l2, category_l3, message, user_id, user_login, user_role, object_type, object_id, object_name, ip_address, user_agent, request_method, request_uri, source, site_id, metadata, via, via_name.
Export Examples
Export all events as a CSV file:
wp duplicator-activity-log export --format=csv > activity-log.csv
Export only high severity events for a 7-day range:
wp duplicator-activity-log export --severity=high --date_from=2026-01-01 --date_to=2026-01-07
Export all failed login attempts as JSON:
wp duplicator-activity-log export --event_type=user_login_failed --format=json
Export all plugin events for a specific date range to a file:
wp duplicator-activity-log export --category_l1=plugin --date_from=2026-01-01 --date_to=2026-01-31 --format=csv > plugins-jan.csv
Export only specific fields for a lightweight CSV:
wp duplicator-activity-log export --format=csv --fields=date_gmt,user_login,severity,message > compact-log.csv
Export everything logged since the last backup:
wp duplicator-activity-log export --since_last_backup --format=csv > since-backup.csv
Purge Command
The purge command deletes activity log entries directly from the command line.
wp duplicator-activity-log purge
Running purge with no flags deletes every entry in the activity log. WP-CLI asks for confirmation before deleting, unless you add --yes. Each purge that deletes entries is recorded as an Activity Log Purged event (High severity) with the number of entries deleted, so after a full purge, and while Record activity is on, the log holds that one entry. The daily retention cleanup is not logged.
The following flags are available:
--older-than=<days>
Delete only entries older than the given number of days, instead of deleting everything.--yes
Skip the confirmation prompt.
Purge Examples
Delete all log entries, with a confirmation prompt:
wp duplicator-activity-log purge
Delete entries older than 90 days:
wp duplicator-activity-log purge --older-than=90
Delete all entries without a confirmation prompt:
wp duplicator-activity-log purge --yes
Use these commands to clean up the activity log on demand. To delete every entry from wp-admin instead, go to Activity Log » Settings » Tools and click Purge All Logs. That button also records an Activity Log Purged event.
Event Commands
The event command reads events from the activity log. It has 3 subcommands: list, get, and stats.
Event List
The list command shows events, newest first.
wp duplicator-activity-log event list
By default, this shows the 20 newest events as a table. The following flags are available. All of them are optional, and they work in any combination:
--severity=
Filter by severity level. Accepted values:info,low,medium,high,critical.--categories=
Comma-separated categories. Each one is a domain, adomain/categorypair, or adomain/category/subcategorypath, for examplewordpress/user. The category rows of theevent statscommand list the codes.--event_type=
Filter by a specific event type code, for example:user_login_failed.--user_id=
Filter events by a specific WordPress user ID.--search=
Search across event messages, usernames, and object names. A whole IP address, for example--search=203.0.113.5, also finds the events recorded from that IP.--date_from=
Show events from this date onward, in theYYYY-MM-DDorYYYY-MM-DD HH:MM:SSformat. Dates and times are in UTC.--date_to=
Show events up to this date and time. Uses the same format as--date_from=. A date on its own includes that whole day.--since_last_backup
Show only the events at or after the last Duplicator backup or restore in the log. You can’t combine this flag with--date_from=. The first line of the output names that backup, in the formSince the last backup: <event> "<backup name>", <date> GMT. If the log holds no Duplicator backup, the command stops with the messageNo Duplicator backup is in the activity log.--via=
Filter by how the change came in. Acceptsai_agent(an AI agent),app(any other application password), orcron(WP-Cron).--object_type=
Filter by the type of object an event is about, for example:post,page,user,plugin.--object_id=
Filter by the ID of the object an event is about. This flag needs--object_type=.--limit=
How many events to show, from 1 to 100. Defaults to 20.--before_id=
Show older events: only IDs below this one, newest first.--after_id=
Show newer events: only IDs above this one, oldest first. You can’t combine--before_id=and--after_id=.--format=
Output format. Acceptstable(default) orjson.
When more events match than the limit shows, the table ends with a line such as More events: --before_id=4500. Then, add that flag to your next command to see the following page. When you page with --after_id=, the line reads More events: --after_id= followed by the newest ID shown.
Event Get
The get command shows one event with every stored field, its request details, and its changes and extra data. The event ID goes after the command:
wp duplicator-activity-log event get 4521
This command accepts the --format= flag, with table (default) or json.
Event Stats
The stats command counts the events of a date range, in total and by severity, category, event type, and how the change came in.
wp duplicator-activity-log event stats
The following flags are available:
--date_from=
Start of the range, in UTC. Defaults to 7 days before--date_to=.--date_to=
End of the range, in UTC. Defaults to now. A date on its own includes that whole day. The range can be 90 days at most.--format=
Output format. Acceptstable(default) orjson.
Event Examples
Show everything logged since the last backup:
wp duplicator-activity-log event list --since_last_backup
Show the 50 newest high severity events:
wp duplicator-activity-log event list --severity=high --limit=50
Show everything WP-Cron changed, as JSON:
wp duplicator-activity-log event list --via=cron --format=json
Show every stored detail of one event:
wp duplicator-activity-log event get 4521
Count the events of January:
wp duplicator-activity-log event stats --date_from=2026-01-01 --date_to=2026-01-31
That’s it! You now know how to export, read, and clean up activity log data from the command line, without opening wp-admin.
Want to change how long entries stay in the log before the daily cleanup removes them? Check out our guide on changing the Activity Log settings.