Skip to main content

benecaster_download_log_entry

Filter Free

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.

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.