Completed
Push — master ( 201c1b...d51ce1 )
by Dwain
04:57
created
includes/class-sensei-question.php 1 patch
Spacing   +286 added lines, -286 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Question Class
@@ -20,34 +20,34 @@  discard block
 block discarded – undo
20 20
 	 * Constructor.
21 21
 	 * @since  1.0.0
22 22
 	 */
23
-	public function __construct () {
23
+	public function __construct() {
24 24
 		$this->question_types = $this->question_types();
25
-		$this->meta_fields = array( 'question_right_answer', 'question_wrong_answers' );
26
-		if ( is_admin() ) {
25
+		$this->meta_fields = array('question_right_answer', 'question_wrong_answers');
26
+		if (is_admin()) {
27 27
 			// Custom Write Panel Columns
28
-			add_filter( 'manage_edit-question_columns', array( $this, 'add_column_headings' ), 10, 1 );
29
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
30
-			add_action( 'add_meta_boxes', array( $this, 'question_edit_panel_metabox' ), 10, 2 );
28
+			add_filter('manage_edit-question_columns', array($this, 'add_column_headings'), 10, 1);
29
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
30
+			add_action('add_meta_boxes', array($this, 'question_edit_panel_metabox'), 10, 2);
31 31
 
32 32
 			// Quesitno list table filters
33
-			add_action( 'restrict_manage_posts', array( $this, 'filter_options' ) );
34
-			add_filter( 'request', array( $this, 'filter_actions' ) );
33
+			add_action('restrict_manage_posts', array($this, 'filter_options'));
34
+			add_filter('request', array($this, 'filter_actions'));
35 35
 
36
-			add_action( 'save_post', array( $this, 'save_question' ), 10, 1 );
36
+			add_action('save_post', array($this, 'save_question'), 10, 1);
37 37
 		} // End If Statement
38 38
 	} // End __construct()
39 39
 
40 40
 	public function question_types() {
41 41
 		$types = array(
42
-			'multiple-choice' => __( 'Multiple Choice', 'woothemes-sensei' ),
43
-			'boolean' => __( 'True/False', 'woothemes-sensei' ),
44
-			'gap-fill' => __( 'Gap Fill', 'woothemes-sensei' ),
45
-			'single-line' => __( 'Single Line', 'woothemes-sensei' ),
46
-			'multi-line' => __( 'Multi Line', 'woothemes-sensei' ),
47
-			'file-upload' => __( 'File Upload', 'woothemes-sensei' ),
42
+			'multiple-choice' => __('Multiple Choice', 'woothemes-sensei'),
43
+			'boolean' => __('True/False', 'woothemes-sensei'),
44
+			'gap-fill' => __('Gap Fill', 'woothemes-sensei'),
45
+			'single-line' => __('Single Line', 'woothemes-sensei'),
46
+			'multi-line' => __('Multi Line', 'woothemes-sensei'),
47
+			'file-upload' => __('File Upload', 'woothemes-sensei'),
48 48
 		);
49 49
 
50
-		return apply_filters( 'sensei_question_types', $types );
50
+		return apply_filters('sensei_question_types', $types);
51 51
 	}
52 52
 
53 53
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	 * @param  array $defaults
58 58
 	 * @return array $new_columns
59 59
 	 */
60
-	public function add_column_headings ( $defaults ) {
60
+	public function add_column_headings($defaults) {
61 61
 		$new_columns['cb'] = '<input type="checkbox" />';
62
-		$new_columns['title'] = _x( 'Question', 'column name', 'woothemes-sensei' );
63
-		$new_columns['question-type'] = _x( 'Type', 'column name', 'woothemes-sensei' );
64
-		$new_columns['question-category'] = _x( 'Categories', 'column name', 'woothemes-sensei' );
65
-		if ( isset( $defaults['date'] ) ) {
62
+		$new_columns['title'] = _x('Question', 'column name', 'woothemes-sensei');
63
+		$new_columns['question-type'] = _x('Type', 'column name', 'woothemes-sensei');
64
+		$new_columns['question-category'] = _x('Categories', 'column name', 'woothemes-sensei');
65
+		if (isset($defaults['date'])) {
66 66
 			$new_columns['date'] = $defaults['date'];
67 67
 		}
68 68
 
@@ -77,27 +77,27 @@  discard block
 block discarded – undo
77 77
 	 * @param  int $id
78 78
 	 * @return void
79 79
 	 */
80
-	public function add_column_data ( $column_name, $id ) {
80
+	public function add_column_data($column_name, $id) {
81 81
 		global $wpdb, $post;
82 82
 
83
-		switch ( $column_name ) {
83
+		switch ($column_name) {
84 84
 
85 85
 			case 'id':
86 86
 				echo $id;
87 87
 			break;
88 88
 
89 89
 			case 'question-type':
90
-				$question_type = strip_tags( get_the_term_list( $id, 'question-type', '', ', ', '' ) );
90
+				$question_type = strip_tags(get_the_term_list($id, 'question-type', '', ', ', ''));
91 91
 				$output = '&mdash;';
92
-				if( isset( $this->question_types[ $question_type ] ) ) {
93
-					$output = $this->question_types[ $question_type ];
92
+				if (isset($this->question_types[$question_type])) {
93
+					$output = $this->question_types[$question_type];
94 94
 				}
95 95
 				echo $output;
96 96
 			break;
97 97
 
98 98
 			case 'question-category':
99
-				$output = strip_tags( get_the_term_list( $id, 'question-category', '', ', ', '' ) );
100
-				if( ! $output ) {
99
+				$output = strip_tags(get_the_term_list($id, 'question-category', '', ', ', ''));
100
+				if ( ! $output) {
101 101
 					$output = '&mdash;';
102 102
 				}
103 103
 				echo $output;
@@ -110,49 +110,49 @@  discard block
 block discarded – undo
110 110
 
111 111
 	} // End add_column_data()
112 112
 
113
-	public function question_edit_panel_metabox( $post_type, $post ) {
114
-		if( in_array( $post_type, array( 'question', 'multiple_question' ) ) ) {
113
+	public function question_edit_panel_metabox($post_type, $post) {
114
+		if (in_array($post_type, array('question', 'multiple_question'))) {
115 115
 
116
-			$metabox_title = __( 'Question', 'woothemes-sensei' );
116
+			$metabox_title = __('Question', 'woothemes-sensei');
117 117
 
118
-			if( isset( $post->ID ) ) {
118
+			if (isset($post->ID)) {
119 119
 
120
-                $question_type = Sensei()->question->get_question_type( $post->ID );
120
+                $question_type = Sensei()->question->get_question_type($post->ID);
121 121
 
122
-				if( $question_type ) {
123
-					$type = $this->question_types[ $question_type ];
124
-					if( $type ) {
122
+				if ($question_type) {
123
+					$type = $this->question_types[$question_type];
124
+					if ($type) {
125 125
 						$metabox_title = $type;
126 126
 					}
127 127
 				}
128 128
 			}
129
-			add_meta_box( 'question-edit-panel', $metabox_title, array( $this, 'question_edit_panel' ), 'question', 'normal', 'high' );
130
-			add_meta_box( 'question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'question', 'side', 'default' );
131
-			add_meta_box( 'multiple-question-lessons-panel', __( 'Quizzes', 'woothemes-sensei' ), array( $this, 'question_lessons_panel' ), 'multiple_question', 'side', 'default' );
129
+			add_meta_box('question-edit-panel', $metabox_title, array($this, 'question_edit_panel'), 'question', 'normal', 'high');
130
+			add_meta_box('question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'question', 'side', 'default');
131
+			add_meta_box('multiple-question-lessons-panel', __('Quizzes', 'woothemes-sensei'), array($this, 'question_lessons_panel'), 'multiple_question', 'side', 'default');
132 132
 		}
133 133
 	}
134 134
 
135 135
 	public function question_edit_panel() {
136 136
 		global  $post, $pagenow;
137 137
 
138
-		add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_scripts' ) );
139
-		add_action( 'admin_enqueue_scripts', array( Sensei()->lesson, 'enqueue_styles' ) );
138
+		add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_scripts'));
139
+		add_action('admin_enqueue_scripts', array(Sensei()->lesson, 'enqueue_styles'));
140 140
 
141 141
 		$html = '<div id="lesson-quiz" class="single-question"><div id="add-question-main">';
142 142
 
143
-		if( 'post-new.php' == $pagenow ) {
143
+		if ('post-new.php' == $pagenow) {
144 144
 
145 145
 			$html .= '<div id="add-question-actions">';
146
-				$html .= Sensei()->lesson->quiz_panel_add( 'question' );
146
+				$html .= Sensei()->lesson->quiz_panel_add('question');
147 147
 			$html .= '</div>';
148 148
 
149 149
 		} else {
150 150
 			$question_id = $post->ID;
151 151
 
152
-			$question_type =  Sensei()->question->get_question_type( $post->ID );
152
+			$question_type = Sensei()->question->get_question_type($post->ID);
153 153
 
154 154
 			$html .= '<div id="add-question-metadata"><table class="widefat">';
155
-				$html .= Sensei()->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' );
155
+				$html .= Sensei()->lesson->quiz_panel_question($question_type, 0, $question_id, 'question');
156 156
 			$html .= '</table></div>';
157 157
 		}
158 158
 
@@ -164,20 +164,20 @@  discard block
 block discarded – undo
164 164
 	public function question_lessons_panel() {
165 165
 		global $post;
166 166
 
167
-		$no_lessons = sprintf( __( '%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei' ), '<em>', '</em>' );
167
+		$no_lessons = sprintf(__('%1$sThis question does not appear in any quizzes yet.%2$s', 'woothemes-sensei'), '<em>', '</em>');
168 168
 
169
-		if( ! isset( $post->ID ) ) {
169
+		if ( ! isset($post->ID)) {
170 170
 			echo $no_lessons;
171 171
 			return;
172 172
 		}
173 173
 
174 174
 		// This retrieves those quizzes the question is directly connected to.
175
-		$quizzes = get_post_meta( $post->ID, '_quiz_id', false );
175
+		$quizzes = get_post_meta($post->ID, '_quiz_id', false);
176 176
 
177 177
 		// Collate all 'multiple_question' quizzes the question is part of.
178
-		$categories_of_question = wp_get_post_terms( $post->ID, 'question-category', array( 'fields' => 'ids' ) );
179
-		if ( ! empty( $categories_of_question ) ) {
180
-			foreach ( $categories_of_question as $term_id ) {
178
+		$categories_of_question = wp_get_post_terms($post->ID, 'question-category', array('fields' => 'ids'));
179
+		if ( ! empty($categories_of_question)) {
180
+			foreach ($categories_of_question as $term_id) {
181 181
 				$qargs = array(
182 182
 					'fields'           => 'ids',
183 183
 					'post_type'        => 'multiple_question',
@@ -191,41 +191,41 @@  discard block
 block discarded – undo
191 191
 					'post_status'      => 'any',
192 192
 					'suppress_filters' => 0,
193 193
 				);
194
-				$cat_question_ids = get_posts( $qargs );
195
-				foreach( $cat_question_ids as $cat_question_id ) {
196
-					$cat_quizzes = get_post_meta( $cat_question_id, '_quiz_id', false );
197
-					$quizzes = array_merge( $quizzes, $cat_quizzes );
194
+				$cat_question_ids = get_posts($qargs);
195
+				foreach ($cat_question_ids as $cat_question_id) {
196
+					$cat_quizzes = get_post_meta($cat_question_id, '_quiz_id', false);
197
+					$quizzes = array_merge($quizzes, $cat_quizzes);
198 198
 				}
199 199
 			}
200
-			$quizzes = array_unique( array_filter( $quizzes ) );
200
+			$quizzes = array_unique(array_filter($quizzes));
201 201
 		}
202 202
 
203
-		if( 0 == count( $quizzes ) ) {
203
+		if (0 == count($quizzes)) {
204 204
 			echo $no_lessons;
205 205
 			return;
206 206
 		}
207 207
 
208 208
 		$lessons = false;
209 209
 
210
-		foreach( $quizzes as $quiz ) {
210
+		foreach ($quizzes as $quiz) {
211 211
 
212
-			$lesson_id = get_post_meta( $quiz, '_quiz_lesson', true );
212
+			$lesson_id = get_post_meta($quiz, '_quiz_lesson', true);
213 213
 
214
-			if( ! $lesson_id ) continue;
214
+			if ( ! $lesson_id) continue;
215 215
 
216
-			$lessons[ $lesson_id ]['title'] = get_the_title( $lesson_id );
217
-			$lessons[ $lesson_id ]['link'] = admin_url( 'post.php?post=' . $lesson_id . '&action=edit' );
216
+			$lessons[$lesson_id]['title'] = get_the_title($lesson_id);
217
+			$lessons[$lesson_id]['link'] = admin_url('post.php?post='.$lesson_id.'&action=edit');
218 218
 		}
219 219
 
220
-		if( ! $lessons ) {
220
+		if ( ! $lessons) {
221 221
 			echo $no_lessons;
222 222
 			return;
223 223
 		}
224 224
 
225 225
 		$html = '<ul>';
226 226
 
227
-		foreach( $lessons as $id => $lesson ) {
228
-			$html .= '<li><a href="' . esc_url( $lesson['link'] ) . '">' . esc_html( $lesson['title'] ) . '</a></li>';
227
+		foreach ($lessons as $id => $lesson) {
228
+			$html .= '<li><a href="'.esc_url($lesson['link']).'">'.esc_html($lesson['title']).'</a></li>';
229 229
 		}
230 230
 
231 231
 		$html .= '</ul>';
@@ -234,30 +234,30 @@  discard block
 block discarded – undo
234 234
 
235 235
 	}
236 236
 
237
-	public function save_question( $post_id = 0 ) {
237
+	public function save_question($post_id = 0) {
238 238
 
239
-		if( ! isset( $_POST['post_type']
240
-            ) || 'question' != $_POST['post_type'] ) {
239
+		if ( ! isset($_POST['post_type']
240
+            ) || 'question' != $_POST['post_type']) {
241 241
             return;
242 242
         }
243 243
 
244 244
 
245 245
 
246 246
         //setup the data for saving
247
-		$data = $_POST ;
247
+		$data = $_POST;
248 248
         $data['quiz_id'] = 0;
249 249
 		$data['question_id'] = $post_id;
250 250
 
251
-		if ( ! wp_is_post_revision( $post_id ) ){
251
+		if ( ! wp_is_post_revision($post_id)) {
252 252
 
253 253
 			// Unhook function to prevent infinite loops
254
-			remove_action( 'save_post', array( $this, 'save_question' ) );
254
+			remove_action('save_post', array($this, 'save_question'));
255 255
 
256 256
 			// Update question data
257
-			$question_id = Sensei()->lesson->lesson_save_question( $data, 'question' );
257
+			$question_id = Sensei()->lesson->lesson_save_question($data, 'question');
258 258
 
259 259
 			// Re-hook same function
260
-			add_action( 'save_post', array( $this, 'save_question' ) );
260
+			add_action('save_post', array($this, 'save_question'));
261 261
 		}
262 262
 
263 263
 		return;
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
 	public function filter_options() {
271 271
 		global $typenow;
272 272
 
273
-		if( is_admin() && 'question' == $typenow ) {
273
+		if (is_admin() && 'question' == $typenow) {
274 274
 
275 275
 			$output = '';
276 276
 
277 277
 			// Question type
278
-			$selected = isset( $_GET['question_type'] ) ? $_GET['question_type'] : '';
279
-			$type_options = '<option value="">' . __( 'All types', 'woothemes-sensei' ) . '</option>';
280
-			foreach( $this->question_types as $label => $type ) {
281
-				$type_options .= '<option value="' . esc_attr( $label ) . '" ' . selected( $selected, $label, false ) . '>' . esc_html( $type ) . '</option>';
278
+			$selected = isset($_GET['question_type']) ? $_GET['question_type'] : '';
279
+			$type_options = '<option value="">'.__('All types', 'woothemes-sensei').'</option>';
280
+			foreach ($this->question_types as $label => $type) {
281
+				$type_options .= '<option value="'.esc_attr($label).'" '.selected($selected, $label, false).'>'.esc_html($type).'</option>';
282 282
 			}
283 283
 
284 284
 			$output .= '<select name="question_type" id="dropdown_question_type">';
@@ -286,12 +286,12 @@  discard block
 block discarded – undo
286 286
 			$output .= '</select>';
287 287
 
288 288
 			// Question category
289
-			$cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
290
-			if ( ! empty( $cats ) && ! is_wp_error( $cats ) ) {
291
-				$selected = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : '';
292
-				$cat_options = '<option value="">' . __( 'All categories', 'woothemes-sensei' ) . '</option>';
293
-				foreach( $cats as $cat ) {
294
-					$cat_options .= '<option value="' . esc_attr( $cat->slug ) . '" ' . selected( $selected, $cat->slug, false ) . '>' . esc_html( $cat->name ) . '</option>';
289
+			$cats = get_terms('question-category', array('hide_empty' => false));
290
+			if ( ! empty($cats) && ! is_wp_error($cats)) {
291
+				$selected = isset($_GET['question_cat']) ? $_GET['question_cat'] : '';
292
+				$cat_options = '<option value="">'.__('All categories', 'woothemes-sensei').'</option>';
293
+				foreach ($cats as $cat) {
294
+					$cat_options .= '<option value="'.esc_attr($cat->slug).'" '.selected($selected, $cat->slug, false).'>'.esc_html($cat->name).'</option>';
295 295
 				}
296 296
 
297 297
 				$output .= '<select name="question_cat" id="dropdown_question_cat">';
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 	 * @param  array $request Current request
309 309
 	 * @return array          Modified request
310 310
 	 */
311
-	public function filter_actions( $request ) {
311
+	public function filter_actions($request) {
312 312
 		global $typenow;
313 313
 
314
-		if( is_admin() && 'question' == $typenow ) {
314
+		if (is_admin() && 'question' == $typenow) {
315 315
 
316 316
 			// Question type
317
-			$question_type = isset( $_GET['question_type'] ) ? $_GET['question_type'] : '';
318
-			if( $question_type ) {
317
+			$question_type = isset($_GET['question_type']) ? $_GET['question_type'] : '';
318
+			if ($question_type) {
319 319
 				$type_query = array(
320 320
 					'taxonomy' => 'question-type',
321 321
 					'terms' => $question_type,
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 			}
326 326
 
327 327
 			// Question category
328
-			$question_cat = isset( $_GET['question_cat'] ) ? $_GET['question_cat'] : '';
329
-			if( $question_cat ) {
328
+			$question_cat = isset($_GET['question_cat']) ? $_GET['question_cat'] : '';
329
+			if ($question_cat) {
330 330
 				$cat_query = array(
331 331
 					'taxonomy' => 'question-category',
332 332
 					'terms' => $question_cat,
@@ -351,16 +351,16 @@  discard block
 block discarded – undo
351 351
      *
352 352
      * @return string $question_type | bool
353 353
      */
354
-    public function get_question_type( $question_id ){
354
+    public function get_question_type($question_id) {
355 355
 
356
-        if( empty( $question_id ) || ! intval( $question_id ) > 0
357
-            || 'question' != get_post_type( $question_id )   ){
356
+        if (empty($question_id) || ! intval($question_id) > 0
357
+            || 'question' != get_post_type($question_id)) {
358 358
             return false;
359 359
         }
360 360
 
361 361
         $question_type = 'multiple-choice';
362
-        $question_types = wp_get_post_terms( $question_id, 'question-type' );
363
-        foreach( $question_types as $type ) {
362
+        $question_types = wp_get_post_terms($question_id, 'question-type');
363
+        foreach ($question_types as $type) {
364 364
             $question_type = $type->slug;
365 365
         }
366 366
 
@@ -377,21 +377,21 @@  discard block
 block discarded – undo
377 377
 	 *
378 378
 	 * @return int $question_grade | bool
379 379
 	 */
380
-	public function get_question_grade( $question_id ) {
380
+	public function get_question_grade($question_id) {
381 381
 
382
-		if ( empty( $question_id ) || ! intval( $question_id ) > 0
383
-			|| 'question' != get_post_type( $question_id ) ) {
382
+		if (empty($question_id) || ! intval($question_id) > 0
383
+			|| 'question' != get_post_type($question_id)) {
384 384
 			return false;
385 385
 		}
386 386
 
387
-		$question_grade_raw = get_post_meta( $question_id, '_question_grade', true );
387
+		$question_grade_raw = get_post_meta($question_id, '_question_grade', true);
388 388
 		// If not set then default to 1...
389
-		if ( false === $question_grade_raw || $question_grade_raw == '' ) {
389
+		if (false === $question_grade_raw || $question_grade_raw == '') {
390 390
 			$question_grade = 1;
391 391
 		}
392 392
 		// ...but allow a grade of 0 for non-marked questions
393 393
 		else {
394
-			$question_grade = intval( $question_grade_raw );
394
+			$question_grade = intval($question_grade_raw);
395 395
 		}
396 396
 		return $question_grade;
397 397
 
@@ -404,9 +404,9 @@  discard block
 block discarded – undo
404 404
      * @since 1.9.0
405 405
      * @param $question_type
406 406
      */
407
-    public static function load_question_template( $question_type ){
407
+    public static function load_question_template($question_type) {
408 408
 
409
-        Sensei_Templates::get_template  ( 'single-quiz/question_type-' . $question_type . '.php' );
409
+        Sensei_Templates::get_template('single-quiz/question_type-'.$question_type.'.php');
410 410
     }
411 411
 
412 412
     /**
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
      * @since 1.9.0
418 418
      * @param $question_id
419 419
      */
420
-    public static function the_question_title( $question_id ){
420
+    public static function the_question_title($question_id) {
421 421
 
422
-        echo self::get_the_question_title( $question_id );
422
+        echo self::get_the_question_title($question_id);
423 423
 
424 424
     }// end the_question_title
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @param $question_id
432 432
      * @return string
433 433
      */
434
-    public static function get_the_question_title( $question_id ){
434
+    public static function get_the_question_title($question_id) {
435 435
 
436 436
         /**
437 437
          * Filter the sensei question title
@@ -439,17 +439,17 @@  discard block
 block discarded – undo
439 439
          * @since 1.3.0
440 440
          * @param $question_title
441 441
          */
442
-        $title = apply_filters( 'sensei_question_title', get_the_title( $question_id ) );
442
+        $title = apply_filters('sensei_question_title', get_the_title($question_id));
443 443
 
444 444
         /**
445 445
          * hook document in class-woothemes-sensei-message.php the_title()
446 446
          */
447
-        $title = apply_filters( 'sensei_single_title', $title, 'question');
447
+        $title = apply_filters('sensei_single_title', $title, 'question');
448 448
 
449 449
         $title_html  = '<span class="question question-title">';
450 450
         $title_html .= $title;
451 451
         $title_html .= '<span class="grade"><?php sensi_the_question_grade()?></span>';
452
-        $title_html .='</span>';
452
+        $title_html .= '</span>';
453 453
 
454 454
         return $title_html;
455 455
     }
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
      * @param $question_id
461 461
      * @return string
462 462
      */
463
-    public static function get_the_question_description( $question_id ){
463
+    public static function get_the_question_description($question_id) {
464 464
 
465
-        $question = get_post( $question_id );
465
+        $question = get_post($question_id);
466 466
 
467 467
         /**
468 468
          * Already documented within WordPress Core
469 469
          */
470
-        return apply_filters( 'the_content', $question->post_content );
470
+        return apply_filters('the_content', $question->post_content);
471 471
 
472 472
     }
473 473
 
@@ -477,9 +477,9 @@  discard block
 block discarded – undo
477 477
      * @since 1.9.0
478 478
      * @param $question_id
479 479
      */
480
-    public static function the_question_description( $question_id  ){
480
+    public static function the_question_description($question_id) {
481 481
 
482
-        echo self::get_the_question_description( $question_id );
482
+        echo self::get_the_question_description($question_id);
483 483
 
484 484
     }
485 485
 
@@ -490,38 +490,38 @@  discard block
 block discarded – undo
490 490
      * @param $question_id
491 491
      * @return string
492 492
      */
493
-    public static function get_the_question_media( $question_id ){
493
+    public static function get_the_question_media($question_id) {
494 494
 
495
-        $question_media = get_post_meta( $question_id, '_question_media', true );
495
+        $question_media = get_post_meta($question_id, '_question_media', true);
496 496
         $question_media_link = '';
497
-        if( 0 < intval( $question_media ) ) {
498
-            $mimetype = get_post_mime_type( $question_media );
499
-            if( $mimetype ) {
500
-                $mimetype_array = explode( '/', $mimetype);
501
-                if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
497
+        if (0 < intval($question_media)) {
498
+            $mimetype = get_post_mime_type($question_media);
499
+            if ($mimetype) {
500
+                $mimetype_array = explode('/', $mimetype);
501
+                if (isset($mimetype_array[0]) && $mimetype_array[0]) {
502 502
                     $question_media_type = $mimetype_array[0];
503
-                    $question_media_url = wp_get_attachment_url( $question_media );
504
-                    $attachment = get_post( $question_media );
503
+                    $question_media_url = wp_get_attachment_url($question_media);
504
+                    $attachment = get_post($question_media);
505 505
                     $question_media_title = $attachment->post_title;
506 506
                     $question_media_description = $attachment->post_content;
507
-                    switch( $question_media_type ) {
507
+                    switch ($question_media_type) {
508 508
                         case 'image':
509
-                            $image_size = apply_filters( 'sensei_question_image_size', 'medium', $question_id );
510
-                            $attachment_src = wp_get_attachment_image_src( $question_media, $image_size );
511
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank"><img src="' . $attachment_src[0] . '" width="' . $attachment_src[1] . '" height="' . $attachment_src[2] . '" /></a>';
509
+                            $image_size = apply_filters('sensei_question_image_size', 'medium', $question_id);
510
+                            $attachment_src = wp_get_attachment_image_src($question_media, $image_size);
511
+                            $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank"><img src="'.$attachment_src[0].'" width="'.$attachment_src[1].'" height="'.$attachment_src[2].'" /></a>';
512 512
                             break;
513 513
 
514 514
                         case 'audio':
515
-                            $question_media_link = wp_audio_shortcode( array( 'src' => $question_media_url ) );
515
+                            $question_media_link = wp_audio_shortcode(array('src' => $question_media_url));
516 516
                             break;
517 517
 
518 518
                         case 'video':
519
-                            $question_media_link = wp_video_shortcode( array( 'src' => $question_media_url ) );
519
+                            $question_media_link = wp_video_shortcode(array('src' => $question_media_url));
520 520
                             break;
521 521
 
522 522
                         default:
523
-                            $question_media_filename = basename( $question_media_url );
524
-                            $question_media_link = '<a class="' . esc_attr( $question_media_type ) . '" title="' . esc_attr( $question_media_title ) . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_filename . '</a>';
523
+                            $question_media_filename = basename($question_media_url);
524
+                            $question_media_link = '<a class="'.esc_attr($question_media_type).'" title="'.esc_attr($question_media_title).'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_filename.'</a>';
525 525
                             break;
526 526
                     }
527 527
                 }
@@ -529,21 +529,21 @@  discard block
 block discarded – undo
529 529
         }
530 530
 
531 531
         $output = '';
532
-        if( $question_media_link ) {
532
+        if ($question_media_link) {
533 533
 
534 534
                 $output .= '<div class="question_media_display">';
535
-                $output .=      $question_media_link;
535
+                $output .= $question_media_link;
536 536
                 $output .= '<dl>';
537 537
 
538
-                if( $question_media_title ) {
538
+                if ($question_media_title) {
539 539
 
540
-                   $output .= '<dt>'. $question_media_title. '</dt>';
540
+                   $output .= '<dt>'.$question_media_title.'</dt>';
541 541
 
542 542
                  }
543 543
 
544
-                if( $question_media_description ) {
544
+                if ($question_media_description) {
545 545
 
546
-                    $output .= '<dd>' . $question_media_description . '</dd>';
546
+                    $output .= '<dd>'.$question_media_description.'</dd>';
547 547
 
548 548
                 }
549 549
 
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
      * @since 1.9.0
565 565
      * @param string $question_id
566 566
      */
567
-    public static function the_question_media( $question_id ){
567
+    public static function the_question_media($question_id) {
568 568
 
569
-        echo self::get_the_question_media( $question_id );
569
+        echo self::get_the_question_media($question_id);
570 570
 
571 571
     }
572 572
 
@@ -577,11 +577,11 @@  discard block
 block discarded – undo
577 577
      *
578 578
      * @param $question_id
579 579
      */
580
-    public static function the_question_hidden_fields( $question_id ){
580
+    public static function the_question_hidden_fields($question_id) {
581 581
         ?>
582 582
 
583
-            <input type="hidden" name="question_id_<?php $question_id;?>" value="<?php $question_id;?>" />
584
-            <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e( $question_id ); ?>" />
583
+            <input type="hidden" name="question_id_<?php $question_id; ?>" value="<?php $question_id; ?>" />
584
+            <input type="hidden" name="questions_asked[]" value="<?php esc_attr_e($question_id); ?>" />
585 585
 
586 586
         <?php
587 587
     }
@@ -592,27 +592,27 @@  discard block
 block discarded – undo
592 592
      * @since 1.9.0
593 593
      * @param $question_id
594 594
      */
595
-    public static function answer_feedback_notes( $question_id ){
595
+    public static function answer_feedback_notes($question_id) {
596 596
 
597 597
         //IDS
598 598
         $quiz_id = get_the_ID();
599
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
599
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
600 600
 
601 601
         // Data to check before showing feedback
602
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, get_current_user_id() );
603
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
604
-        $not_empty_user_quiz_grade = !empty( $user_quiz_grade );
605
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
606
-        $lesson_completed = Sensei_Utils::user_completed_lesson( $lesson_id );
607
-        $quiz_grade_type = get_post_meta( $quiz_id , '_quiz_grade_type', true );
602
+        $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, get_current_user_id());
603
+        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id());
604
+        $not_empty_user_quiz_grade = ! empty($user_quiz_grade);
605
+        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id);
606
+        $lesson_completed = Sensei_Utils::user_completed_lesson($lesson_id);
607
+        $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
608 608
 
609
-        if( ( $lesson_completed  && $not_empty_user_quiz_grade  )
610
-            ||  ( $lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type )
611
-            || ( 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade ) ) {
609
+        if (($lesson_completed && $not_empty_user_quiz_grade)
610
+            ||  ($lesson_completed && ! $reset_quiz_allowed && 'auto' == $quiz_grade_type)
611
+            || ('auto' == $quiz_grade_type && ! $reset_quiz_allowed && $not_empty_user_quiz_grade)) {
612 612
 
613
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, get_current_user_id() );
613
+            $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, get_current_user_id());
614 614
 
615
-            if( $answer_notes ) { ?>
615
+            if ($answer_notes) { ?>
616 616
 
617 617
                 <div class="sensei-message info info-special answer-feedback">
618 618
 
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
                          * @param string $question_id
627 627
                          * @param string $lesson_id
628 628
                          */
629
-                        echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );
629
+                        echo apply_filters('sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id);
630 630
 
631 631
                     ?>
632 632
 
@@ -645,72 +645,72 @@  discard block
 block discarded – undo
645 645
      * @since 1.9.0
646 646
      * @param string $question_id
647 647
      */
648
-    public static function the_answer_result_indication( $question_id ){
648
+    public static function the_answer_result_indication($question_id) {
649 649
 
650
-        global $post,  $current_user, $sensei_question_loop;
650
+        global $post, $current_user, $sensei_question_loop;
651 651
 
652 652
         // Post Data
653 653
         $quiz_id = $sensei_question_loop['quiz_id'];
654
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
654
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
655 655
         $question_item = $sensei_question_loop['current_question'];
656 656
 
657 657
         // Setup variable needed to determine if the message should show and what it should show
658
-        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
659
-        $lesson_complete = Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
660
-        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed( $lesson_id );
661
-        $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
658
+        $user_quiz_grade = Sensei_Quiz::get_user_quiz_grade($lesson_id, get_current_user_id());
659
+        $lesson_complete = Sensei_Utils::user_completed_lesson($lesson_id, get_current_user_id());
660
+        $reset_quiz_allowed = Sensei_Quiz::is_reset_allowed($lesson_id);
661
+        $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
662 662
 
663 663
         // retrieve the question total grade
664
-        $question_grade = Sensei()->question->get_question_grade( $question_id );
664
+        $question_grade = Sensei()->question->get_question_grade($question_id);
665 665
 
666 666
         // retrieve grade the user achieved
667
-        $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, get_current_user_id() );
667
+        $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id());
668 668
 
669 669
         // Question ID
670 670
         $question_id = $question_item->ID;
671 671
 
672 672
         // conditions to check
673
-        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '' ;
674
-        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete &&  $user_quiz_grade != '' && ! $reset_quiz_allowed ;
675
-        $grade_type_auto_a_valid_grade_and_reset_not_allowed =  'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '' ;
673
+        $completed_with_valid_grade = $lesson_complete && $user_quiz_grade != '';
674
+        $completed_with_valid_grade_and_reset_not_allowed = $lesson_complete && $user_quiz_grade != '' && ! $reset_quiz_allowed;
675
+        $grade_type_auto_a_valid_grade_and_reset_not_allowed = 'auto' == $quiz_grade_type && ! $reset_quiz_allowed && $user_quiz_grade != '';
676 676
 
677
-        if (  $completed_with_valid_grade
677
+        if ($completed_with_valid_grade
678 678
             || $completed_with_valid_grade_and_reset_not_allowed
679
-            || $grade_type_auto_a_valid_grade_and_reset_not_allowed  ) {
679
+            || $grade_type_auto_a_valid_grade_and_reset_not_allowed) {
680 680
 
681 681
             $user_correct = false;
682
-            $answer_message = __( 'Incorrect', 'woothemes-sensei' );
682
+            $answer_message = __('Incorrect', 'woothemes-sensei');
683 683
             $answer_message_class = 'user_wrong';
684 684
             // For zero grade mark as 'correct' but add no classes
685
-            if ( 0 == $question_grade ) {
685
+            if (0 == $question_grade) {
686 686
 
687 687
                 $user_correct = true;
688 688
                 $answer_message = '';
689 689
                 $answer_message_class = '';
690 690
 
691
-            } else if( $user_question_grade > 0 ) {
691
+            } else if ($user_question_grade > 0) {
692 692
 
693 693
                 $user_correct = true;
694
-                $answer_message = sprintf( __( 'Grade: %d', 'woothemes-sensei' ), $user_question_grade );
694
+                $answer_message = sprintf(__('Grade: %d', 'woothemes-sensei'), $user_question_grade);
695 695
                 $answer_message_class = 'user_right';
696 696
 
697 697
             }
698 698
 
699 699
             // attach the correct answer if the question is auto gradable and user got it wrong
700
-            if( !$reset_quiz_allowed && !$user_correct ){
700
+            if ( ! $reset_quiz_allowed && ! $user_correct) {
701 701
 
702
-                $answer_message .=  ' - '. __('Right Answer:','woothemes-sensei') . ' ' . self::get_correct_answer( $question_item->ID );
702
+                $answer_message .= ' - '.__('Right Answer:', 'woothemes-sensei').' '.self::get_correct_answer($question_item->ID);
703 703
 
704 704
             }
705 705
 
706 706
             // answer feedback
707
-            $answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $current_user->ID );
708
-            if( $answer_notes ) {
707
+            $answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $current_user->ID);
708
+            if ($answer_notes) {
709 709
                 $answer_message_class .= ' has_notes';
710 710
             }
711 711
             ?>
712 712
 
713
-            <div class="answer_message <?php esc_attr_e( $answer_message_class ); ?>">
713
+            <div class="answer_message <?php esc_attr_e($answer_message_class); ?>">
714 714
 
715 715
                 <span><?php echo $answer_message; ?></span>
716 716
 
@@ -731,39 +731,39 @@  discard block
 block discarded – undo
731 731
      * @param $quiz_id
732 732
      * @return array $question_data
733 733
      */
734
-    public static function get_template_data( $question_id, $quiz_id ){
734
+    public static function get_template_data($question_id, $quiz_id) {
735 735
 
736
-        $lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id  );
736
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
737 737
 
738
-        $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
738
+        $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true);
739 739
         //backwards compatibility
740
-        if( 'on' == $reset_allowed ) {
740
+        if ('on' == $reset_allowed) {
741 741
             $reset_allowed = 1;
742 742
         }
743 743
 
744 744
         // Check again that the lesson is complete
745
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( Sensei()->quiz->get_lesson_id( $quiz_id), get_current_user_id() );
745
+        $user_lesson_end = Sensei_Utils::user_completed_lesson(Sensei()->quiz->get_lesson_id($quiz_id), get_current_user_id());
746 746
         $user_lesson_complete = false;
747
-        if ( $user_lesson_end ) {
747
+        if ($user_lesson_end) {
748 748
             $user_lesson_complete = true;
749 749
         }
750 750
 
751 751
         //setup the question data
752
-        $data[ 'ID' ]                     = $question_id;
753
-        $data[ 'title' ]                  = get_the_title( $question_id );
754
-        $data[ 'content' ]                = get_post( $question_id )->post_content;
755
-        $data[ 'quiz_id' ]                = $quiz_id;
756
-        $data[ 'lesson_id' ]              = Sensei()->quiz->get_lesson_id( $quiz_id );
757
-        $data[ 'type' ]                   = Sensei()->question->get_question_type( $question_id );
758
-        $data[ 'question_grade' ]         = Sensei()->question->get_question_grade(  $question_id  );
759
-        $data[ 'user_question_grade' ]    = Sensei()->quiz->get_user_question_grade( $lesson_id,  $question_id , get_current_user_id());
760
-        $data[ 'question_right_answer' ]  = get_post_meta( $question_id , '_question_right_answer', true );
761
-        $data[ 'question_wrong_answers' ] = get_post_meta( $question_id , '_question_wrong_answers', true );
762
-        $data[ 'user_answer_entry' ]      = Sensei()->quiz->get_user_question_answer( $lesson_id,  $question_id , get_current_user_id() );
763
-        $data[ 'lesson_completed' ]       = Sensei_Utils::user_completed_course( $lesson_id, get_current_user_id( ) );
764
-        $data[ 'quiz_grade_type' ]        = get_post_meta( $quiz_id , '_quiz_grade_type', true );
765
-        $data[ 'reset_quiz_allowed' ]     = $reset_allowed;
766
-        $data[ 'lesson_complete' ]        = $user_lesson_complete;
752
+        $data['ID']                     = $question_id;
753
+        $data['title']                  = get_the_title($question_id);
754
+        $data['content']                = get_post($question_id)->post_content;
755
+        $data['quiz_id']                = $quiz_id;
756
+        $data['lesson_id']              = Sensei()->quiz->get_lesson_id($quiz_id);
757
+        $data['type']                   = Sensei()->question->get_question_type($question_id);
758
+        $data['question_grade']         = Sensei()->question->get_question_grade($question_id);
759
+        $data['user_question_grade']    = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, get_current_user_id());
760
+        $data['question_right_answer']  = get_post_meta($question_id, '_question_right_answer', true);
761
+        $data['question_wrong_answers'] = get_post_meta($question_id, '_question_wrong_answers', true);
762
+        $data['user_answer_entry']      = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, get_current_user_id());
763
+        $data['lesson_completed']       = Sensei_Utils::user_completed_course($lesson_id, get_current_user_id( ));
764
+        $data['quiz_grade_type']        = get_post_meta($quiz_id, '_quiz_grade_type', true);
765
+        $data['reset_quiz_allowed']     = $reset_allowed;
766
+        $data['lesson_complete']        = $user_lesson_complete;
767 767
 
768 768
         /**
769 769
          * Filter the question template data. This filter fires  in
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
          * @param string $question_id
778 778
          * @param string $quiz_id
779 779
          */
780
-        return apply_filters( 'sensei_get_question_template_data', $data, $question_id, $quiz_id );
780
+        return apply_filters('sensei_get_question_template_data', $data, $question_id, $quiz_id);
781 781
 
782 782
     }
783 783
 
@@ -793,28 +793,28 @@  discard block
 block discarded – undo
793 793
      *
794 794
      * @return array()
795 795
      */
796
-    public static function file_upload_load_question_data ( $question_data, $question_id, $quiz_id ){
796
+    public static function file_upload_load_question_data($question_data, $question_id, $quiz_id) {
797 797
 
798 798
 
799
-        if( 'file-upload' == Sensei()->question->get_question_type( $question_id ) ) {
799
+        if ('file-upload' == Sensei()->question->get_question_type($question_id)) {
800 800
 
801 801
             // Get uploaded file
802
-            $attachment_id = $question_data[ 'user_answer_entry' ];
802
+            $attachment_id = $question_data['user_answer_entry'];
803 803
             $answer_media_url = $answer_media_filename = '';
804 804
 
805 805
 
806 806
             $question_helptext = '';
807
-            if( isset( $question_data['question_wrong_answers'][0] ) ) {
807
+            if (isset($question_data['question_wrong_answers'][0])) {
808 808
 
809
-                $question_helptext =  $question_data['question_wrong_answers'][0];
809
+                $question_helptext = $question_data['question_wrong_answers'][0];
810 810
 
811 811
             }
812 812
 
813 813
 
814
-            if( 0 < intval( $attachment_id ) ) {
814
+            if (0 < intval($attachment_id)) {
815 815
 
816
-                $answer_media_url = wp_get_attachment_url( $attachment_id );
817
-                $answer_media_filename = basename( $answer_media_url );
816
+                $answer_media_url = wp_get_attachment_url($attachment_id);
817
+                $answer_media_filename = basename($answer_media_url);
818 818
 
819 819
             }
820 820
 
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
             // Get max upload file size, formatted for display
823 823
             // Code copied from wp-admin/includes/media.php:1515
824 824
             $upload_size_unit = $max_upload_size = wp_max_upload_size();
825
-            $sizes = array( 'KB', 'MB', 'GB' );
826
-            for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ ) {
825
+            $sizes = array('KB', 'MB', 'GB');
826
+            for ($u = -1; $upload_size_unit > 1024 && $u < count($sizes) - 1; $u++) {
827 827
                 $upload_size_unit /= 1024;
828 828
             }
829
-            if ( $u < 0 ) {
829
+            if ($u < 0) {
830 830
 
831 831
                 $upload_size_unit = 0;
832 832
                 $u = 0;
@@ -836,14 +836,14 @@  discard block
 block discarded – undo
836 836
                 $upload_size_unit = (int) $upload_size_unit;
837 837
 
838 838
             }
839
-            $max_upload_size = sprintf( __( 'Maximum upload file size: %d%s' ), esc_html( $upload_size_unit ), esc_html( $sizes[ $u ] ) );
839
+            $max_upload_size = sprintf(__('Maximum upload file size: %d%s'), esc_html($upload_size_unit), esc_html($sizes[$u]));
840 840
 
841 841
             // Assemble all the data needed by the file upload template
842
-            $question_data[ 'answer_media_url' ]      = $answer_media_url;
843
-            $question_data[ 'answer_media_filename' ] = $answer_media_filename;
844
-            $question_data[ 'max_upload_size' ]       = $max_upload_size;
842
+            $question_data['answer_media_url']      = $answer_media_url;
843
+            $question_data['answer_media_filename'] = $answer_media_filename;
844
+            $question_data['max_upload_size']       = $max_upload_size;
845 845
 
846
-            $question_data[ 'question_helptext' ]     = $question_helptext;
846
+            $question_data['question_helptext']     = $question_helptext;
847 847
 
848 848
         }// end if is file upload type
849 849
 
@@ -863,27 +863,27 @@  discard block
 block discarded – undo
863 863
      *
864 864
      * @return array()
865 865
      */
866
-    public static function multiple_choice_load_question_data( $question_data, $question_id, $quiz_id ){
866
+    public static function multiple_choice_load_question_data($question_data, $question_id, $quiz_id) {
867 867
 
868
-        if( 'multiple-choice' == Sensei()->question->get_question_type( $question_id ) ) {
868
+        if ('multiple-choice' == Sensei()->question->get_question_type($question_id)) {
869 869
 
870 870
 
871 871
             $answer_type = 'radio';
872
-            if ( is_array( $question_data[ 'question_right_answer' ] ) && ( 1 < count( $question_data[ 'question_right_answer' ] ) ) ) {
872
+            if (is_array($question_data['question_right_answer']) && (1 < count($question_data['question_right_answer']))) {
873 873
 
874 874
                 $answer_type = 'checkbox';
875 875
 
876 876
             }
877 877
 
878 878
             // Merge right and wrong answers
879
-            if ( is_array( $question_data[ 'question_right_answer' ] ) ) {
879
+            if (is_array($question_data['question_right_answer'])) {
880 880
 
881
-                $merged_options = array_merge( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
881
+                $merged_options = array_merge($question_data['question_wrong_answers'], $question_data['question_right_answer']);
882 882
 
883
-            }  else {
883
+            } else {
884 884
 
885
-                array_push( $question_data[ 'question_wrong_answers' ], $question_data[ 'question_right_answer' ] );
886
-                $merged_options = $question_data[ 'question_wrong_answers' ];
885
+                array_push($question_data['question_wrong_answers'], $question_data['question_right_answer']);
886
+                $merged_options = $question_data['question_wrong_answers'];
887 887
 
888 888
             }
889 889
 
@@ -891,24 +891,24 @@  discard block
 block discarded – undo
891 891
             $question_answers_options = array();
892 892
             $count = 0;
893 893
 
894
-            foreach( $merged_options as $answer ) {
894
+            foreach ($merged_options as $answer) {
895 895
 
896 896
                 $count++;
897 897
                 $question_option = array();
898 898
 
899
-                if( ( $question_data[ 'lesson_completed' ] && $question_data[ 'user_quiz_grade' ] != '' )
900
-                    || ( $question_data[ 'lesson_completed' ] && ! $question_data[ 'reset_quiz_allowed' ] && $question_data[ 'user_quiz_grade' ] != '' )
901
-                    || ( 'auto' == $question_data[ 'quiz_grade_type' ] && ! $question_data[ 'reset_quiz_allowed' ]  && ! empty( $question_data[ 'user_quiz_grade' ] ) ) ) {
899
+                if (($question_data['lesson_completed'] && $question_data['user_quiz_grade'] != '')
900
+                    || ($question_data['lesson_completed'] && ! $question_data['reset_quiz_allowed'] && $question_data['user_quiz_grade'] != '')
901
+                    || ('auto' == $question_data['quiz_grade_type'] && ! $question_data['reset_quiz_allowed'] && ! empty($question_data['user_quiz_grade']))) {
902 902
 
903 903
                     $user_correct = false;
904 904
 
905 905
 
906 906
                     // For zero grade mark as 'correct' but add no classes
907
-                    if ( 0 == $question_data[ 'question_grade' ] ) {
907
+                    if (0 == $question_data['question_grade']) {
908 908
 
909 909
                         $user_correct = true;
910 910
 
911
-                    }  else if( $question_data[ 'user_question_grade' ] > 0 ) {
911
+                    } else if ($question_data['user_question_grade'] > 0) {
912 912
 
913 913
                         $user_correct = true;
914 914
 
@@ -918,20 +918,20 @@  discard block
 block discarded – undo
918 918
 
919 919
                 // setup the option specific classes
920 920
                 $answer_class = '';
921
-                if( isset( $user_correct ) && 0 < $question_data[ 'question_grade' ] ) {
922
-                    if ( is_array( $question_data['question_right_answer'] ) && in_array($answer, $question_data['question_right_answer']) ) {
921
+                if (isset($user_correct) && 0 < $question_data['question_grade']) {
922
+                    if (is_array($question_data['question_right_answer']) && in_array($answer, $question_data['question_right_answer'])) {
923 923
 
924 924
                         $answer_class .= ' right_answer';
925 925
 
926
-                    }  elseif( !is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer ) {
926
+                    }  elseif ( ! is_array($question_data['question_right_answer']) && $question_data['question_right_answer'] == $answer) {
927 927
 
928 928
                         $answer_class .= ' right_answer';
929 929
 
930
-                    } elseif( ( is_array( $question_data['user_answer_entry']  ) && in_array($answer, $question_data['user_answer_entry'] ) )
931
-                        ||  ( !  $question_data['user_answer_entry'] &&  $question_data['user_answer_entry'] == $answer ) ) {
930
+                    } elseif ((is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry']))
931
+                        ||  ( ! $question_data['user_answer_entry'] && $question_data['user_answer_entry'] == $answer)) {
932 932
 
933 933
                         $answer_class = 'user_wrong';
934
-                        if( $user_correct ) {
934
+                        if ($user_correct) {
935 935
 
936 936
                             $answer_class = 'user_right';
937 937
 
@@ -943,26 +943,26 @@  discard block
 block discarded – undo
943 943
 
944 944
                 // determine if the current option must be checked
945 945
                 $checked = '';
946
-                if ( isset( $question_data['user_answer_entry'] ) && 0 < count( $question_data['user_answer_entry'] ) ) {
947
-                    if ( is_array( $question_data['user_answer_entry'] ) && in_array( $answer, $question_data['user_answer_entry'] ) ) {
946
+                if (isset($question_data['user_answer_entry']) && 0 < count($question_data['user_answer_entry'])) {
947
+                    if (is_array($question_data['user_answer_entry']) && in_array($answer, $question_data['user_answer_entry'])) {
948 948
 
949 949
                         $checked = 'checked="checked"';
950 950
 
951
-                    } elseif ( !is_array( $question_data['user_answer_entry'] ) ) {
951
+                    } elseif ( ! is_array($question_data['user_answer_entry'])) {
952 952
 
953
-                        $checked = checked( $answer, $question_data['user_answer_entry'] , false );
953
+                        $checked = checked($answer, $question_data['user_answer_entry'], false);
954 954
 
955 955
                     }
956 956
 
957 957
                 } // End If Statement
958 958
 
959 959
                 //Load the answer option data
960
-                $question_option[ 'ID' ]          = Sensei()->lesson->get_answer_id( $answer );
961
-                $question_option[ 'answer' ]      = $answer;
962
-                $question_option[ 'option_class'] = $answer_class;
963
-                $question_option[ 'checked']      = $checked;
964
-                $question_option[ 'count' ]       = $count;
965
-                $question_option[ 'type' ] = $answer_type;
960
+                $question_option['ID']          = Sensei()->lesson->get_answer_id($answer);
961
+                $question_option['answer']      = $answer;
962
+                $question_option['option_class'] = $answer_class;
963
+                $question_option['checked']      = $checked;
964
+                $question_option['count']       = $count;
965
+                $question_option['type'] = $answer_type;
966 966
 
967 967
                 // add the speci  fic option to the list of options for this question
968 968
                 $question_answers_options[] = $question_option;
@@ -972,47 +972,47 @@  discard block
 block discarded – undo
972 972
 
973 973
             // Shuffle the array depending on the settings
974 974
             $answer_options_sorted = array();
975
-            $random_order = get_post_meta( $question_data['ID'], '_random_order', true );
976
-            if(  $random_order && $random_order == 'yes' ) {
975
+            $random_order = get_post_meta($question_data['ID'], '_random_order', true);
976
+            if ($random_order && $random_order == 'yes') {
977 977
 
978 978
                 $answer_options_sorted = $question_answers_options;
979
-                shuffle( $answer_options_sorted );
979
+                shuffle($answer_options_sorted);
980 980
 
981 981
             } else {
982 982
 
983 983
                 $answer_order = array();
984
-                $answer_order_string = get_post_meta( $question_data['ID'], '_answer_order', true );
985
-                if( $answer_order_string ) {
984
+                $answer_order_string = get_post_meta($question_data['ID'], '_answer_order', true);
985
+                if ($answer_order_string) {
986 986
 
987
-                    $answer_order = array_filter( explode( ',', $answer_order_string ) );
988
-                    if( count( $answer_order ) > 0 ) {
987
+                    $answer_order = array_filter(explode(',', $answer_order_string));
988
+                    if (count($answer_order) > 0) {
989 989
 
990
-                        foreach( $answer_order as $answer_id ) {
990
+                        foreach ($answer_order as $answer_id) {
991 991
 
992
-                            if( isset( $question_answers_options[ $answer_id ] ) ) {
992
+                            if (isset($question_answers_options[$answer_id])) {
993 993
 
994
-                                $answer_options_sorted[ $answer_id ] = $question_answers_options[ $answer_id ];
995
-                                unset( $question_answers_options[ $answer_id ] );
994
+                                $answer_options_sorted[$answer_id] = $question_answers_options[$answer_id];
995
+                                unset($question_answers_options[$answer_id]);
996 996
 
997 997
                             }
998 998
 
999 999
                         }
1000 1000
 
1001
-                        if( count( $question_answers_options ) > 0 ) {
1002
-                            foreach( $question_answers_options as $id => $answer ) {
1001
+                        if (count($question_answers_options) > 0) {
1002
+                            foreach ($question_answers_options as $id => $answer) {
1003 1003
 
1004
-                                $answer_options_sorted[ $id ] = $answer;
1004
+                                $answer_options_sorted[$id] = $answer;
1005 1005
 
1006 1006
                             }
1007 1007
                         }
1008 1008
 
1009
-                    }else{
1009
+                    } else {
1010 1010
 
1011 1011
                         $answer_options_sorted = $question_answers_options;
1012 1012
 
1013 1013
                     }
1014 1014
 
1015
-                }else{
1015
+                } else {
1016 1016
 
1017 1017
                     $answer_options_sorted = $question_answers_options;
1018 1018
 
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
 
1023 1023
 
1024 1024
             // assemble and setup the data for the templates data array
1025
-            $question_data[ 'answer_options' ]    =  $answer_options_sorted;
1025
+            $question_data['answer_options'] = $answer_options_sorted;
1026 1026
 
1027 1027
         }
1028 1028
 
@@ -1042,14 +1042,14 @@  discard block
 block discarded – undo
1042 1042
      *
1043 1043
      * @return array()
1044 1044
      */
1045
-    public static function gap_fill_load_question_data( $question_data, $question_id, $quiz_id ){
1045
+    public static function gap_fill_load_question_data($question_data, $question_id, $quiz_id) {
1046 1046
 
1047
-        if( 'gap-fill' == Sensei()->question->get_question_type( $question_id ) ) {
1047
+        if ('gap-fill' == Sensei()->question->get_question_type($question_id)) {
1048 1048
 
1049
-            $gapfill_array = explode( '||', $question_data[ 'question_right_answer' ] );
1050
-            $question_data[ 'gapfill_pre' ]  = isset( $gapfill_array[0] ) ? $gapfill_array[0] : '';
1051
-            $question_data[ 'gapfill_gap' ]  = isset( $gapfill_array[1] ) ? $gapfill_array[1] : '';
1052
-            $question_data[ 'gapfill_post' ] = isset( $gapfill_array[2] ) ? $gapfill_array[2] : '';
1049
+            $gapfill_array = explode('||', $question_data['question_right_answer']);
1050
+            $question_data['gapfill_pre']  = isset($gapfill_array[0]) ? $gapfill_array[0] : '';
1051
+            $question_data['gapfill_gap']  = isset($gapfill_array[1]) ? $gapfill_array[1] : '';
1052
+            $question_data['gapfill_post'] = isset($gapfill_array[2]) ? $gapfill_array[2] : '';
1053 1053
 
1054 1054
         }
1055 1055
 
@@ -1064,32 +1064,32 @@  discard block
 block discarded – undo
1064 1064
      * @param $question_id
1065 1065
      * @return string $correct_answer or empty
1066 1066
      */
1067
-    public static function get_correct_answer( $question_id ){
1067
+    public static function get_correct_answer($question_id) {
1068 1068
 
1069
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
1070
-        $type = Sensei()->question->get_question_type( $question_id );
1071
-        $type_name = __( 'Multiple Choice', 'woothemes-sensei' );
1069
+        $right_answer = get_post_meta($question_id, '_question_right_answer', true);
1070
+        $type = Sensei()->question->get_question_type($question_id);
1071
+        $type_name = __('Multiple Choice', 'woothemes-sensei');
1072 1072
         $grade_type = 'manual-grade';
1073 1073
 
1074
-        if ('boolean'== $type ) {
1074
+        if ('boolean' == $type) {
1075 1075
 
1076 1076
             $right_answer = ucfirst($right_answer);
1077 1077
 
1078
-        }elseif( 'multiple-choice' == $type ) {
1078
+        }elseif ('multiple-choice' == $type) {
1079 1079
 
1080 1080
             $right_answer = (array) $right_answer;
1081
-            $right_answer = implode( ', ', $right_answer );
1081
+            $right_answer = implode(', ', $right_answer);
1082 1082
 
1083
-        }elseif( 'gap-fill' == $type ) {
1083
+        }elseif ('gap-fill' == $type) {
1084 1084
 
1085
-            $right_answer_array = explode( '||', $right_answer );
1086
-            if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
-            if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
-            if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1085
+            $right_answer_array = explode('||', $right_answer);
1086
+            if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
1087
+            if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
1088
+            if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
1089 1089
 
1090
-            $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
1090
+            $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post;
1091 1091
 
1092
-        }else{
1092
+        } else {
1093 1093
 
1094 1094
             // for non auto gradable question types no answer should be returned.
1095 1095
             $right_answer = '';
@@ -1107,4 +1107,4 @@  discard block
 block discarded – undo
1107 1107
  * for backward compatibility
1108 1108
  * @since 1.9.0
1109 1109
  */
1110
-class WooThemes_Sensei_Question extends Sensei_Question{}
1110
+class WooThemes_Sensei_Question extends Sensei_Question {}
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-legacy-shortcodes.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -15,14 +15,14 @@  discard block
 block discarded – undo
15 15
      *
16 16
      * @since 1.9.0
17 17
      */
18
-    public static function init(){
18
+    public static function init() {
19 19
 
20
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
21
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
22
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
23
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
24
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
25
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
20
+        add_shortcode('allcourses', array(__CLASS__, 'all_courses'));
21
+        add_shortcode('newcourses', array(__CLASS__, 'new_courses'));
22
+        add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses'));
23
+        add_shortcode('freecourses', array(__CLASS__, 'free_courses'));
24
+        add_shortcode('paidcourses', array(__CLASS__, 'paid_courses'));
25
+        add_shortcode('usercourses', array(__CLASS__, 'user_courses'));
26 26
 
27 27
     }
28 28
     /**
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
      * @param mixed $content (default: null)
36 36
      * @return string
37 37
      */
38
-    public static function all_courses( $atts, $content = null ) {
38
+    public static function all_courses($atts, $content = null) {
39 39
 
40
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
40
+        return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title
41 41
 
42 42
     } // all_courses()
43 43
 
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
      * @param mixed $content (default: null)
50 50
      * @return string
51 51
      */
52
-    public static function paid_courses( $atts, $content = null ) {
52
+    public static function paid_courses($atts, $content = null) {
53 53
 
54
-        return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' );
54
+        return self::generate_shortcode_courses('Paid Courses', 'paidcourses');
55 55
 
56 56
     } // End paid_courses()
57 57
 
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
      * @param mixed $content (default: null)
65 65
      * @return string
66 66
      */
67
-    public static function featured_courses( $atts, $content = null ) {
67
+    public static function featured_courses($atts, $content = null) {
68 68
 
69
-        return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' );
69
+        return self::generate_shortcode_courses('Featured Courses', 'featuredcourses');
70 70
 
71 71
     } // End featured_courses()
72 72
 
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
      * @param mixed $content (default: null)
79 79
      * @return string
80 80
      */
81
-    public static function free_courses( $atts, $content = null ) {
81
+    public static function free_courses($atts, $content = null) {
82 82
 
83
-        return self::generate_shortcode_courses( 'Free Courses', 'freecourses' );
83
+        return self::generate_shortcode_courses('Free Courses', 'freecourses');
84 84
 
85 85
     } // End free_courses()
86 86
 
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
      * @param mixed $content (default: null)
93 93
      * @return string
94 94
      */
95
-    public static function new_courses( $atts, $content = null ) {
95
+    public static function new_courses($atts, $content = null) {
96 96
 
97
-        return self::generate_shortcode_courses( 'New Courses', 'newcourses' );
97
+        return self::generate_shortcode_courses('New Courses', 'newcourses');
98 98
 
99 99
     } // End new_courses()
100 100
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param $shortcode_specific_override
108 108
      * @return string
109 109
      */
110
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
110
+    public static function generate_shortcode_courses($title, $shortcode_specific_override) {
111 111
 
112 112
         global  $shortcode_override, $posts_array;
113 113
 
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
 
116 116
         // do not show this short code if there is a shortcode int he url and
117 117
         // this specific shortcode is not the one requested in the ur.
118
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
119
-        if( ! empty( $specific_shortcode_requested) &&
120
-            $specific_shortcode_requested != $shortcode_override ){
118
+        $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
119
+        if ( ! empty($specific_shortcode_requested) &&
120
+            $specific_shortcode_requested != $shortcode_override) {
121 121
 
122 122
             return '';
123 123
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
         $courses = ob_get_clean();
130 130
 
131 131
         $content = '';
132
-        if( count( $posts_array ) > 0 ){
132
+        if (count($posts_array) > 0) {
133 133
 
134
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
134
+            $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>';
135 135
             $before .= '<section id="main-course" class="course-container">';
136 136
 
137 137
             $after = '</section>';
138 138
 
139 139
             //assemble
140
-            $content = $before . $courses . $after;
140
+            $content = $before.$courses.$after;
141 141
 
142 142
         }
143 143
 
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
      * @param mixed $content (default: null)
155 155
      * @return string
156 156
      */
157
-    public static function user_courses( $atts, $content = null ) {
157
+    public static function user_courses($atts, $content = null) {
158 158
         global $shortcode_override;
159
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
159
+        extract(shortcode_atts(array('amount' => 0), $atts));
160 160
 
161 161
         $shortcode_override = 'usercourses';
162 162
 
163 163
         ob_start();
164 164
 
165
-        if( is_user_logged_in() ){
165
+        if (is_user_logged_in()) {
166 166
 
167
-            Sensei_Templates::get_template( 'user/my-courses.php' );
167
+            Sensei_Templates::get_template('user/my-courses.php');
168 168
 
169
-        }else{
169
+        } else {
170 170
 
171 171
             Sensei()->frontend->sensei_login_form();
172 172
 
@@ -182,54 +182,54 @@  discard block
 block discarded – undo
182 182
      * loop-course.php for the old shortcodes.
183 183
      * @since 1.9.0
184 184
      */
185
-    public static function initialise_legacy_course_loop(){
185
+    public static function initialise_legacy_course_loop() {
186 186
 
187 187
         global  $post, $wp_query, $shortcode_override, $course_excludes;
188 188
 
189 189
         // Handle Query Type
190 190
         $query_type = '';
191 191
 
192
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
193
-            $query_type = esc_html( $_GET[ 'action' ] );
192
+        if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) {
193
+            $query_type = esc_html($_GET['action']);
194 194
         } // End If Statement
195 195
 
196
-        if ( '' != $shortcode_override ) {
196
+        if ('' != $shortcode_override) {
197 197
             $query_type = $shortcode_override;
198 198
         } // End If Statement
199 199
 
200
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
200
+        if ( ! is_array($course_excludes)) { $course_excludes = array(); }
201 201
 
202 202
         // Check that query returns results
203 203
         // Handle Pagination
204
-        $paged = $wp_query->get( 'paged' );
205
-        $paged = empty( $paged ) ? 1 : $paged;
204
+        $paged = $wp_query->get('paged');
205
+        $paged = empty($paged) ? 1 : $paged;
206 206
 
207 207
 
208 208
         // Check for pagination settings
209
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
209
+        if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) {
210 210
 
211
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
211
+            $amount = absint(Sensei()->settings->settings['course_archive_amount']);
212 212
 
213 213
         } else {
214 214
 
215
-            $amount = $wp_query->get( 'posts_per_page' );
215
+            $amount = $wp_query->get('posts_per_page');
216 216
 
217 217
         } // End If Statement
218 218
 
219 219
         // This is not a paginated page (or it's simply the first page of a paginated page/post)
220 220
 
221 221
         global $posts_array;
222
-        $course_includes   = array();
222
+        $course_includes = array();
223 223
 
224
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
225
-        $course_query = new WP_Query( $query_args );
224
+        $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes);
225
+        $course_query = new WP_Query($query_args);
226 226
         $posts_array = $course_query->get_posts();
227 227
 
228 228
         // output the courses
229
-        if( ! empty( $posts_array ) ) {
229
+        if ( ! empty($posts_array)) {
230 230
 
231 231
             //output all courses for current query
232
-            self::loop_courses( $course_query, $amount );
232
+            self::loop_courses($course_query, $amount);
233 233
 
234 234
         }
235 235
 
@@ -242,31 +242,31 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @param WP_Query $course_query
244 244
      */
245
-    public static function loop_courses( $course_query, $amount ){
245
+    public static function loop_courses($course_query, $amount) {
246 246
 
247 247
         global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
248 248
 
249
-        if ( count( $course_query->get_posts() ) > 0 ) {
249
+        if (count($course_query->get_posts()) > 0) {
250 250
 
251
-            do_action( 'sensei_course_archive_header', $shortcode_override );
251
+            do_action('sensei_course_archive_header', $shortcode_override);
252 252
 
253
-            foreach ( $course_query->get_posts() as $course){
253
+            foreach ($course_query->get_posts() as $course) {
254 254
 
255 255
                 // Make sure the other loops dont include the same post twice!
256
-                array_push( $course_excludes, $course->ID );
256
+                array_push($course_excludes, $course->ID);
257 257
 
258 258
                 // output the course markup
259
-                self::the_course( $course->ID );
259
+                self::the_course($course->ID);
260 260
 
261 261
             } // End For Loop
262 262
 
263 263
             // More and Prev links
264
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
264
+            $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes));
265 265
             $posts_array       = $posts_array_query->get_posts();
266 266
             $max_pages = $course_query->found_posts / $amount;
267
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
267
+            if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) {
268 268
 
269
-                switch( $shortcode_override ){
269
+                switch ($shortcode_override) {
270 270
                     case 'paidcourses':
271 271
                         $filter = 'paid';
272 272
                         break;
@@ -282,22 +282,22 @@  discard block
 block discarded – undo
282 282
                 }
283 283
 
284 284
                 $quer_args = array();
285
-                $quer_args[ 'paged' ] = '2';
286
-                if( !empty( $filter ) ){
287
-                    $quer_args[ 'course_filter' ] = $filter;
285
+                $quer_args['paged'] = '2';
286
+                if ( ! empty($filter)) {
287
+                    $quer_args['course_filter'] = $filter;
288 288
                 }
289 289
 
290
-                $course_pagination_link = get_post_type_archive_link( 'course' );
291
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
292
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
290
+                $course_pagination_link = get_post_type_archive_link('course');
291
+                $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']);
292
+                $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link));
293 293
 
294 294
                 // next/more
295 295
                 $html  = '<div class="navigation"><div class="nav-next">';
296
-                $html .= '<a href="' . $more_link_url . '">';
296
+                $html .= '<a href="'.$more_link_url.'">';
297 297
                 $html .= $more_link_text;
298 298
                 $html .= '<span class="meta-nav"></span></a></div>';
299 299
 
300
-                echo apply_filters( 'course_archive_next_link', $html );
300
+                echo apply_filters('course_archive_next_link', $html);
301 301
 
302 302
             } // End If Statement
303 303
 
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
      *
310 310
      * @param $course_id
311 311
      */
312
-    public static function the_course( $course_id ){
312
+    public static function the_course($course_id) {
313 313
 
314 314
         // Get meta data
315
-        $course =  get_post( $course_id );
316
-        $user_info = get_userdata( absint( $course->post_author ) );
317
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
315
+        $course = get_post($course_id);
316
+        $user_info = get_userdata(absint($course->post_author));
317
+        $author_link = get_author_posts_url(absint($course->post_author));
318 318
         $author_display_name = $user_info->display_name;
319 319
         $author_id = $course->post_author;
320
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
321
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
322
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
320
+        $category_output = get_the_term_list($course_id, 'course-category', '', ', ', '');
321
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id));
322
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
323 323
         ?>
324 324
 
325
-        <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
325
+        <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>">
326 326
             <?php
327 327
             // so that legacy shortcodes work with thir party plugins that wants to hook in
328
-            do_action('sensei_course_content_before',$course );
328
+            do_action('sensei_course_content_before', $course);
329 329
             ?>
330 330
             <div class="course-content">
331 331
 
@@ -341,19 +341,19 @@  discard block
 block discarded – undo
341 341
 
342 342
                     <p class="sensei-course-meta">
343 343
 
344
-                        <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
345
-                            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name   ); ?></a></span>
344
+                        <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
345
+                            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
346 346
                         <?php } // End If Statement ?>
347 347
 
348 348
                         <span class="course-lesson-count">
349
-                                    <?php echo Sensei()->course->course_lesson_count( $course_id ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?>
349
+                                    <?php echo Sensei()->course->course_lesson_count($course_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?>
350 350
                                 </span>
351 351
 
352
-                        <?php if ( '' != $category_output ) { ?>
353
-                            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
352
+                        <?php if ('' != $category_output) { ?>
353
+                            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
354 354
                         <?php } // End If Statement ?>
355 355
 
356
-                        <?php sensei_simple_course_price( $course_id ); ?>
356
+                        <?php sensei_simple_course_price($course_id); ?>
357 357
 
358 358
                     </p>
359 359
 
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
 
362 362
                     </p>
363 363
 
364
-                    <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
365
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
364
+                    <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) {
365
+                        $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
366 366
                         <p class="sensei-free-lessons">
367
-                            <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
367
+                            <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?>
368 368
                             </a> - <?php echo $preview_lessons; ?>
369 369
                         </p>
370 370
                     <?php } ?>
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-unpurchased-courses.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_unpurchased_courses] shortcode when a user is logged in. If the user is not logged in
@@ -45,25 +45,25 @@  discard block
 block discarded – undo
45 45
      * @param string $content
46 46
      * @param string $shortcode the shortcode that was called for this instance
47 47
      */
48
-    public function __construct( $attributes, $content, $shortcode ){
48
+    public function __construct($attributes, $content, $shortcode) {
49 49
 
50
-        if( !is_user_logged_in() ) {
50
+        if ( ! is_user_logged_in()) {
51 51
             return;
52 52
         }
53 53
 
54 54
         // set up all argument need for constructing the course query
55
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
55
+        $this->number = isset($attributes['number']) ? $attributes['number'] : '10';
56
+        $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title';
57 57
 
58 58
         // set the default for menu_order to be ASC
59
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
59
+        if ('menu_order' == $this->orderby && ! isset($attributes['order'])) {
60 60
 
61
-            $this->order =  'ASC';
61
+            $this->order = 'ASC';
62 62
 
63
-        }else{
63
+        } else {
64 64
 
65 65
             // for everything else use the value passed or the default DESC
66
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
66
+            $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC';
67 67
 
68 68
         }
69 69
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @since 1.9.0
79 79
      */
80
-    protected function setup_course_query(){
80
+    protected function setup_course_query() {
81 81
 
82 82
         // course query parameters to be used for all courses
83 83
         $query_args = array(
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
         );
91 91
 
92 92
         // get all the courses that has a product attached
93
-        $all_courses_query = new WP_Query( $query_args );
93
+        $all_courses_query = new WP_Query($query_args);
94 94
 
95 95
         $paid_courses_not_taken = array();
96 96
         // look through all course and find the purchasable ones that user has not purchased
97
-        foreach( $all_courses_query->posts as $course ){
97
+        foreach ($all_courses_query->posts as $course) {
98 98
 
99 99
             // only keep the courses with a product including only  courses that the user not taking
100
-            $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
101
-            if( is_numeric( $course_product_id )
100
+            $course_product_id = get_post_meta($course->ID, '_course_woocommerce_product', true);
101
+            if (is_numeric($course_product_id)
102 102
                 &&
103
-                ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
104
-            ){
103
+                ! Sensei_Utils::user_started_course($course->ID, get_current_user_id())
104
+            ) {
105 105
 
106 106
                     $paid_courses_not_taken[] = $course->ID;
107 107
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         // this query will be loaded into the global WP_Query in the render function.
115 115
         $query_args['post__in'] = $paid_courses_not_taken;
116 116
         $query_args['posts_per_page'] = $this->number;
117
-        $this->query = new WP_Query( $query_args );
117
+        $this->query = new WP_Query($query_args);
118 118
 
119 119
     }// end setup _course_query
120 120
 
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
      *
124 124
      * @return string $content
125 125
      */
126
-    public function render(){
126
+    public function render() {
127 127
 
128 128
         global $wp_query;
129 129
 
130
-        if( ! is_user_logged_in() ) {
130
+        if ( ! is_user_logged_in()) {
131 131
             return '';
132 132
         }
133 133
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 
140 140
         ob_start();
141 141
         Sensei_Templates::get_template('loop-course.php');
142
-        $shortcode_output =  ob_get_clean();
142
+        $shortcode_output = ob_get_clean();
143 143
 
144 144
         //restore old query
145 145
         $wp_query = $current_global_query;
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,15 +11,15 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
     /**
16 16
      * Load the files needed for the woocommerce integration.
17 17
      *
18 18
      * @since 1.9.0
19 19
      */
20
-    public static function load_woocommerce_integration_hooks(){
20
+    public static function load_woocommerce_integration_hooks() {
21 21
 
22
-        require_once( __DIR__ . '/hooks/woocommerce.php' );
22
+        require_once(__DIR__.'/hooks/woocommerce.php');
23 23
 
24 24
     }
25 25
     /**
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
      * @since 1.9.0
29 29
      * @return bool
30 30
      */
31
-    public static function is_woocommerce_active(){
31
+    public static function is_woocommerce_active() {
32 32
 
33
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
33
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
34 34
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
35 35
 
36 36
     } // end is_woocommerce_active
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return bool
47 47
      */
48
-    public static function is_woocommerce_present(){
48
+    public static function is_woocommerce_present() {
49 49
 
50
-        $active_plugins = (array) get_option( 'active_plugins', array() );
50
+        $active_plugins = (array) get_option('active_plugins', array());
51 51
 
52
-        if ( is_multisite() ){
52
+        if (is_multisite()) {
53 53
 
54
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
54
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
55 55
 
56 56
         }
57 57
 
58
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
58
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
59 59
 
60
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
60
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
61 61
 
62 62
     }// end is_woocommerce_present
63 63
 
@@ -70,48 +70,48 @@  discard block
 block discarded – undo
70 70
      * @param $course_id
71 71
      * @return array $user_course_orders
72 72
      */
73
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
73
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
74 74
 
75
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
75
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
76 76
 
77
-        $orders_query = new WP_Query( array(
77
+        $orders_query = new WP_Query(array(
78 78
             'post_type'   => 'shop_order',
79 79
             'posts_per_page' => -1,
80
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
80
+            'post_status' => array('wc-processing', 'wc-completed'),
81 81
             'meta_key'=> '_customer_user',
82 82
             'meta_value'=> $user_id,
83
-        ) );
83
+        ));
84 84
 
85
-        if( $orders_query->post_count == 0 ){
85
+        if ($orders_query->post_count == 0) {
86 86
 
87 87
             return false;
88 88
 
89 89
         }
90 90
 
91
-        foreach( $orders_query->get_posts() as $order ){
91
+        foreach ($orders_query->get_posts() as $order) {
92 92
 
93
-            $order = new WC_Order( $order->ID );
93
+            $order = new WC_Order($order->ID);
94 94
             $items = $order->get_items();
95 95
 
96
-            $user_orders =  array();
96
+            $user_orders = array();
97 97
 
98
-            foreach( $items as $item ){
98
+            foreach ($items as $item) {
99 99
 
100 100
                 // if the product id on the order and the one given to this function
101 101
                 // this order has been placed by the given user on the given course.
102
-                $product = wc_get_product( $item['product_id'] );
102
+                $product = wc_get_product($item['product_id']);
103 103
 
104
-                if ( $product->is_type( 'variable' )) {
104
+                if ($product->is_type('variable')) {
105 105
 
106 106
                     $item_product_id = $item['variation_id'];
107 107
 
108 108
                 } else {
109 109
 
110
-                    $item_product_id =  $item['product_id'];
110
+                    $item_product_id = $item['product_id'];
111 111
 
112 112
                 }
113 113
 
114
-                if( $course_product_id == $item_product_id ){
114
+                if ($course_product_id == $item_product_id) {
115 115
 
116 116
                     return $order->id;
117 117
 
@@ -135,28 +135,28 @@  discard block
 block discarded – undo
135 135
      * @param $filter_links
136 136
      * @return mixed
137 137
      */
138
-    public static function add_course_archive_wc_filter_links( $filter_links ){
138
+    public static function add_course_archive_wc_filter_links($filter_links) {
139 139
 
140
-        $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url() );
140
+        $course_url = remove_query_arg('paged', Sensei_Utils::get_current_url());
141 141
 
142 142
         $free_courses = self::get_free_courses();
143 143
         $paid_courses = self::get_paid_courses();
144 144
 
145
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
+        if (empty($free_courses) || empty($paid_courses)) {
146 146
             // do not show any WooCommerce filters if all courses are
147 147
             // free or if all courses are paid
148 148
             return $filter_links;
149 149
 
150 150
         }
151 151
 
152
-        $filter_links[] = array(    'id'=>'paid' ,
152
+        $filter_links[] = array('id'=>'paid',
153 153
                                     'url'=> add_query_arg('course_filter', 'paid', $course_url),
154
-                                    'title'=>__( 'Paid', 'woothemes-sensei' )
154
+                                    'title'=>__('Paid', 'woothemes-sensei')
155 155
         );
156 156
 
157
-        $filter_links[] = array(    'id'=>'free',
157
+        $filter_links[] = array('id'=>'free',
158 158
                                     'url'=>add_query_arg('course_filter', 'free', $course_url),
159
-                                    'title'=>__( 'Free', 'woothemes-sensei' )
159
+                                    'title'=>__('Free', 'woothemes-sensei')
160 160
         );
161 161
 
162 162
         return $filter_links;
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
      * @param WP_Query $query
174 174
      * @return WP_Query $query
175 175
      */
176
-    public static function course_archive_wc_filter_free( $query ){
176
+    public static function course_archive_wc_filter_free($query) {
177 177
 
178
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
179
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
178
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
179
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
180 180
 
181 181
             // setup the course meta query
182 182
             $meta_query = self::get_free_courses_meta_query_args();
183 183
 
184 184
             // manipulate the query to return free courses
185
-            $query->set('meta_query', $meta_query );
185
+            $query->set('meta_query', $meta_query);
186 186
 
187 187
             // don't show any paid courses
188 188
             $courses = self::get_paid_courses();
189 189
             $ids = array();
190
-            foreach( $courses as $course ){
190
+            foreach ($courses as $course) {
191 191
                 $ids[] = $course->ID;
192 192
             }
193
-            $query->set( 'post__not_in', $ids );
193
+            $query->set('post__not_in', $ids);
194 194
 
195 195
         }// end if course_filter
196 196
 
@@ -209,16 +209,16 @@  discard block
 block discarded – undo
209 209
      * @param WP_Query $query
210 210
      * @return WP_Query $query
211 211
      */
212
-    public static function course_archive_wc_filter_paid( $query ){
212
+    public static function course_archive_wc_filter_paid($query) {
213 213
 
214
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
215
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
214
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
215
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
216 216
 
217 217
             // setup the course meta query
218 218
             $meta_query = self::get_paid_courses_meta_query_args();
219 219
 
220 220
             // manipulate the query to return free courses
221
-            $query->set('meta_query', $meta_query );
221
+            $query->set('meta_query', $meta_query);
222 222
 
223 223
         }
224 224
 
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
      * single courses if woocommerce is active allowing purchase
232 232
      * information and actions to be hooked from WooCommerce.
233 233
      */
234
-    public static function do_single_course_wc_single_product_action(){
234
+    public static function do_single_course_wc_single_product_action() {
235 235
 
236 236
         /**
237 237
          * this hooks is documented within the WooCommerce plugin.
238 238
          */
239
-        if ( Sensei_WC::is_woocommerce_active() ) {
239
+        if (Sensei_WC::is_woocommerce_active()) {
240 240
 
241
-            do_action( 'woocommerce_before_single_product' );
241
+            do_action('woocommerce_before_single_product');
242 242
 
243 243
         } // End If Statement
244 244
 
@@ -259,23 +259,23 @@  discard block
 block discarded – undo
259 259
      * @param $user_id
260 260
      * @return bool
261 261
      */
262
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
262
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
263 263
 
264 264
         // check if the course has a valid product attached to it
265 265
         // which the user should have purchased if they want to access
266 266
         // the current lesson
267
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
268
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
267
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
268
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
269 269
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
270
-        if( isset ($product) && is_object($product) ){
270
+        if (isset ($product) && is_object($product)) {
271 271
 
272 272
             // valid product found
273
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
273
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
274 274
 
275 275
             // product has a successful order so this user may access the content
276 276
             // this function may only return false or the default
277 277
             // returning true may override other negatives which we don't want
278
-            if( ! $order_id ){
278
+            if ( ! $order_id) {
279 279
 
280 280
                 return false;
281 281
 
@@ -298,23 +298,23 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public static function course_link_from_order( ) {
300 300
 
301
-        if( ! is_order_received_page() ){
301
+        if ( ! is_order_received_page()) {
302 302
             return;
303 303
         }
304 304
 
305
-        $order_id = get_query_var( 'order-received' );
306
-		$order = new WC_Order( $order_id );
305
+        $order_id = get_query_var('order-received');
306
+		$order = new WC_Order($order_id);
307 307
 
308 308
 		// exit early if not wc-completed or wc-processing
309
-		if( 'wc-completed' != $order->post_status
310
-            && 'wc-processing' != $order->post_status  ) {
309
+		if ('wc-completed' != $order->post_status
310
+            && 'wc-processing' != $order->post_status) {
311 311
             return;
312 312
         }
313 313
 
314 314
         $course_links = array(); // store the for links for courses purchased
315
-		foreach ( $order->get_items() as $item ) {
315
+		foreach ($order->get_items() as $item) {
316 316
 
317
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
317
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
318 318
 
319 319
                 // If item has variation_id then its a variation of the product
320 320
                 $item_id = $item['variation_id'];
@@ -326,28 +326,28 @@  discard block
 block discarded – undo
326 326
 
327 327
             } // End If Statement
328 328
 
329
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
329
+            $user_id = get_post_meta($order->id, '_customer_user', true);
330 330
 
331
-            if( $user_id ) {
331
+            if ($user_id) {
332 332
 
333 333
                 // Get all courses for product
334 334
                 $args = Sensei_Course::get_default_query_args();
335
-                $args['meta_query'] = array( array(
335
+                $args['meta_query'] = array(array(
336 336
                             'key' => '_course_woocommerce_product',
337 337
                             'value' => $item_id
338
-                        ) );
338
+                        ));
339 339
                 $args['orderby'] = 'menu_order date';
340 340
                 $args['order'] = 'ASC';
341 341
 
342 342
                 // loop through courses
343
-                $courses = get_posts( $args );
344
-                if( $courses && count( $courses ) > 0 ) {
343
+                $courses = get_posts($args);
344
+                if ($courses && count($courses) > 0) {
345 345
 
346
-                    foreach( $courses as $course ) {
346
+                    foreach ($courses as $course) {
347 347
 
348 348
                         $title = $course->post_title;
349
-                        $permalink = get_permalink( $course->ID );
350
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
349
+                        $permalink = get_permalink($course->ID);
350
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
351 351
 
352 352
                     } // end for each
353 353
 
@@ -358,24 +358,24 @@  discard block
 block discarded – undo
358 358
         }// end loop through orders
359 359
 
360 360
         // add the courses to the WooCommerce notice
361
-        if( ! empty( $course_links) ){
361
+        if ( ! empty($course_links)) {
362 362
 
363 363
             $courses_html = _nx(
364 364
                 'You have purchased the following course:',
365 365
                 'You have purchased the following courses:',
366
-                count( $course_links ),
366
+                count($course_links),
367 367
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
368 368
             );
369 369
 
370
-            foreach( $course_links as $link ){
370
+            foreach ($course_links as $link) {
371 371
 
372
-                $courses_html .= '<li>' . $link . '</li>';
372
+                $courses_html .= '<li>'.$link.'</li>';
373 373
 
374 374
             }
375 375
 
376 376
             $courses_html .= ' </ul>';
377 377
 
378
-            wc_add_notice( $courses_html, 'success' );
378
+            wc_add_notice($courses_html, 'success');
379 379
         }
380 380
 
381 381
 	} // end course_link_order_form
@@ -388,20 +388,20 @@  discard block
 block discarded – undo
388 388
      *
389 389
      * @since 1.9.0
390 390
      */
391
-    public static function course_in_cart_message(){
391
+    public static function course_in_cart_message() {
392 392
 
393 393
         global $post;
394 394
 
395
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
395
+        if (self::is_course_in_cart($post->ID)) { ?>
396 396
 
397 397
             <div class="sensei-message info">'
398 398
                 <?php
399 399
 
400
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
401
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
402
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
400
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
401
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
402
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
403 403
 
404
-                sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
404
+                sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
405 405
 
406 406
                 ?>
407 407
             </div>
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
      * @param $course_id
416 416
      * @return bool
417 417
      */
418
-    public static function is_course_in_cart( $course_id ){
418
+    public static function is_course_in_cart($course_id) {
419 419
 
420
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
421
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
420
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
421
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
422 422
 
423
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
423
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
424 424
 
425
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
425
+            if (self::is_product_in_cart($wc_post_id)) {
426 426
 
427 427
                 return true;
428 428
 
@@ -440,20 +440,20 @@  discard block
 block discarded – undo
440 440
      * @param $product_id
441 441
      * @return bool
442 442
      */
443
-    public static function is_product_in_cart( $product_id ){
443
+    public static function is_product_in_cart($product_id) {
444 444
 
445
-        if ( 0 < $product_id ) {
445
+        if (0 < $product_id) {
446 446
 
447
-            $product = wc_get_product( $product_id );
447
+            $product = wc_get_product($product_id);
448 448
 
449 449
             $parent_id = '';
450
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
450
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
451 451
                 $wc_product_id = $product->parent->id;
452 452
             }
453
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
453
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
454 454
 
455 455
                 $cart_product = $values['data'];
456
-                if( $product_id == $cart_product->id ) {
456
+                if ($product_id == $cart_product->id) {
457 457
 
458 458
                     return true;
459 459
 
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
      *  @type int $wp_post_id
476 476
      * }
477 477
      */
478
-    public static function get_free_product_ids(){
478
+    public static function get_free_product_ids() {
479 479
 
480
-        return  get_posts( array(
480
+        return  get_posts(array(
481 481
             'post_type' => 'product',
482 482
             'posts_per_page' => '1000',
483 483
             'fields' => 'ids',
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @since 1.9.0
503 503
      * @return array $wp_meta_query_param
504 504
      */
505
-    public static function get_free_courses_meta_query_args(){
505
+    public static function get_free_courses_meta_query_args() {
506 506
 
507 507
         return array(
508 508
             'relation' => 'OR',
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
      * @since 1.9.0
527 527
      * @return array $wp_query_meta_query_args_param
528 528
      */
529
-    public static function get_paid_courses_meta_query_args(){
529
+    public static function get_paid_courses_meta_query_args() {
530 530
 
531 531
         $paid_product_ids = self::get_paid_product_ids();
532 532
 
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                 'key'     => '_course_woocommerce_product',
536 536
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
537 537
                 // query
538
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
538
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
539 539
                 'compare' => 'IN',
540 540
             ),
541 541
         );
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
      * @since 1.9.0
550 550
      * @return array $product_query_args
551 551
      */
552
-    public static function get_paid_products_on_sale_query_args(){
552
+    public static function get_paid_products_on_sale_query_args() {
553 553
 
554 554
         $args = array(
555 555
                    'post_type' 		=> 'product',
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
                    'suppress_filters' 	=> 0
560 560
         );
561 561
 
562
-        $args[ 'fields' ]     = 'ids';
562
+        $args['fields']     = 'ids';
563 563
 
564
-        $args[ 'meta_query' ] = array(
564
+        $args['meta_query'] = array(
565 565
             'relation' => 'AND',
566 566
             array(
567 567
                 'key'=> '_regular_price',
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
      *
589 589
      * @return array
590 590
      */
591
-    public static function get_paid_products_not_on_sale_query_args(){
591
+    public static function get_paid_products_not_on_sale_query_args() {
592 592
 
593 593
         $args = array(
594 594
             'post_type' 		=> 'product',
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
             'suppress_filters' 	=> 0
599 599
         );
600 600
 
601
-        $args[ 'fields' ]     = 'ids';
602
-        $args[ 'meta_query' ] = array(
601
+        $args['fields']     = 'ids';
602
+        $args['meta_query'] = array(
603 603
             'relation' => 'AND',
604 604
             array(
605 605
                 'key'=> '_regular_price',
@@ -625,24 +625,24 @@  discard block
 block discarded – undo
625 625
      *
626 626
      * @return array $woocommerce_paid_product_ids
627 627
      */
628
-    public static function get_paid_product_ids(){
628
+    public static function get_paid_product_ids() {
629 629
 
630 630
         // get all the paid WooCommerce products that has regular
631 631
         // and sale price greater than 0
632 632
         // will be used later to check for course with the id as meta
633
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
633
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
634 634
 
635 635
         // get all the paid WooCommerce products that has regular price
636 636
         // greater than 0 without a sale price
637 637
         // will be used later to check for course with the id as meta
638
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
638
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
639 639
 
640 640
         // combine products ID's with regular and sale price grater than zero and those without
641 641
         // sale but regular price greater than zero
642
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
642
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
643 643
 
644 644
         // if
645
-        if( empty($woocommerce_paid_product_ids) ){
645
+        if (empty($woocommerce_paid_product_ids)) {
646 646
             return array( );
647 647
         }
648 648
         return $woocommerce_paid_product_ids;
@@ -661,20 +661,20 @@  discard block
 block discarded – undo
661 661
      *
662 662
      * @return array
663 663
      */
664
-    public static function get_free_courses(){
664
+    public static function get_free_courses() {
665 665
 
666 666
         $free_course_query_args = Sensei_Course::get_default_query_args();
667
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
667
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
668 668
 
669 669
         // don't show any paid courses
670 670
         $courses = self::get_paid_courses();
671 671
         $ids = array();
672
-        foreach( $courses as $course ){
672
+        foreach ($courses as $course) {
673 673
             $ids[] = $course->ID;
674 674
         }
675
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
675
+        $free_course_query_args['post__not_in'] = $ids;
676 676
 
677
-        return get_posts( $free_course_query_args );
677
+        return get_posts($free_course_query_args);
678 678
 
679 679
     }
680 680
 
@@ -684,13 +684,13 @@  discard block
 block discarded – undo
684 684
      * @since 1.9.0
685 685
      * @return array
686 686
      */
687
-    public static function get_paid_courses(){
687
+    public static function get_paid_courses() {
688 688
 
689 689
         $paid_course_query_args = Sensei_Course::get_default_query_args();
690 690
 
691
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
691
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
692 692
 
693
-        return get_posts(  $paid_course_query_args );
693
+        return get_posts($paid_course_query_args);
694 694
     }
695 695
 
696 696
     /**
@@ -705,17 +705,17 @@  discard block
 block discarded – undo
705 705
      * @param int $course_id
706 706
      * @return string $html markup for the button or nothing if user not allowed to buy
707 707
      */
708
-    public static function the_add_to_cart_button_html( $course_id ){
708
+    public static function the_add_to_cart_button_html($course_id) {
709 709
 
710
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) {
710
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id)) {
711 711
             return '';
712 712
         }
713 713
 
714
-        $wc_post_id = self::get_course_product_id( $course_id );
714
+        $wc_post_id = self::get_course_product_id($course_id);
715 715
 
716 716
         // Check if customer purchased the product
717
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
718
-            || empty( $wc_post_id ) ) {
717
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
718
+            || empty($wc_post_id)) {
719 719
 
720 720
             return '';
721 721
 
@@ -723,15 +723,15 @@  discard block
 block discarded – undo
723 723
 
724 724
         // based on simple.php in WC templates/single-product/add-to-cart/
725 725
         // Get the product
726
-        $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
726
+        $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
727 727
 
728 728
         // do not show the button for invalid products, non purchasable products, out
729 729
         // of stock product or if course is already in cart
730
-        if ( ! isset ( $product )
731
-            || ! is_object( $product )
730
+        if ( ! isset ($product)
731
+            || ! is_object($product)
732 732
             || ! $product->is_purchasable()
733 733
             || ! $product->is_in_stock()
734
-            || self::is_course_in_cart( $wc_post_id ) ) {
734
+            || self::is_course_in_cart($wc_post_id)) {
735 735
 
736 736
             return '';
737 737
 
@@ -742,23 +742,23 @@  discard block
 block discarded – undo
742 742
         //
743 743
         ?>
744 744
 
745
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
745
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
746 746
               class="cart"
747 747
               method="post"
748 748
               enctype="multipart/form-data">
749 749
 
750
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
750
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
751 751
 
752 752
             <input type="hidden" name="quantity" value="1" />
753 753
 
754
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
754
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
755 755
 
756 756
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
757
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
757
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
758 758
 
759
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
759
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
760 760
 
761
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
761
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
762 762
 
763 763
                     <?php } ?>
764 764
 
@@ -786,26 +786,26 @@  discard block
 block discarded – undo
786 786
      *
787 787
      * @return string $message
788 788
      */
789
-    public static function alter_no_permissions_message( $message, $post_id ){
789
+    public static function alter_no_permissions_message($message, $post_id) {
790 790
 
791
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
791
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
792 792
             return  $message;
793 793
         }
794 794
 
795
-        $product_id = self::get_course_product_id( $post_id );
795
+        $product_id = self::get_course_product_id($post_id);
796 796
 
797
-        if( ! $product_id
798
-            || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
797
+        if ( ! $product_id
798
+            || self::has_customer_bought_product(get_current_user_id(), $product_id)) {
799 799
 
800 800
             return $message;
801 801
 
802 802
         }
803 803
 
804 804
         ob_start();
805
-        self::the_course_no_permissions_message( $post_id );
805
+        self::the_course_no_permissions_message($post_id);
806 806
         $woocommerce_course_no_permissions_message = ob_get_clean();
807 807
 
808
-        return $woocommerce_course_no_permissions_message ;
808
+        return $woocommerce_course_no_permissions_message;
809 809
 
810 810
     }
811 811
     /**
@@ -814,16 +814,16 @@  discard block
 block discarded – undo
814 814
      *
815 815
      * @since 1.9.0
816 816
      */
817
-    public static function the_course_no_permissions_message( $course_id ){
817
+    public static function the_course_no_permissions_message($course_id) {
818 818
 
819 819
         // login link
820
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
821
-        $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
820
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
821
+        $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
822 822
 
823 823
         ?>
824 824
 
825 825
         <span class="add-to-cart-login">
826
-            <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?>
826
+            <?php echo sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link); ?>
827 827
         </span>
828 828
 
829 829
     <?php }
@@ -838,43 +838,43 @@  discard block
 block discarded – undo
838 838
      *
839 839
      * @return bool
840 840
      */
841
-    public static function has_customer_bought_product ( $user_id, $product_id ){
841
+    public static function has_customer_bought_product($user_id, $product_id) {
842 842
 
843
-        $orders = get_posts( array(
843
+        $orders = get_posts(array(
844 844
             'posts_per_page' => -1,
845 845
             'meta_key'    => '_customer_user',
846
-            'meta_value'  => intval( $user_id ),
846
+            'meta_value'  => intval($user_id),
847 847
             'post_type'   => 'shop_order',
848
-            'post_status' =>  array( 'wc-processing', 'wc-completed' ),
849
-        ) );
848
+            'post_status' =>  array('wc-processing', 'wc-completed'),
849
+        ));
850 850
 
851
-        foreach ( $orders as $order_id ) {
851
+        foreach ($orders as $order_id) {
852 852
 
853
-            $order = new WC_Order( $order_id->ID );
853
+            $order = new WC_Order($order_id->ID);
854 854
 
855
-            if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) {
855
+            if ($order->post_status != 'wc-completed' && $order->post_status != 'wc-processing') {
856 856
 
857 857
                 continue;
858 858
             }
859 859
 
860
-            if ( ! ( 0 < sizeof( $order->get_items() ) ) ) {
860
+            if ( ! (0 < sizeof($order->get_items()))) {
861 861
 
862 862
                 continue;
863 863
 
864 864
             }
865 865
 
866
-            foreach( $order->get_items() as $item ) {
866
+            foreach ($order->get_items() as $item) {
867 867
 
868 868
                 // Check if user has bought product
869
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
869
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
870 870
 
871 871
                     // Check if user has an active subscription for product
872
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
873
-                        $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id );
874
-                        if( $sub_key ) {
875
-                            $sub = WC_Subscriptions_Manager::get_subscription( $sub_key );
876
-                            if( $sub && isset( $sub['status'] ) ) {
877
-                                if( 'active' == $sub['status'] ) {
872
+                    if (class_exists('WC_Subscriptions_Manager')) {
873
+                        $sub_key = WC_Subscriptions_Manager::get_subscription_key($order_id->ID, $product_id);
874
+                        if ($sub_key) {
875
+                            $sub = WC_Subscriptions_Manager::get_subscription($sub_key);
876
+                            if ($sub && isset($sub['status'])) {
877
+                                if ('active' == $sub['status']) {
878 878
                                     return true;
879 879
                                 } else {
880 880
                                     return false;
@@ -903,11 +903,11 @@  discard block
 block discarded – undo
903 903
      * @return string $woocommerce_product_id or false if none exist
904 904
      *
905 905
      */
906
-    public static function get_course_product_id( $course_id ){
906
+    public static function get_course_product_id($course_id) {
907 907
 
908
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
908
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
909 909
 
910
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
910
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
911 911
             return false;
912 912
         }
913 913
 
@@ -921,11 +921,11 @@  discard block
 block discarded – undo
921 921
      * @param array $classes
922 922
      * @return array
923 923
      */
924
-    public static function add_woocommerce_body_class( $classes ){
924
+    public static function add_woocommerce_body_class($classes) {
925 925
 
926
-        if( ! in_array( 'woocommerce', $classes ) ){
926
+        if ( ! in_array('woocommerce', $classes)) {
927 927
 
928
-            $classes[] ='woocommerce';
928
+            $classes[] = 'woocommerce';
929 929
 
930 930
         }
931 931
 
Please login to merge, or discard this patch.
includes/class-sensei-learners-main.php 1 patch
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Learners Overview List Table Class
@@ -23,28 +23,28 @@  discard block
 block discarded – undo
23 23
 	 * @since  1.6.0
24 24
 	 * @return  void
25 25
 	 */
26
-	public function __construct ( $course_id = 0, $lesson_id = 0 ) {
27
-		$this->course_id = intval( $course_id );
28
-		$this->lesson_id = intval( $lesson_id );
26
+	public function __construct($course_id = 0, $lesson_id = 0) {
27
+		$this->course_id = intval($course_id);
28
+		$this->lesson_id = intval($lesson_id);
29 29
 
30
-		if( isset( $_GET['view'] ) && in_array( $_GET['view'], array( 'courses', 'lessons', 'learners' ) ) ) {
30
+		if (isset($_GET['view']) && in_array($_GET['view'], array('courses', 'lessons', 'learners'))) {
31 31
 			$this->view = $_GET['view'];
32 32
 		}
33 33
 
34 34
 		// Viewing a single lesson always sets the view to Learners
35
-		if( $this->lesson_id ) {
35
+		if ($this->lesson_id) {
36 36
 			$this->view = 'learners';
37 37
 		}
38 38
 
39 39
 		// Load Parent token into constructor
40
-		parent::__construct( 'learners_main' );
40
+		parent::__construct('learners_main');
41 41
 
42 42
 		// Actions
43
-		add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) );
44
-		add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) );
45
-		add_action( 'sensei_learners_extra', array( $this, 'add_learners_box' ) );
43
+		add_action('sensei_before_list_table', array($this, 'data_table_header'));
44
+		add_action('sensei_after_list_table', array($this, 'data_table_footer'));
45
+		add_action('sensei_learners_extra', array($this, 'add_learners_box'));
46 46
 
47
-		add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) );
47
+		add_filter('sensei_list_table_search_button_text', array($this, 'search_button'));
48 48
 	} // End __construct()
49 49
 
50 50
 	/**
@@ -54,38 +54,38 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	function get_columns() {
56 56
 		$columns = array();
57
-		switch( $this->view ) {
57
+		switch ($this->view) {
58 58
 			case 'learners':
59 59
 				$columns = array(
60
-					'title' => __( 'Learner', 'woothemes-sensei' ),
61
-					'date_started' => __( 'Date Started', 'woothemes-sensei' ),
62
-					'user_status' => __( 'Status', 'woothemes-sensei' ),
60
+					'title' => __('Learner', 'woothemes-sensei'),
61
+					'date_started' => __('Date Started', 'woothemes-sensei'),
62
+					'user_status' => __('Status', 'woothemes-sensei'),
63 63
 				);
64 64
 				break;
65 65
 
66 66
 			case 'lessons':
67 67
 				$columns = array(
68
-					'title' => __( 'Lesson', 'woothemes-sensei' ),
69
-					'num_learners' => __( '# Learners', 'woothemes-sensei' ),
70
-					'updated' => __( 'Last Updated', 'woothemes-sensei' ),
68
+					'title' => __('Lesson', 'woothemes-sensei'),
69
+					'num_learners' => __('# Learners', 'woothemes-sensei'),
70
+					'updated' => __('Last Updated', 'woothemes-sensei'),
71 71
 				);
72 72
 				break;
73 73
 
74 74
 			case 'courses':
75 75
 			default:
76 76
 				$columns = array(
77
-					'title' => __( 'Course', 'woothemes-sensei' ),
78
-					'num_learners' => __( '# Learners', 'woothemes-sensei' ),
79
-					'updated' => __( 'Last Updated', 'woothemes-sensei' ),
77
+					'title' => __('Course', 'woothemes-sensei'),
78
+					'num_learners' => __('# Learners', 'woothemes-sensei'),
79
+					'updated' => __('Last Updated', 'woothemes-sensei'),
80 80
 				);
81 81
 				break;
82 82
 		}
83 83
 		$columns['actions'] = '';
84 84
 		// Backwards compatible
85
-		if ( 'learners' == $this->view ) {
86
-			$columns = apply_filters( 'sensei_learners_learners_columns', $columns, $this );
85
+		if ('learners' == $this->view) {
86
+			$columns = apply_filters('sensei_learners_learners_columns', $columns, $this);
87 87
 		}
88
-		$columns = apply_filters( 'sensei_learners_default_columns', $columns, $this );
88
+		$columns = apply_filters('sensei_learners_default_columns', $columns, $this);
89 89
 		return $columns;
90 90
 	}
91 91
 
@@ -96,32 +96,32 @@  discard block
 block discarded – undo
96 96
 	 */
97 97
 	function get_sortable_columns() {
98 98
 		$columns = array();
99
-		switch( $this->view ) {
99
+		switch ($this->view) {
100 100
 			case 'learners':
101 101
 				$columns = array(
102
-					'title' => array( 'title', false ),
102
+					'title' => array('title', false),
103 103
 				);
104 104
 				break;
105 105
 
106 106
 			case 'lessons':
107 107
 				$columns = array(
108
-					'title' => array( 'title', false ),
109
-					'updated' => array( 'post_modified', false ),
108
+					'title' => array('title', false),
109
+					'updated' => array('post_modified', false),
110 110
 				);
111 111
 				break;
112 112
 
113 113
 			default:
114 114
 				$columns = array(
115
-					'title' => array( 'title', false ),
116
-					'updated' => array( 'post_modified', false ),
115
+					'title' => array('title', false),
116
+					'updated' => array('post_modified', false),
117 117
 				);
118 118
 				break;
119 119
 		}
120 120
 		// Backwards compatible
121
-		if ( 'learners' == $this->view ) {
122
-			$columns = apply_filters( 'sensei_learners_learners_columns_sortable', $columns, $this );
121
+		if ('learners' == $this->view) {
122
+			$columns = apply_filters('sensei_learners_learners_columns_sortable', $columns, $this);
123 123
 		}
124
-		$columns = apply_filters( 'sensei_learners_default_columns_sortable', $columns, $this );
124
+		$columns = apply_filters('sensei_learners_default_columns_sortable', $columns, $this);
125 125
 		return $columns;
126 126
 	}
127 127
 
@@ -135,72 +135,72 @@  discard block
 block discarded – undo
135 135
 
136 136
 		// Handle orderby
137 137
 		$orderby = '';
138
-		if ( !empty( $_GET['orderby'] ) ) {
139
-			if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) {
140
-				$orderby = esc_html( $_GET['orderby'] );
138
+		if ( ! empty($_GET['orderby'])) {
139
+			if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) {
140
+				$orderby = esc_html($_GET['orderby']);
141 141
 			} // End If Statement
142 142
 		}
143 143
 
144 144
 		// Handle order
145 145
 		$order = 'DESC';
146
-		if ( !empty( $_GET['order'] ) ) {
147
-			$order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC';
146
+		if ( ! empty($_GET['order'])) {
147
+			$order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC';
148 148
 		}
149 149
 
150 150
 		// Handle category selection
151 151
 		$category = false;
152
-		if ( !empty( $_GET['course_cat'] ) ) {
153
-			$category = intval( $_GET['course_cat'] );
152
+		if ( ! empty($_GET['course_cat'])) {
153
+			$category = intval($_GET['course_cat']);
154 154
 		} // End If Statement
155 155
 
156 156
 		// Handle search
157 157
 		$search = false;
158
-		if ( !empty( $_GET['s'] ) ) {
159
-			$search = esc_html( $_GET['s'] );
158
+		if ( ! empty($_GET['s'])) {
159
+			$search = esc_html($_GET['s']);
160 160
 		} // End If Statement
161 161
 
162
-		$per_page = $this->get_items_per_page( 'sensei_comments_per_page' );
163
-		$per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' );
162
+		$per_page = $this->get_items_per_page('sensei_comments_per_page');
163
+		$per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments');
164 164
 
165 165
 		$paged = $this->get_pagenum();
166 166
 		$offset = 0;
167
-		if ( !empty($paged) ) {
168
-			$offset = $per_page * ( $paged - 1 );
167
+		if ( ! empty($paged)) {
168
+			$offset = $per_page * ($paged - 1);
169 169
 		} // End If Statement
170 170
 
171
-		switch( $this->view ) {
171
+		switch ($this->view) {
172 172
 			case 'learners':
173
-				if ( empty($orderby) ) {
173
+				if (empty($orderby)) {
174 174
 					$orderby = '';
175 175
 				}
176
-				$this->items = $this->get_learners( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) );
176
+				$this->items = $this->get_learners(compact('per_page', 'offset', 'orderby', 'order', 'search'));
177 177
 
178 178
 			break;
179 179
 
180 180
 			case 'lessons':
181
-				if ( empty($orderby) ) {
181
+				if (empty($orderby)) {
182 182
 					$orderby = 'post_modified';
183 183
 				}
184
-				$this->items = $this->get_lessons( compact( 'per_page', 'offset', 'orderby', 'order', 'search' ) );
184
+				$this->items = $this->get_lessons(compact('per_page', 'offset', 'orderby', 'order', 'search'));
185 185
 
186 186
 			break;
187 187
 
188 188
 			default:
189
-				if ( empty($orderby) ) {
189
+				if (empty($orderby)) {
190 190
 					$orderby = 'post_modified';
191 191
 				}
192
-				$this->items = $this->get_courses( compact( 'per_page', 'offset', 'orderby', 'order', 'category', 'search' ) );
192
+				$this->items = $this->get_courses(compact('per_page', 'offset', 'orderby', 'order', 'category', 'search'));
193 193
 
194 194
 			break;
195 195
 		}
196 196
 
197 197
 		$total_items = $this->total_items;
198
-		$total_pages = ceil( $total_items / $per_page );
199
-		$this->set_pagination_args( array(
198
+		$total_pages = ceil($total_items / $per_page);
199
+		$this->set_pagination_args(array(
200 200
 			'total_items' => $total_items,
201 201
 			'total_pages' => $total_pages,
202 202
 			'per_page' => $per_page
203
-		) );
203
+		));
204 204
 
205 205
 	} // End prepare_items()
206 206
 
@@ -214,53 +214,53 @@  discard block
 block discarded – undo
214 214
      *
215 215
      * @return void
216 216
 	 */
217
-	protected function get_row_data( $item ) {
217
+	protected function get_row_data($item) {
218 218
 		global $wp_version;
219 219
 
220
-		switch ( $this->view ) {
220
+		switch ($this->view) {
221 221
 			case 'learners' :
222 222
 
223 223
                 // in this case the item passed in is actually the users activity on course of lesson
224 224
                 $user_activity = $item;
225 225
 				$post_id = false;
226 226
 
227
-				if( $this->lesson_id ) {
227
+				if ($this->lesson_id) {
228 228
 
229
-					$post_id = intval( $this->lesson_id );
230
-					$object_type = __( 'lesson', 'woothemes-sensei' );
229
+					$post_id = intval($this->lesson_id);
230
+					$object_type = __('lesson', 'woothemes-sensei');
231 231
 					$post_type = 'lesson';
232 232
 
233
-				} elseif( $this->course_id ) {
233
+				} elseif ($this->course_id) {
234 234
 
235
-					$post_id = intval( $this->course_id );
236
-					$object_type = __( 'course', 'woothemes-sensei' );
235
+					$post_id = intval($this->course_id);
236
+					$object_type = __('course', 'woothemes-sensei');
237 237
 					$post_type = 'course';
238 238
 
239 239
 				}
240 240
 
241
-				if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) {
241
+				if ('complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved) {
242 242
 
243
-                    $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
243
+                    $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>';
244 244
 
245 245
 				} else {
246 246
 
247
-                    $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
247
+                    $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
248 248
 
249 249
 				}
250 250
 
251
-                $title = Sensei()->learners->get_learner_full_name( $user_activity->user_id );
252
-				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
251
+                $title = Sensei()->learners->get_learner_full_name($user_activity->user_id);
252
+				$a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
253 253
 
254 254
                 // get the learners order for this course if the course was purchased
255 255
 
256 256
                 $course_order_id_attribute = '';
257
-                if( Sensei_WC::is_woocommerce_active() ){
257
+                if (Sensei_WC::is_woocommerce_active()) {
258 258
 
259
-                    $course_product_order_id = Sensei_WC::get_learner_course_active_order_id( $user_activity->user_id, $post_id  );
259
+                    $course_product_order_id = Sensei_WC::get_learner_course_active_order_id($user_activity->user_id, $post_id);
260 260
 
261
-                    if( $course_product_order_id ){
261
+                    if ($course_product_order_id) {
262 262
 
263
-                        $course_order_id_attribute = ' data-order_id="' . $course_product_order_id . '" ';
263
+                        $course_order_id_attribute = ' data-order_id="'.$course_product_order_id.'" ';
264 264
 
265 265
                     }
266 266
 
@@ -279,50 +279,50 @@  discard block
 block discarded – undo
279 279
                  *   type html $action_buttons
280 280
                  * }
281 281
                  */
282
-				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
283
-						'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>',
284
-						'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true),
282
+				$column_data = apply_filters('sensei_learners_main_column_data', array(
283
+						'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>',
284
+						'date_started' => get_comment_meta($user_activity->comment_ID, 'start', true),
285 285
 						'user_status' => $status_html,
286
-						'actions' => '<a class="remove-learner button" data-user_id="' . $user_activity->user_id . '" data-post_id="' . $post_id . '" data-post_type="' . $post_type . '" '. $course_order_id_attribute . '">' . sprintf( __( 'Remove from %1$s', 'woothemes-sensei' ), $object_type ) . '</a>',
287
-					), $item, $post_id, $post_type );
286
+						'actions' => '<a class="remove-learner button" data-user_id="'.$user_activity->user_id.'" data-post_id="'.$post_id.'" data-post_type="'.$post_type.'" '.$course_order_id_attribute.'">'.sprintf(__('Remove from %1$s', 'woothemes-sensei'), $object_type).'</a>',
287
+					), $item, $post_id, $post_type);
288 288
 
289 289
 				break;
290 290
 
291 291
 			case 'lessons' :
292
-				$lesson_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_lesson_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any' ) ) );
293
-				$title = get_the_title( $item );
294
-				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
292
+				$lesson_learners = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_learners_lesson_learners', array('post_id' => $item->ID, 'type' => 'sensei_lesson_status', 'status' => 'any')));
293
+				$title = get_the_title($item);
294
+				$a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
295 295
 
296 296
 				$grading_action = '';
297
-				if ( get_post_meta( $item->ID, '_quiz_has_questions', true ) ) {
298
-					$grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>';
297
+				if (get_post_meta($item->ID, '_quiz_has_questions', true)) {
298
+					$grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'lesson_id' => $item->ID, 'course_id' => $this->course_id), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>';
299 299
 				}
300 300
 
301
-				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
302
-						'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>',
301
+				$column_data = apply_filters('sensei_learners_main_column_data', array(
302
+						'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>',
303 303
 						'num_learners' => $lesson_learners,
304 304
 						'updated' => $item->post_modified,
305
-						'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action,
306
-					), $item, $this->course_id );
305
+						'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID, 'course_id' => $this->course_id, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action,
306
+					), $item, $this->course_id);
307 307
 				break;
308 308
 
309 309
 			case 'courses' :
310 310
 			default:
311
-                $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' ) ) );
312
-				$title = get_the_title( $item );
313
-				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
311
+                $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')));
312
+				$title = get_the_title($item);
313
+				$a_title = sprintf(__('Edit &#8220;%s&#8221;'), $title);
314 314
 
315 315
 				$grading_action = '';
316
-				if ( version_compare($wp_version, '4.1', '>=') ) {
317
-					$grading_action = ' <a class="button" href="' . esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $item->ID ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Grading', 'woothemes-sensei' ) . '</a>';
316
+				if (version_compare($wp_version, '4.1', '>=')) {
317
+					$grading_action = ' <a class="button" href="'.esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $item->ID), admin_url('admin.php'))).'">'.__('Grading', 'woothemes-sensei').'</a>';
318 318
 				}
319 319
 
320
-				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
321
-						'title' => '<strong><a class="row-title" href="' . admin_url( 'post.php?action=edit&post=' . $item->ID ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>',
320
+				$column_data = apply_filters('sensei_learners_main_column_data', array(
321
+						'title' => '<strong><a class="row-title" href="'.admin_url('post.php?action=edit&post='.$item->ID).'" title="'.esc_attr($a_title).'">'.$title.'</a></strong>',
322 322
 						'num_learners' => $course_learners,
323 323
 						'updated' => $item->post_modified,
324
-						'actions' => '<a class="button" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners' ), admin_url( 'admin.php' ) ) ) . '">' . __( 'Manage learners', 'woothemes-sensei' ) . '</a> ' . $grading_action,
325
-					), $item );
324
+						'actions' => '<a class="button" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID, 'view' => 'learners'), admin_url('admin.php'))).'">'.__('Manage learners', 'woothemes-sensei').'</a> '.$grading_action,
325
+					), $item);
326 326
 
327 327
 				break;
328 328
 		} // switch
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	 * @since  1.7.0
336 336
 	 * @return array courses
337 337
 	 */
338
-	private function get_courses( $args ) {
338
+	private function get_courses($args) {
339 339
 		$course_args = array(
340 340
 			'post_type' => 'course',
341 341
 			'post_status' => 'publish',
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 			'order' => $args['order'],
346 346
 		);
347 347
 
348
-		if( $args['category'] ) {
348
+		if ($args['category']) {
349 349
 			$course_args['tax_query'][] = array(
350 350
 				'taxonomy' => 'course-category',
351 351
 				'field' => 'id',
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 			);
354 354
 		}
355 355
 
356
-		if( $args['search'] ) {
356
+		if ($args['search']) {
357 357
 			$course_args['s'] = $args['search'];
358 358
 		}
359 359
 
360
-		$courses_query = new WP_Query( apply_filters( 'sensei_learners_filter_courses', $course_args ) );
360
+		$courses_query = new WP_Query(apply_filters('sensei_learners_filter_courses', $course_args));
361 361
 
362 362
 		$this->total_items = $courses_query->found_posts;
363 363
 		return $courses_query->posts;
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @since  1.7.0
369 369
 	 * @return array lessons
370 370
 	 */
371
-	private function get_lessons( $args ) {
371
+	private function get_lessons($args) {
372 372
 		$lesson_args = array(
373 373
 			'post_type' => 'lesson',
374 374
 			'post_status' => 'publish',
@@ -378,18 +378,18 @@  discard block
 block discarded – undo
378 378
 			'order' => $args['order'],
379 379
 		);
380 380
 
381
-		if( $this->course_id ) {
381
+		if ($this->course_id) {
382 382
 			$lesson_args['meta_query'][] = array(
383 383
 				'key' => '_lesson_course',
384 384
 				'value' => $this->course_id,
385 385
 			);
386 386
 		}
387 387
 
388
-		if( $args['search'] ) {
388
+		if ($args['search']) {
389 389
 			$lesson_args['s'] = $args['search'];
390 390
 		}
391 391
 
392
-		$lessons_query = new WP_Query( apply_filters( 'sensei_learners_filter_lessons', $lesson_args ) );
392
+		$lessons_query = new WP_Query(apply_filters('sensei_learners_filter_lessons', $lesson_args));
393 393
 
394 394
 		$this->total_items = $lessons_query->found_posts;
395 395
 		return $lessons_query->posts;
@@ -400,22 +400,22 @@  discard block
 block discarded – undo
400 400
 	 * @since  1.7.0
401 401
 	 * @return array learners
402 402
 	 */
403
-	private function get_learners( $args ) {
403
+	private function get_learners($args) {
404 404
 
405 405
 		$user_ids = false;
406 406
 		$post_id = 0;
407 407
 		$activity = '';
408 408
 
409
-		if( $this->lesson_id ) {
410
-			$post_id = intval( $this->lesson_id );
409
+		if ($this->lesson_id) {
410
+			$post_id = intval($this->lesson_id);
411 411
 			$activity = 'sensei_lesson_status';
412 412
 		}
413
-		elseif( $this->course_id ) {
414
-			$post_id = intval( $this->course_id );
413
+		elseif ($this->course_id) {
414
+			$post_id = intval($this->course_id);
415 415
 			$activity = 'sensei_course_status';
416 416
 		}
417 417
 
418
-		if( ! $post_id || ! $activity ) {
418
+		if ( ! $post_id || ! $activity) {
419 419
 			$this->total_items = 0;
420 420
 			return array();
421 421
 		}
@@ -431,32 +431,32 @@  discard block
 block discarded – undo
431 431
 			);
432 432
 
433 433
 		// Searching users on statuses requires sub-selecting the statuses by user_ids
434
-		if ( $args['search'] ) {
434
+		if ($args['search']) {
435 435
 			$user_args = array(
436
-				'search' => '*' . $args['search'] . '*',
436
+				'search' => '*'.$args['search'].'*',
437 437
 				'fields' => 'ID'
438 438
 			);
439 439
 			// Filter for extending
440
-			$user_args = apply_filters( 'sensei_learners_search_users', $user_args );
441
-			if ( !empty( $user_args ) ) {
442
-				$learners_search = new WP_User_Query( $user_args );
440
+			$user_args = apply_filters('sensei_learners_search_users', $user_args);
441
+			if ( ! empty($user_args)) {
442
+				$learners_search = new WP_User_Query($user_args);
443 443
 				$activity_args['user_id'] = $learners_search->get_results();
444 444
 			}
445 445
 		}
446 446
 
447
-		$activity_args = apply_filters( 'sensei_learners_filter_users', $activity_args );
447
+		$activity_args = apply_filters('sensei_learners_filter_users', $activity_args);
448 448
 
449 449
 		// WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice
450
-		$total_learners = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
450
+		$total_learners = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0)));
451 451
 		// Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views?
452
-		if ( $total_learners < $activity_args['offset'] ) {
453
-			$new_paged = floor( $total_learners / $activity_args['number'] );
452
+		if ($total_learners < $activity_args['offset']) {
453
+			$new_paged = floor($total_learners / $activity_args['number']);
454 454
 			$activity_args['offset'] = $new_paged * $activity_args['number'];
455 455
 		}
456
-		$learners = Sensei_Utils::sensei_check_for_activity( $activity_args, true );
456
+		$learners = Sensei_Utils::sensei_check_for_activity($activity_args, true);
457 457
 		// Need to always return an array, even with only 1 item
458
-		if ( !is_array($learners) ) {
459
-			$learners = array( $learners );
458
+		if ( ! is_array($learners)) {
459
+			$learners = array($learners);
460 460
 		}
461 461
 		$this->total_items = $total_learners;
462 462
 		return $learners;
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
 	 * @return void
470 470
 	 */
471 471
 	public function no_items() {
472
-		switch( $this->view ) {
472
+		switch ($this->view) {
473 473
 			case 'learners' :
474
-				$text = __( 'No learners found.', 'woothemes-sensei' );
474
+				$text = __('No learners found.', 'woothemes-sensei');
475 475
 				break;
476 476
 
477 477
 			case 'lessons' :
478
-				$text = __( 'No lessons found.', 'woothemes-sensei' );
478
+				$text = __('No lessons found.', 'woothemes-sensei');
479 479
 				break;
480 480
 
481 481
 			case 'courses':
482 482
 			case 'default':
483 483
 			default:
484
-				$text = __( 'No courses found.', 'woothemes-sensei' );
484
+				$text = __('No courses found.', 'woothemes-sensei');
485 485
 				break;
486 486
 		}
487
-		echo apply_filters( 'sensei_learners_no_items_text', $text );
487
+		echo apply_filters('sensei_learners_no_items_text', $text);
488 488
 	} // End no_items()
489 489
 
490 490
 	/**
@@ -495,40 +495,40 @@  discard block
 block discarded – undo
495 495
 	public function data_table_header() {
496 496
 
497 497
 		echo '<div class="learners-selects">';
498
-		do_action( 'sensei_learners_before_dropdown_filters' );
498
+		do_action('sensei_learners_before_dropdown_filters');
499 499
 
500 500
 		// Display Course Categories only on default view
501
-		if( 'courses' == $this->view ) {
501
+		if ('courses' == $this->view) {
502 502
 
503 503
 			$selected_cat = 0;
504
-			if ( isset( $_GET['course_cat'] ) && '' != esc_html( $_GET['course_cat'] ) ) {
505
-				$selected_cat = intval( $_GET['course_cat'] );
504
+			if (isset($_GET['course_cat']) && '' != esc_html($_GET['course_cat'])) {
505
+				$selected_cat = intval($_GET['course_cat']);
506 506
 			}
507 507
 
508
-			$cats = get_terms( 'course-category', array( 'hide_empty' => false ) );
508
+			$cats = get_terms('course-category', array('hide_empty' => false));
509 509
 
510
-			echo '<div class="select-box">' . "\n";
510
+			echo '<div class="select-box">'."\n";
511 511
 
512
-				echo '<select id="course-category-options" data-placeholder="' . __( 'Course Category', 'woothemes-sensei' ) . '" name="learners_course_cat" class="chosen_select widefat">' . "\n";
512
+				echo '<select id="course-category-options" data-placeholder="'.__('Course Category', 'woothemes-sensei').'" name="learners_course_cat" class="chosen_select widefat">'."\n";
513 513
 
514
-					echo '<option value="0">' . __( 'All Course Categories', 'woothemes-sensei' ) . '</option>' . "\n";
514
+					echo '<option value="0">'.__('All Course Categories', 'woothemes-sensei').'</option>'."\n";
515 515
 
516
-					foreach( $cats as $cat ) {
517
-						echo '<option value="' . $cat->term_id . '"' . selected( $cat->term_id, $selected_cat, false ) . '>' . $cat->name . '</option>' . "\n";
516
+					foreach ($cats as $cat) {
517
+						echo '<option value="'.$cat->term_id.'"'.selected($cat->term_id, $selected_cat, false).'>'.$cat->name.'</option>'."\n";
518 518
 					}
519 519
 
520
-				echo '</select>' . "\n";
520
+				echo '</select>'."\n";
521 521
 
522
-			echo '</div>' . "\n";
522
+			echo '</div>'."\n";
523 523
 		}
524 524
 		echo '</div><!-- /.learners-selects -->';
525 525
 
526 526
 		$menu = array();
527 527
 		// Have Course no Lesson
528
-		if( $this->course_id && ! $this->lesson_id ) {
528
+		if ($this->course_id && ! $this->lesson_id) {
529 529
 
530 530
 			$learners_class = $lessons_class = '';
531
-			switch( $this->view ) {
531
+			switch ($this->view) {
532 532
 				case 'learners':
533 533
 					$learners_class = 'current';
534 534
 				break;
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
 			$learner_args['view'] = 'learners';
548 548
 			$lesson_args['view'] = 'lessons';
549 549
 
550
-			$menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>';
551
-			$menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>';
550
+			$menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>';
551
+			$menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>';
552 552
 
553 553
 		} 
554 554
 		// Have Course and Lesson
555
-		elseif( $this->course_id && $this->lesson_id ) {
555
+		elseif ($this->course_id && $this->lesson_id) {
556 556
 
557 557
 			$query_args = array(
558 558
 				'page' => $this->page_slug,
@@ -560,18 +560,18 @@  discard block
 block discarded – undo
560 560
 				'view' => 'lessons'
561 561
 			);
562 562
 
563
-			$course = get_the_title( $this->course_id );
563
+			$course = get_the_title($this->course_id);
564 564
 
565
-			$menu['back'] = '<a href="' . esc_url( add_query_arg( $query_args, admin_url( 'admin.php' ) ) ) . '">' . sprintf( __( '%1$sBack to %2$s%3$s', 'woothemes-sensei' ), '<em>&larr; ', $course, '</em>' ) . '</a>';
565
+			$menu['back'] = '<a href="'.esc_url(add_query_arg($query_args, admin_url('admin.php'))).'">'.sprintf(__('%1$sBack to %2$s%3$s', 'woothemes-sensei'), '<em>&larr; ', $course, '</em>').'</a>';
566 566
 		}
567
-		$menu = apply_filters( 'sensei_learners_sub_menu', $menu );
568
-		if ( !empty($menu) ) {
569
-			echo '<ul class="subsubsub">' . "\n";
570
-			foreach ( $menu as $class => $item ) {
571
-				$menu[ $class ] = "\t<li class='$class'>$item";
567
+		$menu = apply_filters('sensei_learners_sub_menu', $menu);
568
+		if ( ! empty($menu)) {
569
+			echo '<ul class="subsubsub">'."\n";
570
+			foreach ($menu as $class => $item) {
571
+				$menu[$class] = "\t<li class='$class'>$item";
572 572
 			}
573
-			echo implode( " |</li>\n", $menu ) . "</li>\n";
574
-			echo '</ul>' . "\n";
573
+			echo implode(" |</li>\n", $menu)."</li>\n";
574
+			echo '</ul>'."\n";
575 575
 		}
576 576
 
577 577
 	} // End data_table_header()
@@ -596,50 +596,50 @@  discard block
 block discarded – undo
596 596
 		$form_post_type = '';
597 597
 		$form_course_id = 0;
598 598
 		$form_lesson_id = 0;
599
-		if( $this->course_id && ! $this->lesson_id ) {
600
-			$post_title = get_the_title( $this->course_id );
601
-			$post_type = __( 'Course', 'woothemes-sensei' );
599
+		if ($this->course_id && ! $this->lesson_id) {
600
+			$post_title = get_the_title($this->course_id);
601
+			$post_type = __('Course', 'woothemes-sensei');
602 602
 			$form_post_type = 'course';
603 603
 			$form_course_id = $this->course_id;
604 604
 		}
605
-		elseif( $this->course_id && $this->lesson_id ) {
606
-			$post_title = get_the_title( $this->lesson_id );
607
-			$post_type = __( 'Lesson', 'woothemes-sensei' );
605
+		elseif ($this->course_id && $this->lesson_id) {
606
+			$post_title = get_the_title($this->lesson_id);
607
+			$post_type = __('Lesson', 'woothemes-sensei');
608 608
 			$form_post_type = 'lesson';
609 609
 			$form_course_id = $this->course_id;
610 610
 			$form_lesson_id = $this->lesson_id;
611
-			$course_title = get_the_title( $this->course_id );
611
+			$course_title = get_the_title($this->course_id);
612 612
 		}
613
-		if ( empty($form_post_type) ) {
613
+		if (empty($form_post_type)) {
614 614
 			return;
615 615
 		}
616 616
 		?>
617 617
 		<div class="postbox">
618
-			<h3><span><?php printf( __( 'Add Learner to %1$s', 'woothemes-sensei' ), $post_type ); ?></span></h3>
618
+			<h3><span><?php printf(__('Add Learner to %1$s', 'woothemes-sensei'), $post_type); ?></span></h3>
619 619
 			<div class="inside">
620 620
 				<form name="add_learner" action="" method="post">
621 621
 					<p>
622
-						<input name="add_user_id" placeholder="<?php _e( 'Find learner', 'woothemes-sensei' ) ;?>" id="add_learner_search" style="min-width:300px;" />
623
-						<?php if( 'lesson' == $form_post_type ) { ?>
624
-							<label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson"  value="yes" /> <?php _e( 'Complete lesson for learner', 'woothemes-sensei' ); ?></label>
625
-						<?php } elseif( 'course' == $form_post_type ) { ?>
626
-							<label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course"  value="yes" /> <?php _e( 'Complete course for learner', 'woothemes-sensei' ); ?></label>
622
+						<input name="add_user_id" placeholder="<?php _e('Find learner', 'woothemes-sensei'); ?>" id="add_learner_search" style="min-width:300px;" />
623
+						<?php if ('lesson' == $form_post_type) { ?>
624
+							<label for="add_complete_lesson"><input type="checkbox" id="add_complete_lesson" name="add_complete_lesson"  value="yes" /> <?php _e('Complete lesson for learner', 'woothemes-sensei'); ?></label>
625
+						<?php } elseif ('course' == $form_post_type) { ?>
626
+							<label for="add_complete_course"><input type="checkbox" id="add_complete_course" name="add_complete_course"  value="yes" /> <?php _e('Complete course for learner', 'woothemes-sensei'); ?></label>
627 627
 						<?php } ?>
628 628
 						<br/>
629
-						<span class="description"><?php _e( 'Search for a user by typing their name or username.', 'woothemes-sensei' ); ?></span>
629
+						<span class="description"><?php _e('Search for a user by typing their name or username.', 'woothemes-sensei'); ?></span>
630 630
 					</p>
631
-					<p><?php submit_button( sprintf( __( 'Add to \'%1$s\'', 'woothemes-sensei' ), $post_title ), 'primary', 'add_learner_submit', false, array() ); ?></p>
632
-					<?php if( 'lesson' == $form_post_type ) { ?>
633
-						<p><span class="description"><?php printf( __( 'Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei' ), $course_title ); ?></span></p>
631
+					<p><?php submit_button(sprintf(__('Add to \'%1$s\'', 'woothemes-sensei'), $post_title), 'primary', 'add_learner_submit', false, array()); ?></p>
632
+					<?php if ('lesson' == $form_post_type) { ?>
633
+						<p><span class="description"><?php printf(__('Learner will also be added to the course \'%1$s\' if they are not already taking it.', 'woothemes-sensei'), $course_title); ?></span></p>
634 634
 					<?php } ?>
635 635
 
636 636
 					<input type="hidden" name="add_post_type" value="<?php echo $form_post_type; ?>" />
637 637
 					<input type="hidden" name="add_course_id" value="<?php echo $form_course_id; ?>" />
638 638
 					<input type="hidden" name="add_lesson_id" value="<?php echo $form_lesson_id; ?>" />
639 639
 					<?php
640
-						do_action( 'sensei_learners_add_learner_form' );
640
+						do_action('sensei_learners_add_learner_form');
641 641
 					?>
642
-					<?php wp_nonce_field( 'add_learner_to_sensei', 'add_learner_nonce' ); ?>
642
+					<?php wp_nonce_field('add_learner_to_sensei', 'add_learner_nonce'); ?>
643 643
 				</form>
644 644
 			</div>
645 645
 		</div>
@@ -651,19 +651,19 @@  discard block
 block discarded – undo
651 651
 	 * @since  1.7.0
652 652
 	 * @return void
653 653
 	 */
654
-	public function search_button( $text = '' ) {
654
+	public function search_button($text = '') {
655 655
 
656
-		switch( $this->view ) {
656
+		switch ($this->view) {
657 657
 			case 'learners':
658
-				$text = __( 'Search Learners', 'woothemes-sensei' );
658
+				$text = __('Search Learners', 'woothemes-sensei');
659 659
 			break;
660 660
 
661 661
 			case 'lessons':
662
-				$text = __( 'Search Lessons', 'woothemes-sensei' );
662
+				$text = __('Search Lessons', 'woothemes-sensei');
663 663
 			break;
664 664
 
665 665
 			default:
666
-				$text = __( 'Search Courses', 'woothemes-sensei' );
666
+				$text = __('Search Courses', 'woothemes-sensei');
667 667
 			break;
668 668
 		}
669 669
 
Please login to merge, or discard this patch.
includes/class-sensei-settings.php 1 patch
Spacing   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /*
5 5
  * Sensei Settings Class
@@ -20,10 +20,10 @@  discard block
 block discarded – undo
20 20
 	 * @since 1.0.0
21 21
 	 * @return void
22 22
 	 */
23
-	public function __construct () {
23
+	public function __construct() {
24 24
 	    parent::__construct(); // Required in extended classes.
25 25
 
26
-        add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) );
26
+        add_action('init', array(__CLASS__, 'flush_rewrite_rules'));
27 27
 
28 28
 	} // End __construct()
29 29
 
@@ -34,11 +34,11 @@  discard block
 block discarded – undo
34 34
      * @param string $setting_name
35 35
      * @return mixed
36 36
      */
37
-    public function get( $setting_name ){
37
+    public function get($setting_name) {
38 38
 
39
-        if( isset( $this->settings[ $setting_name ] ) ){
39
+        if (isset($this->settings[$setting_name])) {
40 40
 
41
-            return $this->settings[ $setting_name ];
41
+            return $this->settings[$setting_name];
42 42
 
43 43
         }
44 44
 
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
 	 * @since  1.0.0
52 52
 	 * @return void
53 53
 	 */
54
-	public function register_settings_screen () {
54
+	public function register_settings_screen() {
55 55
 
56 56
 		$this->settings_version = Sensei()->version; // Use the global plugin version on this settings screen.
57
-		$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
57
+		$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
58 58
 		$this->hook = $hook;
59 59
 
60
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
61
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
62
-			add_action( 'admin_notices', array( $this, 'language_pack_notices' ) );
63
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
64
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
60
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
61
+			add_action('admin_notices', array($this, 'settings_errors'));
62
+			add_action('admin_notices', array($this, 'language_pack_notices'));
63
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
64
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
65 65
 		}
66 66
 	} // End register_settings_screen()
67 67
 
@@ -71,49 +71,49 @@  discard block
 block discarded – undo
71 71
 	 * @since  1.0.0
72 72
 	 * @return void
73 73
 	 */
74
-	public function init_sections () {
74
+	public function init_sections() {
75 75
 		$sections = array();
76 76
 
77 77
 		$sections['default-settings'] = array(
78
-			'name' 			=> __( 'General', 'woothemes-sensei' ),
79
-			'description'	=> __( 'Settings that apply to the entire plugin.', 'woothemes-sensei' )
78
+			'name' 			=> __('General', 'woothemes-sensei'),
79
+			'description'	=> __('Settings that apply to the entire plugin.', 'woothemes-sensei')
80 80
 		);
81 81
 
82 82
 		$sections['course-settings'] = array(
83
-			'name' 			=> __( 'Courses', 'woothemes-sensei' ),
84
-			'description'	=> __( 'Settings that apply to all Courses.', 'woothemes-sensei' )
83
+			'name' 			=> __('Courses', 'woothemes-sensei'),
84
+			'description'	=> __('Settings that apply to all Courses.', 'woothemes-sensei')
85 85
 		);
86 86
 
87 87
 		$sections['lesson-settings'] = array(
88
-			'name' 			=> __( 'Lessons', 'woothemes-sensei' ),
89
-			'description'	=> __( 'Settings that apply to all Lessons.', 'woothemes-sensei' )
88
+			'name' 			=> __('Lessons', 'woothemes-sensei'),
89
+			'description'	=> __('Settings that apply to all Lessons.', 'woothemes-sensei')
90 90
 		);
91 91
 
92 92
 		$sections['email-notification-settings'] = array(
93
-			'name' 			=> __( 'Email Notifications', 'woothemes-sensei' ),
94
-			'description'	=> __( 'Settings for email notifications sent from your site.', 'woothemes-sensei' )
93
+			'name' 			=> __('Email Notifications', 'woothemes-sensei'),
94
+			'description'	=> __('Settings for email notifications sent from your site.', 'woothemes-sensei')
95 95
 		);
96 96
 
97 97
 		$sections['learner-profile-settings'] = array(
98
-			'name' 			=> __( 'Learner Profiles', 'woothemes-sensei' ),
99
-			'description'	=> __( 'Settings for public Learner Profiles.', 'woothemes-sensei' )
98
+			'name' 			=> __('Learner Profiles', 'woothemes-sensei'),
99
+			'description'	=> __('Settings for public Learner Profiles.', 'woothemes-sensei')
100 100
 		);
101 101
 
102
-		if ( Sensei_WC::is_woocommerce_present() ) {
102
+		if (Sensei_WC::is_woocommerce_present()) {
103 103
 			$sections['woocommerce-settings'] = array(
104
-				'name' 			=> __( 'WooCommerce', 'woothemes-sensei' ),
105
-				'description'	=> __( 'Optional settings for WooCommerce functions.', 'woothemes-sensei' )
104
+				'name' 			=> __('WooCommerce', 'woothemes-sensei'),
105
+				'description'	=> __('Optional settings for WooCommerce functions.', 'woothemes-sensei')
106 106
 			);
107 107
 		} // End If Statement
108 108
 
109
-		if ( 'en_US' !== get_locale() ) {
109
+		if ('en_US' !== get_locale()) {
110 110
 			$sections['language-settings'] = array(
111
-				'name' 			=> __( 'Language', 'woothemes-sensei' ),
112
-				'description'	=> __( 'Language options.', 'woothemes-sensei' )
111
+				'name' 			=> __('Language', 'woothemes-sensei'),
112
+				'description'	=> __('Language options.', 'woothemes-sensei')
113 113
 			);
114 114
 		}
115 115
 
116
-		$this->sections = apply_filters( 'sensei_settings_tabs', $sections );
116
+		$this->sections = apply_filters('sensei_settings_tabs', $sections);
117 117
 	} // End init_sections()
118 118
 
119 119
 	/**
@@ -123,71 +123,71 @@  discard block
 block discarded – undo
123 123
 	 * @uses   Sensei_Utils::get_slider_types()
124 124
 	 * @return void
125 125
 	 */
126
-	public function init_fields () {
126
+	public function init_fields() {
127 127
 		global $pagenow;
128 128
 
129 129
 		$pages_array = $this->pages_array();
130
-		$posts_per_page_array = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20' );
131
-		$complete_settings = array( 'passed' => __( 'Once all the course lessons have been completed', 'woothemes-sensei' ), 'complete' => __( 'At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei' ) );
132
-		$course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) );
130
+		$posts_per_page_array = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20');
131
+		$complete_settings = array('passed' => __('Once all the course lessons have been completed', 'woothemes-sensei'), 'complete' => __('At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei'));
132
+		$course_display_settings = array('excerpt' => __('Course Excerpt', 'woothemes-sensei'), 'full' => __('Full Course Content', 'woothemes-sensei'));
133 133
 
134 134
 	    $fields = array();
135 135
 
136 136
 		$fields['access_permission'] = array(
137
-								'name' => __( 'Access Permissions', 'woothemes-sensei' ),
138
-								'description' => __( 'Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei' ),
137
+								'name' => __('Access Permissions', 'woothemes-sensei'),
138
+								'description' => __('Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei'),
139 139
 								'type' => 'checkbox',
140 140
 								'default' => true,
141 141
 								'section' => 'default-settings'
142 142
 								);
143 143
 
144 144
 		$fields['messages_disable'] = array(
145
-								'name' => __( 'Disable Private Messages', 'woothemes-sensei' ),
146
-								'description' => __( 'Disable the private message functions between learners and teachers.', 'woothemes-sensei' ),
145
+								'name' => __('Disable Private Messages', 'woothemes-sensei'),
146
+								'description' => __('Disable the private message functions between learners and teachers.', 'woothemes-sensei'),
147 147
 								'type' => 'checkbox',
148 148
 								'default' => false,
149 149
 								'section' => 'default-settings'
150 150
 								);
151 151
 
152 152
 		$fields['course_page'] = array(
153
-								'name' => __( 'Course Archive Page', 'woothemes-sensei' ),
154
-								'description' => __( 'The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei' ),
153
+								'name' => __('Course Archive Page', 'woothemes-sensei'),
154
+								'description' => __('The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei'),
155 155
 								'type' => 'select',
156
-								'default' => get_option( 'woothemes-sensei_courses_page_id', 0 ),
156
+								'default' => get_option('woothemes-sensei_courses_page_id', 0),
157 157
 								'section' => 'default-settings',
158 158
 								'required' => 0,
159 159
 								'options' => $pages_array
160 160
 								);
161 161
 
162 162
 		$fields['my_course_page'] = array(
163
-								'name' => __( 'My Courses Page', 'woothemes-sensei' ),
164
-								'description' => __( 'The page to use to display the courses that a user is currently taking as well as the courses a user has complete.', 'woothemes-sensei' ),
163
+								'name' => __('My Courses Page', 'woothemes-sensei'),
164
+								'description' => __('The page to use to display the courses that a user is currently taking as well as the courses a user has complete.', 'woothemes-sensei'),
165 165
 								'type' => 'select',
166
-								'default' => get_option( 'woothemes-sensei_user_dashboard_page_id', 0 ),
166
+								'default' => get_option('woothemes-sensei_user_dashboard_page_id', 0),
167 167
 								'section' => 'default-settings',
168 168
 								'required' => 0,
169 169
 								'options' => $pages_array
170 170
 								);
171 171
 
172 172
 		$fields['placeholder_images_enable'] = array(
173
-								'name' => __( 'Use placeholder images', 'woothemes-sensei' ),
174
-								'description' => __( 'Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei' ),
173
+								'name' => __('Use placeholder images', 'woothemes-sensei'),
174
+								'description' => __('Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei'),
175 175
 								'type' => 'checkbox',
176 176
 								'default' => false,
177 177
 								'section' => 'default-settings'
178 178
 								);
179 179
 
180 180
 		$fields['styles_disable'] = array(
181
-								'name' => __( 'Disable Sensei Styles', 'woothemes-sensei' ),
182
-								'description' => __( 'Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei' ),
181
+								'name' => __('Disable Sensei Styles', 'woothemes-sensei'),
182
+								'description' => __('Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei'),
183 183
 								'type' => 'checkbox',
184 184
 								'default' => false,
185 185
 								'section' => 'default-settings'
186 186
 								);
187 187
 
188 188
 		$fields['js_disable'] = array(
189
-								'name' => __( 'Disable Sensei Javascript', 'woothemes-sensei' ),
190
-								'description' => __( 'Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei' ),
189
+								'name' => __('Disable Sensei Javascript', 'woothemes-sensei'),
190
+								'description' => __('Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei'),
191 191
 								'type' => 'checkbox',
192 192
 								'default' => false,
193 193
 								'section' => 'default-settings'
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
     	// Course Settings
197 197
 
198 198
     	$fields['course_completion'] = array(
199
-								'name' => __( 'Courses are complete:', 'woothemes-sensei' ),
200
-								'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ),
199
+								'name' => __('Courses are complete:', 'woothemes-sensei'),
200
+								'description' => __('This will determine when courses are marked as complete.', 'woothemes-sensei'),
201 201
 								'type' => 'select',
202 202
 								'default' => 'passed',
203 203
 								'section' => 'course-settings',
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
 								);
207 207
 
208 208
     	$fields['course_author'] = array(
209
-								'name' => __( 'Display Course Author', 'woothemes-sensei' ),
210
-								'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ),
209
+								'name' => __('Display Course Author', 'woothemes-sensei'),
210
+								'description' => __('Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei'),
211 211
 								'type' => 'checkbox',
212 212
 								'default' => true,
213 213
 								'section' => 'course-settings'
214 214
 								);
215 215
 
216 216
 		$fields['my_course_amount'] = array(
217
-								'name' => __( 'My Courses Pagination', 'woothemes-sensei' ),
218
-								'description' => __( 'The number of courses to output for the my courses page.', 'woothemes-sensei' ),
217
+								'name' => __('My Courses Pagination', 'woothemes-sensei'),
218
+								'description' => __('The number of courses to output for the my courses page.', 'woothemes-sensei'),
219 219
 								'type' => 'range',
220 220
 								'default' => '0',
221 221
 								'section' => 'course-settings',
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
 								);
225 225
 
226 226
 		$fields['course_archive_image_enable'] = array(
227
-								'name' => __( 'Course Archive Image', 'woothemes-sensei' ),
228
-								'description' => __( 'Output the Course Image on the Course Archive Page.', 'woothemes-sensei' ),
227
+								'name' => __('Course Archive Image', 'woothemes-sensei'),
228
+								'description' => __('Output the Course Image on the Course Archive Page.', 'woothemes-sensei'),
229 229
 								'type' => 'checkbox',
230 230
 								'default' => true,
231 231
 								'section' => 'course-settings'
232 232
 								);
233 233
 
234 234
 		$fields['course_archive_image_width'] = array(
235
-								'name' => __( 'Image Width - Archive', 'woothemes-sensei' ),
236
-								'description' => __( 'The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
235
+								'name' => __('Image Width - Archive', 'woothemes-sensei'),
236
+								'description' => __('The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
237 237
 								'type' => 'text',
238 238
 								'default' => '100',
239 239
 								'section' => 'course-settings',
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 								);
242 242
 
243 243
 		$fields['course_archive_image_height'] = array(
244
-								'name' => __( 'Image Height - Archive', 'woothemes-sensei' ),
245
-								'description' => __( 'The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
244
+								'name' => __('Image Height - Archive', 'woothemes-sensei'),
245
+								'description' => __('The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
246 246
 								'type' => 'text',
247 247
 								'default' => '100',
248 248
 								'section' => 'course-settings',
@@ -250,24 +250,24 @@  discard block
 block discarded – undo
250 250
 								);
251 251
 
252 252
 		$fields['course_archive_image_hard_crop'] = array(
253
-								'name' => __( 'Image Hard Crop - Archive', 'woothemes-sensei' ),
254
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
253
+								'name' => __('Image Hard Crop - Archive', 'woothemes-sensei'),
254
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
255 255
 								'type' => 'checkbox',
256 256
 								'default' => false,
257 257
 								'section' => 'course-settings'
258 258
 								);
259 259
 
260 260
 		$fields['course_single_image_enable'] = array(
261
-								'name' => __( 'Single Course Image', 'woothemes-sensei' ),
262
-								'description' => __( 'Output the Course Image on the Single Course Page.', 'woothemes-sensei' ),
261
+								'name' => __('Single Course Image', 'woothemes-sensei'),
262
+								'description' => __('Output the Course Image on the Single Course Page.', 'woothemes-sensei'),
263 263
 								'type' => 'checkbox',
264 264
 								'default' => false,
265 265
 								'section' => 'course-settings'
266 266
 								);
267 267
 
268 268
 		$fields['course_single_image_width'] = array(
269
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
270
-								'description' => __( 'The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
269
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
270
+								'description' => __('The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
271 271
 								'type' => 'text',
272 272
 								'default' => '100',
273 273
 								'section' => 'course-settings',
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 								);
276 276
 
277 277
 		$fields['course_single_image_height'] = array(
278
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
279
-								'description' => __( 'The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
278
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
279
+								'description' => __('The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
280 280
 								'type' => 'text',
281 281
 								'default' => '100',
282 282
 								'section' => 'course-settings',
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
 								);
285 285
 
286 286
 		$fields['course_single_image_hard_crop'] = array(
287
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
288
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
287
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
288
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
289 289
 								'type' => 'checkbox',
290 290
 								'default' => false,
291 291
 								'section' => 'course-settings'
292 292
 								);
293 293
 
294 294
 		$fields['course_single_content_display'] = array(
295
-								'name' => __( 'Single Course page displays:', 'woothemes-sensei' ),
296
-								'description' => __( 'Determines what content to display on the single course page.', 'woothemes-sensei' ),
295
+								'name' => __('Single Course page displays:', 'woothemes-sensei'),
296
+								'description' => __('Determines what content to display on the single course page.', 'woothemes-sensei'),
297 297
 								'type' => 'select',
298 298
 								'default' => 'excerpt',
299 299
 								'section' => 'course-settings',
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
 								);
303 303
 
304 304
 		$fields['course_archive_featured_enable'] = array(
305
-								'name' => __( 'Featured Courses Panel', 'woothemes-sensei' ),
306
-								'description' => __( 'Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
305
+								'name' => __('Featured Courses Panel', 'woothemes-sensei'),
306
+								'description' => __('Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
307 307
 								'type' => 'checkbox',
308 308
 								'default' => true,
309 309
 								'section' => 'course-settings'
310 310
 								);
311 311
 
312 312
 		$fields['course_archive_more_link_text'] = array(
313
-								'name' => __( 'More link text', 'woothemes-sensei' ),
314
-								'description' => __( 'The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei' ),
313
+								'name' => __('More link text', 'woothemes-sensei'),
314
+								'description' => __('The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei'),
315 315
 								'type' => 'text',
316
-								'default' => __ ( 'More', 'woothemes-sensei' ),
316
+								'default' => __('More', 'woothemes-sensei'),
317 317
 								'section' => 'course-settings',
318 318
 								'required' => 0
319 319
 								);
@@ -321,32 +321,32 @@  discard block
 block discarded – undo
321 321
 		// Lesson Settings
322 322
 
323 323
 		$fields['lesson_comments'] = array(
324
-								'name' => __( 'Allow Comments for Lessons', 'woothemes-sensei' ),
325
-								'description' => __( 'This will allow learners to post comments on the single Lesson page, only learner who have access to the Lesson will be allowed to comment.', 'woothemes-sensei' ),
324
+								'name' => __('Allow Comments for Lessons', 'woothemes-sensei'),
325
+								'description' => __('This will allow learners to post comments on the single Lesson page, only learner who have access to the Lesson will be allowed to comment.', 'woothemes-sensei'),
326 326
 								'type' => 'checkbox',
327 327
 								'default' => true,
328 328
 								'section' => 'lesson-settings'
329 329
 								);
330 330
 
331 331
 		$fields['lesson_author'] = array(
332
-								'name' => __( 'Display Lesson Author', 'woothemes-sensei' ),
333
-								'description' => __( 'Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei' ),
332
+								'name' => __('Display Lesson Author', 'woothemes-sensei'),
333
+								'description' => __('Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei'),
334 334
 								'type' => 'checkbox',
335 335
 								'default' => true,
336 336
 								'section' => 'lesson-settings'
337 337
 								);
338 338
 
339 339
 		$fields['course_lesson_image_enable'] = array(
340
-								'name' => __( 'Course Lesson Images', 'woothemes-sensei' ),
341
-								'description' => __( 'Output the Lesson Image on the Single Course Page.', 'woothemes-sensei' ),
340
+								'name' => __('Course Lesson Images', 'woothemes-sensei'),
341
+								'description' => __('Output the Lesson Image on the Single Course Page.', 'woothemes-sensei'),
342 342
 								'type' => 'checkbox',
343 343
 								'default' => false,
344 344
 								'section' => 'lesson-settings'
345 345
 								);
346 346
 
347 347
 		$fields['lesson_archive_image_width'] = array(
348
-								'name' => __( 'Image Width - Course Lessons', 'woothemes-sensei' ),
349
-								'description' => __( 'The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
348
+								'name' => __('Image Width - Course Lessons', 'woothemes-sensei'),
349
+								'description' => __('The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
350 350
 								'type' => 'text',
351 351
 								'default' => '100',
352 352
 								'section' => 'lesson-settings',
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 								);
355 355
 
356 356
 		$fields['lesson_archive_image_height'] = array(
357
-								'name' => __( 'Image Height - Course Lessons', 'woothemes-sensei' ),
358
-								'description' => __( 'The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
357
+								'name' => __('Image Height - Course Lessons', 'woothemes-sensei'),
358
+								'description' => __('The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
359 359
 								'type' => 'text',
360 360
 								'default' => '100',
361 361
 								'section' => 'lesson-settings',
@@ -363,24 +363,24 @@  discard block
 block discarded – undo
363 363
 								);
364 364
 
365 365
 		$fields['lesson_archive_image_hard_crop'] = array(
366
-								'name' => __( 'Image Hard Crop - Course Lessons', 'woothemes-sensei' ),
367
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
366
+								'name' => __('Image Hard Crop - Course Lessons', 'woothemes-sensei'),
367
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
368 368
 								'type' => 'checkbox',
369 369
 								'default' => false,
370 370
 								'section' => 'lesson-settings'
371 371
 								);
372 372
 
373 373
 		$fields['lesson_single_image_enable'] = array(
374
-								'name' => __( 'Single Lesson Images', 'woothemes-sensei' ),
375
-								'description' => __( 'Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei' ),
374
+								'name' => __('Single Lesson Images', 'woothemes-sensei'),
375
+								'description' => __('Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei'),
376 376
 								'type' => 'checkbox',
377 377
 								'default' => false,
378 378
 								'section' => 'lesson-settings'
379 379
 								);
380 380
 
381 381
 		$fields['lesson_single_image_width'] = array(
382
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
383
-								'description' => __( 'The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
382
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
383
+								'description' => __('The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
384 384
 								'type' => 'text',
385 385
 								'default' => '100',
386 386
 								'section' => 'lesson-settings',
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 								);
389 389
 
390 390
 		$fields['lesson_single_image_height'] = array(
391
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
392
-								'description' => __( 'The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
391
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
392
+								'description' => __('The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
393 393
 								'type' => 'text',
394 394
 								'default' => '100',
395 395
 								'section' => 'lesson-settings',
@@ -397,8 +397,8 @@  discard block
 block discarded – undo
397 397
 								);
398 398
 
399 399
 		$fields['lesson_single_image_hard_crop'] = array(
400
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
401
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
400
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
401
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
402 402
 								'type' => 'checkbox',
403 403
 								'default' => false,
404 404
 								'section' => 'lesson-settings'
@@ -406,20 +406,20 @@  discard block
 block discarded – undo
406 406
 
407 407
 		// Learner Profile settings
408 408
 
409
-		$profile_url_base = apply_filters( 'sensei_learner_profiles_url_base', __( 'learner', 'woothemes-sensei') );
410
-		$profile_url_example = trailingslashit( get_site_url() ) . $profile_url_base . '/%username%';
409
+		$profile_url_base = apply_filters('sensei_learner_profiles_url_base', __('learner', 'woothemes-sensei'));
410
+		$profile_url_example = trailingslashit(get_site_url()).$profile_url_base.'/%username%';
411 411
 
412 412
 		$fields['learner_profile_enable'] = array(
413
-							'name' => __( 'Public learner profiles', 'woothemes-sensei' ),
414
-							'description' => sprintf( __( 'Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei' ), $profile_url_example ),
413
+							'name' => __('Public learner profiles', 'woothemes-sensei'),
414
+							'description' => sprintf(__('Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei'), $profile_url_example),
415 415
 							'type' => 'checkbox',
416 416
 							'default' => true,
417 417
 							'section' => 'learner-profile-settings'
418 418
 							);
419 419
 
420 420
 		$fields['learner_profile_show_courses'] = array(
421
-							'name' => __( 'Show learner\'s courses', 'woothemes-sensei' ),
422
-							'description' => __( 'Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei' ),
421
+							'name' => __('Show learner\'s courses', 'woothemes-sensei'),
422
+							'description' => __('Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei'),
423 423
 							'type' => 'checkbox',
424 424
 							'default' => true,
425 425
 							'section' => 'learner-profile-settings'
@@ -428,70 +428,70 @@  discard block
 block discarded – undo
428 428
 		// Email notifications
429 429
 
430 430
 		$learner_email_options = array(
431
-			'learner-graded-quiz' => __( 'Their quiz is graded (auto and manual grading)', 'woothemes-sensei' ),
432
-			'learner-completed-course' => __( 'They complete a course', 'woothemes-sensei' ),
431
+			'learner-graded-quiz' => __('Their quiz is graded (auto and manual grading)', 'woothemes-sensei'),
432
+			'learner-completed-course' => __('They complete a course', 'woothemes-sensei'),
433 433
 		);
434 434
 
435 435
 		$teacher_email_options = array(
436
-            'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ),
437
-            'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ),
438
-            'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ),
439
-            'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ),
440
-			'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ),
436
+            'teacher-started-course' => __('A learner starts their course', 'woothemes-sensei'),
437
+            'teacher-completed-course' => __('A learner completes their course', 'woothemes-sensei'),
438
+            'teacher-completed-lesson' => __('A learner completes a lesson', 'woothemes-sensei'),
439
+            'teacher-quiz-submitted' => __('A learner submits a quiz for grading', 'woothemes-sensei'),
440
+			'teacher-new-message' => __('A learner sends a private message to a teacher', 'woothemes-sensei'),
441 441
 		);
442 442
 
443 443
 		$global_email_options = array(
444
-			'new-message-reply' => __( 'They receive a reply to their private message', 'woothemes-sensei' ),
444
+			'new-message-reply' => __('They receive a reply to their private message', 'woothemes-sensei'),
445 445
 		);
446 446
 
447 447
 		$fields['email_learners'] = array(
448
-								'name' => __( 'Emails Sent to Learners', 'woothemes-sensei' ),
449
-								'description' => __( 'Select the notifications that will be sent to learners.', 'woothemes-sensei' ),
448
+								'name' => __('Emails Sent to Learners', 'woothemes-sensei'),
449
+								'description' => __('Select the notifications that will be sent to learners.', 'woothemes-sensei'),
450 450
 								'type' => 'multicheck',
451 451
 								'options' => $learner_email_options,
452
-								'defaults' => array( 'learner-graded-quiz', 'learner-completed-course' ),
452
+								'defaults' => array('learner-graded-quiz', 'learner-completed-course'),
453 453
 								'section' => 'email-notification-settings'
454 454
 								);
455 455
 
456 456
 		$fields['email_teachers'] = array(
457
-								'name' => __( 'Emails Sent to Teachers', 'woothemes-sensei' ),
458
-								'description' => __( 'Select the notifications that will be sent to teachers.', 'woothemes-sensei' ),
457
+								'name' => __('Emails Sent to Teachers', 'woothemes-sensei'),
458
+								'description' => __('Select the notifications that will be sent to teachers.', 'woothemes-sensei'),
459 459
 								'type' => 'multicheck',
460 460
 								'options' => $teacher_email_options,
461
-								'defaults' => array( 'teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message' ),
461
+								'defaults' => array('teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message'),
462 462
 								'section' => 'email-notification-settings'
463 463
 								);
464 464
 
465 465
 		$fields['email_global'] = array(
466
-								'name' => __( 'Emails Sent to All Users', 'woothemes-sensei' ),
467
-								'description' => __( 'Select the notifications that will be sent to all users.', 'woothemes-sensei' ),
466
+								'name' => __('Emails Sent to All Users', 'woothemes-sensei'),
467
+								'description' => __('Select the notifications that will be sent to all users.', 'woothemes-sensei'),
468 468
 								'type' => 'multicheck',
469 469
 								'options' => $global_email_options,
470
-								'defaults' => array( 'new-message-reply' ),
470
+								'defaults' => array('new-message-reply'),
471 471
 								'section' => 'email-notification-settings'
472 472
 								);
473 473
 
474 474
 		$fields['email_from_name'] = array(
475
-								'name' => __( '"From" Name', 'woothemes-sensei' ),
476
-								'description' => __( 'The name from which all emails will be sent.', 'woothemes-sensei' ),
475
+								'name' => __('"From" Name', 'woothemes-sensei'),
476
+								'description' => __('The name from which all emails will be sent.', 'woothemes-sensei'),
477 477
 								'type' => 'text',
478
-								'default' => get_bloginfo( 'name' ),
478
+								'default' => get_bloginfo('name'),
479 479
 								'section' => 'email-notification-settings',
480 480
 								'required' => 1
481 481
 								);
482 482
 
483 483
 		$fields['email_from_address'] = array(
484
-								'name' => __( '"From" Address', 'woothemes-sensei' ),
485
-								'description' => __( 'The address from which all emails will be sent.', 'woothemes-sensei' ),
484
+								'name' => __('"From" Address', 'woothemes-sensei'),
485
+								'description' => __('The address from which all emails will be sent.', 'woothemes-sensei'),
486 486
 								'type' => 'text',
487
-								'default' => get_bloginfo( 'admin_email' ),
487
+								'default' => get_bloginfo('admin_email'),
488 488
 								'section' => 'email-notification-settings',
489 489
 								'required' => 1
490 490
 								);
491 491
 
492 492
 		$fields['email_header_image'] = array(
493
-								'name' => __( 'Header Image', 'woothemes-sensei' ),
494
-								'description' => sprintf( __( 'Enter a URL to an image you want to show in the email\'s header. Upload your image using the %1$smedia uploader%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'media-new.php' ) . '">', '</a>' ),
493
+								'name' => __('Header Image', 'woothemes-sensei'),
494
+								'description' => sprintf(__('Enter a URL to an image you want to show in the email\'s header. Upload your image using the %1$smedia uploader%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('media-new.php').'">', '</a>'),
495 495
 								'type' => 'text',
496 496
 								'default' => '',
497 497
 								'section' => 'email-notification-settings',
@@ -499,17 +499,17 @@  discard block
 block discarded – undo
499 499
 								);
500 500
 
501 501
 		$fields['email_footer_text'] = array(
502
-								'name' => __( 'Email Footer Text', 'woothemes-sensei' ),
503
-								'description' => __( 'The text to appear in the footer of Sensei emails.', 'woothemes-sensei' ),
502
+								'name' => __('Email Footer Text', 'woothemes-sensei'),
503
+								'description' => __('The text to appear in the footer of Sensei emails.', 'woothemes-sensei'),
504 504
 								'type' => 'textarea',
505
-								'default' => sprintf( __( '%1$s - Powered by Sensei', 'woothemes-sensei' ), get_bloginfo( 'name' ) ),
505
+								'default' => sprintf(__('%1$s - Powered by Sensei', 'woothemes-sensei'), get_bloginfo('name')),
506 506
 								'section' => 'email-notification-settings',
507 507
 								'required' => 0
508 508
 								);
509 509
 
510 510
 		$fields['email_base_color'] = array(
511
-								'name' => __( 'Base Colour', 'woothemes-sensei' ),
512
-								'description' => sprintf( __( 'The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
511
+								'name' => __('Base Colour', 'woothemes-sensei'),
512
+								'description' => sprintf(__('The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
513 513
 								'type' => 'color',
514 514
 								'default' => '#557da1',
515 515
 								'section' => 'email-notification-settings',
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 								);
518 518
 
519 519
 		$fields['email_background_color'] = array(
520
-								'name' => __( 'Background Colour', 'woothemes-sensei' ),
521
-								'description' => sprintf( __( 'The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
520
+								'name' => __('Background Colour', 'woothemes-sensei'),
521
+								'description' => sprintf(__('The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
522 522
 								'type' => 'color',
523 523
 								'default' => '#f5f5f5',
524 524
 								'section' => 'email-notification-settings',
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 								);
527 527
 
528 528
 		$fields['email_body_background_color'] = array(
529
-								'name' => __( 'Body Background Colour', 'woothemes-sensei' ),
530
-								'description' => sprintf( __( 'The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
529
+								'name' => __('Body Background Colour', 'woothemes-sensei'),
530
+								'description' => sprintf(__('The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
531 531
 								'type' => 'color',
532 532
 								'default' => '#fdfdfd',
533 533
 								'section' => 'email-notification-settings',
@@ -535,35 +535,35 @@  discard block
 block discarded – undo
535 535
 								);
536 536
 
537 537
 		$fields['email_text_color'] = array(
538
-								'name' => __( 'Body Text Colour', 'woothemes-sensei' ),
539
-								'description' => sprintf( __( 'The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
538
+								'name' => __('Body Text Colour', 'woothemes-sensei'),
539
+								'description' => sprintf(__('The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
540 540
 								'type' => 'color',
541 541
 								'default' => '#505050',
542 542
 								'section' => 'email-notification-settings',
543 543
 								'required' => 1
544 544
 								);
545 545
 
546
-		if ( Sensei_WC::is_woocommerce_active() ) {
546
+		if (Sensei_WC::is_woocommerce_active()) {
547 547
 			// WooCommerce Settings
548 548
     		$fields['woocommerce_enabled'] = array(
549
-									'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ),
550
-									'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ),
549
+									'name' => __('Enable WooCommerce Courses', 'woothemes-sensei'),
550
+									'description' => __('Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei'),
551 551
 									'type' => 'checkbox',
552 552
 									'default' => true,
553 553
 									'section' => 'woocommerce-settings'
554 554
 									);
555 555
 
556 556
 			$fields['course_archive_free_enable'] = array(
557
-									'name' => __( 'Free Courses Panel', 'woothemes-sensei' ),
558
-									'description' => __( 'Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
557
+									'name' => __('Free Courses Panel', 'woothemes-sensei'),
558
+									'description' => __('Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
559 559
 									'type' => 'checkbox',
560 560
 									'default' => true,
561 561
 									'section' => 'woocommerce-settings'
562 562
 									);
563 563
 
564 564
 			$fields['course_archive_paid_enable'] = array(
565
-									'name' => __( 'Paid Courses Panel', 'woothemes-sensei' ),
566
-									'description' => __( 'Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
565
+									'name' => __('Paid Courses Panel', 'woothemes-sensei'),
566
+									'description' => __('Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
567 567
 									'type' => 'checkbox',
568 568
 									'default' => true,
569 569
 									'section' => 'woocommerce-settings'
@@ -571,18 +571,18 @@  discard block
 block discarded – undo
571 571
 
572 572
 		} // End If Statement
573 573
 
574
-		if ( 'en_US' !== get_locale() ) {
574
+		if ('en_US' !== get_locale()) {
575 575
 			$fields['install_language_pack'] = array(
576
-				'name'        => __( 'Install Language Pack', 'woothemes-sensei' ),
577
-				'description' => __( 'Use this action to install or re-install translation for your language if available.', 'woothemes-sensei' ),
576
+				'name'        => __('Install Language Pack', 'woothemes-sensei'),
577
+				'description' => __('Use this action to install or re-install translation for your language if available.', 'woothemes-sensei'),
578 578
 				'type'        => 'button',
579 579
 				'section'     => 'language-settings',
580 580
 				'target'      => Sensei_Language_Pack_Manager::get_install_uri(),
581
-				'label'       => __( 'Install', 'woothemes-sensei' )
581
+				'label'       => __('Install', 'woothemes-sensei')
582 582
 			);
583 583
 		}
584 584
 
585
-		$this->fields = apply_filters( 'sensei_settings_fields', $fields );
585
+		$this->fields = apply_filters('sensei_settings_fields', $fields);
586 586
 
587 587
 	} // End init_fields()
588 588
 
@@ -592,20 +592,20 @@  discard block
 block discarded – undo
592 592
 	 * @param  $include_milliseconds (default: true) Whether or not to include milliseconds between 0 and 1.
593 593
 	 * @return array Options between 0.1 and 10 seconds.
594 594
 	 */
595
-	private function get_duration_options ( $include_milliseconds = true ) {
596
-		$numbers = array( '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0', '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0' );
595
+	private function get_duration_options($include_milliseconds = true) {
596
+		$numbers = array('1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0', '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0');
597 597
 		$options = array();
598 598
 
599
-		if ( true == (bool)$include_milliseconds ) {
600
-			$milliseconds = array( '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9' );
601
-			foreach ( $milliseconds as $k => $v ) {
599
+		if (true == (bool) $include_milliseconds) {
600
+			$milliseconds = array('0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9');
601
+			foreach ($milliseconds as $k => $v) {
602 602
 				$options[$v] = $v;
603 603
 			}
604 604
 		} else {
605 605
 			$options['0.5'] = '0.5';
606 606
 		}
607 607
 
608
-		foreach ( $numbers as $k => $v ) {
608
+		foreach ($numbers as $k => $v) {
609 609
 			$options[$v] = $v;
610 610
 		}
611 611
 
@@ -621,25 +621,25 @@  discard block
 block discarded – undo
621 621
 	private function pages_array() {
622 622
 		// REFACTOR - Transform this into a field type instead.
623 623
 		// Setup an array of portfolio gallery terms for a dropdown.
624
-		$args = array( 'echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC' );
625
-		$pages_dropdown = wp_dropdown_pages( $args );
624
+		$args = array('echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC');
625
+		$pages_dropdown = wp_dropdown_pages($args);
626 626
 		$page_items = array();
627 627
 
628 628
 		// Quick string hack to make sure we get the pages with the indents.
629
-		$pages_dropdown = str_replace( "<select class='' name='page_id' id='page_id'>", '', $pages_dropdown );
630
-		$pages_dropdown = str_replace( '</select>', '', $pages_dropdown );
631
-		$pages_split = explode( '</option>', $pages_dropdown );
629
+		$pages_dropdown = str_replace("<select class='' name='page_id' id='page_id'>", '', $pages_dropdown);
630
+		$pages_dropdown = str_replace('</select>', '', $pages_dropdown);
631
+		$pages_split = explode('</option>', $pages_dropdown);
632 632
 
633
-		$page_items[] = __( 'Select a Page:', 'woothemes-sensei' );
633
+		$page_items[] = __('Select a Page:', 'woothemes-sensei');
634 634
 
635
-		foreach ( $pages_split as $k => $v ) {
635
+		foreach ($pages_split as $k => $v) {
636 636
 		    $id = '';
637 637
 		    // Get the ID value.
638
-		    preg_match( '/value="(.*?)"/i', $v, $matches );
638
+		    preg_match('/value="(.*?)"/i', $v, $matches);
639 639
 
640
-		    if ( isset( $matches[1] ) ) {
640
+		    if (isset($matches[1])) {
641 641
 		        $id = $matches[1];
642
-		        $page_items[$id] = trim( strip_tags( $v ) );
642
+		        $page_items[$id] = trim(strip_tags($v));
643 643
 		    } // End If Statement
644 644
 		} // End For Loop
645 645
 
@@ -663,10 +663,10 @@  discard block
 block discarded – undo
663 663
      *
664 664
      * @since 1.9.0
665 665
      */
666
-    public static function flush_rewrite_rules(){
666
+    public static function flush_rewrite_rules() {
667 667
 
668
-        if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ]
669
-            && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) {
668
+        if (isset($_POST['option_page']) && 'woothemes-sensei-settings' == $_POST['option_page']
669
+            && isset($_POST['action']) && 'update' == $_POST['action']) {
670 670
 
671 671
             Sensei()->initiate_rewrite_rules_flush();
672 672
 
@@ -680,4 +680,4 @@  discard block
 block discarded – undo
680 680
  * for backward compatibility
681 681
  * @since 1.9.0
682 682
  */
683
-class WooThemes_Sensei_Settings extends Sensei_Settings{}
683
+class WooThemes_Sensei_Settings extends Sensei_Settings {}
Please login to merge, or discard this patch.
includes/class-sensei-course-results.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Course Results Class
@@ -21,20 +21,20 @@  discard block
 block discarded – undo
21 21
 	 * Constructor.
22 22
 	 * @since  1.4.0
23 23
 	 */
24
-	public function __construct () {
24
+	public function __construct() {
25 25
 
26 26
 		// Setup learner profile URL base
27
-		$this->courses_url_base = apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url slug', 'woothemes-sensei' ) );
27
+		$this->courses_url_base = apply_filters('sensei_course_slug', _x('course', 'post type single url slug', 'woothemes-sensei'));
28 28
 
29 29
 		// Setup permalink structure for course results
30
-		add_action( 'init', array( $this, 'setup_permastruct' ) );
31
-		add_filter( 'wp_title', array( $this, 'page_title' ), 10, 2 );
30
+		add_action('init', array($this, 'setup_permastruct'));
31
+		add_filter('wp_title', array($this, 'page_title'), 10, 2);
32 32
 
33 33
 		// Load course results
34
-		add_action( 'sensei_course_results_content_inside_before', array( $this, 'deprecate_course_result_info_hook' ), 10 );
34
+		add_action('sensei_course_results_content_inside_before', array($this, 'deprecate_course_result_info_hook'), 10);
35 35
 
36 36
 		// Add class to body tag
37
-		add_filter( 'body_class', array( $this, 'body_class' ), 10, 1 );
37
+		add_filter('body_class', array($this, 'body_class'), 10, 1);
38 38
 
39 39
 	} // End __construct()
40 40
 
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 * @return void
45 45
 	 */
46 46
 	public function setup_permastruct() {
47
-		add_rewrite_rule( '^' . $this->courses_url_base . '/([^/]*)/results/?', 'index.php?course_results=$matches[1]', 'top' );
48
-		add_rewrite_tag( '%course_results%', '([^&]+)' );
47
+		add_rewrite_rule('^'.$this->courses_url_base.'/([^/]*)/results/?', 'index.php?course_results=$matches[1]', 'top');
48
+		add_rewrite_tag('%course_results%', '([^&]+)');
49 49
 	}
50 50
 
51 51
 	/**
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 * @param  string $sep   Seeparator string
55 55
 	 * @return string        Modified title
56 56
 	 */
57
-	public function page_title( $title, $sep = null ) {
57
+	public function page_title($title, $sep = null) {
58 58
 		global $wp_query;
59
-		if( isset( $wp_query->query_vars['course_results'] ) ) {
60
-			$course = get_page_by_path( $wp_query->query_vars['course_results'], OBJECT, 'course' );
61
-			$title = __( 'Course Results: ', 'woothemes-sensei' ) . $course->post_title . ' ' . $sep . ' ';
59
+		if (isset($wp_query->query_vars['course_results'])) {
60
+			$course = get_page_by_path($wp_query->query_vars['course_results'], OBJECT, 'course');
61
+			$title = __('Course Results: ', 'woothemes-sensei').$course->post_title.' '.$sep.' ';
62 62
 		}
63 63
 		return $title;
64 64
 	}
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
 	 * @param  integer $course_id ID of course
70 70
 	 * @return string             The course results page permalink
71 71
 	 */
72
-	public function get_permalink( $course_id = 0 ) {
72
+	public function get_permalink($course_id = 0) {
73 73
 
74 74
 		$permalink = '';
75 75
 
76
-		if( $course_id > 0 ) {
76
+		if ($course_id > 0) {
77 77
 
78
-			$course = get_post( $course_id );
78
+			$course = get_post($course_id);
79 79
 
80
-			if ( get_option('permalink_structure') ) {
81
-				$permalink = trailingslashit( get_home_url() ) . $this->courses_url_base . '/' . $course->post_name . '/results/';
80
+			if (get_option('permalink_structure')) {
81
+				$permalink = trailingslashit(get_home_url()).$this->courses_url_base.'/'.$course->post_name.'/results/';
82 82
 			} else {
83
-				$permalink = trailingslashit( get_home_url() ) . '?course_results=' . $course->post_name;
83
+				$permalink = trailingslashit(get_home_url()).'?course_results='.$course->post_name;
84 84
 			}
85 85
 		}
86 86
 
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
 	 * @return void
94 94
 	 */
95 95
 	public function content() {
96
-		global $wp_query,  $current_user;
96
+		global $wp_query, $current_user;
97 97
 
98
-		if( isset( $wp_query->query_vars['course_results'] ) ) {
99
-            Sensei_Templates::get_template( 'course-results/course-info.php' );
98
+		if (isset($wp_query->query_vars['course_results'])) {
99
+            Sensei_Templates::get_template('course-results/course-info.php');
100 100
 		}
101 101
 
102 102
 	}
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 
111 111
 		global $course;
112 112
 
113
-		$course_status = Sensei_Utils::sensei_user_course_status_message( $course->ID, get_current_user_id());
114
-		echo '<div class="sensei-message ' . $course_status['box_class'] . '">' . $course_status['message'] . '</div>';
113
+		$course_status = Sensei_Utils::sensei_user_course_status_message($course->ID, get_current_user_id());
114
+		echo '<div class="sensei-message '.$course_status['box_class'].'">'.$course_status['message'].'</div>';
115 115
 
116
-		sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course );
116
+		sensei_do_deprecated_action('sensei_course_results_lessons', '1.9.', 'sensei_course_results_content_inside_after', $course);
117 117
 
118
-        sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID );
118
+        sensei_do_deprecated_action('sensei_course_results_bottom', '1.9.', 'sensei_course_results_content_inside_after', $course->ID);
119 119
 
120 120
 	}
121 121
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	public function course_lessons() {
129 129
 
130 130
 		global $course;
131
-        _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' );
131
+        _deprecated_function('Sensei_modules course_lessons ', '1.9.0');
132 132
 
133 133
 	}
134 134
 
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param  array $classes Existing classes
138 138
 	 * @return array          Modified classes
139 139
 	 */
140
-	public function body_class( $classes ) {
140
+	public function body_class($classes) {
141 141
 		global $wp_query;
142
-		if( isset( $wp_query->query_vars['course_results'] ) ) {
142
+		if (isset($wp_query->query_vars['course_results'])) {
143 143
 			$classes[] = 'course-results';
144 144
 		}
145 145
 		return $classes;
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
      *
151 151
      * @deprecated since 1.9.0
152 152
      */
153
-    public static function deprecate_sensei_course_results_content_hook(){
153
+    public static function deprecate_sensei_course_results_content_hook() {
154 154
 
155
-        sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before');
155
+        sensei_do_deprecated_action('sensei_course_results_content', '1.9.0', 'sensei_course_results_content_before');
156 156
 
157 157
     }
158 158
 
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
      *
162 162
      * @since 1.9.0
163 163
      */
164
-    public static function fire_sensei_message_hook(){
164
+    public static function fire_sensei_message_hook() {
165 165
 
166
-        do_action( 'sensei_frontend_messages' );
166
+        do_action('sensei_frontend_messages');
167 167
 
168 168
     }
169 169
 
@@ -172,9 +172,9 @@  discard block
 block discarded – undo
172 172
      *
173 173
      * @since 1.9.0
174 174
      */
175
-    public static function deprecate_course_result_info_hook(){
175
+    public static function deprecate_course_result_info_hook() {
176 176
 
177
-        sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' );
177
+        sensei_do_deprecated_action('sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before');
178 178
 
179 179
     }
180 180
 
@@ -183,10 +183,10 @@  discard block
 block discarded – undo
183 183
      *
184 184
      * @deprecate since 1.9.0
185 185
      */
186
-    public static function deprecate_course_results_top_hook(){
186
+    public static function deprecate_course_results_top_hook() {
187 187
 
188 188
         global $course;
189
-        sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID );
189
+        sensei_do_deprecated_action('sensei_course_results_top', '1.9.0', 'sensei_course_results_content_inside_before', $course->ID);
190 190
 
191 191
     }
192 192
 
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
      *
196 196
      * @since 1.8.0
197 197
      */
198
-    public static function fire_course_image_hook(){
198
+    public static function fire_course_image_hook() {
199 199
 
200 200
         global $course;
201
-        do_action( 'sensei_course_image', $course->ID );
201
+        do_action('sensei_course_image', $course->ID);
202 202
 
203 203
     }
204 204
 
@@ -209,4 +209,4 @@  discard block
 block discarded – undo
209 209
  * for backward compatibility
210 210
  * @since 1.9.0
211 211
  */
212
-class WooThemes_Sensei_Course_Results extends Sensei_Course_Results{}
212
+class WooThemes_Sensei_Course_Results extends Sensei_Course_Results {}
Please login to merge, or discard this patch.
includes/class-sensei-grading-main.php 1 patch
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Grading Overview List Table Class
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 	 * @since  1.3.0
26 26
 	 * @return  void
27 27
 	 */
28
-	public function __construct ( $args = null ) {
28
+	public function __construct($args = null) {
29 29
 
30 30
 		$defaults = array(
31 31
 			'course_id' => 0,
@@ -33,24 +33,24 @@  discard block
 block discarded – undo
33 33
 			'user_id' => false,
34 34
 			'view' => 'ungraded',
35 35
 		);
36
-		$args = wp_parse_args( $args, $defaults );
36
+		$args = wp_parse_args($args, $defaults);
37 37
 
38
-		$this->course_id = intval( $args['course_id'] );
39
-		$this->lesson_id = intval( $args['lesson_id'] );
40
-		if ( !empty($args['user_id']) ) {
41
-			$this->user_id = intval( $args['user_id'] );
38
+		$this->course_id = intval($args['course_id']);
39
+		$this->lesson_id = intval($args['lesson_id']);
40
+		if ( ! empty($args['user_id'])) {
41
+			$this->user_id = intval($args['user_id']);
42 42
 		}
43 43
 
44
-		if( !empty( $args['view'] ) && in_array( $args['view'], array( 'in-progress', 'graded', 'ungraded', 'all' ) ) ) {
44
+		if ( ! empty($args['view']) && in_array($args['view'], array('in-progress', 'graded', 'ungraded', 'all'))) {
45 45
 			$this->view = $args['view'];
46 46
 		}
47 47
 
48 48
 		// Load Parent token into constructor
49
-		parent::__construct( 'grading_main' );
49
+		parent::__construct('grading_main');
50 50
 
51 51
 		// Actions
52
-		add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) );
53
-		add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) );
52
+		add_action('sensei_before_list_table', array($this, 'data_table_header'));
53
+		add_action('sensei_after_list_table', array($this, 'data_table_footer'));
54 54
 	} // End __construct()
55 55
 
56 56
 	/**
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	 */
61 61
 	function get_columns() {
62 62
 		$columns = array(
63
-			'title' => __( 'Learner', 'woothemes-sensei' ),
64
-			'course' => __( 'Course', 'woothemes-sensei' ),
65
-			'lesson' => __( 'Lesson', 'woothemes-sensei' ),
66
-			'updated' => __( 'Updated', 'woothemes-sensei' ),
67
-			'user_status' => __( 'Status', 'woothemes-sensei' ),
68
-			'user_grade' => __( 'Grade', 'woothemes-sensei' ),
63
+			'title' => __('Learner', 'woothemes-sensei'),
64
+			'course' => __('Course', 'woothemes-sensei'),
65
+			'lesson' => __('Lesson', 'woothemes-sensei'),
66
+			'updated' => __('Updated', 'woothemes-sensei'),
67
+			'user_status' => __('Status', 'woothemes-sensei'),
68
+			'user_grade' => __('Grade', 'woothemes-sensei'),
69 69
 			'action' => '',
70 70
 		);
71 71
 
72
-		$columns = apply_filters( 'sensei_grading_default_columns', $columns, $this );
72
+		$columns = apply_filters('sensei_grading_default_columns', $columns, $this);
73 73
 		return $columns;
74 74
 	}
75 75
 
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	function get_sortable_columns() {
82 82
 		$columns = array(
83
-			'title' => array( 'title', false ),
84
-			'course' => array( 'course', false ),
85
-			'lesson' => array( 'lesson', false ),
86
-			'updated' => array( 'updated', false ),
87
-			'user_status' => array( 'user_status', false ),
88
-			'user_grade' => array( 'user_grade', false ),
83
+			'title' => array('title', false),
84
+			'course' => array('course', false),
85
+			'lesson' => array('lesson', false),
86
+			'updated' => array('updated', false),
87
+			'user_status' => array('user_status', false),
88
+			'user_grade' => array('user_grade', false),
89 89
 		);
90
-		$columns = apply_filters( 'sensei_grading_default_columns_sortable', $columns, $this );
90
+		$columns = apply_filters('sensei_grading_default_columns_sortable', $columns, $this);
91 91
 		return $columns;
92 92
 	}
93 93
 
@@ -101,47 +101,47 @@  discard block
 block discarded – undo
101 101
 
102 102
 		// Handle orderby
103 103
 		$orderby = '';
104
-		if ( !empty( $_GET['orderby'] ) ) {
105
-			if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) {
106
-				$orderby = esc_html( $_GET['orderby'] );
104
+		if ( ! empty($_GET['orderby'])) {
105
+			if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) {
106
+				$orderby = esc_html($_GET['orderby']);
107 107
 			} // End If Statement
108 108
 		}
109 109
 
110 110
 		// Handle order
111 111
 		$order = 'DESC';
112
-		if ( !empty( $_GET['order'] ) ) {
113
-			$order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC';
112
+		if ( ! empty($_GET['order'])) {
113
+			$order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC';
114 114
 		}
115 115
 
116 116
 		// Handle search
117 117
 		$search = false;
118
-		if ( !empty( $_GET['s'] ) ) {
119
-			$search = esc_html( $_GET['s'] );
118
+		if ( ! empty($_GET['s'])) {
119
+			$search = esc_html($_GET['s']);
120 120
 		} // End If Statement
121 121
 		$this->search = $search;
122 122
 
123 123
 		// Searching users on statuses requires sub-selecting the statuses by user_ids
124
-		if ( $this->search ) {
124
+		if ($this->search) {
125 125
 			$user_args = array(
126
-				'search' => '*' . $this->search . '*',
126
+				'search' => '*'.$this->search.'*',
127 127
 				'fields' => 'ID',
128 128
 			);
129 129
 			// Filter for extending
130
-			$user_args = apply_filters( 'sensei_grading_search_users', $user_args );
131
-			if ( !empty( $user_args ) ) {
132
-				$learners_search = new WP_User_Query( $user_args );
130
+			$user_args = apply_filters('sensei_grading_search_users', $user_args);
131
+			if ( ! empty($user_args)) {
132
+				$learners_search = new WP_User_Query($user_args);
133 133
 				// Store for reuse on counts
134 134
 				$this->user_ids = $learners_search->get_results();
135 135
 			}
136 136
 		} // End If Statement
137 137
 
138
-		$per_page = $this->get_items_per_page( 'sensei_comments_per_page' );
139
-		$per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' );
138
+		$per_page = $this->get_items_per_page('sensei_comments_per_page');
139
+		$per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments');
140 140
 
141 141
 		$paged = $this->get_pagenum();
142 142
 		$offset = 0;
143
-		if ( !empty($paged) ) {
144
-			$offset = $per_page * ( $paged - 1 );
143
+		if ( ! empty($paged)) {
144
+			$offset = $per_page * ($paged - 1);
145 145
 		} // End If Statement
146 146
 
147 147
 		$activity_args = array(
@@ -153,27 +153,27 @@  discard block
 block discarded – undo
153 153
 			'status' => 'any',
154 154
 		);
155 155
 
156
-		if( $this->lesson_id ) {
156
+		if ($this->lesson_id) {
157 157
 			$activity_args['post_id'] = $this->lesson_id;
158 158
 		}
159
-		elseif( $this->course_id ) {
159
+		elseif ($this->course_id) {
160 160
 			// Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple
161 161
 			// post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 )
162
-			if ( version_compare($wp_version, '4.1', '>=') ) {
163
-				$activity_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' );
162
+			if (version_compare($wp_version, '4.1', '>=')) {
163
+				$activity_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids');
164 164
 			}
165 165
 		}
166 166
 		// Sub select to group of learners
167
-		if ( $this->user_ids ) {
167
+		if ($this->user_ids) {
168 168
 			$activity_args['user_id'] = (array) $this->user_ids;
169 169
 		}
170 170
 		// Restrict to a single Learner
171
-		if( $this->user_id ) {
171
+		if ($this->user_id) {
172 172
 			$activity_args['user_id'] = $this->user_id;
173 173
 		}
174 174
 
175 175
 
176
-		switch( $this->view ) {
176
+		switch ($this->view) {
177 177
 			case 'in-progress' :
178 178
 				$activity_args['status'] = 'in-progress';
179 179
 				break;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 				break;
184 184
 
185 185
 			case 'graded' :
186
-				$activity_args['status'] = array( 'graded', 'passed', 'failed' );
186
+				$activity_args['status'] = array('graded', 'passed', 'failed');
187 187
 				break;
188 188
 
189 189
 			case 'all' :
@@ -192,31 +192,31 @@  discard block
 block discarded – undo
192 192
 				break;
193 193
 		} // End switch
194 194
 
195
-		$activity_args = apply_filters( 'sensei_grading_filter_statuses', $activity_args );
195
+		$activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args);
196 196
 
197 197
 		// WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice
198
-		$total_statuses = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
198
+		$total_statuses = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0)));
199 199
 
200 200
 		// Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views?
201
-		if ( $total_statuses < $activity_args['offset'] ) {
202
-			$new_paged = floor( $total_statuses / $activity_args['number'] );
201
+		if ($total_statuses < $activity_args['offset']) {
202
+			$new_paged = floor($total_statuses / $activity_args['number']);
203 203
 			$activity_args['offset'] = $new_paged * $activity_args['number'];
204 204
 		}
205
-		$statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true );
205
+		$statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true);
206 206
 		// Need to always return an array, even with only 1 item
207
-		if ( !is_array($statuses) ) {
208
-			$statuses = array( $statuses );
207
+		if ( ! is_array($statuses)) {
208
+			$statuses = array($statuses);
209 209
 		}
210 210
 		$this->total_items = $total_statuses;
211 211
 		$this->items = $statuses;
212 212
 
213 213
 		$total_items = $this->total_items;
214
-		$total_pages = ceil( $total_items / $per_page );
215
-		$this->set_pagination_args( array(
214
+		$total_pages = ceil($total_items / $per_page);
215
+		$this->set_pagination_args(array(
216 216
 			'total_items' => $total_items,
217 217
 			'total_pages' => $total_pages,
218 218
 			'per_page' => $per_page
219
-		) );
219
+		));
220 220
 	}
221 221
 
222 222
 	/**
@@ -224,73 +224,73 @@  discard block
 block discarded – undo
224 224
 	 * @since  1.7.0
225 225
 	 * @param object $item The current item
226 226
 	 */
227
-	protected function get_row_data( $item ) {
227
+	protected function get_row_data($item) {
228 228
 		global $wp_version;
229 229
 
230 230
 		$grade = '';
231
-		if( 'complete' == $item->comment_approved ) {
232
-			$status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>';
233
-			$grade =  __( 'No Grade', 'woothemes-sensei' );
231
+		if ('complete' == $item->comment_approved) {
232
+			$status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>';
233
+			$grade = __('No Grade', 'woothemes-sensei');
234 234
 		}
235
-		elseif( 'graded' == $item->comment_approved ) {
236
-			$status_html = '<span class="graded">' .  __( 'Graded', 'woothemes-sensei' )  . '</span>';
237
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
235
+		elseif ('graded' == $item->comment_approved) {
236
+			$status_html = '<span class="graded">'.__('Graded', 'woothemes-sensei').'</span>';
237
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
238 238
 		}
239
-		elseif( 'passed' == $item->comment_approved ) {
240
-			$status_html = '<span class="passed">' .  __( 'Passed', 'woothemes-sensei' )  . '</span>';
241
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
239
+		elseif ('passed' == $item->comment_approved) {
240
+			$status_html = '<span class="passed">'.__('Passed', 'woothemes-sensei').'</span>';
241
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
242 242
 		}
243
-		elseif( 'failed' == $item->comment_approved ) {
244
-			$status_html = '<span class="failed">' .  __( 'Failed', 'woothemes-sensei' )  . '</span>';
245
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
243
+		elseif ('failed' == $item->comment_approved) {
244
+			$status_html = '<span class="failed">'.__('Failed', 'woothemes-sensei').'</span>';
245
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
246 246
 		}
247
-		elseif( 'ungraded' == $item->comment_approved ) {
248
-			$status_html = '<span class="ungraded">' .  __( 'Ungraded', 'woothemes-sensei' )  . '</span>';
249
-			$grade = __( 'N/A', 'woothemes-sensei' );
247
+		elseif ('ungraded' == $item->comment_approved) {
248
+			$status_html = '<span class="ungraded">'.__('Ungraded', 'woothemes-sensei').'</span>';
249
+			$grade = __('N/A', 'woothemes-sensei');
250 250
 		}
251 251
 		else {
252
-			$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
253
-			$grade = __( 'N/A', 'woothemes-sensei' );
252
+			$status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
253
+			$grade = __('N/A', 'woothemes-sensei');
254 254
 		}
255 255
 
256
-        $title = Sensei()->learners->get_learner_full_name( $item->user_id );
256
+        $title = Sensei()->learners->get_learner_full_name($item->user_id);
257 257
 
258 258
 		// QuizID to be deprecated
259
-		$quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true );
260
-		$quiz_link = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id ), admin_url( 'admin.php' ) ) );
259
+		$quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true);
260
+		$quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php')));
261 261
 
262 262
 		$grade_link = '';
263
-		switch( $item->comment_approved ) {
263
+		switch ($item->comment_approved) {
264 264
 			case 'ungraded':
265
-				$grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei' ) . '</a>';
265
+				$grade_link = '<a class="button-primary button" href="'.$quiz_link.'">'.__('Grade quiz', 'woothemes-sensei').'</a>';
266 266
 				break;
267 267
 
268 268
 			case 'graded':
269 269
 			case 'passed':
270 270
 			case 'failed':
271
-				$grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei' ) . '</a>';
271
+				$grade_link = '<a class="button-secondary button" href="'.$quiz_link.'">'.__('Review grade', 'woothemes-sensei').'</a>';
272 272
 				break;
273 273
 		}
274 274
 
275
-		$course_id = get_post_meta( $item->comment_post_ID, '_lesson_course', true );
275
+		$course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true);
276 276
 		$course_title = '';
277
-		if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) {
278
-			$course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>';
277
+		if ( ! empty($course_id) && version_compare($wp_version, '4.1', '>=')) {
278
+			$course_title = '<a href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))).'">'.get_the_title($course_id).'</a>';
279 279
 		}
280
-		else if ( !empty($course_id) ) {
281
-			$course_title = get_the_title( $course_id );
280
+		else if ( ! empty($course_id)) {
281
+			$course_title = get_the_title($course_id);
282 282
 		}
283
-		$lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>';
283
+		$lesson_title = '<a href="'.add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')).'">'.get_the_title($item->comment_post_ID).'</a>';
284 284
 
285
-		$column_data = apply_filters( 'sensei_grading_main_column_data', array(
286
-				'title' => '<strong><a class="row-title" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id ), admin_url( 'admin.php' ) ) ) . '"">' . $title . '</a></strong>',
285
+		$column_data = apply_filters('sensei_grading_main_column_data', array(
286
+				'title' => '<strong><a class="row-title" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))).'"">'.$title.'</a></strong>',
287 287
 				'course' => $course_title,
288 288
 				'lesson' => $lesson_title,
289 289
 				'updated' => $item->comment_date,
290 290
 				'user_status' => $status_html,
291 291
 				'user_grade' => $grade,
292 292
 				'action' => $grade_link,
293
-			), $item, $course_id );
293
+			), $item, $course_id);
294 294
 
295 295
 		return $column_data;
296 296
 	}
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 */
304 304
 	public function no_items() {
305 305
 
306
-        _e( 'No submissions found.', 'woothemes-sensei' );
306
+        _e('No submissions found.', 'woothemes-sensei');
307 307
 
308 308
 	} // End no_items()
309 309
 
@@ -316,35 +316,35 @@  discard block
 block discarded – undo
316 316
 		global  $wp_version;
317 317
 
318 318
 		echo '<div class="grading-selects">';
319
-		do_action( 'sensei_grading_before_dropdown_filters' );
319
+		do_action('sensei_grading_before_dropdown_filters');
320 320
 
321
-		echo '<div class="select-box">' . "\n";
321
+		echo '<div class="select-box">'."\n";
322 322
 
323
-			echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">' . "\n";
323
+			echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">'."\n";
324 324
 
325
-				echo Sensei()->grading->courses_drop_down_html( $this->course_id );
325
+				echo Sensei()->grading->courses_drop_down_html($this->course_id);
326 326
 
327
-			echo '</select>' . "\n";
327
+			echo '</select>'."\n";
328 328
 
329
-		echo '</div>' . "\n";
329
+		echo '</div>'."\n";
330 330
 
331
-		echo '<div class="select-box">' . "\n";
331
+		echo '<div class="select-box">'."\n";
332 332
 
333
-			echo '<select id="grading-lesson-options" data-placeholder="&larr; ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n";
333
+			echo '<select id="grading-lesson-options" data-placeholder="&larr; '.__('Select a course', 'woothemes-sensei').'" name="grading_lesson" class="chosen_select widefat">'."\n";
334 334
 
335
-				echo Sensei()->grading->lessons_drop_down_html( $this->course_id, $this->lesson_id );
335
+				echo Sensei()->grading->lessons_drop_down_html($this->course_id, $this->lesson_id);
336 336
 
337
-			echo '</select>' . "\n";
337
+			echo '</select>'."\n";
338 338
 
339
-		echo '</div>' . "\n";
339
+		echo '</div>'."\n";
340 340
 
341
-		if( $this->course_id && $this->lesson_id ) {
341
+		if ($this->course_id && $this->lesson_id) {
342 342
 
343
-			echo '<div class="select-box reset-filter">' . "\n";
343
+			echo '<div class="select-box reset-filter">'."\n";
344 344
 
345
-				echo '<a class="button-secondary" href="' . esc_url( remove_query_arg( array( 'lesson_id', 'course_id' ) ) ) . '">' . __( 'Reset filter', 'woothemes-sensei' ) . '</a>' . "\n";
345
+				echo '<a class="button-secondary" href="'.esc_url(remove_query_arg(array('lesson_id', 'course_id'))).'">'.__('Reset filter', 'woothemes-sensei').'</a>'."\n";
346 346
 
347
-			echo '</div>' . "\n";
347
+			echo '</div>'."\n";
348 348
 
349 349
 		}
350 350
 
@@ -359,26 +359,26 @@  discard block
 block discarded – undo
359 359
 		$query_args = array(
360 360
 			'page' => $this->page_slug,
361 361
 		);
362
-		if( $this->course_id ) {
362
+		if ($this->course_id) {
363 363
 			// Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple
364 364
 			// post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 )
365 365
 			$query_args['course_id'] = $this->course_id;
366
-			if ( version_compare($wp_version, '4.1', '>=') ) {
367
-				$count_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' );
366
+			if (version_compare($wp_version, '4.1', '>=')) {
367
+				$count_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids');
368 368
 			}
369 369
 		}
370
-		if( $this->lesson_id ) {
370
+		if ($this->lesson_id) {
371 371
 			$query_args['lesson_id'] = $this->lesson_id;
372 372
 			// Restrict to a single lesson
373 373
 			$count_args['post_id'] = $this->lesson_id;
374 374
 		}
375
-		if( $this->search ) {
375
+		if ($this->search) {
376 376
 			$query_args['s'] = $this->search;
377 377
 		}
378
-		if ( !empty($this->user_ids) ) {
378
+		if ( ! empty($this->user_ids)) {
379 379
 			$count_args['user_id'] = $this->user_ids;
380 380
 		}
381
-		if( !empty($this->user_id) ) {
381
+		if ( ! empty($this->user_id)) {
382 382
 			$query_args['user_id'] = $this->user_id;
383 383
 			$count_args['user_id'] = $this->user_id;
384 384
 		}
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		$all_lessons_count = $ungraded_lessons_count = $graded_lessons_count = $inprogress_lessons_count = 0;
387 387
 		$all_class = $ungraded_class = $graded_class = $inprogress_class = '';
388 388
 
389
-		switch( $this->view ) :
389
+		switch ($this->view) :
390 390
 			case 'all':
391 391
 				$all_class = 'current';
392 392
 				break;
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 				break;
403 403
 		endswitch;
404 404
 
405
-		$counts = Sensei()->grading->count_statuses( apply_filters( 'sensei_grading_count_statues', $count_args ) );
405
+		$counts = Sensei()->grading->count_statuses(apply_filters('sensei_grading_count_statues', $count_args));
406 406
 
407 407
 		$inprogress_lessons_count = $counts['in-progress'];
408 408
 		$ungraded_lessons_count = $counts['ungraded'];
@@ -418,19 +418,19 @@  discard block
 block discarded – undo
418 418
 		$inprogress_args['view'] = 'in-progress';
419 419
 
420 420
 		$format = '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>';
421
-		$menu['all'] = sprintf( $format, $all_class, esc_url( add_query_arg( $all_args, admin_url( 'admin.php' ) ) ), __( 'All', 'woothemes-sensei' ), number_format( (int) $all_lessons_count ) );
422
-		$menu['ungraded'] = sprintf( $format, $ungraded_class, esc_url( add_query_arg( $ungraded_args, admin_url( 'admin.php' ) ) ), __( 'Ungraded', 'woothemes-sensei' ), number_format( (int) $ungraded_lessons_count ) );
423
-		$menu['graded'] = sprintf( $format, $graded_class, esc_url( add_query_arg( $graded_args, admin_url( 'admin.php' ) ) ), __( 'Graded', 'woothemes-sensei' ), number_format( (int) $graded_lessons_count ) );
424
-		$menu['in-progress'] = sprintf( $format, $inprogress_class, esc_url( add_query_arg( $inprogress_args, admin_url( 'admin.php' ) ) ), __( 'In Progress', 'woothemes-sensei' ), number_format( (int) $inprogress_lessons_count ) );
425
-
426
-		$menu = apply_filters( 'sensei_grading_sub_menu', $menu );
427
-		if ( !empty($menu) ) {
428
-			echo '<ul class="subsubsub">' . "\n";
429
-			foreach ( $menu as $class => $item ) {
430
-				$menu[ $class ] = "\t<li class='$class'>$item";
421
+		$menu['all'] = sprintf($format, $all_class, esc_url(add_query_arg($all_args, admin_url('admin.php'))), __('All', 'woothemes-sensei'), number_format((int) $all_lessons_count));
422
+		$menu['ungraded'] = sprintf($format, $ungraded_class, esc_url(add_query_arg($ungraded_args, admin_url('admin.php'))), __('Ungraded', 'woothemes-sensei'), number_format((int) $ungraded_lessons_count));
423
+		$menu['graded'] = sprintf($format, $graded_class, esc_url(add_query_arg($graded_args, admin_url('admin.php'))), __('Graded', 'woothemes-sensei'), number_format((int) $graded_lessons_count));
424
+		$menu['in-progress'] = sprintf($format, $inprogress_class, esc_url(add_query_arg($inprogress_args, admin_url('admin.php'))), __('In Progress', 'woothemes-sensei'), number_format((int) $inprogress_lessons_count));
425
+
426
+		$menu = apply_filters('sensei_grading_sub_menu', $menu);
427
+		if ( ! empty($menu)) {
428
+			echo '<ul class="subsubsub">'."\n";
429
+			foreach ($menu as $class => $item) {
430
+				$menu[$class] = "\t<li class='$class'>$item";
431 431
 			}
432
-			echo implode( " |</li>\n", $menu ) . "</li>\n";
433
-			echo '</ul>' . "\n";
432
+			echo implode(" |</li>\n", $menu)."</li>\n";
433
+			echo '</ul>'."\n";
434 434
 		}
435 435
 
436 436
 	} // End data_table_header()
@@ -451,4 +451,4 @@  discard block
 block discarded – undo
451 451
  * for backward compatibility
452 452
  * @since 1.9.0
453 453
  */
454
-class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main{}
454
+class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main {}
Please login to merge, or discard this patch.
includes/class-sensei-utils.php 1 patch
Spacing   +531 added lines, -531 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Utilities Class
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
 	 * @since   1.0.0
20 20
 	 * @return  string The URL to the placeholder thumbnail image.
21 21
 	 */
22
-	public static function get_placeholder_image () {
22
+	public static function get_placeholder_image() {
23 23
 
24
-		return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) );
24
+		return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png'));
25 25
 	} // End get_placeholder_image()
26 26
 
27 27
 	/**
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @static
34 34
 	 * @return bool
35 35
 	 */
36
-	public static function sensei_is_woocommerce_present () {
36
+	public static function sensei_is_woocommerce_present() {
37 37
 
38 38
         return Sensei_WC::is_woocommerce_present();
39 39
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @static
49 49
 	 * @return boolean
50 50
 	 */
51
-	public static function sensei_is_woocommerce_activated () {
51
+	public static function sensei_is_woocommerce_activated() {
52 52
 
53 53
 		return  Sensei_WC::is_woocommerce_active();
54 54
 
@@ -61,70 +61,70 @@  discard block
 block discarded – undo
61 61
 	 * @param  array $args (default: array())
62 62
 	 * @return bool | int
63 63
 	 */
64
-	public static function sensei_log_activity ( $args = array() ) {
64
+	public static function sensei_log_activity($args = array()) {
65 65
 		global $wpdb;
66 66
 
67 67
 		// Args, minimum data required for WP
68 68
 		$data = array(
69
-					'comment_post_ID' => intval( $args['post_id'] ),
69
+					'comment_post_ID' => intval($args['post_id']),
70 70
 					'comment_author' => '', // Not needed
71 71
 					'comment_author_email' => '', // Not needed
72 72
 					'comment_author_url' => '', // Not needed
73
-					'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '',
74
-					'comment_type' => esc_attr( $args['type'] ),
75
-					'user_id' => intval( $args['user_id'] ),
76
-					'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer'
73
+					'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '',
74
+					'comment_type' => esc_attr($args['type']),
75
+					'user_id' => intval($args['user_id']),
76
+					'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer'
77 77
 				);
78 78
 		// Allow extra data
79
-		if ( !empty($args['username']) ) {
80
-			$data['comment_author'] = sanitize_user( $args['username'] );
79
+		if ( ! empty($args['username'])) {
80
+			$data['comment_author'] = sanitize_user($args['username']);
81 81
 		}
82
-		if ( !empty($args['user_email']) ) {
83
-			$data['comment_author_email'] = sanitize_email( $args['user_email'] );
82
+		if ( ! empty($args['user_email'])) {
83
+			$data['comment_author_email'] = sanitize_email($args['user_email']);
84 84
 		}
85
-		if ( !empty($args['user_url']) ) {
86
-			$data['comment_author_url'] = esc_url( $args['user_url'] );
85
+		if ( ! empty($args['user_url'])) {
86
+			$data['comment_author_url'] = esc_url($args['user_url']);
87 87
 		}
88
-		if ( !empty($args['parent']) ) {
88
+		if ( ! empty($args['parent'])) {
89 89
 			$data['comment_parent'] = $args['parent'];
90 90
 		}
91 91
 		// Sanity check
92
-		if ( empty($args['user_id']) ) {
93
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
92
+		if (empty($args['user_id'])) {
93
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
94 94
 			return false;
95 95
 		}
96 96
 
97
-		do_action( 'sensei_log_activity_before', $args, $data );
97
+		do_action('sensei_log_activity_before', $args, $data);
98 98
 
99 99
 		$flush_cache = false;
100 100
 
101 101
 		// Custom Logic
102 102
 		// Check if comment exists first
103
-		$comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) );
104
-		if ( ! $comment_id ) {
103
+		$comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type']));
104
+		if ( ! $comment_id) {
105 105
 			// Add the comment
106
-			$comment_id = wp_insert_comment( $data );
106
+			$comment_id = wp_insert_comment($data);
107 107
 
108 108
 			$flush_cache = true;
109
-		} elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) {
109
+		} elseif (isset($args['action']) && 'update' == $args['action']) {
110 110
 			// Update the comment if an update was requested
111 111
 			$data['comment_ID'] = $comment_id;
112 112
 			// By default update the timestamp of the comment
113
-			if ( empty($args['keep_time']) ) {
113
+			if (empty($args['keep_time'])) {
114 114
 				$data['comment_date'] = current_time('mysql');
115 115
 			}
116
-			wp_update_comment( $data );
116
+			wp_update_comment($data);
117 117
 			$flush_cache = true;
118 118
 		} // End If Statement
119 119
 
120 120
 		// Manually Flush the Cache
121
-		if ( $flush_cache ) {
121
+		if ($flush_cache) {
122 122
 			wp_cache_flush();
123 123
 		}
124 124
 
125
-		do_action( 'sensei_log_activity_after', $args, $data,  $comment_id );
125
+		do_action('sensei_log_activity_after', $args, $data, $comment_id);
126 126
 
127
-		if ( 0 < $comment_id ) {
127
+		if (0 < $comment_id) {
128 128
 			// Return the ID so that it can be used for meta data storage
129 129
 			return $comment_id;
130 130
 		} else {
@@ -141,41 +141,41 @@  discard block
 block discarded – undo
141 141
 	 * @param  bool $return_comments (default: false)
142 142
 	 * @return mixed | int
143 143
 	 */
144
-	public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) {
144
+	public static function sensei_check_for_activity($args = array(), $return_comments = false) {
145 145
 
146 146
 		global  $wp_version;
147
-		if ( !$return_comments ) {
147
+		if ( ! $return_comments) {
148 148
 			$args['count'] = true;
149 149
 		}
150 150
 
151 151
 		// Are we only retrieving a single entry, or not care about the order...
152
-		if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){
152
+		if (isset($args['count']) || isset($args['post_id'])) {
153 153
 
154 154
 			// ...then we don't need to ask the db to order the results, this overrides WP default behaviour
155
-			if ( version_compare( $wp_version, '4.1', '>=' ) ) {
155
+			if (version_compare($wp_version, '4.1', '>=')) {
156 156
 				$args['order'] = false;
157 157
 				$args['orderby'] = false;
158 158
 			}
159 159
 		}
160 160
 
161 161
 		// A user ID of 0 is in valid, so shortcut this
162
-		if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) {
163
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
162
+		if (isset($args['user_id']) && 0 == intval($args['user_id'])) {
163
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
164 164
 			return false;
165 165
 		}
166 166
 		// Check for legacy code
167
-		if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) {
168
-			_deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) );
167
+		if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) {
168
+			_deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type']));
169 169
 			return false;
170 170
 		}
171 171
 		// Are we checking for specific comment_approved statuses?
172
-		if ( isset($args['status']) ) {
172
+		if (isset($args['status'])) {
173 173
 			// Temporarily store as a custom status if requesting an array...
174
-			if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
174
+			if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) {
175 175
 				// Encode now, decode later
176
-				$args['status'] = implode( ",", $args['status'] );
176
+				$args['status'] = implode(",", $args['status']);
177 177
 				// ...use a filter to switch the encoding back
178
-				add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
178
+				add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
179 179
 			}
180 180
 		}
181 181
 		else {
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 		}
184 184
 
185 185
 		// Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 '
186
-		if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
187
-			add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
186
+		if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) {
187
+			add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
188 188
 		}
189 189
 
190 190
         //Get the comments
@@ -195,14 +195,14 @@  discard block
 block discarded – undo
195 195
          *
196 196
          * @param int|array $comments
197 197
          */
198
-        $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
198
+        $comments = apply_filters('sensei_check_for_activity', get_comments($args));
199 199
 
200
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
201
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
200
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
201
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
202 202
 		// Return comments
203
-		if ( $return_comments ) {
203
+		if ($return_comments) {
204 204
 			// Could check for array of 1 and just return the 1 item?
205
-			if ( is_array($comments) && 1 == count($comments) ) {
205
+			if (is_array($comments) && 1 == count($comments)) {
206 206
 				$comments = array_shift($comments);
207 207
 			}
208 208
 
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
 	 * @param  array $args (default: array())
221 221
 	 * @return array
222 222
 	 */
223
-	public static function sensei_activity_ids ( $args = array() ) {
223
+	public static function sensei_activity_ids($args = array()) {
224 224
 
225 225
 
226
-		$comments = Sensei_Utils::sensei_check_for_activity( $args, true );
226
+		$comments = Sensei_Utils::sensei_check_for_activity($args, true);
227 227
 		// Need to always use an array, even with only 1 item
228
-		if ( !is_array($comments) ) {
229
-			$comments = array( $comments );
228
+		if ( ! is_array($comments)) {
229
+			$comments = array($comments);
230 230
 		}
231 231
 
232 232
 		$post_ids = array();
233 233
 		// Count comments
234
-		if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) {
235
-			foreach ( $comments as $key => $value  ) {
234
+		if (is_array($comments) && (0 < intval(count($comments)))) {
235
+			foreach ($comments as $key => $value) {
236 236
 				// Add matches to id array
237
-				if ( isset( $args['field'] ) && 'comment' == $args['field'] ) {
238
-					array_push( $post_ids, $value->comment_ID );
239
-				} elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) {
240
-					array_push( $post_ids, $value->user_id );
237
+				if (isset($args['field']) && 'comment' == $args['field']) {
238
+					array_push($post_ids, $value->comment_ID);
239
+				} elseif (isset($args['field']) && 'user_id' == $args['field']) {
240
+					array_push($post_ids, $value->user_id);
241 241
 				} else {
242
-					array_push( $post_ids, $value->comment_post_ID );
242
+					array_push($post_ids, $value->comment_post_ID);
243 243
 				} // End If Statement
244 244
 			} // End For Loop
245 245
 			// Reset array indexes
246
-			$post_ids = array_unique( $post_ids );
247
-			$post_ids = array_values( $post_ids );
246
+			$post_ids = array_unique($post_ids);
247
+			$post_ids = array_values($post_ids);
248 248
 		} // End If Statement
249 249
 
250 250
 		return $post_ids;
@@ -258,20 +258,20 @@  discard block
 block discarded – undo
258 258
 	 * @param  array $args (default: array())
259 259
 	 * @return boolean
260 260
 	 */
261
-	public static function sensei_delete_activities ( $args = array() ) {
261
+	public static function sensei_delete_activities($args = array()) {
262 262
 
263 263
 		$dataset_changes = false;
264 264
 
265 265
 		// If activity exists remove activity from log
266
-		$comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true );
267
-		if( $comments ) {
266
+		$comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true);
267
+		if ($comments) {
268 268
 			// Need to always return an array, even with only 1 item
269
-			if ( !is_array( $comments ) ) {
270
-				$comments = array( $comments );
269
+			if ( ! is_array($comments)) {
270
+				$comments = array($comments);
271 271
 			}
272
-			foreach ( $comments as $key => $value  ) {
273
-				if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) {
274
-					$dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true );
272
+			foreach ($comments as $key => $value) {
273
+				if (isset($value->comment_ID) && 0 < $value->comment_ID) {
274
+					$dataset_changes = wp_delete_comment(intval($value->comment_ID), true);
275 275
 				} // End If Statement
276 276
 			} // End For Loop
277 277
 			// Manually flush the cache
@@ -287,25 +287,25 @@  discard block
 block discarded – undo
287 287
      * @param  integer $user_id User ID
288 288
      * @return boolean
289 289
      */
290
-    public static function delete_all_user_activity( $user_id = 0 ) {
290
+    public static function delete_all_user_activity($user_id = 0) {
291 291
 
292 292
     	$dataset_changes = false;
293 293
 
294
-    	if( $user_id ) {
294
+    	if ($user_id) {
295 295
 
296
-			$activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true );
296
+			$activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true);
297 297
 
298
-			if( $activities ) {
298
+			if ($activities) {
299 299
 
300 300
 				// Need to always return an array, even with only 1 item
301
-				if ( ! is_array( $activities ) ) {
302
-					$activities = array( $activities );
301
+				if ( ! is_array($activities)) {
302
+					$activities = array($activities);
303 303
 				}
304 304
 
305
-				foreach( $activities as $activity ) {
306
-					if( '' == $activity->comment_type ) continue;
307
-					if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
308
-					$dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true );
305
+				foreach ($activities as $activity) {
306
+					if ('' == $activity->comment_type) continue;
307
+					if (strpos('sensei_', $activity->comment_type) != 0) continue;
308
+					$dataset_changes = wp_delete_comment(intval($activity->comment_ID), true);
309 309
 					wp_cache_flush();
310 310
 				}
311 311
 			}
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 	 * @param  array $args (default: array())
323 323
 	 * @return string
324 324
 	 */
325
-	public static function sensei_get_activity_value ( $args = array() ) {
325
+	public static function sensei_get_activity_value($args = array()) {
326 326
 
327 327
 
328 328
 		$activity_value = false;
329
-		if ( !empty($args['field']) ) {
330
-			$comment = Sensei_Utils::sensei_check_for_activity( $args, true );
329
+		if ( ! empty($args['field'])) {
330
+			$comment = Sensei_Utils::sensei_check_for_activity($args, true);
331 331
 
332
-			if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
332
+			if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
333 333
 				$activity_value = $comment->{$args['field']};
334 334
 			} // End If Statement
335 335
 		}
@@ -347,22 +347,22 @@  discard block
 block discarded – undo
347 347
      * @param  int $product_id
348 348
      * @return bool
349 349
      */
350
-    public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
350
+    public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) {
351 351
 
352 352
         $emails = array();
353 353
 
354
-        if ( $user_id ) {
355
-            $user = get_user_by( 'id', intval( $user_id ) );
354
+        if ($user_id) {
355
+            $user = get_user_by('id', intval($user_id));
356 356
             $emails[] = $user->user_email;
357 357
         }
358 358
 
359
-        if ( is_email( $customer_email ) )
359
+        if (is_email($customer_email))
360 360
             $emails[] = $customer_email;
361 361
 
362
-        if ( sizeof( $emails ) == 0 )
362
+        if (sizeof($emails) == 0)
363 363
             return false;
364 364
 
365
-        return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
365
+        return Sensei_WC::has_customer_bought_product($user_id, $product_id);
366 366
 
367 367
     } // End sensei_customer_bought_product()
368 368
 
@@ -373,9 +373,9 @@  discard block
 block discarded – undo
373 373
 	 * @param  string $input_name Name for textarea form element
374 374
 	 * @return void
375 375
 	 */
376
-	public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) {
376
+	public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') {
377 377
 
378
-		if( ! $input_name ) $input_name = $editor_id;
378
+		if ( ! $input_name) $input_name = $editor_id;
379 379
 
380 380
 		$buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext';
381 381
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 			'quicktags' => false
394 394
 		);
395 395
 
396
-		wp_editor( $content, $editor_id, $settings );
396
+		wp_editor($content, $editor_id, $settings);
397 397
 
398 398
 	} // End sensei_text_editor()
399 399
 
@@ -403,56 +403,56 @@  discard block
 block discarded – undo
403 403
      * @param int $user_id
404 404
 	 * @return boolean            Whether the answers were saved or not
405 405
 	 */
406
-	public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) {
407
-		if( intval( $user_id ) == 0 ) {
406
+	public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) {
407
+		if (intval($user_id) == 0) {
408 408
 			$user_id = get_current_user_id();
409 409
 		}
410 410
 
411 411
 		$answers_saved = false;
412 412
 
413
-		if( $submitted && intval( $user_id ) > 0 ) {
413
+		if ($submitted && intval($user_id) > 0) {
414 414
 
415
-			foreach( $submitted as $question_id => $answer ) {
415
+			foreach ($submitted as $question_id => $answer) {
416 416
 
417 417
 				// Get question type
418
-				$question_type = Sensei()->question->get_question_type( $question_id );
418
+				$question_type = Sensei()->question->get_question_type($question_id);
419 419
 
420 420
 				// Sanitise answer
421
-				if( 0 == get_magic_quotes_gpc() ) {
422
-					$answer = wp_unslash( $answer );
421
+				if (0 == get_magic_quotes_gpc()) {
422
+					$answer = wp_unslash($answer);
423 423
 				}
424
-				switch( $question_type ) {
425
-					case 'multi-line': $answer = nl2br( $answer ); break;
424
+				switch ($question_type) {
425
+					case 'multi-line': $answer = nl2br($answer); break;
426 426
 					case 'single-line': break;
427 427
 					case 'gap-fill': break;
428
-					default: $answer = maybe_serialize( $answer ); break;
428
+					default: $answer = maybe_serialize($answer); break;
429 429
 				}
430 430
 				$args = array(
431 431
 							'post_id' => $question_id,
432
-							'data' => base64_encode( $answer ),
432
+							'data' => base64_encode($answer),
433 433
 							'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
434 434
 							'user_id' => $user_id,
435 435
 							'action' => 'update'
436 436
 						);
437
-				$answers_saved = Sensei_Utils::sensei_log_activity( $args );
437
+				$answers_saved = Sensei_Utils::sensei_log_activity($args);
438 438
 			}
439 439
 
440 440
 			// Handle file upload questions
441
-			if( isset( $_FILES ) ) {
442
-				foreach( $_FILES as $field => $file ) {
443
-					if( strpos( $field, 'file_upload_' ) !== false ) {
444
-						$question_id = str_replace( 'file_upload_', '', $field );
445
-						if( $file && $question_id ) {
446
-							$attachment_id = self::upload_file( $file );
447
-							if( $attachment_id ) {
441
+			if (isset($_FILES)) {
442
+				foreach ($_FILES as $field => $file) {
443
+					if (strpos($field, 'file_upload_') !== false) {
444
+						$question_id = str_replace('file_upload_', '', $field);
445
+						if ($file && $question_id) {
446
+							$attachment_id = self::upload_file($file);
447
+							if ($attachment_id) {
448 448
 								$args = array(
449 449
 									'post_id' => $question_id,
450
-									'data' => base64_encode( $attachment_id ),
450
+									'data' => base64_encode($attachment_id),
451 451
 									'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
452 452
 									'user_id' => $user_id,
453 453
 									'action' => 'update'
454 454
 								);
455
-								$answers_saved = Sensei_Utils::sensei_log_activity( $args );
455
+								$answers_saved = Sensei_Utils::sensei_log_activity($args);
456 456
 							}
457 457
 						}
458 458
 					}
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 
465 465
 	} // End sensei_save_quiz_answers()
466 466
 
467
-	public static function upload_file( $file = array() ) {
467
+	public static function upload_file($file = array()) {
468 468
 
469
-		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
469
+		require_once(ABSPATH.'wp-admin/includes/admin.php');
470 470
 
471 471
         /**
472 472
          * Filter the data array for the Sensei wp_handle_upload function call
@@ -481,11 +481,11 @@  discard block
 block discarded – undo
481 481
          *     @type string test_form set to false by default
482 482
          * }
483 483
          */
484
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
484
+        $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false));
485 485
 
486
-        $file_return = wp_handle_upload( $file, $file_upload_args );
486
+        $file_return = wp_handle_upload($file, $file_upload_args);
487 487
 
488
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
488
+        if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
489 489
             return false;
490 490
         } else {
491 491
 
@@ -493,19 +493,19 @@  discard block
 block discarded – undo
493 493
 
494 494
             $attachment = array(
495 495
                 'post_mime_type' => $file_return['type'],
496
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
496
+                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
497 497
                 'post_content' => '',
498 498
                 'post_status' => 'inherit',
499 499
                 'guid' => $file_return['url']
500 500
             );
501 501
 
502
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
502
+            $attachment_id = wp_insert_attachment($attachment, $filename);
503 503
 
504
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
505
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
506
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
504
+            require_once(ABSPATH.'wp-admin/includes/image.php');
505
+            $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
506
+            wp_update_attachment_metadata($attachment_id, $attachment_data);
507 507
 
508
-            if( 0 < intval( $attachment_id ) ) {
508
+            if (0 < intval($attachment_id)) {
509 509
             	return $attachment_id;
510 510
             }
511 511
         }
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
      *
532 532
 	 * @return int $quiz_grade total sum of all question grades
533 533
 	 */
534
-	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
534
+	public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') {
535 535
 
536
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
536
+        return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type);
537 537
 
538 538
 	} // End sensei_grade_quiz_auto()
539 539
 
@@ -545,20 +545,20 @@  discard block
 block discarded – undo
545 545
      * @param  string $quiz_grade_type default 'auto'
546 546
 	 * @return boolean
547 547
 	 */
548
-	public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) {
549
-		if( intval( $user_id ) == 0 ) {
548
+	public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') {
549
+		if (intval($user_id) == 0) {
550 550
 			$user_id = get_current_user_id();
551 551
 		}
552 552
 
553 553
 		$activity_logged = false;
554
-		if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) {
555
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
556
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
557
-			$activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade );
554
+		if (intval($quiz_id) > 0 && intval($user_id) > 0) {
555
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
556
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
557
+			$activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade);
558 558
 
559
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
559
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
560 560
 
561
-			do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type );
561
+			do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type);
562 562
 		}
563 563
 
564 564
 		return $activity_logged;
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
      *
579 579
 	 * @return int $question_grade
580 580
 	 */
581
-	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
581
+	public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) {
582 582
 
583
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
583
+       return  WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id);
584 584
 
585 585
 	} // end sensei_grade_question_auto
586 586
 
@@ -591,20 +591,20 @@  discard block
 block discarded – undo
591 591
      * @param int $user_id
592 592
 	 * @return boolean
593 593
 	 */
594
-	public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) {
595
-		if( intval( $user_id ) == 0 ) {
594
+	public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) {
595
+		if (intval($user_id) == 0) {
596 596
 			$user_id = get_current_user_id();
597 597
 		}
598 598
 
599 599
 		$activity_logged = false;
600
-		if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) {
600
+		if (intval($question_id) > 0 && intval($user_id) > 0) {
601 601
 
602
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
603
-			$activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade );
602
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
603
+			$activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade);
604 604
 
605
-			$answer_notes = get_post_meta( $question_id, '_answer_feedback', true );
606
-			if ( !empty($answer_notes) ) {
607
-				update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) );
605
+			$answer_notes = get_post_meta($question_id, '_answer_feedback', true);
606
+			if ( ! empty($answer_notes)) {
607
+				update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes));
608 608
 			}
609 609
 
610 610
 		}
@@ -612,15 +612,15 @@  discard block
 block discarded – undo
612 612
 		return $activity_logged;
613 613
 	}
614 614
 
615
-	public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) {
616
-		if( intval( $user_id ) == 0 ) {
615
+	public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) {
616
+		if (intval($user_id) == 0) {
617 617
 			$user_id = get_current_user_id();
618 618
 		}
619 619
 
620 620
 		$activity_logged = false;
621
-		if( intval( $question_id ) > 0 ) {
622
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
623
-			$activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' );
621
+		if (intval($question_id) > 0) {
622
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
623
+			$activity_logged = delete_comment_meta($user_answer_id, 'user_grade');
624 624
 		}
625 625
 
626 626
 		return $activity_logged;
@@ -638,9 +638,9 @@  discard block
 block discarded – undo
638 638
      *
639 639
      * @return mixed boolean or comment_ID
640 640
      */
641
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
641
+    public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) {
642 642
 
643
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
643
+        return self::sensei_start_lesson($lesson_id, $user_id, $complete);
644 644
 
645 645
     }// end user_start_lesson()
646 646
 
@@ -657,22 +657,22 @@  discard block
 block discarded – undo
657 657
      *
658 658
      * @return mixed boolean or comment_ID
659 659
 	 */
660
-	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
660
+	public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) {
661 661
 
662 662
 
663
-		if( intval( $user_id ) == 0 ) {
663
+		if (intval($user_id) == 0) {
664 664
 			$user_id = get_current_user_id();
665 665
 		}
666 666
 
667 667
 		$activity_logged = false;
668 668
 
669
-		if( intval( $lesson_id ) > 0 ) {
669
+		if (intval($lesson_id) > 0) {
670 670
 
671
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
672
-			if( $course_id ) {
673
-				$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id );
674
-				if( ! $is_user_taking_course ) {
675
-					Sensei_Utils::user_start_course( $user_id, $course_id );
671
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
672
+			if ($course_id) {
673
+				$is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id);
674
+				if ( ! $is_user_taking_course) {
675
+					Sensei_Utils::user_start_course($user_id, $course_id);
676 676
 				}
677 677
 			}
678 678
 
@@ -680,12 +680,12 @@  discard block
 block discarded – undo
680 680
 			$status = 'in-progress';
681 681
 
682 682
 			// Note: When this action runs the lesson status may not yet exist
683
-			do_action( 'sensei_user_lesson_start', $user_id, $lesson_id );
683
+			do_action('sensei_user_lesson_start', $user_id, $lesson_id);
684 684
 
685
-			if( $complete ) {
685
+			if ($complete) {
686 686
 
687
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
688
-				if ( $has_questions ) {
687
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
688
+				if ($has_questions) {
689 689
 					$status = 'passed'; // Force a pass
690 690
 					$metadata['grade'] = 0;
691 691
 				}
@@ -695,31 +695,31 @@  discard block
 block discarded – undo
695 695
 			}
696 696
 
697 697
 			// Check if user is already taking the lesson
698
-			$activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id );
699
-			if( ! $activity_logged ) {
698
+			$activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id);
699
+			if ( ! $activity_logged) {
700 700
 
701 701
 				$metadata['start'] = current_time('mysql');
702
-				$activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
702
+				$activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata);
703 703
 
704 704
             } else {
705 705
 
706 706
                 // if users is already taking the lesson  and the status changes to complete update it
707 707
                 $current_user_activity = get_comment($activity_logged);
708
-                if( $status=='complete' &&
709
-                    $status != $current_user_activity->comment_approved  ){
708
+                if ($status == 'complete' &&
709
+                    $status != $current_user_activity->comment_approved) {
710 710
 
711 711
                     $comment = array();
712 712
                     $comment['comment_ID'] = $activity_logged;
713 713
                     $comment['comment_approved'] = $status;
714
-                    wp_update_comment( $comment );
714
+                    wp_update_comment($comment);
715 715
 
716 716
                 }
717 717
 
718 718
             }
719 719
 
720
-			if ( $complete ) {
720
+			if ($complete) {
721 721
 				// Run this *after* the lesson status has been created/updated
722
-				do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
722
+				do_action('sensei_user_lesson_end', $user_id, $lesson_id);
723 723
 			}
724 724
 
725 725
 		}
@@ -734,20 +734,20 @@  discard block
 block discarded – undo
734 734
 	 * @param int $user_id
735 735
 	 * @return boolean
736 736
 	 */
737
-	public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) {
737
+	public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) {
738 738
 
739 739
 
740
-		if( ! $lesson_id ) return false;
740
+		if ( ! $lesson_id) return false;
741 741
 
742
-		if( intval( $user_id ) == 0 ) {
742
+		if (intval($user_id) == 0) {
743 743
 			$user_id = get_current_user_id();
744 744
 		}
745 745
 
746 746
 		// Process quiz
747
-		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
747
+		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
748 748
 
749 749
 		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
750
-		Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id );
750
+		Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id);
751 751
 
752 752
 		// Delete lesson status
753 753
 		$args = array(
@@ -756,10 +756,10 @@  discard block
 block discarded – undo
756 756
 			'user_id' => $user_id,
757 757
 		);
758 758
 		// This auto deletes the corresponding meta data, such as the quiz grade, and questions asked
759
-		Sensei_Utils::sensei_delete_activities( $args );
759
+		Sensei_Utils::sensei_delete_activities($args);
760 760
 
761
-		if( ! $from_course ) {
762
-			do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
761
+		if ( ! $from_course) {
762
+			do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
763 763
 		}
764 764
 
765 765
 		return true;
@@ -772,19 +772,19 @@  discard block
 block discarded – undo
772 772
 	 * @param int $user_id
773 773
 	 * @return boolean
774 774
 	 */
775
-	public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
775
+	public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) {
776 776
 
777 777
 
778
-		if( ! $course_id ) return false;
778
+		if ( ! $course_id) return false;
779 779
 
780
-		if( intval( $user_id ) == 0 ) {
780
+		if (intval($user_id) == 0) {
781 781
 			$user_id = get_current_user_id();
782 782
 		}
783 783
 
784
-		$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
784
+		$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
785 785
 
786
-		foreach( $lesson_ids as $lesson_id ) {
787
-			Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true );
786
+		foreach ($lesson_ids as $lesson_id) {
787
+			Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true);
788 788
 		}
789 789
 
790 790
 		// Delete course status
@@ -794,36 +794,36 @@  discard block
 block discarded – undo
794 794
 			'user_id' => $user_id,
795 795
 		);
796 796
 
797
-		Sensei_Utils::sensei_delete_activities( $args );
797
+		Sensei_Utils::sensei_delete_activities($args);
798 798
 
799
-		do_action( 'sensei_user_course_reset', $user_id, $course_id );
799
+		do_action('sensei_user_course_reset', $user_id, $course_id);
800 800
 
801 801
 		return true;
802 802
 	}
803 803
 
804
-	public static function sensei_get_quiz_questions( $quiz_id = 0 ) {
804
+	public static function sensei_get_quiz_questions($quiz_id = 0) {
805 805
 
806 806
 
807 807
 		$questions = array();
808 808
 
809
-		if( intval( $quiz_id ) > 0 ) {
810
-			$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
811
-			$questions = Sensei_Utils::array_sort_reorder( $questions );
809
+		if (intval($quiz_id) > 0) {
810
+			$questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
811
+			$questions = Sensei_Utils::array_sort_reorder($questions);
812 812
 		}
813 813
 
814 814
 		return $questions;
815 815
 	}
816 816
 
817
-	public static function sensei_get_quiz_total( $quiz_id = 0 ) {
817
+	public static function sensei_get_quiz_total($quiz_id = 0) {
818 818
 
819 819
 
820 820
 		$quiz_total = 0;
821 821
 
822
-		if( $quiz_id > 0 ) {
823
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
822
+		if ($quiz_id > 0) {
823
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
824 824
 			$question_grade = 0;
825
-			foreach( $questions as $question ) {
826
-				$question_grade = Sensei()->question->get_question_grade( $question->ID );
825
+			foreach ($questions as $question) {
826
+				$question_grade = Sensei()->question->get_question_grade($question->ID);
827 827
 				$quiz_total += $question_grade;
828 828
 			}
829 829
 		}
@@ -838,20 +838,20 @@  discard block
 block discarded – undo
838 838
 	 * @param int $user_id
839 839
 	 * @return string
840 840
 	 */
841
-	public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) {
841
+	public static function sensei_get_user_question_grade($question = 0, $user_id = 0) {
842 842
 		$question_grade = false;
843
-		if( $question ) {
844
-			if ( is_object( $question ) ) {
843
+		if ($question) {
844
+			if (is_object($question)) {
845 845
 				$user_answer_id = $question->comment_ID;
846 846
 			}
847 847
 			else {
848
-				if( intval( $user_id ) == 0 ) {
848
+				if (intval($user_id) == 0) {
849 849
 					$user_id = get_current_user_id();
850 850
 				}
851
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
851
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
852 852
 			}
853
-			if ( $user_answer_id ) {
854
-				$question_grade = get_comment_meta( $user_answer_id, 'user_grade', true );
853
+			if ($user_answer_id) {
854
+				$question_grade = get_comment_meta($user_answer_id, 'user_grade', true);
855 855
 			}
856 856
 		}
857 857
 
@@ -866,52 +866,52 @@  discard block
 block discarded – undo
866 866
 	 * @param int $user_id
867 867
 	 * @return string
868 868
 	 */
869
-	public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) {
869
+	public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) {
870 870
 		$answer_notes = false;
871
-		if( $question ) {
872
-			if ( is_object( $question ) ) {
871
+		if ($question) {
872
+			if (is_object($question)) {
873 873
 				$user_answer_id = $question->comment_ID;
874 874
 			}
875 875
 			else {
876
-				if( intval( $user_id ) == 0 ) {
876
+				if (intval($user_id) == 0) {
877 877
 					$user_id = get_current_user_id();
878 878
 				}
879
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
879
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
880 880
 			}
881
-			if ( $user_answer_id ) {
882
-				$answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) );
881
+			if ($user_answer_id) {
882
+				$answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true));
883 883
 			}
884 884
 		}
885 885
 
886 886
 		return $answer_notes;
887 887
 	}
888 888
 
889
-	public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) {
890
-		if( intval( $user_id ) == 0 ) {
889
+	public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) {
890
+		if (intval($user_id) == 0) {
891 891
 			$user_id = get_current_user_id();
892 892
 		}
893 893
 
894 894
 		$delete_answers = false;
895
-		if( intval( $quiz_id ) > 0 ) {
896
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
897
-			foreach( $questions as $question ) {
898
-				$delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) );
895
+		if (intval($quiz_id) > 0) {
896
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
897
+			foreach ($questions as $question) {
898
+				$delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer'));
899 899
 			}
900 900
 		}
901 901
 
902 902
 		return $delete_answers;
903 903
 	}
904 904
 
905
-	public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) {
906
-		if( intval( $user_id ) == 0 ) {
905
+	public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) {
906
+		if (intval($user_id) == 0) {
907 907
 			$user_id = get_current_user_id();
908 908
 		}
909 909
 
910 910
 		$delete_grade = false;
911
-		if( intval( $quiz_id ) > 0 ) {
912
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
913
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
914
-			$delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' );
911
+		if (intval($quiz_id) > 0) {
912
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
913
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
914
+			$delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade');
915 915
 		}
916 916
 
917 917
 		return $delete_grade;
@@ -924,20 +924,20 @@  discard block
 block discarded – undo
924 924
      * @param string $notes
925 925
 	 * @return boolean
926 926
 	 */
927
-	public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) {
928
-		if( intval( $user_id ) == 0 ) {
927
+	public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') {
928
+		if (intval($user_id) == 0) {
929 929
 			$user_id = get_current_user_id();
930 930
 		}
931 931
 
932 932
 		$activity_logged = false;
933 933
 
934
-		if( intval( $question_id ) > 0 ) {
935
-			$notes = base64_encode( $notes );
934
+		if (intval($question_id) > 0) {
935
+			$notes = base64_encode($notes);
936 936
 
937 937
 			// Don't store empty values, no point
938
-			if ( !empty($notes) ) {
939
-				$user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
940
-				$activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes );
938
+			if ( ! empty($notes)) {
939
+				$user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
940
+				$activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes);
941 941
 			}
942 942
 			else {
943 943
 				$activity_logged = true;
@@ -953,16 +953,16 @@  discard block
 block discarded – undo
953 953
 	 * @param  array $return_array data to be ordered
954 954
 	 * @return array $return_array ordered data
955 955
 	 */
956
-	public static function array_sort_reorder( $return_array ) {
957
-		if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) {
956
+	public static function array_sort_reorder($return_array) {
957
+		if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) {
958 958
 			$sort_key = '';
959 959
 			// if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) {
960 960
 			// 	$sort_key = esc_html( $_GET['orderby'] );
961 961
 			// } // End If Statement
962
-			if ( '' != $sort_key ) {
963
-					Sensei_Utils::sort_array_by_key($return_array,$sort_key);
964
-				if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) {
965
-					$return_array = array_reverse( $return_array, true );
962
+			if ('' != $sort_key) {
963
+					Sensei_Utils::sort_array_by_key($return_array, $sort_key);
964
+				if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) {
965
+					$return_array = array_reverse($return_array, true);
966 966
 				} // End If Statement
967 967
 			} // End If Statement
968 968
 			return $return_array;
@@ -978,15 +978,15 @@  discard block
 block discarded – undo
978 978
 	 * @param  $key string column name in array
979 979
 	 * @return void
980 980
 	 */
981
-	public static function sort_array_by_key( $array, $key ) {
981
+	public static function sort_array_by_key($array, $key) {
982 982
 	    $sorter = array();
983 983
 	    $ret = array();
984
-	    reset( $array );
985
-	    foreach ( $array as $ii => $va ) {
984
+	    reset($array);
985
+	    foreach ($array as $ii => $va) {
986 986
 	        $sorter[$ii] = $va[$key];
987 987
 	    } // End For Loop
988
-	    asort( $sorter );
989
-	    foreach ( $sorter as $ii => $va ) {
988
+	    asort($sorter);
989
+	    foreach ($sorter as $ii => $va) {
990 990
 	        $ret[$ii] = $array[$ii];
991 991
 	    } // End For Loop
992 992
 	    $array = $ret;
@@ -998,10 +998,10 @@  discard block
 block discarded – undo
998 998
 	 * @param  integer $quiz_id
999 999
 	 * @return array of quiz questions
1000 1000
 	 */
1001
-	public static function lesson_quiz_questions( $quiz_id = 0 ) {
1001
+	public static function lesson_quiz_questions($quiz_id = 0) {
1002 1002
 		$questions_array = array();
1003
-		if ( 0 < $quiz_id ) {
1004
-			$question_args = array( 'post_type'         => 'question',
1003
+		if (0 < $quiz_id) {
1004
+			$question_args = array('post_type'         => 'question',
1005 1005
                                     'posts_per_page'       => -1,
1006 1006
                                     'orderby'           => 'ID',
1007 1007
                                     'order'             => 'ASC',
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
                                     'post_status'       => 'any',
1015 1015
                                     'suppress_filters'  => 0
1016 1016
                                 );
1017
-            $questions_array = get_posts( $question_args );
1017
+            $questions_array = get_posts($question_args);
1018 1018
         } // End If Statement
1019 1019
         return $questions_array;
1020 1020
 	} // End lesson_quiz_questions()
@@ -1024,25 +1024,25 @@  discard block
 block discarded – undo
1024 1024
 	 * @param  integer $course_id ID of course
1025 1025
 	 * @return integer            Pass mark for course
1026 1026
 	 */
1027
-	public static function sensei_course_pass_grade( $course_id = 0 ) {
1027
+	public static function sensei_course_pass_grade($course_id = 0) {
1028 1028
 
1029 1029
 
1030 1030
 		$course_passmark = 0;
1031 1031
 
1032
-		if( $course_id > 0 ) {
1033
-			$lessons = Sensei()->course->course_lessons( $course_id );
1032
+		if ($course_id > 0) {
1033
+			$lessons = Sensei()->course->course_lessons($course_id);
1034 1034
 			$lesson_count = 0;
1035 1035
 			$total_passmark = 0;
1036
-			foreach( $lessons as $lesson ) {
1036
+			foreach ($lessons as $lesson) {
1037 1037
 
1038 1038
 				// Get Quiz ID
1039
-				$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
1039
+				$quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
1040 1040
 
1041 1041
 				// Check for a pass being required
1042
-				$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1043
-				if ( $pass_required ) {
1042
+				$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1043
+				if ($pass_required) {
1044 1044
 					// Get quiz passmark
1045
-					$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1045
+					$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1046 1046
 
1047 1047
 					// Add up total passmark
1048 1048
 					$total_passmark += $quiz_passmark;
@@ -1051,12 +1051,12 @@  discard block
 block discarded – undo
1051 1051
 				}
1052 1052
 			}
1053 1053
 			// Might be a case of no required lessons
1054
-			if ( $lesson_count ) {
1055
-				$course_passmark = ( $total_passmark / $lesson_count );
1054
+			if ($lesson_count) {
1055
+				$course_passmark = ($total_passmark / $lesson_count);
1056 1056
 			}
1057 1057
 		}
1058 1058
 
1059
-		return Sensei_Utils::round( $course_passmark );
1059
+		return Sensei_Utils::round($course_passmark);
1060 1060
 	}
1061 1061
 
1062 1062
 	/**
@@ -1065,27 +1065,27 @@  discard block
 block discarded – undo
1065 1065
 	 * @param  integer $user_id   ID of user
1066 1066
 	 * @return integer            User's total grade
1067 1067
 	 */
1068
-	public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) {
1068
+	public static function sensei_course_user_grade($course_id = 0, $user_id = 0) {
1069 1069
 
1070 1070
 
1071
-		if( intval( $user_id ) == 0 ) {
1071
+		if (intval($user_id) == 0) {
1072 1072
 			$user_id = get_current_user_id();
1073 1073
 		}
1074 1074
 
1075 1075
 		$total_grade = 0;
1076 1076
 
1077
-		if( $course_id > 0 && $user_id > 0 ) {
1078
-			$lessons = Sensei()->course->course_lessons( $course_id );
1077
+		if ($course_id > 0 && $user_id > 0) {
1078
+			$lessons = Sensei()->course->course_lessons($course_id);
1079 1079
 			$lesson_count = 0;
1080 1080
 			$total_grade = 0;
1081
-			foreach( $lessons as $lesson ) {
1081
+			foreach ($lessons as $lesson) {
1082 1082
 
1083 1083
 				// Check for lesson having questions, thus a quiz, thus having a grade
1084
-				$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
1085
-				if ( $has_questions ) {
1086
-					$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id );
1084
+				$has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true);
1085
+				if ($has_questions) {
1086
+					$user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id);
1087 1087
 					// Get user quiz grade
1088
-					$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1088
+					$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1089 1089
 
1090 1090
 					// Add up total grade
1091 1091
 					$total_grade += $quiz_grade;
@@ -1095,13 +1095,13 @@  discard block
 block discarded – undo
1095 1095
 			}
1096 1096
 
1097 1097
 			// Might be a case of no lessons with quizzes
1098
-			if ( $lesson_count ) {
1099
-				$total_grade = ( $total_grade / $lesson_count );
1098
+			if ($lesson_count) {
1099
+				$total_grade = ($total_grade / $lesson_count);
1100 1100
 			}
1101 1101
 
1102 1102
 		}
1103 1103
 
1104
-		return Sensei_Utils::round( $total_grade );
1104
+		return Sensei_Utils::round($total_grade);
1105 1105
 	}
1106 1106
 
1107 1107
 	/**
@@ -1110,18 +1110,18 @@  discard block
 block discarded – undo
1110 1110
 	 * @param  integer $user_id   ID of user
1111 1111
 	 * @return boolean
1112 1112
 	 */
1113
-	public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) {
1114
-		if( intval( $user_id ) == 0 ) {
1113
+	public static function sensei_user_passed_course($course_id = 0, $user_id = 0) {
1114
+		if (intval($user_id) == 0) {
1115 1115
 			$user_id = get_current_user_id();
1116 1116
 		}
1117 1117
 
1118 1118
 		$pass = false;
1119 1119
 
1120
-		if( $course_id > 0 && $user_id > 0 ) {
1121
-			$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id );
1122
-			$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id );
1120
+		if ($course_id > 0 && $user_id > 0) {
1121
+			$passmark = Sensei_Utils::sensei_course_pass_grade($course_id);
1122
+			$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id);
1123 1123
 
1124
-			if( $user_grade >= $passmark ) {
1124
+			if ($user_grade >= $passmark) {
1125 1125
 				$pass = true;
1126 1126
 			}
1127 1127
 		}
@@ -1136,38 +1136,38 @@  discard block
 block discarded – undo
1136 1136
 	 * @param  integer $user_id   ID of user
1137 1137
 	 * @return array              Status code and message
1138 1138
 	 */
1139
-	public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) {
1140
-		if( intval( $user_id ) == 0 ) {
1139
+	public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) {
1140
+		if (intval($user_id) == 0) {
1141 1141
 			$user_id = get_current_user_id();
1142 1142
 		}
1143 1143
 
1144 1144
 		$status = 'not_started';
1145 1145
 		$box_class = 'info';
1146
-		$message = __( 'You have not started this course yet.', 'woothemes-sensei' );
1146
+		$message = __('You have not started this course yet.', 'woothemes-sensei');
1147 1147
 
1148
-		if( $course_id > 0 && $user_id > 0 ) {
1148
+		if ($course_id > 0 && $user_id > 0) {
1149 1149
 
1150
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1150
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1151 1151
 
1152
-			if( $started_course ) {
1153
-				$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()!
1154
-				$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()!
1155
-				if( $user_grade >= $passmark ) {
1152
+			if ($started_course) {
1153
+				$passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()!
1154
+				$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()!
1155
+				if ($user_grade >= $passmark) {
1156 1156
 					$status = 'passed';
1157 1157
 					$box_class = 'tick';
1158
-					$message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade );
1158
+					$message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade);
1159 1159
 				} else {
1160 1160
 					$status = 'failed';
1161 1161
 					$box_class = 'alert';
1162
-					$message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade );
1162
+					$message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade);
1163 1163
 				}
1164 1164
 			}
1165 1165
 
1166 1166
 		}
1167 1167
 
1168
-		$message = apply_filters( 'sensei_user_course_status_' . $status, $message );
1168
+		$message = apply_filters('sensei_user_course_status_'.$status, $message);
1169 1169
 
1170
-		return array( 'status' => $status, 'box_class' => $box_class, 'message' => $message );
1170
+		return array('status' => $status, 'box_class' => $box_class, 'message' => $message);
1171 1171
 	}
1172 1172
 
1173 1173
 	/**
@@ -1177,94 +1177,94 @@  discard block
 block discarded – undo
1177 1177
      * @param  bool $is_lesson
1178 1178
 	 * @return array              Status code and message
1179 1179
 	 */
1180
-	public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
1180
+	public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) {
1181 1181
 		global  $current_user;
1182
-		if( intval( $user_id ) == 0 ) {
1182
+		if (intval($user_id) == 0) {
1183 1183
 			$user_id = $current_user->ID;
1184 1184
 		}
1185 1185
 
1186 1186
 		$status = 'not_started';
1187 1187
 		$box_class = 'info';
1188
-		$message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' );
1188
+		$message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei');
1189 1189
 		$extra = '';
1190 1190
 
1191
-		if( $lesson_id > 0 && $user_id > 0 ) {
1191
+		if ($lesson_id > 0 && $user_id > 0) {
1192 1192
 
1193 1193
 			// Prerequisite lesson
1194
-			$prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1194
+			$prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true);
1195 1195
 
1196 1196
 			// Course ID
1197
-			$course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) );
1197
+			$course_id = absint(get_post_meta($lesson_id, '_lesson_course', true));
1198 1198
 
1199 1199
 			// Has user started course
1200
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1200
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1201 1201
 
1202 1202
 			// Has user completed lesson
1203
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1204
-			$lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status );
1203
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1204
+			$lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status);
1205 1205
 
1206 1206
 			// Quiz ID
1207
-			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1207
+			$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1208 1208
 
1209 1209
 			// Quiz grade
1210 1210
 			$quiz_grade = 0;
1211
-			if ( $user_lesson_status ) {
1212
-				$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1211
+			if ($user_lesson_status) {
1212
+				$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1213 1213
 			}
1214 1214
 
1215 1215
 			// Quiz passmark
1216
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1216
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1217 1217
 			$quiz_passmark_float = (float) $quiz_passmark;
1218 1218
 
1219 1219
 			// Pass required
1220
-			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1220
+			$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1221 1221
 
1222 1222
 			// Quiz questions
1223
-			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1223
+			$has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1224 1224
 
1225
-			if ( ! $started_course ) {
1225
+			if ( ! $started_course) {
1226 1226
 
1227 1227
 				$status = 'not_started_course';
1228 1228
 				$box_class = 'info';
1229
-				$message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' );
1229
+				$message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>');
1230 1230
 
1231
-			} elseif ( ! is_user_logged_in() ) {
1231
+			} elseif ( ! is_user_logged_in()) {
1232 1232
 
1233 1233
 				$status = 'login_required';
1234 1234
 				$box_class = 'info';
1235
-				$message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' );
1235
+				$message = __('You must be logged in to take this quiz', 'woothemes-sensei');
1236 1236
 
1237 1237
 			}
1238 1238
 			// Lesson/Quiz is marked as complete thus passing any quiz restrictions
1239
-			elseif ( $lesson_complete ) {
1239
+			elseif ($lesson_complete) {
1240 1240
 
1241 1241
 				$status = 'passed';
1242 1242
 				$box_class = 'tick';
1243 1243
 				// Lesson status will be "complete" (has no Quiz)
1244
-				if ( ! $has_quiz_questions ) {
1245
-					$message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) );
1244
+				if ( ! $has_quiz_questions) {
1245
+					$message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei'));
1246 1246
 				}
1247 1247
 				// Lesson status will be "graded" (no passmark required so might have failed all the questions)
1248
-				elseif ( empty( $quiz_grade ) ) {
1249
-					$message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) );
1248
+				elseif (empty($quiz_grade)) {
1249
+					$message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei'));
1250 1250
 				}
1251 1251
 				// Lesson status will be "passed" (passmark reached)
1252
-				elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) {
1253
-					if( $is_lesson ) {
1254
-						$message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) );
1252
+				elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) {
1253
+					if ($is_lesson) {
1254
+						$message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1255 1255
 					} else {
1256
-						$message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_grade ) );
1256
+						$message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1257 1257
 					}
1258 1258
 				}
1259 1259
 
1260 1260
                 // add next lesson button
1261
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1262
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1261
+                $nav_id_array = sensei_get_prev_next_lessons($lesson_id);
1262
+                $next_lesson_id = absint($nav_id_array['next_lesson']);
1263 1263
 
1264 1264
                 // Output HTML
1265
-                if ( ( 0 < $next_lesson_id ) ) {
1266
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1267
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1265
+                if ((0 < $next_lesson_id)) {
1266
+                    $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id))
1267
+                                . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei')
1268 1268
                                 .'</a>';
1269 1269
 
1270 1270
                 }
@@ -1273,33 +1273,33 @@  discard block
 block discarded – undo
1273 1273
             // Lesson/Quiz not complete
1274 1274
 			else {
1275 1275
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1276
-				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
1276
+				if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) {
1277 1277
 					$status = 'complete';
1278 1278
 					$box_class = 'info';
1279
-					if( $is_lesson ) {
1280
-						$message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' );
1279
+					if ($is_lesson) {
1280
+						$message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>');
1281 1281
 					} else {
1282
-						$message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1282
+						$message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1283 1283
 					}
1284 1284
 				}
1285 1285
 				// Lesson status must be "failed"
1286
-				elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) {
1286
+				elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
1287 1287
 					$status = 'failed';
1288 1288
 					$box_class = 'alert';
1289
-					if( $is_lesson ) {
1290
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1289
+					if ($is_lesson) {
1290
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1291 1291
 					} else {
1292
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1292
+						$message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1293 1293
 					}
1294 1294
 				}
1295 1295
 				// Lesson/Quiz requires a pass
1296
-				elseif( $pass_required ) {
1296
+				elseif ($pass_required) {
1297 1297
 					$status = 'not_started';
1298 1298
 					$box_class = 'info';
1299
-					if( $is_lesson ) {
1300
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1299
+					if ($is_lesson) {
1300
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1301 1301
 					} else {
1302
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1302
+						$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1303 1303
 					}
1304 1304
 				}
1305 1305
 			}
@@ -1307,15 +1307,15 @@  discard block
 block discarded – undo
1307 1307
 		}
1308 1308
 
1309 1309
 		// Legacy filter
1310
-		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1310
+		$message = apply_filters('sensei_user_quiz_status_'.$status, $message);
1311 1311
 
1312
-		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1313
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1314
-			$extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' .  __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' .  __( 'View the lesson quiz', 'woothemes-sensei' )  . '</a></p>';
1312
+		if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) {
1313
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1314
+			$extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>';
1315 1315
 		}
1316 1316
 
1317 1317
 		// Filter of all messages
1318
-		return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson );
1318
+		return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson);
1319 1319
 	}
1320 1320
 
1321 1321
 	/**
@@ -1325,14 +1325,14 @@  discard block
 block discarded – undo
1325 1325
 	 * @param  integer $course_id Course ID
1326 1326
 	 * @return mixed boolean or comment_ID
1327 1327
 	 */
1328
-	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1328
+	public static function user_start_course($user_id = 0, $course_id = 0) {
1329 1329
 
1330 1330
 		$activity_logged = false;
1331 1331
 
1332
-		if( $user_id && $course_id ) {
1332
+		if ($user_id && $course_id) {
1333 1333
 			// Check if user is already on the Course
1334
-			$activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id );
1335
-			if ( ! $activity_logged ) {
1334
+			$activity_logged = Sensei_Utils::user_started_course($course_id, $user_id);
1335
+			if ( ! $activity_logged) {
1336 1336
 
1337 1337
 				// Add user to course
1338 1338
 				$course_metadata = array(
@@ -1341,11 +1341,11 @@  discard block
 block discarded – undo
1341 1341
 					'complete' => 0,
1342 1342
 				);
1343 1343
 
1344
-				$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata );
1344
+				$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata);
1345 1345
 
1346 1346
 				// Allow further actions
1347
-				if ( $activity_logged ) {
1348
-					do_action( 'sensei_user_course_start', $user_id, $course_id );
1347
+				if ($activity_logged) {
1348
+					do_action('sensei_user_course_start', $user_id, $course_id);
1349 1349
 				}
1350 1350
 			}
1351 1351
 		}
@@ -1361,19 +1361,19 @@  discard block
 block discarded – undo
1361 1361
 	 * @param int $user_id
1362 1362
 	 * @return mixed false or comment_ID
1363 1363
 	 */
1364
-	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1364
+	public static function user_started_course($course_id = 0, $user_id = 0) {
1365 1365
 
1366
-		if( $course_id ) {
1367
-			if( ! $user_id ) {
1366
+		if ($course_id) {
1367
+			if ( ! $user_id) {
1368 1368
 				$user_id = get_current_user_id();
1369 1369
 			}
1370 1370
 
1371
-            if( ! $user_id > 0 ){
1371
+            if ( ! $user_id > 0) {
1372 1372
                 return false;
1373 1373
             }
1374 1374
 
1375
-			$user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) );
1376
-			if( $user_course_status_id ) {
1375
+			$user_course_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID'));
1376
+			if ($user_course_status_id) {
1377 1377
 				return $user_course_status_id;
1378 1378
 			}
1379 1379
 		}
@@ -1388,17 +1388,17 @@  discard block
 block discarded – undo
1388 1388
 	 * @param  integer $user_id   User ID
1389 1389
 	 * @return int
1390 1390
 	 */
1391
-	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1391
+	public static function user_complete_course($course_id = 0, $user_id = 0) {
1392 1392
 		global  $wp_version;
1393 1393
 
1394
-		if( $course_id ) {
1395
-			if( ! $user_id ) {
1394
+		if ($course_id) {
1395
+			if ( ! $user_id) {
1396 1396
 				$user_id = get_current_user_id();
1397 1397
 			}
1398 1398
 
1399 1399
 			$course_status = 'in-progress';
1400 1400
 			$course_metadata = array();
1401
-			$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1401
+			$course_completion = Sensei()->settings->settings['course_completion'];
1402 1402
 			$lessons_completed = $total_lessons = 0;
1403 1403
 			$lesson_status_args = array(
1404 1404
 					'user_id' => $user_id,
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
 				);
1408 1408
 
1409 1409
 			// Grab all of this Courses' lessons, looping through each...
1410
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
1411
-			$total_lessons = count( $lesson_ids );
1410
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
1411
+			$total_lessons = count($lesson_ids);
1412 1412
 				// ...if course completion not set to 'passed', and all lessons are complete or graded,
1413 1413
 				// ......then all lessons are 'passed'
1414 1414
 				// ...else if course completion is set to 'passed', check if each lesson has questions...
@@ -1421,29 +1421,29 @@  discard block
 block discarded – undo
1421 1421
 			// The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson()
1422 1422
 			$all_lesson_statuses = array();
1423 1423
 			// In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs
1424
-			if ( version_compare($wp_version, '4.1', '>=') ) {
1424
+			if (version_compare($wp_version, '4.1', '>=')) {
1425 1425
 				$lesson_status_args['post__in'] = $lesson_ids;
1426
-				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1426
+				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1427 1427
 				// Need to always return an array, even with only 1 item
1428
-				if ( !is_array($all_lesson_statuses) ) {
1429
-					$all_lesson_statuses = array( $all_lesson_statuses );
1428
+				if ( ! is_array($all_lesson_statuses)) {
1429
+					$all_lesson_statuses = array($all_lesson_statuses);
1430 1430
 				}
1431 1431
 			}
1432 1432
 			// ...otherwise check each one
1433 1433
 			else {
1434
-				foreach( $lesson_ids as $lesson_id ) {
1434
+				foreach ($lesson_ids as $lesson_id) {
1435 1435
 					$lesson_status_args['post_id'] = $lesson_id;
1436
-					$each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1436
+					$each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1437 1437
 					// Check for valid return before using
1438
-					if ( !empty($each_lesson_status->comment_approved) ) {
1438
+					if ( ! empty($each_lesson_status->comment_approved)) {
1439 1439
 						$all_lesson_statuses[] = $each_lesson_status;
1440 1440
 					}
1441 1441
 				}
1442 1442
 			}
1443
-			foreach( $all_lesson_statuses as $lesson_status ) {
1443
+			foreach ($all_lesson_statuses as $lesson_status) {
1444 1444
 				// If lessons are complete without needing quizzes to be passed
1445
-				if ( 'passed' != $course_completion ) {
1446
-					switch ( $lesson_status->comment_approved ) {
1445
+				if ('passed' != $course_completion) {
1446
+					switch ($lesson_status->comment_approved) {
1447 1447
 						// A user cannot 'complete' a course if a lesson...
1448 1448
 						case 'in-progress': // ...is still in progress
1449 1449
 						case 'ungraded': // ...hasn't yet been graded
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
 					}
1456 1456
 				}
1457 1457
 				else {
1458
-					switch ( $lesson_status->comment_approved ) {
1458
+					switch ($lesson_status->comment_approved) {
1459 1459
 						case 'complete': // Lesson has no quiz/questions
1460 1460
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
1461 1461
 						case 'passed': // Lesson has quiz and the user passed
@@ -1469,20 +1469,20 @@  discard block
 block discarded – undo
1469 1469
 					}
1470 1470
 				}
1471 1471
 			} // Each lesson
1472
-			if ( $lessons_completed == $total_lessons ) {
1472
+			if ($lessons_completed == $total_lessons) {
1473 1473
 				$course_status = 'complete';
1474 1474
 			}
1475 1475
 
1476 1476
 			// Update meta data on how many lessons have been completed
1477 1477
 			$course_metadata['complete'] = $lessons_completed;
1478 1478
 			// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1479
-			$course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1479
+			$course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1480 1480
 
1481
-			$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata );
1481
+			$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata);
1482 1482
 
1483 1483
 			// Allow further actions
1484
-			if ( 'complete' == $course_status ) {
1485
-				do_action( 'sensei_user_course_end', $user_id, $course_id );
1484
+			if ('complete' == $course_status) {
1485
+				do_action('sensei_user_course_end', $user_id, $course_id);
1486 1486
 			}
1487 1487
 			return $activity_logged;
1488 1488
 		}
@@ -1498,31 +1498,31 @@  discard block
 block discarded – undo
1498 1498
 	 * @param int $user_id
1499 1499
 	 * @return boolean
1500 1500
 	 */
1501
-	public static function user_completed_course( $course , $user_id = 0 ) {
1501
+	public static function user_completed_course($course, $user_id = 0) {
1502 1502
 
1503
-		if( $course ) {
1504
-			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1503
+		if ($course) {
1504
+			if (is_object($course) && is_a($course, 'WP_Comment')) {
1505 1505
 				$user_course_status = $course->comment_approved;
1506 1506
 			}
1507
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1507
+			elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) {
1508 1508
 				$user_course_status = $course;
1509 1509
 			}
1510 1510
 			else {
1511
-				if( ! $user_id ) {
1511
+				if ( ! $user_id) {
1512 1512
 					$user_id = get_current_user_id();
1513 1513
 				}
1514 1514
 
1515
-                if( is_a( $course, 'WP_Post' ) ){
1516
-                    $course =   $course->ID;
1515
+                if (is_a($course, 'WP_Post')) {
1516
+                    $course = $course->ID;
1517 1517
                 }
1518 1518
 
1519
-				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1520
-				if( isset( $user_course_status->comment_approved ) ){
1519
+				$user_course_status = Sensei_Utils::user_course_status($course, $user_id);
1520
+				if (isset($user_course_status->comment_approved)) {
1521 1521
                     $user_course_status = $user_course_status->comment_approved;
1522 1522
                 }
1523 1523
 
1524 1524
 			}
1525
-			if( $user_course_status && 'complete' == $user_course_status ) {
1525
+			if ($user_course_status && 'complete' == $user_course_status) {
1526 1526
 				return true;
1527 1527
 			}
1528 1528
 		}
@@ -1537,10 +1537,10 @@  discard block
 block discarded – undo
1537 1537
 	 * @param int $user_id
1538 1538
 	 * @return mixed false or comment_ID
1539 1539
 	 */
1540
-	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1540
+	public static function user_started_lesson($lesson_id = 0, $user_id = 0) {
1541 1541
 
1542
-		if( $lesson_id ) {
1543
-			if( ! $user_id ) {
1542
+		if ($lesson_id) {
1543
+			if ( ! $user_id) {
1544 1544
 				$user_id = get_current_user_id();
1545 1545
 			}
1546 1546
 
@@ -1550,8 +1550,8 @@  discard block
 block discarded – undo
1550 1550
                 'type' => 'sensei_lesson_status',
1551 1551
                 'field' => 'comment_ID' );
1552 1552
 
1553
-			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1554
-			if( $user_lesson_status_id ) {
1553
+			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1554
+			if ($user_lesson_status_id) {
1555 1555
 				return $user_lesson_status_id;
1556 1556
 			}
1557 1557
 		}
@@ -1566,29 +1566,29 @@  discard block
 block discarded – undo
1566 1566
 	 * @param int $user_id
1567 1567
 	 * @return boolean
1568 1568
 	 */
1569
-	public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) {
1569
+	public static function user_completed_lesson($lesson = 0, $user_id = 0) {
1570 1570
 
1571
-		if( $lesson ) {
1571
+		if ($lesson) {
1572 1572
 			$lesson_id = 0;
1573
-			if ( is_object( $lesson ) ) {
1573
+			if (is_object($lesson)) {
1574 1574
 				$user_lesson_status = $lesson->comment_approved;
1575 1575
 				$lesson_id = $lesson->comment_post_ID;
1576 1576
 			}
1577
-			elseif ( ! is_numeric( $lesson ) ) {
1577
+			elseif ( ! is_numeric($lesson)) {
1578 1578
 				$user_lesson_status = $lesson;
1579 1579
 			}
1580 1580
 			else {
1581
-				if( ! $user_id ) {
1581
+				if ( ! $user_id) {
1582 1582
 					$user_id = get_current_user_id();
1583 1583
 				}
1584 1584
 
1585 1585
                 // the user is not logged in
1586
-                if( ! $user_id > 0 ){
1586
+                if ( ! $user_id > 0) {
1587 1587
                     return false;
1588 1588
                 }
1589
-				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1589
+				$_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id);
1590 1590
 
1591
-				if ( $_user_lesson_status ) {
1591
+				if ($_user_lesson_status) {
1592 1592
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1593 1593
 				}
1594 1594
 				else {
@@ -1596,12 +1596,12 @@  discard block
 block discarded – undo
1596 1596
 				}
1597 1597
 				$lesson_id = $lesson;
1598 1598
 			}
1599
-			if ( 'in-progress' != $user_lesson_status ) {
1599
+			if ('in-progress' != $user_lesson_status) {
1600 1600
 				// Check for Passed or Completed Setting
1601 1601
 				// Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting
1602 1602
 //				$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1603 1603
 //				if ( 'passed' == $course_completion ) {
1604
-					switch( $user_lesson_status ) {
1604
+					switch ($user_lesson_status) {
1605 1605
 						case 'complete':
1606 1606
 						case 'graded':
1607 1607
 						case 'passed':
@@ -1610,13 +1610,13 @@  discard block
 block discarded – undo
1610 1610
 
1611 1611
 						case 'failed':
1612 1612
 							// This may be 'completed' depending on...
1613
-							if ( $lesson_id ) {
1613
+							if ($lesson_id) {
1614 1614
 								// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson
1615
-								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1616
-								if ( $lesson_quiz_id ) {
1615
+								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1616
+								if ($lesson_quiz_id) {
1617 1617
 									// ...the quiz pass setting
1618
-									$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
1619
-									if ( empty($pass_required) ) {
1618
+									$pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true);
1619
+									if (empty($pass_required)) {
1620 1620
 										// We just require the user to have done the quiz, not to have passed
1621 1621
 										return true;
1622 1622
 									}
@@ -1639,15 +1639,15 @@  discard block
 block discarded – undo
1639 1639
 	 * @param int $user_id
1640 1640
 	 * @return object
1641 1641
 	 */
1642
-	public static function user_course_status( $course_id = 0, $user_id = 0 ) {
1642
+	public static function user_course_status($course_id = 0, $user_id = 0) {
1643 1643
 
1644 1644
 
1645
-		if( $course_id ) {
1646
-			if( ! $user_id ) {
1645
+		if ($course_id) {
1646
+			if ( ! $user_id) {
1647 1647
 				$user_id = get_current_user_id();
1648 1648
 			}
1649 1649
 
1650
-			$user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true );
1650
+			$user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true);
1651 1651
 			return $user_course_status;
1652 1652
 		}
1653 1653
 
@@ -1662,27 +1662,27 @@  discard block
 block discarded – undo
1662 1662
 	 * @param int $user_id
1663 1663
 	 * @return object | bool
1664 1664
 	 */
1665
-	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1665
+	public static function user_lesson_status($lesson_id = 0, $user_id = 0) {
1666 1666
 
1667
-        if( ! $user_id ) {
1667
+        if ( ! $user_id) {
1668 1668
             $user_id = get_current_user_id();
1669 1669
         }
1670 1670
 
1671
-		if( $lesson_id > 0 && $user_id > 0 ) {
1671
+		if ($lesson_id > 0 && $user_id > 0) {
1672 1672
 
1673
-			$user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true );
1673
+			$user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true);
1674 1674
 			return $user_lesson_status;
1675 1675
 		}
1676 1676
 
1677 1677
 		return false;
1678 1678
 	}
1679 1679
 
1680
-	public static function is_preview_lesson( $lesson_id ) {
1680
+	public static function is_preview_lesson($lesson_id) {
1681 1681
 		$is_preview = false;
1682 1682
 
1683
-		if( 'lesson' == get_post_type( $lesson_id ) ) {
1684
-			$lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true );
1685
-			if ( isset( $lesson_preview ) && '' != $lesson_preview ) {
1683
+		if ('lesson' == get_post_type($lesson_id)) {
1684
+			$lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true);
1685
+			if (isset($lesson_preview) && '' != $lesson_preview) {
1686 1686
 				$is_preview = true;
1687 1687
 			}
1688 1688
 		}
@@ -1690,22 +1690,22 @@  discard block
 block discarded – undo
1690 1690
 		return $is_preview;
1691 1691
 	}
1692 1692
 
1693
-	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1693
+	public static function user_passed_quiz($quiz_id = 0, $user_id = 0) {
1694 1694
 
1695
-		if( ! $quiz_id  ) return false;
1695
+		if ( ! $quiz_id) return false;
1696 1696
 
1697
-		if( ! $user_id ) {
1697
+		if ( ! $user_id) {
1698 1698
 			$user_id = get_current_user_id();
1699 1699
 		}
1700
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1700
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1701 1701
 
1702 1702
 		// Quiz Grade
1703
-		$lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1704
-		$quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
1703
+		$lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1704
+		$quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
1705 1705
 
1706 1706
 		// Check if Grade is greater than or equal to pass percentage
1707
-		$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
1708
-		if ( $quiz_passmark <= intval( $quiz_grade ) ) {
1707
+		$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
1708
+		if ($quiz_passmark <= intval($quiz_grade)) {
1709 1709
 			return true;
1710 1710
 		}
1711 1711
 
@@ -1725,9 +1725,9 @@  discard block
 block discarded – undo
1725 1725
      *
1726 1726
 	 * @return mixed false or comment_ID
1727 1727
 	 */
1728
-	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1728
+	public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) {
1729 1729
 		$comment_id = false;
1730
-		if ( !empty($status) ) {
1730
+		if ( ! empty($status)) {
1731 1731
 			$args = array(
1732 1732
 					'user_id'   => $user_id,
1733 1733
 					'post_id'   => $lesson_id,
@@ -1736,18 +1736,18 @@  discard block
 block discarded – undo
1736 1736
 					'action'    => 'update', // Update the existing status...
1737 1737
 					'keep_time' => true, // ...but don't change the existing timestamp
1738 1738
 				);
1739
-			if( 'in-progress' == $status ) {
1740
-				unset( $args['keep_time'] ); // Keep updating what's happened
1739
+			if ('in-progress' == $status) {
1740
+				unset($args['keep_time']); // Keep updating what's happened
1741 1741
 			}
1742 1742
 
1743
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1744
-			if ( $comment_id && !empty($metadata) ) {
1745
-				foreach( $metadata as $key => $value ) {
1746
-					update_comment_meta( $comment_id, $key, $value );
1743
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1744
+			if ($comment_id && ! empty($metadata)) {
1745
+				foreach ($metadata as $key => $value) {
1746
+					update_comment_meta($comment_id, $key, $value);
1747 1747
 				}
1748 1748
 			}
1749 1749
 
1750
-			do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id );
1750
+			do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id);
1751 1751
 		}
1752 1752
 		return $comment_id;
1753 1753
 	}
@@ -1763,9 +1763,9 @@  discard block
 block discarded – undo
1763 1763
 	 * @param array $metadata
1764 1764
 	 * @return mixed false or comment_ID
1765 1765
 	 */
1766
-	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1766
+	public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) {
1767 1767
 		$comment_id = false;
1768
-		if ( !empty($status) ) {
1768
+		if ( ! empty($status)) {
1769 1769
 			$args = array(
1770 1770
 					'user_id'   => $user_id,
1771 1771
 					'post_id'   => $course_id,
@@ -1774,17 +1774,17 @@  discard block
 block discarded – undo
1774 1774
 					'action'    => 'update', // Update the existing status...
1775 1775
 					'keep_time' => true, // ...but don't change the existing timestamp
1776 1776
 				);
1777
-			if( 'in-progress' == $status ) {
1778
-				unset( $args['keep_time'] ); // Keep updating what's happened
1777
+			if ('in-progress' == $status) {
1778
+				unset($args['keep_time']); // Keep updating what's happened
1779 1779
 			}
1780 1780
 
1781
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1782
-			if ( $comment_id && !empty($metadata) ) {
1783
-				foreach( $metadata as $key => $value ) {
1784
-					update_comment_meta( $comment_id, $key, $value );
1781
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1782
+			if ($comment_id && ! empty($metadata)) {
1783
+				foreach ($metadata as $key => $value) {
1784
+					update_comment_meta($comment_id, $key, $value);
1785 1785
 				}
1786 1786
 			}
1787
-			do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id );
1787
+			do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id);
1788 1788
 		}
1789 1789
 		return $comment_id;
1790 1790
 	}
@@ -1796,9 +1796,9 @@  discard block
 block discarded – undo
1796 1796
 	 * @param  array $pieces (default: array())
1797 1797
 	 * @return array
1798 1798
 	 */
1799
-	public static function single_comment_filter( $pieces ) {
1800
-		unset( $pieces['orderby'] );
1801
-		unset( $pieces['order'] );
1799
+	public static function single_comment_filter($pieces) {
1800
+		unset($pieces['orderby']);
1801
+		unset($pieces['order']);
1802 1802
 
1803 1803
 		return $pieces;
1804 1804
 	}
@@ -1810,9 +1810,9 @@  discard block
 block discarded – undo
1810 1810
 	 * @param  array $pieces (default: array())
1811 1811
 	 * @return array
1812 1812
 	 */
1813
-	public static function comment_any_status_filter( $pieces ) {
1813
+	public static function comment_any_status_filter($pieces) {
1814 1814
 
1815
-		$pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] );
1815
+		$pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']);
1816 1816
 
1817 1817
 		return $pieces;
1818 1818
 	}
@@ -1824,12 +1824,12 @@  discard block
 block discarded – undo
1824 1824
 	 * @param  array $pieces (default: array())
1825 1825
 	 * @return array
1826 1826
 	 */
1827
-	public static function comment_multiple_status_filter( $pieces ) {
1827
+	public static function comment_multiple_status_filter($pieces) {
1828 1828
 
1829
-		preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder );
1830
-		if ( !empty($placeholder[1]) ) {
1831
-			$statuses = explode( ',', $placeholder[1] );
1832
-			$pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] );
1829
+		preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder);
1830
+		if ( ! empty($placeholder[1])) {
1831
+			$statuses = explode(',', $placeholder[1]);
1832
+			$pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']);
1833 1833
 		}
1834 1834
 
1835 1835
 		return $pieces;
@@ -1841,12 +1841,12 @@  discard block
 block discarded – undo
1841 1841
      * @param array $pieces
1842 1842
 	 * @return array $pieces
1843 1843
 	 */
1844
-	public static function comment_total_sum_meta_value_filter( $pieces ) {
1844
+	public static function comment_total_sum_meta_value_filter($pieces) {
1845 1845
 		global $wpdb, $wp_version;
1846 1846
 
1847 1847
 		$pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum ";
1848
-		unset( $pieces['groupby'] );
1849
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1848
+		unset($pieces['groupby']);
1849
+		if (version_compare($wp_version, '4.1', '>=')) {
1850 1850
 			$args['order'] = false;
1851 1851
 			$args['orderby'] = false;
1852 1852
 		}
@@ -1861,12 +1861,12 @@  discard block
 block discarded – undo
1861 1861
 	 * @param  array $pieces (default: array())
1862 1862
 	 * @return array
1863 1863
 	 */
1864
-	public static function get_posts_count_only_filter( $pieces ) {
1864
+	public static function get_posts_count_only_filter($pieces) {
1865 1865
 		global $wp_version;
1866 1866
 
1867 1867
 		$pieces['fields'] = " COUNT(*) AS total ";
1868
-		unset( $pieces['groupby'] );
1869
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1868
+		unset($pieces['groupby']);
1869
+		if (version_compare($wp_version, '4.1', '>=')) {
1870 1870
 			$args['order'] = false;
1871 1871
 			$args['orderby'] = false;
1872 1872
 		}
@@ -1885,9 +1885,9 @@  discard block
 block discarded – undo
1885 1885
      *
1886 1886
      * @return bool $success
1887 1887
      */
1888
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1888
+    public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1889 1889
 
1890
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1890
+        return self::update_user_data($data_key, $post_id, $value, $user_id);
1891 1891
 
1892 1892
     }// end add_user_data
1893 1893
 
@@ -1906,18 +1906,18 @@  discard block
 block discarded – undo
1906 1906
      *
1907 1907
      * @return bool $success
1908 1908
      */
1909
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1909
+    public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1910 1910
 
1911
-        if( ! ( $user_id > 0 ) ){
1911
+        if ( ! ($user_id > 0)) {
1912 1912
             $user_id = get_current_user_id();
1913 1913
         }
1914 1914
 
1915
-        $supported_post_types = array( 'course', 'lesson' );
1916
-        $post_type = get_post_type( $post_id );
1917
-        if( empty( $post_id ) || empty( $data_key )
1918
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1919
-            || !get_userdata( $user_id )
1920
-            || ! in_array( $post_type, $supported_post_types )  ){
1915
+        $supported_post_types = array('course', 'lesson');
1916
+        $post_type = get_post_type($post_id);
1917
+        if (empty($post_id) || empty($data_key)
1918
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1919
+            || ! get_userdata($user_id)
1920
+            || ! in_array($post_type, $supported_post_types)) {
1921 1921
 
1922 1922
             return false;
1923 1923
         }
@@ -1925,20 +1925,20 @@  discard block
 block discarded – undo
1925 1925
         // check if there and existing Sensei status on this post type if not create it
1926 1926
         // and get the  activity ID
1927 1927
         $status_function = 'user_'.$post_type.'_status';
1928
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1929
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1928
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1929
+        if ( ! isset($sensei_user_status->comment_ID)) {
1930 1930
 
1931 1931
             $start_function = 'user_start_'.$post_type;
1932
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1932
+            $sensei_user_activity_id = self::$start_function($user_id, $post_id);
1933 1933
 
1934
-        }else{
1934
+        } else {
1935 1935
 
1936 1936
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1937 1937
 
1938 1938
         }
1939 1939
 
1940 1940
         // store the data
1941
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1941
+        $success = update_comment_meta($sensei_user_activity_id, $data_key, $value);
1942 1942
 
1943 1943
        return $success;
1944 1944
 
@@ -1957,20 +1957,20 @@  discard block
 block discarded – undo
1957 1957
      *
1958 1958
      * @return mixed $user_data_value
1959 1959
      */
1960
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1960
+    public static function get_user_data($data_key, $post_id, $user_id = 0) {
1961 1961
 
1962 1962
         $user_data_value = true;
1963 1963
 
1964
-        if( ! ( $user_id > 0 ) ){
1964
+        if ( ! ($user_id > 0)) {
1965 1965
             $user_id = get_current_user_id();
1966 1966
         }
1967 1967
 
1968
-        $supported_post_types = array( 'course', 'lesson' );
1969
-        $post_type = get_post_type( $post_id );
1970
-        if( empty( $post_id ) || empty( $data_key )
1971
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1972
-            || ! get_userdata( $user_id )
1973
-            || !in_array( $post_type, $supported_post_types )  ){
1968
+        $supported_post_types = array('course', 'lesson');
1969
+        $post_type = get_post_type($post_id);
1970
+        if (empty($post_id) || empty($data_key)
1971
+            || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1972
+            || ! get_userdata($user_id)
1973
+            || ! in_array($post_type, $supported_post_types)) {
1974 1974
 
1975 1975
             return false;
1976 1976
         }
@@ -1978,13 +1978,13 @@  discard block
 block discarded – undo
1978 1978
         // check if there and existing Sensei status on this post type if not create it
1979 1979
         // and get the  activity ID
1980 1980
         $status_function = 'user_'.$post_type.'_status';
1981
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1982
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1981
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1982
+        if ( ! isset($sensei_user_status->comment_ID)) {
1983 1983
             return false;
1984 1984
         }
1985 1985
 
1986 1986
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
1987
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
1987
+        $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true);
1988 1988
 
1989 1989
         return $user_data_value;
1990 1990
 
@@ -1999,19 +1999,19 @@  discard block
 block discarded – undo
1999 1999
      *
2000 2000
      * @return bool $deleted
2001 2001
      */
2002
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2002
+    public static function delete_user_data($data_key, $post_id, $user_id) {
2003 2003
         $deleted = true;
2004 2004
 
2005
-        if( ! ( $user_id > 0 ) ){
2005
+        if ( ! ($user_id > 0)) {
2006 2006
             $user_id = get_current_user_id();
2007 2007
         }
2008 2008
 
2009
-        $supported_post_types = array( 'course', 'lesson' );
2010
-        $post_type = get_post_type( $post_id );
2011
-        if( empty( $post_id ) || empty( $data_key )
2012
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2013
-            || ! get_userdata( $user_id )
2014
-            || !in_array( $post_type, $supported_post_types )  ){
2009
+        $supported_post_types = array('course', 'lesson');
2010
+        $post_type = get_post_type($post_id);
2011
+        if (empty($post_id) || empty($data_key)
2012
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2013
+            || ! get_userdata($user_id)
2014
+            || ! in_array($post_type, $supported_post_types)) {
2015 2015
 
2016 2016
             return false;
2017 2017
         }
@@ -2019,13 +2019,13 @@  discard block
 block discarded – undo
2019 2019
         // check if there and existing Sensei status on this post type if not create it
2020 2020
         // and get the  activity ID
2021 2021
         $status_function = 'user_'.$post_type.'_status';
2022
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2023
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2022
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2023
+        if ( ! isset($sensei_user_status->comment_ID)) {
2024 2024
             return false;
2025 2025
         }
2026 2026
 
2027 2027
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2028
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2028
+        $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
2029 2029
 
2030 2030
         return $deleted;
2031 2031
 
@@ -2050,62 +2050,62 @@  discard block
 block discarded – undo
2050 2050
      *
2051 2051
      * @return string $drop_down_element
2052 2052
      */
2053
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2053
+    public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) {
2054 2054
 
2055 2055
         $drop_down_element = '';
2056 2056
 
2057 2057
         // setup the basic attributes
2058
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2058
+        if ( ! isset($attributes['name']) || empty($attributes['name'])) {
2059 2059
 
2060 2060
             $attributes['name'] = 'sensei-options';
2061 2061
 
2062 2062
         }
2063 2063
 
2064
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2064
+        if ( ! isset($attributes['id']) || empty($attributes['id'])) {
2065 2065
 
2066 2066
             $attributes['id'] = 'sensei-options';
2067 2067
 
2068 2068
         }
2069 2069
 
2070
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2070
+        if ( ! isset($attributes['class']) || empty($attributes['class'])) {
2071 2071
 
2072
-            $attributes['class'] ='chosen_select widefat';
2072
+            $attributes['class'] = 'chosen_select widefat';
2073 2073
 
2074 2074
         }
2075 2075
 
2076 2076
         // create element attributes
2077 2077
         $combined_attributes = '';
2078
-        foreach( $attributes as $attribute => $value ){
2078
+        foreach ($attributes as $attribute => $value) {
2079 2079
 
2080
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2080
+            $combined_attributes .= $attribute.'="'.$value.'"'.' ';
2081 2081
 
2082 2082
         }// end for each
2083 2083
 
2084 2084
 
2085 2085
         // create the select element
2086
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2086
+        $drop_down_element .= '<select '.$combined_attributes.' >'."\n";
2087 2087
 
2088 2088
         // show the none option if the client requested
2089
-        if( $enable_none_option ) {
2090
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2089
+        if ($enable_none_option) {
2090
+            $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
2091 2091
         }
2092 2092
 
2093
-        if ( count( $options ) > 0 ) {
2093
+        if (count($options) > 0) {
2094 2094
 
2095
-            foreach ($options as $value => $option ){
2095
+            foreach ($options as $value => $option) {
2096 2096
 
2097 2097
                 $element = '';
2098
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2099
-                $element .= selected( $value, $selected_value, false ) . '>';
2100
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2098
+                $element .= '<option value="'.esc_attr($value).'"';
2099
+                $element .= selected($value, $selected_value, false).'>';
2100
+                $element .= esc_html($option).'</option>'."\n";
2101 2101
 
2102 2102
                 // add the element to the select html
2103
-                $drop_down_element.= $element;
2103
+                $drop_down_element .= $element;
2104 2104
             } // End For Loop
2105 2105
 
2106 2106
         } // End If Statement
2107 2107
 
2108
-        $drop_down_element .= '</select>' . "\n";
2108
+        $drop_down_element .= '</select>'."\n";
2109 2109
 
2110 2110
         return $drop_down_element;
2111 2111
 
@@ -2125,14 +2125,14 @@  discard block
 block discarded – undo
2125 2125
      *
2126 2126
      * @return double $val
2127 2127
      */
2128
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2128
+    public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') {
2129 2129
 
2130 2130
         /**å
2131 2131
          * Change the precision for the Sensei_Utils::round function.
2132 2132
          * the precision given will be passed into the php round function
2133 2133
          * @since 1.8.5
2134 2134
          */
2135
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2135
+        $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode);
2136 2136
 
2137 2137
         /**
2138 2138
          * Change the mode for the Sensei_Utils::round function.
@@ -2142,15 +2142,15 @@  discard block
 block discarded – undo
2142 2142
          *
2143 2143
          * @since 1.8.5
2144 2144
          */
2145
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2145
+        $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision);
2146 2146
 
2147
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2147
+        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
2148 2148
 
2149
-            return round( $val, $precision, $mode );
2149
+            return round($val, $precision, $mode);
2150 2150
 
2151
-        }else{
2151
+        } else {
2152 2152
 
2153
-            return round( $val, $precision );
2153
+            return round($val, $precision);
2154 2154
 
2155 2155
         }
2156 2156
 
@@ -2162,15 +2162,15 @@  discard block
 block discarded – undo
2162 2162
      * @since 1.9.0
2163 2163
      * @return string $url
2164 2164
      */
2165
-    public static function get_current_url(){
2165
+    public static function get_current_url() {
2166 2166
 
2167 2167
         global $wp;
2168
-        $current_url = trailingslashit( home_url( $wp->request ) );
2169
-        if ( isset( $_GET ) ) {
2168
+        $current_url = trailingslashit(home_url($wp->request));
2169
+        if (isset($_GET)) {
2170 2170
 
2171
-            foreach ($_GET as $param => $val ) {
2171
+            foreach ($_GET as $param => $val) {
2172 2172
 
2173
-                $current_url = add_query_arg( $param, $val , $current_url );
2173
+                $current_url = add_query_arg($param, $val, $current_url);
2174 2174
 
2175 2175
             }
2176 2176
         }
@@ -2200,27 +2200,27 @@  discard block
 block discarded – undo
2200 2200
      * @param array $array_b
2201 2201
      * @return array $merged_array
2202 2202
      */
2203
-    public static function array_zip_merge( $array_a, $array_b ){
2203
+    public static function array_zip_merge($array_a, $array_b) {
2204 2204
 
2205
-        if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2205
+        if ( ! isset($array_a[0]) || ! isset($array_b[0])) {
2206 2206
             trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2207 2207
         }
2208 2208
 
2209 2209
         $merged_array = array();
2210
-        $total_elements = count( $array_a )  + count( $array_b );
2210
+        $total_elements = count($array_a) + count($array_b);
2211 2211
 
2212 2212
         // Zip arrays
2213
-        for ( $i = 0; $i < $total_elements; $i++) {
2213
+        for ($i = 0; $i < $total_elements; $i++) {
2214 2214
 
2215 2215
             // if has an element at current index push a on top
2216
-            if( isset( $array_a[ $i ] ) ){
2217
-                $merged_array[] = $array_a[ $i ]  ;
2216
+            if (isset($array_a[$i])) {
2217
+                $merged_array[] = $array_a[$i];
2218 2218
             }
2219 2219
 
2220 2220
             // next if $array_b has an element at current index push a on top of the element
2221 2221
             // from a if there was one, if not the element before that.
2222
-            if( isset( $array_b[ $i ] ) ){
2223
-                $merged_array[] = $array_b[ $i ]  ;
2222
+            if (isset($array_b[$i])) {
2223
+                $merged_array[] = $array_b[$i];
2224 2224
             }
2225 2225
 
2226 2226
         }
@@ -2235,4 +2235,4 @@  discard block
 block discarded – undo
2235 2235
  * for backward compatibility
2236 2236
  * @since 1.9.0
2237 2237
  */
2238
-class WooThemes_Sensei_Utils extends Sensei_Utils{}
2239 2238
\ No newline at end of file
2239
+class WooThemes_Sensei_Utils extends Sensei_Utils {}
2240 2240
\ No newline at end of file
Please login to merge, or discard this patch.