Completed
Push — master ( 77803a...2e041b )
by Dwain
26:34
created
includes/class-sensei-analysis-lesson-list-table.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 		}
231 231
 
232 232
 		// Output users data
233
-        $user_name = Sensei_Learner::get_full_name( $item->user_id );
233
+		$user_name = Sensei_Learner::get_full_name( $item->user_id );
234 234
 
235
-        if ( !$this->csv_output ) {
235
+		if ( !$this->csv_output ) {
236 236
 			$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) );
237 237
 
238 238
 			$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $user_name . '</a></strong>';
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
 	 */
340 340
 	public function search_button( $text = '' ) {
341 341
 
342
-        $text =  __( 'Search Learners', 'woothemes-sensei' );
342
+		$text =  __( 'Search Learners', 'woothemes-sensei' );
343 343
 
344
-        return $text;
344
+		return $text;
345 345
 
346 346
 	}
347 347
 } // End Class
Please login to merge, or discard this patch.
includes/class-sensei-learner.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,46 +13,46 @@
 block discarded – undo
13 13
  */
14 14
 class Sensei_Student{
15 15
 
16
-    /**
17
-     * Get the students full name
18
-     *
19
-     * This function replaces Sensei_Learner_Managment->get_learner_full_name
20
-     * @since 1.9.0
21
-     *
22
-     * @param $user_id
23
-     * @return bool|mixed|void
24
-     */
25
-    public static function get_full_name( $user_id ){
16
+	/**
17
+	 * Get the students full name
18
+	 *
19
+	 * This function replaces Sensei_Learner_Managment->get_learner_full_name
20
+	 * @since 1.9.0
21
+	 *
22
+	 * @param $user_id
23
+	 * @return bool|mixed|void
24
+	 */
25
+	public static function get_full_name( $user_id ){
26 26
 
27
-        $full_name = '';
27
+		$full_name = '';
28 28
 
29
-        if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
30
-            || !( get_userdata( $user_id ) ) ){
31
-            return false;
32
-        }
29
+		if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
30
+			|| !( get_userdata( $user_id ) ) ){
31
+			return false;
32
+		}
33 33
 
34
-        // get the user details
35
-        $user = get_user_by( 'id', $user_id );
34
+		// get the user details
35
+		$user = get_user_by( 'id', $user_id );
36 36
 
37
-        if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
37
+		if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
38 38
 
39
-            $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
39
+			$full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
40 40
 
41
-        }else{
41
+		}else{
42 42
 
43
-            $full_name =  $user->display_name;
43
+			$full_name =  $user->display_name;
44 44
 
45
-        }
45
+		}
46 46
 
47
-        /**
48
-         * Filter the user full name from the get_learner_full_name function.
49
-         *
50
-         * @since 1.8.0
51
-         * @param $full_name
52
-         * @param $user_id
53
-         */
54
-        return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
47
+		/**
48
+		 * Filter the user full name from the get_learner_full_name function.
49
+		 *
50
+		 * @since 1.8.0
51
+		 * @param $full_name
52
+		 * @param $user_id
53
+		 */
54
+		return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
55 55
 
56
-    }// end get_full_name
56
+	}// end get_full_name
57 57
 
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei-analysis-course-list-table.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -627,7 +627,7 @@
 block discarded – undo
627 627
 		$course = get_post( $this->course_id );
628 628
 		$report = sanitize_title( $course->post_title ) . '-' . $this->view . 's-overview';
629 629
 		if ( $this->user_id ) {
630
-            $user_name = Sensei_Learner::get_full_name( $this->user_id );
630
+			$user_name = Sensei_Learner::get_full_name( $this->user_id );
631 631
 			$report = sanitize_title( $user_name  ) . '-' . $report;
632 632
 		}
633 633
 
Please login to merge, or discard this patch.
includes/class-sensei-frontend.php 1 patch
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
 		// Only show course & lesson excerpts in search results
70 70
 		add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) );
71 71
 
72
-        //Use WooCommerce filter to show admin bar to Teachers.
73
-        add_action( 'init', array( $this, 'sensei_show_admin_bar') );
72
+		//Use WooCommerce filter to show admin bar to Teachers.
73
+		add_action( 'init', array( $this, 'sensei_show_admin_bar') );
74 74
 
75
-        // Remove course from active courses if an order is cancelled or refunded
75
+		// Remove course from active courses if an order is cancelled or refunded
76 76
 		add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
77 77
 		add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
78 78
 		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
 			wp_enqueue_script( Sensei()->token . '-user-dashboard' );
134 134
 
135 135
 
136
-            // Course Archive javascript
137
-            if( is_post_type_archive( 'course' ) ){
136
+			// Course Archive javascript
137
+			if( is_post_type_archive( 'course' ) ){
138 138
 
139
-                wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
140
-                wp_enqueue_script( 'sensei-course-archive-js' );
139
+				wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
140
+				wp_enqueue_script( 'sensei-course-archive-js' );
141 141
 
142
-            }
142
+			}
143 143
 
144 144
 
145 145
 			// Allow additional scripts to be loaded
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	/**
181 181
 	 * sensei_get_template_part function.
182 182
 	 *
183
-     * @deprecated sine 1.9.0
183
+	 * @deprecated sine 1.9.0
184 184
 	 * @access public
185 185
 	 * @param mixed $slug
186 186
 	 * @param string $name (default: '')
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	function sensei_get_template_part( $slug, $name = '' ) {
190 190
 
191
-        _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' );
192
-        Sensei_Templates::get_part( $slug, $name );
191
+		_deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' );
192
+		Sensei_Templates::get_part( $slug, $name );
193 193
 
194 194
 	} // End sensei_get_template_part()
195 195
 
196 196
 	/**
197 197
 	 * sensei_get_template function.
198 198
 	 *
199
-     * @deprecated since 1.9.0
199
+	 * @deprecated since 1.9.0
200 200
 	 * @access public
201 201
 	 * @param mixed $template_name
202 202
 	 * @param array $args (default: array())
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 */
207 207
 	function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
208 208
 
209
-        _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
210
-        Sensei_Templates::get_template($template_name, $args, $template_path, $default_path  );
209
+		_deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
210
+		Sensei_Templates::get_template($template_name, $args, $template_path, $default_path  );
211 211
 
212 212
 	} // End sensei_get_template()
213 213
 
@@ -223,33 +223,33 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) {
225 225
 
226
-        _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
227
-        Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
226
+		_deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
227
+		Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
228 228
 
229 229
 	} // End sensei_locate_template()
230 230
 
231 231
 
232 232
 	/**
233 233
 	 * sensei_output_content_wrapper function.
234
-     *
234
+	 *
235 235
 	 * @access public
236 236
 	 * @return void
237 237
 	 */
238 238
 	function sensei_output_content_wrapper() {
239 239
 
240
-	    // backwards compatibility check for old location under the wrappers directory of the active theme
241
-        $backwards_compatible_wrapper_location =   array(
242
-            Sensei()->template_url . 'wrappers/wrapper-start.php',
243
-            'wrappers/wrapper-start.php'
244
-        );
240
+		// backwards compatibility check for old location under the wrappers directory of the active theme
241
+		$backwards_compatible_wrapper_location =   array(
242
+			Sensei()->template_url . 'wrappers/wrapper-start.php',
243
+			'wrappers/wrapper-start.php'
244
+		);
245 245
 
246
-        $template = locate_template( $backwards_compatible_wrapper_location );
247
-        if( !empty( $template ) ){
246
+		$template = locate_template( $backwards_compatible_wrapper_location );
247
+		if( !empty( $template ) ){
248 248
 
249
-            Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
250
-            return;
249
+			Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
250
+			return;
251 251
 
252
-        }
252
+		}
253 253
 
254 254
 		Sensei_Templates::get_template( 'globals/wrapper-start.php' );
255 255
 
@@ -258,25 +258,25 @@  discard block
 block discarded – undo
258 258
 
259 259
 	/**
260 260
 	 * sensei_output_content_wrapper_end function.
261
-     *
261
+	 *
262 262
 	 * @access public
263 263
 	 * @return void
264 264
 	 */
265 265
 	function sensei_output_content_wrapper_end() {
266 266
 
267
-	    // backwards compatibility check for old location under the wrappers directory of the active theme
268
-        $backwards_compatible_wrapper_location =   array(
269
-            Sensei()->template_url . 'wrappers/wrapper-end.php',
270
-            'wrappers/wrapper-end.php'
271
-        );
267
+		// backwards compatibility check for old location under the wrappers directory of the active theme
268
+		$backwards_compatible_wrapper_location =   array(
269
+			Sensei()->template_url . 'wrappers/wrapper-end.php',
270
+			'wrappers/wrapper-end.php'
271
+		);
272 272
 
273
-        $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
274
-        if( !empty( $backwards_compatible_template ) ){
273
+		$backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
274
+		if( !empty( $backwards_compatible_template ) ){
275 275
 
276
-            Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
277
-            return;
276
+			Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
277
+			return;
278 278
 
279
-        }
279
+		}
280 280
 
281 281
 
282 282
 		Sensei_Templates::get_template( 'globals/wrapper-end.php' );
@@ -292,55 +292,55 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	public static function load_content_pagination() {
294 294
 
295
-        if( is_singular('course') ) {
295
+		if( is_singular('course') ) {
296 296
 
297
-            // backwards compatibility check for old location under the wrappers directory of the active theme
298
-            $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
299
-            if( !empty( $template ) ){
297
+			// backwards compatibility check for old location under the wrappers directory of the active theme
298
+			$template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
299
+			if( !empty( $template ) ){
300 300
 
301
-                Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
302
-                return;
301
+				Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
302
+				return;
303 303
 
304
-            }
304
+			}
305 305
 
306 306
 			Sensei_Templates::get_template( 'globals/pagination-posts.php' );
307 307
 
308 308
 		} elseif( is_singular('lesson') ) {
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-lesson.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-lesson.php' ) );
312
+			if( !empty( $template ) ){
313 313
 
314
-                Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
315
-                return;
314
+				Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
315
+				return;
316 316
 
317
-            }
317
+			}
318 318
 
319 319
 			Sensei_Templates::get_template( 'globals/pagination-lesson.php' );
320 320
 
321 321
 		} elseif( is_singular('quiz') ) {
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-quiz.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-quiz.php' ) );
325
+			if( !empty( $template ) ){
326 326
 
327
-                Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
328
-                return;
327
+				Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
328
+				return;
329 329
 
330
-            }
330
+			}
331 331
 
332 332
 			Sensei_Templates::get_template( 'globals/pagination-quiz.php' );
333 333
 
334 334
 		} else {
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.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.php' ) );
338
+			if( !empty( $template ) ){
339 339
 
340
-                Sensei_Templates::get_template( 'wrappers/pagination.php' );
341
-                return;
340
+				Sensei_Templates::get_template( 'wrappers/pagination.php' );
341
+				return;
342 342
 
343
-            }
343
+			}
344 344
 
345 345
 			Sensei_Templates::get_template( 'globals/pagination.php' );
346 346
 
@@ -397,13 +397,13 @@  discard block
 block discarded – undo
397 397
 
398 398
 				case '#senseimymessages':
399 399
 					$item->url = $my_messages_url;
400
-                    // if no archive link exist for sensei_message
401
-                    // set it back to the place holder
402
-                    if( ! $item->url ){
400
+					// if no archive link exist for sensei_message
401
+					// set it back to the place holder
402
+					if( ! $item->url ){
403 403
 
404
-                        $item->url = '#senseimymessages';
404
+						$item->url = '#senseimymessages';
405 405
 
406
-                    }
406
+					}
407 407
 					break;
408 408
 
409 409
 				case '#senseilearnerprofile':
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
 
470 470
 			// Remove the My Messages link for logged out users or if Private Messages are disabled
471 471
 			if( ! get_post_type_archive_link( 'sensei_message' )
472
-                && '#senseimymessages' == $item->url ) {
472
+				&& '#senseimymessages' == $item->url ) {
473 473
 
474 474
 				if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) {
475 475
 
@@ -492,42 +492,42 @@  discard block
 block discarded – undo
492 492
 
493 493
 	// add category nicenames in body and post class
494 494
 	function sensei_search_results_classes($classes) {
495
-	    global $post;
496
-	    // Handle Search Classes for Courses, Lessons, and WC Products
497
-	    if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
498
-	    	$classes[] = 'post';
495
+		global $post;
496
+		// Handle Search Classes for Courses, Lessons, and WC Products
497
+		if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
498
+			$classes[] = 'post';
499 499
 		} // End If Statement
500
-	    return $classes;
500
+		return $classes;
501 501
 	} // End sensei_search_results_classes()
502 502
 
503
-    /**
504
-     * sensei_single_title output for single page title
505
-     * @since  1.1.0
506
-     * @return void
507
-     * @deprecated
508
-     */
509
-    function the_single_title() {
503
+	/**
504
+	 * sensei_single_title output for single page title
505
+	 * @since  1.1.0
506
+	 * @return void
507
+	 * @deprecated
508
+	 */
509
+	function the_single_title() {
510 510
 
511
-        _deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0');
511
+		_deprecated_function(' WooThemes_Sensei_Frontend::the_single_title', '1.9.0');
512 512
 
513
-    } // End sensei_single_title()
513
+	} // End sensei_single_title()
514 514
 
515 515
 	/**
516 516
 	 * sensei_course_image output for course image Please use Sensei()->course->course_image instead.
517
-     *
518
-     * @deprecated since 1.9.0
519
-     * @param $course_id
520
-     * @param string $width
521
-     * @param string $height
522
-     * @param bool|false $return
523
-     * @return string|void
517
+	 *
518
+	 * @deprecated since 1.9.0
519
+	 * @param $course_id
520
+	 * @param string $width
521
+	 * @param string $height
522
+	 * @param bool|false $return
523
+	 * @return string|void
524 524
 	 */
525 525
 	function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) {
526 526
 
527
-    	if ( ! $return ) {
527
+		if ( ! $return ) {
528 528
 
529 529
 			echo Sensei()->course->course_image( $course_id, $width, $height );
530
-            return '';
530
+			return '';
531 531
 
532 532
 		} // End If Statement
533 533
 
@@ -538,31 +538,31 @@  discard block
 block discarded – undo
538 538
 	/**
539 539
 	 * sensei_lesson_image output for lesson image
540 540
 	 * @since  1.2.0
541
-     * @deprecated since 1.9.0
542
-     * @param $lesson_id
543
-     * @param string $width
544
-     * @param string $height
545
-     * @param bool|false $return
546
-     * @param bool|false $widget
547
-     * @return string
541
+	 * @deprecated since 1.9.0
542
+	 * @param $lesson_id
543
+	 * @param string $width
544
+	 * @param string $height
545
+	 * @param bool|false $return
546
+	 * @param bool|false $widget
547
+	 * @return string
548 548
 	 */
549 549
 	function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) {
550 550
 
551
-        if( ! $return ){
551
+		if( ! $return ){
552 552
 
553
-            echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
554
-            return '';
555
-        }
553
+			echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
554
+			return '';
555
+		}
556 556
 
557
-        return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
557
+		return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
558 558
 
559 559
 	} // End sensei_lesson_image()
560 560
 
561
-    /**
562
-     * @since 1.0.0
563
-     * @param WP_Query $query
564
-     */
565
-    function sensei_course_archive_pagination( $query ) {
561
+	/**
562
+	 * @since 1.0.0
563
+	 * @param WP_Query $query
564
+	 */
565
+	function sensei_course_archive_pagination( $query ) {
566 566
 
567 567
 		if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) {
568 568
 
@@ -585,50 +585,50 @@  discard block
 block discarded – undo
585 585
 	 *
586 586
 	 * @access public
587 587
 	 * @since  1.2.0
588
-     * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header
588
+	 * @deprecated since 1.9.0 use WooThemes_Sensei_Course::archive_header
589 589
 	 * @return void
590 590
 	 */
591 591
 	function sensei_course_archive_header(  ) {
592 592
 
593
-        trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
594
-        WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
593
+		trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
594
+		WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
595 595
 
596 596
 	} // sensei_course_archive_header()
597 597
 
598 598
 	/**
599 599
 	 * sensei_lesson_archive_header function.
600 600
 	 *
601
-     * @deprecated since 1.9.0
601
+	 * @deprecated since 1.9.0
602 602
 	 * @access public
603 603
 	 * @since  1.2.1
604 604
 	 * @return void
605 605
 	 */
606 606
 	public function sensei_lesson_archive_header( ) {
607
-        _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
608
-        Sensei()->lesson->the_archive_header();
607
+		_deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
608
+		Sensei()->lesson->the_archive_header();
609 609
 	} // sensei_course_archive_header()
610 610
 
611
-    /**
612
-     * @deprecated since 1.9.0
613
-     */
611
+	/**
612
+	 * @deprecated since 1.9.0
613
+	 */
614 614
 	public function sensei_message_archive_header( ){
615
-        _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
616
-        Sensei_Messages::the_archive_header();
615
+		_deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
616
+		Sensei_Messages::the_archive_header();
617 617
 	} // sensei_message_archive_header()
618 618
 
619 619
 	/**
620 620
 	 * sensei_course_archive_course_title output for course archive page individual course title
621 621
 	 * @since  1.2.0
622
-     * @param WP_Post $post_item
622
+	 * @param WP_Post $post_item
623 623
 	 * @return void
624 624
 	 */
625 625
 	function sensei_course_archive_course_title( $post_item ) {
626 626
 		if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) {
627 627
 			$post_id = absint( $post_item->ID );
628
-    		$post_title = $post_item->post_title;
628
+			$post_title = $post_item->post_title;
629 629
 		} else {
630 630
 			$post_id = get_the_ID();
631
-    		$post_title = get_the_title();
631
+			$post_title = get_the_title();
632 632
 		} // End If Statement
633 633
 		?><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
634 634
 	} // End sensei_course_archive_course_title()
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	 */
641 641
 	public function sensei_lesson_archive_lesson_title() {
642 642
 		$post_id = get_the_ID();
643
-    	$post_title = get_the_title();
643
+		$post_title = get_the_title();
644 644
 		?><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
645 645
 	} // End sensei_lesson_archive_lesson_title()
646 646
 
@@ -657,9 +657,9 @@  discard block
 block discarded – undo
657 657
 
658 658
 		if( empty( $id )  ){
659 659
 
660
-            $id = get_the_ID();
660
+			$id = get_the_ID();
661 661
 
662
-        }
662
+		}
663 663
 
664 664
 		$sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' );
665 665
 		$separator = apply_filters( 'sensei_breadcrumb_separator', '&gt;' );
@@ -672,31 +672,31 @@  discard block
 block discarded – undo
672 672
 				return;
673 673
 			}
674 674
 			$html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>';
675
-    	} // End If Statement
676
-    	// Quiz
675
+		} // End If Statement
676
+		// Quiz
677 677
 		if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) {
678 678
 			$lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) );
679 679
 			if( ! $lesson_id ) {
680 680
 				return;
681 681
 			}
682 682
 			 $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' .  __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>';
683
-    	} // End If Statement
683
+		} // End If Statement
684 684
 
685
-    	// Allow other plugins to filter html
686
-    	$html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
687
-    	$html .= '</section>';
685
+		// Allow other plugins to filter html
686
+		$html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
687
+		$html .= '</section>';
688 688
 
689
-    	echo $html;
689
+		echo $html;
690 690
 	} // End sensei_breadcrumb()
691 691
 
692 692
 
693
-    /**
694
-     * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead
695
-     */
693
+	/**
694
+	 * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead
695
+	 */
696 696
 	public function sensei_lesson_course_signup_link( ) {
697 697
 
698
-        _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
699
-        WooThemes_Sensei_Lesson::course_signup_link();
698
+		_deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
699
+		WooThemes_Sensei_Lesson::course_signup_link();
700 700
 	}
701 701
 
702 702
 	public function lesson_tags_display( $lesson_id = 0 ) {
@@ -715,27 +715,27 @@  discard block
 block discarded – undo
715 715
 					?><section class="lesson-tags">
716 716
 		    			<?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?>
717 717
 		    		</section><?php
718
-		    	}
719
-	    	}
718
+				}
719
+			}
720 720
 		}
721 721
 	}
722 722
 
723
-    /**
724
-     * @param WP_Query $query
725
-     */
723
+	/**
724
+	 * @param WP_Query $query
725
+	 */
726 726
 	public function lesson_tag_archive_filter( $query ) {
727
-    	if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
728
-    		// Limit to lessons only
729
-    		$query->set( 'post_type', 'lesson' );
727
+		if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
728
+			// Limit to lessons only
729
+			$query->set( 'post_type', 'lesson' );
730 730
 
731
-    		// Set order of lessons
732
-    		$query->set( 'orderby', 'menu_order' );
733
-    		$query->set( 'order', 'ASC' );
731
+			// Set order of lessons
732
+			$query->set( 'orderby', 'menu_order' );
733
+			$query->set( 'order', 'ASC' );
734 734
 
735
-    	}
736
-    }
735
+		}
736
+	}
737 737
 
738
-    public function lesson_tag_archive_header( $title ) {
738
+	public function lesson_tag_archive_header( $title ) {
739 739
 		if( is_tax( 'lesson-tag' ) ) {
740 740
 			$title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) );
741 741
 		}
@@ -757,13 +757,13 @@  discard block
 block discarded – undo
757 757
 			$sanitized_submit = esc_html( $_POST['quiz_action'] );
758 758
 
759 759
 			switch ($sanitized_submit) {
760
-                case 'lesson-complete':
760
+				case 'lesson-complete':
761 761
 
762 762
 					Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true );
763 763
 
764 764
 					break;
765 765
 
766
-                case 'lesson-reset':
766
+				case 'lesson-reset':
767 767
 
768 768
 					Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID );
769 769
 
@@ -875,13 +875,13 @@  discard block
 block discarded – undo
875 875
 		if ( 0 < intval( $post_id ) ) {
876 876
 			$lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true );
877 877
 			if ( 'http' == substr( $lesson_video_embed, 0, 4) ) {
878
-        		// V2 - make width and height a setting for video embed
879
-        		$lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ );
880
-        	} // End If Statement
881
-        	if ( '' != $lesson_video_embed ) {
882
-        	?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php
883
-        	} // End If Statement
884
-        } // End If Statement
878
+				// V2 - make width and height a setting for video embed
879
+				$lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ );
880
+			} // End If Statement
881
+			if ( '' != $lesson_video_embed ) {
882
+			?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php
883
+			} // End If Statement
884
+		} // End If Statement
885 885
 	} // End sensei_lesson_video()
886 886
 
887 887
 	public function sensei_complete_lesson_button() {
@@ -894,8 +894,8 @@  discard block
 block discarded – undo
894 894
 		$pass_required = true;
895 895
 		if( $quiz_id ) {
896 896
 			// Get quiz pass setting
897
-	    	$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
898
-	    }
897
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
898
+		}
899 899
 		if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) {
900 900
 			?>
901 901
 			<form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
@@ -948,12 +948,12 @@  discard block
 block discarded – undo
948 948
 		} // End If Statement
949 949
 	} // End sensei_reset_lesson_button()
950 950
 
951
-    /**
952
-     * @deprecated since 1.9.0
953
-     */
954
-    public function sensei_lesson_quiz_meta( ) {
951
+	/**
952
+	 * @deprecated since 1.9.0
953
+	 */
954
+	public function sensei_lesson_quiz_meta( ) {
955 955
 
956
-        Sensei_Lesson::footer_quiz_call_to_action();
956
+		Sensei_Lesson::footer_quiz_call_to_action();
957 957
 
958 958
 	} // End sensei_lesson_quiz_meta()
959 959
 
@@ -979,38 +979,38 @@  discard block
 block discarded – undo
979 979
         	</p>
980 980
         	<p class="course-excerpt"><?php the_excerpt(); ?></p>
981 981
         	<?php if ( 0 < $free_lesson_count ) {
982
-                $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
982
+				$free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
983 983
                 <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>
984 984
             <?php } ?>
985 985
 		</section><?php
986 986
 	} // End sensei_course_archive_meta()
987 987
 
988
-    /**
989
-     * @deprecated since 1.9.0
990
-     */
988
+	/**
989
+	 * @deprecated since 1.9.0
990
+	 */
991 991
 	public function sensei_single_main_content() {
992
-	    _deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0');
992
+		_deprecated_function('Woothemes_Sensei_Frontend::sensei_single_main_content', '1.9.0');
993 993
 	} // End sensei_single_main_content()
994 994
 
995
-    /**
996
-    * @deprecated since 1.9.0
997
-    */
995
+	/**
996
+	 * @deprecated since 1.9.0
997
+	 */
998 998
 	public function sensei_lesson_archive_main_content() {
999
-        _deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly');
999
+		_deprecated_function('Sensei_Frontend::sensei_lesson_archive_main_content', '1.9.0', 'Please include loop-lesson.php directly');
1000 1000
 	} // End sensei_lesson_archive_main_content()
1001 1001
 
1002
-    /**
1003
-    * @deprecated since 1.9.0
1004
-    */
1002
+	/**
1003
+	 * @deprecated since 1.9.0
1004
+	 */
1005 1005
 	public function sensei_message_archive_main_content() {
1006 1006
 		_deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' );
1007 1007
 	} // End sensei_lesson_archive_main_content()
1008 1008
 
1009
-    /**
1010
-    * @deprecated since 1.9.0
1011
-    */
1009
+	/**
1010
+	 * @deprecated since 1.9.0
1011
+	 */
1012 1012
 	public function sensei_no_permissions_main_content() {
1013
-        _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1013
+		_deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1014 1014
 	} // End sensei_no_permissions_main_content()
1015 1015
 
1016 1016
 	public function sensei_course_category_main_content() {
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 				<div class="col-1">
1059 1059
 					<?php
1060 1060
 					// output the actual form markup
1061
-                    Sensei_Templates::get_template( 'user/login-form.php');
1061
+					Sensei_Templates::get_template( 'user/login-form.php');
1062 1062
 					?>
1063 1063
 				</div>
1064 1064
 
@@ -1139,12 +1139,12 @@  discard block
 block discarded – undo
1139 1139
 
1140 1140
 		//if this is a paid course
1141 1141
 		if ( Sensei_WC::is_woocommerce_active() ) {
1142
-    	    $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1143
-    	    if ( 0 < $wc_post_id ) {
1144
-    	    	$preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1145
-    	    } // End If Statement
1146
-    	}
1147
-    	return $preview_text;
1142
+			$wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1143
+			if ( 0 < $wc_post_id ) {
1144
+				$preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1145
+			} // End If Statement
1146
+		}
1147
+		return $preview_text;
1148 1148
 	}
1149 1149
 
1150 1150
 	public function sensei_lesson_preview_title( $title = '', $id = 0 ) {
@@ -1176,8 +1176,8 @@  discard block
 block discarded – undo
1176 1176
 		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
1177 1177
 		// Handle user starting the course
1178 1178
 		if ( isset( $_POST['course_start'] )
1179
-		    && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1180
-		    && !$is_user_taking_course ) {
1179
+			&& wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1180
+			&& !$is_user_taking_course ) {
1181 1181
 
1182 1182
 			// Start the course
1183 1183
 			$activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID );
@@ -1196,35 +1196,35 @@  discard block
 block discarded – undo
1196 1196
 		} // End If Statement
1197 1197
 	} // End sensei_course_start()
1198 1198
 
1199
-    /**
1200
-     * @deprecated since 1.9.0
1201
-     */
1199
+	/**
1200
+	 * @deprecated since 1.9.0
1201
+	 */
1202 1202
 	public function sensei_course_meta() {
1203
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1204
-        Sensei()->course->the_course_meta( get_post() );
1203
+		_deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1204
+		Sensei()->course->the_course_meta( get_post() );
1205 1205
 	} // End sensei_course_meta()
1206 1206
 
1207
-    /**
1208
-     * @deprecated since 1.9.0
1209
-     */
1207
+	/**
1208
+	 * @deprecated since 1.9.0
1209
+	 */
1210 1210
 	public function sensei_course_meta_video() {
1211
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1212
-        Sensei_Course::the_course_video();
1211
+		_deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1212
+		Sensei_Course::the_course_video();
1213 1213
 	} // End sensei_course_meta_video()
1214 1214
 
1215
-    /**
1216
-     * This function shows the WooCommerce cart notice if the user has
1217
-     * added the current course to cart. It does not show if the user is already taking
1218
-     * the course.
1219
-     *
1220
-     * @since 1.0.2
1221
-     * @return void;
1222
-     */
1223
-    public function sensei_woocommerce_in_cart_message() {
1215
+	/**
1216
+	 * This function shows the WooCommerce cart notice if the user has
1217
+	 * added the current course to cart. It does not show if the user is already taking
1218
+	 * the course.
1219
+	 *
1220
+	 * @since 1.0.2
1221
+	 * @return void;
1222
+	 */
1223
+	public function sensei_woocommerce_in_cart_message() {
1224 1224
 		global $post, $woocommerce;
1225 1225
 
1226 1226
 		$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
1227
-        $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1227
+		$user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1228 1228
 		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
1229 1229
 
1230 1230
 			if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) {
@@ -1272,7 +1272,7 @@  discard block
 block discarded – undo
1272 1272
 				$item_id = $item['product_id'];
1273 1273
 			} 
1274 1274
 
1275
-            if ( $item_id > 0 ) {
1275
+			if ( $item_id > 0 ) {
1276 1276
 
1277 1277
 				$user_id = get_post_meta( $order_id, '_customer_user', true );
1278 1278
 
@@ -1352,15 +1352,15 @@  discard block
 block discarded – undo
1352 1352
 
1353 1353
 					$items = $order->get_items();
1354 1354
 					foreach( $items as $item ) {
1355
-                                            if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1356
-                                                $item_id = $item['variation_id'];
1357
-                                                $product_type = 'variation';
1358
-                                            } else {
1359
-                                                $item_id = $item['product_id'];
1360
-                                            }
1355
+											if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1356
+												$item_id = $item['variation_id'];
1357
+												$product_type = 'variation';
1358
+											} else {
1359
+												$item_id = $item['product_id'];
1360
+											}
1361 1361
 
1362
-                                            $product_ids[] = $item_id;
1363
-                                            }
1362
+											$product_ids[] = $item_id;
1363
+											}
1364 1364
 
1365 1365
 					$order_ids[] = $post_id;
1366 1366
 				}
@@ -1467,32 +1467,32 @@  discard block
 block discarded – undo
1467 1467
 
1468 1468
 				$items = $order->get_items();
1469 1469
 				foreach( $items as $item ) {
1470
-                    $product = wc_get_product( $item['product_id'] );
1470
+					$product = wc_get_product( $item['product_id'] );
1471 1471
 
1472
-                    // handle product bundles
1473
-                    if( $product->is_type('bundle') ){
1472
+					// handle product bundles
1473
+					if( $product->is_type('bundle') ){
1474 1474
 
1475
-                        $bundled_product = new WC_Product_Bundle( $product->id );
1476
-                        $bundled_items = $bundled_product->get_bundled_items();
1475
+						$bundled_product = new WC_Product_Bundle( $product->id );
1476
+						$bundled_items = $bundled_product->get_bundled_items();
1477 1477
 
1478
-                        foreach( $bundled_items as $bundled_item ){
1478
+						foreach( $bundled_items as $bundled_item ){
1479 1479
 
1480
-                            if( $bundled_item->product_id == $course_product_id ) {
1481
-                                Sensei_Utils::user_start_course( $user_id, $course_id );
1482
-                                return;
1483
-                            }
1480
+							if( $bundled_item->product_id == $course_product_id ) {
1481
+								Sensei_Utils::user_start_course( $user_id, $course_id );
1482
+								return;
1483
+							}
1484 1484
 
1485
-                        }
1485
+						}
1486 1486
 
1487
-                    } else {
1487
+					} else {
1488 1488
 
1489
-                    // handle regular products
1490
-                        if( $item['product_id'] == $course_product_id ) {
1491
-                            Sensei_Utils::user_start_course( $user_id, $course_id );
1492
-                            return;
1493
-                        }
1489
+					// handle regular products
1490
+						if( $item['product_id'] == $course_product_id ) {
1491
+							Sensei_Utils::user_start_course( $user_id, $course_id );
1492
+							return;
1493
+						}
1494 1494
 
1495
-                    }
1495
+					}
1496 1496
 				}
1497 1497
 			}
1498 1498
 
@@ -1523,21 +1523,21 @@  discard block
 block discarded – undo
1523 1523
 
1524 1524
 		//if not posted from the sensei login form let
1525 1525
 		// WordPress or any other party handle the failed request
1526
-	    if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form']  ){
1526
+		if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form']  ){
1527 1527
 
1528
-	    	return ;
1528
+			return ;
1529 1529
 
1530
-	    }
1530
+		}
1531 1531
 
1532
-    	// Get the reffering page, where did the post submission come from?
1533
-    	$referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1532
+		// Get the reffering page, where did the post submission come from?
1533
+		$referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1534 1534
 
1535 1535
    		 // if there's a valid referrer, and it's not the default log-in screen
1536
-	    if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1537
-	        // let's append some information (login=failed) to the URL for the theme to use
1538
-	        wp_redirect( esc_url_raw( add_query_arg('login', 'failed',  $referrer) ) );
1539
-	    	exit;
1540
-    	}
1536
+		if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1537
+			// let's append some information (login=failed) to the URL for the theme to use
1538
+			wp_redirect( esc_url_raw( add_query_arg('login', 'failed',  $referrer) ) );
1539
+			exit;
1540
+		}
1541 1541
 	}// End sensei_login_fail_redirect_to_front_end_login
1542 1542
 
1543 1543
 	/**
@@ -1548,46 +1548,46 @@  discard block
 block discarded – undo
1548 1548
 	function sensei_handle_login_request( ) {
1549 1549
 
1550 1550
 		// Check that it is a sensei login request and if it has a valid nonce
1551
-	    if(  isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1551
+		if(  isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1552 1552
 
1553
-	    	// Validate the login request nonce
1554
-		    if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1555
-		    	return;
1556
-		    }
1553
+			// Validate the login request nonce
1554
+			if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1555
+				return;
1556
+			}
1557 1557
 
1558
-		    //get the page where the sensei log form is located
1559
-		    $referrer = $_REQUEST['_wp_http_referer'];
1560
-		    //$redirect = $_REQUEST['_sensei_redirect'];
1558
+			//get the page where the sensei log form is located
1559
+			$referrer = $_REQUEST['_wp_http_referer'];
1560
+			//$redirect = $_REQUEST['_sensei_redirect'];
1561 1561
 
1562
-		    if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1563
-		    	 && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1562
+			if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1563
+				 && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1564 1564
 
1565
-		    	// when the user has entered a password or username do the sensei login
1566
-		    	$creds = array();
1565
+				// when the user has entered a password or username do the sensei login
1566
+				$creds = array();
1567 1567
 
1568
-		    	// check if the requests login is an email address
1569
-		    	if( is_email(  trim( $_REQUEST['log'] ) )  ){
1570
-		    		// query wordpress for the users details
1571
-		    		$user =	get_user_by( 'email', sanitize_email( $_REQUEST['log'] )  );
1568
+				// check if the requests login is an email address
1569
+				if( is_email(  trim( $_REQUEST['log'] ) )  ){
1570
+					// query wordpress for the users details
1571
+					$user =	get_user_by( 'email', sanitize_email( $_REQUEST['log'] )  );
1572 1572
 
1573
-		    		// validate the user object
1574
-		    		if( !$user ){
1573
+					// validate the user object
1574
+					if( !$user ){
1575 1575
 
1576
-		    			// the email doesnt exist
1577
-                        wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1578
-		        		exit;
1576
+						// the email doesnt exist
1577
+						wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1578
+						exit;
1579 1579
 
1580
-		    		}
1580
+					}
1581 1581
 
1582
-		    		//assigne the username to the creds array for further processing
1583
-		    		$creds['user_login'] =  $user->user_login ;
1582
+					//assigne the username to the creds array for further processing
1583
+					$creds['user_login'] =  $user->user_login ;
1584 1584
 
1585
-		    	}else{
1585
+				}else{
1586 1586
 
1587
-		    		// process this as a default username login
1588
-		    		$creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1587
+					// process this as a default username login
1588
+					$creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1589 1589
 
1590
-		    	}
1590
+				}
1591 1591
 
1592 1592
 				// get setup the rest of the creds array
1593 1593
 				$creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] );
@@ -1597,42 +1597,42 @@  discard block
 block discarded – undo
1597 1597
 				$user = wp_signon( $creds, false );
1598 1598
 
1599 1599
 				if ( is_wp_error($user) ){ // on login failure
1600
-                    wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1601
-                    exit;
1600
+					wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1601
+					exit;
1602 1602
 				}else{ // on login success
1603 1603
 
1604 1604
 					/**
1605
-					* change the redirect url programatically
1606
-					*
1607
-					* @since 1.6.1
1608
-					*
1609
-					* @param string $referrer the page where the current url wheresensei login form was posted from
1610
-					*/
1605
+					 * change the redirect url programatically
1606
+					 *
1607
+					 * @since 1.6.1
1608
+					 *
1609
+					 * @param string $referrer the page where the current url wheresensei login form was posted from
1610
+					 */
1611 1611
 
1612 1612
 					$success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) );
1613 1613
 
1614 1614
 					wp_redirect( esc_url_raw( $success_redirect_url ) );
1615
-		        	exit;
1615
+					exit;
1616 1616
 
1617 1617
 				}	// end is_wp_error($user)
1618 1618
 
1619
-		    }else{ // if username or password is empty
1619
+			}else{ // if username or password is empty
1620 1620
 
1621
-                wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1622
-		        exit;
1621
+				wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1622
+				exit;
1623 1623
 
1624
-		    } // end if username $_REQUEST['log']  and password $_REQUEST['pwd'] is empty
1624
+			} // end if username $_REQUEST['log']  and password $_REQUEST['pwd'] is empty
1625 1625
 
1626
-	    }elseif( ( isset( $_GET['login'] ) ) ) {
1627
-	    	// else if this request is a redircect from a previously faile login request
1628
-	    	$this->login_message_process();
1626
+		}elseif( ( isset( $_GET['login'] ) ) ) {
1627
+			// else if this request is a redircect from a previously faile login request
1628
+			$this->login_message_process();
1629 1629
 
1630 1630
 			//exit the handle login request function
1631 1631
 			return;
1632
-	    }
1632
+		}
1633 1633
 
1634
-	    // if none of the above
1635
-	    return;
1634
+		// if none of the above
1635
+		return;
1636 1636
 
1637 1637
 	} // End  sensei_login_fail_redirect_to_front_end_login
1638 1638
 
@@ -1735,7 +1735,7 @@  discard block
 block discarded – undo
1735 1735
 	 */
1736 1736
 	public function login_message_process(){
1737 1737
 
1738
-            // setup the message variables
1738
+			// setup the message variables
1739 1739
 			$message = '';
1740 1740
 
1741 1741
 			//only output message if the url contains login=failed and login=emptyfields
@@ -1754,22 +1754,22 @@  discard block
 block discarded – undo
1754 1754
 	}// end login_message_process
1755 1755
 
1756 1756
 
1757
-    /**
1758
-     * sensei_show_admin_bar(). Use WooCommerce filter
1759
-     * to show admin bar to Teachers as well.
1760
-     *
1761
-     * @return void redirect
1762
-     *
1763
-     */
1764
-    public function sensei_show_admin_bar () {
1757
+	/**
1758
+	 * sensei_show_admin_bar(). Use WooCommerce filter
1759
+	 * to show admin bar to Teachers as well.
1760
+	 *
1761
+	 * @return void redirect
1762
+	 *
1763
+	 */
1764
+	public function sensei_show_admin_bar () {
1765 1765
 
1766
-        if (current_user_can('edit_courses')) {
1766
+		if (current_user_can('edit_courses')) {
1767 1767
 
1768
-            add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1768
+			add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1769 1769
 
1770
-        }
1770
+		}
1771 1771
 
1772
-    }
1772
+	}
1773 1773
 
1774 1774
 } // End Class
1775 1775
 
Please login to merge, or discard this patch.
includes/admin/class-sensei-welcome.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-    exit; // Exit if accessed directly
3
+	exit; // Exit if accessed directly
4 4
 }
5 5
 
6 6
 /**
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
 
18 18
 	/**
19 19
 	 * Hook in tabs.
20
-     * @since 1.8.0
20
+	 * @since 1.8.0
21 21
 	 */
22 22
 	public function __construct() {
23 23
 
24
-        add_action( 'admin_menu', array( $this, 'admin_menus') );
24
+		add_action( 'admin_menu', array( $this, 'admin_menus') );
25 25
 		add_action( 'admin_head', array( $this, 'admin_head' ) );
26 26
 
27 27
 	}
28 28
 
29
-    /**
30
-     * Sends user to the welcome page on first activation.
31
-     *
32
-     * Hooked into activated_plugin
33
-     * @since 1.8.0
34
-     */
35
-    public static function redirect( $plugin ) {
29
+	/**
30
+	 * Sends user to the welcome page on first activation.
31
+	 *
32
+	 * Hooked into activated_plugin
33
+	 * @since 1.8.0
34
+	 */
35
+	public static function redirect( $plugin ) {
36 36
 
37
-        // Bail if activating from network, or bulk, or within an iFrame
38
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
37
+		// Bail if activating from network, or bulk, or within an iFrame
38
+		if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
39 39
 
40
-            return;
40
+			return;
41 41
 
42
-        }
43
-        // don't run for upgrades and for pages already on the welcome screen
44
-        if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] )
45
-            || ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) {
42
+		}
43
+		// don't run for upgrades and for pages already on the welcome screen
44
+		if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] )
45
+			|| ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) {
46 46
 
47
-            return;
47
+			return;
48 48
 
49
-        }
49
+		}
50 50
 
51
-        wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) );
52
-        exit;
53
-    }
51
+		wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) );
52
+		exit;
53
+	}
54 54
 
55 55
 	/**
56 56
 	 * Add admin menus/screens.
57
-     *
58
-     * @since 1.8.0
57
+	 *
58
+	 * @since 1.8.0
59 59
 	 */
60 60
 	public function admin_menus() {
61 61
 
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
 
66 66
 		$welcome_page_name  = __( 'Sensei Activation', 'woothemes-sensei' );
67 67
 		$welcome_page_title = __( 'Welcome to Sensei', 'woothemes-sensei' );
68
-        add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) );
68
+		add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) );
69 69
 
70 70
 	}
71 71
 
72
-    /**
73
-     * Output the Welcome  screen.
74
-     *
75
-     * @since 1.8.0
76
-     */
77
-    public function welcome_screen() {
78
-        ?>
72
+	/**
73
+	 * Output the Welcome  screen.
74
+	 *
75
+	 * @since 1.8.0
76
+	 */
77
+	public function welcome_screen() {
78
+		?>
79 79
         <div class="wrap about-wrap">
80 80
 
81 81
             <?php  $this->intro(); ?>
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
             </div>
129 129
         </div>
130 130
     <?php
131
-    }
131
+	}
132 132
 
133 133
 	/**
134 134
 	 * Add styles just for this page, and remove dashboard page links.
135 135
 	 */
136 136
 	public function admin_head() {
137
-        // remove the menu page so it is not visible in the admin side bar
137
+		// remove the menu page so it is not visible in the admin side bar
138 138
 		remove_submenu_page( 'index.php', 'sensei-welcome' );
139 139
 		?>
140 140
 		<style type="text/css">
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
 		// Random tweet - must be kept to 102 chars to "fit"
260 260
 		$tweets        = array(
261
-            'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.'
261
+			'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.'
262 262
 		);
263 263
 		shuffle( $tweets );
264 264
 		?>
@@ -280,11 +280,11 @@  discard block
 block discarded – undo
280 280
 
281 281
 		<div class="sensei-badge">
282 282
             <?php
283
-                _e('Sensei by WooThemes','woothemes-sensei');
284
-                echo '<br />';
283
+				_e('Sensei by WooThemes','woothemes-sensei');
284
+				echo '<br />';
285 285
 
286
-                printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version );
287
-            ?>
286
+				printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version );
287
+			?>
288 288
         </div>
289 289
 
290 290
 		<p class="sensei-actions">
Please login to merge, or discard this patch.
includes/class-sensei-quiz.php 1 patch
Indentation   +884 added lines, -884 removed lines patch added patch discarded remove patch
@@ -24,69 +24,69 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct ( $file = __FILE__ ) {
26 26
 		$this->file = $file;
27
-        $this->token = 'quiz';
27
+		$this->token = 'quiz';
28 28
 		$this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' );
29 29
 		add_action( 'save_post', array( $this, 'update_author' ));
30 30
 
31 31
 		// listen to the reset button click
32 32
 		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
33 33
 
34
-        // fire the complete quiz button submit for grading action
35
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
34
+		// fire the complete quiz button submit for grading action
35
+		add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
36 36
 
37 37
 		// fire the save user answers quiz button click responder
38 38
 		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
39 39
 
40
-        // fire the load global data function
41
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
40
+		// fire the load global data function
41
+		add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
42 42
 
43
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
43
+		add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
44 44
 
45 45
 
46
-    } // End __construct()
46
+	} // End __construct()
47 47
 
48 48
 	/**
49
-	* Update the quiz author when the lesson post type is save
50
-	*
51
-	* @param int $post_id
52
-	* @return void
53
-	*/
49
+	 * Update the quiz author when the lesson post type is save
50
+	 *
51
+	 * @param int $post_id
52
+	 * @return void
53
+	 */
54 54
 	public function update_author( $post_id ){
55 55
 
56 56
 		// If this isn't a 'lesson' post, don't update it.
57
-        // if this is a revision don't save it
58
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
59
-            || wp_is_post_revision( $post_id ) ) {
57
+		// if this is a revision don't save it
58
+		if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
59
+			|| wp_is_post_revision( $post_id ) ) {
60 60
 
61
-                return;
61
+				return;
62 62
 
63
-        }
64
-	    // get the lesson author id to be use late
65
-	    $saved_post = get_post( $post_id );
66
-	    $new_lesson_author_id =  $saved_post->post_author;
63
+		}
64
+		// get the lesson author id to be use late
65
+		$saved_post = get_post( $post_id );
66
+		$new_lesson_author_id =  $saved_post->post_author;
67 67
 
68
-	    //get the lessons quiz
68
+		//get the lessons quiz
69 69
 		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
70
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
70
+		foreach ( (array) $lesson_quizzes as $quiz_item ) {
71 71
 
72
-	    	if( ! $quiz_item ) {
73
-	    		continue;
74
-	    	}
72
+			if( ! $quiz_item ) {
73
+				continue;
74
+			}
75 75
 
76
-		    // setup the quiz items new author value
76
+			// setup the quiz items new author value
77 77
 			$my_post = array(
78
-			      'ID'           => $quiz_item,
79
-			      'post_author' =>  $new_lesson_author_id
78
+				  'ID'           => $quiz_item,
79
+				  'post_author' =>  $new_lesson_author_id
80 80
 			);
81 81
 
82
-            // remove the action so that it doesn't fire again
83
-            remove_action( 'save_post', array( $this, 'update_author' ));
82
+			// remove the action so that it doesn't fire again
83
+			remove_action( 'save_post', array( $this, 'update_author' ));
84 84
 
85 85
 			// Update the post into the database
86 86
 		  	wp_update_post( $my_post );
87
-	    }
87
+		}
88 88
 
89
-	    return;
89
+		return;
90 90
 	}// end update_author
91 91
 
92 92
 
@@ -117,32 +117,32 @@  discard block
 block discarded – undo
117 117
 	} // end lesson
118 118
 
119 119
 
120
-    /**
121
-     * user_save_quiz_answers_listener
122
-     *
123
-     * This function hooks into the quiz page and accepts the answer form save post.
124
-     * @since 1.7.3
125
-     * @return bool $saved;
126
-     */
127
-    public function user_save_quiz_answers_listener(){
120
+	/**
121
+	 * user_save_quiz_answers_listener
122
+	 *
123
+	 * This function hooks into the quiz page and accepts the answer form save post.
124
+	 * @since 1.7.3
125
+	 * @return bool $saved;
126
+	 */
127
+	public function user_save_quiz_answers_listener(){
128 128
 
129
-        if( ! isset( $_POST[ 'quiz_save' ])
130
-            || !isset( $_POST[ 'sensei_question' ] )
131
-            || empty( $_POST[ 'sensei_question' ] )
132
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
133
-            return;
134
-        }
129
+		if( ! isset( $_POST[ 'quiz_save' ])
130
+			|| !isset( $_POST[ 'sensei_question' ] )
131
+			|| empty( $_POST[ 'sensei_question' ] )
132
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
133
+			return;
134
+		}
135 135
 
136
-        global $post;
137
-        $lesson_id = $this->get_lesson_id( $post->ID );
138
-        $quiz_answers = $_POST[ 'sensei_question' ];
139
-        // call the save function
140
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
136
+		global $post;
137
+		$lesson_id = $this->get_lesson_id( $post->ID );
138
+		$quiz_answers = $_POST[ 'sensei_question' ];
139
+		// call the save function
140
+		self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
141 141
 
142
-        // remove the hook as it should only fire once per click
143
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
142
+		// remove the hook as it should only fire once per click
143
+		remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
144 144
 
145
-    } // end user_save_quiz_answers_listener
145
+	} // end user_save_quiz_answers_listener
146 146
 
147 147
 	/**
148 148
 	 * Save the user answers for the given lesson's quiz
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @access public
154 154
 	 *
155 155
 	 * @param array $quiz_answers
156
-     * @param array $files from global $_FILES
156
+	 * @param array $files from global $_FILES
157 157
 	 * @param int $lesson_id
158 158
 	 * @param int $user_id
159 159
 	 *
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
163 163
 
164
-        if( ! ( $user_id > 0 ) ){
165
-            $user_id = get_current_user_id();
166
-        }
164
+		if( ! ( $user_id > 0 ) ){
165
+			$user_id = get_current_user_id();
166
+		}
167 167
 
168
-        // make sure the parameters are valid before continuing
168
+		// make sure the parameters are valid before continuing
169 169
 		if( empty( $lesson_id ) || empty( $user_id )
170 170
 			|| 'lesson' != get_post_type( $lesson_id )
171 171
 			||!get_userdata( $user_id )
@@ -176,25 +176,25 @@  discard block
 block discarded – undo
176 176
 		}
177 177
 
178 178
 
179
-        // start the lesson before saving the data in case the user has not started the lesson
180
-        $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
179
+		// start the lesson before saving the data in case the user has not started the lesson
180
+		$activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
181 181
 
182 182
 		//prepare the answers
183 183
 		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
184 184
 
185 185
 		// save the user data
186
-        $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
186
+		$answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
187 187
 
188 188
 		// were the answers saved correctly?
189 189
 		if( intval( $answers_saved ) > 0){
190 190
 
191
-            // save transient to make retrieval faster
192
-            $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
193
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
191
+			// save transient to make retrieval faster
192
+			$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
193
+			set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
194 194
 
195
-            // update the message showed to user
196
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
-        }
195
+			// update the message showed to user
196
+			Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
+		}
198 198
 
199 199
 		return $answers_saved;
200 200
 
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 
203 203
 	/**
204 204
 	 * Get the user answers for the given lesson's quiz.
205
-     *
206
-     * This function returns the data that is stored on the lesson as meta and is not compatible with
207
-     * retrieving data for quiz answer before sensei 1.7.4
205
+	 *
206
+	 * This function returns the data that is stored on the lesson as meta and is not compatible with
207
+	 * retrieving data for quiz answer before sensei 1.7.4
208 208
 	 *
209 209
 	 *
210 210
 	 * @since 1.7.4
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
 			return false;
225 225
 		}
226 226
 
227
-        // save some time and get the transient cached data
228
-        $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
229
-        $transient_cached_answers = get_transient( $transient_key );
227
+		// save some time and get the transient cached data
228
+		$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
229
+		$transient_cached_answers = get_transient( $transient_key );
230 230
 
231
-        // return the transient or get the values get the values from the comment meta
232
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
231
+		// return the transient or get the values get the values from the comment meta
232
+		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
233 233
 
234
-            $encoded_user_answers = $transient_cached_answers;
234
+			$encoded_user_answers = $transient_cached_answers;
235 235
 
236
-        }else{
236
+		}else{
237 237
 
238
-            $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
238
+			$encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
239 239
 
240
-        } // end if transient check
240
+		} // end if transient check
241 241
 
242 242
 		if( ! is_array( $encoded_user_answers ) ){
243 243
 			return false;
244 244
 		}
245 245
 
246
-        //set the transient with the new valid data for faster retrieval in future
247
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
246
+		//set the transient with the new valid data for faster retrieval in future
247
+		set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
248 248
 
249 249
 		// decode an unserialize all answers
250 250
 		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 		$current_quiz_id = $post->ID;
279 279
 		$lesson_id = $this->get_lesson_id( $current_quiz_id );
280 280
 
281
-        // reset all user data
282
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
281
+		// reset all user data
282
+		$this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
283 283
 
284 284
 		//this function should only run once
285 285
 		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * Complete/ submit  quiz hooked function
291 291
 	 *
292 292
 	 * This function listens to the complete button submit action and processes the users submitted answers
293
-     * not that this function submits the given users quiz answers for grading.
293
+	 * not that this function submits the given users quiz answers for grading.
294 294
 	 *
295 295
 	 * @since  1.7.4
296 296
 	 * @access public
@@ -300,90 +300,90 @@  discard block
 block discarded – undo
300 300
 	 */
301 301
 	public function user_quiz_submit_listener() {
302 302
 
303
-        // only respond to valid quiz completion submissions
304
-        if( ! isset( $_POST[ 'quiz_complete' ])
305
-            || !isset( $_POST[ 'sensei_question' ] )
306
-            || empty( $_POST[ 'sensei_question' ] )
307
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
308
-            return;
309
-        }
303
+		// only respond to valid quiz completion submissions
304
+		if( ! isset( $_POST[ 'quiz_complete' ])
305
+			|| !isset( $_POST[ 'sensei_question' ] )
306
+			|| empty( $_POST[ 'sensei_question' ] )
307
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
308
+			return;
309
+		}
310 310
 
311
-        global $post, $current_user;
312
-        $lesson_id = $this->get_lesson_id( $post->ID );
313
-        $quiz_answers = $_POST[ 'sensei_question' ];
311
+		global $post, $current_user;
312
+		$lesson_id = $this->get_lesson_id( $post->ID );
313
+		$quiz_answers = $_POST[ 'sensei_question' ];
314 314
 
315
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
315
+		self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
316 316
 
317 317
 	} // End sensei_complete_quiz()
