Completed
Push — master ( 92ad4d...5cef23 )
by Dwain
10:23
created
includes/class-sensei-grading.php 1 patch
Indentation   +419 added lines, -419 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 	/**
21 21
 	 * Constructor
22 22
 	 * @since  1.3.0
23
-     *
24
-     * @param $file
23
+	 *
24
+	 * @param $file
25 25
 	 */
26 26
 	public function __construct ( $file ) {
27 27
 		$this->name = __( 'Grading', 'woothemes-sensei' );
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * Outputs Grading general headers
232 232
 	 * @since  1.3.0
233
-     * @param array $args
233
+	 * @param array $args
234 234
 	 * @return void
235 235
 	 */
236 236
 	public function grading_headers( $args = array( 'nav' => 'default' ) ) {
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		}
283 283
 		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
284 284
 
285
-            $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
285
+			$user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
286 286
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
287 287
 
288 288
 		} // End If Statement
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		}
317 317
 		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
318 318
 
319
-            $user_name = Sensei_Learner::get_full_name( $_GET['user'] );
319
+			$user_name = Sensei_Learner::get_full_name( $_GET['user'] );
320 320
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
321 321
 
322 322
 		} // End If Statement
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	public function count_statuses( $args = array() ) {
366 366
 		global  $wpdb;
367 367
 
368
-        /**
369
-         * Filter fires inside Sensei_Grading::count_statuses
370
-         *
371
-         * Alter the the post_in array to determine which posts the
372
-         * comment query should be limited to.
373
-         * @since 1.8.0
374
-         * @param array $args
375
-         */
376
-        $args = apply_filters( 'sensei_count_statuses_args', $args );
368
+		/**
369
+		 * Filter fires inside Sensei_Grading::count_statuses
370
+		 *
371
+		 * Alter the the post_in array to determine which posts the
372
+		 * comment query should be limited to.
373
+		 * @since 1.8.0
374
+		 * @param array $args
375
+		 */
376
+		$args = apply_filters( 'sensei_count_statuses_args', $args );
377 377
 
378 378
 		if ( 'course' == $args['type'] ) {
379 379
 			$type = 'sensei_course_status';
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 
386 386
 		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s ";
387 387
 
388
-        // Restrict to specific posts
388
+		// Restrict to specific posts
389 389
 		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
390 390
 			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
391 391
 		}
@@ -520,148 +520,148 @@  discard block
 block discarded – undo
520 520
 		return $html;
521 521
 	} // End lessons_drop_down_html()
522 522
 
523
-    /**
524
-     * The process grading function handles admin grading submissions.
525
-     *
526
-     * This function is hooked on to admin_init. It simply accepts
527
-     * the grades as the Grader selected theme and saves the total grade and
528
-     * individual question grades.
529
-     *
530
-     * @return bool
531
-     */
532
-    public function admin_process_grading_submission() {
523
+	/**
524
+	 * The process grading function handles admin grading submissions.
525
+	 *
526
+	 * This function is hooked on to admin_init. It simply accepts
527
+	 * the grades as the Grader selected theme and saves the total grade and
528
+	 * individual question grades.
529
+	 *
530
+	 * @return bool
531
+	 */
532
+	public function admin_process_grading_submission() {
533 533
 
534
-        // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
-        if( ! isset( $_POST['sensei_manual_grade'] )
536
-            || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
-            || ! isset( $_GET['quiz_id'] )
538
-            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
534
+		// NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
+		if( ! isset( $_POST['sensei_manual_grade'] )
536
+			|| ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
+			|| ! isset( $_GET['quiz_id'] )
538
+			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
539 539
 
540
-            return false; //exit and do not grade
540
+			return false; //exit and do not grade
541 541
 
542
-        }
542
+		}
543 543
 
544
-        $quiz_id = $_GET['quiz_id'];
545
-        $user_id = $_GET['user'];
544
+		$quiz_id = $_GET['quiz_id'];
545
+		$user_id = $_GET['user'];
546 546
 
547 547
 
548
-        $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
-        $quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
-        $quiz_grade = 0;
551
-        $count = 0;
552
-        $quiz_grade_total = $_POST['quiz_grade_total'];
553
-        $all_question_grades = array();
554
-        $all_answers_feedback = array();
548
+		$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
+		$quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
+		$quiz_grade = 0;
551
+		$count = 0;
552
+		$quiz_grade_total = $_POST['quiz_grade_total'];
553
+		$all_question_grades = array();
554
+		$all_answers_feedback = array();
555 555
 
556
-        foreach( $questions as $question ) {
556
+		foreach( $questions as $question ) {
557 557
 
558
-            ++$count;
559
-            $question_id = $question->ID;
558
+			++$count;
559
+			$question_id = $question->ID;
560 560
 
561
-            if( isset( $_POST[ 'question_' . $question_id ] ) ) {
561
+			if( isset( $_POST[ 'question_' . $question_id ] ) ) {
562 562
 
563
-                $question_grade = 0;
564
-                if( $_POST[ 'question_' . $question_id ] == 'right' ) {
563
+				$question_grade = 0;
564
+				if( $_POST[ 'question_' . $question_id ] == 'right' ) {
565 565
 
566
-                    $question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
566
+					$question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
567 567
 
568
-                }
568
+				}
569 569
 
570
-                // add data to the array that will, after the loop, be stored on the lesson status
571
-                $all_question_grades[ $question_id ] = $question_grade;
570
+				// add data to the array that will, after the loop, be stored on the lesson status
571
+				$all_question_grades[ $question_id ] = $question_grade;
572 572
 
573
-                // tally up the total quiz grade
574
-                $quiz_grade += $question_grade;
573
+				// tally up the total quiz grade
574
+				$quiz_grade += $question_grade;
575 575
 
576
-            } // endif
576
+			} // endif
577 577
 
578
-            // Question answer feedback / notes
579
-            $question_feedback = '';
580
-            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
578
+			// Question answer feedback / notes
579
+			$question_feedback = '';
580
+			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
581 581
 
582
-                $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
582
+				$question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
583 583
 
584
-            }
585
-            $all_answers_feedback[ $question_id ] = $question_feedback;
584
+			}
585
+			$all_answers_feedback[ $question_id ] = $question_feedback;
586 586
 
587
-        } // end for each $questions
587
+		} // end for each $questions
588 588
 
589
-        //store all question grades on the lesson status
590
-        Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
589
+		//store all question grades on the lesson status
590
+		Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
591 591
 
592
-        //store the feedback from grading
593
-        Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
592
+		//store the feedback from grading
593
+		Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
594 594
 
595
-        // $_POST['all_questions_graded'] is set when all questions have been graded
596
-        // in the class sensei grading user quiz -> display()
597
-        if( $_POST['all_questions_graded'] == 'yes' ) {
595
+		// $_POST['all_questions_graded'] is set when all questions have been graded
596
+		// in the class sensei grading user quiz -> display()
597
+		if( $_POST['all_questions_graded'] == 'yes' ) {
598 598
 
599
-            // set the users total quiz grade
599
+			// set the users total quiz grade
600 600
 			if ( 0 < intval( $quiz_grade_total ) ) {
601
-            $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
601
+			$grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
602 602
 			}
603 603
 			else {
604 604
 				$grade = 0;
605 605
 			}
606
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
-
608
-            // Duplicating what Frontend->sensei_complete_quiz() does
609
-            $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
-            $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
-            $lesson_metadata = array();
612
-            if ( $pass_required ) {
613
-                // Student has reached the pass mark and lesson is complete
614
-                if ( $quiz_passmark <= $grade ) {
615
-                    $lesson_status = 'passed';
616
-                }
617
-                else {
618
-                    $lesson_status = 'failed';
619
-                } // End If Statement
620
-            }
621
-            // Student only has to partake the quiz
622
-            else {
623
-                $lesson_status = 'graded';
624
-            }
625
-            $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
606
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
+
608
+			// Duplicating what Frontend->sensei_complete_quiz() does
609
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
+			$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
+			$lesson_metadata = array();
612
+			if ( $pass_required ) {
613
+				// Student has reached the pass mark and lesson is complete
614
+				if ( $quiz_passmark <= $grade ) {
615
+					$lesson_status = 'passed';
616
+				}
617
+				else {
618
+					$lesson_status = 'failed';
619
+				} // End If Statement
620
+			}
621
+			// Student only has to partake the quiz
622
+			else {
623
+				$lesson_status = 'graded';
624
+			}
625
+			$lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
626 626
 
627
-            Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
627
+			Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
628 628
 
629
-            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
629
+			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
630 630
 
631
-                /**
632
-                 * Summary.
633
-                 *
634
-                 * Description.
635
-                 *
636
-                 * @since 1.7.0
637
-                 *
638
-                 * @param int  $user_id
639
-                 * @param int $quiz_lesson_id
640
-                 */
641
-                do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
631
+				/**
632
+				 * Summary.
633
+				 *
634
+				 * Description.
635
+				 *
636
+				 * @since 1.7.0
637
+				 *
638
+				 * @param int  $user_id
639
+				 * @param int $quiz_lesson_id
640
+				 */
641
+				do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
642 642
 
643
-            } // end if in_array
643
+			} // end if in_array
644 644
 
645
-        }// end if $_POST['all_que...
645
+		}// end if $_POST['all_que...
646 646
 
647
-        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
647
+		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
648 648
 
649
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
649
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
650 650
 
651
-        } elseif ( isset( $_POST['_wp_http_referer'] ) ) {
651
+		} elseif ( isset( $_POST['_wp_http_referer'] ) ) {
652 652
 
653
-            $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
653
+			$load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
654 654
 
655
-        } else {
655
+		} else {
656 656
 
657
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
657
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
658 658
 
659
-        }
659
+		}
660 660
 
661
-        wp_safe_redirect( esc_url_raw( $load_url ) );
662
-        exit;
661
+		wp_safe_redirect( esc_url_raw( $load_url ) );
662
+		exit;
663 663
 
664
-    } // end admin_process_grading_submission
664
+	} // end admin_process_grading_submission
665 665
 
666 666
 	public function get_redirect_url() {
667 667
 		// Parse POST data
@@ -706,398 +706,398 @@  discard block
 block discarded – undo
706 706
 		} // End If Statement
707 707
 	} // End sensei_grading_notices()
708 708
 
709
-    /**
710
-     * Grade quiz automatically
711
-     *
712
-     * This function grades each question automatically if there all questions are auto gradable. If not
713
-     * the quiz will not be auto gradable.
714
-     *
715
-     * @since 1.7.4
716
-     *
717
-     * @param  integer $quiz_id         ID of quiz
718
-     * @param  array $submitted questions id ans answers {
719
-     *          @type int $question_id
720
-     *          @type mixed $answer
721
-     * }
722
-     * @param  integer $total_questions Total questions in quiz (not used)
723
-     * @param string $quiz_grade_type Optional defaults to auto
724
-     *
725
-     * @return int $quiz_grade total sum of all question grades
726
-     */
727
-    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
-
729
-        if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
-            || $quiz_grade_type != 'auto' ) {
731
-            return false; // exit early
732
-        }
733
-
734
-
735
-        $user_id = get_current_user_id();
736
-        $lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
-        $quiz_autogradable = true;
738
-
739
-        /**
740
-         * Filter the types of question types that can be automatically graded.
741
-         *
742
-         * This filter fires inside the auto grade quiz function and provides you with the default list.
743
-         *
744
-         * @param array {
745
-         *      'multiple-choice',
746
-         *      'boolean',
747
-         *      'gap-fill'.
748
-         * }
749
-         */
750
-        $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
-
752
-        $grade_total = 0;
753
-        $all_question_grades = array();
754
-        foreach( $submitted as $question_id => $answer ) {
755
-
756
-            // check if the question is autogradable, either by type, or because the grade is 0
757
-            $question_type = Sensei()->question->get_question_type( $question_id );
709
+	/**
710
+	 * Grade quiz automatically
711
+	 *
712
+	 * This function grades each question automatically if there all questions are auto gradable. If not
713
+	 * the quiz will not be auto gradable.
714
+	 *
715
+	 * @since 1.7.4
716
+	 *
717
+	 * @param  integer $quiz_id         ID of quiz
718
+	 * @param  array $submitted questions id ans answers {
719
+	 *          @type int $question_id
720
+	 *          @type mixed $answer
721
+	 * }
722
+	 * @param  integer $total_questions Total questions in quiz (not used)
723
+	 * @param string $quiz_grade_type Optional defaults to auto
724
+	 *
725
+	 * @return int $quiz_grade total sum of all question grades
726
+	 */
727
+	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
+
729
+		if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
+			|| $quiz_grade_type != 'auto' ) {
731
+			return false; // exit early
732
+		}
733
+
734
+
735
+		$user_id = get_current_user_id();
736
+		$lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
+		$quiz_autogradable = true;
738
+
739
+		/**
740
+		 * Filter the types of question types that can be automatically graded.
741
+		 *
742
+		 * This filter fires inside the auto grade quiz function and provides you with the default list.
743
+		 *
744
+		 * @param array {
745
+		 *      'multiple-choice',
746
+		 *      'boolean',
747
+		 *      'gap-fill'.
748
+		 * }
749
+		 */
750
+		$autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
+
752
+		$grade_total = 0;
753
+		$all_question_grades = array();
754
+		foreach( $submitted as $question_id => $answer ) {
755
+
756
+			// check if the question is autogradable, either by type, or because the grade is 0
757
+			$question_type = Sensei()->question->get_question_type( $question_id );
758 758
 			$achievable_grade = Sensei()->question->get_question_grade( $question_id );
759 759
 			// Question has a zero grade, so skip grading
760 760
 			if ( 0 == $achievable_grade ) {
761 761
 				$all_question_grades[ $question_id ] = $achievable_grade;
762 762
 			}
763
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
-                // Get user question grade
765
-                $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
-                $all_question_grades[ $question_id ] = $question_grade;
767
-                $grade_total += $question_grade;
763
+			elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
+				// Get user question grade
765
+				$question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
+				$all_question_grades[ $question_id ] = $question_grade;
767
+				$grade_total += $question_grade;
768 768
 
769
-            } else {
769
+			} else {
770 770
 
771
-                // There is a question that cannot be autograded
772
-                $quiz_autogradable = false;
771
+				// There is a question that cannot be autograded
772
+				$quiz_autogradable = false;
773 773
 
774
-            } // end if in_array( $question_type...
774
+			} // end if in_array( $question_type...
775 775
 
776
-        }// end for each question
776
+		}// end for each question
777 777
 
778
-        // Only if the whole quiz was autogradable do we set a grade
779
-        if ( $quiz_autogradable ) {
778
+		// Only if the whole quiz was autogradable do we set a grade
779
+		if ( $quiz_autogradable ) {
780 780
 
781
-            $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
781
+			$quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
782 782
 			// Check for zero total from grades
783 783
 			if ( 0 < $quiz_total ) {
784
-            $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
784
+			$grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
785 785
 			}
786 786
 			else {
787 787
 				$grade = 0;
788 788
 			}
789
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
789
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
790 790
 
791
-        } else {
791
+		} else {
792 792
 
793
-            $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
793
+			$grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
794 794
 
795
-        }
796
-
797
-        // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
-        // when doing manual grading.
799
-        Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
795
+		}
800 796
 
801
-        return $grade;
797
+		// store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
+		// when doing manual grading.
799
+		Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
802 800
 
803
-    } // End grade_quiz_auto()
801
+		return $grade;
804 802
 
805
-    /**
806
-     * Grade question automatically
807
-     *
808
-     * This function checks the question typ and then grades it accordingly.
809
-     *
810
-     * @since 1.7.4
811
-     *
812
-     * @param integer $question_id
813
-     * @param string $question_type of the standard Sensei question types
814
-     * @param string $answer
815
-     * @param int $user_id
816
-     *
817
-     * @return int $question_grade
818
-     */
819
-    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
820
-
821
-        if( intval( $user_id ) == 0 ) {
822
-
823
-            $user_id = get_current_user_id();
824
-
825
-        }
826
-
827
-        if( ! ( intval( $question_id ) > 0 ) ) {
828
-
829
-            return false;
830
-
831
-        }
832
-
833
-
834
-        Sensei()->question->get_question_type( $question_id );
835
-
836
-        /**
837
-         * Applying a grade before the auto grading takes place.
838
-         *
839
-         * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
-         * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
-         * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
-         *
843
-         * @param int $question_grade default false
844
-         * @param int $question_id
845
-         * @param string $question_type one of the Sensei question type.
846
-         * @param string $answer user supplied question answer
847
-         */
848
-        $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
803
+	} // End grade_quiz_auto()
849 804
 
850
-        if ( false !== $question_grade ) {
805
+	/**
806
+	 * Grade question automatically
807
+	 *
808
+	 * This function checks the question typ and then grades it accordingly.
809
+	 *
810
+	 * @since 1.7.4
811
+	 *
812
+	 * @param integer $question_id
813
+	 * @param string $question_type of the standard Sensei question types
814
+	 * @param string $answer
815
+	 * @param int $user_id
816
+	 *
817
+	 * @return int $question_grade
818
+	 */
819
+	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
851 820
 
852
-            return $question_grade;
821
+		if( intval( $user_id ) == 0 ) {
853 822
 
854
-        }
823
+			$user_id = get_current_user_id();
855 824
 
856
-        // auto grading core
857
-        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
825
+		}
858 826
 
859
-            $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
827
+		if( ! ( intval( $question_id ) > 0 ) ) {
860 828
 
861
-            if( 0 == get_magic_quotes_gpc() ) {
862
-                $answer = wp_unslash( $answer );
863
-            }
864
-            $answer = (array) $answer;
865
-            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
-                // Loop through all answers ensure none are 'missing'
867
-                $all_correct = true;
868
-                foreach ( $answer as $check_answer ) {
869
-                    if ( !in_array( $check_answer, $right_answer ) ) {
870
-                        $all_correct = false;
871
-                    }
872
-                }
873
-                // If all correct then grade
874
-                if ( $all_correct ) {
875
-                    $question_grade = Sensei()->question->get_question_grade( $question_id );
876
-                }
877
-            }
829
+			return false;
878 830
 
879
-        } elseif( 'gap-fill' == $question_type ){
831
+		}
880 832
 
881
-            $question_grade = self::grade_gap_fill_question( $question_id ,$answer );
882 833
 
883
-        } else{
834
+		Sensei()->question->get_question_type( $question_id );
884 835
 
885
-            /**
886
-             * Grading questions that are not auto gradable.
887
-             *
888
-             * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
-             * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
-             *
891
-             * @param int $question_grade default zero
892
-             * @param int $question_id
893
-             * @param string $question_type one of the Sensei question type.
894
-             * @param string $answer user supplied question answer
895
-             */
896
-            $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
836
+		/**
837
+		 * Applying a grade before the auto grading takes place.
838
+		 *
839
+		 * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
+		 * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
+		 * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
+		 *
843
+		 * @param int $question_grade default false
844
+		 * @param int $question_id
845
+		 * @param string $question_type one of the Sensei question type.
846
+		 * @param string $answer user supplied question answer
847
+		 */
848
+		$question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
897 849
 
898
-        } // end if $question_type
850
+		if ( false !== $question_grade ) {
899 851
 
900
-        return $question_grade;
901
-    } // end grade_question_auto
852
+			return $question_grade;
902 853
 
903
-    /**
904
-     * Grading logic specifically for the gap fill questions
905
-     *
906
-     * @since 1.9.0
907
-     * @param $question_id
908
-     * @param $user_answer
909
-     *
910
-     * @return bool | int false or the grade given to the user answer
911
-     */
912
-    public static function grade_gap_fill_question( $question_id, $user_answer ){
854
+		}
913 855
 
914
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
-        $gapfill_array = explode( '||', $right_answer );
856
+		// auto grading core
857
+		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
916 858
 
917
-        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
-            $user_answer = wp_unslash( $user_answer );
919
-        }
859
+			$right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
920 860
 
921
-        /**
922
-         * case sensitive grading filter
923
-         *
924
-         * alter the value simply use this code in your plugin or the themes functions.php
925
-         * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
-         *
927
-         * @param bool $do_case_sensitive_comparison default false.
928
-         *
929
-         * @since 1.9.0
930
-         */
931
-        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
861
+			if( 0 == get_magic_quotes_gpc() ) {
862
+				$answer = wp_unslash( $answer );
863
+			}
864
+			$answer = (array) $answer;
865
+			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
+				// Loop through all answers ensure none are 'missing'
867
+				$all_correct = true;
868
+				foreach ( $answer as $check_answer ) {
869
+					if ( !in_array( $check_answer, $right_answer ) ) {
870
+						$all_correct = false;
871
+					}
872
+				}
873
+				// If all correct then grade
874
+				if ( $all_correct ) {
875
+					$question_grade = Sensei()->question->get_question_grade( $question_id );
876
+				}
877
+			}
932 878
 
933
-        if( $do_case_sensitive_comparison ){
879
+		} elseif( 'gap-fill' == $question_type ){
934 880
 
935
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
-            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
881
+			$question_grade = self::grade_gap_fill_question( $question_id ,$answer );
937 882
 
938
-                return Sensei()->question->get_question_grade( $question_id );
883
+		} else{
939 884
 
940
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
885
+			/**
886
+			 * Grading questions that are not auto gradable.
887
+			 *
888
+			 * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
+			 * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
+			 *
891
+			 * @param int $question_grade default zero
892
+			 * @param int $question_id
893
+			 * @param string $question_type one of the Sensei question type.
894
+			 * @param string $answer user supplied question answer
895
+			 */
896
+			$question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
941 897
 
942
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
898
+		} // end if $question_type
943 899
 
944
-                    return Sensei()->question->get_question_grade($question_id);
900
+		return $question_grade;
901
+	} // end grade_question_auto
945 902
 
946
-                }else{
903
+	/**
904
+	 * Grading logic specifically for the gap fill questions
905
+	 *
906
+	 * @since 1.9.0
907
+	 * @param $question_id
908
+	 * @param $user_answer
909
+	 *
910
+	 * @return bool | int false or the grade given to the user answer
911
+	 */
912
+	public static function grade_gap_fill_question( $question_id, $user_answer ){
947 913
 
948
-                    return false;
914
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
+		$gapfill_array = explode( '||', $right_answer );
949 916
 
950
-                }
917
+		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
+			$user_answer = wp_unslash( $user_answer );
919
+		}
951 920
 
952
-            }else{
921
+		/**
922
+		 * case sensitive grading filter
923
+		 *
924
+		 * alter the value simply use this code in your plugin or the themes functions.php
925
+		 * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
+		 *
927
+		 * @param bool $do_case_sensitive_comparison default false.
928
+		 *
929
+		 * @since 1.9.0
930
+		 */
931
+		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
953 932
 
954
-                return false;
933
+		if( $do_case_sensitive_comparison ){
955 934
 
956
-            }
935
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
+			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
957 937
 
958
-        }else{
938
+				return Sensei()->question->get_question_grade( $question_id );
959 939
 
960
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
-            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
940
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
962 941
 
963
-               return Sensei()->question->get_question_grade( $question_id );
942
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
964 943
 
965
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
944
+					return Sensei()->question->get_question_grade($question_id);
966 945
 
967
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
946
+				}else{
968 947
 
969
-                    return  Sensei()->question->get_question_grade( $question_id );
948
+					return false;
970 949
 
971
-                }else{
950
+				}
972 951
 
973
-                    return false;
952
+			}else{
974 953
 
975
-                }
954
+				return false;
976 955
 
977
-            }else{
956
+			}
957
+
958
+		}else{
959
+
960
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
+			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
962
+
963
+			   return Sensei()->question->get_question_grade( $question_id );
964
+
965
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
966
+
967
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
968
+
969
+					return  Sensei()->question->get_question_grade( $question_id );
970
+
971
+				}else{
972
+
973
+					return false;
974
+
975
+				}
978 976
 
979
-                return false;
977
+			}else{
978
+
979
+				return false;
980
+
981
+			}
982
+
983
+		}
984
+
985
+	}
986
+
987
+	/**
988
+	 * Counts the lessons that have been graded manually and automatically
989
+	 *
990
+	 * @since 1.9.0
991
+	 * @return int $number_of_graded_lessons
992
+	 */
993
+	public static function get_graded_lessons_count(){
980 994
 
981
-            }
995
+		global $wpdb;
982 996
 
983
-        }
997
+		$comment_query_piece[ 'select']  = "SELECT   COUNT(*) AS total";
998
+		$comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
999
+		$comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade')";
1000
+		$comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
984 1001
 
985
-    }
1002
+		$comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1003
+		$number_of_graded_lessons = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
986 1004
 
987
-    /**
988
-     * Counts the lessons that have been graded manually and automatically
989
-     *
990
-     * @since 1.9.0
991
-     * @return int $number_of_graded_lessons
992
-     */
993
-    public static function get_graded_lessons_count(){
1005
+		return $number_of_graded_lessons;
1006
+	}
994 1007
 
995
-        global $wpdb;
1008
+	/**
1009
+	 * Add together all the graded lesson grades
1010
+	 *
1011
+	 * @since 1.9.0
1012
+	 * @return double $sum_of_all_grades
1013
+	 */
1014
+	public static function get_graded_lessons_sum(){
996 1015
 
997
-        $comment_query_piece[ 'select']  = "SELECT   COUNT(*) AS total";
998
-        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
999
-        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade')";
1000
-        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1016
+		global $wpdb;
1001 1017
 
1002
-        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1003
-        $number_of_graded_lessons = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1018
+		$comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1019
+		$comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1020
+		$comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade')";
1021
+		$comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1004 1022
 
1005
-        return $number_of_graded_lessons;
1006
-    }
1023
+		$comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1024
+		$sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1007 1025
 
1008
-    /**
1009
-     * Add together all the graded lesson grades
1010
-     *
1011
-     * @since 1.9.0
1012
-     * @return double $sum_of_all_grades
1013
-     */
1014
-    public static function get_graded_lessons_sum(){
1026
+		return $sum_of_all_grades;
1015 1027
 
1016
-        global $wpdb;
1028
+	}
1017 1029
 
1018
-        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1019
-        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1020
-        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade')";
1021
-        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1030
+	/**
1031
+	 * Get the sum of all grades for the given user.
1032
+	 *
1033
+	 * @since 1.9.0
1034
+	 * @param $user_id
1035
+	 * @return double
1036
+	 */
1037
+	public static function get_user_graded_lessons_sum( $user_id ){
1038
+		global $wpdb;
1022 1039
 
1023
-        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1024
-        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1040
+		$clean_user_id = esc_sql( $user_id);
1041
+		$comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1042
+		$comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1043
+		$comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade') AND {$wpdb->comments}.user_id = {$clean_user_id} ";
1044
+		$comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1025 1045
 
1026
-        return $sum_of_all_grades;
1046
+		$comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1047
+		$sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1027 1048
 
1028
-    }
1049
+		return $sum_of_all_grades;
1050
+	}
1029 1051
 
1030
-    /**
1031
-     * Get the sum of all grades for the given user.
1032
-     *
1033
-     * @since 1.9.0
1034
-     * @param $user_id
1035
-     * @return double
1036
-     */
1037
-    public static function get_user_graded_lessons_sum( $user_id ){
1038
-        global $wpdb;
1052
+	/**
1053
+	 * Get the sum of all user grades for the given lesson.
1054
+	 *
1055
+	 * @since 1.9.0
1056
+	 *
1057
+	 * @param int lesson_id
1058
+	 * @return double
1059
+	 */
1060
+	public static function get_lessons_users_grades_sum( $lesson_id ){
1039 1061
 
1040
-        $clean_user_id = esc_sql( $user_id);
1041
-        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1042
-        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1043
-        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade') AND {$wpdb->comments}.user_id = {$clean_user_id} ";
1044
-        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1062
+		global $wpdb;
1045 1063
 
1046
-        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1047
-        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1064
+		$clean_lesson_id = esc_sql( $lesson_id);
1065
+		$comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1066
+		$comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1067
+		$comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade') AND {$wpdb->comments}.comment_post_ID = {$clean_lesson_id} ";
1068
+		$comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1048 1069
 
1049
-        return $sum_of_all_grades;
1050
-    }
1070
+		$comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1071
+		$sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1051 1072
 
1052
-    /**
1053
-     * Get the sum of all user grades for the given lesson.
1054
-     *
1055
-     * @since 1.9.0
1056
-     *
1057
-     * @param int lesson_id
1058
-     * @return double
1059
-     */
1060
-    public static function get_lessons_users_grades_sum( $lesson_id ){
1073
+		return $sum_of_all_grades;
1061 1074
 
1062
-        global $wpdb;
1075
+	}//get_lessons_user_grades_sum
1063 1076
 
1064
-        $clean_lesson_id = esc_sql( $lesson_id);
1065
-        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1066
-        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1067
-        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_lesson_status') AND ( wp_commentmeta.meta_key = 'grade') AND {$wpdb->comments}.comment_post_ID = {$clean_lesson_id} ";
1068
-        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1077
+	/**
1078
+	 * Get the sum of all user grades for the given course.
1079
+	 *
1080
+	 * @since 1.9.0
1081
+	 *
1082
+	 * @param int $course_id
1083
+	 * @return double
1084
+	 */
1085
+	public static function get_course_users_grades_sum( $course_id ){
1069 1086
 
1070
-        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1071
-        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1087
+		global $wpdb;
1072 1088
 
1073
-        return $sum_of_all_grades;
1089
+		$clean_course_id = esc_sql( $course_id);
1090
+		$comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1091
+		$comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1092
+		$comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_course_status') AND ( wp_commentmeta.meta_key = 'percent') AND {$wpdb->comments}.comment_post_ID = {$clean_course_id} ";
1093
+		$comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1074 1094
 
1075
-    }//get_lessons_user_grades_sum
1095
+		$comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1096
+		$sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1076 1097
 
1077
-    /**
1078
-     * Get the sum of all user grades for the given course.
1079
-     *
1080
-     * @since 1.9.0
1081
-     *
1082
-     * @param int $course_id
1083
-     * @return double
1084
-     */
1085
-    public static function get_course_users_grades_sum( $course_id ){
1086
-
1087
-        global $wpdb;
1088
-
1089
-        $clean_course_id = esc_sql( $course_id);
1090
-        $comment_query_piece[ 'select']  = "SELECT SUM({$wpdb->commentmeta}.meta_value) AS meta_sum";
1091
-        $comment_query_piece[ 'from']    = " FROM {$wpdb->comments}  INNER JOIN {$wpdb->commentmeta}  ON ( {$wpdb->comments}.comment_ID = {$wpdb->commentmeta}.comment_id ) ";
1092
-        $comment_query_piece[ 'where']   = " WHERE {$wpdb->comments}.comment_type IN ('sensei_course_status') AND ( wp_commentmeta.meta_key = 'percent') AND {$wpdb->comments}.comment_post_ID = {$clean_course_id} ";
1093
-        $comment_query_piece[ 'orderby'] = " ORDER BY {$wpdb->comments}.comment_date_gmt DESC ";
1098
+		return $sum_of_all_grades;
1094 1099
 
1095
-        $comment_query = $comment_query_piece['select'] . $comment_query_piece['from'] . $comment_query_piece['where'] . $comment_query_piece['orderby'];
1096
-        $sum_of_all_grades = intval( $wpdb->get_var( $comment_query, 0, 0 ) );
1097
-
1098
-        return $sum_of_all_grades;
1099
-
1100
-    }//get_lessons_user_grades_sum
1100
+	}//get_lessons_user_grades_sum
1101 1101
 
1102 1102
 } // End Class
1103 1103
 
Please login to merge, or discard this patch.
includes/class-sensei-course.php 1 patch
Indentation   +1444 added lines, -1444 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Sensei_Course {
14 14
 
15
-    /**
16
-     * @var $token
17
-     */
15
+	/**
16
+	 * @var $token
17
+	 */
18 18
 	public $token;
19 19
 
20
-    /**
21
-     * @var array $meta_fields
22
-     */
20
+	/**
21
+	 * @var array $meta_fields
22
+	 */
23 23
 	public $meta_fields;
24 24
 
25
-    /**
26
-     * @var string|bool $my_courses_page reference to the sites
27
-     * my courses page, false if none was set
28
-     */
29
-    public  $my_courses_page;
25
+	/**
26
+	 * @var string|bool $my_courses_page reference to the sites
27
+	 * my courses page, false if none was set
28
+	 */
29
+	public  $my_courses_page;
30 30
 
31 31
 	/**
32 32
 	 * Constructor.
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function __construct () {
36 36
 
37
-        $this->token = 'course';
37
+		$this->token = 'course';
38 38
 
39 39
 		// Setup meta fields for this post type
40 40
 		$this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' );
41 41
 		// Admin actions
42 42
 		if ( is_admin() ) {
43 43
 			// Metabox functions
44
-            add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
44
+			add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
45 45
 			add_action( 'save_post', array( $this, 'meta_box_save' ) );
46 46
 			// Custom Write Panel Columns
47 47
 			add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 );
@@ -57,47 +57,47 @@  discard block
 block discarded – undo
57 57
 		// Update course completion upon grading of a quiz
58 58
 		add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 );
59 59
 
60
-        // show the progress bar ont he single course page
61
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
62
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
60
+		// show the progress bar ont he single course page
61
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
62
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
63 63
 
64
-        // provide an option to block all emails related to a selected course
65
-        add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
66
-        add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
64
+		// provide an option to block all emails related to a selected course
65
+		add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
66
+		add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
67 67
 
68
-        // preview lessons on the course content
69
-        add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
68
+		// preview lessons on the course content
69
+		add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
70 70
 
71
-        // the course meta
72
-        add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
71
+		// the course meta
72
+		add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
73 73
 
74
-        // backwards compatible template hooks
75
-        add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
76
-        add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
74
+		// backwards compatible template hooks
75
+		add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
76
+		add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
77 77
 
78
-        // add the user status on the course to the markup as a class
79
-        add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
78
+		// add the user status on the course to the markup as a class
79
+		add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
80 80
 
81
-        //filter the course query in Sensei specific instances
82
-        add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
81
+		//filter the course query in Sensei specific instances
82
+		add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
83 83
 
84
-        //attache the sorting to the course archive
85
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
84
+		//attache the sorting to the course archive
85
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
86 86
 
87
-        //attach the filter links to the course archive
88
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
87
+		//attach the filter links to the course archive
88
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
89 89
 
90
-        //filter the course query when featured filter is applied
91
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
90
+		//filter the course query when featured filter is applied
91
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
92 92
 
93
-        // handle the order by title post submission
94
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
93
+		// handle the order by title post submission
94
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
95 95
 
96
-        // ensure the course category page respects the manual order set for courses
97
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
96
+		// ensure the course category page respects the manual order set for courses
97
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
98 98
 
99
-        // flush rewrite rules when saving a course
100
-        add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
99
+		// flush rewrite rules when saving a course
100
+		add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
101 101
 
102 102
 	} // End __construct()
103 103
 
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 		add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' );
151 151
 		// Add Meta Box for Course Lessons
152 152
 		add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' );
153
-        // Add Meta Box to link to Manage Learners
154
-        add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
155
-        // Remove "Custom Settings" meta box.
153
+		// Add Meta Box to link to Manage Learners
154
+		add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
155
+		// Remove "Custom Settings" meta box.
156 156
 		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
157 157
 
158
-        // add Disable email notification box
159
-        add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
158
+		// add Disable email notification box
159
+		add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
160 160
 
161 161
 	} // End meta_box_setup()
162 162
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 		$post_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
175 175
 							'posts_per_page' 		=> -1,
176 176
 							'orderby'         	=> 'title',
177
-    						'order'           	=> 'DESC',
178
-    						'exclude' 			=> $post->ID,
179
-    						'post_status'		=> array( 'publish', 'private', 'draft' ),
180
-    						'tax_query'			=> array(
177
+							'order'           	=> 'DESC',
178
+							'exclude' 			=> $post->ID,
179
+							'post_status'		=> array( 'publish', 'private', 'draft' ),
180
+							'tax_query'			=> array(
181 181
 								array(
182 182
 									'taxonomy'	=> 'product_type',
183 183
 									'field'		=> 'slug',
@@ -205,21 +205,21 @@  discard block
 block discarded – undo
205 205
 						$product_object = get_product( $post_item->ID );
206 206
 						$parent_id = wp_get_post_parent_id( $post_item->ID );
207 207
 
208
-                        if( sensei_check_woocommerce_version( '2.1' ) ) {
208
+						if( sensei_check_woocommerce_version( '2.1' ) ) {
209 209
 							$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
210 210
 
211 211
 						} else {
212
-                            // fall back to pre wc 2.1
212
+							// fall back to pre wc 2.1
213 213
 							$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
214 214
 
215 215
 						}
216 216
 
217
-                        $product_name = ucwords( $formatted_variation );
218
-                        if( empty( $product_name ) ){
217
+						$product_name = ucwords( $formatted_variation );
218
+						if( empty( $product_name ) ){
219 219
 
220
-                            $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
220
+							$product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
221 221
 
222
-                        }
222
+						}
223 223
 
224 224
 					} else {
225 225
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 			} else {
271 271
 
272
-                $html .= '<p>' . "\n";
272
+				$html .= '<p>' . "\n";
273 273
 					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n";
274 274
 				$html .= '</p>'."\n";
275 275
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 		$post_args = array(	'post_type' 		=> 'course',
296 296
 							'posts_per_page' 		=> -1,
297 297
 							'orderby'         	=> 'title',
298
-    						'order'           	=> 'DESC',
299
-    						'exclude' 			=> $post->ID,
298
+							'order'           	=> 'DESC',
299
+							'exclude' 			=> $post->ID,
300 300
 							'suppress_filters' 	=> 0
301 301
 							);
302 302
 		$posts_array = get_posts( $post_args );
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 		$checked = '';
339 339
 		if ( isset( $course_featured ) && ( '' != $course_featured ) ) {
340
-	 	    $checked = checked( 'featured', $course_featured, false );
340
+	 		$checked = checked( 'featured', $course_featured, false );
341 341
 	 	} // End If Statement
342 342
 
343 343
 	 	$html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '>&nbsp;' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>';
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
433 433
 		} // End If Statement
434 434
 
435
-        // update field with the new value
436
-        return update_post_meta( $post_id, $meta_key, $new_meta_value );
435
+		// update field with the new value
436
+		return update_post_meta( $post_id, $meta_key, $new_meta_value );
437 437
 
438 438
 	} // End save_post_meta()
439 439
 
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 
458 458
 		$html = '';
459 459
 		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="'
460
-                 . esc_attr( 'woo_' . $this->token . '_noonce' )
461
-                 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
460
+				 . esc_attr( 'woo_' . $this->token . '_noonce' )
461
+				 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
462 462
 
463 463
 		if ( count( $posts_array ) > 0 ) {
464 464
 
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 			$html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n";
480 480
 
481 481
 				$html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id )
482
-                         . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
483
-                         . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
482
+						 . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
483
+						 . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
484 484
 
485 485
 			$html .= '</p>'."\n";
486 486
 		} // End If Statement
@@ -489,29 +489,29 @@  discard block
 block discarded – undo
489 489
 
490 490
 	} // End course_lessons_meta_box_content()
491 491
 
492
-    /**
493
-     * course_manage_meta_box_content function.
494
-     *
495
-     * @since 1.9.0
496
-     * @access public
497
-     * @return void
498
-     */
492
+	/**
493
+	 * course_manage_meta_box_content function.
494
+	 *
495
+	 * @since 1.9.0
496
+	 * @access public
497
+	 * @return void
498
+	 */
499 499
 
500
-    public function course_manage_meta_box_content () {
501
-        global $post;
500
+	public function course_manage_meta_box_content () {
501
+		global $post;
502 502
         
503
-        $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
503
+		$manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
504 504
 
505
-        $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
505
+		$grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
506 506
 
507 507
 
508
-        echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
508
+		echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
509 509
 
510
-        echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
510
+		echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
511 511
 
512 512
 
513 513
 
514
-    } // End course_manage_meta_box_content()
514
+	} // End course_manage_meta_box_content()
515 515
 
516 516
 	/**
517 517
 	 * Add column headings to the "lesson" post list screen.
@@ -652,92 +652,92 @@  discard block
 block discarded – undo
652 652
 			} // End If Statement
653 653
 		} // End If Statement
654 654
 
655
-        $stored_order = get_option( 'sensei_course_order', '' );
656
-        $order = 'ASC';
657
-        $orderby = 'menu_order';
658
-        if( empty( $stored_order ) ){
655
+		$stored_order = get_option( 'sensei_course_order', '' );
656
+		$order = 'ASC';
657
+		$orderby = 'menu_order';
658
+		if( empty( $stored_order ) ){
659 659
 
660
-            $order = 'DESC';
661
-            $orderby = 'date';
660
+			$order = 'DESC';
661
+			$orderby = 'date';
662 662
 
663
-        }
663
+		}
664 664
 
665 665
 		switch ($type) {
666 666
 
667 667
 			case 'usercourses':
668 668
 				$post_args = array(	'post_type' 		=> 'course',
669 669
 									'orderby'         	=> $orderby,
670
-    								'order'           	=> $order,
671
-    								'post_status'      	=> 'publish',
672
-    								'include'			=> $includes,
673
-    								'exclude'			=> $excludes,
674
-    								'suppress_filters' 	=> 0
670
+									'order'           	=> $order,
671
+									'post_status'      	=> 'publish',
672
+									'include'			=> $includes,
673
+									'exclude'			=> $excludes,
674
+									'suppress_filters' 	=> 0
675 675
 									);
676 676
 				break;
677 677
 			case 'freecourses':
678 678
 
679
-                $post_args = array(
680
-                    'post_type' 		=> 'course',
681
-                    'orderby'         	=> $orderby,
682
-                    'order'           	=> $order,
683
-                    'post_status'      	=> 'publish',
684
-                    'exclude'			=> $excludes,
685
-                    'suppress_filters' 	=> 0
686
-                );
687
-                // Sub Query to get all WooCommerce Products that have Zero price
688
-                $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
679
+				$post_args = array(
680
+					'post_type' 		=> 'course',
681
+					'orderby'         	=> $orderby,
682
+					'order'           	=> $order,
683
+					'post_status'      	=> 'publish',
684
+					'exclude'			=> $excludes,
685
+					'suppress_filters' 	=> 0
686
+				);
687
+				// Sub Query to get all WooCommerce Products that have Zero price
688
+				$post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
689 689
 
690
-                break;
690
+				break;
691 691
 
692 692
 			case 'paidcourses':
693 693
 
694
-                $post_args = array(
695
-                    'post_type' 		=> 'course',
696
-                    'orderby'         	=> $orderby,
697
-                    'order'           	=> $order,
698
-                    'post_status'      	=> 'publish',
699
-                    'exclude'			=> $excludes,
700
-                    'suppress_filters' 	=> 0
701
-                );
694
+				$post_args = array(
695
+					'post_type' 		=> 'course',
696
+					'orderby'         	=> $orderby,
697
+					'order'           	=> $order,
698
+					'post_status'      	=> 'publish',
699
+					'exclude'			=> $excludes,
700
+					'suppress_filters' 	=> 0
701
+				);
702 702
 
703
-                // Sub Query to get all WooCommerce Products that have price greater than zero
704
-                $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
703
+				// Sub Query to get all WooCommerce Products that have price greater than zero
704
+				$post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
705 705
 
706 706
 				break;
707 707
 
708 708
 			case 'featuredcourses':
709
-                $post_args = array(	'post_type' 		=> 'course',
710
-                                    'orderby'         	=> $orderby,
711
-                                    'order'           	=> $order,
712
-    								'post_status'      	=> 'publish',
713
-    								'meta_value' 		=> 'featured',
714
-    								'meta_key' 			=> '_course_featured',
715
-    								'meta_compare' 		=> '=',
716
-    								'exclude'			=> $excludes,
717
-    								'suppress_filters' 	=> 0
709
+				$post_args = array(	'post_type' 		=> 'course',
710
+									'orderby'         	=> $orderby,
711
+									'order'           	=> $order,
712
+									'post_status'      	=> 'publish',
713
+									'meta_value' 		=> 'featured',
714
+									'meta_key' 			=> '_course_featured',
715
+									'meta_compare' 		=> '=',
716
+									'exclude'			=> $excludes,
717
+									'suppress_filters' 	=> 0
718 718
 									);
719 719
 				break;
720 720
 			default:
721 721
 				$post_args = array(	'post_type' 		=> 'course',
722
-                                    'orderby'         	=> $orderby,
723
-                                    'order'           	=> $order,
724
-    								'post_status'      	=> 'publish',
725
-    								'exclude'			=> $excludes,
726
-    								'suppress_filters' 	=> 0
722
+									'orderby'         	=> $orderby,
723
+									'order'           	=> $order,
724
+									'post_status'      	=> 'publish',
725
+									'exclude'			=> $excludes,
726
+									'suppress_filters' 	=> 0
727 727
 									);
728 728
 				break;
729 729
 
730 730
 		}
731 731
 
732
-        $post_args['posts_per_page'] = $amount;
733
-        $paged = $wp_query->get( 'paged' );
734
-        $post_args['paged'] = empty( $paged) ? 1 : $paged;
732
+		$post_args['posts_per_page'] = $amount;
733
+		$paged = $wp_query->get( 'paged' );
734
+		$post_args['paged'] = empty( $paged) ? 1 : $paged;
735 735
 
736
-        if( 'newcourses' == $type ){
736
+		if( 'newcourses' == $type ){
737 737
 
738
-            $post_args[ 'orderby' ] = 'date';
739
-            $post_args[ 'order' ] = 'DESC';
740
-        }
738
+			$post_args[ 'orderby' ] = 'date';
739
+			$post_args[ 'order' ] = 'DESC';
740
+		}
741 741
 
742 742
 		return $post_args;
743 743
 	}
@@ -747,22 +747,22 @@  discard block
 block discarded – undo
747 747
 	 * course_image function.
748 748
 	 *
749 749
 	 * Outputs the courses image, or first image from a lesson within a course
750
-     *
751
-     * Will echo the image unless return true is specified.
750
+	 *
751
+	 * Will echo the image unless return true is specified.
752 752
 	 *
753 753
 	 * @access public
754 754
 	 * @param int | WP_Post $course_id (default: 0)
755 755
 	 * @param string $width (default: '100')
756 756
 	 * @param string $height (default: '100')
757
-     * @param bool $return default false
758
-     *
757
+	 * @param bool $return default false
758
+	 *
759 759
 	 * @return string | void
760 760
 	 */
761 761
 	public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) {
762 762
 
763
-        if( is_a( $course_id, 'WP_Post' ) ){
764
-            $course_id = $course_id->ID;
765
-        }
763
+		if( is_a( $course_id, 'WP_Post' ) ){
764
+			$course_id = $course_id->ID;
765
+		}
766 766
 
767 767
 		$html = '';
768 768
 
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
  				// Display Image Placeholder if none
820 820
 				if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) {
821 821
 
822
-                    $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
822
+					$img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
823 823
 
824 824
 				} // End If Statement
825 825
 
@@ -833,15 +833,15 @@  discard block
 block discarded – undo
833 833
 
834 834
 		} // End If Statement
835 835
 
836
-        if( $return ){
836
+		if( $return ){
837 837
 
838
-            return $html;
838
+			return $html;
839 839
 
840
-        }else{
840
+		}else{
841 841
 
842
-            echo $html;
842
+			echo $html;
843 843
 
844
-        }
844
+		}
845 845
 
846 846
 	} // End course_image()
847 847
 
@@ -885,9 +885,9 @@  discard block
 block discarded – undo
885 885
 	 */
886 886
 	public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) {
887 887
 
888
-        if( is_a( $course_id, 'WP_Post' ) ){
889
-            $course_id = $course_id->ID;
890
-        }
888
+		if( is_a( $course_id, 'WP_Post' ) ){
889
+			$course_id = $course_id->ID;
890
+		}
891 891
 
892 892
 		$post_args = array(	'post_type'         => 'lesson',
893 893
 							'posts_per_page'       => -1,
@@ -903,67 +903,67 @@  discard block
 block discarded – undo
903 903
 							'suppress_filters'  => 0,
904 904
 							);
905 905
 		$query_results = new WP_Query( $post_args );
906
-        $lessons = $query_results->posts;
907
-
908
-        // re order the lessons. This could not be done via the OR meta query as there may be lessons
909
-        // with the course order for a different course and this should not be included. It could also not
910
-        // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
911
-        // that have been added to the course.
912
-        if( count( $lessons) > 1  ){
913
-
914
-            foreach( $lessons as $lesson ){
915
-
916
-                $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
917
-                // for lessons with no order set it to be 10000 so that it show up at the end
918
-                $lesson->course_order = $order ? $order : 100000;
919
-            }
920
-
921
-            uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
922
-        }
923
-
924
-        /**
925
-         * Filter runs inside Sensei_Course::course_lessons function
926
-         *
927
-         * Returns all lessons for a given course
928
-         *
929
-         * @param array $lessons
930
-         * @param int $course_id
931
-         */
932
-        $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
933
-
934
-        //return the requested fields
935
-        // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
936
-        // objects
937
-        if( 'ids' == $fields ) {
938
-            $lesson_objects = $lessons;
939
-            $lessons = array();
940
-
941
-            foreach ($lesson_objects as $lesson) {
942
-                $lessons[] = $lesson->ID;
943
-            }
944
-        }
945
-
946
-        return $lessons;
906
+		$lessons = $query_results->posts;
907
+
908
+		// re order the lessons. This could not be done via the OR meta query as there may be lessons
909
+		// with the course order for a different course and this should not be included. It could also not
910
+		// be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
911
+		// that have been added to the course.
912
+		if( count( $lessons) > 1  ){
913
+
914
+			foreach( $lessons as $lesson ){
915
+
916
+				$order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
917
+				// for lessons with no order set it to be 10000 so that it show up at the end
918
+				$lesson->course_order = $order ? $order : 100000;
919
+			}
920
+
921
+			uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
922
+		}
923
+
924
+		/**
925
+		 * Filter runs inside Sensei_Course::course_lessons function
926
+		 *
927
+		 * Returns all lessons for a given course
928
+		 *
929
+		 * @param array $lessons
930
+		 * @param int $course_id
931
+		 */
932
+		$lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
933
+
934
+		//return the requested fields
935
+		// runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
936
+		// objects
937
+		if( 'ids' == $fields ) {
938
+			$lesson_objects = $lessons;
939
+			$lessons = array();
940
+
941
+			foreach ($lesson_objects as $lesson) {
942
+				$lessons[] = $lesson->ID;
943
+			}
944
+		}
945
+
946
+		return $lessons;
947 947
 
948 948
 	} // End course_lessons()
949 949
 
950
-    /**
951
-     * Used for the uasort in $this->course_lessons()
952
-     * @since 1.8.0
953
-     * @access protected
954
-     *
955
-     * @param array $lesson_1
956
-     * @param array $lesson_2
957
-     * @return int
958
-     */
959
-    protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
950
+	/**
951
+	 * Used for the uasort in $this->course_lessons()
952
+	 * @since 1.8.0
953
+	 * @access protected
954
+	 *
955
+	 * @param array $lesson_1
956
+	 * @param array $lesson_2
957
+	 * @return int
958
+	 */
959
+	protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
960 960
 
961
-        if ( $lesson_1->course_order == $lesson_2->course_order ) {
962
-            return 0;
963
-        }
961
+		if ( $lesson_1->course_order == $lesson_2->course_order ) {
962
+			return 0;
963
+		}
964 964
 
965
-        return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
966
-    }
965
+		return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
966
+	}
967 967
 
968 968
 	/**
969 969
 	 * Fetch all quiz ids in a course
@@ -1026,15 +1026,15 @@  discard block
 block discarded – undo
1026 1026
 	 */
1027 1027
 	public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
1028 1028
 
1029
-        $lesson_args = array(	'post_type' 		=> 'lesson',
1029
+		$lesson_args = array(	'post_type' 		=> 'lesson',
1030 1030
 								'posts_per_page' 		=> -1,
1031
-		    					'author'         	=> $author_id,
1032
-		    					'meta_key'        	=> '_lesson_course',
1033
-    							'meta_value'      	=> $course_id,
1034
-    	    					'post_status'      	=> 'publish',
1035
-    	    					'suppress_filters' 	=> 0,
1031
+								'author'         	=> $author_id,
1032
+								'meta_key'        	=> '_lesson_course',
1033
+								'meta_value'      	=> $course_id,
1034
+								'post_status'      	=> 'publish',
1035
+								'suppress_filters' 	=> 0,
1036 1036
 								'fields'            => 'ids', // less data to retrieve
1037
-		    				);
1037
+							);
1038 1038
 		$lessons_array = get_posts( $lesson_args );
1039 1039
 		$count = count( $lessons_array );
1040 1040
 		return $count;
@@ -1052,17 +1052,17 @@  discard block
 block discarded – undo
1052 1052
 
1053 1053
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1054 1054
 								'posts_per_page' 		=> -1,
1055
-		    					'meta_key'        	=> '_lesson_course',
1056
-    							'meta_value'      	=> $course_id,
1057
-    	    					'post_status'      	=> 'publish',
1058
-    	    					'suppress_filters' 	=> 0,
1055
+								'meta_key'        	=> '_lesson_course',
1056
+								'meta_value'      	=> $course_id,
1057
+								'post_status'      	=> 'publish',
1058
+								'suppress_filters' 	=> 0,
1059 1059
 								'fields'            => 'ids', // less data to retrieve
1060
-		    				);
1060
+							);
1061 1061
 		$lessons_array = get_posts( $lesson_args );
1062 1062
 
1063
-        $count = count( $lessons_array );
1063
+		$count = count( $lessons_array );
1064 1064
 
1065
-        return $count;
1065
+		return $count;
1066 1066
 
1067 1067
 	} // End course_lesson_count()
1068 1068
 
@@ -1077,9 +1077,9 @@  discard block
 block discarded – undo
1077 1077
 
1078 1078
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1079 1079
 								'posts_per_page' 		=> -1,
1080
-    	    					'post_status'      	=> 'publish',
1081
-    	    					'suppress_filters' 	=> 0,
1082
-    	    					'meta_query' => array(
1080
+								'post_status'      	=> 'publish',
1081
+								'suppress_filters' 	=> 0,
1082
+								'meta_query' => array(
1083 1083
 									array(
1084 1084
 										'key' => '_lesson_course',
1085 1085
 										'value' => $course_id
@@ -1090,12 +1090,12 @@  discard block
 block discarded – undo
1090 1090
 									)
1091 1091
 								),
1092 1092
 								'fields'            => 'ids', // less data to retrieve
1093
-		    				);
1093
+							);
1094 1094
 		$lessons_array = get_posts( $lesson_args );
1095 1095
 
1096 1096
 		$count = count( $lessons_array );
1097 1097
 
1098
-        return $count;
1098
+		return $count;
1099 1099
 
1100 1100
 	} // End course_lesson_count()
1101 1101
 
@@ -1114,8 +1114,8 @@  discard block
 block discarded – undo
1114 1114
 			$post_args = array(	'post_type' 		=> 'course',
1115 1115
 								'posts_per_page' 		=> -1,
1116 1116
 								'meta_key'        	=> '_course_woocommerce_product',
1117
-	    						'meta_value'      	=> $product_id,
1118
-	    						'post_status'       => 'publish',
1117
+								'meta_value'      	=> $product_id,
1118
+								'post_status'       => 'publish',
1119 1119
 								'suppress_filters' 	=> 0,
1120 1120
 								'orderby' 			=> 'menu_order date',
1121 1121
 								'order' 			=> 'ASC',
@@ -1147,9 +1147,9 @@  discard block
 block discarded – undo
1147 1147
 
1148 1148
 	/**
1149 1149
 	 * load_user_courses_content generates HTML for user's active & completed courses
1150
-     *
1151
-     * This function also ouputs the html so no need to echo the content.
1152
-     *
1150
+	 *
1151
+	 * This function also ouputs the html so no need to echo the content.
1152
+	 *
1153 1153
 	 * @since  1.4.0
1154 1154
 	 * @param  object  $user   Queried user object
1155 1155
 	 * @param  boolean $manage Whether the user has permission to manage the courses
@@ -1158,17 +1158,17 @@  discard block
 block discarded – undo
1158 1158
 	public function load_user_courses_content( $user = false ) {
1159 1159
 		global $course, $my_courses_page, $my_courses_section;
1160 1160
 
1161
-        if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1162
-            || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1161
+		if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1162
+			|| ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1163 1163
 
1164
-            // do not show the content if the settings doesn't allow for it
1165
-            return;
1164
+			// do not show the content if the settings doesn't allow for it
1165
+			return;
1166 1166
 
1167
-        }
1167
+		}
1168 1168
 
1169
-        $manage = ( $user->ID == get_current_user_id() ) ? true : false;
1169
+		$manage = ( $user->ID == get_current_user_id() ) ? true : false;
1170 1170
 
1171
-        do_action( 'sensei_before_learner_course_content', $user );
1171
+		do_action( 'sensei_before_learner_course_content', $user );
1172 1172
 
1173 1173
 		// Build Output HTML
1174 1174
 		$complete_html = $active_html = '';
@@ -1183,7 +1183,7 @@  discard block
 block discarded – undo
1183 1183
 			// Logic for Active and Completed Courses
1184 1184
 			$per_page = 20;
1185 1185
 			if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] )
1186
-                && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1186
+				&& ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1187 1187
 
1188 1188
 				$per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1189 1189
 
@@ -1229,112 +1229,112 @@  discard block
 block discarded – undo
1229 1229
 					}
1230 1230
 				}
1231 1231
 
1232
-			    // Get Course Categories
1233
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1232
+				// Get Course Categories
1233
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1234 1234
 
1235
-                $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1235
+				$active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1236 1236
 
1237
-                // Image
1238
-                $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1237
+				// Image
1238
+				$active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1239 1239
 
1240
-                // Title
1241
-                $active_html .= '<header>';
1240
+				// Title
1241
+				$active_html .= '<header>';
1242 1242
 
1243
-                $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1243
+				$active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1244 1244
 
1245
-                $active_html .= '</header>';
1245
+				$active_html .= '</header>';
1246 1246
 
1247
-                $active_html .= '<section class="entry">';
1247
+				$active_html .= '<section class="entry">';
1248 1248
 
1249
-                $active_html .= '<p class="sensei-course-meta">';
1249
+				$active_html .= '<p class="sensei-course-meta">';
1250 1250
 
1251
-                // Author
1252
-                $user_info = get_userdata( absint( $course_item->post_author ) );
1253
-                if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1254
-                    && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1251
+				// Author
1252
+				$user_info = get_userdata( absint( $course_item->post_author ) );
1253
+				if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1254
+					&& ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1255 1255
 
1256
-                    $active_html .= '<span class="course-author">'
1257
-                        . __( 'by ', 'woothemes-sensei' )
1258
-                        . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1259
-                        . '" title="' . esc_attr( $user_info->display_name ) . '">'
1260
-                        . esc_html( $user_info->display_name )
1261
-                        . '</a></span>';
1256
+					$active_html .= '<span class="course-author">'
1257
+						. __( 'by ', 'woothemes-sensei' )
1258
+						. '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1259
+						. '" title="' . esc_attr( $user_info->display_name ) . '">'
1260
+						. esc_html( $user_info->display_name )
1261
+						. '</a></span>';
1262 1262
 
1263
-                } // End If Statement
1263
+				} // End If Statement
1264 1264
 
1265
-                // Lesson count for this author
1266
-                $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1267
-                // Handle Division by Zero
1268
-                if ( 0 == $lesson_count ) {
1265
+				// Lesson count for this author
1266
+				$lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1267
+				// Handle Division by Zero
1268
+				if ( 0 == $lesson_count ) {
1269 1269
 
1270
-                    $lesson_count = 1;
1270
+					$lesson_count = 1;
1271 1271
 
1272
-                } // End If Statement
1273
-                $active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1274
-                // Course Categories
1275
-                if ( '' != $category_output ) {
1272
+				} // End If Statement
1273
+				$active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1274
+				// Course Categories
1275
+				if ( '' != $category_output ) {
1276 1276
 
1277
-                    $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1277
+					$active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1278 1278
 
1279
-                } // End If Statement
1280
-                $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1279
+				} // End If Statement
1280
+				$active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1281 1281
 
1282
-                $active_html .= '</p>';
1282
+				$active_html .= '</p>';
1283 1283
 
1284
-                $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1284
+				$active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1285 1285
 
1286 1286
 
1287 1287
 
1288
-                $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1288
+				$progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1289 1289
 
1290
-                $active_html .= $this->get_progress_meter( $progress_percentage );
1290
+				$active_html .= $this->get_progress_meter( $progress_percentage );
1291 1291
 
1292
-                $active_html .= '</section>';
1292
+				$active_html .= '</section>';
1293 1293
 
1294
-                if( is_user_logged_in() ) {
1294
+				if( is_user_logged_in() ) {
1295 1295
 
1296
-                    $active_html .= '<section class="entry-actions">';
1296
+					$active_html .= '<section class="entry-actions">';
1297 1297
 
1298
-                    $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1298
+					$active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1299 1299
 
1300
-                    $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1300
+					$active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1301 1301
 
1302
-                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1302
+					$active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1303 1303
 
1304
-                    if ( 0 < absint( count( $course_lessons ) )
1305
-                        && Sensei()->settings->settings['course_completion'] == 'complete' ){
1304
+					if ( 0 < absint( count( $course_lessons ) )
1305
+						&& Sensei()->settings->settings['course_completion'] == 'complete' ){
1306 1306
 
1307
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1308
-                            .  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1307
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1308
+							.  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1309 1309
 
1310
-                    } // End If Statement
1310
+					} // End If Statement
1311 1311
 
1312
-                    $course_purchased = false;
1313
-                    if ( Sensei_WC::is_woocommerce_active() ) {
1312
+					$course_purchased = false;
1313
+					if ( Sensei_WC::is_woocommerce_active() ) {
1314 1314
 
1315
-                        // Get the product ID
1316
-                        $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1317
-                        if ( 0 < $wc_post_id ) {
1315
+						// Get the product ID
1316
+						$wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1317
+						if ( 0 < $wc_post_id ) {
1318 1318
 
1319
-                            $course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1319
+							$course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1320 1320
 
1321
-                        } // End If Statement
1321
+						} // End If Statement
1322 1322
 
1323
-                    } // End If Statement
1323
+					} // End If Statement
1324 1324
 
1325
-                    if ( false == $course_purchased ) {
1325
+					if ( false == $course_purchased ) {
1326 1326
 
1327
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1328
-                            .  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1327
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1328
+							.  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1329 1329
 
1330
-                    } // End If Statement
1330
+					} // End If Statement
1331 1331
 
1332
-                    $active_html .= '</form>';
1332
+					$active_html .= '</form>';
1333 1333
 
1334
-                    $active_html .= '</section>';
1335
-                }
1334
+					$active_html .= '</section>';
1335
+				}
1336 1336
 
1337
-                $active_html .= '</article>';
1337
+				$active_html .= '</article>';
1338 1338
 			}
1339 1339
 
1340 1340
 			// Active pagination
@@ -1374,49 +1374,49 @@  discard block
 block discarded – undo
1374 1374
 			foreach ( $completed_courses as $course_item ) {
1375 1375
 				$course = $course_item;
1376 1376
 
1377
-			    // Get Course Categories
1378
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1377
+				// Get Course Categories
1378
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1379 1379
 
1380
-		    	$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1380
+				$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1381 1381
 
1382
-		    	    // Image
1383
-		    		$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1382
+					// Image
1383
+					$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1384 1384
 
1385
-		    		// Title
1386
-		    		$complete_html .= '<header>';
1385
+					// Title
1386
+					$complete_html .= '<header>';
1387 1387
 
1388
-		    		    $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1388
+						$complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1389 1389
 
1390
-		    		$complete_html .= '</header>';
1390
+					$complete_html .= '</header>';
1391 1391
 
1392
-		    		$complete_html .= '<section class="entry">';
1392
+					$complete_html .= '<section class="entry">';
1393 1393
 
1394
-		    			$complete_html .= '<p class="sensei-course-meta">';
1394
+						$complete_html .= '<p class="sensei-course-meta">';
1395 1395
 
1396
-		    		    	// Author
1397
-		    		    	$user_info = get_userdata( absint( $course_item->post_author ) );
1398
-		    		    	if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1399
-		    		    		$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1400
-		    		    	} // End If Statement
1396
+							// Author
1397
+							$user_info = get_userdata( absint( $course_item->post_author ) );
1398
+							if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1399
+								$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1400
+							} // End If Statement
1401 1401
 
1402
-		    		    	// Lesson count for this author
1403
-		    		    	$complete_html .= '<span class="course-lesson-count">'
1404
-                                . Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1405
-                                . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1406
-                                . '</span>';
1402
+							// Lesson count for this author
1403
+							$complete_html .= '<span class="course-lesson-count">'
1404
+								. Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1405
+								. '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1406
+								. '</span>';
1407 1407
 
1408
-		    		    	// Course Categories
1409
-		    		    	if ( '' != $category_output ) {
1408
+							// Course Categories
1409
+							if ( '' != $category_output ) {
1410 1410
 
1411
-		    		    		$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1411
+								$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1412 1412
 
1413
-		    		    	} // End If Statement
1413
+							} // End If Statement
1414 1414
 
1415 1415
 						$complete_html .= '</p>';
1416 1416
 
1417 1417
 						$complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1418 1418
 
1419
-                        $complete_html .= $this->get_progress_meter( 100 );
1419
+						$complete_html .= $this->get_progress_meter( 100 );
1420 1420
 
1421 1421
 						if( $manage ) {
1422 1422
 							$has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
@@ -1429,22 +1429,22 @@  discard block
 block discarded – undo
1429 1429
 								if( $has_quizzes ) {
1430 1430
 
1431 1431
 									$results_link = '<a class="button view-results" href="'
1432
-                                        . Sensei()->course_results->get_permalink( $course_item->ID )
1433
-                                        . '">' . __( 'View results', 'woothemes-sensei' )
1434
-                                        . '</a>';
1432
+										. Sensei()->course_results->get_permalink( $course_item->ID )
1433
+										. '">' . __( 'View results', 'woothemes-sensei' )
1434
+										. '</a>';
1435 1435
 								}
1436
-                                /**
1437
-                                 * Filter documented in Sensei_Course::the_course_action_buttons
1438
-                                 */
1436
+								/**
1437
+								 * Filter documented in Sensei_Course::the_course_action_buttons
1438
+								 */
1439 1439
 								$complete_html .= apply_filters( 'sensei_results_links', $results_link, $course_item->ID );
1440 1440
 								$complete_html .= '</p>';
1441 1441
 
1442 1442
 							}
1443 1443
 						}
1444 1444
 
1445
-		    		$complete_html .= '</section>';
1445
+					$complete_html .= '</section>';
1446 1446
 
1447
-		    	$complete_html .= '</article>';
1447
+				$complete_html .= '</article>';
1448 1448
 			}
1449 1449
 
1450 1450
 			// Active pagination
@@ -1519,16 +1519,16 @@  discard block
 block discarded – undo
1519 1519
 		    <?php do_action( 'sensei_before_active_user_courses' ); ?>
1520 1520
 
1521 1521
 		    <?php
1522
-            $course_page_url = Sensei_Course::get_courses_page_url();
1523
-            ?>
1522
+			$course_page_url = Sensei_Course::get_courses_page_url();
1523
+			?>
1524 1524
 
1525 1525
 		    <div id="active-courses">
1526 1526
 
1527 1527
 		    	<?php if ( '' != $active_html ) {
1528 1528
 
1529
-		    		echo $active_html;
1529
+					echo $active_html;
1530 1530
 
1531
-		    	} else { ?>
1531
+				} else { ?>
1532 1532
 
1533 1533
 		    		<div class="sensei-message info">
1534 1534
 
@@ -1554,9 +1554,9 @@  discard block
 block discarded – undo
1554 1554
 
1555 1555
 		    	<?php if ( '' != $complete_html ) {
1556 1556
 
1557
-		    		echo $complete_html;
1557
+					echo $complete_html;
1558 1558
 
1559
-		    	} else { ?>
1559
+				} else { ?>
1560 1560
 
1561 1561
 		    		<div class="sensei-message info">
1562 1562
 
@@ -1575,356 +1575,356 @@  discard block
 block discarded – undo
1575 1575
 		<?php do_action( 'sensei_after_user_courses' ); ?>
1576 1576
 
1577 1577
 		<?php
1578
-        echo ob_get_clean();
1578
+		echo ob_get_clean();
1579 1579
 
1580
-        do_action( 'sensei_after_learner_course_content', $user );
1580
+		do_action( 'sensei_after_learner_course_content', $user );
1581 1581
 
1582 1582
 	} // end load_user_courses_content
1583 1583
 
1584
-    /**
1585
-     * Returns a list of all courses
1586
-     *
1587
-     * @since 1.8.0
1588
-     * @return array $courses{
1589
-     *  @type $course WP_Post
1590
-     * }
1591
-     */
1592
-    public static function get_all_courses(){
1593
-
1594
-        $args = array(
1595
-               'post_type' => 'course',
1596
-                'posts_per_page' 		=> -1,
1597
-                'orderby'         	=> 'title',
1598
-                'order'           	=> 'ASC',
1599
-                'post_status'      	=> 'any',
1600
-                'suppress_filters' 	=> 0,
1601
-        );
1602
-
1603
-        $wp_query_obj =  new WP_Query( $args );
1604
-
1605
-        /**
1606
-         * sensei_get_all_courses filter
1607
-         *
1608
-         * This filter runs inside Sensei_Course::get_all_courses.
1609
-         *
1610
-         * @param array $courses{
1611
-         *  @type WP_Post
1612
-         * }
1613
-         * @param array $attributes
1614
-         */
1615
-        return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1616
-
1617
-    }// end get_all_courses
1618
-
1619
-    /**
1620
-     * Generate the course meter component
1621
-     *
1622
-     * @since 1.8.0
1623
-     * @param int $progress_percentage 0 - 100
1624
-     * @return string $progress_bar_html
1625
-     */
1626
-    public function get_progress_meter( $progress_percentage ){
1627
-
1628
-        if ( 50 < $progress_percentage ) {
1629
-            $class = ' green';
1630
-        } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1631
-            $class = ' orange';
1632
-        } else {
1633
-            $class = ' red';
1634
-        }
1635
-        $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1636
-
1637
-        return $progress_bar_html;
1638
-
1639
-    }// end get_progress_meter
1640
-
1641
-    /**
1642
-     * Generate a statement that tells users
1643
-     * how far they are in the course.
1644
-     *
1645
-     * @param int $course_id
1646
-     * @param int $user_id
1647
-     *
1648
-     * @return string $statement_html
1649
-     */
1650
-    public function get_progress_statement( $course_id, $user_id ){
1651
-
1652
-        if( empty( $course_id ) || empty( $user_id )
1653
-        || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1654
-            return '';
1655
-        }
1656
-
1657
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1658
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1659
-
1660
-        $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1661
-
1662
-        /**
1663
-         * Filter the course completion statement.
1664
-         * Default Currently completed $var lesson($plural) of $var in total
1665
-         *
1666
-         * @param string $statement
1667
-         */
1668
-        return apply_filters( 'sensei_course_completion_statement', $statement );
1669
-
1670
-    }// end generate_progress_statement
1671
-
1672
-    /**
1673
-     * Output the course progress statement
1674
-     *
1675
-     * @param $course_id
1676
-     * @return void
1677
-     */
1678
-    public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1679
-        if( empty( $course_id ) ){
1680
-            global $post;
1681
-            $course_id = $post->ID;
1682
-        }
1683
-
1684
-        if( empty( $user_id ) ){
1685
-            $user_id = get_current_user_id();
1686
-        }
1687
-
1688
-        echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1689
-    }
1690
-
1691
-    /**
1692
-     * Output the course progress bar
1693
-     *
1694
-     * @param $course_id
1695
-     * @return void
1696
-     */
1697
-    public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1698
-
1699
-        if( empty( $course_id ) ){
1700
-            global $post;
1701
-            $course_id = $post->ID;
1702
-        }
1703
-
1704
-        if( empty( $user_id ) ){
1705
-            $user_id = get_current_user_id();
1706
-        }
1707
-
1708
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1709
-            || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1710
-            return;
1711
-        }
1712
-        $percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1713
-
1714
-        echo $this->get_progress_meter( $percentage_completed );
1715
-
1716
-    }// end the_progress_meter
1717
-
1718
-    /**
1719
-     * Checks how many lessons are completed
1720
-     *
1721
-     * @since 1.8.0
1722
-     *
1723
-     * @param int $course_id
1724
-     * @param int $user_id
1725
-     * @return array $completed_lesson_ids
1726
-     */
1727
-    public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1728
-
1729
-        if( !( intval( $user_id ) ) > 0 ){
1730
-            $user_id = get_current_user_id();
1731
-        }
1584
+	/**
1585
+	 * Returns a list of all courses
1586
+	 *
1587
+	 * @since 1.8.0
1588
+	 * @return array $courses{
1589
+	 *  @type $course WP_Post
1590
+	 * }
1591
+	 */
1592
+	public static function get_all_courses(){
1593
+
1594
+		$args = array(
1595
+			   'post_type' => 'course',
1596
+				'posts_per_page' 		=> -1,
1597
+				'orderby'         	=> 'title',
1598
+				'order'           	=> 'ASC',
1599
+				'post_status'      	=> 'any',
1600
+				'suppress_filters' 	=> 0,
1601
+		);
1602
+
1603
+		$wp_query_obj =  new WP_Query( $args );
1604
+
1605
+		/**
1606
+		 * sensei_get_all_courses filter
1607
+		 *
1608
+		 * This filter runs inside Sensei_Course::get_all_courses.
1609
+		 *
1610
+		 * @param array $courses{
1611
+		 *  @type WP_Post
1612
+		 * }
1613
+		 * @param array $attributes
1614
+		 */
1615
+		return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1616
+
1617
+	}// end get_all_courses
1732 1618
 
1733
-        $completed_lesson_ids = array();
1619
+	/**
1620
+	 * Generate the course meter component
1621
+	 *
1622
+	 * @since 1.8.0
1623
+	 * @param int $progress_percentage 0 - 100
1624
+	 * @return string $progress_bar_html
1625
+	 */
1626
+	public function get_progress_meter( $progress_percentage ){
1734 1627
 
1735
-        $course_lessons = $this->course_lessons( $course_id );
1628
+		if ( 50 < $progress_percentage ) {
1629
+			$class = ' green';
1630
+		} elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1631
+			$class = ' orange';
1632
+		} else {
1633
+			$class = ' red';
1634
+		}
1635
+		$progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1736 1636
 
1737
-        foreach( $course_lessons as $lesson ){
1637
+		return $progress_bar_html;
1738 1638
 
1739
-            $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1740
-            if( $is_lesson_completed ){
1741
-                $completed_lesson_ids[] = $lesson->ID;
1742
-            }
1743
-
1744
-        }
1745
-
1746
-        return $completed_lesson_ids;
1639
+	}// end get_progress_meter
1747 1640
 
1748
-    }// end get_completed_lesson_ids
1641
+	/**
1642
+	 * Generate a statement that tells users
1643
+	 * how far they are in the course.
1644
+	 *
1645
+	 * @param int $course_id
1646
+	 * @param int $user_id
1647
+	 *
1648
+	 * @return string $statement_html
1649
+	 */
1650
+	public function get_progress_statement( $course_id, $user_id ){
1749 1651
 
1750
-    /**
1751
-     * Calculate the perceantage completed in the course
1752
-     *
1753
-     * @since 1.8.0
1754
-     *
1755
-     * @param int $course_id
1756
-     * @param int $user_id
1757
-     * @return int $percentage
1758
-     */
1759
-    public function get_completion_percentage( $course_id, $user_id = 0 ){
1760
-
1761
-        if( !( intval( $user_id ) ) > 0 ){
1762
-            $user_id = get_current_user_id();
1763
-        }
1764
-
1765
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1766
-
1767
-        if( ! (  $completed  > 0 ) ){
1768
-            return 0;
1769
-        }
1770
-
1771
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1772
-        $percentage = $completed / $total_lessons * 100;
1773
-
1774
-        /**
1775
-         *
1776
-         * Filter the percentage returned for a users course.
1777
-         *
1778
-         * @param $percentage
1779
-         * @param $course_id
1780
-         * @param $user_id
1781
-         * @since 1.8.0
1782
-         */
1783
-        return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1652
+		if( empty( $course_id ) || empty( $user_id )
1653
+		|| ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1654
+			return '';
1655
+		}
1784 1656
 
1785
-    }// end get_completed_lesson_ids
1657
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1658
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1786 1659
 
1787
-    /**
1788
-     * Block email notifications for the specific courses
1789
-     * that the user disabled the notifications.
1790
-     *
1791
-     * @since 1.8.0
1792
-     * @param $should_send
1793
-     * @return bool
1794
-     */
1795
-    public function block_notification_emails( $should_send ){
1796
-        global $sensei_email_data;
1797
-        $email = $sensei_email_data;
1660
+		$statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1798 1661
 
1799
-        $course_id = '';
1662
+		/**
1663
+		 * Filter the course completion statement.
1664
+		 * Default Currently completed $var lesson($plural) of $var in total
1665
+		 *
1666
+		 * @param string $statement
1667
+		 */
1668
+		return apply_filters( 'sensei_course_completion_statement', $statement );
1800 1669
 
1801
-        if( isset( $email['course_id'] ) ){
1670
+	}// end generate_progress_statement
1802 1671
 
1803
-            $course_id = $email['course_id'];
1804
-
1805
-        }elseif( isset( $email['lesson_id'] ) ){
1672
+	/**
1673
+	 * Output the course progress statement
1674
+	 *
1675
+	 * @param $course_id
1676
+	 * @return void
1677
+	 */
1678
+	public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1679
+		if( empty( $course_id ) ){
1680
+			global $post;
1681
+			$course_id = $post->ID;
1682
+		}
1806 1683
 
1807
-            $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1684
+		if( empty( $user_id ) ){
1685
+			$user_id = get_current_user_id();
1686
+		}
1808 1687
 
1809
-        }elseif( isset( $email['quiz_id'] ) ){
1688
+		echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1689
+	}
1690
+
1691
+	/**
1692
+	 * Output the course progress bar
1693
+	 *
1694
+	 * @param $course_id
1695
+	 * @return void
1696
+	 */
1697
+	public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1698
+
1699
+		if( empty( $course_id ) ){
1700
+			global $post;
1701
+			$course_id = $post->ID;
1702
+		}
1703
+
1704
+		if( empty( $user_id ) ){
1705
+			$user_id = get_current_user_id();
1706
+		}
1810 1707
 
1811
-            $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1812
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1708
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1709
+			|| ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1710
+			return;
1711
+		}
1712
+		$percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1813 1713
 
1814
-        }
1714
+		echo $this->get_progress_meter( $percentage_completed );
1715
+
1716
+	}// end the_progress_meter
1717
+
1718
+	/**
1719
+	 * Checks how many lessons are completed
1720
+	 *
1721
+	 * @since 1.8.0
1722
+	 *
1723
+	 * @param int $course_id
1724
+	 * @param int $user_id
1725
+	 * @return array $completed_lesson_ids
1726
+	 */
1727
+	public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1728
+
1729
+		if( !( intval( $user_id ) ) > 0 ){
1730
+			$user_id = get_current_user_id();
1731
+		}
1732
+
1733
+		$completed_lesson_ids = array();
1734
+
1735
+		$course_lessons = $this->course_lessons( $course_id );
1736
+
1737
+		foreach( $course_lessons as $lesson ){
1738
+
1739
+			$is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1740
+			if( $is_lesson_completed ){
1741
+				$completed_lesson_ids[] = $lesson->ID;
1742
+			}
1743
+
1744
+		}
1815 1745
 
1816
-        if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1817
-
1818
-            $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1819
-
1820
-            if ($course_emails_disabled) {
1821
-
1822
-                return false;
1823
-
1824
-            }
1825
-
1826
-        }// end if
1827
-
1828
-        return $should_send;
1829
-    }// end block_notification_emails
1830
-
1831
-    /**
1832
-     * Render the course notification setting meta box
1833
-     *
1834
-     * @since 1.8.0
1835
-     * @param $course
1836
-     */
1837
-    public function course_notification_meta_box_content( $course ){
1838
-
1839
-        $checked = get_post_meta( $course->ID , 'disable_notification', true );
1840
-
1841
-        // generate checked html
1842
-        $checked_html = '';
1843
-        if( $checked ){
1844
-            $checked_html = 'checked="checked"';
1845
-        }
1846
-        wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1847
-
1848
-        echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1849
-        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1850
-
1851
-    }// end course_notification_meta_box_content
1852
-
1853
-    /**
1854
-     * Store the setting for the course notification setting.
1855
-     *
1856
-     * @hooked int save_post
1857
-     * @since 1.8.0
1858
-     *
1859
-     * @param $course_id
1860
-     */
1861
-    public function save_course_notification_meta_box( $course_id ){
1862
-
1863
-        if( !isset( $_POST['_sensei_course_notification']  )
1864
-            || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1865
-            return;
1866
-        }
1867
-
1868
-        if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1869
-            $new_val = true;
1870
-        }else{
1871
-            $new_val = false;
1872
-        }
1873
-
1874
-       update_post_meta( $course_id , 'disable_notification', $new_val );
1875
-
1876
-    }// end save notification meta box
1877
-
1878
-    /**
1879
-     * Backwards compatibility hooks added to ensure that
1880
-     * plugins and other parts of sensei still works.
1881
-     *
1882
-     * This function hooks into `sensei_course_content_inside_before`
1883
-     *
1884
-     * @since 1.9
1885
-     *
1886
-     * @param WP_Post $post
1887
-     */
1888
-    public function content_before_backwards_compatibility_hooks( $post_id ){
1889
-
1890
-        sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1891
-        sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1892
-
1893
-    }
1746
+		return $completed_lesson_ids;
1894 1747
 
1895
-    /**
1896
-     * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1897
-     *
1898
-     * hooked into 'sensei_loop_course_before'
1899
-     *
1900
-     * @since 1.9
1901
-     *
1902
-     * @global WP_Post $post
1903
-     */
1904
-    public  function loop_before_backwards_compatibility_hooks( ){
1905
-
1906
-        global $post;
1907
-        sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1908
-
1909
-    }
1910
-
1911
-    /**
1912
-     * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1913
-     *
1914
-     * hooked into 'sensei_course_content_inside_after'
1915
-     *
1916
-     * @since 1.9.0
1917
-     *
1918
-     * @param integer $course_id
1919
-     */
1920
-    public function the_course_free_lesson_preview( $course_id ){
1921
-        // Meta data
1922
-        $course = get_post( $course_id );
1923
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1924
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1925
-
1926
-        if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1927
-            ?>
1748
+	}// end get_completed_lesson_ids
1749
+
1750
+	/**
1751
+	 * Calculate the perceantage completed in the course
1752
+	 *
1753
+	 * @since 1.8.0
1754
+	 *
1755
+	 * @param int $course_id
1756
+	 * @param int $user_id
1757
+	 * @return int $percentage
1758
+	 */
1759
+	public function get_completion_percentage( $course_id, $user_id = 0 ){
1760
+
1761
+		if( !( intval( $user_id ) ) > 0 ){
1762
+			$user_id = get_current_user_id();
1763
+		}
1764
+
1765
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1766
+
1767
+		if( ! (  $completed  > 0 ) ){
1768
+			return 0;
1769
+		}
1770
+
1771
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1772
+		$percentage = $completed / $total_lessons * 100;
1773
+
1774
+		/**
1775
+		 *
1776
+		 * Filter the percentage returned for a users course.
1777
+		 *
1778
+		 * @param $percentage
1779
+		 * @param $course_id
1780
+		 * @param $user_id
1781
+		 * @since 1.8.0
1782
+		 */
1783
+		return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1784
+
1785
+	}// end get_completed_lesson_ids
1786
+
1787
+	/**
1788
+	 * Block email notifications for the specific courses
1789
+	 * that the user disabled the notifications.
1790
+	 *
1791
+	 * @since 1.8.0
1792
+	 * @param $should_send
1793
+	 * @return bool
1794
+	 */
1795
+	public function block_notification_emails( $should_send ){
1796
+		global $sensei_email_data;
1797
+		$email = $sensei_email_data;
1798
+
1799
+		$course_id = '';
1800
+
1801
+		if( isset( $email['course_id'] ) ){
1802
+
1803
+			$course_id = $email['course_id'];
1804
+
1805
+		}elseif( isset( $email['lesson_id'] ) ){
1806
+
1807
+			$course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1808
+
1809
+		}elseif( isset( $email['quiz_id'] ) ){
1810
+
1811
+			$lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1812
+			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1813
+
1814
+		}
1815
+
1816
+		if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1817
+
1818
+			$course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1819
+
1820
+			if ($course_emails_disabled) {
1821
+
1822
+				return false;
1823
+
1824
+			}
1825
+
1826
+		}// end if
1827
+
1828
+		return $should_send;
1829
+	}// end block_notification_emails
1830
+
1831
+	/**
1832
+	 * Render the course notification setting meta box
1833
+	 *
1834
+	 * @since 1.8.0
1835
+	 * @param $course
1836
+	 */
1837
+	public function course_notification_meta_box_content( $course ){
1838
+
1839
+		$checked = get_post_meta( $course->ID , 'disable_notification', true );
1840
+
1841
+		// generate checked html
1842
+		$checked_html = '';
1843
+		if( $checked ){
1844
+			$checked_html = 'checked="checked"';
1845
+		}
1846
+		wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1847
+
1848
+		echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1849
+		echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1850
+
1851
+	}// end course_notification_meta_box_content
1852
+
1853
+	/**
1854
+	 * Store the setting for the course notification setting.
1855
+	 *
1856
+	 * @hooked int save_post
1857
+	 * @since 1.8.0
1858
+	 *
1859
+	 * @param $course_id
1860
+	 */
1861
+	public function save_course_notification_meta_box( $course_id ){
1862
+
1863
+		if( !isset( $_POST['_sensei_course_notification']  )
1864
+			|| ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1865
+			return;
1866
+		}
1867
+
1868
+		if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1869
+			$new_val = true;
1870
+		}else{
1871
+			$new_val = false;
1872
+		}
1873
+
1874
+	   update_post_meta( $course_id , 'disable_notification', $new_val );
1875
+
1876
+	}// end save notification meta box
1877
+
1878
+	/**
1879
+	 * Backwards compatibility hooks added to ensure that
1880
+	 * plugins and other parts of sensei still works.
1881
+	 *
1882
+	 * This function hooks into `sensei_course_content_inside_before`
1883
+	 *
1884
+	 * @since 1.9
1885
+	 *
1886
+	 * @param WP_Post $post
1887
+	 */
1888
+	public function content_before_backwards_compatibility_hooks( $post_id ){
1889
+
1890
+		sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1891
+		sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1892
+
1893
+	}
1894
+
1895
+	/**
1896
+	 * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1897
+	 *
1898
+	 * hooked into 'sensei_loop_course_before'
1899
+	 *
1900
+	 * @since 1.9
1901
+	 *
1902
+	 * @global WP_Post $post
1903
+	 */
1904
+	public  function loop_before_backwards_compatibility_hooks( ){
1905
+
1906
+		global $post;
1907
+		sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1908
+
1909
+	}
1910
+
1911
+	/**
1912
+	 * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1913
+	 *
1914
+	 * hooked into 'sensei_course_content_inside_after'
1915
+	 *
1916
+	 * @since 1.9.0
1917
+	 *
1918
+	 * @param integer $course_id
1919
+	 */
1920
+	public function the_course_free_lesson_preview( $course_id ){
1921
+		// Meta data
1922
+		$course = get_post( $course_id );
1923
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1924
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1925
+
1926
+		if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1927
+			?>
1928 1928
             <p class="sensei-free-lessons">
1929 1929
                 <a href="<?php echo get_permalink(); ?>">
1930 1930
                     <?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
@@ -1933,23 +1933,23 @@  discard block
 block discarded – undo
1933 1933
             </p>
1934 1934
 
1935 1935
         <?php
1936
-        }
1937
-    }
1936
+		}
1937
+	}
1938 1938
 
1939
-    /**
1940
-     * Add course mata to the course meta hook
1941
-     *
1942
-     * @since 1.9.0
1943
-     * @param integer $course_id
1944
-     */
1945
-    public function the_course_meta( $course_id ){
1946
-        echo '<p class="sensei-course-meta">';
1939
+	/**
1940
+	 * Add course mata to the course meta hook
1941
+	 *
1942
+	 * @since 1.9.0
1943
+	 * @param integer $course_id
1944
+	 */
1945
+	public function the_course_meta( $course_id ){
1946
+		echo '<p class="sensei-course-meta">';
1947 1947
 
1948
-        $course = get_post( $course_id );
1949
-        $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1950
-        $author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1948
+		$course = get_post( $course_id );
1949
+		$category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1950
+		$author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1951 1951
 
1952
-        if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1952
+		if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1953 1953
 
1954 1954
             <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?>
1955 1955
 
@@ -1967,62 +1967,62 @@  discard block
 block discarded – undo
1967 1967
 
1968 1968
         <?php } // End If Statement
1969 1969
 
1970
-        // number of completed lessons
1971
-        if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1972
-            || Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1970
+		// number of completed lessons
1971
+		if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1972
+			|| Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1973 1973
 
1974
-            $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1975
-            $lesson_count = count( $this->course_lessons( $course->ID ) );
1976
-            echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1974
+			$completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1975
+			$lesson_count = count( $this->course_lessons( $course->ID ) );
1976
+			echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1977 1977
 
1978
-        }
1978
+		}
1979 1979
 
1980
-        sensei_simple_course_price( $course->ID );
1980
+		sensei_simple_course_price( $course->ID );
1981 1981
 
1982
-        echo '</p>';
1983
-    } // end the course meta
1982
+		echo '</p>';
1983
+	} // end the course meta
1984 1984
 
1985
-    /**
1986
-     * Filter the classes attached to a post types for courses
1987
-     * and add a status class for when the user is logged in.
1988
-     *
1989
-     * @param $classes
1990
-     * @param $class
1991
-     * @param $post_id
1992
-     *
1993
-     * @return array $classes
1994
-     */
1995
-    public static function add_course_user_status_class( $classes, $class, $course_id ){
1985
+	/**
1986
+	 * Filter the classes attached to a post types for courses
1987
+	 * and add a status class for when the user is logged in.
1988
+	 *
1989
+	 * @param $classes
1990
+	 * @param $class
1991
+	 * @param $post_id
1992
+	 *
1993
+	 * @return array $classes
1994
+	 */
1995
+	public static function add_course_user_status_class( $classes, $class, $course_id ){
1996 1996
 
1997
-        if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
1997
+		if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
1998 1998
 
1999
-            if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
1999
+			if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2000 2000
 
2001
-                $classes[] = 'user-status-completed';
2001
+				$classes[] = 'user-status-completed';
2002 2002
 
2003
-            }else{
2003
+			}else{
2004 2004
 
2005
-                $classes[] = 'user-status-active';
2005
+				$classes[] = 'user-status-active';
2006 2006
 
2007
-            }
2007
+			}
2008 2008
 
2009
-        }
2009
+		}
2010 2010
 
2011
-        return $classes;
2011
+		return $classes;
2012 2012
 
2013
-    }// end add_course_user_status_class
2013
+	}// end add_course_user_status_class
2014 2014
 
2015
-    /**
2016
-     * Prints out the course action buttons links
2017
-     *
2018
-     * - complete course
2019
-     * - delete course
2020
-     *
2021
-     * @param WP_Post $course
2022
-     */
2023
-    public static function the_course_action_buttons( $course ){
2015
+	/**
2016
+	 * Prints out the course action buttons links
2017
+	 *
2018
+	 * - complete course
2019
+	 * - delete course
2020
+	 *
2021
+	 * @param WP_Post $course
2022
+	 */
2023
+	public static function the_course_action_buttons( $course ){
2024 2024
 
2025
-        if( is_user_logged_in() ) { ?>
2025
+		if( is_user_logged_in() ) { ?>
2026 2026
 
2027 2027
             <section class="entry-actions">
2028 2028
                 <form method="POST" action="<?php  echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>">
@@ -2036,50 +2036,50 @@  discard block
 block discarded – undo
2036 2036
                     <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e( intval( $course->ID ) ); ?>" />
2037 2037
 
2038 2038
                     <?php if ( 0 < absint( count( Sensei()->course->course_lessons( $course->ID ) ) )
2039
-                        && Sensei()->settings->settings['course_completion'] == 'complete'
2040
-                        && ! Sensei_Utils::user_completed_course( $course, get_current_user_id() )) { ?>
2039
+						&& Sensei()->settings->settings['course_completion'] == 'complete'
2040
+						&& ! Sensei_Utils::user_completed_course( $course, get_current_user_id() )) { ?>
2041 2041
 
2042 2042
                         <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e( 'Mark as Complete', 'woothemes-sensei' ); ?>" /></span>
2043 2043
 
2044 2044
                    <?php  } // End If Statement
2045 2045
 
2046
-                    $course_purchased = false;
2047
-                    if ( Sensei_WC::is_woocommerce_active() ) {
2048
-                        // Get the product ID
2049
-                        $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2050
-                        if ( 0 < $wc_post_id ) {
2046
+					$course_purchased = false;
2047
+					if ( Sensei_WC::is_woocommerce_active() ) {
2048
+						// Get the product ID
2049
+						$wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2050
+						if ( 0 < $wc_post_id ) {
2051 2051
 
2052
-                            $user = wp_get_current_user();
2053
-                            $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2052
+							$user = wp_get_current_user();
2053
+							$course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2054 2054
 
2055
-                        } // End If Statement
2056
-                    } // End If Statement
2055
+						} // End If Statement
2056
+					} // End If Statement
2057 2057
 
2058
-                    if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?>
2058
+					if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?>
2059 2059
 
2060 2060
                         <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span>
2061 2061
 
2062 2062
                     <?php } // End If Statement
2063 2063
 
2064
-                    $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2065
-                    $results_link = '';
2066
-                    if( $has_quizzes ){
2067
-                        $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2068
-                    }
2064
+					$has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2065
+					$results_link = '';
2066
+					if( $has_quizzes ){
2067
+						$results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2068
+					}
2069 2069
 
2070
-                    // Output only if there is content to display
2071
-                    if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2070
+					// Output only if there is content to display
2071
+					if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2072 2072
 
2073 2073
                         <p class="sensei-results-links">
2074 2074
                             <?php
2075
-                            /**
2076
-                             * Filter the results links
2077
-                             *
2078
-                             * @param string $results_links_html
2079
-                             * @param integer $course_id
2080
-                             */
2081
-                            echo apply_filters( 'sensei_results_links', $results_link, $course->ID );
2082
-                            ?>
2075
+							/**
2076
+							 * Filter the results links
2077
+							 *
2078
+							 * @param string $results_links_html
2079
+							 * @param integer $course_id
2080
+							 */
2081
+							echo apply_filters( 'sensei_results_links', $results_link, $course->ID );
2082
+							?>
2083 2083
                         </p>
2084 2084
 
2085 2085
                     <?php } // end if has filter  ?>
@@ -2088,461 +2088,461 @@  discard block
 block discarded – undo
2088 2088
 
2089 2089
         <?php  }// end if is user logged in
2090 2090
 
2091
-    }// end the_course_action_buttons
2092
-
2093
-    /**
2094
-     * This function alter the main query on the course archive page.
2095
-     * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2096
-     *
2097
-     * This function targets only the course archives and the my courses page. Shortcodes can set their own
2098
-     * query parameters via the arguments.
2099
-     *
2100
-     * This function is hooked into pre_get_posts filter
2101
-     *
2102
-     * @since 1.9.0
2103
-     *
2104
-     * @param WP_Query $query
2105
-     * @return WP_Query $query
2106
-     */
2107
-    public static function course_query_filter( $query ){
2108
-
2109
-        // exit early for no course queries and admin queries
2110
-        if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2111
-            return $query;
2112
-        }
2113
-
2114
-        global $post; // used to get the current page id for my courses
2115
-
2116
-        // for the course archive page
2117
-        if( $query->is_main_query() && is_post_type_archive('course') )
2118
-        {
2119
-            /**
2120
-             * sensei_archive_courses_per_page
2121
-             *
2122
-             * Sensei courses per page on the course
2123
-             * archive
2124
-             *
2125
-             * @since 1.9.0
2126
-             * @param integer $posts_per_page default 10
2127
-             */
2128
-            $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2129
-
2130
-        }
2131
-        // for the my courses page
2132
-        elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2133
-        {
2134
-            /**
2135
-             * sensei_my_courses_per_page
2136
-             *
2137
-             * Sensei courses per page on the my courses page
2138
-             * as set in the settings
2139
-             *
2140
-             * @since 1.9.0
2141
-             * @param integer $posts_per_page default 10
2142
-             */
2143
-            $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2144
-
2145
-        }
2146
-
2147
-        return $query;
2148
-
2149
-    }// end course_query_filter
2150
-
2151
-    /**
2152
-     * Determine the class of the course loop
2153
-     *
2154
-     * This will output .first or .last and .course-item-number-x
2155
-     *
2156
-     * @return array $extra_classes
2157
-     * @since 1.9.0
2158
-     */
2159
-    public static function get_course_loop_content_class ()
2160
-    {
2161
-
2162
-        global $sensei_course_loop;
2163
-
2164
-
2165
-        if( !isset( $sensei_course_loop ) ){
2166
-            $sensei_course_loop = array();
2167
-        }
2168
-
2169
-        if (!isset($sensei_course_loop['counter'])) {
2170
-            $sensei_course_loop['counter'] = 0;
2171
-        }
2172
-
2173
-        if (!isset($sensei_course_loop['columns'])) {
2174
-            $sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2175
-        }
2176
-
2177
-        // increment the counter
2178
-        $sensei_course_loop['counter']++;
2179
-
2180
-        $extra_classes = array();
2181
-        if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2182
-            $extra_classes[] = 'first';
2183
-        }
2184
-
2185
-        if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2186
-            $extra_classes[] = 'last';
2187
-        }
2188
-
2189
-        // add the item number to the classes as well.
2190
-        $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2191
-
2192
-        /**
2193
-         * Filter the course loop class the fires in the  in get_course_loop_content_class function
2194
-         * which is called from the course loop content-course.php
2195
-         *
2196
-         * @since 1.9.0
2197
-         *
2198
-         * @param array $extra_classes
2199
-         * @param WP_Post $loop_current_course
2200
-         */
2201
-        return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2202
-
2203
-    }// end get_course_loop_class
2204
-
2205
-    /**
2206
-     * Get the number of columns set for Sensei courses
2207
-     *
2208
-     * @since 1.9.0
2209
-     * @return mixed|void
2210
-     */
2211
-    public static function get_loop_number_of_columns(){
2212
-
2213
-        /**
2214
-         * Filter the number of columns on the course archive page.
2215
-         *
2216
-         * @since 1.9.0
2217
-         * @param int $number_of_columns default 1
2218
-         */
2219
-        return apply_filters('sensei_course_loop_number_of_columns', 1);
2220
-
2221
-    }
2222
-
2223
-    /**
2224
-     * Output the course archive filter markup
2225
-     *
2226
-     * hooked into sensei_loop_course_before
2227
-     *
2228
-     * @since 1.9.0
2229
-     * @param
2230
-     */
2231
-    public static function course_archive_sorting( $query ){
2232
-
2233
-        // don't show on category pages and other pages
2234
-        if( ! is_archive(  'course ') || is_tax('course-category') ){
2235
-            return;
2236
-        }
2237
-
2238
-        /**
2239
-         * Filter the sensei archive course order by values
2240
-         *
2241
-         * @since 1.9.0
2242
-         * @param array $options {
2243
-         *  @type string $option_value
2244
-         *  @type string $option_string
2245
-         * }
2246
-         */
2247
-        $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2248
-            "newness"     => __( "Sort by newest first", "woothemes-sensei"),
2249
-            "title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2250
-        ));
2251
-
2252
-        // setup the currently selected item
2253
-        $selected = 'newness';
2254
-        if( isset( $_GET['orderby'] ) ){
2255
-
2256
-            $selected =  $_GET[ 'orderby' ];
2257
-
2258
-        }
2259
-
2260
-        ?>
2091
+	}// end the_course_action_buttons
2092
+
2093
+	/**
2094
+	 * This function alter the main query on the course archive page.
2095
+	 * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2096
+	 *
2097
+	 * This function targets only the course archives and the my courses page. Shortcodes can set their own
2098
+	 * query parameters via the arguments.
2099
+	 *
2100
+	 * This function is hooked into pre_get_posts filter
2101
+	 *
2102
+	 * @since 1.9.0
2103
+	 *
2104
+	 * @param WP_Query $query
2105
+	 * @return WP_Query $query
2106
+	 */
2107
+	public static function course_query_filter( $query ){
2108
+
2109
+		// exit early for no course queries and admin queries
2110
+		if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2111
+			return $query;
2112
+		}
2113
+
2114
+		global $post; // used to get the current page id for my courses
2115
+
2116
+		// for the course archive page
2117
+		if( $query->is_main_query() && is_post_type_archive('course') )
2118
+		{
2119
+			/**
2120
+			 * sensei_archive_courses_per_page
2121
+			 *
2122
+			 * Sensei courses per page on the course
2123
+			 * archive
2124
+			 *
2125
+			 * @since 1.9.0
2126
+			 * @param integer $posts_per_page default 10
2127
+			 */
2128
+			$query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2129
+
2130
+		}
2131
+		// for the my courses page
2132
+		elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2133
+		{
2134
+			/**
2135
+			 * sensei_my_courses_per_page
2136
+			 *
2137
+			 * Sensei courses per page on the my courses page
2138
+			 * as set in the settings
2139
+			 *
2140
+			 * @since 1.9.0
2141
+			 * @param integer $posts_per_page default 10
2142
+			 */
2143
+			$query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2144
+
2145
+		}
2146
+
2147
+		return $query;
2148
+
2149
+	}// end course_query_filter
2150
+
2151
+	/**
2152
+	 * Determine the class of the course loop
2153
+	 *
2154
+	 * This will output .first or .last and .course-item-number-x
2155
+	 *
2156
+	 * @return array $extra_classes
2157
+	 * @since 1.9.0
2158
+	 */
2159
+	public static function get_course_loop_content_class ()
2160
+	{
2161
+
2162
+		global $sensei_course_loop;
2163
+
2164
+
2165
+		if( !isset( $sensei_course_loop ) ){
2166
+			$sensei_course_loop = array();
2167
+		}
2168
+
2169
+		if (!isset($sensei_course_loop['counter'])) {
2170
+			$sensei_course_loop['counter'] = 0;
2171
+		}
2172
+
2173
+		if (!isset($sensei_course_loop['columns'])) {
2174
+			$sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2175
+		}
2176
+
2177
+		// increment the counter
2178
+		$sensei_course_loop['counter']++;
2179
+
2180
+		$extra_classes = array();
2181
+		if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2182
+			$extra_classes[] = 'first';
2183
+		}
2184
+
2185
+		if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2186
+			$extra_classes[] = 'last';
2187
+		}
2188
+
2189
+		// add the item number to the classes as well.
2190
+		$extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2191
+
2192
+		/**
2193
+		 * Filter the course loop class the fires in the  in get_course_loop_content_class function
2194
+		 * which is called from the course loop content-course.php
2195
+		 *
2196
+		 * @since 1.9.0
2197
+		 *
2198
+		 * @param array $extra_classes
2199
+		 * @param WP_Post $loop_current_course
2200
+		 */
2201
+		return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2202
+
2203
+	}// end get_course_loop_class
2204
+
2205
+	/**
2206
+	 * Get the number of columns set for Sensei courses
2207
+	 *
2208
+	 * @since 1.9.0
2209
+	 * @return mixed|void
2210
+	 */
2211
+	public static function get_loop_number_of_columns(){
2212
+
2213
+		/**
2214
+		 * Filter the number of columns on the course archive page.
2215
+		 *
2216
+		 * @since 1.9.0
2217
+		 * @param int $number_of_columns default 1
2218
+		 */
2219
+		return apply_filters('sensei_course_loop_number_of_columns', 1);
2220
+
2221
+	}
2222
+
2223
+	/**
2224
+	 * Output the course archive filter markup
2225
+	 *
2226
+	 * hooked into sensei_loop_course_before
2227
+	 *
2228
+	 * @since 1.9.0
2229
+	 * @param
2230
+	 */
2231
+	public static function course_archive_sorting( $query ){
2232
+
2233
+		// don't show on category pages and other pages
2234
+		if( ! is_archive(  'course ') || is_tax('course-category') ){
2235
+			return;
2236
+		}
2237
+
2238
+		/**
2239
+		 * Filter the sensei archive course order by values
2240
+		 *
2241
+		 * @since 1.9.0
2242
+		 * @param array $options {
2243
+		 *  @type string $option_value
2244
+		 *  @type string $option_string
2245
+		 * }
2246
+		 */
2247
+		$course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2248
+			"newness"     => __( "Sort by newest first", "woothemes-sensei"),
2249
+			"title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2250
+		));
2251
+
2252
+		// setup the currently selected item
2253
+		$selected = 'newness';
2254
+		if( isset( $_GET['orderby'] ) ){
2255
+
2256
+			$selected =  $_GET[ 'orderby' ];
2257
+
2258
+		}
2259
+
2260
+		?>
2261 2261
 
2262 2262
         <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST">
2263 2263
             <select name="course-orderby" class="orderby">
2264 2264
                 <?php
2265
-                foreach( $course_order_by_options as $value => $text ){
2265
+				foreach( $course_order_by_options as $value => $text ){
2266 2266
 
2267
-                    echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2267
+					echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2268 2268
 
2269
-                }
2270
-                ?>
2269
+				}
2270
+				?>
2271 2271
             </select>
2272 2272
         </form>
2273 2273
 
2274 2274
     <?php
2275
-    }// end course archive filters
2276
-
2277
-    /**
2278
-     * Output the course archive filter markup
2279
-     *
2280
-     * hooked into sensei_loop_course_before
2281
-     *
2282
-     * @since 1.9.0
2283
-     * @param
2284
-     */
2285
-    public static function course_archive_filters( $query ){
2286
-
2287
-        // don't show on category pages
2288
-        if( is_tax('course-category') ){
2289
-            return;
2290
-        }
2291
-
2292
-        /**
2293
-         * filter the course archive filter buttons
2294
-         *
2295
-         * @since 1.9.0
2296
-         * @param array $filters{
2297
-         *   @type array ( $id, $url , $title )
2298
-         * }
2299
-         *
2300
-         */
2301
-        $filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2302
-            array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2303
-            array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2304
-        ));
2305
-
2306
-
2307
-        ?>
2275
+	}// end course archive filters
2276
+
2277
+	/**
2278
+	 * Output the course archive filter markup
2279
+	 *
2280
+	 * hooked into sensei_loop_course_before
2281
+	 *
2282
+	 * @since 1.9.0
2283
+	 * @param
2284
+	 */
2285
+	public static function course_archive_filters( $query ){
2286
+
2287
+		// don't show on category pages
2288
+		if( is_tax('course-category') ){
2289
+			return;
2290
+		}
2291
+
2292
+		/**
2293
+		 * filter the course archive filter buttons
2294
+		 *
2295
+		 * @since 1.9.0
2296
+		 * @param array $filters{
2297
+		 *   @type array ( $id, $url , $title )
2298
+		 * }
2299
+		 *
2300
+		 */
2301
+		$filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2302
+			array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2303
+			array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2304
+		));
2305
+
2306
+
2307
+		?>
2308 2308
         <ul class="sensei-course-filters clearfix" >
2309 2309
             <?php
2310 2310
 
2311
-            //determine the current active url
2312
-            $current_url = Sensei_Utils::get_current_url();
2311
+			//determine the current active url
2312
+			$current_url = Sensei_Utils::get_current_url();
2313 2313
 
2314
-            foreach( $filters as $filter ) {
2314
+			foreach( $filters as $filter ) {
2315 2315
 
2316
-                $active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2316
+				$active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2317 2317
 
2318
-                echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2318
+				echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2319 2319
 
2320
-            }
2321
-            ?>
2320
+			}
2321
+			?>
2322 2322
 
2323 2323
         </ul>
2324 2324
 
2325 2325
         <?php
2326 2326
 
2327
-    }
2327
+	}
2328 2328
 
2329
-    /**
2330
-     * if the featured link is clicked on the course archive page
2331
-     * filter the courses returned to only show those featured
2332
-     *
2333
-     * Hooked into pre_get_posts
2334
-     *
2335
-     * @since 1.9.0
2336
-     * @param WP_Query $query
2337
-     * @return WP_Query $query
2338
-     */
2339
-    public static function course_archive_featured_filter( $query ){
2340
-
2341
-        if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2342
-            //setup meta query for featured courses
2343
-            $query->set( 'meta_value', 'featured'  );
2344
-            $query->set( 'meta_key', '_course_featured'  );
2345
-            $query->set( 'meta_compare', '='  );
2346
-        }
2347
-
2348
-        return $query;
2349
-    }
2350
-
2351
-    /**
2352
-     * if the course order drop down is changed
2353
-     *
2354
-     * Hooked into pre_get_posts
2355
-     *
2356
-     * @since 1.9.0
2357
-     * @param WP_Query $query
2358
-     * @return WP_Query $query
2359
-     */
2360
-    public static function course_archive_order_by_title( $query ){
2361
-
2362
-        if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2363
-            && 'course'== $query->get('post_type') && $query->is_main_query()  ){
2364
-            // setup the order by title for this query
2365
-            $query->set( 'orderby', 'title'  );
2366
-            $query->set( 'order', 'ASC'  );
2367
-        }
2368
-
2369
-        return $query;
2370
-    }
2371
-
2372
-
2373
-    /**
2374
-     * Get the link to the courses page. This will be the course post type archive
2375
-     * page link or the page the user set in their settings
2376
-     *
2377
-     * @since 1.9.0
2378
-     * @return string $course_page_url
2379
-     */
2380
-    public static function get_courses_page_url(){
2381
-
2382
-        $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2383
-        $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2329
+	/**
2330
+	 * if the featured link is clicked on the course archive page
2331
+	 * filter the courses returned to only show those featured
2332
+	 *
2333
+	 * Hooked into pre_get_posts
2334
+	 *
2335
+	 * @since 1.9.0
2336
+	 * @param WP_Query $query
2337
+	 * @return WP_Query $query
2338
+	 */
2339
+	public static function course_archive_featured_filter( $query ){
2384 2340
 
2385
-        return $course_page_url;
2386
-
2387
-    }// get_course_url
2341
+		if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2342
+			//setup meta query for featured courses
2343
+			$query->set( 'meta_value', 'featured'  );
2344
+			$query->set( 'meta_key', '_course_featured'  );
2345
+			$query->set( 'meta_compare', '='  );
2346
+		}
2388 2347
 
2389
-    /**
2390
-     * Output the headers on the course archive page
2391
-     *
2392
-     * Hooked into the sensei_archive_title
2393
-     *
2394
-     * @since 1.9.0
2395
-     * @param string $query_type
2396
-     * @param string $before_html
2397
-     * @param string $after_html
2398
-     * @return void
2399
-     */
2400
-    public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2348
+		return $query;
2349
+	}
2401 2350
 
2402
-        if( ! is_post_type_archive('course') ){
2403
-            return;
2404
-        }
2351
+	/**
2352
+	 * if the course order drop down is changed
2353
+	 *
2354
+	 * Hooked into pre_get_posts
2355
+	 *
2356
+	 * @since 1.9.0
2357
+	 * @param WP_Query $query
2358
+	 * @return WP_Query $query
2359
+	 */
2360
+	public static function course_archive_order_by_title( $query ){
2405 2361
 
2406
-        // deprecated since 1.9.0
2407
-        sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2362
+		if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2363
+			&& 'course'== $query->get('post_type') && $query->is_main_query()  ){
2364
+			// setup the order by title for this query
2365
+			$query->set( 'orderby', 'title'  );
2366
+			$query->set( 'order', 'ASC'  );
2367
+		}
2408 2368
 
2409
-        $html = '';
2369
+		return $query;
2370
+	}
2410 2371
 
2411
-        if( empty( $before_html ) ){
2412 2372
 
2413
-            $before_html = '<header class="archive-header"><h1>';
2373
+	/**
2374
+	 * Get the link to the courses page. This will be the course post type archive
2375
+	 * page link or the page the user set in their settings
2376
+	 *
2377
+	 * @since 1.9.0
2378
+	 * @return string $course_page_url
2379
+	 */
2380
+	public static function get_courses_page_url(){
2414 2381
 
2415
-        }
2382
+		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2383
+		$course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2416 2384
 
2417
-        if( empty( $after_html ) ){
2385
+		return $course_page_url;
2418 2386
 
2419
-            $after_html = '</h1></header>';
2387
+	}// get_course_url
2420 2388
 
2421
-        }
2389
+	/**
2390
+	 * Output the headers on the course archive page
2391
+	 *
2392
+	 * Hooked into the sensei_archive_title
2393
+	 *
2394
+	 * @since 1.9.0
2395
+	 * @param string $query_type
2396
+	 * @param string $before_html
2397
+	 * @param string $after_html
2398
+	 * @return void
2399
+	 */
2400
+	public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2422 2401
 
2423
-        if ( is_tax( 'course-category' ) ) {
2402
+		if( ! is_post_type_archive('course') ){
2403
+			return;
2404
+		}
2424 2405
 
2425
-            global $wp_query;
2406
+		// deprecated since 1.9.0
2407
+		sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2426 2408
 
2427
-            $taxonomy_obj = $wp_query->get_queried_object();
2428
-            $taxonomy_short_name = $taxonomy_obj->taxonomy;
2429
-            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2430
-            $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2431
-            echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2432
-            return;
2409
+		$html = '';
2433 2410
 
2434
-        } // End If Statement
2411
+		if( empty( $before_html ) ){
2435 2412
 
2436
-        switch ( $query_type ) {
2437
-            case 'newcourses':
2438
-                $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2439
-                break;
2440
-            case 'featuredcourses':
2441
-                $html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2442
-                break;
2443
-            case 'freecourses':
2444
-                $html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2445
-                break;
2446
-            case 'paidcourses':
2447
-                $html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2448
-                break;
2449
-            default:
2450
-                $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2451
-                break;
2452
-        } // End Switch Statement
2413
+			$before_html = '<header class="archive-header"><h1>';
2453 2414
 
2454
-        echo apply_filters( 'course_archive_title', $html );
2415
+		}
2455 2416
 
2456
-    }//course_archive_header
2417
+		if( empty( $after_html ) ){
2457 2418
 
2419
+			$after_html = '</h1></header>';
2458 2420
 
2459
-    /**
2460
-     * Filter the single course content
2461
-     * taking into account if the user has access.
2462
-     *
2463
-     * @1.9.0
2464
-     *
2465
-     * @param string $content
2466
-     * @return string $content or $excerpt
2467
-     */
2468
-    public static function single_course_content( $content ){
2421
+		}
2469 2422
 
2470
-        if( ! is_singular('course') ){
2423
+		if ( is_tax( 'course-category' ) ) {
2471 2424
 
2472
-            return $content;
2425
+			global $wp_query;
2473 2426
 
2474
-        }
2427
+			$taxonomy_obj = $wp_query->get_queried_object();
2428
+			$taxonomy_short_name = $taxonomy_obj->taxonomy;
2429
+			$taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2430
+			$title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2431
+			echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2432
+			return;
2475 2433
 
2476
-        // Content Access Permissions
2477
-        $access_permission = false;
2434
+		} // End If Statement
2478 2435
 
2479
-        if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2436
+		switch ( $query_type ) {
2437
+			case 'newcourses':
2438
+				$html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2439
+				break;
2440
+			case 'featuredcourses':
2441
+				$html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2442
+				break;
2443
+			case 'freecourses':
2444
+				$html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2445
+				break;
2446
+			case 'paidcourses':
2447
+				$html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2448
+				break;
2449
+			default:
2450
+				$html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2451
+				break;
2452
+		} // End Switch Statement
2480 2453
 
2481
-            $access_permission = true;
2454
+		echo apply_filters( 'course_archive_title', $html );
2482 2455
 
2483
-        } // End If Statement
2456
+	}//course_archive_header
2484 2457
 
2485
-        // Check if the user is taking the course
2486
-        $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2487 2458
 
2488
-        if(Sensei_WC::is_woocommerce_active()) {
2459
+	/**
2460
+	 * Filter the single course content
2461
+	 * taking into account if the user has access.
2462
+	 *
2463
+	 * @1.9.0
2464
+	 *
2465
+	 * @param string $content
2466
+	 * @return string $content or $excerpt
2467
+	 */
2468
+	public static function single_course_content( $content ){
2489 2469
 
2490
-            $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2491
-            $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2470
+		if( ! is_singular('course') ){
2492 2471
 
2493
-            $has_product_attached = isset ( $product ) && is_object ( $product );
2472
+			return $content;
2494 2473
 
2495
-        } else {
2474
+		}
2496 2475
 
2497
-            $has_product_attached = false;
2476
+		// Content Access Permissions
2477
+		$access_permission = false;
2498 2478
 
2499
-        }
2479
+		if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2500 2480
 
2501
-        if ( ( is_user_logged_in() && $is_user_taking_course )
2502
-            || ( $access_permission && !$has_product_attached)
2503
-            || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2481
+			$access_permission = true;
2504 2482
 
2505
-            return $content;
2483
+		} // End If Statement
2506 2484
 
2507
-        } else {
2485
+		// Check if the user is taking the course
2486
+		$is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2508 2487
 
2509
-            return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2488
+		if(Sensei_WC::is_woocommerce_active()) {
2510 2489
 
2511
-        }
2490
+			$wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2491
+			$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2512 2492
 
2513
-    }// end single_course_content
2493
+			$has_product_attached = isset ( $product ) && is_object ( $product );
2514 2494
 
2515
-    /**
2516
-     * Output the the single course lessons title with markup.
2517
-     *
2518
-     * @since 1.9.0
2519
-     */
2520
-    public static function the_course_lessons_title(){
2521
-        global $post;
2522
-        $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2523
-        $course_lessons = Sensei()->course->course_lessons( $post->ID );
2495
+		} else {
2524 2496
 
2525
-        // title should be Other Lessons if there are lessons belonging to models.
2526
-        $title = __('Other Lessons', 'woothemes-sensei');
2497
+			$has_product_attached = false;
2527 2498
 
2528
-        // show lessons if the number of lesson in the course is the same as those that isn't assigned to a module
2529
-        if( count( $course_lessons ) == count( $none_module_lessons )  ){
2499
+		}
2530 2500
 
2531
-            $title = __('Lessons', 'woothemes-sensei');
2501
+		if ( ( is_user_logged_in() && $is_user_taking_course )
2502
+			|| ( $access_permission && !$has_product_attached)
2503
+			|| 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2532 2504
 
2533
-        }elseif( empty( $none_module_lessons ) ){ // if the none module lessons are simply empty the title should not be shown
2505
+			return $content;
2534 2506
 
2535
-            $title = '';
2536
-        }
2507
+		} else {
2537 2508
 
2538
-        /**
2539
-         * hook document in class-woothemes-sensei-message.php
2540
-         */
2541
-        $title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2509
+			return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2542 2510
 
2543
-        ob_start(); // start capturing the following output.
2511
+		}
2544 2512
 
2545
-        ?>
2513
+	}// end single_course_content
2514
+
2515
+	/**
2516
+	 * Output the the single course lessons title with markup.
2517
+	 *
2518
+	 * @since 1.9.0
2519
+	 */
2520
+	public static function the_course_lessons_title(){
2521
+		global $post;
2522
+		$none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2523
+		$course_lessons = Sensei()->course->course_lessons( $post->ID );
2524
+
2525
+		// title should be Other Lessons if there are lessons belonging to models.
2526
+		$title = __('Other Lessons', 'woothemes-sensei');
2527
+
2528
+		// show lessons if the number of lesson in the course is the same as those that isn't assigned to a module
2529
+		if( count( $course_lessons ) == count( $none_module_lessons )  ){
2530
+
2531
+			$title = __('Lessons', 'woothemes-sensei');
2532
+
2533
+		}elseif( empty( $none_module_lessons ) ){ // if the none module lessons are simply empty the title should not be shown
2534
+
2535
+			$title = '';
2536
+		}
2537
+
2538
+		/**
2539
+		 * hook document in class-woothemes-sensei-message.php
2540
+		 */
2541
+		$title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2542
+
2543
+		ob_start(); // start capturing the following output.
2544
+
2545
+		?>
2546 2546
 
2547 2547
             <header>
2548 2548
                 <h2> <?php echo $title; ?> </h2>
@@ -2550,290 +2550,290 @@  discard block
 block discarded – undo
2550 2550
 
2551 2551
         <?php
2552 2552
 
2553
-        /**
2554
-         * Filter the title and markup that appears above the lessons on a single course
2555
-         * page.
2556
-         *
2557
-         * @since 1.9.0
2558
-         * @param string $lessons_title_html
2559
-         */
2560
-        echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2553
+		/**
2554
+		 * Filter the title and markup that appears above the lessons on a single course
2555
+		 * page.
2556
+		 *
2557
+		 * @since 1.9.0
2558
+		 * @param string $lessons_title_html
2559
+		 */
2560
+		echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2561 2561
 
2562
-    }// end the_course_lessons_title
2563
-
2564
-    /**
2565
-     * This function loads the global wp_query object with with lessons
2566
-     * of the current course. It is designed to be used on the single-course template
2567
-     * and expects the global post to be a singular course.
2568
-     *
2569
-     * This function excludes lessons belonging to modules as they are
2570
-     * queried separately.
2571
-     *
2572
-     * @since 1.9.0
2573
-     * @global $wp_query
2574
-     */
2575
-    public static function load_single_course_lessons_query(){
2562
+	}// end the_course_lessons_title
2576 2563
 
2577
-        global $post, $wp_query;
2578
-
2579
-        $course_id = $post->ID;
2580
-
2581
-        if( 'course' != get_post_type( $course_id ) ){
2582
-            return;
2583
-        }
2564
+	/**
2565
+	 * This function loads the global wp_query object with with lessons
2566
+	 * of the current course. It is designed to be used on the single-course template
2567
+	 * and expects the global post to be a singular course.
2568
+	 *
2569
+	 * This function excludes lessons belonging to modules as they are
2570
+	 * queried separately.
2571
+	 *
2572
+	 * @since 1.9.0
2573
+	 * @global $wp_query
2574
+	 */
2575
+	public static function load_single_course_lessons_query(){
2584 2576
 
2585
-        $course_lesson_query_args = array(
2586
-            'post_type'         => 'lesson',
2587
-            'posts_per_page'    => 500,
2588
-            'orderby'           => 'date',
2589
-            'order'             => 'ASC',
2590
-            'meta_query'        => array(
2591
-                array(
2592
-                    'key' => '_lesson_course',
2593
-                    'value' => intval( $course_id ),
2594
-                ),
2595
-            ),
2596
-            'post_status'       => 'public',
2597
-            'suppress_filters'  => 0,
2598
-        );
2577
+		global $post, $wp_query;
2599 2578
 
2600
-        // Exclude lessons belonging to modules as they are queried along with the modules.
2601
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2602
-        if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2579
+		$course_id = $post->ID;
2603 2580
 
2604
-            $terms_ids = array();
2605
-            foreach( $modules as $term ){
2581
+		if( 'course' != get_post_type( $course_id ) ){
2582
+			return;
2583
+		}
2606 2584
 
2607
-                $terms_ids[] = $term->term_id;
2585
+		$course_lesson_query_args = array(
2586
+			'post_type'         => 'lesson',
2587
+			'posts_per_page'    => 500,
2588
+			'orderby'           => 'date',
2589
+			'order'             => 'ASC',
2590
+			'meta_query'        => array(
2591
+				array(
2592
+					'key' => '_lesson_course',
2593
+					'value' => intval( $course_id ),
2594
+				),
2595
+			),
2596
+			'post_status'       => 'public',
2597
+			'suppress_filters'  => 0,
2598
+		);
2599
+
2600
+		// Exclude lessons belonging to modules as they are queried along with the modules.
2601
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2602
+		if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2603
+
2604
+			$terms_ids = array();
2605
+			foreach( $modules as $term ){
2606
+
2607
+				$terms_ids[] = $term->term_id;
2608 2608
 
2609
-            }
2609
+			}
2610 2610
 
2611
-            $course_lesson_query_args[ 'tax_query'] = array(
2612
-                array(
2613
-                    'taxonomy' => 'module',
2614
-                    'field'    => 'id',
2615
-                    'terms'    => $terms_ids,
2616
-                    'operator' => 'NOT IN',
2617
-                ),
2618
-            );
2619
-        }
2611
+			$course_lesson_query_args[ 'tax_query'] = array(
2612
+				array(
2613
+					'taxonomy' => 'module',
2614
+					'field'    => 'id',
2615
+					'terms'    => $terms_ids,
2616
+					'operator' => 'NOT IN',
2617
+				),
2618
+			);
2619
+		}
2620 2620
 
2621
-        //setting lesson order
2622
-        $course_lesson_order = get_post_meta( $course_id, '_lesson_order', true);
2623
-        if( !empty( $course_lesson_order ) ){
2621
+		//setting lesson order
2622
+		$course_lesson_order = get_post_meta( $course_id, '_lesson_order', true);
2623
+		if( !empty( $course_lesson_order ) ){
2624 2624
 
2625
-            $course_lesson_query_args['post__in'] = explode( ',', $course_lesson_order );
2626
-            $course_lesson_query_args['orderby']= 'post__in' ;
2627
-            unset( $course_lesson_query_args['order'] );
2625
+			$course_lesson_query_args['post__in'] = explode( ',', $course_lesson_order );
2626
+			$course_lesson_query_args['orderby']= 'post__in' ;
2627
+			unset( $course_lesson_query_args['order'] );
2628 2628
 
2629
-        }
2629
+		}
2630 2630
 
2631
-        $wp_query = new WP_Query( $course_lesson_query_args );
2631
+		$wp_query = new WP_Query( $course_lesson_query_args );
2632 2632
 
2633
-    }// load_single_course_lessons
2633
+	}// load_single_course_lessons
2634 2634
 
2635
-    /**
2636
-     * Flush the rewrite rules for a course post type
2637
-     *
2638
-     * @since 1.9.0
2639
-     *
2640
-     * @param $post_id
2641
-     */
2642
-    public static function flush_rewrite_rules( $post_id ){
2635
+	/**
2636
+	 * Flush the rewrite rules for a course post type
2637
+	 *
2638
+	 * @since 1.9.0
2639
+	 *
2640
+	 * @param $post_id
2641
+	 */
2642
+	public static function flush_rewrite_rules( $post_id ){
2643 2643
 
2644
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2644
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2645 2645
 
2646
-            return;
2646
+			return;
2647 2647
 
2648
-        }
2648
+		}
2649 2649
 
2650 2650
 
2651
-        if( 'course' == get_post_type( $post_id )  ){
2651
+		if( 'course' == get_post_type( $post_id )  ){
2652 2652
 
2653
-            Sensei()->initiate_rewrite_rules_flush();
2653
+			Sensei()->initiate_rewrite_rules_flush();
2654 2654
 
2655
-        }
2655
+		}
2656 2656
 
2657
-    }
2657
+	}
2658 2658
 
2659
-    /**
2660
-     * Optionally return the full content on the single course pages
2661
-     * depending on the users course_single_content_display setting
2662
-     *
2663
-     * @since 1.9.0
2664
-     * @param $excerpt
2665
-     * @return string
2666
-     */
2667
-    public static function full_content_excerpt_override( $excerpt ){
2659
+	/**
2660
+	 * Optionally return the full content on the single course pages
2661
+	 * depending on the users course_single_content_display setting
2662
+	 *
2663
+	 * @since 1.9.0
2664
+	 * @param $excerpt
2665
+	 * @return string
2666
+	 */
2667
+	public static function full_content_excerpt_override( $excerpt ){
2668 2668
 
2669
-        if (   is_singular('course')  &&
2670
-                'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2669
+		if (   is_singular('course')  &&
2670
+				'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2671 2671
 
2672
-            return get_the_content();
2672
+			return get_the_content();
2673 2673
 
2674
-        } else {
2674
+		} else {
2675 2675
 
2676
-            return $excerpt;
2676
+			return $excerpt;
2677 2677
 
2678
-        }
2678
+		}
2679 2679
 
2680
-    }
2680
+	}
2681 2681
 
2682
-    /**
2683
-     * Output the course actions like start taking course, register, add to cart etc.
2684
-     *
2685
-     * @since 1.9.0
2686
-     */
2687
-    public static function the_course_enrolment_actions(){
2688
-        ?>
2682
+	/**
2683
+	 * Output the course actions like start taking course, register, add to cart etc.
2684
+	 *
2685
+	 * @since 1.9.0
2686
+	 */
2687
+	public static function the_course_enrolment_actions(){
2688
+		?>
2689 2689
         <section class="course-meta course-enrolment">
2690 2690
         <?php
2691
-        global  $post, $current_user;
2692
-        $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2693
-        if ( is_user_logged_in() && ! $is_user_taking_course ) {
2694
-
2695
-            // Get the product ID
2696
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2697
-
2698
-            // Check for woocommerce
2699
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2700
-                sensei_wc_add_to_cart($post->ID);
2701
-            } else {
2702
-                sensei_start_course_form($post->ID);
2703
-            } // End If Statement
2704
-
2705
-        } elseif ( is_user_logged_in() ) {
2706
-
2707
-            // Check if course is completed
2708
-            $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2709
-            $completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2710
-            // Success message
2711
-            if ( $completed_course ) { ?>
2691
+		global  $post, $current_user;
2692
+		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2693
+		if ( is_user_logged_in() && ! $is_user_taking_course ) {
2694
+
2695
+			// Get the product ID
2696
+			$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2697
+
2698
+			// Check for woocommerce
2699
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2700
+				sensei_wc_add_to_cart($post->ID);
2701
+			} else {
2702
+				sensei_start_course_form($post->ID);
2703
+			} // End If Statement
2704
+
2705
+		} elseif ( is_user_logged_in() ) {
2706
+
2707
+			// Check if course is completed
2708
+			$user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2709
+			$completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2710
+			// Success message
2711
+			if ( $completed_course ) { ?>
2712 2712
                 <div class="status completed"><?php  _e( 'Completed', 'woothemes-sensei' ); ?></div>
2713 2713
                 <?php
2714
-                $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2715
-                if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2714
+				$has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2715
+				if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2716 2716
                     <p class="sensei-results-links">
2717 2717
                         <?php
2718
-                        $results_link = '';
2719
-                        if( $has_quizzes ) {
2720
-                            $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2721
-                        }
2722
-                        /**
2723
-                         * Filter documented in Sensei_Course::the_course_action_buttons
2724
-                         */
2725
-                        $results_link = apply_filters( 'sensei_results_links', $results_link, $post->ID );
2726
-                        echo $results_link;
2727
-                        ?></p>
2718
+						$results_link = '';
2719
+						if( $has_quizzes ) {
2720
+							$results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2721
+						}
2722
+						/**
2723
+						 * Filter documented in Sensei_Course::the_course_action_buttons
2724
+						 */
2725
+						$results_link = apply_filters( 'sensei_results_links', $results_link, $post->ID );
2726
+						echo $results_link;
2727
+						?></p>
2728 2728
                 <?php } ?>
2729 2729
             <?php } else { ?>
2730 2730
                 <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div>
2731 2731
             <?php }
2732 2732
 
2733
-        } else {
2734
-            // Get the product ID
2735
-            $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2736
-            // Check for woocommerce
2737
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2733
+		} else {
2734
+			// Get the product ID
2735
+			$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
2736
+			// Check for woocommerce
2737
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) {
2738 2738
 
2739
-                sensei_wc_add_to_cart($post->ID);
2739
+				sensei_wc_add_to_cart($post->ID);
2740 2740
 
2741
-            } else {
2741
+			} else {
2742 2742
 
2743
-                if( get_option( 'users_can_register') ) {
2743
+				if( get_option( 'users_can_register') ) {
2744 2744
 
2745 2745
 
2746
-                    $my_courses_page_id = '';
2746
+					$my_courses_page_id = '';
2747 2747
 
2748
-                    /**
2749
-                     * Filter to force Sensei to output the default WordPress user
2750
-                     * registration link.
2751
-                     *
2752
-                     * @since 1.9.0
2753
-                     * @param bool $wp_register_link default false
2754
-                     */
2748
+					/**
2749
+					 * Filter to force Sensei to output the default WordPress user
2750
+					 * registration link.
2751
+					 *
2752
+					 * @since 1.9.0
2753
+					 * @param bool $wp_register_link default false
2754
+					 */
2755 2755
 
2756
-                    $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2756
+					$wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2757 2757
 
2758
-                    $settings = Sensei()->settings->get_settings();
2759
-                    if( isset( $settings[ 'my_course_page' ] )
2760
-                        && 0 < intval( $settings[ 'my_course_page' ] ) ){
2758
+					$settings = Sensei()->settings->get_settings();
2759
+					if( isset( $settings[ 'my_course_page' ] )
2760
+						&& 0 < intval( $settings[ 'my_course_page' ] ) ){
2761 2761
 
2762
-                        $my_courses_page_id = $settings[ 'my_course_page' ];
2762
+						$my_courses_page_id = $settings[ 'my_course_page' ];
2763 2763
 
2764
-                    }
2764
+					}
2765 2765
 
2766
-                    // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2767
-                    // is false, link to My Courses. If not, link to default WordPress registration page.
2768
-                    if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2766
+					// If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2767
+					// is false, link to My Courses. If not, link to default WordPress registration page.
2768
+					if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2769 2769
 
2770
-                        $my_courses_url = get_permalink( $my_courses_page_id  );
2771
-                        $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2772
-                        echo '<div class="status register">' . $register_link . '</div>' ;
2770
+						$my_courses_url = get_permalink( $my_courses_page_id  );
2771
+						$register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2772
+						echo '<div class="status register">' . $register_link . '</div>' ;
2773 2773
 
2774
-                    } else{
2774
+					} else{
2775 2775
 
2776
-                        wp_register( '<div class="status register">', '</div>' );
2776
+						wp_register( '<div class="status register">', '</div>' );
2777 2777
 
2778
-                    }
2778
+					}
2779 2779
 
2780
-                } // end if user can register
2780
+				} // end if user can register
2781 2781
 
2782
-            } // End If Statement
2782
+			} // End If Statement
2783 2783
 
2784
-        } // End If Statement ?>
2784
+		} // End If Statement ?>
2785 2785
 
2786 2786
         </section><?php
2787 2787
 
2788
-    }// end the_course_enrolment_actions
2788
+	}// end the_course_enrolment_actions
2789 2789
 
2790
-    /**
2791
-     * Output the course video inside the loop.
2792
-     *
2793
-     * @since 1.9.0
2794
-     */
2795
-    public static function the_course_video(){
2790
+	/**
2791
+	 * Output the course video inside the loop.
2792
+	 *
2793
+	 * @since 1.9.0
2794
+	 */
2795
+	public static function the_course_video(){
2796 2796
 
2797
-        global $post;
2798
-        // Get the meta info
2799
-        $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2797
+		global $post;
2798
+		// Get the meta info
2799
+		$course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2800 2800
 
2801
-        if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2801
+		if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2802 2802
 
2803
-            $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2803
+			$course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2804 2804
 
2805
-        } // End If Statement
2805
+		} // End If Statement
2806 2806
 
2807
-        if ( '' != $course_video_embed ) { ?>
2807
+		if ( '' != $course_video_embed ) { ?>
2808 2808
 
2809 2809
             <div class="course-video">
2810 2810
                 <?php echo html_entity_decode($course_video_embed); ?>
2811 2811
             </div>
2812 2812
 
2813 2813
         <?php } // End If Statement
2814
-    }
2814
+	}
2815 2815
 
2816
-    /**
2817
-     * Output the title for the single lesson page
2818
-     *
2819
-     * @global $post
2820
-     * @since 1.9.0
2821
-     */
2822
-    public static function the_title(){
2816
+	/**
2817
+	 * Output the title for the single lesson page
2818
+	 *
2819
+	 * @global $post
2820
+	 * @since 1.9.0
2821
+	 */
2822
+	public static function the_title(){
2823 2823
 
2824
-        global $post;
2824
+		global $post;
2825 2825
 
2826
-        ?>
2826
+		?>
2827 2827
         <header>
2828 2828
 
2829 2829
             <h1>
2830 2830
 
2831 2831
                 <?php
2832
-                /**
2833
-                 * Filter documented in class-sensei-messages.php the_title
2834
-                 */
2835
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2836
-                ?>
2832
+				/**
2833
+				 * Filter documented in class-sensei-messages.php the_title
2834
+				 */
2835
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2836
+				?>
2837 2837
 
2838 2838
             </h1>
2839 2839
 
@@ -2841,111 +2841,111 @@  discard block
 block discarded – undo
2841 2841
 
2842 2842
         <?php
2843 2843
 
2844
-    }//the_title
2845
-
2846
-    /**
2847
-     * Show the title on the course category pages
2848
-     *
2849
-     * @since 1.9.0
2850
-     */
2851
-    public static function course_category_title(){
2852
-
2853
-        if( ! is_tax( 'course-category' ) ){
2854
-            return;
2855
-        }
2856
-
2857
-        $category_slug = get_query_var('course-category');
2858
-        $term  = get_term_by('slug',$category_slug,'course-category');
2859
-
2860
-        if( ! empty($term) ){
2861
-
2862
-            $title = $term->name;
2863
-
2864
-        }else{
2865
-
2866
-            $title = 'Course Category';
2867
-
2868
-        }
2869
-
2870
-        $html = '<h2 class="sensei-category-title">';
2871
-        $html .= __('Category') . ' ' . $title;
2872
-        $html .= '</h2>';
2873
-
2874
-        echo apply_filters( 'course_category_title', $html , $term->term_id );
2875
-
2876
-    }// course_category_title
2877
-
2878
-    /**
2879
-     * Alter the course query to respect the order set for courses and apply
2880
-     * this on the course-category pages.
2881
-     *
2882
-     * @since 1.9.0
2883
-     *
2884
-     * @param WP_Query $query
2885
-     * @return WP_Query
2886
-     */
2887
-    public static function alter_course_category_order( $query ){
2888
-
2889
-        if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2890
-            return $query;
2891
-        }
2892
-
2893
-        $order = get_option( 'sensei_course_order', '' );
2894
-        if( !empty( $order )  ){
2895
-            $query->set('orderby', 'menu_order' );
2896
-            $query->set('order', 'ASC' );
2897
-        }
2898
-
2899
-        return $query;
2900
-
2901
-    }
2902
-
2903
-    /**
2904
-     * The very basic course query arguments
2905
-     * so we don't have to repeat this througout
2906
-     * the code base.
2907
-     *
2908
-     * Usage:
2909
-     * $args = Sensei_Course::get_default_query_args();
2910
-     * $args['custom_arg'] ='custom value';
2911
-     * $courses = get_posts( $args )
2912
-     *
2913
-     * @since 1.9.0
2914
-     *
2915
-     * @return array
2916
-     */
2917
-    public static function get_default_query_args(){
2918
-        return array(
2919
-            'post_type' 		=> 'course',
2920
-            'posts_per_page' 		=> 1000,
2921
-            'orderby'         	=> 'date',
2922
-            'order'           	=> 'DESC',
2923
-            'suppress_filters' 	=> 0
2924
-        );
2925
-    }
2926
-
2927
-    /**
2928
-     * Check if the prerequisite course is completed
2929
-     * Courses with no pre-requisite should always return true
2930
-     *
2931
-     * @since 1.9.0
2932
-     * @param $course_id
2933
-     * @return bool
2934
-     */
2935
-    public static function is_prerequisite_complete( $course_id ){
2936
-
2937
-        $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
2938
-
2939
-        // if it has a pre requisite course check it
2940
-        if( ! empty(  $course_prerequisite_id ) ){
2941
-
2942
-            return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
2943
-
2944
-        }
2945
-
2946
-        return true;
2947
-
2948
-    }// end is_prerequisite_complete
2844
+	}//the_title
2845
+
2846
+	/**
2847
+	 * Show the title on the course category pages
2848
+	 *
2849
+	 * @since 1.9.0
2850
+	 */
2851
+	public static function course_category_title(){
2852
+
2853
+		if( ! is_tax( 'course-category' ) ){
2854
+			return;
2855
+		}
2856
+
2857
+		$category_slug = get_query_var('course-category');
2858
+		$term  = get_term_by('slug',$category_slug,'course-category');
2859
+
2860
+		if( ! empty($term) ){
2861
+
2862
+			$title = $term->name;
2863
+
2864
+		}else{
2865
+
2866
+			$title = 'Course Category';
2867
+
2868
+		}
2869
+
2870
+		$html = '<h2 class="sensei-category-title">';
2871
+		$html .= __('Category') . ' ' . $title;
2872
+		$html .= '</h2>';
2873
+
2874
+		echo apply_filters( 'course_category_title', $html , $term->term_id );
2875
+
2876
+	}// course_category_title
2877
+
2878
+	/**
2879
+	 * Alter the course query to respect the order set for courses and apply
2880
+	 * this on the course-category pages.
2881
+	 *
2882
+	 * @since 1.9.0
2883
+	 *
2884
+	 * @param WP_Query $query
2885
+	 * @return WP_Query
2886
+	 */
2887
+	public static function alter_course_category_order( $query ){
2888
+
2889
+		if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2890
+			return $query;
2891
+		}
2892
+
2893
+		$order = get_option( 'sensei_course_order', '' );
2894
+		if( !empty( $order )  ){
2895
+			$query->set('orderby', 'menu_order' );
2896
+			$query->set('order', 'ASC' );
2897
+		}
2898
+
2899
+		return $query;
2900
+
2901
+	}
2902
+
2903
+	/**
2904
+	 * The very basic course query arguments
2905
+	 * so we don't have to repeat this througout
2906
+	 * the code base.
2907
+	 *
2908
+	 * Usage:
2909
+	 * $args = Sensei_Course::get_default_query_args();
2910
+	 * $args['custom_arg'] ='custom value';
2911
+	 * $courses = get_posts( $args )
2912
+	 *
2913
+	 * @since 1.9.0
2914
+	 *
2915
+	 * @return array
2916
+	 */
2917
+	public static function get_default_query_args(){
2918
+		return array(
2919
+			'post_type' 		=> 'course',
2920
+			'posts_per_page' 		=> 1000,
2921
+			'orderby'         	=> 'date',
2922
+			'order'           	=> 'DESC',
2923
+			'suppress_filters' 	=> 0
2924
+		);
2925
+	}
2926
+
2927
+	/**
2928
+	 * Check if the prerequisite course is completed
2929
+	 * Courses with no pre-requisite should always return true
2930
+	 *
2931
+	 * @since 1.9.0
2932
+	 * @param $course_id
2933
+	 * @return bool
2934
+	 */
2935
+	public static function is_prerequisite_complete( $course_id ){
2936
+
2937
+		$course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
2938
+
2939
+		// if it has a pre requisite course check it
2940
+		if( ! empty(  $course_prerequisite_id ) ){
2941
+
2942
+			return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
2943
+
2944
+		}
2945
+
2946
+		return true;
2947
+
2948
+	}// end is_prerequisite_complete
2949 2949
 
2950 2950
 
2951 2951
 }// End Class
Please login to merge, or discard this patch.
includes/class-sensei-analysis-overview-list-table.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 			'order' => $order,
160 160
 		);
161 161
 
162
-        // Handle search
163
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
-            $args['search'] = esc_html( $_GET['s'] );
165
-        }
162
+		// Handle search
163
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
+			$args['search'] = esc_html( $_GET['s'] );
165
+		}
166 166
 
167 167
 		switch ( $this->type ) {
168 168
 			case 'courses':
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		);
220 220
 
221 221
 
222
-        // Handle search
223
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
-            $args['search'] = esc_html( $_GET['s'] );
225
-        }
222
+		// Handle search
223
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
+			$args['search'] = esc_html( $_GET['s'] );
225
+		}
226 226
 
227 227
 
228 228
 		// Start the csv with the column headings
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * Generates the overall array for a single item in the display
261 261
 	 * @since  1.7.0
262 262
 	 * @param object $item The current item
263
-     * @return array $column_data;
263
+	 * @return array $column_data;
264 264
 	 */
265 265
 	protected function get_row_data( $item ) {
266 266
 
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
 				$percent_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ) );
297 297
 				$percent_total = Sensei_Grading::get_course_users_grades_sum( $item->ID );
298 298
 
299
-                $course_average_percent = 0;
300
-                if( $percent_count > 0 && $percent_total > 0 ){
301
-                    $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
-                }
299
+				$course_average_percent = 0;
300
+				if( $percent_count > 0 && $percent_total > 0 ){
301
+					$course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
+				}
303 303
 
304 304
 
305 305
 				// Output course data
@@ -355,12 +355,12 @@  discard block
 block discarded – undo
355 355
 					$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ));
356 356
 					$grade_total = Sensei_Grading::get_lessons_users_grades_sum( $item->ID );
357 357
 
358
-                    $lesson_average_grade = 0;
359
-                    if( $grade_total > 0 && $grade_count > 0 ){
360
-                        $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
-                    }
358
+					$lesson_average_grade = 0;
359
+					if( $grade_total > 0 && $grade_count > 0 ){
360
+						$lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
+					}
362 362
 
363
-                }
363
+				}
364 364
 				// Output lesson data
365 365
 				if ( $this->csv_output ) {
366 366
 					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 				$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ));
418 418
 				$grade_total = Sensei_Grading::get_user_graded_lessons_sum( $item->ID );
419 419
 
420
-                $user_average_grade = 0;
421
-                if( $grade_total > 0 && $grade_count > 0 ){
422
-                    $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
-                }
420
+				$user_average_grade = 0;
421
+				if( $grade_total > 0 && $grade_count > 0 ){
422
+					$user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
+				}
424 424
 
425 425
 				// Output the users data
426 426
 				if ( $this->csv_output ) {
427
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
428
-                }
427
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
428
+				}
429 429
 				else {
430 430
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
431 431
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -519,17 +519,17 @@  discard block
 block discarded – undo
519 519
 		// This stops the full meta data of each user being loaded
520 520
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
521 521
 
522
-        /**
523
-         * Filter the WP_User_Query arguments
524
-         * @since 1.6.0
525
-         * @param $args
526
-         */
527
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
522
+		/**
523
+		 * Filter the WP_User_Query arguments
524
+		 * @since 1.6.0
525
+		 * @param $args
526
+		 */
527
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
528 528
 		$wp_user_search = new WP_User_Query( $args );
529
-        $learners = $wp_user_search->get_results();
529
+		$learners = $wp_user_search->get_results();
530 530
 		$this->total_items = $wp_user_search->get_total();
531 531
 
532
-        return $learners;
532
+		return $learners;
533 533
 
534 534
 	} // End get_learners()
535 535
 
@@ -546,15 +546,15 @@  discard block
 block discarded – undo
546 546
 		$total_courses = Sensei()->course->course_count( array('publish', 'private') );
547 547
 		$total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') );
548 548
 
549
-        /**
550
-         * filter the analysis tot grades query args
551
-         */
549
+		/**
550
+		 * filter the analysis tot grades query args
551
+		 */
552 552
 		$grade_args = apply_filters( 'sensei_analysis_total_quiz_grades', array(
553 553
 				'type' => 'sensei_lesson_status',
554 554
 				'status' => 'any',
555 555
 
556
-                'meta_key' => 'grade'
557
-        ));
556
+				'meta_key' => 'grade'
557
+		));
558 558
 
559 559
 		$total_grade_count = Sensei_Grading::get_graded_lessons_count();
560 560
 		$total_grade_total = Sensei_Grading::get_graded_lessons_sum();
Please login to merge, or discard this patch.
includes/class-sensei-lesson.php 1 patch
Indentation   +1065 added lines, -1065 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function __construct () {
23 23
 
24
-        $this->token = 'lesson';
24
+		$this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27 27
 		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
28 28
 
29
-        $this->question_order = '';
29
+		$this->question_order = '';
30 30
 
31 31
 		// Admin actions
32 32
 		if ( is_admin() ) {
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
 			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85 85
 			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
86 86
 
87
-            // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
87
+			// output bulk edit fields
88
+			add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
+			add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
90 90
 
91
-            // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
91
+			// load quick edit default values
92
+			add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94
-            // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
94
+			// save bulk edit fields
95
+			add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
96 96
 
97
-            // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
97
+			// flush rewrite rules when saving a lesson
98
+			add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		$post_args = array(	'post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192
-    						'order'           	=> 'ASC',
193
-    						'exclude' 			=> $post->ID,
192
+							'order'           	=> 'ASC',
193
+							'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196 196
 		$posts_array = get_posts( $post_args );
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		$checked = '';
228 228
 		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
229
+	 		$checked = checked( 'preview', $lesson_preview, false );
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
 	/**
278
-     * Update the lesson quiz and all the post meta
278
+	 * Update the lesson quiz and all the post meta
279 279
 	 *
280 280
 	 * @access public
281 281
 	 * @return integer|boolean $post_id or false
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 		}
297 297
 
298 298
 		// Temporarily disable the filter
299
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
299
+		remove_action( 'save_post', array( $this, 'quiz_update' ) );
300 300
 		// Save the Quiz
301 301
 		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
302 302
 
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 
312 312
 		// Setup Query Arguments
313 313
 		$post_type_args = array(	'post_content' => $post_content,
314
-  		    						'post_status' => $post_status,
315
-  		    						'post_title' => $post_title,
316
-  		    						'post_type' => 'quiz',
317
-                                    'post_parent' => $post_id,
318
-  		    						);
314
+  									'post_status' => $post_status,
315
+  									'post_title' => $post_title,
316
+  									'post_type' => 'quiz',
317
+									'post_parent' => $post_id,
318
+  									);
319 319
 
320 320
 		$settings = $this->get_quiz_settings();
321 321
 
@@ -323,48 +323,48 @@  discard block
 block discarded – undo
323 323
 		if ( 0 < $quiz_id ) {
324 324
 			// Update the Quiz
325 325
 			$post_type_args[ 'ID' ] = $quiz_id;
326
-		    wp_update_post($post_type_args);
327
-
328
-		    // Update the post meta data
329
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
330
-
331
-		    foreach( $settings as $field ) {
332
-		    	if( 'random_question_order' != $field['id'] ) {
333
-			    	$value = $this->get_submitted_setting_value( $field );
334
-			    	if( isset( $value ) ) {
335
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
336
-			    	}
337
-			    }
338
-		    }
339
-
340
-		    // Set the post terms for quiz-type
341
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
326
+			wp_update_post($post_type_args);
327
+
328
+			// Update the post meta data
329
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
330
+
331
+			foreach( $settings as $field ) {
332
+				if( 'random_question_order' != $field['id'] ) {
333
+					$value = $this->get_submitted_setting_value( $field );
334
+					if( isset( $value ) ) {
335
+						update_post_meta( $quiz_id, '_' . $field['id'], $value );
336
+					}
337
+				}
338
+			}
339
+
340
+			// Set the post terms for quiz-type
341
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
342 342
 		} else {
343 343
 			// Create the Quiz
344
-		    $quiz_id = wp_insert_post($post_type_args);
345
-
346
-		    // Add the post meta data WP will add it if it doesn't exist
347
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
348
-
349
-		    foreach( $settings as $field ) {
350
-		    	if( 'random_question_order' != $field['id'] ) {
351
-
352
-                    //ignore values not posted to avoid
353
-                    // overwriting with empty or default values
354
-                    // when the values are posted from bulk edit or quick edit
355
-                    if( !isset( $_POST[ $field['id'] ] ) ){
356
-                        continue;
357
-                    }
358
-
359
-			    	$value = $this->get_submitted_setting_value( $field );
360
-			    	if( isset( $value ) ) {
361
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
362
-			    	}
363
-			    }
364
-		    }
365
-
366
-		    // Set the post terms for quiz-type
367
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
344
+			$quiz_id = wp_insert_post($post_type_args);
345
+
346
+			// Add the post meta data WP will add it if it doesn't exist
347
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
348
+
349
+			foreach( $settings as $field ) {
350
+				if( 'random_question_order' != $field['id'] ) {
351
+
352
+					//ignore values not posted to avoid
353
+					// overwriting with empty or default values
354
+					// when the values are posted from bulk edit or quick edit
355
+					if( !isset( $_POST[ $field['id'] ] ) ){
356
+						continue;
357
+					}
358
+
359
+					$value = $this->get_submitted_setting_value( $field );
360
+					if( isset( $value ) ) {
361
+						add_post_meta( $quiz_id, '_' . $field['id'], $value );
362
+					}
363
+				}
364
+			}
365
+
366
+			// Set the post terms for quiz-type
367
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
368 368
 		} // End If Statement
369 369
 
370 370
 		// Add default lesson order meta value
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		}
387 387
 
388 388
 		// Restore the previously disabled filter
389
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
389
+		add_action( 'save_post', array( $this, 'quiz_update' ) );
390 390
 
391 391
 	} // End post_updated()
392 392
 
@@ -426,22 +426,22 @@  discard block
 block discarded – undo
426 426
 		// Get the meta key.
427 427
 		$meta_key = '_' . $post_key;
428 428
 
429
-        //ignore fields are not posted
429
+		//ignore fields are not posted
430 430
 
431
-        if( !isset( $_POST[ $post_key ] ) ){
431
+		if( !isset( $_POST[ $post_key ] ) ){
432 432
 
433
-            // except for lesson preview checkbox field
434
-            if( 'lesson_preview' == $post_key ){
433
+			// except for lesson preview checkbox field
434
+			if( 'lesson_preview' == $post_key ){
435 435
 
436
-                $_POST[ $post_key ] = '';
436
+				$_POST[ $post_key ] = '';
437 437
 
438
-            } else {
438
+			} else {
439 439
 
440
-                return false;
440
+				return false;
441 441
 
442
-            }
442
+			}
443 443
 
444
-        }
444
+		}
445 445
 
446 446
 		// Get the posted data and sanitize it for use as an HTML class.
447 447
 		if ( 'lesson_video_embed' == $post_key) {
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
451 451
 		} // End If Statement
452 452
 
453
-        // update field with the new value
454
-        if( -1 != $new_meta_value  ){
455
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
456
-        }
453
+		// update field with the new value
454
+		if( -1 != $new_meta_value  ){
455
+			return update_post_meta( $post_id, $meta_key, $new_meta_value );
456
+		}
457 457
 
458 458
 	} // End save_post_meta()
459 459
 
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 		$post_args = array(	'post_type' 		=> 'course',
479 479
 							'posts_per_page' 		=> -1,
480 480
 							'orderby'         	=> 'title',
481
-    						'order'           	=> 'ASC',
482
-    						'post_status'      	=> 'any',
483
-    						'suppress_filters' 	=> 0,
481
+							'order'           	=> 'ASC',
482
+							'post_status'      	=> 'any',
483
+							'suppress_filters' 	=> 0,
484 484
 							);
485 485
 		$posts_array = get_posts( $post_args );
486 486
 		// Buid the HTML to Output
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
 		// Nonce
489 489
 		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
490 490
 
491
-        // Select the course for the lesson
492
-        $drop_down_args = array(
493
-            'name'=>'lesson_course',
494
-            'id' => 'lesson-course-options'
495
-        );
491
+		// Select the course for the lesson
492
+		$drop_down_args = array(
493
+			'name'=>'lesson_course',
494
+			'id' => 'lesson-course-options'
495
+		);
496 496
 
497
-        $courses = WooThemes_Sensei_Course::get_all_courses();
498
-        $courses_options = array();
499
-        foreach( $courses as $course ){
500
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
501
-        }
502
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
497
+		$courses = WooThemes_Sensei_Course::get_all_courses();
498
+		$courses_options = array();
499
+		foreach( $courses as $course ){
500
+			$courses_options[ $course->ID ] = get_the_title( $course ) ;
501
+		}
502
+		$html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
503 503
 
504
-        // Course Actions Panel
504
+		// Course Actions Panel
505 505
 		if ( current_user_can( 'publish_courses' )) {
506 506
 				$html .= '<div id="lesson-course-actions">';
507 507
 					$html .= '<p>';
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
 							} // End For Loop
528 528
 						$html .= '</select>' . "\n";
529 529
 						// Course Product
530
-                        if ( Sensei_WC::is_woocommerce_active() ) {
530
+						if ( Sensei_WC::is_woocommerce_active() ) {
531 531
 	  						// Get the Products
532 532
 							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
533 533
 
534 534
 							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
535 535
 													'posts_per_page' 		=> -1,
536 536
 													'orderby'         	=> 'title',
537
-	    											'order'           	=> 'DESC',
538
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
539
-	    											'tax_query'			=> array(
537
+													'order'           	=> 'DESC',
538
+													'post_status'		=> array( 'publish', 'private', 'draft' ),
539
+													'tax_query'			=> array(
540 540
 														array(
541 541
 															'taxonomy'	=> 'product_type',
542 542
 															'field'		=> 'slug',
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 															'operator'	=> 'NOT IN'
545 545
 														)
546 546
 													),
547
-	    											'suppress_filters' 	=> 0
547
+													'suppress_filters' 	=> 0
548 548
 													);
549 549
 							$products_array = get_posts( $product_args );
550 550
 							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
@@ -872,58 +872,58 @@  discard block
 block discarded – undo
872 872
 					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
873 873
 						$html .= '<td colspan="5">';
874 874
 							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
875
-					    	$html .= '<div class="question_required_fields">';
876
-
877
-						    	// Question title
878
-						    	$html .= '<div>';
879
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
880
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
881
-						    	$html .= '</div>';
882
-
883
-						    	// Question description
884
-						    	$html .= '<div>';
885
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
886
-						    	$html .= '</div>';
887
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
888
-
889
-						    	// Question grade
890
-						    	$html .= '<div>';
891
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
892
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
893
-						    	$html .= '</div>';
894
-
895
-						    	// Random order
896
-						    	if( $question_type == 'multiple-choice' ) {
897
-						    		$html .= '<div>';
898
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
899
-						    		$html .= '</div>';
900
-						    	}
901
-
902
-						    	// Question media
903
-						    	$html .= '<div>';
904
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
905
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
906
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
907
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
908
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
909
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
910
-						    	$html .= '</div>';
911
-
912
-						    $html .= '</div>';
913
-
914
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
915
-
916
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
875
+							$html .= '<div class="question_required_fields">';
876
+
877
+								// Question title
878
+								$html .= '<div>';
879
+									$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
880
+									$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
881
+								$html .= '</div>';
882
+
883
+								// Question description
884
+								$html .= '<div>';
885
+									$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
886
+								$html .= '</div>';
887
+									$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
888
+
889
+								// Question grade
890
+								$html .= '<div>';
891
+									$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
892
+									$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
893
+								$html .= '</div>';
894
+
895
+								// Random order
896
+								if( $question_type == 'multiple-choice' ) {
897
+									$html .= '<div>';
898
+										$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
899
+									$html .= '</div>';
900
+								}
901
+
902
+								// Question media
903
+								$html .= '<div>';
904
+									$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
905
+									$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
906
+									$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
907
+									$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
908
+									$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
909
+									$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
910
+								$html .= '</div>';
911
+
912
+							$html .= '</div>';
913
+
914
+							$html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
915
+
916
+							$html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
917 917
 							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
918 918
 
919 919
 							if( 'quiz' == $context ) {
920
-					    		$html .= '<div class="update-question">';
921
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
922
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
923
-					    		$html .= '</div>';
924
-					    	}
920
+								$html .= '<div class="update-question">';
921
+									$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
922
+									$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
923
+								$html .= '</div>';
924
+							}
925 925
 
926
-			    		$html .= '</td>';
926
+						$html .= '</td>';
927 927
 					$html .= '</tr>';
928 928
 				}
929 929
 
@@ -944,20 +944,20 @@  discard block
 block discarded – undo
944 944
 			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
945 945
 
946 946
 			if( 'quiz' == $context ) {
947
-	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
948
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
949
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
950
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
951
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
952
-	    			}
953
-	    		$html .= '</h2>';
954
-	    	}
947
+				$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
948
+					$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
949
+					$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
950
+					if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
951
+						$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
952
+					}
953
+				$html .= '</h2>';
954
+			}
955 955
 
956
-	    	$html .= '<div class="tab-content" id="tab-new-content">';
956
+			$html .= '<div class="tab-content" id="tab-new-content">';
957 957
 
958
-	    		if( 'quiz' == $context ) {
959
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
960
-	    		}
958
+				if( 'quiz' == $context ) {
959
+					$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
960
+				}
961 961
 
962 962
 				$html .= '<div class="question">';
963 963
 					$html .= '<div class="question_required_fields">';
@@ -999,18 +999,18 @@  discard block
 block discarded – undo
999 999
 
1000 1000
 						// Random order
1001 1001
 						$html .= '<p class="add_question_random_order">';
1002
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1003
-			    		$html .= '</p>';
1002
+							$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1003
+						$html .= '</p>';
1004 1004
 
1005
-			    		// Question media
1005
+						// Question media
1006 1006
 						$html .= '<p>';
1007
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1008
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1009
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1010
-					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1011
-					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1012
-					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1013
-				    	$html .= '</p>';
1007
+							$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1008
+							$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1009
+							$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1010
+							$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1011
+							$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1012
+							$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1013
+						$html .= '</p>';
1014 1014
 
1015 1015
 					$html .= '</div>';
1016 1016
 				$html .= '</div>';
@@ -1021,19 +1021,19 @@  discard block
 block discarded – undo
1021 1021
 
1022 1022
 				if( 'quiz' == $context ) {
1023 1023
 					$html .= '<div class="add-question">';
1024
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1025
-		    		$html .= '</div>';
1026
-		    	}
1024
+						$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1025
+					$html .= '</div>';
1026
+				}
1027 1027
 
1028
-		    $html .= '</div>';
1028
+			$html .= '</div>';
1029 1029
 
1030
-		    if( 'quiz' == $context ) {
1030
+			if( 'quiz' == $context ) {
1031 1031
 
1032
-			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1032
+				$html .= '<div class="tab-content hidden" id="tab-existing-content">';
1033 1033
 
1034
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1034
+					$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1035 1035
 
1036
-			    	$html .= '<div id="existing-filters" class="alignleft actions">
1036
+					$html .= '<div id="existing-filters" class="alignleft actions">
1037 1037
 			    				<select id="existing-status">
1038 1038
 			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1039 1039
 			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
@@ -1041,23 +1041,23 @@  discard block
 block discarded – undo
1041 1041
 			    				</select>
1042 1042
 			    				<select id="existing-type">
1043 1043
 			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1044
-							    	foreach ( $question_types as $type => $label ) {
1044
+									foreach ( $question_types as $type => $label ) {
1045 1045
 										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1046 1046
 									}
1047
-    				$html .= '</select>
1047
+					$html .= '</select>
1048 1048
     							<select id="existing-category">
1049 1049
 			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1050
-				    				foreach( $question_cats as $cat ) {
1050
+									foreach( $question_cats as $cat ) {
1051 1051
 										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1052 1052
 									}
1053
-    				$html .= '</select>
1053
+					$html .= '</select>
1054 1054
     							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1055 1055
     							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1056 1056
 			    			</div>';
1057 1057
 
1058
-			    	$html .= '<table id="existing-table" class="widefat">';
1058
+					$html .= '<table id="existing-table" class="widefat">';
1059 1059
 
1060
-			    		$html .= '<thead>
1060
+						$html .= '<thead>
1061 1061
 									    <tr>
1062 1062
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1063 1063
 									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
@@ -1085,28 +1085,28 @@  discard block
 block discarded – undo
1085 1085
 
1086 1086
 						$html .= '</tbody>';
1087 1087
 
1088
-			    	$html .= '</table>';
1088
+					$html .= '</table>';
1089 1089
 
1090
-			    	$next_class = '';
1091
-			    	if( $questions['count'] <= 10 ) {
1092
-			    		$next_class = 'hidden';
1093
-			    	}
1090
+					$next_class = '';
1091
+					if( $questions['count'] <= 10 ) {
1092
+						$next_class = 'hidden';
1093
+					}
1094 1094
 
1095
-			    	$html .= '<div id="existing-pagination">';
1096
-			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1097
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1098
-			    	$html .= '</div>';
1095
+					$html .= '<div id="existing-pagination">';
1096
+						$html .= '<input type="hidden" id="existing-page" value="1" />';
1097
+						$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1098
+					$html .= '</div>';
1099 1099
 
1100
-			    	$html .= '<div class="existing-actions">';
1101
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1102
-			    	$html .= '</div>';
1100
+					$html .= '<div class="existing-actions">';
1101
+						$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1102
+					$html .= '</div>';
1103 1103
 
1104
-			    $html .= '</div>';
1104
+				$html .= '</div>';
1105 1105
 
1106
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1107
-				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1106
+				if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1107
+					$html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1108 1108
 
1109
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1109
+						$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1110 1110
 
1111 1111
 						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1112 1112
 						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 
1120 1120
 						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1121 1121
 
1122
-				    $html .= '</div>';
1122
+					$html .= '</div>';
1123 1123
 				}
1124 1124
 			}
1125 1125
 
@@ -1192,14 +1192,14 @@  discard block
 block discarded – undo
1192 1192
 
1193 1193
 		$qry = new WP_Query( $args );
1194 1194
 
1195
-        /**
1196
-         * Filter existing questions query
1197
-         *
1198
-         * @since 1.8.0
1199
-         *
1200
-         * @param WP_Query $wp_query
1201
-         */
1202
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1195
+		/**
1196
+		 * Filter existing questions query
1197
+		 *
1198
+		 * @since 1.8.0
1199
+		 *
1200
+		 * @param WP_Query $wp_query
1201
+		 */
1202
+		$qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1203 1203
 
1204 1204
 		$questions['questions'] = $qry->posts;
1205 1205
 		$questions['count'] = intval( $qry->found_posts );
@@ -1214,14 +1214,14 @@  discard block
 block discarded – undo
1214 1214
 
1215 1215
 		if( ! $question_id ) {
1216 1216
 
1217
-            return;
1217
+			return;
1218 1218
 
1219
-        }
1219
+		}
1220 1220
 
1221 1221
 		$existing_class = '';
1222 1222
 		if( $row % 2 ) {
1223
-            $existing_class = 'alternate';
1224
-        }
1223
+			$existing_class = 'alternate';
1224
+		}
1225 1225
 
1226 1226
 		$question_type = Sensei()->question->get_question_type( $question_id );
1227 1227
 
@@ -1355,67 +1355,67 @@  discard block
 block discarded – undo
1355 1355
 							}
1356 1356
 						}
1357 1357
 
1358
-				    	// Calculate total wrong answers available (defaults to 4)
1359
-				    	$total_wrong = 0;
1360
-				    	if( $question_id ) {
1361
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1362
-				    	}
1363
-				    	if( 0 == intval( $total_wrong ) ) {
1364
-				    		$total_wrong = 1;
1365
-				    	}
1358
+						// Calculate total wrong answers available (defaults to 4)
1359
+						$total_wrong = 0;
1360
+						if( $question_id ) {
1361
+							$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1362
+						}
1363
+						if( 0 == intval( $total_wrong ) ) {
1364
+							$total_wrong = 1;
1365
+						}
1366 1366
 
1367
-                        // Setup Wrong Answer HTML
1368
-                        foreach ( $wrong_answers as $i => $answer ){
1367
+						// Setup Wrong Answer HTML
1368
+						foreach ( $wrong_answers as $i => $answer ){
1369 1369
 
1370
-                            $answer_id = $this->get_answer_id( $answer );
1371
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1372
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1373
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1374
-                            if( $question_id ) {
1370
+							$answer_id = $this->get_answer_id( $answer );
1371
+							$wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1372
+							$wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1373
+							$wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1374
+							if( $question_id ) {
1375 1375
 
1376
-                                $answers[ $answer_id ] = $wrong_answer;
1376
+								$answers[ $answer_id ] = $wrong_answer;
1377 1377
 
1378
-                            } else {
1378
+							} else {
1379 1379
 
1380
-                                $answers[] = $wrong_answer;
1380
+								$answers[] = $wrong_answer;
1381 1381
 
1382
-                            }
1382
+							}
1383 1383
 
1384
-                        } // end for each
1384
+						} // end for each
1385 1385
 
1386
-				    	$answers_sorted = $answers;
1387
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1388
-				    		$answers_sorted = array();
1389
-				    		foreach( $answer_order as $answer_id ) {
1390
-				    			if( isset( $answers[ $answer_id ] ) ) {
1391
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1392
-				    				unset( $answers[ $answer_id ] );
1393
-				    			}
1394
-				    		}
1386
+						$answers_sorted = $answers;
1387
+						if( $question_id && count( $answer_order ) > 0 ) {
1388
+							$answers_sorted = array();
1389
+							foreach( $answer_order as $answer_id ) {
1390
+								if( isset( $answers[ $answer_id ] ) ) {
1391
+									$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1392
+									unset( $answers[ $answer_id ] );
1393
+								}
1394
+							}
1395 1395
 
1396
-				    		if( count( $answers ) > 0 ) {
1397
-						    	foreach( $answers as $id => $answer ) {
1398
-						    		$answers_sorted[ $id ] = $answer;
1399
-						    	}
1400
-						    }
1401
-				    	}
1396
+							if( count( $answers ) > 0 ) {
1397
+								foreach( $answers as $id => $answer ) {
1398
+									$answers_sorted[ $id ] = $answer;
1399
+								}
1400
+							}
1401
+						}
1402 1402
 
1403 1403
 						foreach( $answers_sorted as $id => $answer ) {
1404
-				    		$html .= $answer;
1405
-				    	}
1404
+							$html .= $answer;
1405
+						}
1406 1406
 
1407
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1408
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1409
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1407
+						$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1408
+						$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1409
+						$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1410 1410
 
1411
-				    	$html .= '<div class="add_answer_options">';
1412
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1413
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1414
-				    	$html .= '</div>';
1411
+						$html .= '<div class="add_answer_options">';
1412
+							$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1413
+							$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1414
+						$html .= '</div>';
1415 1415
 
1416
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1416
+						$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1417 1417
 
1418
-			    	$html .= '</div>';
1418
+					$html .= '</div>';
1419 1419
 				break;
1420 1420
 				case 'boolean':
1421 1421
 					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1429 1429
 						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1430 1430
 
1431
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1431
+					$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1432 1432
 
1433 1433
 					$html .= '</div>';
1434 1434
 				break;
@@ -1503,17 +1503,17 @@  discard block
 block discarded – undo
1503 1503
 
1504 1504
 	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1505 1505
 
1506
-        // default field name
1507
-        $field_name = 'answer_feedback';
1508
-        if( 'boolean' == $question_type ){
1506
+		// default field name
1507
+		$field_name = 'answer_feedback';
1508
+		if( 'boolean' == $question_type ){
1509 1509
 
1510
-            $field_name = 'answer_feedback_boolean';
1510
+			$field_name = 'answer_feedback_boolean';
1511 1511
 
1512
-        }elseif( 'multiple-choice' == $question_type ){
1512
+		}elseif( 'multiple-choice' == $question_type ){
1513 1513
 
1514
-            $field_name = 'answer_feedback_multiple_choice';
1514
+			$field_name = 'answer_feedback_multiple_choice';
1515 1515
 
1516
-        }// end if
1516
+		}// end if
1517 1517
 
1518 1518
 		if( $question_counter ) {
1519 1519
 			$field_name = 'answer_' . $question_counter . '_feedback';
@@ -1718,15 +1718,15 @@  discard block
 block discarded – undo
1718 1718
 			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1719 1719
 
1720 1720
 			// Load the lessons script
1721
-            wp_enqueue_media();
1721
+			wp_enqueue_media();
1722 1722
 			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'sensei-core-select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1723 1723
 			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1724 1724
 			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1725 1725
 
1726
-            // Load the bulk edit screen script
1727
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1728
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1729
-            }
1726
+			// Load the bulk edit screen script
1727
+			if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1728
+				wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1729
+			}
1730 1730
 
1731 1731
 			// Localise script
1732 1732
 			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
@@ -1827,7 +1827,7 @@  discard block
 block discarded – undo
1827 1827
 			$nonce = esc_html( $_POST['lesson_add_course_nonce'] );
1828 1828
 		} // End If Statement
1829 1829
 		if ( ! wp_verify_nonce( $nonce, 'lesson_add_course_nonce' )
1830
-            || ! current_user_can( 'edit_lessons' ) ) {
1830
+			|| ! current_user_can( 'edit_lessons' ) ) {
1831 1831
 			die('');
1832 1832
 		} // End If Statement
1833 1833
 		// Parse POST data
@@ -1856,7 +1856,7 @@  discard block
 block discarded – undo
1856 1856
 			$nonce = esc_html( $_POST['lesson_update_question_nonce'] );
1857 1857
 		} // End If Statement
1858 1858
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_nonce' )
1859
-            ||  ! current_user_can( 'edit_questions' )) {
1859
+			||  ! current_user_can( 'edit_questions' )) {
1860 1860
 
1861 1861
 			die('');
1862 1862
 
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
 		} // End If Statement
1910 1910
 
1911 1911
 		if( ! wp_verify_nonce( $nonce, 'lesson_add_multiple_questions_nonce' )
1912
-            || ! current_user_can( 'edit_lessons' ) ) {
1912
+			|| ! current_user_can( 'edit_lessons' ) ) {
1913 1913
 			die( $return );
1914 1914
 		} // End If Statement
1915 1915
 
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
 		} // End If Statement
1966 1966
 
1967 1967
 		if( ! wp_verify_nonce( $nonce, 'lesson_remove_multiple_questions_nonce' )
1968
-        || ! current_user_can( 'edit_lessons' ) ) {
1968
+		|| ! current_user_can( 'edit_lessons' ) ) {
1969 1969
 			die('');
1970 1970
 		} // End If Statement
1971 1971
 
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
 		} // End If Statement
2013 2013
 
2014 2014
 		if( ! wp_verify_nonce( $nonce, 'lesson_add_existing_questions_nonce' )
2015
-        || ! current_user_can( 'edit_lessons' ) ) {
2015
+		|| ! current_user_can( 'edit_lessons' ) ) {
2016 2016
 			die('');
2017 2017
 		} // End If Statement
2018 2018
 
@@ -2037,12 +2037,12 @@  discard block
 block discarded – undo
2037 2037
 
2038 2038
 					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2039 2039
 					if( ! in_array( $quiz_id, $quizzes ) ) {
2040
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2040
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2041 2041
 						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2042 2042
 						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2043
-			    	}
2043
+					}
2044 2044
 
2045
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2045
+					add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2046 2046
 					$question_type = Sensei()->question->get_question_type( $question_id );
2047 2047
 
2048 2048
 					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
@@ -2064,7 +2064,7 @@  discard block
 block discarded – undo
2064 2064
 		} // End If Statement
2065 2065
 
2066 2066
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_grade_type_nonce' )
2067
-        || ! current_user_can( 'edit_lessons' ) ) {
2067
+		|| ! current_user_can( 'edit_lessons' ) ) {
2068 2068
 
2069 2069
 			die('');
2070 2070
 
@@ -2084,8 +2084,8 @@  discard block
 block discarded – undo
2084 2084
 			$nonce = esc_html( $_POST['lesson_update_question_order_nonce'] );
2085 2085
 		} // End If Statement
2086 2086
 
2087
-        if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2088
-            ||! current_user_can( 'edit_lessons' ) ) {
2087
+		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2088
+			||! current_user_can( 'edit_lessons' ) ) {
2089 2089
 			die('');
2090 2090
 		} // End If Statement
2091 2091
 
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
 			$nonce = esc_html( $_POST['lesson_update_question_order_random_nonce'] );
2112 2112
 		} // End If Statement
2113 2113
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_random_nonce' )
2114
-            || ! current_user_can( 'edit_lessons' ) ) {
2114
+			|| ! current_user_can( 'edit_lessons' ) ) {
2115 2115
 
2116 2116
 			die('');
2117 2117
 
@@ -2161,34 +2161,34 @@  discard block
 block discarded – undo
2161 2161
 		$post_content = $course_content;
2162 2162
 		// Course Query Arguments
2163 2163
 		$post_type_args = array(	'post_content' => $post_content,
2164
-  		    						'post_status' => $post_status,
2165
-  		    						'post_title' => $post_title,
2166
-  		    						'post_type' => $post_type
2167
-  		    						);
2164
+  									'post_status' => $post_status,
2165
+  									'post_title' => $post_title,
2166
+  									'post_type' => $post_type
2167
+  									);
2168 2168
   		// Only save if there is a valid title
2169 2169
   		if ( $post_title != '' ) {
2170
-  		    // Check for prerequisite courses & product id
2171
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2172
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2173
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2174
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2175
-  		    // Insert or Update the Lesson Quiz
2176
-		    if ( 0 < $course_id ) {
2177
-		    	$post_type_args[ 'ID' ] = $course_id;
2178
-		    	$course_id = wp_update_post($post_type_args);
2179
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2180
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2181
-		    	if ( 0 < $course_category_id ) {
2182
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2183
-		    	} // End If Statement
2184
-		    } else {
2185
-		    	$course_id = wp_insert_post($post_type_args);
2186
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2187
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2188
-		    	if ( 0 < $course_category_id ) {
2189
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2190
-		    	} // End If Statement
2191
-		    } // End If Statement
2170
+  			// Check for prerequisite courses & product id
2171
+  			$course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2172
+  			$course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2173
+  			$course_category_id = absint( $data[ 'course_category' ] );
2174
+  			if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2175
+  			// Insert or Update the Lesson Quiz
2176
+			if ( 0 < $course_id ) {
2177
+				$post_type_args[ 'ID' ] = $course_id;
2178
+				$course_id = wp_update_post($post_type_args);
2179
+				update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2180
+				update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2181
+				if ( 0 < $course_category_id ) {
2182
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2183
+				} // End If Statement
2184
+			} else {
2185
+				$course_id = wp_insert_post($post_type_args);
2186
+				add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2187
+				add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2188
+				if ( 0 < $course_category_id ) {
2189
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2190
+				} // End If Statement
2191
+			} // End If Statement
2192 2192
 		} // End If Statement
2193 2193
   		// Check that the insert or update saved by testing the post id
2194 2194
   		if ( 0 < $course_id ) {
@@ -2279,17 +2279,17 @@  discard block
 block discarded – undo
2279 2279
 		$answer_feedback = '';
2280 2280
 		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2281 2281
 
2282
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2282
+			$answer_feedback = $data[ 'answer_feedback_boolean' ];
2283 2283
 
2284 2284
 		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2285 2285
 
2286
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2286
+			$answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2287 2287
 
2288
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2288
+		}elseif( isset( $data[ 'answer_feedback' ] )  ){
2289 2289
 
2290
-            $answer_feedback = $data[ 'answer_feedback' ];
2290
+			$answer_feedback = $data[ 'answer_feedback' ];
2291 2291
 
2292
-        } // End If Statement
2292
+		} // End If Statement
2293 2293
 
