benecaster_download_log_entry
Filters the download log row payload before it is written to the download log table. Return the (optionally modified) $data array to allow the row to be written, or return an empty array to skip persistence entirely for this request. When the row is skipped, the redirect still proceeds and the subscriber receives their audio file normally.
This hook fires on every proxied download request, regardless of subscriber tier or authentication state. The raw IP address is never passed — ip_hash is already a SHA-256 hash before this hook fires. Partial byte-range requests (common from podcast apps during stream probing) are logged with the byte_range key populated.
⚠ Returning a non-array skips the write just as an empty array does — the guard is ! is_array( $data ) || empty( $data ). That is the failure mode of forgetting to return $data: downloads simply stop appearing in analytics, with nothing logged to say why. Add a key only if the column exists; $wpdb->insert() fails on an unknown column and the row is dropped silently.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$data |
array |
— | The row about to be written to benecaster_download_log; return an empty array to skip the write |
$episode_id |
int |
— | ID of the episode |
$user_id |
int |
— | WordPress user ID of the downloading subscriber |
Returns:
array
Examples
Skip logging for an internal test account
add_filter(
'benecaster_download_log_entry',
function ( array $data, int $episode_id, int $user_id ): array {
$test_user_id = (int) get_option( 'benecaster_test_user_id' );
if ( $test_user_id > 0 && $user_id === $test_user_id ) {
return []; // Empty array skips persistence.
}
return $data;
},
10, 3
);
Exclude byte-range probe requests
add_filter(
'benecaster_download_log_entry',
function ( array $data, int $episode_id, int $user_id ): array {
// Many apps fire a short Range request before the real download.
if ( isset( $data['byte_range'] ) && str_starts_with( $data['byte_range'], 'bytes=0-' ) ) {
$range_end = (int) substr( $data['byte_range'], strlen( 'bytes=0-' ) );
if ( $range_end < 1024 ) {
return [];
}
}
return $data;
},
10, 3
);
Notes
Modifying episode_id or show_id inside $data does not change which audio file is served — those values are resolved before this hook fires. Skipping the log row suppresses the entry from all analytics views but does not prevent the download itself.
Need this built rather than just documented? See our services →