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 old 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 and change the output format.
Export Flags
All flags are optional and can be combined freely.
- –format=
Output format. Accepts table (default), csv, or json. - –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 and object names. Equivalent to the Search Events field in the admin. - –date_from=
Filter entries by date. Use theYYYY-MM-DDorYYYY-MM-DD HH:MM:SSformat - –date_to=
Show events up to and including this date. - –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
Export all events as a CSV file:
wp duplicator-activity-log export --format=csv > activity-log.csv
Export only High severity events for 7 days:
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
Purge Command
The purge command deletes all log entries older than your configured retention period (set in Activity Log › Settings › General). This is the same action that the daily cron job runs automatically.
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 prompts for confirmation before deleting, unless –yes is passed.
- 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 trigger cleanup on demand instead of waiting for the next scheduled run. For the same action from wp-admin, use Activity Log › Settings › Tools › Purge All Logs.
That’s it! With these commands, you can export and clean up activity log data entirely from the command line, without opening wp-admin.