Completed
Pull Request — master (#1343)
by
unknown
04:41
created
includes/class-sensei-utils.php 1 patch
Spacing   +542 added lines, -542 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
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	 * @since   1.0.0
19 19
 	 * @return  string The URL to the placeholder thumbnail image.
20 20
 	 */
21
-	public static function get_placeholder_image () {
21
+	public static function get_placeholder_image() {
22 22
 
23
-		return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) );
23
+		return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png'));
24 24
 	} // End get_placeholder_image()
25 25
 
26 26
 	/**
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @static
33 33
 	 * @return bool
34 34
 	 */
35
-	public static function sensei_is_woocommerce_present () {
35
+	public static function sensei_is_woocommerce_present() {
36 36
 
37 37
         return Sensei_WC::is_woocommerce_present();
38 38
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @static
48 48
 	 * @return boolean
49 49
 	 */
50
-	public static function sensei_is_woocommerce_activated () {
50
+	public static function sensei_is_woocommerce_activated() {
51 51
 
52 52
 		return  Sensei_WC::is_woocommerce_active();
53 53
 
@@ -60,70 +60,70 @@  discard block
 block discarded – undo
60 60
 	 * @param  array $args (default: array())
61 61
 	 * @return bool | int
62 62
 	 */
63
-	public static function sensei_log_activity ( $args = array() ) {
63
+	public static function sensei_log_activity($args = array()) {
64 64
 		global $wpdb;
65 65
 
66 66
 		// Args, minimum data required for WP
67 67
 		$data = array(
68
-					'comment_post_ID' => intval( $args['post_id'] ),
68
+					'comment_post_ID' => intval($args['post_id']),
69 69
 					'comment_author' => '', // Not needed
70 70
 					'comment_author_email' => '', // Not needed
71 71
 					'comment_author_url' => '', // Not needed
72
-					'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '',
73
-					'comment_type' => esc_attr( $args['type'] ),
74
-					'user_id' => intval( $args['user_id'] ),
75
-					'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer'
72
+					'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '',
73
+					'comment_type' => esc_attr($args['type']),
74
+					'user_id' => intval($args['user_id']),
75
+					'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer'
76 76
 				);
77 77
 		// Allow extra data
78
-		if ( !empty($args['username']) ) {
79
-			$data['comment_author'] = sanitize_user( $args['username'] );
78
+		if ( ! empty($args['username'])) {
79
+			$data['comment_author'] = sanitize_user($args['username']);
80 80
 		}
81
-		if ( !empty($args['user_email']) ) {
82
-			$data['comment_author_email'] = sanitize_email( $args['user_email'] );
81
+		if ( ! empty($args['user_email'])) {
82
+			$data['comment_author_email'] = sanitize_email($args['user_email']);
83 83
 		}
84
-		if ( !empty($args['user_url']) ) {
85
-			$data['comment_author_url'] = esc_url( $args['user_url'] );
84
+		if ( ! empty($args['user_url'])) {
85
+			$data['comment_author_url'] = esc_url($args['user_url']);
86 86
 		}
87
-		if ( !empty($args['parent']) ) {
87
+		if ( ! empty($args['parent'])) {
88 88
 			$data['comment_parent'] = $args['parent'];
89 89
 		}
90 90
 		// Sanity check
91
-		if ( empty($args['user_id']) ) {
92
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
91
+		if (empty($args['user_id'])) {
92
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
93 93
 			return false;
94 94
 		}
95 95
 
96
-		do_action( 'sensei_log_activity_before', $args, $data );
96
+		do_action('sensei_log_activity_before', $args, $data);
97 97
 
98 98
 		$flush_cache = false;
99 99
 
100 100
 		// Custom Logic
101 101
 		// Check if comment exists first
102
-		$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'] ) );
103
-		if ( ! $comment_id ) {
102
+		$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']));
103
+		if ( ! $comment_id) {
104 104
 			// Add the comment
105
-			$comment_id = wp_insert_comment( $data );
105
+			$comment_id = wp_insert_comment($data);
106 106
 
107 107
 			$flush_cache = true;
108
-		} elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) {
108
+		} elseif (isset($args['action']) && 'update' == $args['action']) {
109 109
 			// Update the comment if an update was requested
110 110
 			$data['comment_ID'] = $comment_id;
111 111
 			// By default update the timestamp of the comment
112
-			if ( empty($args['keep_time']) ) {
112
+			if (empty($args['keep_time'])) {
113 113
 				$data['comment_date'] = current_time('mysql');
114 114
 			}
115
-			wp_update_comment( $data );
115
+			wp_update_comment($data);
116 116
 			$flush_cache = true;
117 117
 		} // End If Statement
118 118
 
119 119
 		// Manually Flush the Cache
120
-		if ( $flush_cache ) {
120
+		if ($flush_cache) {
121 121
 			wp_cache_flush();
122 122
 		}
123 123
 
124
-		do_action( 'sensei_log_activity_after', $args, $data,  $comment_id );
124
+		do_action('sensei_log_activity_after', $args, $data, $comment_id);
125 125
 
126
-		if ( 0 < $comment_id ) {
126
+		if (0 < $comment_id) {
127 127
 			// Return the ID so that it can be used for meta data storage
128 128
 			return $comment_id;
129 129
 		} else {
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
 	 * @param  bool $return_comments (default: false)
141 141
 	 * @return mixed | int
142 142
 	 */
143
-	public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) {
143
+	public static function sensei_check_for_activity($args = array(), $return_comments = false) {
144 144
 
145 145
 		global  $wp_version;
146
-		if ( !$return_comments ) {
146
+		if ( ! $return_comments) {
147 147
 			$args['count'] = true;
148 148
 		}
149 149
 
150 150
 		// Are we only retrieving a single entry, or not care about the order...
151
-		if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){
151
+		if (isset($args['count']) || isset($args['post_id'])) {
152 152
 
153 153
 			// ...then we don't need to ask the db to order the results, this overrides WP default behaviour
154
-			if ( version_compare( $wp_version, '4.1', '>=' ) ) {
154
+			if (version_compare($wp_version, '4.1', '>=')) {
155 155
 				$args['order'] = false;
156 156
 				$args['orderby'] = false;
157 157
 			}
158 158
 		}
159 159
 
160 160
 		// A user ID of 0 is in valid, so shortcut this
161
-		if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) {
162
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
161
+		if (isset($args['user_id']) && 0 == intval($args['user_id'])) {
162
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
163 163
 			return false;
164 164
 		}
165 165
 		// Check for legacy code
166
-		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') ) ) {
167
-			_deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) );
166
+		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'))) {
167
+			_deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type']));
168 168
 			return false;
169 169
 		}
170 170
 		// Are we checking for specific comment_approved statuses?
171
-		if ( isset($args['status']) ) {
171
+		if (isset($args['status'])) {
172 172
 			// Temporarily store as a custom status if requesting an array...
173
-			if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
173
+			if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) {
174 174
 				// Encode now, decode later
175
-				$args['status'] = implode( ",", $args['status'] );
175
+				$args['status'] = implode(",", $args['status']);
176 176
 				// ...use a filter to switch the encoding back
177
-				add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
177
+				add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
178 178
 			}
179 179
 		}
180 180
 		else {
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 		}
183 183
 
184 184
 		// Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 '
185
-		if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
186
-			add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
185
+		if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) {
186
+			add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
187 187
 		}
188 188
 
189 189
         //Get the comments
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
          *
195 195
          * @param int|array $comments
196 196
          */
197
-        $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
197
+        $comments = apply_filters('sensei_check_for_activity', get_comments($args));
198 198
 
199
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
200
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
199
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
200
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
201 201
 		// Return comments
202
-		if ( $return_comments ) {
202
+		if ($return_comments) {
203 203
 			// Could check for array of 1 and just return the 1 item?
204
-			if ( is_array($comments) && 1 == count($comments) ) {
204
+			if (is_array($comments) && 1 == count($comments)) {
205 205
 				$comments = array_shift($comments);
206 206
 			}
207 207
 
@@ -219,31 +219,31 @@  discard block
 block discarded – undo
219 219
 	 * @param  array $args (default: array())
220 220
 	 * @return array
221 221
 	 */
222
-	public static function sensei_activity_ids ( $args = array() ) {
222
+	public static function sensei_activity_ids($args = array()) {
223 223
 
224 224
 
225
-		$comments = Sensei_Utils::sensei_check_for_activity( $args, true );
225
+		$comments = Sensei_Utils::sensei_check_for_activity($args, true);
226 226
 		// Need to always use an array, even with only 1 item
227
-		if ( !is_array($comments) ) {
228
-			$comments = array( $comments );
227
+		if ( ! is_array($comments)) {
228
+			$comments = array($comments);
229 229
 		}
230 230
 
231 231
 		$post_ids = array();
232 232
 		// Count comments
233
-		if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) {
234
-			foreach ( $comments as $key => $value  ) {
233
+		if (is_array($comments) && (0 < intval(count($comments)))) {
234
+			foreach ($comments as $key => $value) {
235 235
 				// Add matches to id array
236
-				if ( isset( $args['field'] ) && 'comment' == $args['field'] ) {
237
-					array_push( $post_ids, $value->comment_ID );
238
-				} elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) {
239
-					array_push( $post_ids, $value->user_id );
236
+				if (isset($args['field']) && 'comment' == $args['field']) {
237
+					array_push($post_ids, $value->comment_ID);
238
+				} elseif (isset($args['field']) && 'user_id' == $args['field']) {
239
+					array_push($post_ids, $value->user_id);
240 240
 				} else {
241
-					array_push( $post_ids, $value->comment_post_ID );
241
+					array_push($post_ids, $value->comment_post_ID);
242 242
 				} // End If Statement
243 243
 			} // End For Loop
244 244
 			// Reset array indexes
245
-			$post_ids = array_unique( $post_ids );
246
-			$post_ids = array_values( $post_ids );
245
+			$post_ids = array_unique($post_ids);
246
+			$post_ids = array_values($post_ids);
247 247
 		} // End If Statement
248 248
 
249 249
 		return $post_ids;
@@ -257,20 +257,20 @@  discard block
 block discarded – undo
257 257
 	 * @param  array $args (default: array())
258 258
 	 * @return boolean
259 259
 	 */
260
-	public static function sensei_delete_activities ( $args = array() ) {
260
+	public static function sensei_delete_activities($args = array()) {
261 261
 
262 262
 		$dataset_changes = false;
263 263
 
264 264
 		// If activity exists remove activity from log
265
-		$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 );
266
-		if( $comments ) {
265
+		$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);
266
+		if ($comments) {
267 267
 			// Need to always return an array, even with only 1 item
268
-			if ( !is_array( $comments ) ) {
269
-				$comments = array( $comments );
268
+			if ( ! is_array($comments)) {
269
+				$comments = array($comments);
270 270
 			}
271
-			foreach ( $comments as $key => $value  ) {
272
-				if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) {
273
-					$dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true );
271
+			foreach ($comments as $key => $value) {
272
+				if (isset($value->comment_ID) && 0 < $value->comment_ID) {
273
+					$dataset_changes = wp_delete_comment(intval($value->comment_ID), true);
274 274
 				} // End If Statement
275 275
 			} // End For Loop
276 276
 			// Manually flush the cache
@@ -286,25 +286,25 @@  discard block
 block discarded – undo
286 286
      * @param  integer $user_id User ID
287 287
      * @return boolean
288 288
      */
289
-    public static function delete_all_user_activity( $user_id = 0 ) {
289
+    public static function delete_all_user_activity($user_id = 0) {
290 290
 
291 291
     	$dataset_changes = false;
292 292
 
293
-    	if( $user_id ) {
293
+    	if ($user_id) {
294 294
 
295
-			$activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true );
295
+			$activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true);
296 296
 
297
-			if( $activities ) {
297
+			if ($activities) {
298 298
 
299 299
 				// Need to always return an array, even with only 1 item
300
-				if ( ! is_array( $activities ) ) {
301
-					$activities = array( $activities );
300
+				if ( ! is_array($activities)) {
301
+					$activities = array($activities);
302 302
 				}
303 303
 
304
-				foreach( $activities as $activity ) {
305
-					if( '' == $activity->comment_type ) continue;
306
-					if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
307
-					$dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true );
304
+				foreach ($activities as $activity) {
305
+					if ('' == $activity->comment_type) continue;
306
+					if (strpos('sensei_', $activity->comment_type) != 0) continue;
307
+					$dataset_changes = wp_delete_comment(intval($activity->comment_ID), true);
308 308
 					wp_cache_flush();
309 309
 				}
310 310
 			}
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 	 * @param  array $args (default: array())
322 322
 	 * @return string
323 323
 	 */
324
-	public static function sensei_get_activity_value ( $args = array() ) {
324
+	public static function sensei_get_activity_value($args = array()) {
325 325
 
326 326
 		$activity_value = false;
327
-		if ( !empty($args['field']) ) {
328
-			$comment = Sensei_Utils::sensei_check_for_activity( $args, true );
327
+		if ( ! empty($args['field'])) {
328
+			$comment = Sensei_Utils::sensei_check_for_activity($args, true);
329 329
 
330
-			if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
330
+			if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
331 331
 				$activity_value = $comment->{$args['field']};
332 332
 			} // End If Statement
333 333
 		}
@@ -345,22 +345,22 @@  discard block
 block discarded – undo
345 345
      * @param  int $product_id
346 346
      * @return bool
347 347
      */
348
-    public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
348
+    public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) {
349 349
 
350 350
         $emails = array();
351 351
 
352
-        if ( $user_id ) {
353
-            $user = get_user_by( 'id', intval( $user_id ) );
352
+        if ($user_id) {
353
+            $user = get_user_by('id', intval($user_id));
354 354
             $emails[] = $user->user_email;
355 355
         }
356 356
 
357
-        if ( is_email( $customer_email ) )
357
+        if (is_email($customer_email))
358 358
             $emails[] = $customer_email;
359 359
 
360
-        if ( sizeof( $emails ) == 0 )
360
+        if (sizeof($emails) == 0)
361 361
             return false;
362 362
 
363
-        return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
363
+        return Sensei_WC::has_customer_bought_product($user_id, $product_id);
364 364
 
365 365
     } // End sensei_customer_bought_product()
366 366
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 * @param  string $input_name Name for text area form element
372 372
 	 * @return void
373 373
 	 */
374
-	public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) {
374
+	public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') {
375 375
 
376
-		if( ! $input_name ) $input_name = $editor_id;
376
+		if ( ! $input_name) $input_name = $editor_id;
377 377
 
378 378
 		$buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext';
379 379
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			'quicktags' => false
392 392
 		);
393 393
 
394
-		wp_editor( $content, $editor_id, $settings );
394
+		wp_editor($content, $editor_id, $settings);
395 395
 
396 396
 	} // End sensei_text_editor()
397 397
 
@@ -401,57 +401,57 @@  discard block
 block discarded – undo
401 401
      * @param int $user_id
402 402
 	 * @return boolean            Whether the answers were saved or not
403 403
 	 */
404
-	public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) {
404
+	public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) {
405 405
 
406
-		if( intval( $user_id ) == 0 ) {
406
+		if (intval($user_id) == 0) {
407 407
 			$user_id = get_current_user_id();
408 408
 		}
409 409
 
410 410
 		$answers_saved = false;
411 411
 
412
-		if( $submitted && intval( $user_id ) > 0 ) {
412
+		if ($submitted && intval($user_id) > 0) {
413 413
 
414
-			foreach( $submitted as $question_id => $answer ) {
414
+			foreach ($submitted as $question_id => $answer) {
415 415
 
416 416
 				// Get question type
417
-				$question_type = Sensei()->question->get_question_type( $question_id );
417
+				$question_type = Sensei()->question->get_question_type($question_id);
418 418
 
419 419
 				// Sanitise answer
420
-				if( 0 == get_magic_quotes_gpc() ) {
421
-					$answer = wp_unslash( $answer );
420
+				if (0 == get_magic_quotes_gpc()) {
421
+					$answer = wp_unslash($answer);
422 422
 				}
423
-				switch( $question_type ) {
424
-					case 'multi-line': $answer = nl2br( $answer ); break;
423
+				switch ($question_type) {
424
+					case 'multi-line': $answer = nl2br($answer); break;
425 425
 					case 'single-line': break;
426 426
 					case 'gap-fill': break;
427
-					default: $answer = maybe_serialize( $answer ); break;
427
+					default: $answer = maybe_serialize($answer); break;
428 428
 				}
429 429
 				$args = array(
430 430
 							'post_id' => $question_id,
431
-							'data' => base64_encode( $answer ),
431
+							'data' => base64_encode($answer),
432 432
 							'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
433 433
 							'user_id' => $user_id,
434 434
 							'action' => 'update'
435 435
 						);
436
-				$answers_saved = Sensei_Utils::sensei_log_activity( $args );
436
+				$answers_saved = Sensei_Utils::sensei_log_activity($args);
437 437
 			}
438 438
 
439 439
 			// Handle file upload questions
440
-			if( isset( $_FILES ) ) {
441
-				foreach( $_FILES as $field => $file ) {
442
-					if( strpos( $field, 'file_upload_' ) !== false ) {
443
-						$question_id = str_replace( 'file_upload_', '', $field );
444
-						if( $file && $question_id ) {
445
-							$attachment_id = self::upload_file( $file );
446
-							if( $attachment_id ) {
440
+			if (isset($_FILES)) {
441
+				foreach ($_FILES as $field => $file) {
442
+					if (strpos($field, 'file_upload_') !== false) {
443
+						$question_id = str_replace('file_upload_', '', $field);
444
+						if ($file && $question_id) {
445
+							$attachment_id = self::upload_file($file);
446
+							if ($attachment_id) {
447 447
 								$args = array(
448 448
 									'post_id' => $question_id,
449
-									'data' => base64_encode( $attachment_id ),
449
+									'data' => base64_encode($attachment_id),
450 450
 									'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
451 451
 									'user_id' => $user_id,
452 452
 									'action' => 'update'
453 453
 								);
454
-								$answers_saved = Sensei_Utils::sensei_log_activity( $args );
454
+								$answers_saved = Sensei_Utils::sensei_log_activity($args);
455 455
 							}
456 456
 						}
457 457
 					}
@@ -463,9 +463,9 @@  discard block
 block discarded – undo
463 463
 
464 464
 	} // End sensei_save_quiz_answers()
465 465
 
466
-	public static function upload_file( $file = array() ) {
466
+	public static function upload_file($file = array()) {
467 467
 
468
-		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
468
+		require_once(ABSPATH.'wp-admin/includes/admin.php');
469 469
 
470 470
         /**
471 471
          * Filter the data array for the Sensei wp_handle_upload function call
@@ -480,11 +480,11 @@  discard block
 block discarded – undo
480 480
          *     @type string test_form set to false by default
481 481
          * }
482 482
          */
483
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
483
+        $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false));
484 484
 
485
-        $file_return = wp_handle_upload( $file, $file_upload_args );
485
+        $file_return = wp_handle_upload($file, $file_upload_args);
486 486
 
487
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
487
+        if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
488 488
             return false;
489 489
         } else {
490 490
 
@@ -492,19 +492,19 @@  discard block
 block discarded – undo
492 492
 
493 493
             $attachment = array(
494 494
                 'post_mime_type' => $file_return['type'],
495
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
495
+                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
496 496
                 'post_content' => '',
497 497
                 'post_status' => 'inherit',
498 498
                 'guid' => $file_return['url']
499 499
             );
500 500
 
501
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
501
+            $attachment_id = wp_insert_attachment($attachment, $filename);
502 502
 
503
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
504
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
505
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
503
+            require_once(ABSPATH.'wp-admin/includes/image.php');
504
+            $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
505
+            wp_update_attachment_metadata($attachment_id, $attachment_data);
506 506
 
507
-            if( 0 < intval( $attachment_id ) ) {
507
+            if (0 < intval($attachment_id)) {
508 508
             	return $attachment_id;
509 509
             }
510 510
         }
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
      *
531 531
 	 * @return int $quiz_grade total sum of all question grades
532 532
 	 */
533
-	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
533
+	public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') {
534 534
 
535
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
535
+        return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type);
536 536
 
537 537
 	} // End sensei_grade_quiz_auto()
538 538
 
@@ -544,20 +544,20 @@  discard block
 block discarded – undo
544 544
      * @param  string $quiz_grade_type default 'auto'
545 545
 	 * @return boolean
546 546
 	 */
547
-	public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) {
548
-		if( intval( $user_id ) == 0 ) {
547
+	public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') {
548
+		if (intval($user_id) == 0) {
549 549
 			$user_id = get_current_user_id();
550 550
 		}
551 551
 
552 552
 		$activity_logged = false;
553
-		if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) {
554
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
555
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
556
-			$activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade );
553
+		if (intval($quiz_id) > 0 && intval($user_id) > 0) {
554
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
555
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
556
+			$activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade);
557 557
 
558
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
558
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
559 559
 
560
-			do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type );
560
+			do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type);
561 561
 		}
562 562
 
563 563
 		return $activity_logged;
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
      *
578 578
 	 * @return int $question_grade
579 579
 	 */
580
-	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
580
+	public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) {
581 581
 
582
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
582
+       return  WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id);
583 583
 
584 584
 	} // end sensei_grade_question_auto
585 585
 
@@ -590,20 +590,20 @@  discard block
 block discarded – undo
590 590
      * @param int $user_id
591 591
 	 * @return boolean
592 592
 	 */
593
-	public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) {
594
-		if( intval( $user_id ) == 0 ) {
593
+	public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) {
594
+		if (intval($user_id) == 0) {
595 595
 			$user_id = get_current_user_id();
596 596
 		}
597 597
 
598 598
 		$activity_logged = false;
599
-		if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) {
599
+		if (intval($question_id) > 0 && intval($user_id) > 0) {
600 600
 
601
-			$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' ) );
602
-			$activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade );
601
+			$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'));
602
+			$activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade);
603 603
 
604
-			$answer_notes = get_post_meta( $question_id, '_answer_feedback', true );
605
-			if ( !empty($answer_notes) ) {
606
-				update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) );
604
+			$answer_notes = get_post_meta($question_id, '_answer_feedback', true);
605
+			if ( ! empty($answer_notes)) {
606
+				update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes));
607 607
 			}
608 608
 
609 609
 		}
@@ -611,15 +611,15 @@  discard block
 block discarded – undo
611 611
 		return $activity_logged;
612 612
 	}
613 613
 
614
-	public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) {
615
-		if( intval( $user_id ) == 0 ) {
614
+	public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) {
615
+		if (intval($user_id) == 0) {
616 616
 			$user_id = get_current_user_id();
617 617
 		}
618 618
 
619 619
 		$activity_logged = false;
620
-		if( intval( $question_id ) > 0 ) {
621
-			$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' ) );
622
-			$activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' );
620
+		if (intval($question_id) > 0) {
621
+			$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'));
622
+			$activity_logged = delete_comment_meta($user_answer_id, 'user_grade');
623 623
 		}
624 624
 
625 625
 		return $activity_logged;
@@ -637,9 +637,9 @@  discard block
 block discarded – undo
637 637
      *
638 638
      * @return mixed boolean or comment_ID
639 639
      */
640
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
640
+    public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) {
641 641
 
642
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
642
+        return self::sensei_start_lesson($lesson_id, $user_id, $complete);
643 643
 
644 644
     }// end user_start_lesson()
645 645
 
@@ -656,22 +656,22 @@  discard block
 block discarded – undo
656 656
      *
657 657
      * @return mixed boolean or comment_ID
658 658
 	 */
659
-	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
659
+	public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) {
660 660
 
661 661
 
662
-		if( intval( $user_id ) == 0 ) {
662
+		if (intval($user_id) == 0) {
663 663
 			$user_id = get_current_user_id();
664 664
 		}
665 665
 
666 666
 		$activity_logged = false;
667 667
 
668
-		if( intval( $lesson_id ) > 0 ) {
668
+		if (intval($lesson_id) > 0) {
669 669
 
670
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
671
-			if( $course_id ) {
672
-				$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id );
673
-				if( ! $is_user_taking_course ) {
674
-					Sensei_Utils::user_start_course( $user_id, $course_id );
670
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
671
+			if ($course_id) {
672
+				$is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id);
673
+				if ( ! $is_user_taking_course) {
674
+					Sensei_Utils::user_start_course($user_id, $course_id);
675 675
 				}
676 676
 			}
677 677
 
@@ -679,12 +679,12 @@  discard block
 block discarded – undo
679 679
 			$status = 'in-progress';
680 680
 
681 681
 			// Note: When this action runs the lesson status may not yet exist
682
-			do_action( 'sensei_user_lesson_start', $user_id, $lesson_id );
682
+			do_action('sensei_user_lesson_start', $user_id, $lesson_id);
683 683
 
684
-			if( $complete ) {
684
+			if ($complete) {
685 685
 
686
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
687
-				if ( $has_questions ) {
686
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
687
+				if ($has_questions) {
688 688
 					$status = 'passed'; // Force a pass
689 689
 					$metadata['grade'] = 0;
690 690
 				}
@@ -694,31 +694,31 @@  discard block
 block discarded – undo
694 694
 			}
695 695
 
696 696
 			// Check if user is already taking the lesson
697
-			$activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id );
698
-			if( ! $activity_logged ) {
697
+			$activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id);
698
+			if ( ! $activity_logged) {
699 699
 
700 700
 				$metadata['start'] = current_time('mysql');
701
-				$activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
701
+				$activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata);
702 702
 
703 703
             } else {
704 704
 
705 705
                 // if users is already taking the lesson  and the status changes to complete update it
706 706
                 $current_user_activity = get_comment($activity_logged);
707
-                if( $status=='complete' &&
708
-                    $status != $current_user_activity->comment_approved  ){
707
+                if ($status == 'complete' &&
708
+                    $status != $current_user_activity->comment_approved) {
709 709
 
710 710
                     $comment = array();
711 711
                     $comment['comment_ID'] = $activity_logged;
712 712
                     $comment['comment_approved'] = $status;
713
-                    wp_update_comment( $comment );
713
+                    wp_update_comment($comment);
714 714
 
715 715
                 }
716 716
 
717 717
             }
718 718
 
719
-			if ( $complete ) {
719
+			if ($complete) {
720 720
 				// Run this *after* the lesson status has been created/updated
721
-				do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
721
+				do_action('sensei_user_lesson_end', $user_id, $lesson_id);
722 722
 			}
723 723
 
724 724
 		}
@@ -733,23 +733,23 @@  discard block
 block discarded – undo
733 733
 	 * @param int $user_id
734 734
 	 * @return boolean
735 735
 	 */
736
-	public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) {
736
+	public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) {
737 737
 
738
-		if( ! $lesson_id ) return false;
738
+		if ( ! $lesson_id) return false;
739 739
 
740
-		if( intval( $user_id ) == 0 ) {
740
+		if (intval($user_id) == 0) {
741 741
 			$user_id = get_current_user_id();
742 742
 		}
743 743
 
744 744
 		// Process quiz
745
-		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
745
+		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
746 746
 
747 747
 		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
748
-		Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id );
748
+		Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id);
749 749
 
750 750
 
751 751
 		// Delete quiz saved answers
752
-		Sensei()->quiz->reset_user_lesson_data( $lesson_id, $user_id );
752
+		Sensei()->quiz->reset_user_lesson_data($lesson_id, $user_id);
753 753
 
754 754
 		// Delete lesson status
755 755
 		$args = array(
@@ -758,10 +758,10 @@  discard block
 block discarded – undo
758 758
 			'user_id' => $user_id,
759 759
 		);
760 760
 		// This auto deletes the corresponding meta data, such as the quiz grade, and questions asked
761
-		Sensei_Utils::sensei_delete_activities( $args );
761
+		Sensei_Utils::sensei_delete_activities($args);
762 762
 
763
-		if( ! $from_course ) {
764
-			do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
763
+		if ( ! $from_course) {
764
+			do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
765 765
 		}
766 766
 
767 767
 		return true;
@@ -774,19 +774,19 @@  discard block
 block discarded – undo
774 774
 	 * @param int $user_id
775 775
 	 * @return boolean
776 776
 	 */
777
-	public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
777
+	public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) {
778 778
 
779 779
 
780
-		if( ! $course_id ) return false;
780
+		if ( ! $course_id) return false;
781 781
 
782
-		if( intval( $user_id ) == 0 ) {
782
+		if (intval($user_id) == 0) {
783 783
 			$user_id = get_current_user_id();
784 784
 		}
785 785
 
786
-		$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
786
+		$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
787 787
 
788
-		foreach( $lesson_ids as $lesson_id ) {
789
-			Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true );
788
+		foreach ($lesson_ids as $lesson_id) {
789
+			Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true);
790 790
 		}
791 791
 
792 792
 		// Delete course status
@@ -796,36 +796,36 @@  discard block
 block discarded – undo
796 796
 			'user_id' => $user_id,
797 797
 		);
798 798
 
799
-		Sensei_Utils::sensei_delete_activities( $args );
799
+		Sensei_Utils::sensei_delete_activities($args);
800 800
 
801
-		do_action( 'sensei_user_course_reset', $user_id, $course_id );
801
+		do_action('sensei_user_course_reset', $user_id, $course_id);
802 802
 
803 803
 		return true;
804 804
 	}
805 805
 
806
-	public static function sensei_get_quiz_questions( $quiz_id = 0 ) {
806
+	public static function sensei_get_quiz_questions($quiz_id = 0) {
807 807
 
808 808
 
809 809
 		$questions = array();
810 810
 
811
-		if( intval( $quiz_id ) > 0 ) {
812
-			$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
813
-			$questions = Sensei_Utils::array_sort_reorder( $questions );
811
+		if (intval($quiz_id) > 0) {
812
+			$questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
813
+			$questions = Sensei_Utils::array_sort_reorder($questions);
814 814
 		}
815 815
 
816 816
 		return $questions;
817 817
 	}
818 818
 
819
-	public static function sensei_get_quiz_total( $quiz_id = 0 ) {
819
+	public static function sensei_get_quiz_total($quiz_id = 0) {
820 820
 
821 821
 
822 822
 		$quiz_total = 0;
823 823
 
824
-		if( $quiz_id > 0 ) {
825
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
824
+		if ($quiz_id > 0) {
825
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
826 826
 			$question_grade = 0;
827
-			foreach( $questions as $question ) {
828
-				$question_grade = Sensei()->question->get_question_grade( $question->ID );
827
+			foreach ($questions as $question) {
828
+				$question_grade = Sensei()->question->get_question_grade($question->ID);
829 829
 				$quiz_total += $question_grade;
830 830
 			}
831 831
 		}
@@ -840,20 +840,20 @@  discard block
 block discarded – undo
840 840
 	 * @param int $user_id
841 841
 	 * @return string
842 842
 	 */
843
-	public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) {
843
+	public static function sensei_get_user_question_grade($question = 0, $user_id = 0) {
844 844
 		$question_grade = false;
845
-		if( $question ) {
846
-			if ( is_object( $question ) ) {
845
+		if ($question) {
846
+			if (is_object($question)) {
847 847
 				$user_answer_id = $question->comment_ID;
848 848
 			}
849 849
 			else {
850
-				if( intval( $user_id ) == 0 ) {
850
+				if (intval($user_id) == 0) {
851 851
 					$user_id = get_current_user_id();
852 852
 				}
853
-				$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' ) );
853
+				$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'));
854 854
 			}
855
-			if ( $user_answer_id ) {
856
-				$question_grade = get_comment_meta( $user_answer_id, 'user_grade', true );
855
+			if ($user_answer_id) {
856
+				$question_grade = get_comment_meta($user_answer_id, 'user_grade', true);
857 857
 			}
858 858
 		}
859 859
 
@@ -868,52 +868,52 @@  discard block
 block discarded – undo
868 868
 	 * @param int $user_id
869 869
 	 * @return string
870 870
 	 */
871
-	public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) {
871
+	public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) {
872 872
 		$answer_notes = false;
873
-		if( $question ) {
874
-			if ( is_object( $question ) ) {
873
+		if ($question) {
874
+			if (is_object($question)) {
875 875
 				$user_answer_id = $question->comment_ID;
876 876
 			}
877 877
 			else {
878
-				if( intval( $user_id ) == 0 ) {
878
+				if (intval($user_id) == 0) {
879 879
 					$user_id = get_current_user_id();
880 880
 				}
881
-				$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' ) );
881
+				$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'));
882 882
 			}
883
-			if ( $user_answer_id ) {
884
-				$answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) );
883
+			if ($user_answer_id) {
884
+				$answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true));
885 885
 			}
886 886
 		}
887 887
 
888 888
 		return $answer_notes;
889 889
 	}
890 890
 
891
-	public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) {
892
-		if( intval( $user_id ) == 0 ) {
891
+	public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) {
892
+		if (intval($user_id) == 0) {
893 893
 			$user_id = get_current_user_id();
894 894
 		}
895 895
 
896 896
 		$delete_answers = false;
897
-		if( intval( $quiz_id ) > 0 ) {
898
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
899
-			foreach( $questions as $question ) {
900
-				$delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) );
897
+		if (intval($quiz_id) > 0) {
898
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
899
+			foreach ($questions as $question) {
900
+				$delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer'));
901 901
 			}
902 902
 		}
903 903
 
904 904
 		return $delete_answers;
905 905
 	}
906 906
 
907
-	public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) {
908
-		if( intval( $user_id ) == 0 ) {
907
+	public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) {
908
+		if (intval($user_id) == 0) {
909 909
 			$user_id = get_current_user_id();
910 910
 		}
911 911
 
912 912
 		$delete_grade = false;
913
-		if( intval( $quiz_id ) > 0 ) {
914
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
915
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
916
-			$delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' );
913
+		if (intval($quiz_id) > 0) {
914
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
915
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
916
+			$delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade');
917 917
 		}
918 918
 
919 919
 		return $delete_grade;
@@ -926,20 +926,20 @@  discard block
 block discarded – undo
926 926
      * @param string $notes
927 927
 	 * @return boolean
928 928
 	 */
929
-	public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) {
930
-		if( intval( $user_id ) == 0 ) {
929
+	public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') {
930
+		if (intval($user_id) == 0) {
931 931
 			$user_id = get_current_user_id();
932 932
 		}
933 933
 
934 934
 		$activity_logged = false;
935 935
 
936
-		if( intval( $question_id ) > 0 ) {
937
-			$notes = base64_encode( $notes );
936
+		if (intval($question_id) > 0) {
937
+			$notes = base64_encode($notes);
938 938
 
939 939
 			// Don't store empty values, no point
940
-			if ( !empty($notes) ) {
941
-				$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' ) );
942
-				$activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes );
940
+			if ( ! empty($notes)) {
941
+				$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'));
942
+				$activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes);
943 943
 			}
944 944
 			else {
945 945
 				$activity_logged = true;
@@ -955,16 +955,16 @@  discard block
 block discarded – undo
955 955
 	 * @param  array $return_array data to be ordered
956 956
 	 * @return array $return_array ordered data
957 957
 	 */
958
-	public static function array_sort_reorder( $return_array ) {
959
-		if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) {
958
+	public static function array_sort_reorder($return_array) {
959
+		if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) {
960 960
 			$sort_key = '';
961 961
 			// if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) {
962 962
 			// 	$sort_key = esc_html( $_GET['orderby'] );
963 963
 			// } // End If Statement
964
-			if ( '' != $sort_key ) {
965
-					Sensei_Utils::sort_array_by_key($return_array,$sort_key);
966
-				if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) {
967
-					$return_array = array_reverse( $return_array, true );
964
+			if ('' != $sort_key) {
965
+					Sensei_Utils::sort_array_by_key($return_array, $sort_key);
966
+				if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) {
967
+					$return_array = array_reverse($return_array, true);
968 968
 				} // End If Statement
969 969
 			} // End If Statement
970 970
 			return $return_array;
@@ -980,15 +980,15 @@  discard block
 block discarded – undo
980 980
 	 * @param  $key string column name in array
981 981
 	 * @return void
982 982
 	 */
983
-	public static function sort_array_by_key( $array, $key ) {
983
+	public static function sort_array_by_key($array, $key) {
984 984
 	    $sorter = array();
985 985
 	    $ret = array();
986
-	    reset( $array );
987
-	    foreach ( $array as $ii => $va ) {
986
+	    reset($array);
987
+	    foreach ($array as $ii => $va) {
988 988
 	        $sorter[$ii] = $va[$key];
989 989
 	    } // End For Loop
990
-	    asort( $sorter );
991
-	    foreach ( $sorter as $ii => $va ) {
990
+	    asort($sorter);
991
+	    foreach ($sorter as $ii => $va) {
992 992
 	        $ret[$ii] = $array[$ii];
993 993
 	    } // End For Loop
994 994
 	    $array = $ret;
@@ -1000,10 +1000,10 @@  discard block
 block discarded – undo
1000 1000
 	 * @param  integer $quiz_id
1001 1001
 	 * @return array of quiz questions
1002 1002
 	 */
1003
-	public static function lesson_quiz_questions( $quiz_id = 0 ) {
1003
+	public static function lesson_quiz_questions($quiz_id = 0) {
1004 1004
 		$questions_array = array();
1005
-		if ( 0 < $quiz_id ) {
1006
-			$question_args = array( 'post_type'         => 'question',
1005
+		if (0 < $quiz_id) {
1006
+			$question_args = array('post_type'         => 'question',
1007 1007
                                     'posts_per_page'       => -1,
1008 1008
                                     'orderby'           => 'ID',
1009 1009
                                     'order'             => 'ASC',
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
                                     'post_status'       => 'any',
1017 1017
                                     'suppress_filters'  => 0
1018 1018
                                 );
1019
-            $questions_array = get_posts( $question_args );
1019
+            $questions_array = get_posts($question_args);
1020 1020
         } // End If Statement
1021 1021
         return $questions_array;
1022 1022
 	} // End lesson_quiz_questions()
@@ -1026,25 +1026,25 @@  discard block
 block discarded – undo
1026 1026
 	 * @param  integer $course_id ID of course
1027 1027
 	 * @return integer            Pass mark for course
1028 1028
 	 */
1029
-	public static function sensei_course_pass_grade( $course_id = 0 ) {
1029
+	public static function sensei_course_pass_grade($course_id = 0) {
1030 1030
 
1031 1031
 
1032 1032
 		$course_passmark = 0;
1033 1033
 
1034
-		if( $course_id > 0 ) {
1035
-			$lessons = Sensei()->course->course_lessons( $course_id );
1034
+		if ($course_id > 0) {
1035
+			$lessons = Sensei()->course->course_lessons($course_id);
1036 1036
 			$lesson_count = 0;
1037 1037
 			$total_passmark = 0;
1038
-			foreach( $lessons as $lesson ) {
1038
+			foreach ($lessons as $lesson) {
1039 1039
 
1040 1040
 				// Get Quiz ID
1041
-				$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
1041
+				$quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
1042 1042
 
1043 1043
 				// Check for a pass being required
1044
-				$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1045
-				if ( $pass_required ) {
1044
+				$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1045
+				if ($pass_required) {
1046 1046
 					// Get quiz passmark
1047
-					$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1047
+					$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1048 1048
 
1049 1049
 					// Add up total passmark
1050 1050
 					$total_passmark += $quiz_passmark;
@@ -1053,12 +1053,12 @@  discard block
 block discarded – undo
1053 1053
 				}
1054 1054
 			}
1055 1055
 			// Might be a case of no required lessons
1056
-			if ( $lesson_count ) {
1057
-				$course_passmark = ( $total_passmark / $lesson_count );
1056
+			if ($lesson_count) {
1057
+				$course_passmark = ($total_passmark / $lesson_count);
1058 1058
 			}
1059 1059
 		}
1060 1060
 
1061
-		return Sensei_Utils::round( $course_passmark );
1061
+		return Sensei_Utils::round($course_passmark);
1062 1062
 	}
1063 1063
 
1064 1064
 	/**
@@ -1067,31 +1067,31 @@  discard block
 block discarded – undo
1067 1067
 	 * @param  integer $user_id   ID of user
1068 1068
 	 * @return integer            User's total grade
1069 1069
 	 */
1070
-	public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) {
1070
+	public static function sensei_course_user_grade($course_id = 0, $user_id = 0) {
1071 1071
 
1072 1072
 
1073
-		if( intval( $user_id ) == 0 ) {
1073
+		if (intval($user_id) == 0) {
1074 1074
 			$user_id = get_current_user_id();
1075 1075
 		}
1076 1076
 
1077 1077
 		$total_grade = 0;
1078 1078
 
1079
-		if( $course_id > 0 && $user_id > 0 ) {
1080
-			$lessons = Sensei()->course->course_lessons( $course_id );
1079
+		if ($course_id > 0 && $user_id > 0) {
1080
+			$lessons = Sensei()->course->course_lessons($course_id);
1081 1081
 			$lesson_count = 0;
1082 1082
 			$total_grade = 0;
1083
-			foreach( $lessons as $lesson ) {
1083
+			foreach ($lessons as $lesson) {
1084 1084
 
1085 1085
 				// Check for lesson having questions, thus a quiz, thus having a grade
1086
-				$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
1087
-				if ( $has_questions ) {
1088
-					$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id );
1086
+				$has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true);
1087
+				if ($has_questions) {
1088
+					$user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id);
1089 1089
 
1090
-					if(  empty( $user_lesson_status ) ){
1090
+					if (empty($user_lesson_status)) {
1091 1091
 						continue;
1092 1092
 					}
1093 1093
 					// Get user quiz grade
1094
-					$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1094
+					$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1095 1095
 
1096 1096
 					// Add up total grade
1097 1097
 					$total_grade += $quiz_grade;
@@ -1101,13 +1101,13 @@  discard block
 block discarded – undo
1101 1101
 			}
1102 1102
 
1103 1103
 			// Might be a case of no lessons with quizzes
1104
-			if ( $lesson_count ) {
1105
-				$total_grade = ( $total_grade / $lesson_count );
1104
+			if ($lesson_count) {
1105
+				$total_grade = ($total_grade / $lesson_count);
1106 1106
 			}
1107 1107
 
1108 1108
 		}
1109 1109
 
1110
-		return Sensei_Utils::round( $total_grade );
1110
+		return Sensei_Utils::round($total_grade);
1111 1111
 	}
1112 1112
 
1113 1113
 	/**
@@ -1116,18 +1116,18 @@  discard block
 block discarded – undo
1116 1116
 	 * @param  integer $user_id   ID of user
1117 1117
 	 * @return boolean
1118 1118
 	 */
1119
-	public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) {
1120
-		if( intval( $user_id ) == 0 ) {
1119
+	public static function sensei_user_passed_course($course_id = 0, $user_id = 0) {
1120
+		if (intval($user_id) == 0) {
1121 1121
 			$user_id = get_current_user_id();
1122 1122
 		}
1123 1123
 
1124 1124
 		$pass = false;
1125 1125
 
1126
-		if( $course_id > 0 && $user_id > 0 ) {
1127
-			$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id );
1128
-			$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id );
1126
+		if ($course_id > 0 && $user_id > 0) {
1127
+			$passmark = Sensei_Utils::sensei_course_pass_grade($course_id);
1128
+			$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id);
1129 1129
 
1130
-			if( $user_grade >= $passmark ) {
1130
+			if ($user_grade >= $passmark) {
1131 1131
 				$pass = true;
1132 1132
 			}
1133 1133
 		}
@@ -1141,37 +1141,37 @@  discard block
 block discarded – undo
1141 1141
 	 * @param  integer $course_id ID of course
1142 1142
 	 * @param  integer $user_id   ID of user
1143 1143
 	 */
1144
-	public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) {
1145
-		if( intval( $user_id ) == 0 ) {
1144
+	public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) {
1145
+		if (intval($user_id) == 0) {
1146 1146
 			$user_id = get_current_user_id();
1147 1147
 		}
1148 1148
 
1149 1149
 		$status = 'not_started';
1150 1150
 		$box_class = 'info';
1151
-		$message = __( 'You have not started this course yet.', 'woothemes-sensei' );
1151
+		$message = __('You have not started this course yet.', 'woothemes-sensei');
1152 1152
 
1153
-		if( $course_id > 0 && $user_id > 0 ) {
1153
+		if ($course_id > 0 && $user_id > 0) {
1154 1154
 
1155
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1155
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1156 1156
 
1157
-			if( $started_course ) {
1158
-				$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()!
1159
-				$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()!
1160
-				if( $user_grade >= $passmark ) {
1157
+			if ($started_course) {
1158
+				$passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()!
1159
+				$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()!
1160
+				if ($user_grade >= $passmark) {
1161 1161
 					$status = 'passed';
1162 1162
 					$box_class = 'tick';
1163
-					$message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade );
1163
+					$message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade);
1164 1164
 				} else {
1165 1165
 					$status = 'failed';
1166 1166
 					$box_class = 'alert';
1167
-					$message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade );
1167
+					$message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade);
1168 1168
 				}
1169 1169
 			}
1170 1170
 
1171 1171
 		}
1172 1172
 
1173
-		$message = apply_filters( 'sensei_user_course_status_' . $status, $message );
1174
-		Sensei()->notices->add_notice( $message, $box_class   );
1173
+		$message = apply_filters('sensei_user_course_status_'.$status, $message);
1174
+		Sensei()->notices->add_notice($message, $box_class);
1175 1175
 	}
1176 1176
 
1177 1177
 	/**
@@ -1181,94 +1181,94 @@  discard block
 block discarded – undo
1181 1181
      * @param  bool $is_lesson
1182 1182
 	 * @return array              Status code and message
1183 1183
 	 */
1184
-	public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
1184
+	public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) {
1185 1185
 		global  $current_user;
1186
-		if( intval( $user_id ) == 0 ) {
1186
+		if (intval($user_id) == 0) {
1187 1187
 			$user_id = $current_user->ID;
1188 1188
 		}
1189 1189
 
1190 1190
 		$status = 'not_started';
1191 1191
 		$box_class = 'info';
1192
-		$message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' );
1192
+		$message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei');
1193 1193
 		$extra = '';
1194 1194
 
1195
-		if( $lesson_id > 0 && $user_id > 0 ) {
1195
+		if ($lesson_id > 0 && $user_id > 0) {
1196 1196
 
1197 1197
 			// Prerequisite lesson
1198
-			$prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1198
+			$prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true);
1199 1199
 
1200 1200
 			// Course ID
1201
-			$course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) );
1201
+			$course_id = absint(get_post_meta($lesson_id, '_lesson_course', true));
1202 1202
 
1203 1203
 			// Has user started course
1204
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1204
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1205 1205
 
1206 1206
 			// Has user completed lesson
1207
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1208
-			$lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status );
1207
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1208
+			$lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status);
1209 1209
 
1210 1210
 			// Quiz ID
1211
-			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1211
+			$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1212 1212
 
1213 1213
 			// Quiz grade
1214 1214
 			$quiz_grade = 0;
1215
-			if ( $user_lesson_status ) {
1216
-				$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1215
+			if ($user_lesson_status) {
1216
+				$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1217 1217
 			}
1218 1218
 
1219 1219
 			// Quiz passmark
1220
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1220
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1221 1221
 			$quiz_passmark_float = (float) $quiz_passmark;
1222 1222
 
1223 1223
 			// Pass required
1224
-			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1224
+			$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1225 1225
 
1226 1226
 			// Quiz questions
1227
-			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1227
+			$has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1228 1228
 
1229
-			if ( ! $started_course ) {
1229
+			if ( ! $started_course) {
1230 1230
 
1231 1231
 				$status = 'not_started_course';
1232 1232
 				$box_class = 'info';
1233
-				$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>' );
1233
+				$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>');
1234 1234
 
1235
-			} elseif ( ! is_user_logged_in() ) {
1235
+			} elseif ( ! is_user_logged_in()) {
1236 1236
 
1237 1237
 				$status = 'login_required';
1238 1238
 				$box_class = 'info';
1239
-				$message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' );
1239
+				$message = __('You must be logged in to take this quiz', 'woothemes-sensei');
1240 1240
 
1241 1241
 			}
1242 1242
 			// Lesson/Quiz is marked as complete thus passing any quiz restrictions
1243
-			elseif ( $lesson_complete ) {
1243
+			elseif ($lesson_complete) {
1244 1244
 
1245 1245
 				$status = 'passed';
1246 1246
 				$box_class = 'tick';
1247 1247
 				// Lesson status will be "complete" (has no Quiz)
1248
-				if ( ! $has_quiz_questions ) {
1249
-					$message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) );
1248
+				if ( ! $has_quiz_questions) {
1249
+					$message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei'));
1250 1250
 				}
1251 1251
 				// Lesson status will be "graded" (no passmark required so might have failed all the questions)
1252
-				elseif ( empty( $quiz_grade ) ) {
1253
-					$message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) );
1252
+				elseif (empty($quiz_grade)) {
1253
+					$message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei'));
1254 1254
 				}
1255 1255
 				// Lesson status will be "passed" (passmark reached)
1256
-				elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) {
1257
-					if( $is_lesson ) {
1258
-						$message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) );
1256
+				elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) {
1257
+					if ($is_lesson) {
1258
+						$message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1259 1259
 					} else {
1260
-						$message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_grade ) );
1260
+						$message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1261 1261
 					}
1262 1262
 				}
1263 1263
 
1264 1264
                 // add next lesson button
1265
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1266
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1265
+                $nav_id_array = sensei_get_prev_next_lessons($lesson_id);
1266
+                $next_lesson_id = absint($nav_id_array['next_lesson']);
1267 1267
 
1268 1268
                 // Output HTML
1269
-                if ( ( 0 < $next_lesson_id ) ) {
1270
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1271
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1269
+                if ((0 < $next_lesson_id)) {
1270
+                    $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id))
1271
+                                . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei')
1272 1272
                                 .'</a>';
1273 1273
 
1274 1274
                 }
@@ -1277,52 +1277,52 @@  discard block
 block discarded – undo
1277 1277
             // Lesson/Quiz not complete
1278 1278
 			else {
1279 1279
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1280
-				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
1280
+				if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) {
1281 1281
 					$status = 'complete';
1282 1282
 					$box_class = 'info';
1283
-					if( $is_lesson ) {
1284
-						$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>' );
1283
+					if ($is_lesson) {
1284
+						$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>');
1285 1285
 					} else {
1286
-						$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 ) );
1287
-						$message .= sprintf( __( ' %1$sGo back to the lesson page%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . esc_attr( get_the_title( $lesson_id ) ) . '">', '</a>' );
1286
+						$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));
1287
+						$message .= sprintf(__(' %1$sGo back to the lesson page%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($lesson_id)).'" title="'.esc_attr(get_the_title($lesson_id)).'">', '</a>');
1288 1288
 					}
1289 1289
 				}
1290 1290
 				// Lesson status must be "failed"
1291
-				elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) {
1291
+				elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
1292 1292
 					$status = 'failed';
1293 1293
 					$box_class = 'alert';
1294
-					if( $is_lesson ) {
1295
-						$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 ) );
1294
+					if ($is_lesson) {
1295
+						$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));
1296 1296
 					} else {
1297
-						$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 ) );
1297
+						$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));
1298 1298
 					}
1299 1299
 				}
1300 1300
 				// Lesson/Quiz requires a pass
1301
-				elseif( $pass_required ) {
1301
+				elseif ($pass_required) {
1302 1302
 					$status = 'not_started';
1303 1303
 					$box_class = 'info';
1304
-					if( $is_lesson ) {
1305
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1304
+					if ($is_lesson) {
1305
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1306 1306
 					} else {
1307
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1307
+						$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1308 1308
 					}
1309 1309
 				}
1310 1310
 			}
1311 1311
 
1312
-		}else{
1312
+		} else {
1313 1313
 
1314
-			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1315
-			$a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
1316
-			$a_element .= __( 'course', 'woothemes-sensei' );
1314
+			$course_id = Sensei()->lesson->get_course_id($lesson_id);
1315
+			$a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
1316
+			$a_element .= __('course', 'woothemes-sensei');
1317 1317
 			$a_element .= '</a>';
1318 1318
 
1319
-			if ( Sensei_WC::is_course_purchasable( $course_id ) ){
1319
+			if (Sensei_WC::is_course_purchasable($course_id)) {
1320 1320
 
1321
-				$message = sprintf( __( 'Please purchase the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1321
+				$message = sprintf(__('Please purchase the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1322 1322
 
1323 1323
 			} else {
1324 1324
 
1325
-				$message = sprintf( __( 'Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1325
+				$message = sprintf(__('Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1326 1326
 
1327 1327
 			}
1328 1328
 
@@ -1330,15 +1330,15 @@  discard block
 block discarded – undo
1330 1330
 		}
1331 1331
 
1332 1332
 		// Legacy filter
1333
-		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1333
+		$message = apply_filters('sensei_user_quiz_status_'.$status, $message);
1334 1334
 
1335
-		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1336
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1337
-			$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>';
1335
+		if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) {
1336
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1337
+			$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>';
1338 1338
 		}
1339 1339
 
1340 1340
 		// Filter of all messages
1341
-		return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson );
1341
+		return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson);
1342 1342
 	}
1343 1343
 
1344 1344
 	/**
@@ -1348,14 +1348,14 @@  discard block
 block discarded – undo
1348 1348
 	 * @param  integer $course_id Course ID
1349 1349
 	 * @return mixed boolean or comment_ID
1350 1350
 	 */
1351
-	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1351
+	public static function user_start_course($user_id = 0, $course_id = 0) {
1352 1352
 
1353 1353
 		$activity_logged = false;
1354 1354
 
1355
-		if( $user_id && $course_id ) {
1355
+		if ($user_id && $course_id) {
1356 1356
 			// Check if user is already on the Course
1357
-			$activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id );
1358
-			if ( ! $activity_logged ) {
1357
+			$activity_logged = Sensei_Utils::user_started_course($course_id, $user_id);
1358
+			if ( ! $activity_logged) {
1359 1359
 
1360 1360
 				// Add user to course
1361 1361
 				$course_metadata = array(
@@ -1364,11 +1364,11 @@  discard block
 block discarded – undo
1364 1364
 					'complete' => 0,
1365 1365
 				);
1366 1366
 
1367
-				$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata );
1367
+				$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata);
1368 1368
 
1369 1369
 				// Allow further actions
1370
-				if ( $activity_logged ) {
1371
-					do_action( 'sensei_user_course_start', $user_id, $course_id );
1370
+				if ($activity_logged) {
1371
+					do_action('sensei_user_course_start', $user_id, $course_id);
1372 1372
 				}
1373 1373
 			}
1374 1374
 		}
@@ -1384,19 +1384,19 @@  discard block
 block discarded – undo
1384 1384
 	 * @param int $user_id
1385 1385
 	 * @return mixed false or comment_ID
1386 1386
 	 */
1387
-	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1387
+	public static function user_started_course($course_id = 0, $user_id = 0) {
1388 1388
 
1389
-		if( $course_id ) {
1390
-			if( ! $user_id ) {
1389
+		if ($course_id) {
1390
+			if ( ! $user_id) {
1391 1391
 				$user_id = get_current_user_id();
1392 1392
 			}
1393 1393
 
1394
-            if( ! $user_id > 0 ){
1394
+            if ( ! $user_id > 0) {
1395 1395
                 return false;
1396 1396
             }
1397 1397
 
1398
-			$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' ) );
1399
-			if( $user_course_status_id ) {
1398
+			$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'));
1399
+			if ($user_course_status_id) {
1400 1400
 				return $user_course_status_id;
1401 1401
 			}
1402 1402
 		}
@@ -1411,17 +1411,17 @@  discard block
 block discarded – undo
1411 1411
 	 * @param  integer $user_id   User ID
1412 1412
 	 * @return int
1413 1413
 	 */
1414
-	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1414
+	public static function user_complete_course($course_id = 0, $user_id = 0) {
1415 1415
 		global  $wp_version;
1416 1416
 
1417
-		if( $course_id ) {
1418
-			if( ! $user_id ) {
1417
+		if ($course_id) {
1418
+			if ( ! $user_id) {
1419 1419
 				$user_id = get_current_user_id();
1420 1420
 			}
1421 1421
 
1422 1422
 			$course_status = 'in-progress';
1423 1423
 			$course_metadata = array();
1424
-			$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1424
+			$course_completion = Sensei()->settings->settings['course_completion'];
1425 1425
 			$lessons_completed = $total_lessons = 0;
1426 1426
 			$lesson_status_args = array(
1427 1427
 					'user_id' => $user_id,
@@ -1430,8 +1430,8 @@  discard block
 block discarded – undo
1430 1430
 				);
1431 1431
 
1432 1432
 			// Grab all of this Courses' lessons, looping through each...
1433
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
1434
-			$total_lessons = count( $lesson_ids );
1433
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
1434
+			$total_lessons = count($lesson_ids);
1435 1435
 				// ...if course completion not set to 'passed', and all lessons are complete or graded,
1436 1436
 				// ......then all lessons are 'passed'
1437 1437
 				// ...else if course completion is set to 'passed', check if each lesson has questions...
@@ -1444,29 +1444,29 @@  discard block
 block discarded – undo
1444 1444
 			// The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson()
1445 1445
 			$all_lesson_statuses = array();
1446 1446
 			// In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs
1447
-			if ( version_compare($wp_version, '4.1', '>=') ) {
1447
+			if (version_compare($wp_version, '4.1', '>=')) {
1448 1448
 				$lesson_status_args['post__in'] = $lesson_ids;
1449
-				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1449
+				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1450 1450
 				// Need to always return an array, even with only 1 item
1451
-				if ( !is_array($all_lesson_statuses) ) {
1452
-					$all_lesson_statuses = array( $all_lesson_statuses );
1451
+				if ( ! is_array($all_lesson_statuses)) {
1452
+					$all_lesson_statuses = array($all_lesson_statuses);
1453 1453
 				}
1454 1454
 			}
1455 1455
 			// ...otherwise check each one
1456 1456
 			else {
1457
-				foreach( $lesson_ids as $lesson_id ) {
1457
+				foreach ($lesson_ids as $lesson_id) {
1458 1458
 					$lesson_status_args['post_id'] = $lesson_id;
1459
-					$each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1459
+					$each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1460 1460
 					// Check for valid return before using
1461
-					if ( !empty($each_lesson_status->comment_approved) ) {
1461
+					if ( ! empty($each_lesson_status->comment_approved)) {
1462 1462
 						$all_lesson_statuses[] = $each_lesson_status;
1463 1463
 					}
1464 1464
 				}
1465 1465
 			}
1466
-			foreach( $all_lesson_statuses as $lesson_status ) {
1466
+			foreach ($all_lesson_statuses as $lesson_status) {
1467 1467
 				// If lessons are complete without needing quizzes to be passed
1468
-				if ( 'passed' != $course_completion ) {
1469
-					switch ( $lesson_status->comment_approved ) {
1468
+				if ('passed' != $course_completion) {
1469
+					switch ($lesson_status->comment_approved) {
1470 1470
 						// A user cannot 'complete' a course if a lesson...
1471 1471
 						case 'in-progress': // ...is still in progress
1472 1472
 						case 'ungraded': // ...hasn't yet been graded
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
 					}
1479 1479
 				}
1480 1480
 				else {
1481
-					switch ( $lesson_status->comment_approved ) {
1481
+					switch ($lesson_status->comment_approved) {
1482 1482
 						case 'complete': // Lesson has no quiz/questions
1483 1483
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
1484 1484
 						case 'passed': // Lesson has quiz and the user passed
@@ -1492,20 +1492,20 @@  discard block
 block discarded – undo
1492 1492
 					}
1493 1493
 				}
1494 1494
 			} // Each lesson
1495
-			if ( $lessons_completed == $total_lessons ) {
1495
+			if ($lessons_completed == $total_lessons) {
1496 1496
 				$course_status = 'complete';
1497 1497
 			}
1498 1498
 
1499 1499
 			// Update meta data on how many lessons have been completed
1500 1500
 			$course_metadata['complete'] = $lessons_completed;
1501 1501
 			// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1502
-			$course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1502
+			$course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1503 1503
 
1504
-			$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata );
1504
+			$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata);
1505 1505
 
1506 1506
 			// Allow further actions
1507
-			if ( 'complete' == $course_status ) {
1508
-				do_action( 'sensei_user_course_end', $user_id, $course_id );
1507
+			if ('complete' == $course_status) {
1508
+				do_action('sensei_user_course_end', $user_id, $course_id);
1509 1509
 			}
1510 1510
 			return $activity_logged;
1511 1511
 		}
@@ -1521,40 +1521,40 @@  discard block
 block discarded – undo
1521 1521
 	 * @param int $user_id
1522 1522
 	 * @return boolean
1523 1523
 	 */
1524
-	public static function user_completed_course( $course , $user_id = 0 ) {
1524
+	public static function user_completed_course($course, $user_id = 0) {
1525 1525
 
1526
-		if( $course ) {
1527
-			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1526
+		if ($course) {
1527
+			if (is_object($course) && is_a($course, 'WP_Comment')) {
1528 1528
 				$user_course_status = $course->comment_approved;
1529 1529
 			}
1530
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1530
+			elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) {
1531 1531
 				$user_course_status = $course;
1532 1532
 			}
1533 1533
 			else {
1534 1534
 
1535 1535
 				// check the user_id
1536
-				if( ! $user_id ) {
1536
+				if ( ! $user_id) {
1537 1537
 
1538 1538
 					$user_id = get_current_user_id();
1539 1539
 
1540
-					if( empty( $user_id ) ){
1540
+					if (empty($user_id)) {
1541 1541
 
1542 1542
 						return false;
1543 1543
 
1544 1544
 					}
1545 1545
 				}
1546 1546
 
1547
-                if( is_a( $course, 'WP_Post' ) ){
1548
-                    $course =   $course->ID;
1547
+                if (is_a($course, 'WP_Post')) {
1548
+                    $course = $course->ID;
1549 1549
                 }
1550 1550
 
1551
-				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1552
-				if( isset( $user_course_status->comment_approved ) ){
1551
+				$user_course_status = Sensei_Utils::user_course_status($course, $user_id);
1552
+				if (isset($user_course_status->comment_approved)) {
1553 1553
                     $user_course_status = $user_course_status->comment_approved;
1554 1554
                 }
1555 1555
 
1556 1556
 			}
1557
-			if( $user_course_status && 'complete' == $user_course_status ) {
1557
+			if ($user_course_status && 'complete' == $user_course_status) {
1558 1558
 				return true;
1559 1559
 			}
1560 1560
 		}
@@ -1569,10 +1569,10 @@  discard block
 block discarded – undo
1569 1569
 	 * @param int $user_id
1570 1570
 	 * @return mixed false or comment_ID
1571 1571
 	 */
1572
-	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1572
+	public static function user_started_lesson($lesson_id = 0, $user_id = 0) {
1573 1573
 
1574
-		if( $lesson_id ) {
1575
-			if( ! $user_id ) {
1574
+		if ($lesson_id) {
1575
+			if ( ! $user_id) {
1576 1576
 				$user_id = get_current_user_id();
1577 1577
 			}
1578 1578
 
@@ -1582,8 +1582,8 @@  discard block
 block discarded – undo
1582 1582
                 'type' => 'sensei_lesson_status',
1583 1583
                 'field' => 'comment_ID' );
1584 1584
 
1585
-			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1586
-			if( $user_lesson_status_id ) {
1585
+			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1586
+			if ($user_lesson_status_id) {
1587 1587
 				return $user_lesson_status_id;
1588 1588
 			}
1589 1589
 		}
@@ -1598,29 +1598,29 @@  discard block
 block discarded – undo
1598 1598
 	 * @param int $user_id
1599 1599
 	 * @return boolean
1600 1600
 	 */
1601
-	public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) {
1601
+	public static function user_completed_lesson($lesson = 0, $user_id = 0) {
1602 1602
 
1603
-		if( $lesson ) {
1603
+		if ($lesson) {
1604 1604
 			$lesson_id = 0;
1605
-			if ( is_object( $lesson ) ) {
1605
+			if (is_object($lesson)) {
1606 1606
 				$user_lesson_status = $lesson->comment_approved;
1607 1607
 				$lesson_id = $lesson->comment_post_ID;
1608 1608
 			}
1609
-			elseif ( ! is_numeric( $lesson ) ) {
1609
+			elseif ( ! is_numeric($lesson)) {
1610 1610
 				$user_lesson_status = $lesson;
1611 1611
 			}
1612 1612
 			else {
1613
-				if( ! $user_id ) {
1613
+				if ( ! $user_id) {
1614 1614
 					$user_id = get_current_user_id();
1615 1615
 				}
1616 1616
 
1617 1617
                 // the user is not logged in
1618
-                if( ! $user_id > 0 ){
1618
+                if ( ! $user_id > 0) {
1619 1619
                     return false;
1620 1620
                 }
1621
-				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1621
+				$_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id);
1622 1622
 
1623
-				if ( $_user_lesson_status ) {
1623
+				if ($_user_lesson_status) {
1624 1624
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1625 1625
 				}
1626 1626
 				else {
@@ -1628,12 +1628,12 @@  discard block
 block discarded – undo
1628 1628
 				}
1629 1629
 				$lesson_id = $lesson;
1630 1630
 			}
1631
-			if ( 'in-progress' != $user_lesson_status ) {
1631
+			if ('in-progress' != $user_lesson_status) {
1632 1632
 				// Check for Passed or Completed Setting
1633 1633
 				// Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting
1634 1634
 //				$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1635 1635
 //				if ( 'passed' == $course_completion ) {
1636
-					switch( $user_lesson_status ) {
1636
+					switch ($user_lesson_status) {
1637 1637
 						case 'complete':
1638 1638
 						case 'graded':
1639 1639
 						case 'passed':
@@ -1642,13 +1642,13 @@  discard block
 block discarded – undo
1642 1642
 
1643 1643
 						case 'failed':
1644 1644
 							// This may be 'completed' depending on...
1645
-							if ( $lesson_id ) {
1645
+							if ($lesson_id) {
1646 1646
 								// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson
1647
-								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1648
-								if ( $lesson_quiz_id ) {
1647
+								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1648
+								if ($lesson_quiz_id) {
1649 1649
 									// ...the quiz pass setting
1650
-									$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
1651
-									if ( empty($pass_required) ) {
1650
+									$pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true);
1651
+									if (empty($pass_required)) {
1652 1652
 										// We just require the user to have done the quiz, not to have passed
1653 1653
 										return true;
1654 1654
 									}
@@ -1671,15 +1671,15 @@  discard block
 block discarded – undo
1671 1671
 	 * @param int $user_id
1672 1672
 	 * @return object
1673 1673
 	 */
1674
-	public static function user_course_status( $course_id = 0, $user_id = 0 ) {
1674
+	public static function user_course_status($course_id = 0, $user_id = 0) {
1675 1675
 
1676 1676
 
1677
-		if( $course_id ) {
1678
-			if( ! $user_id ) {
1677
+		if ($course_id) {
1678
+			if ( ! $user_id) {
1679 1679
 				$user_id = get_current_user_id();
1680 1680
 			}
1681 1681
 
1682
-			$user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true );
1682
+			$user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true);
1683 1683
 			return $user_course_status;
1684 1684
 		}
1685 1685
 
@@ -1694,27 +1694,27 @@  discard block
 block discarded – undo
1694 1694
 	 * @param int $user_id
1695 1695
 	 * @return object | bool
1696 1696
 	 */
1697
-	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1697
+	public static function user_lesson_status($lesson_id = 0, $user_id = 0) {
1698 1698
 
1699
-        if( ! $user_id ) {
1699
+        if ( ! $user_id) {
1700 1700
             $user_id = get_current_user_id();
1701 1701
         }
1702 1702
 
1703
-		if( $lesson_id > 0 && $user_id > 0 ) {
1703
+		if ($lesson_id > 0 && $user_id > 0) {
1704 1704
 
1705
-			$user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true );
1705
+			$user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true);
1706 1706
 			return $user_lesson_status;
1707 1707
 		}
1708 1708
 
1709 1709
 		return false;
1710 1710
 	}
1711 1711
 
1712
-	public static function is_preview_lesson( $lesson_id ) {
1712
+	public static function is_preview_lesson($lesson_id) {
1713 1713
 		$is_preview = false;
1714 1714
 
1715
-		if( 'lesson' == get_post_type( $lesson_id ) ) {
1716
-			$lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true );
1717
-			if ( isset( $lesson_preview ) && '' != $lesson_preview ) {
1715
+		if ('lesson' == get_post_type($lesson_id)) {
1716
+			$lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true);
1717
+			if (isset($lesson_preview) && '' != $lesson_preview) {
1718 1718
 				$is_preview = true;
1719 1719
 			}
1720 1720
 		}
@@ -1722,22 +1722,22 @@  discard block
 block discarded – undo
1722 1722
 		return $is_preview;
1723 1723
 	}
1724 1724
 
1725
-	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1725
+	public static function user_passed_quiz($quiz_id = 0, $user_id = 0) {
1726 1726
 
1727
-		if( ! $quiz_id  ) return false;
1727
+		if ( ! $quiz_id) return false;
1728 1728
 
1729
-		if( ! $user_id ) {
1729
+		if ( ! $user_id) {
1730 1730
 			$user_id = get_current_user_id();
1731 1731
 		}
1732
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1732
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1733 1733
 
1734 1734
 		// Quiz Grade
1735
-		$lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1736
-		$quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
1735
+		$lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1736
+		$quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
1737 1737
 
1738 1738
 		// Check if Grade is greater than or equal to pass percentage
1739
-		$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
1740
-		if ( $quiz_passmark <= intval( $quiz_grade ) ) {
1739
+		$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
1740
+		if ($quiz_passmark <= intval($quiz_grade)) {
1741 1741
 			return true;
1742 1742
 		}
1743 1743
 
@@ -1757,9 +1757,9 @@  discard block
 block discarded – undo
1757 1757
      *
1758 1758
 	 * @return mixed false or comment_ID
1759 1759
 	 */
1760
-	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1760
+	public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) {
1761 1761
 		$comment_id = false;
1762
-		if ( !empty($status) ) {
1762
+		if ( ! empty($status)) {
1763 1763
 			$args = array(
1764 1764
 					'user_id'   => $user_id,
1765 1765
 					'post_id'   => $lesson_id,
@@ -1768,18 +1768,18 @@  discard block
 block discarded – undo
1768 1768
 					'action'    => 'update', // Update the existing status...
1769 1769
 					'keep_time' => true, // ...but don't change the existing timestamp
1770 1770
 				);
1771
-			if( 'in-progress' == $status ) {
1772
-				unset( $args['keep_time'] ); // Keep updating what's happened
1771
+			if ('in-progress' == $status) {
1772
+				unset($args['keep_time']); // Keep updating what's happened
1773 1773
 			}
1774 1774
 
1775
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1776
-			if ( $comment_id && !empty($metadata) ) {
1777
-				foreach( $metadata as $key => $value ) {
1778
-					update_comment_meta( $comment_id, $key, $value );
1775
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1776
+			if ($comment_id && ! empty($metadata)) {
1777
+				foreach ($metadata as $key => $value) {
1778
+					update_comment_meta($comment_id, $key, $value);
1779 1779
 				}
1780 1780
 			}
1781 1781
 
1782
-			do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id );
1782
+			do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id);
1783 1783
 		}
1784 1784
 		return $comment_id;
1785 1785
 	}
@@ -1795,9 +1795,9 @@  discard block
 block discarded – undo
1795 1795
 	 * @param array $metadata
1796 1796
 	 * @return mixed false or comment_ID
1797 1797
 	 */
1798
-	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1798
+	public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) {
1799 1799
 		$comment_id = false;
1800
-		if ( !empty($status) ) {
1800
+		if ( ! empty($status)) {
1801 1801
 			$args = array(
1802 1802
 					'user_id'   => $user_id,
1803 1803
 					'post_id'   => $course_id,
@@ -1806,17 +1806,17 @@  discard block
 block discarded – undo
1806 1806
 					'action'    => 'update', // Update the existing status...
1807 1807
 					'keep_time' => true, // ...but don't change the existing timestamp
1808 1808
 				);
1809
-			if( 'in-progress' == $status ) {
1810
-				unset( $args['keep_time'] ); // Keep updating what's happened
1809
+			if ('in-progress' == $status) {
1810
+				unset($args['keep_time']); // Keep updating what's happened
1811 1811
 			}
1812 1812
 
1813
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1814
-			if ( $comment_id && !empty($metadata) ) {
1815
-				foreach( $metadata as $key => $value ) {
1816
-					update_comment_meta( $comment_id, $key, $value );
1813
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1814
+			if ($comment_id && ! empty($metadata)) {
1815
+				foreach ($metadata as $key => $value) {
1816
+					update_comment_meta($comment_id, $key, $value);
1817 1817
 				}
1818 1818
 			}
1819
-			do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id );
1819
+			do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id);
1820 1820
 		}
1821 1821
 		return $comment_id;
1822 1822
 	}
@@ -1828,9 +1828,9 @@  discard block
 block discarded – undo
1828 1828
 	 * @param  array $pieces (default: array())
1829 1829
 	 * @return array
1830 1830
 	 */
1831
-	public static function single_comment_filter( $pieces ) {
1832
-		unset( $pieces['orderby'] );
1833
-		unset( $pieces['order'] );
1831
+	public static function single_comment_filter($pieces) {
1832
+		unset($pieces['orderby']);
1833
+		unset($pieces['order']);
1834 1834
 
1835 1835
 		return $pieces;
1836 1836
 	}
@@ -1842,9 +1842,9 @@  discard block
 block discarded – undo
1842 1842
 	 * @param  array $pieces (default: array())
1843 1843
 	 * @return array
1844 1844
 	 */
1845
-	public static function comment_any_status_filter( $pieces ) {
1845
+	public static function comment_any_status_filter($pieces) {
1846 1846
 
1847
-		$pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] );
1847
+		$pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']);
1848 1848
 
1849 1849
 		return $pieces;
1850 1850
 	}
@@ -1856,12 +1856,12 @@  discard block
 block discarded – undo
1856 1856
 	 * @param  array $pieces (default: array())
1857 1857
 	 * @return array
1858 1858
 	 */
1859
-	public static function comment_multiple_status_filter( $pieces ) {
1859
+	public static function comment_multiple_status_filter($pieces) {
1860 1860
 
1861
-		preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder );
1862
-		if ( !empty($placeholder[1]) ) {
1863
-			$statuses = explode( ',', $placeholder[1] );
1864
-			$pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] );
1861
+		preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder);
1862
+		if ( ! empty($placeholder[1])) {
1863
+			$statuses = explode(',', $placeholder[1]);
1864
+			$pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']);
1865 1865
 		}
1866 1866
 
1867 1867
 		return $pieces;
@@ -1873,12 +1873,12 @@  discard block
 block discarded – undo
1873 1873
      * @param array $pieces
1874 1874
 	 * @return array $pieces
1875 1875
 	 */
1876
-	public static function comment_total_sum_meta_value_filter( $pieces ) {
1876
+	public static function comment_total_sum_meta_value_filter($pieces) {
1877 1877
 		global $wpdb, $wp_version;
1878 1878
 
1879 1879
 		$pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum ";
1880
-		unset( $pieces['groupby'] );
1881
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1880
+		unset($pieces['groupby']);
1881
+		if (version_compare($wp_version, '4.1', '>=')) {
1882 1882
 			$args['order'] = false;
1883 1883
 			$args['orderby'] = false;
1884 1884
 		}
@@ -1893,12 +1893,12 @@  discard block
 block discarded – undo
1893 1893
 	 * @param  array $pieces (default: array())
1894 1894
 	 * @return array
1895 1895
 	 */
1896
-	public static function get_posts_count_only_filter( $pieces ) {
1896
+	public static function get_posts_count_only_filter($pieces) {
1897 1897
 		global $wp_version;
1898 1898
 
1899 1899
 		$pieces['fields'] = " COUNT(*) AS total ";
1900
-		unset( $pieces['groupby'] );
1901
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1900
+		unset($pieces['groupby']);
1901
+		if (version_compare($wp_version, '4.1', '>=')) {
1902 1902
 			$args['order'] = false;
1903 1903
 			$args['orderby'] = false;
1904 1904
 		}
@@ -1917,9 +1917,9 @@  discard block
 block discarded – undo
1917 1917
      *
1918 1918
      * @return bool $success
1919 1919
      */
1920
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1920
+    public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1921 1921
 
1922
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1922
+        return self::update_user_data($data_key, $post_id, $value, $user_id);
1923 1923
 
1924 1924
     }// end add_user_data
1925 1925
 
@@ -1938,18 +1938,18 @@  discard block
 block discarded – undo
1938 1938
      *
1939 1939
      * @return bool $success
1940 1940
      */
1941
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1941
+    public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1942 1942
 
1943
-        if( ! ( $user_id > 0 ) ){
1943
+        if ( ! ($user_id > 0)) {
1944 1944
             $user_id = get_current_user_id();
1945 1945
         }
1946 1946
 
1947
-        $supported_post_types = array( 'course', 'lesson' );
1948
-        $post_type = get_post_type( $post_id );
1949
-        if( empty( $post_id ) || empty( $data_key )
1950
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1951
-            || !get_userdata( $user_id )
1952
-            || ! in_array( $post_type, $supported_post_types )  ){
1947
+        $supported_post_types = array('course', 'lesson');
1948
+        $post_type = get_post_type($post_id);
1949
+        if (empty($post_id) || empty($data_key)
1950
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1951
+            || ! get_userdata($user_id)
1952
+            || ! in_array($post_type, $supported_post_types)) {
1953 1953
 
1954 1954
             return false;
1955 1955
         }
@@ -1957,20 +1957,20 @@  discard block
 block discarded – undo
1957 1957
         // check if there and existing Sensei status on this post type if not create it
1958 1958
         // and get the  activity ID
1959 1959
         $status_function = 'user_'.$post_type.'_status';
1960
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1961
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1960
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1961
+        if ( ! isset($sensei_user_status->comment_ID)) {
1962 1962
 
1963 1963
             $start_function = 'user_start_'.$post_type;
1964
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1964
+            $sensei_user_activity_id = self::$start_function($user_id, $post_id);
1965 1965
 
1966
-        }else{
1966
+        } else {
1967 1967
 
1968 1968
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1969 1969
 
1970 1970
         }
1971 1971
 
1972 1972
         // store the data
1973
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1973
+        $success = update_comment_meta($sensei_user_activity_id, $data_key, $value);
1974 1974
 
1975 1975
        return $success;
1976 1976
 
@@ -1989,20 +1989,20 @@  discard block
 block discarded – undo
1989 1989
      *
1990 1990
      * @return mixed $user_data_value
1991 1991
      */
1992
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1992
+    public static function get_user_data($data_key, $post_id, $user_id = 0) {
1993 1993
 
1994 1994
         $user_data_value = true;
1995 1995
 
1996
-        if( ! ( $user_id > 0 ) ){
1996
+        if ( ! ($user_id > 0)) {
1997 1997
             $user_id = get_current_user_id();
1998 1998
         }
1999 1999
 
2000
-        $supported_post_types = array( 'course', 'lesson' );
2001
-        $post_type = get_post_type( $post_id );
2002
-        if( empty( $post_id ) || empty( $data_key )
2003
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2004
-            || ! get_userdata( $user_id )
2005
-            || !in_array( $post_type, $supported_post_types )  ){
2000
+        $supported_post_types = array('course', 'lesson');
2001
+        $post_type = get_post_type($post_id);
2002
+        if (empty($post_id) || empty($data_key)
2003
+            || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2004
+            || ! get_userdata($user_id)
2005
+            || ! in_array($post_type, $supported_post_types)) {
2006 2006
 
2007 2007
             return false;
2008 2008
         }
@@ -2010,13 +2010,13 @@  discard block
 block discarded – undo
2010 2010
         // check if there and existing Sensei status on this post type if not create it
2011 2011
         // and get the  activity ID
2012 2012
         $status_function = 'user_'.$post_type.'_status';
2013
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2014
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2013
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2014
+        if ( ! isset($sensei_user_status->comment_ID)) {
2015 2015
             return false;
2016 2016
         }
2017 2017
 
2018 2018
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2019
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2019
+        $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true);
2020 2020
 
2021 2021
         return $user_data_value;
2022 2022
 
@@ -2031,19 +2031,19 @@  discard block
 block discarded – undo
2031 2031
      *
2032 2032
      * @return bool $deleted
2033 2033
      */
2034
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2034
+    public static function delete_user_data($data_key, $post_id, $user_id) {
2035 2035
         $deleted = true;
2036 2036
 
2037
-        if( ! ( $user_id > 0 ) ){
2037
+        if ( ! ($user_id > 0)) {
2038 2038
             $user_id = get_current_user_id();
2039 2039
         }
2040 2040
 
2041
-        $supported_post_types = array( 'course', 'lesson' );
2042
-        $post_type = get_post_type( $post_id );
2043
-        if( empty( $post_id ) || empty( $data_key )
2044
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2045
-            || ! get_userdata( $user_id )
2046
-            || !in_array( $post_type, $supported_post_types )  ){
2041
+        $supported_post_types = array('course', 'lesson');
2042
+        $post_type = get_post_type($post_id);
2043
+        if (empty($post_id) || empty($data_key)
2044
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2045
+            || ! get_userdata($user_id)
2046
+            || ! in_array($post_type, $supported_post_types)) {
2047 2047
 
2048 2048
             return false;
2049 2049
         }
@@ -2051,13 +2051,13 @@  discard block
 block discarded – undo
2051 2051
         // check if there and existing Sensei status on this post type if not create it
2052 2052
         // and get the  activity ID
2053 2053
         $status_function = 'user_'.$post_type.'_status';
2054
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2055
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2054
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2055
+        if ( ! isset($sensei_user_status->comment_ID)) {
2056 2056
             return false;
2057 2057
         }
2058 2058
 
2059 2059
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2060
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2060
+        $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
2061 2061
 
2062 2062
         return $deleted;
2063 2063
 
@@ -2082,62 +2082,62 @@  discard block
 block discarded – undo
2082 2082
      *
2083 2083
      * @return string $drop_down_element
2084 2084
      */
2085
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2085
+    public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) {
2086 2086
 
2087 2087
         $drop_down_element = '';
2088 2088
 
2089 2089
         // setup the basic attributes
2090
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2090
+        if ( ! isset($attributes['name']) || empty($attributes['name'])) {
2091 2091
 
2092 2092
             $attributes['name'] = 'sensei-options';
2093 2093
 
2094 2094
         }
2095 2095
 
2096
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2096
+        if ( ! isset($attributes['id']) || empty($attributes['id'])) {
2097 2097
 
2098 2098
             $attributes['id'] = 'sensei-options';
2099 2099
 
2100 2100
         }
2101 2101
 
2102
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2102
+        if ( ! isset($attributes['class']) || empty($attributes['class'])) {
2103 2103
 
2104
-            $attributes['class'] ='chosen_select widefat';
2104
+            $attributes['class'] = 'chosen_select widefat';
2105 2105
 
2106 2106
         }
2107 2107
 
2108 2108
         // create element attributes
2109 2109
         $combined_attributes = '';
2110
-        foreach( $attributes as $attribute => $value ){
2110
+        foreach ($attributes as $attribute => $value) {
2111 2111
 
2112
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2112
+            $combined_attributes .= $attribute.'="'.$value.'"'.' ';
2113 2113
 
2114 2114
         }// end for each
2115 2115
 
2116 2116
 
2117 2117
         // create the select element
2118
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2118
+        $drop_down_element .= '<select '.$combined_attributes.' >'."\n";
2119 2119
 
2120 2120
         // show the none option if the client requested
2121
-        if( $enable_none_option ) {
2122
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2121
+        if ($enable_none_option) {
2122
+            $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
2123 2123
         }
2124 2124
 
2125
-        if ( count( $options ) > 0 ) {
2125
+        if (count($options) > 0) {
2126 2126
 
2127
-            foreach ($options as $value => $option ){
2127
+            foreach ($options as $value => $option) {
2128 2128
 
2129 2129
                 $element = '';
2130
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2131
-                $element .= selected( $value, $selected_value, false ) . '>';
2132
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2130
+                $element .= '<option value="'.esc_attr($value).'"';
2131
+                $element .= selected($value, $selected_value, false).'>';
2132
+                $element .= esc_html($option).'</option>'."\n";
2133 2133
 
2134 2134
                 // add the element to the select html
2135
-                $drop_down_element.= $element;
2135
+                $drop_down_element .= $element;
2136 2136
             } // End For Loop
2137 2137
 
2138 2138
         } // End If Statement
2139 2139
 
2140
-        $drop_down_element .= '</select>' . "\n";
2140
+        $drop_down_element .= '</select>'."\n";
2141 2141
 
2142 2142
         return $drop_down_element;
2143 2143
 
@@ -2157,14 +2157,14 @@  discard block
 block discarded – undo
2157 2157
      *
2158 2158
      * @return double $val
2159 2159
      */
2160
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2160
+    public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') {
2161 2161
 
2162 2162
         /**å
2163 2163
          * Change the precision for the Sensei_Utils::round function.
2164 2164
          * the precision given will be passed into the php round function
2165 2165
          * @since 1.8.5
2166 2166
          */
2167
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2167
+        $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode);
2168 2168
 
2169 2169
         /**
2170 2170
          * Change the mode for the Sensei_Utils::round function.
@@ -2174,15 +2174,15 @@  discard block
 block discarded – undo
2174 2174
          *
2175 2175
          * @since 1.8.5
2176 2176
          */
2177
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2177
+        $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision);
2178 2178
 
2179
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2179
+        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
2180 2180
 
2181
-            return round( $val, $precision, $mode );
2181
+            return round($val, $precision, $mode);
2182 2182
 
2183
-        }else{
2183
+        } else {
2184 2184
 
2185
-            return round( $val, $precision );
2185
+            return round($val, $precision);
2186 2186
 
2187 2187
         }
2188 2188
 
@@ -2194,15 +2194,15 @@  discard block
 block discarded – undo
2194 2194
      * @since 1.9.0
2195 2195
      * @return string $url
2196 2196
      */
2197
-    public static function get_current_url(){
2197
+    public static function get_current_url() {
2198 2198
 
2199 2199
         global $wp;
2200
-        $current_url = trailingslashit( home_url( $wp->request ) );
2201
-        if ( isset( $_GET ) ) {
2200
+        $current_url = trailingslashit(home_url($wp->request));
2201
+        if (isset($_GET)) {
2202 2202
 
2203
-            foreach ($_GET as $param => $val ) {
2203
+            foreach ($_GET as $param => $val) {
2204 2204
 
2205
-                $current_url = add_query_arg( $param, $val , $current_url );
2205
+                $current_url = add_query_arg($param, $val, $current_url);
2206 2206
 
2207 2207
             }
2208 2208
         }
@@ -2232,27 +2232,27 @@  discard block
 block discarded – undo
2232 2232
      * @param array $array_b
2233 2233
      * @return array $merged_array
2234 2234
      */
2235
-    public static function array_zip_merge( $array_a, $array_b ){
2235
+    public static function array_zip_merge($array_a, $array_b) {
2236 2236
 
2237
-        if( ! is_array( $array_a ) || ! is_array( $array_b )  ){
2237
+        if ( ! is_array($array_a) || ! is_array($array_b)) {
2238 2238
             trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2239 2239
         }
2240 2240
 
2241 2241
         $merged_array = array();
2242
-        $total_elements = count( $array_a )  + count( $array_b );
2242
+        $total_elements = count($array_a) + count($array_b);
2243 2243
 
2244 2244
         // Zip arrays
2245
-        for ( $i = 0; $i < $total_elements; $i++) {
2245
+        for ($i = 0; $i < $total_elements; $i++) {
2246 2246
 
2247 2247
             // if has an element at current index push a on top
2248
-            if( isset( $array_a[ $i ] ) ){
2249
-                $merged_array[] = $array_a[ $i ]  ;
2248
+            if (isset($array_a[$i])) {
2249
+                $merged_array[] = $array_a[$i];
2250 2250
             }
2251 2251
 
2252 2252
             // next if $array_b has an element at current index push a on top of the element
2253 2253
             // from a if there was one, if not the element before that.
2254
-            if( isset( $array_b[ $i ] ) ){
2255
-                $merged_array[] = $array_b[ $i ]  ;
2254
+            if (isset($array_b[$i])) {
2255
+                $merged_array[] = $array_b[$i];
2256 2256
             }
2257 2257
 
2258 2258
         }
@@ -2267,4 +2267,4 @@  discard block
 block discarded – undo
2267 2267
  * @ignore only for backward compatibility
2268 2268
  * @since 1.9.0
2269 2269
  */
2270
-class WooThemes_Sensei_Utils extends Sensei_Utils{}
2271 2270
\ No newline at end of file
2271
+class WooThemes_Sensei_Utils extends Sensei_Utils {}
2272 2272
\ No newline at end of file
Please login to merge, or discard this patch.