benecaster_before_analytics_prune
Fires immediately before Benecaster begins deleting aged analytics rows. Both the nightly scheduled run and the manual “Prune now” operation in the settings UI trigger this hook.
This action fires only after the [benecaster_analytics_prune_skip](/hooks/benecaster_analytics_prune_skip/) filter returns `false` — aborted runs do not trigger it. At the point this hook fires, no data has been deleted yet. The `$tables` array lists every table targeted in this run; each will have rows older than `$retention_days` days removed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$source |
string |
— | One of 'cron' or 'manual' |
$retention_days |
int |
— | Configured retention window in days |
$tables |
string[] |
— | Table names about to be pruned |
Examples
Snapshot row count before pruning
add_action( 'benecaster_before_analytics_prune', function ( string $source, int $retention_days, array $tables ): void {
global $wpdb;
$pre_count = (int) $wpdb->get_var(
"SELECT COUNT(*) FROM {$wpdb->prefix}benecaster_download_log"
);
update_option( 'my_plugin_pre_prune_download_count', $pre_count );
}, 10, 3 );
Notes
Use benecaster_after_analytics_prune to observe per-table deletion counts and elapsed time after the run completes. Use benecaster_analytics_prune_skip to prevent this hook from firing by aborting the prune entirely.