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 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[] |
— | Opaque internal identifiers for the analytics datasets about to be pruned — useful only for counting or logging, not for querying |
Examples
Record prune start for monitoring
add_action( 'benecaster_before_analytics_prune', function ( string $source, int $retention_days, array $tables ): void {
update_option( 'my_plugin_last_prune_start', [
'source' => $source,
'retention_days' => $retention_days,
'dataset_count' => count( $tables ),
'started_at' => time(),
] );
}, 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.
Need this built rather than just documented? See our services →