318 318
 
319
-    /**
320
-     * This function set's up the data need for the quiz page
321
-     *
322
-     * This function hooks into sensei_complete_quiz and load the global data for the
323
-     * current quiz.
324
-     *
325
-     * @since 1.7.4
326
-     * @access public
327
-     *
328
-     */
329
-    public function load_global_quiz_data(){
319
+	/**
320
+	 * This function set's up the data need for the quiz page
321
+	 *
322
+	 * This function hooks into sensei_complete_quiz and load the global data for the
323
+	 * current quiz.
324
+	 *
325
+	 * @since 1.7.4
326
+	 * @access public
327
+	 *
328
+	 */
329
+	public function load_global_quiz_data(){
330 330
 
331
-        global  $post, $current_user;
332
-        $this->data = new stdClass();
331
+		global  $post, $current_user;
332
+		$this->data = new stdClass();
333 333
 
334
-        // Default grade
335
-        $grade = 0;
334
+		// Default grade
335
+		$grade = 0;
336 336
 
337
-        // Get Quiz Questions
338
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
337
+		// Get Quiz Questions
338
+		$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
339 339
 
340
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
340
+		$quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
341 341
 
342
-        // Get quiz grade type
343
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
342
+		// Get quiz grade type
343
+		$quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
344 344
 
345
-        // Get quiz pass setting
346
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
345
+		// Get quiz pass setting
346
+		$pass_required = get_post_meta( $post->ID, '_pass_required', true );
347 347
 
348
-        // Get quiz pass mark
349
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
348
+		// Get quiz pass mark
349
+		$quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
350 350
 
351
-        // Get latest quiz answers and grades
352
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
353
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
354
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
355
-        $user_quiz_grade = 0;
356
-        if( isset( $user_lesson_status->comment_ID ) ) {
357
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
358
-        }
351
+		// Get latest quiz answers and grades
352
+		$lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
353
+		$user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
354
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
355
+		$user_quiz_grade = 0;
356
+		if( isset( $user_lesson_status->comment_ID ) ) {
357
+			$user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
358
+		}
359 359
 
360
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
360
+		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
361 361
 
362
-        // Check again that the lesson is complete
363
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
-        $user_lesson_complete = false;
365
-        if ( $user_lesson_end ) {
366
-            $user_lesson_complete = true;
367
-        } // End If Statement
362
+		// Check again that the lesson is complete
363
+		$user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
+		$user_lesson_complete = false;
365
+		if ( $user_lesson_end ) {
366
+			$user_lesson_complete = true;
367
+		} // End If Statement
368 368
 
369
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
-        //backwards compatibility
371
-        if( 'on' == $reset_allowed ) {
372
-            $reset_allowed = 1;
373
-        }
369
+		$reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
+		//backwards compatibility
371
+		if( 'on' == $reset_allowed ) {
372
+			$reset_allowed = 1;
373
+		}
374 374
 
375
-        // Build frontend data object for backwards compatibility
376
-        // using this is no longer recommended
377
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
-        $this->data->quiz_passmark = $quiz_passmark;
379
-        $this->data->quiz_lesson = $quiz_lesson_id;
380
-        $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
381
-        $this->data->user_lesson_end = $user_lesson_end;
382
-        $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
383
-        $this->data->lesson_quiz_questions = $lesson_quiz_questions;
384
-        $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
375
+		// Build frontend data object for backwards compatibility
376
+		// using this is no longer recommended
377
+		$this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
+		$this->data->quiz_passmark = $quiz_passmark;
379
+		$this->data->quiz_lesson = $quiz_lesson_id;
380
+		$this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
381
+		$this->data->user_lesson_end = $user_lesson_end;
382
+		$this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
383
+		$this->data->lesson_quiz_questions = $lesson_quiz_questions;
384
+		$this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
385 385
 
386
-    } // end load_global_quiz_data
386
+	} // end load_global_quiz_data
387 387
 
388 388
 
389 389
 	/**
@@ -413,25 +413,25 @@  discard block
 block discarded – undo
413 413
 		foreach( $unprepared_answers as $question_id => $answer ) {
414 414
 
415 415
 			//get the current questions question type
416
-            $question_type = Sensei()->question->get_question_type( $question_id );
416
+			$question_type = Sensei()->question->get_question_type( $question_id );
417 417
 
418 418
 			// Sanitise answer
419 419
 			if( 0 == get_magic_quotes_gpc() ) {
420 420
 				$answer = wp_unslash( $answer );
421 421
 			}
422 422
 
423
-            // compress the answer for saving
423
+			// compress the answer for saving
424 424
 			if( 'multi-line' == $question_type ) {
425
-                $answer = esc_html( $answer );
426
-            }elseif( 'file-upload' == $question_type  ){
427
-                $file_key = 'file_upload_' . $question_id;
428
-                if( isset( $files[ $file_key ] ) ) {
429
-                        $attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
430
-                        if( $attachment_id ) {
431
-                            $answer = $attachment_id;
432
-                        }
433
-                    }
434
-            } // end if
425
+				$answer = esc_html( $answer );
426
+			}elseif( 'file-upload' == $question_type  ){
427
+				$file_key = 'file_upload_' . $question_id;
428
+				if( isset( $files[ $file_key ] ) ) {
429
+						$attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
430
+						if( $attachment_id ) {
431
+							$answer = $attachment_id;
432
+						}
433
+					}
434
+			} // end if
435 435
 
436 436
 			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
437 437
 
@@ -440,813 +440,813 @@  discard block
 block discarded – undo
440 440
 		return $prepared_answers;
441 441
 	} // prepare_form_submitted_answers
442 442
 
443
-    /**
444
-     * Reset user submitted questions
445
-     *
446
-     * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
447
-     * the save_user_answers as currently the saved and submitted answers are stored differently.
448
-     *
449
-     * @since 1.7.4
450
-     * @access public
451
-     *
452
-     * @return bool $reset_success
453
-     * @param int $user_id
454
-     * @param int $lesson_id
455
-     */
456
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
443
+	/**
444
+	 * Reset user submitted questions
445
+	 *
446
+	 * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
447
+	 * the save_user_answers as currently the saved and submitted answers are stored differently.
448
+	 *
449
+	 * @since 1.7.4
450
+	 * @access public
451
+	 *
452
+	 * @return bool $reset_success
453
+	 * @param int $user_id
454
+	 * @param int $lesson_id
455
+	 */
456
+	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
457
+
458
+		//make sure the parameters are valid
459
+		if( empty( $lesson_id ) || empty( $user_id )
460
+			|| 'lesson' != get_post_type( $lesson_id )
461
+			|| ! get_userdata( $user_id ) ){
462
+			return false;
463
+		}
464
+
465
+
466
+
467
+		//get the users lesson status to make
468
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
469
+		if( ! isset( $user_lesson_status->comment_ID ) ) {
470
+			// this user is not taking this lesson so this process is not needed
471
+			return false;
472
+		}
473
+
474
+		//get the lesson quiz and course
475
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
476
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
477
+
478
+		// reset the transients
479
+		$answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
480
+		$grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
481
+		$answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
482
+		delete_transient( $answers_transient_key );
483
+		delete_transient( $grades_transient_key );
484
+		delete_transient( $answers_feedback_transient_key );
485
+
486
+		// reset the quiz answers and feedback notes
487
+		$deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
488
+		$deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
489
+		$deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
490
+
491
+		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
492
+		Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
493
+
494
+		Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
495
+
496
+		// Update course completion
497
+		Sensei_Utils::update_course_status( $user_id, $course_id );
457 498
 
458
-        //make sure the parameters are valid
459
-        if( empty( $lesson_id ) || empty( $user_id )
460
-            || 'lesson' != get_post_type( $lesson_id )
461
-            || ! get_userdata( $user_id ) ){
462
-            return false;
463
-        }
464
-
465
-
466
-
467
-        //get the users lesson status to make
468
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
469
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
470
-            // this user is not taking this lesson so this process is not needed
471
-            return false;
472
-        }
499
+		// Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
500
+		do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
501
+		Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
473 502
 
474
-        //get the lesson quiz and course
475
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
476
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
503
+		return ( $deleted_answers && $deleted_grades ) ;
477 504
 
478
-        // reset the transients
479
-        $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
480
-        $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
481
-        $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
482
-        delete_transient( $answers_transient_key );
483
-        delete_transient( $grades_transient_key );
484
-        delete_transient( $answers_feedback_transient_key );
505
+	} // end reset_user_lesson_data
485 506
 
486
-        // reset the quiz answers and feedback notes
487
-        $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
488
-        $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
489
-        $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
507
+	 /**
508
+	  * Submit the users quiz answers for grading
509
+	  *
510
+	  * This function accepts users answers and stores it but also initiates the grading
511
+	  * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
512
+	  *
513
+	  * @since 1.7.4
514
+	  * @access public
515
+	  *
516
+	  * @param array $quiz_answers
517
+	  * @param array $files from $_FILES
518
+	  * @param int $user_id
519
+	  * @param int $lesson_id
520
+	  *
521
+	  * @return bool $answers_submitted
522
+	  */
523
+	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
490 524
 
491
-        // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
492
-        Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
525
+		 $answers_submitted = false;
493 526
 
494
-        Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
527
+		 // get the user_id if none was passed in use the current logged in user
528
+		 if( ! intval( $user_id ) > 0 ) {
529
+			 $user_id = get_current_user_id();
530
+		 }
495 531
 
496
-        // Update course completion
497
-        Sensei_Utils::update_course_status( $user_id, $course_id );
532
+		 // make sure the parameters are valid before continuing
533
+		 if( empty( $lesson_id ) || empty( $user_id )
534
+			 || 'lesson' != get_post_type( $lesson_id )
535
+			 ||!get_userdata( $user_id )
536
+			 || !is_array( $quiz_answers ) ){
498 537
 
499
-        // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
500
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
501
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
538
+			 return false;
502 539
 
503
-        return ( $deleted_answers && $deleted_grades ) ;
540
+		 }
504 541
 
505
-    } // end reset_user_lesson_data
542
+		 // Default grade
543
+		 $grade = 0;
506 544
 
507
-     /**
508
-      * Submit the users quiz answers for grading
509
-      *
510
-      * This function accepts users answers and stores it but also initiates the grading
511
-      * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
512
-      *
513
-      * @since 1.7.4
514
-      * @access public
515
-      *
516
-      * @param array $quiz_answers
517
-      * @param array $files from $_FILES
518
-      * @param int $user_id
519
-      * @param int $lesson_id
520
-      *
521
-      * @return bool $answers_submitted
522
-      */
523
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
545
+		 // Get Quiz ID
546
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
524 547
 
525
-         $answers_submitted = false;
548
+		 // Get quiz grade type
549
+		 $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
526 550
 
527
-         // get the user_id if none was passed in use the current logged in user
528
-         if( ! intval( $user_id ) > 0 ) {
529
-             $user_id = get_current_user_id();
530
-         }
551
+		 // Get quiz pass setting
552
+		 $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
531 553
 
532
-         // make sure the parameters are valid before continuing
533
-         if( empty( $lesson_id ) || empty( $user_id )
534
-             || 'lesson' != get_post_type( $lesson_id )
535
-             ||!get_userdata( $user_id )
536
-             || !is_array( $quiz_answers ) ){
554
+		 // Get the minimum percentage need to pass this quiz
555
+		 $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
537 556
 
538
-             return false;
557
+		 // Handle Quiz Questions asked
558
+		 // This is to ensure we save the questions that we've asked this user and that this can't be change unless
559
+		 // the quiz is reset by admin or user( user: only if the setting is enabled ).
560
+		 // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
561
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
562
+		 $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
563
+		 if( empty( $questions_asked ) ){
539 564
 
540
-         }
565
+			 $questions_asked = array_keys( $quiz_answers );
566
+			 $questions_asked_string = implode( ',', $questions_asked );
541 567
 
542
-         // Default grade
543
-         $grade = 0;
568
+			 // Save questions that were asked in this quiz
569
+			 update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
544 570
 
545
-         // Get Quiz ID
546
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
571
+		 }
547 572
 
548
-         // Get quiz grade type
549
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
573
+		 // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
574
+		 self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
550 575
 
551
-         // Get quiz pass setting
552
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
576
+		 // Grade quiz
577
+		 $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
553 578
 
554
-         // Get the minimum percentage need to pass this quiz
555
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
579
+		 // Get Lesson Grading Setting
580
+		 $lesson_metadata = array();
581
+		 $lesson_status = 'ungraded'; // Default when completing a quiz
556 582
 
557
-         // Handle Quiz Questions asked
558
-         // This is to ensure we save the questions that we've asked this user and that this can't be change unless
559
-         // the quiz is reset by admin or user( user: only if the setting is enabled ).
560
-         // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
561
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
562
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
563
-         if( empty( $questions_asked ) ){
583
+		 // At this point the answers have been submitted
584
+		 $answers_submitted = true;
564 585
 
565
-             $questions_asked = array_keys( $quiz_answers );
566
-             $questions_asked_string = implode( ',', $questions_asked );
567
-
568
-             // Save questions that were asked in this quiz
569
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
586
+		 // if this condition is false the quiz should manually be graded by admin
587
+		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
570 588
 
571
-         }
589
+			 // Quiz has been automatically Graded
590
+			 if ( 'on' == $pass_required ) {
572 591
 
573
-         // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
574
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
592
+				 // Student has reached the pass mark and lesson is complete
593
+				 if ( $quiz_pass_percentage <= $grade ) {
575 594
 
576
-         // Grade quiz
577
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
595
+					 $lesson_status = 'passed';
578 596
 
579
-         // Get Lesson Grading Setting
580
-         $lesson_metadata = array();
581
-         $lesson_status = 'ungraded'; // Default when completing a quiz
597
+				 } else {
582 598
 
583
-         // At this point the answers have been submitted
584
-         $answers_submitted = true;
599
+					 $lesson_status = 'failed';
585 600
 
586
-         // if this condition is false the quiz should manually be graded by admin
587
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
601
+				 } // End If Statement
588 602
 
589
-             // Quiz has been automatically Graded
590
-             if ( 'on' == $pass_required ) {
603
+			 } else {
591 604
 
592
-                 // Student has reached the pass mark and lesson is complete
593
-                 if ( $quiz_pass_percentage <= $grade ) {
605
+				 // Student only has to partake the quiz
606
+				 $lesson_status = 'graded';
607
+
608
+			 }
609
+
610
+			 $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
611
+
612
+		 } // end if ! is_wp_error( $grade ...
613
+
614
+		 Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
594 615
 
595
-                     $lesson_status = 'passed';
616
+		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
596 617
 
597
-                 } else {
618
+			 /**
619
+			  * Lesson end action hook
620
+			  *
621
+			  * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
622
+			  *
623
+			  * @param int $user_id
624
+			  * @param int $lesson_id
625
+			  */
626
+			 do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
598 627
 
599
-                     $lesson_status = 'failed';
628
+		 }
600 629
 
601
-                 } // End If Statement
630
+		 /**
631
+		  * User quiz has been submitted
632
+		  *
633
+		  * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
634
+		  * results.
635
+		  *
636
+		  * @param int $user_id
637
+		  * @param int $quiz_id
638
+		  * @param string $grade
639
+		  * @param string $quiz_pass_percentage
640
+		  * @param string $quiz_grade_type
641
+		  */
642
+		 do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
602 643
 
603
-             } else {
644
+		 return $answers_submitted;
604 645
 
605
-                 // Student only has to partake the quiz
606
-                 $lesson_status = 'graded';
607
-
608
-             }
609
-
610
-             $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
611
-
612
-         } // end if ! is_wp_error( $grade ...
613
-
614
-         Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
646
+	 }// end submit_answers_for_grading
615 647
 
616
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
648
+	 /**
649
+	  * Get the user question answer
650
+	  *
651
+	  * This function gets the the users saved answer on given quiz for the given question parameter
652
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
653
+	  *
654
+	  * @since 1.7.4
655
+	  *
656
+	  * @param int  $lesson_id
657
+	  * @param int $question_id
658
+	  * @param int  $user_id ( optional )
659
+	  *
660
+	  * @return bool $answers_submitted
661
+	  */
662
+	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
617 663
 
618
-             /**
619
-              * Lesson end action hook
620
-              *
621
-              * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
622
-              *
623
-              * @param int $user_id
624
-              * @param int $lesson_id
625
-              */
626
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
664
+		 // parameter validation
665
+		 if( empty( $lesson_id ) || empty( $question_id )
666
+			 || ! ( intval( $lesson_id  ) > 0 )
667
+			 || ! ( intval( $question_id  ) > 0 )
668
+			 || 'lesson' != get_post_type( $lesson_id )
669
+			 || 'question' != get_post_type( $question_id )) {
627 670
 
628
-         }
671
+			 return false;
672
+		 }
673
+
674
+		 if( ! ( intval( $user_id ) > 0 )   ){
675
+			 $user_id = get_current_user_id();
676
+		 }
677
+
678
+		 $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
+
680
+		 if( !$users_answers || empty( $users_answers )
681
+		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
682
+
683
+			 //Fallback for pre 1.7.4 data
684
+			 $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
+
686
+			 if( ! isset( $comment->comment_content ) ){
687
+				 return false;
688
+			 }
689
+
690
+			 return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
+		 }
692
+
693
+		 return $users_answers[ $question_id ];
694
+
695
+	 }// end get_user_question_answer
696
+
697
+	 /**
698
+	  * Saving the users quiz question grades
699
+	  *
700
+	  * This function save all the grades for all the question in a given quiz on the lesson
701
+	  * comment meta. It makes use of transients to save the grades for easier access at a later stage
702
+	  *
703
+	  * @since 1.7.4
704
+	  *
705
+	  * @param array $quiz_grades{
706
+	  *      @type int $question_id
707
+	  *      @type int $question_grade
708
+	  * }
709
+	  * @param $lesson_id
710
+	  * @param $user_id (Optional) will use the current user if not supplied
711
+	  *
712
+	  * @return bool
713
+	  */
714
+	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
+
716
+		 // get the user_id if none was passed in use the current logged in user
717
+		 if( ! intval( $user_id ) > 0 ) {
718
+			 $user_id = get_current_user_id();
719
+		 }
720
+
721
+		 // make sure the parameters are valid before continuing
722
+		 if( empty( $lesson_id ) || empty( $user_id )
723
+			 || 'lesson' != get_post_type( $lesson_id )
724
+			 ||!get_userdata( $user_id )
725
+			 || !is_array( $quiz_grades ) ){
726
+
727
+			 return false;
728
+
729
+		 }
730
+
731
+		 $success = false;
732
+
733
+		 // save that data for the user on the lesson comment meta
734
+		 $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
+
736
+		 // were the grades save successfully ?
737
+		 if( intval( $comment_meta_id ) > 0 ) {
738
+
739
+			 $success = true;
740
+			 // save transient
741
+			 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
742
+			 set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
743
+		 }
744
+
745
+		 return $success;
746
+
747
+	 }// end set_user_grades
748
+
749
+	 /**
750
+	  * Retrieve the users quiz question grades
751
+	  *
752
+	  * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
753
+	  *
754
+	  * @since 1.7.4
755
+	  *
756
+	  * @param $lesson_id
757
+	  * @param $user_id (Optional) will use the current user if not supplied
758
+	  *
759
+	  * @return array $user_quiz_grades or false if none exists for this users
760
+	  */
761
+	 public function get_user_grades( $lesson_id, $user_id = 0 ){
762
+
763
+		 $user_grades = array();
764
+
765
+		 // get the user_id if none was passed in use the current logged in user
766
+		 if( ! intval( $user_id ) > 0 ) {
767
+			 $user_id = get_current_user_id();
768
+		 }
769
+
770
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
771
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
772
+			 return false;
773
+		 }
774
+
775
+		 // save some time and get the transient cached data
776
+		 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
777
+		 $user_grades = get_transient( $transient_key );
778
+
779
+		 // get the data if nothing was stored in the transient
780
+		 if( empty( $user_grades  ) || false != $user_grades ){
781
+
782
+			 $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
+
784
+			 //set the transient with the new valid data for faster retrieval in future
785
+			 set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
+
787
+		 } // end if transient check
788
+
789
+		 // if there is no data for this user
790
+		 if( ! is_array( $user_grades ) ){
791
+			 return false;
792
+		 }
793
+
794
+		 return $user_grades;
795
+
796
+	 }// end  get_user_grades
797
+
798
+	 /**
799
+	  * Get the user question grade
800
+	  *
801
+	  * This function gets the grade on a quiz for the given question parameter
802
+	  * It does NOT do any grading. It simply retrieves the data that was stored during grading.
803
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
804
+	  *
805
+	  * @since 1.7.4
806
+	  *
807
+	  * @param int  $lesson_id
808
+	  * @param int $question_id
809
+	  * @param int  $user_id ( optional )
810
+	  *
811
+	  * @return bool $question_grade
812
+	  */
813
+	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
+
815
+		 // parameter validation
816
+		 if( empty( $lesson_id ) || empty( $question_id )
817
+			 || ! ( intval( $lesson_id  ) > 0 )
818
+			 || ! ( intval( $question_id  ) > 0 )
819
+			 || 'lesson' != get_post_type( $lesson_id )
820
+			 || 'question' != get_post_type( $question_id )) {
821
+
822
+			 return false;
823
+		 }
824
+
825
+		 $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
+
827
+		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
+
829
+			 //fallback to data pre 1.7.4
830
+			 $args = array(
831
+				 'post_id' => $question_id,
832
+				 'user_id' => $user_id,
833
+				 'type'    => 'sensei_user_answer'
834
+			 );
835
+
836
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
837
+			 $fall_back_grade = false;
838
+			 if( isset( $question_activity->comment_ID ) ){
839
+				 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
840
+			 }
841
+
842
+			 return $fall_back_grade;
843
+
844
+		 } // end if $all_user_grades...
845
+
846
+		 return $all_user_grades[ $question_id ];
847
+
848
+	 }// end get_user_question_grade
849
+
850
+	 /**
851
+	  * Save the user's answers feedback
852
+	  *
853
+	  * For this function you must supply all three parameters. If will return false one is left out.
854
+	  * The data will be saved on the lesson ID supplied.
855
+	  *
856
+	  * @since 1.7.5
857
+	  * @access public
858
+	  *
859
+	  * @param array $answers_feedback{
860
+	  *  $type int $question_id
861
+	  *  $type string $question_feedback
862
+	  * }
863
+	  * @param int $lesson_id
864
+	  * @param int $user_id
865
+	  *
866
+	  * @return false or int $feedback_saved
867
+	  */
868
+	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
+
870
+		// make sure the parameters are valid before continuing
871
+		if( empty( $lesson_id ) || empty( $user_id )
872
+			|| 'lesson' != get_post_type( $lesson_id )
873
+			||!get_userdata( $user_id )
874
+			|| !is_array( $answers_feedback ) ){
875
+
876
+			return false;
877
+
878
+		}
879
+
880
+
881
+		// check if the lesson is started before saving, if not start the lesson for the user
882
+		if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
883
+			Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
884
+		}
629 885
 
630
-         /**
631
-          * User quiz has been submitted
632
-          *
633
-          * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
634
-          * results.
635
-          *
636
-          * @param int $user_id
637
-          * @param int $quiz_id
638
-          * @param string $grade
639
-          * @param string $quiz_pass_percentage
640
-          * @param string $quiz_grade_type
641
-          */
642
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
886
+		// encode the feedback
887
+		$encoded_answers_feedback =  array();
888
+		foreach( $answers_feedback as $question_id => $feedback ){
889
+			$encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
890
+		}
891
+
892
+		// save the user data
893
+		$feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
+
895
+		//Were the the question feedback save correctly?
896
+		if( intval( $feedback_saved ) > 0){
897
+
898
+			// save transient to make retrieval faster in future
899
+			 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
900
+			 set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
643 901
 
644
-         return $answers_submitted;
902
+		}
903
+
904
+		return $feedback_saved;
905
+
906
+	} // end save_user_answers_feedback
907
+
908
+	 /**
909
+	  * Get the user's answers feedback.
910
+	  *
911
+	  * This function returns the feedback submitted by the teacher/admin
912
+	  * during grading. Grading occurs manually or automatically.
913
+	  *
914
+	  * @since 1.7.5
915
+	  * @access public
916
+	  *
917
+	  * @param int $lesson_id
918
+	  * @param int $user_id
919
+	  *
920
+	  * @return false | array $answers_feedback{
921
+	  *  $type int $question_id
922
+	  *  $type string $question_feedback
923
+	  * }
924
+	  */
925
+	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
+
927
+		 $answers_feedback = array();
645 928
 
646
-     }// end submit_answers_for_grading
929
+		 // get the user_id if none was passed in use the current logged in user
930
+		 if( ! intval( $user_id ) > 0 ) {
931
+			 $user_id = get_current_user_id();
932
+		 }
647 933
 
648
-     /**
649
-      * Get the user question answer
650
-      *
651
-      * This function gets the the users saved answer on given quiz for the given question parameter
652
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
653
-      *
654
-      * @since 1.7.4
655
-      *
656
-      * @param int  $lesson_id
657
-      * @param int $question_id
658
-      * @param int  $user_id ( optional )
659
-      *
660
-      * @return bool $answers_submitted
661
-      */
662
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
934
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
935
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
936
+			 return false;
937
+		 }
938
+
939
+		 // first check the transient to save a few split seconds
940
+		 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
941
+		 $encoded_feedback = get_transient( $transient_key );
942
+
943
+		 // get the data if nothing was stored in the transient
944
+		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
+
946
+			 $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
+
948
+			 //set the transient with the new valid data for faster retrieval in future
949
+			 set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
+
951
+		 } // end if transient check
663 952
 
664
-         // parameter validation
665
-         if( empty( $lesson_id ) || empty( $question_id )
666
-             || ! ( intval( $lesson_id  ) > 0 )
667
-             || ! ( intval( $question_id  ) > 0 )
668
-             || 'lesson' != get_post_type( $lesson_id )
669
-             || 'question' != get_post_type( $question_id )) {
953
+		 // if there is no data for this user
954
+		 if( ! is_array( $encoded_feedback ) ){
955
+			 return false;
956
+		 }
670 957
 
671
-             return false;
672
-         }
673
-
674
-         if( ! ( intval( $user_id ) > 0 )   ){
675
-             $user_id = get_current_user_id();
676
-         }
677
-
678
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
-
680
-         if( !$users_answers || empty( $users_answers )
681
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
682
-
683
-             //Fallback for pre 1.7.4 data
684
-             $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
-
686
-             if( ! isset( $comment->comment_content ) ){
687
-                 return false;
688
-             }
689
-
690
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
-         }
692
-
693
-         return $users_answers[ $question_id ];
694
-
695
-     }// end get_user_question_answer
696
-
697
-     /**
698
-      * Saving the users quiz question grades
699
-      *
700
-      * This function save all the grades for all the question in a given quiz on the lesson
701
-      * comment meta. It makes use of transients to save the grades for easier access at a later stage
702
-      *
703
-      * @since 1.7.4
704
-      *
705
-      * @param array $quiz_grades{
706
-      *      @type int $question_id
707
-      *      @type int $question_grade
708
-      * }
709
-      * @param $lesson_id
710
-      * @param $user_id (Optional) will use the current user if not supplied
711
-      *
712
-      * @return bool
713
-      */
714
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
-
716
-         // get the user_id if none was passed in use the current logged in user
717
-         if( ! intval( $user_id ) > 0 ) {
718
-             $user_id = get_current_user_id();
719
-         }
720
-
721
-         // make sure the parameters are valid before continuing
722
-         if( empty( $lesson_id ) || empty( $user_id )
723
-             || 'lesson' != get_post_type( $lesson_id )
724
-             ||!get_userdata( $user_id )
725
-             || !is_array( $quiz_grades ) ){
726
-
727
-             return false;
728
-
729
-         }
730
-
731
-         $success = false;
732
-
733
-         // save that data for the user on the lesson comment meta
734
-         $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
-
736
-         // were the grades save successfully ?
737
-         if( intval( $comment_meta_id ) > 0 ) {
738
-
739
-             $success = true;
740
-             // save transient
741
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
742
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
743
-         }
744
-
745
-         return $success;
746
-
747
-     }// end set_user_grades
748
-
749
-     /**
750
-      * Retrieve the users quiz question grades
751
-      *
752
-      * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
753
-      *
754
-      * @since 1.7.4
755
-      *
756
-      * @param $lesson_id
757
-      * @param $user_id (Optional) will use the current user if not supplied
758
-      *
759
-      * @return array $user_quiz_grades or false if none exists for this users
760
-      */
761
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
762
-
763
-         $user_grades = array();
764
-
765
-         // get the user_id if none was passed in use the current logged in user
766
-         if( ! intval( $user_id ) > 0 ) {
767
-             $user_id = get_current_user_id();
768
-         }
769
-
770
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
771
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
772
-             return false;
773
-         }
774
-
775
-         // save some time and get the transient cached data
776
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
777
-         $user_grades = get_transient( $transient_key );
778
-
779
-         // get the data if nothing was stored in the transient
780
-         if( empty( $user_grades  ) || false != $user_grades ){
781
-
782
-             $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
-
784
-             //set the transient with the new valid data for faster retrieval in future
785
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
-
787
-         } // end if transient check
788
-
789
-         // if there is no data for this user
790
-         if( ! is_array( $user_grades ) ){
791
-             return false;
792
-         }
793
-
794
-         return $user_grades;
795
-
796
-     }// end  get_user_grades
797
-
798
-     /**
799
-      * Get the user question grade
800
-      *
801
-      * This function gets the grade on a quiz for the given question parameter
802
-      * It does NOT do any grading. It simply retrieves the data that was stored during grading.
803
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
804
-      *
805
-      * @since 1.7.4
806
-      *
807
-      * @param int  $lesson_id
808
-      * @param int $question_id
809
-      * @param int  $user_id ( optional )
810
-      *
811
-      * @return bool $question_grade
812
-      */
813
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
-
815
-         // parameter validation
816
-         if( empty( $lesson_id ) || empty( $question_id )
817
-             || ! ( intval( $lesson_id  ) > 0 )
818
-             || ! ( intval( $question_id  ) > 0 )
819
-             || 'lesson' != get_post_type( $lesson_id )
820
-             || 'question' != get_post_type( $question_id )) {
821
-
822
-             return false;
823
-         }
824
-
825
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
-
827
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
-
829
-             //fallback to data pre 1.7.4
830
-             $args = array(
831
-                 'post_id' => $question_id,
832
-                 'user_id' => $user_id,
833
-                 'type'    => 'sensei_user_answer'
834
-             );
835
-
836
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
837
-             $fall_back_grade = false;
838
-             if( isset( $question_activity->comment_ID ) ){
839
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
840
-             }
841
-
842
-             return $fall_back_grade;
843
-
844
-         } // end if $all_user_grades...
845
-
846
-         return $all_user_grades[ $question_id ];
847
-
848
-     }// end get_user_question_grade
849
-
850
-     /**
851
-      * Save the user's answers feedback
852
-      *
853
-      * For this function you must supply all three parameters. If will return false one is left out.
854
-      * The data will be saved on the lesson ID supplied.
855
-      *
856
-      * @since 1.7.5
857
-      * @access public
858
-      *
859
-      * @param array $answers_feedback{
860
-      *  $type int $question_id
861
-      *  $type string $question_feedback
862
-      * }
863
-      * @param int $lesson_id
864
-      * @param int $user_id
865
-      *
866
-      * @return false or int $feedback_saved
867
-      */
868
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
-
870
-        // make sure the parameters are valid before continuing
871
-        if( empty( $lesson_id ) || empty( $user_id )
872
-            || 'lesson' != get_post_type( $lesson_id )
873
-            ||!get_userdata( $user_id )
874
-            || !is_array( $answers_feedback ) ){
875
-
876
-            return false;
877
-
878
-        }
879
-
880
-
881
-        // check if the lesson is started before saving, if not start the lesson for the user
882
-        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
883
-            Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
884
-        }
885
-
886
-        // encode the feedback
887
-        $encoded_answers_feedback =  array();
888
-        foreach( $answers_feedback as $question_id => $feedback ){
889
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
890
-        }
891
-
892
-        // save the user data
893
-        $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
-
895
-        //Were the the question feedback save correctly?
896
-        if( intval( $feedback_saved ) > 0){
897
-
898
-            // save transient to make retrieval faster in future
899
-             $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
900
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
901
-
902
-        }
903
-
904
-        return $feedback_saved;
905
-
906
-    } // end save_user_answers_feedback
907
-
908
-     /**
909
-      * Get the user's answers feedback.
910
-      *
911
-      * This function returns the feedback submitted by the teacher/admin
912
-      * during grading. Grading occurs manually or automatically.
913
-      *
914
-      * @since 1.7.5
915
-      * @access public
916
-      *
917
-      * @param int $lesson_id
918
-      * @param int $user_id
919
-      *
920
-      * @return false | array $answers_feedback{
921
-      *  $type int $question_id
922
-      *  $type string $question_feedback
923
-      * }
924
-      */
925
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
-
927
-         $answers_feedback = array();
928
-
929
-         // get the user_id if none was passed in use the current logged in user
930
-         if( ! intval( $user_id ) > 0 ) {
931
-             $user_id = get_current_user_id();
932
-         }
933
-
934
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
935
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
936
-             return false;
937
-         }
938
-
939
-         // first check the transient to save a few split seconds
940
-         $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
941
-         $encoded_feedback = get_transient( $transient_key );
942
-
943
-         // get the data if nothing was stored in the transient
944
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
-
946
-             $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
-
948
-             //set the transient with the new valid data for faster retrieval in future
949
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
-
951
-         } // end if transient check
952
-
953
-         // if there is no data for this user
954
-         if( ! is_array( $encoded_feedback ) ){
955
-             return false;
956
-         }
957
-
958
-         foreach( $encoded_feedback as $question_id => $feedback ){
958
+		 foreach( $encoded_feedback as $question_id => $feedback ){
959 959
 
960
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
960
+			 $answers_feedback[ $question_id ] = base64_decode( $feedback );
961 961
 
962
-         }
962
+		 }
963 963
 
964
-         return $answers_feedback;
964
+		 return $answers_feedback;
965 965
 
966
-     } // end get_user_answers_feedback
966
+	 } // end get_user_answers_feedback
967 967
 
968
-     /**
969
-      * Get the user's answer feedback for a specific question.
970
-      *
971
-      * This function gives you a single answer note/feedback string
972
-      * for the user on the given question.
973
-      *
974
-      * @since 1.7.5
975
-      * @access public
976
-      *
977
-      * @param int $lesson_id
978
-      * @param int $question_id
979
-      * @param int $user_id
980
-      *
981
-      * @return string $feedback or bool if false
982
-      */
983
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
968
+	 /**
969
+	  * Get the user's answer feedback for a specific question.
970
+	  *
971
+	  * This function gives you a single answer note/feedback string
972
+	  * for the user on the given question.
973
+	  *
974
+	  * @since 1.7.5
975
+	  * @access public
976
+	  *
977
+	  * @param int $lesson_id
978
+	  * @param int $question_id
979
+	  * @param int $user_id
980
+	  *
981
+	  * @return string $feedback or bool if false
982
+	  */
983
+	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
984 984
 
985
-         $feedback = false;
985
+		 $feedback = false;
986 986
 
987
-         // parameter validation
988
-         if( empty( $lesson_id ) || empty( $question_id )
989
-             || ! ( intval( $lesson_id  ) > 0 )
990
-             || ! ( intval( $question_id  ) > 0 )
991
-             || 'lesson' != get_post_type( $lesson_id )
992
-             || 'question' != get_post_type( $question_id )) {
987
+		 // parameter validation
988
+		 if( empty( $lesson_id ) || empty( $question_id )
989
+			 || ! ( intval( $lesson_id  ) > 0 )
990
+			 || ! ( intval( $question_id  ) > 0 )
991
+			 || 'lesson' != get_post_type( $lesson_id )
992
+			 || 'question' != get_post_type( $question_id )) {
993 993
 
994
-             return false;
995
-         }
994
+			 return false;
995
+		 }
996 996
 
997
-         // get all the feedback for the user on the given lesson
998
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
997
+		 // get all the feedback for the user on the given lesson
998
+		 $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
999 999
 
1000
-         if( !$all_feedback || empty( $all_feedback )
1001
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1000
+		 if( !$all_feedback || empty( $all_feedback )
1001
+			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1002 1002
 
1003
-             //fallback to data pre 1.7.4
1003
+			 //fallback to data pre 1.7.4
1004 1004
 
1005
-             // setup the sensei data query
1006
-             $args = array(
1007
-                 'post_id' => $question_id,
1008
-                 'user_id' => $user_id,
1009
-                 'type'    => 'sensei_user_answer'
1010
-             );
1011
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1005
+			 // setup the sensei data query
1006
+			 $args = array(
1007
+				 'post_id' => $question_id,
1008
+				 'user_id' => $user_id,
1009
+				 'type'    => 'sensei_user_answer'
1010
+			 );
1011
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1012 1012
 
1013
-             // set the default to false and return that if no old data is available.
1014
-             if( isset( $question_activity->comment_ID ) ){
1015
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1016
-             }
1013
+			 // set the default to false and return that if no old data is available.
1014
+			 if( isset( $question_activity->comment_ID ) ){
1015
+				 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1016
+			 }
1017 1017
 
1018
-             // finally use the default question feedback
1019
-             if( empty( $feedback ) ){
1020
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1021
-             }
1018
+			 // finally use the default question feedback
1019
+			 if( empty( $feedback ) ){
1020
+				 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1021
+			 }
1022 1022
 
1023
-             return $feedback;
1023
+			 return $feedback;
1024 1024
 
1025
-         }
1025
+		 }
1026 1026
 
1027
-         return $all_feedback[ $question_id ];
1027
+		 return $all_feedback[ $question_id ];
1028 1028
 
1029
-     } // end get_user_question_feedback
1029
+	 } // end get_user_question_feedback
1030 1030
 
1031
-     /**
1032
-      * Check if a quiz has no questions, and redirect back to lesson.
1033
-      *
1034
-      * Though a quiz is created for each lesson, it should not be visible
1035
-      * unless it has questions.
1036
-      *
1037
-      * @since 1.9.0
1038
-      * @access public
1039
-      * @param none
1040
-      * @return void
1041
-      */
1031
+	 /**
1032
+	  * Check if a quiz has no questions, and redirect back to lesson.
1033
+	  *
1034
+	  * Though a quiz is created for each lesson, it should not be visible
1035
+	  * unless it has questions.
1036
+	  *
1037
+	  * @since 1.9.0
1038
+	  * @access public
1039
+	  * @param none
1040
+	  * @return void
1041
+	  */
1042 1042
 
1043
-     public function quiz_has_no_questions() {
1043
+	 public function quiz_has_no_questions() {
1044 1044
 
1045
-         if( ! is_singular( 'quiz' ) )  {
1046
-             return;
1047
-         }
1045
+		 if( ! is_singular( 'quiz' ) )  {
1046
+			 return;
1047
+		 }
1048 1048
 
1049
-         global $post;
1049
+		 global $post;
1050 1050
 
1051
-         $lesson_id = $this->get_lesson_id($post->ID);
1051
+		 $lesson_id = $this->get_lesson_id($post->ID);
1052 1052
 
1053
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1053
+		 $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1054 1054
 
1055
-         $lesson = get_post($lesson_id);
1055
+		 $lesson = get_post($lesson_id);
1056 1056
 
1057
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1057
+		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1058 1058
 
1059
-             wp_redirect(get_permalink($lesson->ID), 301);
1060
-             exit;
1059
+			 wp_redirect(get_permalink($lesson->ID), 301);
1060
+			 exit;
1061 1061
 
1062
-         }
1062
+		 }
1063 1063
 
1064
-     } // end quiz_has_no_questions
1064
+	 } // end quiz_has_no_questions
1065 1065
 
1066 1066
 /**
1067
-  * Deprecate the sensei_single_main_content on the single-quiz template.
1068
-  *
1069
-  * @deprecated since 1.9.0
1070
-  */
1067
+ * Deprecate the sensei_single_main_content on the single-quiz template.
1068
+ *
1069
+ * @deprecated since 1.9.0
1070
+ */
1071 1071
  public static function deprecate_quiz_sensei_single_main_content_hook(){
1072 1072
 
1073
-     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1073
+	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1074 1074
 
1075 1075
  }
1076
-    /*
1076
+	/*
1077 1077
      * Deprecate the sensei_quiz_single_title on the single-quiz template.
1078 1078
      *
1079 1079
      * @deprecated since 1.9.0
1080 1080
      */
1081
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1081
+	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1082 1082
 
1083
-         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1083
+		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1084 1084
 
1085
-     }
1085
+	 }
1086 1086
 
1087
-     /**
1088
-      * Filter the single title and add the Quiz to it.
1089
-      *
1090
-      * @param string $title
1091
-      * @param int $id title post id
1092
-      * @return string $quiz_title
1093
-      */
1094
-     public static function single_quiz_title( $title, $post_id ){
1087
+	 /**
1088
+	  * Filter the single title and add the Quiz to it.
1089
+	  *
1090
+	  * @param string $title
1091
+	  * @param int $id title post id
1092
+	  * @return string $quiz_title
1093
+	  */
1094
+	 public static function single_quiz_title( $title, $post_id ){
1095 1095
 
1096
-         if( 'quiz' == get_post_type( $post_id ) ){
1096
+		 if( 'quiz' == get_post_type( $post_id ) ){
1097 1097
 
1098
-             $title_with_no_quizzes = $title;
1098
+			 $title_with_no_quizzes = $title;
1099 1099
 
1100
-             // if the title has quiz, remove it: legacy titles have the word quiz stored.
1101
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1100
+			 // if the title has quiz, remove it: legacy titles have the word quiz stored.
1101
+			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1102 1102
 
1103
-                 // remove all possible appearances of quiz
1104
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1105
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1106
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1103
+				 // remove all possible appearances of quiz
1104
+				 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1105
+				 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1106
+				 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1107 1107
 
1108
-             }
1108
+			 }
1109 1109
 
1110
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1111
-         }
1110
+			 $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1111
+		 }
1112 1112
 
1113
-         /**
1114
-          * hook document in class-woothemes-sensei-message.php
1115
-          */
1116
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1113
+		 /**
1114
+		  * hook document in class-woothemes-sensei-message.php
1115
+		  */
1116
+		 return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1117 1117
 
1118
-     }
1118
+	 }
1119 1119
 
1120
-     /**
1121
-      * Initialize the quiz question loop on the single quiz template
1122
-      *
1123
-      * The function will create a global quiz loop varialbe.
1124
-      *
1125
-      * @since 1.9.0
1126
-      *
1127
-      */
1128
-     public static function start_quiz_questions_loop(){
1120
+	 /**
1121
+	  * Initialize the quiz question loop on the single quiz template
1122
+	  *
1123
+	  * The function will create a global quiz loop varialbe.
1124
+	  *
1125
+	  * @since 1.9.0
1126
+	  *
1127
+	  */
1128
+	 public static function start_quiz_questions_loop(){
1129 1129
 
1130
-         global $sensei_question_loop;
1130
+		 global $sensei_question_loop;
1131 1131
 
1132
-         //intialize the questions loop object
1133
-         $sensei_question_loop['current'] = -1;
1134
-         $sensei_question_loop['total']   =  0;
1135
-         $sensei_question_loop['questions'] = array();
1132
+		 //intialize the questions loop object
1133
+		 $sensei_question_loop['current'] = -1;
1134
+		 $sensei_question_loop['total']   =  0;
1135
+		 $sensei_question_loop['questions'] = array();
1136 1136
 
1137 1137
 
1138
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1138
+		 $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1139 1139
 
1140
-         if( count( $questions  ) > 0  ){
1140
+		 if( count( $questions  ) > 0  ){
1141 1141
 
1142
-             $sensei_question_loop['total']   =  count( $questions );
1143
-             $sensei_question_loop['questions'] = $questions;
1144
-             $sensei_question_loop['quiz_id'] = get_the_ID();
1142
+			 $sensei_question_loop['total']   =  count( $questions );
1143
+			 $sensei_question_loop['questions'] = $questions;
1144
+			 $sensei_question_loop['quiz_id'] = get_the_ID();
1145 1145
 
1146
-         }
1146
+		 }
1147 1147
 
1148
-     }// static function
1148
+	 }// static function
1149 1149
 
1150
-     /**
1151
-      * Initialize the quiz question loop on the single quiz template
1152
-      *
1153
-      * The function will create a global quiz loop varialbe.
1154
-      *
1155
-      * @since 1.9.0
1156
-      *
1157
-      */
1158
-     public static function stop_quiz_questions_loop(){
1150
+	 /**
1151
+	  * Initialize the quiz question loop on the single quiz template
1152
+	  *
1153
+	  * The function will create a global quiz loop varialbe.
1154
+	  *
1155
+	  * @since 1.9.0
1156
+	  *
1157
+	  */
1158
+	 public static function stop_quiz_questions_loop(){
1159 1159
 
1160
-         $sensei_question_loop['total']   =  0;
1161
-         $sensei_question_loop['questions'] = array();
1162
-         $sensei_question_loop['quiz_id'] = '';
1160
+		 $sensei_question_loop['total']   =  0;
1161
+		 $sensei_question_loop['questions'] = array();
1162
+		 $sensei_question_loop['quiz_id'] = '';
1163 1163
 
1164
-     }
1164
+	 }
1165 1165
 
1166
-     /**
1167
-      * Output the title for the single quiz page
1168
-      *
1169
-      * @since 1.9.0
1170
-      */
1171
-     public static function the_title(){
1172
-         ?>
1166
+	 /**
1167
+	  * Output the title for the single quiz page
1168
+	  *
1169
+	  * @since 1.9.0
1170
+	  */
1171
+	 public static function the_title(){
1172
+		 ?>
1173 1173
          <header>
1174 1174
 
1175 1175
              <h1>
1176 1176
 
1177 1177
                  <?php
1178
-                 /**
1179
-                  * Filter documented in class-sensei-messages.php the_title
1180
-                  */
1181
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1182
-                 ?>
1178
+				 /**
1179
+				  * Filter documented in class-sensei-messages.php the_title
1180
+				  */
1181
+				 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1182
+				 ?>
1183 1183
 
1184 1184
              </h1>
1185 1185
 
1186 1186
          </header>
1187 1187
 
1188 1188
          <?php
1189
-     }//the_title
1189
+	 }//the_title
1190 1190
 
1191
-     /**
1192
-      * Output the sensei quiz status message.
1193
-      *
1194
-      * @param $quiz_id
1195
-      */
1196
-    public static function  the_user_status_message( $quiz_id ){
1191
+	 /**
1192
+	  * Output the sensei quiz status message.
1193
+	  *
1194
+	  * @param $quiz_id
1195
+	  */
1196
+	public static function  the_user_status_message( $quiz_id ){
1197 1197
 
1198
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1199
-        $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1200
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1198
+		$lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1199
+		$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1200
+		echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1201 1201
 
1202
-    }
1202
+	}
1203 1203
 
1204
-     /**
1205
-      * This functions runs the old sensei_quiz_action_buttons action
1206
-      * for backwards compatiblity sake.
1207
-      *
1208
-      * @since 1.9.0
1209
-      * @deprecated
1210
-      */
1211
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1204
+	 /**
1205
+	  * This functions runs the old sensei_quiz_action_buttons action
1206
+	  * for backwards compatiblity sake.
1207
+	  *
1208
+	  * @since 1.9.0
1209
+	  * @deprecated
1210
+	  */
1211
+	 public static function deprecate_sensei_quiz_action_buttons_hook(){
1212 1212
 
1213
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1213
+		 sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1214 1214
 
1215
-     }
1215
+	 }
1216 1216
 
1217
-     /**
1218
-      * The quiz action buttons needed to ouput quiz
1219
-      * action such as reset complete and save.
1220
-      *
1221
-      * @since 1.3.0
1222
-      */
1223
-     public static function action_buttons() {
1217
+	 /**
1218
+	  * The quiz action buttons needed to ouput quiz
1219
+	  * action such as reset complete and save.
1220
+	  *
1221
+	  * @since 1.3.0
1222
+	  */
1223
+	 public static function action_buttons() {
1224 1224
 
1225
-         global $post, $current_user;
1225
+		 global $post, $current_user;
1226 1226
 
1227
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1228
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1229
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1230
-         $show_actions = true;
1231
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1227
+		 $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1228
+		 $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1229
+		 $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1230
+		 $show_actions = true;
1231
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1232 1232
 
1233
-         //setup quiz grade
1234
-         $user_quiz_grade = '';
1235
-         if( ! empty( $user_lesson_status  ) ){
1236
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
-         }
1233
+		 //setup quiz grade
1234
+		 $user_quiz_grade = '';
1235
+		 if( ! empty( $user_lesson_status  ) ){
1236
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
+		 }
1238 1238
 
1239 1239
 
1240
-         if( intval( $lesson_prerequisite ) > 0 ) {
1240
+		 if( intval( $lesson_prerequisite ) > 0 ) {
1241 1241
 
1242
-             // If the user hasn't completed the prereq then hide the current actions
1243
-             $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1242
+			 // If the user hasn't completed the prereq then hide the current actions
1243
+			 $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1244 1244
 
1245
-         }
1246
-         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1245
+		 }
1246
+		 if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1247 1247
 
1248
-             // Get Reset Settings
1249
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1248
+			 // Get Reset Settings
1249
+			 $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1250 1250
 
1251 1251
              <!-- Action Nonce's -->
1252 1252
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
@@ -1273,55 +1273,55 @@  discard block
 block discarded – undo
1273 1273
 
1274 1274
          <?php }
1275 1275
 
1276
-     } // End sensei_quiz_action_buttons()
1277
-
1278
-     /**
1279
-      * Fetch the quiz grade
1280
-      *
1281
-      * @since 1.9.0
1282
-      *
1283
-      * @param int $lesson_id
1284
-      * @param int $user_id
1285
-      *
1286
-      * @return double $user_quiz_grade
1287
-      */
1288
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1289
-
1290
-         // get the quiz grade
1291
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1292
-         $user_quiz_grade = 0;
1293
-         if( isset( $user_lesson_status->comment_ID ) ) {
1294
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
-         }
1296
-
1297
-         return (double) $user_quiz_grade;
1298
-
1299
-     }
1300
-
1301
-     /**
1302
-      * Check the quiz reset property for a given lesson's quiz.
1303
-      *
1304
-      * The data is stored on the quiz but going forward the quiz post
1305
-      * type will be retired, hence the lesson_id is a require parameter.
1306
-      *
1307
-      * @since 1.9.0
1308
-      *
1309
-      * @param int $lesson_id
1310
-      * @return bool
1311
-      */
1312
-     public static function is_reset_allowed( $lesson_id ){
1313
-
1314
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1315
-
1316
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1317
-         //backwards compatibility
1318
-         if( 'on' == $reset_allowed ) {
1319
-             $reset_allowed = 1;
1320
-         }
1321
-
1322
-         return (bool) $reset_allowed;
1323
-
1324
-     }
1276
+	 } // End sensei_quiz_action_buttons()
1277
+
1278
+	 /**
1279
+	  * Fetch the quiz grade
1280
+	  *
1281
+	  * @since 1.9.0
1282
+	  *
1283
+	  * @param int $lesson_id
1284
+	  * @param int $user_id
1285
+	  *
1286
+	  * @return double $user_quiz_grade
1287
+	  */
1288
+	 public static function get_user_quiz_grade( $lesson_id, $user_id ){
1289
+
1290
+		 // get the quiz grade
1291
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1292
+		 $user_quiz_grade = 0;
1293
+		 if( isset( $user_lesson_status->comment_ID ) ) {
1294
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
+		 }
1296
+
1297
+		 return (double) $user_quiz_grade;
1298
+
1299
+	 }
1300
+
1301
+	 /**
1302
+	  * Check the quiz reset property for a given lesson's quiz.
1303
+	  *
1304
+	  * The data is stored on the quiz but going forward the quiz post
1305
+	  * type will be retired, hence the lesson_id is a require parameter.
1306
+	  *
1307
+	  * @since 1.9.0
1308
+	  *
1309
+	  * @param int $lesson_id
1310
+	  * @return bool
1311
+	  */
1312
+	 public static function is_reset_allowed( $lesson_id ){
1313
+
1314
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1315
+
1316
+		 $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1317
+		 //backwards compatibility
1318
+		 if( 'on' == $reset_allowed ) {
1319
+			 $reset_allowed = 1;
1320
+		 }
1321
+
1322
+		 return (bool) $reset_allowed;
1323
+
1324
+	 }
1325 1325
 
1326 1326
  } // End Class WooThemes_Sensei_Quiz
1327 1327
 
Please login to merge, or discard this patch.
includes/class-sensei-learners-main.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 
206 206
 	/**
207 207
 	 * Generates content for a single row of the table in the user management
208
-     * screen.
209
-     *
208
+	 * screen.
209
+	 *
210 210
 	 * @since  1.7.0
211
-     *
211
+	 *
212 212
 	 * @param object $item The current item
213
-     *
214
-     * @return void
213
+	 *
214
+	 * @return void
215 215
 	 */
216 216
 	protected function get_row_data( $item ) {
217 217
 		global $wp_version;
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 		switch ( $this->view ) {
220 220
 			case 'learners' :
221 221
 
222
-                // in this case the item passed in is actually the users activity on course of lesson
223
-                $user_activity = $item;
222
+				// in this case the item passed in is actually the users activity on course of lesson
223
+				$user_activity = $item;
224 224
 				$post_id = false;
225 225
 
226 226
 				if( $this->lesson_id ) {
@@ -239,30 +239,30 @@  discard block
 block discarded – undo
239 239
 
240 240
 				if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) {
241 241
 
242
-                    $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
242
+					$status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
243 243
 
244 244
 				} else {
245 245
 
246
-                    $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
246
+					$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
247 247
 
248 248
 				}
249 249
 
250
-                $title = Sensei_Learner::get_full_name( $user_activity->user_id );
250
+				$title = Sensei_Learner::get_full_name( $user_activity->user_id );
251 251
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
252 252
 
253
-                /**
254
-                 * sensei_learners_main_column_data filter
255
-                 *
256
-                 * This filter runs on the learner management screen for a specific course.
257
-                 * It provides the learner row column details.
258
-                 *
259
-                 * @param array $columns{
260
-                 *   type string $title
261
-                 *   type string $date_started
262
-                 *   type string $course_status (completed, started etc)
263
-                 *   type html $action_buttons
264
-                 * }
265
-                 */
253
+				/**
254
+				 * sensei_learners_main_column_data filter
255
+				 *
256
+				 * This filter runs on the learner management screen for a specific course.
257
+				 * It provides the learner row column details.
258
+				 *
259
+				 * @param array $columns{
260
+				 *   type string $title
261
+				 *   type string $date_started
262
+				 *   type string $course_status (completed, started etc)
263
+				 *   type html $action_buttons
264
+				 * }
265
+				 */
266 266
 				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
267 267
 						'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>',
268 268
 						'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true),
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
 			case 'courses' :
294 294
 			default:
295
-                $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
295
+				$course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
296 296
 				$title = get_the_title( $item );
297 297
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
298 298
 
Please login to merge, or discard this patch.
includes/class-sensei-grading.php 1 patch
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 	/**
21 21
 	 * Constructor
22 22
 	 * @since  1.3.0
23
-     *
24
-     * @param $file
23
+	 *
24
+	 * @param $file
25 25
 	 */
26 26
 	public function __construct ( $file ) {
27 27
 		$this->name = __( 'Grading', 'woothemes-sensei' );
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * Outputs Grading general headers
232 232
 	 * @since  1.3.0
233
-     * @param array $args
233
+	 * @param array $args
234 234
 	 * @return void
235 235
 	 */
236 236
 	public function grading_headers( $args = array( 'nav' => 'default' ) ) {
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		}
283 283
 		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
284 284
 
285
-            $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
285
+			$user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
286 286
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
287 287
 
288 288
 		} // End If Statement
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		}
317 317
 		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
318 318
 
319
-            $user_name = Sensei_Learner::get_full_name( $_GET['user'] );
319
+			$user_name = Sensei_Learner::get_full_name( $_GET['user'] );
320 320
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
321 321
 
322 322
 		} // End If Statement
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	public function count_statuses( $args = array() ) {
366 366
 		global  $wpdb;
367 367
 
368
-        /**
369
-         * Filter fires inside Sensei_Grading::count_statuses
370
-         *
371
-         * Alter the the post_in array to determine which posts the
372
-         * comment query should be limited to.
373
-         * @since 1.8.0
374
-         * @param array $args
375
-         */
376
-        $args = apply_filters( 'sensei_count_statuses_args', $args );
368
+		/**
369
+		 * Filter fires inside Sensei_Grading::count_statuses
370
+		 *
371
+		 * Alter the the post_in array to determine which posts the
372
+		 * comment query should be limited to.
373
+		 * @since 1.8.0
374
+		 * @param array $args
375
+		 */
376
+		$args = apply_filters( 'sensei_count_statuses_args', $args );
377 377
 
378 378
 		if ( 'course' == $args['type'] ) {
379 379
 			$type = 'sensei_course_status';
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 
386 386
 		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s ";
387 387
 
388
-        // Restrict to specific posts
388
+		// Restrict to specific posts
389 389
 		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
390 390
 			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
391 391
 		}
@@ -520,148 +520,148 @@  discard block
 block discarded – undo
520 520
 		return $html;
521 521
 	} // End lessons_drop_down_html()
522 522
 
523
-    /**
524
-     * The process grading function handles admin grading submissions.
525
-     *
526
-     * This function is hooked on to admin_init. It simply accepts
527
-     * the grades as the Grader selected theme and saves the total grade and
528
-     * individual question grades.
529
-     *
530
-     * @return bool
531
-     */
532
-    public function admin_process_grading_submission() {
523
+	/**
524
+	 * The process grading function handles admin grading submissions.
525
+	 *
526
+	 * This function is hooked on to admin_init. It simply accepts
527
+	 * the grades as the Grader selected theme and saves the total grade and
528
+	 * individual question grades.
529
+	 *
530
+	 * @return bool
531
+	 */
532
+	public function admin_process_grading_submission() {
533 533
 
534
-        // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
-        if( ! isset( $_POST['sensei_manual_grade'] )
536
-            || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
-            || ! isset( $_GET['quiz_id'] )
538
-            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
534
+		// NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
+		if( ! isset( $_POST['sensei_manual_grade'] )
536
+			|| ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
+			|| ! isset( $_GET['quiz_id'] )
538
+			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
539 539
 
540
-            return false; //exit and do not grade
540
+			return false; //exit and do not grade
541 541
 
542
-        }
542
+		}
543 543
 
544
-        $quiz_id = $_GET['quiz_id'];
545
-        $user_id = $_GET['user'];
544
+		$quiz_id = $_GET['quiz_id'];
545
+		$user_id = $_GET['user'];
546 546
 
547 547
 
548
-        $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
-        $quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
-        $quiz_grade = 0;
551
-        $count = 0;
552
-        $quiz_grade_total = $_POST['quiz_grade_total'];
553
-        $all_question_grades = array();
554
-        $all_answers_feedback = array();
548
+		$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
+		$quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
+		$quiz_grade = 0;
551
+		$count = 0;
552
+		$quiz_grade_total = $_POST['quiz_grade_total'];
553
+		$all_question_grades = array();
554
+		$all_answers_feedback = array();
555 555
 
556
-        foreach( $questions as $question ) {
556
+		foreach( $questions as $question ) {
557 557
 
558
-            ++$count;
559
-            $question_id = $question->ID;
558
+			++$count;
559
+			$question_id = $question->ID;
560 560
 
561
-            if( isset( $_POST[ 'question_' . $question_id ] ) ) {
561
+			if( isset( $_POST[ 'question_' . $question_id ] ) ) {
562 562
 
563
-                $question_grade = 0;
564
-                if( $_POST[ 'question_' . $question_id ] == 'right' ) {
563
+				$question_grade = 0;
564
+				if( $_POST[ 'question_' . $question_id ] == 'right' ) {
565 565
 
566
-                    $question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
566
+					$question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
567 567
 
568
-                }
568
+				}
569 569
 
570
-                // add data to the array that will, after the loop, be stored on the lesson status
571
-                $all_question_grades[ $question_id ] = $question_grade;
570
+				// add data to the array that will, after the loop, be stored on the lesson status
571
+				$all_question_grades[ $question_id ] = $question_grade;
572 572
 
573
-                // tally up the total quiz grade
574
-                $quiz_grade += $question_grade;
573
+				// tally up the total quiz grade
574
+				$quiz_grade += $question_grade;
575 575
 
576
-            } // endif
576
+			} // endif
577 577
 
578
-            // Question answer feedback / notes
579
-            $question_feedback = '';
580
-            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
578
+			// Question answer feedback / notes
579
+			$question_feedback = '';
580
+			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
581 581
 
582
-                $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
582
+				$question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
583 583
 
584
-            }
585
-            $all_answers_feedback[ $question_id ] = $question_feedback;
584
+			}
585
+			$all_answers_feedback[ $question_id ] = $question_feedback;
586 586
 
587
-        } // end for each $questions
587
+		} // end for each $questions
588 588
 
589
-        //store all question grades on the lesson status
590
-        Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
589
+		//store all question grades on the lesson status
590
+		Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
591 591
 
592
-        //store the feedback from grading
593
-        Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
592
+		//store the feedback from grading
593
+		Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
594 594
 
595
-        // $_POST['all_questions_graded'] is set when all questions have been graded
596
-        // in the class sensei grading user quiz -> display()
597
-        if( $_POST['all_questions_graded'] == 'yes' ) {
595
+		// $_POST['all_questions_graded'] is set when all questions have been graded
596
+		// in the class sensei grading user quiz -> display()
597
+		if( $_POST['all_questions_graded'] == 'yes' ) {
598 598
 
599
-            // set the users total quiz grade
599
+			// set the users total quiz grade
600 600
 			if ( 0 < intval( $quiz_grade_total ) ) {
601
-            $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
601
+			$grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
602 602
 			}
603 603
 			else {
604 604
 				$grade = 0;
605 605
 			}
606
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
-
608
-            // Duplicating what Frontend->sensei_complete_quiz() does
609
-            $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
-            $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
-            $lesson_metadata = array();
612
-            if ( $pass_required ) {
613
-                // Student has reached the pass mark and lesson is complete
614
-                if ( $quiz_passmark <= $grade ) {
615
-                    $lesson_status = 'passed';
616
-                }
617
-                else {
618
-                    $lesson_status = 'failed';
619
-                } // End If Statement
620
-            }
621
-            // Student only has to partake the quiz
622
-            else {
623
-                $lesson_status = 'graded';
624
-            }
625
-            $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
606
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
+
608
+			// Duplicating what Frontend->sensei_complete_quiz() does
609
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
+			$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
+			$lesson_metadata = array();
612
+			if ( $pass_required ) {
613
+				// Student has reached the pass mark and lesson is complete
614
+				if ( $quiz_passmark <= $grade ) {
615
+					$lesson_status = 'passed';
616
+				}
617
+				else {
618
+					$lesson_status = 'failed';
619
+				} // End If Statement
620
+			}
621
+			// Student only has to partake the quiz
622
+			else {
623
+				$lesson_status = 'graded';
624
+			}
625
+			$lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
626 626
 
627
-            Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
627
+			Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
628 628
 
629
-            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
629
+			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
630 630
 
631
-                /**
632
-                 * Summary.
633
-                 *
634
-                 * Description.
635
-                 *
636
-                 * @since 1.7.0
637
-                 *
638
-                 * @param int  $user_id
639
-                 * @param int $quiz_lesson_id
640
-                 */
641
-                do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
631
+				/**
632
+				 * Summary.
633
+				 *
634
+				 * Description.
635
+				 *
636
+				 * @since 1.7.0
637
+				 *
638
+				 * @param int  $user_id
639
+				 * @param int $quiz_lesson_id
640
+				 */
641
+				do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
642 642
 
643
-            } // end if in_array
643
+			} // end if in_array
644 644
 
645
-        }// end if $_POST['all_que...
645
+		}// end if $_POST['all_que...
646 646
 
647
-        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
647
+		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
648 648
 
649
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
649
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
650 650
 
651
-        } elseif ( isset( $_POST['_wp_http_referer'] ) ) {
651
+		} elseif ( isset( $_POST['_wp_http_referer'] ) ) {
652 652
 
653
-            $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
653
+			$load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
654 654
 
655
-        } else {
655
+		} else {
656 656
 
657
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
657
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
658 658
 
659
-        }
659
+		}
660 660
 
661
-        wp_safe_redirect( esc_url_raw( $load_url ) );
662
-        exit;
661
+		wp_safe_redirect( esc_url_raw( $load_url ) );
662
+		exit;
663 663
 
664
-    } // end admin_process_grading_submission
664
+	} // end admin_process_grading_submission
665 665
 
666 666
 	public function get_redirect_url() {
667 667
 		// Parse POST data
@@ -706,283 +706,283 @@  discard block
 block discarded – undo
706 706
 		} // End If Statement
707 707
 	} // End sensei_grading_notices()
708 708
 
709
-    /**
710
-     * Grade quiz automatically
711
-     *
712
-     * This function grades each question automatically if there all questions are auto gradable. If not
713
-     * the quiz will not be auto gradable.
714
-     *
715
-     * @since 1.7.4
716
-     *
717
-     * @param  integer $quiz_id         ID of quiz
718
-     * @param  array $submitted questions id ans answers {
719
-     *          @type int $question_id
720
-     *          @type mixed $answer
721
-     * }
722
-     * @param  integer $total_questions Total questions in quiz (not used)
723
-     * @param string $quiz_grade_type Optional defaults to auto
724
-     *
725
-     * @return int $quiz_grade total sum of all question grades
726
-     */
727
-    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
-
729
-        if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
-            || $quiz_grade_type != 'auto' ) {
731
-            return false; // exit early
732
-        }
733
-
734
-
735
-        $user_id = get_current_user_id();
736
-        $lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
-        $quiz_autogradable = true;
738
-
739
-        /**
740
-         * Filter the types of question types that can be automatically graded.
741
-         *
742
-         * This filter fires inside the auto grade quiz function and provides you with the default list.
743
-         *
744
-         * @param array {
745
-         *      'multiple-choice',
746
-         *      'boolean',
747
-         *      'gap-fill'.
748
-         * }
749
-         */
750
-        $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
-
752
-        $grade_total = 0;
753
-        $all_question_grades = array();
754
-        foreach( $submitted as $question_id => $answer ) {
755
-
756
-            // check if the question is autogradable, either by type, or because the grade is 0
757
-            $question_type = Sensei()->question->get_question_type( $question_id );
709
+	/**
710
+	 * Grade quiz automatically
711
+	 *
712
+	 * This function grades each question automatically if there all questions are auto gradable. If not
713
+	 * the quiz will not be auto gradable.
714
+	 *
715
+	 * @since 1.7.4
716
+	 *
717
+	 * @param  integer $quiz_id         ID of quiz
718
+	 * @param  array $submitted questions id ans answers {
719
+	 *          @type int $question_id
720
+	 *          @type mixed $answer
721
+	 * }
722
+	 * @param  integer $total_questions Total questions in quiz (not used)
723
+	 * @param string $quiz_grade_type Optional defaults to auto
724
+	 *
725
+	 * @return int $quiz_grade total sum of all question grades
726
+	 */
727
+	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
+
729
+		if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
+			|| $quiz_grade_type != 'auto' ) {
731
+			return false; // exit early
732
+		}
733
+
734
+
735
+		$user_id = get_current_user_id();
736
+		$lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
+		$quiz_autogradable = true;
738
+
739
+		/**
740
+		 * Filter the types of question types that can be automatically graded.
741
+		 *
742
+		 * This filter fires inside the auto grade quiz function and provides you with the default list.
743
+		 *
744
+		 * @param array {
745
+		 *      'multiple-choice',
746
+		 *      'boolean',
747
+		 *      'gap-fill'.
748
+		 * }
749
+		 */
750
+		$autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
+
752
+		$grade_total = 0;
753
+		$all_question_grades = array();
754
+		foreach( $submitted as $question_id => $answer ) {
755
+
756
+			// check if the question is autogradable, either by type, or because the grade is 0
757
+			$question_type = Sensei()->question->get_question_type( $question_id );
758 758
 			$achievable_grade = Sensei()->question->get_question_grade( $question_id );
759 759
 			// Question has a zero grade, so skip grading
760 760
 			if ( 0 == $achievable_grade ) {
761 761
 				$all_question_grades[ $question_id ] = $achievable_grade;
762 762
 			}
763
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
-                // Get user question grade
765
-                $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
-                $all_question_grades[ $question_id ] = $question_grade;
767
-                $grade_total += $question_grade;
763
+			elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
+				// Get user question grade
765
+				$question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
+				$all_question_grades[ $question_id ] = $question_grade;
767
+				$grade_total += $question_grade;
768 768
 
769
-            } else {
769
+			} else {
770 770
 
771
-                // There is a question that cannot be autograded
772
-                $quiz_autogradable = false;
771
+				// There is a question that cannot be autograded
772
+				$quiz_autogradable = false;
773 773
 
774
-            } // end if in_array( $question_type...
774
+			} // end if in_array( $question_type...
775 775
 
776
-        }// end for each question
776
+		}// end for each question
777 777
 
778
-        // Only if the whole quiz was autogradable do we set a grade
779
-        if ( $quiz_autogradable ) {
778
+		// Only if the whole quiz was autogradable do we set a grade
779
+		if ( $quiz_autogradable ) {
780 780
 
781
-            $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
781
+			$quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
782 782
 			// Check for zero total from grades
783 783
 			if ( 0 < $quiz_total ) {
784
-            $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
784
+			$grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
785 785
 			}
786 786
 			else {
787 787
 				$grade = 0;
788 788
 			}
789
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
789
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
790 790
 
791
-        } else {
791
+		} else {
792 792
 
793
-            $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
793
+			$grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
794 794
 
795
-        }
796
-
797
-        // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
-        // when doing manual grading.
799
-        Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
795
+		}
800 796
 
801
-        return $grade;
797
+		// store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
+		// when doing manual grading.
799
+		Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
802 800
 
803
-    } // End grade_quiz_auto()
801
+		return $grade;
804 802
 
805
-    /**
806
-     * Grade question automatically
807
-     *
808
-     * This function checks the question typ and then grades it accordingly.
809
-     *
810
-     * @since 1.7.4
811
-     *
812
-     * @param integer $question_id
813
-     * @param string $question_type of the standard Sensei question types
814
-     * @param string $answer
815
-     * @param int $user_id
816
-     *
817
-     * @return int $question_grade
818
-     */
819
-    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
820
-
821
-        if( intval( $user_id ) == 0 ) {
822
-
823
-            $user_id = get_current_user_id();
824
-
825
-        }
826
-
827
-        if( ! ( intval( $question_id ) > 0 ) ) {
828
-
829
-            return false;
830
-
831
-        }
832
-
833
-
834
-        Sensei()->question->get_question_type( $question_id );
835
-
836
-        /**
837
-         * Applying a grade before the auto grading takes place.
838
-         *
839
-         * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
-         * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
-         * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
-         *
843
-         * @param int $question_grade default false
844
-         * @param int $question_id
845
-         * @param string $question_type one of the Sensei question type.
846
-         * @param string $answer user supplied question answer
847
-         */
848
-        $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
803
+	} // End grade_quiz_auto()
849 804
 
850
-        if ( false !== $question_grade ) {
805
+	/**
806
+	 * Grade question automatically
807
+	 *
808
+	 * This function checks the question typ and then grades it accordingly.
809
+	 *
810
+	 * @since 1.7.4
811
+	 *
812
+	 * @param integer $question_id
813
+	 * @param string $question_type of the standard Sensei question types
814
+	 * @param string $answer
815
+	 * @param int $user_id
816
+	 *
817
+	 * @return int $question_grade
818
+	 */
819
+	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
820
+
821
+		if( intval( $user_id ) == 0 ) {
822
+
823
+			$user_id = get_current_user_id();
824
+
825
+		}
826
+
827
+		if( ! ( intval( $question_id ) > 0 ) ) {
828
+
829
+			return false;
830
+
831
+		}
832
+
833
+
834
+		Sensei()->question->get_question_type( $question_id );
835
+
836
+		/**
837
+		 * Applying a grade before the auto grading takes place.
838
+		 *
839
+		 * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
+		 * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
+		 * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
+		 *
843
+		 * @param int $question_grade default false
844
+		 * @param int $question_id
845
+		 * @param string $question_type one of the Sensei question type.
846
+		 * @param string $answer user supplied question answer
847
+		 */
848
+		$question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
851 849
 
852
-            return $question_grade;
850
+		if ( false !== $question_grade ) {
853 851
 
854
-        }
852
+			return $question_grade;
855 853
 
856
-        // auto grading core
857
-        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
854
+		}
858 855
 
859
-            $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
856
+		// auto grading core
857
+		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
860 858
 
861
-            if( 0 == get_magic_quotes_gpc() ) {
862
-                $answer = wp_unslash( $answer );
863
-            }
864
-            $answer = (array) $answer;
865
-            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
-                // Loop through all answers ensure none are 'missing'
867
-                $all_correct = true;
868
-                foreach ( $answer as $check_answer ) {
869
-                    if ( !in_array( $check_answer, $right_answer ) ) {
870
-                        $all_correct = false;
871
-                    }
872
-                }
873
-                // If all correct then grade
874
-                if ( $all_correct ) {
875
-                    $question_grade = Sensei()->question->get_question_grade( $question_id );
876
-                }
877
-            }
859
+			$right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
878 860
 
879
-        } elseif( 'gap-fill' == $question_type ){
861
+			if( 0 == get_magic_quotes_gpc() ) {
862
+				$answer = wp_unslash( $answer );
863
+			}
864
+			$answer = (array) $answer;
865
+			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
+				// Loop through all answers ensure none are 'missing'
867
+				$all_correct = true;
868
+				foreach ( $answer as $check_answer ) {
869
+					if ( !in_array( $check_answer, $right_answer ) ) {
870
+						$all_correct = false;
871
+					}
872
+				}
873
+				// If all correct then grade
874
+				if ( $all_correct ) {
875
+					$question_grade = Sensei()->question->get_question_grade( $question_id );
876
+				}
877
+			}
880 878
 
881
-            $question_grade = self::grade_gap_fill_question( $question_id ,$answer );
879
+		} elseif( 'gap-fill' == $question_type ){
882 880
 
883
-        } else{
881
+			$question_grade = self::grade_gap_fill_question( $question_id ,$answer );
884 882
 
885
-            /**
886
-             * Grading questions that are not auto gradable.
887
-             *
888
-             * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
-             * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
-             *
891
-             * @param int $question_grade default zero
892
-             * @param int $question_id
893
-             * @param string $question_type one of the Sensei question type.
894
-             * @param string $answer user supplied question answer
895
-             */
896
-            $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
883
+		} else{
897 884
 
898
-        } // end if $question_type
885
+			/**
886
+			 * Grading questions that are not auto gradable.
887
+			 *
888
+			 * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
+			 * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
+			 *
891
+			 * @param int $question_grade default zero
892
+			 * @param int $question_id
893
+			 * @param string $question_type one of the Sensei question type.
894
+			 * @param string $answer user supplied question answer
895
+			 */
896
+			$question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
899 897
 
900
-        return $question_grade;
901
-    } // end grade_question_auto
898
+		} // end if $question_type
902 899
 
903
-    /**
904
-     * Grading logic specifically for the gap fill questions
905
-     *
906
-     * @since 1.9.0
907
-     * @param $question_id
908
-     * @param $user_answer
909
-     *
910
-     * @return bool | int false or the grade given to the user answer
911
-     */
912
-    public static function grade_gap_fill_question( $question_id, $user_answer ){
900
+		return $question_grade;
901
+	} // end grade_question_auto
913 902
 
914
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
-        $gapfill_array = explode( '||', $right_answer );
903
+	/**
904
+	 * Grading logic specifically for the gap fill questions
905
+	 *
906
+	 * @since 1.9.0
907
+	 * @param $question_id
908
+	 * @param $user_answer
909
+	 *
910
+	 * @return bool | int false or the grade given to the user answer
911
+	 */
912
+	public static function grade_gap_fill_question( $question_id, $user_answer ){
916 913
 
917
-        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
-            $user_answer = wp_unslash( $user_answer );
919
-        }
914
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
+		$gapfill_array = explode( '||', $right_answer );
920 916
 
921
-        /**
922
-         * case sensitive grading filter
923
-         *
924
-         * alter the value simply use this code in your plugin or the themes functions.php
925
-         * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
-         *
927
-         * @param bool $do_case_sensitive_comparison default false.
928
-         *
929
-         * @since 1.9.0
930
-         */
931
-        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
917
+		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
+			$user_answer = wp_unslash( $user_answer );
919
+		}
920
+
921
+		/**
922
+		 * case sensitive grading filter
923
+		 *
924
+		 * alter the value simply use this code in your plugin or the themes functions.php
925
+		 * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
+		 *
927
+		 * @param bool $do_case_sensitive_comparison default false.
928
+		 *
929
+		 * @since 1.9.0
930
+		 */
931
+		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
932 932
 
933
-        if( $do_case_sensitive_comparison ){
933
+		if( $do_case_sensitive_comparison ){
934 934
 
935
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
-            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
935
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
+			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
937 937
 
938
-                return Sensei()->question->get_question_grade( $question_id );
938
+				return Sensei()->question->get_question_grade( $question_id );
939 939
 
940
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
940
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
941 941
 
942
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
942
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
943 943
 
944
-                    return Sensei()->question->get_question_grade($question_id);
944
+					return Sensei()->question->get_question_grade($question_id);
945 945
 
946
-                }else{
946
+				}else{
947 947
 
948
-                    return false;
948
+					return false;
949 949
 
950
-                }
950
+				}
951 951
 
952
-            }else{
952
+			}else{
953 953
 
954
-                return false;
954
+				return false;
955 955
 
956
-            }
956
+			}
957 957
 
958
-        }else{
958
+		}else{
959 959
 
960
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
-            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
960
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
+			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
962 962
 
963
-               return Sensei()->question->get_question_grade( $question_id );
963
+			   return Sensei()->question->get_question_grade( $question_id );
964 964
 
965
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
965
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
966 966
 
967
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
967
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
968 968
 
969
-                    return  Sensei()->question->get_question_grade( $question_id );
969
+					return  Sensei()->question->get_question_grade( $question_id );
970 970
 
971
-                }else{
971
+				}else{
972 972
 
973
-                    return false;
973
+					return false;
974 974
 
975
-                }
975
+				}
976 976
 
977
-            }else{
977
+			}else{
978 978
 
979
-                return false;
979
+				return false;
980 980
 
981
-            }
981
+			}
982 982
 
983
-        }
983
+		}
984 984
 
985
-    }
985
+	}
986 986
 
987 987
 } // End Class
988 988
 
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 1 patch
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -12,251 +12,251 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Sensei_Teacher {
14 14
 
15
-    /**
16
-     * $teacher_role
17
-     *
18
-     * Keeps a reference to the teacher role object
19
-     *
20
-     * @access protected
21
-     * @since 1.8.0
22
-     */
23
-    protected $teacher_role;
24
-
25
-    /**
26
-     * $token
27
-     *
28
-     * Keeps a reference to the global sensei token
29
-     *
30
-     * @access protected
31
-     * @since 1.8.0
32
-     */
33
-    public  $token;
34
-
35
-    /**
36
-     * Sensei_Teacher::__constructor
37
-     *
38
-     * Constructor Function
39
-     *
40
-     * @since 1.8.0
41
-     * @access public
42
-     */
43
-    public function __construct ( ) {
44
-
45
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
-
51
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
-
53
-        //filter the quiz submissions
54
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
-
56
-        //grading totals count only those belonging to the teacher
57
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
-
59
-        // show the courses owned by a user on his author archive page
60
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
-
62
-        // notify admin when a teacher creates a course
63
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
-
65
-        // limit the analysis view to only the users taking courses belong to this teacher
66
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
-
68
-        // give teacher access to question post type
69
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
-
71
-        // Teacher column on the courses list on the admin edit screen
72
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
-
75
-        //admin edit messages query limit teacher
76
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
-
78
-        //add filter by teacher on courses list
79
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
-
82
-        // Handle media library restrictions
83
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
-
86
-        // update lesson owner to course teacher when saved
87
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
-
89
-        // If a Teacher logs in, redirect to /wp-admin/
90
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
-
92
-
93
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
-
96
-
97
-    } // end __constructor()
98
-
99
-    /**
100
-     * Sensei_Teacher::create_teacher_role
101
-     *
102
-     * This function checks if the role exist, if not it creates it.
103
-     * for the teacher role
104
-     *
105
-     * @since 1.8.0
106
-     * @access public
107
-     * @return void
108
-     */
109
-    public function create_role ( ) {
110
-
111
-        // check if the role exists
112
-        $this->teacher_role = get_role( 'teacher' );
113
-
114
-        // if the the teacher is not a valid WordPress role create it
115
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
-           // create the role
117
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
-       }
119
-
120
-       // add the capabilities before returning
121
-        $this->add_capabilities();
122
-
123
-    }// end create_teacher_role
124
-
125
-    /**
126
-     * Sensei_Teacher::add_capabilities
127
-     *
128
-     * @since 1.8.0
129
-     * @access protected
130
-     */
131
-    protected function add_capabilities ( ) {
132
-
133
-        // if this is not a valid WP_Role object exit without adding anything
134
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
-            return;
136
-        }
137
-
138
-        /**
139
-         * Sensei teachers capabilities array filter
140
-         *
141
-         * These capabilities will be applied to the teacher role
142
-         * @param array $capabilities
143
-         * keys: (string) $cap_name => (bool) $grant
144
-         */
145
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
-            // General access rules
147
-            'read' => true,
148
-            'manage_sensei_grades' => true,
149
-            'moderate_comments'=> true,
150
-            'upload_files'	=> true,
151
-            'edit_files'	=> true,
152
-
153
-            //Lessons
154
-            'publish_lessons'	 => true,
155
-            'manage_lesson_categories'	 => true,
156
-            'edit_lessons'	 => true,
157
-            'edit_published_lessons'  => true,
158
-            'edit_private_lessons' => true,
159
-            'read_private_lessons' => true,
160
-            'delete_published_lessons' => true,
161
-
162
-            // Courses
163
-            'create_courses' => true,
164
-            'publish_courses'	 => false,
165
-            'manage_course_categories'	 => true,
166
-            'edit_courses'	 => true,
167
-            'edit_published_courses'  => true,
168
-            'edit_private_courses' => true,
169
-            'read_private_courses' => true,
170
-            'delete_published_courses' => true,
171
-
172
-            // Quiz
173
-            'publish_quizzes'	 => true,
174
-            'edit_quizzes'	 => true,
175
-            'edit_published_quizzes'  => true,
176
-            'edit_private_quizzes' => true,
177
-            'read_private_quizzes' => true,
178
-
179
-            // Questions
180
-            'publish_questions'	 => true,
181
-            'edit_questions'	 => true,
182
-            'edit_published_questions'  => true,
183
-            'edit_private_questions' => true,
184
-            'read_private_questions' => true,
185
-
186
-            //messages
187
-            'publish_sensei_messages'	 => true,
188
-            'edit_sensei_messages'	 => true,
189
-            'edit_published_sensei_messages'  => true,
190
-            'edit_private_sensei_messages' => true,
191
-            'read_private_sensei_messages' => true,
192
-
193
-            // Comments -
194
-            // Necessary cap so Teachers can moderate comments
195
-            // on their own lessons. We restrict access to other
196
-            // post types in $this->restrict_posts_menu_page()
197
-
198
-            'edit_posts' => true,
199
-
200
-        ));
201
-
202
-        foreach ( $caps as $cap => $grant ) {
203
-
204
-            // load the capability on to the teacher role
205
-            $this->teacher_role->add_cap($cap, $grant);
206
-
207
-        } // end for each
208
-
209
-    }// end add_cap
210
-
211
-    /**
212
-     * Sensei_Teacher::teacher_meta_box
213
-     *
214
-     * Add the teacher metabox to the course post type edit screen
215
-     *
216
-     * @since 1.8.0
217
-     * @access public
218
-     * @parameter string $post_type
219
-     * @parameter WP_Post $post
220
-     * @return void
221
-     */
222
-    public function add_teacher_meta_boxes ( $post ) {
223
-
224
-        if( !current_user_can('manage_options') ){
225
-            return;
226
-        }
227
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
-            'course',
229
-            'side',
230
-            'core'
231
-        );
232
-
233
-    } // end teacher_meta_box()
234
-
235
-    /**
236
-     * Sensei_Teacher::teacher_meta_box_content
237
-     *
238
-     * Render the teacher meta box markup
239
-     *
240
-     * @since 1.8.0
241
-     * @access public
242
-     * @parameters
243
-     */
244
-    public function teacher_meta_box_content ( $post ) {
245
-
246
-        // get the current author
247
-        $current_author = $post->post_author;
248
-
249
-        //get the users authorised to author courses
250
-        $users = $this->get_teachers_and_authors();
251
-
252
-    ?>
15
+	/**
16
+	 * $teacher_role
17
+	 *
18
+	 * Keeps a reference to the teacher role object
19
+	 *
20
+	 * @access protected
21
+	 * @since 1.8.0
22
+	 */
23
+	protected $teacher_role;
24
+
25
+	/**
26
+	 * $token
27
+	 *
28
+	 * Keeps a reference to the global sensei token
29
+	 *
30
+	 * @access protected
31
+	 * @since 1.8.0
32
+	 */
33
+	public  $token;
34
+
35
+	/**
36
+	 * Sensei_Teacher::__constructor
37
+	 *
38
+	 * Constructor Function
39
+	 *
40
+	 * @since 1.8.0
41
+	 * @access public
42
+	 */
43
+	public function __construct ( ) {
44
+
45
+		add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
+		add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
+		add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
+		add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
+		add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
+
51
+		add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
+
53
+		//filter the quiz submissions
54
+		add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
+
56
+		//grading totals count only those belonging to the teacher
57
+		add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
+
59
+		// show the courses owned by a user on his author archive page
60
+		add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
+
62
+		// notify admin when a teacher creates a course
63
+		add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
+
65
+		// limit the analysis view to only the users taking courses belong to this teacher
66
+		add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
+
68
+		// give teacher access to question post type
69
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
+
71
+		// Teacher column on the courses list on the admin edit screen
72
+		add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
+		add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
+
75
+		//admin edit messages query limit teacher
76
+		add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
+
78
+		//add filter by teacher on courses list
79
+		add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
+		add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
+
82
+		// Handle media library restrictions
83
+		add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
+		add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
+
86
+		// update lesson owner to course teacher when saved
87
+		add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
+
89
+		// If a Teacher logs in, redirect to /wp-admin/
90
+		add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
+
92
+
93
+		add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
+		add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
+
96
+
97
+	} // end __constructor()
98
+
99
+	/**
100
+	 * Sensei_Teacher::create_teacher_role
101
+	 *
102
+	 * This function checks if the role exist, if not it creates it.
103
+	 * for the teacher role
104
+	 *
105
+	 * @since 1.8.0
106
+	 * @access public
107
+	 * @return void
108
+	 */
109
+	public function create_role ( ) {
110
+
111
+		// check if the role exists
112
+		$this->teacher_role = get_role( 'teacher' );
113
+
114
+		// if the the teacher is not a valid WordPress role create it
115
+	   if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
+		   // create the role
117
+		   $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
+	   }
119
+
120
+	   // add the capabilities before returning
121
+		$this->add_capabilities();
122
+
123
+	}// end create_teacher_role
124
+
125
+	/**
126
+	 * Sensei_Teacher::add_capabilities
127
+	 *
128
+	 * @since 1.8.0
129
+	 * @access protected
130
+	 */
131
+	protected function add_capabilities ( ) {
132
+
133
+		// if this is not a valid WP_Role object exit without adding anything
134
+		if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
+			return;
136
+		}
137
+
138
+		/**
139
+		 * Sensei teachers capabilities array filter
140
+		 *
141
+		 * These capabilities will be applied to the teacher role
142
+		 * @param array $capabilities
143
+		 * keys: (string) $cap_name => (bool) $grant
144
+		 */
145
+		$caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
+			// General access rules
147
+			'read' => true,
148
+			'manage_sensei_grades' => true,
149
+			'moderate_comments'=> true,
150
+			'upload_files'	=> true,
151
+			'edit_files'	=> true,
152
+
153
+			//Lessons
154
+			'publish_lessons'	 => true,
155
+			'manage_lesson_categories'	 => true,
156
+			'edit_lessons'	 => true,
157
+			'edit_published_lessons'  => true,
158
+			'edit_private_lessons' => true,
159
+			'read_private_lessons' => true,
160
+			'delete_published_lessons' => true,
161
+
162
+			// Courses
163
+			'create_courses' => true,
164
+			'publish_courses'	 => false,
165
+			'manage_course_categories'	 => true,
166
+			'edit_courses'	 => true,
167
+			'edit_published_courses'  => true,
168
+			'edit_private_courses' => true,
169
+			'read_private_courses' => true,
170
+			'delete_published_courses' => true,
171
+
172
+			// Quiz
173
+			'publish_quizzes'	 => true,
174
+			'edit_quizzes'	 => true,
175
+			'edit_published_quizzes'  => true,
176
+			'edit_private_quizzes' => true,
177
+			'read_private_quizzes' => true,
178
+
179
+			// Questions
180
+			'publish_questions'	 => true,
181
+			'edit_questions'	 => true,
182
+			'edit_published_questions'  => true,
183
+			'edit_private_questions' => true,
184
+			'read_private_questions' => true,
185
+
186
+			//messages
187
+			'publish_sensei_messages'	 => true,
188
+			'edit_sensei_messages'	 => true,
189
+			'edit_published_sensei_messages'  => true,
190
+			'edit_private_sensei_messages' => true,
191
+			'read_private_sensei_messages' => true,
192
+
193
+			// Comments -
194
+			// Necessary cap so Teachers can moderate comments
195
+			// on their own lessons. We restrict access to other
196
+			// post types in $this->restrict_posts_menu_page()
197
+
198
+			'edit_posts' => true,
199
+
200
+		));
201
+
202
+		foreach ( $caps as $cap => $grant ) {
203
+
204
+			// load the capability on to the teacher role
205
+			$this->teacher_role->add_cap($cap, $grant);
206
+
207
+		} // end for each
208
+
209
+	}// end add_cap
210
+
211
+	/**
212
+	 * Sensei_Teacher::teacher_meta_box
213
+	 *
214
+	 * Add the teacher metabox to the course post type edit screen
215
+	 *
216
+	 * @since 1.8.0
217
+	 * @access public
218
+	 * @parameter string $post_type
219
+	 * @parameter WP_Post $post
220
+	 * @return void
221
+	 */
222
+	public function add_teacher_meta_boxes ( $post ) {
223
+
224
+		if( !current_user_can('manage_options') ){
225
+			return;
226
+		}
227
+		add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
+			'course',
229
+			'side',
230
+			'core'
231
+		);
232
+
233
+	} // end teacher_meta_box()
234
+
235
+	/**
236
+	 * Sensei_Teacher::teacher_meta_box_content
237
+	 *
238
+	 * Render the teacher meta box markup
239
+	 *
240
+	 * @since 1.8.0
241
+	 * @access public
242
+	 * @parameters
243
+	 */
244
+	public function teacher_meta_box_content ( $post ) {
245
+
246
+		// get the current author
247
+		$current_author = $post->post_author;
248
+
249
+		//get the users authorised to author courses
250
+		$users = $this->get_teachers_and_authors();
251
+
252
+	?>
253 253
         <select name="sensei-course-teacher-author" class="sensei course teacher">
254 254
 
255 255
             <?php foreach ( $users as $user_id ) { ?>
256 256
 
257 257
                     <?php
258
-                        $user = get_user_by('id', $user_id);
259
-                    ?>
258
+						$user = get_user_by('id', $user_id);
259
+					?>
260 260
                     <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
261 261
                         <?php echo  $user->display_name; ?>
262 262
                     </option>
@@ -267,1289 +267,1289 @@  discard block
 block discarded – undo
267 267
 
268 268
         <?php
269 269
 
270
-    } // end render_teacher_meta_box()
271
-
272
-    /**
273
-     * Sensei_Teacher::get_teachers_and_authors
274
-     *
275
-     * Get a list of users who can author courses, lessons and quizes.
276
-     *
277
-     * @since 1.8.0
278
-     * @access public
279
-     * @parameters
280
-     * @return array $users user id array
281
-     */
282
-    public function get_teachers_and_authors ( ){
283
-
284
-        $author_query_args = array(
285
-            'blog_id'      => $GLOBALS['blog_id'],
286
-            'fields'       => 'any',
287
-            'who'          => 'authors'
288
-        );
289
-
290
-        $authors = get_users( $author_query_args );
291
-
292
-        $teacher_query_args = array(
293
-            'blog_id'      => $GLOBALS['blog_id'],
294
-            'fields'       => 'any',
295
-            'role'         => 'teacher',
296
-        );
297
-
298
-        $teachers = get_users( $teacher_query_args );
299
-
300
-        return  array_unique( array_merge( $teachers, $authors ) );
301
-
302
-    }// end get_teachers_and_authors
303
-
304
-    /**
305
-     * Sensei_Teacher::save_teacher_meta_box
306
-     *
307
-     * Save the new teacher / author to course and all lessons
308
-     *
309
-     * Hooked into admin_init
310
-     *
311
-     * @since 1.8.0
312
-     * @access public
313
-     * @parameters
314
-     * @return array $users user id array
315
-     */
316
-    public function save_teacher_meta_box ( $course_id ){
270
+	} // end render_teacher_meta_box()
271
+
272
+	/**
273
+	 * Sensei_Teacher::get_teachers_and_authors
274
+	 *
275
+	 * Get a list of users who can author courses, lessons and quizes.
276
+	 *
277
+	 * @since 1.8.0
278
+	 * @access public
279
+	 * @parameters
280
+	 * @return array $users user id array
281
+	 */
282
+	public function get_teachers_and_authors ( ){
283
+
284
+		$author_query_args = array(
285
+			'blog_id'      => $GLOBALS['blog_id'],
286
+			'fields'       => 'any',
287
+			'who'          => 'authors'
288
+		);
289
+
290
+		$authors = get_users( $author_query_args );
291
+
292
+		$teacher_query_args = array(
293
+			'blog_id'      => $GLOBALS['blog_id'],
294
+			'fields'       => 'any',
295
+			'role'         => 'teacher',
296
+		);
297
+
298
+		$teachers = get_users( $teacher_query_args );
299
+
300
+		return  array_unique( array_merge( $teachers, $authors ) );
301
+
302
+	}// end get_teachers_and_authors
303
+
304
+	/**
305
+	 * Sensei_Teacher::save_teacher_meta_box
306
+	 *
307
+	 * Save the new teacher / author to course and all lessons
308
+	 *
309
+	 * Hooked into admin_init
310
+	 *
311
+	 * @since 1.8.0
312
+	 * @access public
313
+	 * @parameters
314
+	 * @return array $users user id array
315
+	 */
316
+	public function save_teacher_meta_box ( $course_id ){
317 317
 
318
-        // check if this is a post from saving the teacher, if not exit early
319
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
-            return;
321
-        }
318
+		// check if this is a post from saving the teacher, if not exit early
319
+		if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
+			return;
321
+		}
322 322
 
323
-        //don't fire this hook again
324
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
323
+		//don't fire this hook again
324
+		remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
325 325
 
326
-        // get the current post object
327
-        $post = get_post( $course_id );
326
+		// get the current post object
327
+		$post = get_post( $course_id );
328 328
 
329
-        // get the current teacher/author
330
-        $current_author = absint( $post->post_author );
331
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
329
+		// get the current teacher/author
330
+		$current_author = absint( $post->post_author );
331
+		$new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
332 332
 
333
-        // loop through all post lessons to update their authors as well
334
-        $this->update_course_lessons_author( $course_id , $new_author );
333
+		// loop through all post lessons to update their authors as well
334
+		$this->update_course_lessons_author( $course_id , $new_author );
335 335
 
336
-        // do not do any processing if the selected author is the same as the current author
337
-        if( $current_author == $new_author ){
338
-            return;
339
-        }
336
+		// do not do any processing if the selected author is the same as the current author
337
+		if( $current_author == $new_author ){
338
+			return;
339
+		}
340 340
 
341
-        // save the course  author
342
-        $post_updates = array(
343
-            'ID' => $post->ID ,
344
-            'post_author' => $new_author
345
-        );
346
-        wp_update_post( $post_updates );
341
+		// save the course  author
342
+		$post_updates = array(
343
+			'ID' => $post->ID ,
344
+			'post_author' => $new_author
345
+		);
346
+		wp_update_post( $post_updates );
347 347
 
348
-        // ensure the the modules are update so that then new teacher has access to them
349
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
348
+		// ensure the the modules are update so that then new teacher has access to them
349
+		Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
350 350
 
351
-        // notify the new teacher
352
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
351
+		// notify the new teacher
352
+		$this->teacher_course_assigned_notification( $new_author, $course_id );
353 353
 
354
-    } // end save_teacher_meta_box
354
+	} // end save_teacher_meta_box
355 355
 
356
-    /**
357
-     * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
-     * the new author. Making sure the course terms are maintained.
359
-     *
360
-     * This function also checks if terms are shared, with other courses
361
-     *
362
-     * @param $course_id
363
-     * @param $new_teacher_id
364
-     * @return void
365
-     */
366
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
356
+	/**
357
+	 * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
+	 * the new author. Making sure the course terms are maintained.
359
+	 *
360
+	 * This function also checks if terms are shared, with other courses
361
+	 *
362
+	 * @param $course_id
363
+	 * @param $new_teacher_id
364
+	 * @return void
365
+	 */
366
+	public static function update_course_modules_author( $course_id ,$new_teacher_id ){
367 367
 
368
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
-            return;
370
-        }
368
+		if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
+			return;
370
+		}
371 371
 
372
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
372
+		$terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
373 373
 
374
-        if( empty( $terms_selected_on_course ) ){
375
-            return;
376
-        }
374
+		if( empty( $terms_selected_on_course ) ){
375
+			return;
376
+		}
377 377
 
378
-        foreach( $terms_selected_on_course as $term ){
378
+		foreach( $terms_selected_on_course as $term ){
379 379
 
380
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
-            if( $new_teacher_id != $term_author->ID  ){
380
+			$term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
+			if( $new_teacher_id != $term_author->ID  ){
382 382
 
383
-                $new_term = '';
383
+				$new_term = '';
384 384
 
385
-                //if the new teacher is admin first check to see if the term with this name already exists
386
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
385
+				//if the new teacher is admin first check to see if the term with this name already exists
386
+				if( user_can( $new_teacher_id, 'manage_options' ) ){
387 387
 
388
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
-                    $existing_admin_terms = get_terms( 'module', $term_args );
391
-                    if( !empty( $existing_admin_terms ) ){
392
-                        // insert it even if it exists
393
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
-                    }
395
-                }
388
+					$slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
+					$term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
+					$existing_admin_terms = get_terms( 'module', $term_args );
391
+					if( !empty( $existing_admin_terms ) ){
392
+						// insert it even if it exists
393
+						$new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
+					}
395
+				}
396 396
 
397
-                if( empty ( $new_term ) ){
397
+				if( empty ( $new_term ) ){
398 398
 
399
-                   //setup the new slug
400
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
-
402
-                   // create new term and set it
403
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
-
405
-                }
399
+				   //setup the new slug
400
+				   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
+
402
+				   // create new term and set it
403
+				   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
+
405
+				}
406 406
 
407 407
 
408 408
 
409
-                // if term exists
410
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
409
+				// if term exists
410
+				if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
411 411
 
412
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
-                    $term_id = $existing_term->term_id;
412
+					$existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
+					$term_id = $existing_term->term_id;
414 414
 
415
-                }else{
415
+				}else{
416 416
 
417
-                    // for a new term simply get the term from the returned value
418
-                    $term_id = $new_term['term_id'];
417
+					// for a new term simply get the term from the returned value
418
+					$term_id = $new_term['term_id'];
419 419
 
420
-                } // end if term exist
420
+				} // end if term exist
421 421
 
422
-                // set the terms selected on the course
423
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
422
+				// set the terms selected on the course
423
+				wp_set_object_terms( $course_id, $term_id , 'module', true );
424 424
 
425
-                // remove old term
426
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
425
+				// remove old term
426
+				wp_remove_object_terms( $course_id, $term->term_id, 'module' );
427 427
 
428
-                // update the lessons within the current module term
429
-                $lessons = Sensei()->course->course_lessons( $course_id );
430
-                foreach( $lessons as $lesson  ){
428
+				// update the lessons within the current module term
429
+				$lessons = Sensei()->course->course_lessons( $course_id );
430
+				foreach( $lessons as $lesson  ){
431 431
 
432
-                    if( has_term( $term->slug, 'module', $lesson ) ){
432
+					if( has_term( $term->slug, 'module', $lesson ) ){
433 433
 
434
-                        // add the new term, the false at the end says to replace all terms on this module
435
-                        // with the new term.
436
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
-                    }
434
+						// add the new term, the false at the end says to replace all terms on this module
435
+						// with the new term.
436
+						wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
+						update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
+					}
439 439
 
440
-                }// end for each
440
+				}// end for each
441 441
 
442
-            }
443
-        }
442
+			}
443
+		}
444 444
 
445
-    }// end update_course_module_terms_author
445
+	}// end update_course_module_terms_author
446 446
 
447
-    /**
448
-     * Sensei_Teacher::update_course_lessons_author
449
-     *
450
-     * Update all course lessons and their quiz with a new author
451
-     *
452
-     * @since 1.8.0
453
-     * @access public
454
-     * @parameters
455
-     * @return array $users user id array
456
-     */
457
-    public function update_course_lessons_author ( $course_id, $new_author  ){
447
+	/**
448
+	 * Sensei_Teacher::update_course_lessons_author
449
+	 *
450
+	 * Update all course lessons and their quiz with a new author
451
+	 *
452
+	 * @since 1.8.0
453
+	 * @access public
454
+	 * @parameters
455
+	 * @return array $users user id array
456
+	 */
457
+	public function update_course_lessons_author ( $course_id, $new_author  ){
458 458
 
459 459
 
460
-        if( empty( $course_id ) || empty( $new_author ) ){
461
-            return false;
462
-        }
460
+		if( empty( $course_id ) || empty( $new_author ) ){
461
+			return false;
462
+		}
463 463
 
464
-        //get a list of course lessons
465
-        $lessons = Sensei()->course->course_lessons( $course_id );
464
+		//get a list of course lessons
465
+		$lessons = Sensei()->course->course_lessons( $course_id );
466 466
 
467
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
-            return false;
469
-        }
467
+		if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
+			return false;
469
+		}
470 470
 
471
-        // update each lesson and quiz author
472
-        foreach( $lessons as $lesson ){
471
+		// update each lesson and quiz author
472
+		foreach( $lessons as $lesson ){
473 473
 
474
-            // don't update if the author is tha same as the new author
475
-            if( $new_author == $lesson->post_author ){
476
-                continue;
477
-            }
474
+			// don't update if the author is tha same as the new author
475
+			if( $new_author == $lesson->post_author ){
476
+				continue;
477
+			}
478 478
 
479
-            // update lesson author
480
-            wp_update_post( array(
481
-                'ID'=> $lesson->ID,
482
-                'post_author' => $new_author
483
-                ) );
479
+			// update lesson author
480
+			wp_update_post( array(
481
+				'ID'=> $lesson->ID,
482
+				'post_author' => $new_author
483
+				) );
484 484
 
485
-            // update quiz author
486
-            //get the lessons quiz
487
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
-            if( is_array( $lesson_quizzes ) ){
489
-                foreach ( $lesson_quizzes as $quiz_id ) {
490
-                    // update quiz with new author
491
-                    wp_update_post( array(
492
-                        'ID'           => $quiz_id,
493
-                        'post_author' =>  $new_author
494
-                    ) );
495
-                }
496
-            }else{
497
-                wp_update_post( array(
498
-                    'ID'           => $lesson_quizzes,
499
-                    'post_author' =>  $new_author
500
-                ) );
501
-            }
485
+			// update quiz author
486
+			//get the lessons quiz
487
+			$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
+			if( is_array( $lesson_quizzes ) ){
489
+				foreach ( $lesson_quizzes as $quiz_id ) {
490
+					// update quiz with new author
491
+					wp_update_post( array(
492
+						'ID'           => $quiz_id,
493
+						'post_author' =>  $new_author
494
+					) );
495
+				}
496
+			}else{
497
+				wp_update_post( array(
498
+					'ID'           => $lesson_quizzes,
499
+					'post_author' =>  $new_author
500
+				) );
501
+			}
502 502
 
503
-        } // end for each lessons
503
+		} // end for each lessons
504 504
 
505
-        return true;
505
+		return true;
506 506
 
507
-    }// end update_course_lessons_author
508
-
509
-
510
-
511
-    /**
512
-     * Sensei_Teacher::course_analysis_teacher_access_limit
513
-     *
514
-     * Alter the query so that users can only see their courses on the analysis page
515
-     *
516
-     * @since 1.8.0
517
-     * @access public
518
-     * @parameters $query
519
-     * @return array $users user id array
520
-     */
521
-    public function course_analysis_teacher_access_limit ( $query ) {
522
-
523
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
-            return $query;
525
-        }
526
-
527
-        if ( ! function_exists( 'get_current_screen' ) ) {
528
-            return $query;
529
-        }
530
-
531
-        $screen = get_current_screen();
532
-        $sensei_post_types = array('course', 'lesson', 'question' );
533
-
534
-        // exit early for the following conditions
535
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
-
537
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
-            return $query;
540
-        }
541
-
542
-        global $current_user;
543
-        // set the query author to the current user to only show those those posts
544
-        $query->set( 'author', $current_user->ID );
545
-        return $query;
546
-
547
-    }// end course_analysis_teacher_access_limit
548
-
549
-
550
-    /**
551
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
-     *
553
-     * Determine if we're in admin and the current logged in use is a teacher
554
-     *
555
-     * @since 1.8.0
556
-     * @access public
557
-     * @parameters array $wp_query
558
-     * @return bool $is_admin_teacher
559
-     */
560
-    public function is_admin_teacher ( ){
561
-
562
-        if( ! is_user_logged_in()){
563
-            return false;
564
-        }
565
-        $is_admin_teacher = false;
566
-
567
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
-
569
-            $is_admin_teacher = true;
570
-
571
-        }
572
-
573
-        return $is_admin_teacher;
574
-
575
-    } // end is_admin_teacher
576
-
577
-    /**
578
-     * Show correct post counts on list table for Sensei post types
579
-     *
580
-     * @since 1.8.0
581
-     *
582
-     * @param  object $counts Default status counts
583
-     * @param  string $type   Current post type
584
-     * @param  string $perm   User permission level
585
-     * @return object         Modified status counts
586
-     */
587
-    public function list_table_counts( $counts, $type, $perm ) {
588
-        global $current_user;
589
-
590
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
-            return $counts;
592
-        }
593
-
594
-        if( ! $this->is_admin_teacher() ) {
595
-            return $counts;
596
-        }
597
-
598
-        $args = array(
599
-            'post_type' => $type,
600
-            'author' => $current_user->ID,
601
-            'posts_per_page' => -1
602
-        );
603
-
604
-         // Get all available statuses
605
-        $stati = get_post_stati();
606
-
607
-        // Update count object
608
-        foreach( $stati as $status ) {
609
-            $args['post_status'] = $status;
610
-            $posts = get_posts( $args );
611
-            $counts->$status = count( $posts );
612
-        }
613
-
614
-        return $counts;
615
-    }
616
-
617
-    /**
618
-     * Filter the post queries to show
619
-     * only lesson /course and users that belong
620
-     * to the current logged teacher.
621
-     *
622
-     * @since 1.8.0
623
-     *
624
-     */
625
-    public function filter_queries ( $query ) {
626
-        global $current_user;
627
-
628
-        if( ! $this->is_admin_teacher() ) {
629
-            return;
630
-        }
631
-
632
-        if ( ! function_exists( 'get_current_screen' ) ) {
633
-            return;
634
-        }
635
-
636
-        $screen = get_current_screen();
637
-        if( empty( $screen ) ) {
638
-            return $query;
639
-        }
640
-        switch( $screen->id ) {
641
-            case 'sensei_page_sensei_grading':
642
-            case 'sensei_page_sensei_analysis':
643
-            case 'sensei_page_sensei_learners':
644
-            case 'lesson':
645
-            case 'course':
646
-            case 'question':
647
-            case 'lesson_page_module-order':
648
-
649
-            /**
650
-             * sensei_filter_queries_set_author
651
-             * Filter the author Sensei set for queries
652
-             *
653
-             * @since 1.8.0
654
-             *
655
-             * @param int $user_id
656
-             * @param string $screen_id
657
-             *
658
-             */
659
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
-            break;
661
-        }
662
-    }
663
-
664
-    /**
665
-     * Limit grading quizzes to only those within courses belonging to the current teacher
666
-     * . This excludes the admin user.
667
-     *
668
-     * @since 1.8.0
669
-     * @hooked into the_comments
670
-     * @param array  $comments
671
-     *
672
-     * @return array $comments
673
-     */
674
-    public function filter_grading_activity_queries( $comments ){
675
-
676
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
-            return $comments ;
678
-        }
679
-
680
-        //check if we're on the grading screen
681
-        $screen = get_current_screen();
682
-
683
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
-            return $comments;
685
-        }
686
-
687
-        // get the course and determine if the current teacher is the owner
688
-        // if not remove it from the list of comments to be returned
689
-        foreach( $comments as $key => $comment){
690
-            $lesson = get_post( $comment->comment_post_ID );
691
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
-            $course = get_post( $course_id );
693
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
-                //remove this as the teacher should see this.
695
-                unset( $comments[ $key ] );
696
-            }
697
-        }
698
-        return $comments ;
699
-
700
-    }// end function filter grading
701
-
702
-    /**
703
-     * Limit the grading screen totals to only show lessons in the course
704
-     * belonging to the currently logged in teacher. This only applies to
705
-     * the teacher role.
706
-     *
707
-     * @since 1.8.0
708
-     *
709
-     * @hooked into sensei_count_statuses_args
710
-     * @param array $args
711
-     *
712
-     * @return array  $args
713
-     */
714
-    public function limit_grading_totals( $args ){
715
-
716
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
-            return $args ;
718
-        }
719
-
720
-        //get the teachers courses
721
-        // the query is already filtered to only the teacher
722
-        $courses =  Sensei()->course->get_all_courses();
723
-
724
-        if( empty(  $courses ) || ! is_array( $courses ) ){
725
-            return $args;
726
-        }
727
-
728
-        //setup the lessons quizzes  to limit the grading totals to
729
-        $quiz_scope = array();
730
-        foreach( $courses as $course ){
731
-
732
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
733
-
734
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
-
736
-                foreach(  $course_lessons as $lesson ){
737
-
738
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
-                    if( !empty( $quiz_id ) ) {
740
-
741
-                        array_push( $quiz_scope, $quiz_id );
742
-
743
-                    }
744
-
745
-                }
746
-
747
-            }
748
-
749
-        }
750
-
751
-        $args['post__in'] = $quiz_scope;
752
-
753
-        return $args;
754
-    }
755
-
756
-    /**
757
-     * It ensures that the author archive shows course by the current user.
758
-     *
759
-     * This function is hooked into the pre_get_posts filter
760
-     *
761
-     * @param WP_Query $query
762
-     * @return WP_Query $query
763
-     */
764
-    public function add_courses_to_author_archive( $query ) {
765
-
766
-        if ( is_admin() || ! $query->is_author() ){
767
-            return $query;
768
-        }
769
-
770
-        // this should only apply to users with the teacher role
771
-        $current_page_user = get_user_by('login', $query->get('author_name') );
772
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
-
774
-            return $query;
775
-
776
-        }
777
-
778
-        // Change post types depending on what is set already
779
-        $current_post_types = $query->get( 'post_type' );
780
-        if( empty( $current_post_types  ) ){
781
-
782
-            // if empty it means post by default, so add post so that it also includes that for now
783
-            $new_post_types = array( 'post', 'course' );
784
-
785
-        } elseif( is_array( $current_post_types  ) ) {
786
-
787
-            // merge the post types instead of overwriting it
788
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
-
790
-        }else{
791
-
792
-            // in this instance it is probably just one post type in string format
793
-            $new_post_types =  array( $current_post_types , 'course');
794
-
795
-        }
796
-
797
-        // change the query before returning it
798
-        $query->set('post_type', $new_post_types );
799
-
800
-        /**
801
-         * Change the query on the teacher author archive template
802
-         *
803
-         * @since 1.8.4
804
-         * @param WP_Query $query
805
-         */
806
-        return apply_filters( 'sensei_teacher_archive_query', $query );
807
-
808
-    }
809
-
810
-    /**
811
-     * Notify teacher when someone assigns a course to their account.
812
-     *
813
-     * @since 1.8.0
814
-     *
815
-     * @param $teacher_id
816
-     * @param $course_id
817
-     * @return bool
818
-     */
819
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
-
821
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
-            return false;
823
-        }
824
-
825
-        // if new user is the same as the current logged user, they don't need an email
826
-        if( $teacher_id == get_current_user_id() ){
827
-            return true;
828
-        }
829
-
830
-        // load the email class
831
-        include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
-        $email = new Sensei_Email_Teacher_New_Course_Assignment();
833
-        $email->trigger( $teacher_id, $course_id );
834
-
835
-        return true;
836
-    } // end  teacher_course_assigned_notification
837
-
838
-    /**
839
-     * Email the admin when a teacher creates a new course
840
-     *
841
-     * This function hooks into wp_insert_post
842
-     *
843
-     * @since 1.8.0
844
-     * @param int $course_id
845
-     * @return bool
846
-     */
847
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
-
849
-        $course_id = $post->ID;
850
-
851
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
-
854
-            return false;
855
-
856
-        }
857
-
858
-        /**
859
-         * Filter the option to send admin notification emails when teachers creation
860
-         * course.
861
-         *
862
-         * @since 1.8.0
863
-         *
864
-         * @param bool $on default true
865
-         */
866
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
-            return false;
868
-        }
869
-
870
-        // setting up the data needed by the email template
871
-        global $sensei_email_data;
872
-        $template = 'admin-teacher-new-course-created';
873
-        $course = get_post( $course_id );
874
-        $teacher = new WP_User( $course->post_author );
875
-        $recipient = get_option('admin_email', true);
876
-
877
-        // don't send if the course is created by admin
878
-        if( $recipient == $teacher->user_email ){
879
-            return;
880
-        }
881
-
882
-        /**
883
-         * Filter the email Header for the admin-teacher-new-course-created template
884
-         *
885
-         * @since 1.8.0
886
-         * @param string $template
887
-         */
888
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
-
890
-        /**
891
-         * Filter the email subject for the the
892
-         * admin-teacher-new-course-created template
893
-         *
894
-         * @since 1.8.0
895
-         * @param string $subject default New course assigned to you
896
-         * @param string $template
897
-         */
898
-        $subject = apply_filters('sensei_email_subject',
899
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
-                                $template );
901
-
902
-        //course edit link
903
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
-
905
-        // Construct data array
906
-        $email_data = array(
907
-            'template'			=> $template,
908
-            'heading' =>  $heading,
909
-            'teacher'		=> $teacher,
910
-            'course_id'			=> $course_id,
911
-            'course_name'			=> $course->post_title,
912
-            'course_edit_link' => $course_edit_link,
913
-        );
914
-
915
-        /**
916
-         * Filter the sensei email data for the admin-teacher-new-course-created template
917
-         *
918
-         * @since 1.8.0
919
-         * @param array $email_data
920
-         * @param string $template
921
-         */
922
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
-
924
-        // Send mail
925
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
-
927
-    }// end notify admin of course creation
928
-
929
-    /**
930
-     * Limit the analysis view to only the users taking courses belong to this teacher
931
-     *
932
-     * Hooked into sensei_analysis_get_learners
933
-     * @param array $args WP_User_Query arguments
934
-     * @return array $learners_query_results
935
-     */
936
-    public function limit_analysis_learners( $args ){
937
-
938
-        // show default for none teachers
939
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
940
-                return $args;
941
-        }
942
-
943
-        // for teachers all courses only return those which belong to the teacher
944
-        // as they don't have access to course belonging to other users
945
-        $teacher_courses = Sensei()->course->get_all_courses();
507
+	}// end update_course_lessons_author
508
+
509
+
510
+
511
+	/**
512
+	 * Sensei_Teacher::course_analysis_teacher_access_limit
513
+	 *
514
+	 * Alter the query so that users can only see their courses on the analysis page
515
+	 *
516
+	 * @since 1.8.0
517
+	 * @access public
518
+	 * @parameters $query
519
+	 * @return array $users user id array
520
+	 */
521
+	public function course_analysis_teacher_access_limit ( $query ) {
522
+
523
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
+			return $query;
525
+		}
526
+
527
+		if ( ! function_exists( 'get_current_screen' ) ) {
528
+			return $query;
529
+		}
530
+
531
+		$screen = get_current_screen();
532
+		$sensei_post_types = array('course', 'lesson', 'question' );
533
+
534
+		// exit early for the following conditions
535
+		$limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
+
537
+		if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
+			|| ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
+			return $query;
540
+		}
541
+
542
+		global $current_user;
543
+		// set the query author to the current user to only show those those posts
544
+		$query->set( 'author', $current_user->ID );
545
+		return $query;
546
+
547
+	}// end course_analysis_teacher_access_limit
548
+
549
+
550
+	/**
551
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
+	 *
553
+	 * Determine if we're in admin and the current logged in use is a teacher
554
+	 *
555
+	 * @since 1.8.0
556
+	 * @access public
557
+	 * @parameters array $wp_query
558
+	 * @return bool $is_admin_teacher
559
+	 */
560
+	public function is_admin_teacher ( ){
561
+
562
+		if( ! is_user_logged_in()){
563
+			return false;
564
+		}
565
+		$is_admin_teacher = false;
566
+
567
+		if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
+
569
+			$is_admin_teacher = true;
570
+
571
+		}
572
+
573
+		return $is_admin_teacher;
574
+
575
+	} // end is_admin_teacher
576
+
577
+	/**
578
+	 * Show correct post counts on list table for Sensei post types
579
+	 *
580
+	 * @since 1.8.0
581
+	 *
582
+	 * @param  object $counts Default status counts
583
+	 * @param  string $type   Current post type
584
+	 * @param  string $perm   User permission level
585
+	 * @return object         Modified status counts
586
+	 */
587
+	public function list_table_counts( $counts, $type, $perm ) {
588
+		global $current_user;
589
+
590
+		if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
+			return $counts;
592
+		}
593
+
594
+		if( ! $this->is_admin_teacher() ) {
595
+			return $counts;
596
+		}
597
+
598
+		$args = array(
599
+			'post_type' => $type,
600
+			'author' => $current_user->ID,
601
+			'posts_per_page' => -1
602
+		);
603
+
604
+		 // Get all available statuses
605
+		$stati = get_post_stati();
606
+
607
+		// Update count object
608
+		foreach( $stati as $status ) {
609
+			$args['post_status'] = $status;
610
+			$posts = get_posts( $args );
611
+			$counts->$status = count( $posts );
612
+		}
613
+
614
+		return $counts;
615
+	}
616
+
617
+	/**
618
+	 * Filter the post queries to show
619
+	 * only lesson /course and users that belong
620
+	 * to the current logged teacher.
621
+	 *
622
+	 * @since 1.8.0
623
+	 *
624
+	 */
625
+	public function filter_queries ( $query ) {
626
+		global $current_user;
627
+
628
+		if( ! $this->is_admin_teacher() ) {
629
+			return;
630
+		}
631
+
632
+		if ( ! function_exists( 'get_current_screen' ) ) {
633
+			return;
634
+		}
635
+
636
+		$screen = get_current_screen();
637
+		if( empty( $screen ) ) {
638
+			return $query;
639
+		}
640
+		switch( $screen->id ) {
641
+			case 'sensei_page_sensei_grading':
642
+			case 'sensei_page_sensei_analysis':
643
+			case 'sensei_page_sensei_learners':
644
+			case 'lesson':
645
+			case 'course':
646
+			case 'question':
647
+			case 'lesson_page_module-order':
648
+
649
+			/**
650
+			 * sensei_filter_queries_set_author
651
+			 * Filter the author Sensei set for queries
652
+			 *
653
+			 * @since 1.8.0
654
+			 *
655
+			 * @param int $user_id
656
+			 * @param string $screen_id
657
+			 *
658
+			 */
659
+			$query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
+			break;
661
+		}
662
+	}
663
+
664
+	/**
665
+	 * Limit grading quizzes to only those within courses belonging to the current teacher
666
+	 * . This excludes the admin user.
667
+	 *
668
+	 * @since 1.8.0
669
+	 * @hooked into the_comments
670
+	 * @param array  $comments
671
+	 *
672
+	 * @return array $comments
673
+	 */
674
+	public function filter_grading_activity_queries( $comments ){
675
+
676
+		if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
+			return $comments ;
678
+		}
679
+
680
+		//check if we're on the grading screen
681
+		$screen = get_current_screen();
682
+
683
+		if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
+			return $comments;
685
+		}
686
+
687
+		// get the course and determine if the current teacher is the owner
688
+		// if not remove it from the list of comments to be returned
689
+		foreach( $comments as $key => $comment){
690
+			$lesson = get_post( $comment->comment_post_ID );
691
+			$course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
+			$course = get_post( $course_id );
693
+			if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
+				//remove this as the teacher should see this.
695
+				unset( $comments[ $key ] );
696
+			}
697
+		}
698
+		return $comments ;
699
+
700
+	}// end function filter grading
701
+
702
+	/**
703
+	 * Limit the grading screen totals to only show lessons in the course
704
+	 * belonging to the currently logged in teacher. This only applies to
705
+	 * the teacher role.
706
+	 *
707
+	 * @since 1.8.0
708
+	 *
709
+	 * @hooked into sensei_count_statuses_args
710
+	 * @param array $args
711
+	 *
712
+	 * @return array  $args
713
+	 */
714
+	public function limit_grading_totals( $args ){
715
+
716
+		if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
+			return $args ;
718
+		}
719
+
720
+		//get the teachers courses
721
+		// the query is already filtered to only the teacher
722
+		$courses =  Sensei()->course->get_all_courses();
723
+
724
+		if( empty(  $courses ) || ! is_array( $courses ) ){
725
+			return $args;
726
+		}
727
+
728
+		//setup the lessons quizzes  to limit the grading totals to
729
+		$quiz_scope = array();
730
+		foreach( $courses as $course ){
731
+
732
+			$course_lessons = Sensei()->course->course_lessons( $course->ID );
733
+
734
+			if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
+
736
+				foreach(  $course_lessons as $lesson ){
737
+
738
+					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
+					if( !empty( $quiz_id ) ) {
740
+
741
+						array_push( $quiz_scope, $quiz_id );
742
+
743
+					}
744
+
745
+				}
746
+
747
+			}
748
+
749
+		}
750
+
751
+		$args['post__in'] = $quiz_scope;
752
+
753
+		return $args;
754
+	}
755
+
756
+	/**
757
+	 * It ensures that the author archive shows course by the current user.
758
+	 *
759
+	 * This function is hooked into the pre_get_posts filter
760
+	 *
761
+	 * @param WP_Query $query
762
+	 * @return WP_Query $query
763
+	 */
764
+	public function add_courses_to_author_archive( $query ) {
765
+
766
+		if ( is_admin() || ! $query->is_author() ){
767
+			return $query;
768
+		}
769
+
770
+		// this should only apply to users with the teacher role
771
+		$current_page_user = get_user_by('login', $query->get('author_name') );
772
+		if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
+
774
+			return $query;
775
+
776
+		}
777
+
778
+		// Change post types depending on what is set already
779
+		$current_post_types = $query->get( 'post_type' );
780
+		if( empty( $current_post_types  ) ){
781
+
782
+			// if empty it means post by default, so add post so that it also includes that for now
783
+			$new_post_types = array( 'post', 'course' );
784
+
785
+		} elseif( is_array( $current_post_types  ) ) {
786
+
787
+			// merge the post types instead of overwriting it
788
+			$new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
+
790
+		}else{
791
+
792
+			// in this instance it is probably just one post type in string format
793
+			$new_post_types =  array( $current_post_types , 'course');
794
+
795
+		}
796
+
797
+		// change the query before returning it
798
+		$query->set('post_type', $new_post_types );
799
+
800
+		/**
801
+		 * Change the query on the teacher author archive template
802
+		 *
803
+		 * @since 1.8.4
804
+		 * @param WP_Query $query
805
+		 */
806
+		return apply_filters( 'sensei_teacher_archive_query', $query );
807
+
808
+	}
809
+
810
+	/**
811
+	 * Notify teacher when someone assigns a course to their account.
812
+	 *
813
+	 * @since 1.8.0
814
+	 *
815
+	 * @param $teacher_id
816
+	 * @param $course_id
817
+	 * @return bool
818
+	 */
819
+	public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
+
821
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
+			return false;
823
+		}
824
+
825
+		// if new user is the same as the current logged user, they don't need an email
826
+		if( $teacher_id == get_current_user_id() ){
827
+			return true;
828
+		}
829
+
830
+		// load the email class
831
+		include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
+		$email = new Sensei_Email_Teacher_New_Course_Assignment();
833
+		$email->trigger( $teacher_id, $course_id );
834
+
835
+		return true;
836
+	} // end  teacher_course_assigned_notification
837
+
838
+	/**
839
+	 * Email the admin when a teacher creates a new course
840
+	 *
841
+	 * This function hooks into wp_insert_post
842
+	 *
843
+	 * @since 1.8.0
844
+	 * @param int $course_id
845
+	 * @return bool
846
+	 */
847
+	public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
+
849
+		$course_id = $post->ID;
850
+
851
+		if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
+			|| 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
+
854
+			return false;
855
+
856
+		}
857
+
858
+		/**
859
+		 * Filter the option to send admin notification emails when teachers creation
860
+		 * course.
861
+		 *
862
+		 * @since 1.8.0
863
+		 *
864
+		 * @param bool $on default true
865
+		 */
866
+		if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
+			return false;
868
+		}
869
+
870
+		// setting up the data needed by the email template
871
+		global $sensei_email_data;
872
+		$template = 'admin-teacher-new-course-created';
873
+		$course = get_post( $course_id );
874
+		$teacher = new WP_User( $course->post_author );
875
+		$recipient = get_option('admin_email', true);
876
+
877
+		// don't send if the course is created by admin
878
+		if( $recipient == $teacher->user_email ){
879
+			return;
880
+		}
881
+
882
+		/**
883
+		 * Filter the email Header for the admin-teacher-new-course-created template
884
+		 *
885
+		 * @since 1.8.0
886
+		 * @param string $template
887
+		 */
888
+		$heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
+
890
+		/**
891
+		 * Filter the email subject for the the
892
+		 * admin-teacher-new-course-created template
893
+		 *
894
+		 * @since 1.8.0
895
+		 * @param string $subject default New course assigned to you
896
+		 * @param string $template
897
+		 */
898
+		$subject = apply_filters('sensei_email_subject',
899
+								'['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
+								$template );
901
+
902
+		//course edit link
903
+		$course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
+
905
+		// Construct data array
906
+		$email_data = array(
907
+			'template'			=> $template,
908
+			'heading' =>  $heading,
909
+			'teacher'		=> $teacher,
910
+			'course_id'			=> $course_id,
911
+			'course_name'			=> $course->post_title,
912
+			'course_edit_link' => $course_edit_link,
913
+		);
914
+
915
+		/**
916
+		 * Filter the sensei email data for the admin-teacher-new-course-created template
917
+		 *
918
+		 * @since 1.8.0
919
+		 * @param array $email_data
920
+		 * @param string $template
921
+		 */
922
+		$sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
+
924
+		// Send mail
925
+		Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
+
927
+	}// end notify admin of course creation
928
+
929
+	/**
930
+	 * Limit the analysis view to only the users taking courses belong to this teacher
931
+	 *
932
+	 * Hooked into sensei_analysis_get_learners
933
+	 * @param array $args WP_User_Query arguments
934
+	 * @return array $learners_query_results
935
+	 */
936
+	public function limit_analysis_learners( $args ){
937
+
938
+		// show default for none teachers
939
+		if( ! Sensei()->teacher->is_admin_teacher() ) {
940
+				return $args;
941
+		}
942
+
943
+		// for teachers all courses only return those which belong to the teacher
944
+		// as they don't have access to course belonging to other users
945
+		$teacher_courses = Sensei()->course->get_all_courses();
946 946
 
947
-        // if the user has no courses they should see no users
948
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
-            // tell the query to return 0 students
950
-            $args[ 'include'] = array( 0 );
951
-            return $args;
952
-
953
-        }
954
-
955
-        $learner_ids_for_teacher_courses = array();
956
-        foreach( $teacher_courses as $course ){
957
-
958
-            $course_learner_ids = array();
959
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
-
961
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
-                continue; // skip to the next course as there are no users on this course
963
-            }
964
-
965
-            // it could be an array of comments or a single comment
966
-            if( is_array( $activity_comments ) ){
947
+		// if the user has no courses they should see no users
948
+		if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
+			// tell the query to return 0 students
950
+			$args[ 'include'] = array( 0 );
951
+			return $args;
952
+
953
+		}
954
+
955
+		$learner_ids_for_teacher_courses = array();
956
+		foreach( $teacher_courses as $course ){
957
+
958
+			$course_learner_ids = array();
959
+			$activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
+
961
+			if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
+				continue; // skip to the next course as there are no users on this course
963
+			}
964
+
965
+			// it could be an array of comments or a single comment
966
+			if( is_array( $activity_comments ) ){
967 967
 
968
-                foreach( $activity_comments as $comment ){
968
+				foreach( $activity_comments as $comment ){
969 969
 
970
-                    $user = get_userdata( $comment->user_id );
970
+					$user = get_userdata( $comment->user_id );
971 971
 
972
-                    if( empty( $user ) ){
973
-                        // next comment in this array
974
-                        continue;
975
-                    }
972
+					if( empty( $user ) ){
973
+						// next comment in this array
974
+						continue;
975
+					}
976 976
 
977
-                    $course_learner_ids[] = $user->ID;
978
-                }
977
+					$course_learner_ids[] = $user->ID;
978
+				}
979 979
 
980
-            }else{
980
+			}else{
981 981
 
982
-                $user = get_userdata( $activity_comments->user_id );
983
-                $course_learner_ids[] = $user->ID;
982
+				$user = get_userdata( $activity_comments->user_id );
983
+				$course_learner_ids[] = $user->ID;
984 984
 
985
-            }
985
+			}
986 986
 
987
-            // add learners on this course to the all courses learner list
988
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
987
+			// add learners on this course to the all courses learner list
988
+			$learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
989 989
 
990
-        }
990
+		}
991 991
 
992
-        // if there are no students taking the courses by this teacher don't show them any of the other users
993
-        if( empty( $learner_ids_for_teacher_courses ) ){
992
+		// if there are no students taking the courses by this teacher don't show them any of the other users
993
+		if( empty( $learner_ids_for_teacher_courses ) ){
994 994
 
995
-            $args[ 'include'] = array( 0 );
995
+			$args[ 'include'] = array( 0 );
996 996
 
997
-        }else{
997
+		}else{
998 998
 
999
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
999
+			$args[ 'include'] = $learner_ids_for_teacher_courses;
1000 1000
 
1001
-        }
1001
+		}
1002 1002
 
1003
-        // return the WP_Use_Query arguments
1004
-        return $args;
1003
+		// return the WP_Use_Query arguments
1004
+		return $args;
1005 1005
 
1006
-    }// end limit_analysis_learners
1006
+	}// end limit_analysis_learners
1007 1007
 
1008
-    /**
1009
-     * Give teacher full admin access to the question post type
1010
-     * in certain cases.
1011
-     *
1012
-     * @since 1.8.0
1013
-     * @param $questions
1014
-     * @return mixed
1015
-     */
1016
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1008
+	/**
1009
+	 * Give teacher full admin access to the question post type
1010
+	 * in certain cases.
1011
+	 *
1012
+	 * @since 1.8.0
1013
+	 * @param $questions
1014
+	 * @return mixed
1015
+	 */
1016
+	public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1017 1017
 
1018
-        if( ! $this->is_admin_teacher() ){
1019
-            return $questions;
1020
-        }
1018
+		if( ! $this->is_admin_teacher() ){
1019
+			return $questions;
1020
+		}
1021 1021
 
1022
-        $screen = get_current_screen();
1022
+		$screen = get_current_screen();
1023 1023
 
1024
-        // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1024
+		// don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
+		remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1026 1026
 
1027
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1027
+		if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1028 1028
 
1029
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
-            if( ! empty($admin_user) ){
1029
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
+			if( ! empty($admin_user) ){
1031 1031
 
1032
-                $current_teacher_id = get_current_user_id();
1032
+				$current_teacher_id = get_current_user_id();
1033 1033
 
1034
-                // set current user to admin so teacher can view all questions
1035
-                wp_set_current_user( $admin_user->ID  );
1036
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1034
+				// set current user to admin so teacher can view all questions
1035
+				wp_set_current_user( $admin_user->ID  );
1036
+				$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1037 1037
 
1038
-                // set the teacher as the current use again
1039
-                wp_set_current_user( $current_teacher_id );
1040
-            }
1038
+				// set the teacher as the current use again
1039
+				wp_set_current_user( $current_teacher_id );
1040
+			}
1041 1041
 
1042
-        }
1043
-        // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1042
+		}
1043
+		// attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1045 1045
 
1046
-        return $questions;
1047
-    }
1046
+		return $questions;
1047
+	}
1048 1048
 
1049
-    /**
1050
-     * Give the teacher role access to questions from the question bank
1051
-     *
1052
-     * @since 1.8.0
1053
-     * @param $wp_query
1054
-     * @return mixed
1055
-     */
1056
-    public function give_access_to_all_questions( $wp_query ){
1049
+	/**
1050
+	 * Give the teacher role access to questions from the question bank
1051
+	 *
1052
+	 * @since 1.8.0
1053
+	 * @param $wp_query
1054
+	 * @return mixed
1055
+	 */
1056
+	public function give_access_to_all_questions( $wp_query ){
1057 1057
 
1058
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1058
+		if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1059 1059
 
1060
-            return $wp_query;
1061
-        }
1060
+			return $wp_query;
1061
+		}
1062 1062
 
1063
-        $screen = get_current_screen();
1064
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1063
+		$screen = get_current_screen();
1064
+		if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
+			|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1066 1066
 
1067
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
-            if( ! empty($admin_user) ){
1067
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
+			if( ! empty($admin_user) ){
1069 1069
 
1070
-                $current_teacher_id = get_current_user_id();
1070
+				$current_teacher_id = get_current_user_id();
1071 1071
 
1072
-                // set current user to admin so teacher can view all questions
1073
-                wp_set_current_user( $admin_user->ID  );
1072
+				// set current user to admin so teacher can view all questions
1073
+				wp_set_current_user( $admin_user->ID  );
1074 1074
 
1075
-                //run new query as admin
1076
-                $wp_query = new WP_Query( $wp_query->query );
1075
+				//run new query as admin
1076
+				$wp_query = new WP_Query( $wp_query->query );
1077 1077
 
1078
-                //set the teache as current use again
1079
-                wp_set_current_user( $current_teacher_id );
1078
+				//set the teache as current use again
1079
+				wp_set_current_user( $current_teacher_id );
1080 1080
 
1081
-            }
1082
-        }
1081
+			}
1082
+		}
1083 1083
 
1084
-        return $wp_query;
1085
-    }// end give_access_to_all_questions
1084
+		return $wp_query;
1085
+	}// end give_access_to_all_questions
1086 1086
 
1087
-    /**
1088
-     * Add new column heading to the course admin edit list
1089
-     *
1090
-     * @since 1.8.0
1091
-     * @param $columns
1092
-     * @return array
1093
-     */
1094
-    public function course_column_heading($columns) {
1087
+	/**
1088
+	 * Add new column heading to the course admin edit list
1089
+	 *
1090
+	 * @since 1.8.0
1091
+	 * @param $columns
1092
+	 * @return array
1093
+	 */
1094
+	public function course_column_heading($columns) {
1095 1095
 
1096
-        if( $this->is_admin_teacher() ){
1097
-            return $columns;
1098
-        }
1099
-        $new_columns = array(
1100
-            'teacher' => __('Teacher', 'woothemes-sensei'),
1101
-        );
1102
-        return array_merge($columns, $new_columns);
1096
+		if( $this->is_admin_teacher() ){
1097
+			return $columns;
1098
+		}
1099
+		$new_columns = array(
1100
+			'teacher' => __('Teacher', 'woothemes-sensei'),
1101
+		);
1102
+		return array_merge($columns, $new_columns);
1103 1103
 
1104
-    }// end teacher column add
1104
+	}// end teacher column add
1105 1105
 
1106
-    /**
1107
-     * Print out  teacher column data
1108
-     *
1109
-     * @since 1.8.0
1110
-     * @param $column
1111
-     * @param $course_id
1112
-     */
1113
-    public function course_column_data( $column, $course_id  ){
1106
+	/**
1107
+	 * Print out  teacher column data
1108
+	 *
1109
+	 * @since 1.8.0
1110
+	 * @param $column
1111
+	 * @param $course_id
1112
+	 */
1113
+	public function course_column_data( $column, $course_id  ){
1114 1114
 
1115
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
-            return;
1117
-        }
1115
+		if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
+			return;
1117
+		}
1118 1118
 
1119
-        $course = get_post( $course_id );
1120
-        $teacher = get_userdata( $course->post_author );
1119
+		$course = get_post( $course_id );
1120
+		$teacher = get_userdata( $course->post_author );
1121 1121
 
1122
-        if( !$teacher ){
1123
-            return;
1124
-        }
1122
+		if( !$teacher ){
1123
+			return;
1124
+		}
1125 1125
 
1126
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1126
+		echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1127 1127
 
1128
-    }// end course_column_ data
1128
+	}// end course_column_ data
1129 1129
 
1130
-    /**
1131
-     * Return only courses belonging to the given teacher.
1132
-     *
1133
-     *
1134
-     * @since 1.8.0
1135
-     *
1136
-     * @param int $teacher_id
1137
-     * @param bool $return_ids_only
1138
-     *
1139
-     * @return array $teachers_courses
1140
-     */
1141
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1130
+	/**
1131
+	 * Return only courses belonging to the given teacher.
1132
+	 *
1133
+	 *
1134
+	 * @since 1.8.0
1135
+	 *
1136
+	 * @param int $teacher_id
1137
+	 * @param bool $return_ids_only
1138
+	 *
1139
+	 * @return array $teachers_courses
1140
+	 */
1141
+	public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1142 1142
 
1143
-        $teachers_courses = array();
1143
+		$teachers_courses = array();
1144 1144
 
1145
-        if( empty( $teacher_id  ) ){
1146
-            $teacher_id = get_current_user_id();
1147
-        }
1145
+		if( empty( $teacher_id  ) ){
1146
+			$teacher_id = get_current_user_id();
1147
+		}
1148 1148
 
1149
-        $all_courses = Sensei()->course->get_all_courses();
1149
+		$all_courses = Sensei()->course->get_all_courses();
1150 1150
 
1151
-        if( empty( $all_courses ) ){
1152
-            return $all_courses;
1153
-        }
1151
+		if( empty( $all_courses ) ){
1152
+			return $all_courses;
1153
+		}
1154 1154
 
1155
-        foreach( $all_courses as $course ){
1155
+		foreach( $all_courses as $course ){
1156 1156
 
1157
-            if( $course->post_author != $teacher_id  ){
1158
-                continue;
1159
-            }
1157
+			if( $course->post_author != $teacher_id  ){
1158
+				continue;
1159
+			}
1160 1160
 
1161
-            if( $return_ids_only ){
1161
+			if( $return_ids_only ){
1162 1162
 
1163
-                $teachers_courses[] = $course->ID;
1163
+				$teachers_courses[] = $course->ID;
1164 1164
 
1165
-            }else{
1165
+			}else{
1166 1166
 
1167
-                $teachers_courses[] = $course;
1167
+				$teachers_courses[] = $course;
1168 1168
 
1169
-            }
1169
+			}
1170 1170
 
1171
-        }
1171
+		}
1172 1172
 
1173
-        return $teachers_courses;
1173
+		return $teachers_courses;
1174 1174
 
1175
-    }
1175
+	}
1176 1176
 
1177
-    /**
1178
-     * Limit the message display to only those sent to the current teacher
1179
-     *
1180
-     * @since 1.8.0
1181
-     *
1182
-     * @param $query
1183
-     * @return mixed
1184
-     */
1185
-    public function limit_edit_messages_query( $query ){
1186
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
-            return $query;
1188
-        }
1189
-
1190
-        $teacher = wp_get_current_user();
1191
-
1192
-        $query->set( 'meta_key', '_receiver' );
1193
-        $meta_query_args = array(
1194
-            'key'     => '_receiver',
1195
-            'value'   => $teacher->get('user_login') ,
1196
-            'compare' => '='
1197
-        );
1177
+	/**
1178
+	 * Limit the message display to only those sent to the current teacher
1179
+	 *
1180
+	 * @since 1.8.0
1181
+	 *
1182
+	 * @param $query
1183
+	 * @return mixed
1184
+	 */
1185
+	public function limit_edit_messages_query( $query ){
1186
+		if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
+			return $query;
1188
+		}
1189
+
1190
+		$teacher = wp_get_current_user();
1191
+
1192
+		$query->set( 'meta_key', '_receiver' );
1193
+		$meta_query_args = array(
1194
+			'key'     => '_receiver',
1195
+			'value'   => $teacher->get('user_login') ,
1196
+			'compare' => '='
1197
+		);
1198 1198
 
1199
-        $query->set('meta_query', $meta_query_args  );
1199
+		$query->set('meta_query', $meta_query_args  );
1200 1200
 
1201
-        return $query;
1202
-    }
1201
+		return $query;
1202
+	}
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Add options to filter courses by teacher
1207
-     *
1208
-     * @since 1.8.0
1209
-     *
1210
-     * @return void
1211
-     */
1212
-    public function course_teacher_filter_options() {
1213
-        global $typenow;
1205
+	/**
1206
+	 * Add options to filter courses by teacher
1207
+	 *
1208
+	 * @since 1.8.0
1209
+	 *
1210
+	 * @return void
1211
+	 */
1212
+	public function course_teacher_filter_options() {
1213
+		global $typenow;
1214 1214
 
1215
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
-            return;
1217
-        }
1215
+		if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
+			return;
1217
+		}
1218 1218
 
1219
-        // get all roles
1220
-        $roles = get_editable_roles();
1219
+		// get all roles
1220
+		$roles = get_editable_roles();
1221 1221
 
1222
-        // get roles with the course edit capability
1223
-        // and then get the users with those roles
1224
-        $users_who_can_edit_courses = array();
1225
-        foreach( $roles as $role_item ){
1222
+		// get roles with the course edit capability
1223
+		// and then get the users with those roles
1224
+		$users_who_can_edit_courses = array();
1225
+		foreach( $roles as $role_item ){
1226 1226
 
1227
-            $role = get_role( strtolower( $role_item['name'] ) );
1227
+			$role = get_role( strtolower( $role_item['name'] ) );
1228 1228
 
1229
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1229
+			if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1230 1230
 
1231
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1231
+				$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
+				$role_users_who_can_edit_courses = get_users( $user_query_args );
1233 1233
 
1234
-                // add user from the current $user_role to all users
1235
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1234
+				// add user from the current $user_role to all users
1235
+				$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1236 1236
 
1237
-            }
1237
+			}
1238 1238
 
1239
-        }
1239
+		}
1240 1240
 
1241
-        // Create the select element with the given users who can edit course
1242
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
-        $course_options = '';
1244
-        foreach( $users_who_can_edit_courses as $user ) {
1245
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
-        }
1241
+		// Create the select element with the given users who can edit course
1242
+		$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
+		$course_options = '';
1244
+		foreach( $users_who_can_edit_courses as $user ) {
1245
+			$course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
+		}
1247 1247
 
1248
-        $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
-        $output .= $course_options;
1251
-        $output .= '</select>';
1248
+		$output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
+		$output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
+		$output .= $course_options;
1251
+		$output .= '</select>';
1252 1252
 
1253
-        echo $output;
1254
-    }
1253
+		echo $output;
1254
+	}
1255 1255
 
1256
-    /**
1257
-     * Modify the main query on the admin course list screen
1258
-     *
1259
-     * @since 1.8.0
1260
-     *
1261
-     * @param $query
1262
-     * @return $query
1263
-     */
1264
-    public function teacher_filter_query_modify( $query ){
1265
-        global $typenow;
1256
+	/**
1257
+	 * Modify the main query on the admin course list screen
1258
+	 *
1259
+	 * @since 1.8.0
1260
+	 *
1261
+	 * @param $query
1262
+	 * @return $query
1263
+	 */
1264
+	public function teacher_filter_query_modify( $query ){
1265
+		global $typenow;
1266 1266
 
1267
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
-            return $query;
1269
-        }
1270
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
-
1272
-        if( empty( $course_teacher ) ) {
1273
-            return $query;
1274
-        }
1275
-
1276
-        $query['author'] = $course_teacher;
1277
-        return $query;
1278
-    }
1279
-
1280
-    /**
1281
-     * Only show current teacher's media in the media library
1282
-     * @param  array $request Default request arguments
1283
-     * @return array          Modified request arguments
1284
-     */
1285
-    public function restrict_media_library( $request = array() ) {
1286
-
1287
-        if( ! is_admin() ) {
1288
-            return $request;
1289
-        }
1290
-
1291
-        if( ! $this->is_admin_teacher() ) {
1292
-            return $request;
1293
-        }
1294
-
1295
-        $screen = get_current_screen();
1296
-
1297
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
-            $teacher = intval( get_current_user_id() );
1299
-
1300
-            if( $teacher ) {
1301
-                $request['author__in'] = array( $teacher );
1302
-            }
1303
-        }
1304
-
1305
-        return $request;
1306
-    } // End restrict_media_library()
1307
-
1308
-    /**
1309
-     * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
-     * @param  array $query Default query arguments
1311
-     * @return array        Modified query arguments
1312
-     */
1313
-    public function restrict_media_library_modal( $query = array() ) {
1314
-
1315
-        if( ! is_admin() ) {
1316
-            return $query;
1317
-        }
1318
-
1319
-        if( ! $this->is_admin_teacher() ) {
1320
-            return $query;
1321
-        }
1322
-
1323
-        $teacher = intval( get_current_user_id() );
1324
-
1325
-        if( $teacher ) {
1326
-            $query['author__in'] = array( $teacher );
1327
-        }
1328
-
1329
-        return $query;
1330
-    } // End restrict_media_library_modal()
1331
-
1332
-    /**
1333
-     * When saving the lesson, update the teacher if the lesson belongs to a course
1334
-     *
1335
-     * @since 1.8.0
1336
-     *
1337
-     * @param int $lesson_id
1338
-     */
1339
-    public function update_lesson_teacher( $lesson_id ){
1340
-
1341
-        if( 'lesson'!= get_post_type() ){
1342
-            return;
1343
-        }
1267
+		if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
+			return $query;
1269
+		}
1270
+		$course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
+
1272
+		if( empty( $course_teacher ) ) {
1273
+			return $query;
1274
+		}
1275
+
1276
+		$query['author'] = $course_teacher;
1277
+		return $query;
1278
+	}
1279
+
1280
+	/**
1281
+	 * Only show current teacher's media in the media library
1282
+	 * @param  array $request Default request arguments
1283
+	 * @return array          Modified request arguments
1284
+	 */
1285
+	public function restrict_media_library( $request = array() ) {
1286
+
1287
+		if( ! is_admin() ) {
1288
+			return $request;
1289
+		}
1290
+
1291
+		if( ! $this->is_admin_teacher() ) {
1292
+			return $request;
1293
+		}
1294
+
1295
+		$screen = get_current_screen();
1296
+
1297
+		if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
+			$teacher = intval( get_current_user_id() );
1299
+
1300
+			if( $teacher ) {
1301
+				$request['author__in'] = array( $teacher );
1302
+			}
1303
+		}
1304
+
1305
+		return $request;
1306
+	} // End restrict_media_library()
1307
+
1308
+	/**
1309
+	 * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
+	 * @param  array $query Default query arguments
1311
+	 * @return array        Modified query arguments
1312
+	 */
1313
+	public function restrict_media_library_modal( $query = array() ) {
1314
+
1315
+		if( ! is_admin() ) {
1316
+			return $query;
1317
+		}
1318
+
1319
+		if( ! $this->is_admin_teacher() ) {
1320
+			return $query;
1321
+		}
1322
+
1323
+		$teacher = intval( get_current_user_id() );
1324
+
1325
+		if( $teacher ) {
1326
+			$query['author__in'] = array( $teacher );
1327
+		}
1328
+
1329
+		return $query;
1330
+	} // End restrict_media_library_modal()
1331
+
1332
+	/**
1333
+	 * When saving the lesson, update the teacher if the lesson belongs to a course
1334
+	 *
1335
+	 * @since 1.8.0
1336
+	 *
1337
+	 * @param int $lesson_id
1338
+	 */
1339
+	public function update_lesson_teacher( $lesson_id ){
1340
+
1341
+		if( 'lesson'!= get_post_type() ){
1342
+			return;
1343
+		}
1344 1344
 
1345
-        // this should only run once per request cycle
1346
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1345
+		// this should only run once per request cycle
1346
+		remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1347 1347
 
1348
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1348
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1349 1349
 
1350
-        if(  empty( $course_id ) || ! $course_id ){
1351
-            return;
1352
-        }
1350
+		if(  empty( $course_id ) || ! $course_id ){
1351
+			return;
1352
+		}
1353 1353
 
1354
-        $course = get_post( $course_id );
1354
+		$course = get_post( $course_id );
1355 1355
 
1356
-        $lesson_update_args= array(
1357
-            'ID' => $lesson_id ,
1358
-            'post_author' => $course->post_author
1359
-        );
1360
-        wp_update_post( $lesson_update_args );
1356
+		$lesson_update_args= array(
1357
+			'ID' => $lesson_id ,
1358
+			'post_author' => $course->post_author
1359
+		);
1360
+		wp_update_post( $lesson_update_args );
1361 1361
 
1362
-    } // end update_lesson_teacher
1362
+	} // end update_lesson_teacher
1363 1363
 
1364
-    /**
1365
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
-     *
1367
-     * Limit teachers to only see their courses, lessons and questions
1368
-     *
1369
-     * @since 1.8.0
1370
-     * @access public
1371
-     * @parameters array $wp_query
1372
-     * @return WP_Query $wp_query
1373
-     */
1374
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
-        global $current_user;
1364
+	/**
1365
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
+	 *
1367
+	 * Limit teachers to only see their courses, lessons and questions
1368
+	 *
1369
+	 * @since 1.8.0
1370
+	 * @access public
1371
+	 * @parameters array $wp_query
1372
+	 * @return WP_Query $wp_query
1373
+	 */
1374
+	public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
+		global $current_user;
1376 1376
 
1377
-        //exit early
1378
-        if( ! $this->is_admin_teacher() ){
1379
-            return $wp_query;
1380
-        }
1377
+		//exit early
1378
+		if( ! $this->is_admin_teacher() ){
1379
+			return $wp_query;
1380
+		}
1381 1381
 
1382
-        if ( ! function_exists( 'get_current_screen' ) ) {
1383
-            return $wp_query;
1384
-        }
1382
+		if ( ! function_exists( 'get_current_screen' ) ) {
1383
+			return $wp_query;
1384
+		}
1385 1385
 
1386
-        $screen = get_current_screen();
1386
+		$screen = get_current_screen();
1387 1387
 
1388
-        if( empty( $screen ) ){
1389
-            return $wp_query;
1390
-        }
1388
+		if( empty( $screen ) ){
1389
+			return $wp_query;
1390
+		}
1391 1391
 
1392
-        // for any of these conditions limit what the teacher will see
1393
-        $limit_screens = array(
1394
-            'edit-lesson',
1395
-            'edit-course',
1396
-            'edit-question',
1397
-            'course_page_course-order',
1398
-            'lesson_page_lesson-order',
1399
-        );
1392
+		// for any of these conditions limit what the teacher will see
1393
+		$limit_screens = array(
1394
+			'edit-lesson',
1395
+			'edit-course',
1396
+			'edit-question',
1397
+			'course_page_course-order',
1398
+			'lesson_page_lesson-order',
1399
+		);
1400 1400
 
1401
-        if(  in_array($screen->id  , $limit_screens ) ) {
1401
+		if(  in_array($screen->id  , $limit_screens ) ) {
1402 1402
 
1403
-            // set the query author to the current user to only show those those posts
1404
-            $wp_query->set( 'author', $current_user->ID );
1405
-        }
1403
+			// set the query author to the current user to only show those those posts
1404
+			$wp_query->set( 'author', $current_user->ID );
1405
+		}
1406 1406
 
1407
-        return $wp_query;
1407
+		return $wp_query;
1408 1408
 
1409
-    } // end limit_teacher_edit_screen_post_types()
1409
+	} // end limit_teacher_edit_screen_post_types()
1410 1410
 
1411 1411
 
1412
-    /**
1413
-     * Sensei_Teacher::teacher_login_redirect
1414
-     *
1415
-     * Redirect teachers to /wp-admin/ after login
1416
-     *
1417
-     * @since 1.8.7
1418
-     * @access public
1419
-     * @param string $user_login
1420
-     * @param object $user
1421
-     * @return void
1422
-     */
1412
+	/**
1413
+	 * Sensei_Teacher::teacher_login_redirect
1414
+	 *
1415
+	 * Redirect teachers to /wp-admin/ after login
1416
+	 *
1417
+	 * @since 1.8.7
1418
+	 * @access public
1419
+	 * @param string $user_login
1420
+	 * @param object $user
1421
+	 * @return void
1422
+	 */
1423 1423
 
1424
-    public function teacher_login_redirect( $user_login, $user  ) {
1424
+	public function teacher_login_redirect( $user_login, $user  ) {
1425 1425
 
1426
-        if (user_can($user, 'edit_courses')) {
1426
+		if (user_can($user, 'edit_courses')) {
1427 1427
 
1428
-            if (isset($_POST['redirect_to'])) {
1428
+			if (isset($_POST['redirect_to'])) {
1429 1429
 
1430
-                wp_redirect($_POST['redirect_to'], 303);
1430
+				wp_redirect($_POST['redirect_to'], 303);
1431 1431
 
1432
-                exit;
1432
+				exit;
1433 1433
 
1434
-            } else {
1434
+			} else {
1435 1435
 
1436
-                wp_redirect(admin_url(), 303);
1436
+				wp_redirect(admin_url(), 303);
1437 1437
 
1438
-                exit;
1438
+				exit;
1439 1439
 
1440
-            }
1441
-        }
1440
+			}
1441
+		}
1442 1442
 
1443
-    } // end teacher_login_redirect()
1443
+	} // end teacher_login_redirect()
1444 1444
 
1445 1445
 
1446 1446
 
1447
-    /**
1448
-     * Sensei_Teacher::restrict_posts_menu_page()
1449
-     *
1450
-     * Remove the Posts menu page for teachers and restrict access to it.
1451
-     * We have to do this because we give teachers the 'edit_posts' cap
1452
-     * so they can 'moderate_comments' as well.
1453
-     *
1454
-     * @since 1.8.7
1455
-     * @access public
1456
-     * @parameters void
1457
-     * @return void
1458
-     */
1447
+	/**
1448
+	 * Sensei_Teacher::restrict_posts_menu_page()
1449
+	 *
1450
+	 * Remove the Posts menu page for teachers and restrict access to it.
1451
+	 * We have to do this because we give teachers the 'edit_posts' cap
1452
+	 * so they can 'moderate_comments' as well.
1453
+	 *
1454
+	 * @since 1.8.7
1455
+	 * @access public
1456
+	 * @parameters void
1457
+	 * @return void
1458
+	 */
1459 1459
 
1460
-    public function restrict_posts_menu_page() {
1460
+	public function restrict_posts_menu_page() {
1461 1461
 
1462
-        global $pagenow, $typenow;
1462
+		global $pagenow, $typenow;
1463 1463
 
1464
-        $user = wp_get_current_user();
1464
+		$user = wp_get_current_user();
1465 1465
 
1466
-        /**
1467
-         * Filter the option to hide the Posts menu page.
1468
-         *
1469
-         * @since 1.8.7
1470
-         *
1471
-         * @param bool $restrict default true
1472
-         */
1466
+		/**
1467
+		 * Filter the option to hide the Posts menu page.
1468
+		 *
1469
+		 * @since 1.8.7
1470
+		 *
1471
+		 * @param bool $restrict default true
1472
+		 */
1473 1473
 
1474
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1474
+		$restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1475 1475
 
1476
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1476
+		if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1477 1477
 
1478
-            remove_menu_page('edit.php');
1478
+			remove_menu_page('edit.php');
1479 1479
 
1480
-            if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1480
+			if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1481 1481
 
1482
-                if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1482
+				if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1483 1483
 
1484
-                    wp_die('You do not have sufficient permissions to access this page.');
1484
+					wp_die('You do not have sufficient permissions to access this page.');
1485 1485
 
1486
-                }
1486
+				}
1487 1487
 
1488
-            }
1488
+			}
1489 1489
 
1490
-        }
1490
+		}
1491 1491
 
1492
-    } // end restrict_posts_menu_page()
1492
+	} // end restrict_posts_menu_page()
1493 1493
 
1494
-    /**
1495
-     * Sensei_Teacher::restrict_comment_moderation()
1496
-     *
1497
-     * Restrict commendation moderation for teachers
1498
-     * so they can only moderate comments made to posts they own.
1499
-     *
1500
-     * @since 1.8.7
1501
-     * @access public
1502
-     * @parameters obj $clauses
1503
-     * @return WP_Comment_Query  $clauses
1504
-     */
1494
+	/**
1495
+	 * Sensei_Teacher::restrict_comment_moderation()
1496
+	 *
1497
+	 * Restrict commendation moderation for teachers
1498
+	 * so they can only moderate comments made to posts they own.
1499
+	 *
1500
+	 * @since 1.8.7
1501
+	 * @access public
1502
+	 * @parameters obj $clauses
1503
+	 * @return WP_Comment_Query  $clauses
1504
+	 */
1505 1505
 
1506
-    public function restrict_comment_moderation ( $clauses ) {
1506
+	public function restrict_comment_moderation ( $clauses ) {
1507 1507
 
1508
-        global $pagenow;
1508
+		global $pagenow;
1509 1509
 
1510
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1510
+		if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1511 1511
 
1512
-            $clauses->query_vars['post_author'] = get_current_user_id();
1512
+			$clauses->query_vars['post_author'] = get_current_user_id();
1513 1513
 
1514
-        }
1514
+		}
1515 1515
 
1516
-        return $clauses;
1516
+		return $clauses;
1517 1517
 
1518
-    }   // end restrict_comment_moderation()
1518
+	}   // end restrict_comment_moderation()
1519 1519
 
1520
-    /**
1521
-     * Determine if a user is a teacher by ID
1522
-     *
1523
-     * @param int $user_id
1524
-     *
1525
-     * @return bool
1526
-     */
1527
-    public static function is_a_teacher( $user_id ){
1520
+	/**
1521
+	 * Determine if a user is a teacher by ID
1522
+	 *
1523
+	 * @param int $user_id
1524
+	 *
1525
+	 * @return bool
1526
+	 */
1527
+	public static function is_a_teacher( $user_id ){
1528 1528
 
1529
-        $user = get_user_by('id', $user_id);
1529
+		$user = get_user_by('id', $user_id);
1530 1530
 
1531
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1531
+		if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1532 1532
 
1533
-            return true;
1533
+			return true;
1534 1534
 
1535
-        }else{
1535
+		}else{
1536 1536
 
1537
-            return false;
1537
+			return false;
1538 1538
 
1539
-        }
1539
+		}
1540 1540
 
1541
-    }// end is_a_teacher
1541
+	}// end is_a_teacher
1542 1542
 
1543
-    /**
1544
-     * The archive title on the teacher archive filter
1545
-     *
1546
-     * @since 1.9.0
1547
-     */
1548
-    public static function archive_title(){
1543
+	/**
1544
+	 * The archive title on the teacher archive filter
1545
+	 *
1546
+	 * @since 1.9.0
1547
+	 */
1548
+	public static function archive_title(){
1549 1549
 
1550
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1551
-        $author_name = $author->display_name;
1552
-        ?>
1550
+		$author = get_user_by( 'id', get_query_var( 'author' ) );
1551
+		$author_name = $author->display_name;
1552
+		?>
1553 1553
             <h2 class="teacher-archive-title">
1554 1554
 
1555 1555
                 <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
@@ -1557,17 +1557,17 @@  discard block
 block discarded – undo
1557 1557
             </h2>
1558 1558
         <?php
1559 1559
 
1560
-    }// archive title
1560
+	}// archive title
1561 1561
 
1562
-    /**
1563
-     * Removing course meta on the teacher archive page
1564
-     *
1565
-     * @since 1.9.0
1566
-     */
1567
-    public static function remove_course_meta_on_teacher_archive(){
1562
+	/**
1563
+	 * Removing course meta on the teacher archive page
1564
+	 *
1565
+	 * @since 1.9.0
1566
+	 */
1567
+	public static function remove_course_meta_on_teacher_archive(){
1568 1568
 
1569
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1569
+		remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1570 1570
 
1571
-    }
1571
+	}
1572 1572
 
1573 1573
 } // End Class
Please login to merge, or discard this patch.