Append custom columns or short-circuit the write for download log rows
benecaster_download_log_entry is the last chance to change a download record before it is written. Use it to attach something of your own — a campaign the listener arrived from, say, stored in a column your add-on added — or to tidy a value Benecaster worked out.
It can also stop the write entirely. Hand back nothing and the record is not saved, and the benecaster_download_logged event that normally follows does not fire either. That is the intended way to exclude traffic you do not want counted — your own monitoring, a known bot — but it is a real deletion of data you will not get back, so be sure the test you are filtering on is right before you ship it.
Code
<?php
add_filter(
'benecaster_download_log_entry',
function ( array $data, int $episode_id, int $user_id ): array {
// Tag the row with a request-scoped campaign attribute.
$campaign = isset( $_GET['utm_campaign'] ) ? sanitize_key( wp_unslash( $_GET['utm_campaign'] ) ) : '';
if ( '' !== $campaign ) {
$data['campaign'] = $campaign;
}
return $data;
},
10,
3
);
Hooks Used
Need this built rather than just documented? See our services →