Completed
Push — master ( f1dc7e...f45963 )
by Dwain
05:41
created
includes/admin/class-sensei-welcome.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-    exit; // Exit if accessed directly
3
+	exit; // Exit if accessed directly
4 4
 }
5 5
 
6 6
 /**
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
 
18 18
 	/**
19 19
 	 * Hook in tabs.
20
-     * @since 1.8.0
20
+	 * @since 1.8.0
21 21
 	 */
22 22
 	public function __construct() {
23 23
 
24
-        add_action( 'admin_menu', array( $this, 'admin_menus') );
24
+		add_action( 'admin_menu', array( $this, 'admin_menus') );
25 25
 		add_action( 'admin_head', array( $this, 'admin_head' ) );
26 26
 
27 27
 	}
28 28
 
29
-    /**
30
-     * Sends user to the welcome page on first activation.
31
-     *
32
-     * Hooked into activated_plugin
33
-     * @since 1.8.0
34
-     */
35
-    public static function redirect( $plugin ) {
29
+	/**
30
+	 * Sends user to the welcome page on first activation.
31
+	 *
32
+	 * Hooked into activated_plugin
33
+	 * @since 1.8.0
34
+	 */
35
+	public static function redirect( $plugin ) {
36 36
 
37
-        // Bail if activating from network, or bulk, or within an iFrame
38
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
37
+		// Bail if activating from network, or bulk, or within an iFrame
38
+		if ( is_network_admin() || isset( $_GET['activate-multi'] ) || defined( 'IFRAME_REQUEST' ) ) {
39 39
 
40
-            return;
40
+			return;
41 41
 
42
-        }
43
-        // don't run for upgrades and for pages already on the welcome screen
44
-        if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] )
45
-            || ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) {
42
+		}
43
+		// don't run for upgrades and for pages already on the welcome screen
44
+		if ( ( isset( $_GET['action'] ) && 'upgrade-plugin' == $_GET['action'] )
45
+			|| ( ! empty( $_GET['page'] ) && $_GET['page'] === 'sensei-welcome' ) ) {
46 46
 
47
-            return;
47
+			return;
48 48
 
49
-        }
49
+		}
50 50
 
51
-        wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) );
52
-        exit;
53
-    }
51
+		wp_redirect( admin_url( 'index.php?page=sensei-welcome' ) );
52
+		exit;
53
+	}
54 54
 
55 55
 	/**
56 56
 	 * Add admin menus/screens.
57
-     *
58
-     * @since 1.8.0
57
+	 *
58
+	 * @since 1.8.0
59 59
 	 */
60 60
 	public function admin_menus() {
61 61
 
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
 
66 66
 		$welcome_page_name  = __( 'Sensei Activation', 'woothemes-sensei' );
67 67
 		$welcome_page_title = __( 'Welcome to Sensei', 'woothemes-sensei' );
68
-        add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) );
68
+		add_dashboard_page( $welcome_page_title, $welcome_page_name, 'manage_options', 'sensei-welcome', array( $this, 'welcome_screen' ) );
69 69
 
70 70
 	}
71 71
 
72
-    /**
73
-     * Output the Welcome  screen.
74
-     *
75
-     * @since 1.8.0
76
-     */
77
-    public function welcome_screen() {
78
-        ?>
72
+	/**
73
+	 * Output the Welcome  screen.
74
+	 *
75
+	 * @since 1.8.0
76
+	 */
77
+	public function welcome_screen() {
78
+		?>
79 79
         <div class="wrap about-wrap">
80 80
 
81 81
             <?php  $this->intro(); ?>
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
             </div>
129 129
         </div>
130 130
     <?php
131
-    }
131
+	}
132 132
 
133 133
 	/**
134 134
 	 * Add styles just for this page, and remove dashboard page links.
135 135
 	 */
136 136
 	public function admin_head() {
137
-        // remove the menu page so it is not visible in the admin side bar
137
+		// remove the menu page so it is not visible in the admin side bar
138 138
 		remove_submenu_page( 'index.php', 'sensei-welcome' );
139 139
 		?>
140 140
 		<style type="text/css">
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 
259 259
 		// Random tweet - must be kept to 102 chars to "fit"
260 260
 		$tweets        = array(
261
-            'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.'
261
+			'I\'ve just installed Sensei - A premium Learning Management plugin for #WordPress.'
262 262
 		);
263 263
 		shuffle( $tweets );
264 264
 		?>
@@ -280,11 +280,11 @@  discard block
 block discarded – undo
280 280
 
281 281
 		<div class="sensei-badge">
282 282
             <?php
283
-                _e('Sensei by WooThemes','woothemes-sensei');
284
-                echo '<br />';
283
+				_e('Sensei by WooThemes','woothemes-sensei');
284
+				echo '<br />';
285 285
 
286
-                printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version );
287
-            ?>
286
+				printf( __( 'Version %s', 'woothemes-sensei' ), Sensei()->version );
287
+			?>
288 288
         </div>
289 289
 
290 290
 		<p class="sensei-actions">
Please login to merge, or discard this patch.
includes/class-sensei-quiz.php 1 patch
Indentation   +884 added lines, -884 removed lines patch added patch discarded remove patch
@@ -24,69 +24,69 @@  discard block
 block discarded – undo
24 24
 	 */
25 25
 	public function __construct ( $file = __FILE__ ) {
26 26
 		$this->file = $file;
27
-        $this->token = 'quiz';
27
+		$this->token = 'quiz';
28 28
 		$this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' );
29 29
 		add_action( 'save_post', array( $this, 'update_author' ));
30 30
 
31 31
 		// listen to the reset button click
32 32
 		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
33 33
 
34
-        // fire the complete quiz button submit for grading action
35
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
34
+		// fire the complete quiz button submit for grading action
35
+		add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
36 36
 
37 37
 		// fire the save user answers quiz button click responder
38 38
 		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
39 39
 
40
-        // fire the load global data function
41
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
40
+		// fire the load global data function
41
+		add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
42 42
 
43
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
43
+		add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
44 44
 
45 45
 
46
-    } // End __construct()
46
+	} // End __construct()
47 47
 
48 48
 	/**
49
-	* Update the quiz author when the lesson post type is save
50
-	*
51
-	* @param int $post_id
52
-	* @return void
53
-	*/
49
+	 * Update the quiz author when the lesson post type is save
50
+	 *
51
+	 * @param int $post_id
52
+	 * @return void
53
+	 */
54 54
 	public function update_author( $post_id ){
55 55
 
56 56
 		// If this isn't a 'lesson' post, don't update it.
57
-        // if this is a revision don't save it
58
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
59
-            || wp_is_post_revision( $post_id ) ) {
57
+		// if this is a revision don't save it
58
+		if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
59
+			|| wp_is_post_revision( $post_id ) ) {
60 60
 
61
-                return;
61
+				return;
62 62
 
63
-        }
64
-	    // get the lesson author id to be use late
65
-	    $saved_post = get_post( $post_id );
66
-	    $new_lesson_author_id =  $saved_post->post_author;
63
+		}
64
+		// get the lesson author id to be use late
65
+		$saved_post = get_post( $post_id );
66
+		$new_lesson_author_id =  $saved_post->post_author;
67 67
 
68
-	    //get the lessons quiz
68
+		//get the lessons quiz
69 69
 		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
70
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
70
+		foreach ( (array) $lesson_quizzes as $quiz_item ) {
71 71
 
72
-	    	if( ! $quiz_item ) {
73
-	    		continue;
74
-	    	}
72
+			if( ! $quiz_item ) {
73
+				continue;
74
+			}
75 75
 
76
-		    // setup the quiz items new author value
76
+			// setup the quiz items new author value
77 77
 			$my_post = array(
78
-			      'ID'           => $quiz_item,
79
-			      'post_author' =>  $new_lesson_author_id
78
+				  'ID'           => $quiz_item,
79
+				  'post_author' =>  $new_lesson_author_id
80 80
 			);
81 81
 
82
-            // remove the action so that it doesn't fire again
83
-            remove_action( 'save_post', array( $this, 'update_author' ));
82
+			// remove the action so that it doesn't fire again
83
+			remove_action( 'save_post', array( $this, 'update_author' ));
84 84
 
85 85
 			// Update the post into the database
86 86
 		  	wp_update_post( $my_post );
87
-	    }
87
+		}
88 88
 
89
-	    return;
89
+		return;
90 90
 	}// end update_author
91 91
 
92 92
 
@@ -117,32 +117,32 @@  discard block
 block discarded – undo
117 117
 	} // end lesson
118 118
 
119 119
 
120
-    /**
121
-     * user_save_quiz_answers_listener
122
-     *
123
-     * This function hooks into the quiz page and accepts the answer form save post.
124
-     * @since 1.7.3
125
-     * @return bool $saved;
126
-     */
127
-    public function user_save_quiz_answers_listener(){
120
+	/**
121
+	 * user_save_quiz_answers_listener
122
+	 *
123
+	 * This function hooks into the quiz page and accepts the answer form save post.
124
+	 * @since 1.7.3
125
+	 * @return bool $saved;
126
+	 */
127
+	public function user_save_quiz_answers_listener(){
128 128
 
129
-        if( ! isset( $_POST[ 'quiz_save' ])
130
-            || !isset( $_POST[ 'sensei_question' ] )
131
-            || empty( $_POST[ 'sensei_question' ] )
132
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
133
-            return;
134
-        }
129
+		if( ! isset( $_POST[ 'quiz_save' ])
130
+			|| !isset( $_POST[ 'sensei_question' ] )
131
+			|| empty( $_POST[ 'sensei_question' ] )
132
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
133
+			return;
134
+		}
135 135
 
136
-        global $post;
137
-        $lesson_id = $this->get_lesson_id( $post->ID );
138
-        $quiz_answers = $_POST[ 'sensei_question' ];
139
-        // call the save function
140
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
136
+		global $post;
137
+		$lesson_id = $this->get_lesson_id( $post->ID );
138
+		$quiz_answers = $_POST[ 'sensei_question' ];
139
+		// call the save function
140
+		self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
141 141
 
142
-        // remove the hook as it should only fire once per click
143
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
142
+		// remove the hook as it should only fire once per click
143
+		remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
144 144
 
145
-    } // end user_save_quiz_answers_listener
145
+	} // end user_save_quiz_answers_listener
146 146
 
147 147
 	/**
148 148
 	 * Save the user answers for the given lesson's quiz
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @access public
154 154
 	 *
155 155
 	 * @param array $quiz_answers
156
-     * @param array $files from global $_FILES
156
+	 * @param array $files from global $_FILES
157 157
 	 * @param int $lesson_id
158 158
 	 * @param int $user_id
159 159
 	 *
@@ -161,11 +161,11 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
163 163
 
164
-        if( ! ( $user_id > 0 ) ){
165
-            $user_id = get_current_user_id();
166
-        }
164
+		if( ! ( $user_id > 0 ) ){
165
+			$user_id = get_current_user_id();
166
+		}
167 167
 
168
-        // make sure the parameters are valid before continuing
168
+		// make sure the parameters are valid before continuing
169 169
 		if( empty( $lesson_id ) || empty( $user_id )
170 170
 			|| 'lesson' != get_post_type( $lesson_id )
171 171
 			||!get_userdata( $user_id )
@@ -176,25 +176,25 @@  discard block
 block discarded – undo
176 176
 		}
177 177
 
178 178
 
179
-        // start the lesson before saving the data in case the user has not started the lesson
180
-        $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
179
+		// start the lesson before saving the data in case the user has not started the lesson
180
+		$activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
181 181
 
182 182
 		//prepare the answers
183 183
 		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
184 184
 
185 185
 		// save the user data
186
-        $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
186
+		$answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
187 187
 
188 188
 		// were the answers saved correctly?
189 189
 		if( intval( $answers_saved ) > 0){
190 190
 
191
-            // save transient to make retrieval faster
192
-            $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
193
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
191
+			// save transient to make retrieval faster
192
+			$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
193
+			set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
194 194
 
195
-            // update the message showed to user
196
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
-        }
195
+			// update the message showed to user
196
+			Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
+		}
198 198
 
199 199
 		return $answers_saved;
200 200
 
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 
203 203
 	/**
204 204
 	 * Get the user answers for the given lesson's quiz.
205
-     *
206
-     * This function returns the data that is stored on the lesson as meta and is not compatible with
207
-     * retrieving data for quiz answer before sensei 1.7.4
205
+	 *
206
+	 * This function returns the data that is stored on the lesson as meta and is not compatible with
207
+	 * retrieving data for quiz answer before sensei 1.7.4
208 208
 	 *
209 209
 	 *
210 210
 	 * @since 1.7.4
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
 			return false;
225 225
 		}
226 226
 
227
-        // save some time and get the transient cached data
228
-        $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
229
-        $transient_cached_answers = get_transient( $transient_key );
227
+		// save some time and get the transient cached data
228
+		$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
229
+		$transient_cached_answers = get_transient( $transient_key );
230 230
 
231
-        // return the transient or get the values get the values from the comment meta
232
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
231
+		// return the transient or get the values get the values from the comment meta
232
+		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
233 233
 
234
-            $encoded_user_answers = $transient_cached_answers;
234
+			$encoded_user_answers = $transient_cached_answers;
235 235
 
236
-        }else{
236
+		}else{
237 237
 
238
-            $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
238
+			$encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
239 239
 
240
-        } // end if transient check
240
+		} // end if transient check
241 241
 
242 242
 		if( ! is_array( $encoded_user_answers ) ){
243 243
 			return false;
244 244
 		}
245 245
 
246
-        //set the transient with the new valid data for faster retrieval in future
247
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
246
+		//set the transient with the new valid data for faster retrieval in future
247
+		set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
248 248
 
249 249
 		// decode an unserialize all answers
250 250
 		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
 		$current_quiz_id = $post->ID;
279 279
 		$lesson_id = $this->get_lesson_id( $current_quiz_id );
280 280
 
281
-        // reset all user data
282
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
281
+		// reset all user data
282
+		$this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
283 283
 
284 284
 		//this function should only run once
285 285
 		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * Complete/ submit  quiz hooked function
291 291
 	 *
292 292
 	 * This function listens to the complete button submit action and processes the users submitted answers
293
-     * not that this function submits the given users quiz answers for grading.
293
+	 * not that this function submits the given users quiz answers for grading.
294 294
 	 *
295 295
 	 * @since  1.7.4
296 296
 	 * @access public
@@ -300,90 +300,90 @@  discard block
 block discarded – undo
300 300
 	 */
301 301
 	public function user_quiz_submit_listener() {
302 302
 
303
-        // only respond to valid quiz completion submissions
304
-        if( ! isset( $_POST[ 'quiz_complete' ])
305
-            || !isset( $_POST[ 'sensei_question' ] )
306
-            || empty( $_POST[ 'sensei_question' ] )
307
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
308
-            return;
309
-        }
303
+		// only respond to valid quiz completion submissions
304
+		if( ! isset( $_POST[ 'quiz_complete' ])
305
+			|| !isset( $_POST[ 'sensei_question' ] )
306
+			|| empty( $_POST[ 'sensei_question' ] )
307
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
308
+			return;
309
+		}
310 310
 
311
-        global $post, $current_user;
312
-        $lesson_id = $this->get_lesson_id( $post->ID );
313
-        $quiz_answers = $_POST[ 'sensei_question' ];
311
+		global $post, $current_user;
312
+		$lesson_id = $this->get_lesson_id( $post->ID );
313
+		$quiz_answers = $_POST[ 'sensei_question' ];
314 314
 
315
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
315
+		self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
316 316
 
317 317
 	} // End sensei_complete_quiz()
318 318
 
319
-    /**
320
-     * This function set's up the data need for the quiz page
321
-     *
322
-     * This function hooks into sensei_complete_quiz and load the global data for the
323
-     * current quiz.
324
-     *
325
-     * @since 1.7.4
326
-     * @access public
327
-     *
328
-     */
329
-    public function load_global_quiz_data(){
319
+	/**
320
+	 * This function set's up the data need for the quiz page
321
+	 *
322
+	 * This function hooks into sensei_complete_quiz and load the global data for the
323
+	 * current quiz.
324
+	 *
325
+	 * @since 1.7.4
326
+	 * @access public
327
+	 *
328
+	 */
329
+	public function load_global_quiz_data(){
330 330
 
331
-        global  $post, $current_user;
332
-        $this->data = new stdClass();
331
+		global  $post, $current_user;
332
+		$this->data = new stdClass();
333 333
 
334
-        // Default grade
335
-        $grade = 0;
334
+		// Default grade
335
+		$grade = 0;
336 336
 
337
-        // Get Quiz Questions
338
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
337
+		// Get Quiz Questions
338
+		$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
339 339
 
340
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
340
+		$quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
341 341
 
342
-        // Get quiz grade type
343
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
342
+		// Get quiz grade type
343
+		$quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
344 344
 
345
-        // Get quiz pass setting
346
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
345
+		// Get quiz pass setting
346
+		$pass_required = get_post_meta( $post->ID, '_pass_required', true );
347 347
 
348
-        // Get quiz pass mark
349
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
348
+		// Get quiz pass mark
349
+		$quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
350 350
 
351
-        // Get latest quiz answers and grades
352
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
353
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
354
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
355
-        $user_quiz_grade = 0;
356
-        if( isset( $user_lesson_status->comment_ID ) ) {
357
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
358
-        }
351
+		// Get latest quiz answers and grades
352
+		$lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
353
+		$user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
354
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
355
+		$user_quiz_grade = 0;
356
+		if( isset( $user_lesson_status->comment_ID ) ) {
357
+			$user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
358
+		}
359 359
 
360
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
360
+		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
361 361
 
362
-        // Check again that the lesson is complete
363
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
-        $user_lesson_complete = false;
365
-        if ( $user_lesson_end ) {
366
-            $user_lesson_complete = true;
367
-        } // End If Statement
362
+		// Check again that the lesson is complete
363
+		$user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
+		$user_lesson_complete = false;
365
+		if ( $user_lesson_end ) {
366
+			$user_lesson_complete = true;
367
+		} // End If Statement
368 368
 
369
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
-        //backwards compatibility
371
-        if( 'on' == $reset_allowed ) {
372
-            $reset_allowed = 1;
373
-        }
369
+		$reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
+		//backwards compatibility
371
+		if( 'on' == $reset_allowed ) {
372
+			$reset_allowed = 1;
373
+		}
374 374
 
375
-        // Build frontend data object for backwards compatibility
376
-        // using this is no longer recommended
377
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
-        $this->data->quiz_passmark = $quiz_passmark;
379
-        $this->data->quiz_lesson = $quiz_lesson_id;
380
-        $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
381
-        $this->data->user_lesson_end = $user_lesson_end;
382
-        $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
383
-        $this->data->lesson_quiz_questions = $lesson_quiz_questions;
384
-        $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
375
+		// Build frontend data object for backwards compatibility
376
+		// using this is no longer recommended
377
+		$this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
+		$this->data->quiz_passmark = $quiz_passmark;
379
+		$this->data->quiz_lesson = $quiz_lesson_id;
380
+		$this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
381
+		$this->data->user_lesson_end = $user_lesson_end;
382
+		$this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
383
+		$this->data->lesson_quiz_questions = $lesson_quiz_questions;
384
+		$this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
385 385
 
386
-    } // end load_global_quiz_data
386
+	} // end load_global_quiz_data
387 387
 
388 388
 
389 389
 	/**
@@ -413,25 +413,25 @@  discard block
 block discarded – undo
413 413
 		foreach( $unprepared_answers as $question_id => $answer ) {
414 414
 
415 415
 			//get the current questions question type
416
-            $question_type = Sensei()->question->get_question_type( $question_id );
416
+			$question_type = Sensei()->question->get_question_type( $question_id );
417 417
 
418 418
 			// Sanitise answer
419 419
 			if( 0 == get_magic_quotes_gpc() ) {
420 420
 				$answer = wp_unslash( $answer );
421 421
 			}
422 422
 
423
-            // compress the answer for saving
423
+			// compress the answer for saving
424 424
 			if( 'multi-line' == $question_type ) {
425
-                $answer = esc_html( $answer );
426
-            }elseif( 'file-upload' == $question_type  ){
427
-                $file_key = 'file_upload_' . $question_id;
428
-                if( isset( $files[ $file_key ] ) ) {
429
-                        $attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
430
-                        if( $attachment_id ) {
431
-                            $answer = $attachment_id;
432
-                        }
433
-                    }
434
-            } // end if
425
+				$answer = esc_html( $answer );
426
+			}elseif( 'file-upload' == $question_type  ){
427
+				$file_key = 'file_upload_' . $question_id;
428
+				if( isset( $files[ $file_key ] ) ) {
429
+						$attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
430
+						if( $attachment_id ) {
431
+							$answer = $attachment_id;
432
+						}
433
+					}
434
+			} // end if
435 435
 
436 436
 			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
437 437
 
@@ -440,813 +440,813 @@  discard block
 block discarded – undo
440 440
 		return $prepared_answers;
441 441
 	} // prepare_form_submitted_answers
442 442
 
443
-    /**
444
-     * Reset user submitted questions
445
-     *
446
-     * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
447
-     * the save_user_answers as currently the saved and submitted answers are stored differently.
448
-     *
449
-     * @since 1.7.4
450
-     * @access public
451
-     *
452
-     * @return bool $reset_success
453
-     * @param int $user_id
454
-     * @param int $lesson_id
455
-     */
456
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
443
+	/**
444
+	 * Reset user submitted questions
445
+	 *
446
+	 * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
447
+	 * the save_user_answers as currently the saved and submitted answers are stored differently.
448
+	 *
449
+	 * @since 1.7.4
450
+	 * @access public
451
+	 *
452
+	 * @return bool $reset_success
453
+	 * @param int $user_id
454
+	 * @param int $lesson_id
455
+	 */
456
+	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
457
+
458
+		//make sure the parameters are valid
459
+		if( empty( $lesson_id ) || empty( $user_id )
460
+			|| 'lesson' != get_post_type( $lesson_id )
461
+			|| ! get_userdata( $user_id ) ){
462
+			return false;
463
+		}
464
+
465
+
466
+
467
+		//get the users lesson status to make
468
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
469
+		if( ! isset( $user_lesson_status->comment_ID ) ) {
470
+			// this user is not taking this lesson so this process is not needed
471
+			return false;
472
+		}
473
+
474
+		//get the lesson quiz and course
475
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
476
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
477
+
478
+		// reset the transients
479
+		$answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
480
+		$grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
481
+		$answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
482
+		delete_transient( $answers_transient_key );
483
+		delete_transient( $grades_transient_key );
484
+		delete_transient( $answers_feedback_transient_key );
485
+
486
+		// reset the quiz answers and feedback notes
487
+		$deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
488
+		$deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
489
+		$deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
490
+
491
+		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
492
+		Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
493
+
494
+		Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
495
+
496
+		// Update course completion
497
+		Sensei_Utils::update_course_status( $user_id, $course_id );
457 498
 
458
-        //make sure the parameters are valid
459
-        if( empty( $lesson_id ) || empty( $user_id )
460
-            || 'lesson' != get_post_type( $lesson_id )
461
-            || ! get_userdata( $user_id ) ){
462
-            return false;
463
-        }
464
-
465
-
466
-
467
-        //get the users lesson status to make
468
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
469
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
470
-            // this user is not taking this lesson so this process is not needed
471
-            return false;
472
-        }
499
+		// Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
500
+		do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
501
+		Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
473 502
 
474
-        //get the lesson quiz and course
475
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
476
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
503
+		return ( $deleted_answers && $deleted_grades ) ;
477 504
 
478
-        // reset the transients
479
-        $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
480
-        $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
481
-        $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
482
-        delete_transient( $answers_transient_key );
483
-        delete_transient( $grades_transient_key );
484
-        delete_transient( $answers_feedback_transient_key );
505
+	} // end reset_user_lesson_data
485 506
 
486
-        // reset the quiz answers and feedback notes
487
-        $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
488
-        $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
489
-        $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
507
+	 /**
508
+	  * Submit the users quiz answers for grading
509
+	  *
510
+	  * This function accepts users answers and stores it but also initiates the grading
511
+	  * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
512
+	  *
513
+	  * @since 1.7.4
514
+	  * @access public
515
+	  *
516
+	  * @param array $quiz_answers
517
+	  * @param array $files from $_FILES
518
+	  * @param int $user_id
519
+	  * @param int $lesson_id
520
+	  *
521
+	  * @return bool $answers_submitted
522
+	  */
523
+	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
490 524
 
491
-        // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
492
-        Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
525
+		 $answers_submitted = false;
493 526
 
494
-        Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
527
+		 // get the user_id if none was passed in use the current logged in user
528
+		 if( ! intval( $user_id ) > 0 ) {
529
+			 $user_id = get_current_user_id();
530
+		 }
495 531
 
496
-        // Update course completion
497
-        Sensei_Utils::update_course_status( $user_id, $course_id );
532
+		 // make sure the parameters are valid before continuing
533
+		 if( empty( $lesson_id ) || empty( $user_id )
534
+			 || 'lesson' != get_post_type( $lesson_id )
535
+			 ||!get_userdata( $user_id )
536
+			 || !is_array( $quiz_answers ) ){
498 537
 
499
-        // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
500
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
501
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
538
+			 return false;
502 539
 
503
-        return ( $deleted_answers && $deleted_grades ) ;
540
+		 }
504 541
 
505
-    } // end reset_user_lesson_data
542
+		 // Default grade
543
+		 $grade = 0;
506 544
 
507
-     /**
508
-      * Submit the users quiz answers for grading
509
-      *
510
-      * This function accepts users answers and stores it but also initiates the grading
511
-      * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
512
-      *
513
-      * @since 1.7.4
514
-      * @access public
515
-      *
516
-      * @param array $quiz_answers
517
-      * @param array $files from $_FILES
518
-      * @param int $user_id
519
-      * @param int $lesson_id
520
-      *
521
-      * @return bool $answers_submitted
522
-      */
523
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
545
+		 // Get Quiz ID
546
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
524 547
 
525
-         $answers_submitted = false;
548
+		 // Get quiz grade type
549
+		 $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
526 550
 
527
-         // get the user_id if none was passed in use the current logged in user
528
-         if( ! intval( $user_id ) > 0 ) {
529
-             $user_id = get_current_user_id();
530
-         }
551
+		 // Get quiz pass setting
552
+		 $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
531 553
 
532
-         // make sure the parameters are valid before continuing
533
-         if( empty( $lesson_id ) || empty( $user_id )
534
-             || 'lesson' != get_post_type( $lesson_id )
535
-             ||!get_userdata( $user_id )
536
-             || !is_array( $quiz_answers ) ){
554
+		 // Get the minimum percentage need to pass this quiz
555
+		 $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
537 556
 
538
-             return false;
557
+		 // Handle Quiz Questions asked
558
+		 // This is to ensure we save the questions that we've asked this user and that this can't be change unless
559
+		 // the quiz is reset by admin or user( user: only if the setting is enabled ).
560
+		 // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
561
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
562
+		 $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
563
+		 if( empty( $questions_asked ) ){
539 564
 
540
-         }
565
+			 $questions_asked = array_keys( $quiz_answers );
566
+			 $questions_asked_string = implode( ',', $questions_asked );
541 567
 
542
-         // Default grade
543
-         $grade = 0;
568
+			 // Save questions that were asked in this quiz
569
+			 update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
544 570
 
545
-         // Get Quiz ID
546
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
571
+		 }
547 572
 
548
-         // Get quiz grade type
549
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
573
+		 // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
574
+		 self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
550 575
 
551
-         // Get quiz pass setting
552
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
576
+		 // Grade quiz
577
+		 $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
553 578
 
554
-         // Get the minimum percentage need to pass this quiz
555
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
579
+		 // Get Lesson Grading Setting
580
+		 $lesson_metadata = array();
581
+		 $lesson_status = 'ungraded'; // Default when completing a quiz
556 582
 
557
-         // Handle Quiz Questions asked
558
-         // This is to ensure we save the questions that we've asked this user and that this can't be change unless
559
-         // the quiz is reset by admin or user( user: only if the setting is enabled ).
560
-         // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
561
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
562
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
563
-         if( empty( $questions_asked ) ){
583
+		 // At this point the answers have been submitted
584
+		 $answers_submitted = true;
564 585
 
565
-             $questions_asked = array_keys( $quiz_answers );
566
-             $questions_asked_string = implode( ',', $questions_asked );
567
-
568
-             // Save questions that were asked in this quiz
569
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
586
+		 // if this condition is false the quiz should manually be graded by admin
587
+		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
570 588
 
571
-         }
589
+			 // Quiz has been automatically Graded
590
+			 if ( 'on' == $pass_required ) {
572 591
 
573
-         // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
574
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
592
+				 // Student has reached the pass mark and lesson is complete
593
+				 if ( $quiz_pass_percentage <= $grade ) {
575 594
 
576
-         // Grade quiz
577
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
595
+					 $lesson_status = 'passed';
578 596
 
579
-         // Get Lesson Grading Setting
580
-         $lesson_metadata = array();
581
-         $lesson_status = 'ungraded'; // Default when completing a quiz
597
+				 } else {
582 598
 
583
-         // At this point the answers have been submitted
584
-         $answers_submitted = true;
599
+					 $lesson_status = 'failed';
585 600
 
586
-         // if this condition is false the quiz should manually be graded by admin
587
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
601
+				 } // End If Statement
588 602
 
589
-             // Quiz has been automatically Graded
590
-             if ( 'on' == $pass_required ) {
603
+			 } else {
591 604
 
592
-                 // Student has reached the pass mark and lesson is complete
593
-                 if ( $quiz_pass_percentage <= $grade ) {
605
+				 // Student only has to partake the quiz
606
+				 $lesson_status = 'graded';
607
+
608
+			 }
609
+
610
+			 $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
611
+
612
+		 } // end if ! is_wp_error( $grade ...
613
+
614
+		 Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
594 615
 
595
-                     $lesson_status = 'passed';
616
+		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
596 617
 
597
-                 } else {
618
+			 /**
619
+			  * Lesson end action hook
620
+			  *
621
+			  * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
622
+			  *
623
+			  * @param int $user_id
624
+			  * @param int $lesson_id
625
+			  */
626
+			 do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
598 627
 
599
-                     $lesson_status = 'failed';
628
+		 }
600 629
 
601
-                 } // End If Statement
630
+		 /**
631
+		  * User quiz has been submitted
632
+		  *
633
+		  * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
634
+		  * results.
635
+		  *
636
+		  * @param int $user_id
637
+		  * @param int $quiz_id
638
+		  * @param string $grade
639
+		  * @param string $quiz_pass_percentage
640
+		  * @param string $quiz_grade_type
641
+		  */
642
+		 do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
602 643
 
603
-             } else {
644
+		 return $answers_submitted;
604 645
 
605
-                 // Student only has to partake the quiz
606
-                 $lesson_status = 'graded';
607
-
608
-             }
609
-
610
-             $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
611
-
612
-         } // end if ! is_wp_error( $grade ...
613
-
614
-         Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
646
+	 }// end submit_answers_for_grading
615 647
 
616
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
648
+	 /**
649
+	  * Get the user question answer
650
+	  *
651
+	  * This function gets the the users saved answer on given quiz for the given question parameter
652
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
653
+	  *
654
+	  * @since 1.7.4
655
+	  *
656
+	  * @param int  $lesson_id
657
+	  * @param int $question_id
658
+	  * @param int  $user_id ( optional )
659
+	  *
660
+	  * @return bool $answers_submitted
661
+	  */
662
+	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
617 663
 
618
-             /**
619
-              * Lesson end action hook
620
-              *
621
-              * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
622
-              *
623
-              * @param int $user_id
624
-              * @param int $lesson_id
625
-              */
626
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
664
+		 // parameter validation
665
+		 if( empty( $lesson_id ) || empty( $question_id )
666
+			 || ! ( intval( $lesson_id  ) > 0 )
667
+			 || ! ( intval( $question_id  ) > 0 )
668
+			 || 'lesson' != get_post_type( $lesson_id )
669
+			 || 'question' != get_post_type( $question_id )) {
627 670
 
628
-         }
671
+			 return false;
672
+		 }
673
+
674
+		 if( ! ( intval( $user_id ) > 0 )   ){
675
+			 $user_id = get_current_user_id();
676
+		 }
677
+
678
+		 $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
+
680
+		 if( !$users_answers || empty( $users_answers )
681
+		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
682
+
683
+			 //Fallback for pre 1.7.4 data
684
+			 $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
+
686
+			 if( ! isset( $comment->comment_content ) ){
687
+				 return false;
688
+			 }
689
+
690
+			 return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
+		 }
692
+
693
+		 return $users_answers[ $question_id ];
694
+
695
+	 }// end get_user_question_answer
696
+
697
+	 /**
698
+	  * Saving the users quiz question grades
699
+	  *
700
+	  * This function save all the grades for all the question in a given quiz on the lesson
701
+	  * comment meta. It makes use of transients to save the grades for easier access at a later stage
702
+	  *
703
+	  * @since 1.7.4
704
+	  *
705
+	  * @param array $quiz_grades{
706
+	  *      @type int $question_id
707
+	  *      @type int $question_grade
708
+	  * }
709
+	  * @param $lesson_id
710
+	  * @param $user_id (Optional) will use the current user if not supplied
711
+	  *
712
+	  * @return bool
713
+	  */
714
+	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
+
716
+		 // get the user_id if none was passed in use the current logged in user
717
+		 if( ! intval( $user_id ) > 0 ) {
718
+			 $user_id = get_current_user_id();
719
+		 }
720
+
721
+		 // make sure the parameters are valid before continuing
722
+		 if( empty( $lesson_id ) || empty( $user_id )
723
+			 || 'lesson' != get_post_type( $lesson_id )
724
+			 ||!get_userdata( $user_id )
725
+			 || !is_array( $quiz_grades ) ){
726
+
727
+			 return false;
728
+
729
+		 }
730
+
731
+		 $success = false;
732
+
733
+		 // save that data for the user on the lesson comment meta
734
+		 $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
+
736
+		 // were the grades save successfully ?
737
+		 if( intval( $comment_meta_id ) > 0 ) {
738
+
739
+			 $success = true;
740
+			 // save transient
741
+			 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
742
+			 set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
743
+		 }
744
+
745
+		 return $success;
746
+
747
+	 }// end set_user_grades
748
+
749
+	 /**
750
+	  * Retrieve the users quiz question grades
751
+	  *
752
+	  * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
753
+	  *
754
+	  * @since 1.7.4
755
+	  *
756
+	  * @param $lesson_id
757
+	  * @param $user_id (Optional) will use the current user if not supplied
758
+	  *
759
+	  * @return array $user_quiz_grades or false if none exists for this users
760
+	  */
761
+	 public function get_user_grades( $lesson_id, $user_id = 0 ){
762
+
763
+		 $user_grades = array();
764
+
765
+		 // get the user_id if none was passed in use the current logged in user
766
+		 if( ! intval( $user_id ) > 0 ) {
767
+			 $user_id = get_current_user_id();
768
+		 }
769
+
770
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
771
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
772
+			 return false;
773
+		 }
774
+
775
+		 // save some time and get the transient cached data
776
+		 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
777
+		 $user_grades = get_transient( $transient_key );
778
+
779
+		 // get the data if nothing was stored in the transient
780
+		 if( empty( $user_grades  ) || false != $user_grades ){
781
+
782
+			 $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
+
784
+			 //set the transient with the new valid data for faster retrieval in future
785
+			 set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
+
787
+		 } // end if transient check
788
+
789
+		 // if there is no data for this user
790
+		 if( ! is_array( $user_grades ) ){
791
+			 return false;
792
+		 }
793
+
794
+		 return $user_grades;
795
+
796
+	 }// end  get_user_grades
797
+
798
+	 /**
799
+	  * Get the user question grade
800
+	  *
801
+	  * This function gets the grade on a quiz for the given question parameter
802
+	  * It does NOT do any grading. It simply retrieves the data that was stored during grading.
803
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
804
+	  *
805
+	  * @since 1.7.4
806
+	  *
807
+	  * @param int  $lesson_id
808
+	  * @param int $question_id
809
+	  * @param int  $user_id ( optional )
810
+	  *
811
+	  * @return bool $question_grade
812
+	  */
813
+	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
+
815
+		 // parameter validation
816
+		 if( empty( $lesson_id ) || empty( $question_id )
817
+			 || ! ( intval( $lesson_id  ) > 0 )
818
+			 || ! ( intval( $question_id  ) > 0 )
819
+			 || 'lesson' != get_post_type( $lesson_id )
820
+			 || 'question' != get_post_type( $question_id )) {
821
+
822
+			 return false;
823
+		 }
824
+
825
+		 $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
+
827
+		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
+
829
+			 //fallback to data pre 1.7.4
830
+			 $args = array(
831
+				 'post_id' => $question_id,
832
+				 'user_id' => $user_id,
833
+				 'type'    => 'sensei_user_answer'
834
+			 );
835
+
836
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
837
+			 $fall_back_grade = false;
838
+			 if( isset( $question_activity->comment_ID ) ){
839
+				 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
840
+			 }
841
+
842
+			 return $fall_back_grade;
843
+
844
+		 } // end if $all_user_grades...
845
+
846
+		 return $all_user_grades[ $question_id ];
847
+
848
+	 }// end get_user_question_grade
849
+
850
+	 /**
851
+	  * Save the user's answers feedback
852
+	  *
853
+	  * For this function you must supply all three parameters. If will return false one is left out.
854
+	  * The data will be saved on the lesson ID supplied.
855
+	  *
856
+	  * @since 1.7.5
857
+	  * @access public
858
+	  *
859
+	  * @param array $answers_feedback{
860
+	  *  $type int $question_id
861
+	  *  $type string $question_feedback
862
+	  * }
863
+	  * @param int $lesson_id
864
+	  * @param int $user_id
865
+	  *
866
+	  * @return false or int $feedback_saved
867
+	  */
868
+	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
+
870
+		// make sure the parameters are valid before continuing
871
+		if( empty( $lesson_id ) || empty( $user_id )
872
+			|| 'lesson' != get_post_type( $lesson_id )
873
+			||!get_userdata( $user_id )
874
+			|| !is_array( $answers_feedback ) ){
875
+
876
+			return false;
877
+
878
+		}
879
+
880
+
881
+		// check if the lesson is started before saving, if not start the lesson for the user
882
+		if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
883
+			Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
884
+		}
629 885
 
630
-         /**
631
-          * User quiz has been submitted
632
-          *
633
-          * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
634
-          * results.
635
-          *
636
-          * @param int $user_id
637
-          * @param int $quiz_id
638
-          * @param string $grade
639
-          * @param string $quiz_pass_percentage
640
-          * @param string $quiz_grade_type
641
-          */
642
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
886
+		// encode the feedback
887
+		$encoded_answers_feedback =  array();
888
+		foreach( $answers_feedback as $question_id => $feedback ){
889
+			$encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
890
+		}
891
+
892
+		// save the user data
893
+		$feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
+
895
+		//Were the the question feedback save correctly?
896
+		if( intval( $feedback_saved ) > 0){
897
+
898
+			// save transient to make retrieval faster in future
899
+			 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
900
+			 set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
643 901
 
644
-         return $answers_submitted;
902
+		}
903
+
904
+		return $feedback_saved;
905
+
906
+	} // end save_user_answers_feedback
907
+
908
+	 /**
909
+	  * Get the user's answers feedback.
910
+	  *
911
+	  * This function returns the feedback submitted by the teacher/admin
912
+	  * during grading. Grading occurs manually or automatically.
913
+	  *
914
+	  * @since 1.7.5
915
+	  * @access public
916
+	  *
917
+	  * @param int $lesson_id
918
+	  * @param int $user_id
919
+	  *
920
+	  * @return false | array $answers_feedback{
921
+	  *  $type int $question_id
922
+	  *  $type string $question_feedback
923
+	  * }
924
+	  */
925
+	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
+
927
+		 $answers_feedback = array();
645 928
 
646
-     }// end submit_answers_for_grading
929
+		 // get the user_id if none was passed in use the current logged in user
930
+		 if( ! intval( $user_id ) > 0 ) {
931
+			 $user_id = get_current_user_id();
932
+		 }
647 933
 
648
-     /**
649
-      * Get the user question answer
650
-      *
651
-      * This function gets the the users saved answer on given quiz for the given question parameter
652
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
653
-      *
654
-      * @since 1.7.4
655
-      *
656
-      * @param int  $lesson_id
657
-      * @param int $question_id
658
-      * @param int  $user_id ( optional )
659
-      *
660
-      * @return bool $answers_submitted
661
-      */
662
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
934
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
935
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
936
+			 return false;
937
+		 }
938
+
939
+		 // first check the transient to save a few split seconds
940
+		 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
941
+		 $encoded_feedback = get_transient( $transient_key );
942
+
943
+		 // get the data if nothing was stored in the transient
944
+		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
+
946
+			 $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
+
948
+			 //set the transient with the new valid data for faster retrieval in future
949
+			 set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
+
951
+		 } // end if transient check
663 952
 
664
-         // parameter validation
665
-         if( empty( $lesson_id ) || empty( $question_id )
666
-             || ! ( intval( $lesson_id  ) > 0 )
667
-             || ! ( intval( $question_id  ) > 0 )
668
-             || 'lesson' != get_post_type( $lesson_id )
669
-             || 'question' != get_post_type( $question_id )) {
953
+		 // if there is no data for this user
954
+		 if( ! is_array( $encoded_feedback ) ){
955
+			 return false;
956
+		 }
670 957
 
671
-             return false;
672
-         }
673
-
674
-         if( ! ( intval( $user_id ) > 0 )   ){
675
-             $user_id = get_current_user_id();
676
-         }
677
-
678
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
-
680
-         if( !$users_answers || empty( $users_answers )
681
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
682
-
683
-             //Fallback for pre 1.7.4 data
684
-             $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
-
686
-             if( ! isset( $comment->comment_content ) ){
687
-                 return false;
688
-             }
689
-
690
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
-         }
692
-
693
-         return $users_answers[ $question_id ];
694
-
695
-     }// end get_user_question_answer
696
-
697
-     /**
698
-      * Saving the users quiz question grades
699
-      *
700
-      * This function save all the grades for all the question in a given quiz on the lesson
701
-      * comment meta. It makes use of transients to save the grades for easier access at a later stage
702
-      *
703
-      * @since 1.7.4
704
-      *
705
-      * @param array $quiz_grades{
706
-      *      @type int $question_id
707
-      *      @type int $question_grade
708
-      * }
709
-      * @param $lesson_id
710
-      * @param $user_id (Optional) will use the current user if not supplied
711
-      *
712
-      * @return bool
713
-      */
714
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
-
716
-         // get the user_id if none was passed in use the current logged in user
717
-         if( ! intval( $user_id ) > 0 ) {
718
-             $user_id = get_current_user_id();
719
-         }
720
-
721
-         // make sure the parameters are valid before continuing
722
-         if( empty( $lesson_id ) || empty( $user_id )
723
-             || 'lesson' != get_post_type( $lesson_id )
724
-             ||!get_userdata( $user_id )
725
-             || !is_array( $quiz_grades ) ){
726
-
727
-             return false;
728
-
729
-         }
730
-
731
-         $success = false;
732
-
733
-         // save that data for the user on the lesson comment meta
734
-         $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
-
736
-         // were the grades save successfully ?
737
-         if( intval( $comment_meta_id ) > 0 ) {
738
-
739
-             $success = true;
740
-             // save transient
741
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
742
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
743
-         }
744
-
745
-         return $success;
746
-
747
-     }// end set_user_grades
748
-
749
-     /**
750
-      * Retrieve the users quiz question grades
751
-      *
752
-      * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
753
-      *
754
-      * @since 1.7.4
755
-      *
756
-      * @param $lesson_id
757
-      * @param $user_id (Optional) will use the current user if not supplied
758
-      *
759
-      * @return array $user_quiz_grades or false if none exists for this users
760
-      */
761
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
762
-
763
-         $user_grades = array();
764
-
765
-         // get the user_id if none was passed in use the current logged in user
766
-         if( ! intval( $user_id ) > 0 ) {
767
-             $user_id = get_current_user_id();
768
-         }
769
-
770
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
771
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
772
-             return false;
773
-         }
774
-
775
-         // save some time and get the transient cached data
776
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
777
-         $user_grades = get_transient( $transient_key );
778
-
779
-         // get the data if nothing was stored in the transient
780
-         if( empty( $user_grades  ) || false != $user_grades ){
781
-
782
-             $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
-
784
-             //set the transient with the new valid data for faster retrieval in future
785
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
-
787
-         } // end if transient check
788
-
789
-         // if there is no data for this user
790
-         if( ! is_array( $user_grades ) ){
791
-             return false;
792
-         }
793
-
794
-         return $user_grades;
795
-
796
-     }// end  get_user_grades
797
-
798
-     /**
799
-      * Get the user question grade
800
-      *
801
-      * This function gets the grade on a quiz for the given question parameter
802
-      * It does NOT do any grading. It simply retrieves the data that was stored during grading.
803
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
804
-      *
805
-      * @since 1.7.4
806
-      *
807
-      * @param int  $lesson_id
808
-      * @param int $question_id
809
-      * @param int  $user_id ( optional )
810
-      *
811
-      * @return bool $question_grade
812
-      */
813
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
-
815
-         // parameter validation
816
-         if( empty( $lesson_id ) || empty( $question_id )
817
-             || ! ( intval( $lesson_id  ) > 0 )
818
-             || ! ( intval( $question_id  ) > 0 )
819
-             || 'lesson' != get_post_type( $lesson_id )
820
-             || 'question' != get_post_type( $question_id )) {
821
-
822
-             return false;
823
-         }
824
-
825
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
-
827
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
-
829
-             //fallback to data pre 1.7.4
830
-             $args = array(
831
-                 'post_id' => $question_id,
832
-                 'user_id' => $user_id,
833
-                 'type'    => 'sensei_user_answer'
834
-             );
835
-
836
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
837
-             $fall_back_grade = false;
838
-             if( isset( $question_activity->comment_ID ) ){
839
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
840
-             }
841
-
842
-             return $fall_back_grade;
843
-
844
-         } // end if $all_user_grades...
845
-
846
-         return $all_user_grades[ $question_id ];
847
-
848
-     }// end get_user_question_grade
849
-
850
-     /**
851
-      * Save the user's answers feedback
852
-      *
853
-      * For this function you must supply all three parameters. If will return false one is left out.
854
-      * The data will be saved on the lesson ID supplied.
855
-      *
856
-      * @since 1.7.5
857
-      * @access public
858
-      *
859
-      * @param array $answers_feedback{
860
-      *  $type int $question_id
861
-      *  $type string $question_feedback
862
-      * }
863
-      * @param int $lesson_id
864
-      * @param int $user_id
865
-      *
866
-      * @return false or int $feedback_saved
867
-      */
868
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
-
870
-        // make sure the parameters are valid before continuing
871
-        if( empty( $lesson_id ) || empty( $user_id )
872
-            || 'lesson' != get_post_type( $lesson_id )
873
-            ||!get_userdata( $user_id )
874
-            || !is_array( $answers_feedback ) ){
875
-
876
-            return false;
877
-
878
-        }
879
-
880
-
881
-        // check if the lesson is started before saving, if not start the lesson for the user
882
-        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
883
-            Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
884
-        }
885
-
886
-        // encode the feedback
887
-        $encoded_answers_feedback =  array();
888
-        foreach( $answers_feedback as $question_id => $feedback ){
889
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
890
-        }
891
-
892
-        // save the user data
893
-        $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
-
895
-        //Were the the question feedback save correctly?
896
-        if( intval( $feedback_saved ) > 0){
897
-
898
-            // save transient to make retrieval faster in future
899
-             $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
900
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
901
-
902
-        }
903
-
904
-        return $feedback_saved;
905
-
906
-    } // end save_user_answers_feedback
907
-
908
-     /**
909
-      * Get the user's answers feedback.
910
-      *
911
-      * This function returns the feedback submitted by the teacher/admin
912
-      * during grading. Grading occurs manually or automatically.
913
-      *
914
-      * @since 1.7.5
915
-      * @access public
916
-      *
917
-      * @param int $lesson_id
918
-      * @param int $user_id
919
-      *
920
-      * @return false | array $answers_feedback{
921
-      *  $type int $question_id
922
-      *  $type string $question_feedback
923
-      * }
924
-      */
925
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
-
927
-         $answers_feedback = array();
928
-
929
-         // get the user_id if none was passed in use the current logged in user
930
-         if( ! intval( $user_id ) > 0 ) {
931
-             $user_id = get_current_user_id();
932
-         }
933
-
934
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
935
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
936
-             return false;
937
-         }
938
-
939
-         // first check the transient to save a few split seconds
940
-         $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
941
-         $encoded_feedback = get_transient( $transient_key );
942
-
943
-         // get the data if nothing was stored in the transient
944
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
-
946
-             $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
-
948
-             //set the transient with the new valid data for faster retrieval in future
949
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
-
951
-         } // end if transient check
952
-
953
-         // if there is no data for this user
954
-         if( ! is_array( $encoded_feedback ) ){
955
-             return false;
956
-         }
957
-
958
-         foreach( $encoded_feedback as $question_id => $feedback ){
958
+		 foreach( $encoded_feedback as $question_id => $feedback ){
959 959
 
960
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
960
+			 $answers_feedback[ $question_id ] = base64_decode( $feedback );
961 961
 
962
-         }
962
+		 }
963 963
 
964
-         return $answers_feedback;
964
+		 return $answers_feedback;
965 965
 
966
-     } // end get_user_answers_feedback
966
+	 } // end get_user_answers_feedback
967 967
 
968
-     /**
969
-      * Get the user's answer feedback for a specific question.
970
-      *
971
-      * This function gives you a single answer note/feedback string
972
-      * for the user on the given question.
973
-      *
974
-      * @since 1.7.5
975
-      * @access public
976
-      *
977
-      * @param int $lesson_id
978
-      * @param int $question_id
979
-      * @param int $user_id
980
-      *
981
-      * @return string $feedback or bool if false
982
-      */
983
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
968
+	 /**
969
+	  * Get the user's answer feedback for a specific question.
970
+	  *
971
+	  * This function gives you a single answer note/feedback string
972
+	  * for the user on the given question.
973
+	  *
974
+	  * @since 1.7.5
975
+	  * @access public
976
+	  *
977
+	  * @param int $lesson_id
978
+	  * @param int $question_id
979
+	  * @param int $user_id
980
+	  *
981
+	  * @return string $feedback or bool if false
982
+	  */
983
+	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
984 984
 
985
-         $feedback = false;
985
+		 $feedback = false;
986 986
 
987
-         // parameter validation
988
-         if( empty( $lesson_id ) || empty( $question_id )
989
-             || ! ( intval( $lesson_id  ) > 0 )
990
-             || ! ( intval( $question_id  ) > 0 )
991
-             || 'lesson' != get_post_type( $lesson_id )
992
-             || 'question' != get_post_type( $question_id )) {
987
+		 // parameter validation
988
+		 if( empty( $lesson_id ) || empty( $question_id )
989
+			 || ! ( intval( $lesson_id  ) > 0 )
990
+			 || ! ( intval( $question_id  ) > 0 )
991
+			 || 'lesson' != get_post_type( $lesson_id )
992
+			 || 'question' != get_post_type( $question_id )) {
993 993
 
994
-             return false;
995
-         }
994
+			 return false;
995
+		 }
996 996
 
997
-         // get all the feedback for the user on the given lesson
998
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
997
+		 // get all the feedback for the user on the given lesson
998
+		 $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
999 999
 
1000
-         if( !$all_feedback || empty( $all_feedback )
1001
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1000
+		 if( !$all_feedback || empty( $all_feedback )
1001
+			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1002 1002
 
1003
-             //fallback to data pre 1.7.4
1003
+			 //fallback to data pre 1.7.4
1004 1004
 
1005
-             // setup the sensei data query
1006
-             $args = array(
1007
-                 'post_id' => $question_id,
1008
-                 'user_id' => $user_id,
1009
-                 'type'    => 'sensei_user_answer'
1010
-             );
1011
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1005
+			 // setup the sensei data query
1006
+			 $args = array(
1007
+				 'post_id' => $question_id,
1008
+				 'user_id' => $user_id,
1009
+				 'type'    => 'sensei_user_answer'
1010
+			 );
1011
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1012 1012
 
1013
-             // set the default to false and return that if no old data is available.
1014
-             if( isset( $question_activity->comment_ID ) ){
1015
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1016
-             }
1013
+			 // set the default to false and return that if no old data is available.
1014
+			 if( isset( $question_activity->comment_ID ) ){
1015
+				 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1016
+			 }
1017 1017
 
1018
-             // finally use the default question feedback
1019
-             if( empty( $feedback ) ){
1020
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1021
-             }
1018
+			 // finally use the default question feedback
1019
+			 if( empty( $feedback ) ){
1020
+				 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1021
+			 }
1022 1022
 
1023
-             return $feedback;
1023
+			 return $feedback;
1024 1024
 
1025
-         }
1025
+		 }
1026 1026
 
1027
-         return $all_feedback[ $question_id ];
1027
+		 return $all_feedback[ $question_id ];
1028 1028
 
1029
-     } // end get_user_question_feedback
1029
+	 } // end get_user_question_feedback
1030 1030
 
1031
-     /**
1032
-      * Check if a quiz has no questions, and redirect back to lesson.
1033
-      *
1034
-      * Though a quiz is created for each lesson, it should not be visible
1035
-      * unless it has questions.
1036
-      *
1037
-      * @since 1.9.0
1038
-      * @access public
1039
-      * @param none
1040
-      * @return void
1041
-      */
1031
+	 /**
1032
+	  * Check if a quiz has no questions, and redirect back to lesson.
1033
+	  *
1034
+	  * Though a quiz is created for each lesson, it should not be visible
1035
+	  * unless it has questions.
1036
+	  *
1037
+	  * @since 1.9.0
1038
+	  * @access public
1039
+	  * @param none
1040
+	  * @return void
1041
+	  */
1042 1042
 
1043
-     public function quiz_has_no_questions() {
1043
+	 public function quiz_has_no_questions() {
1044 1044
 
1045
-         if( ! is_singular( 'quiz' ) )  {
1046
-             return;
1047
-         }
1045
+		 if( ! is_singular( 'quiz' ) )  {
1046
+			 return;
1047
+		 }
1048 1048
 
1049
-         global $post;
1049
+		 global $post;
1050 1050
 
1051
-         $lesson_id = $this->get_lesson_id($post->ID);
1051
+		 $lesson_id = $this->get_lesson_id($post->ID);
1052 1052
 
1053
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1053
+		 $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1054 1054
 
1055
-         $lesson = get_post($lesson_id);
1055
+		 $lesson = get_post($lesson_id);
1056 1056
 
1057
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1057
+		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1058 1058
 
1059
-             wp_redirect(get_permalink($lesson->ID), 301);
1060
-             exit;
1059
+			 wp_redirect(get_permalink($lesson->ID), 301);
1060
+			 exit;
1061 1061
 
1062
-         }
1062
+		 }
1063 1063
 
1064
-     } // end quiz_has_no_questions
1064
+	 } // end quiz_has_no_questions
1065 1065
 
1066 1066
 /**
1067
-  * Deprecate the sensei_single_main_content on the single-quiz template.
1068
-  *
1069
-  * @deprecated since 1.9.0
1070
-  */
1067
+ * Deprecate the sensei_single_main_content on the single-quiz template.
1068
+ *
1069
+ * @deprecated since 1.9.0
1070
+ */
1071 1071
  public static function deprecate_quiz_sensei_single_main_content_hook(){
1072 1072
 
1073
-     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1073
+	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1074 1074
 
1075 1075
  }
1076
-    /*
1076
+	/*
1077 1077
      * Deprecate the sensei_quiz_single_title on the single-quiz template.
1078 1078
      *
1079 1079
      * @deprecated since 1.9.0
1080 1080
      */
1081
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1081
+	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1082 1082
 
1083
-         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1083
+		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1084 1084
 
1085
-     }
1085
+	 }
1086 1086
 
1087
-     /**
1088
-      * Filter the single title and add the Quiz to it.
1089
-      *
1090
-      * @param string $title
1091
-      * @param int $id title post id
1092
-      * @return string $quiz_title
1093
-      */
1094
-     public static function single_quiz_title( $title, $post_id ){
1087
+	 /**
1088
+	  * Filter the single title and add the Quiz to it.
1089
+	  *
1090
+	  * @param string $title
1091
+	  * @param int $id title post id
1092
+	  * @return string $quiz_title
1093
+	  */
1094
+	 public static function single_quiz_title( $title, $post_id ){
1095 1095
 
1096
-         if( 'quiz' == get_post_type( $post_id ) ){
1096
+		 if( 'quiz' == get_post_type( $post_id ) ){
1097 1097
 
1098
-             $title_with_no_quizzes = $title;
1098
+			 $title_with_no_quizzes = $title;
1099 1099
 
1100
-             // if the title has quiz, remove it: legacy titles have the word quiz stored.
1101
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1100
+			 // if the title has quiz, remove it: legacy titles have the word quiz stored.
1101
+			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1102 1102
 
1103
-                 // remove all possible appearances of quiz
1104
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1105
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1106
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1103
+				 // remove all possible appearances of quiz
1104
+				 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1105
+				 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1106
+				 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1107 1107
 
1108
-             }
1108
+			 }
1109 1109
 
1110
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1111
-         }
1110
+			 $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1111
+		 }
1112 1112
 
1113
-         /**
1114
-          * hook document in class-woothemes-sensei-message.php
1115
-          */
1116
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1113
+		 /**
1114
+		  * hook document in class-woothemes-sensei-message.php
1115
+		  */
1116
+		 return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1117 1117
 
1118
-     }
1118
+	 }
1119 1119
 
1120
-     /**
1121
-      * Initialize the quiz question loop on the single quiz template
1122
-      *
1123
-      * The function will create a global quiz loop varialbe.
1124
-      *
1125
-      * @since 1.9.0
1126
-      *
1127
-      */
1128
-     public static function start_quiz_questions_loop(){
1120
+	 /**
1121
+	  * Initialize the quiz question loop on the single quiz template
1122
+	  *
1123
+	  * The function will create a global quiz loop varialbe.
1124
+	  *
1125
+	  * @since 1.9.0
1126
+	  *
1127
+	  */
1128
+	 public static function start_quiz_questions_loop(){
1129 1129
 
1130
-         global $sensei_question_loop;
1130
+		 global $sensei_question_loop;
1131 1131
 
1132
-         //intialize the questions loop object
1133
-         $sensei_question_loop['current'] = -1;
1134
-         $sensei_question_loop['total']   =  0;
1135
-         $sensei_question_loop['questions'] = array();
1132
+		 //intialize the questions loop object
1133
+		 $sensei_question_loop['current'] = -1;
1134
+		 $sensei_question_loop['total']   =  0;
1135
+		 $sensei_question_loop['questions'] = array();
1136 1136
 
1137 1137
 
1138
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1138
+		 $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1139 1139
 
1140
-         if( count( $questions  ) > 0  ){
1140
+		 if( count( $questions  ) > 0  ){
1141 1141
 
1142
-             $sensei_question_loop['total']   =  count( $questions );
1143
-             $sensei_question_loop['questions'] = $questions;
1144
-             $sensei_question_loop['quiz_id'] = get_the_ID();
1142
+			 $sensei_question_loop['total']   =  count( $questions );
1143
+			 $sensei_question_loop['questions'] = $questions;
1144
+			 $sensei_question_loop['quiz_id'] = get_the_ID();
1145 1145
 
1146
-         }
1146
+		 }
1147 1147
 
1148
-     }// static function
1148
+	 }// static function
1149 1149
 
1150
-     /**
1151
-      * Initialize the quiz question loop on the single quiz template
1152
-      *
1153
-      * The function will create a global quiz loop varialbe.
1154
-      *
1155
-      * @since 1.9.0
1156
-      *
1157
-      */
1158
-     public static function stop_quiz_questions_loop(){
1150
+	 /**
1151
+	  * Initialize the quiz question loop on the single quiz template
1152
+	  *
1153
+	  * The function will create a global quiz loop varialbe.
1154
+	  *
1155
+	  * @since 1.9.0
1156
+	  *
1157
+	  */
1158
+	 public static function stop_quiz_questions_loop(){
1159 1159
 
1160
-         $sensei_question_loop['total']   =  0;
1161
-         $sensei_question_loop['questions'] = array();
1162
-         $sensei_question_loop['quiz_id'] = '';
1160
+		 $sensei_question_loop['total']   =  0;
1161
+		 $sensei_question_loop['questions'] = array();
1162
+		 $sensei_question_loop['quiz_id'] = '';
1163 1163
 
1164
-     }
1164
+	 }
1165 1165
 
1166
-     /**
1167
-      * Output the title for the single quiz page
1168
-      *
1169
-      * @since 1.9.0
1170
-      */
1171
-     public static function the_title(){
1172
-         ?>
1166
+	 /**
1167
+	  * Output the title for the single quiz page
1168
+	  *
1169
+	  * @since 1.9.0
1170
+	  */
1171
+	 public static function the_title(){
1172
+		 ?>
1173 1173
          <header>
1174 1174
 
1175 1175
              <h1>
1176 1176
 
1177 1177
                  <?php
1178
-                 /**
1179
-                  * Filter documented in class-sensei-messages.php the_title
1180
-                  */
1181
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1182
-                 ?>
1178
+				 /**
1179
+				  * Filter documented in class-sensei-messages.php the_title
1180
+				  */
1181
+				 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1182
+				 ?>
1183 1183
 
1184 1184
              </h1>
1185 1185
 
1186 1186
          </header>
1187 1187
 
1188 1188
          <?php
1189
-     }//the_title
1189
+	 }//the_title
1190 1190
 
1191
-     /**
1192
-      * Output the sensei quiz status message.
1193
-      *
1194
-      * @param $quiz_id
1195
-      */
1196
-    public static function  the_user_status_message( $quiz_id ){
1191
+	 /**
1192
+	  * Output the sensei quiz status message.
1193
+	  *
1194
+	  * @param $quiz_id
1195
+	  */
1196
+	public static function  the_user_status_message( $quiz_id ){
1197 1197
 
1198
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1199
-        $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1200
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1198
+		$lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1199
+		$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1200
+		echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1201 1201
 
1202
-    }
1202
+	}
1203 1203
 
1204
-     /**
1205
-      * This functions runs the old sensei_quiz_action_buttons action
1206
-      * for backwards compatiblity sake.
1207
-      *
1208
-      * @since 1.9.0
1209
-      * @deprecated
1210
-      */
1211
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1204
+	 /**
1205
+	  * This functions runs the old sensei_quiz_action_buttons action
1206
+	  * for backwards compatiblity sake.
1207
+	  *
1208
+	  * @since 1.9.0
1209
+	  * @deprecated
1210
+	  */
1211
+	 public static function deprecate_sensei_quiz_action_buttons_hook(){
1212 1212
 
1213
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1213
+		 sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1214 1214
 
1215
-     }
1215
+	 }
1216 1216
 
1217
-     /**
1218
-      * The quiz action buttons needed to ouput quiz
1219
-      * action such as reset complete and save.
1220
-      *
1221
-      * @since 1.3.0
1222
-      */
1223
-     public static function action_buttons() {
1217
+	 /**
1218
+	  * The quiz action buttons needed to ouput quiz
1219
+	  * action such as reset complete and save.
1220
+	  *
1221
+	  * @since 1.3.0
1222
+	  */
1223
+	 public static function action_buttons() {
1224 1224
 
1225
-         global $post, $current_user;
1225
+		 global $post, $current_user;
1226 1226
 
1227
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1228
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1229
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1230
-         $show_actions = true;
1231
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1227
+		 $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1228
+		 $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1229
+		 $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1230
+		 $show_actions = true;
1231
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1232 1232
 
1233
-         //setup quiz grade
1234
-         $user_quiz_grade = '';
1235
-         if( ! empty( $user_lesson_status  ) ){
1236
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
-         }
1233
+		 //setup quiz grade
1234
+		 $user_quiz_grade = '';
1235
+		 if( ! empty( $user_lesson_status  ) ){
1236
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
+		 }
1238 1238
 
1239 1239
 
1240
-         if( intval( $lesson_prerequisite ) > 0 ) {
1240
+		 if( intval( $lesson_prerequisite ) > 0 ) {
1241 1241
 
1242
-             // If the user hasn't completed the prereq then hide the current actions
1243
-             $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1242
+			 // If the user hasn't completed the prereq then hide the current actions
1243
+			 $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1244 1244
 
1245
-         }
1246
-         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1245
+		 }
1246
+		 if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1247 1247
 
1248
-             // Get Reset Settings
1249
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1248
+			 // Get Reset Settings
1249
+			 $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1250 1250
 
1251 1251
              <!-- Action Nonce's -->
1252 1252
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
@@ -1273,55 +1273,55 @@  discard block
 block discarded – undo
1273 1273
 
1274 1274
          <?php }
1275 1275
 
1276
-     } // End sensei_quiz_action_buttons()
1277
-
1278
-     /**
1279
-      * Fetch the quiz grade
1280
-      *
1281
-      * @since 1.9.0
1282
-      *
1283
-      * @param int $lesson_id
1284
-      * @param int $user_id
1285
-      *
1286
-      * @return double $user_quiz_grade
1287
-      */
1288
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1289
-
1290
-         // get the quiz grade
1291
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1292
-         $user_quiz_grade = 0;
1293
-         if( isset( $user_lesson_status->comment_ID ) ) {
1294
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
-         }
1296
-
1297
-         return (double) $user_quiz_grade;
1298
-
1299
-     }
1300
-
1301
-     /**
1302
-      * Check the quiz reset property for a given lesson's quiz.
1303
-      *
1304
-      * The data is stored on the quiz but going forward the quiz post
1305
-      * type will be retired, hence the lesson_id is a require parameter.
1306
-      *
1307
-      * @since 1.9.0
1308
-      *
1309
-      * @param int $lesson_id
1310
-      * @return bool
1311
-      */
1312
-     public static function is_reset_allowed( $lesson_id ){
1313
-
1314
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1315
-
1316
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1317
-         //backwards compatibility
1318
-         if( 'on' == $reset_allowed ) {
1319
-             $reset_allowed = 1;
1320
-         }
1321
-
1322
-         return (bool) $reset_allowed;
1323
-
1324
-     }
1276
+	 } // End sensei_quiz_action_buttons()
1277
+
1278
+	 /**
1279
+	  * Fetch the quiz grade
1280
+	  *
1281
+	  * @since 1.9.0
1282
+	  *
1283
+	  * @param int $lesson_id
1284
+	  * @param int $user_id
1285
+	  *
1286
+	  * @return double $user_quiz_grade
1287
+	  */
1288
+	 public static function get_user_quiz_grade( $lesson_id, $user_id ){
1289
+
1290
+		 // get the quiz grade
1291
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1292
+		 $user_quiz_grade = 0;
1293
+		 if( isset( $user_lesson_status->comment_ID ) ) {
1294
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
+		 }
1296
+
1297
+		 return (double) $user_quiz_grade;
1298
+
1299
+	 }
1300
+
1301
+	 /**
1302
+	  * Check the quiz reset property for a given lesson's quiz.
1303
+	  *
1304
+	  * The data is stored on the quiz but going forward the quiz post
1305
+	  * type will be retired, hence the lesson_id is a require parameter.
1306
+	  *
1307
+	  * @since 1.9.0
1308
+	  *
1309
+	  * @param int $lesson_id
1310
+	  * @return bool
1311
+	  */
1312
+	 public static function is_reset_allowed( $lesson_id ){
1313
+
1314
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1315
+
1316
+		 $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1317
+		 //backwards compatibility
1318
+		 if( 'on' == $reset_allowed ) {
1319
+			 $reset_allowed = 1;
1320
+		 }
1321
+
1322
+		 return (bool) $reset_allowed;
1323
+
1324
+	 }
1325 1325
 
1326 1326
  } // End Class WooThemes_Sensei_Quiz
1327 1327
 
Please login to merge, or discard this patch.
includes/class-sensei-learners-main.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -205,13 +205,13 @@  discard block
 block discarded – undo
205 205
 
206 206
 	/**
207 207
 	 * Generates content for a single row of the table in the user management
208
-     * screen.
209
-     *
208
+	 * screen.
209
+	 *
210 210
 	 * @since  1.7.0
211
-     *
211
+	 *
212 212
 	 * @param object $item The current item
213
-     *
214
-     * @return void
213
+	 *
214
+	 * @return void
215 215
 	 */
216 216
 	protected function get_row_data( $item ) {
217 217
 		global $wp_version;
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 		switch ( $this->view ) {
220 220
 			case 'learners' :
221 221
 
222
-                // in this case the item passed in is actually the users activity on course of lesson
223
-                $user_activity = $item;
222
+				// in this case the item passed in is actually the users activity on course of lesson
223
+				$user_activity = $item;
224 224
 				$post_id = false;
225 225
 
226 226
 				if( $this->lesson_id ) {
@@ -239,30 +239,30 @@  discard block
 block discarded – undo
239 239
 
240 240
 				if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) {
241 241
 
242
-                    $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
242
+					$status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
243 243
 
244 244
 				} else {
245 245
 
246
-                    $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
246
+					$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
247 247
 
248 248
 				}
249 249
 
250
-                $title = Sensei_Learner::get_full_name( $user_activity->user_id );
250
+				$title = Sensei_Learner::get_full_name( $user_activity->user_id );
251 251
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
252 252
 
253
-                /**
254
-                 * sensei_learners_main_column_data filter
255
-                 *
256
-                 * This filter runs on the learner management screen for a specific course.
257
-                 * It provides the learner row column details.
258
-                 *
259
-                 * @param array $columns{
260
-                 *   type string $title
261
-                 *   type string $date_started
262
-                 *   type string $course_status (completed, started etc)
263
-                 *   type html $action_buttons
264
-                 * }
265
-                 */
253
+				/**
254
+				 * sensei_learners_main_column_data filter
255
+				 *
256
+				 * This filter runs on the learner management screen for a specific course.
257
+				 * It provides the learner row column details.
258
+				 *
259
+				 * @param array $columns{
260
+				 *   type string $title
261
+				 *   type string $date_started
262
+				 *   type string $course_status (completed, started etc)
263
+				 *   type html $action_buttons
264
+				 * }
265
+				 */
266 266
 				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
267 267
 						'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>',
268 268
 						'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true),
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 
293 293
 			case 'courses' :
294 294
 			default:
295
-                $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
295
+				$course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
296 296
 				$title = get_the_title( $item );
297 297
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
298 298
 
Please login to merge, or discard this patch.
includes/class-sensei-grading.php 1 patch
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
 	/**
21 21
 	 * Constructor
22 22
 	 * @since  1.3.0
23
-     *
24
-     * @param $file
23
+	 *
24
+	 * @param $file
25 25
 	 */
26 26
 	public function __construct ( $file ) {
27 27
 		$this->name = __( 'Grading', 'woothemes-sensei' );
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	/**
231 231
 	 * Outputs Grading general headers
232 232
 	 * @since  1.3.0
233
-     * @param array $args
233
+	 * @param array $args
234 234
 	 * @return void
235 235
 	 */
236 236
 	public function grading_headers( $args = array( 'nav' => 'default' ) ) {
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 		}
283 283
 		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
284 284
 
285
-            $user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
285
+			$user_name = Sensei_Learner::get_full_name( $_GET['user_id'] );
286 286
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
287 287
 
288 288
 		} // End If Statement
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		}
317 317
 		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
318 318
 
319
-            $user_name = Sensei_Learner::get_full_name( $_GET['user'] );
319
+			$user_name = Sensei_Learner::get_full_name( $_GET['user'] );
320 320
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
321 321
 
322 322
 		} // End If Statement
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	public function count_statuses( $args = array() ) {
366 366
 		global  $wpdb;
367 367
 
368
-        /**
369
-         * Filter fires inside Sensei_Grading::count_statuses
370
-         *
371
-         * Alter the the post_in array to determine which posts the
372
-         * comment query should be limited to.
373
-         * @since 1.8.0
374
-         * @param array $args
375
-         */
376
-        $args = apply_filters( 'sensei_count_statuses_args', $args );
368
+		/**
369
+		 * Filter fires inside Sensei_Grading::count_statuses
370
+		 *
371
+		 * Alter the the post_in array to determine which posts the
372
+		 * comment query should be limited to.
373
+		 * @since 1.8.0
374
+		 * @param array $args
375
+		 */
376
+		$args = apply_filters( 'sensei_count_statuses_args', $args );
377 377
 
378 378
 		if ( 'course' == $args['type'] ) {
379 379
 			$type = 'sensei_course_status';
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 
386 386
 		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s ";
387 387
 
388
-        // Restrict to specific posts
388
+		// Restrict to specific posts
389 389
 		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
390 390
 			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
391 391
 		}
@@ -520,148 +520,148 @@  discard block
 block discarded – undo
520 520
 		return $html;
521 521
 	} // End lessons_drop_down_html()
522 522
 
523
-    /**
524
-     * The process grading function handles admin grading submissions.
525
-     *
526
-     * This function is hooked on to admin_init. It simply accepts
527
-     * the grades as the Grader selected theme and saves the total grade and
528
-     * individual question grades.
529
-     *
530
-     * @return bool
531
-     */
532
-    public function admin_process_grading_submission() {
523
+	/**
524
+	 * The process grading function handles admin grading submissions.
525
+	 *
526
+	 * This function is hooked on to admin_init. It simply accepts
527
+	 * the grades as the Grader selected theme and saves the total grade and
528
+	 * individual question grades.
529
+	 *
530
+	 * @return bool
531
+	 */
532
+	public function admin_process_grading_submission() {
533 533
 
534
-        // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
-        if( ! isset( $_POST['sensei_manual_grade'] )
536
-            || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
-            || ! isset( $_GET['quiz_id'] )
538
-            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
534
+		// NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
535
+		if( ! isset( $_POST['sensei_manual_grade'] )
536
+			|| ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
537
+			|| ! isset( $_GET['quiz_id'] )
538
+			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
539 539
 
540
-            return false; //exit and do not grade
540
+			return false; //exit and do not grade
541 541
 
542
-        }
542
+		}
543 543
 
544
-        $quiz_id = $_GET['quiz_id'];
545
-        $user_id = $_GET['user'];
544
+		$quiz_id = $_GET['quiz_id'];
545
+		$user_id = $_GET['user'];
546 546
 
547 547
 
548
-        $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
-        $quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
-        $quiz_grade = 0;
551
-        $count = 0;
552
-        $quiz_grade_total = $_POST['quiz_grade_total'];
553
-        $all_question_grades = array();
554
-        $all_answers_feedback = array();
548
+		$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
549
+		$quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
+		$quiz_grade = 0;
551
+		$count = 0;
552
+		$quiz_grade_total = $_POST['quiz_grade_total'];
553
+		$all_question_grades = array();
554
+		$all_answers_feedback = array();
555 555
 
556
-        foreach( $questions as $question ) {
556
+		foreach( $questions as $question ) {
557 557
 
558
-            ++$count;
559
-            $question_id = $question->ID;
558
+			++$count;
559
+			$question_id = $question->ID;
560 560
 
561
-            if( isset( $_POST[ 'question_' . $question_id ] ) ) {
561
+			if( isset( $_POST[ 'question_' . $question_id ] ) ) {
562 562
 
563
-                $question_grade = 0;
564
-                if( $_POST[ 'question_' . $question_id ] == 'right' ) {
563
+				$question_grade = 0;
564
+				if( $_POST[ 'question_' . $question_id ] == 'right' ) {
565 565
 
566
-                    $question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
566
+					$question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
567 567
 
568
-                }
568
+				}
569 569
 
570
-                // add data to the array that will, after the loop, be stored on the lesson status
571
-                $all_question_grades[ $question_id ] = $question_grade;
570
+				// add data to the array that will, after the loop, be stored on the lesson status
571
+				$all_question_grades[ $question_id ] = $question_grade;
572 572
 
573
-                // tally up the total quiz grade
574
-                $quiz_grade += $question_grade;
573
+				// tally up the total quiz grade
574
+				$quiz_grade += $question_grade;
575 575
 
576
-            } // endif
576
+			} // endif
577 577
 
578
-            // Question answer feedback / notes
579
-            $question_feedback = '';
580
-            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
578
+			// Question answer feedback / notes
579
+			$question_feedback = '';
580
+			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
581 581
 
582
-                $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
582
+				$question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
583 583
 
584
-            }
585
-            $all_answers_feedback[ $question_id ] = $question_feedback;
584
+			}
585
+			$all_answers_feedback[ $question_id ] = $question_feedback;
586 586
 
587
-        } // end for each $questions
587
+		} // end for each $questions
588 588
 
589
-        //store all question grades on the lesson status
590
-        Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
589
+		//store all question grades on the lesson status
590
+		Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
591 591
 
592
-        //store the feedback from grading
593
-        Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
592
+		//store the feedback from grading
593
+		Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
594 594
 
595
-        // $_POST['all_questions_graded'] is set when all questions have been graded
596
-        // in the class sensei grading user quiz -> display()
597
-        if( $_POST['all_questions_graded'] == 'yes' ) {
595
+		// $_POST['all_questions_graded'] is set when all questions have been graded
596
+		// in the class sensei grading user quiz -> display()
597
+		if( $_POST['all_questions_graded'] == 'yes' ) {
598 598
 
599
-            // set the users total quiz grade
599
+			// set the users total quiz grade
600 600
 			if ( 0 < intval( $quiz_grade_total ) ) {
601
-            $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
601
+			$grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
602 602
 			}
603 603
 			else {
604 604
 				$grade = 0;
605 605
 			}
606
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
-
608
-            // Duplicating what Frontend->sensei_complete_quiz() does
609
-            $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
-            $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
-            $lesson_metadata = array();
612
-            if ( $pass_required ) {
613
-                // Student has reached the pass mark and lesson is complete
614
-                if ( $quiz_passmark <= $grade ) {
615
-                    $lesson_status = 'passed';
616
-                }
617
-                else {
618
-                    $lesson_status = 'failed';
619
-                } // End If Statement
620
-            }
621
-            // Student only has to partake the quiz
622
-            else {
623
-                $lesson_status = 'graded';
624
-            }
625
-            $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
606
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
607
+
608
+			// Duplicating what Frontend->sensei_complete_quiz() does
609
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
610
+			$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
+			$lesson_metadata = array();
612
+			if ( $pass_required ) {
613
+				// Student has reached the pass mark and lesson is complete
614
+				if ( $quiz_passmark <= $grade ) {
615
+					$lesson_status = 'passed';
616
+				}
617
+				else {
618
+					$lesson_status = 'failed';
619
+				} // End If Statement
620
+			}
621
+			// Student only has to partake the quiz
622
+			else {
623
+				$lesson_status = 'graded';
624
+			}
625
+			$lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
626 626
 
627
-            Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
627
+			Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
628 628
 
629
-            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
629
+			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
630 630
 
631
-                /**
632
-                 * Summary.
633
-                 *
634
-                 * Description.
635
-                 *
636
-                 * @since 1.7.0
637
-                 *
638
-                 * @param int  $user_id
639
-                 * @param int $quiz_lesson_id
640
-                 */
641
-                do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
631
+				/**
632
+				 * Summary.
633
+				 *
634
+				 * Description.
635
+				 *
636
+				 * @since 1.7.0
637
+				 *
638
+				 * @param int  $user_id
639
+				 * @param int $quiz_lesson_id
640
+				 */
641
+				do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
642 642
 
643
-            } // end if in_array
643
+			} // end if in_array
644 644
 
645
-        }// end if $_POST['all_que...
645
+		}// end if $_POST['all_que...
646 646
 
647
-        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
647
+		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
648 648
 
649
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
649
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
650 650
 
651
-        } elseif ( isset( $_POST['_wp_http_referer'] ) ) {
651
+		} elseif ( isset( $_POST['_wp_http_referer'] ) ) {
652 652
 
653
-            $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
653
+			$load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
654 654
 
655
-        } else {
655
+		} else {
656 656
 
657
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
657
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
658 658
 
659
-        }
659
+		}
660 660
 
661
-        wp_safe_redirect( esc_url_raw( $load_url ) );
662
-        exit;
661
+		wp_safe_redirect( esc_url_raw( $load_url ) );
662
+		exit;
663 663
 
664
-    } // end admin_process_grading_submission
664
+	} // end admin_process_grading_submission
665 665
 
666 666
 	public function get_redirect_url() {
667 667
 		// Parse POST data
@@ -706,283 +706,283 @@  discard block
 block discarded – undo
706 706
 		} // End If Statement
707 707
 	} // End sensei_grading_notices()
708 708
 
709
-    /**
710
-     * Grade quiz automatically
711
-     *
712
-     * This function grades each question automatically if there all questions are auto gradable. If not
713
-     * the quiz will not be auto gradable.
714
-     *
715
-     * @since 1.7.4
716
-     *
717
-     * @param  integer $quiz_id         ID of quiz
718
-     * @param  array $submitted questions id ans answers {
719
-     *          @type int $question_id
720
-     *          @type mixed $answer
721
-     * }
722
-     * @param  integer $total_questions Total questions in quiz (not used)
723
-     * @param string $quiz_grade_type Optional defaults to auto
724
-     *
725
-     * @return int $quiz_grade total sum of all question grades
726
-     */
727
-    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
-
729
-        if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
-            || $quiz_grade_type != 'auto' ) {
731
-            return false; // exit early
732
-        }
733
-
734
-
735
-        $user_id = get_current_user_id();
736
-        $lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
-        $quiz_autogradable = true;
738
-
739
-        /**
740
-         * Filter the types of question types that can be automatically graded.
741
-         *
742
-         * This filter fires inside the auto grade quiz function and provides you with the default list.
743
-         *
744
-         * @param array {
745
-         *      'multiple-choice',
746
-         *      'boolean',
747
-         *      'gap-fill'.
748
-         * }
749
-         */
750
-        $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
-
752
-        $grade_total = 0;
753
-        $all_question_grades = array();
754
-        foreach( $submitted as $question_id => $answer ) {
755
-
756
-            // check if the question is autogradable, either by type, or because the grade is 0
757
-            $question_type = Sensei()->question->get_question_type( $question_id );
709
+	/**
710
+	 * Grade quiz automatically
711
+	 *
712
+	 * This function grades each question automatically if there all questions are auto gradable. If not
713
+	 * the quiz will not be auto gradable.
714
+	 *
715
+	 * @since 1.7.4
716
+	 *
717
+	 * @param  integer $quiz_id         ID of quiz
718
+	 * @param  array $submitted questions id ans answers {
719
+	 *          @type int $question_id
720
+	 *          @type mixed $answer
721
+	 * }
722
+	 * @param  integer $total_questions Total questions in quiz (not used)
723
+	 * @param string $quiz_grade_type Optional defaults to auto
724
+	 *
725
+	 * @return int $quiz_grade total sum of all question grades
726
+	 */
727
+	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
728
+
729
+		if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
730
+			|| $quiz_grade_type != 'auto' ) {
731
+			return false; // exit early
732
+		}
733
+
734
+
735
+		$user_id = get_current_user_id();
736
+		$lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
737
+		$quiz_autogradable = true;
738
+
739
+		/**
740
+		 * Filter the types of question types that can be automatically graded.
741
+		 *
742
+		 * This filter fires inside the auto grade quiz function and provides you with the default list.
743
+		 *
744
+		 * @param array {
745
+		 *      'multiple-choice',
746
+		 *      'boolean',
747
+		 *      'gap-fill'.
748
+		 * }
749
+		 */
750
+		$autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
751
+
752
+		$grade_total = 0;
753
+		$all_question_grades = array();
754
+		foreach( $submitted as $question_id => $answer ) {
755
+
756
+			// check if the question is autogradable, either by type, or because the grade is 0
757
+			$question_type = Sensei()->question->get_question_type( $question_id );
758 758
 			$achievable_grade = Sensei()->question->get_question_grade( $question_id );
759 759
 			// Question has a zero grade, so skip grading
760 760
 			if ( 0 == $achievable_grade ) {
761 761
 				$all_question_grades[ $question_id ] = $achievable_grade;
762 762
 			}
763
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
-                // Get user question grade
765
-                $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
-                $all_question_grades[ $question_id ] = $question_grade;
767
-                $grade_total += $question_grade;
763
+			elseif ( in_array( $question_type, $autogradable_question_types ) ) {
764
+				// Get user question grade
765
+				$question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
766
+				$all_question_grades[ $question_id ] = $question_grade;
767
+				$grade_total += $question_grade;
768 768
 
769
-            } else {
769
+			} else {
770 770
 
771
-                // There is a question that cannot be autograded
772
-                $quiz_autogradable = false;
771
+				// There is a question that cannot be autograded
772
+				$quiz_autogradable = false;
773 773
 
774
-            } // end if in_array( $question_type...
774
+			} // end if in_array( $question_type...
775 775
 
776
-        }// end for each question
776
+		}// end for each question
777 777
 
778
-        // Only if the whole quiz was autogradable do we set a grade
779
-        if ( $quiz_autogradable ) {
778
+		// Only if the whole quiz was autogradable do we set a grade
779
+		if ( $quiz_autogradable ) {
780 780
 
781
-            $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
781
+			$quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
782 782
 			// Check for zero total from grades
783 783
 			if ( 0 < $quiz_total ) {
784
-            $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
784
+			$grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
785 785
 			}
786 786
 			else {
787 787
 				$grade = 0;
788 788
 			}
789
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
789
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
790 790
 
791
-        } else {
791
+		} else {
792 792
 
793
-            $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
793
+			$grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
794 794
 
795
-        }
796
-
797
-        // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
-        // when doing manual grading.
799
-        Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
795
+		}
800 796
 
801
-        return $grade;
797
+		// store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
798
+		// when doing manual grading.
799
+		Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
802 800
 
803
-    } // End grade_quiz_auto()
801
+		return $grade;
804 802
 
805
-    /**
806
-     * Grade question automatically
807
-     *
808
-     * This function checks the question typ and then grades it accordingly.
809
-     *
810
-     * @since 1.7.4
811
-     *
812
-     * @param integer $question_id
813
-     * @param string $question_type of the standard Sensei question types
814
-     * @param string $answer
815
-     * @param int $user_id
816
-     *
817
-     * @return int $question_grade
818
-     */
819
-    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
820
-
821
-        if( intval( $user_id ) == 0 ) {
822
-
823
-            $user_id = get_current_user_id();
824
-
825
-        }
826
-
827
-        if( ! ( intval( $question_id ) > 0 ) ) {
828
-
829
-            return false;
830
-
831
-        }
832
-
833
-
834
-        Sensei()->question->get_question_type( $question_id );
835
-
836
-        /**
837
-         * Applying a grade before the auto grading takes place.
838
-         *
839
-         * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
-         * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
-         * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
-         *
843
-         * @param int $question_grade default false
844
-         * @param int $question_id
845
-         * @param string $question_type one of the Sensei question type.
846
-         * @param string $answer user supplied question answer
847
-         */
848
-        $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
803
+	} // End grade_quiz_auto()
849 804
 
850
-        if ( false !== $question_grade ) {
805
+	/**
806
+	 * Grade question automatically
807
+	 *
808
+	 * This function checks the question typ and then grades it accordingly.
809
+	 *
810
+	 * @since 1.7.4
811
+	 *
812
+	 * @param integer $question_id
813
+	 * @param string $question_type of the standard Sensei question types
814
+	 * @param string $answer
815
+	 * @param int $user_id
816
+	 *
817
+	 * @return int $question_grade
818
+	 */
819
+	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
820
+
821
+		if( intval( $user_id ) == 0 ) {
822
+
823
+			$user_id = get_current_user_id();
824
+
825
+		}
826
+
827
+		if( ! ( intval( $question_id ) > 0 ) ) {
828
+
829
+			return false;
830
+
831
+		}
832
+
833
+
834
+		Sensei()->question->get_question_type( $question_id );
835
+
836
+		/**
837
+		 * Applying a grade before the auto grading takes place.
838
+		 *
839
+		 * This filter is applied just before the question is auto graded. It fires in the context of a single question
840
+		 * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
841
+		 * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
842
+		 *
843
+		 * @param int $question_grade default false
844
+		 * @param int $question_id
845
+		 * @param string $question_type one of the Sensei question type.
846
+		 * @param string $answer user supplied question answer
847
+		 */
848
+		$question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
851 849
 
852
-            return $question_grade;
850
+		if ( false !== $question_grade ) {
853 851
 
854
-        }
852
+			return $question_grade;
855 853
 
856
-        // auto grading core
857
-        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
854
+		}
858 855
 
859
-            $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
856
+		// auto grading core
857
+		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
860 858
 
861
-            if( 0 == get_magic_quotes_gpc() ) {
862
-                $answer = wp_unslash( $answer );
863
-            }
864
-            $answer = (array) $answer;
865
-            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
-                // Loop through all answers ensure none are 'missing'
867
-                $all_correct = true;
868
-                foreach ( $answer as $check_answer ) {
869
-                    if ( !in_array( $check_answer, $right_answer ) ) {
870
-                        $all_correct = false;
871
-                    }
872
-                }
873
-                // If all correct then grade
874
-                if ( $all_correct ) {
875
-                    $question_grade = Sensei()->question->get_question_grade( $question_id );
876
-                }
877
-            }
859
+			$right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
878 860
 
879
-        } elseif( 'gap-fill' == $question_type ){
861
+			if( 0 == get_magic_quotes_gpc() ) {
862
+				$answer = wp_unslash( $answer );
863
+			}
864
+			$answer = (array) $answer;
865
+			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
866
+				// Loop through all answers ensure none are 'missing'
867
+				$all_correct = true;
868
+				foreach ( $answer as $check_answer ) {
869
+					if ( !in_array( $check_answer, $right_answer ) ) {
870
+						$all_correct = false;
871
+					}
872
+				}
873
+				// If all correct then grade
874
+				if ( $all_correct ) {
875
+					$question_grade = Sensei()->question->get_question_grade( $question_id );
876
+				}
877
+			}
880 878
 
881
-            $question_grade = self::grade_gap_fill_question( $question_id ,$answer );
879
+		} elseif( 'gap-fill' == $question_type ){
882 880
 
883
-        } else{
881
+			$question_grade = self::grade_gap_fill_question( $question_id ,$answer );
884 882
 
885
-            /**
886
-             * Grading questions that are not auto gradable.
887
-             *
888
-             * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
-             * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
-             *
891
-             * @param int $question_grade default zero
892
-             * @param int $question_id
893
-             * @param string $question_type one of the Sensei question type.
894
-             * @param string $answer user supplied question answer
895
-             */
896
-            $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
883
+		} else{
897 884
 
898
-        } // end if $question_type
885
+			/**
886
+			 * Grading questions that are not auto gradable.
887
+			 *
888
+			 * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
889
+			 * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
890
+			 *
891
+			 * @param int $question_grade default zero
892
+			 * @param int $question_id
893
+			 * @param string $question_type one of the Sensei question type.
894
+			 * @param string $answer user supplied question answer
895
+			 */
896
+			$question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
899 897
 
900
-        return $question_grade;
901
-    } // end grade_question_auto
898
+		} // end if $question_type
902 899
 
903
-    /**
904
-     * Grading logic specifically for the gap fill questions
905
-     *
906
-     * @since 1.9.0
907
-     * @param $question_id
908
-     * @param $user_answer
909
-     *
910
-     * @return bool | int false or the grade given to the user answer
911
-     */
912
-    public static function grade_gap_fill_question( $question_id, $user_answer ){
900
+		return $question_grade;
901
+	} // end grade_question_auto
913 902
 
914
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
-        $gapfill_array = explode( '||', $right_answer );
903
+	/**
904
+	 * Grading logic specifically for the gap fill questions
905
+	 *
906
+	 * @since 1.9.0
907
+	 * @param $question_id
908
+	 * @param $user_answer
909
+	 *
910
+	 * @return bool | int false or the grade given to the user answer
911
+	 */
912
+	public static function grade_gap_fill_question( $question_id, $user_answer ){
916 913
 
917
-        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
-            $user_answer = wp_unslash( $user_answer );
919
-        }
914
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
915
+		$gapfill_array = explode( '||', $right_answer );
920 916
 
921
-        /**
922
-         * case sensitive grading filter
923
-         *
924
-         * alter the value simply use this code in your plugin or the themes functions.php
925
-         * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
-         *
927
-         * @param bool $do_case_sensitive_comparison default false.
928
-         *
929
-         * @since 1.9.0
930
-         */
931
-        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
917
+		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
918
+			$user_answer = wp_unslash( $user_answer );
919
+		}
920
+
921
+		/**
922
+		 * case sensitive grading filter
923
+		 *
924
+		 * alter the value simply use this code in your plugin or the themes functions.php
925
+		 * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
926
+		 *
927
+		 * @param bool $do_case_sensitive_comparison default false.
928
+		 *
929
+		 * @since 1.9.0
930
+		 */
931
+		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
932 932
 
933
-        if( $do_case_sensitive_comparison ){
933
+		if( $do_case_sensitive_comparison ){
934 934
 
935
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
-            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
935
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
936
+			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
937 937
 
938
-                return Sensei()->question->get_question_grade( $question_id );
938
+				return Sensei()->question->get_question_grade( $question_id );
939 939
 
940
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
940
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
941 941
 
942
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
942
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
943 943
 
944
-                    return Sensei()->question->get_question_grade($question_id);
944
+					return Sensei()->question->get_question_grade($question_id);
945 945
 
946
-                }else{
946
+				}else{
947 947
 
948
-                    return false;
948
+					return false;
949 949
 
950
-                }
950
+				}
951 951
 
952
-            }else{
952
+			}else{
953 953
 
954
-                return false;
954
+				return false;
955 955
 
956
-            }
956
+			}
957 957
 
958
-        }else{
958
+		}else{
959 959
 
960
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
-            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
960
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
961
+			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
962 962
 
963
-               return Sensei()->question->get_question_grade( $question_id );
963
+			   return Sensei()->question->get_question_grade( $question_id );
964 964
 
965
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
965
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
966 966
 
967
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
967
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
968 968
 
969
-                    return  Sensei()->question->get_question_grade( $question_id );
969
+					return  Sensei()->question->get_question_grade( $question_id );
970 970
 
971
-                }else{
971
+				}else{
972 972
 
973
-                    return false;
973
+					return false;
974 974
 
975
-                }
975
+				}
976 976
 
977
-            }else{
977
+			}else{
978 978
 
979
-                return false;
979
+				return false;
980 980
 
981
-            }
981
+			}
982 982
 
983
-        }
983
+		}
984 984
 
985
-    }
985
+	}
986 986
 
987 987
 } // End Class
988 988
 
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 1 patch
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -12,251 +12,251 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Sensei_Teacher {
14 14
 
15
-    /**
16
-     * $teacher_role
17
-     *
18
-     * Keeps a reference to the teacher role object
19
-     *
20
-     * @access protected
21
-     * @since 1.8.0
22
-     */
23
-    protected $teacher_role;
24
-
25
-    /**
26
-     * $token
27
-     *
28
-     * Keeps a reference to the global sensei token
29
-     *
30
-     * @access protected
31
-     * @since 1.8.0
32
-     */
33
-    public  $token;
34
-
35
-    /**
36
-     * Sensei_Teacher::__constructor
37
-     *
38
-     * Constructor Function
39
-     *
40
-     * @since 1.8.0
41
-     * @access public
42
-     */
43
-    public function __construct ( ) {
44
-
45
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
-
51
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
-
53
-        //filter the quiz submissions
54
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
-
56
-        //grading totals count only those belonging to the teacher
57
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
-
59
-        // show the courses owned by a user on his author archive page
60
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
-
62
-        // notify admin when a teacher creates a course
63
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
-
65
-        // limit the analysis view to only the users taking courses belong to this teacher
66
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
-
68
-        // give teacher access to question post type
69
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
-
71
-        // Teacher column on the courses list on the admin edit screen
72
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
-
75
-        //admin edit messages query limit teacher
76
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
-
78
-        //add filter by teacher on courses list
79
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
-
82
-        // Handle media library restrictions
83
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
-
86
-        // update lesson owner to course teacher when saved
87
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
-
89
-        // If a Teacher logs in, redirect to /wp-admin/
90
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
-
92
-
93
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
-
96
-
97
-    } // end __constructor()
98
-
99
-    /**
100
-     * Sensei_Teacher::create_teacher_role
101
-     *
102
-     * This function checks if the role exist, if not it creates it.
103
-     * for the teacher role
104
-     *
105
-     * @since 1.8.0
106
-     * @access public
107
-     * @return void
108
-     */
109
-    public function create_role ( ) {
110
-
111
-        // check if the role exists
112
-        $this->teacher_role = get_role( 'teacher' );
113
-
114
-        // if the the teacher is not a valid WordPress role create it
115
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
-           // create the role
117
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
-       }
119
-
120
-       // add the capabilities before returning
121
-        $this->add_capabilities();
122
-
123
-    }// end create_teacher_role
124
-
125
-    /**
126
-     * Sensei_Teacher::add_capabilities
127
-     *
128
-     * @since 1.8.0
129
-     * @access protected
130
-     */
131
-    protected function add_capabilities ( ) {
132
-
133
-        // if this is not a valid WP_Role object exit without adding anything
134
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
-            return;
136
-        }
137
-
138
-        /**
139
-         * Sensei teachers capabilities array filter
140
-         *
141
-         * These capabilities will be applied to the teacher role
142
-         * @param array $capabilities
143
-         * keys: (string) $cap_name => (bool) $grant
144
-         */
145
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
-            // General access rules
147
-            'read' => true,
148
-            'manage_sensei_grades' => true,
149
-            'moderate_comments'=> true,
150
-            'upload_files'	=> true,
151
-            'edit_files'	=> true,
152
-
153
-            //Lessons
154
-            'publish_lessons'	 => true,
155
-            'manage_lesson_categories'	 => true,
156
-            'edit_lessons'	 => true,
157
-            'edit_published_lessons'  => true,
158
-            'edit_private_lessons' => true,
159
-            'read_private_lessons' => true,
160
-            'delete_published_lessons' => true,
161
-
162
-            // Courses
163
-            'create_courses' => true,
164
-            'publish_courses'	 => false,
165
-            'manage_course_categories'	 => true,
166
-            'edit_courses'	 => true,
167
-            'edit_published_courses'  => true,
168
-            'edit_private_courses' => true,
169
-            'read_private_courses' => true,
170
-            'delete_published_courses' => true,
171
-
172
-            // Quiz
173
-            'publish_quizzes'	 => true,
174
-            'edit_quizzes'	 => true,
175
-            'edit_published_quizzes'  => true,
176
-            'edit_private_quizzes' => true,
177
-            'read_private_quizzes' => true,
178
-
179
-            // Questions
180
-            'publish_questions'	 => true,
181
-            'edit_questions'	 => true,
182
-            'edit_published_questions'  => true,
183
-            'edit_private_questions' => true,
184
-            'read_private_questions' => true,
185
-
186
-            //messages
187
-            'publish_sensei_messages'	 => true,
188
-            'edit_sensei_messages'	 => true,
189
-            'edit_published_sensei_messages'  => true,
190
-            'edit_private_sensei_messages' => true,
191
-            'read_private_sensei_messages' => true,
192
-
193
-            // Comments -
194
-            // Necessary cap so Teachers can moderate comments
195
-            // on their own lessons. We restrict access to other
196
-            // post types in $this->restrict_posts_menu_page()
197
-
198
-            'edit_posts' => true,
199
-
200
-        ));
201
-
202
-        foreach ( $caps as $cap => $grant ) {
203
-
204
-            // load the capability on to the teacher role
205
-            $this->teacher_role->add_cap($cap, $grant);
206
-
207
-        } // end for each
208
-
209
-    }// end add_cap
210
-
211
-    /**
212
-     * Sensei_Teacher::teacher_meta_box
213
-     *
214
-     * Add the teacher metabox to the course post type edit screen
215
-     *
216
-     * @since 1.8.0
217
-     * @access public
218
-     * @parameter string $post_type
219
-     * @parameter WP_Post $post
220
-     * @return void
221
-     */
222
-    public function add_teacher_meta_boxes ( $post ) {
223
-
224
-        if( !current_user_can('manage_options') ){
225
-            return;
226
-        }
227
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
-            'course',
229
-            'side',
230
-            'core'
231
-        );
232
-
233
-    } // end teacher_meta_box()
234
-
235
-    /**
236
-     * Sensei_Teacher::teacher_meta_box_content
237
-     *
238
-     * Render the teacher meta box markup
239
-     *
240
-     * @since 1.8.0
241
-     * @access public
242
-     * @parameters
243
-     */
244
-    public function teacher_meta_box_content ( $post ) {
245
-
246
-        // get the current author
247
-        $current_author = $post->post_author;
248
-
249
-        //get the users authorised to author courses
250
-        $users = $this->get_teachers_and_authors();
251
-
252
-    ?>
15
+	/**
16
+	 * $teacher_role
17
+	 *
18
+	 * Keeps a reference to the teacher role object
19
+	 *
20
+	 * @access protected
21
+	 * @since 1.8.0
22
+	 */
23
+	protected $teacher_role;
24
+
25
+	/**
26
+	 * $token
27
+	 *
28
+	 * Keeps a reference to the global sensei token
29
+	 *
30
+	 * @access protected
31
+	 * @since 1.8.0
32
+	 */
33
+	public  $token;
34
+
35
+	/**
36
+	 * Sensei_Teacher::__constructor
37
+	 *
38
+	 * Constructor Function
39
+	 *
40
+	 * @since 1.8.0
41
+	 * @access public
42
+	 */
43
+	public function __construct ( ) {
44
+
45
+		add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
+		add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
+		add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
+		add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
+		add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
+
51
+		add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
+
53
+		//filter the quiz submissions
54
+		add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
+
56
+		//grading totals count only those belonging to the teacher
57
+		add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
+
59
+		// show the courses owned by a user on his author archive page
60
+		add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
+
62
+		// notify admin when a teacher creates a course
63
+		add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
+
65
+		// limit the analysis view to only the users taking courses belong to this teacher
66
+		add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
+
68
+		// give teacher access to question post type
69
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
+
71
+		// Teacher column on the courses list on the admin edit screen
72
+		add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
+		add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
+
75
+		//admin edit messages query limit teacher
76
+		add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
+
78
+		//add filter by teacher on courses list
79
+		add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
+		add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
+
82
+		// Handle media library restrictions
83
+		add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
+		add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
+
86
+		// update lesson owner to course teacher when saved
87
+		add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
+
89
+		// If a Teacher logs in, redirect to /wp-admin/
90
+		add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
+
92
+
93
+		add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
+		add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
+
96
+
97
+	} // end __constructor()
98
+
99
+	/**
100
+	 * Sensei_Teacher::create_teacher_role
101
+	 *
102
+	 * This function checks if the role exist, if not it creates it.
103
+	 * for the teacher role
104
+	 *
105
+	 * @since 1.8.0
106
+	 * @access public
107
+	 * @return void
108
+	 */
109
+	public function create_role ( ) {
110
+
111
+		// check if the role exists
112
+		$this->teacher_role = get_role( 'teacher' );
113
+
114
+		// if the the teacher is not a valid WordPress role create it
115
+	   if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
+		   // create the role
117
+		   $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
+	   }
119
+
120
+	   // add the capabilities before returning
121
+		$this->add_capabilities();
122
+
123
+	}// end create_teacher_role
124
+
125
+	/**
126
+	 * Sensei_Teacher::add_capabilities
127
+	 *
128
+	 * @since 1.8.0
129
+	 * @access protected
130
+	 */
131
+	protected function add_capabilities ( ) {
132
+
133
+		// if this is not a valid WP_Role object exit without adding anything
134
+		if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
+			return;
136
+		}
137
+
138
+		/**
139
+		 * Sensei teachers capabilities array filter
140
+		 *
141
+		 * These capabilities will be applied to the teacher role
142
+		 * @param array $capabilities
143
+		 * keys: (string) $cap_name => (bool) $grant
144
+		 */
145
+		$caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
+			// General access rules
147
+			'read' => true,
148
+			'manage_sensei_grades' => true,
149
+			'moderate_comments'=> true,
150
+			'upload_files'	=> true,
151
+			'edit_files'	=> true,
152
+
153
+			//Lessons
154
+			'publish_lessons'	 => true,
155
+			'manage_lesson_categories'	 => true,
156
+			'edit_lessons'	 => true,
157
+			'edit_published_lessons'  => true,
158
+			'edit_private_lessons' => true,
159
+			'read_private_lessons' => true,
160
+			'delete_published_lessons' => true,
161
+
162
+			// Courses
163
+			'create_courses' => true,
164
+			'publish_courses'	 => false,
165
+			'manage_course_categories'	 => true,
166
+			'edit_courses'	 => true,
167
+			'edit_published_courses'  => true,
168
+			'edit_private_courses' => true,
169
+			'read_private_courses' => true,
170
+			'delete_published_courses' => true,
171
+
172
+			// Quiz
173
+			'publish_quizzes'	 => true,
174
+			'edit_quizzes'	 => true,
175
+			'edit_published_quizzes'  => true,
176
+			'edit_private_quizzes' => true,
177
+			'read_private_quizzes' => true,
178
+
179
+			// Questions
180
+			'publish_questions'	 => true,
181
+			'edit_questions'	 => true,
182
+			'edit_published_questions'  => true,
183
+			'edit_private_questions' => true,
184
+			'read_private_questions' => true,
185
+
186
+			//messages
187
+			'publish_sensei_messages'	 => true,
188
+			'edit_sensei_messages'	 => true,
189
+			'edit_published_sensei_messages'  => true,
190
+			'edit_private_sensei_messages' => true,
191
+			'read_private_sensei_messages' => true,
192
+
193
+			// Comments -
194
+			// Necessary cap so Teachers can moderate comments
195
+			// on their own lessons. We restrict access to other
196
+			// post types in $this->restrict_posts_menu_page()
197
+
198
+			'edit_posts' => true,
199
+
200
+		));
201
+
202
+		foreach ( $caps as $cap => $grant ) {
203
+
204
+			// load the capability on to the teacher role
205
+			$this->teacher_role->add_cap($cap, $grant);
206
+
207
+		} // end for each
208
+
209
+	}// end add_cap
210
+
211
+	/**
212
+	 * Sensei_Teacher::teacher_meta_box
213
+	 *
214
+	 * Add the teacher metabox to the course post type edit screen
215
+	 *
216
+	 * @since 1.8.0
217
+	 * @access public
218
+	 * @parameter string $post_type
219
+	 * @parameter WP_Post $post
220
+	 * @return void
221
+	 */
222
+	public function add_teacher_meta_boxes ( $post ) {
223
+
224
+		if( !current_user_can('manage_options') ){
225
+			return;
226
+		}
227
+		add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
+			'course',
229
+			'side',
230
+			'core'
231
+		);
232
+
233
+	} // end teacher_meta_box()
234
+
235
+	/**
236
+	 * Sensei_Teacher::teacher_meta_box_content
237
+	 *
238
+	 * Render the teacher meta box markup
239
+	 *
240
+	 * @since 1.8.0
241
+	 * @access public
242
+	 * @parameters
243
+	 */
244
+	public function teacher_meta_box_content ( $post ) {
245
+
246
+		// get the current author
247
+		$current_author = $post->post_author;
248
+
249
+		//get the users authorised to author courses
250
+		$users = $this->get_teachers_and_authors();
251
+
252
+	?>
253 253
         <select name="sensei-course-teacher-author" class="sensei course teacher">
254 254
 
255 255
             <?php foreach ( $users as $user_id ) { ?>
256 256
 
257 257
                     <?php
258
-                        $user = get_user_by('id', $user_id);
259
-                    ?>
258
+						$user = get_user_by('id', $user_id);
259
+					?>
260 260
                     <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
261 261
                         <?php echo  $user->display_name; ?>
262 262
                     </option>
@@ -267,1289 +267,1289 @@  discard block
 block discarded – undo
267 267
 
268 268
         <?php
269 269
 
270
-    } // end render_teacher_meta_box()
271
-
272
-    /**
273
-     * Sensei_Teacher::get_teachers_and_authors
274
-     *
275
-     * Get a list of users who can author courses, lessons and quizes.
276
-     *
277
-     * @since 1.8.0
278
-     * @access public
279
-     * @parameters
280
-     * @return array $users user id array
281
-     */
282
-    public function get_teachers_and_authors ( ){
283
-
284
-        $author_query_args = array(
285
-            'blog_id'      => $GLOBALS['blog_id'],
286
-            'fields'       => 'any',
287
-            'who'          => 'authors'
288
-        );
289
-
290
-        $authors = get_users( $author_query_args );
291
-
292
-        $teacher_query_args = array(
293
-            'blog_id'      => $GLOBALS['blog_id'],
294
-            'fields'       => 'any',
295
-            'role'         => 'teacher',
296
-        );
297
-
298
-        $teachers = get_users( $teacher_query_args );
299
-
300
-        return  array_unique( array_merge( $teachers, $authors ) );
301
-
302
-    }// end get_teachers_and_authors
303
-
304
-    /**
305
-     * Sensei_Teacher::save_teacher_meta_box
306
-     *
307
-     * Save the new teacher / author to course and all lessons
308
-     *
309
-     * Hooked into admin_init
310
-     *
311
-     * @since 1.8.0
312
-     * @access public
313
-     * @parameters
314
-     * @return array $users user id array
315
-     */
316
-    public function save_teacher_meta_box ( $course_id ){
270
+	} // end render_teacher_meta_box()
271
+
272
+	/**
273
+	 * Sensei_Teacher::get_teachers_and_authors
274
+	 *
275
+	 * Get a list of users who can author courses, lessons and quizes.
276
+	 *
277
+	 * @since 1.8.0
278
+	 * @access public
279
+	 * @parameters
280
+	 * @return array $users user id array
281
+	 */
282
+	public function get_teachers_and_authors ( ){
283
+
284
+		$author_query_args = array(
285
+			'blog_id'      => $GLOBALS['blog_id'],
286
+			'fields'       => 'any',
287
+			'who'          => 'authors'
288
+		);
289
+
290
+		$authors = get_users( $author_query_args );
291
+
292
+		$teacher_query_args = array(
293
+			'blog_id'      => $GLOBALS['blog_id'],
294
+			'fields'       => 'any',
295
+			'role'         => 'teacher',
296
+		);
297
+
298
+		$teachers = get_users( $teacher_query_args );
299
+
300
+		return  array_unique( array_merge( $teachers, $authors ) );
301
+
302
+	}// end get_teachers_and_authors
303
+
304
+	/**
305
+	 * Sensei_Teacher::save_teacher_meta_box
306
+	 *
307
+	 * Save the new teacher / author to course and all lessons
308
+	 *
309
+	 * Hooked into admin_init
310
+	 *
311
+	 * @since 1.8.0
312
+	 * @access public
313
+	 * @parameters
314
+	 * @return array $users user id array
315
+	 */
316
+	public function save_teacher_meta_box ( $course_id ){
317 317
 
318
-        // check if this is a post from saving the teacher, if not exit early
319
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
-            return;
321
-        }
318
+		// check if this is a post from saving the teacher, if not exit early
319
+		if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
+			return;
321
+		}
322 322
 
323
-        //don't fire this hook again
324
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
323
+		//don't fire this hook again
324
+		remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
325 325
 
326
-        // get the current post object
327
-        $post = get_post( $course_id );
326
+		// get the current post object
327
+		$post = get_post( $course_id );
328 328
 
329
-        // get the current teacher/author
330
-        $current_author = absint( $post->post_author );
331
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
329
+		// get the current teacher/author
330
+		$current_author = absint( $post->post_author );
331
+		$new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
332 332
 
333
-        // loop through all post lessons to update their authors as well
334
-        $this->update_course_lessons_author( $course_id , $new_author );
333
+		// loop through all post lessons to update their authors as well
334
+		$this->update_course_lessons_author( $course_id , $new_author );
335 335
 
336
-        // do not do any processing if the selected author is the same as the current author
337
-        if( $current_author == $new_author ){
338
-            return;
339
-        }
336
+		// do not do any processing if the selected author is the same as the current author
337
+		if( $current_author == $new_author ){
338
+			return;
339
+		}
340 340
 
341
-        // save the course  author
342
-        $post_updates = array(
343
-            'ID' => $post->ID ,
344
-            'post_author' => $new_author
345
-        );
346
-        wp_update_post( $post_updates );
341
+		// save the course  author
342
+		$post_updates = array(
343
+			'ID' => $post->ID ,
344
+			'post_author' => $new_author
345
+		);
346
+		wp_update_post( $post_updates );
347 347
 
348
-        // ensure the the modules are update so that then new teacher has access to them
349
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
348
+		// ensure the the modules are update so that then new teacher has access to them
349
+		Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
350 350
 
351
-        // notify the new teacher
352
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
351
+		// notify the new teacher
352
+		$this->teacher_course_assigned_notification( $new_author, $course_id );
353 353
 
354
-    } // end save_teacher_meta_box
354
+	} // end save_teacher_meta_box
355 355
 
356
-    /**
357
-     * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
-     * the new author. Making sure the course terms are maintained.
359
-     *
360
-     * This function also checks if terms are shared, with other courses
361
-     *
362
-     * @param $course_id
363
-     * @param $new_teacher_id
364
-     * @return void
365
-     */
366
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
356
+	/**
357
+	 * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
+	 * the new author. Making sure the course terms are maintained.
359
+	 *
360
+	 * This function also checks if terms are shared, with other courses
361
+	 *
362
+	 * @param $course_id
363
+	 * @param $new_teacher_id
364
+	 * @return void
365
+	 */
366
+	public static function update_course_modules_author( $course_id ,$new_teacher_id ){
367 367
 
368
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
-            return;
370
-        }
368
+		if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
+			return;
370
+		}
371 371
 
372
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
372
+		$terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
373 373
 
374
-        if( empty( $terms_selected_on_course ) ){
375
-            return;
376
-        }
374
+		if( empty( $terms_selected_on_course ) ){
375
+			return;
376
+		}
377 377
 
378
-        foreach( $terms_selected_on_course as $term ){
378
+		foreach( $terms_selected_on_course as $term ){
379 379
 
380
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
-            if( $new_teacher_id != $term_author->ID  ){
380
+			$term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
+			if( $new_teacher_id != $term_author->ID  ){
382 382
 
383
-                $new_term = '';
383
+				$new_term = '';
384 384
 
385
-                //if the new teacher is admin first check to see if the term with this name already exists
386
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
385
+				//if the new teacher is admin first check to see if the term with this name already exists
386
+				if( user_can( $new_teacher_id, 'manage_options' ) ){
387 387
 
388
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
-                    $existing_admin_terms = get_terms( 'module', $term_args );
391
-                    if( !empty( $existing_admin_terms ) ){
392
-                        // insert it even if it exists
393
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
-                    }
395
-                }
388
+					$slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
+					$term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
+					$existing_admin_terms = get_terms( 'module', $term_args );
391
+					if( !empty( $existing_admin_terms ) ){
392
+						// insert it even if it exists
393
+						$new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
+					}
395
+				}
396 396
 
397
-                if( empty ( $new_term ) ){
397
+				if( empty ( $new_term ) ){
398 398
 
399
-                   //setup the new slug
400
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
-
402
-                   // create new term and set it
403
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
-
405
-                }
399
+				   //setup the new slug
400
+				   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
+
402
+				   // create new term and set it
403
+				   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
+
405
+				}
406 406
 
407 407
 
408 408
 
409
-                // if term exists
410
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
409
+				// if term exists
410
+				if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
411 411
 
412
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
-                    $term_id = $existing_term->term_id;
412
+					$existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
+					$term_id = $existing_term->term_id;
414 414
 
415
-                }else{
415
+				}else{
416 416
 
417
-                    // for a new term simply get the term from the returned value
418
-                    $term_id = $new_term['term_id'];
417
+					// for a new term simply get the term from the returned value
418
+					$term_id = $new_term['term_id'];
419 419
 
420
-                } // end if term exist
420
+				} // end if term exist
421 421
 
422
-                // set the terms selected on the course
423
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
422
+				// set the terms selected on the course
423
+				wp_set_object_terms( $course_id, $term_id , 'module', true );
424 424
 
425
-                // remove old term
426
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
425
+				// remove old term
426
+				wp_remove_object_terms( $course_id, $term->term_id, 'module' );
427 427
 
428
-                // update the lessons within the current module term
429
-                $lessons = Sensei()->course->course_lessons( $course_id );
430
-                foreach( $lessons as $lesson  ){
428
+				// update the lessons within the current module term
429
+				$lessons = Sensei()->course->course_lessons( $course_id );
430
+				foreach( $lessons as $lesson  ){
431 431
 
432
-                    if( has_term( $term->slug, 'module', $lesson ) ){
432
+					if( has_term( $term->slug, 'module', $lesson ) ){
433 433
 
434
-                        // add the new term, the false at the end says to replace all terms on this module
435
-                        // with the new term.
436
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
-                    }
434
+						// add the new term, the false at the end says to replace all terms on this module
435
+						// with the new term.
436
+						wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
+						update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
+					}
439 439
 
440
-                }// end for each
440
+				}// end for each
441 441
 
442
-            }
443
-        }
442
+			}
443
+		}
444 444
 
445
-    }// end update_course_module_terms_author
445
+	}// end update_course_module_terms_author
446 446
 
447
-    /**
448
-     * Sensei_Teacher::update_course_lessons_author
449
-     *
450
-     * Update all course lessons and their quiz with a new author
451
-     *
452
-     * @since 1.8.0
453
-     * @access public
454
-     * @parameters
455
-     * @return array $users user id array
456
-     */
457
-    public function update_course_lessons_author ( $course_id, $new_author  ){
447
+	/**
448
+	 * Sensei_Teacher::update_course_lessons_author
449
+	 *
450
+	 * Update all course lessons and their quiz with a new author
451
+	 *
452
+	 * @since 1.8.0
453
+	 * @access public
454
+	 * @parameters
455
+	 * @return array $users user id array
456
+	 */
457
+	public function update_course_lessons_author ( $course_id, $new_author  ){
458 458
 
459 459
 
460
-        if( empty( $course_id ) || empty( $new_author ) ){
461
-            return false;
462
-        }
460
+		if( empty( $course_id ) || empty( $new_author ) ){
461
+			return false;
462
+		}
463 463
 
464
-        //get a list of course lessons
465
-        $lessons = Sensei()->course->course_lessons( $course_id );
464
+		//get a list of course lessons
465
+		$lessons = Sensei()->course->course_lessons( $course_id );
466 466
 
467
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
-            return false;
469
-        }
467
+		if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
+			return false;
469
+		}
470 470
 
471
-        // update each lesson and quiz author
472
-        foreach( $lessons as $lesson ){
471
+		// update each lesson and quiz author
472
+		foreach( $lessons as $lesson ){
473 473
 
474
-            // don't update if the author is tha same as the new author
475
-            if( $new_author == $lesson->post_author ){
476
-                continue;
477
-            }
474
+			// don't update if the author is tha same as the new author
475
+			if( $new_author == $lesson->post_author ){
476
+				continue;
477
+			}
478 478
 
479
-            // update lesson author
480
-            wp_update_post( array(
481
-                'ID'=> $lesson->ID,
482
-                'post_author' => $new_author
483
-                ) );
479
+			// update lesson author
480
+			wp_update_post( array(
481
+				'ID'=> $lesson->ID,
482
+				'post_author' => $new_author
483
+				) );
484 484
 
485
-            // update quiz author
486
-            //get the lessons quiz
487
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
-            if( is_array( $lesson_quizzes ) ){
489
-                foreach ( $lesson_quizzes as $quiz_id ) {
490
-                    // update quiz with new author
491
-                    wp_update_post( array(
492
-                        'ID'           => $quiz_id,
493
-                        'post_author' =>  $new_author
494
-                    ) );
495
-                }
496
-            }else{
497
-                wp_update_post( array(
498
-                    'ID'           => $lesson_quizzes,
499
-                    'post_author' =>  $new_author
500
-                ) );
501
-            }
485
+			// update quiz author
486
+			//get the lessons quiz
487
+			$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
+			if( is_array( $lesson_quizzes ) ){
489
+				foreach ( $lesson_quizzes as $quiz_id ) {
490
+					// update quiz with new author
491
+					wp_update_post( array(
492
+						'ID'           => $quiz_id,
493
+						'post_author' =>  $new_author
494
+					) );
495
+				}
496
+			}else{
497
+				wp_update_post( array(
498
+					'ID'           => $lesson_quizzes,
499
+					'post_author' =>  $new_author
500
+				) );
501
+			}
502 502
 
503
-        } // end for each lessons
503
+		} // end for each lessons
504 504
 
505
-        return true;
505
+		return true;
506 506
 
507
-    }// end update_course_lessons_author
508
-
509
-
510
-
511
-    /**
512
-     * Sensei_Teacher::course_analysis_teacher_access_limit
513
-     *
514
-     * Alter the query so that users can only see their courses on the analysis page
515
-     *
516
-     * @since 1.8.0
517
-     * @access public
518
-     * @parameters $query
519
-     * @return array $users user id array
520
-     */
521
-    public function course_analysis_teacher_access_limit ( $query ) {
522
-
523
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
-            return $query;
525
-        }
526
-
527
-        if ( ! function_exists( 'get_current_screen' ) ) {
528
-            return $query;
529
-        }
530
-
531
-        $screen = get_current_screen();
532
-        $sensei_post_types = array('course', 'lesson', 'question' );
533
-
534
-        // exit early for the following conditions
535
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
-
537
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
-            return $query;
540
-        }
541
-
542
-        global $current_user;
543
-        // set the query author to the current user to only show those those posts
544
-        $query->set( 'author', $current_user->ID );
545
-        return $query;
546
-
547
-    }// end course_analysis_teacher_access_limit
548
-
549
-
550
-    /**
551
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
-     *
553
-     * Determine if we're in admin and the current logged in use is a teacher
554
-     *
555
-     * @since 1.8.0
556
-     * @access public
557
-     * @parameters array $wp_query
558
-     * @return bool $is_admin_teacher
559
-     */
560
-    public function is_admin_teacher ( ){
561
-
562
-        if( ! is_user_logged_in()){
563
-            return false;
564
-        }
565
-        $is_admin_teacher = false;
566
-
567
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
-
569
-            $is_admin_teacher = true;
570
-
571
-        }
572
-
573
-        return $is_admin_teacher;
574
-
575
-    } // end is_admin_teacher
576
-
577
-    /**
578
-     * Show correct post counts on list table for Sensei post types
579
-     *
580
-     * @since 1.8.0
581
-     *
582
-     * @param  object $counts Default status counts
583
-     * @param  string $type   Current post type
584
-     * @param  string $perm   User permission level
585
-     * @return object         Modified status counts
586
-     */
587
-    public function list_table_counts( $counts, $type, $perm ) {
588
-        global $current_user;
589
-
590
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
-            return $counts;
592
-        }
593
-
594
-        if( ! $this->is_admin_teacher() ) {
595
-            return $counts;
596
-        }
597
-
598
-        $args = array(
599
-            'post_type' => $type,
600
-            'author' => $current_user->ID,
601
-            'posts_per_page' => -1
602
-        );
603
-
604
-         // Get all available statuses
605
-        $stati = get_post_stati();
606
-
607
-        // Update count object
608
-        foreach( $stati as $status ) {
609
-            $args['post_status'] = $status;
610
-            $posts = get_posts( $args );
611
-            $counts->$status = count( $posts );
612
-        }
613
-
614
-        return $counts;
615
-    }
616
-
617
-    /**
618
-     * Filter the post queries to show
619
-     * only lesson /course and users that belong
620
-     * to the current logged teacher.
621
-     *
622
-     * @since 1.8.0
623
-     *
624
-     */
625
-    public function filter_queries ( $query ) {
626
-        global $current_user;
627
-
628
-        if( ! $this->is_admin_teacher() ) {
629
-            return;
630
-        }
631
-
632
-        if ( ! function_exists( 'get_current_screen' ) ) {
633
-            return;
634
-        }
635
-
636
-        $screen = get_current_screen();
637
-        if( empty( $screen ) ) {
638
-            return $query;
639
-        }
640
-        switch( $screen->id ) {
641
-            case 'sensei_page_sensei_grading':
642
-            case 'sensei_page_sensei_analysis':
643
-            case 'sensei_page_sensei_learners':
644
-            case 'lesson':
645
-            case 'course':
646
-            case 'question':
647
-            case 'lesson_page_module-order':
648
-
649
-            /**
650
-             * sensei_filter_queries_set_author
651
-             * Filter the author Sensei set for queries
652
-             *
653
-             * @since 1.8.0
654
-             *
655
-             * @param int $user_id
656
-             * @param string $screen_id
657
-             *
658
-             */
659
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
-            break;
661
-        }
662
-    }
663
-
664
-    /**
665
-     * Limit grading quizzes to only those within courses belonging to the current teacher
666
-     * . This excludes the admin user.
667
-     *
668
-     * @since 1.8.0
669
-     * @hooked into the_comments
670
-     * @param array  $comments
671
-     *
672
-     * @return array $comments
673
-     */
674
-    public function filter_grading_activity_queries( $comments ){
675
-
676
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
-            return $comments ;
678
-        }
679
-
680
-        //check if we're on the grading screen
681
-        $screen = get_current_screen();
682
-
683
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
-            return $comments;
685
-        }
686
-
687
-        // get the course and determine if the current teacher is the owner
688
-        // if not remove it from the list of comments to be returned
689
-        foreach( $comments as $key => $comment){
690
-            $lesson = get_post( $comment->comment_post_ID );
691
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
-            $course = get_post( $course_id );
693
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
-                //remove this as the teacher should see this.
695
-                unset( $comments[ $key ] );
696
-            }
697
-        }
698
-        return $comments ;
699
-
700
-    }// end function filter grading
701
-
702
-    /**
703
-     * Limit the grading screen totals to only show lessons in the course
704
-     * belonging to the currently logged in teacher. This only applies to
705
-     * the teacher role.
706
-     *
707
-     * @since 1.8.0
708
-     *
709
-     * @hooked into sensei_count_statuses_args
710
-     * @param array $args
711
-     *
712
-     * @return array  $args
713
-     */
714
-    public function limit_grading_totals( $args ){
715
-
716
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
-            return $args ;
718
-        }
719
-
720
-        //get the teachers courses
721
-        // the query is already filtered to only the teacher
722
-        $courses =  Sensei()->course->get_all_courses();
723
-
724
-        if( empty(  $courses ) || ! is_array( $courses ) ){
725
-            return $args;
726
-        }
727
-
728
-        //setup the lessons quizzes  to limit the grading totals to
729
-        $quiz_scope = array();
730
-        foreach( $courses as $course ){
731
-
732
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
733
-
734
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
-
736
-                foreach(  $course_lessons as $lesson ){
737
-
738
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
-                    if( !empty( $quiz_id ) ) {
740
-
741
-                        array_push( $quiz_scope, $quiz_id );
742
-
743
-                    }
744
-
745
-                }
746
-
747
-            }
748
-
749
-        }
750
-
751
-        $args['post__in'] = $quiz_scope;
752
-
753
-        return $args;
754
-    }
755
-
756
-    /**
757
-     * It ensures that the author archive shows course by the current user.
758
-     *
759
-     * This function is hooked into the pre_get_posts filter
760
-     *
761
-     * @param WP_Query $query
762
-     * @return WP_Query $query
763
-     */
764
-    public function add_courses_to_author_archive( $query ) {
765
-
766
-        if ( is_admin() || ! $query->is_author() ){
767
-            return $query;
768
-        }
769
-
770
-        // this should only apply to users with the teacher role
771
-        $current_page_user = get_user_by('login', $query->get('author_name') );
772
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
-
774
-            return $query;
775
-
776
-        }
777
-
778
-        // Change post types depending on what is set already
779
-        $current_post_types = $query->get( 'post_type' );
780
-        if( empty( $current_post_types  ) ){
781
-
782
-            // if empty it means post by default, so add post so that it also includes that for now
783
-            $new_post_types = array( 'post', 'course' );
784
-
785
-        } elseif( is_array( $current_post_types  ) ) {
786
-
787
-            // merge the post types instead of overwriting it
788
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
-
790
-        }else{
791
-
792
-            // in this instance it is probably just one post type in string format
793
-            $new_post_types =  array( $current_post_types , 'course');
794
-
795
-        }
796
-
797
-        // change the query before returning it
798
-        $query->set('post_type', $new_post_types );
799
-
800
-        /**
801
-         * Change the query on the teacher author archive template
802
-         *
803
-         * @since 1.8.4
804
-         * @param WP_Query $query
805
-         */
806
-        return apply_filters( 'sensei_teacher_archive_query', $query );
807
-
808
-    }
809
-
810
-    /**
811
-     * Notify teacher when someone assigns a course to their account.
812
-     *
813
-     * @since 1.8.0
814
-     *
815
-     * @param $teacher_id
816
-     * @param $course_id
817
-     * @return bool
818
-     */
819
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
-
821
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
-            return false;
823
-        }
824
-
825
-        // if new user is the same as the current logged user, they don't need an email
826
-        if( $teacher_id == get_current_user_id() ){
827
-            return true;
828
-        }
829
-
830
-        // load the email class
831
-        include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
-        $email = new Sensei_Email_Teacher_New_Course_Assignment();
833
-        $email->trigger( $teacher_id, $course_id );
834
-
835
-        return true;
836
-    } // end  teacher_course_assigned_notification
837
-
838
-    /**
839
-     * Email the admin when a teacher creates a new course
840
-     *
841
-     * This function hooks into wp_insert_post
842
-     *
843
-     * @since 1.8.0
844
-     * @param int $course_id
845
-     * @return bool
846
-     */
847
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
-
849
-        $course_id = $post->ID;
850
-
851
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
-
854
-            return false;
855
-
856
-        }
857
-
858
-        /**
859
-         * Filter the option to send admin notification emails when teachers creation
860
-         * course.
861
-         *
862
-         * @since 1.8.0
863
-         *
864
-         * @param bool $on default true
865
-         */
866
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
-            return false;
868
-        }
869
-
870
-        // setting up the data needed by the email template
871
-        global $sensei_email_data;
872
-        $template = 'admin-teacher-new-course-created';
873
-        $course = get_post( $course_id );
874
-        $teacher = new WP_User( $course->post_author );
875
-        $recipient = get_option('admin_email', true);
876
-
877
-        // don't send if the course is created by admin
878
-        if( $recipient == $teacher->user_email ){
879
-            return;
880
-        }
881
-
882
-        /**
883
-         * Filter the email Header for the admin-teacher-new-course-created template
884
-         *
885
-         * @since 1.8.0
886
-         * @param string $template
887
-         */
888
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
-
890
-        /**
891
-         * Filter the email subject for the the
892
-         * admin-teacher-new-course-created template
893
-         *
894
-         * @since 1.8.0
895
-         * @param string $subject default New course assigned to you
896
-         * @param string $template
897
-         */
898
-        $subject = apply_filters('sensei_email_subject',
899
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
-                                $template );
901
-
902
-        //course edit link
903
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
-
905
-        // Construct data array
906
-        $email_data = array(
907
-            'template'			=> $template,
908
-            'heading' =>  $heading,
909
-            'teacher'		=> $teacher,
910
-            'course_id'			=> $course_id,
911
-            'course_name'			=> $course->post_title,
912
-            'course_edit_link' => $course_edit_link,
913
-        );
914
-
915
-        /**
916
-         * Filter the sensei email data for the admin-teacher-new-course-created template
917
-         *
918
-         * @since 1.8.0
919
-         * @param array $email_data
920
-         * @param string $template
921
-         */
922
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
-
924
-        // Send mail
925
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
-
927
-    }// end notify admin of course creation
928
-
929
-    /**
930
-     * Limit the analysis view to only the users taking courses belong to this teacher
931
-     *
932
-     * Hooked into sensei_analysis_get_learners
933
-     * @param array $args WP_User_Query arguments
934
-     * @return array $learners_query_results
935
-     */
936
-    public function limit_analysis_learners( $args ){
937
-
938
-        // show default for none teachers
939
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
940
-                return $args;
941
-        }
942
-
943
-        // for teachers all courses only return those which belong to the teacher
944
-        // as they don't have access to course belonging to other users
945
-        $teacher_courses = Sensei()->course->get_all_courses();
507
+	}// end update_course_lessons_author
508
+
509
+
510
+
511
+	/**
512
+	 * Sensei_Teacher::course_analysis_teacher_access_limit
513
+	 *
514
+	 * Alter the query so that users can only see their courses on the analysis page
515
+	 *
516
+	 * @since 1.8.0
517
+	 * @access public
518
+	 * @parameters $query
519
+	 * @return array $users user id array
520
+	 */
521
+	public function course_analysis_teacher_access_limit ( $query ) {
522
+
523
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
+			return $query;
525
+		}
526
+
527
+		if ( ! function_exists( 'get_current_screen' ) ) {
528
+			return $query;
529
+		}
530
+
531
+		$screen = get_current_screen();
532
+		$sensei_post_types = array('course', 'lesson', 'question' );
533
+
534
+		// exit early for the following conditions
535
+		$limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
+
537
+		if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
+			|| ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
+			return $query;
540
+		}
541
+
542
+		global $current_user;
543
+		// set the query author to the current user to only show those those posts
544
+		$query->set( 'author', $current_user->ID );
545
+		return $query;
546
+
547
+	}// end course_analysis_teacher_access_limit
548
+
549
+
550
+	/**
551
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
+	 *
553
+	 * Determine if we're in admin and the current logged in use is a teacher
554
+	 *
555
+	 * @since 1.8.0
556
+	 * @access public
557
+	 * @parameters array $wp_query
558
+	 * @return bool $is_admin_teacher
559
+	 */
560
+	public function is_admin_teacher ( ){
561
+
562
+		if( ! is_user_logged_in()){
563
+			return false;
564
+		}
565
+		$is_admin_teacher = false;
566
+
567
+		if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
+
569
+			$is_admin_teacher = true;
570
+
571
+		}
572
+
573
+		return $is_admin_teacher;
574
+
575
+	} // end is_admin_teacher
576
+
577
+	/**
578
+	 * Show correct post counts on list table for Sensei post types
579
+	 *
580
+	 * @since 1.8.0
581
+	 *
582
+	 * @param  object $counts Default status counts
583
+	 * @param  string $type   Current post type
584
+	 * @param  string $perm   User permission level
585
+	 * @return object         Modified status counts
586
+	 */
587
+	public function list_table_counts( $counts, $type, $perm ) {
588
+		global $current_user;
589
+
590
+		if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
+			return $counts;
592
+		}
593
+
594
+		if( ! $this->is_admin_teacher() ) {
595
+			return $counts;
596
+		}
597
+
598
+		$args = array(
599
+			'post_type' => $type,
600
+			'author' => $current_user->ID,
601
+			'posts_per_page' => -1
602
+		);
603
+
604
+		 // Get all available statuses
605
+		$stati = get_post_stati();
606
+
607
+		// Update count object
608
+		foreach( $stati as $status ) {
609
+			$args['post_status'] = $status;
610
+			$posts = get_posts( $args );
611
+			$counts->$status = count( $posts );
612
+		}
613
+
614
+		return $counts;
615
+	}
616
+
617
+	/**
618
+	 * Filter the post queries to show
619
+	 * only lesson /course and users that belong
620
+	 * to the current logged teacher.
621
+	 *
622
+	 * @since 1.8.0
623
+	 *
624
+	 */
625
+	public function filter_queries ( $query ) {
626
+		global $current_user;
627
+
628
+		if( ! $this->is_admin_teacher() ) {
629
+			return;
630
+		}
631
+
632
+		if ( ! function_exists( 'get_current_screen' ) ) {
633
+			return;
634
+		}
635
+
636
+		$screen = get_current_screen();
637
+		if( empty( $screen ) ) {
638
+			return $query;
639
+		}
640
+		switch( $screen->id ) {
641
+			case 'sensei_page_sensei_grading':
642
+			case 'sensei_page_sensei_analysis':
643
+			case 'sensei_page_sensei_learners':
644
+			case 'lesson':
645
+			case 'course':
646
+			case 'question':
647
+			case 'lesson_page_module-order':
648
+
649
+			/**
650
+			 * sensei_filter_queries_set_author
651
+			 * Filter the author Sensei set for queries
652
+			 *
653
+			 * @since 1.8.0
654
+			 *
655
+			 * @param int $user_id
656
+			 * @param string $screen_id
657
+			 *
658
+			 */
659
+			$query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
+			break;
661
+		}
662
+	}
663
+
664
+	/**
665
+	 * Limit grading quizzes to only those within courses belonging to the current teacher
666
+	 * . This excludes the admin user.
667
+	 *
668
+	 * @since 1.8.0
669
+	 * @hooked into the_comments
670
+	 * @param array  $comments
671
+	 *
672
+	 * @return array $comments
673
+	 */
674
+	public function filter_grading_activity_queries( $comments ){
675
+
676
+		if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
+			return $comments ;
678
+		}
679
+
680
+		//check if we're on the grading screen
681
+		$screen = get_current_screen();
682
+
683
+		if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
+			return $comments;
685
+		}
686
+
687
+		// get the course and determine if the current teacher is the owner
688
+		// if not remove it from the list of comments to be returned
689
+		foreach( $comments as $key => $comment){
690
+			$lesson = get_post( $comment->comment_post_ID );
691
+			$course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
+			$course = get_post( $course_id );
693
+			if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
+				//remove this as the teacher should see this.
695
+				unset( $comments[ $key ] );
696
+			}
697
+		}
698
+		return $comments ;
699
+
700
+	}// end function filter grading
701
+
702
+	/**
703
+	 * Limit the grading screen totals to only show lessons in the course
704
+	 * belonging to the currently logged in teacher. This only applies to
705
+	 * the teacher role.
706
+	 *
707
+	 * @since 1.8.0
708
+	 *
709
+	 * @hooked into sensei_count_statuses_args
710
+	 * @param array $args
711
+	 *
712
+	 * @return array  $args
713
+	 */
714
+	public function limit_grading_totals( $args ){
715
+
716
+		if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
+			return $args ;
718
+		}
719
+
720
+		//get the teachers courses
721
+		// the query is already filtered to only the teacher
722
+		$courses =  Sensei()->course->get_all_courses();
723
+
724
+		if( empty(  $courses ) || ! is_array( $courses ) ){
725
+			return $args;
726
+		}
727
+
728
+		//setup the lessons quizzes  to limit the grading totals to
729
+		$quiz_scope = array();
730
+		foreach( $courses as $course ){
731
+
732
+			$course_lessons = Sensei()->course->course_lessons( $course->ID );
733
+
734
+			if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
+
736
+				foreach(  $course_lessons as $lesson ){
737
+
738
+					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
+					if( !empty( $quiz_id ) ) {
740
+
741
+						array_push( $quiz_scope, $quiz_id );
742
+
743
+					}
744
+
745
+				}
746
+
747
+			}
748
+
749
+		}
750
+
751
+		$args['post__in'] = $quiz_scope;
752
+
753
+		return $args;
754
+	}
755
+
756
+	/**
757
+	 * It ensures that the author archive shows course by the current user.
758
+	 *
759
+	 * This function is hooked into the pre_get_posts filter
760
+	 *
761
+	 * @param WP_Query $query
762
+	 * @return WP_Query $query
763
+	 */
764
+	public function add_courses_to_author_archive( $query ) {
765
+
766
+		if ( is_admin() || ! $query->is_author() ){
767
+			return $query;
768
+		}
769
+
770
+		// this should only apply to users with the teacher role
771
+		$current_page_user = get_user_by('login', $query->get('author_name') );
772
+		if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
+
774
+			return $query;
775
+
776
+		}
777
+
778
+		// Change post types depending on what is set already
779
+		$current_post_types = $query->get( 'post_type' );
780
+		if( empty( $current_post_types  ) ){
781
+
782
+			// if empty it means post by default, so add post so that it also includes that for now
783
+			$new_post_types = array( 'post', 'course' );
784
+
785
+		} elseif( is_array( $current_post_types  ) ) {
786
+
787
+			// merge the post types instead of overwriting it
788
+			$new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
+
790
+		}else{
791
+
792
+			// in this instance it is probably just one post type in string format
793
+			$new_post_types =  array( $current_post_types , 'course');
794
+
795
+		}
796
+
797
+		// change the query before returning it
798
+		$query->set('post_type', $new_post_types );
799
+
800
+		/**
801
+		 * Change the query on the teacher author archive template
802
+		 *
803
+		 * @since 1.8.4
804
+		 * @param WP_Query $query
805
+		 */
806
+		return apply_filters( 'sensei_teacher_archive_query', $query );
807
+
808
+	}
809
+
810
+	/**
811
+	 * Notify teacher when someone assigns a course to their account.
812
+	 *
813
+	 * @since 1.8.0
814
+	 *
815
+	 * @param $teacher_id
816
+	 * @param $course_id
817
+	 * @return bool
818
+	 */
819
+	public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
+
821
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
+			return false;
823
+		}
824
+
825
+		// if new user is the same as the current logged user, they don't need an email
826
+		if( $teacher_id == get_current_user_id() ){
827
+			return true;
828
+		}
829
+
830
+		// load the email class
831
+		include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
+		$email = new Sensei_Email_Teacher_New_Course_Assignment();
833
+		$email->trigger( $teacher_id, $course_id );
834
+
835
+		return true;
836
+	} // end  teacher_course_assigned_notification
837
+
838
+	/**
839
+	 * Email the admin when a teacher creates a new course
840
+	 *
841
+	 * This function hooks into wp_insert_post
842
+	 *
843
+	 * @since 1.8.0
844
+	 * @param int $course_id
845
+	 * @return bool
846
+	 */
847
+	public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
+
849
+		$course_id = $post->ID;
850
+
851
+		if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
+			|| 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
+
854
+			return false;
855
+
856
+		}
857
+
858
+		/**
859
+		 * Filter the option to send admin notification emails when teachers creation
860
+		 * course.
861
+		 *
862
+		 * @since 1.8.0
863
+		 *
864
+		 * @param bool $on default true
865
+		 */
866
+		if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
+			return false;
868
+		}
869
+
870
+		// setting up the data needed by the email template
871
+		global $sensei_email_data;
872
+		$template = 'admin-teacher-new-course-created';
873
+		$course = get_post( $course_id );
874
+		$teacher = new WP_User( $course->post_author );
875
+		$recipient = get_option('admin_email', true);
876
+
877
+		// don't send if the course is created by admin
878
+		if( $recipient == $teacher->user_email ){
879
+			return;
880
+		}
881
+
882
+		/**
883
+		 * Filter the email Header for the admin-teacher-new-course-created template
884
+		 *
885
+		 * @since 1.8.0
886
+		 * @param string $template
887
+		 */
888
+		$heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
+
890
+		/**
891
+		 * Filter the email subject for the the
892
+		 * admin-teacher-new-course-created template
893
+		 *
894
+		 * @since 1.8.0
895
+		 * @param string $subject default New course assigned to you
896
+		 * @param string $template
897
+		 */
898
+		$subject = apply_filters('sensei_email_subject',
899
+								'['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
+								$template );
901
+
902
+		//course edit link
903
+		$course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
+
905
+		// Construct data array
906
+		$email_data = array(
907
+			'template'			=> $template,
908
+			'heading' =>  $heading,
909
+			'teacher'		=> $teacher,
910
+			'course_id'			=> $course_id,
911
+			'course_name'			=> $course->post_title,
912
+			'course_edit_link' => $course_edit_link,
913
+		);
914
+
915
+		/**
916
+		 * Filter the sensei email data for the admin-teacher-new-course-created template
917
+		 *
918
+		 * @since 1.8.0
919
+		 * @param array $email_data
920
+		 * @param string $template
921
+		 */
922
+		$sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
+
924
+		// Send mail
925
+		Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
+
927
+	}// end notify admin of course creation
928
+
929
+	/**
930
+	 * Limit the analysis view to only the users taking courses belong to this teacher
931
+	 *
932
+	 * Hooked into sensei_analysis_get_learners
933
+	 * @param array $args WP_User_Query arguments
934
+	 * @return array $learners_query_results
935
+	 */
936
+	public function limit_analysis_learners( $args ){
937
+
938
+		// show default for none teachers
939
+		if( ! Sensei()->teacher->is_admin_teacher() ) {
940
+				return $args;
941
+		}
942
+
943
+		// for teachers all courses only return those which belong to the teacher
944
+		// as they don't have access to course belonging to other users
945
+		$teacher_courses = Sensei()->course->get_all_courses();
946 946
 
947
-        // if the user has no courses they should see no users
948
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
-            // tell the query to return 0 students
950
-            $args[ 'include'] = array( 0 );
951
-            return $args;
952
-
953
-        }
954
-
955
-        $learner_ids_for_teacher_courses = array();
956
-        foreach( $teacher_courses as $course ){
957
-
958
-            $course_learner_ids = array();
959
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
-
961
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
-                continue; // skip to the next course as there are no users on this course
963
-            }
964
-
965
-            // it could be an array of comments or a single comment
966
-            if( is_array( $activity_comments ) ){
947
+		// if the user has no courses they should see no users
948
+		if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
+			// tell the query to return 0 students
950
+			$args[ 'include'] = array( 0 );
951
+			return $args;
952
+
953
+		}
954
+
955
+		$learner_ids_for_teacher_courses = array();
956
+		foreach( $teacher_courses as $course ){
957
+
958
+			$course_learner_ids = array();
959
+			$activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
+
961
+			if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
+				continue; // skip to the next course as there are no users on this course
963
+			}
964
+
965
+			// it could be an array of comments or a single comment
966
+			if( is_array( $activity_comments ) ){
967 967
 
968
-                foreach( $activity_comments as $comment ){
968
+				foreach( $activity_comments as $comment ){
969 969
 
970
-                    $user = get_userdata( $comment->user_id );
970
+					$user = get_userdata( $comment->user_id );
971 971
 
972
-                    if( empty( $user ) ){
973
-                        // next comment in this array
974
-                        continue;
975
-                    }
972
+					if( empty( $user ) ){
973
+						// next comment in this array
974
+						continue;
975
+					}
976 976
 
977
-                    $course_learner_ids[] = $user->ID;
978
-                }
977
+					$course_learner_ids[] = $user->ID;
978
+				}
979 979
 
980
-            }else{
980
+			}else{
981 981
 
982
-                $user = get_userdata( $activity_comments->user_id );
983
-                $course_learner_ids[] = $user->ID;
982
+				$user = get_userdata( $activity_comments->user_id );
983
+				$course_learner_ids[] = $user->ID;
984 984
 
985
-            }
985
+			}
986 986
 
987
-            // add learners on this course to the all courses learner list
988
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
987
+			// add learners on this course to the all courses learner list
988
+			$learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
989 989
 
990
-        }
990
+		}
991 991
 
992
-        // if there are no students taking the courses by this teacher don't show them any of the other users
993
-        if( empty( $learner_ids_for_teacher_courses ) ){
992
+		// if there are no students taking the courses by this teacher don't show them any of the other users
993
+		if( empty( $learner_ids_for_teacher_courses ) ){
994 994
 
995
-            $args[ 'include'] = array( 0 );
995
+			$args[ 'include'] = array( 0 );
996 996
 
997
-        }else{
997
+		}else{
998 998
 
999
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
999
+			$args[ 'include'] = $learner_ids_for_teacher_courses;
1000 1000
 
1001
-        }
1001
+		}
1002 1002
 
1003
-        // return the WP_Use_Query arguments
1004
-        return $args;
1003
+		// return the WP_Use_Query arguments
1004
+		return $args;
1005 1005
 
1006
-    }// end limit_analysis_learners
1006
+	}// end limit_analysis_learners
1007 1007
 
1008
-    /**
1009
-     * Give teacher full admin access to the question post type
1010
-     * in certain cases.
1011
-     *
1012
-     * @since 1.8.0
1013
-     * @param $questions
1014
-     * @return mixed
1015
-     */
1016
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1008
+	/**
1009
+	 * Give teacher full admin access to the question post type
1010
+	 * in certain cases.
1011
+	 *
1012
+	 * @since 1.8.0
1013
+	 * @param $questions
1014
+	 * @return mixed
1015
+	 */
1016
+	public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1017 1017
 
1018
-        if( ! $this->is_admin_teacher() ){
1019
-            return $questions;
1020
-        }
1018
+		if( ! $this->is_admin_teacher() ){
1019
+			return $questions;
1020
+		}
1021 1021
 
1022
-        $screen = get_current_screen();
1022
+		$screen = get_current_screen();
1023 1023
 
1024
-        // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1024
+		// don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
+		remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1026 1026
 
1027
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1027
+		if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1028 1028
 
1029
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
-            if( ! empty($admin_user) ){
1029
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
+			if( ! empty($admin_user) ){
1031 1031
 
1032
-                $current_teacher_id = get_current_user_id();
1032
+				$current_teacher_id = get_current_user_id();
1033 1033
 
1034
-                // set current user to admin so teacher can view all questions
1035
-                wp_set_current_user( $admin_user->ID  );
1036
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1034
+				// set current user to admin so teacher can view all questions
1035
+				wp_set_current_user( $admin_user->ID  );
1036
+				$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1037 1037
 
1038
-                // set the teacher as the current use again
1039
-                wp_set_current_user( $current_teacher_id );
1040
-            }
1038
+				// set the teacher as the current use again
1039
+				wp_set_current_user( $current_teacher_id );
1040
+			}
1041 1041
 
1042
-        }
1043
-        // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1042
+		}
1043
+		// attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1045 1045
 
1046
-        return $questions;
1047
-    }
1046
+		return $questions;
1047
+	}
1048 1048
 
1049
-    /**
1050
-     * Give the teacher role access to questions from the question bank
1051
-     *
1052
-     * @since 1.8.0
1053
-     * @param $wp_query
1054
-     * @return mixed
1055
-     */
1056
-    public function give_access_to_all_questions( $wp_query ){
1049
+	/**
1050
+	 * Give the teacher role access to questions from the question bank
1051
+	 *
1052
+	 * @since 1.8.0
1053
+	 * @param $wp_query
1054
+	 * @return mixed
1055
+	 */
1056
+	public function give_access_to_all_questions( $wp_query ){
1057 1057
 
1058
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1058
+		if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1059 1059
 
1060
-            return $wp_query;
1061
-        }
1060
+			return $wp_query;
1061
+		}
1062 1062
 
1063
-        $screen = get_current_screen();
1064
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1063
+		$screen = get_current_screen();
1064
+		if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
+			|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1066 1066
 
1067
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
-            if( ! empty($admin_user) ){
1067
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
+			if( ! empty($admin_user) ){
1069 1069
 
1070
-                $current_teacher_id = get_current_user_id();
1070
+				$current_teacher_id = get_current_user_id();
1071 1071
 
1072
-                // set current user to admin so teacher can view all questions
1073
-                wp_set_current_user( $admin_user->ID  );
1072
+				// set current user to admin so teacher can view all questions
1073
+				wp_set_current_user( $admin_user->ID  );
1074 1074
 
1075
-                //run new query as admin
1076
-                $wp_query = new WP_Query( $wp_query->query );
1075
+				//run new query as admin
1076
+				$wp_query = new WP_Query( $wp_query->query );
1077 1077
 
1078
-                //set the teache as current use again
1079
-                wp_set_current_user( $current_teacher_id );
1078
+				//set the teache as current use again
1079
+				wp_set_current_user( $current_teacher_id );
1080 1080
 
1081
-            }
1082
-        }
1081
+			}
1082
+		}
1083 1083
 
1084
-        return $wp_query;
1085
-    }// end give_access_to_all_questions
1084
+		return $wp_query;
1085
+	}// end give_access_to_all_questions
1086 1086
 
1087
-    /**
1088
-     * Add new column heading to the course admin edit list
1089
-     *
1090
-     * @since 1.8.0
1091
-     * @param $columns
1092
-     * @return array
1093
-     */
1094
-    public function course_column_heading($columns) {
1087
+	/**
1088
+	 * Add new column heading to the course admin edit list
1089
+	 *
1090
+	 * @since 1.8.0
1091
+	 * @param $columns
1092
+	 * @return array
1093
+	 */
1094
+	public function course_column_heading($columns) {
1095 1095
 
1096
-        if( $this->is_admin_teacher() ){
1097
-            return $columns;
1098
-        }
1099
-        $new_columns = array(
1100
-            'teacher' => __('Teacher', 'woothemes-sensei'),
1101
-        );
1102
-        return array_merge($columns, $new_columns);
1096
+		if( $this->is_admin_teacher() ){
1097
+			return $columns;
1098
+		}
1099
+		$new_columns = array(
1100
+			'teacher' => __('Teacher', 'woothemes-sensei'),
1101
+		);
1102
+		return array_merge($columns, $new_columns);
1103 1103
 
1104
-    }// end teacher column add
1104
+	}// end teacher column add
1105 1105
 
1106
-    /**
1107
-     * Print out  teacher column data
1108
-     *
1109
-     * @since 1.8.0
1110
-     * @param $column
1111
-     * @param $course_id
1112
-     */
1113
-    public function course_column_data( $column, $course_id  ){
1106
+	/**
1107
+	 * Print out  teacher column data
1108
+	 *
1109
+	 * @since 1.8.0
1110
+	 * @param $column
1111
+	 * @param $course_id
1112
+	 */
1113
+	public function course_column_data( $column, $course_id  ){
1114 1114
 
1115
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
-            return;
1117
-        }
1115
+		if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
+			return;
1117
+		}
1118 1118
 
1119
-        $course = get_post( $course_id );
1120
-        $teacher = get_userdata( $course->post_author );
1119
+		$course = get_post( $course_id );
1120
+		$teacher = get_userdata( $course->post_author );
1121 1121
 
1122
-        if( !$teacher ){
1123
-            return;
1124
-        }
1122
+		if( !$teacher ){
1123
+			return;
1124
+		}
1125 1125
 
1126
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1126
+		echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1127 1127
 
1128
-    }// end course_column_ data
1128
+	}// end course_column_ data
1129 1129
 
1130
-    /**
1131
-     * Return only courses belonging to the given teacher.
1132
-     *
1133
-     *
1134
-     * @since 1.8.0
1135
-     *
1136
-     * @param int $teacher_id
1137
-     * @param bool $return_ids_only
1138
-     *
1139
-     * @return array $teachers_courses
1140
-     */
1141
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1130
+	/**
1131
+	 * Return only courses belonging to the given teacher.
1132
+	 *
1133
+	 *
1134
+	 * @since 1.8.0
1135
+	 *
1136
+	 * @param int $teacher_id
1137
+	 * @param bool $return_ids_only
1138
+	 *
1139
+	 * @return array $teachers_courses
1140
+	 */
1141
+	public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1142 1142
 
1143
-        $teachers_courses = array();
1143
+		$teachers_courses = array();
1144 1144
 
1145
-        if( empty( $teacher_id  ) ){
1146
-            $teacher_id = get_current_user_id();
1147
-        }
1145
+		if( empty( $teacher_id  ) ){
1146
+			$teacher_id = get_current_user_id();
1147
+		}
1148 1148
 
1149
-        $all_courses = Sensei()->course->get_all_courses();
1149
+		$all_courses = Sensei()->course->get_all_courses();
1150 1150
 
1151
-        if( empty( $all_courses ) ){
1152
-            return $all_courses;
1153
-        }
1151
+		if( empty( $all_courses ) ){
1152
+			return $all_courses;
1153
+		}
1154 1154
 
1155
-        foreach( $all_courses as $course ){
1155
+		foreach( $all_courses as $course ){
1156 1156
 
1157
-            if( $course->post_author != $teacher_id  ){
1158
-                continue;
1159
-            }
1157
+			if( $course->post_author != $teacher_id  ){
1158
+				continue;
1159
+			}
1160 1160
 
1161
-            if( $return_ids_only ){
1161
+			if( $return_ids_only ){
1162 1162
 
1163
-                $teachers_courses[] = $course->ID;
1163
+				$teachers_courses[] = $course->ID;
1164 1164
 
1165
-            }else{
1165
+			}else{
1166 1166
 
1167
-                $teachers_courses[] = $course;
1167
+				$teachers_courses[] = $course;
1168 1168
 
1169
-            }
1169
+			}
1170 1170
 
1171
-        }
1171
+		}
1172 1172
 
1173
-        return $teachers_courses;
1173
+		return $teachers_courses;
1174 1174
 
1175
-    }
1175
+	}
1176 1176
 
1177
-    /**
1178
-     * Limit the message display to only those sent to the current teacher
1179
-     *
1180
-     * @since 1.8.0
1181
-     *
1182
-     * @param $query
1183
-     * @return mixed
1184
-     */
1185
-    public function limit_edit_messages_query( $query ){
1186
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
-            return $query;
1188
-        }
1189
-
1190
-        $teacher = wp_get_current_user();
1191
-
1192
-        $query->set( 'meta_key', '_receiver' );
1193
-        $meta_query_args = array(
1194
-            'key'     => '_receiver',
1195
-            'value'   => $teacher->get('user_login') ,
1196
-            'compare' => '='
1197
-        );
1177
+	/**
1178
+	 * Limit the message display to only those sent to the current teacher
1179
+	 *
1180
+	 * @since 1.8.0
1181
+	 *
1182
+	 * @param $query
1183
+	 * @return mixed
1184
+	 */
1185
+	public function limit_edit_messages_query( $query ){
1186
+		if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
+			return $query;
1188
+		}
1189
+
1190
+		$teacher = wp_get_current_user();
1191
+
1192
+		$query->set( 'meta_key', '_receiver' );
1193
+		$meta_query_args = array(
1194
+			'key'     => '_receiver',
1195
+			'value'   => $teacher->get('user_login') ,
1196
+			'compare' => '='
1197
+		);
1198 1198
 
1199
-        $query->set('meta_query', $meta_query_args  );
1199
+		$query->set('meta_query', $meta_query_args  );
1200 1200
 
1201
-        return $query;
1202
-    }
1201
+		return $query;
1202
+	}
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Add options to filter courses by teacher
1207
-     *
1208
-     * @since 1.8.0
1209
-     *
1210
-     * @return void
1211
-     */
1212
-    public function course_teacher_filter_options() {
1213
-        global $typenow;
1205
+	/**
1206
+	 * Add options to filter courses by teacher
1207
+	 *
1208
+	 * @since 1.8.0
1209
+	 *
1210
+	 * @return void
1211
+	 */
1212
+	public function course_teacher_filter_options() {
1213
+		global $typenow;
1214 1214
 
1215
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
-            return;
1217
-        }
1215
+		if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
+			return;
1217
+		}
1218 1218
 
1219
-        // get all roles
1220
-        $roles = get_editable_roles();
1219
+		// get all roles
1220
+		$roles = get_editable_roles();
1221 1221
 
1222
-        // get roles with the course edit capability
1223
-        // and then get the users with those roles
1224
-        $users_who_can_edit_courses = array();
1225
-        foreach( $roles as $role_item ){
1222
+		// get roles with the course edit capability
1223
+		// and then get the users with those roles
1224
+		$users_who_can_edit_courses = array();
1225
+		foreach( $roles as $role_item ){
1226 1226
 
1227
-            $role = get_role( strtolower( $role_item['name'] ) );
1227
+			$role = get_role( strtolower( $role_item['name'] ) );
1228 1228
 
1229
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1229
+			if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1230 1230
 
1231
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1231
+				$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
+				$role_users_who_can_edit_courses = get_users( $user_query_args );
1233 1233
 
1234
-                // add user from the current $user_role to all users
1235
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1234
+				// add user from the current $user_role to all users
1235
+				$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1236 1236
 
1237
-            }
1237
+			}
1238 1238
 
1239
-        }
1239
+		}
1240 1240
 
1241
-        // Create the select element with the given users who can edit course
1242
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
-        $course_options = '';
1244
-        foreach( $users_who_can_edit_courses as $user ) {
1245
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
-        }
1241
+		// Create the select element with the given users who can edit course
1242
+		$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
+		$course_options = '';
1244
+		foreach( $users_who_can_edit_courses as $user ) {
1245
+			$course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
+		}
1247 1247
 
1248
-        $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
-        $output .= $course_options;
1251
-        $output .= '</select>';
1248
+		$output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
+		$output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
+		$output .= $course_options;
1251
+		$output .= '</select>';
1252 1252
 
1253
-        echo $output;
1254
-    }
1253
+		echo $output;
1254
+	}
1255 1255
 
1256
-    /**
1257
-     * Modify the main query on the admin course list screen
1258
-     *
1259
-     * @since 1.8.0
1260
-     *
1261
-     * @param $query
1262
-     * @return $query
1263
-     */
1264
-    public function teacher_filter_query_modify( $query ){
1265
-        global $typenow;
1256
+	/**
1257
+	 * Modify the main query on the admin course list screen
1258
+	 *
1259
+	 * @since 1.8.0
1260
+	 *
1261
+	 * @param $query
1262
+	 * @return $query
1263
+	 */
1264
+	public function teacher_filter_query_modify( $query ){
1265
+		global $typenow;
1266 1266
 
1267
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
-            return $query;
1269
-        }
1270
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
-
1272
-        if( empty( $course_teacher ) ) {
1273
-            return $query;
1274
-        }
1275
-
1276
-        $query['author'] = $course_teacher;
1277
-        return $query;
1278
-    }
1279
-
1280
-    /**
1281
-     * Only show current teacher's media in the media library
1282
-     * @param  array $request Default request arguments
1283
-     * @return array          Modified request arguments
1284
-     */
1285
-    public function restrict_media_library( $request = array() ) {
1286
-
1287
-        if( ! is_admin() ) {
1288
-            return $request;
1289
-        }
1290
-
1291
-        if( ! $this->is_admin_teacher() ) {
1292
-            return $request;
1293
-        }
1294
-
1295
-        $screen = get_current_screen();
1296
-
1297
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
-            $teacher = intval( get_current_user_id() );
1299
-
1300
-            if( $teacher ) {
1301
-                $request['author__in'] = array( $teacher );
1302
-            }
1303
-        }
1304
-
1305
-        return $request;
1306
-    } // End restrict_media_library()
1307
-
1308
-    /**
1309
-     * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
-     * @param  array $query Default query arguments
1311
-     * @return array        Modified query arguments
1312
-     */
1313
-    public function restrict_media_library_modal( $query = array() ) {
1314
-
1315
-        if( ! is_admin() ) {
1316
-            return $query;
1317
-        }
1318
-
1319
-        if( ! $this->is_admin_teacher() ) {
1320
-            return $query;
1321
-        }
1322
-
1323
-        $teacher = intval( get_current_user_id() );
1324
-
1325
-        if( $teacher ) {
1326
-            $query['author__in'] = array( $teacher );
1327
-        }
1328
-
1329
-        return $query;
1330
-    } // End restrict_media_library_modal()
1331
-
1332
-    /**
1333
-     * When saving the lesson, update the teacher if the lesson belongs to a course
1334
-     *
1335
-     * @since 1.8.0
1336
-     *
1337
-     * @param int $lesson_id
1338
-     */
1339
-    public function update_lesson_teacher( $lesson_id ){
1340
-
1341
-        if( 'lesson'!= get_post_type() ){
1342
-            return;
1343
-        }
1267
+		if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
+			return $query;
1269
+		}
1270
+		$course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
+
1272
+		if( empty( $course_teacher ) ) {
1273
+			return $query;
1274
+		}
1275
+
1276
+		$query['author'] = $course_teacher;
1277
+		return $query;
1278
+	}
1279
+
1280
+	/**
1281
+	 * Only show current teacher's media in the media library
1282
+	 * @param  array $request Default request arguments
1283
+	 * @return array          Modified request arguments
1284
+	 */
1285
+	public function restrict_media_library( $request = array() ) {
1286
+
1287
+		if( ! is_admin() ) {
1288
+			return $request;
1289
+		}
1290
+
1291
+		if( ! $this->is_admin_teacher() ) {
1292
+			return $request;
1293
+		}
1294
+
1295
+		$screen = get_current_screen();
1296
+
1297
+		if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
+			$teacher = intval( get_current_user_id() );
1299
+
1300
+			if( $teacher ) {
1301
+				$request['author__in'] = array( $teacher );
1302
+			}
1303
+		}
1304
+
1305
+		return $request;
1306
+	} // End restrict_media_library()
1307
+
1308
+	/**
1309
+	 * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
+	 * @param  array $query Default query arguments
1311
+	 * @return array        Modified query arguments
1312
+	 */
1313
+	public function restrict_media_library_modal( $query = array() ) {
1314
+
1315
+		if( ! is_admin() ) {
1316
+			return $query;
1317
+		}
1318
+
1319
+		if( ! $this->is_admin_teacher() ) {
1320
+			return $query;
1321
+		}
1322
+
1323
+		$teacher = intval( get_current_user_id() );
1324
+
1325
+		if( $teacher ) {
1326
+			$query['author__in'] = array( $teacher );
1327
+		}
1328
+
1329
+		return $query;
1330
+	} // End restrict_media_library_modal()
1331
+
1332
+	/**
1333
+	 * When saving the lesson, update the teacher if the lesson belongs to a course
1334
+	 *
1335
+	 * @since 1.8.0
1336
+	 *
1337
+	 * @param int $lesson_id
1338
+	 */
1339
+	public function update_lesson_teacher( $lesson_id ){
1340
+
1341
+		if( 'lesson'!= get_post_type() ){
1342
+			return;
1343
+		}
1344 1344
 
1345
-        // this should only run once per request cycle
1346
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1345
+		// this should only run once per request cycle
1346
+		remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1347 1347
 
1348
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1348
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1349 1349
 
1350
-        if(  empty( $course_id ) || ! $course_id ){
1351
-            return;
1352
-        }
1350
+		if(  empty( $course_id ) || ! $course_id ){
1351
+			return;
1352
+		}
1353 1353
 
1354
-        $course = get_post( $course_id );
1354
+		$course = get_post( $course_id );
1355 1355
 
1356
-        $lesson_update_args= array(
1357
-            'ID' => $lesson_id ,
1358
-            'post_author' => $course->post_author
1359
-        );
1360
-        wp_update_post( $lesson_update_args );
1356
+		$lesson_update_args= array(
1357
+			'ID' => $lesson_id ,
1358
+			'post_author' => $course->post_author
1359
+		);
1360
+		wp_update_post( $lesson_update_args );
1361 1361
 
1362
-    } // end update_lesson_teacher
1362
+	} // end update_lesson_teacher
1363 1363
 
1364
-    /**
1365
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
-     *
1367
-     * Limit teachers to only see their courses, lessons and questions
1368
-     *
1369
-     * @since 1.8.0
1370
-     * @access public
1371
-     * @parameters array $wp_query
1372
-     * @return WP_Query $wp_query
1373
-     */
1374
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
-        global $current_user;
1364
+	/**
1365
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
+	 *
1367
+	 * Limit teachers to only see their courses, lessons and questions
1368
+	 *
1369
+	 * @since 1.8.0
1370
+	 * @access public
1371
+	 * @parameters array $wp_query
1372
+	 * @return WP_Query $wp_query
1373
+	 */
1374
+	public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
+		global $current_user;
1376 1376
 
1377
-        //exit early
1378
-        if( ! $this->is_admin_teacher() ){
1379
-            return $wp_query;
1380
-        }
1377
+		//exit early
1378
+		if( ! $this->is_admin_teacher() ){
1379
+			return $wp_query;
1380
+		}
1381 1381
 
1382
-        if ( ! function_exists( 'get_current_screen' ) ) {
1383
-            return $wp_query;
1384
-        }
1382
+		if ( ! function_exists( 'get_current_screen' ) ) {
1383
+			return $wp_query;
1384
+		}
1385 1385
 
1386
-        $screen = get_current_screen();
1386
+		$screen = get_current_screen();
1387 1387
 
1388
-        if( empty( $screen ) ){
1389
-            return $wp_query;
1390
-        }
1388
+		if( empty( $screen ) ){
1389
+			return $wp_query;
1390
+		}
1391 1391
 
1392
-        // for any of these conditions limit what the teacher will see
1393
-        $limit_screens = array(
1394
-            'edit-lesson',
1395
-            'edit-course',
1396
-            'edit-question',
1397
-            'course_page_course-order',
1398
-            'lesson_page_lesson-order',
1399
-        );
1392
+		// for any of these conditions limit what the teacher will see
1393
+		$limit_screens = array(
1394
+			'edit-lesson',
1395
+			'edit-course',
1396
+			'edit-question',
1397
+			'course_page_course-order',
1398
+			'lesson_page_lesson-order',
1399
+		);
1400 1400
 
1401
-        if(  in_array($screen->id  , $limit_screens ) ) {
1401
+		if(  in_array($screen->id  , $limit_screens ) ) {
1402 1402
 
1403
-            // set the query author to the current user to only show those those posts
1404
-            $wp_query->set( 'author', $current_user->ID );
1405
-        }
1403
+			// set the query author to the current user to only show those those posts
1404
+			$wp_query->set( 'author', $current_user->ID );
1405
+		}
1406 1406
 
1407
-        return $wp_query;
1407
+		return $wp_query;
1408 1408
 
1409
-    } // end limit_teacher_edit_screen_post_types()
1409
+	} // end limit_teacher_edit_screen_post_types()
1410 1410
 
1411 1411
 
1412
-    /**
1413
-     * Sensei_Teacher::teacher_login_redirect
1414
-     *
1415
-     * Redirect teachers to /wp-admin/ after login
1416
-     *
1417
-     * @since 1.8.7
1418
-     * @access public
1419
-     * @param string $user_login
1420
-     * @param object $user
1421
-     * @return void
1422
-     */
1412
+	/**
1413
+	 * Sensei_Teacher::teacher_login_redirect
1414
+	 *
1415
+	 * Redirect teachers to /wp-admin/ after login
1416
+	 *
1417
+	 * @since 1.8.7
1418
+	 * @access public
1419
+	 * @param string $user_login
1420
+	 * @param object $user
1421
+	 * @return void
1422
+	 */
1423 1423
 
1424
-    public function teacher_login_redirect( $user_login, $user  ) {
1424
+	public function teacher_login_redirect( $user_login, $user  ) {
1425 1425
 
1426
-        if (user_can($user, 'edit_courses')) {
1426
+		if (user_can($user, 'edit_courses')) {
1427 1427
 
1428
-            if (isset($_POST['redirect_to'])) {
1428
+			if (isset($_POST['redirect_to'])) {
1429 1429
 
1430
-                wp_redirect($_POST['redirect_to'], 303);
1430
+				wp_redirect($_POST['redirect_to'], 303);
1431 1431
 
1432
-                exit;
1432
+				exit;
1433 1433
 
1434
-            } else {
1434
+			} else {
1435 1435
 
1436
-                wp_redirect(admin_url(), 303);
1436
+				wp_redirect(admin_url(), 303);
1437 1437
 
1438
-                exit;
1438
+				exit;
1439 1439
 
1440
-            }
1441
-        }
1440
+			}
1441
+		}
1442 1442
 
1443
-    } // end teacher_login_redirect()
1443
+	} // end teacher_login_redirect()
1444 1444
 
1445 1445
 
1446 1446
 
1447
-    /**
1448
-     * Sensei_Teacher::restrict_posts_menu_page()
1449
-     *
1450
-     * Remove the Posts menu page for teachers and restrict access to it.
1451
-     * We have to do this because we give teachers the 'edit_posts' cap
1452
-     * so they can 'moderate_comments' as well.
1453
-     *
1454
-     * @since 1.8.7
1455
-     * @access public
1456
-     * @parameters void
1457
-     * @return void
1458
-     */
1447
+	/**
1448
+	 * Sensei_Teacher::restrict_posts_menu_page()
1449
+	 *
1450
+	 * Remove the Posts menu page for teachers and restrict access to it.
1451
+	 * We have to do this because we give teachers the 'edit_posts' cap
1452
+	 * so they can 'moderate_comments' as well.
1453
+	 *
1454
+	 * @since 1.8.7
1455
+	 * @access public
1456
+	 * @parameters void
1457
+	 * @return void
1458
+	 */
1459 1459
 
1460
-    public function restrict_posts_menu_page() {
1460
+	public function restrict_posts_menu_page() {
1461 1461
 
1462
-        global $pagenow, $typenow;
1462
+		global $pagenow, $typenow;
1463 1463
 
1464
-        $user = wp_get_current_user();
1464
+		$user = wp_get_current_user();
1465 1465
 
1466
-        /**
1467
-         * Filter the option to hide the Posts menu page.
1468
-         *
1469
-         * @since 1.8.7
1470
-         *
1471
-         * @param bool $restrict default true
1472
-         */
1466
+		/**
1467
+		 * Filter the option to hide the Posts menu page.
1468
+		 *
1469
+		 * @since 1.8.7
1470
+		 *
1471
+		 * @param bool $restrict default true
1472
+		 */
1473 1473
 
1474
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1474
+		$restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1475 1475
 
1476
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1476
+		if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1477 1477
 
1478
-            remove_menu_page('edit.php');
1478
+			remove_menu_page('edit.php');
1479 1479
 
1480
-            if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1480
+			if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1481 1481
 
1482
-                if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1482
+				if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1483 1483
 
1484
-                    wp_die('You do not have sufficient permissions to access this page.');
1484
+					wp_die('You do not have sufficient permissions to access this page.');
1485 1485
 
1486
-                }
1486
+				}
1487 1487
 
1488
-            }
1488
+			}
1489 1489
 
1490
-        }
1490
+		}
1491 1491
 
1492
-    } // end restrict_posts_menu_page()
1492
+	} // end restrict_posts_menu_page()
1493 1493
 
1494
-    /**
1495
-     * Sensei_Teacher::restrict_comment_moderation()
1496
-     *
1497
-     * Restrict commendation moderation for teachers
1498
-     * so they can only moderate comments made to posts they own.
1499
-     *
1500
-     * @since 1.8.7
1501
-     * @access public
1502
-     * @parameters obj $clauses
1503
-     * @return WP_Comment_Query  $clauses
1504
-     */
1494
+	/**
1495
+	 * Sensei_Teacher::restrict_comment_moderation()
1496
+	 *
1497
+	 * Restrict commendation moderation for teachers
1498
+	 * so they can only moderate comments made to posts they own.
1499
+	 *
1500
+	 * @since 1.8.7
1501
+	 * @access public
1502
+	 * @parameters obj $clauses
1503
+	 * @return WP_Comment_Query  $clauses
1504
+	 */
1505 1505
 
1506
-    public function restrict_comment_moderation ( $clauses ) {
1506
+	public function restrict_comment_moderation ( $clauses ) {
1507 1507
 
1508
-        global $pagenow;
1508
+		global $pagenow;
1509 1509
 
1510
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1510
+		if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1511 1511
 
1512
-            $clauses->query_vars['post_author'] = get_current_user_id();
1512
+			$clauses->query_vars['post_author'] = get_current_user_id();
1513 1513
 
1514
-        }
1514
+		}
1515 1515
 
1516
-        return $clauses;
1516
+		return $clauses;
1517 1517
 
1518
-    }   // end restrict_comment_moderation()
1518
+	}   // end restrict_comment_moderation()
1519 1519
 
1520
-    /**
1521
-     * Determine if a user is a teacher by ID
1522
-     *
1523
-     * @param int $user_id
1524
-     *
1525
-     * @return bool
1526
-     */
1527
-    public static function is_a_teacher( $user_id ){
1520
+	/**
1521
+	 * Determine if a user is a teacher by ID
1522
+	 *
1523
+	 * @param int $user_id
1524
+	 *
1525
+	 * @return bool
1526
+	 */
1527
+	public static function is_a_teacher( $user_id ){
1528 1528
 
1529
-        $user = get_user_by('id', $user_id);
1529
+		$user = get_user_by('id', $user_id);
1530 1530
 
1531
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1531
+		if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1532 1532
 
1533
-            return true;
1533
+			return true;
1534 1534
 
1535
-        }else{
1535
+		}else{
1536 1536
 
1537
-            return false;
1537
+			return false;
1538 1538
 
1539
-        }
1539
+		}
1540 1540
 
1541
-    }// end is_a_teacher
1541
+	}// end is_a_teacher
1542 1542
 
1543
-    /**
1544
-     * The archive title on the teacher archive filter
1545
-     *
1546
-     * @since 1.9.0
1547
-     */
1548
-    public static function archive_title(){
1543
+	/**
1544
+	 * The archive title on the teacher archive filter
1545
+	 *
1546
+	 * @since 1.9.0
1547
+	 */
1548
+	public static function archive_title(){
1549 1549
 
1550
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1551
-        $author_name = $author->display_name;
1552
-        ?>
1550
+		$author = get_user_by( 'id', get_query_var( 'author' ) );
1551
+		$author_name = $author->display_name;
1552
+		?>
1553 1553
             <h2 class="teacher-archive-title">
1554 1554
 
1555 1555
                 <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
@@ -1557,17 +1557,17 @@  discard block
 block discarded – undo
1557 1557
             </h2>
1558 1558
         <?php
1559 1559
 
1560
-    }// archive title
1560
+	}// archive title
1561 1561
 
1562
-    /**
1563
-     * Removing course meta on the teacher archive page
1564
-     *
1565
-     * @since 1.9.0
1566
-     */
1567
-    public static function remove_course_meta_on_teacher_archive(){
1562
+	/**
1563
+	 * Removing course meta on the teacher archive page
1564
+	 *
1565
+	 * @since 1.9.0
1566
+	 */
1567
+	public static function remove_course_meta_on_teacher_archive(){
1568 1568
 
1569
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1569
+		remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1570 1570
 
1571
-    }
1571
+	}
1572 1572
 
1573 1573
 } // End Class
Please login to merge, or discard this patch.
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-lesson.php 1 patch
Indentation   +1027 added lines, -1027 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function __construct () {
23 23
 
24
-        $this->token = 'lesson';
24
+		$this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27 27
 		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
28 28
 
29
-        $this->question_order = '';
29
+		$this->question_order = '';
30 30
 
31 31
 		// Admin actions
32 32
 		if ( is_admin() ) {
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
 			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85 85
 			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
86 86
 
87
-            // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
87
+			// output bulk edit fields
88
+			add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
+			add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
90 90
 
91
-            // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
91
+			// load quick edit default values
92
+			add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94
-            // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
94
+			// save bulk edit fields
95
+			add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
96 96
 
97
-            // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
97
+			// flush rewrite rules when saving a lesson
98
+			add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		$post_args = array(	'post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192
-    						'order'           	=> 'ASC',
193
-    						'exclude' 			=> $post->ID,
192
+							'order'           	=> 'ASC',
193
+							'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196 196
 		$posts_array = get_posts( $post_args );
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		$checked = '';
228 228
 		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
229
+	 		$checked = checked( 'preview', $lesson_preview, false );
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
 
277 277
 	/**
278
-     * Update the lesson quiz and all the post meta
278
+	 * Update the lesson quiz and all the post meta
279 279
 	 *
280 280
 	 * @access public
281 281
 	 * @return integer|boolean $post_id or false
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 		}
297 297
 
298 298
 		// Temporarily disable the filter
299
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
299
+		remove_action( 'save_post', array( $this, 'quiz_update' ) );
300 300
 		// Save the Quiz
301 301
 		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
302 302
 
@@ -311,11 +311,11 @@  discard block
 block discarded – undo
311 311
 
312 312
 		// Setup Query Arguments
313 313
 		$post_type_args = array(	'post_content' => $post_content,
314
-  		    						'post_status' => $post_status,
315
-  		    						'post_title' => $post_title,
316
-  		    						'post_type' => 'quiz',
317
-                                    'post_parent' => $post_id,
318
-  		    						);
314
+  									'post_status' => $post_status,
315
+  									'post_title' => $post_title,
316
+  									'post_type' => 'quiz',
317
+									'post_parent' => $post_id,
318
+  									);
319 319
 
320 320
 		$settings = $this->get_quiz_settings();
321 321
 
@@ -323,48 +323,48 @@  discard block
 block discarded – undo
323 323
 		if ( 0 < $quiz_id ) {
324 324
 			// Update the Quiz
325 325
 			$post_type_args[ 'ID' ] = $quiz_id;
326
-		    wp_update_post($post_type_args);
327
-
328
-		    // Update the post meta data
329
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
330
-
331
-		    foreach( $settings as $field ) {
332
-		    	if( 'random_question_order' != $field['id'] ) {
333
-			    	$value = $this->get_submitted_setting_value( $field );
334
-			    	if( isset( $value ) ) {
335
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
336
-			    	}
337
-			    }
338
-		    }
339
-
340
-		    // Set the post terms for quiz-type
341
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
326
+			wp_update_post($post_type_args);
327
+
328
+			// Update the post meta data
329
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
330
+
331
+			foreach( $settings as $field ) {
332
+				if( 'random_question_order' != $field['id'] ) {
333
+					$value = $this->get_submitted_setting_value( $field );
334
+					if( isset( $value ) ) {
335
+						update_post_meta( $quiz_id, '_' . $field['id'], $value );
336
+					}
337
+				}
338
+			}
339
+
340
+			// Set the post terms for quiz-type
341
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
342 342
 		} else {
343 343
 			// Create the Quiz
344
-		    $quiz_id = wp_insert_post($post_type_args);
345
-
346
-		    // Add the post meta data WP will add it if it doesn't exist
347
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
348
-
349
-		    foreach( $settings as $field ) {
350
-		    	if( 'random_question_order' != $field['id'] ) {
351
-
352
-                    //ignore values not posted to avoid
353
-                    // overwriting with empty or default values
354
-                    // when the values are posted from bulk edit or quick edit
355
-                    if( !isset( $_POST[ $field['id'] ] ) ){
356
-                        continue;
357
-                    }
358
-
359
-			    	$value = $this->get_submitted_setting_value( $field );
360
-			    	if( isset( $value ) ) {
361
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
362
-			    	}
363
-			    }
364
-		    }
365
-
366
-		    // Set the post terms for quiz-type
367
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
344
+			$quiz_id = wp_insert_post($post_type_args);
345
+
346
+			// Add the post meta data WP will add it if it doesn't exist
347
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
348
+
349
+			foreach( $settings as $field ) {
350
+				if( 'random_question_order' != $field['id'] ) {
351
+
352
+					//ignore values not posted to avoid
353
+					// overwriting with empty or default values
354
+					// when the values are posted from bulk edit or quick edit
355
+					if( !isset( $_POST[ $field['id'] ] ) ){
356
+						continue;
357
+					}
358
+
359
+					$value = $this->get_submitted_setting_value( $field );
360
+					if( isset( $value ) ) {
361
+						add_post_meta( $quiz_id, '_' . $field['id'], $value );
362
+					}
363
+				}
364
+			}
365
+
366
+			// Set the post terms for quiz-type
367
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
368 368
 		} // End If Statement
369 369
 
370 370
 		// Add default lesson order meta value
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		}
387 387
 
388 388
 		// Restore the previously disabled filter
389
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
389
+		add_action( 'save_post', array( $this, 'quiz_update' ) );
390 390
 
391 391
 	} // End post_updated()
392 392
 
@@ -426,22 +426,22 @@  discard block
 block discarded – undo
426 426
 		// Get the meta key.
427 427
 		$meta_key = '_' . $post_key;
428 428
 
429
-        //ignore fields are not posted
429
+		//ignore fields are not posted
430 430
 
431
-        if( !isset( $_POST[ $post_key ] ) ){
431
+		if( !isset( $_POST[ $post_key ] ) ){
432 432
 
433
-            // except for lesson preview checkbox field
434
-            if( 'lesson_preview' == $post_key ){
433
+			// except for lesson preview checkbox field
434
+			if( 'lesson_preview' == $post_key ){
435 435
 
436
-                $_POST[ $post_key ] = '';
436
+				$_POST[ $post_key ] = '';
437 437
 
438
-            } else {
438
+			} else {
439 439
 
440
-                return false;
440
+				return false;
441 441
 
442
-            }
442
+			}
443 443
 
444
-        }
444
+		}
445 445
 
446 446
 		// Get the posted data and sanitize it for use as an HTML class.
447 447
 		if ( 'lesson_video_embed' == $post_key) {
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
451 451
 		} // End If Statement
452 452
 
453
-        // update field with the new value
454
-        if( -1 != $new_meta_value  ){
455
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
456
-        }
453
+		// update field with the new value
454
+		if( -1 != $new_meta_value  ){
455
+			return update_post_meta( $post_id, $meta_key, $new_meta_value );
456
+		}
457 457
 
458 458
 	} // End save_post_meta()
459 459
 
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 		$post_args = array(	'post_type' 		=> 'course',
479 479
 							'posts_per_page' 		=> -1,
480 480
 							'orderby'         	=> 'title',
481
-    						'order'           	=> 'ASC',
482
-    						'post_status'      	=> 'any',
483
-    						'suppress_filters' 	=> 0,
481
+							'order'           	=> 'ASC',
482
+							'post_status'      	=> 'any',
483
+							'suppress_filters' 	=> 0,
484 484
 							);
485 485
 		$posts_array = get_posts( $post_args );
486 486
 		// Buid the HTML to Output
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
 		// Nonce
489 489
 		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
490 490
 
491
-        // Select the course for the lesson
492
-        $drop_down_args = array(
493
-            'name'=>'lesson_course',
494
-            'id' => 'lesson-course-options'
495
-        );
491
+		// Select the course for the lesson
492
+		$drop_down_args = array(
493
+			'name'=>'lesson_course',
494
+			'id' => 'lesson-course-options'
495
+		);
496 496
 
497
-        $courses = WooThemes_Sensei_Course::get_all_courses();
498
-        $courses_options = array();
499
-        foreach( $courses as $course ){
500
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
501
-        }
502
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
497
+		$courses = WooThemes_Sensei_Course::get_all_courses();
498
+		$courses_options = array();
499
+		foreach( $courses as $course ){
500
+			$courses_options[ $course->ID ] = get_the_title( $course ) ;
501
+		}
502
+		$html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
503 503
 
504
-        // Course Actions Panel
504
+		// Course Actions Panel
505 505
 		if ( current_user_can( 'publish_courses' )) {
506 506
 				$html .= '<div id="lesson-course-actions">';
507 507
 					$html .= '<p>';
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
 							} // End For Loop
528 528
 						$html .= '</select>' . "\n";
529 529
 						// Course Product
530
-                        if ( Sensei_WC::is_woocommerce_active() ) {
530
+						if ( Sensei_WC::is_woocommerce_active() ) {
531 531
 	  						// Get the Products
532 532
 							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
533 533
 
534 534
 							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
535 535
 													'posts_per_page' 		=> -1,
536 536
 													'orderby'         	=> 'title',
537
-	    											'order'           	=> 'DESC',
538
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
539
-	    											'tax_query'			=> array(
537
+													'order'           	=> 'DESC',
538
+													'post_status'		=> array( 'publish', 'private', 'draft' ),
539
+													'tax_query'			=> array(
540 540
 														array(
541 541
 															'taxonomy'	=> 'product_type',
542 542
 															'field'		=> 'slug',
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
 															'operator'	=> 'NOT IN'
545 545
 														)
546 546
 													),
547
-	    											'suppress_filters' 	=> 0
547
+													'suppress_filters' 	=> 0
548 548
 													);
549 549
 							$products_array = get_posts( $product_args );
550 550
 							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
@@ -872,58 +872,58 @@  discard block
 block discarded – undo
872 872
 					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
873 873
 						$html .= '<td colspan="5">';
874 874
 							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
875
-					    	$html .= '<div class="question_required_fields">';
876
-
877
-						    	// Question title
878
-						    	$html .= '<div>';
879
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
880
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
881
-						    	$html .= '</div>';
882
-
883
-						    	// Question description
884
-						    	$html .= '<div>';
885
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
886
-						    	$html .= '</div>';
887
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
888
-
889
-						    	// Question grade
890
-						    	$html .= '<div>';
891
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
892
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
893
-						    	$html .= '</div>';
894
-
895
-						    	// Random order
896
-						    	if( $question_type == 'multiple-choice' ) {
897
-						    		$html .= '<div>';
898
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
899
-						    		$html .= '</div>';
900
-						    	}
901
-
902
-						    	// Question media
903
-						    	$html .= '<div>';
904
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
905
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
906
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
907
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
908
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
909
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
910
-						    	$html .= '</div>';
911
-
912
-						    $html .= '</div>';
913
-
914
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
915
-
916
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
875
+							$html .= '<div class="question_required_fields">';
876
+
877
+								// Question title
878
+								$html .= '<div>';
879
+									$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
880
+									$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
881
+								$html .= '</div>';
882
+
883
+								// Question description
884
+								$html .= '<div>';
885
+									$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
886
+								$html .= '</div>';
887
+									$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
888
+
889
+								// Question grade
890
+								$html .= '<div>';
891
+									$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
892
+									$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
893
+								$html .= '</div>';
894
+
895
+								// Random order
896
+								if( $question_type == 'multiple-choice' ) {
897
+									$html .= '<div>';
898
+										$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
899
+									$html .= '</div>';
900
+								}
901
+
902
+								// Question media
903
+								$html .= '<div>';
904
+									$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
905
+									$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
906
+									$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
907
+									$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
908
+									$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
909
+									$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
910
+								$html .= '</div>';
911
+
912
+							$html .= '</div>';
913
+
914
+							$html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
915
+
916
+							$html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
917 917
 							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
918 918
 
919 919
 							if( 'quiz' == $context ) {
920
-					    		$html .= '<div class="update-question">';
921
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
922
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
923
-					    		$html .= '</div>';
924
-					    	}
920
+								$html .= '<div class="update-question">';
921
+									$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
922
+									$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
923
+								$html .= '</div>';
924
+							}
925 925
 
926
-			    		$html .= '</td>';
926
+						$html .= '</td>';
927 927
 					$html .= '</tr>';
928 928
 				}
929 929
 
@@ -944,20 +944,20 @@  discard block
 block discarded – undo
944 944
 			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
945 945
 
946 946
 			if( 'quiz' == $context ) {
947
-	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
948
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
949
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
950
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
951
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
952
-	    			}
953
-	    		$html .= '</h2>';
954
-	    	}
947
+				$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
948
+					$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
949
+					$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
950
+					if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
951
+						$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
952
+					}
953
+				$html .= '</h2>';
954
+			}
955 955
 
956
-	    	$html .= '<div class="tab-content" id="tab-new-content">';
956
+			$html .= '<div class="tab-content" id="tab-new-content">';
957 957
 
958
-	    		if( 'quiz' == $context ) {
959
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
960
-	    		}
958
+				if( 'quiz' == $context ) {
959
+					$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
960
+				}
961 961
 
962 962
 				$html .= '<div class="question">';
963 963
 					$html .= '<div class="question_required_fields">';
@@ -999,18 +999,18 @@  discard block
 block discarded – undo
999 999
 
1000 1000
 						// Random order
1001 1001
 						$html .= '<p class="add_question_random_order">';
1002
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1003
-			    		$html .= '</p>';
1002
+							$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1003
+						$html .= '</p>';
1004 1004
 
1005
-			    		// Question media
1005
+						// Question media
1006 1006
 						$html .= '<p>';
1007
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1008
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1009
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1010
-					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1011
-					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1012
-					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1013
-				    	$html .= '</p>';
1007
+							$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1008
+							$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1009
+							$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1010
+							$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1011
+							$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1012
+							$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1013
+						$html .= '</p>';
1014 1014
 
1015 1015
 					$html .= '</div>';
1016 1016
 				$html .= '</div>';
@@ -1021,19 +1021,19 @@  discard block
 block discarded – undo
1021 1021
 
1022 1022
 				if( 'quiz' == $context ) {
1023 1023
 					$html .= '<div class="add-question">';
1024
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1025
-		    		$html .= '</div>';
1026
-		    	}
1024
+						$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1025
+					$html .= '</div>';
1026
+				}
1027 1027
 
1028
-		    $html .= '</div>';
1028
+			$html .= '</div>';
1029 1029
 
1030
-		    if( 'quiz' == $context ) {
1030
+			if( 'quiz' == $context ) {
1031 1031
 
1032
-			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1032
+				$html .= '<div class="tab-content hidden" id="tab-existing-content">';
1033 1033
 
1034
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1034
+					$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1035 1035
 
1036
-			    	$html .= '<div id="existing-filters" class="alignleft actions">
1036
+					$html .= '<div id="existing-filters" class="alignleft actions">
1037 1037
 			    				<select id="existing-status">
1038 1038
 			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1039 1039
 			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
@@ -1041,23 +1041,23 @@  discard block
 block discarded – undo
1041 1041
 			    				</select>
1042 1042
 			    				<select id="existing-type">
1043 1043
 			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1044
-							    	foreach ( $question_types as $type => $label ) {
1044
+									foreach ( $question_types as $type => $label ) {
1045 1045
 										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1046 1046
 									}
1047
-    				$html .= '</select>
1047
+					$html .= '</select>
1048 1048
     							<select id="existing-category">
1049 1049
 			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1050
-				    				foreach( $question_cats as $cat ) {
1050
+									foreach( $question_cats as $cat ) {
1051 1051
 										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1052 1052
 									}
1053
-    				$html .= '</select>
1053
+					$html .= '</select>
1054 1054
     							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1055 1055
     							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1056 1056
 			    			</div>';
1057 1057
 
1058
-			    	$html .= '<table id="existing-table" class="widefat">';
1058
+					$html .= '<table id="existing-table" class="widefat">';
1059 1059
 
1060
-			    		$html .= '<thead>
1060
+						$html .= '<thead>
1061 1061
 									    <tr>
1062 1062
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1063 1063
 									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
@@ -1085,28 +1085,28 @@  discard block
 block discarded – undo
1085 1085
 
1086 1086
 						$html .= '</tbody>';
1087 1087
 
1088
-			    	$html .= '</table>';
1088
+					$html .= '</table>';
1089 1089
 
1090
-			    	$next_class = '';
1091
-			    	if( $questions['count'] <= 10 ) {
1092
-			    		$next_class = 'hidden';
1093
-			    	}
1090
+					$next_class = '';
1091
+					if( $questions['count'] <= 10 ) {
1092
+						$next_class = 'hidden';
1093
+					}
1094 1094
 
1095
-			    	$html .= '<div id="existing-pagination">';
1096
-			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1097
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1098
-			    	$html .= '</div>';
1095
+					$html .= '<div id="existing-pagination">';
1096
+						$html .= '<input type="hidden" id="existing-page" value="1" />';
1097
+						$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1098
+					$html .= '</div>';
1099 1099
 
1100
-			    	$html .= '<div class="existing-actions">';
1101
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1102
-			    	$html .= '</div>';
1100
+					$html .= '<div class="existing-actions">';
1101
+						$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1102
+					$html .= '</div>';
1103 1103
 
1104
-			    $html .= '</div>';
1104
+				$html .= '</div>';
1105 1105
 
1106
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1107
-				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1106
+				if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1107
+					$html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1108 1108
 
1109
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1109
+						$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1110 1110
 
1111 1111
 						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1112 1112
 						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
@@ -1119,7 +1119,7 @@  discard block
 block discarded – undo
1119 1119
 
1120 1120
 						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1121 1121
 
1122
-				    $html .= '</div>';
1122
+					$html .= '</div>';
1123 1123
 				}
1124 1124
 			}
1125 1125
 
@@ -1192,14 +1192,14 @@  discard block
 block discarded – undo
1192 1192
 
1193 1193
 		$qry = new WP_Query( $args );
1194 1194
 
1195
-        /**
1196
-         * Filter existing questions query
1197
-         *
1198
-         * @since 1.8.0
1199
-         *
1200
-         * @param WP_Query $wp_query
1201
-         */
1202
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1195
+		/**
1196
+		 * Filter existing questions query
1197
+		 *
1198
+		 * @since 1.8.0
1199
+		 *
1200
+		 * @param WP_Query $wp_query
1201
+		 */
1202
+		$qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1203 1203
 
1204 1204
 		$questions['questions'] = $qry->posts;
1205 1205
 		$questions['count'] = intval( $qry->found_posts );
@@ -1214,14 +1214,14 @@  discard block
 block discarded – undo
1214 1214
 
1215 1215
 		if( ! $question_id ) {
1216 1216
 
1217
-            return;
1217
+			return;
1218 1218
 
1219
-        }
1219
+		}
1220 1220
 
1221 1221
 		$existing_class = '';
1222 1222
 		if( $row % 2 ) {
1223
-            $existing_class = 'alternate';
1224
-        }
1223
+			$existing_class = 'alternate';
1224
+		}
1225 1225
 
1226 1226
 		$question_type = Sensei()->question->get_question_type( $question_id );
1227 1227
 
@@ -1355,67 +1355,67 @@  discard block
 block discarded – undo
1355 1355
 							}
