Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Created June 23, 2024 07:39
Show Gist options
  • Save MrVibe/f58e38d7b9867d212b111ffd96ac404e to your computer and use it in GitHub Desktop.
Save MrVibe/f58e38d7b9867d212b111ffd96ac404e to your computer and use it in GitHub Desktop.
WPLMS Quiz retake should include questions which were incorrect and exclude questions which were correct.
add_filter('bp_course_dynamic_quiz_tag_questions',function($args,$alltags,$quiz_id,$user_id){
//fetch result
$user_quiz_result = bp_course_get_quiz_results_meta($quiz_id,$user_id);
if(empty($user_quiz_result)){
return $args;
}
if(is_serialized($user_quiz_result)){
$user_quiz_result = unserialize($user_quiz_result);
}
$include_ids = $exclude_ids=[];
foreach($user_quiz_result as $q){
if((empty($q['marks']) || $q['marks'] <= 0) && !empty($q['id'])){
$include_ids[]=$q['id'];
}else{
$exclude_ids[]=$q['id'];
}
}
if(!empty($include_ids)){
$args['post__in']=$include_ids;
$args['post__not_in']=$exclude_ids;
}
return $args;
},10,4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment