Completed
Push — master ( 6f9e7a...de5671 )
by Dwain
09:23
created
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/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-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-messages.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * @since  1.6.0
22 22
 	 */
23 23
 	public function __construct () {
24
-        $this->token = 'messages';
24
+		$this->token = 'messages';
25 25
 		$this->post_type = 'sensei_message';
26 26
 		$this->meta_fields = array( 'sender', 'receiver' );
27 27
 
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 		// Monitor when new reply is posted
37 37
 		add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 );
38 38
 
39
-        // Block WordPress from sending comment update emails for the messages post type
40
-        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
39
+		// Block WordPress from sending comment update emails for the messages post type
40
+		add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
41 41
 
42
-        // Block WordPress from sending comment moderator emails on the sensei messages post types
43
-        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
42
+		// Block WordPress from sending comment moderator emails on the sensei messages post types
43
+		add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
44 44
 
45 45
 		// Process saving of message posts
46 46
 		add_action( 'save_post', array( $this, 'save_message' ) );
@@ -48,20 +48,20 @@  discard block
 block discarded – undo
48 48
 		// Add message links to courses & lessons
49 49
 		add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 );
50 50
 
51
-        // add message link to lesson
52
-        add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 );
51
+		// add message link to lesson
52
+		add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 );
53 53
 
54
-        // add message link to lesson
55
-        add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 );
54
+		// add message link to lesson
55
+		add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 );
56 56
 
57 57
 		// Hide messages and replies from users who do not have access
58
-        add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 );
59
-        add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 );
60
-        add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 );
61
-        add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 );
62
-        add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 );
63
-        add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 );
64
-        add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 );
58
+		add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 );
59
+		add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 );
60
+		add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 );
61
+		add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 );
62
+		add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 );
63
+		add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 );
64
+		add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 );
65 65
 	} // End __construct()
66 66
 
67 67
 	public function add_menu_item() {
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	public function send_message_link( $post_id = 0, $user_id = 0 ) {
163 163
 		global  $post;
164 164
 
165
-        // only show the link for the allowed post types:
166
-        $allowed_post_types = array('lesson', 'course', 'quiz');
165
+		// only show the link for the allowed post types:
166
+		$allowed_post_types = array('lesson', 'course', 'quiz');
167 167
 		if ( ! in_array( get_post_type() , $allowed_post_types ) ) {
168 168
 
169 169
 			return;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 				} elseif( 'course' == $post->post_type ) {
187 187
 					$contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' );
188 188
 				}else{
189
-                    $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
190
-                }
189
+					$contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
190
+				}
191 191
 
192 192
 				$html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>';
193 193
 			}
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 
213 213
 		if( ! isset( $post->ID ) ) return $html;
214 214
 
215
-        //confirm private message
216
-        $confirmation = '';
217
-        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) {
215
+		//confirm private message
216
+		$confirmation = '';
217
+		if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) {
218 218
 
219
-            $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei');
220
-            $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>';
219
+			$confirmation_message = __('Your private message has been sent.', 'woothemes-sensei');
220
+			$confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>';
221 221
 
222
-        }
222
+		}
223 223
 
224 224
 		$html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>';
225
-        $html .= '<p>';
226
-        $html .=  $confirmation;
227
-        $html .= '</p>';
225
+		$html .= '<p>';
226
+		$html .=  $confirmation;
227
+		$html .= '</p>';
228 228
 		$html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">';
229 229
 			$html .= '<p class="form-row form-row-wide">';
230 230
 				$html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>';
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	public function message_reply_received( $comment_id = 0 ) {
256 256
 
257 257
 		// Get comment object
258
-    	$comment = get_comment( $comment_id );
258
+		$comment = get_comment( $comment_id );
259 259
 
260 260
 		if( is_null( $comment ) ) return;
261 261
 
@@ -270,87 +270,87 @@  discard block
 block discarded – undo
270 270
 		do_action( 'sensei_private_message_reply', $comment, $message );
271 271
 	}
272 272
 
273
-    /**
274
-     * This function stops WordPress from sending the default comment update emails.
275
-     *
276
-     * This function is hooked into comment_notification_recipients. It will simply return
277
-     * an empty array if the current passed in comment is on a message post type.
278
-     *
279
-     * @param array $emails
280
-     * @param int $comment_id
281
-     * @return array;
282
-     */
283
-    public function stop_wp_comment_emails( $emails , $comment_id ){
273
+	/**
274
+	 * This function stops WordPress from sending the default comment update emails.
275
+	 *
276
+	 * This function is hooked into comment_notification_recipients. It will simply return
277
+	 * an empty array if the current passed in comment is on a message post type.
278
+	 *
279
+	 * @param array $emails
280
+	 * @param int $comment_id
281
+	 * @return array;
282
+	 */
283
+	public function stop_wp_comment_emails( $emails , $comment_id ){
284 284
 
285
-        $comment = get_comment( $comment_id );
286
-        if( isset( $comment->comment_post_ID ) &&
287
-            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){
285
+		$comment = get_comment( $comment_id );
286
+		if( isset( $comment->comment_post_ID ) &&
287
+			'sensei_message' == get_post_type( $comment->comment_post_ID )  ){
288 288
 
289
-            // empty the emails array to ensure no emails are sent for this comment
290
-            $emails = array();
289
+			// empty the emails array to ensure no emails are sent for this comment
290
+			$emails = array();
291 291
 
292
-        }
293
-        return $emails;
292
+		}
293
+		return $emails;
294 294
 
295
-    }// end stop_wp_comment_emails
295
+	}// end stop_wp_comment_emails
296 296
 
297 297
 	/**
298
-     * Save new message post
299
-     * @param  integer $sender_id   ID of sender
300
-     * @param  integer $receiver_id ID of receiver
301
-     * @param  string  $message     Message content
302
-     * @param  string  $post_id     ID of post related to message
303
-     * @return mixed                Message ID on success, boolean false on failure
304
-     */
305
-    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
298
+	 * Save new message post
299
+	 * @param  integer $sender_id   ID of sender
300
+	 * @param  integer $receiver_id ID of receiver
301
+	 * @param  string  $message     Message content
302
+	 * @param  string  $post_id     ID of post related to message
303
+	 * @return mixed                Message ID on success, boolean false on failure
304
+	 */
305
+	private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
306 306
 
307
-    	$message_id = false;
307
+		$message_id = false;
308 308
 
309
-    	if( $sender_id && $receiver_id && $message && $post_id ) {
309
+		if( $sender_id && $receiver_id && $message && $post_id ) {
310 310
 
311
-    		$title = wp_trim_words( $message, 8, '...' );
311
+			$title = wp_trim_words( $message, 8, '...' );
312 312
 
313
-    		// Set up post data for message
314
-	    	$message_data = array(
315
-	            'post_type'      => $this->post_type,
316
-	            'post_title'     => esc_html( $title ),
317
-	            'post_content'   => esc_html( $message ),
318
-	            'post_status'    => 'publish',
319
-	            'ping_status'    => 'closed',
320
-	            'comment_status' => 'open',
321
-	            'post_excerpt'   => '',
322
-	            'post_author'	 => intval( $sender_id )
323
-	        );
313
+			// Set up post data for message
314
+			$message_data = array(
315
+				'post_type'      => $this->post_type,
316
+				'post_title'     => esc_html( $title ),
317
+				'post_content'   => esc_html( $message ),
318
+				'post_status'    => 'publish',
319
+				'ping_status'    => 'closed',
320
+				'comment_status' => 'open',
321
+				'post_excerpt'   => '',
322
+				'post_author'	 => intval( $sender_id )
323
+			);
324 324
 
325
-	    	// Insert post
326
-	        $message_id = wp_insert_post( $message_data );
325
+			// Insert post
326
+			$message_id = wp_insert_post( $message_data );
327 327
 
328
-	        if( ! is_wp_error( $message_id ) ) {
328
+			if( ! is_wp_error( $message_id ) ) {
329 329
 
330
-	        	// Add sender to message meta
331
-	        	$sender = get_userdata( $sender_id );
332
-	        	add_post_meta( $message_id, '_sender', $sender->user_login );
330
+				// Add sender to message meta
331
+				$sender = get_userdata( $sender_id );
332
+				add_post_meta( $message_id, '_sender', $sender->user_login );
333 333
 
334
-	        	// Add receiver to message meta
335
-	        	$receiver = get_userdata( $receiver_id );
336
-		        add_post_meta( $message_id, '_receiver', $receiver->user_login );
334
+				// Add receiver to message meta
335
+				$receiver = get_userdata( $receiver_id );
336
+				add_post_meta( $message_id, '_receiver', $receiver->user_login );
337 337
 
338
-		        // Add lesson/course ID to message meta
339
-		        $post = get_post( $post_id );
340
-		        add_post_meta( $message_id, '_posttype', $post->post_type );
341
-		        add_post_meta( $message_id, '_post', $post->ID );
338
+				// Add lesson/course ID to message meta
339
+				$post = get_post( $post_id );
340
+				add_post_meta( $message_id, '_posttype', $post->post_type );
341
+				add_post_meta( $message_id, '_post', $post->ID );
342 342
 
343
-		        do_action( 'sensei_new_private_message', $message_id );
343
+				do_action( 'sensei_new_private_message', $message_id );
344 344
 
345
-		    } else {
345
+			} else {
346 346
 
347
-		    	$message_id = false;
347
+				$message_id = false;
348 348
 
349
-		    }
350
-	    }
349
+			}
350
+		}
351 351
 