1356 1356
 						}
1357 1357
 
1358
-				    	// Calculate total wrong answers available (defaults to 4)
1359
-				    	$total_wrong = 0;
1360
-				    	if( $question_id ) {
1361
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1362
-				    	}
1363
-				    	if( 0 == intval( $total_wrong ) ) {
1364
-				    		$total_wrong = 1;
1365
-				    	}
1358
+						// Calculate total wrong answers available (defaults to 4)
1359
+						$total_wrong = 0;
1360
+						if( $question_id ) {
1361
+							$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1362
+						}
1363
+						if( 0 == intval( $total_wrong ) ) {
1364
+							$total_wrong = 1;
1365
+						}
1366 1366
 
1367
-                        // Setup Wrong Answer HTML
1368
-                        foreach ( $wrong_answers as $i => $answer ){
1367
+						// Setup Wrong Answer HTML
1368
+						foreach ( $wrong_answers as $i => $answer ){
1369 1369
 
1370
-                            $answer_id = $this->get_answer_id( $answer );
1371
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1372
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1373
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1374
-                            if( $question_id ) {
1370
+							$answer_id = $this->get_answer_id( $answer );
1371
+							$wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1372
+							$wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1373
+							$wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1374
+							if( $question_id ) {
1375 1375
 
1376
-                                $answers[ $answer_id ] = $wrong_answer;
1376
+								$answers[ $answer_id ] = $wrong_answer;
1377 1377
 
1378
-                            } else {
1378
+							} else {
1379 1379
 
1380
-                                $answers[] = $wrong_answer;
1380
+								$answers[] = $wrong_answer;
1381 1381
 
1382
-                            }
1382
+							}
1383 1383
 
1384
-                        } // end for each
1384
+						} // end for each
1385 1385
 
1386
-				    	$answers_sorted = $answers;
1387
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1388
-				    		$answers_sorted = array();
1389
-				    		foreach( $answer_order as $answer_id ) {
1390
-				    			if( isset( $answers[ $answer_id ] ) ) {
1391
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1392
-				    				unset( $answers[ $answer_id ] );
1393
-				    			}
1394
-				    		}
1386
+						$answers_sorted = $answers;
1387
+						if( $question_id && count( $answer_order ) > 0 ) {
1388
+							$answers_sorted = array();
1389
+							foreach( $answer_order as $answer_id ) {
1390
+								if( isset( $answers[ $answer_id ] ) ) {
1391
+									$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1392
+									unset( $answers[ $answer_id ] );
1393
+								}
1394
+							}
1395 1395
 
1396
-				    		if( count( $answers ) > 0 ) {
1397
-						    	foreach( $answers as $id => $answer ) {
1398
-						    		$answers_sorted[ $id ] = $answer;
1399
-						    	}
1400
-						    }
1401
-				    	}
1396
+							if( count( $answers ) > 0 ) {
1397
+								foreach( $answers as $id => $answer ) {
1398
+									$answers_sorted[ $id ] = $answer;
1399
+								}
1400
+							}
1401
+						}
1402 1402
 
1403 1403
 						foreach( $answers_sorted as $id => $answer ) {
1404
-				    		$html .= $answer;
1405
-				    	}
1404
+							$html .= $answer;
1405
+						}
1406 1406
 
1407
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1408
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1409
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1407
+						$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1408
+						$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1409
+						$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1410 1410
 
1411
-				    	$html .= '<div class="add_answer_options">';
1412
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1413
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1414
-				    	$html .= '</div>';
1411
+						$html .= '<div class="add_answer_options">';
1412
+							$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1413
+							$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1414
+						$html .= '</div>';
1415 1415
 
1416
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1416
+						$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1417 1417
 
1418
-			    	$html .= '</div>';
1418
+					$html .= '</div>';
1419 1419
 				break;
1420 1420
 				case 'boolean':
1421 1421
 					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1429 1429
 						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1430 1430
 
1431
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1431
+					$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1432 1432
 
1433 1433
 					$html .= '</div>';
1434 1434
 				break;
@@ -1503,17 +1503,17 @@  discard block
 block discarded – undo
1503 1503
 
1504 1504
 	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1505 1505
 
1506
-        // default field name
1507
-        $field_name = 'answer_feedback';
1508
-        if( 'boolean' == $question_type ){
1506
+		// default field name
1507
+		$field_name = 'answer_feedback';
1508
+		if( 'boolean' == $question_type ){
1509 1509
 
1510
-            $field_name = 'answer_feedback_boolean';
1510
+			$field_name = 'answer_feedback_boolean';
1511 1511
 
1512
-        }elseif( 'multiple-choice' == $question_type ){
1512
+		}elseif( 'multiple-choice' == $question_type ){
1513 1513
 
1514
-            $field_name = 'answer_feedback_multiple_choice';
1514
+			$field_name = 'answer_feedback_multiple_choice';
1515 1515
 
1516
-        }// end if
1516
+		}// end if
1517 1517
 
1518 1518
 		if( $question_counter ) {
1519 1519
 			$field_name = 'answer_' . $question_counter . '_feedback';
@@ -1718,15 +1718,15 @@  discard block
 block discarded – undo
1718 1718
 			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1719 1719
 
1720 1720
 			// Load the lessons script
1721
-            wp_enqueue_media();
1721
+			wp_enqueue_media();
1722 1722
 			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1723 1723
 			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1724 1724
 			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1725 1725
 
1726
-            // Load the bulk edit screen script
1727
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1728
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1729
-            }
1726
+			// Load the bulk edit screen script
1727
+			if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1728
+				wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1729
+			}
1730 1730
 
1731 1731
 			// Localise script
1732 1732
 			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
@@ -2029,12 +2029,12 @@  discard block
 block discarded – undo
2029 2029
 
2030 2030
 					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2031 2031
 					if( ! in_array( $quiz_id, $quizzes ) ) {
2032
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2032
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2033 2033
 						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2034 2034
 						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2035
-			    	}
2035
+					}
2036 2036
 
2037
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2037
+					add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2038 2038
 					$question_type = Sensei()->question->get_question_type( $question_id );
2039 2039
 
2040 2040
 					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
@@ -2140,34 +2140,34 @@  discard block
 block discarded – undo
2140 2140
 		$post_content = $course_content;
2141 2141
 		// Course Query Arguments
2142 2142
 		$post_type_args = array(	'post_content' => $post_content,
2143
-  		    						'post_status' => $post_status,
2144
-  		    						'post_title' => $post_title,
2145
-  		    						'post_type' => $post_type
2146
-  		    						);
2143
+  									'post_status' => $post_status,
2144
+  									'post_title' => $post_title,
2145
+  									'post_type' => $post_type
2146
+  									);
2147 2147
   		// Only save if there is a valid title
2148 2148
   		if ( $post_title != '' ) {
2149
-  		    // Check for prerequisite courses & product id
2150
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2151
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2152
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2153
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2154
-  		    // Insert or Update the Lesson Quiz
2155
-		    if ( 0 < $course_id ) {
2156
-		    	$post_type_args[ 'ID' ] = $course_id;
2157
-		    	$course_id = wp_update_post($post_type_args);
2158
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2159
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2160
-		    	if ( 0 < $course_category_id ) {
2161
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2162
-		    	} // End If Statement
2163
-		    } else {
2164
-		    	$course_id = wp_insert_post($post_type_args);
2165
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2166
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2167
-		    	if ( 0 < $course_category_id ) {
2168
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2169
-		    	} // End If Statement
2170
-		    } // End If Statement
2149
+  			// Check for prerequisite courses & product id
2150
+  			$course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2151
+  			$course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2152
+  			$course_category_id = absint( $data[ 'course_category' ] );
2153
+  			if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2154
+  			// Insert or Update the Lesson Quiz
2155
+			if ( 0 < $course_id ) {
2156
+				$post_type_args[ 'ID' ] = $course_id;
2157
+				$course_id = wp_update_post($post_type_args);
2158
+				update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2159
+				update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2160
+				if ( 0 < $course_category_id ) {
2161
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2162
+				} // End If Statement
2163
+			} else {
2164
+				$course_id = wp_insert_post($post_type_args);
2165
+				add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2166
+				add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2167
+				if ( 0 < $course_category_id ) {
2168
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2169
+				} // End If Statement
2170
+			} // End If Statement
2171 2171
 		} // End If Statement
2172 2172
   		// Check that the insert or update saved by testing the post id
2173 2173
   		if ( 0 < $course_id ) {
@@ -2258,17 +2258,17 @@  discard block
 block discarded – undo
2258 2258
 		$answer_feedback = '';
2259 2259
 		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2260 2260
 
2261
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2261
+			$answer_feedback = $data[ 'answer_feedback_boolean' ];
2262 2262
 
2263 2263
 		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2264 2264
 
2265
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2265
+			$answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2266 2266
 
2267
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2267
+		}elseif( isset( $data[ 'answer_feedback' ] )  ){
2268 2268
 
2269
-            $answer_feedback = $data[ 'answer_feedback' ];
2269
+			$answer_feedback = $data[ 'answer_feedback' ];
2270 2270
 
2271
-        } // End If Statement
2271
+		} // End If Statement
2272 2272
 
2273 2273
 		$post_title = $question_text;
2274 2274
 		$post_author = $data[ 'post_author' ];
@@ -2283,10 +2283,10 @@  discard block
 block discarded – undo
2283 2283
 		}
2284 2284
 		// Question Query Arguments
2285 2285
 		$post_type_args = array(	'post_content' => $post_content,
2286
-  		    						'post_status' => $post_status,
2287
-  		    						'post_title' => $post_title,
2288
-  		    						'post_type' => $post_type
2289
-  		    						);
2286
+  									'post_status' => $post_status,
2287
+  									'post_title' => $post_title,
2288
+  									'post_type' => $post_type
2289
+  									);
2290 2290
 
2291 2291
   		// Remove empty values and reindex the array
2292 2292
   		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
@@ -2322,14 +2322,14 @@  discard block
 block discarded – undo
2322 2322
   		if ( $post_title != '' ) {
2323 2323
 
2324 2324
   			// Get Quiz ID for the question
2325
-  		    $quiz_id = $data['quiz_id'];
2325
+  			$quiz_id = $data['quiz_id'];
2326 2326
 
2327
-  		    // Get question media
2327
+  			// Get question media
2328 2328
 			$question_media = $data['question_media'];
2329 2329
 
2330
-  		    // Get answer order
2331
-  		    $answer_order = '';
2332
-  		    if( isset( $data['answer_order'] ) ) {
2330
+  			// Get answer order
2331
+  			$answer_order = '';
2332
+  			if( isset( $data['answer_order'] ) ) {
2333 2333
 				$answer_order = $data['answer_order'];
2334 2334
 			}
2335 2335
 
@@ -2339,38 +2339,38 @@  discard block
 block discarded – undo
2339 2339
 				$random_order = $data['random_order'];
2340 2340
 			}
2341 2341
 
2342
-  		    // Insert or Update the question
2343
-  		    if ( 0 < $question_id ) {
2344
-
2345
-  		    	$post_type_args[ 'ID' ] = $question_id;
2346
-		    	$question_id = wp_update_post( $post_type_args );
2347
-
2348
-		    	// Update poast meta
2349
-		    	if( 'quiz' == $context ) {
2350
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2351
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2352
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2353
-			    	}
2354
-		    	}
2355
-
2356
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2357
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2358
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2359
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2360
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2361
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2362
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2363
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2364
-
2365
-		    	if( 'quiz' != $context ) {
2366
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2367
-		    	}
2342
+  			// Insert or Update the question
2343
+  			if ( 0 < $question_id ) {
2344
+
2345
+  				$post_type_args[ 'ID' ] = $question_id;
2346
+				$question_id = wp_update_post( $post_type_args );
2347
+
2348
+				// Update poast meta
2349
+				if( 'quiz' == $context ) {
2350
+					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2351
+					if( ! in_array( $quiz_id, $quizzes ) ) {
2352
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2353
+					}
2354
+				}
2355
+
2356
+				update_post_meta( $question_id, '_question_grade', $question_grade );
2357
+				update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2358
+				update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2359
+				update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2360
+				update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2361
+				update_post_meta( $question_id, '_question_media', $question_media );
2362
+				update_post_meta( $question_id, '_answer_order', $answer_order );
2363
+				update_post_meta( $question_id, '_random_order', $random_order );
2364
+
2365
+				if( 'quiz' != $context ) {
2366
+					wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2367
+				}
2368 2368
 				// Don't store empty value, no point
2369 2369
 				if ( !empty($answer_feedback) ) {
2370 2370
 					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2371 2371
 				}
2372 2372
 
2373
-		    } else {
2373
+			} else {
2374 2374
 				$question_id = wp_insert_post( $post_type_args );
2375 2375
 				$question_count = intval( $data['question_count'] );
2376 2376
 				++$question_count;
@@ -2383,29 +2383,29 @@  discard block
 block discarded – undo
2383 2383
 				}
2384 2384
 
2385 2385
 				if( isset( $question_grade ) ) {
2386
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2387
-		    	}
2388
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2389
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2390
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2391
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2392
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2393
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2394
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2395
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2386
+					add_post_meta( $question_id, '_question_grade', $question_grade );
2387
+				}
2388
+				add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2389
+				add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2390
+				add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2391
+				add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2392
+				add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2393
+				add_post_meta( $question_id, '_question_media', $question_media );
2394
+				add_post_meta( $question_id, '_answer_order', $answer_order );
2395
+				add_post_meta( $question_id, '_random_order', $random_order );
2396 2396
 				// Don't store empty value, no point
2397 2397
 				if ( !empty($answer_feedback) ) {
2398 2398
 					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2399 2399
 				}
2400 2400
 
2401
-		    	// Set the post terms for question-type
2402
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2401
+				// Set the post terms for question-type
2402
+				wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2403 2403
 
2404
-			    if( $question_category ) {
2405
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2406
-	    		}
2404
+				if( $question_category ) {
2405
+					wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2406
+				}
2407 2407
 
2408
-		    } // End If Statement
2408
+			} // End If Statement
2409 2409
 		} // End If Statement
2410 2410
   		// Check that the insert or update saved by testing the post id
2411 2411
   		if ( 0 < $question_id ) {
@@ -2454,7 +2454,7 @@  discard block
 block discarded – undo
2454 2454
 	public function lesson_complexities() {
2455 2455
 
2456 2456
 		// V2 - make filter for this array
2457
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2457
+		$lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2458 2458
 									'std' => __( 'Standard', 'woothemes-sensei' ),
2459 2459
 									'hard' => __( 'Hard', 'woothemes-sensei' )
2460 2460
 									);
@@ -2521,14 +2521,14 @@  discard block
 block discarded – undo
2521 2521
 		$post_args = array(	'post_type' 		=> 'quiz',
2522 2522
 							'posts_per_page' 		=> 1,
2523 2523
 							'orderby'         	=> 'title',
2524
-    						'order'           	=> 'DESC',
2525
-    						'post_parent'      	=> $lesson_id,
2526
-    						'post_status'		=> $post_status,
2524
+							'order'           	=> 'DESC',
2525
+							'post_parent'      	=> $lesson_id,
2526
+							'post_status'		=> $post_status,
2527 2527
 							'suppress_filters' 	=> 0,
2528 2528
 							'fields'            => $fields
2529 2529
 							);
2530 2530
 		$posts_array = get_posts( $post_args );
2531
-        $quiz_id = array_shift($posts_array);
2531
+		$quiz_id = array_shift($posts_array);
2532 2532
 
2533 2533
 		return $quiz_id;
2534 2534
 	} // End lesson_quizzes()
@@ -2536,34 +2536,34 @@  discard block
 block discarded – undo
2536 2536
 
2537 2537
 	/**
2538 2538
 	 * Fetches all the questions for a quiz depending on certain conditions.
2539
-     *
2540
-     * Determine which questions should be shown depending on:
2541
-     * - admin/teacher selected questions to be shown
2542
-     * - questions shown to a user previously (saved as asked questions)
2543
-     * - limit number of questions lesson setting
2544 2539
 	 *
2545
-     * @since 1.0
2540
+	 * Determine which questions should be shown depending on:
2541
+	 * - admin/teacher selected questions to be shown
2542
+	 * - questions shown to a user previously (saved as asked questions)
2543
+	 * - limit number of questions lesson setting
2544
+	 *
2545
+	 * @since 1.0
2546 2546
 	 * @param int $quiz_id (default: 0)
2547 2547
 	 * @param string $post_status (default: 'publish')
2548 2548
 	 * @param string $orderby (default: 'meta_value_num title')
2549 2549
 	 * @param string $order (default: 'ASC')
2550
-     *
2550
+	 *
2551 2551
 	 * @return array $questions { $question type WP_Post }
2552 2552
 	 */
2553 2553
 	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2554 2554
 
2555 2555
 		$quiz_id = (string) $quiz_id;
2556
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2556
+		$quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2557 2557
 
2558
-        // setup the user id
2559
-        if( is_admin() ) {
2560
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2561
-        } else {
2562
-            $user_id = get_current_user_id();
2563
-        }
2558
+		// setup the user id
2559
+		if( is_admin() ) {
2560
+			$user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2561
+		} else {
2562
+			$user_id = get_current_user_id();
2563
+		}
2564 2564
 
2565
-        // get the users current status on the lesson
2566
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2565
+		// get the users current status on the lesson
2566
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2567 2567
 
2568 2568
 		// Set the default question order if it has not already been set for this quiz
2569 2569
 		$this->set_default_question_order( $quiz_id );
@@ -2593,14 +2593,14 @@  discard block
 block discarded – undo
2593 2593
 			'suppress_filters' 	=> 0
2594 2594
 		);
2595 2595
 
2596
-        //query the questions
2596
+		//query the questions
2597 2597
 		$questions_query = new WP_Query( $question_query_args );
2598 2598
 
2599
-        // Set return array to initially include all items
2600
-        $questions = $questions_query->posts;
2599
+		// Set return array to initially include all items
2600
+		$questions = $questions_query->posts;
2601 2601
 
2602
-        // set the questions array that will be manipulated within this function
2603
-        $questions_array = $questions_query->posts;
2602
+		// set the questions array that will be manipulated within this function
2603
+		$questions_array = $questions_query->posts;
2604 2604
 
2605 2605
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2606 2606
 		$selected_questions = false;
@@ -2713,36 +2713,36 @@  discard block
 block discarded – undo
2713 2713
 			}
2714 2714
 		}
2715 2715
 
2716
-        // Save the questions that will be asked for the current user
2717
-        // this happens only once per user/quiz, unless the user resets the quiz
2718
-        if( ! is_admin() ){
2716
+		// Save the questions that will be asked for the current user
2717
+		// this happens only once per user/quiz, unless the user resets the quiz
2718
+		if( ! is_admin() ){
2719 2719
 
2720
-            if( $user_lesson_status ) {
2720
+			if( $user_lesson_status ) {
2721 2721
 
2722
-                $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2723
-                if ( empty($questions_asked) && $user_lesson_status) {
2722
+				$questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2723
+				if ( empty($questions_asked) && $user_lesson_status) {
2724 2724
 
2725
-                    $questions_asked = array();
2726
-                    foreach ($questions as $question) {
2725
+					$questions_asked = array();
2726
+					foreach ($questions as $question) {
2727 2727
 
2728
-                        $questions_asked[] = $question->ID;
2728
+						$questions_asked[] = $question->ID;
2729 2729
 
2730
-                    }
2730
+					}
2731 2731
 
2732
-                    // save the questions asked id
2733
-                    $questions_asked_csv = implode(',', $questions_asked);
2734
-                    update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2732
+					// save the questions asked id
2733
+					$questions_asked_csv = implode(',', $questions_asked);
2734
+					update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2735 2735
 
2736
-                }
2737
-            }
2738
-        }
2736
+				}
2737
+			}
2738
+		}
2739 2739
 
2740
-        /**
2741
-         * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2742
-         *
2743
-         * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2744
-         * @since 1.8.0
2745
-         */
2740
+		/**
2741
+		 * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2742
+		 *
2743
+		 * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2744
+		 * @since 1.8.0
2745
+		 */
2746 2746
 		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2747 2747
 
2748 2748
 	} // End lesson_quiz_questions()
@@ -2846,7 +2846,7 @@  discard block
 block discarded – undo
2846 2846
  			// Display Image Placeholder if none
2847 2847
 			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2848 2848
 
2849
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2849
+				$img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2850 2850
 
2851 2851
 			} // End If Statement
2852 2852
 
@@ -2858,417 +2858,417 @@  discard block
 block discarded – undo
2858 2858
 
2859 2859
 	} // End lesson_image()
2860 2860
 
2861
-    /**
2862
-     * Ooutpu the lesson image
2863
-     *
2864
-     * @since 1.9.0
2865
-     * @param integer $lesson_id
2866
-     */
2867
-    public static function the_lesson_image( $lesson_id = 0 ){
2861
+	/**
2862
+	 * Ooutpu the lesson image
2863
+	 *
2864
+	 * @since 1.9.0
2865
+	 * @param integer $lesson_id
2866
+	 */
2867
+	public static function the_lesson_image( $lesson_id = 0 ){
2868 2868
 
2869
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2869
+		echo Sensei()->lesson->lesson_image( $lesson_id );
2870 2870
 
2871
-    }
2871
+	}
2872 2872
 
2873 2873
 	/**
2874 2874
 	 * Returns the the lesson excerpt.
2875 2875
 	 *
2876 2876
 	 * @param WP_Post $lesson
2877
-     * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2877
+	 * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2878 2878
 	 * @return string
2879 2879
 	 */
2880 2880
 	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2881 2881
 		$html = '';
2882 2882
 		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2883 2883
 
2884
-            $excerpt =  $lesson->post_excerpt;
2884
+			$excerpt =  $lesson->post_excerpt;
2885 2885
 
2886
-            // if $add_p_tags true wrap with <p> else return the excerpt as is
2887
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2886
+			// if $add_p_tags true wrap with <p> else return the excerpt as is
2887
+			$html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2888 2888
 
2889 2889
 		}
2890 2890
 		return apply_filters( 'sensei_lesson_excerpt', $html );
2891 2891
 
2892 2892
 	} // End lesson_excerpt()
2893 2893
 
2894
-    /**
2895
-     * Returns the course for a given lesson
2896
-     *
2897
-     * @since 1.7.4
2898
-     * @access public
2899
-     *
2900
-     * @param int $lesson_id
2901
-     * @return int|bool $course_id or bool when nothing is found.
2902
-     */
2903
-     public function get_course_id( $lesson_id ){
2904
-
2905
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2906
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2907
-             return false;
2908
-         }
2909
-
2910
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2911
-
2912
-         // make sure the course id is valid
2913
-         if( empty( $lesson_course_id )
2914
-             || is_array( $lesson_course_id )
2915
-             || intval( $lesson_course_id ) < 1
2916
-             || 'course' != get_post_type( $lesson_course_id ) ){
2917
-
2918
-             return false;
2919
-
2920
-         }
2921
-
2922
-         return $lesson_course_id;
2923
-
2924
-     }// en get_course_id
2925
-
2926
-    /**
2927
-     * Add the admin all lessons screen edit options.
2928
-     *
2929
-     * The fields in this function work for both quick and bulk edit. The ID attributes is used
2930
-     * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2931
-     * name attribute is will be used by the quick edit and submitted via standard POST. This
2932
-     * will use this classes save_post_meta function to save the new field data.
2933
-     *
2934
-     * @hooked quick_edit_custom_box
2935
-     * @hooked bulk_edit_custom_box
2936
-     *
2937
-     * @since 1.8.0
2938
-     *
2939
-     * @param string $column_name
2940
-     * @param string $post_type
2941
-     * @return void
2942
-     */
2943
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2944
-
2945
-        // only show these options ont he lesson post type edit screen
2946
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2947
-            return;
2948
-        }
2949
-
2950
-        ?>
2894
+	/**
2895
+	 * Returns the course for a given lesson
2896
+	 *
2897
+	 * @since 1.7.4
2898
+	 * @access public
2899
+	 *
2900
+	 * @param int $lesson_id
2901
+	 * @return int|bool $course_id or bool when nothing is found.
2902
+	 */
2903
+	 public function get_course_id( $lesson_id ){
2904
+
2905
+		 if( ! isset( $lesson_id ) || empty( $lesson_id )
2906
+		 ||  'lesson' != get_post_type( $lesson_id ) ){
2907
+			 return false;
2908
+		 }
2909
+
2910
+		 $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2911
+
2912
+		 // make sure the course id is valid
2913
+		 if( empty( $lesson_course_id )
2914
+			 || is_array( $lesson_course_id )
2915
+			 || intval( $lesson_course_id ) < 1
2916
+			 || 'course' != get_post_type( $lesson_course_id ) ){
2917
+
2918
+			 return false;
2919
+
2920
+		 }
2921
+
2922
+		 return $lesson_course_id;
2923
+
2924
+	 }// en get_course_id
2925
+
2926
+	/**
2927
+	 * Add the admin all lessons screen edit options.
2928
+	 *
2929
+	 * The fields in this function work for both quick and bulk edit. The ID attributes is used
2930
+	 * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2931
+	 * name attribute is will be used by the quick edit and submitted via standard POST. This
2932
+	 * will use this classes save_post_meta function to save the new field data.
2933
+	 *
2934
+	 * @hooked quick_edit_custom_box
2935
+	 * @hooked bulk_edit_custom_box
2936
+	 *
2937
+	 * @since 1.8.0
2938
+	 *
2939
+	 * @param string $column_name
2940
+	 * @param string $post_type
2941
+	 * @return void
2942
+	 */
2943
+	public function all_lessons_edit_fields( $column_name, $post_type ) {
2944
+
2945
+		// only show these options ont he lesson post type edit screen
2946
+		if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2947
+			return;
2948
+		}
2949
+
2950
+		?>
2951 2951
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2952 2952
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2953 2953
                     <?php
2954
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2955
-                    // create a nonce field to be  used as a security measure when saving the data
2956
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2957
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2958
-
2959
-                    // unchanged option - we need this in because
2960
-                    // the default option in bulk edit should not be empty. If it is
2961
-                    // the user will erase data they didn't want to touch.
2962
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2963
-
2964
-                    //
2965
-                    //course selection
2966
-                    //
2967
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2968
-                    $course_options = array();
2969
-                    if ( count( $courses ) > 0 ) {
2970
-                        foreach ($courses as $course ){
2971
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
2972
-                        }
2973
-                    }
2974
-                    //pre-append the no change option
2975
-                    $course_options['-1']=  $no_change_text;
2976
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2977
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2978
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2979
-
2980
-                    //
2981
-                    // lesson complexity selection
2982
-                    //
2983
-                    $lesson_complexities =  $this->lesson_complexities();
2984
-                    //pre-append the no change option
2985
-                    $lesson_complexities['-1']=  $no_change_text;
2986
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2987
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2988
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2989
-
2990
-                    ?>
2954
+					echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2955
+					// create a nonce field to be  used as a security measure when saving the data
2956
+					wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2957
+					wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2958
+
2959
+					// unchanged option - we need this in because
2960
+					// the default option in bulk edit should not be empty. If it is
2961
+					// the user will erase data they didn't want to touch.
2962
+					$no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2963
+
2964
+					//
2965
+					//course selection
2966
+					//
2967
+					$courses =  WooThemes_Sensei_Course::get_all_courses();
2968
+					$course_options = array();
2969
+					if ( count( $courses ) > 0 ) {
2970
+						foreach ($courses as $course ){
2971
+							$course_options[ $course->ID ] = get_the_title( $course->ID );
2972
+						}
2973
+					}
2974
+					//pre-append the no change option
2975
+					$course_options['-1']=  $no_change_text;
2976
+					$course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2977
+					$course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2978
+					echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2979
+
2980
+					//
2981
+					// lesson complexity selection
2982
+					//
2983
+					$lesson_complexities =  $this->lesson_complexities();
2984
+					//pre-append the no change option
2985
+					$lesson_complexities['-1']=  $no_change_text;
2986
+					$complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2987
+					$complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2988
+					echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2989
+
2990
+					?>
2991 2991
 
2992 2992
                     <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4>
2993 2993
 
2994 2994
                     <?php
2995 2995
 
2996
-                    //
2997
-                    // Lesson require pass to complete
2998
-                    //
2999
-                    $pass_required_options = array(
3000
-                        '-1' => $no_change_text,
3001
-                         '0' => __('No','woothemes'),
3002
-                         '1' => __('Yes','woothemes'),
3003
-                    );
3004
-
3005
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3006
-                                                                'id'=> 'sensei-edit-lesson-pass-required',
3007
-                                                                'class'=>' '   );
3008
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3009
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3010
-
3011
-                    //
3012
-                    // Quiz pass percentage
3013
-                    //
3014
-                    $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3015
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3016
-
3017
-                    //
3018
-                    // Enable quiz reset button
3019
-                    //
3020
-                    $quiz_reset_select__options = array(
3021
-                        '-1' => $no_change_text,
3022
-                        '0' => __('No','woothemes'),
3023
-                        '1' => __('Yes','woothemes'),
3024
-                    );
3025
-                    $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3026
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3027
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3028
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3029
-
3030
-                    ?>
2996
+					//
2997
+					// Lesson require pass to complete
2998
+					//
2999
+					$pass_required_options = array(
3000
+						'-1' => $no_change_text,
3001
+						 '0' => __('No','woothemes'),
3002
+						 '1' => __('Yes','woothemes'),
3003
+					);
3004
+
3005
+					$pass_required_select_attributes = array( 'name'=> 'pass_required',
3006
+																'id'=> 'sensei-edit-lesson-pass-required',
3007
+																'class'=>' '   );
3008
+					$require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3009
+					echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3010
+
3011
+					//
3012
+					// Quiz pass percentage
3013
+					//
3014
+					$quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3015
+					echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3016
+
3017
+					//
3018
+					// Enable quiz reset button
3019
+					//
3020
+					$quiz_reset_select__options = array(
3021
+						'-1' => $no_change_text,
3022
+						'0' => __('No','woothemes'),
3023
+						'1' => __('Yes','woothemes'),
3024
+					);
3025
+					$quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3026
+					$quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3027
+					$quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3028
+					echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3029
+
3030
+					?>
3031 3031
             </div>
3032 3032
         </fieldset>
3033 3033
     <?php
3034
-    }// all_lessons_edit_fields
3035
-
3036
-    /**
3037
-     * Create the html for the edit field
3038
-     *
3039
-     * Wraps the passed in field and title combination with the correct html.
3040
-     *
3041
-     * @since 1.8.0
3042
-     *
3043
-     * @param string $title that will stand to the left of the field.
3044
-     * @param string $field type markup for the field that must be wrapped.
3045
-     * @return string $field_html
3046
-     */
3047
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3048
-
3049
-        $html = '';
3050
-        $html = '<div class="inline-edit-group" >';
3051
-        $html .=  '<span class="title">'. $title .'</span> ';
3052
-        $html .= '<span class="input-text-wrap">';
3053
-        $html .= $field;
3054
-        $html .= '</span>';
3055
-        $html .= '</label></div>';
3056
-
3057
-        return $html ;
3058
-
3059
-    }//end generate_all_lessons_edit_field
3060
-
3061
-    /**
3062
-     * Respond to the ajax call from the bulk edit save function. This comes
3063
-     * from the admin all lesson screen.
3064
-     *
3065
-     * @since 1.8.0
3066
-     * @return void
3067
-     */
3068
-    function save_all_lessons_edit_fields() {
3069
-
3070
-        // verify all the data before attempting to save
3071
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3072
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3073
-            die();
3074
-        }
3075
-
3076
-        // get our variables
3077
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3078
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3079
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3080
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3081
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3082
-        // store the values for all selected posts
3083
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3084
-
3085
-            // get the quiz id needed for the quiz meta
3086
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3087
-
3088
-            // do not save the items if the value is -1 as this
3089
-            // means it was not changed
3090
-
3091
-            // update lesson course
3092
-            if( -1 != $new_course ){
3093
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3094
-            }
3095
-            // update lesson complexity
3096
-            if( -1 != $new_complexity ){
3097
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3098
-            }
3099
-
3100
-            // Quiz Related settings
3101
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3102
-
3103
-                // update pass required
3104
-                if (-1 != $new_pass_required) {
3105
-
3106
-                    $checked = $new_pass_required  ? 'on' : '';
3107
-                    update_post_meta($quiz_id, '_pass_required', $checked);
3108
-                    unset( $checked );
3109
-                }
3034
+	}// all_lessons_edit_fields
3110 3035
 
