Completed
Push — master ( 201c1b...d51ce1 )
by Dwain
04:57
created
templates/course-results/lessons.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
 <?php if ( is_user_logged_in() ): ?>
18 18
 
19 19
     <?php
20
-    /**
21
-     * Fires inside course-results/lessons.php after the
22
-     * is uer logged check, just above the lessons header.
23
-     * @since 1.4.0
24
-     */
25
-    do_action( 'sensei_course_results_before_lessons', $course->ID );
26
-    ?>
20
+	/**
21
+	 * Fires inside course-results/lessons.php after the
22
+	 * is uer logged check, just above the lessons header.
23
+	 * @since 1.4.0
24
+	 */
25
+	do_action( 'sensei_course_results_before_lessons', $course->ID );
26
+	?>
27 27
 
28 28
     <header>
29 29
 
@@ -36,33 +36,33 @@  discard block
 block discarded – undo
36 36
         <?php
37 37
 
38 38
 		$displayed_lessons = array();
39
-        $modules = Sensei()->modules->get_course_modules( intval( $course->ID ) );
39
+		$modules = Sensei()->modules->get_course_modules( intval( $course->ID ) );
40 40
 
41
-        // List modules with lessons
42
-        foreach( $modules as $module ) {
41
+		// List modules with lessons
42
+		foreach( $modules as $module ) {
43 43
 
44
-            $lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id );
45
-            $lessons = $lessons_query->get_posts();
44
+			$lessons_query = Sensei()->modules->get_lessons_query( $course->ID, $module->term_id );
45
+			$lessons = $lessons_query->get_posts();
46 46
 
47
-            if( count( $lessons ) > 0 ) { ?>
47
+			if( count( $lessons ) > 0 ) { ?>
48 48
 
49 49
                 <h3> <?php echo $module->name; ?></h3>
50 50
 
51 51
                 <?php
52
-                $count = 0;
53
-                foreach( $lessons as $lesson ) {
54
-
55
-                    $lesson_grade = 'n/a';
56
-                    $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
57
-                    if ( $has_questions ) {
58
-                        $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() );
59
-                        // Get user quiz grade
60
-                        $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
61
-                        if ( $lesson_grade ) {
62
-                            $lesson_grade .= '%';
63
-                        }
64
-                    }
65
-                    ?>
52
+				$count = 0;
53
+				foreach( $lessons as $lesson ) {
54
+
55
+					$lesson_grade = 'n/a';
56
+					$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
57
+					if ( $has_questions ) {
58
+						$lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id() );
59
+						// Get user quiz grade
60
+						$lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
61
+						if ( $lesson_grade ) {
62
+							$lesson_grade .= '%';
63
+						}
64
+					}
65
+					?>
66 66
                     <h2>
67 67
 
68 68
                         <a href="<?php esc_url_raw( get_permalink( $lesson->ID ) ); ?>"
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 
81 81
                 <?php
82 82
 
83
-                }// end for each
83
+				}// end for each
84 84
 
85
-            }// end if count lesson
85
+			}// end if count lesson
86 86
 
87
-        } // end for each module
88
-        ?>
87
+		} // end for each module
88
+		?>
89 89
 
90 90
         <?php
91 91
 
92
-        $lessons = Sensei()->modules->get_none_module_lessons( $course->ID );
93
-        if( 0 < count( $lessons ) ): ?>
92
+		$lessons = Sensei()->modules->get_none_module_lessons( $course->ID );
93
+		if( 0 < count( $lessons ) ): ?>
94 94
 
95 95
 			<h3>
96 96
 
@@ -101,17 +101,17 @@  discard block
 block discarded – undo
101 101
             <?php foreach ( $lessons as $lesson ): ?>
102 102
 
103 103
                 <?php
104
-                $lesson_grade = 'n/a';
105
-                $has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
106
-                if ( $has_questions ) {
107
-                    $lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id());
108
-                    // Get user quiz grade
109
-                    $lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
110
-                    if ( $lesson_grade ) {
111
-                        $lesson_grade .= '%';
112
-                    }
113
-                }
114
-                ?>
104
+				$lesson_grade = 'n/a';
105
+				$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
106
+				if ( $has_questions ) {
107
+					$lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, get_current_user_id());
108
+					// Get user quiz grade
109
+					$lesson_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
110
+					if ( $lesson_grade ) {
111
+						$lesson_grade .= '%';
112
+					}
113
+				}
114
+				?>
115 115
 
116 116
                 <h2>
117 117
 
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 
138 138
                 <?php
139 139
 
140
-                    $course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() );
141
-                    echo $course_user_grade . '%';
140
+					$course_user_grade = Sensei_Utils::sensei_course_user_grade( $course->ID, get_current_user_id() );
141
+					echo $course_user_grade . '%';
142 142
 
143
-                ?>
143
+				?>
144 144
 
145 145
             </span>
146 146
 
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
     </article>
150 150
 
151 151
     <?php
152
-    /**
153
-     * Fires inside course-results/lessons.php after the
154
-     * is uer logged check, at the bottom of all lessons.
155
-     *
156
-     * @since 1.4.0
157
-     */
152
+	/**
153
+	 * Fires inside course-results/lessons.php after the
154
+	 * is uer logged check, at the bottom of all lessons.
155
+	 *
156
+	 * @since 1.4.0
157
+	 */
158 158
 	do_action( 'sensei_course_results_after_lessons', $course->ID );
159
-    ?>
159
+	?>
160 160
 
161 161
 <?php endif; //user logged in ?>
162 162
\ No newline at end of file
Please login to merge, or discard this patch.
templates/single-quiz/question_type-multi-line.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 
15 15
 <?php
16 16
 
17
-    /**
18
-     * Get the question data with the current quiz id
19
-     * All data is loaded in this array to keep the template clean.
20
-     */
21
-    $question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );
17
+	/**
18
+	 * Get the question data with the current quiz id
19
+	 * All data is loaded in this array to keep the template clean.
20
+	 */
21
+	$question_data = WooThemes_Sensei_Question::get_template_data( sensei_get_the_question_id(), get_the_ID() );
22 22
 
23 23
 ?>
24 24
 
25 25
 <?php
26 26
 
27
-    Sensei_Utils::sensei_text_editor( $question_data[ 'user_answer_entry' ]  ,
28
-                                                'textquestion' . $question_data[ 'ID' ] ,
29
-                                                'sensei_question[' . $question_data[ 'ID' ] . ']' );
27
+	Sensei_Utils::sensei_text_editor( $question_data[ 'user_answer_entry' ]  ,
28
+												'textquestion' . $question_data[ 'ID' ] ,
29
+												'sensei_question[' . $question_data[ 'ID' ] . ']' );
30 30
 
31 31
 ?>
32 32
 
Please login to merge, or discard this patch.
templates/course-results.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,26 +1,26 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * The Template for displaying course archives, including the course page template.
4
- *
5
- * Override this template by copying it to yourtheme/sensei/archive-course.php
6
- *
7
- * @author 		Automattic
8
- * @package 	Sensei
9
- * @category    Templates
10
- * @version     1.9.0
11
- */
3
+	 * The Template for displaying course archives, including the course page template.
4
+	 *
5
+	 * Override this template by copying it to yourtheme/sensei/archive-course.php
6
+	 *
7
+	 * @author 		Automattic
8
+	 * @package 	Sensei
9
+	 * @category    Templates
10
+	 * @version     1.9.0
11
+	 */
12 12
 ?>
13 13
 
14 14
 <?php  get_sensei_header();  ?>
15 15
 
16 16
 <?php
17 17
 /**
18
- * This hook fire inside learner-profile.php before the content
19
- *
20
- * @since 1.9.0
21
- *
22
- * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20
23
- */
18
+	 * This hook fire inside learner-profile.php before the content
19
+	 *
20
+	 * @since 1.9.0
21
+	 *
22
+	 * @hooked Sensei_Course_Results::deprecate_sensei_course_results_content_hook() - 20
23
+	 */
24 24
 do_action( 'sensei_course_results_content_before' );
25 25
 ?>
26 26
 
@@ -34,15 +34,15 @@  discard block
 block discarded – undo
34 34
     <section class="entry fix">
35 35
 
36 36
         <?php
37
-        /**
38
-         * This hook fire inside learner-profile.php inside directly before the content
39
-         *
40
-         * @since 1.9.0
41
-         *
42
-         * @hooked Sensei_Course_Results::fire_sensei_message_hook() - 20
43
-         */
44
-        do_action( 'sensei_course_results_content_inside_before' );
45
-        ?>
37
+		/**
38
+		 * This hook fire inside learner-profile.php inside directly before the content
39
+		 *
40
+		 * @since 1.9.0
41
+		 *
42
+		 * @hooked Sensei_Course_Results::fire_sensei_message_hook() - 20
43
+		 */
44
+		do_action( 'sensei_course_results_content_inside_before' );
45
+		?>
46 46
 
47 47
         <header>
48 48
 
@@ -56,27 +56,27 @@  discard block
 block discarded – undo
56 56
 
57 57
             <section class="course-results-lessons">
58 58
                 <?php
59
-                $started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
60
-                if( $started_course ) {
59
+				$started_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
60
+				if( $started_course ) {
61 61
 
62
-                    sensei_the_course_results_lessons();
62
+					sensei_the_course_results_lessons();
63 63
 
64
-                }
65
-                ?>
64
+				}
65
+				?>
66 66
             </section>
67 67
 
68 68
         <?php endif; ?>
69 69
 
70 70
         <?php
71
-        /**
72
-         * This hook fire inside learner-profile.php inside directly after the content
73
-         *
74
-         * @since 1.9.0
75
-         *
76
-         * @hooked Sensei()->course_results->course_info - 20
77
-         */
78
-        do_action( 'sensei_course_results_content_inside_after' );
79
-        ?>
71
+		/**
72
+		 * This hook fire inside learner-profile.php inside directly after the content
73
+		 *
74
+		 * @since 1.9.0
75
+		 *
76
+		 * @hooked Sensei()->course_results->course_info - 20
77
+		 */
78
+		do_action( 'sensei_course_results_content_inside_after' );
79
+		?>
80 80
 
81 81
     </section>
82 82
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 
85 85
 <?php
86 86
 /**
87
- * This hook fire inside course-results.php before the content
88
- *
89
- * @since 1.9.0
90
- *
91
- */
87
+		 * This hook fire inside course-results.php before the content
88
+		 *
89
+		 * @since 1.9.0
90
+		 *
91
+		 */
92 92
 do_action( 'sensei_course_results_content_after' );
93 93
 ?>
94 94
 
Please login to merge, or discard this patch.
includes/class-sensei-frontend.php 1 patch
Indentation   +311 added lines, -311 removed lines patch added patch discarded remove patch
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 		// Only show course & lesson excerpts in search results
72 72
 		add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) );
73 73
 
74
-        //Use WooCommerce filter to show admin bar to Teachers.
75
-        add_action( 'init', array( $this, 'sensei_show_admin_bar') );
74
+		//Use WooCommerce filter to show admin bar to Teachers.
75
+		add_action( 'init', array( $this, 'sensei_show_admin_bar') );
76 76
 
77
-        // Remove course from active courses if an order is cancelled or refunded
77
+		// Remove course from active courses if an order is cancelled or refunded
78 78
 		add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
79 79
 		add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
80 80
 		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 			wp_enqueue_script( $this->token . '-user-dashboard' );
146 146
 
147 147
 
148
-            // Course Archive javascript
149
-            if( is_post_type_archive( 'course' ) ){
148
+			// Course Archive javascript
149
+			if( is_post_type_archive( 'course' ) ){
150 150
 
151
-                wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
152
-                wp_enqueue_script( 'sensei-course-archive-js' );
151
+				wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
152
+				wp_enqueue_script( 'sensei-course-archive-js' );
153 153
 
154
-            }
154
+			}
155 155
 
156 156
 
157 157
 			// Allow additional scripts to be loaded
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	/**
194 194
 	 * sensei_get_template_part function.
195 195
 	 *
196
-     * @deprecated sine 1.9.0
196
+	 * @deprecated sine 1.9.0
197 197
 	 * @access public
198 198
 	 * @param mixed $slug
199 199
 	 * @param string $name (default: '')
@@ -201,15 +201,15 @@  discard block
 block discarded – undo
201 201
 	 */
202 202
 	function sensei_get_template_part( $slug, $name = '' ) {
203 203
 
204
-        _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' );
205
-        Sensei_Templates::get_part( $slug, $name );
204
+		_deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' );
205
+		Sensei_Templates::get_part( $slug, $name );
206 206
 
207 207
 	} // End sensei_get_template_part()
208 208
 
209 209
 	/**
210 210
 	 * sensei_get_template function.
211 211
 	 *
212
-     * @deprecated since 1.9.0
212
+	 * @deprecated since 1.9.0
213 213
 	 * @access public
214 214
 	 * @param mixed $template_name
215 215
 	 * @param array $args (default: array())
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
221 221
 
222
-        _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
223
-        Sensei_Templates::get_template($template_name, $args, $template_path, $default_path  );
222
+		_deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
223
+		Sensei_Templates::get_template($template_name, $args, $template_path, $default_path  );
224 224
 
225 225
 	} // End sensei_get_template()
226 226
 
@@ -236,33 +236,33 @@  discard block
 block discarded – undo
236 236
 	 */
237 237
 	function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) {
238 238
 
239
-        _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
240
-        Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
239
+		_deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
240
+		Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
241 241
 
242 242
 	} // End sensei_locate_template()
243 243
 
244 244
 
245 245
 	/**
246 246
 	 * sensei_output_content_wrapper function.
247
-     *
247
+	 *
248 248
 	 * @access public
249 249
 	 * @return void
250 250
 	 */
251 251
 	function sensei_output_content_wrapper() {
252 252
 
253
-	    // backwards compatibility check for old location under the wrappers directory of the active theme
254
-        $backwards_compatible_wrapper_location =   array(
255
-            Sensei()->template_url . 'wrappers/wrapper-start.php',
256
-            'wrappers/wrapper-start.php'
257
-        );
253
+		// backwards compatibility check for old location under the wrappers directory of the active theme
254
+		$backwards_compatible_wrapper_location =   array(
255
+			Sensei()->template_url . 'wrappers/wrapper-start.php',
256
+			'wrappers/wrapper-start.php'
257
+		);
258 258
 
259
-        $template = locate_template( $backwards_compatible_wrapper_location );
260
-        if( !empty( $template ) ){
259
+		$template = locate_template( $backwards_compatible_wrapper_location );
260
+		if( !empty( $template ) ){
261 261
 
262
-            Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
263
-            return;
262
+			Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
263
+			return;
264 264
 
265
-        }
265
+		}
266 266
 
267 267
 		Sensei_Templates::get_template( 'globals/wrapper-start.php' );
268 268
 
@@ -271,25 +271,25 @@  discard block
 block discarded – undo
271 271
 
272 272
 	/**
273 273
 	 * sensei_output_content_wrapper_end function.
274
-     *
274
+	 *
275 275
 	 * @access public
276 276
 	 * @return void
277 277
 	 */
278 278
 	function sensei_output_content_wrapper_end() {
279 279
 
280
-	    // backwards compatibility check for old location under the wrappers directory of the active theme
281
-        $backwards_compatible_wrapper_location =   array(
282
-            Sensei()->template_url . 'wrappers/wrapper-end.php',
283
-            'wrappers/wrapper-end.php'
284
-        );
280
+		// backwards compatibility check for old location under the wrappers directory of the active theme
281
+		$backwards_compatible_wrapper_location =   array(
282
+			Sensei()->template_url . 'wrappers/wrapper-end.php',
283
+			'wrappers/wrapper-end.php'
284
+		);
285 285
 
286
-        $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
287
-        if( !empty( $backwards_compatible_template ) ){
286
+		$backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
287
+		if( !empty( $backwards_compatible_template ) ){
288 288
 
289
-            Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
290
-            return;
289
+			Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
290
+			return;
291 291
 
292
-        }
292
+		}
293 293
 
294 294
 
295 295
 		Sensei_Templates::get_template( 'globals/wrapper-end.php' );
@@ -305,55 +305,55 @@  discard block
 block discarded – undo
305 305
 	 */
306 306
 	public static function load_content_pagination() {
307 307
 
308
-        if( is_singular('course') ) {
308
+		if( is_singular('course') ) {
309 309
 
310
-            // backwards compatibility check for old location under the wrappers directory of the active theme
311
-            $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
312
-            if( !empty( $template ) ){
310
+			// backwards compatibility check for old location under the wrappers directory of the active theme
311
+			$template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
312
+			if( !empty( $template ) ){
313 313
 
314
-                Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
315
-                return;
314
+				Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
315
+				return;
316 316
 
317
-            }
317
+			}
318 318
 
319 319
 			Sensei_Templates::get_template( 'globals/pagination-posts.php' );
320 320
 
321 321
 		} elseif( is_singular('lesson') ) {
322 322
 
323
-		    // backwards compatibility check for old location under the wrappers directory of the active theme
324
-		    $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) );
325
-            if( !empty( $template ) ){
323
+			// backwards compatibility check for old location under the wrappers directory of the active theme
324
+			$template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) );
325
+			if( !empty( $template ) ){
326 326
 
327
-                Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
328
-                return;
327
+				Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
328
+				return;
329 329
 
330
-            }
330
+			}
331 331
 
332 332
 			Sensei_Templates::get_template( 'globals/pagination-lesson.php' );
333 333
 
334 334
 		} elseif( is_singular('quiz') ) {
335 335
 
336
-		    // backwards compatibility check for old location under the wrappers directory of the active theme
337
-		    $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) );
338
-            if( !empty( $template ) ){
336
+			// backwards compatibility check for old location under the wrappers directory of the active theme
337
+			$template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) );
338
+			if( !empty( $template ) ){
339 339
 
340
-                Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
341
-                return;
340
+				Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
341
+				return;
342 342
 
343
-            }
343
+			}
344 344
 
345 345
 			Sensei_Templates::get_template( 'globals/pagination-quiz.php' );
346 346
 
347 347
 		} else {
348 348
 
349
-            // backwards compatibility check for old location under the wrappers directory of the active theme
350
-            $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) );
351
-            if( !empty( $template ) ){
349
+			// backwards compatibility check for old location under the wrappers directory of the active theme
350
+			$template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) );
351
+			if( !empty( $template ) ){
352 352
 
353
-                Sensei_Templates::get_template( 'wrappers/pagination.php' );
354
-                return;
353
+				Sensei_Templates::get_template( 'wrappers/pagination.php' );
354
+				return;
355 355
 
356
-            }
356
+			}
357 357
 
358 358
 			Sensei_Templates::get_template( 'globals/pagination.php' );
359 359
 
@@ -410,13 +410,13 @@  discard block
 block discarded – undo
410 410
 
411 411
 				case '#senseimymessages':
412 412
 					$item->url = $my_messages_url;
413
-                    // if no archive link exist for sensei_message
414
-                    // set it back to the place holder
415
-                    if( ! $item->url ){
413
+					// if no archive link exist for sensei_message
414
+					// set it back to the place holder
415
+					if( ! $item->url ){
416 416
 
417
-                        $item->url = '#senseimymessages';
417
+						$item->url = '#senseimymessages';
418 418
 
419
-                    }
419
+					}
420 420
 					break;
421 421
 
422 422
 				case '#senseilearnerprofile':
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
 
483 483
 			// Remove the My Messages link for logged out users or if Private Messages are disabled
484 484
 			if( ! get_post_type_archive_link( 'sensei_message' )
485
-                && '#senseimymessages' == $item->url ) {
485
+				&& '#senseimymessages' == $item->url ) {
486 486
 
487 487
 				if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) {
488 488
 
@@ -505,44 +505,44 @@  discard block
 block discarded – undo
505 505
 
506 506
 	// add category nicenames in body and post class
507 507
 	function sensei_search_results_classes($classes) {
508
-	    global $post;
509
-	    // Handle Search Classes for Courses, Lessons, and WC Products
510
-	    if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
511
-	    	$classes[] = 'post';
508
+		global $post;
509
+		// Handle Search Classes for Courses, Lessons, and WC Products
510
+		if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
511
+			$classes[] = 'post';
512 512
 		} // End If Statement
513
-	    return $classes;
513
+		return $classes;
514 514
 	} // End sensei_search_results_classes()
515 515
 
516
-    /**
517
-     * sensei_single_title output for single page title
518
-     * @since  1.1.0
519
-     * @return void
520
-     * @deprecate
521
-     */
522
-    function the_single_title() {
516
+	/**
517
+	 * sensei_single_title output for single page title
518
+	 * @since  1.1.0
519
+	 * @return void
520
+	 * @deprecate
521
+	 */
522
+	function the_single_title() {
523 523
 
524
-        _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0');
524
+		_deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0');
525 525
 
526
-    } // End sensei_single_title()
526
+	} // End sensei_single_title()
527 527
 
528 528
 	/**
529 529
 	 * sensei_course_image output for course image Please use Sensei()->course->course_image instead.
530
-     *
531
-     * @deprecated since 1.9.0
532
-     * @param $course_id
533
-     * @param string $width
534
-     * @param string $height
535
-     * @param bool|false $return
536
-     * @return string|void
530
+	 *
531
+	 * @deprecated since 1.9.0
532
+	 * @param $course_id
533
+	 * @param string $width
534
+	 * @param string $height
535
+	 * @param bool|false $return
536
+	 * @return string|void
537 537
 	 */
538 538
 	function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) {
539 539
 
540
-        trigger_error( 'Sensei Deprecated function: sensei_course_image since 1.9.0 . Please use Sensei()->course->course_image instead.');
540
+		trigger_error( 'Sensei Deprecated function: sensei_course_image since 1.9.0 . Please use Sensei()->course->course_image instead.');
541 541
 
542
-    	if ( ! $return ) {
542
+		if ( ! $return ) {
543 543
 
544 544
 			echo Sensei()->course->course_image( $course_id, $width, $height );
545
-            return '';
545
+			return '';
546 546
 
547 547
 		} // End If Statement
548 548
 
@@ -553,31 +553,31 @@  discard block
 block discarded – undo
553 553
 	/**
554 554
 	 * sensei_lesson_image output for lesson image
555 555
 	 * @since  1.2.0
556
-     * @deprecated since 1.9.0
557
-     * @param $lesson_id
558
-     * @param string $width
559
-     * @param string $height
560
-     * @param bool|false $return
561
-     * @param bool|false $widget
562
-     * @return string
556
+	 * @deprecated since 1.9.0
557
+	 * @param $lesson_id
558
+	 * @param string $width
559
+	 * @param string $height
560
+	 * @param bool|false $return
561
+	 * @param bool|false $widget
562
+	 * @return string
563 563
 	 */
564 564
 	function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) {
565 565
 
566
-        if( ! $return ){
566
+		if( ! $return ){
567 567
 
568
-            echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
569
-            return '';
570
-        }
568
+			echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
569
+			return '';
570
+		}
571 571
 
572
-        return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
572
+		return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
573 573
 
574 574
 	} // End sensei_lesson_image()
575 575
 
576
-    /**
577
-     * @since 1.0.0
578
-     * @param WP_Query $query
579
-     */
580
-    function sensei_course_archive_pagination( $query ) {
576
+	/**
577
+	 * @since 1.0.0
578
+	 * @param WP_Query $query
579
+	 */
580
+	function sensei_course_archive_pagination( $query ) {
581 581
 
582 582
 		if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) {
583 583
 
@@ -600,50 +600,50 @@  discard block
 block discarded – undo
600 600
 	 *
601 601
 	 * @access public
602 602
 	 * @since  1.2.0
603
-     * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header
603
+	 * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header
604 604
 	 * @return void
605 605
 	 */
606 606
 	function sensei_course_archive_header(  ) {
607 607
 
608
-        trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
609
-        WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
608
+		trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
609
+		WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
610 610
 
611 611
 	} // sensei_course_archive_header()
612 612
 
613 613
 	/**
614 614
 	 * sensei_lesson_archive_header function.
615 615
 	 *
616
-     * @deprecated since 1.9.0
616
+	 * @deprecated since 1.9.0
617 617
 	 * @access public
618 618
 	 * @since  1.2.1
619 619
 	 * @return void
620 620
 	 */
621 621
 	public function sensei_lesson_archive_header( ) {
622
-        _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
623
-        Sensei()->lesson->the_archive_header();
622
+		_deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
623
+		Sensei()->lesson->the_archive_header();
624 624
 	} // sensei_course_archive_header()
625 625
 
626
-    /**
627
-     * @deprecated since 1.9.0
628
-     */
626
+	/**
627
+	 * @deprecated since 1.9.0
628
+	 */
629 629
 	public function sensei_message_archive_header( ){
630
-        _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
631
-        Sensei_Messages::the_archive_header();
630
+		_deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
631
+		Sensei_Messages::the_archive_header();
632 632
 	} // sensei_message_archive_header()
633 633
 
634 634
 	/**
635 635
 	 * sensei_course_archive_course_title output for course archive page individual course title
636 636
 	 * @since  1.2.0
637
-     * @param WP_Post $post_item
637
+	 * @param WP_Post $post_item
638 638
 	 * @return void
639 639
 	 */
640 640
 	function sensei_course_archive_course_title( $post_item ) {
641 641
 		if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) {
642 642
 			$post_id = absint( $post_item->ID );
643
-    		$post_title = $post_item->post_title;
643
+			$post_title = $post_item->post_title;
644 644
 		} else {
645 645
 			$post_id = get_the_ID();
646
-    		$post_title = get_the_title();
646
+			$post_title = get_the_title();
647 647
 		} // End If Statement
648 648
 		?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
649 649
 	} // End sensei_course_archive_course_title()
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 	 */
656 656
 	public function sensei_lesson_archive_lesson_title() {
657 657
 		$post_id = get_the_ID();
658
-    	$post_title = get_the_title();
658
+		$post_title = get_the_title();
659 659
 		?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
660 660
 	} // End sensei_lesson_archive_lesson_title()
661 661
 
@@ -672,9 +672,9 @@  discard block
 block discarded – undo
672 672
 
673 673
 		if( empty( $id )  ){
674 674
 
675
-            $id = get_the_ID();
675
+			$id = get_the_ID();
676 676
 
677
-        }
677
+		}
678 678
 
679 679
 		$sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' );
680 680
 		$separator = apply_filters( 'sensei_breadcrumb_separator', '&gt;' );
@@ -687,31 +687,31 @@  discard block
 block discarded – undo
687 687
 				return;
688 688
 			}
689 689
 			$html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>';
690
-    	} // End If Statement
691
-    	// Quiz
690
+		} // End If Statement
691
+		// Quiz
692 692
 		if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) {
693 693
 			$lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) );
694 694
 			if( ! $lesson_id ) {
695 695
 				return;
696 696
 			}
697 697
 			 $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' .  __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>';
698
-    	} // End If Statement
698
+		} // End If Statement
699 699
 
700
-    	// Allow other plugins to filter html
701
-    	$html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
702
-    	$html .= '</section>';
700
+		// Allow other plugins to filter html
701
+		$html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
702
+		$html .= '</section>';
703 703
 
704
-    	echo $html;
704
+		echo $html;
705 705
 	} // End sensei_breadcrumb()
706 706
 
707 707
 
708
-    /**
709
-     * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead
710
-     */
708
+	/**
709
+	 * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead
710
+	 */
711 711
 	public function sensei_lesson_course_signup_link( ) {
712 712
 
713
-        _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
714
-        WooThemes_Sensei_Lesson::course_signup_link();
713
+		_deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
714
+		WooThemes_Sensei_Lesson::course_signup_link();
715 715
 	}
716 716
 
717 717
 	public function lesson_tags_display( $lesson_id = 0 ) {
@@ -730,27 +730,27 @@  discard block
 block discarded – undo
730 730
 					?><section class="lesson-tags">
731 731
 		    			<?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?>
732 732
 		    		</section><?php
733
-		    	}
734
-	    	}
733
+				}
734
+			}
735 735
 		}
736 736
 	}
737 737
 
738
-    /**
739
-     * @param WP_Query $query
740
-     */
738
+	/**
739
+	 * @param WP_Query $query
740
+	 */
741 741
 	public function lesson_tag_archive_filter( $query ) {
742
-    	if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
743
-    		// Limit to lessons only
744
-    		$query->set( 'post_type', 'lesson' );
742
+		if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
743
+			// Limit to lessons only
744
+			$query->set( 'post_type', 'lesson' );
745 745
 
746
-    		// Set order of lessons
747
-    		$query->set( 'orderby', 'menu_order' );
748
-    		$query->set( 'order', 'ASC' );
746
+			// Set order of lessons
747
+			$query->set( 'orderby', 'menu_order' );
748
+			$query->set( 'order', 'ASC' );
749 749
 
750
-    	}
751
-    }
750
+		}
751
+	}
752 752
 
753
-    public function lesson_tag_archive_header( $title ) {
753
+	public function lesson_tag_archive_header( $title ) {
754 754
 		if( is_tax( 'lesson-tag' ) ) {
755 755
 			$title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) );
756 756
 		}
@@ -772,13 +772,13 @@  discard block
 block discarded – undo
772 772
 			$sanitized_submit = esc_html( $_POST['quiz_action'] );
773 773
 
774 774
 			switch ($sanitized_submit) {
775
-                case 'lesson-complete':
775
+				case 'lesson-complete':
776 776
 
777 777
 					Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true );
778 778
 
779 779
 					break;
780 780
 
781
-                case 'lesson-reset':
781
+				case 'lesson-reset':
782 782
 
783 783
 					Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID );
784 784
 
@@ -890,13 +890,13 @@  discard block
 block discarded – undo
890 890
 		if ( 0 < intval( $post_id ) ) {
891 891
 			$lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true );
