LifterLMS: Send Visitors to Login From Lessons
Redirects logged-out visitors who open a lesson or quiz to the login screen, then back to that lesson once they log in.
Opens WPIDE on
Code
if ( ! function_exists( 'llms_get_student' ) ) {
return;
}
add_action( 'template_redirect', function () {
if ( is_user_logged_in() || ! is_singular( array( 'lesson', 'llms_quiz' ) ) ) {
return;
}
if ( 'yes' === get_post_meta( get_queried_object_id(), '_llms_free_lesson', true ) ) {
return;
}
wp_safe_redirect( wp_login_url( get_permalink() ) );
exit;
} );
Notes
Free lessons marked as "free lesson" in LifterLMS stay open to everyone.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.