3111
-                // update pass percentage
3112
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3036
+	/**
3037
+	 * Create the html for the edit field
3038
+	 *
3039
+	 * Wraps the passed in field and title combination with the correct html.
3040
+	 *
3041
+	 * @since 1.8.0
3042
+	 *
3043
+	 * @param string $title that will stand to the left of the field.
3044
+	 * @param string $field type markup for the field that must be wrapped.
3045
+	 * @return string $field_html
3046
+	 */
3047
+	public function generate_all_lessons_edit_field( $title  ,$field ){
3113 3048
 
3114
-                        update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3049
+		$html = '';
3050
+		$html = '<div class="inline-edit-group" >';
3051
+		$html .=  '<span class="title">'. $title .'</span> ';
3052
+		$html .= '<span class="input-text-wrap">';
3053
+		$html .= $field;
3054
+		$html .= '</span>';
3055
+		$html .= '</label></div>';
3115 3056
 
3116
-                }
3057
+		return $html ;
3117 3058
 
3118
-                //
3119
-                // update enable quiz reset
3120
-                //
3121
-                if (-1 != $new_enable_quiz_reset ) {
3059
+	}//end generate_all_lessons_edit_field
3122 3060
 
3123
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3124
-                    update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3125
-                    unset( $checked );
3061
+	/**
3062
+	 * Respond to the ajax call from the bulk edit save function. This comes
3063
+	 * from the admin all lesson screen.
3064
+	 *
3065
+	 * @since 1.8.0
3066
+	 * @return void
3067
+	 */
3068
+	function save_all_lessons_edit_fields() {
3126 3069
 
3127
-                }
3070
+		// verify all the data before attempting to save
3071
+		if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3072
+			||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3073
+			die();
3074
+		}
3128 3075
 
3076
+		// get our variables
3077
+		$new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3078
+		$new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3079
+		$new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3080
+		$new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3081
+		$new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3082
+		// store the values for all selected posts
3083
+		foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3129 3084
 
3130
-            } // end if quiz
3085
+			// get the quiz id needed for the quiz meta
3086
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3131 3087
 
3132
-        }// end for each
3088
+			// do not save the items if the value is -1 as this
3089
+			// means it was not changed
3133 3090
 
3134
-        die();
3091
+			// update lesson course
3092
+			if( -1 != $new_course ){
3093
+				update_post_meta( $lesson_id, '_lesson_course', $new_course );
3094
+			}
3095
+			// update lesson complexity
3096
+			if( -1 != $new_complexity ){
3097
+				update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3098
+			}
3135 3099
 
3136
-    } // end save_all_lessons_edit_fields
3100
+			// Quiz Related settings
3101
+			if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3137 3102
 
3138
-    /**
3139
-     * Loading the quick edit fields defaults.
3140
-     *
3141
-     * This function will localise the default values along with the script that will
3142
-     * add these values to the inputs.
3143
-     *
3144
-     * NOTE: this function runs for each row in the edit column
3145
-     *
3146
-     * @since 1.8.0
3147
-     * @return void
3148
-     */
3149
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3103
+				// update pass required
3104
+				if (-1 != $new_pass_required) {
3150 3105
 
3151
-        if( 'lesson-course' != $column_name ){
3152
-            return;
3153
-        }
3154
-        // load the script
3155
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3156
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3106
+					$checked = $new_pass_required  ? 'on' : '';
3107
+					update_post_meta($quiz_id, '_pass_required', $checked);
3108
+					unset( $checked );
3109
+				}
3157 3110
 
3158
-        // setup the values for all meta fields
3159
-        $data = array();
3160
-        foreach( $this->meta_fields as $field ){
3111
+				// update pass percentage
3112
+				if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3161 3113
 
3162
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3114
+						update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3163 3115
 
3164
-        }
3165
-        // add quiz meta fields
3166
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3167
-        foreach( Sensei()->quiz->meta_fields as $field ){
3116
+				}
3168 3117
 
3169
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3118
+				//
3119
+				// update enable quiz reset
3120
+				//
3121
+				if (-1 != $new_enable_quiz_reset ) {
3170 3122
 
3171
-        }
3123
+					$checked = $new_enable_quiz_reset ? 'on' : ''  ;
3124
+					update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3125
+					unset( $checked );
3172 3126
 
3173
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3127
+				}
3174 3128
 
3175
-    }// end quick edit admin defaults
3176 3129
 
3177
-    /**
3178
-     * Filter the classes for lessons on the single course page.
3179
-     *
3180
-     * Adds the nesecary classes depending on the user data
3181
-     *
3182
-     * @since 1.9.0
3183
-     * @param array $classes
3184
-     * @return array $classes
3185
-     */
3186
-    public static function single_course_lessons_classes( $classes ){
3130
+			} // end if quiz
3187 3131
 
3188
-        if(  is_singular('course') ){
3132
+		}// end for each
3189 3133
 
3190
-            global $post;
3191
-            $course_id = $post->ID;
3134
+		die();
3192 3135
 
3193
-            $lesson_classes = array( 'course', 'post' );
3194
-            if ( is_user_logged_in() ) {
3136
+	} // end save_all_lessons_edit_fields
3195 3137
 
3196
-                // Check if Lesson is complete
3197
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3198
-                if ( $single_lesson_complete ) {
3138
+	/**
3139
+	 * Loading the quick edit fields defaults.
3140
+	 *
3141
+	 * This function will localise the default values along with the script that will
3142
+	 * add these values to the inputs.
3143
+	 *
3144
+	 * NOTE: this function runs for each row in the edit column
3145
+	 *
3146
+	 * @since 1.8.0
3147
+	 * @return void
3148
+	 */
3149
+	public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3199 3150
 
3200
-                    $lesson_classes[] = 'lesson-completed';
3151
+		if( 'lesson-course' != $column_name ){
3152
+			return;
3153
+		}
3154
+		// load the script
3155
+		$suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3156
+		wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3201 3157
 
3202
-                } // End If Statement
3158
+		// setup the values for all meta fields
3159
+		$data = array();
3160
+		foreach( $this->meta_fields as $field ){
3203 3161
 
3204
-            } // End If Statement
3162
+			$data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3205 3163
 
3206
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3207
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3164
+		}
3165
+		// add quiz meta fields
3166
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3167
+		foreach( Sensei()->quiz->meta_fields as $field ){
3208 3168
 
3209
-                $lesson_classes[] = 'lesson-preview';
3169
+			$data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3210 3170
 
3211
-            }
3171
+		}
3172
+
3173
+		wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3174
+
3175
+	}// end quick edit admin defaults
3176
+
3177
+	/**
3178
+	 * Filter the classes for lessons on the single course page.
3179
+	 *
3180
+	 * Adds the nesecary classes depending on the user data
3181
+	 *
3182
+	 * @since 1.9.0
3183
+	 * @param array $classes
3184
+	 * @return array $classes
3185
+	 */
3186
+	public static function single_course_lessons_classes( $classes ){
3212 3187
 
3213
-            $classes = array_merge( $classes, $lesson_classes  );
3188
+		if(  is_singular('course') ){
3214 3189
 
3215
-        }
3190
+			global $post;
3191
+			$course_id = $post->ID;
3216 3192
 
3217
-        return $classes;
3193
+			$lesson_classes = array( 'course', 'post' );
3194
+			if ( is_user_logged_in() ) {
3218 3195
 
3219
-    }// end single_course_lessons_classes
3196
+				// Check if Lesson is complete
3197
+				$single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3198
+				if ( $single_lesson_complete ) {
3220 3199
 
3221
-    /**
3222
-     * Output the lesson meta for the given lesson
3223
-     *
3224
-     * @since 1.9.0
3225
-     * @param $lesson_id
3226
-     */
3227
-    public static function the_lesson_meta( $lesson_id ){
3200
+					$lesson_classes[] = 'lesson-completed';
3228 3201
 
3229
-        global $wp_query;
3230
-        $loop_lesson_number = $wp_query->current_post + 1;
3202
+				} // End If Statement
3203
+
3204
+			} // End If Statement
3231 3205
 
3232
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3233
-        $single_lesson_complete = false;
3234
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3206
+			$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3207
+			if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3235 3208
 
3236
-        // Get Lesson data
3237
-        $complexity_array = Sensei()->lesson->lesson_complexities();
3209
+				$lesson_classes[] = 'lesson-preview';
3238 3210
 
3239
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3240
-        if ( '' != $lesson_complexity ) {
3211
+			}
3241 3212
 
3242
-            $lesson_complexity = $complexity_array[$lesson_complexity];
3213
+			$classes = array_merge( $classes, $lesson_classes  );
3243 3214
 
3244
-        }
3245
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3246
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3247
-        $preview_label = '';
3248
-        if ( $is_preview && !$is_user_taking_course ) {
3215
+		}
3249 3216
 
3250
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3251
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3217
+		return $classes;
3252 3218
 
3253
-        }
3219
+	}// end single_course_lessons_classes
3254 3220
 
3221
+	/**
3222
+	 * Output the lesson meta for the given lesson
3223
+	 *
3224
+	 * @since 1.9.0
3225
+	 * @param $lesson_id
3226
+	 */
3227
+	public static function the_lesson_meta( $lesson_id ){
3255 3228
 
3256
-        $count_markup= '';
3257
-        /**
3258
-         * Filter for if you want the $lesson_count to show next to the lesson.
3259
-         *
3260
-         * @since 1.0
3261
-         * @param bool default false.
3262
-         */
3263
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3229
+		global $wp_query;
3230
+		$loop_lesson_number = $wp_query->current_post + 1;
3264 3231
 
3265
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3232
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
3233
+		$single_lesson_complete = false;
3234
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3266 3235
 
3267
-        }
3236
+		// Get Lesson data
3237
+		$complexity_array = Sensei()->lesson->lesson_complexities();
3268 3238
 
3269
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3239
+		$lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3240
+		if ( '' != $lesson_complexity ) {
3270 3241
 
3271
-        ?>
3242
+			$lesson_complexity = $complexity_array[$lesson_complexity];
3243
+
3244
+		}
3245
+		$user_info = get_userdata( absint( get_post()->post_author ) );
3246
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3247
+		$preview_label = '';
3248
+		if ( $is_preview && !$is_user_taking_course ) {
3249
+
3250
+			$preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3251
+			$preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3252
+
3253
+		}
3254
+
3255
+
3256
+		$count_markup= '';
3257
+		/**
3258
+		 * Filter for if you want the $lesson_count to show next to the lesson.
3259
+		 *
3260
+		 * @since 1.0
3261
+		 * @param bool default false.
3262
+		 */
3263
+		if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3264
+
3265
+			$count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3266
+
3267
+		}
3268
+
3269
+		$heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3270
+
3271
+		?>
3272 3272
         <header>
3273 3273
             <h2>
3274 3274
                 <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
@@ -3281,40 +3281,40 @@  discard block
 block discarded – undo
3281 3281
 
3282 3282
                 <?php
3283 3283
 
3284
-                $meta_html = '';
3285
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3284
+				$meta_html = '';
3285
+				$user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3286 3286
 
3287
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3288
-                if ( '' != $lesson_length ) {
3287
+				$lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3288
+				if ( '' != $lesson_length ) {
3289 3289
 
3290
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3290
+					$meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3291 3291
 
3292
-                }
3292
+				}
3293 3293
 
3294
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3294
+				if ( Sensei()->settings->get( 'lesson_author' ) ) {
3295 3295
 
3296
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3296
+					$meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3297 3297
 
3298
-                } // End If Statement
3299
-                if ( '' != $lesson_complexity ) {
3298
+				} // End If Statement
3299
+				if ( '' != $lesson_complexity ) {
3300 3300
 
3301
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3301
+					$meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3302 3302
 
3303
-                }
3303
+				}
3304 3304
 
3305
-                if ( $single_lesson_complete ) {
3305
+				if ( $single_lesson_complete ) {
3306 3306
 
3307
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3307
+					$meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3308 3308
 
3309
-                } elseif ( $user_lesson_status ) {
3309
+				} elseif ( $user_lesson_status ) {
3310 3310
 
3311
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3311
+					$meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3312 3312
 
3313
-                } // End If Statement
3313
+				} // End If Statement
3314 3314
 
3315
-                echo $meta_html;
3315
+				echo $meta_html;
3316 3316
 
3317
-                ?>
3317
+				?>
3318 3318
 
3319 3319
             </p> <!-- lesson meta -->
3320 3320
 
@@ -3322,132 +3322,132 @@  discard block
 block discarded – undo
3322 3322
 
3323 3323
     <?php
3324 3324
 
3325
-    } // end the_lesson_meta
3325
+	} // end the_lesson_meta
3326 3326
 
3327
-    /**
3328
-     * Output the lessons thumbnail
3329
-     *
3330
-     * 1.9.0
3331
-     *
3332
-     * @param $lesson_id
3333
-     */
3334
-    public static function the_lesson_thumbnail( $lesson_id ){
3327
+	/**
3328
+	 * Output the lessons thumbnail
3329
+	 *
3330
+	 * 1.9.0
3331
+	 *
3332
+	 * @param $lesson_id
3333
+	 */
3334
+	public static function the_lesson_thumbnail( $lesson_id ){
3335 3335
 
3336
-        if( empty( $lesson_id ) ){
3336
+		if( empty( $lesson_id ) ){
3337 3337
 
3338
-            $lesson_id = get_the_ID();
3338
+			$lesson_id = get_the_ID();
3339 3339
 
3340
-        }
3340
+		}
3341 3341
 
3342
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3343
-            return;
3344
-        }
3342
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3343
+			return;
3344
+		}
3345 3345
 
3346
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3347
-    }
3346
+		echo Sensei()->lesson->lesson_image( $lesson_id );
3347
+	}
3348 3348
 
3349 3349
 
3350
-    /**
3351
-     * Alter the sensei lesson excerpt.
3352
-     *
3353
-     * @since 1.9.0
3354
-     * @param string $excerpt
3355
-     * @return string $excerpt
3356
-     */
3357
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3350
+	/**
3351
+	 * Alter the sensei lesson excerpt.
3352
+	 *
3353
+	 * @since 1.9.0
3354
+	 * @param string $excerpt
3355
+	 * @return string $excerpt
3356
+	 */
3357
+	public static function alter_the_lesson_excerpt( $excerpt ) {
3358 3358
 
3359
-        if ('lesson' == get_post_type(get_the_ID())){
3359
+		if ('lesson' == get_post_type(get_the_ID())){
3360 3360
 
3361
-            // remove this hooks to avoid an infinite loop.
3362
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3361
+			// remove this hooks to avoid an infinite loop.
3362
+			remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3363 3363
 
3364
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3365
-        }
3364
+			return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3365
+		}
3366 3366
 
3367
-        return $excerpt;
3367
+		return $excerpt;
3368 3368
 
3369
-    }// end the_lesson_excerpt
3369
+	}// end the_lesson_excerpt
3370 3370
 
3371
-    /**
3372
-     * Returns the lesson prerequisite for the given lesson id.
3373
-     *
3374
-     * @since 1.9.0
3375
-     *
3376
-     * @param $current_lesson_id
3377
-     * @return mixed | bool | int $prerequisite_lesson_id or false
3378
-     */
3379
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3371
+	/**
3372
+	 * Returns the lesson prerequisite for the given lesson id.
3373
+	 *
3374
+	 * @since 1.9.0
3375
+	 *
3376
+	 * @param $current_lesson_id
3377
+	 * @return mixed | bool | int $prerequisite_lesson_id or false
3378
+	 */
3379
+	public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3380 3380
 
3381
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3381
+		$prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3382 3382
 
3383
-        // set ti to false if not a valid prerequisite lesson id
3384
-        if(  empty( $prerequisite_lesson_id )
3385
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3386
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3383
+		// set ti to false if not a valid prerequisite lesson id
3384
+		if(  empty( $prerequisite_lesson_id )
3385
+			|| 'lesson' != get_post_type( $prerequisite_lesson_id )
3386
+			|| $prerequisite_lesson_id == $current_lesson_id  ) {
3387 3387
 
3388
-            $prerequisite_lesson_id = false;
3388
+			$prerequisite_lesson_id = false;
3389 3389
 
3390
-        }
3390
+		}
3391 3391
 
3392
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3392
+		return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3393 3393
 
3394
-    }
3394
+	}
3395 3395
 
3396
-    /**
3397
-     * This function requires that you pass in the lesson you would like to check for
3398
-     * a pre-requisite and not the pre-requisite. It will check if the
3399
-     * lesson has a pre-requiste and then check if it is completed.
3400
-     *
3401
-     * @since 1.9.0
3402
-     *
3403
-     * @param $lesson_id
3404
-     * @param $user_id
3405
-     * @return bool
3406
-     */
3407
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3396
+	/**
3397
+	 * This function requires that you pass in the lesson you would like to check for
3398
+	 * a pre-requisite and not the pre-requisite. It will check if the
3399
+	 * lesson has a pre-requiste and then check if it is completed.
3400
+	 *
3401
+	 * @since 1.9.0
3402
+	 *
3403
+	 * @param $lesson_id
3404
+	 * @param $user_id
3405
+	 * @return bool
3406
+	 */
3407
+	public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3408 3408
 
3409
-        if( empty( $lesson_id ) || empty( $user_id )
3410
-        || 'lesson' != get_post_type( $lesson_id )
3411
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3409
+		if( empty( $lesson_id ) || empty( $user_id )
3410
+		|| 'lesson' != get_post_type( $lesson_id )
3411
+		||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3412 3412
 
3413
-            return false;
3413
+			return false;
3414 3414
 
3415
-        }
3415
+		}
3416 3416
 
3417
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3417
+		$pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3418 3418
 
3419
-        // not a valid pre-requisite so pre-requisite is completed
3420
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3421
-            || ! is_numeric( $pre_requisite_id ) ){
3419
+		// not a valid pre-requisite so pre-requisite is completed
3420
+		if( 'lesson' != get_post_type( $pre_requisite_id )
3421
+			|| ! is_numeric( $pre_requisite_id ) ){
3422 3422
 
3423
-            return true;
3423
+			return true;
3424 3424
 
3425
-        }
3425
+		}
3426 3426
 
3427
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3427
+		return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3428 3428
 
3429
-    }// end is_prerequisite_complete
3429
+	}// end is_prerequisite_complete
3430 3430
 
3431
-    /**
3432
-     * Show the user not taking course message if it is the case
3433
-     *
3434
-     * @since 1.9.0
3435
-     */
3436
-    public  static function user_not_taking_course_message(){
3431
+	/**
3432
+	 * Show the user not taking course message if it is the case
3433
+	 *
3434
+	 * @since 1.9.0
3435
+	 */
3436
+	public  static function user_not_taking_course_message(){
3437 3437
 
3438
-        $lesson_id = get_the_ID();
3438
+		$lesson_id = get_the_ID();
3439 3439
 
3440
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3441
-            return;
3442
-        }
3440
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3441
+			return;
3442
+		}
3443 3443
 
3444
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3445
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3446
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3447
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3444
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3445
+		$pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3446
+		$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3447
+		$user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3448 3448
 
3449
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3450
-            ?>
3449
+		if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3450
+			?>
3451 3451
 
3452 3452
             <div class="sensei-message alert">
3453 3453
                 <?php echo Sensei()->permissions_message['message']; ?>
@@ -3455,46 +3455,46 @@  discard block
 block discarded – undo
3455 3455
 
3456 3456
             <?php
3457 3457
 
3458
-        }// end if
3458
+		}// end if
3459 3459
 
3460
-    } // end user_not_taking_course_message
3460
+	} // end user_not_taking_course_message
3461 3461
 
3462
-    /**
3463
-     * Outputs the lessons course signup lingk
3464
-     *
3465
-     * This hook runs inside the single lesson page.
3466
-     *
3467
-     * @since 1.9.0
3468
-     */
3469
-    public static function course_signup_link( ){
3462
+	/**
3463
+	 * Outputs the lessons course signup lingk
3464
+	 *
3465
+	 * This hook runs inside the single lesson page.
3466
+	 *
3467
+	 * @since 1.9.0
3468
+	 */
3469
+	public static function course_signup_link( ){
3470 3470
 
3471
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3471
+		$course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3472 3472
 
3473
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3473
+		if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3474 3474
 
3475
-            return;
3475
+			return;
3476 3476
 
3477
-        }
3478
-        ?>
3477
+		}
3478
+		?>
3479 3479
 
3480 3480
         <section class="course-signup lesson-meta">
3481 3481
 
3482 3482
             <?php
3483
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3483
+			$wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3484 3484
 
3485
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3485
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3486 3486
 
3487
-                global $current_user;
3488
-                if( is_user_logged_in() ) {
3489
-                    wp_get_current_user();
3487
+				global $current_user;
3488
+				if( is_user_logged_in() ) {
3489
+					wp_get_current_user();
3490 3490
 
3491
-                    $course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3491
+					$course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3492 3492
 
3493
-                    if( $course_purchased ) {
3493
+					if( $course_purchased ) {
3494 3494
 
3495
-                        $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3496
-                        $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3497
-                        ?>
3495
+						$prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3496
+						$course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3497
+						?>
3498 3498
                             <div class="sensei-message info">
3499 3499
 
3500 3500
                                 <?php  echo sprintf( __( 'Please complete %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); ?>
@@ -3506,14 +3506,14 @@  discard block
 block discarded – undo
3506 3506
                         <div class="sensei-message info">
3507 3507
 
3508 3508
                             <?php
3509
-                            $course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3510
-                                            . '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3511
-                                            . '">' . __( 'course', 'woothemes-sensei' )
3512
-                                            . '</a>';
3509
+							$course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3510
+											. '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3511
+											. '">' . __( 'course', 'woothemes-sensei' )
3512
+											. '</a>';
3513 3513
 
3514
-                            echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3514
+							echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3515 3515
 
3516
-                            ?>
3516
+							?>
3517 3517
 
3518 3518
                         </div>
3519 3519
                     <?php } ?>
@@ -3530,14 +3530,14 @@  discard block
 block discarded – undo
3530 3530
 
3531 3531
                 <div class="sensei-message info">
3532 3532
                     <?php
3533
-                    $course_link =  '<a href="'
3534
-                                        . esc_url( get_permalink( $course_id ) )
3535
-                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3536
-                                        . '">' . __( 'course', 'woothemes-sensei' )
3537
-                                    . '</a>';
3538
-
3539
-                    echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3540
-                    ?>
3533
+					$course_link =  '<a href="'
3534
+										. esc_url( get_permalink( $course_id ) )
3535
+										. '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3536
+										. '">' . __( 'course', 'woothemes-sensei' )
3537
+									. '</a>';
3538
+
3539
+					echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3540
+					?>
3541 3541
                 </div>
3542 3542
 
3543 3543
             <?php endif; ?>
@@ -3547,75 +3547,75 @@  discard block
 block discarded – undo
3547 3547
         </section>
3548 3548
 
3549 3549
         <?php
3550
-    }// end course_signup_link
3550
+	}// end course_signup_link
3551 3551
 
3552
-    /**
3553
-     * Show a message telling the user to complete the previous message if they haven't done so yet
3554
-     *
3555
-     * @since 1.9.0
3556
-     */
3557
-    public  static function prerequisite_complete_message(){
3552
+	/**
3553
+	 * Show a message telling the user to complete the previous message if they haven't done so yet
3554
+	 *
3555
+	 * @since 1.9.0
3556
+	 */
3557
+	public  static function prerequisite_complete_message(){
3558 3558
 
3559
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3560
-        $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3561
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3559
+		$lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3560
+		$lesson_has_pre_requisite = $lesson_prerequisite > 0;
3561
+		if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3562 3562
 
3563
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3564
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3563
+			$prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3564
+			echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3565 3565
 
3566
-        }
3566
+		}
3567 3567
 
3568
-    }
3568
+	}
3569 3569
 
3570
-    /**
3571
-     * Deprecate the sensei_lesson_archive_header hook but keep it
3572
-     * active for backwards compatibility.
3573
-     *
3574
-     * @deprecated since 1.9.0
3575
-     */
3576
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3570
+	/**
3571
+	 * Deprecate the sensei_lesson_archive_header hook but keep it
3572
+	 * active for backwards compatibility.
3573
+	 *
3574
+	 * @deprecated since 1.9.0
3575
+	 */
3576
+	public static function deprecate_sensei_lesson_archive_header_hook(){
3577 3577
 
3578
-        sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3578
+		sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3579 3579
 
3580
-    }
3580
+	}
3581 3581
 
3582
-    /**
3583
-     * Outputs the the lesson archive header.
3584
-     *
3585
-     * @since  1.9.0
3586
-     * @return void
3587
-     */
3588
-    public function the_archive_header( ) {
3582
+	/**
3583
+	 * Outputs the the lesson archive header.
3584
+	 *
3585
+	 * @since  1.9.0
3586
+	 * @return void
3587
+	 */
3588
+	public function the_archive_header( ) {
3589 3589
 
3590
-        $before_html = '<header class="archive-header"><h1>';
3591
-        $after_html = '</h1></header>';
3592
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3590
+		$before_html = '<header class="archive-header"><h1>';
3591
+		$after_html = '</h1></header>';
3592
+		$html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3593 3593
 
3594
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3594
+		echo apply_filters( 'sensei_lesson_archive_title', $html );
3595 3595
 
3596
-    } // sensei_course_archive_header()
3596
+	} // sensei_course_archive_header()
3597 3597
 
3598
-    /**
3599
-     * Output the title for the single lesson page
3600
-     *
3601
-     * @global $post
3602
-     * @since 1.9.0
3603
-     */
3604
-    public static function the_title(){
3598
+	/**
3599
+	 * Output the title for the single lesson page
3600
+	 *
3601
+	 * @global $post
3602
+	 * @since 1.9.0
3603
+	 */
3604
+	public static function the_title(){
3605 3605
 
3606
-        global $post;
3606
+		global $post;
3607 3607
 
3608
-        ?>
3608
+		?>
3609 3609
         <header>
3610 3610
 
3611 3611
             <h1>
3612 3612
 
3613 3613
                 <?php
3614
-                /**
3615
-                 * Filter documented in class-sensei-messages.php the_title
3616
-                 */
3617
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3618
-                ?>
3614
+				/**
3615
+				 * Filter documented in class-sensei-messages.php the_title
3616
+				 */
3617
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3618
+				?>
3619 3619
 
3620 3620
             </h1>
3621 3621
 
@@ -3623,68 +3623,68 @@  discard block
 block discarded – undo
3623 3623
 
3624 3624
         <?php
3625 3625
 
3626
-    }//the_title
3626
+	}//the_title
3627 3627
 
3628
-    /**
3629
-     * Flush the rewrite rules for a lesson post type
3630
-     *
3631
-     * @since 1.9.0
3632
-     *
3633
-     * @param $post_id
3634
-     */
3635
-    public static function flush_rewrite_rules( $post_id ){
3628
+	/**
3629
+	 * Flush the rewrite rules for a lesson post type
3630
+	 *
3631
+	 * @since 1.9.0
3632
+	 *
3633
+	 * @param $post_id
3634
+	 */
3635
+	public static function flush_rewrite_rules( $post_id ){
3636 3636
 
3637
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3637
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3638 3638
 
3639
-            return;
3639
+			return;
3640 3640
 
3641
-        }
3641
+		}
3642 3642
 
3643 3643
 
3644
-        if( 'lesson' == get_post_type( $post_id )  ){
3644
+		if( 'lesson' == get_post_type( $post_id )  ){
3645 3645
 
3646
-            Sensei()->initiate_rewrite_rules_flush();
3646
+			Sensei()->initiate_rewrite_rules_flush();
3647 3647
 
3648
-        }
3648
+		}
3649 3649
 
3650
-    }
3650
+	}
3651 3651
 
3652
-    /**
3653
-     * Output the quiz specific buttons and messaging on the single lesson page
3654
-     *
3655
-     *
3656
-     * @since 1.0.0 moved here from frontend class
3657
-     *
3658
-     * @param int $lesson_id
3659
-     * @param int $user_id
3660
-     */
3661
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3652
+	/**
3653
+	 * Output the quiz specific buttons and messaging on the single lesson page
3654
+	 *
3655
+	 *
3656
+	 * @since 1.0.0 moved here from frontend class
3657
+	 *
3658
+	 * @param int $lesson_id
3659
+	 * @param int $user_id
3660
+	 */
3661
+	public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3662 3662
 
3663 3663
 
3664
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3665
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3666
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3667
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3668
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3669
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3670
-        $show_actions              = is_user_logged_in() ? true : false;
3664
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3665
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3666
+		$lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3667
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3668
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3669
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3670
+		$show_actions              = is_user_logged_in() ? true : false;
3671 3671
 
3672
-        if( intval( $lesson_prerequisite ) > 0 ) {
3672
+		if( intval( $lesson_prerequisite ) > 0 ) {
3673 3673
 
3674
-            // If the user hasn't completed the prereq then hide the current actions
3675
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3674
+			// If the user hasn't completed the prereq then hide the current actions
3675
+			$show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3676 3676
 
3677
-        }
3678
-        ?>
3677
+		}
3678
+		?>
3679 3679
 
3680 3680
         <footer>
3681 3681
 
3682 3682
             <?php
3683
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3683
+			if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3684 3684
 
3685
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3686
-                if( $has_quiz_questions ) {
3687
-                    ?>
3685
+				$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3686
+				if( $has_quiz_questions ) {
3687
+					?>
3688 3688
 
3689 3689
                     <p>
3690 3690
 
@@ -3699,87 +3699,87 @@  discard block
 block discarded – undo
3699 3699
                     </p>
3700 3700
 
3701 3701
                     <?php
3702
-                }
3702
+				}
3703 3703
 
3704
-            } // End If Statement
3704
+			} // End If Statement
3705 3705
 
3706
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3706
+			if ( $show_actions && ! $has_user_completed_lesson ) {
3707 3707
 
3708
-                sensei_complete_lesson_button();
3708
+				sensei_complete_lesson_button();
3709 3709
 
3710
-            } elseif( $show_actions ) {
3710
+			} elseif( $show_actions ) {
3711 3711
 
3712
-                sensei_reset_lesson_button();
3712
+				sensei_reset_lesson_button();
3713 3713
 
3714
-            } // End If Statement
3715
-            ?>
3714
+			} // End If Statement
3715
+			?>
3716 3716
 
3717 3717
         </footer>
3718 3718
 
3719 3719
         <?php
3720
-    } // End sensei_lesson_quiz_meta()
3720
+	} // End sensei_lesson_quiz_meta()
3721 3721
 
3722
-    /**
3723
-     * Show the lesson comments. This should be used in the loop.
3724
-     *
3725
-     * @since 1.9.0
3726
-     */
3727
-    public static function output_comments(){
3722
+	/**
3723
+	 * Show the lesson comments. This should be used in the loop.
3724
+	 *
3725
+	 * @since 1.9.0
3726
+	 */
3727
+	public static function output_comments(){
3728 3728
 
3729
-        if( ! is_user_logged_in() ){
3730
-            return;
3731
-        }
3729
+		if( ! is_user_logged_in() ){
3730
+			return;
3731
+		}
3732 3732
 
3733
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3734
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3735
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3736
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3733
+		$pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3734
+		$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3735
+		$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3736
+		$user_taking_course = Sensei_Utils::user_started_course($course_id );
3737 3737
 
3738
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3738
+		$lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3739 3739
 
3740
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3740
+		if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3741 3741
 
3742
-            comments_template();
3742
+			comments_template();
3743 3743
 
3744
-        } // End If Statement
3744
+		} // End If Statement
3745 3745
 
3746
-    } //output_comments
3746
+	} //output_comments
3747 3747
 
3748
-    /**
3749
-     * Display the leeson quiz status if it should be shown
3750
-     *
3751
-     * @param int $lesson_id defaults to the global lesson id
3752
-     * @param int $user_id defaults to the current user id
3753
-     *
3754
-     * @since 1.9.0
3755
-     */
3756
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3748
+	/**
3749
+	 * Display the leeson quiz status if it should be shown
3750
+	 *
3751
+	 * @param int $lesson_id defaults to the global lesson id
3752
+	 * @param int $user_id defaults to the current user id
3753
+	 *
3754
+	 * @since 1.9.0
3755
+	 */
3756
+	public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3757 3757
 
3758
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3759
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3760
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3761
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3762
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3758
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3759
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3760
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3761
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3762
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3763 3763
 
3764 3764
 
3765
-        if ( $quiz_id && is_user_logged_in()
3766
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3765
+		if ( $quiz_id && is_user_logged_in()
3766
+			&& Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3767 3767
 
3768
-            $no_quiz_count = 0;
3769
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3768
+			$no_quiz_count = 0;
3769
+			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3770 3770
 
3771
-            // Display lesson quiz status message
3772
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3773
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3774
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3775
-                if( $has_quiz_questions ) {
3776
-                   // echo $status['extra'];
3777
-                } // End If Statement
3778
-            } // End If Statement
3771
+			// Display lesson quiz status message
3772
+			if ( $has_user_completed_lesson || $has_quiz_questions ) {
3773
+				$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3774
+				echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3775
+				if( $has_quiz_questions ) {
3776
+				   // echo $status['extra'];
3777
+				} // End If Statement
3778
+			} // End If Statement
3779 3779
 
3780
-        }
3780
+		}
3781 3781
 
3782
-    }
3782
+	}
3783 3783
 
3784 3784
 } // End Class
3785 3785
 
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.