892 892
 			if ( 'http' == substr( $lesson_video_embed, 0, 4) ) {
893
-        		// V2 - make width and height a setting for video embed
894
-        		$lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ );
895
-        	} // End If Statement
896
-        	if ( '' != $lesson_video_embed ) {
897
-        	?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php
898
-        	} // End If Statement
899
-        } // End If Statement
893
+				// V2 - make width and height a setting for video embed
894
+				$lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ );
895
+			} // End If Statement
896
+			if ( '' != $lesson_video_embed ) {
897
+			?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php
898
+			} // End If Statement
899
+		} // End If Statement
900 900
 	} // End sensei_lesson_video()
901 901
 
902 902
 	public function sensei_complete_lesson_button() {
@@ -909,8 +909,8 @@  discard block
 block discarded – undo
909 909
 		$pass_required = true;
910 910
 		if( $quiz_id ) {
911 911
 			// Get quiz pass setting
912
-	    	$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
913
-	    }
912
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
913
+		}
914 914
 		if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) {
915 915
 			?>
916 916
 			<form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
@@ -963,12 +963,12 @@  discard block
 block discarded – undo
963 963
 		} // End If Statement
964 964
 	} // End sensei_reset_lesson_button()
965 965
 
966
-    /**
967
-     * @deprecated since 1.9.0
968
-     */
969
-    public function sensei_lesson_quiz_meta( ) {
966
+	/**
967
+	 * @deprecated since 1.9.0
968
+	 */
969
+	public function sensei_lesson_quiz_meta( ) {
970 970
 
971
-        Sensei_Lesson::footer_quiz_call_to_action();
971
+		Sensei_Lesson::footer_quiz_call_to_action();
972 972
 
973 973
 	} // End sensei_lesson_quiz_meta()
974 974
 
@@ -994,38 +994,38 @@  discard block
 block discarded – undo
994 994
         	</p>
995 995
         	<p class="course-excerpt"><?php the_excerpt(); ?></p>
996 996
         	<?php if ( 0 < $free_lesson_count ) {
997
-                $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
997
+				$free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
998 998
                 <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p>
999 999
             <?php } ?>
1000 1000
 		</section><?php
1001 1001
 	} // End sensei_course_archive_meta()
1002 1002
 
1003
-    /**
1004
-     * @deprecated since 1.9.0
1005
-     */
1003
+	/**
1004
+	 * @deprecated since 1.9.0
1005
+	 */
1006 1006
 	public function sensei_single_main_content() {
1007
-	    _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0');
1007
+		_deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0');
1008 1008
 	} // End sensei_single_main_content()
1009 1009
 
1010
-    /**
1011
-    * @deprecated since 1.9.0
1012
-    */
1010
+	/**
1011
+	 * @deprecated since 1.9.0
1012
+	 */
1013 1013
 	public function sensei_lesson_archive_main_content() {
1014
-        _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly');
1014
+		_deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly');
1015 1015
 	} // End sensei_lesson_archive_main_content()
1016 1016
 
1017
-    /**
1018
-    * @deprecated since 1.9.0
1019
-    */
1017
+	/**
1018
+	 * @deprecated since 1.9.0
1019
+	 */
1020 1020
 	public function sensei_message_archive_main_content() {
1021 1021
 		_deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' );
1022 1022
 	} // End sensei_lesson_archive_main_content()
1023 1023
 
1024
-    /**
1025
-    * @deprecated since 1.9.0
1026
-    */
1024
+	/**
1025
+	 * @deprecated since 1.9.0
1026
+	 */
1027 1027
 	public function sensei_no_permissions_main_content() {
1028
-        _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1028
+		_deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1029 1029
 	} // End sensei_no_permissions_main_content()
1030 1030
 
1031 1031
 	public function sensei_course_category_main_content() {
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
 				<div class="col-1">
1074 1074
 					<?php
1075 1075
 					// output the actual form markup
1076
-                    Sensei_Templates::get_template( 'user/login-form.php');
1076
+					Sensei_Templates::get_template( 'user/login-form.php');
1077 1077
 					?>
1078 1078
 				</div>
1079 1079
 
@@ -1154,12 +1154,12 @@  discard block
 block discarded – undo
1154 1154
 
1155 1155
 		//if this is a paid course
1156 1156
 		if ( Sensei_WC::is_woocommerce_active() ) {
1157
-    	    $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1158
-    	    if ( 0 < $wc_post_id ) {
1159
-    	    	$preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1160
-    	    } // End If Statement
1161
-    	}
1162
-    	return $preview_text;
1157
+			$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1158
+			if ( 0 < $wc_post_id ) {
1159
+				$preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1160
+			} // End If Statement
1161
+		}
1162
+		return $preview_text;
1163 1163
 	}
1164 1164
 
1165 1165
 	public function sensei_lesson_preview_title( $title = '', $id = 0 ) {
@@ -1191,8 +1191,8 @@  discard block
 block discarded – undo
1191 1191
 		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
1192 1192
 		// Handle user starting the course
1193 1193
 		if ( isset( $_POST['course_start'] )
1194
-		    && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1195
-		    && !$is_user_taking_course ) {
1194
+			&& wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1195
+			&& !$is_user_taking_course ) {
1196 1196
 
1197 1197
 			// Start the course
1198 1198
 			$activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID );
@@ -1211,35 +1211,35 @@  discard block
 block discarded – undo
1211 1211
 		} // End If Statement
1212 1212
 	} // End sensei_course_start()
1213 1213
 
1214
-    /**
1215
-     * @deprecated since 1.9.0
1216
-     */
1214
+	/**
1215
+	 * @deprecated since 1.9.0
1216
+	 */
1217 1217
 	public function sensei_course_meta() {
1218
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1219
-        Sensei()->course->the_course_meta( get_post() );
1218
+		_deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1219
+		Sensei()->course->the_course_meta( get_post() );
1220 1220
 	} // End sensei_course_meta()
1221 1221
 
1222
-    /**
1223
-     * @deprecated since 1.9.0
1224
-     */
1222
+	/**
1223
+	 * @deprecated since 1.9.0
1224
+	 */
1225 1225
 	public function sensei_course_meta_video() {
1226
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1227
-        Sensei_Course::the_course_video();
1226
+		_deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1227
+		Sensei_Course::the_course_video();
1228 1228
 	} // End sensei_course_meta_video()
1229 1229
 
1230
-    /**
1231
-     * This function shows the WooCommerce cart notice if the user has
1232
-     * added the current course to cart. It does not show if the user is already taking
1233
-     * the course.
1234
-     *
1235
-     * @since 1.0.2
1236
-     * @return void;
1237
-     */
1238
-    public function sensei_woocommerce_in_cart_message() {
1230
+	/**
1231
+	 * This function shows the WooCommerce cart notice if the user has
1232
+	 * added the current course to cart. It does not show if the user is already taking
1233
+	 * the course.
1234
+	 *
1235
+	 * @since 1.0.2
1236
+	 * @return void;
1237
+	 */
1238
+	public function sensei_woocommerce_in_cart_message() {
1239 1239
 		global $post, $woocommerce;
1240 1240
 
1241 1241
 		$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
1242
-        $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1242
+		$user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1243 1243
 		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
1244 1244
 
1245 1245
 			if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) {
@@ -1287,7 +1287,7 @@  discard block
 block discarded – undo
1287 1287
 				$item_id = $item['product_id'];
1288 1288
 			} 
1289 1289
 
1290
-            if ( $item_id > 0 ) {
1290
+			if ( $item_id > 0 ) {
1291 1291
 
1292 1292
 				$user_id = get_post_meta( $order_id, '_customer_user', true );
1293 1293
 
@@ -1367,15 +1367,15 @@  discard block
 block discarded – undo
1367 1367
 
1368 1368
 					$items = $order->get_items();
1369 1369
 					foreach( $items as $item ) {
1370
-                                            if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1371
-                                                $item_id = $item['variation_id'];
1372
-                                                $product_type = 'variation';
1373
-                                            } else {
1374
-                                                $item_id = $item['product_id'];
1375
-                                            }
1370
+											if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1371
+												$item_id = $item['variation_id'];
1372
+												$product_type = 'variation';
1373
+											} else {
1374
+												$item_id = $item['product_id'];
1375
+											}
1376 1376
 
1377
-                                            $product_ids[] = $item_id;
1378
-                                            }
1377
+											$product_ids[] = $item_id;
1378
+											}
1379 1379
 
1380 1380
 					$order_ids[] = $post_id;
1381 1381
 				}
@@ -1482,32 +1482,32 @@  discard block
 block discarded – undo
1482 1482
 
1483 1483
 				$items = $order->get_items();
1484 1484
 				foreach( $items as $item ) {
1485
-                    $product = wc_get_product( $item['product_id'] );
1485
+					$product = wc_get_product( $item['product_id'] );
1486 1486
 
1487
-                    // handle product bundles
1488
-                    if( $product->is_type('bundle') ){
1487
+					// handle product bundles
1488
+					if( $product->is_type('bundle') ){
1489 1489
 
1490
-                        $bundled_product = new WC_Product_Bundle( $product->id );
1491
-                        $bundled_items = $bundled_product->get_bundled_items();
1490
+						$bundled_product = new WC_Product_Bundle( $product->id );
1491
+						$bundled_items = $bundled_product->get_bundled_items();
1492 1492
 
1493
-                        foreach( $bundled_items as $bundled_item ){
1493
+						foreach( $bundled_items as $bundled_item ){
1494 1494
 
1495
-                            if( $bundled_item->product_id == $course_product_id ) {
1496
-                                Sensei_Utils::user_start_course( $user_id, $course_id );
1497
-                                return;
1498
-                            }
1495
+							if( $bundled_item->product_id == $course_product_id ) {
1496
+								Sensei_Utils::user_start_course( $user_id, $course_id );
1497
+								return;
1498
+							}
1499 1499
 
1500
-                        }
1500
+						}
1501 1501
 
1502
-                    } else {
1502
+					} else {
1503 1503
 
1504
-                    // handle regular products
1505
-                        if( $item['product_id'] == $course_product_id ) {
1506
-                            Sensei_Utils::user_start_course( $user_id, $course_id );
1507
-                            return;
1508
-                        }
1504
+					// handle regular products
1505
+						if( $item['product_id'] == $course_product_id ) {
1506
+							Sensei_Utils::user_start_course( $user_id, $course_id );
1507
+							return;
1508
+						}
1509 1509
 
1510
-                    }
1510
+					}
1511 1511
 				}
1512 1512
 			}
1513 1513
 
@@ -1538,21 +1538,21 @@  discard block
 block discarded – undo
1538 1538
 
1539 1539
 		//if not posted from the sensei login form let
1540 1540
 		// WordPress or any other party handle the failed request
1541
-	    if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form']  ){
1541
+		if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form']  ){
1542 1542
 
1543
-	    	return ;
1543
+			return ;
1544 1544
 
1545
-	    }
1545
+		}
1546 1546
 
1547
-    	// Get the reffering page, where did the post submission come from?
1548
-    	$referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1547
+		// Get the reffering page, where did the post submission come from?
1548
+		$referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1549 1549
 
1550 1550
    		 // if there's a valid referrer, and it's not the default log-in screen
1551
-	    if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1552
-	        // let's append some information (login=failed) to the URL for the theme to use
1553
-	        wp_redirect( esc_url_raw( add_query_arg('login', 'failed',  $referrer) ) );
1554
-	    	exit;
1555
-    	}
1551
+		if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1552
+			// let's append some information (login=failed) to the URL for the theme to use
1553
+			wp_redirect( esc_url_raw( add_query_arg('login', 'failed',  $referrer) ) );
1554
+			exit;
1555
+		}
1556 1556
 	}// End sensei_login_fail_redirect_to_front_end_login
1557 1557
 
1558 1558
 	/**
@@ -1564,47 +1564,47 @@  discard block
 block discarded – undo
1564 1564
 
1565 1565
 
1566 1566
 		// Check that it is a sensei login request and if it has a valid nonce
1567
-	    if(  isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1567
+		if(  isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1568 1568
 
1569
-	    	// Validate the login request nonce
1570
-		    if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1571
-		    	return;
1572
-		    }
1569
+			// Validate the login request nonce
1570
+			if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1571
+				return;
1572
+			}
1573 1573
 
1574 1574
 
1575
-		    //get the page where the sensei log form is located
1576
-		    $referrer = $_REQUEST['_wp_http_referer'];
1577
-		    //$redirect = $_REQUEST['_sensei_redirect'];
1575
+			//get the page where the sensei log form is located
1576
+			$referrer = $_REQUEST['_wp_http_referer'];
1577
+			//$redirect = $_REQUEST['_sensei_redirect'];
1578 1578
 
1579
-		    if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1580
-		    	 && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1579
+			if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1580
+				 && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1581 1581
 
1582
-		    	// when the user has entered a password or username do the sensei login
1583
-		    	$creds = array();
1582
+				// when the user has entered a password or username do the sensei login
1583
+				$creds = array();
1584 1584
 
1585
-		    	// check if the requests login is an email address
1586
-		    	if( is_email(  trim( $_REQUEST['log'] ) )  ){
1587
-		    		// query wordpress for the users details
1588
-		    		$user =	get_user_by( 'email', sanitize_email( $_REQUEST['log'] )  );
1585
+				// check if the requests login is an email address
1586
+				if( is_email(  trim( $_REQUEST['log'] ) )  ){
1587
+					// query wordpress for the users details
1588
+					$user =	get_user_by( 'email', sanitize_email( $_REQUEST['log'] )  );
1589 1589
 
1590
-		    		// validate the user object
1591
-		    		if( !$user ){
1590
+					// validate the user object
1591
+					if( !$user ){
1592 1592
 
1593
-		    			// the email doesnt exist
1594
-                        wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1595
-		        		exit;
1593
+						// the email doesnt exist
1594
+						wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1595
+						exit;
1596 1596
 
1597
-		    		}
1597
+					}
1598 1598
 
1599
-		    		//assigne the username to the creds array for further processing
1600
-		    		$creds['user_login'] =  $user->user_login ;
1599
+					//assigne the username to the creds array for further processing
1600
+					$creds['user_login'] =  $user->user_login ;
1601 1601
 
1602
-		    	}else{
1602
+				}else{
1603 1603
 
1604
-		    		// process this as a default username login
1605
-		    		$creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1604
+					// process this as a default username login
1605
+					$creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1606 1606
 
1607
-		    	}
1607
+				}
1608 1608
 
1609 1609
 				// get setup the rest of the creds array
1610 1610
 				$creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] );
@@ -1614,42 +1614,42 @@  discard block
 block discarded – undo
1614 1614
 				$user = wp_signon( $creds, false );
1615 1615
 
1616 1616
 				if ( is_wp_error($user) ){ // on login failure
1617
-                    wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1618
-                    exit;
1617
+					wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1618
+					exit;
1619 1619
 				}else{ // on login success
1620 1620
 
1621 1621
 					/**
1622
-					* change the redirect url programatically
1623
-					*
1624
-					* @since 1.6.1
1625
-					*
1626
-					* @param string $referrer the page where the current url wheresensei login form was posted from
1627
-					*/
1622
+					 * change the redirect url programatically
1623
+					 *
1624
+					 * @since 1.6.1
1625
+					 *
1626
+					 * @param string $referrer the page where the current url wheresensei login form was posted from
1627
+					 */
1628 1628
 
1629 1629
 					$success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) );
1630 1630
 
1631 1631
 					wp_redirect( esc_url_raw( $success_redirect_url ) );
1632
-		        	exit;
1632
+					exit;
1633 1633
 
1634 1634
 				}	// end is_wp_error($user)
1635 1635
 
1636
-		    }else{ // if username or password is empty
1636
+			}else{ // if username or password is empty
1637 1637
 
1638
-                wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1639
-		        exit;
1638
+				wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1639
+				exit;
1640 1640
 
1641
-		    } // end if username $_REQUEST['log']  and password $_REQUEST['pwd'] is empty
1641
+			} // end if username $_REQUEST['log']  and password $_REQUEST['pwd'] is empty
1642 1642
 
1643
-	    }elseif( ( isset( $_GET['login'] ) ) ) {
1644
-	    	// else if this request is a redircect from a previously faile login request
1645
-	    	$this->login_message_process();
1643
+		}elseif( ( isset( $_GET['login'] ) ) ) {
1644
+			// else if this request is a redircect from a previously faile login request
1645
+			$this->login_message_process();
1646 1646
 
1647 1647
 			//exit the handle login request function
1648 1648
 			return;
1649
-	    }
1649
+		}
1650 1650
 
1651
-	    // if none of the above
1652
-	    return;
1651
+		// if none of the above
1652
+		return;
1653 1653
 
1654 1654
 	} // End  sensei_login_fail_redirect_to_front_end_login
1655 1655
 
@@ -1753,7 +1753,7 @@  discard block
 block discarded – undo
1753 1753
 	public function login_message_process(){
1754 1754
 
1755 1755
 
1756
-		    // setup the message variables
1756
+			// setup the message variables
1757 1757
 			$message = '';
1758 1758
 
1759 1759
 			//only output message if the url contains login=failed and login=emptyfields
@@ -1772,22 +1772,22 @@  discard block
 block discarded – undo
1772 1772
 	}// end login_message_process
1773 1773
 
1774 1774
 
1775
-    /**
1776
-     * sensei_show_admin_bar(). Use WooCommerce filter
1777
-     * to show admin bar to Teachers as well.
1778
-     *
1779
-     * @return void redirect
1780
-     *
1781
-     */
1782
-    public function sensei_show_admin_bar () {
1775
+	/**
1776
+	 * sensei_show_admin_bar(). Use WooCommerce filter
1777
+	 * to show admin bar to Teachers as well.
1778
+	 *
1779
+	 * @return void redirect
1780
+	 *
1781
+	 */
1782
+	public function sensei_show_admin_bar () {
1783 1783
 
1784
-        if (current_user_can('edit_courses')) {
1784
+		if (current_user_can('edit_courses')) {
1785 1785
 
1786
-            add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1786
+			add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1787 1787
 
1788
-        }
1788
+		}
1789 1789
 
1790
-    }
1790
+	}
1791 1791
 
1792 1792
 } // End Class
1793 1793
 
Please login to merge, or discard this patch.
includes/class-sensei.php 1 patch
Indentation   +1298 added lines, -1298 removed lines patch added patch discarded remove patch
@@ -14,1316 +14,1316 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Main {
16 16
 
17
-    /**
18
-     * @var file
19
-     * Reference to the main plugin file
20
-     */
21
-    private $file;
22
-
23
-    /**
24
-     * @var $_instance reference to the the main and only instance of the Sensei class.
25
-     * @since 1.8.0
26
-     */
27
-    protected static $_instance = null;
28
-
29
-    /**
30
-     * Main reference to the plugins current version
31
-     */
32
-    public $version;
33
-
34
-    /**
35
-     * Public token, referencing for the text domain.
36
-     */
37
-    public $token = 'woothemes-sensei';
38
-
39
-    /**
40
-     * Plugin url and path for use when access resources.
41
-     */
42
-    public $plugin_url;
43
-    public $plugin_path;
44
-    public $template_url;
45
-
46
-    /**
47
-     * @var WooThemes_Sensei_PostTypes
48
-     * All Sensei sub classes. Currently used to access functionality contained within
49
-     * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
-     */
51
-    public $post_types;
52
-
53
-    /**
54
-     * @var WooThemes_Sensei_Settings
55
-     */
56
-    public $settings;
57
-
58
-    /**
59
-     * @var WooThemes_Sensei_Course_Results
60
-     */
61
-    public $course_results;
62
-
63
-    /**
64
-     * @var WooThemes_Sensei_Course
65
-     */
66
-    public $course;
67
-
68
-    /**
69
-     * @var WooThemes_Sensei_Lesson
70
-     */
71
-    public $lesson;
72
-
73
-    /**
74
-     * @var WooThemes_Sensei_Quiz
75
-     */
76
-    public $quiz;
77
-
78
-    /**
79
-     * @var WooThemes_Sensei_Question
80
-     */
81
-    public $question;
82
-
83
-    /**
84
-     * @var WooThemes_Sensei_Admin
85
-     */
86
-    public $admin;
87
-
88
-    /**
89
-     * @var WooThemes_Sensei_Frontend
90
-     */
91
-    public $frontend;
92
-
93
-    /**
94
-     * @var String
95
-     */
96
-    public $notice;
97
-
98
-    /**
99
-     * @var WooThemes_Sensei_Grading
100
-     */
101
-    public $grading;
102
-
103
-    /**
104
-     * @var WooThemes_Sensei_Emails
105
-     */
106
-    public $emails;
107
-
108
-    /**
109
-     * @var WooThemes_Sensei_Learner_Profiles
110
-     */
111
-    public $learner_profiles;
112
-
113
-    /**
114
-     * @var Sensei_Teacher
115
-     */
116
-    public $teacher;
117
-
118
-    /**
119
-     * @var WooThemes_Sensei_Learners
120
-     */
121
-    public $learners;
122
-
123
-    /**
124
-     * @var array
125
-     * Global instance for access to the permissions message shown
126
-     * when users do not have the right privileges to access resources.
127
-     */
128
-    public $permissions_message;
129
-
130
-    /**
131
-     * @var Sensei_Core_Modules Sensei Modules functionality
132
-     */
133
-    public $modules;
134
-
135
-    /**
136
-     * @var Sensei_Analysis
137
-     */
138
-    public $analysis;
139
-
140
-    /**
141
-     * Constructor method.
142
-     * @param  string $file The base file of the plugin.
143
-     * @since  1.0.0
144
-     */
145
-    public function __construct ( $file ) {
146
-
147
-        // Setup object data
148
-        $this->file = $file;
149
-        $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
150
-        $this->plugin_path = trailingslashit( dirname( $file ) );
151
-        $this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
152
-        $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
153
-
154
-        // Initialize the core Sensei functionality
155
-        $this->init();
17
+	/**
18
+	 * @var file
19
+	 * Reference to the main plugin file
20
+	 */
21
+	private $file;
22
+
23
+	/**
24
+	 * @var $_instance reference to the the main and only instance of the Sensei class.
25
+	 * @since 1.8.0
26
+	 */
27
+	protected static $_instance = null;
28
+
29
+	/**
30
+	 * Main reference to the plugins current version
31
+	 */
32
+	public $version;
33
+
34
+	/**
35
+	 * Public token, referencing for the text domain.
36
+	 */
37
+	public $token = 'woothemes-sensei';
38
+
39
+	/**
40
+	 * Plugin url and path for use when access resources.
41
+	 */
42
+	public $plugin_url;
43
+	public $plugin_path;
44
+	public $template_url;
45
+
46
+	/**
47
+	 * @var WooThemes_Sensei_PostTypes
48
+	 * All Sensei sub classes. Currently used to access functionality contained within
49
+	 * within Sensei sub classes e.g. Sensei()->course->all_courses()
50
+	 */
51
+	public $post_types;
52
+
53
+	/**
54
+	 * @var WooThemes_Sensei_Settings
55
+	 */
56
+	public $settings;
57
+
58
+	/**
59
+	 * @var WooThemes_Sensei_Course_Results
60
+	 */
61
+	public $course_results;
62
+
63
+	/**
64
+	 * @var WooThemes_Sensei_Course
65
+	 */
66
+	public $course;
67
+
68
+	/**
69
+	 * @var WooThemes_Sensei_Lesson
70
+	 */
71
+	public $lesson;
72
+
73
+	/**
74
+	 * @var WooThemes_Sensei_Quiz
75
+	 */
76
+	public $quiz;
77
+
78
+	/**
79
+	 * @var WooThemes_Sensei_Question
80
+	 */
81
+	public $question;
82
+
83
+	/**
84
+	 * @var WooThemes_Sensei_Admin
85
+	 */
86
+	public $admin;
87
+
88
+	/**
89
+	 * @var WooThemes_Sensei_Frontend
90
+	 */
91
+	public $frontend;
92
+
93
+	/**
94
+	 * @var String
95
+	 */
96
+	public $notice;
97
+
98
+	/**
99
+	 * @var WooThemes_Sensei_Grading
100
+	 */
101
+	public $grading;
102
+
103
+	/**
104
+	 * @var WooThemes_Sensei_Emails
105
+	 */
106
+	public $emails;
107
+
108
+	/**
109
+	 * @var WooThemes_Sensei_Learner_Profiles
110
+	 */
111
+	public $learner_profiles;
112
+
113
+	/**
114
+	 * @var Sensei_Teacher
115
+	 */
116
+	public $teacher;
117
+
118
+	/**
119
+	 * @var WooThemes_Sensei_Learners
120
+	 */
121
+	public $learners;
122
+
123
+	/**
124
+	 * @var array
125
+	 * Global instance for access to the permissions message shown
126
+	 * when users do not have the right privileges to access resources.
127
+	 */
128
+	public $permissions_message;
129
+
130
+	/**
131
+	 * @var Sensei_Core_Modules Sensei Modules functionality
132
+	 */
133
+	public $modules;
134
+
135
+	/**
136
+	 * @var Sensei_Analysis
137
+	 */
138
+	public $analysis;
139
+
140
+	/**
141
+	 * Constructor method.
142
+	 * @param  string $file The base file of the plugin.
143
+	 * @since  1.0.0
144
+	 */
145
+	public function __construct ( $file ) {
146
+
147
+		// Setup object data
148
+		$this->file = $file;
149
+		$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
150
+		$this->plugin_path = trailingslashit( dirname( $file ) );
151
+		$this->template_url	= apply_filters( 'sensei_template_url', 'sensei/' );
152
+		$this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) );
153
+
154
+		// Initialize the core Sensei functionality
155
+		$this->init();
156 156
 
157
-        // Installation
158
-        if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
157
+		// Installation
158
+		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install();
159 159
 
160
-        // Run this on activation.
161
-        register_activation_hook( $this->file, array( $this, 'activation' ) );
160
+		// Run this on activation.
161
+		register_activation_hook( $this->file, array( $this, 'activation' ) );
162 162
 
163
-        // Setup post types.
164
-        $this->post_types = new Sensei_PostTypes();
165
-        $this->post_types->token = 'woothemes-sensei-posttypes';
166
-
167
-        // Lad the updates class
168
-        $this->updates = new WooThemes_Sensei_Updates( $this );
169
-
170
-        // Setup settings screen.
171
-        $this->settings = new Sensei_Settings();
172
-        $this->settings->token = 'woothemes-sensei-settings';
173
-
174
-        // Setup Admin Settings data
175
-        if ( is_admin() ) {
176
-
177
-            $this->settings->has_tabs 	= true;
178
-            $this->settings->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
179
-            $this->settings->menu_label	= __( 'Settings', 'woothemes-sensei' );
180
-            $this->settings->page_slug	= 'woothemes-sensei-settings';
163
+		// Setup post types.
164
+		$this->post_types = new Sensei_PostTypes();
165
+		$this->post_types->token = 'woothemes-sensei-posttypes';
166
+
167
+		// Lad the updates class
168
+		$this->updates = new WooThemes_Sensei_Updates( $this );
169
+
170
+		// Setup settings screen.
171
+		$this->settings = new Sensei_Settings();
172
+		$this->settings->token = 'woothemes-sensei-settings';
173
+
174
+		// Setup Admin Settings data
175
+		if ( is_admin() ) {
176
+
177
+			$this->settings->has_tabs 	= true;
178
+			$this->settings->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
179
+			$this->settings->menu_label	= __( 'Settings', 'woothemes-sensei' );
180
+			$this->settings->page_slug	= 'woothemes-sensei-settings';
181 181
 
182
-        } // End If Statement
182
+		} // End If Statement
183 183
 
184
-        $this->settings->setup_settings();
185
-        $this->settings->get_settings();
184
+		$this->settings->setup_settings();
185
+		$this->settings->get_settings();
186 186
 
187
-        // Load Course Results Class
188
-        $this->course_results = new Sensei_Course_Results();
189
-        $this->course_results->token = $this->token;
187
+		// Load Course Results Class
188
+		$this->course_results = new Sensei_Course_Results();
189
+		$this->course_results->token = $this->token;
190 190
 
191
-        // Load the teacher role
192
-        $this->teacher = new Sensei_Teacher();
191
+		// Load the teacher role
192
+		$this->teacher = new Sensei_Teacher();
193 193
 
194
-        // Add the Course class
195
-        $this->course = $this->post_types->course;
194
+		// Add the Course class
195
+		$this->course = $this->post_types->course;
196 196
 
197
-        // Add the lesson class
198
-        $this->lesson = $this->post_types->lesson;
197
+		// Add the lesson class
198
+		$this->lesson = $this->post_types->lesson;
199 199
 
200
-        // Add the question class
201
-        $this->question = $this->post_types->question;
200
+		// Add the question class
201
+		$this->question = $this->post_types->question;
202 202
 
203
-        //Add the quiz class
204
-        $this->quiz = $this->post_types->quiz;
203
+		//Add the quiz class
204
+		$this->quiz = $this->post_types->quiz;
205 205
 
206
-        // load the modules class
207
-        add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
206
+		// load the modules class
207
+		add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) );
208 208
 
209
-        // Load Learner Management Functionality
210
-        $this->learners = new Sensei_Learners( $file );
211
-        $this->learners->token = $this->token;
209
+		// Load Learner Management Functionality
210
+		$this->learners = new Sensei_Learners( $file );
211
+		$this->learners->token = $this->token;
212 212
 
213
-        // Differentiate between administration and frontend logic.
214
-        if ( is_admin() ) {
213
+		// Differentiate between administration and frontend logic.
214
+		if ( is_admin() ) {
215 215
 
216
-            // Load Admin Welcome class
217
-            new Sensei_Welcome();
216
+			// Load Admin Welcome class
217
+			new Sensei_Welcome();
218 218
 
219
-            // Load Admin Class
220
-            $this->admin = new Sensei_Admin( $file );
221
-            $this->admin->token = $this->token;
219
+			// Load Admin Class
220
+			$this->admin = new Sensei_Admin( $file );
221
+			$this->admin->token = $this->token;
222 222
 
223
-            // Load Analysis Reports
224
-            $this->analysis = new Sensei_Analysis( $file );
225
-            $this->analysis->token = $this->token;
223
+			// Load Analysis Reports
224
+			$this->analysis = new Sensei_Analysis( $file );
225
+			$this->analysis->token = $this->token;
226 226
 
227 227
 
228
-        } else {
228
+		} else {
229 229
 
230
-            // Load Frontend Class
231
-            $this->frontend = new Sensei_Frontend();
232
-            $this->frontend->token = $this->token;
233
-            $this->frontend->init();
230
+			// Load Frontend Class
231
+			$this->frontend = new Sensei_Frontend();
232
+			$this->frontend->token = $this->token;
233
+			$this->frontend->init();
234 234
 
235
-            // Load notice Class
236
-            $this->notices = new Sensei_Notices();
235
+			// Load notice Class
236
+			$this->notices = new Sensei_Notices();
237 237
 
238
-        }
238
+		}
239 239
 
240
-        // Load Grading Functionality
241
-        $this->grading = new Sensei_Grading( $file );
242
-        $this->grading->token = $this->token;
240
+		// Load Grading Functionality
241
+		$this->grading = new Sensei_Grading( $file );
242
+		$this->grading->token = $this->token;
243 243
 
244
-        // Load Email Class
245
-        $this->emails = new Sensei_Emails( $file );
246
-        $this->emails->token = $this->token;
244
+		// Load Email Class
245
+		$this->emails = new Sensei_Emails( $file );
246
+		$this->emails->token = $this->token;
247 247
 
248
-        // Load Learner Profiles Class
249
-        $this->learner_profiles = new Sensei_Learner_Profiles();
250
-        $this->learner_profiles->token = $this->token;
248
+		// Load Learner Profiles Class
249
+		$this->learner_profiles = new Sensei_Learner_Profiles();
250
+		$this->learner_profiles->token = $this->token;
251 251
 
252
-        // Image Sizes
253
-        $this->init_image_sizes();
252
+		// Image Sizes
253
+		$this->init_image_sizes();
254 254
 
255
-        // Force WooCommerce Required Settings
256
-        $this->set_woocommerce_functionality();
257
-        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
258
-        add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
255
+		// Force WooCommerce Required Settings
256
+		$this->set_woocommerce_functionality();
257
+		add_action( 'widgets_init', array( $this, 'register_widgets' ) );
258
+		add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) );
259 259
 
260
-        // WooCommerce Payment Actions
261
-        add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
262
-        add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
263
-        add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
264
-        add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
265
-        add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
266
-        add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
267
-        add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
260
+		// WooCommerce Payment Actions
261
+		add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) );
262
+		add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) );
263
+		add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) );
264
+		add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) );
265
+		add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) );
266
+		add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) );
267
+		add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) );
268 268
 
269
-        // WooCommerce Subscriptions Actions
270
-        add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
271
-        add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
272
-        add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
273
-        add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
274
-        add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
269
+		// WooCommerce Subscriptions Actions
270
+		add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 );
271
+		add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
272
+		add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
273
+		add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
274
+		add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 );
275 275
 
276
-        // Add Email link to course orders
277
-        add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
276
+		// Add Email link to course orders
277
+		add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 );
278 278
 
279
-        // Filter comment counts
280
-        add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
279
+		// Filter comment counts
280
+		add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 );
281 281
 
282
-        add_action( 'body_class', array( $this, 'body_class' ) );
282
+		add_action( 'body_class', array( $this, 'body_class' ) );
283 283
 
284
-        // Check for and activate JetPack LaTeX support
285
-        add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
284
+		// Check for and activate JetPack LaTeX support
285
+		add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules
286 286
 
287
-        // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
288
-        add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
287
+		// check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1
288
+		add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 );
289 289
 
290
-    } // End __construct()
290
+	} // End __construct()
291 291
 
292
-    /**
293
-     * Load the foundations of Sensei.
294
-     * @since 1.9.0
295
-     */
296
-    protected function init(){
292
+	/**
293
+	 * Load the foundations of Sensei.
294
+	 * @since 1.9.0
295
+	 */
296
+	protected function init(){
297 297
 
298
-        // Localisation
299
-        $this->load_plugin_textdomain();
300
-        add_action( 'init', array( $this, 'load_localisation' ), 0 );
298
+		// Localisation
299
+		$this->load_plugin_textdomain();
300
+		add_action( 'init', array( $this, 'load_localisation' ), 0 );
301 301
 
302
-        // load the shortcode loader into memory, so as to listen to all for
303
-        // all shortcodes on the front end
304
-        new Sensei_Shortcode_Loader();
302
+		// load the shortcode loader into memory, so as to listen to all for
303
+		// all shortcodes on the front end
304
+		new Sensei_Shortcode_Loader();
305 305
 
306
-    }
306
+	}
307 307
 
