Created
August 23, 2018 15:02
-
-
Save actual-saurabh/e9722d81353d5cb760122c1ba2f96ac1 to your computer and use it in GitHub Desktop.
LifterLMS Course redirect to first incomplete lesson
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
<?php // Do not copy this line | |
// Copy from under this line and paste into your child theme's functions.php | |
add_action( 'template_redirect', 'lifterlms_course_continue_redirect' ); | |
if ( ! function_exists( 'lifterlms_course_continue_redirect' ) ) { | |
function lifterlms_course_continue_redirect( $post_id = null, $student = null, $progress = null ) { | |
if ( ! $post_id ) { | |
$post_id = get_the_ID(); | |
if ( ! $post_id ) { | |
return ''; | |
} | |
} | |
$course = llms_get_post( $post_id ); | |
if ( ! $course || ! is_a( $course, 'LLMS_Post_Model' ) ) { | |
return ''; | |
} | |
if ( $course->get( 'type' ) != 'course' ) { | |
return ''; | |
} | |
if ( ! $student ) { | |
$student = llms_get_student(); | |
} | |
if ( ! $student || ! $student->exists() || ! llms_is_user_enrolled( $student->get_id(), $course->get( 'id' ) ) ) { | |
return ''; | |
} | |
if ( is_null( $progress ) ) { | |
$progress = $student->get_progress( $course->get( 'id' ), 'course' ); | |
} | |
if ( 100 == $progress ) { | |
return ''; | |
} else { | |
$lesson = $student->get_next_lesson( $course->get( 'id' ) ); | |
if ( $lesson ) { | |
wp_safe_redirect( get_permalink( $lesson ) ); | |
exit(); | |
} | |
} | |
} | |
}// End if(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment