-
-
Save ituk/6aa866c39f008c1c420525f3cf0a8313 to your computer and use it in GitHub Desktop.
Learndash: bypass course limitations for group leaders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Helper function to check if current user is a course group leader **/ | |
function bayadaim_is_course_gl($course_id, $user_id){ | |
$is_course_gl = false; | |
if($course_id == ''){ | |
if ( empty( $post) ) { | |
global $post; | |
} | |
if( 'sfwd-lessons' === $post->post_type ){ | |
$course_id = learndash_get_setting( $post, 'course' ); | |
} | |
elseif( 'sfwd-topic' === $post->post_type ){ | |
$lesson_id = learndash_get_setting( $post, 'lesson' ); | |
$course_id = learndash_get_setting( $lesson_id, 'course' ); | |
} | |
elseif( 'sfwd-course' === $post->post_type ){ | |
$course_id = learndash_get_course_id( $post->ID ); | |
} | |
//probably should add quizz here as well | |
} | |
if($user_id == ''){ | |
$user_id = get_current_user_id(); | |
} | |
$group_ids = learndash_get_course_groups($course_id); | |
if(!empty($group_ids)){ | |
foreach($group_ids as $group_id){ | |
$group_leader_ids = learndash_get_groups_administrator_ids( $group_id ); | |
if(in_array($user_id, $group_leader_ids)){ | |
$is_course_gl = true; | |
continue; | |
} | |
} | |
}else{ | |
$is_course_gl = false; | |
} | |
return $is_course_gl; | |
} | |
/** Give group leader full access to all course content **/ | |
//set bypass to true | |
function bayadaim_prerequities_bypass( $bypass, $user_id, $post_id, $post ) { | |
$check = bayadaim_is_course_gl($course_id, $user_id); | |
if ( $check ) { | |
$bypass = true; | |
} | |
return $bypass; | |
} | |
add_filter( 'learndash_prerequities_bypass', 'bayadaim_prerequities_bypass', 10, 4 ); | |
//set previous step as completed | |
function bayadaim_previous_step_completed($completed, $post_id, $user_id){ | |
$check = bayadaim_is_course_gl($course_id, $user_id); | |
if ( $check ) { | |
$completed = true; | |
} | |
return $completed; | |
} | |
add_filter( 'learndash_previous_step_completed', 'bayadaim_previous_step_completed', 10, 3 ); | |
//show next step link | |
function bayadaim_show_next_link( $show_next_link = false, $user_id, $post_id ) { | |
$check = bayadaim_is_course_gl($course_id, $user_id); | |
if ( $check ) { | |
$show_next_link = true; | |
} | |
return $show_next_link; | |
} | |
add_filter('learndash_show_next_link', 'bayadaim_show_next_link', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment