Please add this code in your wp-content/plugins/wplms-customizer/wplms-customizer.php file :
add_action('wplms_evaluate_course','course_reset_on_finish',999,3);
function course_reset_on_finish($course_id,$marks,$user_id){
$status = bp_course_get_user_course_status($user_id,$course_id);
if(isset($status) && is_numeric($status)){ // Necessary for continue course
$course_curriculum=vibe_sanitize(get_post_meta($course_id,'vibe_course_curriculum',false));
update_user_meta($user_id,'progress'.$course_id,0);
foreach($course_curriculum as $c){
if(is_numeric($c)){
delete_user_meta($user_id,$c);
delete_post_meta($c,$user_id);
if(get_post_type($c) == 'quiz'){
$questions = vibe_sanitize(get_post_meta($c,'quiz_questions'.$user_id,false));
if(!isset($questions) || !is_array($questions)) // Fallback for Older versions
$questions = vibe_sanitize(get_post_meta($c,'vibe_quiz_questions',false));
else
delete_post_meta($c,'quiz_questions'.$user_id); // Re-capture new questions in quiz begining
if(isset($questions) && is_array($questions) && is_Array($questions['ques']))
foreach($questions['ques'] as $question){
global $wpdb;
if(isset($question) && $question !='' && is_numeric($question))
$wpdb->query($wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='trash' WHERE comment_post_ID=%d AND user_id=%d",$question,$user_id));
}
}
}
}
/*=== Fix in 1.5 : Reset Badges and CErtificates on Course Reset === */
$user_badges=vibe_sanitize(get_user_meta($user_id,'badges',false));
$user_certifications=vibe_sanitize(get_user_meta($user_id,'certificates',false));
if(isset($user_badges) && is_Array($user_badges) && in_array($course_id,$user_badges)){
$key=array_search($course_id,$user_badges);
unset($user_badges[$key]);
$user_badges = array_values($user_badges);
update_user_meta($user_id,'badges',$user_badges);
}
if(isset($user_certifications) && is_Array($user_certifications) && in_array($course_id,$user_certifications)){
$key=array_search($course_id,$user_certifications);
unset($user_certifications[$key]);
$user_certifications = array_values($user_certifications);
update_user_meta($user_id,'certificates',$user_certifications);
}
/*==== End Fix ======*/
echo '<p>'.__('Course Reset for User','vibe').'</p>';
do_action('wplms_course_reset',$course_id,$user_id);
}
}