Hi @rqcmt
I believe the action hook you are looking for is edd_file_download_has_access
Try adjusting your code for that filter and see how that works: https://github.com/awesomemotive/easy-digital-downloads/blob/main/includes/process-download.php#L64
Thread Starter
rqcmt
(@rqcmt)
Hi Mihai,
Thanks for the quick reply and the advice!
As per your suggestion, I’ve tried using the edd_file_download_has_access filter, but I’m encountering some unexpected behavior.
Specifically, I’m seeing two main issues:
- Incorrect Argument Count: The filter sometimes fires with only 3 arguments instead of the expected 6.
- Filter Not Firing At All: After adjusting my code to handle the 3-argument scenario, the filter often stops firing completely.
Could these be known issues in EDD 3.3.9, or might something else be at play? Any insights you can offer would be greatly appreciated.
Thanks,
The filter only has 3 parameters that it passes. When you create your snippet, try setting the priority to 99 to make sure your code runs last in the process.
add_filter( 'edd_file_download_has_access', 'check_file_download', 99, 3 );
Thread Starter
rqcmt
(@rqcmt)
Thank you for your previous assistance with the edd_file_download_has_access. Following Mihai’s suggestion, I’ve adjusted my code to use the edd_file_download_has_access filter, but I’m still encountering unexpected behavior.
Problem Description:
Filter Not Firing Consistently:
Despite setting up the edd_file_download_has_access filter, it often doesn’t fire at all when a download attempt is made (my internal logs within the hook are not output).
When it does fire, I consistently see logs like DEBUG: Download ID: N/A | Payment ID: [numeric_value] and Logic Path: Invalid download object. Denying access., leading to download failures.
This suggests that the download ID isn’t being correctly retrieved by my custom code.
Question:
Is the issue of the edd_file_download_has_access filter not firing consistently, or not correctly providing the download ID, a known issue with EDD?
Could you please advise on the recommended way to reliably get the download ID when this filter is called, or if there are any other settings or environmental factors I should check?
Your continued help is greatly appreciated. Thank you.
Hi @rqcmt
can you share your custom code here so that I can run some tests on my end? Are you just using the core EDD plugin for file downloads or are there other extensions involved?
Thread Starter
rqcmt
(@rqcmt)
Hi Mihai,
Filter Not Firing Consistently: Despite setting up the edd_file_download_has_access filter, it often doesn’t fire at all when a download attempt is made (my internal logs within the hook are not output).
When it does fire, I consistently see logs like DEBUG: Download ID: N/A | Payment ID: [numeric_value] and Logic Path: Invalid download object. Denying access., which means the download ID is always invalid. This leads to download failures.
This suggests that the download ID isn’t being correctly retrieved by my custom code.
My Code:
Here’s the minimal version of the code I’m using:
function my_edd_restrict_download_after_expiration( $has_access, $download_id, $payment_meta ) {
// This log sometimes doesn't appear at all, and when it does, download_id is always 0 or invalid.
// error_log( 'DEBUG: edd_file_download_has_access filter fired. Download ID: ' . $download_id . ' | Payment Meta: ' . print_r( $payment_meta, true ) );
// My actual restriction logic would go here, but it's not reached consistently.
// For now, I'm just returning $has_access to see if the filter fires correctly.
return $has_access;
}
add_filter( 'edd_file_download_has_access', 'my_edd_restrict_download_after_expiration', 99, 3 );
Context:
I’m only using the core EDD functionality for file downloads. There are no other EDD extensions involved that might interfere with the download process.
Question:
Is the issue of the edd_file_download_has_access filter not firing consistently, or not correctly providing the download ID, a known issue with EDD?
Could you please advise on the recommended way to reliably get the download ID when this filter is called, or if there are any other settings or environmental factors I should check?
Your continued help is greatly appreciated. Thank you.
Hi,
Can you please reach out to our team here https://easydigitaldownloads.com/support/ so we can take a closer look at this?
@rqcmt a small update here.
The correct filter parameters would be these:
function my_edd_restrict_download_after_expiration( $has_access, $order_id, $download_args ) {
// This log sometimes doesn't appear at all, and when it does, download_id is always 0 or invalid.
error_log( 'DEBUG: edd_file_download_has_access filter fired. Order ID: ' . $order_id . ' | Download args: ' . print_r( $download_args, true ) );
// My actual restriction logic would go here, but it's not reached consistently.
// For now, I'm just returning $has_access to see if the filter fires correctly.
return $has_access;
}
add_filter( 'edd_file_download_has_access', 'my_edd_restrict_download_after_expiration', 99, 3 );
It is passing the $has_access, $order_id, and the $download_args.
From those $download_args, you could obtain the Download ID via $download_args[‘download’]. Try the snippet above and see if that’s what you need.
Thread Starter
rqcmt
(@rqcmt)
Hi Mihai,
Thank you so much for your help over such a long period regarding the issue with Easy Digital Downloads’ download expiration not working correctly. Thanks to your advice, I’m happy to report that the problem has finally been resolved!
The ultimate key to solving this was the correction to the parameters passed to the edd_file_download_has_access filter that you pointed out.
Thank you very much!