352
-	    return $message_id;
353
-    }
352
+		return $message_id;
353
+	}
354 354
 
355 355
 	/**
356 356
 	 * Check if user has access to view this message
@@ -389,56 +389,56 @@  discard block
 block discarded – undo
389 389
 		remove_meta_box('commentstatusdiv', $this->post_type, 'normal');
390 390
 	}
391 391
 
392
-    /**
393
-     * Function message_login()
394
-     *
395
-     * Only show /messages/* to logged in users, and
396
-     * redirect logged out users to wp-login.php
397
-     *
398
-     * @since 1.9.0
399
-     * @param  none
400
-     * @return void
401
-     */
392
+	/**
393
+	 * Function message_login()
394
+	 *
395
+	 * Only show /messages/* to logged in users, and
396
+	 * redirect logged out users to wp-login.php
397
+	 *
398
+	 * @since 1.9.0
399
+	 * @param  none
400
+	 * @return void
401
+	 */
402 402
 
403
-    public function message_login () {
403
+	public function message_login () {
404 404
 
405
-        if ( is_user_logged_in() ) {
405
+		if ( is_user_logged_in() ) {
406 406
 
407
-            return;
408
-        }
407
+			return;
408
+		}
409 409
 
410
-        $settings = Sensei()->settings->get_settings();
411
-        if( isset( $settings[ 'my_course_page' ] )
412
-            && 0 < intval( $settings[ 'my_course_page' ] ) ){
410
+		$settings = Sensei()->settings->get_settings();
411
+		if( isset( $settings[ 'my_course_page' ] )
412
+			&& 0 < intval( $settings[ 'my_course_page' ] ) ){
413 413
 
414
-            $my_courses_page_id = $settings[ 'my_course_page' ];
414
+			$my_courses_page_id = $settings[ 'my_course_page' ];
415 415
 
416
-            $my_courses_url = get_permalink($my_courses_page_id);
416
+			$my_courses_url = get_permalink($my_courses_page_id);
417 417
 
418
-        }
418
+		}
419 419
 
420
-        if ( is_single() && is_singular( $this->post_type )
421
-            || is_post_type_archive( $this->post_type ) ) {
420
+		if ( is_single() && is_singular( $this->post_type )
421
+			|| is_post_type_archive( $this->post_type ) ) {
422 422
 
423
-            if ( isset($my_courses_url) ) {
423
+			if ( isset($my_courses_url) ) {
424 424
 
425
-                wp_redirect($my_courses_url, 303);
426
-                exit;
427
-            }
425
+				wp_redirect($my_courses_url, 303);
426
+				exit;
427
+			}
428 428
 
429
-            else {
429
+			else {
430 430
 
431
-                wp_redirect(home_url('/wp-login.php'), 303);
432
-                exit;
433
-            }
431
+				wp_redirect(home_url('/wp-login.php'), 303);
432
+				exit;
433
+			}
434 434
 
435
-        }
436
-    }
435
+		}
436
+	}
437 437
 	/**
438
-     * Only show allowed messages in messages archive
439
-     * @param  WP_Query $query Original query
440
-     * @return void
441
-     */
438
+	 * Only show allowed messages in messages archive
439
+	 * @param  WP_Query $query Original query
440
+	 * @return void
441
+	 */
442 442
 	public function message_list( $query ) {
443 443
 		global $current_user;
444 444
 
@@ -555,17 +555,17 @@  discard block
 block discarded – undo
555 555
 		return $open;
556 556
 	}
557 557
 
558
-    /**
559
-     * Print outthe message was sent by $sender_username on the
560
-     *
561
-     * @since 1.9.0
562
-     */
563
-    public static function the_message_sent_by_title(){
558
+	/**
559
+	 * Print outthe message was sent by $sender_username on the
560
+	 *
561
+	 * @since 1.9.0
562
+	 */
563
+	public static function the_message_sent_by_title(){
564 564
 
565
-        $sender_username = get_post_meta( get_the_ID() , '_sender', true );
566
-        if( $sender_username ) {
565
+		$sender_username = get_post_meta( get_the_ID() , '_sender', true );
566
+		if( $sender_username ) {
567 567
 
568
-            $sender = get_user_by( 'login', $sender_username ); ?>
568
+			$sender = get_user_by( 'login', $sender_username ); ?>
569 569
 
570 570
             <p class="message-meta">
571 571
                 <small>
@@ -577,41 +577,41 @@  discard block
 block discarded – undo
577 577
 
578 578
         <?php }
579 579
 
580
-    }
580
+	}
581 581
 
582
-    /**
583
-     * sensei_single_title output for single page title
584
-     * @since  1.1.0
585
-     * @return void
586
-     * @deprecate
587
-     */
588
-    public static function the_title() {
582
+	/**
583
+	 * sensei_single_title output for single page title
584
+	 * @since  1.1.0
585
+	 * @return void
586
+	 * @deprecate
587
+	 */
588
+	public static function the_title() {
589 589
 
590
-        global $post;
590
+		global $post;
591 591
 
592
-        $content_post_id = get_post_meta( $post->ID, '_post', true );
593
-        if( $content_post_id ) {
594
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' );
595
-        } else {
596
-            $title = get_the_title( $post->ID );
597
-        }
592
+		$content_post_id = get_post_meta( $post->ID, '_post', true );
593
+		if( $content_post_id ) {
594
+			$title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' );
595
+		} else {
596
+			$title = get_the_title( $post->ID );
597
+		}
598 598
 
599
-        ?>
599
+		?>
600 600
         <header>
601 601
 
602 602
             <h1>
603 603
 
604 604
                 <?php
605
-                /**
606
-                 * Filter Sensei single title
607
-                 *
608
-                 * @since 1.8.0
609
-                 * @param string $title
610
-                 * @param string $template
611
-                 * @param string $post_type
612
-                 */
613
-                echo apply_filters( 'sensei_single_title', $title, $post->post_type );
614
-                ?>
605
+				/**
606
+				 * Filter Sensei single title
607
+				 *
608
+				 * @since 1.8.0
609
+				 * @param string $title
610
+				 * @param string $template
611
+				 * @param string $post_type
612
+				 */
613
+				echo apply_filters( 'sensei_single_title', $title, $post->post_type );
614
+				?>
615 615
 
616 616
             </h1>
617 617
 
@@ -619,52 +619,52 @@  discard block
 block discarded – undo
619 619
 
620 620
         <?php
621 621
 
622
-    } // End sensei_single_title()
622
+	} // End sensei_single_title()
623 623
 
624
-    /**
625
-     * Generates the my messages
626
-     * archive header.
627
-     *
628
-     * @since 1.9.0
629
-     *
630
-     * @return string
631
-     */
632
-    public static function the_archive_header( ){
624
+	/**
625
+	 * Generates the my messages
626
+	 * archive header.
627
+	 *
628
+	 * @since 1.9.0
629
+	 *
630
+	 * @return string
631
+	 */
632
+	public static function the_archive_header( ){
633 633
 
634
-        $html = '';
635
-        $html .= '<header class="archive-header"><h1>';
636
-        $html .= __( 'My Messages', 'woothemes-sensei' );
637
-        $html .= '</h1></header>';
634
+		$html = '';
635
+		$html .= '<header class="archive-header"><h1>';
636
+		$html .= __( 'My Messages', 'woothemes-sensei' );
637
+		$html .= '</h1></header>';
638 638
 
639
-        /**
640
-         * Filter the sensei messages archive title.
641
-         * @since 1.0.0
642
-         */
643
-        echo apply_filters( 'sensei_message_archive_title', $html );
639
+		/**
640
+		 * Filter the sensei messages archive title.
641
+		 * @since 1.0.0
642
+		 */
643
+		echo apply_filters( 'sensei_message_archive_title', $html );
644 644
 
645
-    } // get_archive_header()
645
+	} // get_archive_header()
646 646
 
647
-    /**
648
-     * Output the title for a message given the post_id.
649
-     *
650
-     * @since 1.9.0
651
-     * @param $post_id
652
-     */
653
-    public static function the_message_title( $message_post_id ){
647
+	/**
648
+	 * Output the title for a message given the post_id.
649
+	 *
650
+	 * @since 1.9.0
651
+	 * @param $post_id
652
+	 */
653
+	public static function the_message_title( $message_post_id ){
654 654
 
655
-        $content_post_id = get_post_meta( $message_post_id, '_post', true );
655
+		$content_post_id = get_post_meta( $message_post_id, '_post', true );
656 656
 
657
-        if( $content_post_id ) {
657
+		if( $content_post_id ) {
658 658
 
659
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) );
659
+			$title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) );
660 660
 
661
-        } else {
661
+		} else {
662 662
 
663
-            $title = get_the_title( $message_post_id );
663
+			$title = get_the_title( $message_post_id );
664 664
 
665
-        }
665
+		}
666 666
 
667
-        ?>
667
+		?>
668 668
         <h2>
669 669
             <a href="<?php esc_url( get_permalink( $message_post_id ) );?>">
670 670
                 <?php echo  $title; ?>
@@ -673,21 +673,21 @@  discard block
 block discarded – undo
673 673
         </h2>
674 674
 
675 675
         <?php
676
-    } //end the_message_header
676
+	} //end the_message_header
677 677
 
678
-    /**
679
-     * Output the message sender given the post id.
680
-     *
681
-     * @param $message_post_id
682
-     */
683
-    public  static function the_message_sender( $message_post_id ){
678
+	/**
679
+	 * Output the message sender given the post id.
680
+	 *
681
+	 * @param $message_post_id
682
+	 */
683
+	public  static function the_message_sender( $message_post_id ){
684 684
 
685
-        $sender_username = get_post_meta( $message_post_id, '_sender', true );
686
-        $sender = get_user_by( 'login', $sender_username );
685
+		$sender_username = get_post_meta( $message_post_id, '_sender', true );
686
+		$sender = get_user_by( 'login', $sender_username );
687 687
 
688
-        if( $sender_username && $sender instanceof WP_User ) {
689
-            $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() );
690
-            ?>
688
+		if( $sender_username && $sender instanceof WP_User ) {
689
+			$sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() );
690
+			?>
691 691
             <p class="message-meta">
692 692
                 <small>
693 693
                     <em> <?php echo $sender_display_name; ?> </em>
@@ -695,18 +695,18 @@  discard block
 block discarded – undo
695 695
             </p>
696 696
 
697 697
             <?php
698
-        } // end if
699
-
700
-    } // end the_message_archive_sender
701
-
702
-    /**
703
-     * Link to the users my messages page
704
-     *
705
-     * @since 1.9.0
706
-     */
707
-    public static function the_my_messages_link(){
708
-        if( ! Sensei()->settings->get('messages_disable')  ) {
709
-            ?>
698
+		} // end if
699
+
700
+	} // end the_message_archive_sender
701
+
702
+	/**
703
+	 * Link to the users my messages page
704
+	 *
705
+	 * @since 1.9.0
706
+	 */
707
+	public static function the_my_messages_link(){
708
+		if( ! Sensei()->settings->get('messages_disable')  ) {
709
+			?>
710 710
             <p class="my-messages-link-container">
711 711
                 <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>"
712 712
                    title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>">
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
                 </a>
715 715
             </p>
716 716
             <?php
717
-        }
718
-    }
717
+		}
718
+	}
719 719
 
720 720
 } // End Class
721 721
 
Please login to merge, or discard this patch.
includes/class-sensei-autoloader.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -1,147 +1,147 @@
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
3 3
 /**
4
- * Loading all class files within the Sensei/includes directory
5
- *
6
- * The auto loader class listens for calls to classes within Sensei and loads
7
- * the file containing the class.
8
- *
9
- * @package Core
10
- * @since 1.9.0
11
- */
4
+	 * Loading all class files within the Sensei/includes directory
5
+	 *
6
+	 * The auto loader class listens for calls to classes within Sensei and loads
7
+	 * the file containing the class.
8
+	 *
9
+	 * @package Core
10
+	 * @since 1.9.0
11
+	 */
12 12
 class Sensei_Autoloader {
13 13
 
14
-    /**
15
-     * @var path to the includes directory within Sensei.
16
-     */
17
-    private $include_path = 'includes';
18
-
19
-    /**
20
-     * @var array $class_file_map. List of classes mapped to their files
21
-     */
22
-    private $class_file_map = array();
23
-
24
-    /**
25
-     * Constructor
26
-     * @since 1.9.0
27
-     */
28
-    public function __construct(){
29
-
30
-        // make sure we do not override an existing autoload function
31
-        if( function_exists('__autoload') ){
32
-           spl_autoload_register( '__autoload' );
33
-        }
34
-
35
-        // setup a relative path for the current autoload instance
36
-        $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
37
-
38
-        //setup the class file map
39
-        $this->initialize_class_file_map();
40
-
41
-        // add Sensei custom auto loader
42
-        spl_autoload_register( array( $this, 'autoload' )  );
43
-
44
-    }
45
-
46
-    /**
47
-     * Generate a list of Sensei class and map them the their respective
48
-     * files within the includes directory
49
-     *
50
-     * @since 1.9.0
51
-     */
52
-    public function initialize_class_file_map(){
53
-
54
-        $this->class_file_map = array(
55
-
56
-            /**
57
-             * Main Sensei class
58
-             */
59
-            'Sensei_Main' => 'class-sensei.php',
60
-
61
-            /**
62
-             * Admin
63
-             */
64
-            'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
65
-            'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
66
-
67
-            /**
68
-             * Shortcodes
69
-             */
70
-            'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
71
-            'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
72
-            'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
73
-            'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
74
-            'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
75
-            'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
76
-            'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
77
-            'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
78
-            'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
79
-            'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
80
-            'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
81
-            'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
82
-
83
-            /**
84
-             * Built in theme integration support
85
-             */
86
-            'Sensei_Theme_Integration_Loader' => 'theme-integrations/theme-integration-loader.php',
87
-            'Sensei__S'                       => 'theme-integrations/_s.php',
88
-            'Sensei_Twentyeleven'             => 'theme-integrations/twentyeleven.php',
89
-            'Sensei_Twentytwelve'             => 'theme-integrations/twentytwelve.php',
90
-            'Sensei_Twentythirteen'           => 'theme-integrations/Twentythirteen.php',
91
-            'Sensei_Twentyfourteen'           => 'theme-integrations/Twentyfourteen.php',
92
-            'Sensei_Twentyfifteen'            => 'theme-integrations/Twentyfifteen.php',
93
-            'Sensei_Twentysixteen'            => 'theme-integrations/Twentysixteen.php',
94
-            'Sensei_Storefront'               => 'theme-integrations/Storefront.php',
95
-
96
-            /**
97
-             * WooCommerce
98
-             */
99
-            'Sensei_WC' => 'class-sensei-wc.php',
100
-
101
-        );
102
-    }
103
-
104
-    /**
105
-     * Autoload all sensei files as the class names are used.
106
-     */
107
-    public function autoload( $class ){
108
-
109
-        // only handle classes with the word `sensei` in it
110
-        if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
111
-
112
-            return;
113
-
114
-        }
115
-
116
-        // exit if we didn't provide mapping for this class
117
-        if( isset( $this->class_file_map[ $class ] ) ){
118
-
119
-            $file_location = $this->include_path . $this->class_file_map[ $class ];
120
-            require_once( $file_location);
121
-            return;
122
-
123
-        }
124
-
125
-        // check for file in the main includes directory
126
-        $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
127
-        if( file_exists( $class_file_path ) ){
128
-
129
-            require_once( $class_file_path );
130
-            return;
131
-        }
132
-
133
-        // lastly check legacy types
134
-        $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
135
-        $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
136
-        if( file_exists( $legacy_class_file_path ) ){
137
-
138
-            require_once( $legacy_class_file_path );
139
-            return;
140
-        }
141
-
142
-        return;
143
-
144
-    }// end autoload
14
+	/**
15
+	 * @var path to the includes directory within Sensei.
16
+	 */
17
+	private $include_path = 'includes';
18
+
19
+	/**
20
+	 * @var array $class_file_map. List of classes mapped to their files
21
+	 */
22
+	private $class_file_map = array();
23
+
24
+	/**
25
+	 * Constructor
26
+	 * @since 1.9.0
27
+	 */
28
+	public function __construct(){
29
+
30
+		// make sure we do not override an existing autoload function
31
+		if( function_exists('__autoload') ){
32
+		   spl_autoload_register( '__autoload' );
33
+		}
34
+
35
+		// setup a relative path for the current autoload instance
36
+		$this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
37
+
38
+		//setup the class file map
39
+		$this->initialize_class_file_map();
40
+
41
+		// add Sensei custom auto loader
42
+		spl_autoload_register( array( $this, 'autoload' )  );
43
+
44
+	}
45
+
46
+	/**
47
+	 * Generate a list of Sensei class and map them the their respective
48
+	 * files within the includes directory
49
+	 *
50
+	 * @since 1.9.0
51
+	 */
52
+	public function initialize_class_file_map(){
53
+
54
+		$this->class_file_map = array(
55
+
56
+			/**
57
+			 * Main Sensei class
58
+			 */
59
+			'Sensei_Main' => 'class-sensei.php',
60
+
61
+			/**
62
+			 * Admin
63
+			 */
64
+			'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
65
+			'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
66
+
67
+			/**
68
+			 * Shortcodes
69
+			 */
70
+			'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
71
+			'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
72
+			'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
73
+			'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
74
+			'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
75
+			'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
76
+			'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
77
+			'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
78
+			'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
79
+			'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
80
+			'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
81
+			'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
82
+
83
+			/**
84
+			 * Built in theme integration support
85
+			 */
86
+			'Sensei_Theme_Integration_Loader' => 'theme-integrations/theme-integration-loader.php',
87
+			'Sensei__S'                       => 'theme-integrations/_s.php',
88
+			'Sensei_Twentyeleven'             => 'theme-integrations/twentyeleven.php',
89
+			'Sensei_Twentytwelve'             => 'theme-integrations/twentytwelve.php',
90
+			'Sensei_Twentythirteen'           => 'theme-integrations/Twentythirteen.php',
91
+			'Sensei_Twentyfourteen'           => 'theme-integrations/Twentyfourteen.php',
92
+			'Sensei_Twentyfifteen'            => 'theme-integrations/Twentyfifteen.php',
93
+			'Sensei_Twentysixteen'            => 'theme-integrations/Twentysixteen.php',
94
+			'Sensei_Storefront'               => 'theme-integrations/Storefront.php',
95
+
96
+			/**
97
+			 * WooCommerce
98
+			 */
99
+			'Sensei_WC' => 'class-sensei-wc.php',
100
+
101
+		);
102
+	}
103
+
104
+	/**
105
+	 * Autoload all sensei files as the class names are used.
106
+	 */
107
+	public function autoload( $class ){
108
+
109
+		// only handle classes with the word `sensei` in it
110
+		if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
111
+
112
+			return;
113
+
114
+		}
115
+
116
+		// exit if we didn't provide mapping for this class
117
+		if( isset( $this->class_file_map[ $class ] ) ){
118
+
119
+			$file_location = $this->include_path . $this->class_file_map[ $class ];
120
+			require_once( $file_location);
121
+			return;
122
+
123
+		}
124
+
125
+		// check for file in the main includes directory
126
+		$class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
127
+		if( file_exists( $class_file_path ) ){
128
+
129
+			require_once( $class_file_path );
130
+			return;
131
+		}
132
+
133
+		// lastly check legacy types
134
+		$stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
135
+		$legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
136
+		if( file_exists( $legacy_class_file_path ) ){
137
+
138
+			require_once( $legacy_class_file_path );
139
+			return;
140
+		}
141
+
142
+		return;
143
+
144
+	}// end autoload
145 145
 
146 146
 }
147 147
 new Sensei_Autoloader();
Please login to merge, or discard this patch.
includes/class-sensei-analysis-overview-list-table.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 			'order' => $order,
160 160
 		);
161 161
 
162
-        // Handle search
163
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
-            $args['search'] = esc_html( $_GET['s'] );
165
-        }
162
+		// Handle search
163
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
+			$args['search'] = esc_html( $_GET['s'] );
165
+		}
166 166
 
167 167
 		switch ( $this->type ) {
168 168
 			case 'courses':
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		);
220 220
 
221 221
 
222
-        // Handle search
223
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
-            $args['search'] = esc_html( $_GET['s'] );
225
-        }
222
+		// Handle search
223
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
+			$args['search'] = esc_html( $_GET['s'] );
225
+		}
226 226
 
227 227
 
228 228
 		// Start the csv with the column headings
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * Generates the overall array for a single item in the display
261 261
 	 * @since  1.7.0
262 262
 	 * @param object $item The current item
263
-     * @return array $column_data;
263
+	 * @return array $column_data;
264 264
 	 */
265 265
 	protected function get_row_data( $item ) {
266 266
 
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 
420 420
 				// Output the users data
421 421
 				if ( $this->csv_output ) {
422
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
423
-                }
422
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
423
+				}
424 424
 				else {
425 425
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
426 426
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -514,17 +514,17 @@  discard block
 block discarded – undo
514 514
 		// This stops the full meta data of each user being loaded
515 515
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
516 516
 
517
-        /**
518
-         * Filter the WP_User_Query arguments
519
-         * @since 1.6.0
520
-         * @param $args
521
-         */
522
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
517
+		/**
518
+		 * Filter the WP_User_Query arguments
519
+		 * @since 1.6.0
520
+		 * @param $args
521
+		 */
522
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
523 523
 		$wp_user_search = new WP_User_Query( $args );
524
-        $learners = $wp_user_search->get_results();
524
+		$learners = $wp_user_search->get_results();
525 525
 		$this->total_items = $wp_user_search->get_total();
526 526
 
527
-        return $learners;
527
+		return $learners;
528 528
 
529 529
 	} // End get_learners()
530 530
 
Please login to merge, or discard this patch.
includes/class-sensei-emails.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 		add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 );
46 46
 		add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 );
47 47
 		add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 );
48
-        add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
48
+		add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
49 49
 		add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 );
50 50
 		add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 );
51 51
 		add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 );
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 		$this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' );
63 63
 		$this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' );
64 64
 		$this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' );
65
-        $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
66
-        $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
67
-        $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
65
+		$this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
66
+		$this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
67
+		$this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
68 68
 		$this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' );
69 69
 		$this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' );
70 70
 		$this->emails = apply_filters( 'sensei_email_classes', $this->emails );
@@ -171,20 +171,20 @@  discard block
 block discarded – undo
171 171
 		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
172 172
 		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
173 173
 
174
-        // Send
175
-        $send_email = true;
174
+		// Send
175
+		$send_email = true;
176 176
 
177
-        /**
178
-         * Filter Sensei's ability to send out emails.
179
-         *
180
-         * @since 1.8.0
181
-         * @param bool $send_email default true
182
-         */
183
-        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
177
+		/**
178
+		 * Filter Sensei's ability to send out emails.
179
+		 *
180
+		 * @since 1.8.0
181
+		 * @param bool $send_email default true
182
+		 */
183
+		if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
184 184
 
185
-            wp_mail( $to, $subject, $message, $headers, $attachments );
185
+			wp_mail( $to, $subject, $message, $headers, $attachments );
186 186
 
187
-        }
187
+		}
188 188
 
189 189
 		// Unhook filters
190 190
 		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
@@ -326,44 +326,44 @@  discard block
 block discarded – undo
326 326
 		}
327 327
 	}
328 328
 
329
-    /**
330
-     * teacher_completed_lesson()
331
-     *
332
-     * Send email to teacher on student completing lesson
333
-     *
334
-     * @access public
335
-     * @return void
336
-     * @since 1.9.0
337
-     */
338
-    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
339
-
340
-
341
-        $send = false;
342
-
343
-        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
344
-            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
345
-                $send = true;
346
-            }
347
-        } else {
348
-            $send = true;
349
-        }
350
-
351
-        if( $send ) {
352
-            $email = $this->emails['teacher-completed-lesson'];
353
-            $email->trigger( $learner_id, $lesson_id );
354
-        }
355
-    }
329
+	/**
330
+	 * teacher_completed_lesson()
331
+	 *
332
+	 * Send email to teacher on student completing lesson
333
+	 *
334
+	 * @access public
335
+	 * @return void
336
+	 * @since 1.9.0
337
+	 */
338
+	function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
339
+
340
+
341
+		$send = false;
342
+
343
+		if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
344
+			if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
345
+				$send = true;
346
+			}
347
+		} else {
348
+			$send = true;
349
+		}
350
+
351
+		if( $send ) {
352
+			$email = $this->emails['teacher-completed-lesson'];
353
+			$email->trigger( $learner_id, $lesson_id );
354
+		}
355
+	}
356 356
 
357 357
 	/**
358 358
 	 * Send email to teacher on quiz submission
359 359
 	 *
360 360
 	 *
361
-     * @param int $learner_id
362
-     * @param int $quiz_id
363
-     * @param int $grade
364
-     * @param int $passmark
365
-     * @param string $quiz_grade_type
366
-     */
361
+	 * @param int $learner_id
362
+	 * @param int $quiz_id
363
+	 * @param int $grade
364
+	 * @param int $passmark
365
+	 * @param string $quiz_grade_type
366
+	 */
367 367
 	function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) {
368 368
 
369 369
 		$send = false;
Please login to merge, or discard this patch.