2294 2294
 		$post_title = $question_text;
2295 2295
 		$post_author = $data[ 'post_author' ];
@@ -2304,10 +2304,10 @@  discard block
 block discarded – undo
2304 2304
 		}
2305 2305
 		// Question Query Arguments
2306 2306
 		$post_type_args = array(	'post_content' => $post_content,
2307
-  		    						'post_status' => $post_status,
2308
-  		    						'post_title' => $post_title,
2309
-  		    						'post_type' => $post_type
2310
-  		    						);
2307
+  									'post_status' => $post_status,
2308
+  									'post_title' => $post_title,
2309
+  									'post_type' => $post_type
2310
+  									);
2311 2311
 
2312 2312
   		// Remove empty values and reindex the array
2313 2313
   		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
@@ -2343,14 +2343,14 @@  discard block
 block discarded – undo
2343 2343
   		if ( $post_title != '' ) {
2344 2344
 
2345 2345
   			// Get Quiz ID for the question
2346
-  		    $quiz_id = $data['quiz_id'];
2346
+  			$quiz_id = $data['quiz_id'];
2347 2347
 
2348
-  		    // Get question media
2348
+  			// Get question media
2349 2349
 			$question_media = $data['question_media'];
2350 2350
 
2351
-  		    // Get answer order
2352
-  		    $answer_order = '';
2353
-  		    if( isset( $data['answer_order'] ) ) {
2351
+  			// Get answer order
2352
+  			$answer_order = '';
2353
+  			if( isset( $data['answer_order'] ) ) {
2354 2354
 				$answer_order = $data['answer_order'];
2355 2355
 			}
2356 2356
 
@@ -2360,38 +2360,38 @@  discard block
 block discarded – undo
2360 2360
 				$random_order = $data['random_order'];
2361 2361
 			}
2362 2362
 
2363
-  		    // Insert or Update the question
2364
-  		    if ( 0 < $question_id ) {
2365
-
2366
-  		    	$post_type_args[ 'ID' ] = $question_id;
2367
-		    	$question_id = wp_update_post( $post_type_args );
2368
-
2369
-		    	// Update poast meta
2370
-		    	if( 'quiz' == $context ) {
2371
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2372
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2373
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2374
-			    	}
2375
-		    	}
2376
-
2377
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2378
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2379
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2380
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2381
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2382
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2383
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2384
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2385
-
2386
-		    	if( 'quiz' != $context ) {
2387
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2388
-		    	}
2363
+  			// Insert or Update the question
2364
+  			if ( 0 < $question_id ) {
2365
+
2366
+  				$post_type_args[ 'ID' ] = $question_id;
2367
+				$question_id = wp_update_post( $post_type_args );
2368
+
2369
+				// Update poast meta
2370
+				if( 'quiz' == $context ) {
2371
+					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2372
+					if( ! in_array( $quiz_id, $quizzes ) ) {
2373
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2374
+					}
2375
+				}
2376
+
2377
+				update_post_meta( $question_id, '_question_grade', $question_grade );
2378
+				update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2379
+				update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2380
+				update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2381
+				update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2382
+				update_post_meta( $question_id, '_question_media', $question_media );
2383
+				update_post_meta( $question_id, '_answer_order', $answer_order );
2384
+				update_post_meta( $question_id, '_random_order', $random_order );
2385
+
2386
+				if( 'quiz' != $context ) {
2387
+					wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2388
+				}
2389 2389
 				// Don't store empty value, no point
2390 2390
 				if ( !empty($answer_feedback) ) {
2391 2391
 					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2392 2392
 				}
2393 2393
 
2394
-		    } else {
2394
+			} else {
2395 2395
 				$question_id = wp_insert_post( $post_type_args );
2396 2396
 				$question_count = intval( $data['question_count'] );
2397 2397
 				++$question_count;
@@ -2404,29 +2404,29 @@  discard block
 block discarded – undo
2404 2404
 				}
2405 2405
 
2406 2406
 				if( isset( $question_grade ) ) {
2407
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2408
-		    	}
2409
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2410
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2411
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2412
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2413
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2414
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2415
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2416
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2407
+					add_post_meta( $question_id, '_question_grade', $question_grade );
2408
+				}
2409
+				add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2410
+				add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2411
+				add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2412
+				add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2413
+				add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2414
+				add_post_meta( $question_id, '_question_media', $question_media );
2415
+				add_post_meta( $question_id, '_answer_order', $answer_order );
2416
+				add_post_meta( $question_id, '_random_order', $random_order );
2417 2417
 				// Don't store empty value, no point
2418 2418
 				if ( !empty($answer_feedback) ) {
2419 2419
 					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2420 2420
 				}
2421 2421
 
2422
-		    	// Set the post terms for question-type
2423
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2422
+				// Set the post terms for question-type
2423
+				wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2424 2424
 
2425
-			    if( $question_category ) {
2426
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2427
-	    		}
2425
+				if( $question_category ) {
2426
+					wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2427
+				}
2428 2428
 
2429
-		    } // End If Statement
2429
+			} // End If Statement
2430 2430
 		} // End If Statement
2431 2431
   		// Check that the insert or update saved by testing the post id
2432 2432
   		if ( 0 < $question_id ) {
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
 	public function lesson_complexities() {
2476 2476
 
2477 2477
 		// V2 - make filter for this array
2478
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2478
+		$lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2479 2479
 									'std' => __( 'Standard', 'woothemes-sensei' ),
2480 2480
 									'hard' => __( 'Hard', 'woothemes-sensei' )
2481 2481
 									);
@@ -2542,14 +2542,14 @@  discard block
 block discarded – undo
2542 2542
 		$post_args = array(	'post_type' 		=> 'quiz',
2543 2543
 							'posts_per_page' 		=> 1,
2544 2544
 							'orderby'         	=> 'title',
2545
-    						'order'           	=> 'DESC',
2546
-    						'post_parent'      	=> $lesson_id,
2547
-    						'post_status'		=> $post_status,
2545
+							'order'           	=> 'DESC',
2546
+							'post_parent'      	=> $lesson_id,
2547
+							'post_status'		=> $post_status,
2548 2548
 							'suppress_filters' 	=> 0,
2549 2549
 							'fields'            => $fields
2550 2550
 							);
2551 2551
 		$posts_array = get_posts( $post_args );
2552
-        $quiz_id = array_shift($posts_array);
2552
+		$quiz_id = array_shift($posts_array);
2553 2553
 
2554 2554
 		return $quiz_id;
2555 2555
 	} // End lesson_quizzes()
@@ -2557,34 +2557,34 @@  discard block
 block discarded – undo
2557 2557
 
2558 2558
 	/**
2559 2559
 	 * Fetches all the questions for a quiz depending on certain conditions.
2560
-     *
2561
-     * Determine which questions should be shown depending on:
2562
-     * - admin/teacher selected questions to be shown
2563
-     * - questions shown to a user previously (saved as asked questions)
2564
-     * - limit number of questions lesson setting
2565 2560
 	 *
2566
-     * @since 1.0
2561
+	 * Determine which questions should be shown depending on:
2562
+	 * - admin/teacher selected questions to be shown
2563
+	 * - questions shown to a user previously (saved as asked questions)
2564
+	 * - limit number of questions lesson setting
2565
+	 *
2566
+	 * @since 1.0
2567 2567
 	 * @param int $quiz_id (default: 0)
2568 2568
 	 * @param string $post_status (default: 'publish')
2569 2569
 	 * @param string $orderby (default: 'meta_value_num title')
2570 2570
 	 * @param string $order (default: 'ASC')
2571
-     *
2571
+	 *
2572 2572
 	 * @return array $questions { $question type WP_Post }
2573 2573
 	 */
2574 2574
 	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2575 2575
 
2576 2576
 		$quiz_id = (string) $quiz_id;
2577
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2577
+		$quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2578 2578
 
2579
-        // setup the user id
2580
-        if( is_admin() ) {
2581
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2582
-        } else {
2583
-            $user_id = get_current_user_id();
2584
-        }
2579
+		// setup the user id
2580
+		if( is_admin() ) {
2581
+			$user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2582
+		} else {
2583
+			$user_id = get_current_user_id();
2584
+		}
2585 2585
 
2586
-        // get the users current status on the lesson
2587
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2586
+		// get the users current status on the lesson
2587
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2588 2588
 
2589 2589
 		// Set the default question order if it has not already been set for this quiz
2590 2590
 		$this->set_default_question_order( $quiz_id );
@@ -2614,14 +2614,14 @@  discard block
 block discarded – undo
2614 2614
 			'suppress_filters' 	=> 0
2615 2615
 		);
2616 2616
 
2617
-        //query the questions
2617
+		//query the questions
2618 2618
 		$questions_query = new WP_Query( $question_query_args );
2619 2619
 
2620
-        // Set return array to initially include all items
2621
-        $questions = $questions_query->posts;
2620
+		// Set return array to initially include all items
2621
+		$questions = $questions_query->posts;
2622 2622
 
2623
-        // set the questions array that will be manipulated within this function
2624
-        $questions_array = $questions_query->posts;
2623
+		// set the questions array that will be manipulated within this function
2624
+		$questions_array = $questions_query->posts;
2625 2625
 
2626 2626
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2627 2627
 		$selected_questions = false;
@@ -2734,36 +2734,36 @@  discard block
 block discarded – undo
2734 2734
 			}
2735 2735
 		}
2736 2736
 
2737
-        // Save the questions that will be asked for the current user
2738
-        // this happens only once per user/quiz, unless the user resets the quiz
2739
-        if( ! is_admin() ){
2737
+		// Save the questions that will be asked for the current user
2738
+		// this happens only once per user/quiz, unless the user resets the quiz
2739
+		if( ! is_admin() ){
2740 2740
 
2741
-            if( $user_lesson_status ) {
2741
+			if( $user_lesson_status ) {
2742 2742
 
2743
-                $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2744
-                if ( empty($questions_asked) && $user_lesson_status) {
2743
+				$questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2744
+				if ( empty($questions_asked) && $user_lesson_status) {
2745 2745
 
2746
-                    $questions_asked = array();
2747
-                    foreach ($questions as $question) {
2746
+					$questions_asked = array();
2747
+					foreach ($questions as $question) {
2748 2748
 
2749
-                        $questions_asked[] = $question->ID;
2749
+						$questions_asked[] = $question->ID;
2750 2750
 
2751
-                    }
2751
+					}
2752 2752
 
2753
-                    // save the questions asked id
2754
-                    $questions_asked_csv = implode(',', $questions_asked);
2755
-                    update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2753
+					// save the questions asked id
2754
+					$questions_asked_csv = implode(',', $questions_asked);
2755
+					update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2756 2756
 
2757
-                }
2758
-            }
2759
-        }
2757
+				}
2758
+			}
2759
+		}
2760 2760
 
2761
-        /**
2762
-         * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2763
-         *
2764
-         * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2765
-         * @since 1.8.0
2766
-         */
2761
+		/**
2762
+		 * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2763
+		 *
2764
+		 * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2765
+		 * @since 1.8.0
2766
+		 */
2767 2767
 		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2768 2768
 
2769 2769
 	} // End lesson_quiz_questions()
@@ -2867,7 +2867,7 @@  discard block
 block discarded – undo
2867 2867
  			// Display Image Placeholder if none
2868 2868
 			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2869 2869
 
2870
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2870
+				$img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2871 2871
 
2872 2872
 			} // End If Statement
2873 2873
 
@@ -2879,418 +2879,418 @@  discard block
 block discarded – undo
2879 2879
 
2880 2880
 	} // End lesson_image()
2881 2881
 
2882
-    /**
2883
-     * Ooutpu the lesson image
2884
-     *
2885
-     * @since 1.9.0
2886
-     * @param integer $lesson_id
2887
-     */
2888
-    public static function the_lesson_image( $lesson_id = 0 ){
2882
+	/**
2883
+	 * Ooutpu the lesson image
2884
+	 *
2885
+	 * @since 1.9.0
2886
+	 * @param integer $lesson_id
2887
+	 */
2888
+	public static function the_lesson_image( $lesson_id = 0 ){
2889 2889
 
2890
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2890
+		echo Sensei()->lesson->lesson_image( $lesson_id );
2891 2891
 
2892
-    }
2892
+	}
2893 2893
 
2894 2894
 	/**
2895 2895
 	 * Returns the the lesson excerpt.
2896 2896
 	 *
2897 2897
 	 * @param WP_Post $lesson
2898
-     * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2898
+	 * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2899 2899
 	 * @return string
2900 2900
 	 */
2901 2901
 	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2902 2902
 		$html = '';
2903 2903
 		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2904 2904
 
2905
-            $excerpt =  $lesson->post_excerpt;
2905
+			$excerpt =  $lesson->post_excerpt;
2906 2906
 
2907
-            // if $add_p_tags true wrap with <p> else return the excerpt as is
2908
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2907
+			// if $add_p_tags true wrap with <p> else return the excerpt as is
2908
+			$html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2909 2909
 
2910 2910
 		}
2911 2911
 		return apply_filters( 'sensei_lesson_excerpt', $html );
2912 2912
 
2913 2913
 	} // End lesson_excerpt()
2914 2914
 
2915
-    /**
2916
-     * Returns the course for a given lesson
2917
-     *
2918
-     * @since 1.7.4
2919
-     * @access public
2920
-     *
2921
-     * @param int $lesson_id
2922
-     * @return int|bool $course_id or bool when nothing is found.
2923
-     */
2924
-     public function get_course_id( $lesson_id ){
2925
-
2926
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2927
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2928
-             return false;
2929
-         }
2930
-
2931
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2932
-
2933
-         // make sure the course id is valid
2934
-         if( empty( $lesson_course_id )
2935
-             || is_array( $lesson_course_id )
2936
-             || intval( $lesson_course_id ) < 1
2937
-             || 'course' != get_post_type( $lesson_course_id ) ){
2938
-
2939
-             return false;
2940
-
2941
-         }
2942
-
2943
-         return $lesson_course_id;
2944
-
2945
-     }// en get_course_id
2946
-
2947
-    /**
2948
-     * Add the admin all lessons screen edit options.
2949
-     *
2950
-     * The fields in this function work for both quick and bulk edit. The ID attributes is used
2951
-     * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2952
-     * name attribute is will be used by the quick edit and submitted via standard POST. This
2953
-     * will use this classes save_post_meta function to save the new field data.
2954
-     *
2955
-     * @hooked quick_edit_custom_box
2956
-     * @hooked bulk_edit_custom_box
2957
-     *
2958
-     * @since 1.8.0
2959
-     *
2960
-     * @param string $column_name
2961
-     * @param string $post_type
2962
-     * @return void
2963
-     */
2964
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2965
-
2966
-        // only show these options ont he lesson post type edit screen
2967
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name
2968
-            || ! current_user_can( 'edit_lessons' ) ) {
2969
-            return;
2970
-        }
2971
-
2972
-        ?>
2915
+	/**
2916
+	 * Returns the course for a given lesson
2917
+	 *
2918
+	 * @since 1.7.4
2919
+	 * @access public
2920
+	 *
2921
+	 * @param int $lesson_id
2922
+	 * @return int|bool $course_id or bool when nothing is found.
2923
+	 */
2924
+	 public function get_course_id( $lesson_id ){
2925
+
2926
+		 if( ! isset( $lesson_id ) || empty( $lesson_id )
2927
+		 ||  'lesson' != get_post_type( $lesson_id ) ){
2928
+			 return false;
2929
+		 }
2930
+
2931
+		 $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2932
+
2933
+		 // make sure the course id is valid
2934
+		 if( empty( $lesson_course_id )
2935
+			 || is_array( $lesson_course_id )
2936
+			 || intval( $lesson_course_id ) < 1
2937
+			 || 'course' != get_post_type( $lesson_course_id ) ){
2938
+
2939
+			 return false;
2940
+
2941
+		 }
2942
+
2943
+		 return $lesson_course_id;
2944
+
2945
+	 }// en get_course_id
2946
+
2947
+	/**
2948
+	 * Add the admin all lessons screen edit options.
2949
+	 *
2950
+	 * The fields in this function work for both quick and bulk edit. The ID attributes is used
2951
+	 * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2952
+	 * name attribute is will be used by the quick edit and submitted via standard POST. This
2953
+	 * will use this classes save_post_meta function to save the new field data.
2954
+	 *
2955
+	 * @hooked quick_edit_custom_box
2956
+	 * @hooked bulk_edit_custom_box
2957
+	 *
2958
+	 * @since 1.8.0
2959
+	 *
2960
+	 * @param string $column_name
2961
+	 * @param string $post_type
2962
+	 * @return void
2963
+	 */
2964
+	public function all_lessons_edit_fields( $column_name, $post_type ) {
2965
+
2966
+		// only show these options ont he lesson post type edit screen
2967
+		if( 'lesson' != $post_type || 'lesson-course' != $column_name
2968
+			|| ! current_user_can( 'edit_lessons' ) ) {
2969
+			return;
2970
+		}
2971
+
2972
+		?>
2973 2973
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2974 2974
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2975 2975
                     <?php
2976
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2977
-                    // create a nonce field to be  used as a security measure when saving the data
2978
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2979
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2980
-
2981
-                    // unchanged option - we need this in because
2982
-                    // the default option in bulk edit should not be empty. If it is
2983
-                    // the user will erase data they didn't want to touch.
2984
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2985
-
2986
-                    //
2987
-                    //course selection
2988
-                    //
2989
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2990
-                    $course_options = array();
2991
-                    if ( count( $courses ) > 0 ) {
2992
-                        foreach ($courses as $course ){
2993
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
2994
-                        }
2995
-                    }
2996
-                    //pre-append the no change option
2997
-                    $course_options['-1']=  $no_change_text;
2998
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2999
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3000
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3001
-
3002
-                    //
3003
-                    // lesson complexity selection
3004
-                    //
3005
-                    $lesson_complexities =  $this->lesson_complexities();
3006
-                    //pre-append the no change option
3007
-                    $lesson_complexities['-1']=  $no_change_text;
3008
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3009
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3010
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3011
-
3012
-                    ?>
2976
+					echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2977
+					// create a nonce field to be  used as a security measure when saving the data
2978
+					wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2979
+					wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2980
+
2981
+					// unchanged option - we need this in because
2982
+					// the default option in bulk edit should not be empty. If it is
2983
+					// the user will erase data they didn't want to touch.
2984
+					$no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2985
+
2986
+					//
2987
+					//course selection
2988
+					//
2989
+					$courses =  WooThemes_Sensei_Course::get_all_courses();
2990
+					$course_options = array();
2991
+					if ( count( $courses ) > 0 ) {
2992
+						foreach ($courses as $course ){
2993
+							$course_options[ $course->ID ] = get_the_title( $course->ID );
2994
+						}
2995
+					}
2996
+					//pre-append the no change option
2997
+					$course_options['-1']=  $no_change_text;
2998
+					$course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2999
+					$course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3000
+					echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3001
+
3002
+					//
3003
+					// lesson complexity selection
3004
+					//
3005
+					$lesson_complexities =  $this->lesson_complexities();
3006
+					//pre-append the no change option
3007
+					$lesson_complexities['-1']=  $no_change_text;
3008
+					$complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3009
+					$complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3010
+					echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3011
+
3012
+					?>
3013 3013
 
3014 3014
                     <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4>
3015 3015
 
3016 3016
                     <?php
3017 3017
 
3018
-                    //
3019
-                    // Lesson require pass to complete
3020
-                    //
3021
-                    $pass_required_options = array(
3022
-                        '-1' => $no_change_text,
3023
-                         '0' => __('No','woothemes'),
3024
-                         '1' => __('Yes','woothemes'),
3025
-                    );
3026
-
3027
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3028
-                                                                'id'=> 'sensei-edit-lesson-pass-required',
3029
-                                                                'class'=>' '   );
3030
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3031
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3032
-
3033
-                    //
3034
-                    // Quiz pass percentage
3035
-                    //
3036
-                    $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3037
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3038
-
3039
-                    //
3040
-                    // Enable quiz reset button
3041
-                    //
3042
-                    $quiz_reset_select__options = array(
3043
-                        '-1' => $no_change_text,
3044
-                        '0' => __('No','woothemes'),
3045
-                        '1' => __('Yes','woothemes'),
3046
-                    );
3047
-                    $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3048
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3049
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3050
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3051
-
3052
-                    ?>
3018
+					//
3019
+					// Lesson require pass to complete
3020
+					//
3021
+					$pass_required_options = array(
3022
+						'-1' => $no_change_text,
3023
+						 '0' => __('No','woothemes'),
3024
+						 '1' => __('Yes','woothemes'),
3025
+					);
3026
+
3027
+					$pass_required_select_attributes = array( 'name'=> 'pass_required',
3028
+																'id'=> 'sensei-edit-lesson-pass-required',
3029
+																'class'=>' '   );
3030
+					$require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3031
+					echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3032
+
3033
+					//
3034
+					// Quiz pass percentage
3035
+					//
3036
+					$quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3037
+					echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3038
+
3039
+					//
3040
+					// Enable quiz reset button
3041
+					//
3042
+					$quiz_reset_select__options = array(
3043
+						'-1' => $no_change_text,
3044
+						'0' => __('No','woothemes'),
3045
+						'1' => __('Yes','woothemes'),
3046
+					);
3047
+					$quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3048
+					$quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3049
+					$quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3050
+					echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3051
+
3052
+					?>
3053 3053
             </div>
3054 3054
         </fieldset>
3055 3055
     <?php
3056
-    }// all_lessons_edit_fields
3057
-
3058
-    /**
3059
-     * Create the html for the edit field
3060
-     *
3061
-     * Wraps the passed in field and title combination with the correct html.
3062
-     *
3063
-     * @since 1.8.0
3064
-     *
3065
-     * @param string $title that will stand to the left of the field.
3066
-     * @param string $field type markup for the field that must be wrapped.
3067
-     * @return string $field_html
3068
-     */
3069
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3070
-
3071
-        $html = '';
3072
-        $html = '<div class="inline-edit-group" >';
3073
-        $html .=  '<span class="title">'. $title .'</span> ';
3074
-        $html .= '<span class="input-text-wrap">';
3075
-        $html .= $field;
3076
-        $html .= '</span>';
3077
-        $html .= '</label></div>';
3078
-
3079
-        return $html ;
3080
-
3081
-    }//end generate_all_lessons_edit_field
3082
-
3083
-    /**
3084
-     * Respond to the ajax call from the bulk edit save function. This comes
3085
-     * from the admin all lesson screen.
3086
-     *
3087
-     * @since 1.8.0
3088
-     * @return void
3089
-     */
3090
-    function save_all_lessons_edit_fields() {
3091
-
3092
-        // verify all the data before attempting to save
3093
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3094
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3095
-            die();
3096
-        }
3097
-
3098
-        // get our variables
3099
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3100
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3101
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3102
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3103
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3104
-        // store the values for all selected posts
3105
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3106
-
3107
-            // get the quiz id needed for the quiz meta
3108
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3109
-
3110
-            // do not save the items if the value is -1 as this
3111
-            // means it was not changed
3112
-
3113
-            // update lesson course
3114
-            if( -1 != $new_course ){
3115
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3116
-            }
3117
-            // update lesson complexity
3118
-            if( -1 != $new_complexity ){
3119
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3120
-            }
3121
-
3122
-            // Quiz Related settings
3123
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3124
-
3125
-                // update pass required
3126
-                if (-1 != $new_pass_required) {
3127
-
3128
-                    $checked = $new_pass_required  ? 'on' : '';
3129
-                    update_post_meta($quiz_id, '_pass_required', $checked);
3130
-                    unset( $checked );
3131
-                }
3056
+	}// all_lessons_edit_fields
3132 3057
 
3133
-                // update pass percentage
3134
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3058
+	/**
3059
+	 * Create the html for the edit field
3060
+	 *
3061
+	 * Wraps the passed in field and title combination with the correct html.
3062
+	 *
3063
+	 * @since 1.8.0
3064
+	 *
3065
+	 * @param string $title that will stand to the left of the field.
3066
+	 * @param string $field type markup for the field that must be wrapped.
3067
+	 * @return string $field_html
3068
+	 */
3069
+	public function generate_all_lessons_edit_field( $title  ,$field ){
3135 3070
 
3136
-                        update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3071
+		$html = '';
3072
+		$html = '<div class="inline-edit-group" >';
3073
+		$html .=  '<span class="title">'. $title .'</span> ';
3074
+		$html .= '<span class="input-text-wrap">';
3075
+		$html .= $field;
3076
+		$html .= '</span>';
3077
+		$html .= '</label></div>';
3137 3078
 
3138
-                }
3079
+		return $html ;
3139 3080
 
3140
-                //
3141
-                // update enable quiz reset
3142
-                //
3143
-                if (-1 != $new_enable_quiz_reset ) {
3081
+	}//end generate_all_lessons_edit_field
3144 3082
 
3145
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3146
-                    update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3147
-                    unset( $checked );
3083
+	/**
3084
+	 * Respond to the ajax call from the bulk edit save function. This comes
3085
+	 * from the admin all lesson screen.
3086
+	 *
3087
+	 * @since 1.8.0
3088
+	 * @return void
3089
+	 */
3090
+	function save_all_lessons_edit_fields() {
3148 3091
 
3149
-                }
3092
+		// verify all the data before attempting to save
3093
+		if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3094
+			||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3095
+			die();
3096
+		}
3150 3097
 
3098
+		// get our variables
3099
+		$new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3100
+		$new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3101
+		$new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3102
+		$new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3103
+		$new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3104
+		// store the values for all selected posts
3105
+		foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3151 3106
 
3152
-            } // end if quiz
3107
+			// get the quiz id needed for the quiz meta
3108
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3153 3109
 
3154
-        }// end for each
3110
+			// do not save the items if the value is -1 as this
3111
+			// means it was not changed
3155 3112
 
3156
-        die();
3113
+			// update lesson course
3114
+			if( -1 != $new_course ){
3115
+				update_post_meta( $lesson_id, '_lesson_course', $new_course );
3116
+			}
3117
+			// update lesson complexity
3118
+			if( -1 != $new_complexity ){
3119
+				update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3120
+			}
3157 3121
 
3158
-    } // end save_all_lessons_edit_fields
3122
+			// Quiz Related settings
3123
+			if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3159 3124
 
3160
-    /**
3161
-     * Loading the quick edit fields defaults.
3162
-     *
3163
-     * This function will localise the default values along with the script that will
3164
-     * add these values to the inputs.
3165
-     *
3166
-     * NOTE: this function runs for each row in the edit column
3167
-     *
3168
-     * @since 1.8.0
3169
-     * @return void
3170
-     */
3171
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3125
+				// update pass required
3126
+				if (-1 != $new_pass_required) {
3172 3127
 
3173
-        if( 'lesson-course' != $column_name ){
3174
-            return;
3175
-        }
3176
-        // load the script
3177
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3178
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3128
+					$checked = $new_pass_required  ? 'on' : '';
3129
+					update_post_meta($quiz_id, '_pass_required', $checked);
3130
+					unset( $checked );
3131
+				}
3132
+
3133
+				// update pass percentage
3134
+				if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3135
+
3136
+						update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3137
+
3138
+				}
3139
+
3140
+				//
3141
+				// update enable quiz reset
3142
+				//
3143
+				if (-1 != $new_enable_quiz_reset ) {
3144
+
3145
+					$checked = $new_enable_quiz_reset ? 'on' : ''  ;
3146
+					update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3147
+					unset( $checked );
3148
+
3149
+				}
3179 3150
 
3180
-        // setup the values for all meta fields
3181
-        $data = array();
3182
-        foreach( $this->meta_fields as $field ){
3183 3151
 
3184
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3152
+			} // end if quiz
3185 3153
 
3186
-        }
3187
-        // add quiz meta fields
3188
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3189
-        foreach( Sensei()->quiz->meta_fields as $field ){
3154
+		}// end for each
3190 3155
 
3191
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3156
+		die();
3157
+
3158
+	} // end save_all_lessons_edit_fields
3159
+
3160
+	/**
3161
+	 * Loading the quick edit fields defaults.
3162
+	 *
3163
+	 * This function will localise the default values along with the script that will
3164
+	 * add these values to the inputs.
3165
+	 *
3166
+	 * NOTE: this function runs for each row in the edit column
3167
+	 *
3168
+	 * @since 1.8.0
3169
+	 * @return void
3170
+	 */
3171
+	public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3192 3172
 
3193
-        }
3173
+		if( 'lesson-course' != $column_name ){
3174
+			return;
3175
+		}
3176
+		// load the script
3177
+		$suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3178
+		wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3194 3179
 
3195
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3180
+		// setup the values for all meta fields
3181
+		$data = array();
3182
+		foreach( $this->meta_fields as $field ){
3196 3183
 
3197
-    }// end quick edit admin defaults
3184
+			$data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3198 3185
 