308
-    /**
309
-     * This function is linked into the activation
310
-     * hook to reset flush the urls to ensure Sensei post types show up.
311
-     *
312
-     * @since 1.9.0
313
-     *
314
-     * @param $plugin
315
-     */
316
-    public static function activation_flush_rules( $plugin ){
317
-
318
-        if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
319
-
320
-            flush_rewrite_rules(true);
321
-
322
-        }
323
-
324
-    }
325
-
326
-    /**
327
-     * Global Sensei Instance
328
-     *
329
-     * Ensure that only one instance of the main Sensei class can be loaded.
330
-     *
331
-     * @since 1.8.0
332
-     * @static
333
-     * @see WC()
334
-     * @return WooThemes_Sensei Instance.
335
-     */
336
-    public static function instance() {
337
-
338
-        if ( is_null( self::$_instance ) ) {
339
-
340
-            //Sensei requires a reference to the main Sensei plugin file
341
-            $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
342
-
343
-            self::$_instance = new self( $sensei_main_plugin_file  );
344
-
345
-        }
346
-
347
-        return self::$_instance;
348
-
349
-    } // end instance()
350
-
351
-    /**
352
-     * Cloning is forbidden.
353
-     * @since 1.8.0
354
-     */
355
-    public function __clone() {
356
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '2.1' );
357
-    }
358
-
359
-    /**
360
-     * Unserializing instances of this class is forbidden.
361
-     * @since 1.8.0
362
-     */
363
-    public function __wakeup() {
364
-        _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '2.1' );
365
-    }
366
-
367
-    /**
368
-     * Run Sensei updates.
369
-     * @access  public
370
-     * @since   1.1.0
371
-     * @return  void
372
-     */
373
-    public function run_updates() {
374
-        // Run updates if administrator
375
-        if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
376
-
377
-            $this->updates->update();
378
-
379
-        } // End If Statement
380
-    } // End run_updates()
381
-
382
-    /**
383
-     * Setup required WooCommerce settings.
384
-     * @access  public
385
-     * @since   1.1.0
386
-     * @return  void
387
-     */
388
-    public function set_woocommerce_functionality() {
389
-        // Disable guest checkout if a course is in the cart as we need a valid user to store data for
390
-        add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
391
-
392
-        // Mark orders with virtual products as complete rather then stay processing
393
-        add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
394
-
395
-    } // End set_woocommerce_functionality()
396
-
397
-    /**
398
-     * Disable guest checkout if a course product is in the cart
399
-     * @param  boolean $guest_checkout Current guest checkout setting
400
-     * @return boolean                 Modified guest checkout setting
401
-     */
402
-    public function disable_guest_checkout( $guest_checkout ) {
403
-        global $woocommerce;
404
-
405
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
406
-
407
-            if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
408
-                foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
409
-                    if( isset( $product['product_id'] ) ) {
410
-                        $args = array(
411
-                            'posts_per_page' => -1,
412
-                            'post_type' => 'course',
413
-                            'meta_query' => array(
414
-                                array(
415
-                                    'key' => '_course_woocommerce_product',
416
-                                    'value' => $product['product_id']
417
-                                )
418
-                            )
419
-                        );
420
-                        $posts = get_posts( $args );
421
-                        if( $posts && count( $posts ) > 0 ) {
422
-                            foreach( $posts as $course ) {
423
-                                $guest_checkout = '';
424
-                                break;
425
-                            }
426
-                        }
427
-                    }
428
-                }
429
-            }
430
-        }
431
-
432
-        return $guest_checkout;
433
-    }
434
-
435
-    /**
436
-     * Change order status with virtual products to completed
437
-     * @since  1.1.0
438
-     * @param string $order_status
439
-     * @param int $order_id
440
-     * @return string
441
-     **/
442
-    public function virtual_order_payment_complete( $order_status, $order_id ) {
443
-        $order = new WC_Order( $order_id );
444
-        if ( ! isset ( $order ) ) return;
445
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
446
-            $virtual_order = true;
447
-
448
-            if ( count( $order->get_items() ) > 0 ) {
449
-                foreach( $order->get_items() as $item ) {
450
-                    if ( $item['product_id'] > 0 ) {
451
-                        $_product = $order->get_product_from_item( $item );
452
-                        if ( ! $_product->is_virtual() ) {
453
-                            $virtual_order = false;
454
-                            break;
455
-                        } // End If Statement
456
-                    } // End If Statement
457
-                } // End For Loop
458
-            } // End If Statement
459
-
460
-            // virtual order, mark as completed
461
-            if ( $virtual_order ) {
462
-                return 'completed';
463
-            } // End If Statement
464
-        } // End If Statement
465
-        return $order_status;
466
-    }
467
-
468
-    /**
469
-     * Register the widgets.
470
-     * @access public
471
-     * @since  1.0.0
472
-     * @return void
473
-     */
474
-    public function register_widgets () {
475
-        // Widget List (key => value is filename => widget class).
476
-        $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
477
-                'lesson-component' 	=> 'Lesson_Component',
478
-                'course-categories' => 'Course_Categories',
479
-                'category-courses' 	=> 'Category_Courses' )
480
-        );
481
-        foreach ( $widget_list as $key => $value ) {
482
-            if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) {
483
-                require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' );
484
-                register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
485
-            }
486
-        } // End For Loop
487
-
488
-        do_action( 'sensei_register_widgets' );
489
-    } // End register_widgets()
490
-
491
-    /**
492
-     * Load the plugin's localisation file.
493
-     * @access public
494
-     * @since  1.0.0
495
-     * @return void
496
-     */
497
-    public function load_localisation () {
498
-        load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
499
-    } // End load_localisation()
500
-
501
-    /**
502
-     * Load the plugin textdomain from the main WordPress "languages" folder.
503
-     * @access  public
504
-     * @since   1.0.0
505
-     * @return  void
506
-     */
507
-    public function load_plugin_textdomain () {
508
-        $domain = 'woothemes-sensei';
509
-        // The "plugin_locale" filter is also used in load_plugin_textdomain()
510
-        $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
511
-        load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
512
-        load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
513
-    } // End load_plugin_textdomain()
514
-
515
-    /**
516
-     * Run on activation.
517
-     * @access public
518
-     * @since  1.0.0
519
-     * @return void
520
-     */
521
-    public function activation () {
522
-        $this->register_plugin_version();
523
-    } // End activation()
524
-
525
-
526
-    /**
527
-     * Register activation hooks.
528
-     * @access public
529
-     * @since  1.0.0
530
-     * @return void
531
-     */
532
-    public function install () {
533
-        register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
534
-        register_activation_hook( $this->file, 'flush_rewrite_rules' );
535
-    } // End install()
536
-
537
-
538
-    /**
539
-     * Run on activation of the plugin.
540
-     * @access public
541
-     * @since  1.0.0
542
-     * @return void
543
-     */
544
-    public function activate_sensei () {
545
-        update_option( 'skip_install_sensei_pages', 0 );
546
-        update_option( 'sensei_installed', 1 );
547
-    } // End activate_sensei()
548
-
549
-    /**
550
-     * Register the plugin's version.
551
-     * @access public
552
-     * @since  1.0.0
553
-     * @return void
554
-     */
555
-    private function register_plugin_version () {
556
-        if ( $this->version != '' ) {
557
-
558
-            // Check previous version to see if forced updates must run
559
-            // $old_version = get_option( 'woothemes-sensei-version', false );
560
-            // if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
561
-            // 	update_option( 'woothemes-sensei-force-updates', $this->version );
562
-            // } else {
563
-            // 	delete_option( 'woothemes-sensei-force-updates' );
564
-            // }
565
-
566
-            update_option( 'woothemes-sensei-version', $this->version );
567
-        }
568
-    } // End register_plugin_version()
569
-
570
-    /**
571
-     * Ensure that "post-thumbnails" support is available for those themes that don't register it.
572
-     * @access  public
573
-     * @since   1.0.1
574
-     * @return  void
575
-     */
576
-    public function ensure_post_thumbnails_support () {
577
-        if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
578
-    } // End ensure_post_thumbnails_support()
579
-
580
-
581
-    /**
582
-     * template_loader function.
583
-     *
584
-     * @access public
585
-     * @param mixed $template
586
-     * @return void
587
-     * @deprecated
588
-     */
589
-    public function template_loader ( $template = '' ) {
590
-
591
-        _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
592
-        return Sensei_Templates::template_loader( $template );
593
-
594
-    } // End template_loader()
595
-
596
-    /**
597
-     * Determine the relative path to the plugin's directory.
598
-     * @access public
599
-     * @since  1.0.0
600
-     * @return string $sensei_plugin_path
601
-     */
602
-    public function plugin_path () {
603
-
604
-        if ( $this->plugin_path ) {
605
-
606
-            $sensei_plugin_path =  $this->plugin_path;
607
-
608
-        }else{
609
-
610
-            $sensei_plugin_path = plugin_dir_path( __FILE__ );
611
-
612
-        }
613
-
614
-        return $sensei_plugin_path;
615
-
616
-    } // End plugin_path()
617
-
618
-
619
-    /**
620
-     * Retrieve the ID of a specified page setting.
621
-     * @access public
622
-     * @since  1.0.0
623
-     * @param  string $page
624
-     * @return int
625
-     */
626
-    public function get_page_id ( $page ) {
627
-        $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
628
-        return ( $page ) ? $page : -1;
629
-    } // End get_page_id()
630
-
631
-
632
-    /**
633
-     * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
634
-     * @access public
635
-     * @since  1.0.0
636
-     * @param  int 			$course_id  (default: 0)
637
-     * @param  array/Object $order_user (default: array()) Specific user's data.
638
-     * @return void
639
-     */
640
-    public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
641
-        global $current_user;
642
-
643
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return;
644
-
645
-        $data_update = false;
646
-
647
-        // Get the product ID
648
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
649
-
650
-        // Check if in the admin
651
-        if ( is_admin() ) {
652
-            $user_login = $order_user['user_login'];
653
-            $user_email = $order_user['user_email'];
654
-            $user_url = $order_user['user_url'];
655
-            $user_id = $order_user['ID'];
656
-        } else {
657
-            $user_login = $current_user->user_login;
658
-            $user_email = $current_user->user_email;
659
-            $user_url = $current_user->user_url;
660
-            $user_id = $current_user->ID;
661
-        } // End If Statement
662
-
663
-        // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
664
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
665
-        if( 0 < absint( $course_prerequisite_id ) ) {
666
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
667
-            if ( ! $prereq_course_complete ) {
668
-                // Remove all course user meta
669
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
670
-            }
671
-        }
672
-
673
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
674
-
675
-        if( ! $is_user_taking_course ) {
676
-
677
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
678
-
679
-                $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
680
-
681
-                $is_user_taking_course = false;
682
-                if ( true == $activity_logged ) {
683
-                    $is_user_taking_course = true;
684
-                } // End If Statement
685
-            } // End If Statement
686
-        }
687
-
688
-        return $is_user_taking_course;
689
-    } // End woocommerce_course_update()
690
-
691
-
692
-    /**
693
-     * check_user_permissions function.
694
-     *
695
-     * @access public
696
-     * @param string $page (default: '')
697
-     * @param array $data (default: array())
698
-     * @return bool
699
-     */
700
-    public function check_user_permissions ( $page = '', $data = array() ) {
701
-        // REFACTOR
702
-        global $current_user, $post;
703
-
704
-        // if use is not logged in
705
-        if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){
706
-            $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
707
-            $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
708
-            return;
709
-        }
710
-
711
-
712
-        // Get User Meta
713
-        get_currentuserinfo();
714
-
715
-        $user_allowed = false;
716
-
717
-        switch ( $page ) {
718
-            case 'course-single':
719
-                // check for prerequisite course or lesson,
720
-                $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
721
-                $update_course = $this->woocommerce_course_update( $post->ID );
722
-                // Count completed lessons
723
-                if ( 0 < absint( $course_prerequisite_id ) ) {
724
-
725
-                    $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
726
-
727
-                }
728
-                else {
729
-                    $prerequisite_complete = true;
730
-                } // End If Statement
731
-                // Handles restrictions
732
-                if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
733
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
734
-                    $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
735
-                    $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
736
-                } else {
737
-                    $user_allowed = true;
738
-                } // End If Statement
739
-                break;
740
-            case 'lesson-single':
741
-                // Check for WC purchase
742
-                $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
743
-
744
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
745
-                $is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
746
-                if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
747
-                    $user_allowed = true;
748
-                } elseif( $this->access_settings() && false == $is_preview ) {
749
-
750
-                    $user_allowed = true;
751
-                } else {
752
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
753
-                    $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
754
-                    $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
755
-                    if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
756
-                        if ( $is_preview ) {
757
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
758
-                        } else {
759
-                            $this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
760
-                        }
761
-                    } else {
762
-                        if ( $is_preview ) {
763
-                            $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
764
-                        } else {
765
-                            /** This filter is documented in class-woothemes-sensei-frontend.php */
766
-                            $this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
767
-                        }
768
-                    } // End If Statement
769
-                } // End If Statement
770
-                break;
771
-            case 'quiz-single':
772
-                $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
773
-                $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
774
-
775
-                $update_course = $this->woocommerce_course_update( $lesson_course_id );
776
-                if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
777
-
778
-                    // Check for prerequisite lesson for this quiz
779
-                    $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
780
-                    $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
781
-
782
-                    // Handle restrictions
783
-                    if( sensei_all_access() ) {
784
-                        $user_allowed = true;
785
-                    } else {
786
-                        if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
787
-                            $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
788
-                            $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
789
-                            $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
790
-                        } else {
791
-                            $user_allowed = true;
792
-                        } // End If Statement
793
-                    } // End If Statement
794
-                } elseif( $this->access_settings() ) {
795
-                    // Check if the user has started the course
796
-
797
-                    if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
798
-
799
-                        $user_allowed = false;
800
-                        $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
801
-                        $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
802
-                        $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
803
-                        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
804
-                            $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
805
-                        } else {
806
-                            $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
807
-                        } // End If Statement
808
-                    } else {
809
-                        $user_allowed = true;
810
-                    } // End If Statement
811
-                } else {
812
-                    $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
813
-                    $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
814
-                    $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
815
-                } // End If Statement
816
-                break;
817
-            default:
818
-                $user_allowed = true;
819
-                break;
820
-
821
-        } // End Switch Statement
822
-
823
-        /**
824
-         * filter the permissions message shown on sensei post types.
825
-         *
826
-         * @since 1.8.7
827
-         *
828
-         * @param array $permissions_message{
829
-         *
830
-         *   @type string $title
831
-         *   @type string $message
832
-         *
833
-         * }
834
-         * @param string $post_id
835
-         */
836
-        $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
837
-
838
-
839
-        if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
840
-            $user_allowed = true;
841
-        }
842
-
843
-        return apply_filters( 'sensei_access_permissions', $user_allowed );
844
-    } // End get_placeholder_image()
845
-
846
-
847
-    /**
848
-     * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
849
-     * @since  1.0.0
850
-     * @access public
851
-     * @return void
852
-     */
853
-    public function access_settings () {
854
-
855
-        if( sensei_all_access() ) return true;
856
-
857
-        if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
858
-            if ( is_user_logged_in() ) {
859
-                return true;
860
-            } else {
861
-                return false;
862
-            } // End If Statement
863
-        } else {
864
-            return true;
865
-        } // End If Statement
866
-    } // End access_settings()
867
-
868
-    /**
869
-     * sensei_woocommerce_complete_order description
870
-     * @since   1.0.3
871
-     * @access  public
872
-     * @param   int $order_id WC order ID
873
-     * @return  void
874
-     */
875
-    public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
876
-        $order_user = array();
877
-        // Check for WooCommerce
878
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
879
-            // Get order object
880
-            $order = new WC_Order( $order_id );
881
-            $user = get_user_by( 'id', $order->user_id );
882
-            $order_user['ID'] = $user->ID;
883
-            $order_user['user_login'] = $user->user_login;
884
-            $order_user['user_email'] = $user->user_email;
885
-            $order_user['user_url'] = $user->user_url;
886
-            // Run through each product ordered
887
-            if ( 0 < sizeof( $order->get_items() ) ) {
888
-                foreach( $order->get_items() as $item ) {
889
-                    $product_type = '';
890
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
891
-                        $item_id = $item['variation_id'];
892
-                        $product_type = 'variation';
893
-                    } else {
894
-                        $item_id = $item['product_id'];
895
-                    } // End If Statement
896
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
897
-                    // Get courses that use the WC product
898
-                    $courses = $this->post_types->course->get_product_courses( $_product->id );
899
-                    // Loop and update those courses
900
-                    foreach ( $courses as $course_item ) {
901
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
902
-                    } // End For Loop
903
-                } // End For Loop
904
-            } // End If Statement
905
-            // Add meta to indicate that payment has been completed successfully
906
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
907
-        } // End If Statement
908
-    } // End sensei_woocommerce_complete_order()
909
-
910
-    /**
911
-     * Runs when an order is cancelled.
912
-     * @since   1.2.0
913
-     * @access  public
914
-     * @param   integer $order_id order ID
915
-     * @return  void
916
-     */
917
-    public function sensei_woocommerce_cancel_order ( $order_id ) {
918
-
919
-        // Get order object
920
-        $order = new WC_Order( $order_id );
921
-
922
-        // Run through each product ordered
923
-        if ( 0 < sizeof( $order->get_items() ) ) {
924
-
925
-            // Get order user
926
-            $user_id = $order->__get( 'user_id' );
927
-
928
-            foreach( $order->get_items() as $item ) {
929
-
930
-                $product_type = '';
931
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
932
-                    $item_id = $item['variation_id'];
933
-                    $product_type = 'variation';
934
-                } else {
935
-                    $item_id = $item['product_id'];
936
-                } // End If Statement
937
-                $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
938
-
939
-                // Get courses that use the WC product
940
-                $courses = array();
941
-                $courses = $this->post_types->course->get_product_courses( $item_id );
942
-
943
-                // Loop and update those courses
944
-                foreach ($courses as $course_item){
945
-                    // Check and Remove course from courses user meta
946
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
947
-                } // End For Loop
948
-            } // End For Loop
949
-        } // End If Statement
950
-    } // End sensei_woocommerce_cancel_order()
951
-
952
-    /**
953
-     * Runs when an subscription is cancelled or expires.
954
-     * @since   1.3.3
955
-     * @access  public
956
-     * @param   integer $user_id User ID
957
-     * @param   integer $subscription_key Subscription Unique Key
958
-     * @return  void
959
-     */
960
-    public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
961
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
962
-        self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
963
-    }
964
-
965
-    /**
966
-     * Runs when an subscription is re-activated after suspension.
967
-     * @since   1.3.3
968
-     * @access  public
969
-     * @param   integer $user_id User ID
970
-     * @param   integer $subscription_key Subscription Unique Key
971
-     * @return  void
972
-     */
973
-    public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
974
-        $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
975
-        $order = new WC_Order( $subscription['order_id'] );
976
-        $user = get_user_by( 'id', $order->user_id );
977
-        $order_user = array();
978
-        $order_user['ID'] = $user->ID;
979
-        $order_user['user_login'] = $user->user_login;
980
-        $order_user['user_email'] = $user->user_email;
981
-        $order_user['user_url'] = $user->user_url;
982
-        $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
983
-        foreach ( $courses as $course_item ){
984
-            $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
985
-        } // End For Loop
986
-    } // End sensei_woocommerce_reactivate_subscription
987
-
988
-    /**
989
-     * Returns the WooCommerce Product Object
990
-     *
991
-     * The code caters for pre and post WooCommerce 2.2 installations.
992
-     *
993
-     * @since   1.1.1
994
-     * @access  public
995
-     * @param   integer $wc_product_id Product ID or Variation ID
996
-     * @param   string  $product_type  '' or 'variation'
997
-     * @return   WC_Product $wc_product_object
998
-     */
999
-    public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1000
-
1001
-        $wc_product_object = false;
1002
-        if ( 0 < intval( $wc_product_id ) ) {
1003
-
1004
-            // Get the product
1005
-            if ( function_exists( 'wc_get_product' ) ) {
1006
-
1007
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1008
-
1009
-            } elseif ( function_exists( 'get_product' ) ) {
1010
-
1011
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1012
-
1013
-            } else {
1014
-
1015
-                // Pre WC 2.0
1016
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1017
-
1018
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1019
-
1020
-                } else {
1021
-
1022
-                    $wc_product_object = new WC_Product( $wc_product_id );
1023
-
1024
-                } // End If Statement
1025
-
1026
-            } // End If Statement
1027
-
1028
-        } // End If Statement
1029
-
1030
-        return $wc_product_object;
1031
-
1032
-    } // End sensei_get_woocommerce_product_object()
1033
-
1034
-    /**
1035
-     * load_class loads in class files
1036
-     * @since   1.2.0
1037
-     * @access  public
1038
-     * @return  void
1039
-     */
1040
-    public function load_class ( $class_name = '' ) {
1041
-        if ( '' != $class_name && '' != $this->token ) {
1042
-            require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1043
-        } // End If Statement
1044
-    } // End load_class()
1045
-
1046
-    /**
1047
-     * sensei_activate_subscription runs when a subscription product is purchased
1048
-     * @since   1.2.0
1049
-     * @access  public
1050
-     * @param   integer $order_id order ID
1051
-     * @return  void
1052
-     */
1053
-    public function sensei_activate_subscription(  $order_id = 0 ) {
1054
-        if ( 0 < intval( $order_id ) ) {
1055
-            $order = new WC_Order( $order_id );
1056
-            $user = get_user_by('id', $order->user_id);
1057
-            $order_user['ID'] = $user->ID;
1058
-            $order_user['user_login'] = $user->user_login;
1059
-            $order_user['user_email'] = $user->user_email;
1060
-            $order_user['user_url'] = $user->user_url;
1061
-            // Run through each product ordered
1062
-            if (sizeof($order->get_items())>0) {
1063
-                foreach($order->get_items() as $item) {
1064
-                    $product_type = '';
1065
-                    if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1066
-                        $item_id = $item['variation_id'];
1067
-                        $product_type = 'subscription_variation';
1068
-                    } else {
1069
-                        $item_id = $item['product_id'];
1070
-                    } // End If Statement
1071
-                    $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1072
-                    // Get courses that use the WC product
1073
-                    $courses = array();
1074
-                    if ( $product_type == 'subscription_variation' ) {
1075
-                        $courses = $this->post_types->course->get_product_courses( $item_id );
1076
-                    } // End If Statement
1077
-                    // Loop and update those courses
1078
-                    foreach ($courses as $course_item){
1079
-                        $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1080
-                    } // End For Loop
1081
-                } // End For Loop
1082
-            } // End If Statement
1083
-        } // End If Statement
1084
-    } // End sensei_activate_subscription()
1085
-
1086
-    /**
1087
-     * sensei_woocommerce_email_course_details adds detail to email
1088
-     * @since   1.4.5
1089
-     * @access  public
1090
-     * @param   WC_Order $order
1091
-     * @return  void
1092
-     */
1093
-    public function sensei_woocommerce_email_course_details( $order ) {
1094
-        global $woocommerce;
1095
-
1096
-        // exit early if not wc-completed or wc-processing
1097
-        if( 'wc-completed' != $order->post_status
1098
-            && 'wc-processing' != $order->post_status  ) {
1099
-            return;
1100
-        }
1101
-
1102
-        $order_items = $order->get_items();
1103
-        $order_id = $order->id;
1104
-
1105
-        //If object have items go through them all to find course
1106
-        if ( 0 < sizeof( $order_items ) ) {
1107
-
1108
-        echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1109
-
1110
-        foreach ( $order_items as $item ) {
1111
-
1112
-                $product_type = '';
1113
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1114
-                    // If item has variation_id then its from variation
1115
-                    $item_id = $item['variation_id'];
1116
-                    $product_type = 'variation';
1117
-                } else {
1118
-                    // If not its real product set its id to item_id
1119
-                    $item_id = $item['product_id'];
1120
-                } // End If Statement
1121
-
1122
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1123
-
1124
-                if( $user_id ) {
1125
-
1126
-                    // Get all courses for product
1127
-                    $args = array(
1128
-                        'posts_per_page' => -1,
1129
-                        'post_type' => 'course',
1130
-                        'meta_query' => array(
1131
-                            array(
1132
-                                'key' => '_course_woocommerce_product',
1133
-                                'value' => $item_id
1134
-                            )
1135
-                        ),
1136
-                        'orderby' => 'menu_order date',
1137
-                        'order' => 'ASC',
1138
-                    );
1139
-                    $courses = get_posts( $args );
1140
-
1141
-                    if( $courses && count( $courses ) > 0 ) {
1142
-
1143
-                        foreach( $courses as $course ) {
1144
-
1145
-                            $title = $course->post_title;
1146
-                            $permalink = get_permalink( $course->ID );
1147
-
1148
-                            echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1149
-                        }
1150
-                    }
1151
-                }
1152
-            }
1153
-        }
1154
-    }
1155
-
1156
-    /**
1157
-     * Filtering wp_count_comments to ensure that Sensei comments are ignored
1158
-     * @since   1.4.0
1159
-     * @access  public
1160
-     * @param  array   $comments
1161
-     * @param  integer $post_id
1162
-     * @return array
1163
-     */
1164
-    public function sensei_count_comments( $comments, $post_id ) {
1165
-        global $wpdb;
1166
-
1167
-        $post_id = (int) $post_id;
1168
-
1169
-        $count = wp_cache_get("comments-{$post_id}", 'counts');
1170
-
1171
-        if ( false !== $count ) {
1172
-            return $count;
1173
-        }
1174
-
1175
-        $statuses = array( '' ); // Default to the WP normal comments
1176
-        $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1177
-        foreach ( (array) $stati AS $status ) {
1178
-            if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1179
-                $statuses[] = $status['comment_type'];
1180
-            }
1181
-        }
1182
-        $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1183
-
1184
-        if ( $post_id > 0 )
1185
-            $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1186
-
1187
-        $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1188
-
1189
-        $total = 0;
1190
-        $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1191
-        foreach ( (array) $count as $row ) {
1192
-            // Don't count post-trashed toward totals
1193
-            if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1194
-                $total += $row['num_comments'];
1195
-            if ( isset( $approved[$row['comment_approved']] ) )
1196
-                $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1197
-        }
1198
-
1199
-        $stats['total_comments'] = $total;
1200
-        foreach ( $approved as $key ) {
1201
-            if ( empty($stats[$key]) )
1202
-                $stats[$key] = 0;
1203
-        }
1204
-
1205
-        $stats = (object) $stats;
1206
-        wp_cache_set("comments-{$post_id}", $stats, 'counts');
1207
-
1208
-        return $stats;
1209
-    }
1210
-
1211
-    /**
1212
-     * Init images.
1213
-     *
1214
-     * @since 1.4.5
1215
-     * @access public
1216
-     * @return void
1217
-     */
1218
-    public function init_image_sizes() {
1219
-        $course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1220
-        $course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1221
-        $lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1222
-        $lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1223
-
1224
-        add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1225
-        add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1226
-        add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1227
-        add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1228
-    }
1229
-
1230
-    /**
1231
-     * Get an image size.
1232
-     *
1233
-     * Variable is filtered by sensei_get_image_size_{image_size}
1234
-     *
1235
-     * @since 1.4.5
1236
-     * @access public
1237
-     * @param mixed $image_size
1238
-     * @return string
1239
-     */
1240
-    public function get_image_size( $image_size ) {
1241
-
1242
-        // Only return sizes we define in settings
1243
-        if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1244
-            return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1245
-
1246
-        if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1247
-            $this->settings->settings[ $image_size . '_width' ] = false;
1248
-        }
1249
-        if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1250
-            $this->settings->settings[ $image_size . '_height' ] = false;
1251
-        }
1252
-        if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1253
-            $this->settings->settings[ $image_size . '_hard_crop' ] = false;
1254
-        }
1255
-
1256
-        $size = array_filter( array(
1257
-            'width' => $this->settings->settings[ $image_size . '_width' ],
1258
-            'height' => $this->settings->settings[ $image_size . '_height' ],
1259
-            'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1260
-        ) );
1261
-
1262
-        $size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1263
-        $size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1264
-        $size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1265
-
1266
-        return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1267
-    }
1268
-
1269
-    public function body_class( $classes ) {
1270
-        if( is_sensei() ) {
1271
-            $classes[] = 'sensei';
1272
-        }
1273
-        return $classes;
1274
-    }
1275
-
1276
-    /**
1277
-     * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1278
-     *
1279
-     * @return null
1280
-     * @since 1.7.0
1281
-     */
1282
-    public function jetpack_latex_support() {
1283
-        if ( function_exists( 'latex_markup') ) {
1284
-            add_filter( 'sensei_question_title', 'latex_markup' );
1285
-            add_filter( 'sensei_answer_text', 'latex_markup' );
1286
-        }
1287
-    }
1288
-
1289
-    /**
1290
-     * Load the module functionality.
1291
-     *
1292
-     * This function is hooked into plugins_loaded to avoid conflicts with
1293
-     * the retired modules extension.
1294
-     *
1295
-     * @since 1.8.0
1296
-     */
1297
-    public function load_modules_class(){
1298
-        global $sensei_modules;
1299
-
1300
-        if( !class_exists( 'Sensei_Modules' )
1301
-            &&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1302
-
1303
-            //Load the modules class
1304
-            require_once( 'class-sensei-modules.php');
1305
-            Sensei()->modules = new Sensei_Core_Modules( $this->file );
1306
-
1307
-        }else{
1308
-            // fallback for people still using the modules extension.
1309
-            global $sensei_modules;
1310
-            Sensei()->modules = $sensei_modules;
1311
-            add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1312
-        }
1313
-    }
1314
-
1315
-    /**
1316
-     * Tell the user to that the modules extension is no longer needed.
1317
-     *
1318
-     * @since 1.8.0
1319
-     */
1320
-    public function disable_sensei_modules_extension(){ ?>
308
+	/**
309
+	 * This function is linked into the activation
310
+	 * hook to reset flush the urls to ensure Sensei post types show up.
311
+	 *
312
+	 * @since 1.9.0
313
+	 *
314
+	 * @param $plugin
315
+	 */
316
+	public static function activation_flush_rules( $plugin ){
317
+
318
+		if( strpos( $plugin, '/woothemes-sensei.php' ) > 0  ){
319
+
320
+			flush_rewrite_rules(true);
321
+
322
+		}
323
+
324
+	}
325
+
326
+	/**
327
+	 * Global Sensei Instance
328
+	 *
329
+	 * Ensure that only one instance of the main Sensei class can be loaded.
330
+	 *
331
+	 * @since 1.8.0
332
+	 * @static
333
+	 * @see WC()
334
+	 * @return WooThemes_Sensei Instance.
335
+	 */
336
+	public static function instance() {
337
+
338
+		if ( is_null( self::$_instance ) ) {
339
+
340
+			//Sensei requires a reference to the main Sensei plugin file
341
+			$sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php';
342
+
343
+			self::$_instance = new self( $sensei_main_plugin_file  );
344
+
345
+		}
346
+
347
+		return self::$_instance;
348
+
349
+	} // end instance()
350
+
351
+	/**
352
+	 * Cloning is forbidden.
353
+	 * @since 1.8.0
354
+	 */
355
+	public function __clone() {
356
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '2.1' );
357
+	}
358
+
359
+	/**
360
+	 * Unserializing instances of this class is forbidden.
361
+	 * @since 1.8.0
362
+	 */
363
+	public function __wakeup() {
364
+		_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'woothemes-sensei' ), '2.1' );
365
+	}
366
+
367
+	/**
368
+	 * Run Sensei updates.
369
+	 * @access  public
370
+	 * @since   1.1.0
371
+	 * @return  void
372
+	 */
373
+	public function run_updates() {
374
+		// Run updates if administrator
375
+		if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) {
376
+
377
+			$this->updates->update();
378
+
379
+		} // End If Statement
380
+	} // End run_updates()
381
+
382
+	/**
383
+	 * Setup required WooCommerce settings.
384
+	 * @access  public
385
+	 * @since   1.1.0
386
+	 * @return  void
387
+	 */
388
+	public function set_woocommerce_functionality() {
389
+		// Disable guest checkout if a course is in the cart as we need a valid user to store data for
390
+		add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) );
391
+
392
+		// Mark orders with virtual products as complete rather then stay processing
393
+		add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 );
394
+
395
+	} // End set_woocommerce_functionality()
396
+
397
+	/**
398
+	 * Disable guest checkout if a course product is in the cart
399
+	 * @param  boolean $guest_checkout Current guest checkout setting
400
+	 * @return boolean                 Modified guest checkout setting
401
+	 */
402
+	public function disable_guest_checkout( $guest_checkout ) {
403
+		global $woocommerce;
404
+
405
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
406
+
407
+			if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) {
408
+				foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) {
409
+					if( isset( $product['product_id'] ) ) {
410
+						$args = array(
411
+							'posts_per_page' => -1,
412
+							'post_type' => 'course',
413
+							'meta_query' => array(
414
+								array(
415
+									'key' => '_course_woocommerce_product',
416
+									'value' => $product['product_id']
417
+								)
418
+							)
419
+						);
420
+						$posts = get_posts( $args );
421
+						if( $posts && count( $posts ) > 0 ) {
422
+							foreach( $posts as $course ) {
423
+								$guest_checkout = '';
424
+								break;
425
+							}
426
+						}
427
+					}
428
+				}
429
+			}
430
+		}
431
+
432
+		return $guest_checkout;
433
+	}
434
+
435
+	/**
436
+	 * Change order status with virtual products to completed
437
+	 * @since  1.1.0
438
+	 * @param string $order_status
439
+	 * @param int $order_id
440
+	 * @return string
441
+	 **/
442
+	public function virtual_order_payment_complete( $order_status, $order_id ) {
443
+		$order = new WC_Order( $order_id );
444
+		if ( ! isset ( $order ) ) return;
445
+		if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
446
+			$virtual_order = true;
447
+
448
+			if ( count( $order->get_items() ) > 0 ) {
449
+				foreach( $order->get_items() as $item ) {
450
+					if ( $item['product_id'] > 0 ) {
451
+						$_product = $order->get_product_from_item( $item );
452
+						if ( ! $_product->is_virtual() ) {
453
+							$virtual_order = false;
454
+							break;
455
+						} // End If Statement
456
+					} // End If Statement
457
+				} // End For Loop
458
+			} // End If Statement
459
+
460
+			// virtual order, mark as completed
461
+			if ( $virtual_order ) {
462
+				return 'completed';
463
+			} // End If Statement
464
+		} // End If Statement
465
+		return $order_status;
466
+	}
467
+
468
+	/**
469
+	 * Register the widgets.
470
+	 * @access public
471
+	 * @since  1.0.0
472
+	 * @return void
473
+	 */
474
+	public function register_widgets () {
475
+		// Widget List (key => value is filename => widget class).
476
+		$widget_list = apply_filters( 'sensei_registered_widgets_list', array( 	'course-component' 	=> 'Course_Component',
477
+				'lesson-component' 	=> 'Lesson_Component',
478
+				'course-categories' => 'Course_Categories',
479
+				'category-courses' 	=> 'Category_Courses' )
480
+		);
481
+		foreach ( $widget_list as $key => $value ) {
482
+			if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) {
483
+				require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' );
484
+				register_widget( 'WooThemes_Sensei_' . $value . '_Widget' );
485
+			}
486
+		} // End For Loop
487
+
488
+		do_action( 'sensei_register_widgets' );
489
+	} // End register_widgets()
490
+
491
+	/**
492
+	 * Load the plugin's localisation file.
493
+	 * @access public
494
+	 * @since  1.0.0
495
+	 * @return void
496
+	 */
497
+	public function load_localisation () {
498
+		load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' );
499
+	} // End load_localisation()
500
+
501
+	/**
502
+	 * Load the plugin textdomain from the main WordPress "languages" folder.
503
+	 * @access  public
504
+	 * @since   1.0.0
505
+	 * @return  void
506
+	 */
507
+	public function load_plugin_textdomain () {
508
+		$domain = 'woothemes-sensei';
509
+		// The "plugin_locale" filter is also used in load_plugin_textdomain()
510
+		$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
511
+		load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' );
512
+		load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' );
513
+	} // End load_plugin_textdomain()
514
+
515
+	/**
516
+	 * Run on activation.
517
+	 * @access public
518
+	 * @since  1.0.0
519
+	 * @return void
520
+	 */
521
+	public function activation () {
522
+		$this->register_plugin_version();
523
+	} // End activation()
524
+
525
+
526
+	/**
527
+	 * Register activation hooks.
528
+	 * @access public
529
+	 * @since  1.0.0
530
+	 * @return void
531
+	 */
532
+	public function install () {
533
+		register_activation_hook( $this->file, array( $this, 'activate_sensei' ) );
534
+		register_activation_hook( $this->file, 'flush_rewrite_rules' );
535
+	} // End install()
536
+
537
+
538
+	/**
539
+	 * Run on activation of the plugin.
540
+	 * @access public
541
+	 * @since  1.0.0
542
+	 * @return void
543
+	 */
544
+	public function activate_sensei () {
545
+		update_option( 'skip_install_sensei_pages', 0 );
546
+		update_option( 'sensei_installed', 1 );
547
+	} // End activate_sensei()
548
+
549
+	/**
550
+	 * Register the plugin's version.
551
+	 * @access public
552
+	 * @since  1.0.0
553
+	 * @return void
554
+	 */
555
+	private function register_plugin_version () {
556
+		if ( $this->version != '' ) {
557
+
558
+			// Check previous version to see if forced updates must run
559
+			// $old_version = get_option( 'woothemes-sensei-version', false );
560
+			// if( $old_version && version_compare( $old_version, '1.7.0', '<' )  ) {
561
+			// 	update_option( 'woothemes-sensei-force-updates', $this->version );
562
+			// } else {
563
+			// 	delete_option( 'woothemes-sensei-force-updates' );
564
+			// }
565
+
566
+			update_option( 'woothemes-sensei-version', $this->version );
567
+		}
568
+	} // End register_plugin_version()
569
+
570
+	/**
571
+	 * Ensure that "post-thumbnails" support is available for those themes that don't register it.
572
+	 * @access  public
573
+	 * @since   1.0.1
574
+	 * @return  void
575
+	 */
576
+	public function ensure_post_thumbnails_support () {
577
+		if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); }
578
+	} // End ensure_post_thumbnails_support()
579
+
580
+
581
+	/**
582
+	 * template_loader function.
583
+	 *
584
+	 * @access public
585
+	 * @param mixed $template
586
+	 * @return void
587
+	 * @deprecated
588
+	 */
589
+	public function template_loader ( $template = '' ) {
590
+
591
+		_deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' );
592
+		return Sensei_Templates::template_loader( $template );
593
+
594
+	} // End template_loader()
595
+
596
+	/**
597
+	 * Determine the relative path to the plugin's directory.
598
+	 * @access public
599
+	 * @since  1.0.0
600
+	 * @return string $sensei_plugin_path
601
+	 */
602
+	public function plugin_path () {
603
+
604
+		if ( $this->plugin_path ) {
605
+
606
+			$sensei_plugin_path =  $this->plugin_path;
607
+
608
+		}else{
609
+
610
+			$sensei_plugin_path = plugin_dir_path( __FILE__ );
611
+
612
+		}
613
+
614
+		return $sensei_plugin_path;
615
+
616
+	} // End plugin_path()
617
+
618
+
619
+	/**
620
+	 * Retrieve the ID of a specified page setting.
621
+	 * @access public
622
+	 * @since  1.0.0
623
+	 * @param  string $page
624
+	 * @return int
625
+	 */
626
+	public function get_page_id ( $page ) {
627
+		$page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) );
628
+		return ( $page ) ? $page : -1;
629
+	} // End get_page_id()
630
+
631
+
632
+	/**
633
+	 * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course.
634
+	 * @access public
635
+	 * @since  1.0.0
636
+	 * @param  int 			$course_id  (default: 0)
637
+	 * @param  array/Object $order_user (default: array()) Specific user's data.
638
+	 * @return void
639
+	 */
640
+	public function woocommerce_course_update ( $course_id = 0, $order_user = array()  ) {
641
+		global $current_user;
642
+
643
+		if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return;
644
+
645
+		$data_update = false;
646
+
647
+		// Get the product ID
648
+		$wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
649
+
650
+		// Check if in the admin
651
+		if ( is_admin() ) {
652
+			$user_login = $order_user['user_login'];
653
+			$user_email = $order_user['user_email'];
654
+			$user_url = $order_user['user_url'];
655
+			$user_id = $order_user['ID'];
656
+		} else {
657
+			$user_login = $current_user->user_login;
658
+			$user_email = $current_user->user_email;
659
+			$user_url = $current_user->user_url;
660
+			$user_id = $current_user->ID;
661
+		} // End If Statement
662
+
663
+		// This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
664
+		$course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
665
+		if( 0 < absint( $course_prerequisite_id ) ) {
666
+			$prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
667
+			if ( ! $prereq_course_complete ) {
668
+				// Remove all course user meta
669
+				return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
670
+			}
671
+		}
672
+
673
+		$is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
674
+
675
+		if( ! $is_user_taking_course ) {
676
+
677
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) {
678
+
679
+				$activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) );
680
+
681
+				$is_user_taking_course = false;
682
+				if ( true == $activity_logged ) {
683
+					$is_user_taking_course = true;
684
+				} // End If Statement
685
+			} // End If Statement
686
+		}
687
+
688
+		return $is_user_taking_course;
689
+	} // End woocommerce_course_update()
690
+
691
+
692
+	/**
693
+	 * check_user_permissions function.
694
+	 *
695
+	 * @access public
696
+	 * @param string $page (default: '')
697
+	 * @param array $data (default: array())
698
+	 * @return bool
699
+	 */
700
+	public function check_user_permissions ( $page = '', $data = array() ) {
701
+		// REFACTOR
702
+		global $current_user, $post;
703
+
704
+		// if use is not logged in
705
+		if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){
706
+			$this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' );
707
+			$this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() );
708
+			return;
709
+		}
710
+
711
+
712
+		// Get User Meta
713
+		get_currentuserinfo();
714
+
715
+		$user_allowed = false;
716
+
717
+		switch ( $page ) {
718
+			case 'course-single':
719
+				// check for prerequisite course or lesson,
720
+				$course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true);
721
+				$update_course = $this->woocommerce_course_update( $post->ID );
722
+				// Count completed lessons
723
+				if ( 0 < absint( $course_prerequisite_id ) ) {
724
+
725
+					$prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID );
726
+
727
+				}
728
+				else {
729
+					$prerequisite_complete = true;
730
+				} // End If Statement
731
+				// Handles restrictions
732
+				if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) {
733
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
734
+					$course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
735
+					$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link );
736
+				} else {
737
+					$user_allowed = true;
738
+				} // End If Statement
739
+				break;
740
+			case 'lesson-single':
741
+				// Check for WC purchase
742
+				$lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true );
743
+
744
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
745
+				$is_preview = Sensei_Utils::is_preview_lesson( $post->ID );
746
+				if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
747
+					$user_allowed = true;
748
+				} elseif( $this->access_settings() && false == $is_preview ) {
749
+
750
+					$user_allowed = true;
751
+				} else {
752
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
753
+					$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
754
+					$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
755
+					if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
756
+						if ( $is_preview ) {
757
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
758
+						} else {
759
+							$this->permissions_message['message'] =  sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link );
760
+						}
761
+					} else {
762
+						if ( $is_preview ) {
763
+							$this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link );
764
+						} else {
765
+							/** This filter is documented in class-woothemes-sensei-frontend.php */
766
+							$this->permissions_message['message'] =  sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
767
+						}
768
+					} // End If Statement
769
+				} // End If Statement
770
+				break;
771
+			case 'quiz-single':
772
+				$lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true );
773
+				$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true );
774
+
775
+				$update_course = $this->woocommerce_course_update( $lesson_course_id );
776
+				if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) {
777
+
778
+					// Check for prerequisite lesson for this quiz
779
+					$lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true);
780
+					$user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID);
781
+
782
+					// Handle restrictions
783
+					if( sensei_all_access() ) {
784
+						$user_allowed = true;
785
+					} else {
786
+						if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) {
787
+							$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
788
+							$lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>';
789
+							$this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link );
790
+						} else {
791
+							$user_allowed = true;
792
+						} // End If Statement
793
+					} // End If Statement
794
+				} elseif( $this->access_settings() ) {
795
+					// Check if the user has started the course
796
+
797
+					if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) {
798
+
799
+						$user_allowed = false;
800
+						$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
801
+						$course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
802
+						$wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true );
803
+						if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
804
+							$this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
805
+						} else {
806
+							$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link );
807
+						} // End If Statement
808
+					} else {
809
+						$user_allowed = true;
810
+					} // End If Statement
811
+				} else {
812
+					$this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' );
813
+					$course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>';
814
+					$this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link );
815
+				} // End If Statement
816
+				break;
817
+			default:
818
+				$user_allowed = true;
819
+				break;
820
+
821
+		} // End Switch Statement
822
+
823
+		/**
824
+		 * filter the permissions message shown on sensei post types.
825
+		 *
826
+		 * @since 1.8.7
827
+		 *
828
+		 * @param array $permissions_message{
829
+		 *
830
+		 *   @type string $title
831
+		 *   @type string $message
832
+		 *
833
+		 * }
834
+		 * @param string $post_id
835
+		 */
836
+		$this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID );
837
+
838
+
839
+		if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) {
840
+			$user_allowed = true;
841
+		}
842
+
843
+		return apply_filters( 'sensei_access_permissions', $user_allowed );
844
+	} // End get_placeholder_image()
845
+
846
+
847
+	/**
848
+	 * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check.
849
+	 * @since  1.0.0
850
+	 * @access public
851
+	 * @return void
852
+	 */
853
+	public function access_settings () {
854
+
855
+		if( sensei_all_access() ) return true;
856
+
857
+		if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) {
858
+			if ( is_user_logged_in() ) {
859
+				return true;
860
+			} else {
861
+				return false;
862
+			} // End If Statement
863
+		} else {
864
+			return true;
865
+		} // End If Statement
866
+	} // End access_settings()
867
+
868
+	/**
869
+	 * sensei_woocommerce_complete_order description
870
+	 * @since   1.0.3
871
+	 * @access  public
872
+	 * @param   int $order_id WC order ID
873
+	 * @return  void
874
+	 */
875
+	public function sensei_woocommerce_complete_order ( $order_id = 0 ) {
876
+		$order_user = array();
877
+		// Check for WooCommerce
878
+		if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
879
+			// Get order object
880
+			$order = new WC_Order( $order_id );
881
+			$user = get_user_by( 'id', $order->user_id );
882
+			$order_user['ID'] = $user->ID;
883
+			$order_user['user_login'] = $user->user_login;
884
+			$order_user['user_email'] = $user->user_email;
885
+			$order_user['user_url'] = $user->user_url;
886
+			// Run through each product ordered
887
+			if ( 0 < sizeof( $order->get_items() ) ) {
888
+				foreach( $order->get_items() as $item ) {
889
+					$product_type = '';
890
+					if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
891
+						$item_id = $item['variation_id'];
892
+						$product_type = 'variation';
893
+					} else {
894
+						$item_id = $item['product_id'];
895
+					} // End If Statement
896
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
897
+					// Get courses that use the WC product
898
+					$courses = $this->post_types->course->get_product_courses( $_product->id );
899
+					// Loop and update those courses
900
+					foreach ( $courses as $course_item ) {
901
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
902
+					} // End For Loop
903
+				} // End For Loop
904
+			} // End If Statement
905
+			// Add meta to indicate that payment has been completed successfully
906
+			update_post_meta( $order_id, 'sensei_payment_complete', '1' );
907
+		} // End If Statement
908
+	} // End sensei_woocommerce_complete_order()
909
+
910
+	/**
911
+	 * Runs when an order is cancelled.
912
+	 * @since   1.2.0
913
+	 * @access  public
914
+	 * @param   integer $order_id order ID
915
+	 * @return  void
916
+	 */
917
+	public function sensei_woocommerce_cancel_order ( $order_id ) {
918
+
919
+		// Get order object
920
+		$order = new WC_Order( $order_id );
921
+
922
+		// Run through each product ordered
923
+		if ( 0 < sizeof( $order->get_items() ) ) {
924
+
925
+			// Get order user
926
+			$user_id = $order->__get( 'user_id' );
927
+
928
+			foreach( $order->get_items() as $item ) {
929
+
930
+				$product_type = '';
931
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
932
+					$item_id = $item['variation_id'];
933
+					$product_type = 'variation';
934
+				} else {
935
+					$item_id = $item['product_id'];
936
+				} // End If Statement
937
+				$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
938
+
939
+				// Get courses that use the WC product
940
+				$courses = array();
941
+				$courses = $this->post_types->course->get_product_courses( $item_id );
942
+
943
+				// Loop and update those courses
944
+				foreach ($courses as $course_item){
945
+					// Check and Remove course from courses user meta
946
+					$dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
947
+				} // End For Loop
948
+			} // End For Loop
949
+		} // End If Statement
950
+	} // End sensei_woocommerce_cancel_order()
951
+
952
+	/**
953
+	 * Runs when an subscription is cancelled or expires.
954
+	 * @since   1.3.3
955
+	 * @access  public
956
+	 * @param   integer $user_id User ID
957
+	 * @param   integer $subscription_key Subscription Unique Key
958
+	 * @return  void
959
+	 */
960
+	public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) {
961
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
962
+		self::sensei_woocommerce_cancel_order( $subscription['order_id'] );
963
+	}
964
+
965
+	/**
966
+	 * Runs when an subscription is re-activated after suspension.
967
+	 * @since   1.3.3
968
+	 * @access  public
969
+	 * @param   integer $user_id User ID
970
+	 * @param   integer $subscription_key Subscription Unique Key
971
+	 * @return  void
972
+	 */
973
+	public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) {
974
+		$subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key );
975
+		$order = new WC_Order( $subscription['order_id'] );
976
+		$user = get_user_by( 'id', $order->user_id );
977
+		$order_user = array();
978
+		$order_user['ID'] = $user->ID;
979
+		$order_user['user_login'] = $user->user_login;
980
+		$order_user['user_email'] = $user->user_email;
981
+		$order_user['user_url'] = $user->user_url;
982
+		$courses = $this->post_types->course->get_product_courses( $subscription['product_id'] );
983
+		foreach ( $courses as $course_item ){
984
+			$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
985
+		} // End For Loop
986
+	} // End sensei_woocommerce_reactivate_subscription
987
+
988
+	/**
989
+	 * Returns the WooCommerce Product Object
990
+	 *
991
+	 * The code caters for pre and post WooCommerce 2.2 installations.
992
+	 *
993
+	 * @since   1.1.1
994
+	 * @access  public
995
+	 * @param   integer $wc_product_id Product ID or Variation ID
996
+	 * @param   string  $product_type  '' or 'variation'
997
+	 * @return   WC_Product $wc_product_object
998
+	 */
999
+	public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) {
1000
+
1001
+		$wc_product_object = false;
1002
+		if ( 0 < intval( $wc_product_id ) ) {
1003
+
1004
+			// Get the product
1005
+			if ( function_exists( 'wc_get_product' ) ) {
1006
+
1007
+				$wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1008
+
1009
+			} elseif ( function_exists( 'get_product' ) ) {
1010
+
1011
+				$wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1012
+
1013
+			} else {
1014
+
1015
+				// Pre WC 2.0
1016
+				if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1017
+
1018
+					$wc_product_object = new WC_Product_Variation( $wc_product_id );
1019
+
1020
+				} else {
1021
+
1022
+					$wc_product_object = new WC_Product( $wc_product_id );
1023
+
1024
+				} // End If Statement
1025
+
1026
+			} // End If Statement
1027
+
1028
+		} // End If Statement
1029
+
1030
+		return $wc_product_object;
1031
+
1032
+	} // End sensei_get_woocommerce_product_object()
1033
+
1034
+	/**
1035
+	 * load_class loads in class files
1036
+	 * @since   1.2.0
1037
+	 * @access  public
1038
+	 * @return  void
1039
+	 */
1040
+	public function load_class ( $class_name = '' ) {
1041
+		if ( '' != $class_name && '' != $this->token ) {
1042
+			require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' );
1043
+		} // End If Statement
1044
+	} // End load_class()
1045
+
1046
+	/**
1047
+	 * sensei_activate_subscription runs when a subscription product is purchased
1048
+	 * @since   1.2.0
1049
+	 * @access  public
1050
+	 * @param   integer $order_id order ID
1051
+	 * @return  void
1052
+	 */
1053
+	public function sensei_activate_subscription(  $order_id = 0 ) {
1054
+		if ( 0 < intval( $order_id ) ) {
1055
+			$order = new WC_Order( $order_id );
1056
+			$user = get_user_by('id', $order->user_id);
1057
+			$order_user['ID'] = $user->ID;
1058
+			$order_user['user_login'] = $user->user_login;
1059
+			$order_user['user_email'] = $user->user_email;
1060
+			$order_user['user_url'] = $user->user_url;
1061
+			// Run through each product ordered
1062
+			if (sizeof($order->get_items())>0) {
1063
+				foreach($order->get_items() as $item) {
1064
+					$product_type = '';
1065
+					if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1066
+						$item_id = $item['variation_id'];
1067
+						$product_type = 'subscription_variation';
1068
+					} else {
1069
+						$item_id = $item['product_id'];
1070
+					} // End If Statement
1071
+					$_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type );
1072
+					// Get courses that use the WC product
1073
+					$courses = array();
1074
+					if ( $product_type == 'subscription_variation' ) {
1075
+						$courses = $this->post_types->course->get_product_courses( $item_id );
1076
+					} // End If Statement
1077
+					// Loop and update those courses
1078
+					foreach ($courses as $course_item){
1079
+						$update_course = $this->woocommerce_course_update( $course_item->ID, $order_user );
1080
+					} // End For Loop
1081
+				} // End For Loop
1082
+			} // End If Statement
1083
+		} // End If Statement
1084
+	} // End sensei_activate_subscription()
1085
+
1086
+	/**
1087
+	 * sensei_woocommerce_email_course_details adds detail to email
1088
+	 * @since   1.4.5
1089
+	 * @access  public
1090
+	 * @param   WC_Order $order
1091
+	 * @return  void
1092
+	 */
1093
+	public function sensei_woocommerce_email_course_details( $order ) {
1094
+		global $woocommerce;
1095
+
1096
+		// exit early if not wc-completed or wc-processing
1097
+		if( 'wc-completed' != $order->post_status
1098
+			&& 'wc-processing' != $order->post_status  ) {
1099
+			return;
1100
+		}
1101
+
1102
+		$order_items = $order->get_items();
1103
+		$order_id = $order->id;
1104
+
1105
+		//If object have items go through them all to find course
1106
+		if ( 0 < sizeof( $order_items ) ) {
1107
+
1108
+		echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1109
+
1110
+		foreach ( $order_items as $item ) {
1111
+
1112
+				$product_type = '';
1113
+				if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1114
+					// If item has variation_id then its from variation
1115
+					$item_id = $item['variation_id'];
1116
+					$product_type = 'variation';
1117
+				} else {
1118
+					// If not its real product set its id to item_id
1119
+					$item_id = $item['product_id'];
1120
+				} // End If Statement
1121
+
1122
+				$user_id = get_post_meta( $order_id, '_customer_user', true );
1123
+
1124
+				if( $user_id ) {
1125
+
1126
+					// Get all courses for product
1127
+					$args = array(
1128
+						'posts_per_page' => -1,
1129
+						'post_type' => 'course',
1130
+						'meta_query' => array(
1131
+							array(
1132
+								'key' => '_course_woocommerce_product',
1133
+								'value' => $item_id
1134
+							)
1135
+						),
1136
+						'orderby' => 'menu_order date',
1137
+						'order' => 'ASC',
1138
+					);
1139
+					$courses = get_posts( $args );
1140
+
1141
+					if( $courses && count( $courses ) > 0 ) {
1142
+
1143
+						foreach( $courses as $course ) {
1144
+
1145
+							$title = $course->post_title;
1146
+							$permalink = get_permalink( $course->ID );
1147
+
1148
+							echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1149
+						}
1150
+					}
1151
+				}
1152
+			}
1153
+		}
1154
+	}
1155
+
1156
+	/**
1157
+	 * Filtering wp_count_comments to ensure that Sensei comments are ignored
1158
+	 * @since   1.4.0
1159
+	 * @access  public
1160
+	 * @param  array   $comments
1161
+	 * @param  integer $post_id
1162
+	 * @return array
1163
+	 */
1164
+	public function sensei_count_comments( $comments, $post_id ) {
1165
+		global $wpdb;
1166
+
1167
+		$post_id = (int) $post_id;
1168
+
1169
+		$count = wp_cache_get("comments-{$post_id}", 'counts');
1170
+
1171
+		if ( false !== $count ) {
1172
+			return $count;
1173
+		}
1174
+
1175
+		$statuses = array( '' ); // Default to the WP normal comments
1176
+		$stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A );
1177
+		foreach ( (array) $stati AS $status ) {
1178
+			if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) {
1179
+				$statuses[] = $status['comment_type'];
1180
+			}
1181
+		}
1182
+		$where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')";
1183
+
1184
+		if ( $post_id > 0 )
1185
+			$where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );
1186
+
1187
+		$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
1188
+
1189
+		$total = 0;
1190
+		$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
1191
+		foreach ( (array) $count as $row ) {
1192
+			// Don't count post-trashed toward totals
1193
+			if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
1194
+				$total += $row['num_comments'];
1195
+			if ( isset( $approved[$row['comment_approved']] ) )
1196
+				$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1197
+		}
1198
+
1199
+		$stats['total_comments'] = $total;
1200
+		foreach ( $approved as $key ) {
1201
+			if ( empty($stats[$key]) )
1202
+				$stats[$key] = 0;
1203
+		}
1204
+
1205
+		$stats = (object) $stats;
1206
+		wp_cache_set("comments-{$post_id}", $stats, 'counts');
1207
+
1208
+		return $stats;
1209
+	}
1210
+
1211
+	/**
1212
+	 * Init images.
1213
+	 *
1214
+	 * @since 1.4.5
1215
+	 * @access public
1216
+	 * @return void
1217
+	 */
1218
+	public function init_image_sizes() {
1219
+		$course_archive_thumbnail 	= $this->get_image_size( 'course_archive_image' );
1220
+		$course_single_thumbnail	= $this->get_image_size( 'course_single_image' );
1221
+		$lesson_archive_thumbnail 	= $this->get_image_size( 'lesson_archive_image' );
1222
+		$lesson_single_thumbnail	= $this->get_image_size( 'lesson_single_image' );
1223
+
1224
+		add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] );
1225
+		add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] );
1226
+		add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] );
1227
+		add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] );
1228
+	}
1229
+
1230
+	/**
1231
+	 * Get an image size.
1232
+	 *
1233
+	 * Variable is filtered by sensei_get_image_size_{image_size}
1234
+	 *
1235
+	 * @since 1.4.5
1236
+	 * @access public
1237
+	 * @param mixed $image_size
1238
+	 * @return string
1239
+	 */
1240
+	public function get_image_size( $image_size ) {
1241
+
1242
+		// Only return sizes we define in settings
1243
+		if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) )
1244
+			return apply_filters( 'sensei_get_image_size_' . $image_size, '' );
1245
+
1246
+		if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) {
1247
+			$this->settings->settings[ $image_size . '_width' ] = false;
1248
+		}
1249
+		if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) {
1250
+			$this->settings->settings[ $image_size . '_height' ] = false;
1251
+		}
1252
+		if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) {
1253
+			$this->settings->settings[ $image_size . '_hard_crop' ] = false;
1254
+		}
1255
+
1256
+		$size = array_filter( array(
1257
+			'width' => $this->settings->settings[ $image_size . '_width' ],
1258
+			'height' => $this->settings->settings[ $image_size . '_height' ],
1259
+			'crop' => $this->settings->settings[ $image_size . '_hard_crop' ]
1260
+		) );
1261
+
1262
+		$size['width'] 	= isset( $size['width'] ) ? $size['width'] : '100';
1263
+		$size['height'] = isset( $size['height'] ) ? $size['height'] : '100';
1264
+		$size['crop'] 	= isset( $size['crop'] ) ? $size['crop'] : 0;
1265
+
1266
+		return apply_filters( 'sensei_get_image_size_' . $image_size, $size );
1267
+	}
1268
+
1269
+	public function body_class( $classes ) {
1270
+		if( is_sensei() ) {
1271
+			$classes[] = 'sensei';
1272
+		}
1273
+		return $classes;
1274
+	}
1275
+
1276
+	/**
1277
+	 * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers
1278
+	 *
1279
+	 * @return null
1280
+	 * @since 1.7.0
1281
+	 */
1282
+	public function jetpack_latex_support() {
1283
+		if ( function_exists( 'latex_markup') ) {
1284
+			add_filter( 'sensei_question_title', 'latex_markup' );
1285
+			add_filter( 'sensei_answer_text', 'latex_markup' );
1286
+		}
1287
+	}
1288
+
1289
+	/**
1290
+	 * Load the module functionality.
1291
+	 *
1292
+	 * This function is hooked into plugins_loaded to avoid conflicts with
1293
+	 * the retired modules extension.
1294
+	 *
1295
+	 * @since 1.8.0
1296
+	 */
1297
+	public function load_modules_class(){
1298
+		global $sensei_modules;
1299
+
1300
+		if( !class_exists( 'Sensei_Modules' )
1301
+			&&  'Sensei_Modules' != get_class( $sensei_modules ) ) {
1302
+
1303
+			//Load the modules class
1304
+			require_once( 'class-sensei-modules.php');
1305
+			Sensei()->modules = new Sensei_Core_Modules( $this->file );
1306
+
1307
+		}else{
1308
+			// fallback for people still using the modules extension.
1309
+			global $sensei_modules;
1310
+			Sensei()->modules = $sensei_modules;
1311
+			add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 );
1312
+		}
1313
+	}
1314
+
1315
+	/**
1316
+	 * Tell the user to that the modules extension is no longer needed.
1317
+	 *
1318
+	 * @since 1.8.0
1319
+	 */
1320
+	public function disable_sensei_modules_extension(){ ?>
1321 1321
         <div class="notice updated fade">
1322 1322
             <p>
1323 1323
                 <?php
1324
-                $plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1325
-                $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1326
-                ?>
1324
+				$plugin_manage_url = admin_url().'plugins.php#sensei-modules';
1325
+				$plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> ';
1326
+				?>
1327 1327
                 <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension.
1328 1328
                 Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules).
1329 1329
             </p>
@@ -1331,46 +1331,46 @@  discard block
 block discarded – undo
1331 1331
 
1332 1332
     <?php }// end function
1333 1333
 
1334
-    /**
1335
-     * Sensei wide rewrite flush call.
1336
-     *
1337
-     * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1338
-     *
1339
-     * After the option is one the Rules will be flushed.
1340
-     *
1341
-     * @since 1.9.0
1342
-     */
1343
-    public function flush_rewrite_rules(){
1334
+	/**
1335
+	 * Sensei wide rewrite flush call.
1336
+	 *
1337
+	 * To use this simply update the option 'sensei_flush_rewrite_rules' to 1
1338
+	 *
1339
+	 * After the option is one the Rules will be flushed.
1340
+	 *
1341
+	 * @since 1.9.0
1342
+	 */
1343
+	public function flush_rewrite_rules(){
1344 1344
 
1345
-        // ensures that the rewrite rules are flushed on the second
1346
-        // attempt. This ensure that the settings for any other process
1347
-        // have been completed and saved to the database before we refresh the
1348
-        // rewrite rules.
1349
-        $option =  get_option('sensei_flush_rewrite_rules');
1350
-        if( '1' == $option ) {
1345
+		// ensures that the rewrite rules are flushed on the second
1346
+		// attempt. This ensure that the settings for any other process
1347
+		// have been completed and saved to the database before we refresh the
1348
+		// rewrite rules.
1349
+		$option =  get_option('sensei_flush_rewrite_rules');
1350
+		if( '1' == $option ) {
1351 1351
 
1352
-            update_option('sensei_flush_rewrite_rules', '2');
1352
+			update_option('sensei_flush_rewrite_rules', '2');
1353 1353
 
1354
-        }elseif( '2' == $option ) {
1354
+		}elseif( '2' == $option ) {
1355 1355
 
1356
-            flush_rewrite_rules();
1357
-            update_option('sensei_flush_rewrite_rules', '0');
1356
+			flush_rewrite_rules();
1357
+			update_option('sensei_flush_rewrite_rules', '0');
1358 1358
 
1359
-        }
1359
+		}
1360 1360
 
1361
-    } // end flush_rewrite_rules
1361
+	} // end flush_rewrite_rules
1362 1362
 
1363
-    /**
1364
-     * Calling this function will tell Sensei to flush rewrite
1365
-     * rules on the next load.
1366
-     *
1367
-     * @since 1.9.0
1368
-     */
1369
-    public function initiate_rewrite_rules_flush(){
1363
+	/**
1364
+	 * Calling this function will tell Sensei to flush rewrite
1365
+	 * rules on the next load.
1366
+	 *
1367
+	 * @since 1.9.0
1368
+	 */
1369
+	public function initiate_rewrite_rules_flush(){
1370 1370
 
1371
-        update_option('sensei_flush_rewrite_rules', '1');
1371
+		update_option('sensei_flush_rewrite_rules', '1');
1372 1372
 
1373
-    }
1373
+	}
1374 1374
 
1375 1375
 } // End Class
1376 1376
 
Please login to merge, or discard this patch.
includes/class-sensei-question.php 1 patch
Indentation   +566 added lines, -566 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 			if( isset( $post->ID ) ) {
119 119
 
120
-                $question_type = Sensei()->question->get_question_type( $post->ID );
120
+				$question_type = Sensei()->question->get_question_type( $post->ID );
121 121
 
122 122
 				if( $question_type ) {
123 123
 					$type = $this->question_types[ $question_type ];
@@ -237,15 +237,15 @@  discard block
 block discarded – undo
237 237
 	public function save_question( $post_id = 0 ) {
238 238
 
239 239
 		if( ! isset( $_POST['post_type']
240
-            ) || 'question' != $_POST['post_type'] ) {
241
-            return;
242
-        }
240
+			) || 'question' != $_POST['post_type'] ) {
241
+			return;
242
+		}
243 243
 
244 244
 
245 245
 
246
-        //setup the data for saving
246
+		//setup the data for saving
247 247
 		$data = $_POST ;
248
-        $data['quiz_id'] = 0;
248
+		$data['quiz_id'] = 0;
249 249
 		$data['question_id'] = $post_id;
250 250
 
251 251
 		if ( ! wp_is_post_revision( $post_id ) ){
@@ -339,34 +339,34 @@  discard block
 block discarded – undo
339 339
 		return $request;
340 340
 	}
341 341
 
342
-    /**
343
-     * Get the type of question by id
344
-     *
345
-     * This function uses the post terms to determine which question type
346
-     * the passed question id belongs to.
347
-     *
348
-     * @since 1.7.4
349
-     *
350
-     * @param int $question_id
351
-     *
352
-     * @return string $question_type | bool
353
-     */
354
-    public function get_question_type( $question_id ){
355
-
356
-        if( empty( $question_id ) || ! intval( $question_id ) > 0
357
-            || 'question' != get_post_type( $question_id )   ){
358
-            return false;
359
-        }
360
-
361
-        $question_type = 'multiple-choice';
362
-        $question_types = wp_get_post_terms( $question_id, 'question-type' );
363
-        foreach( $question_types as $type ) {
364
-            $question_type = $type->slug;
365
-        }
366
-
367
-        return $question_type;
368
-
369
-    }// end get_question_type
342
+	/**
343
+	 * Get the type of question by id
344
+	 *
345
+	 * This function uses the post terms to determine which question type
346
+	 * the passed question id belongs to.
347
+	 *
348
+	 * @since 1.7.4
349
+	 *
350
+	 * @param int $question_id
351
+	 *
352
+	 * @return string $question_type | bool
353
+	 */
354
+	public function get_question_type( $question_id ){
355
+
356
+		if( empty( $question_id ) || ! intval( $question_id ) > 0
357
+			|| 'question' != get_post_type( $question_id )   ){
358
+			return false;
359
+		}
360
+
361
+		$question_type = 'multiple-choice';
362
+		$question_types = wp_get_post_terms( $question_id, 'question-type' );
363
+		foreach( $question_types as $type ) {
364
+			$question_type = $type->slug;
365
+		}
366
+
367
+		return $question_type;
368
+
369
+	}// end get_question_type
370 370
 
371 371
 	/**
372 372
 	 * Given a question ID, return the grade that can be achieved.
@@ -398,317 +398,317 @@  discard block
 block discarded – undo
398 398
 	} // end get_question_grade
399 399
 
400 400
 
401
-    /**
402
-     * This function simply loads the question type template
403
-     *
404
-     * @since 1.9.0
405
-     * @param $question_type
406
-     */
407
-    public static function load_question_template( $question_type ){
408
-
409
-        Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
-    }
411
-
412
-    /**
413
-     * Echo the sensei question title.
414
-     *
415
-     * @uses WooThemes_Sensei_Question::get_the_question_title
416
-     *
417
-     * @since 1.9.0
418
-     * @param $question_id
419
-     */
420
-    public static function the_question_title( $question_id ){
421
-
422
-        echo self::get_the_question_title( $question_id );
423
-
424
-    }// end the_question_title
425
-
426
-    /**
427
-     * Generate the question title with it's grade.
428
-     *
429
-     * @since 1.9.0
430
-     *
431
-     * @param $question_id
432
-     * @return string
433
-     */
434
-    public static function get_the_question_title( $question_id ){
435
-
436
-        /**
437
-         * Filter the sensei question title
438
-         *
439
-         * @since 1.3.0
440
-         * @param $question_title
441
-         */
442
-        $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
-
444
-        /**
445
-         * hook document in class-woothemes-sensei-message.php the_title()
446
-         */
447
-        $title = apply_filters( 'sensei_single_title', $title, 'question');
448
-
449
-        $title_html  = '<span class="question question-title">';
450
-        $title_html .= $title;
451
-        $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
-        $title_html .='</span>';
453
-
454
-        return $title_html;
455
-    }
456
-
457
-    /**
458
-     * Tech the question description
459
-     *
460
-     * @param $question_id
461
-     * @return string
462
-     */
463
-    public static function get_the_question_description( $question_id ){
464
-
465
-        $question = get_post( $question_id );
466
-
467
-        /**
468
-         * Already documented within WordPress Core
469
-         */
470
-        return apply_filters( 'the_content', $question->post_content );
471
-
472
-    }
473
-
474
-    /**
475
-     * Output the question description
476
-     *
477
-     * @since 1.9.0
478
-     * @param $question_id
479
-     */
480
-    public static function the_question_description( $question_id  ){
481
-
482
-        echo self::get_the_question_description( $question_id );
483
-
484
-    }
485
-
486
-    /**
487
-     * Get the questions media markup
488
-     *
489
-     * @since 1.9.0
490
-     * @param $question_id
491
-     * @return string
492
-     */
493
-    public static function get_the_question_media( $question_id ){
494
-
495
-        $question_media = get_post_meta( $question_id, '_question_media', true );
496
-        $question_media_link = '';
497
-        if( 0 < intval( $question_media ) ) {
498
-            $mimetype = get_post_mime_type( $question_media );
499
-            if( $mimetype ) {
500
-                $mimetype_array = explode( '/', $mimetype);
501
-                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
-                    $question_media_type = $mimetype_array[0];
503
-                    $question_media_url = wp_get_attachment_url( $question_media );
504
-                    $attachment = get_post( $question_media );
505
-                    $question_media_title = $attachment->post_title;
506
-                    $question_media_description = $attachment->post_content;
507
-                    switch( $question_media_type ) {
508
-                        case 'image':
509
-                            $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
-                            $attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
-                            break;
513
-
514
-                        case 'audio':
515
-                            $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
-                            break;
517
-
518
-                        case 'video':
519
-                            $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
-                            break;
521
-
522
-                        default:
523
-                            $question_media_filename = basename( $question_media_url );
524
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
-                            break;
526
-                    }
527
-                }
528
-            }
529
-        }
530
-
531
-        $output = '';
532
-        if( $question_media_link ) {
533
-
534
-                $output .= '<div class="question_media_display">';
535
-                $output .=      $question_media_link;
536
-                $output .= '<dl>';
537
-
538
-                if( $question_media_title ) {
539
-
540
-                   $output .= '<dt>'. $question_media_title. '</dt>';
541
-
542
-                 }
543
-
544
-                if( $question_media_description ) {
545
-
546
-                    $output .= '<dd>' . $question_media_description . '</dd>';
547
-
548
-                }
549
-
550
-                $output .= '</dl>';
551
-                $output .= '</div>';
401
+	/**
402
+	 * This function simply loads the question type template
403
+	 *
404
+	 * @since 1.9.0
405
+	 * @param $question_type
406
+	 */
407
+	public static function load_question_template( $question_type ){
408
+
409
+		Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
410
+	}
411
+
412
+	/**
413
+	 * Echo the sensei question title.
414
+	 *
415
+	 * @uses WooThemes_Sensei_Question::get_the_question_title
416
+	 *
417
+	 * @since 1.9.0
418
+	 * @param $question_id
419
+	 */
420
+	public static function the_question_title( $question_id ){
421
+
422
+		echo self::get_the_question_title( $question_id );
423
+
424
+	}// end the_question_title
425
+
426
+	/**
427
+	 * Generate the question title with it's grade.
428
+	 *
429
+	 * @since 1.9.0
430
+	 *
431
+	 * @param $question_id
432
+	 * @return string
433
+	 */
434
+	public static function get_the_question_title( $question_id ){
435
+
436
+		/**
437
+		 * Filter the sensei question title
438
+		 *
439
+		 * @since 1.3.0
440
+		 * @param $question_title
441
+		 */
442
+		$title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
443
+
444
+		/**
445
+		 * hook document in class-woothemes-sensei-message.php the_title()
446
+		 */
447
+		$title = apply_filters( 'sensei_single_title', $title, 'question');
448
+
449
+		$title_html  = '<span class="question question-title">';
450
+		$title_html .= $title;
451
+		$title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
+		$title_html .='</span>';
453
+
454
+		return $title_html;
455
+	}
456
+
457
+	/**
458
+	 * Tech the question description
459
+	 *
460
+	 * @param $question_id
461
+	 * @return string
462
+	 */
463
+	public static function get_the_question_description( $question_id ){
464
+
465
+		$question = get_post( $question_id );
466
+
467
+		/**
468
+		 * Already documented within WordPress Core
469
+		 */
470
+		return apply_filters( 'the_content', $question->post_content );
471
+
472
+	}
473
+
474
+	/**
475
+	 * Output the question description
476
+	 *
477
+	 * @since 1.9.0
478
+	 * @param $question_id
479
+	 */
480
+	public static function the_question_description( $question_id  ){
481
+
482
+		echo self::get_the_question_description( $question_id );
483
+
484
+	}
485
+
486
+	/**
487
+	 * Get the questions media markup
488
+	 *
489
+	 * @since 1.9.0
490
+	 * @param $question_id
491
+	 * @return string
492
+	 */
493
+	public static function get_the_question_media( $question_id ){
494
+
495
+		$question_media = get_post_meta( $question_id, '_question_media', true );
496
+		$question_media_link = '';
497
+		if( 0 < intval( $question_media ) ) {
498
+			$mimetype = get_post_mime_type( $question_media );
499
+			if( $mimetype ) {
500
+				$mimetype_array = explode( '/', $mimetype);
501
+				if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
502
+					$question_media_type = $mimetype_array[0];
503
+					$question_media_url = wp_get_attachment_url( $question_media );
504
+					$attachment = get_post( $question_media );
505
+					$question_media_title = $attachment->post_title;
506
+					$question_media_description = $attachment->post_content;
507
+					switch( $question_media_type ) {
508
+						case 'image':
509
+							$image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
+							$attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
512
+							break;
513
+
514
+						case 'audio':
515
+							$question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
516
+							break;
517
+
518
+						case 'video':
519
+							$question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
520
+							break;
521
+
522
+						default:
523
+							$question_media_filename = basename( $question_media_url );
524
+							$question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
525
+							break;
526
+					}
527
+				}
528
+			}
529
+		}
530
+
531
+		$output = '';
532
+		if( $question_media_link ) {
552 533
 
534
+				$output .= '<div class="question_media_display">';
535
+				$output .=      $question_media_link;
536
+				$output .= '<dl>';
553 537
 
554
-         }
555
-
556
-        return $output;
557
-
558
-    } // end get_the_question_media
559
-
538
+				if( $question_media_title ) {
560 539
 
561
-    /**
562
-     * Output the question media
563
-     *
564
-     * @since 1.9.0
565
-     * @param string $question_id
566
-     */
567
-    public static function the_question_media( $question_id ){
540
+				   $output .= '<dt>'. $question_media_title. '</dt>';
568 541
 
569
-        echo self::get_the_question_media( $question_id );
542
+				 }
570 543
 
571
-    }
544
+				if( $question_media_description ) {
572 545
 
573
-    /**
574
-     * Output a special field for the question needed for question submission.
575
-     *
576
-     * @since 1.9.0
577
-     *
578
-     * @param $question_id
579
-     */
580
-    public static function the_question_hidden_fields( $question_id ){
581
-        ?>
546
+					$output .= '<dd>' . $question_media_description . '</dd>';
547
+
548
+				}
549
+
550
+				$output .= '</dl>';
551
+				$output .= '</div>';
552
+
553
+
554
+		 }
555
+
556
+		return $output;
557
+
558
+	} // end get_the_question_media
559
+
560
+
561
+	/**
562
+	 * Output the question media
563
+	 *
564
+	 * @since 1.9.0
565
+	 * @param string $question_id
566
+	 */
567
+	public static function the_question_media( $question_id ){
568
+
569
+		echo self::get_the_question_media( $question_id );
570
+
571
+	}
572
+
573
+	/**
574
+	 * Output a special field for the question needed for question submission.
575
+	 *
576
+	 * @since 1.9.0
577
+	 *
578
+	 * @param $question_id
579
+	 */
580
+	public static function the_question_hidden_fields( $question_id ){
581
+		?>
582 582
 
583 583
             <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" />
584 584
             <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" />
585 585
 
586 586
         <?php
587
-    }
587
+	}
588 588
 
589
-    /**
590
-     * This function can only be run withing the single quiz question loop
591
-     *
592
-     * @since 1.9.0
593
-     * @param $question_id
594
-     */
595
-    public static function answer_feedback_notes( $question_id ){
589
+	/**
590
+	 * This function can only be run withing the single quiz question loop
591
+	 *
592
+	 * @since 1.9.0
593
+	 * @param $question_id
594
+	 */
595
+	public static function answer_feedback_notes( $question_id ){
596 596
 
597
-        //IDS
598
-        $quiz_id = get_the_ID();
599
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
597
+		//IDS
598
+		$quiz_id = get_the_ID();
599
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
600 600
 
601
-        // Data to check before showing feedback
602
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
-        $not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
-        $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
-        $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
601
+		// Data to check before showing feedback
602
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
+		$not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
+		$lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
+		$quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
608 608
 
609
-        if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
-            ||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
-            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
609
+		if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
+			||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
+			|| ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
612 612
 
613
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
613
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
614 614
 
615
-            if( $answer_notes ) { ?>
615
+			if( $answer_notes ) { ?>
616 616
 
617 617
                 <div class="sensei-message info info-special answer-feedback">
618 618
 
619 619
                     <?php
620 620
 
621
-                        /**
622
-                         * Filter the answer feedback
623
-                         * Since 1.9.0
624
-                         *
625
-                         * @param string $answer_notes
626
-                         * @param string $question_id
627
-                         * @param string $lesson_id
628
-                         */
629
-                        echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
621
+						/**
622
+						 * Filter the answer feedback
623
+						 * Since 1.9.0
624
+						 *
625
+						 * @param string $answer_notes
626
+						 * @param string $question_id
627
+						 * @param string $lesson_id
628
+						 */
629
+						echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
630 630
 
631
-                    ?>
631
+					?>
632 632
 
633 633
                 </div>
634 634
 
635 635
             <?php }
636 636
 
637
-        }// end if we can show answer feedback
637
+		}// end if we can show answer feedback
638 638
 
639
-    }// end answer_feedback_notes
639
+	}// end answer_feedback_notes
640 640
 
641
-    /**
642
-     * This function has to be run inside the quiz question loop on the single quiz page.
643
-     *
644
-     *
645
-     * @since 1.9.0
646
-     * @param string $question_id
647
-     */
648
-    public static function the_answer_result_indication( $question_id ){
641
+	/**
642
+	 * This function has to be run inside the quiz question loop on the single quiz page.
643
+	 *
644
+	 *
645
+	 * @since 1.9.0
646
+	 * @param string $question_id
647
+	 */
648
+	public static function the_answer_result_indication( $question_id ){
649 649
 
650
-        global $post,  $current_user, $sensei_question_loop;
650
+		global $post,  $current_user, $sensei_question_loop;
651 651
 
652
-        // Post Data
653
-        $quiz_id = $sensei_question_loop['quiz_id'];
654
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
-        $question_item = $sensei_question_loop['current_question'];
652
+		// Post Data
653
+		$quiz_id = $sensei_question_loop['quiz_id'];
654
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
655
+		$question_item = $sensei_question_loop['current_question'];
656 656
 
657
-        // Setup variable needed to determine if the message should show and what it should show
658
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
-        $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
-        $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
657
+		// Setup variable needed to determine if the message should show and what it should show
658
+		$user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
+		$lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
+		$reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
+		$quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
662 662
 
663
-        // retrieve the question total grade
664
-        $question_grade = Sensei()->question->get_question_grade( $question_id );
663
+		// retrieve the question total grade
664
+		$question_grade = Sensei()->question->get_question_grade( $question_id );
665 665
 
666
-        // retrieve grade the user achieved
667
-        $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
666
+		// retrieve grade the user achieved
667
+		$user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
668 668
 
669
-        // Question ID
670
-        $question_id = $question_item->ID;
669
+		// Question ID
670
+		$question_id = $question_item->ID;
671 671
 
672
-        // conditions to check
673
-        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
-        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
-        $grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
672
+		// conditions to check
673
+		$completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
+		$completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
+		$grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
676 676
 
677
-        if (  $completed_with_valid_grade
678
-            || $completed_with_valid_grade_and_reset_not_allowed
679
-            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
677
+		if (  $completed_with_valid_grade
678
+			|| $completed_with_valid_grade_and_reset_not_allowed
679
+			|| $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
680 680
 
681
-            $user_correct = false;
682
-            $answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
-            $answer_message_class = 'user_wrong';
684
-            // For zero grade mark as 'correct' but add no classes
685
-            if ( 0 == $question_grade ) {
681
+			$user_correct = false;
682
+			$answer_message = __( 'Incorrect', 'woothemes-sensei' );
683
+			$answer_message_class = 'user_wrong';
684
+			// For zero grade mark as 'correct' but add no classes
685
+			if ( 0 == $question_grade ) {
686 686
 
687
-                $user_correct = true;
688
-                $answer_message = '';
689
-                $answer_message_class = '';
687
+				$user_correct = true;
688
+				$answer_message = '';
689
+				$answer_message_class = '';
690 690
 
691
-            } else if( $user_question_grade > 0 ) {
691
+			} else if( $user_question_grade > 0 ) {
692 692
 
693
-                $user_correct = true;
694
-                $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
-                $answer_message_class = 'user_right';
693
+				$user_correct = true;
694
+				$answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
695
+				$answer_message_class = 'user_right';
696 696
 
697
-            }
697
+			}
698 698
 
699
-            // attach the correct answer if the question is auto gradable and user got it wrong
700
-            if( !$reset_quiz_allowed && !$user_correct ){
699
+			// attach the correct answer if the question is auto gradable and user got it wrong
700
+			if( !$reset_quiz_allowed && !$user_correct ){
701 701
 
702
-                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
702
+				$answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
703 703
 
704
-            }
704
+			}
705 705
 
706
-            // answer feedback
707
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
-            if( $answer_notes ) {
709
-                $answer_message_class .= ' has_notes';
710
-            }
711
-            ?>
706
+			// answer feedback
707
+			$answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
+			if( $answer_notes ) {
709
+				$answer_message_class .= ' has_notes';
710
+			}
711
+			?>
712 712
 
713 713
             <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>">
714 714
 
@@ -718,387 +718,387 @@  discard block
 block discarded – undo
718 718
 
719 719
             <?php
720 720
 
721
-        } // end if user can see all the goodies
722
-
723
-    }// end the_answer_result_indication
724
-
725
-    /**
726
-     * Generate the question template data and return it as an array.
727
-     *
728
-     * @since 1.9.0
729
-     *
730
-     * @param string $question_id
731
-     * @param $quiz_id
732
-     * @return array $question_data
733
-     */
734
-    public static function get_template_data( $question_id, $quiz_id ){
735
-
736
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
737
-
738
-        $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
-        //backwards compatibility
740
-        if( 'on' == $reset_allowed ) {
741
-            $reset_allowed = 1;
742
-        }
743
-
744
-        // Check again that the lesson is complete
745
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
-        $user_lesson_complete = false;
747
-        if ( $user_lesson_end ) {
748
-            $user_lesson_complete = true;
749
-        }
750
-
751
-        //setup the question data
752
-        $data[ 'ID' ]                     = $question_id;
753
-        $data[ 'title' ]                  = get_the_title( $question_id );
754
-        $data[ 'content' ]                = get_post( $question_id )->post_content;
755
-        $data[ 'quiz_id' ]                = $quiz_id;
756
-        $data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
-        $data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
-        $data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
-        $data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
-        $data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
-        $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
-        $data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
-        $data[ 'lesson_completed' ]       = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
-        $data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
-        $data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
-        $data[ 'lesson_complete' ]        = $user_lesson_complete;
767
-
768
-        /**
769
-         * Filter the question template data. This filter fires  in
770
-         * the get_template_data function
771
-         *
772
-         * @hooked self::boolean_load_question_data
773
-         *
774
-         * @since 1.9.0
775
-         *
776
-         * @param array $data
777
-         * @param string $question_id
778
-         * @param string $quiz_id
779
-         */
780
-        return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
721
+		} // end if user can see all the goodies
781 722
 
782
-    }
723
+	}// end the_answer_result_indication
783 724
 
