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 and purging entries straight from the command line.
This guide covers using WP-CLI with the Activity Log plugin, including every available export 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,wordpress,appearance,taxonomy,settings.--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.--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 means midnight at the start of that day, so events from that day are left out. To include the whole day, add the time, for example--date_to="2026-01-07 23:59:59".--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.
Export Examples
wp duplicator-activity-log export --format=csv > activity-log.csv
Export all events as a CSV file:
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 23:59:59"
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 23:59:59" --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
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.
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’s it! You now know how to export 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 Configuring Activity Log Settings.