Using WP-CLI with the Activity Log
The Activity Log plugin includes WP-CLI commands for exporting log data and purging old entries from the command line. This is useful for automating log exports, integrating with scripts, or managing logs on headless or staging environments.
Requirements
You’ll need WP-CLI installed on your server and 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. You can filter the results using any combination of the available flags.
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=
Show events from this date onwards. Accepts any date format PHP’s strtotime() understands, e.g. 2026-01-01 or yesterday.
--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 include in the output. Useful for narrowing CSV exports. Available fields: id, date_gmt, user_login, user_role, severity, event_type, message, object_name, ip_address, is_cli.
Export Examples
Export all events as a CSV file:
wp duplicator-activity-log export --format=csv > activity-log.csv
Export only High severity events from the last 7 days:
wp duplicator-activity-log export --severity=high --date_from="7 days ago"
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.
wp duplicator-activity-log purge
This is useful if you’ve changed your retention period and want to immediately clean up old entries without waiting for the next scheduled run, or if you need to trigger it manually in a deployment script.
To purge all log entries regardless of age, use the Purge All Logs button in Activity Log › Settings › Tools instead.