Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. if ( !function_exists( 'learn_press_course_content_summary' ) ) {
  2.     /**
  3.      * Display the content of a lesson in a course content
  4.      * @return int
  5.      */
  6.     function learn_press_course_content_summary() {
  7.         $lesson_id = isset( $_GET['lesson'] ) ? $_GET['lesson'] : '';
  8.         echo $lesson_id;
  9.  
  10.  
  11.         // this doesn't work
  12.         // $book_id = isset( $_GET['book'] ) ? $_GET['book'] : '';
  13.         // echo $book_id;
  14.  
  15.         global $post;
  16.         // ensure that we are passing the lesson correctly
  17.         if ( $lesson_id && ( 'lpr_lesson' == get_post_type( $lesson_id ) ) && ( $lesson = get_post( $lesson_id ) ) ) {
  18.             //check if user enrolled this course or not
  19.             $course_id    = get_the_ID();
  20.             $user_id      = get_current_user_id();
  21.             $user_courses = learn_press_get_user_courses( $user_id );
  22.             $enrolled     = false;
  23.             if ( isset( $user_courses ) && is_array( $user_courses ) ) {
  24.                 $enrolled = in_array( $course_id, $user_courses );
  25.             }
  26.             //if( !$enrolled && ! learn_press_is_lesson_preview( $lesson_id ) ) {
  27.             if ( !learn_press_user_can_view_lesson( $lesson_id ) ) {
  28.                 echo "You have to enrolled to see lesson content";
  29.                 do_action( 'learn_press_course_content_course' );
  30.                 return 0;
  31.             }
  32.  
  33.             // setup lesson as global post so we can uses the template function as in the loop
  34.             $post = $lesson;
  35.             setup_postdata( $post );
  36.             do_action( 'learn_press_course_content_lesson', $post );
  37.  
  38.             // now reset the post to the course
  39.             wp_reset_postdata();
  40.         } else {
  41.             do_action( 'learn_press_course_content_course' );
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement