Completed
Push — master ( 41ac09...b67cca )
by Dwain
05:16
created
includes/class-sensei-utils.php 1 patch
Spacing   +543 added lines, -543 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,51 +1277,51 @@  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 ) );
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 1287
 					}
1288 1288
 				}
1289 1289
 				// Lesson status must be "failed"
1290
-				elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) {
1290
+				elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
1291 1291
 					$status = 'failed';
1292 1292
 					$box_class = 'alert';
1293
-					if( $is_lesson ) {
1294
-						$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 ) );
1293
+					if ($is_lesson) {
1294
+						$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));
1295 1295
 					} else {
1296
-						$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 ) );
1296
+						$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 1297
 					}
1298 1298
 				}
1299 1299
 				// Lesson/Quiz requires a pass
1300
-				elseif( $pass_required ) {
1300
+				elseif ($pass_required) {
1301 1301
 					$status = 'not_started';
1302 1302
 					$box_class = 'info';
1303
-					if( $is_lesson ) {
1304
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1303
+					if ($is_lesson) {
1304
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1305 1305
 					} else {
1306
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1306
+						$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1307 1307
 					}
1308 1308
 				}
1309 1309
 			}
1310 1310
 
1311
-		}else{
1311
+		} else {
1312 1312
 
1313
-			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1314
-			$a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
1315
-			$a_element .= __( 'course', 'woothemes-sensei' );
1313
+			$course_id = Sensei()->lesson->get_course_id($lesson_id);
1314
+			$a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
1315
+			$a_element .= __('course', 'woothemes-sensei');
1316 1316
 			$a_element .= '</a>';
1317 1317
 
1318
-			if ( Sensei_WC::is_course_purchasable( $course_id ) ){
1318
+			if (Sensei_WC::is_course_purchasable($course_id)) {
1319 1319
 
1320
-				$message = sprintf( __( 'Please purchase the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1320
+				$message = sprintf(__('Please purchase the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1321 1321
 
1322 1322
 			} else {
1323 1323
 
1324
-				$message = sprintf( __( 'Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1324
+				$message = sprintf(__('Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1325 1325
 
1326 1326
 			}
1327 1327
 
@@ -1329,15 +1329,15 @@  discard block
 block discarded – undo
1329 1329
 		}
1330 1330
 
1331 1331
 		// Legacy filter
1332
-		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1332
+		$message = apply_filters('sensei_user_quiz_status_'.$status, $message);
1333 1333
 
1334
-		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1335
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1336
-			$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>';
1334
+		if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) {
1335
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1336
+			$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>';
1337 1337
 		}
1338 1338
 
1339 1339
 		// Filter of all messages
1340
-		return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson );
1340
+		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 1341
 	}
1342 1342
 
1343 1343
 	/**
@@ -1347,14 +1347,14 @@  discard block
 block discarded – undo
1347 1347
 	 * @param  integer $course_id Course ID
1348 1348
 	 * @return mixed boolean or comment_ID
1349 1349
 	 */
1350
-	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1350
+	public static function user_start_course($user_id = 0, $course_id = 0) {
1351 1351
 
1352 1352
 		$activity_logged = false;
1353 1353
 
1354
-		if( $user_id && $course_id ) {
1354
+		if ($user_id && $course_id) {
1355 1355
 			// Check if user is already on the Course
1356
-			$activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id );
1357
-			if ( ! $activity_logged ) {
1356
+			$activity_logged = Sensei_Utils::user_started_course($course_id, $user_id);
1357
+			if ( ! $activity_logged) {
1358 1358
 
1359 1359
 				// Add user to course
1360 1360
 				$course_metadata = array(
@@ -1363,11 +1363,11 @@  discard block
 block discarded – undo
1363 1363
 					'complete' => 0,
1364 1364
 				);
1365 1365
 
1366
-				$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata );
1366
+				$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata);
1367 1367
 
1368 1368
 				// Allow further actions
1369
-				if ( $activity_logged ) {
1370
-					do_action( 'sensei_user_course_start', $user_id, $course_id );
1369
+				if ($activity_logged) {
1370
+					do_action('sensei_user_course_start', $user_id, $course_id);
1371 1371
 				}
1372 1372
 			}
1373 1373
 		}
@@ -1383,19 +1383,19 @@  discard block
 block discarded – undo
1383 1383
 	 * @param int $user_id
1384 1384
 	 * @return mixed false or comment_ID
1385 1385
 	 */
1386
-	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1386
+	public static function user_started_course($course_id = 0, $user_id = 0) {
1387 1387
 
1388 1388
 		$user_started_course = false;
1389 1389
 
1390
-		if( $course_id ) {
1390
+		if ($course_id) {
1391 1391
 
1392
-			if( ! $user_id ) {
1392
+			if ( ! $user_id) {
1393 1393
 				$user_id = get_current_user_id();
1394 1394
 			}
1395 1395
 
1396
-            if ( ! $user_id > 0 ) {
1396
+            if ( ! $user_id > 0) {
1397 1397
 
1398
-	            $user_started_course =  false;
1398
+	            $user_started_course = false;
1399 1399
 
1400 1400
             } else {
1401 1401
 
@@ -1406,9 +1406,9 @@  discard block
 block discarded – undo
1406 1406
 		            'field' => 'comment_ID'
1407 1407
 	            );
1408 1408
 
1409
-				$user_course_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1409
+				$user_course_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1410 1410
 
1411
-				if ( $user_course_status_id ) {
1411
+				if ($user_course_status_id) {
1412 1412
 
1413 1413
 					$user_started_course = $user_course_status_id;
1414 1414
 
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
 		 * @param bool $user_started_course
1425 1425
 		 * @param integer $course_id
1426 1426
 		 */
1427
-		return apply_filters( 'sensei_user_started_course', $user_started_course, $course_id, $user_id );
1427
+		return apply_filters('sensei_user_started_course', $user_started_course, $course_id, $user_id);
1428 1428
 
1429 1429
 	}
1430 1430
 
@@ -1436,17 +1436,17 @@  discard block
 block discarded – undo
1436 1436
 	 * @param  integer $user_id   User ID
1437 1437
 	 * @return int
1438 1438
 	 */
1439
-	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1439
+	public static function user_complete_course($course_id = 0, $user_id = 0) {
1440 1440
 		global  $wp_version;
1441 1441
 
1442
-		if( $course_id ) {
1443
-			if( ! $user_id ) {
1442
+		if ($course_id) {
1443
+			if ( ! $user_id) {
1444 1444
 				$user_id = get_current_user_id();
1445 1445
 			}
1446 1446
 
1447 1447
 			$course_status = 'in-progress';
1448 1448
 			$course_metadata = array();
1449
-			$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1449
+			$course_completion = Sensei()->settings->settings['course_completion'];
1450 1450
 			$lessons_completed = $total_lessons = 0;
1451 1451
 			$lesson_status_args = array(
1452 1452
 					'user_id' => $user_id,
@@ -1455,8 +1455,8 @@  discard block
 block discarded – undo
1455 1455
 				);
1456 1456
 
1457 1457
 			// Grab all of this Courses' lessons, looping through each...
1458
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
1459
-			$total_lessons = count( $lesson_ids );
1458
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
1459
+			$total_lessons = count($lesson_ids);
1460 1460
 				// ...if course completion not set to 'passed', and all lessons are complete or graded,
1461 1461
 				// ......then all lessons are 'passed'
1462 1462
 				// ...else if course completion is set to 'passed', check if each lesson has questions...
@@ -1469,29 +1469,29 @@  discard block
 block discarded – undo
1469 1469
 			// The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson()
1470 1470
 			$all_lesson_statuses = array();
1471 1471
 			// In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs
1472
-			if ( version_compare($wp_version, '4.1', '>=') ) {
1472
+			if (version_compare($wp_version, '4.1', '>=')) {
1473 1473
 				$lesson_status_args['post__in'] = $lesson_ids;
1474
-				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1474
+				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1475 1475
 				// Need to always return an array, even with only 1 item
1476
-				if ( !is_array($all_lesson_statuses) ) {
1477
-					$all_lesson_statuses = array( $all_lesson_statuses );
1476
+				if ( ! is_array($all_lesson_statuses)) {
1477
+					$all_lesson_statuses = array($all_lesson_statuses);
1478 1478
 				}
1479 1479
 			}
1480 1480
 			// ...otherwise check each one
1481 1481
 			else {
1482
-				foreach( $lesson_ids as $lesson_id ) {
1482
+				foreach ($lesson_ids as $lesson_id) {
1483 1483
 					$lesson_status_args['post_id'] = $lesson_id;
1484
-					$each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1484
+					$each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1485 1485
 					// Check for valid return before using
1486
-					if ( !empty($each_lesson_status->comment_approved) ) {
1486
+					if ( ! empty($each_lesson_status->comment_approved)) {
1487 1487
 						$all_lesson_statuses[] = $each_lesson_status;
1488 1488
 					}
1489 1489
 				}
1490 1490
 			}
1491
-			foreach( $all_lesson_statuses as $lesson_status ) {
1491
+			foreach ($all_lesson_statuses as $lesson_status) {
1492 1492
 				// If lessons are complete without needing quizzes to be passed
1493
-				if ( 'passed' != $course_completion ) {
1494
-					switch ( $lesson_status->comment_approved ) {
1493
+				if ('passed' != $course_completion) {
1494
+					switch ($lesson_status->comment_approved) {
1495 1495
 						// A user cannot 'complete' a course if a lesson...
1496 1496
 						case 'in-progress': // ...is still in progress
1497 1497
 						case 'ungraded': // ...hasn't yet been graded
@@ -1503,7 +1503,7 @@  discard block
 block discarded – undo
1503 1503
 					}
1504 1504
 				}
1505 1505
 				else {
1506
-					switch ( $lesson_status->comment_approved ) {
1506
+					switch ($lesson_status->comment_approved) {
1507 1507
 						case 'complete': // Lesson has no quiz/questions
1508 1508
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
1509 1509
 						case 'passed': // Lesson has quiz and the user passed
@@ -1517,20 +1517,20 @@  discard block
 block discarded – undo
1517 1517
 					}
1518 1518
 				}
1519 1519
 			} // Each lesson
1520
-			if ( $lessons_completed == $total_lessons ) {
1520
+			if ($lessons_completed == $total_lessons) {
1521 1521
 				$course_status = 'complete';
1522 1522
 			}
1523 1523
 
1524 1524
 			// Update meta data on how many lessons have been completed
1525 1525
 			$course_metadata['complete'] = $lessons_completed;
1526 1526
 			// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1527
-			$course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1527
+			$course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1528 1528
 
1529
-			$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata );
1529
+			$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata);
1530 1530
 
1531 1531
 			// Allow further actions
1532
-			if ( 'complete' == $course_status ) {
1533
-				do_action( 'sensei_user_course_end', $user_id, $course_id );
1532
+			if ('complete' == $course_status) {
1533
+				do_action('sensei_user_course_end', $user_id, $course_id);
1534 1534
 			}
1535 1535
 			return $activity_logged;
1536 1536
 		}
@@ -1546,40 +1546,40 @@  discard block
 block discarded – undo
1546 1546
 	 * @param int $user_id
1547 1547
 	 * @return boolean
1548 1548
 	 */
1549
-	public static function user_completed_course( $course , $user_id = 0 ) {
1549
+	public static function user_completed_course($course, $user_id = 0) {
1550 1550
 
1551
-		if( $course ) {
1552
-			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1551
+		if ($course) {
1552
+			if (is_object($course) && is_a($course, 'WP_Comment')) {
1553 1553
 				$user_course_status = $course->comment_approved;
1554 1554
 			}
1555
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1555
+			elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) {
1556 1556
 				$user_course_status = $course;
1557 1557
 			}
1558 1558
 			else {
1559 1559
 
1560 1560
 				// check the user_id
1561
-				if( ! $user_id ) {
1561
+				if ( ! $user_id) {
1562 1562
 
1563 1563
 					$user_id = get_current_user_id();
1564 1564
 
1565
-					if( empty( $user_id ) ){
1565
+					if (empty($user_id)) {
1566 1566
 
1567 1567
 						return false;
1568 1568
 
1569 1569
 					}
1570 1570
 				}
1571 1571
 
1572
-                if( is_a( $course, 'WP_Post' ) ){
1573
-                    $course =   $course->ID;
1572
+                if (is_a($course, 'WP_Post')) {
1573
+                    $course = $course->ID;
1574 1574
                 }
1575 1575
 
1576
-				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1577
-				if( isset( $user_course_status->comment_approved ) ){
1576
+				$user_course_status = Sensei_Utils::user_course_status($course, $user_id);
1577
+				if (isset($user_course_status->comment_approved)) {
1578 1578
                     $user_course_status = $user_course_status->comment_approved;
1579 1579
                 }
1580 1580
 
1581 1581
 			}
1582
-			if( $user_course_status && 'complete' == $user_course_status ) {
1582
+			if ($user_course_status && 'complete' == $user_course_status) {
1583 1583
 				return true;
1584 1584
 			}
1585 1585
 		}
@@ -1594,10 +1594,10 @@  discard block
 block discarded – undo
1594 1594
 	 * @param int $user_id
1595 1595
 	 * @return mixed false or comment_ID
1596 1596
 	 */
1597
-	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1597
+	public static function user_started_lesson($lesson_id = 0, $user_id = 0) {
1598 1598
 
1599
-		if( $lesson_id ) {
1600
-			if( ! $user_id ) {
1599
+		if ($lesson_id) {
1600
+			if ( ! $user_id) {
1601 1601
 				$user_id = get_current_user_id();
1602 1602
 			}
1603 1603
 
@@ -1607,8 +1607,8 @@  discard block
 block discarded – undo
1607 1607
                 'type' => 'sensei_lesson_status',
1608 1608
                 'field' => 'comment_ID' );
1609 1609
 
1610
-			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1611
-			if( $user_lesson_status_id ) {
1610
+			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1611
+			if ($user_lesson_status_id) {
1612 1612
 				return $user_lesson_status_id;
1613 1613
 			}
1614 1614
 		}
@@ -1623,29 +1623,29 @@  discard block
 block discarded – undo
1623 1623
 	 * @param int $user_id
1624 1624
 	 * @return boolean
1625 1625
 	 */
1626
-	public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) {
1626
+	public static function user_completed_lesson($lesson = 0, $user_id = 0) {
1627 1627
 
1628
-		if( $lesson ) {
1628
+		if ($lesson) {
1629 1629
 			$lesson_id = 0;
1630
-			if ( is_object( $lesson ) ) {
1630
+			if (is_object($lesson)) {
1631 1631
 				$user_lesson_status = $lesson->comment_approved;
1632 1632
 				$lesson_id = $lesson->comment_post_ID;
1633 1633
 			}
1634
-			elseif ( ! is_numeric( $lesson ) ) {
1634
+			elseif ( ! is_numeric($lesson)) {
1635 1635
 				$user_lesson_status = $lesson;
1636 1636
 			}
1637 1637
 			else {
1638
-				if( ! $user_id ) {
1638
+				if ( ! $user_id) {
1639 1639
 					$user_id = get_current_user_id();
1640 1640
 				}
1641 1641
 
1642 1642
                 // the user is not logged in
1643
-                if( ! $user_id > 0 ){
1643
+                if ( ! $user_id > 0) {
1644 1644
                     return false;
1645 1645
                 }
1646
-				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1646
+				$_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id);
1647 1647
 
1648
-				if ( $_user_lesson_status ) {
1648
+				if ($_user_lesson_status) {
1649 1649
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1650 1650
 				}
1651 1651
 				else {
@@ -1653,12 +1653,12 @@  discard block
 block discarded – undo
1653 1653
 				}
1654 1654
 				$lesson_id = $lesson;
1655 1655
 			}
1656
-			if ( 'in-progress' != $user_lesson_status ) {
1656
+			if ('in-progress' != $user_lesson_status) {
1657 1657
 				// Check for Passed or Completed Setting
1658 1658
 				// Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting
1659 1659
 //				$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1660 1660
 //				if ( 'passed' == $course_completion ) {
1661
-					switch( $user_lesson_status ) {
1661
+					switch ($user_lesson_status) {
1662 1662
 						case 'complete':
1663 1663
 						case 'graded':
1664 1664
 						case 'passed':
@@ -1667,13 +1667,13 @@  discard block
 block discarded – undo
1667 1667
 
1668 1668
 						case 'failed':
1669 1669
 							// This may be 'completed' depending on...
1670
-							if ( $lesson_id ) {
1670
+							if ($lesson_id) {
1671 1671
 								// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson
1672
-								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1673
-								if ( $lesson_quiz_id ) {
1672
+								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1673
+								if ($lesson_quiz_id) {
1674 1674
 									// ...the quiz pass setting
1675
-									$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
1676
-									if ( empty($pass_required) ) {
1675
+									$pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true);
1676
+									if (empty($pass_required)) {
1677 1677
 										// We just require the user to have done the quiz, not to have passed
1678 1678
 										return true;
1679 1679
 									}
@@ -1696,15 +1696,15 @@  discard block
 block discarded – undo
1696 1696
 	 * @param int $user_id
1697 1697
 	 * @return object
1698 1698
 	 */
1699
-	public static function user_course_status( $course_id = 0, $user_id = 0 ) {
1699
+	public static function user_course_status($course_id = 0, $user_id = 0) {
1700 1700
 
1701 1701
 
1702
-		if( $course_id ) {
1703
-			if( ! $user_id ) {
1702
+		if ($course_id) {
1703
+			if ( ! $user_id) {
1704 1704
 				$user_id = get_current_user_id();
1705 1705
 			}
1706 1706
 
1707
-			$user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true );
1707
+			$user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true);
1708 1708
 			return $user_course_status;
1709 1709
 		}
1710 1710
 
@@ -1719,27 +1719,27 @@  discard block
 block discarded – undo
1719 1719
 	 * @param int $user_id
1720 1720
 	 * @return object | bool
1721 1721
 	 */
1722
-	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1722
+	public static function user_lesson_status($lesson_id = 0, $user_id = 0) {
1723 1723
 
1724
-        if( ! $user_id ) {
1724
+        if ( ! $user_id) {
1725 1725
             $user_id = get_current_user_id();
1726 1726
         }
1727 1727
 
1728
-		if( $lesson_id > 0 && $user_id > 0 ) {
1728
+		if ($lesson_id > 0 && $user_id > 0) {
1729 1729
 
1730
-			$user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true );
1730
+			$user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true);
1731 1731
 			return $user_lesson_status;
1732 1732
 		}
1733 1733
 
1734 1734
 		return false;
1735 1735
 	}
1736 1736
 
1737
-	public static function is_preview_lesson( $lesson_id ) {
1737
+	public static function is_preview_lesson($lesson_id) {
1738 1738
 		$is_preview = false;
1739 1739
 
1740
-		if( 'lesson' == get_post_type( $lesson_id ) ) {
1741
-			$lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true );
1742
-			if ( isset( $lesson_preview ) && '' != $lesson_preview ) {
1740
+		if ('lesson' == get_post_type($lesson_id)) {
1741
+			$lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true);
1742
+			if (isset($lesson_preview) && '' != $lesson_preview) {
1743 1743
 				$is_preview = true;
1744 1744
 			}
1745 1745
 		}
@@ -1747,22 +1747,22 @@  discard block
 block discarded – undo
1747 1747
 		return $is_preview;
1748 1748
 	}
1749 1749
 
1750
-	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1750
+	public static function user_passed_quiz($quiz_id = 0, $user_id = 0) {
1751 1751
 
1752
-		if( ! $quiz_id  ) return false;
1752
+		if ( ! $quiz_id) return false;
1753 1753
 
1754
-		if( ! $user_id ) {
1754
+		if ( ! $user_id) {
1755 1755
 			$user_id = get_current_user_id();
1756 1756
 		}
1757
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1757
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1758 1758
 
1759 1759
 		// Quiz Grade
1760
-		$lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1761
-		$quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
1760
+		$lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1761
+		$quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
1762 1762
 
1763 1763
 		// Check if Grade is greater than or equal to pass percentage
1764
-		$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
1765
-		if ( $quiz_passmark <= intval( $quiz_grade ) ) {
1764
+		$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
1765
+		if ($quiz_passmark <= intval($quiz_grade)) {
1766 1766
 			return true;
1767 1767
 		}
1768 1768
 
@@ -1782,9 +1782,9 @@  discard block
 block discarded – undo
1782 1782
      *
1783 1783
 	 * @return mixed false or comment_ID
1784 1784
 	 */
1785
-	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1785
+	public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) {
1786 1786
 		$comment_id = false;
1787
-		if ( !empty($status) ) {
1787
+		if ( ! empty($status)) {
1788 1788
 			$args = array(
1789 1789
 					'user_id'   => $user_id,
1790 1790
 					'post_id'   => $lesson_id,
@@ -1793,18 +1793,18 @@  discard block
 block discarded – undo
1793 1793
 					'action'    => 'update', // Update the existing status...
1794 1794
 					'keep_time' => true, // ...but don't change the existing timestamp
1795 1795
 				);
1796
-			if( 'in-progress' == $status ) {
1797
-				unset( $args['keep_time'] ); // Keep updating what's happened
1796
+			if ('in-progress' == $status) {
1797
+				unset($args['keep_time']); // Keep updating what's happened
1798 1798
 			}
1799 1799
 
1800
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1801
-			if ( $comment_id && !empty($metadata) ) {
1802
-				foreach( $metadata as $key => $value ) {
1803
-					update_comment_meta( $comment_id, $key, $value );
1800
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1801
+			if ($comment_id && ! empty($metadata)) {
1802
+				foreach ($metadata as $key => $value) {
1803
+					update_comment_meta($comment_id, $key, $value);
1804 1804
 				}
1805 1805
 			}
1806 1806
 
1807
-			do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id );
1807
+			do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id);
1808 1808
 		}
1809 1809
 		return $comment_id;
1810 1810
 	}
@@ -1820,9 +1820,9 @@  discard block
 block discarded – undo
1820 1820
 	 * @param array $metadata
1821 1821
 	 * @return mixed false or comment_ID
1822 1822
 	 */
1823
-	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1823
+	public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) {
1824 1824
 		$comment_id = false;
1825
-		if ( !empty($status) ) {
1825
+		if ( ! empty($status)) {
1826 1826
 			$args = array(
1827 1827
 					'user_id'   => $user_id,
1828 1828
 					'post_id'   => $course_id,
@@ -1831,17 +1831,17 @@  discard block
 block discarded – undo
1831 1831
 					'action'    => 'update', // Update the existing status...
1832 1832
 					'keep_time' => true, // ...but don't change the existing timestamp
1833 1833
 				);
1834
-			if( 'in-progress' == $status ) {
1835
-				unset( $args['keep_time'] ); // Keep updating what's happened
1834
+			if ('in-progress' == $status) {
1835
+				unset($args['keep_time']); // Keep updating what's happened
1836 1836
 			}
1837 1837
 
1838
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1839
-			if ( $comment_id && !empty($metadata) ) {
1840
-				foreach( $metadata as $key => $value ) {
1841
-					update_comment_meta( $comment_id, $key, $value );
1838
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1839
+			if ($comment_id && ! empty($metadata)) {
1840
+				foreach ($metadata as $key => $value) {
1841
+					update_comment_meta($comment_id, $key, $value);
1842 1842
 				}
1843 1843
 			}
1844
-			do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id );
1844
+			do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id);
1845 1845
 		}
1846 1846
 		return $comment_id;
1847 1847
 	}
@@ -1853,9 +1853,9 @@  discard block
 block discarded – undo
1853 1853
 	 * @param  array $pieces (default: array())
1854 1854
 	 * @return array
1855 1855
 	 */
1856
-	public static function single_comment_filter( $pieces ) {
1857
-		unset( $pieces['orderby'] );
1858
-		unset( $pieces['order'] );
1856
+	public static function single_comment_filter($pieces) {
1857
+		unset($pieces['orderby']);
1858
+		unset($pieces['order']);
1859 1859
 
1860 1860
 		return $pieces;
1861 1861
 	}
@@ -1867,9 +1867,9 @@  discard block
 block discarded – undo
1867 1867
 	 * @param  array $pieces (default: array())
1868 1868
 	 * @return array
1869 1869
 	 */
1870
-	public static function comment_any_status_filter( $pieces ) {
1870
+	public static function comment_any_status_filter($pieces) {
1871 1871
 
1872
-		$pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] );
1872
+		$pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']);
1873 1873
 
1874 1874
 		return $pieces;
1875 1875
 	}
@@ -1881,12 +1881,12 @@  discard block
 block discarded – undo
1881 1881
 	 * @param  array $pieces (default: array())
1882 1882
 	 * @return array
1883 1883
 	 */
1884
-	public static function comment_multiple_status_filter( $pieces ) {
1884
+	public static function comment_multiple_status_filter($pieces) {
1885 1885
 
1886
-		preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder );
1887
-		if ( !empty($placeholder[1]) ) {
1888
-			$statuses = explode( ',', $placeholder[1] );
1889
-			$pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] );
1886
+		preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder);
1887
+		if ( ! empty($placeholder[1])) {
1888
+			$statuses = explode(',', $placeholder[1]);
1889
+			$pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']);
1890 1890
 		}
1891 1891
 
1892 1892
 		return $pieces;
@@ -1898,12 +1898,12 @@  discard block
 block discarded – undo
1898 1898
      * @param array $pieces
1899 1899
 	 * @return array $pieces
1900 1900
 	 */
1901
-	public static function comment_total_sum_meta_value_filter( $pieces ) {
1901
+	public static function comment_total_sum_meta_value_filter($pieces) {
1902 1902
 		global $wpdb, $wp_version;
1903 1903
 
1904 1904
 		$pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum ";
1905
-		unset( $pieces['groupby'] );
1906
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1905
+		unset($pieces['groupby']);
1906
+		if (version_compare($wp_version, '4.1', '>=')) {
1907 1907
 			$args['order'] = false;
1908 1908
 			$args['orderby'] = false;
1909 1909
 		}
@@ -1918,12 +1918,12 @@  discard block
 block discarded – undo
1918 1918
 	 * @param  array $pieces (default: array())
1919 1919
 	 * @return array
1920 1920
 	 */
1921
-	public static function get_posts_count_only_filter( $pieces ) {
1921
+	public static function get_posts_count_only_filter($pieces) {
1922 1922
 		global $wp_version;
1923 1923
 
1924 1924
 		$pieces['fields'] = " COUNT(*) AS total ";
1925
-		unset( $pieces['groupby'] );
1926
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1925
+		unset($pieces['groupby']);
1926
+		if (version_compare($wp_version, '4.1', '>=')) {
1927 1927
 			$args['order'] = false;
1928 1928
 			$args['orderby'] = false;
1929 1929
 		}
@@ -1942,9 +1942,9 @@  discard block
 block discarded – undo
1942 1942
      *
1943 1943
      * @return bool $success
1944 1944
      */
1945
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1945
+    public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1946 1946
 
1947
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1947
+        return self::update_user_data($data_key, $post_id, $value, $user_id);
1948 1948
 
1949 1949
     }// end add_user_data
1950 1950
 
@@ -1963,18 +1963,18 @@  discard block
 block discarded – undo
1963 1963
      *
1964 1964
      * @return bool $success
1965 1965
      */
1966
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1966
+    public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1967 1967
 
1968
-        if( ! ( $user_id > 0 ) ){
1968
+        if ( ! ($user_id > 0)) {
1969 1969
             $user_id = get_current_user_id();
1970 1970
         }
1971 1971
 
1972
-        $supported_post_types = array( 'course', 'lesson' );
1973
-        $post_type = get_post_type( $post_id );
1974
-        if( empty( $post_id ) || empty( $data_key )
1975
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1976
-            || !get_userdata( $user_id )
1977
-            || ! in_array( $post_type, $supported_post_types )  ){
1972
+        $supported_post_types = array('course', 'lesson');
1973
+        $post_type = get_post_type($post_id);
1974
+        if (empty($post_id) || empty($data_key)
1975
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1976
+            || ! get_userdata($user_id)
1977
+            || ! in_array($post_type, $supported_post_types)) {
1978 1978
 
1979 1979
             return false;
1980 1980
         }
@@ -1982,20 +1982,20 @@  discard block
 block discarded – undo
1982 1982
         // check if there and existing Sensei status on this post type if not create it
1983 1983
         // and get the  activity ID
1984 1984
         $status_function = 'user_'.$post_type.'_status';
1985
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1986
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1985
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1986
+        if ( ! isset($sensei_user_status->comment_ID)) {
1987 1987
 
1988 1988
             $start_function = 'user_start_'.$post_type;
1989
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1989
+            $sensei_user_activity_id = self::$start_function($user_id, $post_id);
1990 1990
 
1991
-        }else{
1991
+        } else {
1992 1992
 
1993 1993
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1994 1994
 
1995 1995
         }
1996 1996
 
1997 1997
         // store the data
1998
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1998
+        $success = update_comment_meta($sensei_user_activity_id, $data_key, $value);
1999 1999
 
2000 2000
        return $success;
2001 2001
 
@@ -2014,20 +2014,20 @@  discard block
 block discarded – undo
2014 2014
      *
2015 2015
      * @return mixed $user_data_value
2016 2016
      */
2017
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
2017
+    public static function get_user_data($data_key, $post_id, $user_id = 0) {
2018 2018
 
2019 2019
         $user_data_value = true;
2020 2020
 
2021
-        if( ! ( $user_id > 0 ) ){
2021
+        if ( ! ($user_id > 0)) {
2022 2022
             $user_id = get_current_user_id();
2023 2023
         }
2024 2024
 
2025
-        $supported_post_types = array( 'course', 'lesson' );
2026
-        $post_type = get_post_type( $post_id );
2027
-        if( empty( $post_id ) || empty( $data_key )
2028
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2029
-            || ! get_userdata( $user_id )
2030
-            || !in_array( $post_type, $supported_post_types )  ){
2025
+        $supported_post_types = array('course', 'lesson');
2026
+        $post_type = get_post_type($post_id);
2027
+        if (empty($post_id) || empty($data_key)
2028
+            || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2029
+            || ! get_userdata($user_id)
2030
+            || ! in_array($post_type, $supported_post_types)) {
2031 2031
 
2032 2032
             return false;
2033 2033
         }
@@ -2035,13 +2035,13 @@  discard block
 block discarded – undo
2035 2035
         // check if there and existing Sensei status on this post type if not create it
2036 2036
         // and get the  activity ID
2037 2037
         $status_function = 'user_'.$post_type.'_status';
2038
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2039
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2038
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2039
+        if ( ! isset($sensei_user_status->comment_ID)) {
2040 2040
             return false;
2041 2041
         }
2042 2042
 
2043 2043
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2044
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2044
+        $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true);
2045 2045
 
2046 2046
         return $user_data_value;
2047 2047
 
@@ -2056,19 +2056,19 @@  discard block
 block discarded – undo
2056 2056
      *
2057 2057
      * @return bool $deleted
2058 2058
      */
2059
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2059
+    public static function delete_user_data($data_key, $post_id, $user_id) {
2060 2060
         $deleted = true;
2061 2061
 
2062
-        if( ! ( $user_id > 0 ) ){
2062
+        if ( ! ($user_id > 0)) {
2063 2063
             $user_id = get_current_user_id();
2064 2064
         }
2065 2065
 
2066
-        $supported_post_types = array( 'course', 'lesson' );
2067
-        $post_type = get_post_type( $post_id );
2068
-        if( empty( $post_id ) || empty( $data_key )
2069
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2070
-            || ! get_userdata( $user_id )
2071
-            || !in_array( $post_type, $supported_post_types )  ){
2066
+        $supported_post_types = array('course', 'lesson');
2067
+        $post_type = get_post_type($post_id);
2068
+        if (empty($post_id) || empty($data_key)
2069
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2070
+            || ! get_userdata($user_id)
2071
+            || ! in_array($post_type, $supported_post_types)) {
2072 2072
 
2073 2073
             return false;
2074 2074
         }
@@ -2076,13 +2076,13 @@  discard block
 block discarded – undo
2076 2076
         // check if there and existing Sensei status on this post type if not create it
2077 2077
         // and get the  activity ID
2078 2078
         $status_function = 'user_'.$post_type.'_status';
2079
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2080
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2079
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2080
+        if ( ! isset($sensei_user_status->comment_ID)) {
2081 2081
             return false;
2082 2082
         }
2083 2083
 
2084 2084
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2085
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2085
+        $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
2086 2086
 
2087 2087
         return $deleted;
2088 2088
 
@@ -2107,62 +2107,62 @@  discard block
 block discarded – undo
2107 2107
      *
2108 2108
      * @return string $drop_down_element
2109 2109
      */
2110
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2110
+    public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) {
2111 2111
 
2112 2112
         $drop_down_element = '';
2113 2113
 
2114 2114
         // setup the basic attributes
2115
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2115
+        if ( ! isset($attributes['name']) || empty($attributes['name'])) {
2116 2116
 
2117 2117
             $attributes['name'] = 'sensei-options';
2118 2118
 
2119 2119
         }
2120 2120
 
2121
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2121
+        if ( ! isset($attributes['id']) || empty($attributes['id'])) {
2122 2122
 
2123 2123
             $attributes['id'] = 'sensei-options';
2124 2124
 
2125 2125
         }
2126 2126
 
2127
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2127
+        if ( ! isset($attributes['class']) || empty($attributes['class'])) {
2128 2128
 
2129
-            $attributes['class'] ='chosen_select widefat';
2129
+            $attributes['class'] = 'chosen_select widefat';
2130 2130
 
2131 2131
         }
2132 2132
 
2133 2133
         // create element attributes
2134 2134
         $combined_attributes = '';
2135
-        foreach( $attributes as $attribute => $value ){
2135
+        foreach ($attributes as $attribute => $value) {
2136 2136
 
2137
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2137
+            $combined_attributes .= $attribute.'="'.$value.'"'.' ';
2138 2138
 
2139 2139
         }// end for each
2140 2140
 
2141 2141
 
2142 2142
         // create the select element
2143
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2143
+        $drop_down_element .= '<select '.$combined_attributes.' >'."\n";
2144 2144
 
2145 2145
         // show the none option if the client requested
2146
-        if( $enable_none_option ) {
2147
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2146
+        if ($enable_none_option) {
2147
+            $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
2148 2148
         }
2149 2149
 
2150
-        if ( count( $options ) > 0 ) {
2150
+        if (count($options) > 0) {
2151 2151
 
2152
-            foreach ($options as $value => $option ){
2152
+            foreach ($options as $value => $option) {
2153 2153
 
2154 2154
                 $element = '';
2155
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2156
-                $element .= selected( $value, $selected_value, false ) . '>';
2157
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2155
+                $element .= '<option value="'.esc_attr($value).'"';
2156
+                $element .= selected($value, $selected_value, false).'>';
2157
+                $element .= esc_html($option).'</option>'."\n";
2158 2158
 
2159 2159
                 // add the element to the select html
2160
-                $drop_down_element.= $element;
2160
+                $drop_down_element .= $element;
2161 2161
             } // End For Loop
2162 2162
 
2163 2163
         } // End If Statement
2164 2164
 
2165
-        $drop_down_element .= '</select>' . "\n";
2165
+        $drop_down_element .= '</select>'."\n";
2166 2166
 
2167 2167
         return $drop_down_element;
2168 2168
 
@@ -2182,14 +2182,14 @@  discard block
 block discarded – undo
2182 2182
      *
2183 2183
      * @return double $val
2184 2184
      */
2185
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2185
+    public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') {
2186 2186
 
2187 2187
         /**å
2188 2188
          * Change the precision for the Sensei_Utils::round function.
2189 2189
          * the precision given will be passed into the php round function
2190 2190
          * @since 1.8.5
2191 2191
          */
2192
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2192
+        $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode);
2193 2193
 
2194 2194
         /**
2195 2195
          * Change the mode for the Sensei_Utils::round function.
@@ -2199,15 +2199,15 @@  discard block
 block discarded – undo
2199 2199
          *
2200 2200
          * @since 1.8.5
2201 2201
          */
2202
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2202
+        $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision);
2203 2203
 
2204
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2204
+        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
2205 2205
 
2206
-            return round( $val, $precision, $mode );
2206
+            return round($val, $precision, $mode);
2207 2207
 
2208
-        }else{
2208
+        } else {
2209 2209
 
2210
-            return round( $val, $precision );
2210
+            return round($val, $precision);
2211 2211
 
2212 2212
         }
2213 2213
 
@@ -2219,15 +2219,15 @@  discard block
 block discarded – undo
2219 2219
      * @since 1.9.0
2220 2220
      * @return string $url
2221 2221
      */
2222
-    public static function get_current_url(){
2222
+    public static function get_current_url() {
2223 2223
 
2224 2224
         global $wp;
2225
-        $current_url = trailingslashit( home_url( $wp->request ) );
2226
-        if ( isset( $_GET ) ) {
2225
+        $current_url = trailingslashit(home_url($wp->request));
2226
+        if (isset($_GET)) {
2227 2227
 
2228
-            foreach ($_GET as $param => $val ) {
2228
+            foreach ($_GET as $param => $val) {
2229 2229
 
2230
-                $current_url = add_query_arg( $param, $val , $current_url );
2230
+                $current_url = add_query_arg($param, $val, $current_url);
2231 2231
 
2232 2232
             }
2233 2233
         }
@@ -2257,27 +2257,27 @@  discard block
 block discarded – undo
2257 2257
      * @param array $array_b
2258 2258
      * @return array $merged_array
2259 2259
      */
2260
-    public static function array_zip_merge( $array_a, $array_b ){
2260
+    public static function array_zip_merge($array_a, $array_b) {
2261 2261
 
2262
-        if( ! is_array( $array_a ) || ! is_array( $array_b )  ){
2262
+        if ( ! is_array($array_a) || ! is_array($array_b)) {
2263 2263
             trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2264 2264
         }
2265 2265
 
2266 2266
         $merged_array = array();
2267
-        $total_elements = count( $array_a )  + count( $array_b );
2267
+        $total_elements = count($array_a) + count($array_b);
2268 2268
 
2269 2269
         // Zip arrays
2270
-        for ( $i = 0; $i < $total_elements; $i++) {
2270
+        for ($i = 0; $i < $total_elements; $i++) {
2271 2271
 
2272 2272
             // if has an element at current index push a on top
2273
-            if( isset( $array_a[ $i ] ) ){
2274
-                $merged_array[] = $array_a[ $i ]  ;
2273
+            if (isset($array_a[$i])) {
2274
+                $merged_array[] = $array_a[$i];
2275 2275
             }
2276 2276
 
2277 2277
             // next if $array_b has an element at current index push a on top of the element
2278 2278
             // from a if there was one, if not the element before that.
2279
-            if( isset( $array_b[ $i ] ) ){
2280
-                $merged_array[] = $array_b[ $i ]  ;
2279
+            if (isset($array_b[$i])) {
2280
+                $merged_array[] = $array_b[$i];
2281 2281
             }
2282 2282
 
2283 2283
         }
@@ -2292,4 +2292,4 @@  discard block
 block discarded – undo
2292 2292
  * @ignore only for backward compatibility
2293 2293
  * @since 1.9.0
2294 2294
  */
2295
-class WooThemes_Sensei_Utils extends Sensei_Utils{}
2296 2295
\ No newline at end of file
2296
+class WooThemes_Sensei_Utils extends Sensei_Utils {}
2297 2297
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 1 patch
Spacing   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,17 +11,17 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
 
16 16
     /**
17 17
      * Load the files needed for the woocommerce integration.
18 18
      *
19 19
      * @since 1.9.0
20 20
      */
21
-    public static function load_woocommerce_integration_hooks(){
21
+    public static function load_woocommerce_integration_hooks() {
22 22
 
23
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
24
-        require_once( $woocommerce_hooks_file_path );
23
+	    $woocommerce_hooks_file_path = Sensei()->plugin_path().'includes/hooks/woocommerce.php';
24
+        require_once($woocommerce_hooks_file_path);
25 25
 
26 26
     }
27 27
     /**
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
      * @since 1.9.0
31 31
      * @return bool
32 32
      */
33
-    public static function is_woocommerce_active(){
33
+    public static function is_woocommerce_active() {
34 34
 
35
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
36 36
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
37 37
 
38 38
     } // end is_woocommerce_active
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return bool
49 49
      */
50
-    public static function is_woocommerce_present(){
50
+    public static function is_woocommerce_present() {
51 51
 
52
-        $active_plugins = (array) get_option( 'active_plugins', array() );
52
+        $active_plugins = (array) get_option('active_plugins', array());
53 53
 
54
-        if ( is_multisite() ){
54
+        if (is_multisite()) {
55 55
 
56
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
56
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
57 57
 
58 58
         }
59 59
 
60
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
60
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
61 61
 
62
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
62
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
63 63
 
64 64
     }// end is_woocommerce_present
65 65
 
@@ -72,48 +72,48 @@  discard block
 block discarded – undo
72 72
      * @param $course_id
73 73
      * @return array $user_course_orders
74 74
      */
75
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
75
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
76 76
 
77
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
77
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
78 78
 
79
-        $orders_query = new WP_Query( array(
79
+        $orders_query = new WP_Query(array(
80 80
             'post_type'   => 'shop_order',
81 81
             'posts_per_page' => -1,
82
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
82
+            'post_status' => array('wc-processing', 'wc-completed'),
83 83
             'meta_key'=> '_customer_user',
84 84
             'meta_value'=> $user_id,
85
-        ) );
85
+        ));
86 86
 
87
-        if( $orders_query->post_count == 0 ){
87
+        if ($orders_query->post_count == 0) {
88 88
 
89 89
             return false;
90 90
 
91 91
         }
92 92
 
93
-        foreach( $orders_query->get_posts() as $order ){
93
+        foreach ($orders_query->get_posts() as $order) {
94 94
 
95
-            $order = new WC_Order( $order->ID );
95
+            $order = new WC_Order($order->ID);
96 96
             $items = $order->get_items();
97 97
 
98
-            $user_orders =  array();
98
+            $user_orders = array();
99 99
 
100
-            foreach( $items as $item ){
100
+            foreach ($items as $item) {
101 101
 
102 102
                 // if the product id on the order and the one given to this function
103 103
                 // this order has been placed by the given user on the given course.
104
-                $product = wc_get_product( $item['product_id'] );
104
+                $product = wc_get_product($item['product_id']);
105 105
 
106
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
106
+                if (is_object($product) && $product->is_type('variable')) {
107 107
 
108 108
                     $item_product_id = $item['variation_id'];
109 109
 
110 110
                 } else {
111 111
 
112
-                    $item_product_id =  $item['product_id'];
112
+                    $item_product_id = $item['product_id'];
113 113
 
114 114
                 }
115 115
 
116
-                if( $course_product_id == $item_product_id ){
116
+                if ($course_product_id == $item_product_id) {
117 117
 
118 118
                     return $order->id;
119 119
 
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
      * @param $filter_links
138 138
      * @return mixed
139 139
      */
140
-    public static function add_course_archive_wc_filter_links( $filter_links ){
140
+    public static function add_course_archive_wc_filter_links($filter_links) {
141 141
 
142 142
         $free_courses = self::get_free_courses();
143 143
         $paid_courses = self::get_paid_courses();
144 144
 
145
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
+        if (empty($free_courses) || empty($paid_courses)) {
146 146
             // do not show any WooCommerce filters if all courses are
147 147
             // free or if all courses are paid
148 148
             return $filter_links;
@@ -150,15 +150,15 @@  discard block
 block discarded – undo
150 150
         }
151 151
 
152 152
         $filter_links[] = array(
153
-            'id'=>'paid' ,
154
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
155
-            'title'=>__( 'Paid', 'woothemes-sensei' )
153
+            'id'=>'paid',
154
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
155
+            'title'=>__('Paid', 'woothemes-sensei')
156 156
         );
157 157
 
158 158
         $filter_links[] = array(
159 159
             'id'=>'free',
160
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
161
-            'title'=>__( 'Free', 'woothemes-sensei' )
160
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
161
+            'title'=>__('Free', 'woothemes-sensei')
162 162
         );
163 163
 
164 164
         return $filter_links;
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
      * @param WP_Query $query
176 176
      * @return WP_Query $query
177 177
      */
178
-    public static function course_archive_wc_filter_free( $query ){
178
+    public static function course_archive_wc_filter_free($query) {
179 179
 
180
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
181
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
180
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
181
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
182 182
 
183 183
             // setup the course meta query
184 184
             $meta_query = self::get_free_courses_meta_query_args();
185 185
 
186 186
             // manipulate the query to return free courses
187
-            $query->set('meta_query', $meta_query );
187
+            $query->set('meta_query', $meta_query);
188 188
 
189 189
             // don't show any paid courses
190 190
             $courses = self::get_paid_courses();
191 191
             $ids = array();
192
-            foreach( $courses as $course ){
192
+            foreach ($courses as $course) {
193 193
                 $ids[] = $course->ID;
194 194
             }
195
-            $query->set( 'post__not_in', $ids );
195
+            $query->set('post__not_in', $ids);
196 196
 
197 197
         }// end if course_filter
198 198
 
@@ -211,16 +211,16 @@  discard block
 block discarded – undo
211 211
      * @param WP_Query $query
212 212
      * @return WP_Query $query
213 213
      */
214
-    public static function course_archive_wc_filter_paid( $query ){
214
+    public static function course_archive_wc_filter_paid($query) {
215 215
 
216
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
217
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
216
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
217
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
218 218
 
219 219
             // setup the course meta query
220 220
             $meta_query = self::get_paid_courses_meta_query_args();
221 221
 
222 222
             // manipulate the query to return free courses
223
-            $query->set('meta_query', $meta_query );
223
+            $query->set('meta_query', $meta_query);
224 224
 
225 225
         }
226 226
 
@@ -233,14 +233,14 @@  discard block
 block discarded – undo
233 233
      * single courses if woocommerce is active allowing purchase
234 234
      * information and actions to be hooked from WooCommerce.
235 235
      */
236
-    public static function do_single_course_wc_single_product_action(){
236
+    public static function do_single_course_wc_single_product_action() {
237 237
 
238 238
         /**
239 239
          * this hooks is documented within the WooCommerce plugin.
240 240
          */
241
-        if ( Sensei_WC::is_woocommerce_active() ) {
241
+        if (Sensei_WC::is_woocommerce_active()) {
242 242
 
243
-            do_action( 'woocommerce_before_single_product' );
243
+            do_action('woocommerce_before_single_product');
244 244
 
245 245
         } // End If Statement
246 246
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
      * @param $user_id
262 262
      * @return bool
263 263
      */
264
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
264
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
265 265
 
266 266
 	    // do not override access to admins
267
-	    $course_id = Sensei()->lesson->get_course_id( $lesson_id );
268
-	    if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id )
269
-	         || Sensei_Utils::user_started_course( $course_id, $user_id )  ){
267
+	    $course_id = Sensei()->lesson->get_course_id($lesson_id);
268
+	    if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)
269
+	         || Sensei_Utils::user_started_course($course_id, $user_id)) {
270 270
 
271 271
 			return true;
272 272
 
@@ -275,18 +275,18 @@  discard block
 block discarded – undo
275 275
         // check if the course has a valid product attached to it
276 276
         // which the user should have purchased if they want to access
277 277
         // the current lesson
278
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
279
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
278
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
279
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
280 280
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
281
-        if( isset ($product) && is_object($product) ){
281
+        if (isset ($product) && is_object($product)) {
282 282
 
283 283
             // valid product found
284
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
284
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
285 285
 
286 286
             // product has a successful order so this user may access the content
287 287
             // this function may only return false or the default
288 288
             // returning true may override other negatives which we don't want
289
-            if( ! $order_id ){
289
+            if ( ! $order_id) {
290 290
 
291 291
                 return false;
292 292
 
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public static function course_link_from_order( ) {
311 311
 
312
-        if( ! is_order_received_page() ){
312
+        if ( ! is_order_received_page()) {
313 313
             return;
314 314
         }
315 315
 
316
-        $order_id = get_query_var( 'order-received' );
317
-		$order = new WC_Order( $order_id );
316
+        $order_id = get_query_var('order-received');
317
+		$order = new WC_Order($order_id);
318 318
 
319 319
 		// exit early if not wc-completed or wc-processing
320
-		if( 'wc-completed' != $order->post_status
321
-            && 'wc-processing' != $order->post_status  ) {
320
+		if ('wc-completed' != $order->post_status
321
+            && 'wc-processing' != $order->post_status) {
322 322
             return;
323 323
         }
324 324
 
325 325
         $course_links = array(); // store the for links for courses purchased
326
-		foreach ( $order->get_items() as $item ) {
326
+		foreach ($order->get_items() as $item) {
327 327
 
328
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
328
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
329 329
 
330 330
                 // If item has variation_id then its a variation of the product
331 331
                 $item_id = $item['variation_id'];
@@ -337,28 +337,28 @@  discard block
 block discarded – undo
337 337
 
338 338
             } // End If Statement
339 339
 
340
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
340
+            $user_id = get_post_meta($order->id, '_customer_user', true);
341 341
 
342
-            if( $user_id ) {
342
+            if ($user_id) {
343 343
 
344 344
                 // Get all courses for product
345 345
                 $args = Sensei_Course::get_default_query_args();
346
-                $args['meta_query'] = array( array(
346
+                $args['meta_query'] = array(array(
347 347
                             'key' => '_course_woocommerce_product',
348 348
                             'value' => $item_id
349
-                        ) );
349
+                        ));
350 350
                 $args['orderby'] = 'menu_order date';
351 351
                 $args['order'] = 'ASC';
352 352
 
353 353
                 // loop through courses
354
-                $courses = get_posts( $args );
355
-                if( $courses && count( $courses ) > 0 ) {
354
+                $courses = get_posts($args);
355
+                if ($courses && count($courses) > 0) {
356 356
 
357
-                    foreach( $courses as $course ) {
357
+                    foreach ($courses as $course) {
358 358
 
359 359
                         $title = $course->post_title;
360
-                        $permalink = get_permalink( $course->ID );
361
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
360
+                        $permalink = get_permalink($course->ID);
361
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
362 362
 
363 363
                     } // end for each
364 364
 
@@ -369,24 +369,24 @@  discard block
 block discarded – undo
369 369
         }// end loop through orders
370 370
 
371 371
         // add the courses to the WooCommerce notice
372
-        if( ! empty( $course_links) ){
372
+        if ( ! empty($course_links)) {
373 373
 
374 374
             $courses_html = _nx(
375 375
                 'You have purchased the following course:',
376 376
                 'You have purchased the following courses:',
377
-                count( $course_links ),
377
+                count($course_links),
378 378
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
379 379
             );
380 380
 
381
-            foreach( $course_links as $link ){
381
+            foreach ($course_links as $link) {
382 382
 
383
-                $courses_html .= '<li>' . $link . '</li>';
383
+                $courses_html .= '<li>'.$link.'</li>';
384 384
 
385 385
             }
386 386
 
387 387
             $courses_html .= ' </ul>';
388 388
 
389
-            wc_add_notice( $courses_html, 'success' );
389
+            wc_add_notice($courses_html, 'success');
390 390
         }
391 391
 
392 392
 	} // end course_link_order_form
@@ -399,20 +399,20 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @since 1.9.0
401 401
      */
402
-    public static function course_in_cart_message(){
402
+    public static function course_in_cart_message() {
403 403
 
404 404
         global $post;
405 405
 
406
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
406
+        if (self::is_course_in_cart($post->ID)) { ?>
407 407
 
408 408
             <div class="sensei-message info">
409 409
                 <?php
410 410
 
411
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
412
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
413
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
411
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
412
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
413
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
414 414
 
415
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
415
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
416 416
 
417 417
                 ?>
418 418
             </div>
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
      * @param $course_id
427 427
      * @return bool
428 428
      */
429
-    public static function is_course_in_cart( $course_id ){
429
+    public static function is_course_in_cart($course_id) {
430 430
 
431
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
432
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
431
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
432
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
433 433
 
434
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
434
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
435 435
 
436
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
436
+            if (self::is_product_in_cart($wc_post_id)) {
437 437
 
438 438
                 return true;
439 439
 
@@ -451,20 +451,20 @@  discard block
 block discarded – undo
451 451
      * @param $product_id
452 452
      * @return bool
453 453
      */
454
-    public static function is_product_in_cart( $product_id ){
454
+    public static function is_product_in_cart($product_id) {
455 455
 
456
-        if ( 0 < $product_id ) {
456
+        if (0 < $product_id) {
457 457
 
458
-            $product = wc_get_product( $product_id );
458
+            $product = wc_get_product($product_id);
459 459
 
460 460
             $parent_id = '';
461
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
461
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
462 462
                 $wc_product_id = $product->parent->id;
463 463
             }
464
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
464
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
465 465
 
466 466
                 $cart_product = $values['data'];
467
-                if( $product_id == $cart_product->id ) {
467
+                if ($product_id == $cart_product->id) {
468 468
 
469 469
                     return true;
470 470
 
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
      *  @type int $wp_post_id
487 487
      * }
488 488
      */
489
-    public static function get_free_product_ids(){
489
+    public static function get_free_product_ids() {
490 490
 
491
-        return  get_posts( array(
491
+        return  get_posts(array(
492 492
             'post_type' => 'product',
493 493
             'posts_per_page' => '1000',
494 494
             'fields' => 'ids',
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      * @since 1.9.0
514 514
      * @return array $wp_meta_query_param
515 515
      */
516
-    public static function get_free_courses_meta_query_args(){
516
+    public static function get_free_courses_meta_query_args() {
517 517
 
518 518
         return array(
519 519
             'relation' => 'OR',
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      * @since 1.9.0
538 538
      * @return array $wp_query_meta_query_args_param
539 539
      */
540
-    public static function get_paid_courses_meta_query_args(){
540
+    public static function get_paid_courses_meta_query_args() {
541 541
 
542 542
         $paid_product_ids = self::get_paid_product_ids();
543 543
 
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                 'key'     => '_course_woocommerce_product',
547 547
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
548 548
                 // query
549
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
549
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
550 550
                 'compare' => 'IN',
551 551
             ),
552 552
         );
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      * @since 1.9.0
561 561
      * @return array $product_query_args
562 562
      */
563
-    public static function get_paid_products_on_sale_query_args(){
563
+    public static function get_paid_products_on_sale_query_args() {
564 564
 
565 565
         $args = array(
566 566
                    'post_type' 		=> 'product',
@@ -570,9 +570,9 @@  discard block
 block discarded – undo
570 570
                    'suppress_filters' 	=> 0
571 571
         );
572 572
 
573
-        $args[ 'fields' ]     = 'ids';
573
+        $args['fields']     = 'ids';
574 574
 
575
-        $args[ 'meta_query' ] = array(
575
+        $args['meta_query'] = array(
576 576
             'relation' => 'AND',
577 577
             array(
578 578
                 'key'=> '_regular_price',
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
      *
600 600
      * @return array
601 601
      */
602
-    public static function get_paid_products_not_on_sale_query_args(){
602
+    public static function get_paid_products_not_on_sale_query_args() {
603 603
 
604 604
         $args = array(
605 605
             'post_type' 		=> 'product',
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
             'suppress_filters' 	=> 0
610 610
         );
611 611
 
612
-        $args[ 'fields' ]     = 'ids';
613
-        $args[ 'meta_query' ] = array(
612
+        $args['fields']     = 'ids';
613
+        $args['meta_query'] = array(
614 614
             'relation' => 'AND',
615 615
             array(
616 616
                 'key'=> '_regular_price',
@@ -636,24 +636,24 @@  discard block
 block discarded – undo
636 636
      *
637 637
      * @return array $woocommerce_paid_product_ids
638 638
      */
639
-    public static function get_paid_product_ids(){
639
+    public static function get_paid_product_ids() {
640 640
 
641 641
         // get all the paid WooCommerce products that has regular
642 642
         // and sale price greater than 0
643 643
         // will be used later to check for course with the id as meta
644
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
644
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
645 645
 
646 646
         // get all the paid WooCommerce products that has regular price
647 647
         // greater than 0 without a sale price
648 648
         // will be used later to check for course with the id as meta
649
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
649
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
650 650
 
651 651
         // combine products ID's with regular and sale price grater than zero and those without
652 652
         // sale but regular price greater than zero
653
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
653
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
654 654
 
655 655
         // if
656
-        if( empty($woocommerce_paid_product_ids) ){
656
+        if (empty($woocommerce_paid_product_ids)) {
657 657
             return array( );
658 658
         }
659 659
         return $woocommerce_paid_product_ids;
@@ -673,24 +673,24 @@  discard block
 block discarded – undo
673 673
      * @param array $args
674 674
      * @return array
675 675
      */
676
-    public static function get_free_courses( $args = array() ){
676
+    public static function get_free_courses($args = array()) {
677 677
 
678 678
         $free_course_query_args = Sensei_Course::get_default_query_args();
679
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
679
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
680 680
 
681
-	    if( !empty( $args ) ){
682
-		    wp_parse_args( $args, $free_course_query_args  );
681
+	    if ( ! empty($args)) {
682
+		    wp_parse_args($args, $free_course_query_args);
683 683
 	    }
684 684
 
685 685
         // don't show any paid courses
686 686
         $courses = self::get_paid_courses();
687 687
         $ids = array();
688
-        foreach( $courses as $course ){
688
+        foreach ($courses as $course) {
689 689
             $ids[] = $course->ID;
690 690
         }
691
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
691
+        $free_course_query_args['post__not_in'] = $ids;
692 692
 
693
-        return get_posts( $free_course_query_args );
693
+        return get_posts($free_course_query_args);
694 694
 
695 695
     }
696 696
 
@@ -702,17 +702,17 @@  discard block
 block discarded – undo
702 702
      *
703 703
      * @return array
704 704
      */
705
-    public static function get_paid_courses( $args = array() ){
705
+    public static function get_paid_courses($args = array()) {
706 706
 
707 707
         $paid_course_query_args = Sensei_Course::get_default_query_args();
708 708
 
709
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
709
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
710 710
 
711
-	    if( !empty( $args ) ){
712
-		    wp_parse_args( $args, $paid_course_query_args  );
711
+	    if ( ! empty($args)) {
712
+		    wp_parse_args($args, $paid_course_query_args);
713 713
 	    }
714 714
 
715
-        return get_posts(  $paid_course_query_args );
715
+        return get_posts($paid_course_query_args);
716 716
     }
717 717
 
718 718
     /**
@@ -727,17 +727,17 @@  discard block
 block discarded – undo
727 727
      * @param int $course_id
728 728
      * @return string $html markup for the button or nothing if user not allowed to buy
729 729
      */
730
-    public static function the_add_to_cart_button_html( $course_id ){
730
+    public static function the_add_to_cart_button_html($course_id) {
731 731
 
732
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id ) || self::is_course_in_cart( $course_id ) ) {
732
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id) || self::is_course_in_cart($course_id)) {
733 733
             return '';
734 734
         }
735 735
 
736
-        $wc_post_id = self::get_course_product_id( $course_id );
736
+        $wc_post_id = self::get_course_product_id($course_id);
737 737
 
738 738
         // Check if customer purchased the product
739
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
740
-            || empty( $wc_post_id ) ) {
739
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
740
+            || empty($wc_post_id)) {
741 741
 
742 742
             return '';
743 743
 
@@ -745,15 +745,15 @@  discard block
 block discarded – undo
745 745
 
746 746
         // based on simple.php in WC templates/single-product/add-to-cart/
747 747
         // Get the product
748
-        $product = self::get_product_object( $wc_post_id );
748
+        $product = self::get_product_object($wc_post_id);
749 749
 
750 750
         // do not show the button for invalid products, non purchasable products, out
751 751
         // of stock product or if course is already in cart
752
-        if ( ! isset ( $product )
753
-            || ! is_object( $product )
752
+        if ( ! isset ($product)
753
+            || ! is_object($product)
754 754
             || ! $product->is_purchasable()
755 755
             || ! $product->is_in_stock()
756
-            || self::is_course_in_cart( $wc_post_id ) ) {
756
+            || self::is_course_in_cart($wc_post_id)) {
757 757
 
758 758
             return '';
759 759
 
@@ -764,23 +764,23 @@  discard block
 block discarded – undo
764 764
         //
765 765
         ?>
766 766
 
767
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
767
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
768 768
               class="cart"
769 769
               method="post"
770 770
               enctype="multipart/form-data">
771 771
 
772
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
772
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
773 773
 
774 774
             <input type="hidden" name="quantity" value="1" />
775 775
 
776
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
776
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
777 777
 
778 778
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
779
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
779
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
780 780
 
781
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
781
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
782 782
 
783
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
783
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
784 784
 
785 785
                     <?php } ?>
786 786
 
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             <?php } ?>
790 790
 
791 791
             <button type="submit" class="single_add_to_cart_button button alt">
792
-                <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?>
792
+                <?php $button_text = $product->get_price_html().' - '.__('Purchase this Course', 'woothemes-sensei'); ?>
793 793
                 <?php
794 794
                 /**
795 795
                  * Filter Add to Cart button text
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
                  *
799 799
                  * @param string $button_text
800 800
                  */
801
-                echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text );
801
+                echo apply_filters('sensei_wc_single_add_to_cart_button_text', $button_text);
802 802
                 ?>
803 803
             </button>
804 804
 
@@ -818,26 +818,26 @@  discard block
 block discarded – undo
818 818
      *
819 819
      * @return string $message
820 820
      */
821
-    public static function alter_no_permissions_message( $message, $post_id ){
821
+    public static function alter_no_permissions_message($message, $post_id) {
822 822
 
823
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
823
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
824 824
             return  $message;
825 825
         }
826 826
 
827
-        $product_id = self::get_course_product_id( $post_id );
827
+        $product_id = self::get_course_product_id($post_id);
828 828
 
829
-        if( ! $product_id
830
-            || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
829
+        if ( ! $product_id
830
+            || ! self::has_customer_bought_product(get_current_user_id(), $product_id)) {
831 831
 
832 832
             return $message;
833 833
 
834 834
         }
835 835
 
836 836
         ob_start();
837
-        self::the_course_no_permissions_message( $post_id );
837
+        self::the_course_no_permissions_message($post_id);
838 838
         $woocommerce_course_no_permissions_message = ob_get_clean();
839 839
 
840
-        return $woocommerce_course_no_permissions_message ;
840
+        return $woocommerce_course_no_permissions_message;
841 841
 
842 842
     }
843 843
     /**
@@ -846,18 +846,18 @@  discard block
 block discarded – undo
846 846
      *
847 847
      * @since 1.9.0
848 848
      */
849
-    public static function the_course_no_permissions_message( $course_id ){
849
+    public static function the_course_no_permissions_message($course_id) {
850 850
 
851 851
         // login link
852
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
853
-	    $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
854
-	    $wc_product_id =  self::get_course_product_id( $course_id );
852
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
853
+	    $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
854
+	    $wc_product_id = self::get_course_product_id($course_id);
855 855
 
856
-	    if ( self::is_product_in_cart( $wc_product_id ) ) {
856
+	    if (self::is_product_in_cart($wc_product_id)) {
857 857
 
858
-		    $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>';
858
+		    $cart_link = '<a href="'.wc_get_checkout_url().'" title="'.__('Checkout', 'woocommerce').'">'.__('checkout', 'woocommerce').'</a>';
859 859
 
860
-		    $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link );
860
+		    $message = sprintf(__('This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei'), $cart_link);
861 861
 		    ?>
862 862
 		    <span class="add-to-cart-login">
863 863
 		            <?php echo $message; ?>
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
 		    <?php
867 867
 
868
-	    } elseif ( is_user_logged_in() ) {
868
+	    } elseif (is_user_logged_in()) {
869 869
 
870 870
 		    ?>
871 871
 		    <style>
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
 		    <?php
878 878
 
879 879
 	    } else {
880
-		    $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
880
+		    $message = sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link);
881 881
 	        ?>
882 882
 		        <span class="add-to-cart-login">
883 883
 		            <?php echo $message; ?>
@@ -897,34 +897,34 @@  discard block
 block discarded – undo
897 897
      *
898 898
      * @return bool
899 899
      */
900
-    public static function has_customer_bought_product ( $user_id, $product_id ){
900
+    public static function has_customer_bought_product($user_id, $product_id) {
901 901
 
902
-        $orders = self::get_user_product_orders( $user_id, $product_id );
902
+        $orders = self::get_user_product_orders($user_id, $product_id);
903 903
 
904
-        foreach ( $orders as $order_id ) {
904
+        foreach ($orders as $order_id) {
905 905
 
906
-            $order = new WC_Order( $order_id->ID );
906
+            $order = new WC_Order($order_id->ID);
907 907
 
908 908
             // wc-active is the subscriptions complete status
909
-            if ( ! in_array( $order->post_status, array( 'wc-processing', 'wc-completed' ) )
910
-                || ! ( 0 < sizeof( $order->get_items() ) )  ){
909
+            if ( ! in_array($order->post_status, array('wc-processing', 'wc-completed'))
910
+                || ! (0 < sizeof($order->get_items()))) {
911 911
 
912 912
                 continue;
913 913
 
914 914
             }
915 915
 
916
-            foreach( $order->get_items() as $item ) {
916
+            foreach ($order->get_items() as $item) {
917 917
 
918 918
                 // Check if user has bought product
919
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
919
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
920 920
 
921 921
                     // Check if user has an active subscription for product
922
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
923
-                        $sub_key = wcs_get_subscription( $order );
924
-                        if( $sub_key ) {
925
-                            $sub = wcs_get_subscription( $sub_key );
926
-                            if( $sub && isset( $sub['status'] ) ) {
927
-                                if( 'active' == $sub['status'] ) {
922
+                    if (class_exists('WC_Subscriptions_Manager')) {
923
+                        $sub_key = wcs_get_subscription($order);
924
+                        if ($sub_key) {
925
+                            $sub = wcs_get_subscription($sub_key);
926
+                            if ($sub && isset($sub['status'])) {
927
+                                if ('active' == $sub['status']) {
928 928
                                     return true;
929 929
                                 } else {
930 930
                                     return false;
@@ -956,11 +956,11 @@  discard block
 block discarded – undo
956 956
      * @return string $woocommerce_product_id or false if none exist
957 957
      *
958 958
      */
959
-    public static function get_course_product_id( $course_id ){
959
+    public static function get_course_product_id($course_id) {
960 960
 
961
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
961
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
962 962
 
963
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
963
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
964 964
             return false;
965 965
         }
966 966
 
@@ -976,11 +976,11 @@  discard block
 block discarded – undo
976 976
      * @param array $classes
977 977
      * @return array
978 978
      */
979
-    public static function add_woocommerce_body_class( $classes ){
979
+    public static function add_woocommerce_body_class($classes) {
980 980
 
981
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
981
+        if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) {
982 982
 
983
-            $classes[] ='woocommerce';
983
+            $classes[] = 'woocommerce';
984 984
 
985 985
         }
986 986
 
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
      *
999 999
      * @return  void
1000 1000
      */
1001
-    public static function activate_subscription(  $order ) {
1001
+    public static function activate_subscription($order) {
1002 1002
 
1003 1003
         $order_user = get_user_by('id', $order->user_id);
1004 1004
         $user['ID'] = $order_user->ID;
@@ -1007,13 +1007,13 @@  discard block
 block discarded – undo
1007 1007
         $user['user_url'] = $order_user->user_url;
1008 1008
 
1009 1009
         // Run through each product ordered
1010
-        if ( ! sizeof($order->get_items() )>0 ) {
1010
+        if ( ! sizeof($order->get_items()) > 0) {
1011 1011
 
1012 1012
             return;
1013 1013
 
1014 1014
         }
1015 1015
 
1016
-        foreach($order->get_items() as $item) {
1016
+        foreach ($order->get_items() as $item) {
1017 1017
 
1018 1018
             $product_type = '';
1019 1019
 
@@ -1028,21 +1028,21 @@  discard block
 block discarded – undo
1028 1028
 
1029 1029
             } // End If Statement
1030 1030
 
1031
-            $_product = self::get_product_object( $item_id, $product_type );
1031
+            $_product = self::get_product_object($item_id, $product_type);
1032 1032
 
1033 1033
             // Get courses that use the WC product
1034 1034
             $courses = array();
1035 1035
 
1036
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1036
+            if ( ! in_array($product_type, self::get_subscription_types())) {
1037 1037
 
1038
-                $courses = Sensei()->course->get_product_courses( $item_id );
1038
+                $courses = Sensei()->course->get_product_courses($item_id);
1039 1039
 
1040 1040
             } // End If Statement
1041 1041
 
1042 1042
             // Loop and add the user to the course.
1043
-            foreach ( $courses as $course_item ){
1043
+            foreach ($courses as $course_item) {
1044 1044
 
1045
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1045
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
1046 1046
 
1047 1047
             } // End For Loop
1048 1048
 
@@ -1060,13 +1060,13 @@  discard block
 block discarded – undo
1060 1060
      *
1061 1061
      * @return  void
1062 1062
      */
1063
-    public static function email_course_details(  $order ){
1063
+    public static function email_course_details($order) {
1064 1064
 
1065 1065
         global $woocommerce;
1066 1066
 
1067 1067
         // exit early if not wc-completed or wc-processing
1068
-        if( 'wc-completed' != $order->post_status
1069
-            && 'wc-processing' != $order->post_status  ) {
1068
+        if ('wc-completed' != $order->post_status
1069
+            && 'wc-processing' != $order->post_status) {
1070 1070
             return;
1071 1071
         }
1072 1072
 
@@ -1074,16 +1074,16 @@  discard block
 block discarded – undo
1074 1074
         $order_id = $order->id;
1075 1075
 
1076 1076
         //If object have items go through them all to find course
1077
-        if ( 0 < sizeof( $order_items ) ) {
1077
+        if (0 < sizeof($order_items)) {
1078 1078
 
1079
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1079
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1080 1080
             $order_contains_courses = false;
1081 1081
 
1082 1082
 
1083
-            foreach ( $order_items as $item ) {
1083
+            foreach ($order_items as $item) {
1084 1084
 
1085 1085
                 $product_type = '';
1086
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1086
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1087 1087
                     // If item has variation_id then its from variation
1088 1088
                     $item_id = $item['variation_id'];
1089 1089
                     $product_type = 'variation';
@@ -1092,9 +1092,9 @@  discard block
 block discarded – undo
1092 1092
                     $item_id = $item['product_id'];
1093 1093
                 } // End If Statement
1094 1094
 
1095
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1095
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1096 1096
 
1097
-                if( $user_id ) {
1097
+                if ($user_id) {
1098 1098
 
1099 1099
                     // Get all courses for product
1100 1100
                     $args = array(
@@ -1109,16 +1109,16 @@  discard block
 block discarded – undo
1109 1109
                         'orderby' => 'menu_order date',
1110 1110
                         'order' => 'ASC',
1111 1111
                     );
1112
-                    $courses = get_posts( $args );
1112
+                    $courses = get_posts($args);
1113 1113
 
1114
-                    if( $courses && count( $courses ) > 0 ) {
1114
+                    if ($courses && count($courses) > 0) {
1115 1115
 
1116
-                        foreach( $courses as $course ) {
1116
+                        foreach ($courses as $course) {
1117 1117
 
1118 1118
                             $title = $course->post_title;
1119
-                            $permalink = get_permalink( $course->ID );
1119
+                            $permalink = get_permalink($course->ID);
1120 1120
                             $order_contains_courses = true;
1121
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1121
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1122 1122
                         }
1123 1123
 
1124 1124
 
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
             } // end for each order item
1130 1130
 
1131 1131
             // Output Course details
1132
-            if( $order_contains_courses ){
1132
+            if ($order_contains_courses) {
1133 1133
 
1134 1134
                 echo $course_details_html;
1135 1135
 
@@ -1147,33 +1147,33 @@  discard block
 block discarded – undo
1147 1147
      * @param   int $order_id WC order ID
1148 1148
      * @return  void
1149 1149
      */
1150
-    public static function complete_order ( $order_id = 0 ) {
1150
+    public static function complete_order($order_id = 0) {
1151 1151
 
1152 1152
         $order_user = array();
1153 1153
 
1154 1154
         // Check for WooCommerce
1155
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1155
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1156 1156
             // Get order object
1157
-            $order = new WC_Order( $order_id );
1157
+            $order = new WC_Order($order_id);
1158 1158
 
1159
-	        if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) {
1159
+	        if ( ! in_array($order->get_status(), array('complete', 'processing'))) {
1160 1160
 
1161 1161
 		        return;
1162 1162
 
1163 1163
 	        }
1164 1164
 
1165
-            $user = get_user_by( 'id', $order->get_user_id() );
1165
+            $user = get_user_by('id', $order->get_user_id());
1166 1166
             $order_user['ID'] = $user->ID;
1167 1167
             $order_user['user_login'] = $user->user_login;
1168 1168
             $order_user['user_email'] = $user->user_email;
1169 1169
             $order_user['user_url'] = $user->user_url;
1170 1170
             // Run through each product ordered
1171
-            if ( 0 < sizeof( $order->get_items() ) ) {
1171
+            if (0 < sizeof($order->get_items())) {
1172 1172
 
1173
-                foreach( $order->get_items() as $item ) {
1173
+                foreach ($order->get_items() as $item) {
1174 1174
 
1175 1175
                     $product_type = '';
1176
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1176
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1177 1177
 
1178 1178
                         $item_id = $item['variation_id'];
1179 1179
                         $product_type = 'variation';
@@ -1184,15 +1184,15 @@  discard block
 block discarded – undo
1184 1184
 
1185 1185
                     } // End If Statement
1186 1186
 
1187
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1187
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1188 1188
 
1189 1189
                     // Get courses that use the WC product
1190
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1190
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1191 1191
 
1192 1192
                     // Loop and update those courses
1193
-                    foreach ( $courses as $course_item ) {
1193
+                    foreach ($courses as $course_item) {
1194 1194
 
1195
-                        $update_course = self::course_update( $course_item->ID, $order_user );
1195
+                        $update_course = self::course_update($course_item->ID, $order_user);
1196 1196
 
1197 1197
                     } // End For Loop
1198 1198
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
             } // End If Statement
1202 1202
             // Add meta to indicate that payment has been completed successfully
1203
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1203
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1204 1204
 
1205 1205
         } // End If Statement
1206 1206
 
@@ -1214,34 +1214,34 @@  discard block
 block discarded – undo
1214 1214
      * @param   integer| WC_Order $order_id order ID
1215 1215
      * @return  void
1216 1216
      */
1217
-    public static function cancel_order ( $order_id ) {
1217
+    public static function cancel_order($order_id) {
1218 1218
 
1219 1219
 		// Get order object
1220
-		if( is_object( $order_id ) ){
1220
+		if (is_object($order_id)) {
1221 1221
 
1222 1222
 			$order = $order_id;
1223 1223
 
1224
-		}else{
1224
+		} else {
1225 1225
 
1226
-			$order = new WC_Order( $order_id );
1226
+			$order = new WC_Order($order_id);
1227 1227
 		}
1228 1228
 
1229
-		if ( ! in_array( $order->get_status(), array( 'cancelled', 'refunded' ) ) ) {
1229
+		if ( ! in_array($order->get_status(), array('cancelled', 'refunded'))) {
1230 1230
 
1231 1231
 			return;
1232 1232
 
1233 1233
 		}
1234 1234
 
1235 1235
         // Run through each product ordered
1236
-        if ( 0 < sizeof( $order->get_items() ) ) {
1236
+        if (0 < sizeof($order->get_items())) {
1237 1237
 
1238 1238
             // Get order user
1239
-            $user_id = $order->__get( 'user_id' );
1239
+            $user_id = $order->__get('user_id');
1240 1240
 
1241
-            foreach( $order->get_items() as $item ) {
1241
+            foreach ($order->get_items() as $item) {
1242 1242
 
1243 1243
                 $product_type = '';
1244
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1244
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1245 1245
 
1246 1246
                     $item_id = $item['variation_id'];
1247 1247
                     $product_type = 'variation';
@@ -1252,20 +1252,20 @@  discard block
 block discarded – undo
1252 1252
 
1253 1253
                 } // End If Statement
1254 1254
 
1255
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1255
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1256 1256
 
1257 1257
                 // Get courses that use the WC product
1258 1258
                 $courses = array();
1259
-                $courses = Sensei()->course->get_product_courses( $item_id );
1259
+                $courses = Sensei()->course->get_product_courses($item_id);
1260 1260
 
1261 1261
                 // Loop and update those courses
1262
-                foreach ($courses as $course_item){
1262
+                foreach ($courses as $course_item) {
1263 1263
 
1264
-	                if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){
1264
+	                if (self::has_customer_bought_product($user_id, $course_item->ID)) {
1265 1265
 		                continue;
1266 1266
 	                }
1267 1267
                     // Check and Remove course from courses user meta
1268
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1268
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1269 1269
 
1270 1270
                 } // End For Loop
1271 1271
 
@@ -1286,30 +1286,30 @@  discard block
 block discarded – undo
1286 1286
      * @param   string  $product_type  '' or 'variation'
1287 1287
      * @return   WC_Product $wc_product_object
1288 1288
      */
1289
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1289
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1290 1290
 
1291 1291
         $wc_product_object = false;
1292
-        if ( 0 < intval( $wc_product_id ) ) {
1292
+        if (0 < intval($wc_product_id)) {
1293 1293
 
1294 1294
             // Get the product
1295
-            if ( function_exists( 'wc_get_product' ) ) {
1295
+            if (function_exists('wc_get_product')) {
1296 1296
 
1297
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1297
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1298 1298
 
1299
-            } elseif ( function_exists( 'get_product' ) ) {
1299
+            } elseif (function_exists('get_product')) {
1300 1300
 
1301
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1301
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1302 1302
 
1303 1303
             } else {
1304 1304
 
1305 1305
                 // Pre WC 2.0
1306
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1306
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1307 1307
 
1308
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1308
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1309 1309
 
1310 1310
                 } else {
1311 1311
 
1312
-                    $wc_product_object = new WC_Product( $wc_product_id );
1312
+                    $wc_product_object = new WC_Product($wc_product_id);
1313 1313
 
1314 1314
                 } // End If Statement
1315 1315
 
@@ -1332,19 +1332,19 @@  discard block
 block discarded – undo
1332 1332
      *
1333 1333
      * @return bool|int
1334 1334
      */
1335
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1335
+    public static function course_update($course_id = 0, $order_user = array()) {
1336 1336
 
1337 1337
         global $current_user;
1338 1338
 
1339
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1339
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1340 1340
 
1341 1341
         $data_update = false;
1342 1342
 
1343 1343
         // Get the product ID
1344
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1344
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1345 1345
 
1346 1346
         // Check if in the admin
1347
-        if ( is_admin() ) {
1347
+        if (is_admin()) {
1348 1348
 
1349 1349
             $user_login = $order_user['user_login'];
1350 1350
             $user_email = $order_user['user_email'];
@@ -1361,28 +1361,28 @@  discard block
 block discarded – undo
1361 1361
         } // End If Statement
1362 1362
 
1363 1363
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1364
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1365
-        if( 0 < absint( $course_prerequisite_id ) ) {
1364
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1365
+        if (0 < absint($course_prerequisite_id)) {
1366 1366
 
1367
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1368
-            if ( ! $prereq_course_complete ) {
1367
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1368
+            if ( ! $prereq_course_complete) {
1369 1369
 
1370 1370
                 // Remove all course user meta
1371
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1371
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1372 1372
 
1373 1373
             }
1374 1374
         }
1375 1375
 
1376
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1376
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1377 1377
 
1378 1378
         if ( ! $is_user_taking_course
1379 1379
             && Sensei_WC::is_woocommerce_active()
1380 1380
             && 0 < $wc_post_id
1381
-            && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) {
1381
+            && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id)) {
1382 1382
 
1383
-	            $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) );
1383
+	            $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1384 1384
 
1385
-	            if ( true == $activity_logged ) {
1385
+	            if (true == $activity_logged) {
1386 1386
 
1387 1387
 		            $is_user_taking_course = true;
1388 1388
 
@@ -1404,14 +1404,14 @@  discard block
 block discarded – undo
1404 1404
      *
1405 1405
      * @return boolean                 Modified guest checkout setting
1406 1406
      */
1407
-    public static function disable_guest_checkout( $guest_checkout ) {
1407
+    public static function disable_guest_checkout($guest_checkout) {
1408 1408
 
1409
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1409
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1410 1410
 
1411
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1411
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1412 1412
 
1413
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1414
-                    if( isset( $product['product_id'] ) ) {
1413
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1414
+                    if (isset($product['product_id'])) {
1415 1415
 
1416 1416
                         $args = array(
1417 1417
                             'posts_per_page' => -1,
@@ -1424,11 +1424,11 @@  discard block
 block discarded – undo
1424 1424
                             )
1425 1425
                         );
1426 1426
 
1427
-                        $posts = get_posts( $args );
1427
+                        $posts = get_posts($args);
1428 1428
 
1429
-                        if( $posts && count( $posts ) > 0 ) {
1429
+                        if ($posts && count($posts) > 0) {
1430 1430
 
1431
-                            foreach( $posts as $course ) {
1431
+                            foreach ($posts as $course) {
1432 1432
                                 $guest_checkout = '';
1433 1433
                                 break;
1434 1434
 
@@ -1457,23 +1457,23 @@  discard block
 block discarded – undo
1457 1457
      *
1458 1458
      * @return string
1459 1459
      **/
1460
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1460
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1461 1461
 
1462
-        $order = new WC_Order( $order_id );
1462
+        $order = new WC_Order($order_id);
1463 1463
 
1464
-        if ( ! isset ( $order ) ) return '';
1464
+        if ( ! isset ($order)) return '';
1465 1465
 
1466
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1466
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1467 1467
 
1468 1468
             $virtual_order = true;
1469 1469
 
1470
-            if ( count( $order->get_items() ) > 0 ) {
1470
+            if (count($order->get_items()) > 0) {
1471 1471
 
1472
-                foreach( $order->get_items() as $item ) {
1472
+                foreach ($order->get_items() as $item) {
1473 1473
 
1474
-                    if ( $item['product_id'] > 0 ) {
1475
-                        $_product = $order->get_product_from_item( $item );
1476
-                        if ( ! $_product->is_virtual() ) {
1474
+                    if ($item['product_id'] > 0) {
1475
+                        $_product = $order->get_product_from_item($item);
1476
+                        if ( ! $_product->is_virtual()) {
1477 1477
 
1478 1478
                             $virtual_order = false;
1479 1479
                             break;
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             } // End If Statement
1488 1488
 
1489 1489
             // virtual order, mark as completed
1490
-            if ( $virtual_order ) {
1490
+            if ($virtual_order) {
1491 1491
 
1492 1492
                 return 'completed';
1493 1493
 
@@ -1510,14 +1510,14 @@  discard block
 block discarded – undo
1510 1510
      * @param  integer $user_id
1511 1511
      * @return boolean $user_access_permission
1512 1512
      */
1513
-    public static function get_subscription_permission( $user_access_permission , $user_id ){
1513
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1514 1514
 
1515 1515
         global $post;
1516 1516
 
1517 1517
         // ignore the current case if the following conditions are met
1518
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1519
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1520
-            || ! wcs_user_has_subscription( $user_id) ){
1518
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1519
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1520
+            || ! wcs_user_has_subscription($user_id)) {
1521 1521
 
1522 1522
             return $user_access_permission;
1523 1523
 
@@ -1527,25 +1527,25 @@  discard block
 block discarded – undo
1527 1527
         // is the subscription on the the current course?
1528 1528
 
1529 1529
         $course_id = 0;
1530
-        if ( 'course' == $post->post_type ){
1530
+        if ('course' == $post->post_type) {
1531 1531
 
1532 1532
             $course_id = $post->ID;
1533 1533
 
1534
-        } elseif ( 'lesson' == $post->post_type ) {
1534
+        } elseif ('lesson' == $post->post_type) {
1535 1535
 
1536
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1536
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1537 1537
 
1538 1538
         } else {
1539 1539
 
1540
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1541
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1540
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1541
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1542 1542
 
1543 1543
         }
1544 1544
 
1545 1545
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1546
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1547
-        $product = wc_get_product( $product_id );
1548
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1546
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1547
+        $product = wc_get_product($product_id);
1548
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1549 1549
 
1550 1550
             return $user_access_permission;
1551 1551
 
@@ -1553,19 +1553,19 @@  discard block
 block discarded – undo
1553 1553
 
1554 1554
         // give access if user has active subscription on the product otherwise restrict it.
1555 1555
         // also check if the user was added to the course directly after the subscription started.
1556
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1557
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1558
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1556
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1557
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1558
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1559 1559
 
1560 1560
             $user_access_permission = true;
1561 1561
 
1562
-        }else{
1562
+        } else {
1563 1563
 
1564 1564
             $user_access_permission = false;
1565 1565
             // do not show the WC permissions message
1566
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1567
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1568
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1566
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1567
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1568
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1569 1569
         }
1570 1570
 
1571 1571
         return $user_access_permission;
@@ -1581,9 +1581,9 @@  discard block
 block discarded – undo
1581 1581
 	 *
1582 1582
 	 * @return bool $has_user_started_course
1583 1583
 	 */
1584
-	public static function get_subscription_user_started_course( $has_user_started_course, $course_id, $user_id ){
1584
+	public static function get_subscription_user_started_course($has_user_started_course, $course_id, $user_id) {
1585 1585
 
1586
-		if ( ! is_user_logged_in( ) ) {
1586
+		if ( ! is_user_logged_in( )) {
1587 1587
 
1588 1588
 			return $has_user_started_course;
1589 1589
 
@@ -1591,26 +1591,26 @@  discard block
 block discarded – undo
1591 1591
 
1592 1592
 		// cached user course access for this process instance
1593 1593
 		global $sensei_wc_subscription_access_store;
1594
-		if ( ! is_array( $sensei_wc_subscription_access_store ) ) {
1594
+		if ( ! is_array($sensei_wc_subscription_access_store)) {
1595 1595
 			$sensei_wc_subscription_access_store = array();
1596 1596
 		}
1597 1597
 
1598 1598
 		// user temp cached data so we don't output the mesage again
1599
-		$user_data_index_key = $course_id .'_' . $user_id;
1600
-		if ( isset( $sensei_wc_subscription_access_store[ $user_data_index_key  ] ) ) {
1599
+		$user_data_index_key = $course_id.'_'.$user_id;
1600
+		if (isset($sensei_wc_subscription_access_store[$user_data_index_key])) {
1601 1601
 
1602
-			return $sensei_wc_subscription_access_store[ $user_data_index_key ];
1602
+			return $sensei_wc_subscription_access_store[$user_data_index_key];
1603 1603
 
1604 1604
 		} else {
1605 1605
 
1606
-			if( empty( $course_id ) || empty( $user_id ) ){
1606
+			if (empty($course_id) || empty($user_id)) {
1607 1607
 				return $has_user_started_course;
1608 1608
 			}
1609 1609
 
1610 1610
 			// if the course has no subscription WooCommerce product attached to return the permissions as is
1611
-			$product_id = Sensei_WC::get_course_product_id( $course_id );
1612
-			$product = wc_get_product( $product_id );
1613
-			if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1611
+			$product_id = Sensei_WC::get_course_product_id($course_id);
1612
+			$product = wc_get_product($product_id);
1613
+			if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1614 1614
 
1615 1615
 				return $has_user_started_course;
1616 1616
 
@@ -1618,9 +1618,9 @@  discard block
 block discarded – undo
1618 1618
 
1619 1619
 			// give access if user has active subscription on the product otherwise restrict it.
1620 1620
 			// also check if the user was added to the course directly after the subscription started.
1621
-			if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1622
-			    || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1623
-			    || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  )  ){
1621
+			if (wcs_user_has_subscription($user_id, $product_id, 'active')
1622
+			    || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1623
+			    || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1624 1624
 
1625 1625
 				$has_user_started_course = true;
1626 1626
 
@@ -1629,7 +1629,7 @@  discard block
 block discarded – undo
1629 1629
 				$has_user_started_course = false;
1630 1630
 
1631 1631
 			}
1632
-			$sensei_wc_subscription_access_store[ $user_data_index_key ] = $has_user_started_course;
1632
+			$sensei_wc_subscription_access_store[$user_data_index_key] = $has_user_started_course;
1633 1633
 			return $has_user_started_course;
1634 1634
 		}
1635 1635
 
@@ -1641,9 +1641,9 @@  discard block
 block discarded – undo
1641 1641
      * @since 1.9.0
1642 1642
      * @return array
1643 1643
      */
1644
-    public static function get_subscription_types(){
1644
+    public static function get_subscription_types() {
1645 1645
 
1646
-        return array( 'subscription','subscription_variation','variable-subscription' );
1646
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1647 1647
 
1648 1648
     }
1649 1649
 
@@ -1663,16 +1663,16 @@  discard block
 block discarded – undo
1663 1663
      *
1664 1664
      * @return bool
1665 1665
      */
1666
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1666
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1667 1667
 
1668 1668
         $course_start_date = '';
1669 1669
         $subscription_start_date = '';
1670
-        $is_a_subscription ='';
1670
+        $is_a_subscription = '';
1671 1671
         $was_user_added_without_subscription = false;
1672 1672
 
1673 1673
         // if user is not on the course they were not added
1674
-	    remove_filter( 'sensei_user_started_course',     array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 );
1675
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1674
+	    remove_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3);
1675
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1676 1676
 
1677 1677
             return false;
1678 1678
 
@@ -1681,36 +1681,36 @@  discard block
 block discarded – undo
1681 1681
         // if user doesn't have a subscription and is taking the course
1682 1682
         // they were added manually
1683 1683
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1684
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1684
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1685 1685
 
1686 1686
             return true;
1687 1687
 
1688 1688
         }
1689 1689
 
1690
-	    add_filter( 'sensei_user_started_course',     array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 );
1690
+	    add_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3);
1691 1691
 
1692
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1692
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1693 1693
 
1694 1694
         // comparing dates setup data
1695
-        $course_start_date = date_create( $course_status->comment_date );
1696
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1695
+        $course_start_date = date_create($course_status->comment_date);
1696
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1697 1697
 
1698 1698
         // comparing every subscription
1699
-        foreach( $subscriptions as $subscription ){
1699
+        foreach ($subscriptions as $subscription) {
1700 1700
 
1701 1701
             // for the following statuses we know the user was not added
1702 1702
             // manually
1703 1703
             $status = $subscription->get_status();
1704
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1704
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1705 1705
 
1706 1706
                 continue;
1707 1707
 
1708 1708
             }
1709 1709
 
1710
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1710
+            $current_subscription_start_date = date_create($subscription->modified_date);
1711 1711
 
1712 1712
             // is the last updated subscription date newer than course start date
1713
-            if (  $current_subscription_start_date > $course_start_date   ) {
1713
+            if ($current_subscription_start_date > $course_start_date) {
1714 1714
 
1715 1715
                 return false;
1716 1716
 
@@ -1729,20 +1729,20 @@  discard block
 block discarded – undo
1729 1729
 	 *
1730 1730
 	 * @return array $orders
1731 1731
 	 */
1732
-	public static function get_user_product_orders( $user_id =  0, $product_id ) {
1732
+	public static function get_user_product_orders($user_id = 0, $product_id) {
1733 1733
 
1734 1734
 		$args = array(
1735 1735
 			'numberposts' => -1,
1736 1736
 			'post_type' => 'shop_order',
1737 1737
 			'meta_key'    => '_customer_user',
1738
-			'meta_value'  => intval( $user_id ),
1738
+			'meta_value'  => intval($user_id),
1739 1739
 		);
1740 1740
 
1741
-		if( class_exists( 'WC_Subscriptions_Manager' ) ) {
1742
-			$args['post_type'] = array( 'shop_order', 'shop_subscription' );
1741
+		if (class_exists('WC_Subscriptions_Manager')) {
1742
+			$args['post_type'] = array('shop_order', 'shop_subscription');
1743 1743
 		}
1744 1744
 
1745
-		return get_posts( $args );
1745
+		return get_posts($args);
1746 1746
 
1747 1747
 	}
1748 1748
 
@@ -1758,12 +1758,12 @@  discard block
 block discarded – undo
1758 1758
 	 *
1759 1759
 	 * @return bool
1760 1760
 	 */
1761
-	public static function is_course_purchasable( $course_id = 0 ){
1761
+	public static function is_course_purchasable($course_id = 0) {
1762 1762
 
1763
-		if( ! self::is_woocommerce_active() ){
1763
+		if ( ! self::is_woocommerce_active()) {
1764 1764
 			return false;
1765 1765
 		}
1766
-		$course_product = wc_get_product( self::get_course_product_id( $course_id ) );
1766
+		$course_product = wc_get_product(self::get_course_product_id($course_id));
1767 1767
 
1768 1768
 		return $course_product->is_purchasable();
1769 1769
 
Please login to merge, or discard this patch.
includes/hooks/woocommerce.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,20 +7,20 @@  discard block
 block discarded – undo
7 7
  * show the WooCommerce course filter links above the courses
8 8
  * @since 1.9.0
9 9
  */
10
-add_filter( 'sensei_archive_course_filter_by_options', array( 'Sensei_WC', 'add_course_archive_wc_filter_links' ) );
10
+add_filter('sensei_archive_course_filter_by_options', array('Sensei_WC', 'add_course_archive_wc_filter_links'));
11 11
 
12 12
 /**
13 13
  * filter the queries for paid and free course based on the users selection.
14 14
  * @since 1.9.0
15 15
  */
16
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_free'));
17
-add_filter('pre_get_posts', array( 'Sensei_WC', 'course_archive_wc_filter_paid'));
16
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_free'));
17
+add_filter('pre_get_posts', array('Sensei_WC', 'course_archive_wc_filter_paid'));
18 18
 
19 19
 /**
20 20
  * Add woocommerce action above single course the action
21 21
  * @since 1.9.0
22 22
  */
23
-add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action') ,50) ;
23
+add_action('sensei_before_main_content', array('Sensei_WC', 'do_single_course_wc_single_product_action'), 50);
24 24
 
25 25
 
26 26
 /******************************
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  * Single Lesson Hooks
29 29
  *
30 30
  ******************************/
31
-add_filter( 'sensei_can_user_view_lesson', array( 'Sensei_WC','alter_can_user_view_lesson' ), 20, 3 );
31
+add_filter('sensei_can_user_view_lesson', array('Sensei_WC', 'alter_can_user_view_lesson'), 20, 3);
32 32
 
33 33
 /******************************
34 34
  *
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  *
37 37
  ******************************/
38 38
 // add a notice on the checkout page to tell users about the course they've purchase
39
-add_action( 'template_redirect', array( 'Sensei_WC','course_link_from_order' ) );
39
+add_action('template_redirect', array('Sensei_WC', 'course_link_from_order'));
40 40
 
41 41
 /******************************
42 42
  *
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
  ******************************/
46 46
 //@since 1.9.0
47 47
 //show a notice if the user has already added the current course to their cart
48
-add_action( 'sensei_single_course_content_inside_before', array( 'Sensei_WC', 'course_in_cart_message' ), 20 );
48
+add_action('sensei_single_course_content_inside_before', array('Sensei_WC', 'course_in_cart_message'), 20);
49 49
 
50 50
 /******************************
51 51
  *
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
  ******************************/
55 55
 //@since 1.9.0
56 56
 // alter the no permissions message to show the woocommerce message instead
57
-add_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
57
+add_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
58 58
 
59 59
 // @since 1.9.0
60 60
 // add  woocommerce class to the the no permission body class to ensure WooCommerce elements are styled
61
-add_filter( 'body_class', array( 'Sensei_WC', 'add_woocommerce_body_class' ), 20, 1);
61
+add_filter('body_class', array('Sensei_WC', 'add_woocommerce_body_class'), 20, 1);
62 62
 
63 63
 
64 64
 /************************************
@@ -67,28 +67,28 @@  discard block
 block discarded – undo
67 67
  *
68 68
  ************************************/
69 69
 // Add Email link to course orders
70
-add_action( 'woocommerce_email_after_order_table', array( 'Sensei_WC', 'email_course_details' ), 10, 1 );
70
+add_action('woocommerce_email_after_order_table', array('Sensei_WC', 'email_course_details'), 10, 1);
71 71
 
72 72
 /************************************
73 73
  *
74 74
  * Checkout
75 75
  *
76 76
  ************************************/
77
-add_action( 'woocommerce_delete_shop_order_transients',           array( 'Sensei_WC', 'complete_order' ) );
78
-add_action( 'woocommerce_delete_shop_order_transients',            array( 'Sensei_WC', 'cancel_order' ) );
77
+add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'complete_order'));
78
+add_action('woocommerce_delete_shop_order_transients', array('Sensei_WC', 'cancel_order'));
79 79
 // Disable guest checkout if a course is in the cart as we need a valid user to store data for
80
-add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( 'Sensei_WC', 'disable_guest_checkout' ) );
80
+add_filter('pre_option_woocommerce_enable_guest_checkout', array('Sensei_WC', 'disable_guest_checkout'));
81 81
 // Mark orders with virtual products as complete rather then stay processing
82
-add_filter( 'woocommerce_payment_complete_order_status',    array( 'Sensei_WC', 'virtual_order_payment_complete' ), 10, 2 );
82
+add_filter('woocommerce_payment_complete_order_status', array('Sensei_WC', 'virtual_order_payment_complete'), 10, 2);
83 83
 
84 84
 /************************************
85 85
  *
86 86
  * WooCommerce Subscriptions
87 87
  *
88 88
  ************************************/
89
-add_action( 'woocommerce_subscription_status_pending_to_active', array( 'Sensei_WC', 'activate_subscription' ), 50, 3 );
89
+add_action('woocommerce_subscription_status_pending_to_active', array('Sensei_WC', 'activate_subscription'), 50, 3);
90 90
 // filter the user permission of the subscription is not valid
91
-add_filter( 'sensei_access_permissions',               array( 'Sensei_WC', 'get_subscription_permission' ), 10, 2 );
91
+add_filter('sensei_access_permissions', array('Sensei_WC', 'get_subscription_permission'), 10, 2);
92 92
 
93 93
 //block user from accessing course when subscription
94
-add_filter( 'sensei_user_started_course',     array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 );
94
+add_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3);
Please login to merge, or discard this patch.