Completed
Pull Request — master (#1233)
by Dan
07:34
created
includes/class-sensei-settings-api.php 4 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -796,7 +796,7 @@
 block discarded – undo
796 796
 	 * Return an array of field types expecting an array value returned.
797 797
 	 * @access protected
798 798
 	 * @since  1.0.0
799
-	 * @return array
799
+	 * @return string[]
800 800
 	 */
801 801
 	protected function get_array_field_types () {
802 802
 		return array( 'multicheck' );
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function register_hook_listener() {
59 59
 
60
-        add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
60
+		add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
61 61
 		add_action( 'admin_init', array( $this, 'settings_fields' ) );
62 62
 		add_action( 'init', array( $this, 'general_init' ) );
63 63
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 	 * @return void
354 354
 	 */
355 355
 	public function settings_errors () {
356
-        settings_errors( $this->token . '-errors' );
356
+		settings_errors( $this->token . '-errors' );
357 357
 	} // End settings_errors()
358 358
 
359 359
 	/**
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 		echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n";
420 420
 		if ( $has_description ) {
421 421
 			echo wp_kses( $args['data']['description'], array( 'a' => array(
422
-																	        'href' => array(),
423
-																	        'title' => array()
424
-																	    )
422
+																			'href' => array(),
423
+																			'title' => array()
424
+																		)
425 425
 															)
426 426
 						) . '</label>' . "\n";
427 427
 		}
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 */
811 811
 	public function enqueue_scripts () {
812 812
 
813
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
813
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
814 814
 
815 815
 		wp_enqueue_script( 'farbtastic' );
816 816
 		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version );
Please login to merge, or discard this patch.
Spacing   +227 added lines, -227 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
  * A settings API (wrapping the WordPress Settings API).
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @access public
32 32
 	 * @since  1.0.0
33 33
 	 */
34
-	public function __construct () {
34
+	public function __construct() {
35 35
 
36 36
 		$this->token = 'woothemes-sensei-settings';
37 37
 		$this->page_slug = 'woothemes-sensei-settings-api';
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	public function register_hook_listener() {
59 59
 
60
-        add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
61
-		add_action( 'admin_init', array( $this, 'settings_fields' ) );
62
-		add_action( 'init', array( $this, 'general_init' ) );
60
+        add_action('admin_menu', array($this, 'register_settings_screen'), 60);
61
+		add_action('admin_init', array($this, 'settings_fields'));
62
+		add_action('init', array($this, 'general_init'));
63 63
 
64 64
 	} // End setup_settings()
65 65
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		$this->init_sections();
74 74
 		$this->init_fields();
75 75
 		$this->get_settings();
76
-		if ( $this->has_tabs == true ) {
76
+		if ($this->has_tabs == true) {
77 77
 			$this->create_tabs();
78 78
 		} // End If Statement
79 79
 	} // End general_init()
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
 	 * @since  1.0.0
85 85
 	 * @return void
86 86
 	 */
87
-	public function init_sections () {
87
+	public function init_sections() {
88 88
 		// Override this function in your class and assign the array of sections to $this->sections.
89
-		_e( 'Override init_sections() in your class.', 'woothemes-sensei' );
89
+		_e('Override init_sections() in your class.', 'woothemes-sensei');
90 90
 	} // End init_sections()
91 91
 
92 92
 	/**
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 	 * @since  1.0.0
96 96
 	 * @return void
97 97
 	 */
98
-	public function init_fields () {
98
+	public function init_fields() {
99 99
 		// Override this function in your class and assign the array of sections to $this->fields.
100
-		_e( 'Override init_fields() in your class.', 'woothemes-sensei' );
100
+		_e('Override init_fields() in your class.', 'woothemes-sensei');
101 101
 	} // End init_fields()
102 102
 
103 103
 	/**
@@ -106,34 +106,34 @@  discard block
 block discarded – undo
106 106
 	 * @since  1.1.0
107 107
 	 * @return void
108 108
 	 */
109
-	public function settings_tabs () {
109
+	public function settings_tabs() {
110 110
 
111
-		if ( ! $this->has_tabs ) { return; }
111
+		if ( ! $this->has_tabs) { return; }
112 112
 
113
-		if ( count( $this->tabs ) > 0 ) {
113
+		if (count($this->tabs) > 0) {
114 114
 			$html = '';
115 115
 
116
-			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n";
116
+			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n";
117 117
 
118 118
 			$sections = array(
119
-						'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' )
119
+						'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab')
120 120
 					);
121 121
 
122
-			foreach ( $this->tabs as $k => $v ) {
123
-				$sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' );
122
+			foreach ($this->tabs as $k => $v) {
123
+				$sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab');
124 124
 			}
125 125
 
126 126
 			$count = 1;
127
-			foreach ( $sections as $k => $v ) {
127
+			foreach ($sections as $k => $v) {
128 128
 				$count++;
129
-				$html .= '<li><a href="' . $v['href'] . '"';
130
-				if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; }
131
-				$html .= '>' . esc_attr( $v['name'] ) . '</a>';
132
-				if ( $count <= count( $sections ) ) { $html .= ' | '; }
133
-				$html .= '</li>' . "\n";
129
+				$html .= '<li><a href="'.$v['href'].'"';
130
+				if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; }
131
+				$html .= '>'.esc_attr($v['name']).'</a>';
132
+				if ($count <= count($sections)) { $html .= ' | '; }
133
+				$html .= '</li>'."\n";
134 134
 			}
135 135
 
136
-			$html .= '</ul><div class="clear"></div>' . "\n";
136
+			$html .= '</ul><div class="clear"></div>'."\n";
137 137
 
138 138
 			echo $html;
139 139
 		}
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 	 * @since  1.1.0
146 146
 	 * @return void
147 147
 	 */
148
-	private function create_tabs () {
149
-		if ( count( $this->sections ) > 0 ) {
148
+	private function create_tabs() {
149
+		if (count($this->sections) > 0) {
150 150
 			$tabs = array();
151
-			foreach ( $this->sections as $k => $v ) {
151
+			foreach ($this->sections as $k => $v) {
152 152
 				$tabs[$k] = $v;
153 153
 			}
154 154
 
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 	 * @since  1.0.0
163 163
 	 * @return void
164 164
 	 */
165
-	public function create_sections () {
166
-		if ( count( $this->sections ) > 0 ) {
167
-			foreach ( $this->sections as $k => $v ) {
168
-				add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token );
165
+	public function create_sections() {
166
+		if (count($this->sections) > 0) {
167
+			foreach ($this->sections as $k => $v) {
168
+				add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token);
169 169
 			}
170 170
 		}
171 171
 	} // End create_sections()
@@ -176,18 +176,18 @@  discard block
 block discarded – undo
176 176
 	 * @since  1.0.0
177 177
 	 * @return void
178 178
 	 */
179
-	public function create_fields () {
180
-		if ( count( $this->sections ) > 0 ) {
179
+	public function create_fields() {
180
+		if (count($this->sections) > 0) {
181 181
 			// $this->parse_fields( $this->fields );
182 182
 
183
-			foreach ( $this->fields as $k => $v ) {
184
-				$method = $this->determine_method( $v, 'form' );
183
+			foreach ($this->fields as $k => $v) {
184
+				$method = $this->determine_method($v, 'form');
185 185
 				$name = $v['name'];
186
-				if ( $v['type'] == 'info' ) { $name = ''; }
187
-				add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) );
186
+				if ($v['type'] == 'info') { $name = ''; }
187
+				add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v));
188 188
 
189 189
 				// Let the API know that we have a colourpicker field.
190
-				if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; }
190
+				if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; }
191 191
 			}
192 192
 		}
193 193
 	} // End create_fields()
@@ -199,43 +199,43 @@  discard block
 block discarded – undo
199 199
 	 * @param  array $data
200 200
 	 * @return callable,  array or string
201 201
 	 */
202
-	protected function determine_method ( $data, $type = 'form' ) {
202
+	protected function determine_method($data, $type = 'form') {
203 203
 		$method = '';
204 204
 
205
-		if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; }
205
+		if ( ! in_array($type, array('form', 'validate', 'check'))) { return; }
206 206
 
207 207
 		// Check for custom functions.
208
-		if ( isset( $data[$type] ) ) {
209
-			if ( function_exists( $data[$type] ) ) {
208
+		if (isset($data[$type])) {
209
+			if (function_exists($data[$type])) {
210 210
 				$method = $data[$type];
211 211
 			}
212 212
 
213
-			if ( $method == '' && method_exists( $this, $data[$type] ) ) {
214
-				if ( $type == 'form' ) {
215
-					$method = array( $this, $data[$type] );
213
+			if ($method == '' && method_exists($this, $data[$type])) {
214
+				if ($type == 'form') {
215
+					$method = array($this, $data[$type]);
216 216
 				} else {
217 217
 					$method = $data[$type];
218 218
 				}
219 219
 			}
220 220
 		}
221 221
 
222
-		if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) {
223
-			if ( $type == 'form' ) {
224
-				$method = array( $this, $type . '_field_' . $data['type'] );
222
+		if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) {
223
+			if ($type == 'form') {
224
+				$method = array($this, $type.'_field_'.$data['type']);
225 225
 			} else {
226
-				$method = $type . '_field_' . $data['type'];
226
+				$method = $type.'_field_'.$data['type'];
227 227
 			}
228 228
 		}
229 229
 
230
-		if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) {
231
-			$method = $this->token . '_' . $type . '_field_' . $data['type'];
230
+		if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) {
231
+			$method = $this->token.'_'.$type.'_field_'.$data['type'];
232 232
 		}
233 233
 
234
-		if ( $method == '' ) {
235
-			if ( $type == 'form' ) {
236
-				$method = array( $this, $type . '_field_text' );
234
+		if ($method == '') {
235
+			if ($type == 'form') {
236
+				$method = array($this, $type.'_field_text');
237 237
 			} else {
238
-				$method = $type . '_field_text';
238
+				$method = $type.'_field_text';
239 239
 			}
240 240
 		}
241 241
 
@@ -249,10 +249,10 @@  discard block
 block discarded – undo
249 249
 	 * @param  array $fields
250 250
 	 * @return void
251 251
 	 */
252
-	public function parse_fields ( $fields ) {
253
-		foreach ( $fields as $k => $v ) {
254
-			if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) {
255
-				if ( ! isset( $this->sections[$v['section']]['fields'] ) ) {
252
+	public function parse_fields($fields) {
253
+		foreach ($fields as $k => $v) {
254
+			if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) {
255
+				if ( ! isset($this->sections[$v['section']]['fields'])) {
256 256
 					$this->sections[$v['section']]['fields'] = array();
257 257
 				}
258 258
 
@@ -269,19 +269,19 @@  discard block
 block discarded – undo
269 269
 	 * @since 1.0.0
270 270
 	 * @return void
271 271
 	 */
272
-	public function register_settings_screen () {
272
+	public function register_settings_screen() {
273 273
 
274
-		if ( current_user_can( 'manage_sensei' ) ) {
275
-			$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
274
+		if (current_user_can('manage_sensei')) {
275
+			$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
276 276
 
277 277
 			$this->hook = $hook;
278 278
 		}
279 279
 
280
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
280
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
281 281
 
282
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
283
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
284
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
282
+			add_action('admin_notices', array($this, 'settings_errors'));
283
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
284
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
285 285
 
286 286
 		}
287 287
 	} // End register_settings_screen()
@@ -292,21 +292,21 @@  discard block
 block discarded – undo
292 292
 	 * @since  1.0.0
293 293
 	 * @return void
294 294
 	 */
295
-	public function settings_screen () {
295
+	public function settings_screen() {
296 296
 
297 297
 ?>
298
-<div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>">
299
-	<?php screen_icon( 'woothemes-sensei' ); ?>
300
-	<h2><?php echo esc_html( $this->name ); ?><?php if ( '' != $this->settings_version ) { echo ' <span class="version">' . $this->settings_version . '</span>'; } ?></h2>
301
-	<p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
302
-	<?php do_action( 'settings_before_form' ); ?>
298
+<div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>">
299
+	<?php screen_icon('woothemes-sensei'); ?>
300
+	<h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { echo ' <span class="version">'.$this->settings_version.'</span>'; } ?></h2>
301
+	<p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
302
+	<?php do_action('settings_before_form'); ?>
303 303
 	<form action="options.php" method="post">
304 304
 		<?php $this->settings_tabs(); ?>
305
-		<?php settings_fields( $this->token ); ?>
306
-		<?php do_settings_sections( $this->token ); ?>
305
+		<?php settings_fields($this->token); ?>
306
+		<?php do_settings_sections($this->token); ?>
307 307
 		<?php submit_button(); ?>
308 308
 	</form>
309
-	<?php do_action( 'settings_after_form' ); ?>
309
+	<?php do_action('settings_after_form'); ?>
310 310
 </div><!--/#woothemes-sensei-->
311 311
 <?php
312 312
 	} // End settings_screen()
@@ -317,16 +317,16 @@  discard block
 block discarded – undo
317 317
 	 * @since  1.0.0
318 318
 	 * @return array
319 319
 	 */
320
-	public function get_settings () {
321
-		if ( ! is_array( $this->settings ) ) {
322
-			$this->settings = get_option( $this->token, array() );
320
+	public function get_settings() {
321
+		if ( ! is_array($this->settings)) {
322
+			$this->settings = get_option($this->token, array());
323 323
 		}
324 324
 
325
-		foreach ( $this->fields as $k => $v ) {
326
-			if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) {
325
+		foreach ($this->fields as $k => $v) {
326
+			if ( ! isset($this->settings[$k]) && isset($v['default'])) {
327 327
 				$this->settings[$k] = $v['default'];
328 328
 			}
329
-			if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) {
329
+			if ($v['type'] == 'checkbox' && $this->settings[$k] != true) {
330 330
 				$this->settings[$k] = 0;
331 331
 			}
332 332
 		}
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 * @since  1.0.0
341 341
 	 * @return void
342 342
 	 */
343
-	public function settings_fields () {
344
-		register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) );
343
+	public function settings_fields() {
344
+		register_setting($this->token, $this->token, array($this, 'validate_fields'));
345 345
 		$this->create_sections();
346 346
 		$this->create_fields();
347 347
 	} // End settings_fields()
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	 * @since  1.0.0
353 353
 	 * @return void
354 354
 	 */
355
-	public function settings_errors () {
356
-        settings_errors( $this->token . '-errors' );
355
+	public function settings_errors() {
356
+        settings_errors($this->token.'-errors');
357 357
 	} // End settings_errors()
358 358
 
359 359
 	/**
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	 * @since  1.0.0
363 363
 	 * @return void
364 364
 	 */
365
-	public function section_description ( $section ) {
366
-		if ( isset( $this->sections[$section['id']]['description'] ) ) {
367
-			echo wpautop( $this->sections[$section['id']]['description'] );
365
+	public function section_description($section) {
366
+		if (isset($this->sections[$section['id']]['description'])) {
367
+			echo wpautop($this->sections[$section['id']]['description']);
368 368
 		}
369 369
 	} // End section_description_main()
370 370
 
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
 	 * @param  array $args
376 376
 	 * @return void
377 377
 	 */
378
-	public function form_field_text ( $args ) {
378
+	public function form_field_text($args) {
379 379
 		$options = $this->get_settings();
380 380
 
381
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
382
-		if ( isset( $args['data']['description'] ) ) {
383
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
381
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n";
382
+		if (isset($args['data']['description'])) {
383
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
384 384
 		}
385 385
 	} // End form_field_text()
386 386
 
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
 	 * @param  array $args
392 392
 	 * @return void
393 393
 	 */
394
-	public function form_field_color ( $args ) {
394
+	public function form_field_color($args) {
395 395
 		$options = $this->get_settings();
396 396
 
397
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
397
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n";
398 398
 		echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>';
399
-		if ( isset( $args['data']['description'] ) ) {
400
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
399
+		if (isset($args['data']['description'])) {
400
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
401 401
 		}
402 402
 	} // End form_field_text()
403 403
 
@@ -408,22 +408,22 @@  discard block
 block discarded – undo
408 408
 	 * @param  array $args
409 409
 	 * @return void
410 410
 	 */
411
-	public function form_field_checkbox ( $args ) {
411
+	public function form_field_checkbox($args) {
412 412
 		$options = $this->get_settings();
413 413
 
414 414
 		$has_description = false;
415
-		if ( isset( $args['data']['description'] ) ) {
415
+		if (isset($args['data']['description'])) {
416 416
 			$has_description = true;
417
-			echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n";
417
+			echo '<label for="'.esc_attr($args['key']).'">'."\n";
418 418
 		}
419
-		echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n";
420
-		if ( $has_description ) {
421
-			echo wp_kses( $args['data']['description'], array( 'a' => array(
419
+		echo '<input id="'.$args['key'].'" name="'.$this->token.'['.esc_attr($args['key']).']" type="checkbox" value="1"'.checked(esc_attr($options[$args['key']]), '1', false).' />'."\n";
420
+		if ($has_description) {
421
+			echo wp_kses($args['data']['description'], array('a' => array(
422 422
 																	        'href' => array(),
423 423
 																	        'title' => array()
424 424
 																	    )
425 425
 															)
426
-						) . '</label>' . "\n";
426
+						).'</label>'."\n";
427 427
 		}
428 428
 	} // End form_field_checkbox()
429 429
 
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 	 * @param  array $args
435 435
 	 * @return void
436 436
 	 */
437
-	public function form_field_textarea ( $args ) {
437
+	public function form_field_textarea($args) {
438 438
 		$options = $this->get_settings();
439 439
 
440
-		echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n";
441
-		if ( isset( $args['data']['description'] ) ) {
442
-			echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
440
+		echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n";
441
+		if (isset($args['data']['description'])) {
442
+			echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
443 443
 		}
444 444
 	} // End form_field_textarea()
445 445
 
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
 	 * @param  array $args
451 451
 	 * @return void
452 452
 	 */
453
-	public function form_field_select ( $args ) {
453
+	public function form_field_select($args) {
454 454
 		$options = $this->get_settings();
455 455
 
456
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
456
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
457 457
 			$html = '';
458
-			$html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n";
459
-				foreach ( $args['data']['options'] as $k => $v ) {
460
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
458
+			$html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n";
459
+				foreach ($args['data']['options'] as $k => $v) {
460
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
461 461
 				}
462
-			$html .= '</select>' . "\n";
462
+			$html .= '</select>'."\n";
463 463
 			echo $html;
464 464
 
465
-			if ( isset( $args['data']['description'] ) ) {
466
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
465
+			if (isset($args['data']['description'])) {
466
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
467 467
 			}
468 468
 		}
469 469
 	} // End form_field_select()
@@ -475,18 +475,18 @@  discard block
 block discarded – undo
475 475
 	 * @param  array $args
476 476
 	 * @return void
477 477
 	 */
478
-	public function form_field_radio ( $args ) {
478
+	public function form_field_radio($args) {
479 479
 		$options = $this->get_settings();
480 480
 
481
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
481
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
482 482
 			$html = '';
483
-			foreach ( $args['data']['options'] as $k => $v ) {
484
-				$html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
483
+			foreach ($args['data']['options'] as $k => $v) {
484
+				$html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
485 485
 			}
486 486
 			echo $html;
487 487
 
488
-			if ( isset( $args['data']['description'] ) ) {
489
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
488
+			if (isset($args['data']['description'])) {
489
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
490 490
 			}
491 491
 		}
492 492
 	} // End form_field_radio()
@@ -498,28 +498,28 @@  discard block
 block discarded – undo
498 498
 	 * @param  array $args
499 499
 	 * @return void
500 500
 	 */
501
-	public function form_field_multicheck ( $args ) {
501
+	public function form_field_multicheck($args) {
502 502
 		$options = $this->get_settings();
503 503
 
504
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
505
-			$html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n";
506
-			foreach ( $args['data']['options'] as $k => $v ) {
504
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
505
+			$html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n";
506
+			foreach ($args['data']['options'] as $k => $v) {
507 507
 				$checked = '';
508 508
 
509
-				if( isset( $options[ $args['key'] ] ) ) {
510
-					if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; }
509
+				if (isset($options[$args['key']])) {
510
+					if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; }
511 511
 				} else {
512
-					if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; }
512
+					if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; }
513 513
 				}
514
-				$html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n";
515
-				$html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n";
516
-				$html .= '</label><br />' . "\n";
514
+				$html .= '<label for="checkbox-'.esc_attr($k).'">'."\n";
515
+				$html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n";
516
+				$html .= '</label><br />'."\n";
517 517
 			}
518
-			$html .= '</div>' . "\n";
518
+			$html .= '</div>'."\n";
519 519
 			echo $html;
520 520
 
521
-			if ( isset( $args['data']['description'] ) ) {
522
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
521
+			if (isset($args['data']['description'])) {
522
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
523 523
 			}
524 524
 		}
525 525
 	} // End form_field_multicheck()
@@ -531,20 +531,20 @@  discard block
 block discarded – undo
531 531
 	 * @param  array $args
532 532
 	 * @return void
533 533
 	 */
534
-	public function form_field_range ( $args ) {
534
+	public function form_field_range($args) {
535 535
 		$options = $this->get_settings();
536 536
 
537
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
537
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
538 538
 			$html = '';
539
-			$html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n";
540
-				foreach ( $args['data']['options'] as $k => $v ) {
541
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
539
+			$html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n";
540
+				foreach ($args['data']['options'] as $k => $v) {
541
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
542 542
 				}
543
-			$html .= '</select>' . "\n";
543
+			$html .= '</select>'."\n";
544 544
 			echo $html;
545 545
 
546
-			if ( isset( $args['data']['description'] ) ) {
547
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
546
+			if (isset($args['data']['description'])) {
547
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
548 548
 			}
549 549
 		}
550 550
 	} // End form_field_range()
@@ -556,18 +556,18 @@  discard block
 block discarded – undo
556 556
 	 * @param  array $args
557 557
 	 * @return void
558 558
 	 */
559
-	public function form_field_images ( $args ) {
559
+	public function form_field_images($args) {
560 560
 		$options = $this->get_settings();
561 561
 
562
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
562
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
563 563
 			$html = '';
564
-			foreach ( $args['data']['options'] as $k => $v ) {
565
-				$html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
564
+			foreach ($args['data']['options'] as $k => $v) {
565
+				$html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
566 566
 			}
567 567
 			echo $html;
568 568
 
569
-			if ( isset( $args['data']['description'] ) ) {
570
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
569
+			if (isset($args['data']['description'])) {
570
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
571 571
 			}
572 572
 		}
573 573
 	} // End form_field_images()
@@ -579,19 +579,19 @@  discard block
 block discarded – undo
579 579
 	 * @param  array $args
580 580
 	 * @return void
581 581
 	 */
582
-	public function form_field_info ( $args ) {
582
+	public function form_field_info($args) {
583 583
 		$class = '';
584
-		if ( isset( $args['data']['class'] ) ) {
585
-			$class = ' ' . esc_attr( $args['data']['class'] );
584
+		if (isset($args['data']['class'])) {
585
+			$class = ' '.esc_attr($args['data']['class']);
586 586
 		}
587
-		$html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n";
588
-		if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) {
589
-			$html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n";
587
+		$html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n";
588
+		if (isset($args['data']['name']) && ($args['data']['name'] != '')) {
589
+			$html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n";
590 590
 		}
591
-		if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) {
592
-			$html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n";
591
+		if (isset($args['data']['description']) && ($args['data']['description'] != '')) {
592
+			$html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n";
593 593
 		}
594
-		$html .= '</div>' . "\n";
594
+		$html .= '</div>'."\n";
595 595
 
596 596
 		echo $html;
597 597
 	} // End form_field_info()
@@ -603,14 +603,14 @@  discard block
 block discarded – undo
603 603
 	 * @since  1.9.0
604 604
 	 * @param  array $args
605 605
 	 */
606
-	public function form_field_button( $args ) {
606
+	public function form_field_button($args) {
607 607
 		$options = $this->get_settings();
608 608
 
609
-		if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) {
610
-			printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) );
609
+		if (isset($args['data']['target']) && isset($args['data']['label'])) {
610
+			printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label']));
611 611
 
612
-			if ( isset( $args['data']['description'] ) ) {
613
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
612
+			if (isset($args['data']['description'])) {
613
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
614 614
 			}
615 615
 		}
616 616
 	} // End form_field_button()
@@ -624,23 +624,23 @@  discard block
 block discarded – undo
624 624
 	 * @uses   $this->parse_errors()
625 625
 	 * @return array $options
626 626
 	 */
627
-	public function validate_fields ( $input ) {
627
+	public function validate_fields($input) {
628 628
 		$options = $this->get_settings();
629 629
 
630
-		foreach ( $this->fields as $k => $v ) {
630
+		foreach ($this->fields as $k => $v) {
631 631
 			// Make sure checkboxes are present even when false.
632
-			if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; }
633
-			if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; }
632
+			if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; }
633
+			if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; }
634 634
 
635
-			if ( isset( $input[$k] ) ) {
635
+			if (isset($input[$k])) {
636 636
 				// Perform checks on required fields.
637
-				if ( isset( $v['required'] ) && ( $v['required'] == true ) ) {
638
-					if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) {
639
-						$this->add_error( $k, $v );
637
+				if (isset($v['required']) && ($v['required'] == true)) {
638
+					if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) {
639
+						$this->add_error($k, $v);
640 640
 						continue;
641 641
 					} else {
642
-						if ( $input[$k] == '' ) {
643
-							$this->add_error( $k, $v );
642
+						if ($input[$k] == '') {
643
+							$this->add_error($k, $v);
644 644
 							continue;
645 645
 						}
646 646
 					}
@@ -649,28 +649,28 @@  discard block
 block discarded – undo
649 649
 				$value = $input[$k];
650 650
 
651 651
 				// Check if the field is valid.
652
-				$method = $this->determine_method( $v, 'check' );
652
+				$method = $this->determine_method($v, 'check');
653 653
 
654
-				if ( function_exists ( $method ) ) {
655
-					$is_valid = $method( $value );
654
+				if (function_exists($method)) {
655
+					$is_valid = $method($value);
656 656
 				} else {
657
-					if ( method_exists( $this, $method ) ) {
658
-						$is_valid = $this->$method( $value );
657
+					if (method_exists($this, $method)) {
658
+						$is_valid = $this->$method($value);
659 659
 					}
660 660
 				}
661 661
 
662
-				if ( ! $is_valid ) {
663
-					$this->add_error( $k, $v );
662
+				if ( ! $is_valid) {
663
+					$this->add_error($k, $v);
664 664
 					continue;
665 665
 				}
666 666
 
667
-				$method = $this->determine_method( $v, 'validate' );
667
+				$method = $this->determine_method($v, 'validate');
668 668
 
669
-				if ( function_exists ( $method ) ) {
670
-					$options[$k] = $method( $value );
669
+				if (function_exists($method)) {
670
+					$options[$k] = $method($value);
671 671
 				} else {
672
-					if ( method_exists( $this, $method ) ) {
673
-						$options[$k] = $this->$method( $value );
672
+					if (method_exists($this, $method)) {
673
+						$options[$k] = $this->$method($value);
674 674
 					}
675 675
 				}
676 676
 			}
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 	 * @param  string $input
689 689
 	 * @return string
690 690
 	 */
691
-	public function validate_field_text ( $input ) {
692
-		return trim( esc_attr( $input ) );
691
+	public function validate_field_text($input) {
692
+		return trim(esc_attr($input));
693 693
 	} // End validate_field_text()
694 694
 
695 695
 	/**
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
699 699
 	 * @param  string $input
700 700
 	 * @return string
701 701
 	 */
702
-	public function validate_field_checkbox ( $input ) {
703
-		if ( ! isset( $input ) ) {
702
+	public function validate_field_checkbox($input) {
703
+		if ( ! isset($input)) {
704 704
 			return 0;
705 705
 		} else {
706
-			return (bool)$input;
706
+			return (bool) $input;
707 707
 		}
708 708
 	} // End validate_field_checkbox()
709 709
 
@@ -714,10 +714,10 @@  discard block
 block discarded – undo
714 714
 	 * @param  string $input
715 715
 	 * @return string
716 716
 	 */
717
-	public function validate_field_multicheck ( $input ) {
717
+	public function validate_field_multicheck($input) {
718 718
 		$input = (array) $input;
719 719
 
720
-		$input = array_map( 'esc_attr', $input );
720
+		$input = array_map('esc_attr', $input);
721 721
 
722 722
 		return $input;
723 723
 	} // End validate_field_multicheck()
@@ -729,8 +729,8 @@  discard block
 block discarded – undo
729 729
 	 * @param  string $input
730 730
 	 * @return string
731 731
 	 */
732
-	public function validate_field_range ( $input ) {
733
-		$input = number_format( floatval( $input ), 0 );
732
+	public function validate_field_range($input) {
733
+		$input = number_format(floatval($input), 0);
734 734
 
735 735
 		return $input;
736 736
 	} // End validate_field_range()
@@ -742,8 +742,8 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $input
743 743
 	 * @return string
744 744
 	 */
745
-	public function validate_field_url ( $input ) {
746
-		return trim( esc_url( $input ) );
745
+	public function validate_field_url($input) {
746
+		return trim(esc_url($input));
747 747
 	} // End validate_field_url()
748 748
 
749 749
 	/**
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	 * @since  1.1.0
753 753
 	 * @return boolean Is the value valid?
754 754
 	 */
755
-	public function check_field_text ( $input ) {
755
+	public function check_field_text($input) {
756 756
 		$is_valid = true;
757 757
 
758 758
 		return $is_valid;
@@ -766,11 +766,11 @@  discard block
 block discarded – undo
766 766
 	 * @param  array $data
767 767
 	 * @return void
768 768
 	 */
769
-	protected function add_error ( $key, $data ) {
770
-		if ( isset( $data['error_message'] ) ) {
769
+	protected function add_error($key, $data) {
770
+		if (isset($data['error_message'])) {
771 771
 			$message = $data['error_message'];
772 772
 		} else {
773
-			$message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] );
773
+			$message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']);
774 774
 		}
775 775
 		$this->errors[$key] = $message;
776 776
 	} // End add_error()
@@ -781,14 +781,14 @@  discard block
 block discarded – undo
781 781
 	 * @since   1.0.0
782 782
 	 * @return  void
783 783
 	 */
784
-	protected function parse_errors () {
785
-		if ( count ( $this->errors ) > 0 ) {
786
-			foreach ( $this->errors as $k => $v ) {
787
-				add_settings_error( $this->token . '-errors', $k, $v, 'error' );
784
+	protected function parse_errors() {
785
+		if (count($this->errors) > 0) {
786
+			foreach ($this->errors as $k => $v) {
787
+				add_settings_error($this->token.'-errors', $k, $v, 'error');
788 788
 			}
789 789
 		} else {
790
-			$message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name );
791
-			add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' );
790
+			$message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name);
791
+			add_settings_error($this->token.'-errors', $this->token, $message, 'updated');
792 792
 		}
793 793
 	} // End parse_errors()
794 794
 
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
 	 * @since  1.0.0
799 799
 	 * @return array
800 800
 	 */
801
-	protected function get_array_field_types () {
802
-		return array( 'multicheck' );
801
+	protected function get_array_field_types() {
802
+		return array('multicheck');
803 803
 	} // End get_array_field_types()
804 804
 
805 805
 	/**
@@ -808,21 +808,21 @@  discard block
 block discarded – undo
808 808
 	 * @since  1.0.0
809 809
 	 * @return void
810 810
 	 */
811
-	public function enqueue_scripts () {
811
+	public function enqueue_scripts() {
812 812
 
813
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
813
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
814 814
 
815
-		wp_enqueue_script( 'farbtastic' );
816
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version );
815
+		wp_enqueue_script('farbtastic');
816
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version);
817 817
 
818
-		if ( $this->has_range ) {
819
-			wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version );
818
+		if ($this->has_range) {
819
+			wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version);
820 820
 		}
821 821
 
822
-		wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version );
822
+		wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version);
823 823
 
824
-		if ( $this->has_imageselector ) {
825
-			wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' );
824
+		if ($this->has_imageselector) {
825
+			wp_enqueue_script('woothemes-sensei-settings-imageselectors');
826 826
 		}
827 827
 
828 828
 	} // End enqueue_scripts()
@@ -833,12 +833,12 @@  discard block
 block discarded – undo
833 833
 	 * @since  1.0.0
834 834
 	 * @return void
835 835
 	 */
836
-	public function enqueue_styles () {
836
+	public function enqueue_styles() {
837 837
 
838
-		wp_enqueue_style( $this->token . '-admin' );
838
+		wp_enqueue_style($this->token.'-admin');
839 839
 
840
-		wp_enqueue_style( 'farbtastic' );
841
-		wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version );
840
+		wp_enqueue_style('farbtastic');
841
+		wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version);
842 842
 
843 843
 		$this->enqueue_field_styles();
844 844
 	} // End enqueue_styles()
@@ -849,16 +849,16 @@  discard block
 block discarded – undo
849 849
 	 * @since  1.0.0
850 850
 	 * @return void
851 851
 	 */
852
-	public function enqueue_field_styles () {
852
+	public function enqueue_field_styles() {
853 853
 
854
-		if ( $this->has_range ) {
855
-			wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version );
854
+		if ($this->has_range) {
855
+			wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version);
856 856
 		}
857 857
 
858
-		wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version );
858
+		wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version);
859 859
 
860
-		if ( $this->has_imageselector ) {
861
-			wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' );
860
+		if ($this->has_imageselector) {
861
+			wp_enqueue_style('woothemes-sensei-settings-imageselectors');
862 862
 		}
863 863
 	} // End enqueue_field_styles()
864 864
 } // End Class
@@ -868,4 +868,4 @@  discard block
 block discarded – undo
868 868
  * @ignore only for backward compatibility
869 869
  * @since 1.9.0
870 870
  */
871
-class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{}
871
+class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {}
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-user-messages.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -15,91 +15,91 @@
 block discarded – undo
15 15
  */
16 16
 class Sensei_Shortcode_User_Messages implements Sensei_Shortcode_Interface {
17 17
 
18
-    /**
19
-     * @var WP_Query
20
-     * messages for the current user
21
-     */
22
-    protected $messages_query;
23
-
24
-    /**
25
-     * Setup the shortcode object
26
-     *
27
-     * @since 1.9.0
28
-     * @param array $attributes
29
-     * @param string $content
30
-     * @param string $shortcode the shortcode that was called for this instance
31
-     */
32
-    public function __construct( $attributes, $content, $shortcode ){
33
-
34
-        $this->setup_messages_query();
35
-
36
-    }
37
-
38
-    /**
39
-     * create the messages query .
40
-     *
41
-     * @return mixed
42
-     */
43
-    public function setup_messages_query(){
44
-
45
-        $user = wp_get_current_user();
46
-
47
-        $args = array(
48
-            'post_type' => 'sensei_message',
49
-            'posts_per_page' => 500,
50
-            'orderby' => 'date',
51
-            'order' => 'DESC',
52
-            'post_status' => 'publish',
53
-            'meta_query' => array(
54
-                array(
55
-                    'key'     => '_sender',
56
-                    'value'   => $user->user_login,
57
-                    'compare' => '=',
58
-                ),
59
-            ),
60
-        );
61
-
62
-        $this->messages_query  = new WP_Query( $args );
63
-    }
64
-
65
-    /**
66
-     * Rendering the shortcode this class is responsible for.
67
-     *
68
-     * @return string $content
69
-     */
70
-    public function render(){
71
-
72
-        if( !is_user_logged_in() ){
73
-
74
-            Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert'  );
75
-
76
-        } elseif( 0 == $this->messages_query->post_count ){
77
-
78
-            Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert'  );
79
-        }
80
-
81
-        $messages_disabled_in_settings =  ! ( ! isset( Sensei()->settings->settings['messages_disable'] )
82
-                                            || ! Sensei()->settings->settings['messages_disable'] ) ;
83
-
84
-        // don't show anything if messages are disable
85
-        if( $messages_disabled_in_settings ){
86
-            return '';
87
-        }
88
-
89
-        //set the wp_query to the current messages query
90
-        global $wp_query;
91
-        $wp_query = $this->messages_query;
92
-
93
-        ob_start();
94
-        Sensei()->notices->print_notices();
95
-        Sensei_Templates::get_part('loop', 'message');
96
-        $messages_html = ob_get_clean();
97
-
98
-        // set back the global query
99
-        wp_reset_query();
100
-
101
-        return $messages_html;
102
-
103
-    }// end render
18
+	/**
19
+	 * @var WP_Query
20
+	 * messages for the current user
21
+	 */
22
+	protected $messages_query;
23
+
24
+	/**
25
+	 * Setup the shortcode object
26
+	 *
27
+	 * @since 1.9.0
28
+	 * @param array $attributes
29
+	 * @param string $content
30
+	 * @param string $shortcode the shortcode that was called for this instance
31
+	 */
32
+	public function __construct( $attributes, $content, $shortcode ){
33
+
34
+		$this->setup_messages_query();
35
+
36
+	}
37
+
38
+	/**
39
+	 * create the messages query .
40
+	 *
41
+	 * @return mixed
42
+	 */
43
+	public function setup_messages_query(){
44
+
45
+		$user = wp_get_current_user();
46
+
47
+		$args = array(
48
+			'post_type' => 'sensei_message',
49
+			'posts_per_page' => 500,
50
+			'orderby' => 'date',
51
+			'order' => 'DESC',
52
+			'post_status' => 'publish',
53
+			'meta_query' => array(
54
+				array(
55
+					'key'     => '_sender',
56
+					'value'   => $user->user_login,
57
+					'compare' => '=',
58
+				),
59
+			),
60
+		);
61
+
62
+		$this->messages_query  = new WP_Query( $args );
63
+	}
64
+
65
+	/**
66
+	 * Rendering the shortcode this class is responsible for.
67
+	 *
68
+	 * @return string $content
69
+	 */
70
+	public function render(){
71
+
72
+		if( !is_user_logged_in() ){
73
+
74
+			Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert'  );
75
+
76
+		} elseif( 0 == $this->messages_query->post_count ){
77
+
78
+			Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert'  );
79
+		}
80
+
81
+		$messages_disabled_in_settings =  ! ( ! isset( Sensei()->settings->settings['messages_disable'] )
82
+											|| ! Sensei()->settings->settings['messages_disable'] ) ;
83
+
84
+		// don't show anything if messages are disable
85
+		if( $messages_disabled_in_settings ){
86
+			return '';
87
+		}
88
+
89
+		//set the wp_query to the current messages query
90
+		global $wp_query;
91
+		$wp_query = $this->messages_query;
92
+
93
+		ob_start();
94
+		Sensei()->notices->print_notices();
95
+		Sensei_Templates::get_part('loop', 'message');
96
+		$messages_html = ob_get_clean();
97
+
98
+		// set back the global query
99
+		wp_reset_query();
100
+
101
+		return $messages_html;
102
+
103
+	}// end render
104 104
 
105 105
 }// end class
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_user_messages] shortcode. The current users messages.
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      * @param string $content
30 30
      * @param string $shortcode the shortcode that was called for this instance
31 31
      */
32
-    public function __construct( $attributes, $content, $shortcode ){
32
+    public function __construct($attributes, $content, $shortcode) {
33 33
 
34 34
         $this->setup_messages_query();
35 35
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return mixed
42 42
      */
43
-    public function setup_messages_query(){
43
+    public function setup_messages_query() {
44 44
 
45 45
         $user = wp_get_current_user();
46 46
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             ),
60 60
         );
61 61
 
62
-        $this->messages_query  = new WP_Query( $args );
62
+        $this->messages_query = new WP_Query($args);
63 63
     }
64 64
 
65 65
     /**
@@ -67,22 +67,22 @@  discard block
 block discarded – undo
67 67
      *
68 68
      * @return string $content
69 69
      */
70
-    public function render(){
70
+    public function render() {
71 71
 
72
-        if( !is_user_logged_in() ){
72
+        if ( ! is_user_logged_in()) {
73 73
 
74
-            Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert'  );
74
+            Sensei()->notices->add_notice(__('Please login to view your messages.', 'woothemes-sensei'), 'alert');
75 75
 
76
-        } elseif( 0 == $this->messages_query->post_count ){
76
+        } elseif (0 == $this->messages_query->post_count) {
77 77
 
78
-            Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert'  );
78
+            Sensei()->notices->add_notice(__('You do not have any messages.', 'woothemes-sensei'), 'alert');
79 79
         }
80 80
 
81
-        $messages_disabled_in_settings =  ! ( ! isset( Sensei()->settings->settings['messages_disable'] )
82
-                                            || ! Sensei()->settings->settings['messages_disable'] ) ;
81
+        $messages_disabled_in_settings = ! ( ! isset(Sensei()->settings->settings['messages_disable'])
82
+                                            || ! Sensei()->settings->settings['messages_disable']);
83 83
 
84 84
         // don't show anything if messages are disable
85
-        if( $messages_disabled_in_settings ){
85
+        if ($messages_disabled_in_settings) {
86 86
             return '';
87 87
         }
88 88
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-unpurchased-courses.php 3 patches
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Post Types Class
@@ -146,7 +149,7 @@  discard block
 block discarded – undo
146 149
 
147 150
              return get_page_uri( $settings_course_page->ID );
148 151
 
149
-        }else{
152
+        } else{
150 153
 
151 154
             return 'courses';
152 155
 
Please login to merge, or discard this patch.
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -14,148 +14,148 @@
 block discarded – undo
14 14
  */
15 15
 class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface {
16 16
 
17
-    /**
18
-     * @var WP_Query to help setup the query needed by the render method.
19
-     */
20
-    protected $query;
21
-
22
-    /**
23
-     * @var string number of items to show on the current page
24
-     * Default: all.
25
-     */
26
-    protected $number;
27
-
28
-    /**
29
-     * @var string ordery by course field
30
-     * Default: date
31
-     */
32
-    protected $orderby;
33
-
34
-    /**
35
-     * @var string ASC or DESC
36
-     * Default: 'DESC'
37
-     */
38
-    protected  $order;
39
-
40
-    /**
41
-     * Setup the shortcode object
42
-     *
43
-     * @since 1.9.0
44
-     * @param array $attributes
45
-     * @param string $content
46
-     * @param string $shortcode the shortcode that was called for this instance
47
-     */
48
-    public function __construct( $attributes, $content, $shortcode ){
49
-
50
-        // set up all argument need for constructing the course query
51
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
52
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
53
-
54
-        // set the default for menu_order to be ASC
55
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
56
-
57
-            $this->order =  'ASC';
17
+	/**
18
+	 * @var WP_Query to help setup the query needed by the render method.
19
+	 */
20
+	protected $query;
21
+
22
+	/**
23
+	 * @var string number of items to show on the current page
24
+	 * Default: all.
25
+	 */
26
+	protected $number;
27
+
28
+	/**
29
+	 * @var string ordery by course field
30
+	 * Default: date
31
+	 */
32
+	protected $orderby;
33
+
34
+	/**
35
+	 * @var string ASC or DESC
36
+	 * Default: 'DESC'
37
+	 */
38
+	protected  $order;
39
+
40
+	/**
41
+	 * Setup the shortcode object
42
+	 *
43
+	 * @since 1.9.0
44
+	 * @param array $attributes
45
+	 * @param string $content
46
+	 * @param string $shortcode the shortcode that was called for this instance
47
+	 */
48
+	public function __construct( $attributes, $content, $shortcode ){
49
+
50
+		// set up all argument need for constructing the course query
51
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
52
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
53
+
54
+		// set the default for menu_order to be ASC
55
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
56
+
57
+			$this->order =  'ASC';
58 58
 
59
-        }else{
59
+		}else{
60 60
 
61
-            // for everything else use the value passed or the default DESC
62
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
61
+			// for everything else use the value passed or the default DESC
62
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
63 63
 
64
-        }
64
+		}
65 65
 
66
-        // setup the course query that will be used when rendering
67
-        $this->setup_course_query();
68
-    }
66
+		// setup the course query that will be used when rendering
67
+		$this->setup_course_query();
68
+	}
69 69
 
70
-    /**
71
-     * Sets up the object course query
72
-     * that will be used int he render method.
73
-     *
74
-     * @since 1.9.0
75
-     */
76
-    protected function setup_course_query(){
70
+	/**
71
+	 * Sets up the object course query
72
+	 * that will be used int he render method.
73
+	 *
74
+	 * @since 1.9.0
75
+	 */
76
+	protected function setup_course_query(){
77 77
 
78 78
 
79
-        // course query parameters to be used for all courses
80
-        $query_args = array(
81
-            'post_type'        => 'course',
82
-            'post_status'      => 'publish',
83
-            // the number specified by the user will be used later in this function
84
-            'posts_per_page' => 1000,
85
-            'orderby'          => $this->orderby,
86
-            'order'            => $this->order
87
-        );
79
+		// course query parameters to be used for all courses
80
+		$query_args = array(
81
+			'post_type'        => 'course',
82
+			'post_status'      => 'publish',
83
+			// the number specified by the user will be used later in this function
84
+			'posts_per_page' => 1000,
85
+			'orderby'          => $this->orderby,
86
+			'order'            => $this->order
87
+		);
88 88
 
89
-        // get all the courses that has a product attached
90
-        $all_courses_query = new WP_Query( $query_args );
89
+		// get all the courses that has a product attached
90
+		$all_courses_query = new WP_Query( $query_args );
91 91
 
92
-        $paid_courses_not_taken = array();
93
-        // look through all course and find the purchasable ones that user has not purchased
94
-        foreach( $all_courses_query->posts as $course ){
92
+		$paid_courses_not_taken = array();
93
+		// look through all course and find the purchasable ones that user has not purchased
94
+		foreach( $all_courses_query->posts as $course ){
95 95
 
96
-            // only keep the courses with a product including only  courses that the user not taking
97
-            $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
98
-            if( is_numeric( $course_product_id )
99
-                &&
100
-                ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
101
-            ){
96
+			// only keep the courses with a product including only  courses that the user not taking
97
+			$course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
98
+			if( is_numeric( $course_product_id )
99
+				&&
100
+				! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
101
+			){
102 102
 
103
-                    $paid_courses_not_taken[] = $course->ID;
103
+					$paid_courses_not_taken[] = $course->ID;
104 104
 
105
-                }
105
+				}
106 106
 
107
-        } // end foreach
107
+		} // end foreach
108 108
 
109
-        // setup the course query again and only use the course the user has not purchased.
110
-        // this query will be loaded into the global WP_Query in the render function.
111
-        $query_args[ 'post__in' ] = $paid_courses_not_taken;
112
-        $query_args[ 'posts_per_page' ] = $this->number;
109
+		// setup the course query again and only use the course the user has not purchased.
110
+		// this query will be loaded into the global WP_Query in the render function.
111
+		$query_args[ 'post__in' ] = $paid_courses_not_taken;
112
+		$query_args[ 'posts_per_page' ] = $this->number;
113 113
 
114
-        $this->query = new WP_Query( $query_args );
114
+		$this->query = new WP_Query( $query_args );
115 115
 
116
-    }// end setup _course_query
116
+	}// end setup _course_query
117 117
 
118
-    /**
119
-     * Rendering the shortcode this class is responsible for.
120
-     *
121
-     * @return string $content
122
-     */
123
-    public function render(){
118
+	/**
119
+	 * Rendering the shortcode this class is responsible for.
120
+	 *
121
+	 * @return string $content
122
+	 */
123
+	public function render(){
124 124
 
125
-        global $wp_query;
125
+		global $wp_query;
126 126
 
127
-        if ( ! is_user_logged_in() ) {
127
+		if ( ! is_user_logged_in() ) {
128 128
 
129
-            $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
130
-            $anchor_after = '</a>';
131
-            $notice = sprintf(
132
-                __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'),
133
-                $anchor_before,
134
-                $anchor_after
135
-            );
129
+			$anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
130
+			$anchor_after = '</a>';
131
+			$notice = sprintf(
132
+				__('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'),
133
+				$anchor_before,
134
+				$anchor_after
135
+			);
136 136
 
137
-            Sensei()->notices->add_notice( $notice, 'info' );
138
-            Sensei()->notices->print_notices();
137
+			Sensei()->notices->add_notice( $notice, 'info' );
138
+			Sensei()->notices->print_notices();
139 139
 
140
-            return '';
140
+			return '';
141 141
 
142
-        }
142
+		}
143 143
 
144
-        // keep a reference to old query
145
-        $current_global_query = $wp_query;
146
-        // assign the query setup in $this-> setup_course_query
147
-        $wp_query = $this->query;
144
+		// keep a reference to old query
145
+		$current_global_query = $wp_query;
146
+		// assign the query setup in $this-> setup_course_query
147
+		$wp_query = $this->query;
148 148
 
149
-        ob_start();
150
-        Sensei()->notices->print_notices();
151
-        Sensei_Templates::get_template('loop-course.php');
152
-        $shortcode_output =  ob_get_clean();
149
+		ob_start();
150
+		Sensei()->notices->print_notices();
151
+		Sensei_Templates::get_template('loop-course.php');
152
+		$shortcode_output =  ob_get_clean();
153 153
 
154
-        //restore old query
155
-        $wp_query = $current_global_query;
154
+		//restore old query
155
+		$wp_query = $current_global_query;
156 156
 
157
-        return $shortcode_output;
157
+		return $shortcode_output;
158 158
 
159
-    }// end render
159
+	}// end render
160 160
 
161 161
 }
162 162
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_unpurchased_courses] shortcode when a user is logged in. If the user is not logged in
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
      * @param string $content
46 46
      * @param string $shortcode the shortcode that was called for this instance
47 47
      */
48
-    public function __construct( $attributes, $content, $shortcode ){
48
+    public function __construct($attributes, $content, $shortcode) {
49 49
 
50 50
         // set up all argument need for constructing the course query
51
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
52
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
51
+        $this->number = isset($attributes['number']) ? $attributes['number'] : '10';
52
+        $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'title';
53 53
 
54 54
         // set the default for menu_order to be ASC
55
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
55
+        if ('menu_order' == $this->orderby && ! isset($attributes['order'])) {
56 56
 
57
-            $this->order =  'ASC';
57
+            $this->order = 'ASC';
58 58
 
59
-        }else{
59
+        } else {
60 60
 
61 61
             // for everything else use the value passed or the default DESC
62
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
62
+            $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC';
63 63
 
64 64
         }
65 65
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @since 1.9.0
75 75
      */
76
-    protected function setup_course_query(){
76
+    protected function setup_course_query() {
77 77
 
78 78
 
79 79
         // course query parameters to be used for all courses
@@ -87,18 +87,18 @@  discard block
 block discarded – undo
87 87
         );
88 88
 
89 89
         // get all the courses that has a product attached
90
-        $all_courses_query = new WP_Query( $query_args );
90
+        $all_courses_query = new WP_Query($query_args);
91 91
 
92 92
         $paid_courses_not_taken = array();
93 93
         // look through all course and find the purchasable ones that user has not purchased
94
-        foreach( $all_courses_query->posts as $course ){
94
+        foreach ($all_courses_query->posts as $course) {
95 95
 
96 96
             // only keep the courses with a product including only  courses that the user not taking
97
-            $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
98
-            if( is_numeric( $course_product_id )
97
+            $course_product_id = get_post_meta($course->ID, '_course_woocommerce_product', true);
98
+            if (is_numeric($course_product_id)
99 99
                 &&
100
-                ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
101
-            ){
100
+                ! Sensei_Utils::user_started_course($course->ID, get_current_user_id())
101
+            ) {
102 102
 
103 103
                     $paid_courses_not_taken[] = $course->ID;
104 104
 
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
 
109 109
         // setup the course query again and only use the course the user has not purchased.
110 110
         // this query will be loaded into the global WP_Query in the render function.
111
-        $query_args[ 'post__in' ] = $paid_courses_not_taken;
112
-        $query_args[ 'posts_per_page' ] = $this->number;
111
+        $query_args['post__in'] = $paid_courses_not_taken;
112
+        $query_args['posts_per_page'] = $this->number;
113 113
 
114
-        $this->query = new WP_Query( $query_args );
114
+        $this->query = new WP_Query($query_args);
115 115
 
116 116
     }// end setup _course_query
117 117
 
@@ -120,13 +120,13 @@  discard block
 block discarded – undo
120 120
      *
121 121
      * @return string $content
122 122
      */
123
-    public function render(){
123
+    public function render() {
124 124
 
125 125
         global $wp_query;
126 126
 
127
-        if ( ! is_user_logged_in() ) {
127
+        if ( ! is_user_logged_in()) {
128 128
 
129
-            $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
129
+            $anchor_before = '<a href="'.esc_url(sensei_user_login_url()).'" >';
130 130
             $anchor_after = '</a>';
131 131
             $notice = sprintf(
132 132
                 __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'),
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 $anchor_after
135 135
             );
136 136
 
137
-            Sensei()->notices->add_notice( $notice, 'info' );
137
+            Sensei()->notices->add_notice($notice, 'info');
138 138
             Sensei()->notices->print_notices();
139 139
 
140 140
             return '';
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
         ob_start();
150 150
         Sensei()->notices->print_notices();
151 151
         Sensei_Templates::get_template('loop-course.php');
152
-        $shortcode_output =  ob_get_clean();
152
+        $shortcode_output = ob_get_clean();
153 153
 
154 154
         //restore old query
155 155
         $wp_query = $current_global_query;
Please login to merge, or discard this patch.
includes/class-sensei-learner-profiles.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@  discard block
 block discarded – undo
10 10
  * @since 1.4.0
11 11
  */
12 12
 class Sensei_Learner_Profiles {
13
-    /**
14
-     * @var string
15
-     */
16
-    private $profile_url_base;
13
+	/**
14
+	 * @var string
15
+	 */
16
+	private $profile_url_base;
17 17
 
18 18
 	/**
19 19
 	 * Constructor.
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function setup_permastruct() {
44 44
 
45
-        if( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] )
46
-            && Sensei()->settings->settings[ 'learner_profile_enable' ] ) {
45
+		if( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] )
46
+			&& Sensei()->settings->settings[ 'learner_profile_enable' ] ) {
47 47
 
48 48
 			add_rewrite_rule( '^' . $this->profile_url_base . '/([^/]*)/?', 'index.php?learner_profile=$matches[1]', 'top' );
49 49
 			add_rewrite_tag( '%learner_profile%', '([^&]+)' );
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 		if( isset( $wp_query->query_vars['learner_profile'] ) ) {
63 63
 			$learner_user = get_user_by( 'login', $wp_query->query_vars['learner_profile'] );
64 64
 
65
-            $name = Sensei_Learner::get_full_name( $learner_user->ID );
65
+			$name = Sensei_Learner::get_full_name( $learner_user->ID );
66 66
 
67 67
 			$title = apply_filters( 'sensei_learner_profile_courses_heading', sprintf( __( 'Courses %s is taking', 'woothemes-sensei' ), $name ) ) . ' ' . $sep . ' ';
68 68
 		}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 
111 111
 			if( isset( $wp_query->query_vars['learner_profile'] ) ) {
112 112
 
113
-                Sensei_Templates::get_template( 'learner-profile/learner-info.php' );
113
+				Sensei_Templates::get_template( 'learner-profile/learner-info.php' );
114 114
 
115 115
 			}
116 116
 		}
@@ -140,43 +140,43 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public static function user_info( $user ) {
142 142
 
143
-        /**
144
-         * This hooke fires inside the Sensei_Learner_Profiles::user_info function.
145
-         * just before the htmls is generated.
146
-         * @since 1.0.0
147
-         */
148
-        do_action( 'sensei_learner_profile_info', $user );
149
-
150
-        /**
151
-         * This filter runs inside the Sensei_Learner_Profiles::user_info function.
152
-         * Here you can change the user avatar.
153
-         *
154
-         * @since 1.0.0
155
-         *
156
-         * @param false|string `<img>` $user_avatar
157
-         */
143
+		/**
144
+		 * This hooke fires inside the Sensei_Learner_Profiles::user_info function.
145
+		 * just before the htmls is generated.
146
+		 * @since 1.0.0
147
+		 */
148
+		do_action( 'sensei_learner_profile_info', $user );
149
+
150
+		/**
151
+		 * This filter runs inside the Sensei_Learner_Profiles::user_info function.
152
+		 * Here you can change the user avatar.
153
+		 *
154
+		 * @since 1.0.0
155
+		 *
156
+		 * @param false|string `<img>` $user_avatar
157
+		 */
158 158
 		$learner_avatar = apply_filters( 'sensei_learner_profile_info_avatar', get_avatar( $user->ID, 120 ), $user->ID );
159 159
 
160
-        /**
161
-         * This filter runs inside the Sensei_Learner_Profiles::user_info function.
162
-         * Here you can change the learner profile user display name.
163
-         * @since 1.0.0
164
-         *
165
-         * @param string $user_display_name
166
-         * @param string $user_id
167
-         */
160
+		/**
161
+		 * This filter runs inside the Sensei_Learner_Profiles::user_info function.
162
+		 * Here you can change the learner profile user display name.
163
+		 * @since 1.0.0
164
+		 *
165
+		 * @param string $user_display_name
166
+		 * @param string $user_id
167
+		 */
168 168
 		$learner_name = apply_filters( 'sensei_learner_profile_info_name', $user->display_name, $user->ID );
169 169
 
170
-        /**
171
-         * This filter runs inside the Sensei_Learner_Profiles::user_info function.
172
-         * With this filter can change the users description on the learner user info
173
-         * output.
174
-         *
175
-         * @since 1.0.0
176
-         *
177
-         * @param string $user_description
178
-         * @param string $user_id
179
-         */
170
+		/**
171
+		 * This filter runs inside the Sensei_Learner_Profiles::user_info function.
172
+		 * With this filter can change the users description on the learner user info
173
+		 * output.
174
+		 *
175
+		 * @since 1.0.0
176
+		 *
177
+		 * @param string $user_description
178
+		 * @param string $user_id
179
+		 */
180 180
 		$learner_bio = apply_filters( 'sensei_learner_profile_info_bio', $user->description, $user->ID );
181 181
 		?>
182 182
 
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
 		return $classes;
211 211
 	}
212 212
 
213
-    /**
214
-     * Deprecate the deprecate_sensei_learner_profile_content hook
215
-     *
216
-     * @since 1.9.0
217
-     */
218
-    public static function deprecate_sensei_learner_profile_content_hook(){
213
+	/**
214
+	 * Deprecate the deprecate_sensei_learner_profile_content hook
215
+	 *
216
+	 * @since 1.9.0
217
+	 */
218
+	public static function deprecate_sensei_learner_profile_content_hook(){
219 219
 
220
-        sensei_do_deprecated_action( 'sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before' );
220
+		sensei_do_deprecated_action( 'sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before' );
221 221
 
222
-    }
222
+	}
223 223
 
224 224
 
225 225
 } // End Class
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 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
  * All functionality pertaining to the learner profiles in Sensei.
@@ -19,20 +19,20 @@  discard block
 block discarded – undo
19 19
 	 * Constructor.
20 20
 	 * @since  1.4.0
21 21
 	 */
22
-	public function __construct () {
22
+	public function __construct() {
23 23
 
24 24
 		// Setup learner profile URL base
25
-		$this->profile_url_base = apply_filters( 'sensei_learner_profiles_url_base', __( 'learner', 'woothemes-sensei') );
25
+		$this->profile_url_base = apply_filters('sensei_learner_profiles_url_base', __('learner', 'woothemes-sensei'));
26 26
 
27 27
 		// Setup permalink structure for learner profiles
28
-		add_action( 'init', array( $this, 'setup_permastruct' ) );
29
-		add_filter( 'wp_title', array( $this, 'page_title' ), 10, 2 );
28
+		add_action('init', array($this, 'setup_permastruct'));
29
+		add_filter('wp_title', array($this, 'page_title'), 10, 2);
30 30
 
31 31
 		// Set heading for courses section of learner profiles
32
-		add_action( 'sensei_learner_profile_info', array( $this, 'learner_profile_courses_heading' ), 30, 1 );
32
+		add_action('sensei_learner_profile_info', array($this, 'learner_profile_courses_heading'), 30, 1);
33 33
 
34 34
 		// Add class to body tag
35
-		add_filter( 'body_class', array( $this, 'learner_profile_body_class' ), 10, 1 );
35
+		add_filter('body_class', array($this, 'learner_profile_body_class'), 10, 1);
36 36
 	} // End __construct()
37 37
 
38 38
 	/**
@@ -42,11 +42,11 @@  discard block
 block discarded – undo
42 42
 	 */
43 43
 	public function setup_permastruct() {
44 44
 
45
-        if( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] )
46
-            && Sensei()->settings->settings[ 'learner_profile_enable' ] ) {
45
+        if (isset(Sensei()->settings->settings['learner_profile_enable'])
46
+            && Sensei()->settings->settings['learner_profile_enable']) {
47 47
 
48
-			add_rewrite_rule( '^' . $this->profile_url_base . '/([^/]*)/?', 'index.php?learner_profile=$matches[1]', 'top' );
49
-			add_rewrite_tag( '%learner_profile%', '([^&]+)' );
48
+			add_rewrite_rule('^'.$this->profile_url_base.'/([^/]*)/?', 'index.php?learner_profile=$matches[1]', 'top');
49
+			add_rewrite_tag('%learner_profile%', '([^&]+)');
50 50
 
51 51
 		}
52 52
 	}
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 	 * @param  string $sep   Seeparator string
58 58
 	 * @return string        Modified title
59 59
 	 */
60
-	public function page_title( $title, $sep = null ) {
60
+	public function page_title($title, $sep = null) {
61 61
 		global $wp_query;
62
-		if( isset( $wp_query->query_vars['learner_profile'] ) ) {
63
-			$learner_user = get_user_by( 'login', $wp_query->query_vars['learner_profile'] );
62
+		if (isset($wp_query->query_vars['learner_profile'])) {
63
+			$learner_user = get_user_by('login', $wp_query->query_vars['learner_profile']);
64 64
 
65
-            $name = Sensei_Learner::get_full_name( $learner_user->ID );
65
+            $name = Sensei_Learner::get_full_name($learner_user->ID);
66 66
 
67
-			$title = apply_filters( 'sensei_learner_profile_courses_heading', sprintf( __( 'Courses %s is taking', 'woothemes-sensei' ), $name ) ) . ' ' . $sep . ' ';
67
+			$title = apply_filters('sensei_learner_profile_courses_heading', sprintf(__('Courses %s is taking', 'woothemes-sensei'), $name)).' '.$sep.' ';
68 68
 		}
69 69
 		return $title;
70 70
 	}
@@ -75,23 +75,23 @@  discard block
 block discarded – undo
75 75
 	 * @param  integer $user_id ID of user
76 76
 	 * @return string           The learner profile permalink
77 77
 	 */
78
-	public function get_permalink( $user_id = 0 ) {
78
+	public function get_permalink($user_id = 0) {
79 79
 		$user = false;
80
-		if( $user_id == 0 ) {
80
+		if ($user_id == 0) {
81 81
 			global $current_user;
82 82
 			wp_get_current_user();
83 83
 			$user = $current_user;
84 84
 		} else {
85
-			$user = get_userdata( $user_id );
85
+			$user = get_userdata($user_id);
86 86
 		}
87 87
 
88 88
 		$permalink = '';
89 89
 
90
-		if( $user ) {
91
-			if ( get_option('permalink_structure') ) {
92
-				$permalink = trailingslashit( get_site_url() ) . $this->profile_url_base . '/' . $user->user_nicename;
90
+		if ($user) {
91
+			if (get_option('permalink_structure')) {
92
+				$permalink = trailingslashit(get_site_url()).$this->profile_url_base.'/'.$user->user_nicename;
93 93
 			} else {
94
-				$permalink = trailingslashit( get_site_url() ) . '?learner_profile=' . $user->user_nicename;
94
+				$permalink = trailingslashit(get_site_url()).'?learner_profile='.$user->user_nicename;
95 95
 			}
96 96
 		}
97 97
 
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
 	 * @return void
105 105
 	 */
106 106
 	public function content() {
107
-		global $wp_query,  $learner_user, $current_user;
107
+		global $wp_query, $learner_user, $current_user;
108 108
 
109
-		if( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] ) && Sensei()->settings->settings[ 'learner_profile_enable' ] ) {
109
+		if (isset(Sensei()->settings->settings['learner_profile_enable']) && Sensei()->settings->settings['learner_profile_enable']) {
110 110
 
111
-			if( isset( $wp_query->query_vars['learner_profile'] ) ) {
111
+			if (isset($wp_query->query_vars['learner_profile'])) {
112 112
 
113
-                Sensei_Templates::get_template( 'learner-profile/learner-info.php' );
113
+                Sensei_Templates::get_template('learner-profile/learner-info.php');
114 114
 
115 115
 			}
116 116
 		}
@@ -122,14 +122,14 @@  discard block
 block discarded – undo
122 122
 	 * @param  object $user Queried user object
123 123
 	 * @return void
124 124
 	 */
125
-	public function learner_profile_courses_heading( $user ) {
126
-		if( strlen( $user->first_name ) > 0 ) {
125
+	public function learner_profile_courses_heading($user) {
126
+		if (strlen($user->first_name) > 0) {
127 127
 			$name = $user->first_name;
128 128
 		} else {
129 129
 			$name = $user->display_name;
130 130
 		}
131
-		$name = apply_filters( 'sensei_learner_profile_courses_heading_name', $name );
132
-		echo '<h2>' . apply_filters( 'sensei_learner_profile_courses_heading', sprintf( __( 'Courses %s is taking', 'woothemes-sensei' ), $name ) ) . '</h2>';
131
+		$name = apply_filters('sensei_learner_profile_courses_heading_name', $name);
132
+		echo '<h2>'.apply_filters('sensei_learner_profile_courses_heading', sprintf(__('Courses %s is taking', 'woothemes-sensei'), $name)).'</h2>';
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 	 * @param  object $user Queried user object
139 139
 	 * @return void
140 140
 	 */
141
-	public static function user_info( $user ) {
141
+	public static function user_info($user) {
142 142
 
143 143
         /**
144 144
          * This hooke fires inside the Sensei_Learner_Profiles::user_info function.
145 145
          * just before the htmls is generated.
146 146
          * @since 1.0.0
147 147
          */
148
-        do_action( 'sensei_learner_profile_info', $user );
148
+        do_action('sensei_learner_profile_info', $user);
149 149
 
150 150
         /**
151 151
          * This filter runs inside the Sensei_Learner_Profiles::user_info function.
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
          *
156 156
          * @param false|string `<img>` $user_avatar
157 157
          */
158
-		$learner_avatar = apply_filters( 'sensei_learner_profile_info_avatar', get_avatar( $user->ID, 120 ), $user->ID );
158
+		$learner_avatar = apply_filters('sensei_learner_profile_info_avatar', get_avatar($user->ID, 120), $user->ID);
159 159
 
160 160
         /**
161 161
          * This filter runs inside the Sensei_Learner_Profiles::user_info function.
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
          * @param string $user_display_name
166 166
          * @param string $user_id
167 167
          */
168
-		$learner_name = apply_filters( 'sensei_learner_profile_info_name', $user->display_name, $user->ID );
168
+		$learner_name = apply_filters('sensei_learner_profile_info_name', $user->display_name, $user->ID);
169 169
 
170 170
         /**
171 171
          * This filter runs inside the Sensei_Learner_Profiles::user_info function.
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
          * @param string $user_description
178 178
          * @param string $user_id
179 179
          */
180
-		$learner_bio = apply_filters( 'sensei_learner_profile_info_bio', $user->description, $user->ID );
180
+		$learner_bio = apply_filters('sensei_learner_profile_info_bio', $user->description, $user->ID);
181 181
 		?>
182 182
 
183 183
 		<div id="learner-info">
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 				<h2><?php echo $learner_name; ?></h2>
190 190
 
191
-				<div class="description"><?php echo wpautop( $learner_bio ); ?></div>
191
+				<div class="description"><?php echo wpautop($learner_bio); ?></div>
192 192
 
193 193
 			</div>
194 194
 
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 	 * @param  array $classes Existing classes
203 203
 	 * @return array          Modified classes
204 204
 	 */
205
-	public function learner_profile_body_class( $classes ) {
205
+	public function learner_profile_body_class($classes) {
206 206
 		global $wp_query;
207
-		if( isset( $wp_query->query_vars['learner_profile'] ) ) {
207
+		if (isset($wp_query->query_vars['learner_profile'])) {
208 208
 			$classes[] = 'learner-profile';
209 209
 		}
210 210
 		return $classes;
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
      *
216 216
      * @since 1.9.0
217 217
      */
218
-    public static function deprecate_sensei_learner_profile_content_hook(){
218
+    public static function deprecate_sensei_learner_profile_content_hook() {
219 219
 
220
-        sensei_do_deprecated_action( 'sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before' );
220
+        sensei_do_deprecated_action('sensei_learner_profile_content', '1.9.0', 'sensei_learner_profile_content_before');
221 221
 
222 222
     }
223 223
 
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-learner-completed-course.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5
-if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Completed_Course' ) ) :
5
+if ( ! class_exists('WooThemes_Sensei_Email_Learner_Completed_Course')) :
6 6
 
7 7
 /**
8 8
  * Learner Completed Course
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	 */
31 31
 	function __construct() {
32 32
 		$this->template = 'learner-completed-course';
33
-		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
34
-		$this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a course', 'woothemes-sensei' ), $this->template );
33
+		$this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template);
34
+		$this->heading = apply_filters('sensei_email_heading', __('You have completed a course', 'woothemes-sensei'), $this->template);
35 35
 	}
36 36
 
37 37
 	/**
@@ -40,32 +40,32 @@  discard block
 block discarded – undo
40 40
 	 * @access public
41 41
 	 * @return void
42 42
 	 */
43
-	function trigger( $user_id = 0, $course_id = 0 ) {
43
+	function trigger($user_id = 0, $course_id = 0) {
44 44
 		global  $sensei_email_data;
45 45
 
46 46
 		// Get learner user object
47
-		$this->user = new WP_User( $user_id );
47
+		$this->user = new WP_User($user_id);
48 48
 
49 49
 		// Get passed status
50
-		$passed = __( 'passed', 'woothemes-sensei' );
51
-		if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $user_id ) ) {
52
-			$passed = __( 'failed', 'woothemes-sensei' );
50
+		$passed = __('passed', 'woothemes-sensei');
51
+		if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $user_id)) {
52
+			$passed = __('failed', 'woothemes-sensei');
53 53
 		}
54 54
 
55 55
 		// Construct data array
56
-		$sensei_email_data = apply_filters( 'sensei_email_data', array(
56
+		$sensei_email_data = apply_filters('sensei_email_data', array(
57 57
 			'template'			=> $this->template,
58 58
 			'heading'			=> $this->heading,
59 59
 			'user_id'			=> $user_id,
60 60
 			'course_id'			=> $course_id,
61 61
 			'passed'			=> $passed,
62
-		), $this->template );
62
+		), $this->template);
63 63
 
64 64
 		// Set recipient (learner)
65
-		$this->recipient = stripslashes( $this->user->user_email );
65
+		$this->recipient = stripslashes($this->user->user_email);
66 66
 
67 67
 		// Send mail
68
-		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
68
+		Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template));
69 69
 	}
70 70
 }
71 71
 
Please login to merge, or discard this patch.
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,10 +38,10 @@
 block discarded – undo
38 38
 	 * trigger function.
39 39
 	 *
40 40
 	 * @access public
41
-     *
42
-     * @param int $user_id
43
-     * @param int $course_id
44
-     *
41
+	 *
42
+	 * @param int $user_id
43
+	 * @param int $course_id
44
+	 *
45 45
 	 * @return void
46 46
 	 */
47 47
 	function trigger( $user_id = 0, $course_id = 0 ) {
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-teacher-completed-course.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5
-if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Course' ) ) :
5
+if ( ! class_exists('WooThemes_Sensei_Email_Teacher_Completed_Course')) :
6 6
 
7 7
 /**
8 8
  * Teacher Completed Course
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	function __construct() {
33 33
 		$this->template = 'teacher-completed-course';
34
-		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
35
-		$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a course', 'woothemes-sensei' ), $this->template );
34
+		$this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your student has completed a course', 'woothemes-sensei'), get_bloginfo('name')), $this->template);
35
+		$this->heading = apply_filters('sensei_email_heading', __('Your student has completed a course', 'woothemes-sensei'), $this->template);
36 36
 	}
37 37
 
38 38
 	/**
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
 	 * @access public
42 42
 	 * @return void
43 43
 	 */
44
-	function trigger( $learner_id = 0, $course_id = 0 ) {
44
+	function trigger($learner_id = 0, $course_id = 0) {
45 45
 		global  $sensei_email_data;
46 46
 
47 47
 		// Get learner user object
48
-		$this->learner = new WP_User( $learner_id );
48
+		$this->learner = new WP_User($learner_id);
49 49
 
50 50
 		// Get teacher ID and user object
51
-		$teacher_id = get_post_field( 'post_author', $course_id, 'raw' );
52
-		$this->teacher = new WP_User( $teacher_id );
51
+		$teacher_id = get_post_field('post_author', $course_id, 'raw');
52
+		$this->teacher = new WP_User($teacher_id);
53 53
 
54 54
 		// Get passed status
55
-		$passed = __( 'passed', 'woothemes-sensei' );
56
-		if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $learner_id ) ) {
57
-			$passed = __( 'failed', 'woothemes-sensei' );
55
+		$passed = __('passed', 'woothemes-sensei');
56
+		if ( ! Sensei_Utils::sensei_user_passed_course($course_id, $learner_id)) {
57
+			$passed = __('failed', 'woothemes-sensei');
58 58
 		}
59 59
 
60 60
 		// Construct data array
61
-		$sensei_email_data = apply_filters( 'sensei_email_data', array(
61
+		$sensei_email_data = apply_filters('sensei_email_data', array(
62 62
 			'template'			=> $this->template,
63 63
 			'heading'			=> $this->heading,
64 64
 			'teacher_id'		=> $teacher_id,
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
 			'learner_name'		=> $this->learner->display_name,
67 67
 			'course_id'			=> $course_id,
68 68
 			'passed'			=> $passed,
69
-		), $this->template );
69
+		), $this->template);
70 70
 
71 71
 		// Set recipient (learner)
72
-		$this->recipient = stripslashes( $this->teacher->user_email );
72
+		$this->recipient = stripslashes($this->teacher->user_email);
73 73
 
74 74
 		// Send mail
75
-		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
75
+		Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template));
76 76
 	}
77 77
 }
78 78
 
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,9 +37,9 @@
 block discarded – undo
37 37
 	/**
38 38
 	 * trigger function.
39 39
 	 *
40
-     * @param int $learner_id
41
-     * @param int $course_id
42
-     *
40
+	 * @param int $learner_id
41
+	 * @param int $course_id
42
+	 *
43 43
 	 * @return void
44 44
 	 */
45 45
 	function trigger( $learner_id = 0, $course_id = 0 ) {
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-new-message-reply.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -16,38 +16,38 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class WooThemes_Sensei_Email_New_Message_Reply {
18 18
 
19
-    /**
20
-     * @var string
21
-     */
22
-    var $template;
23
-
24
-    /**
25
-     * @var string
26
-     */
19
+	/**
20
+	 * @var string
21
+	 */
22
+	var $template;
23
+
24
+	/**
25
+	 * @var string
26
+	 */
27 27
 	var $subject;
28 28
 
29
-    /**
30
-     * @var string
31
-     */
32
-    var $heading;
29
+	/**
30
+	 * @var string
31
+	 */
32
+	var $heading;
33 33
 
34
-    /**
35
-     * @var string
36
-     */
34
+	/**
35
+	 * @var string
36
+	 */
37 37
 	var $recipient;
38 38
 
39 39
 	var $original_sender;
40 40
 	var $original_receiver;
41 41
 	var $commenter;
42 42
 
43
-    /**
44
-     * @var WP_Post
45
-     */
43
+	/**
44
+	 * @var WP_Post
45
+	 */
46 46
 	var $message;
47 47
 
48
-    /**
49
-     * @var WP_Comment
50
-     */
48
+	/**
49
+	 * @var WP_Comment
50
+	 */
51 51
 	var $comment;
52 52
 
53 53
 	/**
@@ -64,9 +64,9 @@  discard block
 block discarded – undo
64 64
 	/**
65 65
 	 * trigger function.
66 66
 	 *
67
-     * @param WP_Comment $comment
68
-     * @param string $message
69
-     *
67
+	 * @param WP_Comment $comment
68
+	 * @param string $message
69
+	 *
70 70
 	 * @return void
71 71
 	 */
72 72
 	function trigger ( $comment, $message ) {
@@ -90,16 +90,16 @@  discard block
 block discarded – undo
90 90
 
91 91
 		$comment_link = get_comment_link( $comment );
92 92
 
93
-        // setup the post type parameter
94
-        $content_type = get_post_type( $content_id );
95
-        if( !$content_type ){
96
-            $content_type ='';
97
-        }
93
+		// setup the post type parameter
94
+		$content_type = get_post_type( $content_id );
95
+		if( !$content_type ){
96
+			$content_type ='';
97
+		}
98 98
 
99
-        // Construct data array
100
-        $sensei_email_data = apply_filters( 'sensei_email_data', array(
101
-            'template'			=> $this->template,
102
-            $content_type.'_id' => $content_id,
99
+		// Construct data array
100
+		$sensei_email_data = apply_filters( 'sensei_email_data', array(
101
+			'template'			=> $this->template,
102
+			$content_type.'_id' => $content_id,
103 103
 			'heading'			=> $this->heading,
104 104
 			'commenter_name'	=> $this->commenter->display_name,
105 105
 			'message'			=> $this->comment->comment_content,
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5
-if ( ! class_exists( 'WooThemes_Sensei_Email_New_Message_Reply' ) ) :
5
+if ( ! class_exists('WooThemes_Sensei_Email_New_Message_Reply')) :
6 6
 
7 7
 /**
8 8
  * Teacher New Message
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	function __construct() {
59 59
 		$this->template = 'new-message-reply';
60
-		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have a new message', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
61
-		$this->heading = apply_filters( 'sensei_email_heading', __( 'You have received a reply to your private message', 'woothemes-sensei' ), $this->template );
60
+		$this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have a new message', 'woothemes-sensei'), get_bloginfo('name')), $this->template);
61
+		$this->heading = apply_filters('sensei_email_heading', __('You have received a reply to your private message', 'woothemes-sensei'), $this->template);
62 62
 	}
63 63
 
64 64
 	/**
@@ -69,35 +69,35 @@  discard block
 block discarded – undo
69 69
      *
70 70
 	 * @return void
71 71
 	 */
72
-	function trigger ( $comment, $message ) {
72
+	function trigger($comment, $message) {
73 73
 
74 74
 		global  $sensei_email_data;
75 75
 
76 76
 		$this->comment = $comment;
77 77
 		$this->message = $message;
78 78
 
79
-		$this->commenter = get_userdata( $comment->user_id );
79
+		$this->commenter = get_userdata($comment->user_id);
80 80
 
81
-		$original_sender = get_post_meta( $this->message->ID, '_sender', true );
82
-		$this->original_sender = get_user_by( 'login', $original_sender );
81
+		$original_sender = get_post_meta($this->message->ID, '_sender', true);
82
+		$this->original_sender = get_user_by('login', $original_sender);
83 83
 
84
-		$original_receiver = get_post_meta( $this->message->ID, '_receiver', true );
85
-		$this->original_receiver = get_user_by( 'login', $original_receiver );
84
+		$original_receiver = get_post_meta($this->message->ID, '_receiver', true);
85
+		$this->original_receiver = get_user_by('login', $original_receiver);
86 86
 
87
-		$content_type = get_post_meta( $this->message->ID, '_posttype', true );
88
-		$content_id = get_post_meta( $this->message->ID, '_post', true );
89
-		$content_title = get_the_title( $content_id );
87
+		$content_type = get_post_meta($this->message->ID, '_posttype', true);
88
+		$content_id = get_post_meta($this->message->ID, '_post', true);
89
+		$content_title = get_the_title($content_id);
90 90
 
91
-		$comment_link = get_comment_link( $comment );
91
+		$comment_link = get_comment_link($comment);
92 92
 
93 93
         // setup the post type parameter
94
-        $content_type = get_post_type( $content_id );
95
-        if( !$content_type ){
96
-            $content_type ='';
94
+        $content_type = get_post_type($content_id);
95
+        if ( ! $content_type) {
96
+            $content_type = '';
97 97
         }
98 98
 
99 99
         // Construct data array
100
-        $sensei_email_data = apply_filters( 'sensei_email_data', array(
100
+        $sensei_email_data = apply_filters('sensei_email_data', array(
101 101
             'template'			=> $this->template,
102 102
             $content_type.'_id' => $content_id,
103 103
 			'heading'			=> $this->heading,
@@ -106,17 +106,17 @@  discard block
 block discarded – undo
106 106
 			'comment_link'		=> $comment_link,
107 107
 			'content_title'		=> $content_title,
108 108
 			'content_type'		=> $content_type,
109
-		), $this->template );
109
+		), $this->template);
110 110
 
111 111
 		// Set recipient
112
-		if( $this->commenter->user_login == $original_sender ) {
113
-			$this->recipient = stripslashes( $this->original_receiver->user_email );
112
+		if ($this->commenter->user_login == $original_sender) {
113
+			$this->recipient = stripslashes($this->original_receiver->user_email);
114 114
 		} else {
115
-			$this->recipient = stripslashes( $this->original_sender->user_email );
115
+			$this->recipient = stripslashes($this->original_sender->user_email);
116 116
 		}
117 117
 
118 118
 		// Send mail
119
-		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
119
+		Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template));
120 120
 	}
121 121
 }
122 122
 
Please login to merge, or discard this patch.
includes/emails/class-woothemes-sensei-email-learner-graded-quiz.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@
 block discarded – undo
36 36
 	/**
37 37
 	 * trigger function.
38 38
 	 *
39
-     * @param int $user_id
40
-     * @param int $quiz_id
41
-     * @param int $grade
42
-     * @param int $passmark
43
-     *
39
+	 * @param int $user_id
40
+	 * @param int $quiz_id
41
+	 * @param int $grade
42
+	 * @param int $passmark
43
+	 *
44 44
 	 * @return void
45 45
 	 */
46 46
 	function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) {
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
4 4
 
5
-if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Graded_Quiz' ) ) :
5
+if ( ! class_exists('WooThemes_Sensei_Email_Learner_Graded_Quiz')) :
6 6
 
7 7
 /**
8 8
  * Learner Graded Quiz
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
 	 */
30 30
 	function __construct() {
31 31
 		$this->template = 'learner-graded-quiz';
32
-		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your quiz has been graded', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
33
-		$this->heading = apply_filters( 'sensei_email_heading', __( 'Your quiz has been graded', 'woothemes-sensei' ), $this->template );
32
+		$this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your quiz has been graded', 'woothemes-sensei'), get_bloginfo('name')), $this->template);
33
+		$this->heading = apply_filters('sensei_email_heading', __('Your quiz has been graded', 'woothemes-sensei'), $this->template);
34 34
 	}
35 35
 
36 36
 	/**
@@ -43,48 +43,48 @@  discard block
 block discarded – undo
43 43
      *
44 44
 	 * @return void
45 45
 	 */
46
-	function trigger ( $user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0 ) {
46
+	function trigger($user_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0) {
47 47
 
48 48
 		global  $sensei_email_data;
49 49
 
50 50
 		// Get learner user object
51
-		$this->user = new WP_User( $user_id );
51
+		$this->user = new WP_User($user_id);
52 52
 
53 53
 		// Get passed flag
54
-		$passed = __( 'failed', 'woothemes-sensei' );
55
-		if( $grade >= $passmark ) {
56
-			$passed = __( 'passed', 'woothemes-sensei' );
54
+		$passed = __('failed', 'woothemes-sensei');
55
+		if ($grade >= $passmark) {
56
+			$passed = __('passed', 'woothemes-sensei');
57 57
 		}
58 58
 
59 59
 		// Get grade tye (auto/manual)
60
-		$grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
60
+		$grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
61 61
 
62
-		if( 'auto' == $grade_type ) {
63
-			$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a quiz', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
64
-			$this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a quiz', 'woothemes-sensei' ), $this->template );
62
+		if ('auto' == $grade_type) {
63
+			$this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] You have completed a quiz', 'woothemes-sensei'), get_bloginfo('name')), $this->template);
64
+			$this->heading = apply_filters('sensei_email_heading', __('You have completed a quiz', 'woothemes-sensei'), $this->template);
65 65
 		}
66 66
 
67
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
67
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
68 68
 
69 69
 		// Construct data array
70
-		$sensei_email_data = apply_filters( 'sensei_email_data', array(
70
+		$sensei_email_data = apply_filters('sensei_email_data', array(
71 71
 			'template'			=> $this->template,
72 72
 			'heading'			=> $this->heading,
73 73
 			'user_id'			=> $user_id,
74
-			'user_name'         => stripslashes( $this->user->display_name ),
74
+			'user_name'         => stripslashes($this->user->display_name),
75 75
 			'lesson_id'			=> $lesson_id,
76 76
 			'quiz_id'			=> $quiz_id,
77 77
 			'grade'				=> $grade,
78 78
 			'passmark'			=> $passmark,
79 79
 			'passed'			=> $passed,
80 80
 			'grade_type'		=> $grade_type,
81
-		), $this->template );
81
+		), $this->template);
82 82
 
83 83
 		// Set recipient (learner)
84
-		$this->recipient = stripslashes( $this->user->user_email );
84
+		$this->recipient = stripslashes($this->user->user_email);
85 85
 
86 86
 		// Send mail
87
-		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
87
+		Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template));
88 88
 	}
89 89
 }
90 90
 
Please login to merge, or discard this patch.
includes/class-sensei-utils.php 4 patches
Braces   +41 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Utilities Class
@@ -181,8 +184,7 @@  discard block
 block discarded – undo
181 184
 				// ...use a filter to switch the encoding back
182 185
 				add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
183 186
 			}
184
-		}
185
-		else {
187
+		} else {
186 188
 			$args['status'] = 'any'; // 'log' == 'sensei_user_answer'
187 189
 		}
188 190
 
@@ -307,8 +309,12 @@  discard block
 block discarded – undo
307 309
 				}
308 310
 
309 311
 				foreach( $activities as $activity ) {
310
-					if( '' == $activity->comment_type ) continue;
311
-					if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
312
+					if( '' == $activity->comment_type ) {
313
+						continue;
314
+					}
315
+					if( strpos( 'sensei_', $activity->comment_type ) != 0 ) {
316
+						continue;
317
+					}
312 318
 					$dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true );
313 319
 					wp_cache_flush();
314 320
 				}
@@ -360,11 +366,13 @@  discard block
 block discarded – undo
360 366
             $emails[] = $user->user_email;
361 367
         }
362 368
 
363
-        if ( is_email( $customer_email ) )
364
-            $emails[] = $customer_email;
369
+        if ( is_email( $customer_email ) ) {
370
+                    $emails[] = $customer_email;
371
+        }
365 372
 
366
-        if ( sizeof( $emails ) == 0 )
367
-            return false;
373
+        if ( sizeof( $emails ) == 0 ) {
374
+                    return false;
375
+        }
368 376
 
369 377
         return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
370 378
 
@@ -379,7 +387,9 @@  discard block
 block discarded – undo
379 387
 	 */
380 388
 	public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) {
381 389
 
382
-		if( ! $input_name ) $input_name = $editor_id;
390
+		if( ! $input_name ) {
391
+			$input_name = $editor_id;
392
+		}
383 393
 
384 394
 		$buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext';
385 395
 
@@ -689,8 +699,7 @@  discard block
 block discarded – undo
689 699
 				if ( $has_questions ) {
690 700
 					$status = 'passed'; // Force a pass
691 701
 					$metadata['grade'] = 0;
692
-				}
693
-				else {
702
+				} else {
694 703
 					$status = 'complete';
695 704
 				}
696 705
 			}
@@ -738,7 +747,9 @@  discard block
 block discarded – undo
738 747
 	public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) {
739 748
 
740 749
 
741
-		if( ! $lesson_id ) return false;
750
+		if( ! $lesson_id ) {
751
+			return false;
752
+		}
742 753
 
743 754
 		if( intval( $user_id ) == 0 ) {
744 755
 			$user_id = get_current_user_id();
@@ -776,7 +787,9 @@  discard block
 block discarded – undo
776 787
 	public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
777 788
 
778 789
 
779
-		if( ! $course_id ) return false;
790
+		if( ! $course_id ) {
791
+			return false;
792
+		}
780 793
 
781 794
 		if( intval( $user_id ) == 0 ) {
782 795
 			$user_id = get_current_user_id();
@@ -844,8 +857,7 @@  discard block
 block discarded – undo
844 857
 		if( $question ) {
845 858
 			if ( is_object( $question ) ) {
846 859
 				$user_answer_id = $question->comment_ID;
847
-			}
848
-			else {
860
+			} else {
849 861
 				if( intval( $user_id ) == 0 ) {
850 862
 					$user_id = get_current_user_id();
851 863
 				}
@@ -872,8 +884,7 @@  discard block
 block discarded – undo
872 884
 		if( $question ) {
873 885
 			if ( is_object( $question ) ) {
874 886
 				$user_answer_id = $question->comment_ID;
875
-			}
876
-			else {
887
+			} else {
877 888
 				if( intval( $user_id ) == 0 ) {
878 889
 					$user_id = get_current_user_id();
879 890
 				}
@@ -938,8 +949,7 @@  discard block
 block discarded – undo
938 949
 			if ( !empty($notes) ) {
939 950
 				$user_lesson_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
940 951
 				$activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes );
941
-			}
942
-			else {
952
+			} else {
943 953
 				$activity_logged = true;
944 954
 			}
945 955
 		}
@@ -1451,8 +1461,7 @@  discard block
 block discarded – undo
1451 1461
 							$lessons_completed++;
1452 1462
 							break;
1453 1463
 					}
1454
-				}
1455
-				else {
1464
+				} else {
1456 1465
 					switch ( $lesson_status->comment_approved ) {
1457 1466
 						case 'complete': // Lesson has no quiz/questions
1458 1467
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
@@ -1500,11 +1509,9 @@  discard block
 block discarded – undo
1500 1509
 		if( $course ) {
1501 1510
 			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1502 1511
 				$user_course_status = $course->comment_approved;
1503
-			}
1504
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1512
+			} elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1505 1513
 				$user_course_status = $course;
1506
-			}
1507
-			else {
1514
+			} else {
1508 1515
 				if( ! $user_id ) {
1509 1516
 					$user_id = get_current_user_id();
1510 1517
 				}
@@ -1564,11 +1571,9 @@  discard block
 block discarded – undo
1564 1571
 			if ( is_object( $lesson ) ) {
1565 1572
 				$user_lesson_status = $lesson->comment_approved;
1566 1573
 				$lesson_id = $lesson->comment_post_ID;
1567
-			}
1568
-			elseif ( ! is_numeric( $lesson ) ) {
1574
+			} elseif ( ! is_numeric( $lesson ) ) {
1569 1575
 				$user_lesson_status = $lesson;
1570
-			}
1571
-			else {
1576
+			} else {
1572 1577
 				if( ! $user_id ) {
1573 1578
 					$user_id = get_current_user_id();
1574 1579
 				}
@@ -1581,8 +1586,7 @@  discard block
 block discarded – undo
1581 1586
 
1582 1587
 				if ( $_user_lesson_status ) {
1583 1588
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1584
-				}
1585
-				else {
1589
+				} else {
1586 1590
 					return false; // No status means not complete
1587 1591
 				}
1588 1592
 				$lesson_id = $lesson;
@@ -1683,7 +1687,9 @@  discard block
 block discarded – undo
1683 1687
 
1684 1688
 	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1685 1689
 
1686
-		if( ! $quiz_id  ) return false;
1690
+		if( ! $quiz_id  ) {
1691
+			return false;
1692
+		}
1687 1693
 
1688 1694
 		if( ! $user_id ) {
1689 1695
 			$user_id = get_current_user_id();
@@ -1921,7 +1927,7 @@  discard block
 block discarded – undo
1921 1927
             $start_function = 'user_start_'.$post_type;
1922 1928
             $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1923 1929
 
1924
-        }else{
1930
+        } else{
1925 1931
 
1926 1932
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1927 1933
 
@@ -2138,7 +2144,7 @@  discard block
 block discarded – undo
2138 2144
 
2139 2145
             return round( $val, $precision, $mode );
2140 2146
 
2141
-        }else{
2147
+        } else{
2142 2148
 
2143 2149
             return round( $val, $precision );
2144 2150
 
Please login to merge, or discard this patch.
Doc Comments   +21 added lines, -18 removed lines patch added patch discarded remove patch
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
      * @param  string $customer_email
346 346
      * @param  int $user_id
347 347
      * @param  int $product_id
348
-     * @return bool
348
+     * @return boolean|null
349 349
      */
350 350
     public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
351 351
 
@@ -464,6 +464,9 @@  discard block
 block discarded – undo
464 464
 
465 465
 	} // End sensei_save_quiz_answers()
466 466
 
467
+	/**
468
+	 * @return string
469
+	 */
467 470
 	public static function upload_file( $file = array() ) {
468 471
 
469 472
 		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
@@ -636,7 +639,7 @@  discard block
 block discarded – undo
636 639
      * @param integer $lesson_id
637 640
      * @param bool $complete
638 641
      *
639
-     * @return mixed boolean or comment_ID
642
+     * @return boolean|string boolean or comment_ID
640 643
      */
641 644
     public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
642 645
 
@@ -655,7 +658,7 @@  discard block
 block discarded – undo
655 658
 	 * @param int| string $user_id default 0
656 659
      * @param bool $complete default false
657 660
      *
658
-     * @return mixed boolean or comment_ID
661
+     * @return boolean|string boolean or comment_ID
659 662
 	 */
660 663
 	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
661 664
 
@@ -834,7 +837,7 @@  discard block
 block discarded – undo
834 837
 	/**
835 838
 	 * Returns the user_grade for a specific question and user, or sensei_user_answer entry
836 839
 	 *
837
-	 * @param mixed $question
840
+	 * @param integer $question
838 841
 	 * @param int $user_id
839 842
 	 * @return string
840 843
 	 */
@@ -862,7 +865,7 @@  discard block
 block discarded – undo
862 865
 	 * Returns the answer_notes for a specific question and user, or sensei_user_answer entry
863 866
 	 *
864 867
      * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead
865
-	 * @param mixed $question
868
+	 * @param integer $question
866 869
 	 * @param int $user_id
867 870
 	 * @return string
868 871
 	 */
@@ -975,7 +978,7 @@  discard block
 block discarded – undo
975 978
 	 * sort_array_by_key sorts array by key
976 979
 	 * @since  1.3.0
977 980
 	 * @param  array $array by ref
978
-	 * @param  $key string column name in array
981
+	 * @param  string $key string column name in array
979 982
 	 * @return void
980 983
 	 */
981 984
 	public static function sort_array_by_key( $array, $key ) {
@@ -1022,7 +1025,7 @@  discard block
 block discarded – undo
1022 1025
 	/**
1023 1026
 	 * Get pass mark for course
1024 1027
 	 * @param  integer $course_id ID of course
1025
-	 * @return integer            Pass mark for course
1028
+	 * @return double            Pass mark for course
1026 1029
 	 */
1027 1030
 	public static function sensei_course_pass_grade( $course_id = 0 ) {
1028 1031
 
@@ -1063,7 +1066,7 @@  discard block
 block discarded – undo
1063 1066
 	 * Get user total grade for course
1064 1067
 	 * @param  integer $course_id ID of course
1065 1068
 	 * @param  integer $user_id   ID of user
1066
-	 * @return integer            User's total grade
1069
+	 * @return double            User's total grade
1067 1070
 	 */
1068 1071
 	public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) {
1069 1072
 
@@ -1323,7 +1326,7 @@  discard block
 block discarded – undo
1323 1326
 	 * @since  1.4.8
1324 1327
 	 * @param  integer $user_id   User ID
1325 1328
 	 * @param  integer $course_id Course ID
1326
-	 * @return mixed boolean or comment_ID
1329
+	 * @return string|boolean boolean or comment_ID
1327 1330
 	 */
1328 1331
 	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1329 1332
 
@@ -1359,7 +1362,7 @@  discard block
 block discarded – undo
1359 1362
 	 * @since  1.7.0
1360 1363
 	 * @param int $course_id
1361 1364
 	 * @param int $user_id
1362
-	 * @return mixed false or comment_ID
1365
+	 * @return false|string false or comment_ID
1363 1366
 	 */
1364 1367
 	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1365 1368
 
@@ -1386,7 +1389,7 @@  discard block
 block discarded – undo
1386 1389
 	 * @since  1.7.0
1387 1390
 	 * @param  integer $course_id Course ID
1388 1391
 	 * @param  integer $user_id   User ID
1389
-	 * @return int
1392
+	 * @return boolean
1390 1393
 	 */
1391 1394
 	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1392 1395
 		global  $wp_version;
@@ -1535,7 +1538,7 @@  discard block
 block discarded – undo
1535 1538
 	 * @since  1.7.0
1536 1539
 	 * @param int $lesson_id
1537 1540
 	 * @param int $user_id
1538
-	 * @return mixed false or comment_ID
1541
+	 * @return string|false false or comment_ID
1539 1542
 	 */
1540 1543
 	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1541 1544
 
@@ -1562,7 +1565,7 @@  discard block
 block discarded – undo
1562 1565
 	 * Check if a user has completed a lesson or not
1563 1566
 	 *
1564 1567
      * @uses  Sensei()
1565
-	 * @param mixed $lesson lesson_id or sensei_lesson_status entry
1568
+	 * @param integer $lesson lesson_id or sensei_lesson_status entry
1566 1569
 	 * @param int $user_id
1567 1570
 	 * @return boolean
1568 1571
 	 */
@@ -1660,7 +1663,7 @@  discard block
 block discarded – undo
1660 1663
 	 * @since 1.7.0
1661 1664
 	 * @param int $lesson_id
1662 1665
 	 * @param int $user_id
1663
-	 * @return object | bool
1666
+	 * @return integer | bool
1664 1667
 	 */
1665 1668
 	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1666 1669
 
@@ -1719,11 +1722,11 @@  discard block
 block discarded – undo
1719 1722
 	 * @since  1.7.0
1720 1723
      *
1721 1724
 	 * @param int|string $user_id
1722
-	 * @param int|string $lesson_id
1725
+	 * @param integer $lesson_id
1723 1726
 	 * @param string $status
1724 1727
 	 * @param array $metadata
1725 1728
      *
1726
-	 * @return mixed false or comment_ID
1729
+	 * @return boolean false or comment_ID
1727 1730
 	 */
1728 1731
 	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1729 1732
 		$comment_id = false;
@@ -1761,7 +1764,7 @@  discard block
 block discarded – undo
1761 1764
 	 * @param int $course_id
1762 1765
 	 * @param string $status
1763 1766
 	 * @param array $metadata
1764
-	 * @return mixed false or comment_ID
1767
+	 * @return boolean false or comment_ID
1765 1768
 	 */
1766 1769
 	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1767 1770
 		$comment_id = false;
@@ -1951,7 +1954,7 @@  discard block
 block discarded – undo
1951 1954
      *
1952 1955
      * @since 1.7.4
1953 1956
      *
1954
-     * @param $data_key
1957
+     * @param string $data_key
1955 1958
      * @param $post_id
1956 1959
      * @param int $user_id
1957 1960
      *
Please login to merge, or discard this patch.
Indentation   +492 added lines, -492 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 
27 27
 	/**
28 28
 	 * Check if WooCommerce is present.
29
-     *
30
-     * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present()
29
+	 *
30
+	 * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_present()
31 31
 	 * @access public
32 32
 	 * @since  1.0.2
33 33
 	 * @static
@@ -35,14 +35,14 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
 	public static function sensei_is_woocommerce_present () {
37 37
 
38
-        return Sensei_WC::is_woocommerce_present();
38
+		return Sensei_WC::is_woocommerce_present();
39 39
 
40 40
 	} // End sensei_is_woocommerce_present()
41 41
 
42 42
 	/**
43 43
 	 * Check if WooCommerce is active.
44
-     *
45
-     * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active
44
+	 *
45
+	 * @deprecated since 1.9.0 use Sensei_WC::is_woocommerce_active
46 46
 	 * @access public
47 47
 	 * @since  1.0.2
48 48
 	 * @static
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
 			add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
188 188
 		}
189 189
 
190
-        //Get the comments
191
-        /**
192
-         * This filter runs inside Sensei_Utils::sensei_check_for_activity
193
-         *
194
-         * It runs while getting the comments for the given request.
195
-         *
196
-         * @param int|array $comments
197
-         */
198
-        $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
190
+		//Get the comments
191
+		/**
192
+		 * This filter runs inside Sensei_Utils::sensei_check_for_activity
193
+		 *
194
+		 * It runs while getting the comments for the given request.
195
+		 *
196
+		 * @param int|array $comments
197
+		 */
198
+		$comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
199 199
 
200 200
 		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
201 201
 		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
@@ -280,18 +280,18 @@  discard block
 block discarded – undo
280 280
 		return $dataset_changes;
281 281
 	} // End sensei_delete_activities()
282 282
 
283
-    /**
284
-     * Delete all activity for specified user
285
-     * @access public
283
+	/**
284
+	 * Delete all activity for specified user
285
+	 * @access public
286 286
 	 * @since  1.5.0
287
-     * @param  integer $user_id User ID
288
-     * @return boolean
289
-     */
290
-    public static function delete_all_user_activity( $user_id = 0 ) {
287
+	 * @param  integer $user_id User ID
288
+	 * @return boolean
289
+	 */
290
+	public static function delete_all_user_activity( $user_id = 0 ) {
291 291
 
292
-    	$dataset_changes = false;
292
+		$dataset_changes = false;
293 293
 
294
-    	if( $user_id ) {
294
+		if( $user_id ) {
295 295
 
296 296
 			$activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true );
297 297
 
@@ -336,35 +336,35 @@  discard block
 block discarded – undo
336 336
 		return $activity_value;
337 337
 	} // End sensei_get_activity_value()
338 338
 
339
-    /**
340
-     * Checks if a user (by email) has bought an item.
341
-     *
342
-     * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id)
343
-     * @access public
344
-     * @since  1.0.0
345
-     * @param  string $customer_email
346
-     * @param  int $user_id
347
-     * @param  int $product_id
348
-     * @return bool
349
-     */
350
-    public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
339
+	/**
340
+	 * Checks if a user (by email) has bought an item.
341
+	 *
342
+	 * @deprecated since 1.9.0 use Sensei_WC::has_customer_bought_product($user_id, $product_id)
343
+	 * @access public
344
+	 * @since  1.0.0
345
+	 * @param  string $customer_email
346
+	 * @param  int $user_id
347
+	 * @param  int $product_id
348
+	 * @return bool
349
+	 */
350
+	public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
351 351
 
352
-        $emails = array();
352
+		$emails = array();
353 353
 
354
-        if ( $user_id ) {
355
-            $user = get_user_by( 'id', intval( $user_id ) );
356
-            $emails[] = $user->user_email;
357
-        }
354
+		if ( $user_id ) {
355
+			$user = get_user_by( 'id', intval( $user_id ) );
356
+			$emails[] = $user->user_email;
357
+		}
358 358
 
359
-        if ( is_email( $customer_email ) )
360
-            $emails[] = $customer_email;
359
+		if ( is_email( $customer_email ) )
360
+			$emails[] = $customer_email;
361 361
 
362
-        if ( sizeof( $emails ) == 0 )
363
-            return false;
362
+		if ( sizeof( $emails ) == 0 )
363
+			return false;
364 364
 
365
-        return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
365
+		return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
366 366
 
367
-    } // End sensei_customer_bought_product()
367
+	} // End sensei_customer_bought_product()
368 368
 
369 369
 	/**
370 370
 	 * Load the WordPress rich text editor
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	/**
401 401
 	 * Save quiz answers submitted by users
402 402
 	 * @param  array $submitted User's quiz answers
403
-     * @param int $user_id
403
+	 * @param int $user_id
404 404
 	 * @return boolean            Whether the answers were saved or not
405 405
 	 */
406 406
 	public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) {
@@ -468,72 +468,72 @@  discard block
 block discarded – undo
468 468
 
469 469
 		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
470 470
 
471
-        /**
472
-         * Filter the data array for the Sensei wp_handle_upload function call
473
-         *
474
-         * This filter was mainly added for Unit Testing purposes.
475
-         *
476
-         * @since 1.7.4
477
-         *
478
-         * @param array  $file_upload_args {
479
-         *      array of current values
480
-         *
481
-         *     @type string test_form set to false by default
482
-         * }
483
-         */
484
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
485
-
486
-        $file_return = wp_handle_upload( $file, $file_upload_args );
487
-
488
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
489
-            return false;
490
-        } else {
471
+		/**
472
+		 * Filter the data array for the Sensei wp_handle_upload function call
473
+		 *
474
+		 * This filter was mainly added for Unit Testing purposes.
475
+		 *
476
+		 * @since 1.7.4
477
+		 *
478
+		 * @param array  $file_upload_args {
479
+		 *      array of current values
480
+		 *
481
+		 *     @type string test_form set to false by default
482
+		 * }
483
+		 */
484
+		$file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
485
+
486
+		$file_return = wp_handle_upload( $file, $file_upload_args );
487
+
488
+		if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
489
+			return false;
490
+		} else {
491 491
 
492
-            $filename = $file_return['file'];
492
+			$filename = $file_return['file'];
493 493
 
494
-            $attachment = array(
495
-                'post_mime_type' => $file_return['type'],
496
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
497
-                'post_content' => '',
498
-                'post_status' => 'inherit',
499
-                'guid' => $file_return['url']
500
-            );
494
+			$attachment = array(
495
+				'post_mime_type' => $file_return['type'],
496
+				'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
497
+				'post_content' => '',
498
+				'post_status' => 'inherit',
499
+				'guid' => $file_return['url']
500
+			);
501 501
 
502
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
502
+			$attachment_id = wp_insert_attachment( $attachment, $filename );
503 503
 
504
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
505
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
506
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
504
+			require_once(ABSPATH . 'wp-admin/includes/image.php');
505
+			$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
506
+			wp_update_attachment_metadata( $attachment_id, $attachment_data );
507 507
 
508
-            if( 0 < intval( $attachment_id ) ) {
509
-            	return $attachment_id;
510
-            }
511
-        }
508
+			if( 0 < intval( $attachment_id ) ) {
509
+				return $attachment_id;
510
+			}
511
+		}
512 512
 
513
-        return false;
513
+		return false;
514 514
 	}
515 515
 
516 516
 	/**
517 517
 	 * Grade quiz automatically
518
-     *
519
-     * This function grades each question automatically if the are auto gradable.
520
-     * It store all question grades.
521
-     *
522
-     * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead
523
-     *
518
+	 *
519
+	 * This function grades each question automatically if the are auto gradable.
520
+	 * It store all question grades.
521
+	 *
522
+	 * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead
523
+	 *
524 524
 	 * @param  integer $quiz_id         ID of quiz
525 525
 	 * @param  array $submitted questions id ans answers {
526
-     *          @type int $question_id
527
-     *          @type mixed $answer
528
-     * }
526
+	 *          @type int $question_id
527
+	 *          @type mixed $answer
528
+	 * }
529 529
 	 * @param  integer $total_questions Total questions in quiz (not used)
530
-     * @param string $quiz_grade_type Optional defaults to auto
531
-     *
530
+	 * @param string $quiz_grade_type Optional defaults to auto
531
+	 *
532 532
 	 * @return int $quiz_grade total sum of all question grades
533 533
 	 */
534 534
 	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
535 535
 
536
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
536
+		return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
537 537
 
538 538
 	} // End sensei_grade_quiz_auto()
539 539
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 	 * @param  integer $quiz_id ID of quiz
543 543
 	 * @param  integer $grade   Grade received
544 544
 	 * @param  integer $user_id ID of user being graded
545
-     * @param  string $quiz_grade_type default 'auto'
545
+	 * @param  string $quiz_grade_type default 'auto'
546 546
 	 * @return boolean
547 547
 	 */
548 548
 	public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) {
@@ -566,21 +566,21 @@  discard block
 block discarded – undo
566 566
 
567 567
 	/**
568 568
 	 * Grade question automatically
569
-     *
570
-     * This function checks the question typ and then grades it accordingly.
571
-     *
572
-     * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead
573
-     *
569
+	 *
570
+	 * This function checks the question typ and then grades it accordingly.
571
+	 *
572
+	 * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead
573
+	 *
574 574
 	 * @param integer $question_id
575
-     * @param string $question_type of the standard Sensei question types
575
+	 * @param string $question_type of the standard Sensei question types
576 576
 	 * @param string $answer
577
-     * @param int $user_id
578
-     *
577
+	 * @param int $user_id
578
+	 *
579 579
 	 * @return int $question_grade
580 580
 	 */
581 581
 	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
582 582
 
583
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
583
+	   return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
584 584
 
585 585
 	} // end sensei_grade_question_auto
586 586
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 	 * Grade question
589 589
 	 * @param  integer $question_id ID of question
590 590
 	 * @param  integer $grade       Grade received
591
-     * @param int $user_id
591
+	 * @param int $user_id
592 592
 	 * @return boolean
593 593
 	 */
594 594
 	public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) {
@@ -627,35 +627,35 @@  discard block
 block discarded – undo
627 627
 	}
628 628
 
629 629
 
630
-    /**
631
-     * Alias to Woothemes_Sensei_Utils::sensei_start_lesson
632
-     *
633
-     * @since 1.7.4
634
-     *
635
-     * @param integer $user_id
636
-     * @param integer $lesson_id
637
-     * @param bool $complete
638
-     *
639
-     * @return mixed boolean or comment_ID
640
-     */
641
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
630
+	/**
631
+	 * Alias to Woothemes_Sensei_Utils::sensei_start_lesson
632
+	 *
633
+	 * @since 1.7.4
634
+	 *
635
+	 * @param integer $user_id
636
+	 * @param integer $lesson_id
637
+	 * @param bool $complete
638
+	 *
639
+	 * @return mixed boolean or comment_ID
640
+	 */
641
+	public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
642 642
 
643
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
643
+		return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
644 644
 
645
-    }// end user_start_lesson()
645
+	}// end user_start_lesson()
646 646
 
647 647
 	/**
648 648
 	 * Mark a lesson as started for user
649
-     *
650
-     * Will also start the lesson course for the user if the user hans't started taking it already.
651
-     *
652
-     * @since 1.6.0
653
-     *
649
+	 *
650
+	 * Will also start the lesson course for the user if the user hans't started taking it already.
651
+	 *
652
+	 * @since 1.6.0
653
+	 *
654 654
 	 * @param  integer $lesson_id ID of lesson
655 655
 	 * @param int| string $user_id default 0
656
-     * @param bool $complete default false
657
-     *
658
-     * @return mixed boolean or comment_ID
656
+	 * @param bool $complete default false
657
+	 *
658
+	 * @return mixed boolean or comment_ID
659 659
 	 */
660 660
 	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
661 661
 
@@ -701,21 +701,21 @@  discard block
 block discarded – undo
701 701
 				$metadata['start'] = current_time('mysql');
702 702
 				$activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
703 703
 
704
-            } else {
704
+			} else {
705 705
 
706
-                // if users is already taking the lesson  and the status changes to complete update it
707
-                $current_user_activity = get_comment($activity_logged);
708
-                if( $status=='complete' &&
709
-                    $status != $current_user_activity->comment_approved  ){
706
+				// if users is already taking the lesson  and the status changes to complete update it
707
+				$current_user_activity = get_comment($activity_logged);
708
+				if( $status=='complete' &&
709
+					$status != $current_user_activity->comment_approved  ){
710 710
 
711
-                    $comment = array();
712
-                    $comment['comment_ID'] = $activity_logged;
713
-                    $comment['comment_approved'] = $status;
714
-                    wp_update_comment( $comment );
711
+					$comment = array();
712
+					$comment['comment_ID'] = $activity_logged;
713
+					$comment['comment_approved'] = $status;
714
+					wp_update_comment( $comment );
715 715
 
716
-                }
716
+				}
717 717
 
718
-            }
718
+			}
719 719
 
720 720
 			if ( $complete ) {
721 721
 				// Run this *after* the lesson status has been created/updated
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
 	/**
862 862
 	 * Returns the answer_notes for a specific question and user, or sensei_user_answer entry
863 863
 	 *
864
-     * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead
864
+	 * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead
865 865
 	 * @param mixed $question
866 866
 	 * @param int $user_id
867 867
 	 * @return string
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
 	 * Add answer notes to question
922 922
 	 * @param  integer $question_id ID of question
923 923
 	 * @param  integer $user_id     ID of user
924
-     * @param string $notes
924
+	 * @param string $notes
925 925
 	 * @return boolean
926 926
 	 */
927 927
 	public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) {
@@ -979,17 +979,17 @@  discard block
 block discarded – undo
979 979
 	 * @return void
980 980
 	 */
981 981
 	public static function sort_array_by_key( $array, $key ) {
982
-	    $sorter = array();
983
-	    $ret = array();
984
-	    reset( $array );
985
-	    foreach ( $array as $ii => $va ) {
986
-	        $sorter[$ii] = $va[$key];
987
-	    } // End For Loop
988
-	    asort( $sorter );
989
-	    foreach ( $sorter as $ii => $va ) {
990
-	        $ret[$ii] = $array[$ii];
991
-	    } // End For Loop
992
-	    $array = $ret;
982
+		$sorter = array();
983
+		$ret = array();
984
+		reset( $array );
985
+		foreach ( $array as $ii => $va ) {
986
+			$sorter[$ii] = $va[$key];
987
+		} // End For Loop
988
+		asort( $sorter );
989
+		foreach ( $sorter as $ii => $va ) {
990
+			$ret[$ii] = $array[$ii];
991
+		} // End For Loop
992
+		$array = $ret;
993 993
 	} // End sort_array_by_key()
994 994
 
995 995
 	/**
@@ -1002,21 +1002,21 @@  discard block
 block discarded – undo
1002 1002
 		$questions_array = array();
1003 1003
 		if ( 0 < $quiz_id ) {
1004 1004
 			$question_args = array( 'post_type'         => 'question',
1005
-                                    'posts_per_page'       => -1,
1006
-                                    'orderby'           => 'ID',
1007
-                                    'order'             => 'ASC',
1008
-                                    'meta_query'		=> array(
1005
+									'posts_per_page'       => -1,
1006
+									'orderby'           => 'ID',
1007
+									'order'             => 'ASC',
1008
+									'meta_query'		=> array(
1009 1009
 										array(
1010 1010
 											'key'       => '_quiz_id',
1011 1011
 											'value'     => $quiz_id,
1012 1012
 										)
1013 1013
 									),
1014
-                                    'post_status'       => 'any',
1015
-                                    'suppress_filters'  => 0
1016
-                                );
1017
-            $questions_array = get_posts( $question_args );
1018
-        } // End If Statement
1019
-        return $questions_array;
1014
+									'post_status'       => 'any',
1015
+									'suppress_filters'  => 0
1016
+								);
1017
+			$questions_array = get_posts( $question_args );
1018
+		} // End If Statement
1019
+		return $questions_array;
1020 1020
 	} // End lesson_quiz_questions()
1021 1021
 
1022 1022
 	/**
@@ -1174,7 +1174,7 @@  discard block
 block discarded – undo
1174 1174
 	 * Set the status message displayed to the user for a quiz
1175 1175
 	 * @param  integer $lesson_id ID of quiz lesson
1176 1176
 	 * @param  integer $user_id   ID of user
1177
-     * @param  bool $is_lesson
1177
+	 * @param  bool $is_lesson
1178 1178
 	 * @return array              Status code and message
1179 1179
 	 */
1180 1180
 	public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
@@ -1257,20 +1257,20 @@  discard block
 block discarded – undo
1257 1257
 					}
1258 1258
 				}
1259 1259
 
1260
-                // add next lesson button
1261
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1262
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1260
+				// add next lesson button
1261
+				$nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1262
+				$next_lesson_id = absint( $nav_id_array['next_lesson'] );
1263 1263
 
1264
-                // Output HTML
1265
-                if ( ( 0 < $next_lesson_id ) ) {
1266
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1267
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1268
-                                .'</a>';
1264
+				// Output HTML
1265
+				if ( ( 0 < $next_lesson_id ) ) {
1266
+					$message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1267
+								. '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1268
+								.'</a>';
1269 1269
 
1270
-                }
1270
+				}
1271 1271
 
1272 1272
 			}
1273
-            // Lesson/Quiz not complete
1273
+			// Lesson/Quiz not complete
1274 1274
 			else {
1275 1275
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1276 1276
 				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1311 1311
 
1312 1312
 		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1313
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1313
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1314 1314
 			$extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' .  __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' .  __( 'View the lesson quiz', 'woothemes-sensei' )  . '</a></p>';
1315 1315
 		}
1316 1316
 
@@ -1368,9 +1368,9 @@  discard block
 block discarded – undo
1368 1368
 				$user_id = get_current_user_id();
1369 1369
 			}
1370 1370
 
1371
-            if( ! $user_id > 0 ){
1372
-                return false;
1373
-            }
1371
+			if( ! $user_id > 0 ){
1372
+				return false;
1373
+			}
1374 1374
 
1375 1375
 			$user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) );
1376 1376
 			if( $user_course_status_id ) {
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
 	 * Check if a user has completed a course or not
1495 1495
 	 *
1496 1496
 	 * @param int | WP_Post | WP_Comment $course course_id or sensei_course_status entry
1497
-     *
1497
+	 *
1498 1498
 	 * @param int $user_id
1499 1499
 	 * @return boolean
1500 1500
 	 */
@@ -1512,14 +1512,14 @@  discard block
 block discarded – undo
1512 1512
 					$user_id = get_current_user_id();
1513 1513
 				}
1514 1514
 
1515
-                if( is_a( $course, 'WP_Post' ) ){
1516
-                    $course =   $course->ID;
1517
-                }
1515
+				if( is_a( $course, 'WP_Post' ) ){
1516
+					$course =   $course->ID;
1517
+				}
1518 1518
 
1519 1519
 				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1520 1520
 				if( isset( $user_course_status->comment_approved ) ){
1521
-                    $user_course_status = $user_course_status->comment_approved;
1522
-                }
1521
+					$user_course_status = $user_course_status->comment_approved;
1522
+				}
1523 1523
 
1524 1524
 			}
1525 1525
 			if( $user_course_status && 'complete' == $user_course_status ) {
@@ -1544,11 +1544,11 @@  discard block
 block discarded – undo
1544 1544
 				$user_id = get_current_user_id();
1545 1545
 			}
1546 1546
 
1547
-            $activity_args = array(
1548
-                'post_id' => $lesson_id,
1549
-                'user_id' => $user_id,
1550
-                'type' => 'sensei_lesson_status',
1551
-                'field' => 'comment_ID' );
1547
+			$activity_args = array(
1548
+				'post_id' => $lesson_id,
1549
+				'user_id' => $user_id,
1550
+				'type' => 'sensei_lesson_status',
1551
+				'field' => 'comment_ID' );
1552 1552
 
1553 1553
 			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1554 1554
 			if( $user_lesson_status_id ) {
@@ -1561,7 +1561,7 @@  discard block
 block discarded – undo
1561 1561
 	/**
1562 1562
 	 * Check if a user has completed a lesson or not
1563 1563
 	 *
1564
-     * @uses  Sensei()
1564
+	 * @uses  Sensei()
1565 1565
 	 * @param mixed $lesson lesson_id or sensei_lesson_status entry
1566 1566
 	 * @param int $user_id
1567 1567
 	 * @return boolean
@@ -1582,10 +1582,10 @@  discard block
 block discarded – undo
1582 1582
 					$user_id = get_current_user_id();
1583 1583
 				}
1584 1584
 
1585
-                // the user is not logged in
1586
-                if( ! $user_id > 0 ){
1587
-                    return false;
1588
-                }
1585
+				// the user is not logged in
1586
+				if( ! $user_id > 0 ){
1587
+					return false;
1588
+				}
1589 1589
 				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1590 1590
 
1591 1591
 				if ( $_user_lesson_status ) {
@@ -1664,9 +1664,9 @@  discard block
 block discarded – undo
1664 1664
 	 */
1665 1665
 	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1666 1666
 
1667
-        if( ! $user_id ) {
1668
-            $user_id = get_current_user_id();
1669
-        }
1667
+		if( ! $user_id ) {
1668
+			$user_id = get_current_user_id();
1669
+		}
1670 1670
 
1671 1671
 		if( $lesson_id > 0 && $user_id > 0 ) {
1672 1672
 
@@ -1717,12 +1717,12 @@  discard block
 block discarded – undo
1717 1717
 	 * Sets the status for the lesson
1718 1718
 	 *
1719 1719
 	 * @since  1.7.0
1720
-     *
1720
+	 *
1721 1721
 	 * @param int|string $user_id
1722 1722
 	 * @param int|string $lesson_id
1723 1723
 	 * @param string $status
1724 1724
 	 * @param array $metadata
1725
-     *
1725
+	 *
1726 1726
 	 * @return mixed false or comment_ID
1727 1727
 	 */
1728 1728
 	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
@@ -1838,7 +1838,7 @@  discard block
 block discarded – undo
1838 1838
 	/**
1839 1839
 	 * Adjust the comment query to be faster on the database, used by Analysis admin
1840 1840
 	 * @since  1.7.0
1841
-     * @param array $pieces
1841
+	 * @param array $pieces
1842 1842
 	 * @return array $pieces
1843 1843
 	 */
1844 1844
 	public static function comment_total_sum_meta_value_filter( $pieces ) {
@@ -1873,360 +1873,360 @@  discard block
 block discarded – undo
1873 1873
 		return $pieces;
1874 1874
 	}
1875 1875
 
1876
-    /**
1877
-     *
1878
-     * Alias to Woothemes_Sensei_Utils::update_user_data
1879
-     * @since 1.7.4
1880
-     *
1881
-     * @param string $data_key maximum 39 characters allowed
1882
-     * @param int $post_id
1883
-     * @param mixed $value
1884
-     * @param int $user_id
1885
-     *
1886
-     * @return bool $success
1887
-     */
1888
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1889
-
1890
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1891
-
1892
-    }// end add_user_data
1893
-
1894
-    /**
1895
-     * add user specific data to the passed in sensei post type id
1896
-     *
1897
-     * This function saves comment meta on the users current status. If no status is available
1898
-     * status will be created. It only operates on the available sensei Post types: course, lesson, quiz.
1899
-     *
1900
-     * @since 1.7.4
1901
-     *
1902
-     * @param string $data_key maximum 39 characters allowed
1903
-     * @param int $post_id
1904
-     * @param mixed $value
1905
-     * @param int $user_id
1906
-     *
1907
-     * @return bool $success
1908
-     */
1909
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1910
-
1911
-        if( ! ( $user_id > 0 ) ){
1912
-            $user_id = get_current_user_id();
1913
-        }
1914
-
1915
-        $supported_post_types = array( 'course', 'lesson' );
1916
-        $post_type = get_post_type( $post_id );
1917
-        if( empty( $post_id ) || empty( $data_key )
1918
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1919
-            || !get_userdata( $user_id )
1920
-            || ! in_array( $post_type, $supported_post_types )  ){
1921
-
1922
-            return false;
1923
-        }
1924
-
1925
-        // check if there and existing Sensei status on this post type if not create it
1926
-        // and get the  activity ID
1927
-        $status_function = 'user_'.$post_type.'_status';
1928
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1929
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1930
-
1931
-            $start_function = 'user_start_'.$post_type;
1932
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1933
-
1934
-        }else{
1935
-
1936
-            $sensei_user_activity_id = $sensei_user_status->comment_ID;
1937
-
1938
-        }
1939
-
1940
-        // store the data
1941
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1942
-
1943
-       return $success;
1944
-
1945
-    }//update_user_data
1946
-
1947
-    /**
1948
-     * Get the user data stored on the passed in post type
1949
-     *
1950
-     * This function gets the comment meta on the lesson or course status
1951
-     *
1952
-     * @since 1.7.4
1953
-     *
1954
-     * @param $data_key
1955
-     * @param $post_id
1956
-     * @param int $user_id
1957
-     *
1958
-     * @return mixed $user_data_value
1959
-     */
1960
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1961
-
1962
-        $user_data_value = true;
1963
-
1964
-        if( ! ( $user_id > 0 ) ){
1965
-            $user_id = get_current_user_id();
1966
-        }
1967
-
1968
-        $supported_post_types = array( 'course', 'lesson' );
1969
-        $post_type = get_post_type( $post_id );
1970
-        if( empty( $post_id ) || empty( $data_key )
1971
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1972
-            || ! get_userdata( $user_id )
1973
-            || !in_array( $post_type, $supported_post_types )  ){
1974
-
1975
-            return false;
1976
-        }
1977
-
1978
-        // check if there and existing Sensei status on this post type if not create it
1979
-        // and get the  activity ID
1980
-        $status_function = 'user_'.$post_type.'_status';
1981
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1982
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1983
-            return false;
1984
-        }
1985
-
1986
-        $sensei_user_activity_id = $sensei_user_status->comment_ID;
1987
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
1988
-
1989
-        return $user_data_value;
1990
-
1991
-    }// end get_user_data
1992
-
1993
-    /**
1994
-     * Delete the Sensei user data for the given key, Sensei post type and user combination.
1995
-     *
1996
-     * @param int $data_key
1997
-     * @param int $post_id
1998
-     * @param int $user_id
1999
-     *
2000
-     * @return bool $deleted
2001
-     */
2002
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2003
-        $deleted = true;
1876
+	/**
1877
+	 *
1878
+	 * Alias to Woothemes_Sensei_Utils::update_user_data
1879
+	 * @since 1.7.4
1880
+	 *
1881
+	 * @param string $data_key maximum 39 characters allowed
1882
+	 * @param int $post_id
1883
+	 * @param mixed $value
1884
+	 * @param int $user_id
1885
+	 *
1886
+	 * @return bool $success
1887
+	 */
1888
+	public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1889
+
1890
+		return self::update_user_data( $data_key, $post_id, $value , $user_id );
1891
+
1892
+	}// end add_user_data
1893
+
1894
+	/**
1895
+	 * add user specific data to the passed in sensei post type id
1896
+	 *
1897
+	 * This function saves comment meta on the users current status. If no status is available
1898
+	 * status will be created. It only operates on the available sensei Post types: course, lesson, quiz.
1899
+	 *
1900
+	 * @since 1.7.4
1901
+	 *
1902
+	 * @param string $data_key maximum 39 characters allowed
1903
+	 * @param int $post_id
1904
+	 * @param mixed $value
1905
+	 * @param int $user_id
1906
+	 *
1907
+	 * @return bool $success
1908
+	 */
1909
+	public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1910
+
1911
+		if( ! ( $user_id > 0 ) ){
1912
+			$user_id = get_current_user_id();
1913
+		}
1914
+
1915
+		$supported_post_types = array( 'course', 'lesson' );
1916
+		$post_type = get_post_type( $post_id );
1917
+		if( empty( $post_id ) || empty( $data_key )
1918
+			|| ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1919
+			|| !get_userdata( $user_id )
1920
+			|| ! in_array( $post_type, $supported_post_types )  ){
1921
+
1922
+			return false;
1923
+		}
1924
+
1925
+		// check if there and existing Sensei status on this post type if not create it
1926
+		// and get the  activity ID
1927
+		$status_function = 'user_'.$post_type.'_status';
1928
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
1929
+		if( ! isset( $sensei_user_status->comment_ID ) ){
1930
+
1931
+			$start_function = 'user_start_'.$post_type;
1932
+			$sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1933
+
1934
+		}else{
1935
+
1936
+			$sensei_user_activity_id = $sensei_user_status->comment_ID;
1937
+
1938
+		}
1939
+
1940
+		// store the data
1941
+		$success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1942
+
1943
+	   return $success;
1944
+
1945
+	}//update_user_data
1946
+
1947
+	/**
1948
+	 * Get the user data stored on the passed in post type
1949
+	 *
1950
+	 * This function gets the comment meta on the lesson or course status
1951
+	 *
1952
+	 * @since 1.7.4
1953
+	 *
1954
+	 * @param $data_key
1955
+	 * @param $post_id
1956
+	 * @param int $user_id
1957
+	 *
1958
+	 * @return mixed $user_data_value
1959
+	 */
1960
+	public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1961
+
1962
+		$user_data_value = true;
1963
+
1964
+		if( ! ( $user_id > 0 ) ){
1965
+			$user_id = get_current_user_id();
1966
+		}
1967
+
1968
+		$supported_post_types = array( 'course', 'lesson' );
1969
+		$post_type = get_post_type( $post_id );
1970
+		if( empty( $post_id ) || empty( $data_key )
1971
+			|| ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1972
+			|| ! get_userdata( $user_id )
1973
+			|| !in_array( $post_type, $supported_post_types )  ){
2004 1974
 
2005
-        if( ! ( $user_id > 0 ) ){
2006
-            $user_id = get_current_user_id();
2007
-        }
1975
+			return false;
1976
+		}
2008 1977
 
2009
-        $supported_post_types = array( 'course', 'lesson' );
2010
-        $post_type = get_post_type( $post_id );
2011
-        if( empty( $post_id ) || empty( $data_key )
2012
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2013
-            || ! get_userdata( $user_id )
2014
-            || !in_array( $post_type, $supported_post_types )  ){
1978
+		// check if there and existing Sensei status on this post type if not create it
1979
+		// and get the  activity ID
1980
+		$status_function = 'user_'.$post_type.'_status';
1981
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
1982
+		if( ! isset( $sensei_user_status->comment_ID ) ){
1983
+			return false;
1984
+		}
2015 1985
 
2016
-            return false;
2017
-        }
1986
+		$sensei_user_activity_id = $sensei_user_status->comment_ID;
1987
+		$user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
1988
+
1989
+		return $user_data_value;
1990
+
1991
+	}// end get_user_data
1992
+
1993
+	/**
1994
+	 * Delete the Sensei user data for the given key, Sensei post type and user combination.
1995
+	 *
1996
+	 * @param int $data_key
1997
+	 * @param int $post_id
1998
+	 * @param int $user_id
1999
+	 *
2000
+	 * @return bool $deleted
2001
+	 */
2002
+	public static function delete_user_data( $data_key, $post_id , $user_id ){
2003
+		$deleted = true;
2004
+
2005
+		if( ! ( $user_id > 0 ) ){
2006
+			$user_id = get_current_user_id();
2007
+		}
2008
+
2009
+		$supported_post_types = array( 'course', 'lesson' );
2010
+		$post_type = get_post_type( $post_id );
2011
+		if( empty( $post_id ) || empty( $data_key )
2012
+			|| ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2013
+			|| ! get_userdata( $user_id )
2014
+			|| !in_array( $post_type, $supported_post_types )  ){
2015
+
2016
+			return false;
2017
+		}
2018 2018
 
2019
-        // check if there and existing Sensei status on this post type if not create it
2020
-        // and get the  activity ID
2021
-        $status_function = 'user_'.$post_type.'_status';
2022
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2023
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2024
-            return false;
2025
-        }
2019
+		// check if there and existing Sensei status on this post type if not create it
2020
+		// and get the  activity ID
2021
+		$status_function = 'user_'.$post_type.'_status';
2022
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
2023
+		if( ! isset( $sensei_user_status->comment_ID ) ){
2024
+			return false;
2025
+		}
2026 2026
 
2027
-        $sensei_user_activity_id = $sensei_user_status->comment_ID;
2028
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2027
+		$sensei_user_activity_id = $sensei_user_status->comment_ID;
2028
+		$deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2029 2029
 
2030
-        return $deleted;
2030
+		return $deleted;
2031 2031
 
2032
-    }// end delete_user_data
2032
+	}// end delete_user_data
2033 2033
 
2034 2034
 
2035
-    /**
2036
-     * The function creates a drop down. Never write up a Sensei select statement again.
2037
-     *
2038
-     * @since 1.8.0
2039
-     *
2040
-     * @param string $selected_value
2041
-     * @param $options{
2042
-     *    @type string $value the value saved in the database
2043
-     *    @type string $option what the user will see in the list of items
2044
-     * }
2045
-     * @param array $attributes{
2046
-     *   @type string $attribute  type such name or id etc.
2047
-     *  @type string $value
2048
-     * }
2049
-     * @param bool $enable_none_option
2050
-     *
2051
-     * @return string $drop_down_element
2052
-     */
2053
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2035
+	/**
2036
+	 * The function creates a drop down. Never write up a Sensei select statement again.
2037
+	 *
2038
+	 * @since 1.8.0
2039
+	 *
2040
+	 * @param string $selected_value
2041
+	 * @param $options{
2042
+	 *    @type string $value the value saved in the database
2043
+	 *    @type string $option what the user will see in the list of items
2044
+	 * }
2045
+	 * @param array $attributes{
2046
+	 *   @type string $attribute  type such name or id etc.
2047
+	 *  @type string $value
2048
+	 * }
2049
+	 * @param bool $enable_none_option
2050
+	 *
2051
+	 * @return string $drop_down_element
2052
+	 */
2053
+	public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2054 2054
 
2055
-        $drop_down_element = '';
2055
+		$drop_down_element = '';
2056 2056
 
2057
-        // setup the basic attributes
2058
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2057
+		// setup the basic attributes
2058
+		if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2059 2059
 
2060
-            $attributes['name'] = 'sensei-options';
2060
+			$attributes['name'] = 'sensei-options';
2061 2061
 
2062
-        }
2062
+		}
2063 2063
 
2064
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2064
+		if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2065 2065
 
2066
-            $attributes['id'] = 'sensei-options';
2066
+			$attributes['id'] = 'sensei-options';
2067 2067
 
2068
-        }
2068
+		}
2069 2069
 
2070
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2070
+		if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2071 2071
 
2072
-            $attributes['class'] ='chosen_select widefat';
2072
+			$attributes['class'] ='chosen_select widefat';
2073 2073
 
2074
-        }
2074
+		}
2075 2075
 
2076
-        // create element attributes
2077
-        $combined_attributes = '';
2078
-        foreach( $attributes as $attribute => $value ){
2076
+		// create element attributes
2077
+		$combined_attributes = '';
2078
+		foreach( $attributes as $attribute => $value ){
2079 2079
 
2080
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2080
+			$combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2081 2081
 
2082
-        }// end for each
2082
+		}// end for each
2083 2083
 
2084 2084
 
2085
-        // create the select element
2086
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2085
+		// create the select element
2086
+		$drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2087 2087
 
2088
-        // show the none option if the client requested
2089
-        if( $enable_none_option ) {
2090
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2091
-        }
2088
+		// show the none option if the client requested
2089
+		if( $enable_none_option ) {
2090
+			$drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2091
+		}
2092 2092
 
2093
-        if ( count( $options ) > 0 ) {
2093
+		if ( count( $options ) > 0 ) {
2094 2094
 
2095
-            foreach ($options as $value => $option ){
2095
+			foreach ($options as $value => $option ){
2096 2096
 
2097
-                $element = '';
2098
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2099
-                $element .= selected( $value, $selected_value, false ) . '>';
2100
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2097
+				$element = '';
2098
+				$element.= '<option value="' . esc_attr( $value ) . '"';
2099
+				$element .= selected( $value, $selected_value, false ) . '>';
2100
+				$element .= esc_html(  $option ) . '</option>' . "\n";
2101 2101
 
2102
-                // add the element to the select html
2103
-                $drop_down_element.= $element;
2104
-            } // End For Loop
2102
+				// add the element to the select html
2103
+				$drop_down_element.= $element;
2104
+			} // End For Loop
2105 2105
 
2106
-        } // End If Statement
2106
+		} // End If Statement
2107 2107
 
2108
-        $drop_down_element .= '</select>' . "\n";
2108
+		$drop_down_element .= '</select>' . "\n";
2109 2109
 
2110
-        return $drop_down_element;
2110
+		return $drop_down_element;
2111 2111
 
2112
-    }// generate_drop_down
2112
+	}// generate_drop_down
2113 2113
 
2114
-    /**
2115
-     * Wrapper for the default php round() function.
2116
-     * This allows us to give more control to a user on how they can round Sensei
2117
-     * decimals passed through this function.
2118
-     *
2119
-     * @since 1.8.5
2120
-     *
2121
-     * @param double $val
2122
-     * @param int $precision
2123
-     * @param $mode
2124
-     * @param string $context
2125
-     *
2126
-     * @return double $val
2127
-     */
2128
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2114
+	/**
2115
+	 * Wrapper for the default php round() function.
2116
+	 * This allows us to give more control to a user on how they can round Sensei
2117
+	 * decimals passed through this function.
2118
+	 *
2119
+	 * @since 1.8.5
2120
+	 *
2121
+	 * @param double $val
2122
+	 * @param int $precision
2123
+	 * @param $mode
2124
+	 * @param string $context
2125
+	 *
2126
+	 * @return double $val
2127
+	 */
2128
+	public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2129 2129
 
2130
-        /**å
2130
+		/**å
2131 2131
          * Change the precision for the Sensei_Utils::round function.
2132 2132
          * the precision given will be passed into the php round function
2133 2133
          * @since 1.8.5
2134 2134
          */
2135
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2136
-
2137
-        /**
2138
-         * Change the mode for the Sensei_Utils::round function.
2139
-         * the mode given will be passed into the php round function
2140
-         *
2141
-         * This applies only to PHP version 5.3.0 and greater
2142
-         *
2143
-         * @since 1.8.5
2144
-         */
2145
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2135
+		$precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2136
+
2137
+		/**
2138
+		 * Change the mode for the Sensei_Utils::round function.
2139
+		 * the mode given will be passed into the php round function
2140
+		 *
2141
+		 * This applies only to PHP version 5.3.0 and greater
2142
+		 *
2143
+		 * @since 1.8.5
2144
+		 */
2145
+		$mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2146 2146
 
2147
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2147
+		if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2148 2148
 
2149
-            return round( $val, $precision, $mode );
2149
+			return round( $val, $precision, $mode );
2150 2150
 
2151
-        }else{
2151
+		}else{
2152 2152
 
2153
-            return round( $val, $precision );
2153
+			return round( $val, $precision );
2154 2154
 
2155
-        }
2155
+		}
2156 2156
 
2157
-    }
2157
+	}
2158 2158
 
2159
-    /**
2160
-     * Returns the current url with all the query vars
2161
-     *
2162
-     * @since 1.9.0
2163
-     * @return string $url
2164
-     */
2165
-    public static function get_current_url(){
2159
+	/**
2160
+	 * Returns the current url with all the query vars
2161
+	 *
2162
+	 * @since 1.9.0
2163
+	 * @return string $url
2164
+	 */
2165
+	public static function get_current_url(){
2166 2166
 
2167
-        global $wp;
2168
-        $current_url = trailingslashit( home_url( $wp->request ) );
2169
-        if ( isset( $_GET ) ) {
2167
+		global $wp;
2168
+		$current_url = trailingslashit( home_url( $wp->request ) );
2169
+		if ( isset( $_GET ) ) {
2170 2170
 
2171
-            foreach ($_GET as $param => $val ) {
2171
+			foreach ($_GET as $param => $val ) {
2172 2172
 
2173
-                $current_url = add_query_arg( $param, $val , $current_url );
2173
+				$current_url = add_query_arg( $param, $val , $current_url );
2174 2174
 
2175
-            }
2176
-        }
2175
+			}
2176
+		}
2177 2177
 
2178
-        return $current_url;
2179
-    }
2178
+		return $current_url;
2179
+	}
2180 2180
 
2181
-    /**
2182
-     * Restore the global WP_Query
2183
-     *
2184
-     * @since 1.9.0
2185
-     */
2186
-    public static function restore_wp_query() {
2181
+	/**
2182
+	 * Restore the global WP_Query
2183
+	 *
2184
+	 * @since 1.9.0
2185
+	 */
2186
+	public static function restore_wp_query() {
2187 2187
 
2188
-        wp_reset_query();
2188
+		wp_reset_query();
2189 2189
 
2190
-    }
2190
+	}
2191 2191
 
2192
-    /**
2193
-     * Merge two arrays in a zip like fashion.
2194
-     * If one array is longer than the other the elements will be apended
2195
-     * to the end of the resulting array.
2196
-     *
2197
-     * @since 1.9.0
2198
-     *
2199
-     * @param array $array_a
2200
-     * @param array $array_b
2201
-     * @return array $merged_array
2202
-     */
2203
-    public static function array_zip_merge( $array_a, $array_b ){
2192
+	/**
2193
+	 * Merge two arrays in a zip like fashion.
2194
+	 * If one array is longer than the other the elements will be apended
2195
+	 * to the end of the resulting array.
2196
+	 *
2197
+	 * @since 1.9.0
2198
+	 *
2199
+	 * @param array $array_a
2200
+	 * @param array $array_b
2201
+	 * @return array $merged_array
2202
+	 */
2203
+	public static function array_zip_merge( $array_a, $array_b ){
2204 2204
 
2205
-        if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2206
-            trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2207
-        }
2205
+		if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2206
+			trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2207
+		}
2208 2208
 
2209
-        $merged_array = array();
2210
-        $total_elements = count( $array_a )  + count( $array_b );
2209
+		$merged_array = array();
2210
+		$total_elements = count( $array_a )  + count( $array_b );
2211 2211
 
2212
-        // Zip arrays
2213
-        for ( $i = 0; $i < $total_elements; $i++) {
2212
+		// Zip arrays
2213
+		for ( $i = 0; $i < $total_elements; $i++) {
2214 2214
 
2215
-            // if has an element at current index push a on top
2216
-            if( isset( $array_a[ $i ] ) ){
2217
-                $merged_array[] = $array_a[ $i ]  ;
2218
-            }
2215
+			// if has an element at current index push a on top
2216
+			if( isset( $array_a[ $i ] ) ){
2217
+				$merged_array[] = $array_a[ $i ]  ;
2218
+			}
2219 2219
 
2220
-            // next if $array_b has an element at current index push a on top of the element
2221
-            // from a if there was one, if not the element before that.
2222
-            if( isset( $array_b[ $i ] ) ){
2223
-                $merged_array[] = $array_b[ $i ]  ;
2224
-            }
2220
+			// next if $array_b has an element at current index push a on top of the element
2221
+			// from a if there was one, if not the element before that.
2222
+			if( isset( $array_b[ $i ] ) ){
2223
+				$merged_array[] = $array_b[ $i ]  ;
2224
+			}
2225 2225
 
2226
-        }
2226
+		}
2227 2227
 
2228
-        return $merged_array;
2229
-    }
2228
+		return $merged_array;
2229
+	}
2230 2230
 
2231 2231
 } // End Class
2232 2232
 
Please login to merge, or discard this patch.
Spacing   +531 added lines, -531 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Utilities Class
@@ -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,14 +321,14 @@  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
 
327 327
 		$activity_value = false;
328
-		if ( !empty($args['field']) ) {
329
-			$comment = Sensei_Utils::sensei_check_for_activity( $args, true );
328
+		if ( ! empty($args['field'])) {
329
+			$comment = Sensei_Utils::sensei_check_for_activity($args, true);
330 330
 
331
-			if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
331
+			if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
332 332
 				$activity_value = $comment->{$args['field']};
333 333
 			} // End If Statement
334 334
 		}
@@ -346,22 +346,22 @@  discard block
 block discarded – undo
346 346
      * @param  int $product_id
347 347
      * @return bool
348 348
      */
349
-    public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
349
+    public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) {
350 350
 
351 351
         $emails = array();
352 352
 
353
-        if ( $user_id ) {
354
-            $user = get_user_by( 'id', intval( $user_id ) );
353
+        if ($user_id) {
354
+            $user = get_user_by('id', intval($user_id));
355 355
             $emails[] = $user->user_email;
356 356
         }
357 357
 
358
-        if ( is_email( $customer_email ) )
358
+        if (is_email($customer_email))
359 359
             $emails[] = $customer_email;
360 360
 
361
-        if ( sizeof( $emails ) == 0 )
361
+        if (sizeof($emails) == 0)
362 362
             return false;
363 363
 
364
-        return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
364
+        return Sensei_WC::has_customer_bought_product($user_id, $product_id);
365 365
 
366 366
     } // End sensei_customer_bought_product()
367 367
 
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
 	 * @param  string $input_name Name for text area form element
373 373
 	 * @return void
374 374
 	 */
375
-	public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) {
375
+	public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') {
376 376
 
377
-		if( ! $input_name ) $input_name = $editor_id;
377
+		if ( ! $input_name) $input_name = $editor_id;
378 378
 
379 379
 		$buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext';
380 380
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			'quicktags' => false
393 393
 		);
394 394
 
395
-		wp_editor( $content, $editor_id, $settings );
395
+		wp_editor($content, $editor_id, $settings);
396 396
 
397 397
 	} // End sensei_text_editor()
398 398
 
@@ -402,57 +402,57 @@  discard block
 block discarded – undo
402 402
      * @param int $user_id
403 403
 	 * @return boolean            Whether the answers were saved or not
404 404
 	 */
405
-	public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) {
405
+	public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) {
406 406
 
407
-		if( intval( $user_id ) == 0 ) {
407
+		if (intval($user_id) == 0) {
408 408
 			$user_id = get_current_user_id();
409 409
 		}
410 410
 
411 411
 		$answers_saved = false;
412 412
 
413
-		if( $submitted && intval( $user_id ) > 0 ) {
413
+		if ($submitted && intval($user_id) > 0) {
414 414
 
415
-			foreach( $submitted as $question_id => $answer ) {
415
+			foreach ($submitted as $question_id => $answer) {
416 416
 
417 417
 				// Get question type
418
-				$question_type = Sensei()->question->get_question_type( $question_id );
418
+				$question_type = Sensei()->question->get_question_type($question_id);
419 419
 
420 420
 				// Sanitise answer
421
-				if( 0 == get_magic_quotes_gpc() ) {
422
-					$answer = wp_unslash( $answer );
421
+				if (0 == get_magic_quotes_gpc()) {
422
+					$answer = wp_unslash($answer);
423 423
 				}
424
-				switch( $question_type ) {
425
-					case 'multi-line': $answer = nl2br( $answer ); break;
424
+				switch ($question_type) {
425
+					case 'multi-line': $answer = nl2br($answer); break;
426 426
 					case 'single-line': break;
427 427
 					case 'gap-fill': break;
428
-					default: $answer = maybe_serialize( $answer ); break;
428
+					default: $answer = maybe_serialize($answer); break;
429 429
 				}
430 430
 				$args = array(
431 431
 							'post_id' => $question_id,
432
-							'data' => base64_encode( $answer ),
432
+							'data' => base64_encode($answer),
433 433
 							'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
434 434
 							'user_id' => $user_id,
435 435
 							'action' => 'update'
436 436
 						);
437
-				$answers_saved = Sensei_Utils::sensei_log_activity( $args );
437
+				$answers_saved = Sensei_Utils::sensei_log_activity($args);
438 438
 			}
439 439
 
440 440
 			// Handle file upload questions
441
-			if( isset( $_FILES ) ) {
442
-				foreach( $_FILES as $field => $file ) {
443
-					if( strpos( $field, 'file_upload_' ) !== false ) {
444
-						$question_id = str_replace( 'file_upload_', '', $field );
445
-						if( $file && $question_id ) {
446
-							$attachment_id = self::upload_file( $file );
447
-							if( $attachment_id ) {
441
+			if (isset($_FILES)) {
442
+				foreach ($_FILES as $field => $file) {
443
+					if (strpos($field, 'file_upload_') !== false) {
444
+						$question_id = str_replace('file_upload_', '', $field);
445
+						if ($file && $question_id) {
446
+							$attachment_id = self::upload_file($file);
447
+							if ($attachment_id) {
448 448
 								$args = array(
449 449
 									'post_id' => $question_id,
450
-									'data' => base64_encode( $attachment_id ),
450
+									'data' => base64_encode($attachment_id),
451 451
 									'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
452 452
 									'user_id' => $user_id,
453 453
 									'action' => 'update'
454 454
 								);
455
-								$answers_saved = Sensei_Utils::sensei_log_activity( $args );
455
+								$answers_saved = Sensei_Utils::sensei_log_activity($args);
456 456
 							}
457 457
 						}
458 458
 					}
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 
465 465
 	} // End sensei_save_quiz_answers()
466 466
 
467
-	public static function upload_file( $file = array() ) {
467
+	public static function upload_file($file = array()) {
468 468
 
469
-		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
469
+		require_once(ABSPATH.'wp-admin/includes/admin.php');
470 470
 
471 471
         /**
472 472
          * Filter the data array for the Sensei wp_handle_upload function call
@@ -481,11 +481,11 @@  discard block
 block discarded – undo
481 481
          *     @type string test_form set to false by default
482 482
          * }
483 483
          */
484
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
484
+        $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false));
485 485
 
486
-        $file_return = wp_handle_upload( $file, $file_upload_args );
486
+        $file_return = wp_handle_upload($file, $file_upload_args);
487 487
 
488
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
488
+        if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
489 489
             return false;
490 490
         } else {
491 491
 
@@ -493,19 +493,19 @@  discard block
 block discarded – undo
493 493
 
494 494
             $attachment = array(
495 495
                 'post_mime_type' => $file_return['type'],
496
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
496
+                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
497 497
                 'post_content' => '',
498 498
                 'post_status' => 'inherit',
499 499
                 'guid' => $file_return['url']
500 500
             );
501 501
 
502
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
502
+            $attachment_id = wp_insert_attachment($attachment, $filename);
503 503
 
504
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
505
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
506
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
504
+            require_once(ABSPATH.'wp-admin/includes/image.php');
505
+            $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
506
+            wp_update_attachment_metadata($attachment_id, $attachment_data);
507 507
 
508
-            if( 0 < intval( $attachment_id ) ) {
508
+            if (0 < intval($attachment_id)) {
509 509
             	return $attachment_id;
510 510
             }
511 511
         }
@@ -531,9 +531,9 @@  discard block
 block discarded – undo
531 531
      *
532 532
 	 * @return int $quiz_grade total sum of all question grades
533 533
 	 */
534
-	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
534
+	public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') {
535 535
 
536
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
536
+        return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type);
537 537
 
538 538
 	} // End sensei_grade_quiz_auto()
539 539
 
@@ -545,20 +545,20 @@  discard block
 block discarded – undo
545 545
      * @param  string $quiz_grade_type default 'auto'
546 546
 	 * @return boolean
547 547
 	 */
548
-	public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) {
549
-		if( intval( $user_id ) == 0 ) {
548
+	public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') {
549
+		if (intval($user_id) == 0) {
550 550
 			$user_id = get_current_user_id();
551 551
 		}
552 552
 
553 553
 		$activity_logged = false;
554
-		if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) {
555
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
556
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
557
-			$activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade );
554
+		if (intval($quiz_id) > 0 && intval($user_id) > 0) {
555
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
556
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
557
+			$activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade);
558 558
 
559
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
559
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
560 560
 
561
-			do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type );
561
+			do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type);
562 562
 		}
563 563
 
564 564
 		return $activity_logged;
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
      *
579 579
 	 * @return int $question_grade
580 580
 	 */
581
-	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
581
+	public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) {
582 582
 
583
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
583
+       return  WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id);
584 584
 
585 585
 	} // end sensei_grade_question_auto
586 586
 
@@ -591,20 +591,20 @@  discard block
 block discarded – undo
591 591
      * @param int $user_id
592 592
 	 * @return boolean
593 593
 	 */
594
-	public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) {
595
-		if( intval( $user_id ) == 0 ) {
594
+	public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) {
595
+		if (intval($user_id) == 0) {
596 596
 			$user_id = get_current_user_id();
597 597
 		}
598 598
 
599 599
 		$activity_logged = false;
600
-		if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) {
600
+		if (intval($question_id) > 0 && intval($user_id) > 0) {
601 601
 
602
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
603
-			$activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade );
602
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
603
+			$activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade);
604 604
 
605
-			$answer_notes = get_post_meta( $question_id, '_answer_feedback', true );
606
-			if ( !empty($answer_notes) ) {
607
-				update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) );
605
+			$answer_notes = get_post_meta($question_id, '_answer_feedback', true);
606
+			if ( ! empty($answer_notes)) {
607
+				update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes));
608 608
 			}
609 609
 
610 610
 		}
@@ -612,15 +612,15 @@  discard block
 block discarded – undo
612 612
 		return $activity_logged;
613 613
 	}
614 614
 
615
-	public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) {
616
-		if( intval( $user_id ) == 0 ) {
615
+	public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) {
616
+		if (intval($user_id) == 0) {
617 617
 			$user_id = get_current_user_id();
618 618
 		}
619 619
 
620 620
 		$activity_logged = false;
621
-		if( intval( $question_id ) > 0 ) {
622
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
623
-			$activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' );
621
+		if (intval($question_id) > 0) {
622
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
623
+			$activity_logged = delete_comment_meta($user_answer_id, 'user_grade');
624 624
 		}
625 625
 
626 626
 		return $activity_logged;
@@ -638,9 +638,9 @@  discard block
 block discarded – undo
638 638
      *
639 639
      * @return mixed boolean or comment_ID
640 640
      */
641
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
641
+    public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) {
642 642
 
643
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
643
+        return self::sensei_start_lesson($lesson_id, $user_id, $complete);
644 644
 
645 645
     }// end user_start_lesson()
646 646
 
@@ -657,22 +657,22 @@  discard block
 block discarded – undo
657 657
      *
658 658
      * @return mixed boolean or comment_ID
659 659
 	 */
660
-	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
660
+	public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) {
661 661
 
662 662
 
663
-		if( intval( $user_id ) == 0 ) {
663
+		if (intval($user_id) == 0) {
664 664
 			$user_id = get_current_user_id();
665 665
 		}
666 666
 
667 667
 		$activity_logged = false;
668 668
 
669
-		if( intval( $lesson_id ) > 0 ) {
669
+		if (intval($lesson_id) > 0) {
670 670
 
671
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
672
-			if( $course_id ) {
673
-				$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id );
674
-				if( ! $is_user_taking_course ) {
675
-					Sensei_Utils::user_start_course( $user_id, $course_id );
671
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
672
+			if ($course_id) {
673
+				$is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id);
674
+				if ( ! $is_user_taking_course) {
675
+					Sensei_Utils::user_start_course($user_id, $course_id);
676 676
 				}
677 677
 			}
678 678
 
@@ -680,12 +680,12 @@  discard block
 block discarded – undo
680 680
 			$status = 'in-progress';
681 681
 
682 682
 			// Note: When this action runs the lesson status may not yet exist
683
-			do_action( 'sensei_user_lesson_start', $user_id, $lesson_id );
683
+			do_action('sensei_user_lesson_start', $user_id, $lesson_id);
684 684
 
685
-			if( $complete ) {
685
+			if ($complete) {
686 686
 
687
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
688
-				if ( $has_questions ) {
687
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
688
+				if ($has_questions) {
689 689
 					$status = 'passed'; // Force a pass
690 690
 					$metadata['grade'] = 0;
691 691
 				}
@@ -695,31 +695,31 @@  discard block
 block discarded – undo
695 695
 			}
696 696
 
697 697
 			// Check if user is already taking the lesson
698
-			$activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id );
699
-			if( ! $activity_logged ) {
698
+			$activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id);
699
+			if ( ! $activity_logged) {
700 700
 
701 701
 				$metadata['start'] = current_time('mysql');
702
-				$activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
702
+				$activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata);
703 703
 
704 704
             } else {
705 705
 
706 706
                 // if users is already taking the lesson  and the status changes to complete update it
707 707
                 $current_user_activity = get_comment($activity_logged);
708
-                if( $status=='complete' &&
709
-                    $status != $current_user_activity->comment_approved  ){
708
+                if ($status == 'complete' &&
709
+                    $status != $current_user_activity->comment_approved) {
710 710
 
711 711
                     $comment = array();
712 712
                     $comment['comment_ID'] = $activity_logged;
713 713
                     $comment['comment_approved'] = $status;
714
-                    wp_update_comment( $comment );
714
+                    wp_update_comment($comment);
715 715
 
716 716
                 }
717 717
 
718 718
             }
719 719
 
720
-			if ( $complete ) {
720
+			if ($complete) {
721 721
 				// Run this *after* the lesson status has been created/updated
722
-				do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
722
+				do_action('sensei_user_lesson_end', $user_id, $lesson_id);
723 723
 			}
724 724
 
725 725
 		}
@@ -734,20 +734,20 @@  discard block
 block discarded – undo
734 734
 	 * @param int $user_id
735 735
 	 * @return boolean
736 736
 	 */
737
-	public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) {
737
+	public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) {
738 738
 
739 739
 
740
-		if( ! $lesson_id ) return false;
740
+		if ( ! $lesson_id) return false;
741 741
 
742
-		if( intval( $user_id ) == 0 ) {
742
+		if (intval($user_id) == 0) {
743 743
 			$user_id = get_current_user_id();
744 744
 		}
745 745
 
746 746
 		// Process quiz
747
-		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
747
+		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
748 748
 
749 749
 		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
750
-		Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id );
750
+		Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id);
751 751
 
752 752
 		// Delete lesson status
753 753
 		$args = array(
@@ -756,10 +756,10 @@  discard block
 block discarded – undo
756 756
 			'user_id' => $user_id,
757 757
 		);
758 758
 		// This auto deletes the corresponding meta data, such as the quiz grade, and questions asked
759
-		Sensei_Utils::sensei_delete_activities( $args );
759
+		Sensei_Utils::sensei_delete_activities($args);
760 760
 
761
-		if( ! $from_course ) {
762
-			do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
761
+		if ( ! $from_course) {
762
+			do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
763 763
 		}
764 764
 
765 765
 		return true;
@@ -772,19 +772,19 @@  discard block
 block discarded – undo
772 772
 	 * @param int $user_id
773 773
 	 * @return boolean
774 774
 	 */
775
-	public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
775
+	public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) {
776 776
 
777 777
 
778
-		if( ! $course_id ) return false;
778
+		if ( ! $course_id) return false;
779 779
 
780
-		if( intval( $user_id ) == 0 ) {
780
+		if (intval($user_id) == 0) {
781 781
 			$user_id = get_current_user_id();
782 782
 		}
783 783
 
784
-		$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
784
+		$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
785 785
 
786
-		foreach( $lesson_ids as $lesson_id ) {
787
-			Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true );
786
+		foreach ($lesson_ids as $lesson_id) {
787
+			Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true);
788 788
 		}
789 789
 
790 790
 		// Delete course status
@@ -794,36 +794,36 @@  discard block
 block discarded – undo
794 794
 			'user_id' => $user_id,
795 795
 		);
796 796
 
797
-		Sensei_Utils::sensei_delete_activities( $args );
797
+		Sensei_Utils::sensei_delete_activities($args);
798 798
 
799
-		do_action( 'sensei_user_course_reset', $user_id, $course_id );
799
+		do_action('sensei_user_course_reset', $user_id, $course_id);
800 800
 
801 801
 		return true;
802 802
 	}
803 803
 
804
-	public static function sensei_get_quiz_questions( $quiz_id = 0 ) {
804
+	public static function sensei_get_quiz_questions($quiz_id = 0) {
805 805
 
806 806
 
807 807
 		$questions = array();
808 808
 
809
-		if( intval( $quiz_id ) > 0 ) {
810
-			$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
811
-			$questions = Sensei_Utils::array_sort_reorder( $questions );
809
+		if (intval($quiz_id) > 0) {
810
+			$questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
811
+			$questions = Sensei_Utils::array_sort_reorder($questions);
812 812
 		}
813 813
 
814 814
 		return $questions;
815 815
 	}
816 816
 
817
-	public static function sensei_get_quiz_total( $quiz_id = 0 ) {
817
+	public static function sensei_get_quiz_total($quiz_id = 0) {
818 818
 
819 819
 
820 820
 		$quiz_total = 0;
821 821
 
822
-		if( $quiz_id > 0 ) {
823
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
822
+		if ($quiz_id > 0) {
823
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
824 824
 			$question_grade = 0;
825
-			foreach( $questions as $question ) {
826
-				$question_grade = Sensei()->question->get_question_grade( $question->ID );
825
+			foreach ($questions as $question) {
826
+				$question_grade = Sensei()->question->get_question_grade($question->ID);
827 827
 				$quiz_total += $question_grade;
828 828
 			}
829 829
 		}
@@ -838,20 +838,20 @@  discard block
 block discarded – undo
838 838
 	 * @param int $user_id
839 839
 	 * @return string
840 840
 	 */
841
-	public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) {
841
+	public static function sensei_get_user_question_grade($question = 0, $user_id = 0) {
842 842
 		$question_grade = false;
843
-		if( $question ) {
844
-			if ( is_object( $question ) ) {
843
+		if ($question) {
844
+			if (is_object($question)) {
845 845
 				$user_answer_id = $question->comment_ID;
846 846
 			}
847 847
 			else {
848
-				if( intval( $user_id ) == 0 ) {
848
+				if (intval($user_id) == 0) {
849 849
 					$user_id = get_current_user_id();
850 850
 				}
851
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
851
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
852 852
 			}
853
-			if ( $user_answer_id ) {
854
-				$question_grade = get_comment_meta( $user_answer_id, 'user_grade', true );
853
+			if ($user_answer_id) {
854
+				$question_grade = get_comment_meta($user_answer_id, 'user_grade', true);
855 855
 			}
856 856
 		}
857 857
 
@@ -866,52 +866,52 @@  discard block
 block discarded – undo
866 866
 	 * @param int $user_id
867 867
 	 * @return string
868 868
 	 */
869
-	public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) {
869
+	public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) {
870 870
 		$answer_notes = false;
871
-		if( $question ) {
872
-			if ( is_object( $question ) ) {
871
+		if ($question) {
872
+			if (is_object($question)) {
873 873
 				$user_answer_id = $question->comment_ID;
874 874
 			}
875 875
 			else {
876
-				if( intval( $user_id ) == 0 ) {
876
+				if (intval($user_id) == 0) {
877 877
 					$user_id = get_current_user_id();
878 878
 				}
879
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
879
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
880 880
 			}
881
-			if ( $user_answer_id ) {
882
-				$answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) );
881
+			if ($user_answer_id) {
882
+				$answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true));
883 883
 			}
884 884
 		}
885 885
 
886 886
 		return $answer_notes;
887 887
 	}
888 888
 
889
-	public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) {
890
-		if( intval( $user_id ) == 0 ) {
889
+	public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) {
890
+		if (intval($user_id) == 0) {
891 891
 			$user_id = get_current_user_id();
892 892
 		}
893 893
 
894 894
 		$delete_answers = false;
895
-		if( intval( $quiz_id ) > 0 ) {
896
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
897
-			foreach( $questions as $question ) {
898
-				$delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) );
895
+		if (intval($quiz_id) > 0) {
896
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
897
+			foreach ($questions as $question) {
898
+				$delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer'));
899 899
 			}
900 900
 		}
901 901
 
902 902
 		return $delete_answers;
903 903
 	}
904 904
 
905
-	public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) {
906
-		if( intval( $user_id ) == 0 ) {
905
+	public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) {
906
+		if (intval($user_id) == 0) {
907 907
 			$user_id = get_current_user_id();
908 908
 		}
909 909
 
910 910
 		$delete_grade = false;
911
-		if( intval( $quiz_id ) > 0 ) {
912
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
913
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
914
-			$delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' );
911
+		if (intval($quiz_id) > 0) {
912
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
913
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
914
+			$delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade');
915 915
 		}
916 916
 
917 917
 		return $delete_grade;
@@ -924,20 +924,20 @@  discard block
 block discarded – undo
924 924
      * @param string $notes
925 925
 	 * @return boolean
926 926
 	 */
927
-	public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) {
928
-		if( intval( $user_id ) == 0 ) {
927
+	public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') {
928
+		if (intval($user_id) == 0) {
929 929
 			$user_id = get_current_user_id();
930 930
 		}
931 931
 
932 932
 		$activity_logged = false;
933 933
 
934
-		if( intval( $question_id ) > 0 ) {
935
-			$notes = base64_encode( $notes );
934
+		if (intval($question_id) > 0) {
935
+			$notes = base64_encode($notes);
936 936
 
937 937
 			// Don't store empty values, no point
938
-			if ( !empty($notes) ) {
939
-				$user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
940
-				$activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes );
938
+			if ( ! empty($notes)) {
939
+				$user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
940
+				$activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes);
941 941
 			}
942 942
 			else {
943 943
 				$activity_logged = true;
@@ -953,16 +953,16 @@  discard block
 block discarded – undo
953 953
 	 * @param  array $return_array data to be ordered
954 954
 	 * @return array $return_array ordered data
955 955
 	 */
956
-	public static function array_sort_reorder( $return_array ) {
957
-		if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) {
956
+	public static function array_sort_reorder($return_array) {
957
+		if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) {
958 958
 			$sort_key = '';
959 959
 			// if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) {
960 960
 			// 	$sort_key = esc_html( $_GET['orderby'] );
961 961
 			// } // End If Statement
962
-			if ( '' != $sort_key ) {
963
-					Sensei_Utils::sort_array_by_key($return_array,$sort_key);
964
-				if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) {
965
-					$return_array = array_reverse( $return_array, true );
962
+			if ('' != $sort_key) {
963
+					Sensei_Utils::sort_array_by_key($return_array, $sort_key);
964
+				if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) {
965
+					$return_array = array_reverse($return_array, true);
966 966
 				} // End If Statement
967 967
 			} // End If Statement
968 968
 			return $return_array;
@@ -978,15 +978,15 @@  discard block
 block discarded – undo
978 978
 	 * @param  $key string column name in array
979 979
 	 * @return void
980 980
 	 */
981
-	public static function sort_array_by_key( $array, $key ) {
981
+	public static function sort_array_by_key($array, $key) {
982 982
 	    $sorter = array();
983 983
 	    $ret = array();
984
-	    reset( $array );
985
-	    foreach ( $array as $ii => $va ) {
984
+	    reset($array);
985
+	    foreach ($array as $ii => $va) {
986 986
 	        $sorter[$ii] = $va[$key];
987 987
 	    } // End For Loop
988
-	    asort( $sorter );
989
-	    foreach ( $sorter as $ii => $va ) {
988
+	    asort($sorter);
989
+	    foreach ($sorter as $ii => $va) {
990 990
 	        $ret[$ii] = $array[$ii];
991 991
 	    } // End For Loop
992 992
 	    $array = $ret;
@@ -998,10 +998,10 @@  discard block
 block discarded – undo
998 998
 	 * @param  integer $quiz_id
999 999
 	 * @return array of quiz questions
1000 1000
 	 */
1001
-	public static function lesson_quiz_questions( $quiz_id = 0 ) {
1001
+	public static function lesson_quiz_questions($quiz_id = 0) {
1002 1002
 		$questions_array = array();
1003
-		if ( 0 < $quiz_id ) {
1004
-			$question_args = array( 'post_type'         => 'question',
1003
+		if (0 < $quiz_id) {
1004
+			$question_args = array('post_type'         => 'question',
1005 1005
                                     'posts_per_page'       => -1,
1006 1006
                                     'orderby'           => 'ID',
1007 1007
                                     'order'             => 'ASC',
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
                                     'post_status'       => 'any',
1015 1015
                                     'suppress_filters'  => 0
1016 1016
                                 );
1017
-            $questions_array = get_posts( $question_args );
1017
+            $questions_array = get_posts($question_args);
1018 1018
         } // End If Statement
1019 1019
         return $questions_array;
1020 1020
 	} // End lesson_quiz_questions()
@@ -1024,25 +1024,25 @@  discard block
 block discarded – undo
1024 1024
 	 * @param  integer $course_id ID of course
1025 1025
 	 * @return integer            Pass mark for course
1026 1026
 	 */
1027
-	public static function sensei_course_pass_grade( $course_id = 0 ) {
1027
+	public static function sensei_course_pass_grade($course_id = 0) {
1028 1028
 
1029 1029
 
1030 1030
 		$course_passmark = 0;
1031 1031
 
1032
-		if( $course_id > 0 ) {
1033
-			$lessons = Sensei()->course->course_lessons( $course_id );
1032
+		if ($course_id > 0) {
1033
+			$lessons = Sensei()->course->course_lessons($course_id);
1034 1034
 			$lesson_count = 0;
1035 1035
 			$total_passmark = 0;
1036
-			foreach( $lessons as $lesson ) {
1036
+			foreach ($lessons as $lesson) {
1037 1037
 
1038 1038
 				// Get Quiz ID
1039
-				$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
1039
+				$quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
1040 1040
 
1041 1041
 				// Check for a pass being required
1042
-				$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1043
-				if ( $pass_required ) {
1042
+				$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1043
+				if ($pass_required) {
1044 1044
 					// Get quiz passmark
1045
-					$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1045
+					$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1046 1046
 
1047 1047
 					// Add up total passmark
1048 1048
 					$total_passmark += $quiz_passmark;
@@ -1051,12 +1051,12 @@  discard block
 block discarded – undo
1051 1051
 				}
1052 1052
 			}
1053 1053
 			// Might be a case of no required lessons
1054
-			if ( $lesson_count ) {
1055
-				$course_passmark = ( $total_passmark / $lesson_count );
1054
+			if ($lesson_count) {
1055
+				$course_passmark = ($total_passmark / $lesson_count);
1056 1056
 			}
1057 1057
 		}
1058 1058
 
1059
-		return Sensei_Utils::round( $course_passmark );
1059
+		return Sensei_Utils::round($course_passmark);
1060 1060
 	}
1061 1061
 
1062 1062
 	/**
@@ -1065,27 +1065,27 @@  discard block
 block discarded – undo
1065 1065
 	 * @param  integer $user_id   ID of user
1066 1066
 	 * @return integer            User's total grade
1067 1067
 	 */
1068
-	public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) {
1068
+	public static function sensei_course_user_grade($course_id = 0, $user_id = 0) {
1069 1069
 
1070 1070
 
1071
-		if( intval( $user_id ) == 0 ) {
1071
+		if (intval($user_id) == 0) {
1072 1072
 			$user_id = get_current_user_id();
1073 1073
 		}
1074 1074
 
1075 1075
 		$total_grade = 0;
1076 1076
 
1077
-		if( $course_id > 0 && $user_id > 0 ) {
1078
-			$lessons = Sensei()->course->course_lessons( $course_id );
1077
+		if ($course_id > 0 && $user_id > 0) {
1078
+			$lessons = Sensei()->course->course_lessons($course_id);
1079 1079
 			$lesson_count = 0;
1080 1080
 			$total_grade = 0;
1081
-			foreach( $lessons as $lesson ) {
1081
+			foreach ($lessons as $lesson) {
1082 1082
 
1083 1083
 				// Check for lesson having questions, thus a quiz, thus having a grade
1084
-				$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
1085
-				if ( $has_questions ) {
1086
-					$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id );
1084
+				$has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true);
1085
+				if ($has_questions) {
1086
+					$user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id);
1087 1087
 					// Get user quiz grade
1088
-					$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1088
+					$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1089 1089
 
1090 1090
 					// Add up total grade
1091 1091
 					$total_grade += $quiz_grade;
@@ -1095,13 +1095,13 @@  discard block
 block discarded – undo
1095 1095
 			}
1096 1096
 
1097 1097
 			// Might be a case of no lessons with quizzes
1098
-			if ( $lesson_count ) {
1099
-				$total_grade = ( $total_grade / $lesson_count );
1098
+			if ($lesson_count) {
1099
+				$total_grade = ($total_grade / $lesson_count);
1100 1100
 			}
1101 1101
 
1102 1102
 		}
1103 1103
 
1104
-		return Sensei_Utils::round( $total_grade );
1104
+		return Sensei_Utils::round($total_grade);
1105 1105
 	}
1106 1106
 
1107 1107
 	/**
@@ -1110,18 +1110,18 @@  discard block
 block discarded – undo
1110 1110
 	 * @param  integer $user_id   ID of user
1111 1111
 	 * @return boolean
1112 1112
 	 */
1113
-	public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) {
1114
-		if( intval( $user_id ) == 0 ) {
1113
+	public static function sensei_user_passed_course($course_id = 0, $user_id = 0) {
1114
+		if (intval($user_id) == 0) {
1115 1115
 			$user_id = get_current_user_id();
1116 1116
 		}
1117 1117
 
1118 1118
 		$pass = false;
1119 1119
 
1120
-		if( $course_id > 0 && $user_id > 0 ) {
1121
-			$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id );
1122
-			$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id );
1120
+		if ($course_id > 0 && $user_id > 0) {
1121
+			$passmark = Sensei_Utils::sensei_course_pass_grade($course_id);
1122
+			$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id);
1123 1123
 
1124
-			if( $user_grade >= $passmark ) {
1124
+			if ($user_grade >= $passmark) {
1125 1125
 				$pass = true;
1126 1126
 			}
1127 1127
 		}
@@ -1136,38 +1136,38 @@  discard block
 block discarded – undo
1136 1136
 	 * @param  integer $user_id   ID of user
1137 1137
 	 * @return array              Status code and message
1138 1138
 	 */
1139
-	public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) {
1140
-		if( intval( $user_id ) == 0 ) {
1139
+	public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) {
1140
+		if (intval($user_id) == 0) {
1141 1141
 			$user_id = get_current_user_id();
1142 1142
 		}
1143 1143
 
1144 1144
 		$status = 'not_started';
1145 1145
 		$box_class = 'info';
1146
-		$message = __( 'You have not started this course yet.', 'woothemes-sensei' );
1146
+		$message = __('You have not started this course yet.', 'woothemes-sensei');
1147 1147
 
1148
-		if( $course_id > 0 && $user_id > 0 ) {
1148
+		if ($course_id > 0 && $user_id > 0) {
1149 1149
 
1150
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1150
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1151 1151
 
1152
-			if( $started_course ) {
1153
-				$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()!
1154
-				$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()!
1155
-				if( $user_grade >= $passmark ) {
1152
+			if ($started_course) {
1153
+				$passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()!
1154
+				$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()!
1155
+				if ($user_grade >= $passmark) {
1156 1156
 					$status = 'passed';
1157 1157
 					$box_class = 'tick';
1158
-					$message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade );
1158
+					$message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade);
1159 1159
 				} else {
1160 1160
 					$status = 'failed';
1161 1161
 					$box_class = 'alert';
1162
-					$message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade );
1162
+					$message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade);
1163 1163
 				}
1164 1164
 			}
1165 1165
 
1166 1166
 		}
1167 1167
 
1168
-		$message = apply_filters( 'sensei_user_course_status_' . $status, $message );
1168
+		$message = apply_filters('sensei_user_course_status_'.$status, $message);
1169 1169
 
1170
-		return array( 'status' => $status, 'box_class' => $box_class, 'message' => $message );
1170
+		return array('status' => $status, 'box_class' => $box_class, 'message' => $message);
1171 1171
 	}
1172 1172
 
1173 1173
 	/**
@@ -1177,94 +1177,94 @@  discard block
 block discarded – undo
1177 1177
      * @param  bool $is_lesson
1178 1178
 	 * @return array              Status code and message
1179 1179
 	 */
1180
-	public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
1180
+	public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) {
1181 1181
 		global  $current_user;
1182
-		if( intval( $user_id ) == 0 ) {
1182
+		if (intval($user_id) == 0) {
1183 1183
 			$user_id = $current_user->ID;
1184 1184
 		}
1185 1185
 
1186 1186
 		$status = 'not_started';
1187 1187
 		$box_class = 'info';
1188
-		$message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' );
1188
+		$message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei');
1189 1189
 		$extra = '';
1190 1190
 
1191
-		if( $lesson_id > 0 && $user_id > 0 ) {
1191
+		if ($lesson_id > 0 && $user_id > 0) {
1192 1192
 
1193 1193
 			// Prerequisite lesson
1194
-			$prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1194
+			$prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true);
1195 1195
 
1196 1196
 			// Course ID
1197
-			$course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) );
1197
+			$course_id = absint(get_post_meta($lesson_id, '_lesson_course', true));
1198 1198
 
1199 1199
 			// Has user started course
1200
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1200
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1201 1201
 
1202 1202
 			// Has user completed lesson
1203
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1204
-			$lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status );
1203
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1204
+			$lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status);
1205 1205
 
1206 1206
 			// Quiz ID
1207
-			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1207
+			$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1208 1208
 
1209 1209
 			// Quiz grade
1210 1210
 			$quiz_grade = 0;
1211
-			if ( $user_lesson_status ) {
1212
-				$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1211
+			if ($user_lesson_status) {
1212
+				$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1213 1213
 			}
1214 1214
 
1215 1215
 			// Quiz passmark
1216
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1216
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1217 1217
 			$quiz_passmark_float = (float) $quiz_passmark;
1218 1218
 
1219 1219
 			// Pass required
1220
-			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1220
+			$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1221 1221
 
1222 1222
 			// Quiz questions
1223
-			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1223
+			$has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1224 1224
 
1225
-			if ( ! $started_course ) {
1225
+			if ( ! $started_course) {
1226 1226
 
1227 1227
 				$status = 'not_started_course';
1228 1228
 				$box_class = 'info';
1229
-				$message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' );
1229
+				$message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>');
1230 1230
 
1231
-			} elseif ( ! is_user_logged_in() ) {
1231
+			} elseif ( ! is_user_logged_in()) {
1232 1232
 
1233 1233
 				$status = 'login_required';
1234 1234
 				$box_class = 'info';
1235
-				$message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' );
1235
+				$message = __('You must be logged in to take this quiz', 'woothemes-sensei');
1236 1236
 
1237 1237
 			}
1238 1238
 			// Lesson/Quiz is marked as complete thus passing any quiz restrictions
1239
-			elseif ( $lesson_complete ) {
1239
+			elseif ($lesson_complete) {
1240 1240
 
1241 1241
 				$status = 'passed';
1242 1242
 				$box_class = 'tick';
1243 1243
 				// Lesson status will be "complete" (has no Quiz)
1244
-				if ( ! $has_quiz_questions ) {
1245
-					$message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) );
1244
+				if ( ! $has_quiz_questions) {
1245
+					$message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei'));
1246 1246
 				}
1247 1247
 				// Lesson status will be "graded" (no passmark required so might have failed all the questions)
1248
-				elseif ( empty( $quiz_grade ) ) {
1249
-					$message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) );
1248
+				elseif (empty($quiz_grade)) {
1249
+					$message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei'));
1250 1250
 				}
1251 1251
 				// Lesson status will be "passed" (passmark reached)
1252
-				elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) {
1253
-					if( $is_lesson ) {
1254
-						$message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) );
1252
+				elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) {
1253
+					if ($is_lesson) {
1254
+						$message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1255 1255
 					} else {
1256
-						$message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_grade ) );
1256
+						$message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1257 1257
 					}
1258 1258
 				}
1259 1259
 
1260 1260
                 // add next lesson button
1261
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1262
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1261
+                $nav_id_array = sensei_get_prev_next_lessons($lesson_id);
1262
+                $next_lesson_id = absint($nav_id_array['next_lesson']);
1263 1263
 
1264 1264
                 // Output HTML
1265
-                if ( ( 0 < $next_lesson_id ) ) {
1266
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1267
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1265
+                if ((0 < $next_lesson_id)) {
1266
+                    $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id))
1267
+                                . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei')
1268 1268
                                 .'</a>';
1269 1269
 
1270 1270
                 }
@@ -1273,33 +1273,33 @@  discard block
 block discarded – undo
1273 1273
             // Lesson/Quiz not complete
1274 1274
 			else {
1275 1275
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1276
-				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
1276
+				if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) {
1277 1277
 					$status = 'complete';
1278 1278
 					$box_class = 'info';
1279
-					if( $is_lesson ) {
1280
-						$message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' );
1279
+					if ($is_lesson) {
1280
+						$message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>');
1281 1281
 					} else {
1282
-						$message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1282
+						$message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1283 1283
 					}
1284 1284
 				}
1285 1285
 				// Lesson status must be "failed"
1286
-				elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) {
1286
+				elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
1287 1287
 					$status = 'failed';
1288 1288
 					$box_class = 'alert';
1289
-					if( $is_lesson ) {
1290
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1289
+					if ($is_lesson) {
1290
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1291 1291
 					} else {
1292
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1292
+						$message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1293 1293
 					}
1294 1294
 				}
1295 1295
 				// Lesson/Quiz requires a pass
1296
-				elseif( $pass_required ) {
1296
+				elseif ($pass_required) {
1297 1297
 					$status = 'not_started';
1298 1298
 					$box_class = 'info';
1299
-					if( $is_lesson ) {
1300
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1299
+					if ($is_lesson) {
1300
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1301 1301
 					} else {
1302
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1302
+						$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1303 1303
 					}
1304 1304
 				}
1305 1305
 			}
@@ -1307,15 +1307,15 @@  discard block
 block discarded – undo
1307 1307
 		}
1308 1308
 
1309 1309
 		// Legacy filter
1310
-		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1310
+		$message = apply_filters('sensei_user_quiz_status_'.$status, $message);
1311 1311
 
1312
-		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1313
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1314
-			$extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' .  __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' .  __( 'View the lesson quiz', 'woothemes-sensei' )  . '</a></p>';
1312
+		if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) {
1313
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1314
+			$extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>';
1315 1315
 		}
1316 1316
 
1317 1317
 		// Filter of all messages
1318
-		return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson );
1318
+		return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson);
1319 1319
 	}
1320 1320
 
1321 1321
 	/**
@@ -1325,14 +1325,14 @@  discard block
 block discarded – undo
1325 1325
 	 * @param  integer $course_id Course ID
1326 1326
 	 * @return mixed boolean or comment_ID
1327 1327
 	 */
1328
-	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1328
+	public static function user_start_course($user_id = 0, $course_id = 0) {
1329 1329
 
1330 1330
 		$activity_logged = false;
1331 1331
 
1332
-		if( $user_id && $course_id ) {
1332
+		if ($user_id && $course_id) {
1333 1333
 			// Check if user is already on the Course
1334
-			$activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id );
1335
-			if ( ! $activity_logged ) {
1334
+			$activity_logged = Sensei_Utils::user_started_course($course_id, $user_id);
1335
+			if ( ! $activity_logged) {
1336 1336
 
1337 1337
 				// Add user to course
1338 1338
 				$course_metadata = array(
@@ -1341,11 +1341,11 @@  discard block
 block discarded – undo
1341 1341
 					'complete' => 0,
1342 1342
 				);
1343 1343
 
1344
-				$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata );
1344
+				$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata);
1345 1345
 
1346 1346
 				// Allow further actions
1347
-				if ( $activity_logged ) {
1348
-					do_action( 'sensei_user_course_start', $user_id, $course_id );
1347
+				if ($activity_logged) {
1348
+					do_action('sensei_user_course_start', $user_id, $course_id);
1349 1349
 				}
1350 1350
 			}
1351 1351
 		}
@@ -1361,19 +1361,19 @@  discard block
 block discarded – undo
1361 1361
 	 * @param int $user_id
1362 1362
 	 * @return mixed false or comment_ID
1363 1363
 	 */
1364
-	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1364
+	public static function user_started_course($course_id = 0, $user_id = 0) {
1365 1365
 
1366
-		if( $course_id ) {
1367
-			if( ! $user_id ) {
1366
+		if ($course_id) {
1367
+			if ( ! $user_id) {
1368 1368
 				$user_id = get_current_user_id();
1369 1369
 			}
1370 1370
 
1371
-            if( ! $user_id > 0 ){
1371
+            if ( ! $user_id > 0) {
1372 1372
                 return false;
1373 1373
             }
1374 1374
 
1375
-			$user_course_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) );
1376
-			if( $user_course_status_id ) {
1375
+			$user_course_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID'));
1376
+			if ($user_course_status_id) {
1377 1377
 				return $user_course_status_id;
1378 1378
 			}
1379 1379
 		}
@@ -1388,17 +1388,17 @@  discard block
 block discarded – undo
1388 1388
 	 * @param  integer $user_id   User ID
1389 1389
 	 * @return int
1390 1390
 	 */
1391
-	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1391
+	public static function user_complete_course($course_id = 0, $user_id = 0) {
1392 1392
 		global  $wp_version;
1393 1393
 
1394
-		if( $course_id ) {
1395
-			if( ! $user_id ) {
1394
+		if ($course_id) {
1395
+			if ( ! $user_id) {
1396 1396
 				$user_id = get_current_user_id();
1397 1397
 			}
1398 1398
 
1399 1399
 			$course_status = 'in-progress';
1400 1400
 			$course_metadata = array();
1401
-			$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1401
+			$course_completion = Sensei()->settings->settings['course_completion'];
1402 1402
 			$lessons_completed = $total_lessons = 0;
1403 1403
 			$lesson_status_args = array(
1404 1404
 					'user_id' => $user_id,
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
 				);
1408 1408
 
1409 1409
 			// Grab all of this Courses' lessons, looping through each...
1410
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
1411
-			$total_lessons = count( $lesson_ids );
1410
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
1411
+			$total_lessons = count($lesson_ids);
1412 1412
 				// ...if course completion not set to 'passed', and all lessons are complete or graded,
1413 1413
 				// ......then all lessons are 'passed'
1414 1414
 				// ...else if course completion is set to 'passed', check if each lesson has questions...
@@ -1421,29 +1421,29 @@  discard block
 block discarded – undo
1421 1421
 			// The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson()
1422 1422
 			$all_lesson_statuses = array();
1423 1423
 			// In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs
1424
-			if ( version_compare($wp_version, '4.1', '>=') ) {
1424
+			if (version_compare($wp_version, '4.1', '>=')) {
1425 1425
 				$lesson_status_args['post__in'] = $lesson_ids;
1426
-				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1426
+				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1427 1427
 				// Need to always return an array, even with only 1 item
1428
-				if ( !is_array($all_lesson_statuses) ) {
1429
-					$all_lesson_statuses = array( $all_lesson_statuses );
1428
+				if ( ! is_array($all_lesson_statuses)) {
1429
+					$all_lesson_statuses = array($all_lesson_statuses);
1430 1430
 				}
1431 1431
 			}
1432 1432
 			// ...otherwise check each one
1433 1433
 			else {
1434
-				foreach( $lesson_ids as $lesson_id ) {
1434
+				foreach ($lesson_ids as $lesson_id) {
1435 1435
 					$lesson_status_args['post_id'] = $lesson_id;
1436
-					$each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1436
+					$each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1437 1437
 					// Check for valid return before using
1438
-					if ( !empty($each_lesson_status->comment_approved) ) {
1438
+					if ( ! empty($each_lesson_status->comment_approved)) {
1439 1439
 						$all_lesson_statuses[] = $each_lesson_status;
1440 1440
 					}
1441 1441
 				}
1442 1442
 			}
1443
-			foreach( $all_lesson_statuses as $lesson_status ) {
1443
+			foreach ($all_lesson_statuses as $lesson_status) {
1444 1444
 				// If lessons are complete without needing quizzes to be passed
1445
-				if ( 'passed' != $course_completion ) {
1446
-					switch ( $lesson_status->comment_approved ) {
1445
+				if ('passed' != $course_completion) {
1446
+					switch ($lesson_status->comment_approved) {
1447 1447
 						// A user cannot 'complete' a course if a lesson...
1448 1448
 						case 'in-progress': // ...is still in progress
1449 1449
 						case 'ungraded': // ...hasn't yet been graded
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
 					}
1456 1456
 				}
1457 1457
 				else {
1458
-					switch ( $lesson_status->comment_approved ) {
1458
+					switch ($lesson_status->comment_approved) {
1459 1459
 						case 'complete': // Lesson has no quiz/questions
1460 1460
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
1461 1461
 						case 'passed': // Lesson has quiz and the user passed
@@ -1469,20 +1469,20 @@  discard block
 block discarded – undo
1469 1469
 					}
1470 1470
 				}
1471 1471
 			} // Each lesson
1472
-			if ( $lessons_completed == $total_lessons ) {
1472
+			if ($lessons_completed == $total_lessons) {
1473 1473
 				$course_status = 'complete';
1474 1474
 			}
1475 1475
 
1476 1476
 			// Update meta data on how many lessons have been completed
1477 1477
 			$course_metadata['complete'] = $lessons_completed;
1478 1478
 			// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1479
-			$course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1479
+			$course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1480 1480
 
1481
-			$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata );
1481
+			$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata);
1482 1482
 
1483 1483
 			// Allow further actions
1484
-			if ( 'complete' == $course_status ) {
1485
-				do_action( 'sensei_user_course_end', $user_id, $course_id );
1484
+			if ('complete' == $course_status) {
1485
+				do_action('sensei_user_course_end', $user_id, $course_id);
1486 1486
 			}
1487 1487
 			return $activity_logged;
1488 1488
 		}
@@ -1498,31 +1498,31 @@  discard block
 block discarded – undo
1498 1498
 	 * @param int $user_id
1499 1499
 	 * @return boolean
1500 1500
 	 */
1501
-	public static function user_completed_course( $course , $user_id = 0 ) {
1501
+	public static function user_completed_course($course, $user_id = 0) {
1502 1502
 
1503
-		if( $course ) {
1504
-			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1503
+		if ($course) {
1504
+			if (is_object($course) && is_a($course, 'WP_Comment')) {
1505 1505
 				$user_course_status = $course->comment_approved;
1506 1506
 			}
1507
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1507
+			elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) {
1508 1508
 				$user_course_status = $course;
1509 1509
 			}
1510 1510
 			else {
1511
-				if( ! $user_id ) {
1511
+				if ( ! $user_id) {
1512 1512
 					$user_id = get_current_user_id();
1513 1513
 				}
1514 1514
 
1515
-                if( is_a( $course, 'WP_Post' ) ){
1516
-                    $course =   $course->ID;
1515
+                if (is_a($course, 'WP_Post')) {
1516
+                    $course = $course->ID;
1517 1517
                 }
1518 1518
 
1519
-				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1520
-				if( isset( $user_course_status->comment_approved ) ){
1519
+				$user_course_status = Sensei_Utils::user_course_status($course, $user_id);
1520
+				if (isset($user_course_status->comment_approved)) {
1521 1521
                     $user_course_status = $user_course_status->comment_approved;
1522 1522
                 }
1523 1523
 
1524 1524
 			}
1525
-			if( $user_course_status && 'complete' == $user_course_status ) {
1525
+			if ($user_course_status && 'complete' == $user_course_status) {
1526 1526
 				return true;
1527 1527
 			}
1528 1528
 		}
@@ -1537,10 +1537,10 @@  discard block
 block discarded – undo
1537 1537
 	 * @param int $user_id
1538 1538
 	 * @return mixed false or comment_ID
1539 1539
 	 */
1540
-	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1540
+	public static function user_started_lesson($lesson_id = 0, $user_id = 0) {
1541 1541
 
1542
-		if( $lesson_id ) {
1543
-			if( ! $user_id ) {
1542
+		if ($lesson_id) {
1543
+			if ( ! $user_id) {
1544 1544
 				$user_id = get_current_user_id();
1545 1545
 			}
1546 1546
 
@@ -1550,8 +1550,8 @@  discard block
 block discarded – undo
1550 1550
                 'type' => 'sensei_lesson_status',
1551 1551
                 'field' => 'comment_ID' );
1552 1552
 
1553
-			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1554
-			if( $user_lesson_status_id ) {
1553
+			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1554
+			if ($user_lesson_status_id) {
1555 1555
 				return $user_lesson_status_id;
1556 1556
 			}
1557 1557
 		}
@@ -1566,29 +1566,29 @@  discard block
 block discarded – undo
1566 1566
 	 * @param int $user_id
1567 1567
 	 * @return boolean
1568 1568
 	 */
1569
-	public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) {
1569
+	public static function user_completed_lesson($lesson = 0, $user_id = 0) {
1570 1570
 
1571
-		if( $lesson ) {
1571
+		if ($lesson) {
1572 1572
 			$lesson_id = 0;
1573
-			if ( is_object( $lesson ) ) {
1573
+			if (is_object($lesson)) {
1574 1574
 				$user_lesson_status = $lesson->comment_approved;
1575 1575
 				$lesson_id = $lesson->comment_post_ID;
1576 1576
 			}
1577
-			elseif ( ! is_numeric( $lesson ) ) {
1577
+			elseif ( ! is_numeric($lesson)) {
1578 1578
 				$user_lesson_status = $lesson;
1579 1579
 			}
1580 1580
 			else {
1581
-				if( ! $user_id ) {
1581
+				if ( ! $user_id) {
1582 1582
 					$user_id = get_current_user_id();
1583 1583
 				}
1584 1584
 
1585 1585
                 // the user is not logged in
1586
-                if( ! $user_id > 0 ){
1586
+                if ( ! $user_id > 0) {
1587 1587
                     return false;
1588 1588
                 }
1589
-				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1589
+				$_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id);
1590 1590
 
1591
-				if ( $_user_lesson_status ) {
1591
+				if ($_user_lesson_status) {
1592 1592
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1593 1593
 				}
1594 1594
 				else {
@@ -1596,12 +1596,12 @@  discard block
 block discarded – undo
1596 1596
 				}
1597 1597
 				$lesson_id = $lesson;
1598 1598
 			}
1599
-			if ( 'in-progress' != $user_lesson_status ) {
1599
+			if ('in-progress' != $user_lesson_status) {
1600 1600
 				// Check for Passed or Completed Setting
1601 1601
 				// Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting
1602 1602
 //				$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1603 1603
 //				if ( 'passed' == $course_completion ) {
1604
-					switch( $user_lesson_status ) {
1604
+					switch ($user_lesson_status) {
1605 1605
 						case 'complete':
1606 1606
 						case 'graded':
1607 1607
 						case 'passed':
@@ -1610,13 +1610,13 @@  discard block
 block discarded – undo
1610 1610
 
1611 1611
 						case 'failed':
1612 1612
 							// This may be 'completed' depending on...
1613
-							if ( $lesson_id ) {
1613
+							if ($lesson_id) {
1614 1614
 								// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson
1615
-								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1616
-								if ( $lesson_quiz_id ) {
1615
+								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1616
+								if ($lesson_quiz_id) {
1617 1617
 									// ...the quiz pass setting
1618
-									$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
1619
-									if ( empty($pass_required) ) {
1618
+									$pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true);
1619
+									if (empty($pass_required)) {
1620 1620
 										// We just require the user to have done the quiz, not to have passed
1621 1621
 										return true;
1622 1622
 									}
@@ -1639,15 +1639,15 @@  discard block
 block discarded – undo
1639 1639
 	 * @param int $user_id
1640 1640
 	 * @return object
1641 1641
 	 */
1642
-	public static function user_course_status( $course_id = 0, $user_id = 0 ) {
1642
+	public static function user_course_status($course_id = 0, $user_id = 0) {
1643 1643
 
1644 1644
 
1645
-		if( $course_id ) {
1646
-			if( ! $user_id ) {
1645
+		if ($course_id) {
1646
+			if ( ! $user_id) {
1647 1647
 				$user_id = get_current_user_id();
1648 1648
 			}
1649 1649
 
1650
-			$user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true );
1650
+			$user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true);
1651 1651
 			return $user_course_status;
1652 1652
 		}
1653 1653
 
@@ -1662,27 +1662,27 @@  discard block
 block discarded – undo
1662 1662
 	 * @param int $user_id
1663 1663
 	 * @return object | bool
1664 1664
 	 */
1665
-	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1665
+	public static function user_lesson_status($lesson_id = 0, $user_id = 0) {
1666 1666
 
1667
-        if( ! $user_id ) {
1667
+        if ( ! $user_id) {
1668 1668
             $user_id = get_current_user_id();
1669 1669
         }
1670 1670
 
1671
-		if( $lesson_id > 0 && $user_id > 0 ) {
1671
+		if ($lesson_id > 0 && $user_id > 0) {
1672 1672
 
1673
-			$user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true );
1673
+			$user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true);
1674 1674
 			return $user_lesson_status;
1675 1675
 		}
1676 1676
 
1677 1677
 		return false;
1678 1678
 	}
1679 1679
 
1680
-	public static function is_preview_lesson( $lesson_id ) {
1680
+	public static function is_preview_lesson($lesson_id) {
1681 1681
 		$is_preview = false;
1682 1682
 
1683
-		if( 'lesson' == get_post_type( $lesson_id ) ) {
1684
-			$lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true );
1685
-			if ( isset( $lesson_preview ) && '' != $lesson_preview ) {
1683
+		if ('lesson' == get_post_type($lesson_id)) {
1684
+			$lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true);
1685
+			if (isset($lesson_preview) && '' != $lesson_preview) {
1686 1686
 				$is_preview = true;
1687 1687
 			}
1688 1688
 		}
@@ -1690,22 +1690,22 @@  discard block
 block discarded – undo
1690 1690
 		return $is_preview;
1691 1691
 	}
1692 1692
 
1693
-	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1693
+	public static function user_passed_quiz($quiz_id = 0, $user_id = 0) {
1694 1694
 
1695
-		if( ! $quiz_id  ) return false;
1695
+		if ( ! $quiz_id) return false;
1696 1696
 
1697
-		if( ! $user_id ) {
1697
+		if ( ! $user_id) {
1698 1698
 			$user_id = get_current_user_id();
1699 1699
 		}
1700
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1700
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1701 1701
 
1702 1702
 		// Quiz Grade
1703
-		$lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1704
-		$quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
1703
+		$lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1704
+		$quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
1705 1705
 
1706 1706
 		// Check if Grade is greater than or equal to pass percentage
1707
-		$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
1708
-		if ( $quiz_passmark <= intval( $quiz_grade ) ) {
1707
+		$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
1708
+		if ($quiz_passmark <= intval($quiz_grade)) {
1709 1709
 			return true;
1710 1710
 		}
1711 1711
 
@@ -1725,9 +1725,9 @@  discard block
 block discarded – undo
1725 1725
      *
1726 1726
 	 * @return mixed false or comment_ID
1727 1727
 	 */
1728
-	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1728
+	public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) {
1729 1729
 		$comment_id = false;
1730
-		if ( !empty($status) ) {
1730
+		if ( ! empty($status)) {
1731 1731
 			$args = array(
1732 1732
 					'user_id'   => $user_id,
1733 1733
 					'post_id'   => $lesson_id,
@@ -1736,18 +1736,18 @@  discard block
 block discarded – undo
1736 1736
 					'action'    => 'update', // Update the existing status...
1737 1737
 					'keep_time' => true, // ...but don't change the existing timestamp
1738 1738
 				);
1739
-			if( 'in-progress' == $status ) {
1740
-				unset( $args['keep_time'] ); // Keep updating what's happened
1739
+			if ('in-progress' == $status) {
1740
+				unset($args['keep_time']); // Keep updating what's happened
1741 1741
 			}
1742 1742
 
1743
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1744
-			if ( $comment_id && !empty($metadata) ) {
1745
-				foreach( $metadata as $key => $value ) {
1746
-					update_comment_meta( $comment_id, $key, $value );
1743
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1744
+			if ($comment_id && ! empty($metadata)) {
1745
+				foreach ($metadata as $key => $value) {
1746
+					update_comment_meta($comment_id, $key, $value);
1747 1747
 				}
1748 1748
 			}
1749 1749
 
1750
-			do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id );
1750
+			do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id);
1751 1751
 		}
1752 1752
 		return $comment_id;
1753 1753
 	}
@@ -1763,9 +1763,9 @@  discard block
 block discarded – undo
1763 1763
 	 * @param array $metadata
1764 1764
 	 * @return mixed false or comment_ID
1765 1765
 	 */
1766
-	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1766
+	public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) {
1767 1767
 		$comment_id = false;
1768
-		if ( !empty($status) ) {
1768
+		if ( ! empty($status)) {
1769 1769
 			$args = array(
1770 1770
 					'user_id'   => $user_id,
1771 1771
 					'post_id'   => $course_id,
@@ -1774,17 +1774,17 @@  discard block
 block discarded – undo
1774 1774
 					'action'    => 'update', // Update the existing status...
1775 1775
 					'keep_time' => true, // ...but don't change the existing timestamp
1776 1776
 				);
1777
-			if( 'in-progress' == $status ) {
1778
-				unset( $args['keep_time'] ); // Keep updating what's happened
1777
+			if ('in-progress' == $status) {
1778
+				unset($args['keep_time']); // Keep updating what's happened
1779 1779
 			}
1780 1780
 
1781
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1782
-			if ( $comment_id && !empty($metadata) ) {
1783
-				foreach( $metadata as $key => $value ) {
1784
-					update_comment_meta( $comment_id, $key, $value );
1781
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1782
+			if ($comment_id && ! empty($metadata)) {
1783
+				foreach ($metadata as $key => $value) {
1784
+					update_comment_meta($comment_id, $key, $value);
1785 1785
 				}
1786 1786
 			}
1787
-			do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id );
1787
+			do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id);
1788 1788
 		}
1789 1789
 		return $comment_id;
1790 1790
 	}
@@ -1796,9 +1796,9 @@  discard block
 block discarded – undo
1796 1796
 	 * @param  array $pieces (default: array())
1797 1797
 	 * @return array
1798 1798
 	 */
1799
-	public static function single_comment_filter( $pieces ) {
1800
-		unset( $pieces['orderby'] );
1801
-		unset( $pieces['order'] );
1799
+	public static function single_comment_filter($pieces) {
1800
+		unset($pieces['orderby']);
1801
+		unset($pieces['order']);
1802 1802
 
1803 1803
 		return $pieces;
1804 1804
 	}
@@ -1810,9 +1810,9 @@  discard block
 block discarded – undo
1810 1810
 	 * @param  array $pieces (default: array())
1811 1811
 	 * @return array
1812 1812
 	 */
1813
-	public static function comment_any_status_filter( $pieces ) {
1813
+	public static function comment_any_status_filter($pieces) {
1814 1814
 
1815
-		$pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] );
1815
+		$pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']);
1816 1816
 
1817 1817
 		return $pieces;
1818 1818
 	}
@@ -1824,12 +1824,12 @@  discard block
 block discarded – undo
1824 1824
 	 * @param  array $pieces (default: array())
1825 1825
 	 * @return array
1826 1826
 	 */
1827
-	public static function comment_multiple_status_filter( $pieces ) {
1827
+	public static function comment_multiple_status_filter($pieces) {
1828 1828
 
1829
-		preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder );
1830
-		if ( !empty($placeholder[1]) ) {
1831
-			$statuses = explode( ',', $placeholder[1] );
1832
-			$pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] );
1829
+		preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder);
1830
+		if ( ! empty($placeholder[1])) {
1831
+			$statuses = explode(',', $placeholder[1]);
1832
+			$pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']);
1833 1833
 		}
1834 1834
 
1835 1835
 		return $pieces;
@@ -1841,12 +1841,12 @@  discard block
 block discarded – undo
1841 1841
      * @param array $pieces
1842 1842
 	 * @return array $pieces
1843 1843
 	 */
1844
-	public static function comment_total_sum_meta_value_filter( $pieces ) {
1844
+	public static function comment_total_sum_meta_value_filter($pieces) {
1845 1845
 		global $wpdb, $wp_version;
1846 1846
 
1847 1847
 		$pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum ";
1848
-		unset( $pieces['groupby'] );
1849
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1848
+		unset($pieces['groupby']);
1849
+		if (version_compare($wp_version, '4.1', '>=')) {
1850 1850
 			$args['order'] = false;
1851 1851
 			$args['orderby'] = false;
1852 1852
 		}
@@ -1861,12 +1861,12 @@  discard block
 block discarded – undo
1861 1861
 	 * @param  array $pieces (default: array())
1862 1862
 	 * @return array
1863 1863
 	 */
1864
-	public static function get_posts_count_only_filter( $pieces ) {
1864
+	public static function get_posts_count_only_filter($pieces) {
1865 1865
 		global $wp_version;
1866 1866
 
1867 1867
 		$pieces['fields'] = " COUNT(*) AS total ";
1868
-		unset( $pieces['groupby'] );
1869
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1868
+		unset($pieces['groupby']);
1869
+		if (version_compare($wp_version, '4.1', '>=')) {
1870 1870
 			$args['order'] = false;
1871 1871
 			$args['orderby'] = false;
1872 1872
 		}
@@ -1885,9 +1885,9 @@  discard block
 block discarded – undo
1885 1885
      *
1886 1886
      * @return bool $success
1887 1887
      */
1888
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1888
+    public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1889 1889
 
1890
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1890
+        return self::update_user_data($data_key, $post_id, $value, $user_id);
1891 1891
 
1892 1892
     }// end add_user_data
1893 1893
 
@@ -1906,18 +1906,18 @@  discard block
 block discarded – undo
1906 1906
      *
1907 1907
      * @return bool $success
1908 1908
      */
1909
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1909
+    public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1910 1910
 
1911
-        if( ! ( $user_id > 0 ) ){
1911
+        if ( ! ($user_id > 0)) {
1912 1912
             $user_id = get_current_user_id();
1913 1913
         }
1914 1914
 
1915
-        $supported_post_types = array( 'course', 'lesson' );
1916
-        $post_type = get_post_type( $post_id );
1917
-        if( empty( $post_id ) || empty( $data_key )
1918
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1919
-            || !get_userdata( $user_id )
1920
-            || ! in_array( $post_type, $supported_post_types )  ){
1915
+        $supported_post_types = array('course', 'lesson');
1916
+        $post_type = get_post_type($post_id);
1917
+        if (empty($post_id) || empty($data_key)
1918
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1919
+            || ! get_userdata($user_id)
1920
+            || ! in_array($post_type, $supported_post_types)) {
1921 1921
 
1922 1922
             return false;
1923 1923
         }
@@ -1925,20 +1925,20 @@  discard block
 block discarded – undo
1925 1925
         // check if there and existing Sensei status on this post type if not create it
1926 1926
         // and get the  activity ID
1927 1927
         $status_function = 'user_'.$post_type.'_status';
1928
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1929
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1928
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1929
+        if ( ! isset($sensei_user_status->comment_ID)) {
1930 1930
 
1931 1931
             $start_function = 'user_start_'.$post_type;
1932
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1932
+            $sensei_user_activity_id = self::$start_function($user_id, $post_id);
1933 1933
 
1934
-        }else{
1934
+        } else {
1935 1935
 
1936 1936
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1937 1937
 
1938 1938
         }
1939 1939
 
1940 1940
         // store the data
1941
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1941
+        $success = update_comment_meta($sensei_user_activity_id, $data_key, $value);
1942 1942
 
1943 1943
        return $success;
1944 1944
 
@@ -1957,20 +1957,20 @@  discard block
 block discarded – undo
1957 1957
      *
1958 1958
      * @return mixed $user_data_value
1959 1959
      */
1960
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1960
+    public static function get_user_data($data_key, $post_id, $user_id = 0) {
1961 1961
 
1962 1962
         $user_data_value = true;
1963 1963
 
1964
-        if( ! ( $user_id > 0 ) ){
1964
+        if ( ! ($user_id > 0)) {
1965 1965
             $user_id = get_current_user_id();
1966 1966
         }
1967 1967
 
1968
-        $supported_post_types = array( 'course', 'lesson' );
1969
-        $post_type = get_post_type( $post_id );
1970
-        if( empty( $post_id ) || empty( $data_key )
1971
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1972
-            || ! get_userdata( $user_id )
1973
-            || !in_array( $post_type, $supported_post_types )  ){
1968
+        $supported_post_types = array('course', 'lesson');
1969
+        $post_type = get_post_type($post_id);
1970
+        if (empty($post_id) || empty($data_key)
1971
+            || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1972
+            || ! get_userdata($user_id)
1973
+            || ! in_array($post_type, $supported_post_types)) {
1974 1974
 
1975 1975
             return false;
1976 1976
         }
@@ -1978,13 +1978,13 @@  discard block
 block discarded – undo
1978 1978
         // check if there and existing Sensei status on this post type if not create it
1979 1979
         // and get the  activity ID
1980 1980
         $status_function = 'user_'.$post_type.'_status';
1981
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1982
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1981
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1982
+        if ( ! isset($sensei_user_status->comment_ID)) {
1983 1983
             return false;
1984 1984
         }
1985 1985
 
1986 1986
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
1987
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
1987
+        $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true);
1988 1988
 
1989 1989
         return $user_data_value;
1990 1990
 
@@ -1999,19 +1999,19 @@  discard block
 block discarded – undo
1999 1999
      *
2000 2000
      * @return bool $deleted
2001 2001
      */
2002
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2002
+    public static function delete_user_data($data_key, $post_id, $user_id) {
2003 2003
         $deleted = true;
2004 2004
 
2005
-        if( ! ( $user_id > 0 ) ){
2005
+        if ( ! ($user_id > 0)) {
2006 2006
             $user_id = get_current_user_id();
2007 2007
         }
2008 2008
 
2009
-        $supported_post_types = array( 'course', 'lesson' );
2010
-        $post_type = get_post_type( $post_id );
2011
-        if( empty( $post_id ) || empty( $data_key )
2012
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2013
-            || ! get_userdata( $user_id )
2014
-            || !in_array( $post_type, $supported_post_types )  ){
2009
+        $supported_post_types = array('course', 'lesson');
2010
+        $post_type = get_post_type($post_id);
2011
+        if (empty($post_id) || empty($data_key)
2012
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2013
+            || ! get_userdata($user_id)
2014
+            || ! in_array($post_type, $supported_post_types)) {
2015 2015
 
2016 2016
             return false;
2017 2017
         }
@@ -2019,13 +2019,13 @@  discard block
 block discarded – undo
2019 2019
         // check if there and existing Sensei status on this post type if not create it
2020 2020
         // and get the  activity ID
2021 2021
         $status_function = 'user_'.$post_type.'_status';
2022
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2023
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2022
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2023
+        if ( ! isset($sensei_user_status->comment_ID)) {
2024 2024
             return false;
2025 2025
         }
2026 2026
 
2027 2027
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2028
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2028
+        $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
2029 2029
 
2030 2030
         return $deleted;
2031 2031
 
@@ -2050,62 +2050,62 @@  discard block
 block discarded – undo
2050 2050
      *
2051 2051
      * @return string $drop_down_element
2052 2052
      */
2053
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2053
+    public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) {
2054 2054
 
2055 2055
         $drop_down_element = '';
2056 2056
 
2057 2057
         // setup the basic attributes
2058
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2058
+        if ( ! isset($attributes['name']) || empty($attributes['name'])) {
2059 2059
 
2060 2060
             $attributes['name'] = 'sensei-options';
2061 2061
 
2062 2062
         }
2063 2063
 
2064
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2064
+        if ( ! isset($attributes['id']) || empty($attributes['id'])) {
2065 2065
 
2066 2066
             $attributes['id'] = 'sensei-options';
2067 2067
 
2068 2068
         }
2069 2069
 
2070
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2070
+        if ( ! isset($attributes['class']) || empty($attributes['class'])) {
2071 2071
 
2072
-            $attributes['class'] ='chosen_select widefat';
2072
+            $attributes['class'] = 'chosen_select widefat';
2073 2073
 
2074 2074
         }
2075 2075
 
2076 2076
         // create element attributes
2077 2077
         $combined_attributes = '';
2078
-        foreach( $attributes as $attribute => $value ){
2078
+        foreach ($attributes as $attribute => $value) {
2079 2079
 
2080
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2080
+            $combined_attributes .= $attribute.'="'.$value.'"'.' ';
2081 2081
 
2082 2082
         }// end for each
2083 2083
 
2084 2084
 
2085 2085
         // create the select element
2086
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2086
+        $drop_down_element .= '<select '.$combined_attributes.' >'."\n";
2087 2087
 
2088 2088
         // show the none option if the client requested
2089
-        if( $enable_none_option ) {
2090
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2089
+        if ($enable_none_option) {
2090
+            $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
2091 2091
         }
2092 2092
 
2093
-        if ( count( $options ) > 0 ) {
2093
+        if (count($options) > 0) {
2094 2094
 
2095
-            foreach ($options as $value => $option ){
2095
+            foreach ($options as $value => $option) {
2096 2096
 
2097 2097
                 $element = '';
2098
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2099
-                $element .= selected( $value, $selected_value, false ) . '>';
2100
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2098
+                $element .= '<option value="'.esc_attr($value).'"';
2099
+                $element .= selected($value, $selected_value, false).'>';
2100
+                $element .= esc_html($option).'</option>'."\n";
2101 2101
 
2102 2102
                 // add the element to the select html
2103
-                $drop_down_element.= $element;
2103
+                $drop_down_element .= $element;
2104 2104
             } // End For Loop
2105 2105
 
2106 2106
         } // End If Statement
2107 2107
 
2108
-        $drop_down_element .= '</select>' . "\n";
2108
+        $drop_down_element .= '</select>'."\n";
2109 2109
 
2110 2110
         return $drop_down_element;
2111 2111
 
@@ -2125,14 +2125,14 @@  discard block
 block discarded – undo
2125 2125
      *
2126 2126
      * @return double $val
2127 2127
      */
2128
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2128
+    public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') {
2129 2129
 
2130 2130
         /**å
2131 2131
          * Change the precision for the Sensei_Utils::round function.
2132 2132
          * the precision given will be passed into the php round function
2133 2133
          * @since 1.8.5
2134 2134
          */
2135
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2135
+        $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode);
2136 2136
 
2137 2137
         /**
2138 2138
          * Change the mode for the Sensei_Utils::round function.
@@ -2142,15 +2142,15 @@  discard block
 block discarded – undo
2142 2142
          *
2143 2143
          * @since 1.8.5
2144 2144
          */
2145
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2145
+        $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision);
2146 2146
 
2147
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2147
+        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
2148 2148
 
2149
-            return round( $val, $precision, $mode );
2149
+            return round($val, $precision, $mode);
2150 2150
 
2151
-        }else{
2151
+        } else {
2152 2152
 
2153
-            return round( $val, $precision );
2153
+            return round($val, $precision);
2154 2154
 
2155 2155
         }
2156 2156
 
@@ -2162,15 +2162,15 @@  discard block
 block discarded – undo
2162 2162
      * @since 1.9.0
2163 2163
      * @return string $url
2164 2164
      */
2165
-    public static function get_current_url(){
2165
+    public static function get_current_url() {
2166 2166
 
2167 2167
         global $wp;
2168
-        $current_url = trailingslashit( home_url( $wp->request ) );
2169
-        if ( isset( $_GET ) ) {
2168
+        $current_url = trailingslashit(home_url($wp->request));
2169
+        if (isset($_GET)) {
2170 2170
 
2171
-            foreach ($_GET as $param => $val ) {
2171
+            foreach ($_GET as $param => $val) {
2172 2172
 
2173
-                $current_url = add_query_arg( $param, $val , $current_url );
2173
+                $current_url = add_query_arg($param, $val, $current_url);
2174 2174
 
2175 2175
             }
2176 2176
         }
@@ -2200,27 +2200,27 @@  discard block
 block discarded – undo
2200 2200
      * @param array $array_b
2201 2201
      * @return array $merged_array
2202 2202
      */
2203
-    public static function array_zip_merge( $array_a, $array_b ){
2203
+    public static function array_zip_merge($array_a, $array_b) {
2204 2204
 
2205
-        if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2205
+        if ( ! isset($array_a[0]) || ! isset($array_b[0])) {
2206 2206
             trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2207 2207
         }
2208 2208
 
2209 2209
         $merged_array = array();
2210
-        $total_elements = count( $array_a )  + count( $array_b );
2210
+        $total_elements = count($array_a) + count($array_b);
2211 2211
 
2212 2212
         // Zip arrays
2213
-        for ( $i = 0; $i < $total_elements; $i++) {
2213
+        for ($i = 0; $i < $total_elements; $i++) {
2214 2214
 
2215 2215
             // if has an element at current index push a on top
2216
-            if( isset( $array_a[ $i ] ) ){
2217
-                $merged_array[] = $array_a[ $i ]  ;
2216
+            if (isset($array_a[$i])) {
2217
+                $merged_array[] = $array_a[$i];
2218 2218
             }
2219 2219
 
2220 2220
             // next if $array_b has an element at current index push a on top of the element
2221 2221
             // from a if there was one, if not the element before that.
2222
-            if( isset( $array_b[ $i ] ) ){
2223
-                $merged_array[] = $array_b[ $i ]  ;
2222
+            if (isset($array_b[$i])) {
2223
+                $merged_array[] = $array_b[$i];
2224 2224
             }
2225 2225
 
2226 2226
         }
@@ -2235,4 +2235,4 @@  discard block
 block discarded – undo
2235 2235
  * @ignore only for backward compatibility
2236 2236
  * @since 1.9.0
2237 2237
  */
2238
-class WooThemes_Sensei_Utils extends Sensei_Utils{}
2239 2238
\ No newline at end of file
2239
+class WooThemes_Sensei_Utils extends Sensei_Utils {}
2240 2240
\ No newline at end of file
Please login to merge, or discard this patch.