784
-    /**
785
-     * Load multiple choice question data on the sensei_get_question_template_data
786
-     * filter.
787
-     *
788
-     * @since 1.9.0
789
-     *
790
-     * @param $question_data
791
-     * @param $question_id
792
-     * @param $quiz_id
793
-     *
794
-     * @return array()
795
-     */
796
-    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
725
+	/**
726
+	 * Generate the question template data and return it as an array.
727
+	 *
728
+	 * @since 1.9.0
729
+	 *
730
+	 * @param string $question_id
731
+	 * @param $quiz_id
732
+	 * @return array $question_data
733
+	 */
734
+	public static function get_template_data( $question_id, $quiz_id ){
797 735
 
736
+		$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
798 737
 
799
-        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
738
+		$reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
739
+		//backwards compatibility
740
+		if( 'on' == $reset_allowed ) {
741
+			$reset_allowed = 1;
742
+		}
800 743
 
801
-            // Get uploaded file
802
-            $attachment_id = $question_data[ 'user_answer_entry' ];
803
-            $answer_media_url = $answer_media_filename = '';
744
+		// Check again that the lesson is complete
745
+		$user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
746
+		$user_lesson_complete = false;
747
+		if ( $user_lesson_end ) {
748
+			$user_lesson_complete = true;
749
+		}
804 750
 
751
+		//setup the question data
752
+		$data[ 'ID' ]                     = $question_id;
753
+		$data[ 'title' ]                  = get_the_title( $question_id );
754
+		$data[ 'content' ]                = get_post( $question_id )->post_content;
755
+		$data[ 'quiz_id' ]                = $quiz_id;
756
+		$data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
+		$data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
+		$data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
+		$data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
+		$data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
+		$data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
+		$data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
+		$data[ 'lesson_completed' ]       = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
+		$data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
+		$data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
+		$data[ 'lesson_complete' ]        = $user_lesson_complete;
767
+
768
+		/**
769
+		 * Filter the question template data. This filter fires  in
770
+		 * the get_template_data function
771
+		 *
772
+		 * @hooked self::boolean_load_question_data
773
+		 *
774
+		 * @since 1.9.0
775
+		 *
776
+		 * @param array $data
777
+		 * @param string $question_id
778
+		 * @param string $quiz_id
779
+		 */
780
+		return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
805 781
 
806
-            $question_helptext = '';
807
-            if( isset( $question_data['question_wrong_answers'][0] ) ) {
782
+	}
808 783
 
809
-                $question_helptext =  $question_data['question_wrong_answers'][0];
784
+	/**
785
+	 * Load multiple choice question data on the sensei_get_question_template_data
786
+	 * filter.
787
+	 *
788
+	 * @since 1.9.0
789
+	 *
790
+	 * @param $question_data
791
+	 * @param $question_id
792
+	 * @param $quiz_id
793
+	 *
794
+	 * @return array()
795
+	 */
796
+	public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
810 797
 
811
-            }
812 798
 
799
+		if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
813 800
 
814
-            if( 0 < intval( $attachment_id ) ) {
801
+			// Get uploaded file
802
+			$attachment_id = $question_data[ 'user_answer_entry' ];
803
+			$answer_media_url = $answer_media_filename = '';
815 804
 
816
-                $answer_media_url = wp_get_attachment_url( $attachment_id );
817
-                $answer_media_filename = basename( $answer_media_url );
818 805
 
819
-            }
806
+			$question_helptext = '';
807
+			if( isset( $question_data['question_wrong_answers'][0] ) ) {
820 808
 
809
+				$question_helptext =  $question_data['question_wrong_answers'][0];
821 810
 
822
-            // Get max upload file size, formatted for display
823
-            // Code copied from wp-admin/includes/media.php:1515
824
-            $upload_size_unit = $max_upload_size = wp_max_upload_size();
825
-            $sizes = array( 'KB', 'MB', 'GB' );
826
-            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
-                $upload_size_unit /= 1024;
828
-            }
829
-            if ( $u < 0 ) {
811
+			}
830 812
 
831
-                $upload_size_unit = 0;
832
-                $u = 0;
833 813
 
834
-            } else {
814
+			if( 0 < intval( $attachment_id ) ) {
835 815
 
836
-                $upload_size_unit = (int) $upload_size_unit;
816
+				$answer_media_url = wp_get_attachment_url( $attachment_id );
817
+				$answer_media_filename = basename( $answer_media_url );
837 818
 
838
-            }
839
-            $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
819
+			}
840 820
 
841
-            // Assemble all the data needed by the file upload template
842
-            $question_data[ 'answer_media_url' ]      = $answer_media_url;
843
-            $question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
-            $question_data[ 'max_upload_size' ]       = $max_upload_size;
845 821
 
846
-            $question_data[ 'question_helptext' ]     = $question_helptext;
822
+			// Get max upload file size, formatted for display
823
+			// Code copied from wp-admin/includes/media.php:1515
824
+			$upload_size_unit = $max_upload_size = wp_max_upload_size();
825
+			$sizes = array( 'KB', 'MB', 'GB' );
826
+			for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
827
+				$upload_size_unit /= 1024;
828
+			}
829
+			if ( $u < 0 ) {
847 830
 
848
-        }// end if is file upload type
831
+				$upload_size_unit = 0;
832
+				$u = 0;
849 833
 
850
-        return $question_data;
834
+			} else {
851 835
 
852
-    }// end file_upload_load_question_data
836
+				$upload_size_unit = (int) $upload_size_unit;
853 837
 
854
-    /**
855
-     * Load multiple choice question data on the sensei_get_question_template_data
856
-     * filter.
857
-     *
858
-     * @since 1.9.0
859
-     *
860
-     * @param $question_data
861
-     * @param $question_id
862
-     * @param $quiz_id
863
-     *
864
-     * @return array()
865
-     */
866
-    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
838
+			}
839
+			$max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
867 840
 
868
-        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
841
+			// Assemble all the data needed by the file upload template
842
+			$question_data[ 'answer_media_url' ]      = $answer_media_url;
843
+			$question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
+			$question_data[ 'max_upload_size' ]       = $max_upload_size;
869 845
 
846
+			$question_data[ 'question_helptext' ]     = $question_helptext;
870 847
 
871
-            $answer_type = 'radio';
872
-            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
848
+		}// end if is file upload type
873 849
 
874
-                $answer_type = 'checkbox';
850
+		return $question_data;
875 851
 
876
-            }
852
+	}// end file_upload_load_question_data
877 853
 
878
-            // Merge right and wrong answers
879
-            if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
854
+	/**
855
+	 * Load multiple choice question data on the sensei_get_question_template_data
856
+	 * filter.
857
+	 *
858
+	 * @since 1.9.0
859
+	 *
860
+	 * @param $question_data
861
+	 * @param $question_id
862
+	 * @param $quiz_id
863
+	 *
864
+	 * @return array()
865
+	 */
866
+	public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
880 867
 
881
-                $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
868
+		if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
882 869
 
883
-            }  else {
884 870
 
885
-                array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
-                $merged_options = $question_data[ 'question_wrong_answers' ];
871
+			$answer_type = 'radio';
872
+			if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
887 873
 
888
-            }
874
+				$answer_type = 'checkbox';
889 875
 
890
-            // Setup answer options array.
891
-            $question_answers_options = array();
892
-            $count = 0;
876
+			}
893 877
 
894
-            foreach( $merged_options as $answer ) {
878
+			// Merge right and wrong answers
879
+			if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
895 880
 
896
-                $count++;
897
-                $question_option = array();
881
+				$merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
898 882
 
899
-                if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
-                    || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
-                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
883
+			}  else {
902 884
 
903
-                    $user_correct = false;
885
+				array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
+				$merged_options = $question_data[ 'question_wrong_answers' ];
904 887
 
888
+			}
905 889
 
906
-                    // For zero grade mark as 'correct' but add no classes
907
-                    if ( 0 == $question_data[ 'question_grade' ] ) {
890
+			// Setup answer options array.
891
+			$question_answers_options = array();
892
+			$count = 0;
908 893
 
909
-                        $user_correct = true;
894
+			foreach( $merged_options as $answer ) {
910 895
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
896
+				$count++;
897
+				$question_option = array();
912 898
 
913
-                        $user_correct = true;
899
+				if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
+					|| ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
+					|| ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
914 902
 
915
-                    }
903
+					$user_correct = false;
916 904
 
917
-                }
918 905
 
919
-                // setup the option specific classes
920
-                $answer_class = '';
921
-                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
-                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
906
+					// For zero grade mark as 'correct' but add no classes
907
+					if ( 0 == $question_data[ 'question_grade' ] ) {
923 908
 
924
-                        $answer_class .= ' right_answer';
909
+						$user_correct = true;
925 910
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
911
+					}  else if( $question_data[ 'user_question_grade' ] > 0 ) {
927 912
 
928
-                        $answer_class .= ' right_answer';
913
+						$user_correct = true;
929 914
 
930
-                    } elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
-                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
915
+					}
932 916
 
933
-                        $answer_class = 'user_wrong';
934
-                        if( $user_correct ) {
917
+				}
935 918
 
936
-                            $answer_class = 'user_right';
919
+				// setup the option specific classes
920
+				$answer_class = '';
921
+				if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
+					if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
937 923
 
938
-                        }
924
+						$answer_class .= ' right_answer';
939 925
 
940
-                    }
926
+					}  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
941 927
 
942
-                }
928
+						$answer_class .= ' right_answer';
943 929
 
944
-                // determine if the current option must be checked
945
-                $checked = '';
946
-                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
-                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
930
+					} elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
+						||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
948 932
 
949
-                        $checked = 'checked="checked"';
933
+						$answer_class = 'user_wrong';
934
+						if( $user_correct ) {
950 935
 
951
-                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
936
+							$answer_class = 'user_right';
952 937
 
953
-                        $checked = checked( $answer, $question_data['user_answer_entry'] , false );
938
+						}
954 939
 
955
-                    }
940
+					}
956 941
 
957
-                } // End If Statement
942
+				}
958 943
 
959
-                //Load the answer option data
960
-                $question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
-                $question_option[ 'answer' ]      = $answer;
962
-                $question_option[ 'option_class'] = $answer_class;
963
-                $question_option[ 'checked']      = $checked;
964
-                $question_option[ 'count' ]       = $count;
965
-                $question_option[ 'type' ] = $answer_type;
944
+				// determine if the current option must be checked
945
+				$checked = '';
946
+				if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
+					if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
966 948
 
967
-                // add the speci  fic option to the list of options for this question
968
-                $question_answers_options[] = $question_option;
949
+						$checked = 'checked="checked"';
969 950
 
970
-            } // end for each option
951
+					} elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
971 952
 
953
+						$checked = checked( $answer, $question_data['user_answer_entry'] , false );
972 954
 
973
-            // Shuffle the array depending on the settings
974
-            $answer_options_sorted = array();
975
-            $random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
-            if(  $random_order && $random_order == 'yes' ) {
955
+					}
977 956
 
978
-                $answer_options_sorted = $question_answers_options;
979
-                shuffle( $answer_options_sorted );
957
+				} // End If Statement
980 958
 
981
-            } else {
959
+				//Load the answer option data
960
+				$question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
+				$question_option[ 'answer' ]      = $answer;
962
+				$question_option[ 'option_class'] = $answer_class;
963
+				$question_option[ 'checked']      = $checked;
964
+				$question_option[ 'count' ]       = $count;
965
+				$question_option[ 'type' ] = $answer_type;
982 966
 
983
-                $answer_order = array();
984
-                $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
-                if( $answer_order_string ) {
967
+				// add the speci  fic option to the list of options for this question
968
+				$question_answers_options[] = $question_option;
986 969
 
987
-                    $answer_order = array_filter( explode( ',', $answer_order_string ) );
988
-                    if( count( $answer_order ) > 0 ) {
970
+			} // end for each option
989 971
 
990
-                        foreach( $answer_order as $answer_id ) {
991 972
 
992
-                            if( isset( $question_answers_options[ $answer_id ] ) ) {
973
+			// Shuffle the array depending on the settings
974
+			$answer_options_sorted = array();
975
+			$random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
+			if(  $random_order && $random_order == 'yes' ) {
993 977
 
994
-                                $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
-                                unset( $question_answers_options[ $answer_id ] );
978
+				$answer_options_sorted = $question_answers_options;
979
+				shuffle( $answer_options_sorted );
996 980
 
997
-                            }
981
+			} else {
998 982
 
999
-                        }
983
+				$answer_order = array();
984
+				$answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
+				if( $answer_order_string ) {
1000 986
 
1001
-                        if( count( $question_answers_options ) > 0 ) {
1002
-                            foreach( $question_answers_options as $id => $answer ) {
987
+					$answer_order = array_filter( explode( ',', $answer_order_string ) );
988
+					if( count( $answer_order ) > 0 ) {
1003 989
 
1004
-                                $answer_options_sorted[ $id ] = $answer;
990
+						foreach( $answer_order as $answer_id ) {
1005 991
 
1006
-                            }
1007
-                        }
992
+							if( isset( $question_answers_options[ $answer_id ] ) ) {
1008 993
 
1009
-                    }else{
994
+								$answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
+								unset( $question_answers_options[ $answer_id ] );
1010 996
 
1011
-                        $answer_options_sorted = $question_answers_options;
997
+							}
1012 998
 
1013
-                    }
999
+						}
1014 1000
 
1015
-                }else{
1001
+						if( count( $question_answers_options ) > 0 ) {
1002
+							foreach( $question_answers_options as $id => $answer ) {
1016 1003
 
1017
-                    $answer_options_sorted = $question_answers_options;
1004
+								$answer_options_sorted[ $id ] = $answer;
1018 1005
 
1019
-                } // end if $answer_order_string
1006
+							}
1007
+						}
1020 1008
 
1021
-            } // end if random order
1009
+					}else{
1022 1010
 
1011
+						$answer_options_sorted = $question_answers_options;
1023 1012
 
1024
-            // assemble and setup the data for the templates data array
1025
-            $question_data[ 'answer_options' ]    =  $answer_options_sorted;
1013
+					}
1026 1014
 
1027
-        }
1015
+				}else{
1028 1016
 
1029
-        return $question_data;
1017
+					$answer_options_sorted = $question_answers_options;
1030 1018
 
1031
-    }//  end multiple_choice_load_question_data
1019
+				} // end if $answer_order_string
1032 1020
 
1033
-    /**
1034
-     * Load the gap fill question data on the sensei_get_question_template_data
1035
-     * filter.
1036
-     *
1037
-     * @since 1.9.0
1038
-     *
1039
-     * @param $question_data
1040
-     * @param $question_id
1041
-     * @param $quiz_id
1042
-     *
1043
-     * @return array()
1044
-     */
1045
-    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1021
+			} // end if random order
1046 1022
 
1047
-        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048 1023
 
1049
-            $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
-            $question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
-            $question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
-            $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1024
+			// assemble and setup the data for the templates data array
1025
+			$question_data[ 'answer_options' ]    =  $answer_options_sorted;
1053 1026
 
1054
-        }
1027
+		}
1055 1028
 
1056
-        return $question_data;
1029
+		return $question_data;
1057 1030
 
1058
-    }//  end gap_fill_load_question_data
1031
+	}//  end multiple_choice_load_question_data
1032
+
1033
+	/**
1034
+	 * Load the gap fill question data on the sensei_get_question_template_data
1035
+	 * filter.
1036
+	 *
1037
+	 * @since 1.9.0
1038
+	 *
1039
+	 * @param $question_data
1040
+	 * @param $question_id
1041
+	 * @param $quiz_id
1042
+	 *
1043
+	 * @return array()
1044
+	 */
1045
+	public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1046
+
1047
+		if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1048
+
1049
+			$gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
+			$question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
+			$question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
+			$question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1053
+
1054
+		}
1055
+
1056
+		return $question_data;
1057
+
1058
+	}//  end gap_fill_load_question_data
1059 1059
 
1060 1060
 
1061
-    /**
1062
-     * Get the correct answer for a question
1063
-     *
1064
-     * @param $question_id
1065
-     * @return string $correct_answer or empty
1066
-     */
1067
-    public static function get_correct_answer( $question_id ){
1061
+	/**
1062
+	 * Get the correct answer for a question
1063
+	 *
1064
+	 * @param $question_id
1065
+	 * @return string $correct_answer or empty
1066
+	 */
1067
+	public static function get_correct_answer( $question_id ){
1068 1068
 
1069
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
-        $type = Sensei()->question->get_question_type( $question_id );
1071
-        $type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
-        $grade_type = 'manual-grade';
1069
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
+		$type = Sensei()->question->get_question_type( $question_id );
1071
+		$type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1072
+		$grade_type = 'manual-grade';
1073 1073
 
1074
-        if ('boolean'== $type ) {
1074
+		if ('boolean'== $type ) {
1075 1075
 
1076
-            $right_answer = ucfirst($right_answer);
1076
+			$right_answer = ucfirst($right_answer);
1077 1077
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1078
+		}elseif( 'multiple-choice' == $type ) {
1079 1079
 
1080
-            $right_answer = (array) $right_answer;
1081
-            $right_answer = implode( ', ', $right_answer );
1080
+			$right_answer = (array) $right_answer;
1081
+			$right_answer = implode( ', ', $right_answer );
1082 1082
 
1083
-        }elseif( 'gap-fill' == $type ) {
1083
+		}elseif( 'gap-fill' == $type ) {
1084 1084
 
1085
-            $right_answer_array = explode( '||', $right_answer );
1086
-            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
-            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
-            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1085
+			$right_answer_array = explode( '||', $right_answer );
1086
+			if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
+			if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
+			if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1089 1089
 
1090
-            $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1090
+			$right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1091 1091
 
1092
-        }else{
1092
+		}else{
1093 1093
 
1094
-            // for non auto gradable question types no answer should be returned.
1095
-            $right_answer = '';
1094
+			// for non auto gradable question types no answer should be returned.
1095
+			$right_answer = '';
1096 1096
 
1097
-        }
1097
+		}
1098 1098
 
1099
-        return $right_answer;
1099
+		return $right_answer;
1100 1100
 
1101
-    } // get_correct_answer
1101
+	} // get_correct_answer
1102 1102
 
1103 1103
 } // End Class
1104 1104
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-legacy-shortcodes.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -10,323 +10,323 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Sensei_Legacy_Shortcodes {
12 12
 
13
-    /**
14
-     * Add the legacy shortcodes to WordPress
15
-     *
16
-     * @since 1.9.0
17
-     */
18
-    public static function init(){
19
-
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
-
27
-    }
28
-    /**
29
-     * all_courses shortcode output function.
30
-     *
31
-     * The function should only be called indirectly through do_shortcode()
32
-     *
33
-     * @access public
34
-     * @param mixed $atts
35
-     * @param mixed $content (default: null)
36
-     * @return string
37
-     */
38
-    public static function all_courses( $atts, $content = null ) {
39
-
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
-
42
-    } // all_courses()
43
-
44
-    /**
45
-     * paid_courses function.
46
-     *
47
-     * @access public
48
-     * @param mixed $atts
49
-     * @param mixed $content (default: null)
50
-     * @return string
51
-     */
52
-    public static function paid_courses( $atts, $content = null ) {
53
-
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
-
56
-    } // End paid_courses()
57
-
58
-
59
-    /**
60
-     * featured_courses function.
61
-     *
62
-     * @access public
63
-     * @param mixed $atts
64
-     * @param mixed $content (default: null)
65
-     * @return string
66
-     */
67
-    public static function featured_courses( $atts, $content = null ) {
68
-
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
13
+	/**
14
+	 * Add the legacy shortcodes to WordPress
15
+	 *
16
+	 * @since 1.9.0
17
+	 */
18
+	public static function init(){
19
+
20
+		add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
+		add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
+		add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
+		add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
+		add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
+		add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
26
+
27
+	}
28
+	/**
29
+	 * all_courses shortcode output function.
30
+	 *
31
+	 * The function should only be called indirectly through do_shortcode()
32
+	 *
33
+	 * @access public
34
+	 * @param mixed $atts
35
+	 * @param mixed $content (default: null)
36
+	 * @return string
37
+	 */
38
+	public static function all_courses( $atts, $content = null ) {
39
+
40
+		return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
41
+
42
+	} // all_courses()
43
+
44
+	/**
45
+	 * paid_courses function.
46
+	 *
47
+	 * @access public
48
+	 * @param mixed $atts
49
+	 * @param mixed $content (default: null)
50
+	 * @return string
51
+	 */
52
+	public static function paid_courses( $atts, $content = null ) {
53
+
54
+		return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
55
+
56
+	} // End paid_courses()
57
+
58
+
59
+	/**
60
+	 * featured_courses function.
61
+	 *
62
+	 * @access public
63
+	 * @param mixed $atts
64
+	 * @param mixed $content (default: null)
65
+	 * @return string
66
+	 */
67
+	public static function featured_courses( $atts, $content = null ) {
68
+
69
+		return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
70 70
 
71
-    } // End featured_courses()
71
+	} // End featured_courses()
72 72
 
73
-    /**
74
-     * shortcode_free_courses function.
75
-     *
76
-     * @access public
77
-     * @param mixed $atts
78
-     * @param mixed $content (default: null)
79
-     * @return string
80
-     */
81
-    public static function free_courses( $atts, $content = null ) {
73
+	/**
74
+	 * shortcode_free_courses function.
75
+	 *
76
+	 * @access public
77
+	 * @param mixed $atts
78
+	 * @param mixed $content (default: null)
79
+	 * @return string
80
+	 */
81
+	public static function free_courses( $atts, $content = null ) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+		return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
84 84
 
85
-    } // End free_courses()
85
+	} // End free_courses()
86 86
 
87
-    /**
88
-     * shortcode_new_courses function.
89
-     *
90
-     * @access public
91
-     * @param mixed $atts
92
-     * @param mixed $content (default: null)
93
-     * @return string
94
-     */
95
-    public static function new_courses( $atts, $content = null ) {
87
+	/**
88
+	 * shortcode_new_courses function.
89
+	 *
90
+	 * @access public
91
+	 * @param mixed $atts
92
+	 * @param mixed $content (default: null)
93
+	 * @return string
94
+	 */
95
+	public static function new_courses( $atts, $content = null ) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+		return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
98 98
 
99
-    } // End new_courses()
99
+	} // End new_courses()
100 100
 
101
-    /**
102
-     * Generate courses adding a title.
103
-     *
104
-     * @since 1.9.0
105
-     *
106
-     * @param $title
107
-     * @param $shortcode_specific_override
108
-     * @return string
109
-     */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
101
+	/**
102
+	 * Generate courses adding a title.
103
+	 *
104
+	 * @since 1.9.0
105
+	 *
106
+	 * @param $title
107
+	 * @param $shortcode_specific_override
108
+	 * @return string
109
+	 */
110
+	public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
111 111
 
112
-        global  $shortcode_override, $posts_array;
112
+		global  $shortcode_override, $posts_array;
113 113
 
114
-        $shortcode_override = $shortcode_specific_override;
114
+		$shortcode_override = $shortcode_specific_override;
115 115
 
116
-        // do not show this short code if there is a shortcode int he url and
117
-        // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
116
+		// do not show this short code if there is a shortcode int he url and
117
+		// this specific shortcode is not the one requested in the ur.
118
+		$specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
+		if( ! empty( $specific_shortcode_requested) &&
120
+			$specific_shortcode_requested != $shortcode_override ){
121 121
 
122
-            return '';
122
+			return '';
123 123
 
124
-        }
124
+		}
125 125
 
126
-        // loop and get all courses html
127
-        ob_start();
128
-        self::initialise_legacy_course_loop();
129
-        $courses = ob_get_clean();
126
+		// loop and get all courses html
127
+		ob_start();
128
+		self::initialise_legacy_course_loop();
129
+		$courses = ob_get_clean();
130 130
 
131
-        $content = '';
132
-        if( count( $posts_array ) > 0 ){
131
+		$content = '';
132
+		if( count( $posts_array ) > 0 ){
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
-            $before .= '<section id="main-course" class="course-container">';
134
+			$before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
135
+			$before .= '<section id="main-course" class="course-container">';
136 136
 
137
-            $after = '</section>';
137
+			$after = '</section>';
138 138
 
139
-            //assemble
140
-            $content = $before . $courses . $after;
139
+			//assemble
140
+			$content = $before . $courses . $after;
141 141
 
142
-        }
142
+		}
143 143
 
144
-        return $content;
144
+		return $content;
145 145
 
146
-    }// end generate_shortcode_courses
146
+	}// end generate_shortcode_courses
147 147
 
148 148
 
149
-    /**
150
-     * user_courses function.
151
-     *
152
-     * @access public
153
-     * @param mixed $atts
154
-     * @param mixed $content (default: null)
155
-     * @return string
156
-     */
157
-    public static function user_courses( $atts, $content = null ) {
158
-        global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
149
+	/**
150
+	 * user_courses function.
151
+	 *
152
+	 * @access public
153
+	 * @param mixed $atts
154
+	 * @param mixed $content (default: null)
155
+	 * @return string
156
+	 */
157
+	public static function user_courses( $atts, $content = null ) {
158
+		global $shortcode_override;
159
+		extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
160 160
 
161
-        $shortcode_override = 'usercourses';
161
+		$shortcode_override = 'usercourses';
162 162
 
163
-        ob_start();
163
+		ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+		if( is_user_logged_in() ){
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+			Sensei_Templates::get_template( 'user/my-courses.php' );
168 168
 
169
-        }else{
169
+		}else{
170 170
 
171
-            Sensei()->frontend->sensei_login_form();
171
+			Sensei()->frontend->sensei_login_form();
172 172
 
173
-        }
173
+		}
174 174
 
175
-        $content = ob_get_clean();
176
-        return $content;
175
+		$content = ob_get_clean();
176
+		return $content;
177 177
 
178
-    } // End user_courses()
178
+	} // End user_courses()
179 179
 
180
-    /**
181
-     * This function is simply to honor the legacy
182
-     * loop-course.php for the old shortcodes.
183
-     * @since 1.9.0
184
-     */
185
-    public static function initialise_legacy_course_loop(){
180
+	/**
181
+	 * This function is simply to honor the legacy
182
+	 * loop-course.php for the old shortcodes.
183
+	 * @since 1.9.0
184
+	 */
185
+	public static function initialise_legacy_course_loop(){
186 186
 
187
-        global  $post, $wp_query, $shortcode_override, $course_excludes;
187
+		global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189
-        // Handle Query Type
190
-        $query_type = '';
189
+		// Handle Query Type
190
+		$query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
194
-        } // End If Statement
192
+		if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
+			$query_type = esc_html( $_GET[ 'action' ] );
194
+		} // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
197
-            $query_type = $shortcode_override;
198
-        } // End If Statement
196
+		if ( '' != $shortcode_override ) {
197
+			$query_type = $shortcode_override;
198
+		} // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+		if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
201 201
 
202
-        // Check that query returns results
203
-        // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
202
+		// Check that query returns results
203
+		// Handle Pagination
204
+		$paged = $wp_query->get( 'paged' );
205
+		$paged = empty( $paged ) ? 1 : $paged;
206 206
 
207 207
 
208
-        // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
208
+		// Check for pagination settings
209
+		if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
212 212
 
213
-        } else {
213
+		} else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+			$amount = $wp_query->get( 'posts_per_page' );
216 216
 
217
-        } // End If Statement
217
+		} // End If Statement
218 218
 
219
-        // This is not a paginated page (or it's simply the first page of a paginated page/post)
219
+		// This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221
-        global $posts_array;
222
-        $course_includes   = array();
221
+		global $posts_array;
222
+		$course_includes   = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
226
-        $posts_array = $course_query->get_posts();
224
+		$query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
+		$course_query = new WP_Query( $query_args );
226
+		$posts_array = $course_query->get_posts();
227 227
 
228
-        // output the courses
229
-        if( ! empty( $posts_array ) ) {
228
+		// output the courses
229
+		if( ! empty( $posts_array ) ) {
230 230
 
231
-            //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
231
+			//output all courses for current query
232
+			self::loop_courses( $course_query, $amount );
233 233
 
234
-        }
234
+		}
235 235
 
236
-    }
236
+	}
237 237
 
238
-    /**
239
-     * Loop through courses in the query and output the infomration needed
240
-     *
241
-     * @since 1.9.0
242
-     *
243
-     * @param WP_Query $course_query
244
-     */
245
-    public static function loop_courses( $course_query, $amount ){
238
+	/**
239
+	 * Loop through courses in the query and output the infomration needed
240
+	 *
241
+	 * @since 1.9.0
242
+	 *
243
+	 * @param WP_Query $course_query
244
+	 */
245
+	public static function loop_courses( $course_query, $amount ){
246 246
 
247
-        global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
247
+		global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+		if ( count( $course_query->get_posts() ) > 0 ) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+			do_action( 'sensei_course_archive_header', $shortcode_override );
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+			foreach ( $course_query->get_posts() as $course){
254 254
 
255
-                // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
255
+				// Make sure the other loops dont include the same post twice!
256
+				array_push( $course_excludes, $course->ID );
257 257
 
258
-                // output the course markup
259
-                self::the_course( $course->ID );
258
+				// output the course markup
259
+				self::the_course( $course->ID );
260 260
 
261
-            } // End For Loop
261
+			} // End For Loop
262 262
 
263
-            // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
-            $posts_array       = $posts_array_query->get_posts();
266
-            $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
263
+			// More and Prev links
264
+			$posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
265
+			$posts_array       = $posts_array_query->get_posts();
266
+			$max_pages = $course_query->found_posts / $amount;
267
+			if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
268 268
 
269
-                switch( $shortcode_override ){
270
-                    case 'paidcourses':
271
-                        $filter = 'paid';
272
-                        break;
273
-                    case 'featuredcourses':
274
-                        $filter = 'featured';
275
-                        break;
276
-                    case 'freecourses':
277
-                        $filter = 'free';
278
-                        break;
279
-                    default:
280
-                        $filter = '';
281
-                        break;
282
-                }
269
+				switch( $shortcode_override ){
270
+					case 'paidcourses':
271
+						$filter = 'paid';
272
+						break;
273
+					case 'featuredcourses':
274
+						$filter = 'featured';
275
+						break;
276
+					case 'freecourses':
277
+						$filter = 'free';
278
+						break;
279
+					default:
280
+						$filter = '';
281
+						break;
282
+				}
283 283
 
284
-                $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
288
-                }
284
+				$quer_args = array();
285
+				$quer_args[ 'paged' ] = '2';
286
+				if( !empty( $filter ) ){
287
+					$quer_args[ 'course_filter' ] = $filter;
288
+				}
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+				$course_pagination_link = get_post_type_archive_link( 'course' );
291
+				$more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
+				$more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
293 293
 
294
-                // next/more
295
-                $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
297
-                $html .= $more_link_text;
298
-                $html .= '<span class="meta-nav"></span></a></div>';
294
+				// next/more
295
+				$html  = '<div class="navigation"><div class="nav-next">';
296
+				$html .= '<a href="' . $more_link_url . '">';
297
+				$html .= $more_link_text;
298
+				$html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+				echo apply_filters( 'course_archive_next_link', $html );
301 301
 
302
-            } // End If Statement
302
+			} // End If Statement
303 303
 
304
-        } // End If Statement
305
-    }
304
+		} // End If Statement
305
+	}
306 306
 
307
-    /**
308
-     * Print a single course markup
309
-     *
310
-     * @param $course_id
311
-     */
312
-    public static function the_course( $course_id ){
307
+	/**
308
+	 * Print a single course markup
309
+	 *
310
+	 * @param $course_id
311
+	 */
312
+	public static function the_course( $course_id ){
313 313
 
314
-        // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
318
-        $author_display_name = $user_info->display_name;
319
-        $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
-        ?>
314
+		// Get meta data
315
+		$course =  get_post( $course_id );
316
+		$user_info = get_userdata( absint( $course->post_author ) );
317
+		$author_link = get_author_posts_url( absint( $course->post_author ) );
318
+		$author_display_name = $user_info->display_name;
319
+		$author_id = $course->post_author;
320
+		$category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
323
+		?>
324 324
 
325 325
         <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
326 326
             <?php
327
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
329
-            ?>
327
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
328
+			do_action('sensei_course_content_before',$course );
329
+			?>
330 330
             <div class="course-content">
331 331
 
332 332
                 <?php Sensei()->course->course_image($course_id); ?>
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                     </p>
363 363
 
364 364
                     <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
365
+						$preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
366 366
                         <p class="sensei-free-lessons">
367 367
                             <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
@@ -373,15 +373,15 @@  discard block
 block discarded – undo
373 373
 
374 374
             </div>
375 375
             <?php
376
-            // so that legacy shortcodes work with thir party plugins that wants to hook in
377
-            do_action('sensei_course_content_after', $course);
378
-            ?>
376
+			// so that legacy shortcodes work with thir party plugins that wants to hook in
377
+			do_action('sensei_course_content_after', $course);
378
+			?>
379 379
 
380 380
         </article>
381 381
 
382 382
         <?php
383 383
 
384 384
 
385
-    } // end the_course
385
+	} // end the_course
386 386
 
387 387
 }// end class legacy shortcodes
388 388
\ No newline at end of file
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-unpurchased-courses.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -14,138 +14,138 @@
 block discarded – undo
14 14
  */
15 15
 class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface {
16 16
 
17
-    /**
18
-     * @var WP_Query to help setup the query needed by the render method.
19
-     */
20
-    protected $query;
21
-
22
-    /**
23
-     * @var string number of items to show on the current page
24
-     * Default: all.
25
-     */
26
-    protected $number;
27
-
28
-    /**
29
-     * @var string ordery by course field
30
-     * Default: date
31
-     */
32
-    protected $orderby;
33
-
34
-    /**
35
-     * @var string ASC or DESC
36
-     * Default: 'DESC'
37
-     */
38
-    protected  $order;
39
-
40
-    /**
41
-     * Setup the shortcode object
42
-     *
43
-     * @since 1.9.0
44
-     * @param array $attributes
45
-     * @param string $content
46
-     * @param string $shortcode the shortcode that was called for this instance
47
-     */
48
-    public function __construct( $attributes, $content, $shortcode ){
49
-
50
-        if( !is_user_logged_in() ) {
51
-            return;
52
-        }
53
-
54
-        // set up all argument need for constructing the course query
55
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
57
-
58
-        // set the default for menu_order to be ASC
59
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
60
-
61
-            $this->order =  'ASC';
62
-
63
-        }else{
64
-
65
-            // for everything else use the value passed or the default DESC
66
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
67
-
68
-        }
69
-
70
-        // setup the course query that will be used when rendering
71
-        $this->setup_course_query();
72
-    }
73
-
74
-    /**
75
-     * Sets up the object course query
76
-     * that will be used int he render method.
77
-     *
78
-     * @since 1.9.0
79
-     */
80
-    protected function setup_course_query(){
81
-
82
-        // course query parameters to be used for all courses
83
-        $query_args = array(
84
-            'post_type'        => 'course',
85
-            'post_status'      => 'publish',
86
-            // the number specified by the user will be used later in this function
87
-            'posts_per_page' => 1000,
88
-            'orderby'          => $this->orderby,
89
-            'order'            => $this->order
90
-        );
91
-
92
-        // get all the courses that has a product attached
93
-        $all_courses_query = new WP_Query( $query_args );
94
-
95
-        $paid_courses_not_taken = array();
96
-        // look through all course and find the purchasable ones that user has not purchased
97
-        foreach( $all_courses_query->posts as $course ){
98
-
99
-            // only keep the courses with a product including only  courses that the user not taking
100
-            $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
101
-            if( is_numeric( $course_product_id )
102
-                &&
103
-                ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
104
-            ){
105
-
106
-                    $paid_courses_not_taken[] = $course->ID;
107
-
108
-                }
109
-
110
-        } // end foreach
111
-
112
-
113
-        // setup the course query again and only use the course the user has not purchased.
114
-        // this query will be loaded into the global WP_Query in the render function.
115
-        $query_args['post__in'] = $paid_courses_not_taken;
116
-        $query_args['posts_per_page'] = $this->number;
117
-        $this->query = new WP_Query( $query_args );
118
-
119
-    }// end setup _course_query
17
+	/**
18
+	 * @var WP_Query to help setup the query needed by the render method.
19
+	 */
20
+	protected $query;
21
+
22
+	/**
23
+	 * @var string number of items to show on the current page
24
+	 * Default: all.
25
+	 */
26
+	protected $number;
27
+
28
+	/**
29
+	 * @var string ordery by course field
30
+	 * Default: date
31
+	 */
32
+	protected $orderby;
33
+
34
+	/**
35
+	 * @var string ASC or DESC
36
+	 * Default: 'DESC'
37
+	 */
38
+	protected  $order;
39
+
40
+	/**
41
+	 * Setup the shortcode object
42
+	 *
43
+	 * @since 1.9.0
44
+	 * @param array $attributes
45
+	 * @param string $content
46
+	 * @param string $shortcode the shortcode that was called for this instance
47
+	 */
48
+	public function __construct( $attributes, $content, $shortcode ){
49
+
50
+		if( !is_user_logged_in() ) {
51
+			return;
52
+		}
53
+
54
+		// set up all argument need for constructing the course query
55
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
57
+
58
+		// set the default for menu_order to be ASC
59
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
60
+
61
+			$this->order =  'ASC';
62
+
63
+		}else{
64
+
65
+			// for everything else use the value passed or the default DESC
66
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
67
+
68
+		}
69
+
70
+		// setup the course query that will be used when rendering
71
+		$this->setup_course_query();
72
+	}
73
+
74
+	/**
75
+	 * Sets up the object course query
76
+	 * that will be used int he render method.
77
+	 *
78
+	 * @since 1.9.0
79
+	 */
80
+	protected function setup_course_query(){
81
+
82
+		// course query parameters to be used for all courses
83
+		$query_args = array(
84
+			'post_type'        => 'course',
85
+			'post_status'      => 'publish',
86
+			// the number specified by the user will be used later in this function
87
+			'posts_per_page' => 1000,
88
+			'orderby'          => $this->orderby,
89
+			'order'            => $this->order
90
+		);
91
+
92
+		// get all the courses that has a product attached
93
+		$all_courses_query = new WP_Query( $query_args );
94
+
95
+		$paid_courses_not_taken = array();
96
+		// look through all course and find the purchasable ones that user has not purchased
97
+		foreach( $all_courses_query->posts as $course ){
98
+
99
+			// only keep the courses with a product including only  courses that the user not taking
100
+			$course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
101
+			if( is_numeric( $course_product_id )
102
+				&&
103
+				! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
104
+			){
105
+
106
+					$paid_courses_not_taken[] = $course->ID;
107
+
108
+				}
109
+
110
+		} // end foreach
111
+
112
+
113
+		// setup the course query again and only use the course the user has not purchased.
114
+		// this query will be loaded into the global WP_Query in the render function.
115
+		$query_args['post__in'] = $paid_courses_not_taken;
116
+		$query_args['posts_per_page'] = $this->number;
117
+		$this->query = new WP_Query( $query_args );
118
+
119
+	}// end setup _course_query
120 120
 
121
-    /**
122
-     * Rendering the shortcode this class is responsible for.
123
-     *
124
-     * @return string $content
125
-     */
126
-    public function render(){
121
+	/**
122
+	 * Rendering the shortcode this class is responsible for.
123
+	 *
124
+	 * @return string $content
125
+	 */
126
+	public function render(){
127 127
 
128
-        global $wp_query;
128
+		global $wp_query;
129 129
 
130
-        if( ! is_user_logged_in() ) {
131
-            return '';
132
-        }
130
+		if( ! is_user_logged_in() ) {
131
+			return '';
132
+		}
133 133
 
134
-        // keep a reference to old query
135
-        $current_global_query = $wp_query;
134
+		// keep a reference to old query
135
+		$current_global_query = $wp_query;
136 136
 
137
-        // assign the query setup in $this-> setup_course_query
138
-        $wp_query = $this->query;
137
+		// assign the query setup in $this-> setup_course_query
138
+		$wp_query = $this->query;
139 139
 
140
-        ob_start();
141
-        Sensei_Templates::get_template('loop-course.php');
142
-        $shortcode_output =  ob_get_clean();
140
+		ob_start();
141
+		Sensei_Templates::get_template('loop-course.php');
142
+		$shortcode_output =  ob_get_clean();
143 143
 
144
-        //restore old query
145
-        $wp_query = $current_global_query;
144
+		//restore old query
145
+		$wp_query = $current_global_query;
146 146
 
147
-        return $shortcode_output;
147
+		return $shortcode_output;
148 148
 
149
-    }// end render
149
+	}// end render
150 150
 
151 151
 }
152 152
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 1 patch
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -12,735 +12,735 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 Class Sensei_WC{
15
-    /**
16
-     * Load the files needed for the woocommerce integration.
17
-     *
18
-     * @since 1.9.0
19
-     */
20
-    public static function load_woocommerce_integration_hooks(){
15
+	/**
16
+	 * Load the files needed for the woocommerce integration.
17
+	 *
18
+	 * @since 1.9.0
19
+	 */
20
+	public static function load_woocommerce_integration_hooks(){
21 21
 
22
-        require_once( __DIR__ . '/hooks/woocommerce.php' );
22
+		require_once( __DIR__ . '/hooks/woocommerce.php' );
23 23
 
24
-    }
25
-    /**
26
-     * check if WooCommerce plugin is loaded and allowed by Sensei
27
-     *
28
-     * @since 1.9.0
29
-     * @return bool
30
-     */
31
-    public static function is_woocommerce_active(){
24
+	}
25
+	/**
26
+	 * check if WooCommerce plugin is loaded and allowed by Sensei
27
+	 *
28
+	 * @since 1.9.0
29
+	 * @return bool
30
+	 */
31
+	public static function is_woocommerce_active(){
32 32
 
33
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
-        return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
33
+		$is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
34
+		return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
35 35
 
36
-    } // end is_woocommerce_active
36
+	} // end is_woocommerce_active
37 37
 
38
-    /**
39
-     * Checks if the WooCommerce plugin is installed and activation.
40
-     *
41
-     * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
42
-     * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
43
-     *
44
-     * @since 1.9.0
45
-     *
46
-     * @return bool
47
-     */
48
-    public static function is_woocommerce_present(){
38
+	/**
39
+	 * Checks if the WooCommerce plugin is installed and activation.
40
+	 *
41
+	 * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active().
42
+	 * This function does nott check to see if the Sensei setting for WooCommerce is enabled.
43
+	 *
44
+	 * @since 1.9.0
45
+	 *
46
+	 * @return bool
47
+	 */
48
+	public static function is_woocommerce_present(){
49 49
 
50
-        $active_plugins = (array) get_option( 'active_plugins', array() );
50
+		$active_plugins = (array) get_option( 'active_plugins', array() );
51 51
 
52
-        if ( is_multisite() ){
52
+		if ( is_multisite() ){
53 53
 
54
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
54
+			$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
55 55
 
56
-        }
56
+		}
57 57
 
58
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
58
+		$is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
59 59
 
60
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
60
+		return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
61 61
 
62
-    }// end is_woocommerce_present
62
+	}// end is_woocommerce_present
63 63
 
64
-    /**
65
-     * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
66
-     *
67
-     * If multiple exist we will return the latest order.
68
-     *
69
-     * @param $user_id
70
-     * @param $course_id
71
-     * @return array $user_course_orders
72
-     */
73
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
64
+	/**
65
+	 * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order.
66
+	 *
67
+	 * If multiple exist we will return the latest order.
68
+	 *
69
+	 * @param $user_id
70
+	 * @param $course_id
71
+	 * @return array $user_course_orders
72
+	 */
73
+	public static function get_learner_course_active_order_id( $user_id, $course_id ){
74 74
 
75
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
75
+		$course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
76 76
 
77
-        $orders_query = new WP_Query( array(
78
-            'post_type'   => 'shop_order',
79
-            'posts_per_page' => -1,
80
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
81
-            'meta_key'=> '_customer_user',
82
-            'meta_value'=> $user_id,
83
-        ) );
77
+		$orders_query = new WP_Query( array(
78
+			'post_type'   => 'shop_order',
79
+			'posts_per_page' => -1,
80
+			'post_status' => array( 'wc-processing', 'wc-completed' ),
81
+			'meta_key'=> '_customer_user',
82
+			'meta_value'=> $user_id,
83
+		) );
84 84
 
85
-        if( $orders_query->post_count == 0 ){
85
+		if( $orders_query->post_count == 0 ){
86 86
 
87
-            return false;
87
+			return false;
88 88
 
89
-        }
89
+		}
90 90
 
91
-        foreach( $orders_query->get_posts() as $order ){
91
+		foreach( $orders_query->get_posts() as $order ){
92 92
 
93
-            $order = new WC_Order( $order->ID );
94
-            $items = $order->get_items();
93
+			$order = new WC_Order( $order->ID );
94
+			$items = $order->get_items();
95 95
 
96
-            $user_orders =  array();
96
+			$user_orders =  array();
97 97
 
98
-            foreach( $items as $item ){
98
+			foreach( $items as $item ){
99 99
 
100
-                // if the product id on the order and the one given to this function
101
-                // this order has been placed by the given user on the given course.
102
-                $product = wc_get_product( $item['product_id'] );
100
+				// if the product id on the order and the one given to this function
101
+				// this order has been placed by the given user on the given course.
102
+				$product = wc_get_product( $item['product_id'] );
103 103
 
104
-                if ( $product->is_type( 'variable' )) {
104
+				if ( $product->is_type( 'variable' )) {
105 105
 
106
-                    $item_product_id = $item['variation_id'];
106
+					$item_product_id = $item['variation_id'];
107 107
 
108
-                } else {
108
+				} else {
109 109
 
110
-                    $item_product_id =  $item['product_id'];
110
+					$item_product_id =  $item['product_id'];
111 111
 
112
-                }
112
+				}
113 113
 
114
-                if( $course_product_id == $item_product_id ){
114
+				if( $course_product_id == $item_product_id ){
115 115
 
116
-                    return $order->id;
116
+					return $order->id;
117 117
 
118
-                }
118
+				}
119 119
 
120 120
 
121
-            }//end for each order item
121
+			}//end for each order item
122 122
 
123
-        } // end for each order
123
+		} // end for each order
124 124
 
125
-        // if we reach this place we found no order
126
-        return false;
125
+		// if we reach this place we found no order
126
+		return false;
127 127
 
128
-    } // end get_learner_course_active_order_ids
128
+	} // end get_learner_course_active_order_ids
129 129
 
130
-    /**
131
-     * Output WooCommerce specific course filters
132
-     * Removing the paged argument
133
-     *
134
-     * @since 1.9.0
135
-     * @param $filter_links
136
-     * @return mixed
137
-     */
138
-    public static function add_course_archive_wc_filter_links( $filter_links ){
130
+	/**
131
+	 * Output WooCommerce specific course filters
132
+	 * Removing the paged argument
133
+	 *
134
+	 * @since 1.9.0
135
+	 * @param $filter_links
136
+	 * @return mixed
137
+	 */
138
+	public static function add_course_archive_wc_filter_links( $filter_links ){
139 139
 
140
-        $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() );
140
+		$course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() );
141 141
 
142
-        $free_courses = self::get_free_courses();
143
-        $paid_courses = self::get_paid_courses();
142
+		$free_courses = self::get_free_courses();
143
+		$paid_courses = self::get_paid_courses();
144 144
 
145
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
146
-            // do not show any WooCommerce filters if all courses are
147
-            // free or if all courses are paid
148
-            return $filter_links;
145
+		if ( empty( $free_courses ) || empty( $paid_courses )  ){
146
+			// do not show any WooCommerce filters if all courses are
147
+			// free or if all courses are paid
148
+			return $filter_links;
149 149
 
150
-        }
150
+		}
151 151
 
152
-        $filter_links[] = array(    'id'=>'paid' ,
153
-                                    'url'=> add_query_arg('course_filter', 'paid', $course_url),
154
-                                    'title'=>__( 'Paid', 'woothemes-sensei' )
155
-        );
152
+		$filter_links[] = array(    'id'=>'paid' ,
153
+									'url'=> add_query_arg('course_filter', 'paid', $course_url),
154
+									'title'=>__( 'Paid', 'woothemes-sensei' )
155
+		);
156 156
 
157
-        $filter_links[] = array(    'id'=>'free',
158
-                                    'url'=>add_query_arg('course_filter', 'free', $course_url),
159
-                                    'title'=>__( 'Free', 'woothemes-sensei' )
160
-        );
157
+		$filter_links[] = array(    'id'=>'free',
158
+									'url'=>add_query_arg('course_filter', 'free', $course_url),
159
+									'title'=>__( 'Free', 'woothemes-sensei' )
160
+		);
161 161
 
162
-        return $filter_links;
162
+		return $filter_links;
163 163
 
164
-    }// end add_course_archive_wc_filter_links
164
+	}// end add_course_archive_wc_filter_links
165 165
 
166
-    /**
167
-     * Apply the free filter the the course query
168
-     * getting all course with no products or products with zero price
169
-     *
170
-     * hooked into pre_get_posts
171
-     *
172
-     * @since 1.9.0
173
-     * @param WP_Query $query
174
-     * @return WP_Query $query
175
-     */
176
-    public static function course_archive_wc_filter_free( $query ){
166
+	/**
167
+	 * Apply the free filter the the course query
168
+	 * getting all course with no products or products with zero price
169
+	 *
170
+	 * hooked into pre_get_posts
171
+	 *
172
+	 * @since 1.9.0
173
+	 * @param WP_Query $query
174
+	 * @return WP_Query $query
175
+	 */
176
+	public static function course_archive_wc_filter_free( $query ){
177 177
 
178
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
178
+		if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
180 180
 
181
-            // setup the course meta query
182
-            $meta_query = self::get_free_courses_meta_query_args();
181
+			// setup the course meta query
182
+			$meta_query = self::get_free_courses_meta_query_args();
183 183
 
184
-            // manipulate the query to return free courses
185
-            $query->set('meta_query', $meta_query );
184
+			// manipulate the query to return free courses
185
+			$query->set('meta_query', $meta_query );
186 186
 
187
-            // don't show any paid courses
188
-            $courses = self::get_paid_courses();
189
-            $ids = array();
190
-            foreach( $courses as $course ){
191
-                $ids[] = $course->ID;
192
-            }
193
-            $query->set( 'post__not_in', $ids );
187
+			// don't show any paid courses
188
+			$courses = self::get_paid_courses();
189
+			$ids = array();
190
+			foreach( $courses as $course ){
191
+				$ids[] = $course->ID;
192
+			}
193
+			$query->set( 'post__not_in', $ids );
194 194
 
195
-        }// end if course_filter
195
+		}// end if course_filter
196 196
 
197
-        return $query;
197
+		return $query;
198 198
 
199
-    }// course_archive_wc_filter_free
199
+	}// course_archive_wc_filter_free
200 200
 
201
-    /**
202
-     * Apply the paid filter to the course query on the courses page
203
-     * will include all course with a product attached with a price
204
-     * more than 0
205
-     *
206
-     * hooked into pre_get_posts
207
-     *
208
-     * @since 1.9.0
209
-     * @param WP_Query $query
210
-     * @return WP_Query $query
211
-     */
212
-    public static function course_archive_wc_filter_paid( $query ){
201
+	/**
202
+	 * Apply the paid filter to the course query on the courses page
203
+	 * will include all course with a product attached with a price
204
+	 * more than 0
205
+	 *
206
+	 * hooked into pre_get_posts
207
+	 *
208
+	 * @since 1.9.0
209
+	 * @param WP_Query $query
210
+	 * @return WP_Query $query
211
+	 */
212
+	public static function course_archive_wc_filter_paid( $query ){
213 213
 
214
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
214
+		if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
+			&& 'course' == $query->get( 'post_type') && $query->is_main_query() ){
216 216
 
217
-            // setup the course meta query
218
-            $meta_query = self::get_paid_courses_meta_query_args();
217
+			// setup the course meta query
218
+			$meta_query = self::get_paid_courses_meta_query_args();
219 219
 
220
-            // manipulate the query to return free courses
221
-            $query->set('meta_query', $meta_query );
222
-
223
-        }
224
-
225
-        return $query;
226
-
227
-    }
228
-
229
-    /**
230
-     * Load the WooCommerce single product actions above
231
-     * single courses if woocommerce is active allowing purchase
232
-     * information and actions to be hooked from WooCommerce.
233
-     */
234
-    public static function do_single_course_wc_single_product_action(){
235
-
236
-        /**
237
-         * this hooks is documented within the WooCommerce plugin.
238
-         */
239
-        if ( Sensei_WC::is_woocommerce_active() ) {
240
-
241
-            do_action( 'woocommerce_before_single_product' );
242
-
243
-        } // End If Statement
244
-
245
-    }// end do_single_course_wc_single_product_action
246
-
247
-    /**
248
-     * Hooking into the single lesson page to alter the
249
-     * user access permissions based on if they have purchased the
250
-     * course the lesson belongs to.
251
-     *
252
-     * This function will only return false or the passed in user_access value.
253
-     * It doesn't return true in order to avoid altering other options.
254
-     *
255
-     * @since 1.9.0
256
-     *
257
-     * @param $can_user_view_lesson
258
-     * @param $lesson_id
259
-     * @param $user_id
260
-     * @return bool
261
-     */
262
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
-
264
-        // check if the course has a valid product attached to it
265
-        // which the user should have purchased if they want to access
266
-        // the current lesson
267
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
269
-        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
-        if( isset ($product) && is_object($product) ){
271
-
272
-            // valid product found
273
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
274
-
275
-            // product has a successful order so this user may access the content
276
-            // this function may only return false or the default
277
-            // returning true may override other negatives which we don't want
278
-            if( ! $order_id ){
279
-
280
-                return false;
281
-
282
-            }
283
-
284
-        }
285
-
286
-        // return the passed in value
287
-        return $can_user_view_lesson;
288
-
289
-    }
290
-
291
-    /**
292
-     * Add course link to order thank you and details pages.
293
-     *
294
-     * @since  1.4.5
295
-     * @access public
296
-     *
297
-     * @return void
298
-     */
299
-    public static function course_link_from_order( ) {
300
-
301
-        if( ! is_order_received_page() ){
302
-            return;
303
-        }
304
-
305
-        $order_id = get_query_var( 'order-received' );
220
+			// manipulate the query to return free courses
221
+			$query->set('meta_query', $meta_query );
222
+
223
+		}
224
+
225
+		return $query;
226
+
227
+	}
228
+
229
+	/**
230
+	 * Load the WooCommerce single product actions above
231
+	 * single courses if woocommerce is active allowing purchase
232
+	 * information and actions to be hooked from WooCommerce.
233
+	 */
234
+	public static function do_single_course_wc_single_product_action(){
235
+
236
+		/**
237
+		 * this hooks is documented within the WooCommerce plugin.
238
+		 */
239
+		if ( Sensei_WC::is_woocommerce_active() ) {
240
+
241
+			do_action( 'woocommerce_before_single_product' );
242
+
243
+		} // End If Statement
244
+
245
+	}// end do_single_course_wc_single_product_action
246
+
247
+	/**
248
+	 * Hooking into the single lesson page to alter the
249
+	 * user access permissions based on if they have purchased the
250
+	 * course the lesson belongs to.
251
+	 *
252
+	 * This function will only return false or the passed in user_access value.
253
+	 * It doesn't return true in order to avoid altering other options.
254
+	 *
255
+	 * @since 1.9.0
256
+	 *
257
+	 * @param $can_user_view_lesson
258
+	 * @param $lesson_id
259
+	 * @param $user_id
260
+	 * @return bool
261
+	 */
262
+	public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
263
+
264
+		// check if the course has a valid product attached to it
265
+		// which the user should have purchased if they want to access
266
+		// the current lesson
267
+		$course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
+		$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
269
+		$product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
+		if( isset ($product) && is_object($product) ){
271
+
272
+			// valid product found
273
+			$order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
274
+
275
+			// product has a successful order so this user may access the content
276
+			// this function may only return false or the default
277
+			// returning true may override other negatives which we don't want
278
+			if( ! $order_id ){
279
+
280
+				return false;
281
+
282
+			}
283
+
284
+		}
285
+
286
+		// return the passed in value
287
+		return $can_user_view_lesson;
288
+
289
+	}
290
+
291
+	/**
292
+	 * Add course link to order thank you and details pages.
293
+	 *
294
+	 * @since  1.4.5
295
+	 * @access public
296
+	 *
297
+	 * @return void
298
+	 */
299
+	public static function course_link_from_order( ) {
300
+
301
+		if( ! is_order_received_page() ){
302
+			return;
303
+		}
304
+
305
+		$order_id = get_query_var( 'order-received' );
306 306
 		$order = new WC_Order( $order_id );
307 307
 
308 308
 		// exit early if not wc-completed or wc-processing
309 309
 		if( 'wc-completed' != $order->post_status
310
-            && 'wc-processing' != $order->post_status  ) {
311
-            return;
312
-        }
310
+			&& 'wc-processing' != $order->post_status  ) {
311
+			return;
312
+		}
313 313
 
314
-        $course_links = array(); // store the for links for courses purchased
314
+		$course_links = array(); // store the for links for courses purchased
315 315
 		foreach ( $order->get_items() as $item ) {
316 316
 
317
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
317
+			if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
318 318
 
319
-                // If item has variation_id then its a variation of the product
320
-                $item_id = $item['variation_id'];
319
+				// If item has variation_id then its a variation of the product
320
+				$item_id = $item['variation_id'];
321 321
 
322
-            } else {
322
+			} else {
323 323
 
324
-                //If not its real product set its id to item_id
325
-                $item_id = $item['product_id'];
324
+				//If not its real product set its id to item_id
325
+				$item_id = $item['product_id'];
326 326
 
327
-            } // End If Statement
327
+			} // End If Statement
328 328
 
329
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
329
+			$user_id = get_post_meta( $order->id, '_customer_user', true );
330 330
 
