Skip to content

Instantly share code, notes, and snippets.

@danjjohnson
Last active September 25, 2019 10:18
Show Gist options
  • Select an option

  • Save danjjohnson/3be69ac1ba29f22a1498 to your computer and use it in GitHub Desktop.

Select an option

Save danjjohnson/3be69ac1ba29f22a1498 to your computer and use it in GitHub Desktop.
Sensei - Display lessons on course page only for registered users
add_action( 'sensei_before_main_content', 'sensei_conditional_lesson_display', 10 );
function sensei_conditional_lesson_display() {
if( !is_singular('course') ) return;
global $post, $current_user, $woothemes_sensei;
$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
if ( ! ( $is_user_taking_course || sensei_all_access() ) ) {
remove_action( 'sensei_single_course_content_inside_after' , array( 'Sensei_Course','the_course_lessons_title'), 9 );
remove_action( 'sensei_single_course_content_inside_after', 'course_single_lessons', 10 );
remove_action( 'sensei_single_course_content_inside_after', array( Sensei()->modules, 'load_course_module_content_template' ), 8 );
}
}
@danjjohnson

Copy link
Copy Markdown
Author

Add this code to your theme's functions.php file. It will display the list of lessons on the single course page only for users who are taking the course.

@vince23

vince23 commented Jul 18, 2015

Copy link
Copy Markdown

Doesn't seem to work

@Kellylise

Copy link
Copy Markdown

Ditto - this no longer works

@danjjohnson

Copy link
Copy Markdown
Author

Updated to work with Sensei 1.9+

@danjjohnson

Copy link
Copy Markdown
Author

Updated to also work with modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment