Skip to content

Instantly share code, notes, and snippets.

@MrVibe
Last active January 30, 2018 06:26
Show Gist options
  • Save MrVibe/6053135b0d5b86d1936f96a6e5a2f54d to your computer and use it in GitHub Desktop.
Save MrVibe/6053135b0d5b86d1936f96a6e5a2f54d to your computer and use it in GitHub Desktop.
Assignment completion check in Courses
add_filter('wplms_finish_course_check',function($flag,$course_curriculum){
$user_id = get_current_user_id();
global $post;
if($post->post_type != 'course'){return $flag;}
$course_id = $post->ID;
global $wpdb;
$members_assignment_marks = $wpdb->get_results( $wpdb->prepare("SELECT meta_value as marks,post_id as assignment_id FROM {$wpdb->postmeta} where meta_key=%d AND post_id IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='vibe_assignment_course' AND meta_value = %d)",$user_id,$course_id), ARRAY_A);
if(isset($members_assignment_marks) && is_array($members_assignment_marks) && count($members_assignment_marks)){
foreach($members_assignment_marks as $members_assignment_mark){
//Check if include in Course evaluation is Switched "on" for assignment
$include_in_course = get_post_meta($members_assignment_mark['assignment_id'],'vibe_assignment_evaluation',true);
if(vibe_validate($include_in_course) && !empty($members_assignment_mark['marks'])){
return $members_assignment_mark['assignment_id'];
}
}
}
return $flag;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment