I’ve been looking for a solution to manage event log data and have already followed all the recommendations in your article at https://wpcerber.com/managing-wp-cerber-log-tables/. However, this isn’t fully addressing my issue. Despite setting log retention to 5 and 10 days via the optimization parameters, the cerber_traffic table still contains excessive data and occupies too much database space (>400 MB), with over one-third of entries attributed to the admin user (ID=1).
I’d like to inquire if there’s a method to:
Selectively delete logs only for the admin user (ID=1) or a specific IP address (ideally both criteria combined), without clearing all logs via WP Cerber → Tools.
Exclude logging entirely for the admin user or specific IPs/Hostnames in the Traffic Logging settings.
If this functionality isn’t natively available:
Are there hooks/filters (e.g., for WP Cron) to automate periodic deletion of logs matching these criteria (user ID, IP, etc.)?
Could you provide a recommended SQL query to safely purge these records? (I’d prefer an expert-reviewed query to avoid unintended consequences.)
This granular approach would allow me to retain valuable logs for other users/external sources while reducing unnecessary clutter. I believe many users might benefit from such a feature, as tracking one’s own activity (especially for admins) is often redundant.
Thank you for your time and expertise. I look forward to your insights.
Currently, WP Cerber does not offer a built-in way to exclude specific user IDs or IP addresses from traffic logging. However, this feature is already on our roadmap and is planned for implementation in one of the upcoming releases.
There are also no filters or hooks available to automate selective deletion. That said, since you’re comfortable running SQL, it’s safe to proceed with a manual cleanup. Here are some example queries you can run in the database used by your WordPress site.
To delete all traffic log entries related to the admin user (user_id = 1):
DELETE FROM cerber_traffic
WHERE user_id = 1;
To delete only entries that match both user_id = 1 and a specific IP address (e.g., 192.0.2.1):
DELETE FROM cerber_traffic
WHERE user_id = 1
AND ip = '192.0.2.1';
To delete old entries for user_id = 1, for example, older than 30 days:
DELETE FROM cerber_traffic
WHERE user_id = 1
AND stamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY));
Before executing any DELETE queries, I recommend the following:
Create a full backup of your database.
Run a SELECT query first to preview which rows will be deleted.
Archive any important data before deletion if needed.
After deleting a large number of rows, run the following to free up disk space:
OPTIMIZE TABLE cerber_traffic;
If you’d like to automate cleanup tasks on a schedule using а PHP snippet, let me know. We can guide you through the setup.
Thank you for your response. Yes, I’d like to automate the removal of records related to me using a function managed by a cron job.
This is the code I plan to implement:
add_action('cerber_clean_admin_logs', 'delete_all_admin_cerber_logs');
function delete_all_admin_cerber_logs() {
global $wpdb;
$table = 'cerber_traffic'; // Table (without prefix)
$admin_id = 1; // Admin user ID
$admin_ip = MY_SAFE_IP; // Admin user IP (constant defined in config file)
$http_code = 200; // HTTP status code
$result = $wpdb->query(
$wpdb->prepare(
"DELETE FROM `$table` WHERE user_id = %d AND ip = %s AND http_code = %d",
$admin_id,
$admin_ip,
$http_code
)
);
}
The table cleanup is not handled by this code directly—it’s executed through a separate channel on a different schedule.
If you have better suggestions, I’d be interested in hearing them. Thank you.