331
-            if( $user_id ) {
331
+			if( $user_id ) {
332 332
 
333
-                // Get all courses for product
334
-                $args = Sensei_Course::get_default_query_args();
335
-                $args['meta_query'] = array( array(
336
-                            'key' => '_course_woocommerce_product',
337
-                            'value' => $item_id
338
-                        ) );
339
-                $args['orderby'] = 'menu_order date';
340
-                $args['order'] = 'ASC';
333
+				// Get all courses for product
334
+				$args = Sensei_Course::get_default_query_args();
335
+				$args['meta_query'] = array( array(
336
+							'key' => '_course_woocommerce_product',
337
+							'value' => $item_id
338
+						) );
339
+				$args['orderby'] = 'menu_order date';
340
+				$args['order'] = 'ASC';
341 341
 
342
-                // loop through courses
343
-                $courses = get_posts( $args );
344
-                if( $courses && count( $courses ) > 0 ) {
342
+				// loop through courses
343
+				$courses = get_posts( $args );
344
+				if( $courses && count( $courses ) > 0 ) {
345 345
 
346
-                    foreach( $courses as $course ) {
346
+					foreach( $courses as $course ) {
347 347
 
348
-                        $title = $course->post_title;
349
-                        $permalink = get_permalink( $course->ID );
350
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
348
+						$title = $course->post_title;
349
+						$permalink = get_permalink( $course->ID );
350
+						$course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
351 351
 
352
-                    } // end for each
352
+					} // end for each
353 353
 
354
-                    // close the message div
354
+					// close the message div
355 355
 
356
-                }// end if $courses check
357
-            }
358
-        }// end loop through orders
356
+				}// end if $courses check
357
+			}
358
+		}// end loop through orders
359 359
 
360
-        // add the courses to the WooCommerce notice
361
-        if( ! empty( $course_links) ){
360
+		// add the courses to the WooCommerce notice
361
+		if( ! empty( $course_links) ){
362 362
 
363
-            $courses_html = _nx(
364
-                'You have purchased the following course:',
365
-                'You have purchased the following courses:',
366
-                count( $course_links ),
367
-                'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368
-            );
363
+			$courses_html = _nx(
364
+				'You have purchased the following course:',
365
+				'You have purchased the following courses:',
366
+				count( $course_links ),
367
+				'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368
+			);
369 369
 
370
-            foreach( $course_links as $link ){
370
+			foreach( $course_links as $link ){
371 371
 
372
-                $courses_html .= '<li>' . $link . '</li>';
372
+				$courses_html .= '<li>' . $link . '</li>';
373 373
 
374
-            }
374
+			}
375 375
 
376
-            $courses_html .= ' </ul>';
376
+			$courses_html .= ' </ul>';
377 377
 
378
-            wc_add_notice( $courses_html, 'success' );
379
-        }
378
+			wc_add_notice( $courses_html, 'success' );
379
+		}
380 380
 
381 381
 	} // end course_link_order_form
382 382
 
383
-    /**
384
-     * Show the message that a user should complete
385
-     * their purchase if the course is in the cart
386
-     *
387
-     * This should be used within the course loop or single course page
388
-     *
389
-     * @since 1.9.0
390
-     */
391
-    public static function course_in_cart_message(){
383
+	/**
384
+	 * Show the message that a user should complete
385
+	 * their purchase if the course is in the cart
386
+	 *
387
+	 * This should be used within the course loop or single course page
388
+	 *
389
+	 * @since 1.9.0
390
+	 */
391
+	public static function course_in_cart_message(){
392 392
 
393
-        global $post;
393
+		global $post;
394 394
 
395
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
395
+		if( self::is_course_in_cart( $post->ID ) ){ ?>
396 396
 
397 397
             <div class="sensei-message info">'
398 398
                 <?php
399 399
 
400
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
400
+				$cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
+							  . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
+							  . __('complete the purchase', 'woothemes-sensei') . '</a>';
403 403
 
404
-                sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
404
+				sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
405 405
 
406
-                ?>
406
+				?>
407 407
             </div>
408 408
         <?php }
409 409
 
410
-    } // End sensei_woocommerce_in_cart_message()
410
+	} // End sensei_woocommerce_in_cart_message()
411 411
 
412
-    /**
413
-     * Checks the cart to see if a course is in the cart.
414
-     *
415
-     * @param $course_id
416
-     * @return bool
417
-     */
418
-    public static function is_course_in_cart( $course_id ){
419
-
420
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
422
-
423
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
424
-
425
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
426
-
427
-                return true;
428
-
429
-            }
430
-
431
-        }
432
-
433
-        return false;
434
-
435
-    }// is_course_in_cart
436
-
437
-    /**
438
-     * Check the cart to see if the product is in the cart
439
-     *
440
-     * @param $product_id
441
-     * @return bool
442
-     */
443
-    public static function is_product_in_cart( $product_id ){
444
-
445
-        if ( 0 < $product_id ) {
446
-
447
-            $product = wc_get_product( $product_id );
448
-
449
-            $parent_id = '';
450
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
451
-                $wc_product_id = $product->parent->id;
452
-            }
453
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
454
-
455
-                $cart_product = $values['data'];
456
-                if( $product_id == $cart_product->id ) {
457
-
458
-                    return true;
459
-
460
-                }
461
-
462
-            }
463
-        } // End If Statement
464
-
465
-        return false;
466
-
467
-    } // end is_product_in_car
468
-
469
-    /**
470
-     * Get all free WooCommerce products
471
-     *
472
-     * @since 1.9.0
473
-     *
474
-     * @return array $free_products{
475
-     *  @type int $wp_post_id
476
-     * }
477
-     */
478
-    public static function get_free_product_ids(){
479
-
480
-        return  get_posts( array(
481
-            'post_type' => 'product',
482
-            'posts_per_page' => '1000',
483
-            'fields' => 'ids',
484
-            'meta_query'=> array(
485
-                'relation' => 'OR',
486
-                array(
487
-                    'key'=> '_regular_price',
488
-                    'value' => 0,
489
-                ),
490
-                array(
491
-                    'key'=> '_sale_price',
492
-                    'value' => 0,
493
-                ),
494
-            ),
495
-        ));
496
-
497
-    }// end get free product query
498
-
499
-    /**
500
-     * The metat query for courses that are free
501
-     *
502
-     * @since 1.9.0
503
-     * @return array $wp_meta_query_param
504
-     */
505
-    public static function get_free_courses_meta_query_args(){
506
-
507
-        return array(
508
-            'relation' => 'OR',
509
-            array(
510
-                'key'     => '_course_woocommerce_product',
511
-                'value' => '-',
512
-                'compare' => '=',
513
-            ),
514
-            array(
515
-                'key'     => '_course_woocommerce_product',
516
-                'value' => self::get_free_product_ids(),
517
-                'compare' => 'IN',
518
-            ),
519
-        );
520
-
521
-    }// get_free_courses_meta_query
522
-
523
-    /**
524
-     * The metat query for courses that are free
525
-     *
526
-     * @since 1.9.0
527
-     * @return array $wp_query_meta_query_args_param
528
-     */
529
-    public static function get_paid_courses_meta_query_args(){
530
-
531
-        $paid_product_ids = self::get_paid_product_ids();
532
-
533
-        return array(
534
-            array(
535
-                'key'     => '_course_woocommerce_product',
536
-                // when empty we give a false post_id to ensure the caller doesn't get any courses for their
537
-                // query
538
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
539
-                'compare' => 'IN',
540
-            ),
541
-        );
542
-
543
-    }// get_free_courses_meta_query
544
-
545
-    /**
546
-     * The WordPress Query args
547
-     * for paid products on sale
548
-     *
549
-     * @since 1.9.0
550
-     * @return array $product_query_args
551
-     */
552
-    public static function get_paid_products_on_sale_query_args(){
553
-
554
-        $args = array(
555
-                   'post_type' 		=> 'product',
556
-                   'posts_per_page' 		=> 1000,
557
-                   'orderby'         	=> 'date',
558
-                   'order'           	=> 'DESC',
559
-                   'suppress_filters' 	=> 0
560
-        );
561
-
562
-        $args[ 'fields' ]     = 'ids';
563
-
564
-        $args[ 'meta_query' ] = array(
565
-            'relation' => 'AND',
566
-            array(
567
-                'key'=> '_regular_price',
568
-                'compare' => '>',
569
-                'value' => 0,
570
-            ),
571
-            array(
572
-                'key'=> '_sale_price',
573
-                'compare' => '>',
574
-                'value' => 0,
575
-            ),
576
-        );
577
-
578
-        return $args;
579
-
580
-    } // get_paid_products_on_sale_query_args
581
-
582
-
583
-    /**
584
-     * Return the WordPress query args for
585
-     * products not on sale but that is not a free
586
-     *
587
-     * @since 1.9.0
588
-     *
589
-     * @return array
590
-     */
591
-    public static function get_paid_products_not_on_sale_query_args(){
592
-
593
-        $args = array(
594
-            'post_type' 		=> 'product',
595
-            'posts_per_page' 		=> 1000,
596
-            'orderby'         	=> 'date',
597
-            'order'           	=> 'DESC',
598
-            'suppress_filters' 	=> 0
599
-        );
600
-
601
-        $args[ 'fields' ]     = 'ids';
602
-        $args[ 'meta_query' ] = array(
603
-            'relation' => 'AND',
604
-            array(
605
-                'key'=> '_regular_price',
606
-                'compare' => '>',
607
-                'value' => 0,
608
-            ),
609
-            array(
610
-                'key'=> '_sale_price',
611
-                'compare' => '=',
612
-                'value' => '',
613
-            ),
614
-        );
615
-
616
-        return $args;
617
-
618
-
619
-    } // get_paid_courses_meta_query
620
-
621
-    /**
622
-     * Get all WooCommerce non-free product id's
623
-     *
624
-     * @since 1.9.0
625
-     *
626
-     * @return array $woocommerce_paid_product_ids
627
-     */
628
-    public static function get_paid_product_ids(){
629
-
630
-        // get all the paid WooCommerce products that has regular
631
-        // and sale price greater than 0
632
-        // will be used later to check for course with the id as meta
633
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
634
-
635
-        // get all the paid WooCommerce products that has regular price
636
-        // greater than 0 without a sale price
637
-        // will be used later to check for course with the id as meta
638
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
639
-
640
-        // combine products ID's with regular and sale price grater than zero and those without
641
-        // sale but regular price greater than zero
642
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
643
-
644
-        // if
645
-        if( empty($woocommerce_paid_product_ids) ){
646
-            return array( );
647
-        }
648
-        return $woocommerce_paid_product_ids;
649
-
650
-    }
651
-
652
-    /**
653
-     * Get all free courses.
654
-     *
655
-     * This course that have a WC product attached
656
-     * that has a price or sale price of zero and
657
-     * other courses with no WooCommerce products
658
-     * attached.
659
-     *
660
-     * @since 1.9.0
661
-     *
662
-     * @return array
663
-     */
664
-    public static function get_free_courses(){
665
-
666
-        $free_course_query_args = Sensei_Course::get_default_query_args();
667
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
668
-
669
-        // don't show any paid courses
670
-        $courses = self::get_paid_courses();
671
-        $ids = array();
672
-        foreach( $courses as $course ){
673
-            $ids[] = $course->ID;
674
-        }
675
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
676
-
677
-        return get_posts( $free_course_query_args );
678
-
679
-    }
680
-
681
-    /**
682
-     * Return all products that are not free
683
-     *
684
-     * @since 1.9.0
685
-     * @return array
686
-     */
687
-    public static function get_paid_courses(){
688
-
689
-        $paid_course_query_args = Sensei_Course::get_default_query_args();
690
-
691
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
692
-
693
-        return get_posts(  $paid_course_query_args );
694
-    }
695
-
696
-    /**
697
-     * Show the WooCommerce add to cart button for the  current course
698
-     *
699
-     * The function will only show the button if
700
-     * 1- the user can buy the course
701
-     * 2- if they have completed their pre-requisite
702
-     * 3- if the course has a valid product attached
703
-     *
704
-     * @since 1.9.0
705
-     * @param int $course_id
706
-     * @return string $html markup for the button or nothing if user not allowed to buy
707
-     */
708
-    public static function the_add_to_cart_button_html( $course_id ){
709
-
710
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
711
-            return '';
712
-        }
713
-
714
-        $wc_post_id = self::get_course_product_id( $course_id );
715
-
716
-        // Check if customer purchased the product
717
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
-            || empty( $wc_post_id ) ) {
719
-
720
-            return '';
721
-
722
-        }
723
-
724
-        // based on simple.php in WC templates/single-product/add-to-cart/
725
-        // Get the product
726
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
727
-
728
-        // do not show the button for invalid products, non purchasable products, out
729
-        // of stock product or if course is already in cart
730
-        if ( ! isset ( $product )
731
-            || ! is_object( $product )
732
-            || ! $product->is_purchasable()
733
-            || ! $product->is_in_stock()
734
-            || self::is_course_in_cart( $wc_post_id ) ) {
735
-
736
-            return '';
737
-
738
-        }
739
-
740
-        //
741
-        // button  output:
742
-        //
743
-        ?>
412
+	/**
413
+	 * Checks the cart to see if a course is in the cart.
414
+	 *
415
+	 * @param $course_id
416
+	 * @return bool
417
+	 */
418
+	public static function is_course_in_cart( $course_id ){
419
+
420
+		$wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
+		$user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
422
+
423
+		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
424
+
425
+			if ( self::is_product_in_cart( $wc_post_id ) ) {
426
+
427
+				return true;
428
+
429
+			}
430
+
431
+		}
432
+
433
+		return false;
434
+
435
+	}// is_course_in_cart
436
+
437
+	/**
438
+	 * Check the cart to see if the product is in the cart
439
+	 *
440
+	 * @param $product_id
441
+	 * @return bool
442
+	 */
443
+	public static function is_product_in_cart( $product_id ){
444
+
445
+		if ( 0 < $product_id ) {
446
+
447
+			$product = wc_get_product( $product_id );
448
+
449
+			$parent_id = '';
450
+			if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
451
+				$wc_product_id = $product->parent->id;
452
+			}
453
+			foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
454
+
455
+				$cart_product = $values['data'];
456
+				if( $product_id == $cart_product->id ) {
457
+
458
+					return true;
459
+
460
+				}
461
+
462
+			}
463
+		} // End If Statement
464
+
465
+		return false;
466
+
467
+	} // end is_product_in_car
468
+
469
+	/**
470
+	 * Get all free WooCommerce products
471
+	 *
472
+	 * @since 1.9.0
473
+	 *
474
+	 * @return array $free_products{
475
+	 *  @type int $wp_post_id
476
+	 * }
477
+	 */
478
+	public static function get_free_product_ids(){
479
+
480
+		return  get_posts( array(
481
+			'post_type' => 'product',
482
+			'posts_per_page' => '1000',
483
+			'fields' => 'ids',
484
+			'meta_query'=> array(
485
+				'relation' => 'OR',
486
+				array(
487
+					'key'=> '_regular_price',
488
+					'value' => 0,
489
+				),
490
+				array(
491
+					'key'=> '_sale_price',
492
+					'value' => 0,
493
+				),
494
+			),
495
+		));
496
+
497
+	}// end get free product query
498
+
499
+	/**
500
+	 * The metat query for courses that are free
501
+	 *
502
+	 * @since 1.9.0
503
+	 * @return array $wp_meta_query_param
504
+	 */
505
+	public static function get_free_courses_meta_query_args(){
506
+
507
+		return array(
508
+			'relation' => 'OR',
509
+			array(
510
+				'key'     => '_course_woocommerce_product',
511
+				'value' => '-',
512
+				'compare' => '=',
513
+			),
514
+			array(
515
+				'key'     => '_course_woocommerce_product',
516
+				'value' => self::get_free_product_ids(),
517
+				'compare' => 'IN',
518
+			),
519
+		);
520
+
521
+	}// get_free_courses_meta_query
522
+
523
+	/**
524
+	 * The metat query for courses that are free
525
+	 *
526
+	 * @since 1.9.0
527
+	 * @return array $wp_query_meta_query_args_param
528
+	 */
529
+	public static function get_paid_courses_meta_query_args(){
530
+
531
+		$paid_product_ids = self::get_paid_product_ids();
532
+
533
+		return array(
534
+			array(
535
+				'key'     => '_course_woocommerce_product',
536
+				// when empty we give a false post_id to ensure the caller doesn't get any courses for their
537
+				// query
538
+				'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
539
+				'compare' => 'IN',
540
+			),
541
+		);
542
+
543
+	}// get_free_courses_meta_query
544
+
545
+	/**
546
+	 * The WordPress Query args
547
+	 * for paid products on sale
548
+	 *
549
+	 * @since 1.9.0
550
+	 * @return array $product_query_args
551
+	 */
552
+	public static function get_paid_products_on_sale_query_args(){
553
+
554
+		$args = array(
555
+				   'post_type' 		=> 'product',
556
+				   'posts_per_page' 		=> 1000,
557
+				   'orderby'         	=> 'date',
558
+				   'order'           	=> 'DESC',
559
+				   'suppress_filters' 	=> 0
560
+		);
561
+
562
+		$args[ 'fields' ]     = 'ids';
563
+
564
+		$args[ 'meta_query' ] = array(
565
+			'relation' => 'AND',
566
+			array(
567
+				'key'=> '_regular_price',
568
+				'compare' => '>',
569
+				'value' => 0,
570
+			),
571
+			array(
572
+				'key'=> '_sale_price',
573
+				'compare' => '>',
574
+				'value' => 0,
575
+			),
576
+		);
577
+
578
+		return $args;
579
+
580
+	} // get_paid_products_on_sale_query_args
581
+
582
+
583
+	/**
584
+	 * Return the WordPress query args for
585
+	 * products not on sale but that is not a free
586
+	 *
587
+	 * @since 1.9.0
588
+	 *
589
+	 * @return array
590
+	 */
591
+	public static function get_paid_products_not_on_sale_query_args(){
592
+
593
+		$args = array(
594
+			'post_type' 		=> 'product',
595
+			'posts_per_page' 		=> 1000,
596
+			'orderby'         	=> 'date',
597
+			'order'           	=> 'DESC',
598
+			'suppress_filters' 	=> 0
599
+		);
600
+
601
+		$args[ 'fields' ]     = 'ids';
602
+		$args[ 'meta_query' ] = array(
603
+			'relation' => 'AND',
604
+			array(
605
+				'key'=> '_regular_price',
606
+				'compare' => '>',
607
+				'value' => 0,
608
+			),
609
+			array(
610
+				'key'=> '_sale_price',
611
+				'compare' => '=',
612
+				'value' => '',
613
+			),
614
+		);
615
+
616
+		return $args;
617
+
618
+
619
+	} // get_paid_courses_meta_query
620
+
621
+	/**
622
+	 * Get all WooCommerce non-free product id's
623
+	 *
624
+	 * @since 1.9.0
625
+	 *
626
+	 * @return array $woocommerce_paid_product_ids
627
+	 */
628
+	public static function get_paid_product_ids(){
629
+
630
+		// get all the paid WooCommerce products that has regular
631
+		// and sale price greater than 0
632
+		// will be used later to check for course with the id as meta
633
+		$paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
634
+
635
+		// get all the paid WooCommerce products that has regular price
636
+		// greater than 0 without a sale price
637
+		// will be used later to check for course with the id as meta
638
+		$paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
639
+
640
+		// combine products ID's with regular and sale price grater than zero and those without
641
+		// sale but regular price greater than zero
642
+		$woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
643
+
644
+		// if
645
+		if( empty($woocommerce_paid_product_ids) ){
646
+			return array( );
647
+		}
648
+		return $woocommerce_paid_product_ids;
649
+
650
+	}
651
+
652
+	/**
653
+	 * Get all free courses.
654
+	 *
655
+	 * This course that have a WC product attached
656
+	 * that has a price or sale price of zero and
657
+	 * other courses with no WooCommerce products
658
+	 * attached.
659
+	 *
660
+	 * @since 1.9.0
661
+	 *
662
+	 * @return array
663
+	 */
664
+	public static function get_free_courses(){
665
+
666
+		$free_course_query_args = Sensei_Course::get_default_query_args();
667
+		$free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
668
+
669
+		// don't show any paid courses
670
+		$courses = self::get_paid_courses();
671
+		$ids = array();
672
+		foreach( $courses as $course ){
673
+			$ids[] = $course->ID;
674
+		}
675
+		$free_course_query_args[ 'post__not_in' ] =  $ids;
676
+
677
+		return get_posts( $free_course_query_args );
678
+
679
+	}
680
+
681
+	/**
682
+	 * Return all products that are not free
683
+	 *
684
+	 * @since 1.9.0
685
+	 * @return array
686
+	 */
687
+	public static function get_paid_courses(){
688
+
689
+		$paid_course_query_args = Sensei_Course::get_default_query_args();
690
+
691
+		$paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
692
+
693
+		return get_posts(  $paid_course_query_args );
694
+	}
695
+
696
+	/**
697
+	 * Show the WooCommerce add to cart button for the  current course
698
+	 *
699
+	 * The function will only show the button if
700
+	 * 1- the user can buy the course
701
+	 * 2- if they have completed their pre-requisite
702
+	 * 3- if the course has a valid product attached
703
+	 *
704
+	 * @since 1.9.0
705
+	 * @param int $course_id
706
+	 * @return string $html markup for the button or nothing if user not allowed to buy
707
+	 */
708
+	public static function the_add_to_cart_button_html( $course_id ){
709
+
710
+		if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
711
+			return '';
712
+		}
713
+
714
+		$wc_post_id = self::get_course_product_id( $course_id );
715
+
716
+		// Check if customer purchased the product
717
+		if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
+			|| empty( $wc_post_id ) ) {
719
+
720
+			return '';
721
+
722
+		}
723
+
724
+		// based on simple.php in WC templates/single-product/add-to-cart/
725
+		// Get the product
726
+		$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
727
+
728
+		// do not show the button for invalid products, non purchasable products, out
729
+		// of stock product or if course is already in cart
730
+		if ( ! isset ( $product )
731
+			|| ! is_object( $product )
732
+			|| ! $product->is_purchasable()
733
+			|| ! $product->is_in_stock()
734
+			|| self::is_course_in_cart( $wc_post_id ) ) {
735
+
736
+			return '';
737
+
738
+		}
739
+
740
+		//
741
+		// button  output:
742
+		//
743
+		?>
744 744
 
745 745
         <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
746 746
               class="cart"
@@ -773,54 +773,54 @@  discard block
 block discarded – undo
773 773
         </form>
774 774
 
775 775
         <?php
776
-    } // end the_add_to_cart_button_html
776
+	} // end the_add_to_cart_button_html
777 777
 
778
-    /**
779
-     * Alter the no permissions message on the single course page
780
-     * Changes the message to a WooCommerce specific message.
781
-     *
782
-     * @since 1.9.0
783
-     *
784
-     * @param $message
785
-     * @param $post_id
786
-     *
787
-     * @return string $message
788
-     */
789
-    public static function alter_no_permissions_message( $message, $post_id ){
778
+	/**
779
+	 * Alter the no permissions message on the single course page
780
+	 * Changes the message to a WooCommerce specific message.
781
+	 *
782
+	 * @since 1.9.0
783
+	 *
784
+	 * @param $message
785
+	 * @param $post_id
786
+	 *
787
+	 * @return string $message
788
+	 */
789
+	public static function alter_no_permissions_message( $message, $post_id ){
790 790
 
791
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
792
-            return  $message;
793
-        }
791
+		if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
792
+			return  $message;
793
+		}
794 794
 
795
-        $product_id = self::get_course_product_id( $post_id );
795
+		$product_id = self::get_course_product_id( $post_id );
796 796
 
797
-        if( ! $product_id
798
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
797
+		if( ! $product_id
798
+			|| self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
799 799
 
800
-            return $message;
800
+			return $message;
801 801
 
802
-        }
802
+		}
803 803
 
804
-        ob_start();
805
-        self::the_course_no_permissions_message( $post_id );
806
-        $woocommerce_course_no_permissions_message = ob_get_clean();
804
+		ob_start();
805
+		self::the_course_no_permissions_message( $post_id );
806
+		$woocommerce_course_no_permissions_message = ob_get_clean();
807 807
 
808
-        return $woocommerce_course_no_permissions_message ;
808
+		return $woocommerce_course_no_permissions_message ;
809 809
 
810
-    }
811
-    /**
812
-     * Show the no permissions message when a user is logged in
813
-     * and have not yet purchased the current course
814
-     *
815
-     * @since 1.9.0
816
-     */
817
-    public static function the_course_no_permissions_message( $course_id ){
810
+	}
811
+	/**
812
+	 * Show the no permissions message when a user is logged in
813
+	 * and have not yet purchased the current course
814
+	 *
815
+	 * @since 1.9.0
816
+	 */
817
+	public static function the_course_no_permissions_message( $course_id ){
818 818
 
819
-        // login link
820
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
819
+		// login link
820
+		$my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
+		$login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
822 822
 
823
-        ?>
823
+		?>
824 824
 
825 825
         <span class="add-to-cart-login">
826 826
             <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
@@ -828,110 +828,110 @@  discard block
 block discarded – undo
828 828
 
829 829
     <?php }
830 830
 
831
-    /**
832
-     * Checks if a user has bought a product item.
833
-     *
834
-     * @since  1.9.0
835
-     *
836
-     * @param  int $user_id
837
-     * @param  int $product_id
838
-     *
839
-     * @return bool
840
-     */
841
-    public static function has_customer_bought_product ( $user_id, $product_id ){
831
+	/**
832
+	 * Checks if a user has bought a product item.
833
+	 *
834
+	 * @since  1.9.0
835
+	 *
836
+	 * @param  int $user_id
837
+	 * @param  int $product_id
838
+	 *
839
+	 * @return bool
840
+	 */
841
+	public static function has_customer_bought_product ( $user_id, $product_id ){
842 842
 
843
-        $orders = get_posts( array(
844
-            'posts_per_page' => -1,
845
-            'meta_key'    => '_customer_user',
846
-            'meta_value'  => intval( $user_id ),
847
-            'post_type'   => 'shop_order',
848
-            'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
-        ) );
843
+		$orders = get_posts( array(
844
+			'posts_per_page' => -1,
845
+			'meta_key'    => '_customer_user',
846
+			'meta_value'  => intval( $user_id ),
847
+			'post_type'   => 'shop_order',
848
+			'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
+		) );
850 850
 
851
-        foreach ( $orders as $order_id ) {
851
+		foreach ( $orders as $order_id ) {
852 852
 
853
-            $order = new WC_Order( $order_id->ID );
853
+			$order = new WC_Order( $order_id->ID );
854 854
 
855
-            if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
855
+			if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
856 856
 
857
-                continue;
858
-            }
857
+				continue;
858
+			}
859 859
 
860
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
860
+			if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
861 861
 
862
-                continue;
862
+				continue;
863 863
 
864
-            }
864
+			}
865 865
 
866
-            foreach( $order->get_items() as $item ) {
866
+			foreach( $order->get_items() as $item ) {
867 867
 
868
-                // Check if user has bought product
869
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
868
+				// Check if user has bought product
869
+				if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
870 870
 
871
-                    // Check if user has an active subscription for product
872
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
-                        $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
-                        if( $sub_key ) {
875
-                            $sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
-                            if( $sub && isset( $sub['status'] ) ) {
877
-                                if( 'active' == $sub['status'] ) {
878
-                                    return true;
879
-                                } else {
880
-                                    return false;
881
-                                }
882
-                            }
883
-                        }
884
-                    }
871
+					// Check if user has an active subscription for product
872
+					if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
+						$sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
+						if( $sub_key ) {
875
+							$sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
+							if( $sub && isset( $sub['status'] ) ) {
877
+								if( 'active' == $sub['status'] ) {
878
+									return true;
879
+								} else {
880
+									return false;
881
+								}
882
+							}
883
+						}
884
+					}
885 885
 
886
-                    // Customer has bought product
887
-                    return true;
888
-                } // End If Statement
886
+					// Customer has bought product
887
+					return true;
888
+				} // End If Statement
889 889
 
890
-            } // End For each item
890
+			} // End For each item
891 891
 
892
-        } // End For each order
892
+		} // End For each order
893 893
 
894
-    } // end has customer bought product
894
+	} // end has customer bought product
895 895
 
896
-    /**
897
-     * Return the product id for the given course
898
-     *
899
-     * @since 1.9.0
900
-     *
901
-     * @param int $course_id
902
-     *
903
-     * @return string $woocommerce_product_id or false if none exist
904
-     *
905
-     */
906
-    public static function get_course_product_id( $course_id ){
896
+	/**
897
+	 * Return the product id for the given course
898
+	 *
899
+	 * @since 1.9.0
900
+	 *
901
+	 * @param int $course_id
902
+	 *
903
+	 * @return string $woocommerce_product_id or false if none exist
904
+	 *
905
+	 */
906
+	public static function get_course_product_id( $course_id ){
907 907
 
908
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
908
+		$product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
909 909
 
910
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
911
-            return false;
912
-        }
910
+		if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
911
+			return false;
912
+		}
913 913
 
914
-        return $product_id;
914
+		return $product_id;
915 915
 
916
-    }
916
+	}
917 917
 
918
-    /**
919
-     * Alter the body classes adding WooCommerce to the body
920
-     *
921
-     * @param array $classes
922
-     * @return array
923
-     */
924
-    public static function add_woocommerce_body_class( $classes ){
918
+	/**
919
+	 * Alter the body classes adding WooCommerce to the body
920
+	 *
921
+	 * @param array $classes
922
+	 * @return array
923
+	 */
924
+	public static function add_woocommerce_body_class( $classes ){
925 925
 
926
-        if( ! in_array( 'woocommerce', $classes ) ){
926
+		if( ! in_array( 'woocommerce', $classes ) ){
927 927
 
928
-            $classes[] ='woocommerce';
928
+			$classes[] ='woocommerce';
929 929
 
930
-        }
930
+		}
931 931
 
932 932
 
933
-        return $classes;
933
+		return $classes;
934 934
 
935
-    }
935
+	}
936 936
 
937 937
 }// end Sensei_WC
Please login to merge, or discard this patch.