benecaster_benchmarks_refreshed
Fires after a successful benchmark refresh writes updated industry data to the WordPress transient cache. The transient is already written before callbacks run — reading the benchmark data from within a callback returns the newly refreshed values.
This hook does not fire when a refresh is skipped via benecaster_benchmarks_fetch_skip, when the HTTP request to the license server fails, or when the response is not an array. The $response array is the license server’s response exactly as written to the transient: no normalization is applied first. It carries calculated_at, sample_size, minimum_sample_not_met and a benchmarks object. Treat unknown keys as forwards-compatible additions.
benchmarks holds two shapes, so check a key before reading it. Percentile metrics, currently subscriber_count, look like { label, p25, p50, p75, p90 }. The share distributions membership_plugins and addons_enabled look like { label, sample, shares }, where sample is an integer or null and shares is a { slug: float } map or null. They have no percentiles, so reading p50 on them is an undefined index. They also have no names: the plugin adds display names only in its own GET /analytics/benchmarks REST response, never in this payload. A distribution with sample and shares both null means fewer than 10 sites reported it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$response |
array |
— | The license server's benchmark response just cached: calculated_at, sample_size, minimum_sample_not_met and benchmarks. Percentile metrics carry p25-p90; the membership_plugins and addons_enabled distributions carry sample and shares instead. |
Examples
Purge a page cache on benchmark update
add_action(
'benecaster_benchmarks_refreshed',
function ( array $payload ): void {
delete_transient( 'my_plugin_analytics_page_cache' );
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( sprintf(
'[Benecaster] Benchmarks refreshed. Sample size: %d. Calculated at: %s.',
$payload['sample_size'] ?? 0,
$payload['calculated_at'] ?? 'unknown'
) );
}
}
);
Notify an external monitoring service
add_action(
'benecaster_benchmarks_refreshed',
function ( array $payload ): void {
wp_remote_post(
'https://monitoring.example.com/webhooks/benecaster-benchmarks',
[
'body' => wp_json_encode( [
'event' => 'benchmarks_refreshed',
'calculated_at' => $payload['calculated_at'] ?? null,
'sample_size' => $payload['sample_size'] ?? null,
] ),
'headers' => [ 'Content-Type' => 'application/json' ],
'timeout' => 3,
'blocking' => false,
]
);
}
);
Notes
Modifications to $payload inside a callback have no effect on the cached transient value — this is an action, not a filter. Use benecaster_benchmarks_fetch_skip to prevent a refresh from running.
Need this built rather than just documented? See our services →