Dear WPLMS dev,
Is it possible to set maximum retake course/quiz per day?
Thanks
If you ask me it is possible, the answer is always yes. Turns out this one is easy :
add_filter('bp_course_fetch_user_quiz_retake_count',function($retake_count,$quiz_id,$user_id){
global $wpdb;
$retakes_in_oneday = $wpdb->get_var($wpdb->prepare( "
SELECT count(activity.content) FROM {$bp->activity->table_name} AS activity
WHERE activity.component = 'course'
AND activity.type = 'retake_quiz'
AND user_id = %d
AND ( item_id = %d OR secondary_item_id = %d )
AND date >= now() - INTERVAL 1 DAY
ORDER BY date_recorded DESC
" ,$user_id,$quiz_id,$quiz_id));
if(!empty($retakes_in_oneday)){
//user already attempted quiz once in last 1 day.
return 0;
}
return $retake_count;
});