3199
-    /**
3200
-     * Filter the classes for lessons on the single course page.
3201
-     *
3202
-     * Adds the nesecary classes depending on the user data
3203
-     *
3204
-     * @since 1.9.0
3205
-     * @param array $classes
3206
-     * @return array $classes
3207
-     */
3208
-    public static function single_course_lessons_classes( $classes ){
3186
+		}
3187
+		// add quiz meta fields
3188
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3189
+		foreach( Sensei()->quiz->meta_fields as $field ){
3209 3190
 
3210
-        if(  is_singular('course') ){
3191
+			$data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3211 3192
 
3212
-            global $post;
3213
-            $course_id = $post->ID;
3193
+		}
3214 3194
 
3215
-            $lesson_classes = array( 'course', 'post' );
3216
-            if ( is_user_logged_in() ) {
3195
+		wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3217 3196
 
3218
-                // Check if Lesson is complete
3219
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3220
-                if ( $single_lesson_complete ) {
3197
+	}// end quick edit admin defaults
3221 3198
 
3222
-                    $lesson_classes[] = 'lesson-completed';
3199
+	/**
3200
+	 * Filter the classes for lessons on the single course page.
3201
+	 *
3202
+	 * Adds the nesecary classes depending on the user data
3203
+	 *
3204
+	 * @since 1.9.0
3205
+	 * @param array $classes
3206
+	 * @return array $classes
3207
+	 */
3208
+	public static function single_course_lessons_classes( $classes ){
3223 3209
 
3224
-                } // End If Statement
3210
+		if(  is_singular('course') ){
3225 3211
 
3226
-            } // End If Statement
3212
+			global $post;
3213
+			$course_id = $post->ID;
3227 3214
 
3228
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3229
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3215
+			$lesson_classes = array( 'course', 'post' );
3216
+			if ( is_user_logged_in() ) {
3230 3217
 
3231
-                $lesson_classes[] = 'lesson-preview';
3218
+				// Check if Lesson is complete
3219
+				$single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3220
+				if ( $single_lesson_complete ) {
3232 3221
 
3233
-            }
3222
+					$lesson_classes[] = 'lesson-completed';
3234 3223
 
3235
-            $classes = array_merge( $classes, $lesson_classes  );
3224
+				} // End If Statement
3236 3225
 
3237
-        }
3226
+			} // End If Statement
3238 3227
 
3239
-        return $classes;
3228
+			$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3229
+			if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3240 3230
 
3241
-    }// end single_course_lessons_classes
3231
+				$lesson_classes[] = 'lesson-preview';
3242 3232
 
3243
-    /**
3244
-     * Output the lesson meta for the given lesson
3245
-     *
3246
-     * @since 1.9.0
3247
-     * @param $lesson_id
3248
-     */
3249
-    public static function the_lesson_meta( $lesson_id ){
3233
+			}
3250 3234
 
3251
-        global $wp_query;
3252
-        $loop_lesson_number = $wp_query->current_post + 1;
3235
+			$classes = array_merge( $classes, $lesson_classes  );
3253 3236
 
3254
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3255
-        $single_lesson_complete = false;
3256
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3237
+		}
3257 3238
 
3258
-        // Get Lesson data
3259
-        $complexity_array = Sensei()->lesson->lesson_complexities();
3239
+		return $classes;
3260 3240
 
3261
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3262
-        if ( '' != $lesson_complexity ) {
3241
+	}// end single_course_lessons_classes
3263 3242
 
3264
-            $lesson_complexity = $complexity_array[$lesson_complexity];
3243
+	/**
3244
+	 * Output the lesson meta for the given lesson
3245
+	 *
3246
+	 * @since 1.9.0
3247
+	 * @param $lesson_id
3248
+	 */
3249
+	public static function the_lesson_meta( $lesson_id ){
3265 3250
 
3266
-        }
3267
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3268
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3269
-        $preview_label = '';
3270
-        if ( $is_preview && !$is_user_taking_course ) {
3251
+		global $wp_query;
3252
+		$loop_lesson_number = $wp_query->current_post + 1;
3271 3253
 
3272
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3273
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3254
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
3255
+		$single_lesson_complete = false;
3256
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3274 3257
 
3275
-        }
3258
+		// Get Lesson data
3259
+		$complexity_array = Sensei()->lesson->lesson_complexities();
3276 3260
 
3261
+		$lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3262
+		if ( '' != $lesson_complexity ) {
3277 3263
 
3278
-        $count_markup= '';
3279
-        /**
3280
-         * Filter for if you want the $lesson_count to show next to the lesson.
3281
-         *
3282
-         * @since 1.0
3283
-         * @param bool default false.
3284
-         */
3285
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3264
+			$lesson_complexity = $complexity_array[$lesson_complexity];
3286 3265
 
3287
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3266
+		}
3267
+		$user_info = get_userdata( absint( get_post()->post_author ) );
3268
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3269
+		$preview_label = '';
3270
+		if ( $is_preview && !$is_user_taking_course ) {
3288 3271
 
3289
-        }
3272
+			$preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3273
+			$preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3290 3274
 
3291
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3275
+		}
3292 3276
 
3293
-        ?>
3277
+
3278
+		$count_markup= '';
3279
+		/**
3280
+		 * Filter for if you want the $lesson_count to show next to the lesson.
3281
+		 *
3282
+		 * @since 1.0
3283
+		 * @param bool default false.
3284
+		 */
3285
+		if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3286
+
3287
+			$count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3288
+
3289
+		}
3290
+
3291
+		$heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3292
+
3293
+		?>
3294 3294
         <header>
3295 3295
             <h2>
3296 3296
                 <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
@@ -3303,40 +3303,40 @@  discard block
 block discarded – undo
3303 3303
 
3304 3304
                 <?php
3305 3305
 
3306
-                $meta_html = '';
3307
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3306
+				$meta_html = '';
3307
+				$user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3308 3308
 
3309
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3310
-                if ( '' != $lesson_length ) {
3309
+				$lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3310
+				if ( '' != $lesson_length ) {
3311 3311
 
3312
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3312
+					$meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3313 3313
 
3314
-                }
3314
+				}
3315 3315
 
3316
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3316
+				if ( Sensei()->settings->get( 'lesson_author' ) ) {
3317 3317
 
3318
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3318
+					$meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3319 3319
 
3320
-                } // End If Statement
3321
-                if ( '' != $lesson_complexity ) {
3320
+				} // End If Statement
3321
+				if ( '' != $lesson_complexity ) {
3322 3322
 
3323
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3323
+					$meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3324 3324
 
3325
-                }
3325
+				}
3326 3326
 
3327
-                if ( $single_lesson_complete ) {
3327
+				if ( $single_lesson_complete ) {
3328 3328
 
3329
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3329
+					$meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3330 3330
 
3331
-                } elseif ( $user_lesson_status ) {
3331
+				} elseif ( $user_lesson_status ) {
3332 3332
 
3333
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3333
+					$meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3334 3334
 
3335
-                } // End If Statement
3335
+				} // End If Statement
3336 3336
 
3337
-                echo $meta_html;
3337
+				echo $meta_html;
3338 3338
 
3339
-                ?>
3339
+				?>
3340 3340
 
3341 3341
             </p> <!-- lesson meta -->
3342 3342
 
@@ -3344,132 +3344,132 @@  discard block
 block discarded – undo
3344 3344
 
3345 3345
     <?php
3346 3346
 
3347
-    } // end the_lesson_meta
3347
+	} // end the_lesson_meta
3348 3348
 
3349
-    /**
3350
-     * Output the lessons thumbnail
3351
-     *
3352
-     * 1.9.0
3353
-     *
3354
-     * @param $lesson_id
3355
-     */
3356
-    public static function the_lesson_thumbnail( $lesson_id ){
3349
+	/**
3350
+	 * Output the lessons thumbnail
3351
+	 *
3352
+	 * 1.9.0
3353
+	 *
3354
+	 * @param $lesson_id
3355
+	 */
3356
+	public static function the_lesson_thumbnail( $lesson_id ){
3357 3357
 
3358
-        if( empty( $lesson_id ) ){
3358
+		if( empty( $lesson_id ) ){
3359 3359
 
3360
-            $lesson_id = get_the_ID();
3360
+			$lesson_id = get_the_ID();
3361 3361
 
3362
-        }
3362
+		}
3363 3363
 
3364
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3365
-            return;
3366
-        }
3364
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3365
+			return;
3366
+		}
3367 3367
 
3368
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3369
-    }
3368
+		echo Sensei()->lesson->lesson_image( $lesson_id );
3369
+	}
3370 3370
 
3371 3371
 
3372
-    /**
3373
-     * Alter the sensei lesson excerpt.
3374
-     *
3375
-     * @since 1.9.0
3376
-     * @param string $excerpt
3377
-     * @return string $excerpt
3378
-     */
3379
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3372
+	/**
3373
+	 * Alter the sensei lesson excerpt.
3374
+	 *
3375
+	 * @since 1.9.0
3376
+	 * @param string $excerpt
3377
+	 * @return string $excerpt
3378
+	 */
3379
+	public static function alter_the_lesson_excerpt( $excerpt ) {
3380 3380
 
3381
-        if ('lesson' == get_post_type(get_the_ID())){
3381
+		if ('lesson' == get_post_type(get_the_ID())){
3382 3382
 
3383
-            // remove this hooks to avoid an infinite loop.
3384
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3383
+			// remove this hooks to avoid an infinite loop.
3384
+			remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3385 3385
 
3386
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3387
-        }
3386
+			return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3387
+		}
3388 3388
 
3389
-        return $excerpt;
3389
+		return $excerpt;
3390 3390
 
3391
-    }// end the_lesson_excerpt
3391
+	}// end the_lesson_excerpt
3392 3392
 
3393
-    /**
3394
-     * Returns the lesson prerequisite for the given lesson id.
3395
-     *
3396
-     * @since 1.9.0
3397
-     *
3398
-     * @param $current_lesson_id
3399
-     * @return mixed | bool | int $prerequisite_lesson_id or false
3400
-     */
3401
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3393
+	/**
3394
+	 * Returns the lesson prerequisite for the given lesson id.
3395
+	 *
3396
+	 * @since 1.9.0
3397
+	 *
3398
+	 * @param $current_lesson_id
3399
+	 * @return mixed | bool | int $prerequisite_lesson_id or false
3400
+	 */
3401
+	public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3402 3402
 
3403
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3403
+		$prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3404 3404
 
3405
-        // set ti to false if not a valid prerequisite lesson id
3406
-        if(  empty( $prerequisite_lesson_id )
3407
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3408
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3405
+		// set ti to false if not a valid prerequisite lesson id
3406
+		if(  empty( $prerequisite_lesson_id )
3407
+			|| 'lesson' != get_post_type( $prerequisite_lesson_id )
3408
+			|| $prerequisite_lesson_id == $current_lesson_id  ) {
3409 3409
 
3410
-            $prerequisite_lesson_id = false;
3410
+			$prerequisite_lesson_id = false;
3411 3411
 
3412
-        }
3412
+		}
3413 3413
 
3414
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3414
+		return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3415 3415
 
3416
-    }
3416
+	}
3417 3417
 
3418
-    /**
3419
-     * This function requires that you pass in the lesson you would like to check for
3420
-     * a pre-requisite and not the pre-requisite. It will check if the
3421
-     * lesson has a pre-requiste and then check if it is completed.
3422
-     *
3423
-     * @since 1.9.0
3424
-     *
3425
-     * @param $lesson_id
3426
-     * @param $user_id
3427
-     * @return bool
3428
-     */
3429
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3418
+	/**
3419
+	 * This function requires that you pass in the lesson you would like to check for
3420
+	 * a pre-requisite and not the pre-requisite. It will check if the
3421
+	 * lesson has a pre-requiste and then check if it is completed.
3422
+	 *
3423
+	 * @since 1.9.0
3424
+	 *
3425
+	 * @param $lesson_id
3426
+	 * @param $user_id
3427
+	 * @return bool
3428
+	 */
3429
+	public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3430 3430
 
3431
-        if( empty( $lesson_id ) || empty( $user_id )
3432
-        || 'lesson' != get_post_type( $lesson_id )
3433
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3431
+		if( empty( $lesson_id ) || empty( $user_id )
3432
+		|| 'lesson' != get_post_type( $lesson_id )
3433
+		||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3434 3434
 
3435
-            return false;
3435
+			return false;
3436 3436
 
3437
-        }
3437
+		}
3438 3438
 
3439
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3439
+		$pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3440 3440
 
3441
-        // not a valid pre-requisite so pre-requisite is completed
3442
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3443
-            || ! is_numeric( $pre_requisite_id ) ){
3441
+		// not a valid pre-requisite so pre-requisite is completed
3442
+		if( 'lesson' != get_post_type( $pre_requisite_id )
3443
+			|| ! is_numeric( $pre_requisite_id ) ){
3444 3444
 
3445
-            return true;
3445
+			return true;
3446 3446
 
3447
-        }
3447
+		}
3448 3448
 
3449
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3449
+		return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3450 3450
 
3451
-    }// end is_prerequisite_complete
3451
+	}// end is_prerequisite_complete
3452 3452
 
3453
-    /**
3454
-     * Show the user not taking course message if it is the case
3455
-     *
3456
-     * @since 1.9.0
3457
-     */
3458
-    public  static function user_not_taking_course_message(){
3453
+	/**
3454
+	 * Show the user not taking course message if it is the case
3455
+	 *
3456
+	 * @since 1.9.0
3457
+	 */
3458
+	public  static function user_not_taking_course_message(){
3459 3459
 
3460
-        $lesson_id = get_the_ID();
3460
+		$lesson_id = get_the_ID();
3461 3461
 
3462
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3463
-            return;
3464
-        }
3462
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3463
+			return;
3464
+		}
3465 3465
 
3466
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3467
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3468
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3469
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3466
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3467
+		$pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3468
+		$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3469
+		$user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3470 3470
 
3471
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3472
-            ?>
3471
+		if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3472
+			?>
3473 3473
 
3474 3474
             <div class="sensei-message alert">
3475 3475
                 <?php echo Sensei()->permissions_message['message']; ?>
@@ -3477,46 +3477,46 @@  discard block
 block discarded – undo
3477 3477
 
3478 3478
             <?php
3479 3479
 
3480
-        }// end if
3480
+		}// end if
3481 3481
 
3482
-    } // end user_not_taking_course_message
3482
+	} // end user_not_taking_course_message
3483 3483
 
3484
-    /**
3485
-     * Outputs the lessons course signup lingk
3486
-     *
3487
-     * This hook runs inside the single lesson page.
3488
-     *
3489
-     * @since 1.9.0
3490
-     */
3491
-    public static function course_signup_link( ){
3484
+	/**
3485
+	 * Outputs the lessons course signup lingk
3486
+	 *
3487
+	 * This hook runs inside the single lesson page.
3488
+	 *
3489
+	 * @since 1.9.0
3490
+	 */
3491
+	public static function course_signup_link( ){
3492 3492
 
3493
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3493
+		$course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3494 3494
 
3495
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3495
+		if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3496 3496
 
3497
-            return;
3497
+			return;
3498 3498
 
3499
-        }
3500
-        ?>
3499
+		}
3500
+		?>
3501 3501
 
3502 3502
         <section class="course-signup lesson-meta">
3503 3503
 
3504 3504
             <?php
3505
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3505
+			$wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3506 3506
 
3507
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3507
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3508 3508
 
3509
-                global $current_user;
3510
-                if( is_user_logged_in() ) {
3511
-                    wp_get_current_user();
3509
+				global $current_user;
3510
+				if( is_user_logged_in() ) {
3511
+					wp_get_current_user();
3512 3512
 
3513
-                    $course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3513
+					$course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3514 3514
 
3515
-                    if( $course_purchased ) {
3515
+					if( $course_purchased ) {
3516 3516
 
3517
-                        $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3518
-                        $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3519
-                        ?>
3517
+						$prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3518
+						$course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3519
+						?>
3520 3520
                             <div class="sensei-message info">
3521 3521
 
3522 3522
                                 <?php  echo sprintf( __( 'Please complete %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); ?>
@@ -3528,14 +3528,14 @@  discard block
 block discarded – undo
3528 3528
                         <div class="sensei-message info">
3529 3529
 
3530 3530
                             <?php
3531
-                            $course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3532
-                                            . '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3533
-                                            . '">' . __( 'course', 'woothemes-sensei' )
3534
-                                            . '</a>';
3531
+							$course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3532
+											. '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3533
+											. '">' . __( 'course', 'woothemes-sensei' )
3534
+											. '</a>';
3535 3535
 
3536
-                            echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3536
+							echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3537 3537
 
3538
-                            ?>
3538
+							?>
3539 3539
 
3540 3540
                         </div>
3541 3541
                     <?php } ?>
@@ -3552,14 +3552,14 @@  discard block
 block discarded – undo
3552 3552
 
3553 3553
                 <div class="sensei-message info">
3554 3554
                     <?php
3555
-                    $course_link =  '<a href="'
3556
-                                        . esc_url( get_permalink( $course_id ) )
3557
-                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3558
-                                        . '">' . __( 'course', 'woothemes-sensei' )
3559
-                                    . '</a>';
3560
-
3561
-                    echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3562
-                    ?>
3555
+					$course_link =  '<a href="'
3556
+										. esc_url( get_permalink( $course_id ) )
3557
+										. '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3558
+										. '">' . __( 'course', 'woothemes-sensei' )
3559
+									. '</a>';
3560
+
3561
+					echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3562
+					?>
3563 3563
                 </div>
3564 3564
 
3565 3565
             <?php endif; ?>
@@ -3569,75 +3569,75 @@  discard block
 block discarded – undo
3569 3569
         </section>
3570 3570
 
3571 3571
         <?php
3572
-    }// end course_signup_link
3572
+	}// end course_signup_link
3573 3573
 
3574
-    /**
3575
-     * Show a message telling the user to complete the previous message if they haven't done so yet
3576
-     *
3577
-     * @since 1.9.0
3578
-     */
3579
-    public  static function prerequisite_complete_message(){
3574
+	/**
3575
+	 * Show a message telling the user to complete the previous message if they haven't done so yet
3576
+	 *
3577
+	 * @since 1.9.0
3578
+	 */
3579
+	public  static function prerequisite_complete_message(){
3580 3580
 
3581
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3582
-        $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3583
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3581
+		$lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3582
+		$lesson_has_pre_requisite = $lesson_prerequisite > 0;
3583
+		if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3584 3584
 
3585
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3586
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3585
+			$prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3586
+			echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3587 3587
 
3588
-        }
3588
+		}
3589 3589
 
3590
-    }
3590
+	}
3591 3591
 
3592
-    /**
3593
-     * Deprecate the sensei_lesson_archive_header hook but keep it
3594
-     * active for backwards compatibility.
3595
-     *
3596
-     * @deprecated since 1.9.0
3597
-     */
3598
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3592
+	/**
3593
+	 * Deprecate the sensei_lesson_archive_header hook but keep it
3594
+	 * active for backwards compatibility.
3595
+	 *
3596
+	 * @deprecated since 1.9.0
3597
+	 */
3598
+	public static function deprecate_sensei_lesson_archive_header_hook(){
3599 3599
 
3600
-        sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3600
+		sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3601 3601
 
3602
-    }
3602
+	}
3603 3603
 
3604
-    /**
3605
-     * Outputs the the lesson archive header.
3606
-     *
3607
-     * @since  1.9.0
3608
-     * @return void
3609
-     */
3610
-    public function the_archive_header( ) {
3604
+	/**
3605
+	 * Outputs the the lesson archive header.
3606
+	 *
3607
+	 * @since  1.9.0
3608
+	 * @return void
3609
+	 */
3610
+	public function the_archive_header( ) {
3611 3611
 
3612
-        $before_html = '<header class="archive-header"><h1>';
3613
-        $after_html = '</h1></header>';
3614
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3612
+		$before_html = '<header class="archive-header"><h1>';
3613
+		$after_html = '</h1></header>';
3614
+		$html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3615 3615
 
3616
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3616
+		echo apply_filters( 'sensei_lesson_archive_title', $html );
3617 3617
 
3618
-    } // sensei_course_archive_header()
3618
+	} // sensei_course_archive_header()
3619 3619
 
3620
-    /**
3621
-     * Output the title for the single lesson page
3622
-     *
3623
-     * @global $post
3624
-     * @since 1.9.0
3625
-     */
3626
-    public static function the_title(){
3620
+	/**
3621
+	 * Output the title for the single lesson page
3622
+	 *
3623
+	 * @global $post
3624
+	 * @since 1.9.0
3625
+	 */
3626
+	public static function the_title(){
3627 3627
 
3628
-        global $post;
3628
+		global $post;
3629 3629
 
3630
-        ?>
3630
+		?>
3631 3631
         <header>
3632 3632
 
3633 3633
             <h1>
3634 3634
 
3635 3635
                 <?php
3636
-                /**
3637
-                 * Filter documented in class-sensei-messages.php the_title
3638
-                 */
3639
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3640
-                ?>
3636
+				/**
3637
+				 * Filter documented in class-sensei-messages.php the_title
3638
+				 */
3639
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3640
+				?>
3641 3641
 
3642 3642
             </h1>
3643 3643
 
@@ -3645,68 +3645,68 @@  discard block
 block discarded – undo
3645 3645
 
3646 3646
         <?php
3647 3647
 
3648
-    }//the_title
3648
+	}//the_title
3649 3649
 
3650
-    /**
3651
-     * Flush the rewrite rules for a lesson post type
3652
-     *
3653
-     * @since 1.9.0
3654
-     *
3655
-     * @param $post_id
3656
-     */
3657
-    public static function flush_rewrite_rules( $post_id ){
3650
+	/**
3651
+	 * Flush the rewrite rules for a lesson post type
3652
+	 *
3653
+	 * @since 1.9.0
3654
+	 *
3655
+	 * @param $post_id
3656
+	 */
3657
+	public static function flush_rewrite_rules( $post_id ){
3658 3658
 
3659
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3659
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3660 3660
 
3661
-            return;
3661
+			return;
3662 3662
 
3663
-        }
3663
+		}
3664 3664
 
3665 3665
 
3666
-        if( 'lesson' == get_post_type( $post_id )  ){
3666
+		if( 'lesson' == get_post_type( $post_id )  ){
3667 3667
 
3668
-            Sensei()->initiate_rewrite_rules_flush();
3668
+			Sensei()->initiate_rewrite_rules_flush();
3669 3669
 
3670
-        }
3670
+		}
3671 3671
 
3672
-    }
3672
+	}
3673 3673
 
3674
-    /**
3675
-     * Output the quiz specific buttons and messaging on the single lesson page
3676
-     *
3677
-     *
3678
-     * @since 1.0.0 moved here from frontend class
3679
-     *
3680
-     * @param int $lesson_id
3681
-     * @param int $user_id
3682
-     */
3683
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3674
+	/**
3675
+	 * Output the quiz specific buttons and messaging on the single lesson page
3676
+	 *
3677
+	 *
3678
+	 * @since 1.0.0 moved here from frontend class
3679
+	 *
3680
+	 * @param int $lesson_id
3681
+	 * @param int $user_id
3682
+	 */
3683
+	public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3684 3684
 
3685 3685
 
3686
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3687
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3688
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3689
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3690
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3691
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3692
-        $show_actions              = is_user_logged_in() ? true : false;
3686
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3687
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3688
+		$lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3689
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3690
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3691
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3692
+		$show_actions              = is_user_logged_in() ? true : false;
3693 3693
 
3694
-        if( intval( $lesson_prerequisite ) > 0 ) {
3694
+		if( intval( $lesson_prerequisite ) > 0 ) {
3695 3695
 
3696
-            // If the user hasn't completed the prereq then hide the current actions
3697
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3696
+			// If the user hasn't completed the prereq then hide the current actions
3697
+			$show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3698 3698
 
3699
-        }
3700
-        ?>
3699
+		}
3700
+		?>
3701 3701
 
3702 3702
         <footer>
3703 3703
 
3704 3704
             <?php
3705
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3705
+			if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3706 3706
 
3707
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3708
-                if( $has_quiz_questions ) {
3709
-                    ?>
3707
+				$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3708
+				if( $has_quiz_questions ) {
3709
+					?>
3710 3710
 
3711 3711
                     <p>
3712 3712
 
@@ -3721,123 +3721,123 @@  discard block
 block discarded – undo
3721 3721
                     </p>
3722 3722
 
3723 3723
                     <?php
3724
-                }
3724
+				}
3725 3725
 
3726
-            } // End If Statement
3726
+			} // End If Statement
3727 3727
 
3728
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3728
+			if ( $show_actions && ! $has_user_completed_lesson ) {
3729 3729
 
3730
-                sensei_complete_lesson_button();
3730
+				sensei_complete_lesson_button();
3731 3731
 
3732
-            } elseif( $show_actions ) {
3732
+			} elseif( $show_actions ) {
3733 3733
 
3734
-                sensei_reset_lesson_button();
3734
+				sensei_reset_lesson_button();
3735 3735
 
3736
-            } // End If Statement
3737
-            ?>
3736
+			} // End If Statement
3737
+			?>
3738 3738
 
3739 3739
         </footer>
3740 3740
 
3741 3741
         <?php
3742
-    } // End sensei_lesson_quiz_meta()
3742
+	} // End sensei_lesson_quiz_meta()
3743 3743
 
3744
-    /**
3745
-     * Show the lesson comments. This should be used in the loop.
3746
-     *
3747
-     * @since 1.9.0
3748
-     */
3749
-    public static function output_comments(){
3744
+	/**
3745
+	 * Show the lesson comments. This should be used in the loop.
3746
+	 *
3747
+	 * @since 1.9.0
3748
+	 */
3749
+	public static function output_comments(){
3750 3750
 
3751
-        if( ! is_user_logged_in() ){
3752
-            return;
3753
-        }
3751
+		if( ! is_user_logged_in() ){
3752
+			return;
3753
+		}
3754 3754
 
3755
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3756
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3757
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3758
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3755
+		$pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3756
+		$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3757
+		$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3758
+		$user_taking_course = Sensei_Utils::user_started_course($course_id );
3759 3759
 
3760
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3760
+		$lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3761 3761
 
3762
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3762
+		if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3763 3763
 
3764
-            comments_template();
3764
+			comments_template();
3765 3765
 
3766
-        } // End If Statement
3766
+		} // End If Statement
3767 3767
 
3768
-    } //output_comments
3768
+	} //output_comments
3769 3769
 
3770
-    /**
3771
-     * Display the leeson quiz status if it should be shown
3772
-     *
3773
-     * @param int $lesson_id defaults to the global lesson id
3774
-     * @param int $user_id defaults to the current user id
3775
-     *
3776
-     * @since 1.9.0
3777
-     */
3778
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3770
+	/**
3771
+	 * Display the leeson quiz status if it should be shown
3772
+	 *
3773
+	 * @param int $lesson_id defaults to the global lesson id
3774
+	 * @param int $user_id defaults to the current user id
3775
+	 *
3776
+	 * @since 1.9.0
3777
+	 */
3778
+	public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3779 3779
 
3780
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3781
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3782
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3783
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3784
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3780
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3781
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3782
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3783
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3784
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3785 3785
 
3786 3786
 
3787
-        if ( $quiz_id && is_user_logged_in()
3788
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3787
+		if ( $quiz_id && is_user_logged_in()
3788
+			&& Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3789 3789
 
3790
-            $no_quiz_count = 0;
3791
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3790
+			$no_quiz_count = 0;
3791
+			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3792 3792
 
3793
-            // Display lesson quiz status message
3794
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3795
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3796
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3797
-                if( $has_quiz_questions ) {
3798
-                   // echo $status['extra'];
3799
-                } // End If Statement
3800
-            } // End If Statement
3793
+			// Display lesson quiz status message
3794
+			if ( $has_user_completed_lesson || $has_quiz_questions ) {
3795
+				$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3796
+				echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3797
+				if( $has_quiz_questions ) {
3798
+				   // echo $status['extra'];
3799
+				} // End If Statement
3800
+			} // End If Statement
3801 3801
 
3802
-        }
3802
+		}
3803 3803
 
3804
-    }
3804
+	}
3805 3805
 
3806
-    /**
3807
-     * On the lesson archive limit the number of words the show up if the access settings are enabled
3808
-     *
3809
-     * @since 1.9.0
3810
-     * @param $content
3811
-     * @return string
3812
-     */
3813
-    public static function limit_archive_content ( $content ){
3806
+	/**
3807
+	 * On the lesson archive limit the number of words the show up if the access settings are enabled
3808
+	 *
3809
+	 * @since 1.9.0
3810
+	 * @param $content
3811
+	 * @return string
3812
+	 */
3813
+	public static function limit_archive_content ( $content ){
3814 3814
 
3815
-        if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3815
+		if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3816 3816
 
3817
-            return wp_trim_words( $content, $num_words = 30, $more = '…' );
3818
-        }
3817
+			return wp_trim_words( $content, $num_words = 30, $more = '…' );
3818
+		}
3819 3819
 
3820
-        return $content;
3820
+		return $content;
3821 3821
 
3822
-    } // end limit_archive_content
3822
+	} // end limit_archive_content
3823 3823
 
3824
-    /**
3825
-     * Returns all publised lesson ID's
3826
-     *
3827
-     * @since 1.9.0
3828
-     * @return array
3829
-     */
3830
-    public static function get_all_lesson_ids(){
3824
+	/**
3825
+	 * Returns all publised lesson ID's
3826
+	 *
3827
+	 * @since 1.9.0
3828
+	 * @return array
3829
+	 */
3830
+	public static function get_all_lesson_ids(){
3831 3831
 
3832
-        return get_posts( array(
3833
-            'post_type'=>'lesson',
3834
-            'fields'=>'ids',
3835
-            'post_status' => 'publish',
3836
-            'numberposts' => 4000, // legacy support
3837
-            'post_per_page' => 4000
3838
-        ));
3832
+		return get_posts( array(
3833
+			'post_type'=>'lesson',
3834
+			'fields'=>'ids',
3835
+			'post_status' => 'publish',
3836
+			'numberposts' => 4000, // legacy support
3837
+			'post_per_page' => 4000
3838
+		));
3839 3839
 
3840
-    }
3840
+	}
3841 3841
 
3842 3842
 } // End Class
3843 3843
 
Please login to merge, or discard this patch.
templates/globals/wrapper-start.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Content wrappers Start
4
- *
5
- * All support theme wrappers can be found in includes/theme-integrations
6
- *
7
- * @author 		WooThemes
8
- * @package 	WooCommerce/Templates
9
- * @version     1.6.4
10
- */
3
+		 * Content wrappers Start
4
+		 *
5
+		 * All support theme wrappers can be found in includes/theme-integrations
6
+		 *
7
+		 * @author 		WooThemes
8
+		 * @package 	WooCommerce/Templates
9
+		 * @version     1.6.4
10
+		 */
11 11
 ?>
12 12
 
13 13
 <div id="content" class="page col-full">
Please login to merge, or discard this patch.