dtm_can_download custom filter
-
Hello,
I have this business requirement :
Only allow members to download files if they downloaded less than 20 differents download this month.
So I tried this code in fonctions.php :
add_filter( 'dlm_can_download', array( $this, 'check_custom_rule' ), 10, 2 ); function check_custom_rule( $can_download, $download){ if ( false !== $can_download && $download->is_members_only() ) { if (is_user_logged_in() ) { $current_user = wp_get_current_user(); $current_user->ID; $querystr = "SELECT count(DISTINCT download_id) as count FROM wp_download_log WHERE user_id=$current_user->ID AND YEAR(download_date) = YEAR(NOW()) AND MONTH(download_date) = MONTH(NOW())"; $result = $wpdb->get_results($querystr, OBJECT); $nb_of_dl_this_month = $result[0]->count; if($nb_of_dl_this_month > 20 ){ $can_download = false; } else { $can_download = true; } } } return $can_download; }
But I got access access denied all the time even if I have downloaded only 1 file.
When I excecute this code outside of the filter, I got $can_download to true.
So smth wrong with the way I implemented this filter ?Thanks a lot ??
Regards,
Dorian
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘dtm_can_download custom filter’ is closed to new replies.