Completed
Push — master ( 201c1b...d51ce1 )
by Dwain
04:57
created
apigen/hook-docs.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -10,6 +10,9 @@
 block discarded – undo
10 10
 	private static $found_files            = array();
11 11
 	private static $custom_hooks_found     = '';
12 12
 
13
+	/**
14
+	 * @param string $pattern
15
+	 */
13 16
 	private static function get_files( $pattern, $flags = 0, $path = '' ) {
14 17
 
15 18
 	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -12,20 +12,20 @@  discard block
 block discarded – undo
12 12
 
13 13
 	private static function get_files( $pattern, $flags = 0, $path = '' ) {
14 14
 
15
-	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
15
+		if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
16 16
 
17
-	        if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement
17
+			if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement
18 18
 
19
-	        return self::get_files(basename( $pattern ), $flags, $dir . '/' );
19
+			return self::get_files(basename( $pattern ), $flags, $dir . '/' );
20 20
 
21
-	    } // End IF Statement
21
+		} // End IF Statement
22 22
 
23
-	    $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
24
-	    $files = glob( $path . $pattern, $flags );
23
+		$paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
24
+		$files = glob( $path . $pattern, $flags );
25 25
 
26
-	    if ( is_array( $paths ) ) {
27
-		    foreach ( $paths as $p ) {
28
-			    $found_files = array();
26
+		if ( is_array( $paths ) ) {
27
+			foreach ( $paths as $p ) {
28
+				$found_files = array();
29 29
 		   		$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
30 30
 		   		foreach ( $retrieved_files as $file ) {
31 31
 			   		if ( ! in_array( $file, self::$found_files ) )
@@ -38,10 +38,10 @@  discard block
 block discarded – undo
38 38
 		   			$files = array_merge( $files, $found_files );
39 39
 		   		}
40 40
 
41
-		    } // End FOREACH Loop
42
-	    }
43
-	    return $files;
44
-    }
41
+			} // End FOREACH Loop
42
+		}
43
+		return $files;
44
+	}
45 45
 
46 46
 	private static function get_hook_link( $hook, $details = array() ) {
47 47
 		if ( ! empty( $details['class'] ) ) {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 									if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
127 127
 										self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
128 128
 									} else {
129
-    									self::$custom_hooks_found[ $hook ] = array(
129
+										self::$custom_hooks_found[ $hook ] = array(
130 130
 											'line'     => $token[2],
131 131
 											'class'    => $current_class,
132 132
 											'function' => $current_function,
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -10,32 +10,32 @@  discard block
 block discarded – undo
10 10
 	private static $found_files            = array();
11 11
 	private static $custom_hooks_found     = '';
12 12
 
13
-	private static function get_files( $pattern, $flags = 0, $path = '' ) {
13
+	private static function get_files($pattern, $flags = 0, $path = '') {
14 14
 
15
-	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
15
+	    if ( ! $path && ($dir = dirname($pattern)) != '.') {
16 16
 
17 17
 	        if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement
18 18
 
19
-	        return self::get_files(basename( $pattern ), $flags, $dir . '/' );
19
+	        return self::get_files(basename($pattern), $flags, $dir.'/');
20 20
 
21 21
 	    } // End IF Statement
22 22
 
23
-	    $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
24
-	    $files = glob( $path . $pattern, $flags );
23
+	    $paths = glob($path.'*', GLOB_ONLYDIR | GLOB_NOSORT);
24
+	    $files = glob($path.$pattern, $flags);
25 25
 
26
-	    if ( is_array( $paths ) ) {
27
-		    foreach ( $paths as $p ) {
26
+	    if (is_array($paths)) {
27
+		    foreach ($paths as $p) {
28 28
 			    $found_files = array();
29
-		   		$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
30
-		   		foreach ( $retrieved_files as $file ) {
31
-			   		if ( ! in_array( $file, self::$found_files ) )
29
+		   		$retrieved_files = (array) self::get_files($pattern, $flags, $p.'/');
30
+		   		foreach ($retrieved_files as $file) {
31
+			   		if ( ! in_array($file, self::$found_files))
32 32
 			   			$found_files[] = $file;
33 33
 		   		}
34 34
 
35
-		   		self::$found_files = array_merge( self::$found_files, $found_files );
35
+		   		self::$found_files = array_merge(self::$found_files, $found_files);
36 36
 
37
-		   		if ( is_array( $files ) && is_array( $found_files ) ) {
38
-		   			$files = array_merge( $files, $found_files );
37
+		   		if (is_array($files) && is_array($found_files)) {
38
+		   			$files = array_merge($files, $found_files);
39 39
 		   		}
40 40
 
41 41
 		    } // End FOREACH Loop
@@ -43,29 +43,29 @@  discard block
 block discarded – undo
43 43
 	    return $files;
44 44
     }
45 45
 
46
-	private static function get_hook_link( $hook, $details = array() ) {
47
-		if ( ! empty( $details['class'] ) ) {
48
-			$link = 'http://docs.woothemes.com/wc-apidocs/source-class-' . $details['class'] . '.html#' . $details['line'];
49
-		} elseif ( ! empty( $details['function'] ) ) {
50
-			$link = 'http://docs.woothemes.com/wc-apidocs/source-function-' . $details['function'] . '.html#' . $details['line'];
46
+	private static function get_hook_link($hook, $details = array()) {
47
+		if ( ! empty($details['class'])) {
48
+			$link = 'http://docs.woothemes.com/wc-apidocs/source-class-'.$details['class'].'.html#'.$details['line'];
49
+		} elseif ( ! empty($details['function'])) {
50
+			$link = 'http://docs.woothemes.com/wc-apidocs/source-function-'.$details['function'].'.html#'.$details['line'];
51 51
 		} else {
52
-			$link = 'https://github.com/woothemes/woocommerce/search?utf8=%E2%9C%93&q=' . $hook;
52
+			$link = 'https://github.com/woothemes/woocommerce/search?utf8=%E2%9C%93&q='.$hook;
53 53
 		}
54 54
 
55
-		return '<a href="' . $link . '">' . $hook . '</a>';
55
+		return '<a href="'.$link.'">'.$hook.'</a>';
56 56
 	}
57 57
 
58 58
 	public static function process_hooks() {
59 59
 		// If we have one, get the PHP files from it.
60
-		$template_files 	= self::get_files( '*.php', GLOB_MARK, '../templates/' );
60
+		$template_files = self::get_files('*.php', GLOB_MARK, '../templates/');
61 61
 		$template_files[]	= '../includes/wc-template-functions.php';
62 62
 		$template_files[]	= '../includes/wc-template-hooks.php';
63 63
 
64
-		$shortcode_files 	= self::get_files( '*.php', GLOB_MARK, '../includes/shortcodes/' );
65
-		$widget_files	 	= self::get_files( '*.php', GLOB_MARK, '../includes/widgets/' );
66
-		$admin_files 		= self::get_files( '*.php', GLOB_MARK, '../includes/admin/' );
67
-		$class_files 		= self::get_files( '*.php', GLOB_MARK, '../includes/' );
68
-		$other_files		= array(
64
+		$shortcode_files 	= self::get_files('*.php', GLOB_MARK, '../includes/shortcodes/');
65
+		$widget_files = self::get_files('*.php', GLOB_MARK, '../includes/widgets/');
66
+		$admin_files 		= self::get_files('*.php', GLOB_MARK, '../includes/admin/');
67
+		$class_files 		= self::get_files('*.php', GLOB_MARK, '../includes/');
68
+		$other_files = array(
69 69
 			'../woocommerce.php'
70 70
 		);
71 71
 
@@ -86,34 +86,34 @@  discard block
 block discarded – undo
86 86
 		echo '<h1>Action and Filter Hook Reference</h1>';
87 87
 		echo '<div class="description"><p>The following is a full list of actions and filters found in WooCommerce core.</p></div>';
88 88
 
89
-		foreach ( self::$files_to_scan as $heading => $files ) {
89
+		foreach (self::$files_to_scan as $heading => $files) {
90 90
 			self::$custom_hooks_found = array();
91 91
 
92
-			foreach ( $files as $f ) {
93
-				self::$current_file = basename( $f );
94
-				$tokens             = token_get_all( file_get_contents( $f ) );
92
+			foreach ($files as $f) {
93
+				self::$current_file = basename($f);
94
+				$tokens             = token_get_all(file_get_contents($f));
95 95
 				$token_type         = false;
96 96
 				$current_class      = '';
97 97
 				$current_function   = '';
98 98
 
99
-				if ( in_array( self::$current_file, $scanned ) ) {
99
+				if (in_array(self::$current_file, $scanned)) {
100 100
 					continue;
101 101
 				}
102 102
 
103 103
 				$scanned[] = self::$current_file;
104 104
 
105
-				foreach ( $tokens as $index => $token ) {
106
-					if ( is_array( $token ) ) {
107
-						if ( $token[0] == T_CLASS ) {
105
+				foreach ($tokens as $index => $token) {
106
+					if (is_array($token)) {
107
+						if ($token[0] == T_CLASS) {
108 108
 							$token_type = 'class';
109
-						} elseif ( $token[0] == T_FUNCTION ) {
109
+						} elseif ($token[0] == T_FUNCTION) {
110 110
 							$token_type = 'function';
111
-						} elseif ( $token[1] === 'do_action' ) {
111
+						} elseif ($token[1] === 'do_action') {
112 112
 							$token_type = 'action';
113
-						} elseif ( $token[1] === 'apply_filters' ) {
113
+						} elseif ($token[1] === 'apply_filters') {
114 114
 							$token_type = 'filter';
115
-						} elseif ( $token_type && ! empty( trim( $token[1] ) ) ) {
116
-							switch ( $token_type ) {
115
+						} elseif ($token_type && ! empty(trim($token[1]))) {
116
+							switch ($token_type) {
117 117
 								case 'class' :
118 118
 									$current_class = $token[1];
119 119
 								break;
@@ -122,15 +122,15 @@  discard block
 block discarded – undo
122 122
 								break;
123 123
 								case 'filter' :
124 124
 								case 'action' :
125
-									$hook = trim( $token[1], "'" );
126
-									if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
127
-										self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
125
+									$hook = trim($token[1], "'");
126
+									if (isset(self::$custom_hooks_found[$hook])) {
127
+										self::$custom_hooks_found[$hook]['file'][] = self::$current_file;
128 128
 									} else {
129
-    									self::$custom_hooks_found[ $hook ] = array(
129
+    									self::$custom_hooks_found[$hook] = array(
130 130
 											'line'     => $token[2],
131 131
 											'class'    => $current_class,
132 132
 											'function' => $current_function,
133
-											'file'     => array( self::$current_file ),
133
+											'file'     => array(self::$current_file),
134 134
 											'type'     => $token_type
135 135
 										);
136 136
 									}
@@ -142,24 +142,24 @@  discard block
 block discarded – undo
142 142
 				}
143 143
 			}
144 144
 
145
-			foreach ( self::$custom_hooks_found as $hook => $details ) {
146
-				if ( ! strstr( $hook, 'woocommerce' ) && ! strstr( $hook, 'product' ) && ! strstr( $hook, 'wc_' ) ) {
147
-					unset( self::$custom_hooks_found[ $hook ] );
145
+			foreach (self::$custom_hooks_found as $hook => $details) {
146
+				if ( ! strstr($hook, 'woocommerce') && ! strstr($hook, 'product') && ! strstr($hook, 'wc_')) {
147
+					unset(self::$custom_hooks_found[$hook]);
148 148
 				}
149 149
 			}
150 150
 
151
-			ksort( self::$custom_hooks_found );
151
+			ksort(self::$custom_hooks_found);
152 152
 
153
-			if ( ! empty( self::$custom_hooks_found ) ) {
154
-				echo '<h2>' . $heading . '</h2>';
153
+			if ( ! empty(self::$custom_hooks_found)) {
154
+				echo '<h2>'.$heading.'</h2>';
155 155
 
156 156
 				echo '<table class="summary"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>';
157 157
 
158
-				foreach ( self::$custom_hooks_found as $hook => $details ) {
158
+				foreach (self::$custom_hooks_found as $hook => $details) {
159 159
 					echo '<tr>
160
-						<td>' . self::get_hook_link( $hook, $details ) . '</td>
161
-						<td>' . $details['type'] . '</td>
162
-						<td>' . implode( ', ', array_unique( $details['file'] ) ) . '</td>
160
+						<td>' . self::get_hook_link($hook, $details).'</td>
161
+						<td>' . $details['type'].'</td>
162
+						<td>' . implode(', ', array_unique($details['file'])).'</td>
163 163
 					</tr>' . "\n";
164 164
 				}
165 165
 
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
 
170 170
 		echo '</div><div id="footer">';
171 171
 
172
-		$html   = file_get_contents( '../wc-apidocs/todo.html' );
173
-		$header = current( explode( '<div id="content">', $html ) );
174
-		$header = str_replace( '<li class="active">', '<li>', $header );
175
-		$header = str_replace( '<li class="hooks">', '<li class="active">', $header );
176
-		$footer = end( explode( '<div id="footer">', $html ) );
172
+		$html   = file_get_contents('../wc-apidocs/todo.html');
173
+		$header = current(explode('<div id="content">', $html));
174
+		$header = str_replace('<li class="active">', '<li>', $header);
175
+		$header = str_replace('<li class="hooks">', '<li class="active">', $header);
176
+		$footer = end(explode('<div id="footer">', $html));
177 177
 
178
-		file_put_contents( '../wc-apidocs/hook-docs.html', $header . ob_get_clean() . $footer );
178
+		file_put_contents('../wc-apidocs/hook-docs.html', $header.ob_get_clean().$footer);
179 179
 		echo "Hook docs generated :)\n";
180 180
 	}
181 181
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,8 +28,9 @@
 block discarded – undo
28 28
 			    $found_files = array();
29 29
 		   		$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
30 30
 		   		foreach ( $retrieved_files as $file ) {
31
-			   		if ( ! in_array( $file, self::$found_files ) )
32
-			   			$found_files[] = $file;
31
+			   		if ( ! in_array( $file, self::$found_files ) ) {
32
+			   					   			$found_files[] = $file;
33
+			   		}
33 34
 		   		}
34 35
 
35 36
 		   		self::$found_files = array_merge( self::$found_files, $found_files );
Please login to merge, or discard this patch.
includes/class-sensei-analysis.php 4 patches
Doc Comments   +8 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,6 +21,7 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	 * Constructor
23 23
 	 * @since  1.0.0
24
+	 * @param string $file
24 25
 	 * @return  void
25 26
 	 */
26 27
 	public function __construct ( $file ) {
@@ -215,6 +216,7 @@  discard block
 block discarded – undo
215 216
 	/**
216 217
 	 * An individual users' profile view for analysis, showing their Courses
217 218
 	 * @since  1.2.0
219
+	 * @param integer $user_id
218 220
 	 * @return void
219 221
 	 */
220 222
 	public function analysis_user_profile_view( $user_id ) {
@@ -242,6 +244,7 @@  discard block
 block discarded – undo
242 244
 	/**
243 245
 	 * An individual Course view for analysis, showing the Courses Lessons
244 246
 	 * @since  1.2.0
247
+	 * @param integer $course_id
245 248
 	 * @return void
246 249
 	 */
247 250
 	public function analysis_course_view( $course_id ) {
@@ -269,6 +272,8 @@  discard block
 block discarded – undo
269 272
 	/**
270 273
 	 * An individual Course view for analysis, showing a specific Learners Lessons
271 274
 	 * @since  1.2.0
275
+	 * @param integer $course_id
276
+	 * @param integer $user_id
272 277
 	 * @return void
273 278
 	 */
274 279
 	public function analysis_user_course_view( $course_id, $user_id ) {
@@ -296,6 +301,7 @@  discard block
 block discarded – undo
296 301
 	/**
297 302
 	 * An individual Course view for analysis, showing all the Learners
298 303
 	 * @since  1.2.0
304
+	 * @param integer $course_id
299 305
 	 * @return void
300 306
 	 */
301 307
 	public function analysis_course_users_view( $course_id ) {
@@ -323,6 +329,7 @@  discard block
 block discarded – undo
323 329
 	/**
324 330
 	 * An individual Lesson view for analysis, showing all the Learners
325 331
 	 * @since  1.2.0
332
+	 * @param integer $lesson_id
326 333
 	 * @return void
327 334
 	 */
328 335
 	public function analysis_lesson_users_view( $lesson_id ) {
@@ -633,7 +640,7 @@  discard block
 block discarded – undo
633 640
 	/**
634 641
 	 * Write array data to CSV
635 642
 	 * @since  1.2.0
636
-	 * @param  array  $report_array data array
643
+	 * @param  array  $report_data data array
637 644
 	 * @return void
638 645
 	 */
639 646
 	public function report_write_download( $report_data = array() ) {
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
 		if ( current_user_can( 'manage_sensei_grades' ) ) {
57 57
 
58
-            add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) );
58
+			add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) );
59 59
 
60 60
 		}
61 61
 
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 									'analysis-lesson'
106 106
 									);
107 107
 		foreach ( $classes_to_load as $class_file ) {
108
-            Sensei()->load_class( $class_file );
108
+			Sensei()->load_class( $class_file );
109 109
 		} // End For Loop
110 110
 	} // End load_data_table_files()
111 111
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 
444 444
 			$user_id = intval( $_GET['user_id'] );
445 445
 			$url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) );
446
-            $user_name = Sensei()->learners->get_learner_full_name( $user_id );
446
+			$user_name = Sensei()->learners->get_learner_full_name( $user_id );
447 447
 			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
448 448
 
449 449
 		} // End If Statement
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 			$user_id = intval( $_GET['user_id'] );
465 465
 			$user_data = get_userdata( $user_id );
466 466
 			$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) );
467
-            $user_name = Sensei()->learners->get_learner_full_name( $user_id );
468
-            $title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
467
+			$user_name = Sensei()->learners->get_learner_full_name( $user_id );
468
+			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
469 469
 			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name );
470 470
 		} // End If Statement
471 471
 		if ( isset( $_GET['course_id'] ) ) { 
Please login to merge, or discard this patch.
Spacing   +185 added lines, -185 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 Analysis Class
@@ -23,23 +23,23 @@  discard block
 block discarded – undo
23 23
 	 * @since  1.0.0
24 24
 	 * @return  void
25 25
 	 */
26
-	public function __construct ( $file ) {
26
+	public function __construct($file) {
27 27
 		$this->name = __('Analysis', 'woothemes-sensei');
28 28
 		$this->file = $file;
29 29
 		$this->page_slug = 'sensei_analysis';
30 30
 
31 31
 		// Admin functions
32
-		if ( is_admin() ) {
33
-			add_action( 'admin_menu', array( $this, 'analysis_admin_menu' ), 10);
34
-			add_action( 'analysis_wrapper_container', array( $this, 'wrapper_container'  ) );
35
-			if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
36
-				add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
37
-				add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
32
+		if (is_admin()) {
33
+			add_action('admin_menu', array($this, 'analysis_admin_menu'), 10);
34
+			add_action('analysis_wrapper_container', array($this, 'wrapper_container'));
35
+			if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
36
+				add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
37
+				add_action('admin_print_styles', array($this, 'enqueue_styles'));
38 38
 			}
39 39
 
40
-			add_action( 'admin_init', array( $this, 'report_download_page' ) );
40
+			add_action('admin_init', array($this, 'report_download_page'));
41 41
 
42
-			add_filter( 'user_search_columns', array( $this, 'user_search_columns_filter' ), 10, 3 );
42
+			add_filter('user_search_columns', array($this, 'user_search_columns_filter'), 10, 3);
43 43
 		} // End If Statement
44 44
 	} // End __construct()
45 45
 
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	public function analysis_admin_menu() {
54 54
 		global $menu, $woocommerce;
55 55
 
56
-		if ( current_user_can( 'manage_sensei_grades' ) ) {
56
+		if (current_user_can('manage_sensei_grades')) {
57 57
 
58
-            add_submenu_page( 'sensei', __('Analysis', 'woothemes-sensei'),  __('Analysis', 'woothemes-sensei') , 'manage_sensei_grades', 'sensei_analysis', array( $this, 'analysis_page' ) );
58
+            add_submenu_page('sensei', __('Analysis', 'woothemes-sensei'), __('Analysis', 'woothemes-sensei'), 'manage_sensei_grades', 'sensei_analysis', array($this, 'analysis_page'));
59 59
 
60 60
 		}
61 61
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @since 1.0.0
70 70
 	 * @return void
71 71
 	 */
72
-	public function enqueue_scripts () {
72
+	public function enqueue_scripts() {
73 73
 		// None for now
74 74
 
75 75
 	} // End enqueue_scripts()
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 	 * @since 1.0.0
83 83
 	 * @return void
84 84
 	 */
85
-	public function enqueue_styles () {
85
+	public function enqueue_styles() {
86 86
 
87
-		wp_enqueue_style( Sensei()->token . '-admin' );
87
+		wp_enqueue_style(Sensei()->token.'-admin');
88 88
 
89
-		wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version );
89
+		wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version);
90 90
 
91 91
 	} // End enqueue_styles()
92 92
 
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
 	public function load_data_table_files() {
99 99
 
100 100
 		// Load Analysis Classes
101
-		$classes_to_load = array(	'list-table',
101
+		$classes_to_load = array('list-table',
102 102
 									'analysis-overview',
103 103
 									'analysis-user-profile',
104 104
 									'analysis-course',
105 105
 									'analysis-lesson'
106 106
 									);
107
-		foreach ( $classes_to_load as $class_file ) {
108
-            Sensei()->load_class( $class_file );
107
+		foreach ($classes_to_load as $class_file) {
108
+            Sensei()->load_class($class_file);
109 109
 		} // End For Loop
110 110
 	} // End load_data_table_files()
111 111
 
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
 	 * @param  undefined  $optional_data optional constructor arguments
117 117
 	 * @return object                 class instance object
118 118
 	 */
119
-	public function load_data_object( $name = '', $data = 0, $optional_data = null ) {
119
+	public function load_data_object($name = '', $data = 0, $optional_data = null) {
120 120
 		// Load Analysis data
121
-		$object_name = 'WooThemes_Sensei_Analysis_' . $name . '_List_Table';
122
-		if ( is_null($optional_data) ) {
123
-			$sensei_analysis_object = new $object_name( $data );
121
+		$object_name = 'WooThemes_Sensei_Analysis_'.$name.'_List_Table';
122
+		if (is_null($optional_data)) {
123
+			$sensei_analysis_object = new $object_name($data);
124 124
 		} else {
125
-			$sensei_analysis_object = new $object_name( $data, $optional_data );
125
+			$sensei_analysis_object = new $object_name($data, $optional_data);
126 126
 		}
127 127
 		$sensei_analysis_object->prepare_items();
128 128
 		return $sensei_analysis_object;
@@ -139,40 +139,40 @@  discard block
 block discarded – undo
139 139
 		$course_id = 0;
140 140
 		$lesson_id = 0;
141 141
 		$user_id = 0;
142
-		if( isset( $_GET['course_id'] ) ) {
143
-			$course_id = intval( $_GET['course_id'] );
142
+		if (isset($_GET['course_id'])) {
143
+			$course_id = intval($_GET['course_id']);
144 144
 		}
145
-		if( isset( $_GET['lesson_id'] ) ) {
146
-			$lesson_id = intval( $_GET['lesson_id'] );
145
+		if (isset($_GET['lesson_id'])) {
146
+			$lesson_id = intval($_GET['lesson_id']);
147 147
 		}
148
-		if( isset( $_GET['user_id'] ) ) {
149
-			$user_id = intval( $_GET['user_id'] );
148
+		if (isset($_GET['user_id'])) {
149
+			$user_id = intval($_GET['user_id']);
150 150
 		}
151
-		$type = isset( $_GET['view'] ) ? esc_html( $_GET['view'] ) : false;
151
+		$type = isset($_GET['view']) ? esc_html($_GET['view']) : false;
152 152
 
153
-		if ( 0 < $lesson_id ) {
153
+		if (0 < $lesson_id) {
154 154
 			// Viewing a specific Lesson and all its Learners
155
-			$this->analysis_lesson_users_view( $lesson_id );
155
+			$this->analysis_lesson_users_view($lesson_id);
156 156
 		}
157
-		elseif ( 0 < $course_id && !$user_id && 'user' == $type ) {
157
+		elseif (0 < $course_id && ! $user_id && 'user' == $type) {
158 158
 			// Viewing a specific Course and all its Learners
159
-			$this->analysis_course_users_view( $course_id );
159
+			$this->analysis_course_users_view($course_id);
160 160
 		}
161
-		elseif ( 0 < $course_id && 0 < $user_id ) {
161
+		elseif (0 < $course_id && 0 < $user_id) {
162 162
 			// Viewing a specific Learner on a specific Course, showing their Lessons
163
-			$this->analysis_user_course_view( $course_id, $user_id );
163
+			$this->analysis_user_course_view($course_id, $user_id);
164 164
 		}
165
-		elseif( 0 < $course_id ) {
165
+		elseif (0 < $course_id) {
166 166
 			// Viewing a specific Course and all it's Lessons
167
-			$this->analysis_course_view( $course_id );
167
+			$this->analysis_course_view($course_id);
168 168
 		}
169
-		elseif ( 0 < $user_id ) {
169
+		elseif (0 < $user_id) {
170 170
 			// Viewing a specific Learner, and their Courses
171
-			$this->analysis_user_profile_view( $user_id );
171
+			$this->analysis_user_profile_view($user_id);
172 172
 		}
173 173
 		else {
174 174
 			// Overview of all Learners, all Courses, or all Lessons
175
-			$this->analysis_default_view( $type );
175
+			$this->analysis_default_view($type);
176 176
 		} // End If Statement
177 177
 	} // End analysis_page()
178 178
 
@@ -181,35 +181,35 @@  discard block
 block discarded – undo
181 181
 	 * @since  1.2.0
182 182
 	 * @return void
183 183
 	 */
184
-	public function analysis_default_view( $type ) {
184
+	public function analysis_default_view($type) {
185 185
 
186 186
 		// Load Analysis data
187
-		$sensei_analysis_overview = $this->load_data_object( 'Overview', $type );
187
+		$sensei_analysis_overview = $this->load_data_object('Overview', $type);
188 188
 		// Wrappers
189
-		do_action( 'analysis_before_container' );
190
-		do_action( 'analysis_wrapper_container', 'top' );
189
+		do_action('analysis_before_container');
190
+		do_action('analysis_wrapper_container', 'top');
191 191
 		$this->analysis_headers();
192 192
 		?>
193 193
 		<div id="poststuff" class="sensei-analysis-wrap">
194 194
 			<div class="sensei-analysis-sidebar">
195 195
 				<?php
196
-				do_action( 'sensei_analysis_before_stats_boxes' );
197
-				foreach ( $sensei_analysis_overview->stats_boxes() as $key => $value ) {
198
-					$this->render_stats_box( esc_html( $key ), esc_html( $value ) );
196
+				do_action('sensei_analysis_before_stats_boxes');
197
+				foreach ($sensei_analysis_overview->stats_boxes() as $key => $value) {
198
+					$this->render_stats_box(esc_html($key), esc_html($value));
199 199
 				} // End For Loop
200
-				do_action( 'sensei_analysis_after_stats_boxes' );
200
+				do_action('sensei_analysis_after_stats_boxes');
201 201
 				?>
202 202
 			</div>
203 203
 			<div class="sensei-analysis-main">
204 204
 				<?php $sensei_analysis_overview->display(); ?>
205 205
 			</div>
206 206
 			<div class="sensei-analysis-extra">
207
-				<?php do_action( 'sensei_analysis_extra' ); ?>
207
+				<?php do_action('sensei_analysis_extra'); ?>
208 208
 			</div>
209 209
 		</div>
210 210
 		<?php
211
-		do_action( 'analysis_wrapper_container', 'bottom' );
212
-		do_action( 'analysis_after_container' );
211
+		do_action('analysis_wrapper_container', 'bottom');
212
+		do_action('analysis_after_container');
213 213
 	} // End analysis_default_view()
214 214
 
215 215
 	/**
@@ -217,26 +217,26 @@  discard block
 block discarded – undo
217 217
 	 * @since  1.2.0
218 218
 	 * @return void
219 219
 	 */
220
-	public function analysis_user_profile_view( $user_id ) {
220
+	public function analysis_user_profile_view($user_id) {
221 221
 
222 222
 		// Load Analysis data
223
-		$sensei_analysis_user_profile = $this->load_data_object( 'User_Profile', $user_id );
223
+		$sensei_analysis_user_profile = $this->load_data_object('User_Profile', $user_id);
224 224
 		// Wrappers
225
-		do_action( 'analysis_before_container' );
226
-		do_action( 'analysis_wrapper_container', 'top' );
227
-		$this->analysis_headers( array( 'nav' => 'user_profile' ) );
225
+		do_action('analysis_before_container');
226
+		do_action('analysis_wrapper_container', 'top');
227
+		$this->analysis_headers(array('nav' => 'user_profile'));
228 228
 		?>
229 229
 		<div id="poststuff" class="sensei-analysis-wrap user-profile">
230 230
 			<div class="sensei-analysis-main">
231 231
 				<?php $sensei_analysis_user_profile->display(); ?>
232 232
 			</div>
233 233
 			<div class="sensei-analysis-extra">
234
-				<?php do_action( 'sensei_analysis_extra' ); ?>
234
+				<?php do_action('sensei_analysis_extra'); ?>
235 235
 			</div>
236 236
 		</div>
237 237
 		<?php
238
-		do_action( 'analysis_wrapper_container', 'bottom' );
239
-		do_action( 'analysis_after_container' );
238
+		do_action('analysis_wrapper_container', 'bottom');
239
+		do_action('analysis_after_container');
240 240
 	} // End analysis_user_profile_view()
241 241
 
242 242
 	/**
@@ -244,26 +244,26 @@  discard block
 block discarded – undo
244 244
 	 * @since  1.2.0
245 245
 	 * @return void
246 246
 	 */
247
-	public function analysis_course_view( $course_id ) {
247
+	public function analysis_course_view($course_id) {
248 248
 
249 249
 		// Load Analysis data
250
-		$sensei_analysis_course = $this->load_data_object( 'Course', $course_id );
250
+		$sensei_analysis_course = $this->load_data_object('Course', $course_id);
251 251
 		// Wrappers
252
-		do_action( 'analysis_before_container' );
253
-		do_action( 'analysis_wrapper_container', 'top' );
254
-		$this->analysis_headers( array( 'nav' => 'course' ) );
252
+		do_action('analysis_before_container');
253
+		do_action('analysis_wrapper_container', 'top');
254
+		$this->analysis_headers(array('nav' => 'course'));
255 255
 		?>
256 256
 		<div id="poststuff" class="sensei-analysis-wrap course-profile">
257 257
 			<div class="sensei-analysis-main">
258 258
 				<?php $sensei_analysis_course->display(); ?>
259 259
 			</div>
260 260
 			<div class="sensei-analysis-extra">
261
-				<?php do_action( 'sensei_analysis_extra' ); ?>
261
+				<?php do_action('sensei_analysis_extra'); ?>
262 262
 			</div>
263 263
 		</div>
264 264
 		<?php
265
-		do_action( 'analysis_wrapper_container', 'bottom' );
266
-		do_action( 'analysis_after_container' );
265
+		do_action('analysis_wrapper_container', 'bottom');
266
+		do_action('analysis_after_container');
267 267
 	} // End analysis_course_view()
268 268
 
269 269
 	/**
@@ -271,26 +271,26 @@  discard block
 block discarded – undo
271 271
 	 * @since  1.2.0
272 272
 	 * @return void
273 273
 	 */
274
-	public function analysis_user_course_view( $course_id, $user_id ) {
274
+	public function analysis_user_course_view($course_id, $user_id) {
275 275
 
276 276
 		// Load Analysis data
277
-		$sensei_analysis_user_course = $this->load_data_object( 'Course', $course_id, $user_id );
277
+		$sensei_analysis_user_course = $this->load_data_object('Course', $course_id, $user_id);
278 278
 		// Wrappers
279
-		do_action( 'analysis_before_container' );
280
-		do_action( 'analysis_wrapper_container', 'top' );
281
-		$this->analysis_headers( array( 'nav' => 'user_course' ) );
279
+		do_action('analysis_before_container');
280
+		do_action('analysis_wrapper_container', 'top');
281
+		$this->analysis_headers(array('nav' => 'user_course'));
282 282
 		?>
283 283
 		<div id="poststuff" class="sensei-analysis-wrap course-profile">
284 284
 			<div class="sensei-analysis-main">
285 285
 				<?php $sensei_analysis_user_course->display(); ?>
286 286
 			</div>
287 287
 			<div class="sensei-analysis-extra">
288
-				<?php do_action( 'sensei_analysis_extra' ); ?>
288
+				<?php do_action('sensei_analysis_extra'); ?>
289 289
 			</div>
290 290
 		</div>
291 291
 		<?php
292
-		do_action( 'analysis_wrapper_container', 'bottom' );
293
-		do_action( 'analysis_after_container' );
292
+		do_action('analysis_wrapper_container', 'bottom');
293
+		do_action('analysis_after_container');
294 294
 	} // End analysis_user_course_view()
295 295
 
296 296
 	/**
@@ -298,26 +298,26 @@  discard block
 block discarded – undo
298 298
 	 * @since  1.2.0
299 299
 	 * @return void
300 300
 	 */
301
-	public function analysis_course_users_view( $course_id ) {
301
+	public function analysis_course_users_view($course_id) {
302 302
 
303 303
 		// Load Analysis data
304
-		$sensei_analysis_course_users = $this->load_data_object( 'Course', $course_id );
304
+		$sensei_analysis_course_users = $this->load_data_object('Course', $course_id);
305 305
 		// Wrappers
306
-		do_action( 'analysis_before_container' );
307
-		do_action( 'analysis_wrapper_container', 'top' );
308
-		$this->analysis_headers( array( 'nav' => 'course_users' ) );
306
+		do_action('analysis_before_container');
307
+		do_action('analysis_wrapper_container', 'top');
308
+		$this->analysis_headers(array('nav' => 'course_users'));
309 309
 		?>
310 310
 		<div id="poststuff" class="sensei-analysis-wrap course-profile">
311 311
 			<div class="sensei-analysis-main">
312 312
 				<?php $sensei_analysis_course_users->display(); ?>
313 313
 			</div>
314 314
 			<div class="sensei-analysis-extra">
315
-				<?php do_action( 'sensei_analysis_extra' ); ?>
315
+				<?php do_action('sensei_analysis_extra'); ?>
316 316
 			</div>
317 317
 		</div>
318 318
 		<?php
319
-		do_action( 'analysis_wrapper_container', 'bottom' );
320
-		do_action( 'analysis_after_container' );
319
+		do_action('analysis_wrapper_container', 'bottom');
320
+		do_action('analysis_after_container');
321 321
 	} // End analysis_course_users_view()
322 322
 
323 323
 	/**
@@ -325,26 +325,26 @@  discard block
 block discarded – undo
325 325
 	 * @since  1.2.0
326 326
 	 * @return void
327 327
 	 */
328
-	public function analysis_lesson_users_view( $lesson_id ) {
328
+	public function analysis_lesson_users_view($lesson_id) {
329 329
 
330 330
 		// Load Analysis data
331
-		$sensei_analysis_lesson_users = $this->load_data_object( 'Lesson', $lesson_id );
331
+		$sensei_analysis_lesson_users = $this->load_data_object('Lesson', $lesson_id);
332 332
 		// Wrappers
333
-		do_action( 'analysis_before_container' );
334
-		do_action( 'analysis_wrapper_container', 'top' );
335
-		$this->analysis_headers( array( 'nav' => 'lesson_users' ) );
333
+		do_action('analysis_before_container');
334
+		do_action('analysis_wrapper_container', 'top');
335
+		$this->analysis_headers(array('nav' => 'lesson_users'));
336 336
 		?>
337 337
 		<div id="poststuff" class="sensei-analysis-wrap course-profile">
338 338
 			<div class="sensei-analysis-main">
339 339
 				<?php $sensei_analysis_lesson_users->display(); ?>
340 340
 			</div>
341 341
 			<div class="sensei-analysis-extra">
342
-				<?php do_action( 'sensei_analysis_extra' ); ?>
342
+				<?php do_action('sensei_analysis_extra'); ?>
343 343
 			</div>
344 344
 		</div>
345 345
 		<?php
346
-		do_action( 'analysis_wrapper_container', 'bottom' );
347
-		do_action( 'analysis_after_container' );
346
+		do_action('analysis_wrapper_container', 'bottom');
347
+		do_action('analysis_after_container');
348 348
 	} // End analysis_lesson_users_view()
349 349
 
350 350
 	/**
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
 	 * @param  $data string stats data
355 355
 	 * @return void
356 356
 	 */
357
-	public function render_stats_box( $title, $data ) {
357
+	public function render_stats_box($title, $data) {
358 358
 		?><div class="postbox">
359 359
 			<h3><span><?php echo $title; ?></span></h3>
360 360
 			<div class="inside">
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @since  1.2.0
369 369
 	 * @return void
370 370
 	 */
371
-	public function analysis_headers( $args = array( 'nav' => 'default' ) ) {
371
+	public function analysis_headers($args = array('nav' => 'default')) {
372 372
 
373
-		$function = 'analysis_' . $args['nav'] . '_nav';
373
+		$function = 'analysis_'.$args['nav'].'_nav';
374 374
 		$this->$function();
375 375
 		?>
376 376
 			<p class="powered-by-woo">
377 377
 
378
-                <?php _e( 'Powered by', 'woothemes-sensei' ); ?>
378
+                <?php _e('Powered by', 'woothemes-sensei'); ?>
379 379
 
380 380
                 <a href="http://www.woothemes.com/" title="WooThemes">
381 381
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             </p>
387 387
 
388 388
 		<?php
389
-		do_action( 'sensei_analysis_after_headers' );
389
+		do_action('sensei_analysis_after_headers');
390 390
 	} // End analysis_headers()
391 391
 
392 392
 	/**
@@ -395,10 +395,10 @@  discard block
 block discarded – undo
395 395
 	 * @param $which string
396 396
 	 * @return void
397 397
 	 */
398
-	public function wrapper_container( $which ) {
399
-		if ( 'top' == $which ) {
400
-			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"><?php
401
-		} elseif ( 'bottom' == $which ) {
398
+	public function wrapper_container($which) {
399
+		if ('top' == $which) {
400
+			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"><?php
401
+		} elseif ('bottom' == $which) {
402 402
 			?></div><!--/#woothemes-sensei--><?php
403 403
 		} // End If Statement
404 404
 	} // End wrapper_container()
@@ -410,24 +410,24 @@  discard block
 block discarded – undo
410 410
 	 */
411 411
 	public function analysis_default_nav() {
412 412
 
413
-		$title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) );
414
-		$view = isset($_GET['view']) ? esc_html( $_GET['view'] ) : '';
415
-		switch ( $view ) { 
413
+		$title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
414
+		$view = isset($_GET['view']) ? esc_html($_GET['view']) : '';
415
+		switch ($view) { 
416 416
 			case 'courses' :
417
-				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', __( 'Courses', 'woothemes-sensei' ) );
417
+				$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', __('Courses', 'woothemes-sensei'));
418 418
 				break;
419 419
 
420 420
 			case 'lessons' :
421
-				$title .= sprintf( '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;%s</span>', __( 'Lessons', 'woothemes-sensei' ) );
421
+				$title .= sprintf('&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;%s</span>', __('Lessons', 'woothemes-sensei'));
422 422
 				break;
423 423
 
424 424
 			case 'users' :
425 425
 			default :
426
-				$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;%s</span>', __( 'Learners', 'woothemes-sensei' ) );
426
+				$title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;%s</span>', __('Learners', 'woothemes-sensei'));
427 427
 				break;
428 428
 		}
429 429
 		?>
430
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
430
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
431 431
 		<?php
432 432
 	} // End analysis_default_nav()
433 433
 
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 	 */
439 439
 	public function analysis_user_profile_nav() {
440 440
 
441
-		$title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) );
442
-		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
441
+		$title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
442
+		if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) {
443 443
 
444
-			$user_id = intval( $_GET['user_id'] );
445
-			$url = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $user_id ), admin_url( 'admin.php' ) ) );
446
-            $user_name = Sensei()->learners->get_learner_full_name( $user_id );
447
-			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
444
+			$user_id = intval($_GET['user_id']);
445
+			$url = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $user_id), admin_url('admin.php')));
446
+            $user_name = Sensei()->learners->get_learner_full_name($user_id);
447
+			$title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name);
448 448
 
449 449
 		} // End If Statement
450 450
 		?>
451
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
451
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
452 452
 		<?php
453 453
 	} // End analysis_user_profile_nav()
454 454
 
@@ -459,22 +459,22 @@  discard block
 block discarded – undo
459 459
 	 */
460 460
 	public function analysis_user_course_nav() {
461 461
 
462
-		$title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) );
463
-		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
464
-			$user_id = intval( $_GET['user_id'] );
465
-			$user_data = get_userdata( $user_id );
466
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $user_id ), admin_url( 'admin.php' ) );
467
-            $user_name = Sensei()->learners->get_learner_full_name( $user_id );
468
-            $title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name );
469
-			$title .= sprintf( '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), $user_data->display_name );
462
+		$title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
463
+		if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) {
464
+			$user_id = intval($_GET['user_id']);
465
+			$user_data = get_userdata($user_id);
466
+			$url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $user_id), admin_url('admin.php'));
467
+            $user_name = Sensei()->learners->get_learner_full_name($user_id);
468
+            $title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', $url, $user_name);
469
+			$title .= sprintf('&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), $user_data->display_name);
470 470
 		} // End If Statement
471
-		if ( isset( $_GET['course_id'] ) ) { 
472
-			$course_id = intval( $_GET['course_id'] );
473
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
474
-			$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
471
+		if (isset($_GET['course_id'])) { 
472
+			$course_id = intval($_GET['course_id']);
473
+			$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
474
+			$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
475 475
 		}
476 476
 		?>
477
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
477
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
478 478
 		<?php
479 479
 	} // End analysis_user_course_nav()
480 480
 
@@ -485,14 +485,14 @@  discard block
 block discarded – undo
485 485
 	 */
486 486
 	public function analysis_course_nav() {
487 487
 
488
-		$title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) );
489
-		if ( isset( $_GET['course_id'] ) ) { 
490
-			$course_id = intval( $_GET['course_id'] );
491
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
492
-			$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>',esc_url( $url ), get_the_title( $course_id ) );
488
+		$title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name));
489
+		if (isset($_GET['course_id'])) { 
490
+			$course_id = intval($_GET['course_id']);
491
+			$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
492
+			$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
493 493
 		}
494 494
 		?>
495
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
495
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
496 496
 		<?php
497 497
 	} // End analysis_course_nav()
498 498
 
@@ -503,14 +503,14 @@  discard block
 block discarded – undo
503 503
 	 */
504 504
 	public function analysis_course_users_nav() {
505 505
 
506
-		$title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) );
507
-		if ( isset( $_GET['course_id'] ) ) { 
508
-			$course_id = intval( $_GET['course_id'] );
509
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
510
-			$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
506
+		$title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name));
507
+		if (isset($_GET['course_id'])) { 
508
+			$course_id = intval($_GET['course_id']);
509
+			$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
510
+			$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
511 511
 		}
512 512
 		?>
513
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
513
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
514 514
 		<?php
515 515
 	} // End analysis_course_users_nav()
516 516
 
@@ -521,17 +521,17 @@  discard block
 block discarded – undo
521 521
 	 */
522 522
 	public function analysis_lesson_users_nav() {
523 523
 
524
-		$title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) );
525
-		if ( isset( $_GET['lesson_id'] ) ) { 
526
-			$lesson_id = intval( $_GET['lesson_id'] );
527
-			$course_id = intval( get_post_meta( $lesson_id, '_lesson_course', true ) );
528
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
529
-			$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
530
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) );
531
-			$title .= sprintf( '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) );
524
+		$title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name));
525
+		if (isset($_GET['lesson_id'])) { 
526
+			$lesson_id = intval($_GET['lesson_id']);
527
+			$course_id = intval(get_post_meta($lesson_id, '_lesson_course', true));
528
+			$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
529
+			$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
530
+			$url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php'));
531
+			$title .= sprintf('&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id));
532 532
 		}
533 533
 		?>
534
-			<h2><?php echo apply_filters( 'sensei_analysis_nav_title', $title ); ?></h2>
534
+			<h2><?php echo apply_filters('sensei_analysis_nav_title', $title); ?></h2>
535 535
 		<?php
536 536
 	} // End analysis_lesson_users_nav()
537 537
 
@@ -542,59 +542,59 @@  discard block
 block discarded – undo
542 542
 	 */
543 543
 	public function report_download_page() {
544 544
 		// Check if is a report
545
-		if ( !empty( $_GET['sensei_report_download'] ) ) {
546
-			$report = sanitize_text_field( $_GET['sensei_report_download'] );
545
+		if ( ! empty($_GET['sensei_report_download'])) {
546
+			$report = sanitize_text_field($_GET['sensei_report_download']);
547 547
 
548 548
 			// Simple verification to ensure intent, Note that a Nonce is per user, so the URL can't be shared
549
-			if ( !wp_verify_nonce( $_REQUEST['_sdl_nonce'], 'sensei_csv_download-' . $report ) ) {
550
-				wp_die( __('Invalid request', 'woothemes-sensei') );
549
+			if ( ! wp_verify_nonce($_REQUEST['_sdl_nonce'], 'sensei_csv_download-'.$report)) {
550
+				wp_die(__('Invalid request', 'woothemes-sensei'));
551 551
 			}
552 552
 
553 553
 			// Setup the variables we might need
554
-			$filename = apply_filters( 'sensei_csv_export_filename', $report );
554
+			$filename = apply_filters('sensei_csv_export_filename', $report);
555 555
 			$course_id = 0;
556 556
 			$lesson_id = 0;
557 557
 			$user_id = 0;
558
-			if( isset( $_GET['course_id'] ) ) {
559
-				$course_id = intval( $_GET['course_id'] );
558
+			if (isset($_GET['course_id'])) {
559
+				$course_id = intval($_GET['course_id']);
560 560
 			}
561
-			if( isset( $_GET['lesson_id'] ) ) {
562
-				$lesson_id = intval( $_GET['lesson_id'] );
561
+			if (isset($_GET['lesson_id'])) {
562
+				$lesson_id = intval($_GET['lesson_id']);
563 563
 			}
564
-			if( isset( $_GET['user_id'] ) ) {
565
-				$user_id = intval( $_GET['user_id'] );
564
+			if (isset($_GET['user_id'])) {
565
+				$user_id = intval($_GET['user_id']);
566 566
 			}
567
-			$type = isset( $_GET['view'] ) ? esc_html( $_GET['view'] ) : false;
567
+			$type = isset($_GET['view']) ? esc_html($_GET['view']) : false;
568 568
 
569
-			if ( 0 < $lesson_id ) {
569
+			if (0 < $lesson_id) {
570 570
 				// Viewing a specific Lesson and all its Learners
571
-				$sensei_analysis_report_object = $this->load_report_object( 'Lesson', $lesson_id );
571
+				$sensei_analysis_report_object = $this->load_report_object('Lesson', $lesson_id);
572 572
 			}
573
-			elseif ( 0 < $course_id && 0 < $user_id ) {
573
+			elseif (0 < $course_id && 0 < $user_id) {
574 574
 				// Viewing a specific User on a specific Course
575
-				$sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id, $user_id );
575
+				$sensei_analysis_report_object = $this->load_report_object('Course', $course_id, $user_id);
576 576
 			}
577
-			elseif( 0 < $course_id ) {
577
+			elseif (0 < $course_id) {
578 578
 				// Viewing a specific Course and all it's Lessons, or it's Learners
579
-				$sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id );
579
+				$sensei_analysis_report_object = $this->load_report_object('Course', $course_id);
580 580
 			}
581
-			elseif ( 0 < $user_id ) {
581
+			elseif (0 < $user_id) {
582 582
 				// Viewing a specific Learner, and their Courses
583
-				$sensei_analysis_report_object = $this->load_report_object( 'User_Profile', $user_id );
583
+				$sensei_analysis_report_object = $this->load_report_object('User_Profile', $user_id);
584 584
 			}
585 585
 			else {
586 586
 				// Overview of all Learners, all Courses, or all Lessons
587
-				$sensei_analysis_report_object = $this->load_report_object( 'Overview', $type );
587
+				$sensei_analysis_report_object = $this->load_report_object('Overview', $type);
588 588
 			} // End If Statement
589 589
 
590 590
 			// Handle the headers
591
-			$this->report_set_headers( $filename );
591
+			$this->report_set_headers($filename);
592 592
 
593 593
 			// Collate the data, there could be many different reports for a single object
594
-			$report_data_array = $sensei_analysis_report_object->generate_report( $report );
594
+			$report_data_array = $sensei_analysis_report_object->generate_report($report);
595 595
 
596 596
 			// Output the data
597
-			$this->report_write_download( $report_data_array );
597
+			$this->report_write_download($report_data_array);
598 598
 
599 599
 			// Cleanly exit
600 600
 			exit;
@@ -607,9 +607,9 @@  discard block
 block discarded – undo
607 607
 	 * @param  string $filename name of report file
608 608
 	 * @return void
609 609
 	 */
610
-	public function report_set_headers( $filename = '' ) {
611
-		header( 'Content-Type: text/csv' );
612
-		header( 'Content-Disposition: attachment;filename=' . $filename . '.csv');
610
+	public function report_set_headers($filename = '') {
611
+		header('Content-Type: text/csv');
612
+		header('Content-Disposition: attachment;filename='.$filename.'.csv');
613 613
 	} // End report_set_headers()
614 614
 
615 615
 	/**
@@ -620,12 +620,12 @@  discard block
 block discarded – undo
620 620
 	 * @param  undefined  $optional_data optional constructor arguments
621 621
 	 * @return object                 class instance object
622 622
 	 */
623
-	public function load_report_object( $name = '', $data = 0, $optional_data = null ) {
624
-		$object_name = 'WooThemes_Sensei_Analysis_' . $name . '_List_Table';
625
-		if ( is_null($optional_data) ) {
626
-			$sensei_analysis_report_object = new $object_name( $data );
623
+	public function load_report_object($name = '', $data = 0, $optional_data = null) {
624
+		$object_name = 'WooThemes_Sensei_Analysis_'.$name.'_List_Table';
625
+		if (is_null($optional_data)) {
626
+			$sensei_analysis_report_object = new $object_name($data);
627 627
 		} else {
628
-			$sensei_analysis_report_object = new $object_name( $data, $optional_data );
628
+			$sensei_analysis_report_object = new $object_name($data, $optional_data);
629 629
 		}
630 630
 		return $sensei_analysis_report_object;
631 631
 	} // End load_report_object()
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 	 * @param  array  $report_array data array
637 637
 	 * @return void
638 638
 	 */
639
-	public function report_write_download( $report_data = array() ) {
639
+	public function report_write_download($report_data = array()) {
640 640
 		$fp = fopen('php://output', 'w');
641 641
 		foreach ($report_data as $row) {
642 642
 			fputcsv($fp, $row);
@@ -652,9 +652,9 @@  discard block
 block discarded – undo
652 652
 	 * @param  object $user_query_object     WP_User_Query Object
653 653
 	 * @return array $search_columns         array of user columns to search
654 654
 	 */
655
-	public function user_search_columns_filter( $search_columns, $search, $user_query_object ) {
655
+	public function user_search_columns_filter($search_columns, $search, $user_query_object) {
656 656
 		// Alter $search_columns to include the fields you want to search on
657
-		array_push( $search_columns, 'display_name' );
657
+		array_push($search_columns, 'display_name');
658 658
 		return $search_columns;
659 659
 	}
660 660
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -19 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 Analysis Class
@@ -153,24 +156,19 @@  discard block
 block discarded – undo
153 156
 		if ( 0 < $lesson_id ) {
154 157
 			// Viewing a specific Lesson and all its Learners
155 158
 			$this->analysis_lesson_users_view( $lesson_id );
156
-		}
157
-		elseif ( 0 < $course_id && !$user_id && 'user' == $type ) {
159
+		} elseif ( 0 < $course_id && !$user_id && 'user' == $type ) {
158 160
 			// Viewing a specific Course and all its Learners
159 161
 			$this->analysis_course_users_view( $course_id );
160
-		}
161
-		elseif ( 0 < $course_id && 0 < $user_id ) {
162
+		} elseif ( 0 < $course_id && 0 < $user_id ) {
162 163
 			// Viewing a specific Learner on a specific Course, showing their Lessons
163 164
 			$this->analysis_user_course_view( $course_id, $user_id );
164
-		}
165
-		elseif( 0 < $course_id ) {
165
+		} elseif( 0 < $course_id ) {
166 166
 			// Viewing a specific Course and all it's Lessons
167 167
 			$this->analysis_course_view( $course_id );
168
-		}
169
-		elseif ( 0 < $user_id ) {
168
+		} elseif ( 0 < $user_id ) {
170 169
 			// Viewing a specific Learner, and their Courses
171 170
 			$this->analysis_user_profile_view( $user_id );
172
-		}
173
-		else {
171
+		} else {
174 172
 			// Overview of all Learners, all Courses, or all Lessons
175 173
 			$this->analysis_default_view( $type );
176 174
 		} // End If Statement
@@ -569,20 +567,16 @@  discard block
 block discarded – undo
569 567
 			if ( 0 < $lesson_id ) {
570 568
 				// Viewing a specific Lesson and all its Learners
571 569
 				$sensei_analysis_report_object = $this->load_report_object( 'Lesson', $lesson_id );
572
-			}
573
-			elseif ( 0 < $course_id && 0 < $user_id ) {
570
+			} elseif ( 0 < $course_id && 0 < $user_id ) {
574 571
 				// Viewing a specific User on a specific Course
575 572
 				$sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id, $user_id );
576
-			}
577
-			elseif( 0 < $course_id ) {
573
+			} elseif( 0 < $course_id ) {
578 574
 				// Viewing a specific Course and all it's Lessons, or it's Learners
579 575
 				$sensei_analysis_report_object = $this->load_report_object( 'Course', $course_id );
580
-			}
581
-			elseif ( 0 < $user_id ) {
576
+			} elseif ( 0 < $user_id ) {
582 577
 				// Viewing a specific Learner, and their Courses
583 578
 				$sensei_analysis_report_object = $this->load_report_object( 'User_Profile', $user_id );
584
-			}
585
-			else {
579
+			} else {
586 580
 				// Overview of all Learners, all Courses, or all Lessons
587 581
 				$sensei_analysis_report_object = $this->load_report_object( 'Overview', $type );
588 582
 			} // End If Statement
Please login to merge, or discard this patch.
includes/class-sensei-emails.php 4 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,6 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * Constructor for the email class hooks in all emails that can be sent.
41 41
 	 *
42 42
 	 * @access public
43
+	 * @param string $file
43 44
 	 * @return void
44 45
 	 */
45 46
 	function __construct( $file ) {
@@ -140,7 +141,7 @@  discard block
 block discarded – undo
140 141
 	 * Wraps a message in the sensei mail template.
141 142
 	 *
142 143
 	 * @access public
143
-	 * @param mixed $content
144
+	 * @param null|string $content
144 145
 	 * @return string
145 146
 	 */
146 147
 	function wrap_message( $content ) {
@@ -198,6 +199,9 @@  discard block
 block discarded – undo
198 199
 		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
199 200
 	}
200 201
 
202
+	/**
203
+	 * @param string $email_template
204
+	 */
201 205
 	function get_content( $email_template ) {
202 206
 
203 207
 		$message = $this->load_template( $email_template );
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 		add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 );
52 52
 		add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 );
53 53
 		add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 );
54
-        add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
54
+		add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
55 55
 		add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 );
56 56
 		add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 );
57 57
 		add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 );
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 		$this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' );
69 69
 		$this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' );
70 70
 		$this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' );
71
-        $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
72
-        $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
73
-        $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
71
+		$this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
72
+		$this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
73
+		$this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
74 74
 		$this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' );
75 75
 		$this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' );
76 76
 		$this->emails = apply_filters( 'sensei_email_classes', $this->emails );
@@ -177,20 +177,20 @@  discard block
 block discarded – undo
177 177
 		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
178 178
 		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
179 179
 
180
-        // Send
181
-        $send_email = true;
180
+		// Send
181
+		$send_email = true;
182 182
 
183
-        /**
184
-         * Filter Sensei's ability to send out emails.
185
-         *
186
-         * @since 1.8.0
187
-         * @param bool $send_email default true
188
-         */
189
-        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
183
+		/**
184
+		 * Filter Sensei's ability to send out emails.
185
+		 *
186
+		 * @since 1.8.0
187
+		 * @param bool $send_email default true
188
+		 */
189
+		if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
190 190
 
191
-            wp_mail( $to, $subject, $message, $headers, $attachments );
191
+			wp_mail( $to, $subject, $message, $headers, $attachments );
192 192
 
193
-        }
193
+		}
194 194
 
195 195
 		// Unhook filters
196 196
 		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
@@ -332,33 +332,33 @@  discard block
 block discarded – undo
332 332
 		}
333 333
 	}
334 334
 
335
-    /**
336
-     * teacher_completed_lesson()
337
-     *
338
-     * Send email to teacher on student completing lesson
339
-     *
340
-     * @access public
341
-     * @return void
342
-     * @since 1.9.0
343
-     */
344
-    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
345
-
346
-
347
-        $send = false;
348
-
349
-        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
350
-            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
351
-                $send = true;
352
-            }
353
-        } else {
354
-            $send = true;
355
-        }
356
-
357
-        if( $send ) {
358
-            $email = $this->emails['teacher-completed-lesson'];
359
-            $email->trigger( $learner_id, $lesson_id );
360
-        }
361
-    }
335
+	/**
336
+	 * teacher_completed_lesson()
337
+	 *
338
+	 * Send email to teacher on student completing lesson
339
+	 *
340
+	 * @access public
341
+	 * @return void
342
+	 * @since 1.9.0
343
+	 */
344
+	function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
345
+
346
+
347
+		$send = false;
348
+
349
+		if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
350
+			if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
351
+				$send = true;
352
+			}
353
+		} else {
354
+			$send = true;
355
+		}
356
+
357
+		if( $send ) {
358
+			$email = $this->emails['teacher-completed-lesson'];
359
+			$email->trigger( $learner_id, $lesson_id );
360
+		}
361
+	}
362 362
 
363 363
 	/**
364 364
 	 * Send email to teacher on quiz submission
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 	 * @access public
43 43
 	 * @return void
44 44
 	 */
45
-	function __construct( $file ) {
45
+	function __construct($file) {
46 46
 
47 47
 		$this->init();
48 48
 
49 49
 		// Hooks for sending emails during Sensei events
50
-		add_action( 'sensei_user_quiz_grade', array( $this, 'learner_graded_quiz' ), 10, 4 );
51
-		add_action( 'sensei_course_status_updated', array( $this, 'learner_completed_course' ), 10, 4 );
52
-		add_action( 'sensei_course_status_updated', array( $this, 'teacher_completed_course' ), 10, 4 );
53
-		add_action( 'sensei_user_course_start', array( $this, 'teacher_started_course' ), 10, 2 );
54
-        add_action( 'sensei_user_lesson_end', array( $this, 'teacher_completed_lesson' ), 10, 2 );
55
-		add_action( 'sensei_user_quiz_submitted', array( $this, 'teacher_quiz_submitted' ), 10, 5 );
56
-		add_action( 'sensei_new_private_message', array( $this, 'teacher_new_message' ), 10, 1 );
57
-		add_action( 'sensei_private_message_reply', array( $this, 'new_message_reply' ), 10, 2 );
50
+		add_action('sensei_user_quiz_grade', array($this, 'learner_graded_quiz'), 10, 4);
51
+		add_action('sensei_course_status_updated', array($this, 'learner_completed_course'), 10, 4);
52
+		add_action('sensei_course_status_updated', array($this, 'teacher_completed_course'), 10, 4);
53
+		add_action('sensei_user_course_start', array($this, 'teacher_started_course'), 10, 2);
54
+        add_action('sensei_user_lesson_end', array($this, 'teacher_completed_lesson'), 10, 2);
55
+		add_action('sensei_user_quiz_submitted', array($this, 'teacher_quiz_submitted'), 10, 5);
56
+		add_action('sensei_new_private_message', array($this, 'teacher_new_message'), 10, 1);
57
+		add_action('sensei_private_message_reply', array($this, 'new_message_reply'), 10, 2);
58 58
 
59 59
 		// Let 3rd parties unhook the above via this hook
60
-		do_action( 'sensei_emails', $this );
60
+		do_action('sensei_emails', $this);
61 61
 	}
62 62
 
63 63
 	/**
@@ -65,15 +65,15 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	function init() {
67 67
 
68
-		$this->emails['learner-graded-quiz'] = include( 'emails/class-woothemes-sensei-email-learner-graded-quiz.php' );
69
-		$this->emails['learner-completed-course'] = include( 'emails/class-woothemes-sensei-email-learner-completed-course.php' );
70
-		$this->emails['teacher-completed-course'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-course.php' );
71
-        $this->emails['teacher-started-course'] = include( 'emails/class-woothemes-sensei-email-teacher-started-course.php' );
72
-        $this->emails['teacher-completed-lesson'] = include( 'emails/class-woothemes-sensei-email-teacher-completed-lesson.php' );
73
-        $this->emails['teacher-quiz-submitted'] = include( 'emails/class-woothemes-sensei-email-teacher-quiz-submitted.php' );
74
-		$this->emails['teacher-new-message'] = include( 'emails/class-woothemes-sensei-email-teacher-new-message.php' );
75
-		$this->emails['new-message-reply'] = include( 'emails/class-woothemes-sensei-email-new-message-reply.php' );
76
-		$this->emails = apply_filters( 'sensei_email_classes', $this->emails );
68
+		$this->emails['learner-graded-quiz'] = include('emails/class-woothemes-sensei-email-learner-graded-quiz.php');
69
+		$this->emails['learner-completed-course'] = include('emails/class-woothemes-sensei-email-learner-completed-course.php');
70
+		$this->emails['teacher-completed-course'] = include('emails/class-woothemes-sensei-email-teacher-completed-course.php');
71
+        $this->emails['teacher-started-course'] = include('emails/class-woothemes-sensei-email-teacher-started-course.php');
72
+        $this->emails['teacher-completed-lesson'] = include('emails/class-woothemes-sensei-email-teacher-completed-lesson.php');
73
+        $this->emails['teacher-quiz-submitted'] = include('emails/class-woothemes-sensei-email-teacher-quiz-submitted.php');
74
+		$this->emails['teacher-new-message'] = include('emails/class-woothemes-sensei-email-teacher-new-message.php');
75
+		$this->emails['new-message-reply'] = include('emails/class-woothemes-sensei-email-new-message-reply.php');
76
+		$this->emails = apply_filters('sensei_email_classes', $this->emails);
77 77
 	}
78 78
 
79 79
 	/**
@@ -95,15 +95,15 @@  discard block
 block discarded – undo
95 95
 	function get_from_name() {
96 96
 
97 97
 
98
-		if ( ! $this->_from_name ) {
99
-			if( isset( Sensei()->settings->settings['email_from_name'] ) && '' != Sensei()->settings->settings['email_from_name'] ) {
98
+		if ( ! $this->_from_name) {
99
+			if (isset(Sensei()->settings->settings['email_from_name']) && '' != Sensei()->settings->settings['email_from_name']) {
100 100
 				$this->_from_name = Sensei()->settings->settings['email_from_name'];
101 101
 			} else {
102
-				$this->_from_name = get_bloginfo( 'name' );
102
+				$this->_from_name = get_bloginfo('name');
103 103
 			}
104 104
 		}
105 105
 
106
-		return wp_specialchars_decode( $this->_from_name );
106
+		return wp_specialchars_decode($this->_from_name);
107 107
 	}
108 108
 
109 109
 	/**
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
 	function get_from_address() {
116 116
 
117 117
 
118
-		if ( ! $this->_from_address ) {
119
-			if( isset( Sensei()->settings->settings['email_from_address'] ) && '' != Sensei()->settings->settings['email_from_address'] ) {
118
+		if ( ! $this->_from_address) {
119
+			if (isset(Sensei()->settings->settings['email_from_address']) && '' != Sensei()->settings->settings['email_from_address']) {
120 120
 				$this->_from_address = Sensei()->settings->settings['email_from_address'];
121 121
 			} else {
122
-				$this->_from_address = get_bloginfo( 'admin_email' );
122
+				$this->_from_address = get_bloginfo('admin_email');
123 123
 			}
124 124
 		}
125 125
 
@@ -143,13 +143,13 @@  discard block
 block discarded – undo
143 143
 	 * @param mixed $content
144 144
 	 * @return string
145 145
 	 */
146
-	function wrap_message( $content ) {
146
+	function wrap_message($content) {
147 147
 
148 148
 		$html = '';
149 149
 
150
-		$html .= $this->load_template( 'header' );
151
-		$html .= wpautop( wptexturize( $content ) );
152
-		$html .= $this->load_template( 'footer' );
150
+		$html .= $this->load_template('header');
151
+		$html .= wpautop(wptexturize($content));
152
+		$html .= $this->load_template('footer');
153 153
 
154 154
 		return $html;
155 155
 	}
@@ -166,16 +166,16 @@  discard block
 block discarded – undo
166 166
 	 * @param string $content_type (default: "text/html")
167 167
 	 * @return void
168 168
 	 */
169
-	function send( $to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html' ) {
169
+	function send($to, $subject, $message, $headers = "Content-Type: text/html\r\n", $attachments = "", $content_type = 'text/html') {
170 170
 		global $email_template;
171 171
 
172 172
 		// Set content type
173 173
 		$this->_content_type = $content_type;
174 174
 
175 175
 		// Filters for the email
176
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
177
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
178
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
176
+		add_filter('wp_mail_from', array($this, 'get_from_address'));
177
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'));
178
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'));
179 179
 
180 180
         // Send
181 181
         $send_email = true;
@@ -186,40 +186,40 @@  discard block
 block discarded – undo
186 186
          * @since 1.8.0
187 187
          * @param bool $send_email default true
188 188
          */
189
-        if( apply_filters('sensei_send_emails', $send_email,$to, $subject, $message )  ){
189
+        if (apply_filters('sensei_send_emails', $send_email, $to, $subject, $message)) {
190 190
 
191
-            wp_mail( $to, $subject, $message, $headers, $attachments );
191
+            wp_mail($to, $subject, $message, $headers, $attachments);
192 192
 
193 193
         }
194 194
 
195 195
 		// Unhook filters
196
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
197
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
198
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
196
+		remove_filter('wp_mail_from', array($this, 'get_from_address'));
197
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'));
198
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'));
199 199
 	}
200 200
 
201
-	function get_content( $email_template ) {
201
+	function get_content($email_template) {
202 202
 
203
-		$message = $this->load_template( $email_template );
203
+		$message = $this->load_template($email_template);
204 204
 
205
-		$html = $this->wrap_message( $message );
205
+		$html = $this->wrap_message($message);
206 206
 
207
-		return apply_filters( 'sensei_email', $html, $email_template );
207
+		return apply_filters('sensei_email', $html, $email_template);
208 208
 	}
209 209
 
210
-	function load_template( $template = '' ) {
210
+	function load_template($template = '') {
211 211
 		global  $email_template;
212 212
 
213
-		if( ! $template ) return;
213
+		if ( ! $template) return;
214 214
 
215
-		$email_template = $template . '.php';
216
-		$template = Sensei_Templates::template_loader( '' );
215
+		$email_template = $template.'.php';
216
+		$template = Sensei_Templates::template_loader('');
217 217
 
218 218
 		ob_start();
219 219
 
220
-		do_action( 'sensei_before_email_template', $email_template );
221
-		include( $template );
222
-		do_action( 'sensei_after_email_template', $email_template );
220
+		do_action('sensei_before_email_template', $email_template);
221
+		include($template);
222
+		do_action('sensei_after_email_template', $email_template);
223 223
 
224 224
 		return ob_get_clean();
225 225
 	}
@@ -230,22 +230,22 @@  discard block
 block discarded – undo
230 230
 	 * @access public
231 231
 	 * @return void
232 232
 	 */
233
-	function learner_graded_quiz( $user_id, $quiz_id, $grade, $passmark ) {
233
+	function learner_graded_quiz($user_id, $quiz_id, $grade, $passmark) {
234 234
 
235 235
 
236 236
 		$send = false;
237 237
 
238
-		if( isset( Sensei()->settings->settings['email_learners'] ) ) {
239
-			if( in_array( 'learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'] ) ) {
238
+		if (isset(Sensei()->settings->settings['email_learners'])) {
239
+			if (in_array('learner-graded-quiz', (array) Sensei()->settings->settings['email_learners'])) {
240 240
 				$send = true;
241 241
 			}
242 242
 		} else {
243 243
 			$send = true;
244 244
 		}
245 245
 
246
-		if( $send ) {
246
+		if ($send) {
247 247
 			$email = $this->emails['learner-graded-quiz'];
248
-			$email->trigger( $user_id, $quiz_id, $grade, $passmark );
248
+			$email->trigger($user_id, $quiz_id, $grade, $passmark);
249 249
 		}
250 250
 	}
251 251
 
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
 	 * @access public
256 256
 	 * @return void
257 257
 	 */
258
-	function learner_completed_course( $status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0 ) {
258
+	function learner_completed_course($status = 'in-progress', $user_id = 0, $course_id = 0, $comment_id = 0) {
259 259
 
260 260
 
261
-		if( 'complete' != $status ) {
261
+		if ('complete' != $status) {
262 262
 			return;
263 263
 		}
264 264
 
265 265
 		$send = false;
266 266
 
267
-		if( isset( Sensei()->settings->settings['email_learners'] ) ) {
268
-			if( in_array( 'learner-completed-course', (array) Sensei()->settings->settings['email_learners'] ) ) {
267
+		if (isset(Sensei()->settings->settings['email_learners'])) {
268
+			if (in_array('learner-completed-course', (array) Sensei()->settings->settings['email_learners'])) {
269 269
 				$send = true;
270 270
 			}
271 271
 		} else {
272 272
 			$send = true;
273 273
 		}
274 274
 
275
-		if( $send ) {
275
+		if ($send) {
276 276
 			$email = $this->emails['learner-completed-course'];
277
-			$email->trigger( $user_id, $course_id );
277
+			$email->trigger($user_id, $course_id);
278 278
 		}
279 279
 	}
280 280
 
@@ -284,26 +284,26 @@  discard block
 block discarded – undo
284 284
 	 * @access public
285 285
 	 * @return void
286 286
 	 */
287
-	function teacher_completed_course( $status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0 ) {
287
+	function teacher_completed_course($status = 'in-progress', $learner_id = 0, $course_id = 0, $comment_id = 0) {
288 288
 
289 289
 
290
-		if( 'complete' != $status ) {
290
+		if ('complete' != $status) {
291 291
 			return;
292 292
 		}
293 293
 
294 294
 		$send = false;
295 295
 
296
-		if( isset( Sensei()->settings->settings['email_teachers'] ) ) {
297
-			if( in_array( 'teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'] ) ) {
296
+		if (isset(Sensei()->settings->settings['email_teachers'])) {
297
+			if (in_array('teacher-completed-course', (array) Sensei()->settings->settings['email_teachers'])) {
298 298
 				$send = true;
299 299
 			}
300 300
 		} else {
301 301
 			$send = true;
302 302
 		}
303 303
 
304
-		if( $send ) {
304
+		if ($send) {
305 305
 			$email = $this->emails['teacher-completed-course'];
306
-			$email->trigger( $learner_id, $course_id );
306
+			$email->trigger($learner_id, $course_id);
307 307
 		}
308 308
 	}
309 309
 
@@ -313,22 +313,22 @@  discard block
 block discarded – undo
313 313
 	 * @access public
314 314
 	 * @return void
315 315
 	 */
316
-	function teacher_started_course( $learner_id = 0, $course_id = 0 ) {
316
+	function teacher_started_course($learner_id = 0, $course_id = 0) {
317 317
 
318 318
 
319 319
 		$send = false;
320 320
 
321
-		if( isset( Sensei()->settings->settings['email_teachers'] ) ) {
322
-			if( in_array( 'teacher-started-course', (array) Sensei()->settings->settings['email_teachers'] ) ) {
321
+		if (isset(Sensei()->settings->settings['email_teachers'])) {
322
+			if (in_array('teacher-started-course', (array) Sensei()->settings->settings['email_teachers'])) {
323 323
 				$send = true;
324 324
 			}
325 325
 		} else {
326 326
 			$send = true;
327 327
 		}
328 328
 
329
-		if( $send ) {
329
+		if ($send) {
330 330
 			$email = $this->emails['teacher-started-course'];
331
-			$email->trigger( $learner_id, $course_id );
331
+			$email->trigger($learner_id, $course_id);
332 332
 		}
333 333
 	}
334 334
 
@@ -341,22 +341,22 @@  discard block
 block discarded – undo
341 341
      * @return void
342 342
      * @since 1.9.0
343 343
      */
344
-    function teacher_completed_lesson( $learner_id = 0, $lesson_id = 0 ) {
344
+    function teacher_completed_lesson($learner_id = 0, $lesson_id = 0) {
345 345
 
346 346
 
347 347
         $send = false;
348 348
 
349
-        if( isset( Sensei()->settings->settings[ 'email_teachers' ] ) ) {
350
-            if( in_array( 'teacher-completed-lesson', (array) Sensei()->settings->settings[ 'email_teachers' ]) ) {
349
+        if (isset(Sensei()->settings->settings['email_teachers'])) {
350
+            if (in_array('teacher-completed-lesson', (array) Sensei()->settings->settings['email_teachers'])) {
351 351
                 $send = true;
352 352
             }
353 353
         } else {
354 354
             $send = true;
355 355
         }
356 356
 
357
-        if( $send ) {
357
+        if ($send) {
358 358
             $email = $this->emails['teacher-completed-lesson'];
359
-            $email->trigger( $learner_id, $lesson_id );
359
+            $email->trigger($learner_id, $lesson_id);
360 360
         }
361 361
     }
362 362
 
@@ -366,25 +366,25 @@  discard block
 block discarded – undo
366 366
 	 * @access public
367 367
 	 * @return void
368 368
 	 */
369
-	function teacher_quiz_submitted( $learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual' ) {
369
+	function teacher_quiz_submitted($learner_id = 0, $quiz_id = 0, $grade = 0, $passmark = 0, $quiz_grade_type = 'manual') {
370 370
 
371 371
 
372 372
 
373 373
 		$send = false;
374 374
 
375 375
 		// Only trigger if the quiz was marked as manual grading, or auto grading didn't complete
376
-		if( 'manual' == $quiz_grade_type || is_wp_error( $grade ) ) {
377
-			if( isset( Sensei()->settings->settings['email_teachers'] ) ) {
378
-				if( in_array( 'teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'] ) ) {
376
+		if ('manual' == $quiz_grade_type || is_wp_error($grade)) {
377
+			if (isset(Sensei()->settings->settings['email_teachers'])) {
378
+				if (in_array('teacher-quiz-submitted', (array) Sensei()->settings->settings['email_teachers'])) {
379 379
 					$send = true;
380 380
 				}
381 381
 			} else {
382 382
 				$send = true;
383 383
 			}
384 384
 
385
-			if( $send ) {
385
+			if ($send) {
386 386
 				$email = $this->emails['teacher-quiz-submitted'];
387
-				$email->trigger( $learner_id, $quiz_id );
387
+				$email->trigger($learner_id, $quiz_id);
388 388
 			}
389 389
 
390 390
 		}
@@ -396,22 +396,22 @@  discard block
 block discarded – undo
396 396
 	 * @access public
397 397
 	 * @return void
398 398
 	 */
399
-	function teacher_new_message( $message_id = 0 ) {
399
+	function teacher_new_message($message_id = 0) {
400 400
 
401 401
 
402 402
 		$send = false;
403 403
 
404
-		if( isset( Sensei()->settings->settings['email_teachers'] ) ) {
405
-			if( in_array( 'teacher-new-message', (array) Sensei()->settings->settings['email_teachers'] ) ) {
404
+		if (isset(Sensei()->settings->settings['email_teachers'])) {
405
+			if (in_array('teacher-new-message', (array) Sensei()->settings->settings['email_teachers'])) {
406 406
 				$send = true;
407 407
 			}
408 408
 		} else {
409 409
 			$send = true;
410 410
 		}
411 411
 
412
-		if( $send ) {
412
+		if ($send) {
413 413
 			$email = $this->emails['teacher-new-message'];
414
-			$email->trigger( $message_id );
414
+			$email->trigger($message_id);
415 415
 		}
416 416
 	}
417 417
 
@@ -421,22 +421,22 @@  discard block
 block discarded – undo
421 421
 	 * @access public
422 422
 	 * @return void
423 423
 	 */
424
-	function new_message_reply( $comment, $message ) {
424
+	function new_message_reply($comment, $message) {
425 425
 
426 426
 
427 427
 		$send = false;
428 428
 
429
-		if( isset( Sensei()->settings->settings['email_global'] ) ) {
430
-			if( in_array( 'new-message-reply', (array) Sensei()->settings->settings['email_global'] ) ) {
429
+		if (isset(Sensei()->settings->settings['email_global'])) {
430
+			if (in_array('new-message-reply', (array) Sensei()->settings->settings['email_global'])) {
431 431
 				$send = true;
432 432
 			}
433 433
 		} else {
434 434
 			$send = true;
435 435
 		}
436 436
 
437
-		if( $send ) {
437
+		if ($send) {
438 438
 			$email = $this->emails['new-message-reply'];
439
-			$email->trigger( $comment, $message );
439
+			$email->trigger($comment, $message);
440 440
 		}
441 441
 	}
442 442
 
@@ -447,4 +447,4 @@  discard block
 block discarded – undo
447 447
  * for backward compatibility
448 448
  * @since 1.9.0
449 449
  */
450
-class WooThemes_Sensei_Emails extends Sensei_Emails{}
450
+class WooThemes_Sensei_Emails extends Sensei_Emails {}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -210,7 +210,9 @@
 block discarded – undo
210 210
 	function load_template( $template = '' ) {
211 211
 		global  $email_template;
212 212
 
213
-		if( ! $template ) return;
213
+		if( ! $template ) {
214
+			return;
215
+		}
214 216
 
215 217
 		$email_template = $template . '.php';
216 218
 		$template = Sensei_Templates::template_loader( '' );
Please login to merge, or discard this patch.
includes/class-sensei-grading.php 4 patches
Doc Comments   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * Constructor
23 23
 	 * @since  1.3.0
24 24
      *
25
-     * @param $file
25
+     * @param string $file
26 26
 	 */
27 27
 	public function __construct ( $file ) {
28 28
 		$this->name = __( 'Grading', 'woothemes-sensei' );
@@ -330,6 +330,7 @@  discard block
 block discarded – undo
330 330
 	/**
331 331
 	 * Return array of valid statuses for either Course or Lesson
332 332
 	 * @since  1.7.0
333
+	 * @param string $type
333 334
 	 * @return array
334 335
 	 */
335 336
 	public function get_stati( $type ) {
@@ -529,7 +530,7 @@  discard block
 block discarded – undo
529 530
      * the grades as the Grader selected theme and saves the total grade and
530 531
      * individual question grades.
531 532
      *
532
-     * @return bool
533
+     * @return false|null
533 534
      */
534 535
     public function admin_process_grading_submission() {
535 536
 
@@ -906,8 +907,8 @@  discard block
 block discarded – undo
906 907
      * Grading logic specifically for the gap fill questions
907 908
      *
908 909
      * @since 1.9.0
909
-     * @param $question_id
910
-     * @param $user_answer
910
+     * @param integer $question_id
911
+     * @param string $user_answer
911 912
      *
912 913
      * @return bool | int false or the grade given to the user answer
913 914
      */
Please login to merge, or discard this patch.
Braces   +20 added lines, -28 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 Grading Class
@@ -130,8 +133,7 @@  discard block
 block discarded – undo
130 133
 		$object_name = 'WooThemes_Sensei_Grading_' . $name;
131 134
 		if ( is_null($optional_data) ) {
132 135
 			$sensei_grading_object = new $object_name( $data );
133
-		}
134
-		else {
136
+		} else {
135 137
 			$sensei_grading_object = new $object_name( $data, $optional_data );
136 138
 		} // End If Statement
137 139
 		if ( 'Main' == $name ) {
@@ -150,8 +152,7 @@  discard block
 block discarded – undo
150 152
 
151 153
 		if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
152 154
 			$this->grading_user_quiz_view();
153
-		}
154
-		else {
155
+		} else {
155 156
 			$this->grading_default_view();
156 157
 		} // End If Statement
157 158
 	} // End grading_page()
@@ -273,8 +274,7 @@  discard block
 block discarded – undo
273 274
 			if ( version_compare($wp_version, '4.1', '>=') ) {
274 275
 				$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
275 276
 				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
276
-			}
277
-			else {
277
+			} else {
278 278
 				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title( $course_id ) ); 
279 279
 			}
280 280
 		}
@@ -309,8 +309,7 @@  discard block
 block discarded – undo
309 309
 			if ( version_compare($wp_version, '4.1', '>=') ) {
310 310
 				$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
311 311
 				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
312
-			}
313
-			else {
312
+			} else {
314 313
 				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title( $course_id ) ); 
315 314
 			}
316 315
 			$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) );
@@ -379,8 +378,7 @@  discard block
 block discarded – undo
379 378
 
380 379
 		if ( 'course' == $args['type'] ) {
381 380
 			$type = 'sensei_course_status';
382
-		}
383
-		else {
381
+		} else {
384 382
 			$type = 'sensei_lesson_status';
385 383
 		}
386 384
 		$cache_key = 'sensei-' . $args['type'] . '-statuses';
@@ -390,15 +388,13 @@  discard block
 block discarded – undo
390 388
         // Restrict to specific posts
391 389
 		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
392 390
 			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
393
-		}
394
-		elseif ( !empty( $args['post_id'] ) ) {
391
+		} elseif ( !empty( $args['post_id'] ) ) {
395 392
 			$query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] );
396 393
 		}
397 394
 		// Restrict to specific users
398 395
 		if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) {
399 396
 			$query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')';
400
-		}
401
-		elseif ( !empty( $args['user_id'] ) ) {
397
+		} elseif ( !empty( $args['user_id'] ) ) {
402 398
 			$query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] );
403 399
 		}
404 400
 		$query .= ' GROUP BY comment_approved';
@@ -601,8 +597,7 @@  discard block
 block discarded – undo
601 597
             // set the users total quiz grade
602 598
 			if ( 0 < intval( $quiz_grade_total ) ) {
603 599
             $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
604
-			}
605
-			else {
600
+			} else {
606 601
 				$grade = 0;
607 602
 			}
608 603
             WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
@@ -615,8 +610,7 @@  discard block
 block discarded – undo
615 610
                 // Student has reached the pass mark and lesson is complete
616 611
                 if ( $quiz_passmark <= $grade ) {
617 612
                     $lesson_status = 'passed';
618
-                }
619
-                else {
613
+                } else {
620 614
                     $lesson_status = 'failed';
621 615
                 } // End If Statement
622 616
             }
@@ -761,8 +755,7 @@  discard block
 block discarded – undo
761 755
 			// Question has a zero grade, so skip grading
762 756
 			if ( 0 == $achievable_grade ) {
763 757
 				$all_question_grades[ $question_id ] = $achievable_grade;
764
-			}
765
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
758
+			} elseif ( in_array( $question_type, $autogradable_question_types ) ) {
766 759
                 // Get user question grade
767 760
                 $question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
768 761
                 $all_question_grades[ $question_id ] = $question_grade;
@@ -784,8 +777,7 @@  discard block
 block discarded – undo
784 777
 			// Check for zero total from grades
785 778
 			if ( 0 < $quiz_total ) {
786 779
             $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
787
-			}
788
-			else {
780
+			} else {
789 781
 				$grade = 0;
790 782
 			}
791 783
             WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
@@ -945,19 +937,19 @@  discard block
 block discarded – undo
945 937
 
946 938
                     return Sensei()->question->get_question_grade($question_id);
947 939
 
948
-                }else{
940
+                } else{
949 941
 
950 942
                     return false;
951 943
 
952 944
                 }
953 945
 
954
-            }else{
946
+            } else{
955 947
 
956 948
                 return false;
957 949
 
958 950
             }
959 951
 
960
-        }else{
952
+        } else{
961 953
 
962 954
             // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
963 955
             if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
@@ -970,13 +962,13 @@  discard block
 block discarded – undo
970 962
 
971 963
                     return  Sensei()->question->get_question_grade( $question_id );
972 964
 
973
-                }else{
965
+                } else{
974 966
 
975 967
                     return false;
976 968
 
977 969
                 }
978 970
 
979
-            }else{
971
+            } else{
980 972
 
981 973
                 return false;
982 974
 
Please login to merge, or discard this patch.
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	 * Constructor
23 23
 	 * @since  1.3.0
24
-     *
25
-     * @param $file
24
+	 *
25
+	 * @param $file
26 26
 	 */
27 27
 	public function __construct ( $file ) {
28 28
 		$this->name = __( 'Grading', 'woothemes-sensei' );
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 		}
285 285
 		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
286 286
 
287
-            $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] );
287
+			$user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] );
288 288
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
289 289
 
290 290
 		} // End If Statement
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 		}
319 319
 		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
320 320
 
321
-            $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] );
321
+			$user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] );
322 322
 			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
323 323
 
324 324
 		} // End If Statement
@@ -367,15 +367,15 @@  discard block
 block discarded – undo
367 367
 	public function count_statuses( $args = array() ) {
368 368
 		global  $wpdb;
369 369
 
370
-        /**
371
-         * Filter fires inside Sensei_Grading::count_statuses
372
-         *
373
-         * Alter the the post_in array to determine which posts the
374
-         * comment query should be limited to.
375
-         * @since 1.8.0
376
-         * @param array $args
377
-         */
378
-        $args = apply_filters( 'sensei_count_statuses_args', $args );
370
+		/**
371
+		 * Filter fires inside Sensei_Grading::count_statuses
372
+		 *
373
+		 * Alter the the post_in array to determine which posts the
374
+		 * comment query should be limited to.
375
+		 * @since 1.8.0
376
+		 * @param array $args
377
+		 */
378
+		$args = apply_filters( 'sensei_count_statuses_args', $args );
379 379
 
380 380
 		if ( 'course' == $args['type'] ) {
381 381
 			$type = 'sensei_course_status';
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 
388 388
 		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s ";
389 389
 
390
-        // Restrict to specific posts
390
+		// Restrict to specific posts
391 391
 		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
392 392
 			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
393 393
 		}
@@ -522,148 +522,148 @@  discard block
 block discarded – undo
522 522
 		return $html;
523 523
 	} // End lessons_drop_down_html()
524 524
 
525
-    /**
526
-     * The process grading function handles admin grading submissions.
527
-     *
528
-     * This function is hooked on to admin_init. It simply accepts
529
-     * the grades as the Grader selected theme and saves the total grade and
530
-     * individual question grades.
531
-     *
532
-     * @return bool
533
-     */
534
-    public function admin_process_grading_submission() {
525
+	/**
526
+	 * The process grading function handles admin grading submissions.
527
+	 *
528
+	 * This function is hooked on to admin_init. It simply accepts
529
+	 * the grades as the Grader selected theme and saves the total grade and
530
+	 * individual question grades.
531
+	 *
532
+	 * @return bool
533
+	 */
534
+	public function admin_process_grading_submission() {
535 535
 
536
-        // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
537
-        if( ! isset( $_POST['sensei_manual_grade'] )
538
-            || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
539
-            || ! isset( $_GET['quiz_id'] )
540
-            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
536
+		// NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
537
+		if( ! isset( $_POST['sensei_manual_grade'] )
538
+			|| ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
539
+			|| ! isset( $_GET['quiz_id'] )
540
+			|| $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
541 541
 
542
-            return false; //exit and do not grade
542
+			return false; //exit and do not grade
543 543
 
544
-        }
544
+		}
545 545
 
546
-        $quiz_id = $_GET['quiz_id'];
547
-        $user_id = $_GET['user'];
546
+		$quiz_id = $_GET['quiz_id'];
547
+		$user_id = $_GET['user'];
548 548
 
549 549
 
550
-        $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
551
-        $quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
552
-        $quiz_grade = 0;
553
-        $count = 0;
554
-        $quiz_grade_total = $_POST['quiz_grade_total'];
555
-        $all_question_grades = array();
556
-        $all_answers_feedback = array();
550
+		$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
551
+		$quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
552
+		$quiz_grade = 0;
553
+		$count = 0;
554
+		$quiz_grade_total = $_POST['quiz_grade_total'];
555
+		$all_question_grades = array();
556
+		$all_answers_feedback = array();
557 557
 
558
-        foreach( $questions as $question ) {
558
+		foreach( $questions as $question ) {
559 559
 
560
-            ++$count;
561
-            $question_id = $question->ID;
560
+			++$count;
561
+			$question_id = $question->ID;
562 562
 
563
-            if( isset( $_POST[ 'question_' . $question_id ] ) ) {
563
+			if( isset( $_POST[ 'question_' . $question_id ] ) ) {
564 564
 
565
-                $question_grade = 0;
566
-                if( $_POST[ 'question_' . $question_id ] == 'right' ) {
565
+				$question_grade = 0;
566
+				if( $_POST[ 'question_' . $question_id ] == 'right' ) {
567 567
 
568
-                    $question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
568
+					$question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
569 569
 
570
-                }
570
+				}
571 571
 
572
-                // add data to the array that will, after the loop, be stored on the lesson status
573
-                $all_question_grades[ $question_id ] = $question_grade;
572
+				// add data to the array that will, after the loop, be stored on the lesson status
573
+				$all_question_grades[ $question_id ] = $question_grade;
574 574
 
575
-                // tally up the total quiz grade
576
-                $quiz_grade += $question_grade;
575
+				// tally up the total quiz grade
576
+				$quiz_grade += $question_grade;
577 577
 
578
-            } // endif
578
+			} // endif
579 579
 
580
-            // Question answer feedback / notes
581
-            $question_feedback = '';
582
-            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
580
+			// Question answer feedback / notes
581
+			$question_feedback = '';
582
+			if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
583 583
 
584
-                $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
584
+				$question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
585 585
 
586
-            }
587
-            $all_answers_feedback[ $question_id ] = $question_feedback;
586
+			}
587
+			$all_answers_feedback[ $question_id ] = $question_feedback;
588 588
 
589
-        } // end for each $questions
589
+		} // end for each $questions
590 590
 
591
-        //store all question grades on the lesson status
592
-        Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
591
+		//store all question grades on the lesson status
592
+		Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
593 593
 
594
-        //store the feedback from grading
595
-        Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
594
+		//store the feedback from grading
595
+		Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
596 596
 
597
-        // $_POST['all_questions_graded'] is set when all questions have been graded
598
-        // in the class sensei grading user quiz -> display()
599
-        if( $_POST['all_questions_graded'] == 'yes' ) {
597
+		// $_POST['all_questions_graded'] is set when all questions have been graded
598
+		// in the class sensei grading user quiz -> display()
599
+		if( $_POST['all_questions_graded'] == 'yes' ) {
600 600
 
601
-            // set the users total quiz grade
601
+			// set the users total quiz grade
602 602
 			if ( 0 < intval( $quiz_grade_total ) ) {
603
-            $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
603
+			$grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
604 604
 			}
605 605
 			else {
606 606
 				$grade = 0;
607 607
 			}
608
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
609
-
610
-            // Duplicating what Frontend->sensei_complete_quiz() does
611
-            $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
612
-            $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
613
-            $lesson_metadata = array();
614
-            if ( $pass_required ) {
615
-                // Student has reached the pass mark and lesson is complete
616
-                if ( $quiz_passmark <= $grade ) {
617
-                    $lesson_status = 'passed';
618
-                }
619
-                else {
620
-                    $lesson_status = 'failed';
621
-                } // End If Statement
622
-            }
623
-            // Student only has to partake the quiz
624
-            else {
625
-                $lesson_status = 'graded';
626
-            }
627
-            $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
608
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
609
+
610
+			// Duplicating what Frontend->sensei_complete_quiz() does
611
+			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
612
+			$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
613
+			$lesson_metadata = array();
614
+			if ( $pass_required ) {
615
+				// Student has reached the pass mark and lesson is complete
616
+				if ( $quiz_passmark <= $grade ) {
617
+					$lesson_status = 'passed';
618
+				}
619
+				else {
620
+					$lesson_status = 'failed';
621
+				} // End If Statement
622
+			}
623
+			// Student only has to partake the quiz
624
+			else {
625
+				$lesson_status = 'graded';
626
+			}
627
+			$lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
628 628
 
629
-            Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
629
+			Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
630 630
 
631
-            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
631
+			if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
632 632
 
633
-                /**
634
-                 * Summary.
635
-                 *
636
-                 * Description.
637
-                 *
638
-                 * @since 1.7.0
639
-                 *
640
-                 * @param int  $user_id
641
-                 * @param int $quiz_lesson_id
642
-                 */
643
-                do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
633
+				/**
634
+				 * Summary.
635
+				 *
636
+				 * Description.
637
+				 *
638
+				 * @since 1.7.0
639
+				 *
640
+				 * @param int  $user_id
641
+				 * @param int $quiz_lesson_id
642
+				 */
643
+				do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
644 644
 
645
-            } // end if in_array
645
+			} // end if in_array
646 646
 
647
-        }// end if $_POST['all_que...
647
+		}// end if $_POST['all_que...
648 648
 
649
-        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
649
+		if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
650 650
 
651
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
651
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
652 652
 
653
-        } elseif ( isset( $_POST['_wp_http_referer'] ) ) {
653
+		} elseif ( isset( $_POST['_wp_http_referer'] ) ) {
654 654
 
655
-            $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
655
+			$load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
656 656
 
657
-        } else {
657
+		} else {
658 658
 
659
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
659
+			$load_url = add_query_arg( array( 'message' => 'graded' ) );
660 660
 
661
-        }
661
+		}
662 662
 
663
-        wp_safe_redirect( esc_url_raw( $load_url ) );
664
-        exit;
663
+		wp_safe_redirect( esc_url_raw( $load_url ) );
664
+		exit;
665 665
 
666
-    } // end admin_process_grading_submission
666
+	} // end admin_process_grading_submission
667 667
 
668 668
 	public function get_redirect_url() {
669 669
 		// Parse POST data
@@ -708,283 +708,283 @@  discard block
 block discarded – undo
708 708
 		} // End If Statement
709 709
 	} // End sensei_grading_notices()
710 710
 
711
-    /**
712
-     * Grade quiz automatically
713
-     *
714
-     * This function grades each question automatically if there all questions are auto gradable. If not
715
-     * the quiz will not be auto gradable.
716
-     *
717
-     * @since 1.7.4
718
-     *
719
-     * @param  integer $quiz_id         ID of quiz
720
-     * @param  array $submitted questions id ans answers {
721
-     *          @type int $question_id
722
-     *          @type mixed $answer
723
-     * }
724
-     * @param  integer $total_questions Total questions in quiz (not used)
725
-     * @param string $quiz_grade_type Optional defaults to auto
726
-     *
727
-     * @return int $quiz_grade total sum of all question grades
728
-     */
729
-    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
730
-
731
-        if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
732
-            || $quiz_grade_type != 'auto' ) {
733
-            return false; // exit early
734
-        }
735
-
736
-
737
-        $user_id = get_current_user_id();
738
-        $lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
739
-        $quiz_autogradable = true;
740
-
741
-        /**
742
-         * Filter the types of question types that can be automatically graded.
743
-         *
744
-         * This filter fires inside the auto grade quiz function and provides you with the default list.
745
-         *
746
-         * @param array {
747
-         *      'multiple-choice',
748
-         *      'boolean',
749
-         *      'gap-fill'.
750
-         * }
751
-         */
752
-        $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
753
-
754
-        $grade_total = 0;
755
-        $all_question_grades = array();
756
-        foreach( $submitted as $question_id => $answer ) {
757
-
758
-            // check if the question is autogradable, either by type, or because the grade is 0
759
-            $question_type = Sensei()->question->get_question_type( $question_id );
711
+	/**
712
+	 * Grade quiz automatically
713
+	 *
714
+	 * This function grades each question automatically if there all questions are auto gradable. If not
715
+	 * the quiz will not be auto gradable.
716
+	 *
717
+	 * @since 1.7.4
718
+	 *
719
+	 * @param  integer $quiz_id         ID of quiz
720
+	 * @param  array $submitted questions id ans answers {
721
+	 *          @type int $question_id
722
+	 *          @type mixed $answer
723
+	 * }
724
+	 * @param  integer $total_questions Total questions in quiz (not used)
725
+	 * @param string $quiz_grade_type Optional defaults to auto
726
+	 *
727
+	 * @return int $quiz_grade total sum of all question grades
728
+	 */
729
+	public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
730
+
731
+		if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
732
+			|| $quiz_grade_type != 'auto' ) {
733
+			return false; // exit early
734
+		}
735
+
736
+
737
+		$user_id = get_current_user_id();
738
+		$lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
739
+		$quiz_autogradable = true;
740
+
741
+		/**
742
+		 * Filter the types of question types that can be automatically graded.
743
+		 *
744
+		 * This filter fires inside the auto grade quiz function and provides you with the default list.
745
+		 *
746
+		 * @param array {
747
+		 *      'multiple-choice',
748
+		 *      'boolean',
749
+		 *      'gap-fill'.
750
+		 * }
751
+		 */
752
+		$autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
753
+
754
+		$grade_total = 0;
755
+		$all_question_grades = array();
756
+		foreach( $submitted as $question_id => $answer ) {
757
+
758
+			// check if the question is autogradable, either by type, or because the grade is 0
759
+			$question_type = Sensei()->question->get_question_type( $question_id );
760 760
 			$achievable_grade = Sensei()->question->get_question_grade( $question_id );
761 761
 			// Question has a zero grade, so skip grading
762 762
 			if ( 0 == $achievable_grade ) {
763 763
 				$all_question_grades[ $question_id ] = $achievable_grade;
764 764
 			}
765
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
766
-                // Get user question grade
767
-                $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
768
-                $all_question_grades[ $question_id ] = $question_grade;
769
-                $grade_total += $question_grade;
765
+			elseif ( in_array( $question_type, $autogradable_question_types ) ) {
766
+				// Get user question grade
767
+				$question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
768
+				$all_question_grades[ $question_id ] = $question_grade;
769
+				$grade_total += $question_grade;
770 770
 
771
-            } else {
771
+			} else {
772 772
 
773
-                // There is a question that cannot be autograded
774
-                $quiz_autogradable = false;
773
+				// There is a question that cannot be autograded
774
+				$quiz_autogradable = false;
775 775
 
776
-            } // end if in_array( $question_type...
776
+			} // end if in_array( $question_type...
777 777
 
778
-        }// end for each question
778
+		}// end for each question
779 779
 
780
-        // Only if the whole quiz was autogradable do we set a grade
781
-        if ( $quiz_autogradable ) {
780
+		// Only if the whole quiz was autogradable do we set a grade
781
+		if ( $quiz_autogradable ) {
782 782
 
783
-            $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
783
+			$quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
784 784
 			// Check for zero total from grades
785 785
 			if ( 0 < $quiz_total ) {
786
-            $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
786
+			$grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
787 787
 			}
788 788
 			else {
789 789
 				$grade = 0;
790 790
 			}
791
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
791
+			Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
792 792
 
793
-        } else {
793
+		} else {
794 794
 
795
-            $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
795
+			$grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
796 796
 
797
-        }
798
-
799
-        // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
800
-        // when doing manual grading.
801
-        Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
797
+		}
802 798
 
803
-        return $grade;
799
+		// store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
800
+		// when doing manual grading.
801
+		Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
804 802
 
805
-    } // End grade_quiz_auto()
803
+		return $grade;
806 804
 
807
-    /**
808
-     * Grade question automatically
809
-     *
810
-     * This function checks the question typ and then grades it accordingly.
811
-     *
812
-     * @since 1.7.4
813
-     *
814
-     * @param integer $question_id
815
-     * @param string $question_type of the standard Sensei question types
816
-     * @param string $answer
817
-     * @param int $user_id
818
-     *
819
-     * @return int $question_grade
820
-     */
821
-    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
822
-
823
-        if( intval( $user_id ) == 0 ) {
824
-
825
-            $user_id = get_current_user_id();
826
-
827
-        }
828
-
829
-        if( ! ( intval( $question_id ) > 0 ) ) {
830
-
831
-            return false;
832
-
833
-        }
834
-
835
-
836
-        Sensei()->question->get_question_type( $question_id );
837
-
838
-        /**
839
-         * Applying a grade before the auto grading takes place.
840
-         *
841
-         * This filter is applied just before the question is auto graded. It fires in the context of a single question
842
-         * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
843
-         * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
844
-         *
845
-         * @param int $question_grade default false
846
-         * @param int $question_id
847
-         * @param string $question_type one of the Sensei question type.
848
-         * @param string $answer user supplied question answer
849
-         */
850
-        $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
805
+	} // End grade_quiz_auto()
851 806
 
852
-        if ( false !== $question_grade ) {
807
+	/**
808
+	 * Grade question automatically
809
+	 *
810
+	 * This function checks the question typ and then grades it accordingly.
811
+	 *
812
+	 * @since 1.7.4
813
+	 *
814
+	 * @param integer $question_id
815
+	 * @param string $question_type of the standard Sensei question types
816
+	 * @param string $answer
817
+	 * @param int $user_id
818
+	 *
819
+	 * @return int $question_grade
820
+	 */
821
+	public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
822
+
823
+		if( intval( $user_id ) == 0 ) {
824
+
825
+			$user_id = get_current_user_id();
826
+
827
+		}
828
+
829
+		if( ! ( intval( $question_id ) > 0 ) ) {
830
+
831
+			return false;
832
+
833
+		}
834
+
835
+
836
+		Sensei()->question->get_question_type( $question_id );
837
+
838
+		/**
839
+		 * Applying a grade before the auto grading takes place.
840
+		 *
841
+		 * This filter is applied just before the question is auto graded. It fires in the context of a single question
842
+		 * in the sensei_grade_question_auto function. It fires irrespective of the question type. If you return a value
843
+		 * other than false the auto grade functionality will be ignored and your supplied grade will be user for this question.
844
+		 *
845
+		 * @param int $question_grade default false
846
+		 * @param int $question_id
847
+		 * @param string $question_type one of the Sensei question type.
848
+		 * @param string $answer user supplied question answer
849
+		 */
850
+		$question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
853 851
 
854
-            return $question_grade;
852
+		if ( false !== $question_grade ) {
855 853
 
856
-        }
854
+			return $question_grade;
857 855
 
858
-        // auto grading core
859
-        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
856
+		}
860 857
 
861
-            $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
858
+		// auto grading core
859
+		if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
862 860
 
863
-            if( 0 == get_magic_quotes_gpc() ) {
864
-                $answer = wp_unslash( $answer );
865
-            }
866
-            $answer = (array) $answer;
867
-            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
868
-                // Loop through all answers ensure none are 'missing'
869
-                $all_correct = true;
870
-                foreach ( $answer as $check_answer ) {
871
-                    if ( !in_array( $check_answer, $right_answer ) ) {
872
-                        $all_correct = false;
873
-                    }
874
-                }
875
-                // If all correct then grade
876
-                if ( $all_correct ) {
877
-                    $question_grade = Sensei()->question->get_question_grade( $question_id );
878
-                }
879
-            }
861
+			$right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
880 862
 
881
-        } elseif( 'gap-fill' == $question_type ){
863
+			if( 0 == get_magic_quotes_gpc() ) {
864
+				$answer = wp_unslash( $answer );
865
+			}
866
+			$answer = (array) $answer;
867
+			if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
868
+				// Loop through all answers ensure none are 'missing'
869
+				$all_correct = true;
870
+				foreach ( $answer as $check_answer ) {
871
+					if ( !in_array( $check_answer, $right_answer ) ) {
872
+						$all_correct = false;
873
+					}
874
+				}
875
+				// If all correct then grade
876
+				if ( $all_correct ) {
877
+					$question_grade = Sensei()->question->get_question_grade( $question_id );
878
+				}
879
+			}
882 880
 
883
-            $question_grade = self::grade_gap_fill_question( $question_id ,$answer );
881
+		} elseif( 'gap-fill' == $question_type ){
884 882
 
885
-        } else{
883
+			$question_grade = self::grade_gap_fill_question( $question_id ,$answer );
886 884
 
887
-            /**
888
-             * Grading questions that are not auto gradable.
889
-             *
890
-             * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
891
-             * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
892
-             *
893
-             * @param int $question_grade default zero
894
-             * @param int $question_id
895
-             * @param string $question_type one of the Sensei question type.
896
-             * @param string $answer user supplied question answer
897
-             */
898
-            $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
885
+		} else{
899 886
 
900
-        } // end if $question_type
887
+			/**
888
+			 * Grading questions that are not auto gradable.
889
+			 *
890
+			 * This filter is applied the context of ta single question within the sensei_grade_question_auto function.
891
+			 * It fires for all other questions types. It does not apply to 'multiple-choice'  , 'boolean' and gap-fill.
892
+			 *
893
+			 * @param int $question_grade default zero
894
+			 * @param int $question_id
895
+			 * @param string $question_type one of the Sensei question type.
896
+			 * @param string $answer user supplied question answer
897
+			 */
898
+			$question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
901 899
 
902
-        return $question_grade;
903
-    } // end grade_question_auto
900
+		} // end if $question_type
904 901
 
905
-    /**
906
-     * Grading logic specifically for the gap fill questions
907
-     *
908
-     * @since 1.9.0
909
-     * @param $question_id
910
-     * @param $user_answer
911
-     *
912
-     * @return bool | int false or the grade given to the user answer
913
-     */
914
-    public static function grade_gap_fill_question( $question_id, $user_answer ){
902
+		return $question_grade;
903
+	} // end grade_question_auto
915 904
 
916
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
917
-        $gapfill_array = explode( '||', $right_answer );
905
+	/**
906
+	 * Grading logic specifically for the gap fill questions
907
+	 *
908
+	 * @since 1.9.0
909
+	 * @param $question_id
910
+	 * @param $user_answer
911
+	 *
912
+	 * @return bool | int false or the grade given to the user answer
913
+	 */
914
+	public static function grade_gap_fill_question( $question_id, $user_answer ){
918 915
 
919
-        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
920
-            $user_answer = wp_unslash( $user_answer );
921
-        }
916
+		$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
917
+		$gapfill_array = explode( '||', $right_answer );
922 918
 
923
-        /**
924
-         * case sensitive grading filter
925
-         *
926
-         * alter the value simply use this code in your plugin or the themes functions.php
927
-         * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
928
-         *
929
-         * @param bool $do_case_sensitive_comparison default false.
930
-         *
931
-         * @since 1.9.0
932
-         */
933
-        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
919
+		if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
920
+			$user_answer = wp_unslash( $user_answer );
921
+		}
922
+
923
+		/**
924
+		 * case sensitive grading filter
925
+		 *
926
+		 * alter the value simply use this code in your plugin or the themes functions.php
927
+		 * add_filter( 'sensei_gap_fill_case_sensitive_grading','__return_true' );
928
+		 *
929
+		 * @param bool $do_case_sensitive_comparison default false.
930
+		 *
931
+		 * @since 1.9.0
932
+		 */
933
+		$do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
934 934
 
935
-        if( $do_case_sensitive_comparison ){
935
+		if( $do_case_sensitive_comparison ){
936 936
 
937
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
938
-            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
937
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
938
+			if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
939 939
 
940
-                return Sensei()->question->get_question_grade( $question_id );
940
+				return Sensei()->question->get_question_grade( $question_id );
941 941
 
942
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
942
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
943 943
 
944
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
944
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
945 945
 
946
-                    return Sensei()->question->get_question_grade($question_id);
946
+					return Sensei()->question->get_question_grade($question_id);
947 947
 
948
-                }else{
948
+				}else{
949 949
 
950
-                    return false;
950
+					return false;
951 951
 
952
-                }
952
+				}
953 953
 
954
-            }else{
954
+			}else{
955 955
 
956
-                return false;
956
+				return false;
957 957
 
958
-            }
958
+			}
959 959
 
960
-        }else{
960
+		}else{
961 961
 
962
-            // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
963
-            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
962
+			// Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
963
+			if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
964 964
 
965
-               return Sensei()->question->get_question_grade( $question_id );
965
+			   return Sensei()->question->get_question_grade( $question_id );
966 966
 
967
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
967
+			} else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
968 968
 
969
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
969
+				if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
970 970
 
971
-                    return  Sensei()->question->get_question_grade( $question_id );
971
+					return  Sensei()->question->get_question_grade( $question_id );
972 972
 
973
-                }else{
973
+				}else{
974 974
 
975
-                    return false;
975
+					return false;
976 976
 
977
-                }
977
+				}
978 978
 
979
-            }else{
979
+			}else{
980 980
 
981
-                return false;
981
+				return false;
982 982
 
983
-            }
983
+			}
984 984
 
985
-        }
985
+		}
986 986
 
987
-    }
987
+	}
988 988
 
989 989
 } // End Class
990 990
 
Please login to merge, or discard this patch.
Spacing   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Grading Class
@@ -24,30 +24,30 @@  discard block
 block discarded – undo
24 24
      *
25 25
      * @param $file
26 26
 	 */
27
-	public function __construct ( $file ) {
28
-		$this->name = __( 'Grading', 'woothemes-sensei' );
27
+	public function __construct($file) {
28
+		$this->name = __('Grading', 'woothemes-sensei');
29 29
 		$this->file = $file;
30 30
 		$this->page_slug = 'sensei_grading';
31 31
 
32 32
 		// Admin functions
33
-		if ( is_admin() ) {
34
-			add_action( 'admin_menu', array( $this, 'grading_admin_menu' ), 20);
35
-			add_action( 'grading_wrapper_container', array( $this, 'wrapper_container'  ) );
36
-			if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
37
-				add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
38
-				add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
33
+		if (is_admin()) {
34
+			add_action('admin_menu', array($this, 'grading_admin_menu'), 20);
35
+			add_action('grading_wrapper_container', array($this, 'wrapper_container'));
36
+			if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
37
+				add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
38
+				add_action('admin_print_styles', array($this, 'enqueue_styles'));
39 39
 			}
40 40
 
41
-			add_action( 'admin_init', array( $this, 'admin_process_grading_submission' ) );
41
+			add_action('admin_init', array($this, 'admin_process_grading_submission'));
42 42
 
43
-			add_action( 'admin_notices', array( $this, 'add_grading_notices' ) );
43
+			add_action('admin_notices', array($this, 'add_grading_notices'));
44 44
 //			add_action( 'sensei_grading_notices', array( $this, 'sensei_grading_notices' ) );
45 45
 		} // End If Statement
46 46
 
47 47
 		// Ajax functions
48
-		if ( is_admin() ) {
49
-			add_action( 'wp_ajax_get_lessons_dropdown', array( $this, 'get_lessons_dropdown' ) );
50
-			add_action( 'wp_ajax_get_redirect_url', array( $this, 'get_redirect_url' ) );
48
+		if (is_admin()) {
49
+			add_action('wp_ajax_get_lessons_dropdown', array($this, 'get_lessons_dropdown'));
50
+			add_action('wp_ajax_get_redirect_url', array($this, 'get_redirect_url'));
51 51
 		} // End If Statement
52 52
 	} // End __construct()
53 53
 
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	public function grading_admin_menu() {
61 61
 		global $menu;
62 62
 
63
-		if ( current_user_can( 'manage_sensei_grades' ) ) {
64
-			$grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'),  __('Grading', 'woothemes-sensei') , 'manage_sensei_grades', $this->page_slug, array( $this, 'grading_page' ) );
63
+		if (current_user_can('manage_sensei_grades')) {
64
+			$grading_page = add_submenu_page('sensei', __('Grading', 'woothemes-sensei'), __('Grading', 'woothemes-sensei'), 'manage_sensei_grades', $this->page_slug, array($this, 'grading_page'));
65 65
 		}
66 66
 
67 67
 	} // End grading_admin_menu()
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
 	 * @since 1.3.0
75 75
 	 * @return void
76 76
 	 */
77
-	public function enqueue_scripts () {
77
+	public function enqueue_scripts() {
78 78
 
79 79
 
80
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
80
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
81 81
 
82 82
 		// Load Grading JS
83
-		wp_enqueue_script( 'sensei-grading-general', Sensei()->plugin_url . 'assets/js/grading-general' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
83
+		wp_enqueue_script('sensei-grading-general', Sensei()->plugin_url.'assets/js/grading-general'.$suffix.'.js', array('jquery'), Sensei()->version);
84 84
 
85 85
 	} // End enqueue_scripts()
86 86
 
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
 	 * @since 1.0.0
93 93
 	 * @return void
94 94
 	 */
95
-	public function enqueue_styles () {
95
+	public function enqueue_styles() {
96 96
 
97
-		wp_enqueue_style( Sensei()->token . '-admin' );
97
+		wp_enqueue_style(Sensei()->token.'-admin');
98 98
 
99
-		wp_enqueue_style( 'woothemes-sensei-settings-api', Sensei()->plugin_url . 'assets/css/settings.css', '', Sensei()->version );
99
+		wp_enqueue_style('woothemes-sensei-settings-api', Sensei()->plugin_url.'assets/css/settings.css', '', Sensei()->version);
100 100
 
101 101
 	} // End enqueue_styles()
102 102
 
@@ -108,12 +108,12 @@  discard block
 block discarded – undo
108 108
 	public function load_data_table_files() {
109 109
 
110 110
 		// Load Grading Classes
111
-		$classes_to_load = array(	'list-table',
111
+		$classes_to_load = array('list-table',
112 112
 									'grading-main',
113 113
 									'grading-user-quiz'
114 114
 									);
115
-		foreach ( $classes_to_load as $class_file ) {
116
-			Sensei()->load_class( $class_file );
115
+		foreach ($classes_to_load as $class_file) {
116
+			Sensei()->load_class($class_file);
117 117
 		} // End For Loop
118 118
 	} // End load_data_table_files()
119 119
 
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
 	 * @param  undefined  $optional_data optional constructor arguments
126 126
 	 * @return object                 class instance object
127 127
 	 */
128
-	public function load_data_object( $name = '', $data = 0, $optional_data = null ) {
128
+	public function load_data_object($name = '', $data = 0, $optional_data = null) {
129 129
 		// Load Analysis data
130
-		$object_name = 'WooThemes_Sensei_Grading_' . $name;
131
-		if ( is_null($optional_data) ) {
132
-			$sensei_grading_object = new $object_name( $data );
130
+		$object_name = 'WooThemes_Sensei_Grading_'.$name;
131
+		if (is_null($optional_data)) {
132
+			$sensei_grading_object = new $object_name($data);
133 133
 		}
134 134
 		else {
135
-			$sensei_grading_object = new $object_name( $data, $optional_data );
135
+			$sensei_grading_object = new $object_name($data, $optional_data);
136 136
 		} // End If Statement
137
-		if ( 'Main' == $name ) {
137
+		if ('Main' == $name) {
138 138
 			$sensei_grading_object->prepare_items();
139 139
 		} // End If Statement
140 140
 		return $sensei_grading_object;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 */
149 149
 	public function grading_page() {
150 150
 
151
-		if ( isset( $_GET['quiz_id'] ) && 0 < intval( $_GET['quiz_id'] ) && isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
151
+		if (isset($_GET['quiz_id']) && 0 < intval($_GET['quiz_id']) && isset($_GET['user']) && 0 < intval($_GET['user'])) {
152 152
 			$this->grading_user_quiz_view();
153 153
 		}
154 154
 		else {
@@ -164,23 +164,23 @@  discard block
 block discarded – undo
164 164
 	public function grading_default_view() {
165 165
 
166 166
 		// Load Grading data
167
-		if( !empty( $_GET['course_id'] ) ) {
168
-			$course_id = intval( $_GET['course_id'] );
167
+		if ( ! empty($_GET['course_id'])) {
168
+			$course_id = intval($_GET['course_id']);
169 169
 		}
170
-		if( !empty( $_GET['lesson_id'] ) ) {
171
-			$lesson_id = intval( $_GET['lesson_id'] );
170
+		if ( ! empty($_GET['lesson_id'])) {
171
+			$lesson_id = intval($_GET['lesson_id']);
172 172
 		}
173
-		if( !empty( $_GET['user_id'] ) ) {
174
-			$user_id = intval( $_GET['user_id'] );
173
+		if ( ! empty($_GET['user_id'])) {
174
+			$user_id = intval($_GET['user_id']);
175 175
 		}
176
-		if( !empty( $_GET['view'] ) ) {
177
-			$view = esc_html( $_GET['view'] );
176
+		if ( ! empty($_GET['view'])) {
177
+			$view = esc_html($_GET['view']);
178 178
 		}
179
-		$sensei_grading_overview = $this->load_data_object( 'Main', compact( 'course_id', 'lesson_id', 'user_id', 'view' ) );
179
+		$sensei_grading_overview = $this->load_data_object('Main', compact('course_id', 'lesson_id', 'user_id', 'view'));
180 180
 
181 181
 		// Wrappers
182
-		do_action( 'grading_before_container' );
183
-		do_action( 'grading_wrapper_container', 'top' );
182
+		do_action('grading_before_container');
183
+		do_action('grading_wrapper_container', 'top');
184 184
 		$this->grading_headers();
185 185
 		?>
186 186
 		<div id="poststuff" class="sensei-grading-wrap">
@@ -188,12 +188,12 @@  discard block
 block discarded – undo
188 188
 				<?php $sensei_grading_overview->display(); ?>
189 189
 			</div>
190 190
 			<div class="sensei-grading-extra">
191
-				<?php do_action( 'sensei_grading_extra' ); ?>
191
+				<?php do_action('sensei_grading_extra'); ?>
192 192
 			</div>
193 193
 		</div>
194 194
 		<?php
195
-		do_action( 'grading_wrapper_container', 'bottom' );
196
-		do_action( 'grading_after_container' );
195
+		do_action('grading_wrapper_container', 'bottom');
196
+		do_action('grading_after_container');
197 197
 	} // End grading_default_view()
198 198
 
199 199
 	/**
@@ -206,17 +206,17 @@  discard block
 block discarded – undo
206 206
 		// Load Grading data
207 207
 		$user_id = 0;
208 208
 		$quiz_id = 0;
209
-		if( isset( $_GET['user'] ) ) {
210
-			$user_id = intval( $_GET['user'] );
209
+		if (isset($_GET['user'])) {
210
+			$user_id = intval($_GET['user']);
211 211
 		}
212
-		if( isset( $_GET['quiz_id'] ) ) {
213
-			$quiz_id = intval( $_GET['quiz_id'] );
212
+		if (isset($_GET['quiz_id'])) {
213
+			$quiz_id = intval($_GET['quiz_id']);
214 214
 		}
215
-		$sensei_grading_user_profile = $this->load_data_object( 'User_Quiz', $user_id, $quiz_id );
215
+		$sensei_grading_user_profile = $this->load_data_object('User_Quiz', $user_id, $quiz_id);
216 216
 		// Wrappers
217
-		do_action( 'grading_before_container' );
218
-		do_action( 'grading_wrapper_container', 'top' );
219
-		$this->grading_headers( array( 'nav' => 'user_quiz' ) );
217
+		do_action('grading_before_container');
218
+		do_action('grading_wrapper_container', 'top');
219
+		$this->grading_headers(array('nav' => 'user_quiz'));
220 220
 		?>
221 221
 		<div id="poststuff" class="sensei-grading-wrap user-profile">
222 222
 			<div class="sensei-grading-main">
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
 			</div>
226 226
 		</div>
227 227
 		<?php
228
-		do_action( 'grading_wrapper_container', 'bottom' );
229
-		do_action( 'grading_after_container' );
228
+		do_action('grading_wrapper_container', 'bottom');
229
+		do_action('grading_after_container');
230 230
 	} // End grading_user_quiz_view()
231 231
 
232 232
 	/**
@@ -234,15 +234,15 @@  discard block
 block discarded – undo
234 234
 	 * @since  1.3.0
235 235
 	 * @return void
236 236
 	 */
237
-	public function grading_headers( $args = array( 'nav' => 'default' ) ) {
237
+	public function grading_headers($args = array('nav' => 'default')) {
238 238
 
239 239
 
240
-		$function = 'grading_' . $args['nav'] . '_nav';
240
+		$function = 'grading_'.$args['nav'].'_nav';
241 241
 		$this->$function();
242 242
 		?>
243
-			<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>
243
+			<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>
244 244
 		<?php
245
-		do_action( 'sensei_grading_after_headers' );
245
+		do_action('sensei_grading_after_headers');
246 246
 	} // End grading_headers()
247 247
 
248 248
 	/**
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
 	 * @param $which string
252 252
 	 * @return void
253 253
 	 */
254
-	public function wrapper_container( $which ) {
255
-		if ( 'top' == $which ) {
256
-			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"><?php
257
-		} elseif ( 'bottom' == $which ) {
254
+	public function wrapper_container($which) {
255
+		if ('top' == $which) {
256
+			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"><?php
257
+		} elseif ('bottom' == $which) {
258 258
 			?></div><!--/#woothemes-sensei--><?php
259 259
 		} // End If Statement
260 260
 	} // End wrapper_container()
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
 	public function grading_default_nav() {
268 268
 		global  $wp_version;
269 269
 
270
-		$title = sprintf( '<a href="%s">%s</a>', esc_url(add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) );
271
-		if ( isset( $_GET['course_id'] ) ) { 
272
-			$course_id = intval( $_GET['course_id'] );
273
-			if ( version_compare($wp_version, '4.1', '>=') ) {
274
-				$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
275
-				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
270
+		$title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
271
+		if (isset($_GET['course_id'])) { 
272
+			$course_id = intval($_GET['course_id']);
273
+			if (version_compare($wp_version, '4.1', '>=')) {
274
+				$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
275
+				$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
276 276
 			}
277 277
 			else {
278
-				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title( $course_id ) ); 
278
+				$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title($course_id)); 
279 279
 			}
280 280
 		}
281
-		if ( isset( $_GET['lesson_id'] ) ) { 
282
-			$lesson_id = intval( $_GET['lesson_id'] );
283
-			$title .= '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;' . get_the_title( intval( $lesson_id ) ) . '</span>'; 
281
+		if (isset($_GET['lesson_id'])) { 
282
+			$lesson_id = intval($_GET['lesson_id']);
283
+			$title .= '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;'.get_the_title(intval($lesson_id)).'</span>'; 
284 284
 		}
285
-		if ( isset( $_GET['user_id'] ) && 0 < intval( $_GET['user_id'] ) ) {
285
+		if (isset($_GET['user_id']) && 0 < intval($_GET['user_id'])) {
286 286
 
287
-            $user_name = Sensei()->learners->get_learner_full_name( $_GET['user_id'] );
288
-			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
287
+            $user_name = Sensei()->learners->get_learner_full_name($_GET['user_id']);
288
+			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;'.$user_name.'</span>';
289 289
 
290 290
 		} // End If Statement
291 291
 		?>
292
-			<h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2>
292
+			<h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2>
293 293
 		<?php
294 294
 	} // End grading_default_nav()
295 295
 
@@ -301,29 +301,29 @@  discard block
 block discarded – undo
301 301
 	public function grading_user_quiz_nav() {
302 302
 		global  $wp_version;
303 303
 
304
-		$title = sprintf( '<a href="%s">%s</a>', add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ), esc_html( $this->name ) );
305
-		if ( isset( $_GET['quiz_id'] ) ) { 
306
-			$quiz_id = intval( $_GET['quiz_id'] );
307
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
308
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
309
-			if ( version_compare($wp_version, '4.1', '>=') ) {
310
-				$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
311
-				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
304
+		$title = sprintf('<a href="%s">%s</a>', add_query_arg(array('page' => $this->page_slug), admin_url('admin.php')), esc_html($this->name));
305
+		if (isset($_GET['quiz_id'])) { 
306
+			$quiz_id = intval($_GET['quiz_id']);
307
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
308
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
309
+			if (version_compare($wp_version, '4.1', '>=')) {
310
+				$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
311
+				$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
312 312
 			}
313 313
 			else {
314
-				$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title( $course_id ) ); 
314
+				$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;%s</span>', get_the_title($course_id)); 
315 315
 			}
316
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id ), admin_url( 'admin.php' ) );
317
-			$title .= sprintf( '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $lesson_id ) );
316
+			$url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id), admin_url('admin.php'));
317
+			$title .= sprintf('&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($lesson_id));
318 318
 		}
319
-		if ( isset( $_GET['user'] ) && 0 < intval( $_GET['user'] ) ) {
319
+		if (isset($_GET['user']) && 0 < intval($_GET['user'])) {
320 320
 
321
-            $user_name = Sensei()->learners->get_learner_full_name( $_GET['user'] );
322
-			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;' . $user_name . '</span>';
321
+            $user_name = Sensei()->learners->get_learner_full_name($_GET['user']);
322
+			$title .= '&nbsp;&nbsp;<span class="user-title">&gt;&nbsp;&nbsp;'.$user_name.'</span>';
323 323
 
324 324
 		} // End If Statement
325 325
 		?>
326
-			<h2><?php echo apply_filters( 'sensei_grading_nav_title', $title ); ?></h2>
326
+			<h2><?php echo apply_filters('sensei_grading_nav_title', $title); ?></h2>
327 327
 		<?php
328 328
 	} // End grading_user_quiz_nav()
329 329
 
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
 	 * @since  1.7.0
333 333
 	 * @return array
334 334
 	 */
335
-	public function get_stati( $type ) {
335
+	public function get_stati($type) {
336 336
 		$statuses = array();
337
-		switch( $type ) {
337
+		switch ($type) {
338 338
 			case 'course' :
339 339
 				$statuses = array(
340 340
 					'in-progress',
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @param  array $args (default: array())
365 365
 	 * @return object
366 366
 	 */
367
-	public function count_statuses( $args = array() ) {
367
+	public function count_statuses($args = array()) {
368 368
 		global  $wpdb;
369 369
 
370 370
         /**
@@ -375,71 +375,71 @@  discard block
 block discarded – undo
375 375
          * @since 1.8.0
376 376
          * @param array $args
377 377
          */
378
-        $args = apply_filters( 'sensei_count_statuses_args', $args );
378
+        $args = apply_filters('sensei_count_statuses_args', $args);
379 379
 
380
-		if ( 'course' == $args['type'] ) {
380
+		if ('course' == $args['type']) {
381 381
 			$type = 'sensei_course_status';
382 382
 		}
383 383
 		else {
384 384
 			$type = 'sensei_lesson_status';
385 385
 		}
386
-		$cache_key = 'sensei-' . $args['type'] . '-statuses';
386
+		$cache_key = 'sensei-'.$args['type'].'-statuses';
387 387
 
388 388
 		$query = "SELECT comment_approved, COUNT( * ) AS total FROM {$wpdb->comments} WHERE comment_type = %s ";
389 389
 
390 390
         // Restrict to specific posts
391
-		if ( isset( $args['post__in'] ) && !empty( $args['post__in'] ) && is_array( $args['post__in'] ) ) {
392
-			$query .= ' AND comment_post_ID IN (' . implode( ',', array_map( 'absint', $args['post__in'] ) ) . ')';
391
+		if (isset($args['post__in']) && ! empty($args['post__in']) && is_array($args['post__in'])) {
392
+			$query .= ' AND comment_post_ID IN ('.implode(',', array_map('absint', $args['post__in'])).')';
393 393
 		}
394
-		elseif ( !empty( $args['post_id'] ) ) {
395
-			$query .= $wpdb->prepare( ' AND comment_post_ID = %d', $args['post_id'] );
394
+		elseif ( ! empty($args['post_id'])) {
395
+			$query .= $wpdb->prepare(' AND comment_post_ID = %d', $args['post_id']);
396 396
 		}
397 397
 		// Restrict to specific users
398
-		if ( isset( $args['user_id'] ) && is_array( $args['user_id'] ) ) {
399
-			$query .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $args['user_id'] ) ) . ')';
398
+		if (isset($args['user_id']) && is_array($args['user_id'])) {
399
+			$query .= ' AND user_id IN ('.implode(',', array_map('absint', $args['user_id'])).')';
400 400
 		}
401
-		elseif ( !empty( $args['user_id'] ) ) {
402
-			$query .= $wpdb->prepare( ' AND user_id = %d', $args['user_id'] );
401
+		elseif ( ! empty($args['user_id'])) {
402
+			$query .= $wpdb->prepare(' AND user_id = %d', $args['user_id']);
403 403
 		}
404 404
 		$query .= ' GROUP BY comment_approved';
405 405
 
406
-		$counts = wp_cache_get( $cache_key, 'counts' );
407
-		if ( false === $counts ) {
408
-			$sql = $wpdb->prepare( $query, $type );
409
-			$results = (array) $wpdb->get_results( $sql, ARRAY_A );
410
-			$counts = array_fill_keys( $this->get_stati( $type ), 0 );
406
+		$counts = wp_cache_get($cache_key, 'counts');
407
+		if (false === $counts) {
408
+			$sql = $wpdb->prepare($query, $type);
409
+			$results = (array) $wpdb->get_results($sql, ARRAY_A);
410
+			$counts = array_fill_keys($this->get_stati($type), 0);
411 411
 
412
-			foreach ( $results as $row ) {
413
-				$counts[ $row['comment_approved'] ] = $row['total'];
412
+			foreach ($results as $row) {
413
+				$counts[$row['comment_approved']] = $row['total'];
414 414
 			}
415
-			wp_cache_set( $cache_key, $counts, 'counts' );
415
+			wp_cache_set($cache_key, $counts, 'counts');
416 416
 		}
417 417
 
418
-		if( ! isset( $counts['graded'] ) ) {
418
+		if ( ! isset($counts['graded'])) {
419 419
 			$counts['graded'] = 0;
420 420
 		}
421 421
 
422
-		if( ! isset( $counts['ungraded'] ) ) {
422
+		if ( ! isset($counts['ungraded'])) {
423 423
 			$counts['ungraded'] = 0;
424 424
 		}
425 425
 
426
-		if( ! isset( $counts['passed'] ) ) {
426
+		if ( ! isset($counts['passed'])) {
427 427
 			$counts['passed'] = 0;
428 428
 		}
429 429
 
430
-		if( ! isset( $counts['failed'] ) ) {
430
+		if ( ! isset($counts['failed'])) {
431 431
 			$counts['failed'] = 0;
432 432
 		}
433 433
 
434
-		if( ! isset( $counts['in-progress'] ) ) {
434
+		if ( ! isset($counts['in-progress'])) {
435 435
 			$counts['in-progress'] = 0;
436 436
 		}
437 437
 
438
-		if( ! isset( $counts['complete'] ) ) {
438
+		if ( ! isset($counts['complete'])) {
439 439
 			$counts['complete'] = 0;
440 440
 		}
441 441
 
442
-		return apply_filters( 'sensei_count_statuses', $counts, $type );
442
+		return apply_filters('sensei_count_statuses', $counts, $type);
443 443
 	} // End sensei_count_statuses()
444 444
 
445 445
 	/**
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
 	 * @since  1.7.0
448 448
 	 * @return string
449 449
 	 */
450
-	public function courses_drop_down_html( $selected_course_id = 0 ) {
450
+	public function courses_drop_down_html($selected_course_id = 0) {
451 451
 
452 452
 		$html = '';
453 453
 
454
-		$course_args = array(   'post_type'         => 'course',
454
+		$course_args = array('post_type'         => 'course',
455 455
 								'posts_per_page'       => -1,
456 456
 								'orderby'           => 'title',
457 457
 								'order'             => 'ASC',
@@ -459,12 +459,12 @@  discard block
 block discarded – undo
459 459
 								'suppress_filters'  => 0,
460 460
 								'fields'            => 'ids',
461 461
 							);
462
-		$courses = get_posts( apply_filters( 'sensei_grading_filter_courses', $course_args ) );
462
+		$courses = get_posts(apply_filters('sensei_grading_filter_courses', $course_args));
463 463
 
464
-		$html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>';
465
-		if ( count( $courses ) > 0 ) {
466
-			foreach ($courses as $course_id){
467
-				$html .= '<option value="' . esc_attr( absint( $course_id ) ) . '" ' . selected( $course_id, $selected_course_id, false ) . '>' . esc_html( get_the_title( $course_id ) ) . '</option>' . "\n";
464
+		$html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>';
465
+		if (count($courses) > 0) {
466
+			foreach ($courses as $course_id) {
467
+				$html .= '<option value="'.esc_attr(absint($course_id)).'" '.selected($course_id, $selected_course_id, false).'>'.esc_html(get_the_title($course_id)).'</option>'."\n";
468 468
 			} // End For Loop
469 469
 		} // End If Statement
470 470
 
@@ -485,20 +485,20 @@  discard block
 block discarded – undo
485 485
 		$course_data = array();
486 486
 		parse_str($data, $course_data);
487 487
 
488
-		$course_id = intval( $course_data['course_id'] );
488
+		$course_id = intval($course_data['course_id']);
489 489
 
490
-		$html = $this->lessons_drop_down_html( $course_id );
490
+		$html = $this->lessons_drop_down_html($course_id);
491 491
 
492 492
 		echo $html;
493 493
 		die(); // WordPress may print out a spurious zero without this can be particularly bad if using JSON
494 494
 	}
495 495
 
496
-	public function lessons_drop_down_html( $course_id = 0, $selected_lesson_id = 0 ) {
496
+	public function lessons_drop_down_html($course_id = 0, $selected_lesson_id = 0) {
497 497
 
498 498
 		$html = '';
499
-		if ( 0 < intval( $course_id ) ) {
499
+		if (0 < intval($course_id)) {
500 500
 
501
-			$lesson_args = array( 'post_type'       => 'lesson',
501
+			$lesson_args = array('post_type'       => 'lesson',
502 502
 								'posts_per_page'       => -1,
503 503
 								'orderby'           => 'title',
504 504
 								'order'             => 'ASC',
@@ -508,12 +508,12 @@  discard block
 block discarded – undo
508 508
 								'suppress_filters'  => 0,
509 509
 								'fields'            => 'ids',
510 510
 								);
511
-			$lessons = get_posts( apply_filters( 'sensei_grading_filter_lessons', $lesson_args ) );
511
+			$lessons = get_posts(apply_filters('sensei_grading_filter_lessons', $lesson_args));
512 512
 
513
-			$html .= '<option value="">' . __( 'Select a lesson', 'woothemes-sensei' ) . '</option>';
514
-			if ( count( $lessons ) > 0 ) {
515
-				foreach ( $lessons as $lesson_id ){
516
-					$html .= '<option value="' . esc_attr( absint( $lesson_id ) ) . '" ' . selected( $lesson_id, $selected_lesson_id, false ) . '>' . esc_html( get_the_title( $lesson_id ) ) . '</option>' . "\n";
513
+			$html .= '<option value="">'.__('Select a lesson', 'woothemes-sensei').'</option>';
514
+			if (count($lessons) > 0) {
515
+				foreach ($lessons as $lesson_id) {
516
+					$html .= '<option value="'.esc_attr(absint($lesson_id)).'" '.selected($lesson_id, $selected_lesson_id, false).'>'.esc_html(get_the_title($lesson_id)).'</option>'."\n";
517 517
 				} // End For Loop
518 518
 			} // End If Statement
519 519
 
@@ -534,10 +534,10 @@  discard block
 block discarded – undo
534 534
     public function admin_process_grading_submission() {
535 535
 
536 536
         // NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
537
-        if( ! isset( $_POST['sensei_manual_grade'] )
538
-            || ! wp_verify_nonce( $_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading' )
539
-            || ! isset( $_GET['quiz_id'] )
540
-            || $_GET['quiz_id'] != $_POST['sensei_manual_grade'] ) {
537
+        if ( ! isset($_POST['sensei_manual_grade'])
538
+            || ! wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading')
539
+            || ! isset($_GET['quiz_id'])
540
+            || $_GET['quiz_id'] != $_POST['sensei_manual_grade']) {
541 541
 
542 542
             return false; //exit and do not grade
543 543
 
@@ -547,30 +547,30 @@  discard block
 block discarded – undo
547 547
         $user_id = $_GET['user'];
548 548
 
549 549
 
550
-        $questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
551
-        $quiz_lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
550
+        $questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
551
+        $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
552 552
         $quiz_grade = 0;
553 553
         $count = 0;
554 554
         $quiz_grade_total = $_POST['quiz_grade_total'];
555 555
         $all_question_grades = array();
556 556
         $all_answers_feedback = array();
557 557
 
558
-        foreach( $questions as $question ) {
558
+        foreach ($questions as $question) {
559 559
 
560 560
             ++$count;
561 561
             $question_id = $question->ID;
562 562
 
563
-            if( isset( $_POST[ 'question_' . $question_id ] ) ) {
563
+            if (isset($_POST['question_'.$question_id])) {
564 564
 
565 565
                 $question_grade = 0;
566
-                if( $_POST[ 'question_' . $question_id ] == 'right' ) {
566
+                if ($_POST['question_'.$question_id] == 'right') {
567 567
 
568
-                    $question_grade = $_POST[ 'question_' . $question_id . '_grade' ];
568
+                    $question_grade = $_POST['question_'.$question_id.'_grade'];
569 569
 
570 570
                 }
571 571
 
572 572
                 // add data to the array that will, after the loop, be stored on the lesson status
573
-                $all_question_grades[ $question_id ] = $question_grade;
573
+                $all_question_grades[$question_id] = $question_grade;
574 574
 
575 575
                 // tally up the total quiz grade
576 576
                 $quiz_grade += $question_grade;
@@ -579,41 +579,41 @@  discard block
 block discarded – undo
579 579
 
580 580
             // Question answer feedback / notes
581 581
             $question_feedback = '';
582
-            if( isset( $_POST[ 'questions_feedback' ][ $question_id ] ) ){
582
+            if (isset($_POST['questions_feedback'][$question_id])) {
583 583
 
584
-                $question_feedback = wp_unslash( $_POST[ 'questions_feedback' ][ $question_id ] );
584
+                $question_feedback = wp_unslash($_POST['questions_feedback'][$question_id]);
585 585
 
586 586
             }
587
-            $all_answers_feedback[ $question_id ] = $question_feedback;
587
+            $all_answers_feedback[$question_id] = $question_feedback;
588 588
 
589 589
         } // end for each $questions
590 590
 
591 591
         //store all question grades on the lesson status
592
-        Sensei()->quiz->set_user_grades( $all_question_grades, $quiz_lesson_id , $user_id );
592
+        Sensei()->quiz->set_user_grades($all_question_grades, $quiz_lesson_id, $user_id);
593 593
 
594 594
         //store the feedback from grading
595
-        Sensei()->quiz->save_user_answers_feedback( $all_answers_feedback, $quiz_lesson_id , $user_id );
595
+        Sensei()->quiz->save_user_answers_feedback($all_answers_feedback, $quiz_lesson_id, $user_id);
596 596
 
597 597
         // $_POST['all_questions_graded'] is set when all questions have been graded
598 598
         // in the class sensei grading user quiz -> display()
599
-        if( $_POST['all_questions_graded'] == 'yes' ) {
599
+        if ($_POST['all_questions_graded'] == 'yes') {
600 600
 
601 601
             // set the users total quiz grade
602
-			if ( 0 < intval( $quiz_grade_total ) ) {
603
-            $grade = abs( round( ( doubleval( $quiz_grade ) * 100 ) / ( $quiz_grade_total ), 2 ) );
602
+			if (0 < intval($quiz_grade_total)) {
603
+            $grade = abs(round((doubleval($quiz_grade) * 100) / ($quiz_grade_total), 2));
604 604
 			}
605 605
 			else {
606 606
 				$grade = 0;
607 607
 			}
608
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id );
608
+            Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id);
609 609
 
610 610
             // Duplicating what Frontend->sensei_complete_quiz() does
611
-            $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
612
-            $quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
611
+            $pass_required = get_post_meta($quiz_id, '_pass_required', true);
612
+            $quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
613 613
             $lesson_metadata = array();
614
-            if ( $pass_required ) {
614
+            if ($pass_required) {
615 615
                 // Student has reached the pass mark and lesson is complete
616
-                if ( $quiz_passmark <= $grade ) {
616
+                if ($quiz_passmark <= $grade) {
617 617
                     $lesson_status = 'passed';
618 618
                 }
619 619
                 else {
@@ -626,9 +626,9 @@  discard block
 block discarded – undo
626 626
             }
627 627
             $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
628 628
 
629
-            Sensei_Utils::update_lesson_status( $user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata );
629
+            Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata);
630 630
 
631
-            if(  in_array( $lesson_status, array( 'passed', 'graded'  ) ) ) {
631
+            if (in_array($lesson_status, array('passed', 'graded'))) {
632 632
 
633 633
                 /**
634 634
                  * Summary.
@@ -640,27 +640,27 @@  discard block
 block discarded – undo
640 640
                  * @param int  $user_id
641 641
                  * @param int $quiz_lesson_id
642 642
                  */
643
-                do_action( 'sensei_user_lesson_end', $user_id, $quiz_lesson_id );
643
+                do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id);
644 644
 
645 645
             } // end if in_array
646 646
 
647 647
         }// end if $_POST['all_que...
648 648
 
649
-        if( isset( $_POST['sensei_grade_next_learner'] ) && strlen( $_POST['sensei_grade_next_learner'] ) > 0 ) {
649
+        if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) {
650 650
 
651
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
651
+            $load_url = add_query_arg(array('message' => 'graded'));
652 652
 
653
-        } elseif ( isset( $_POST['_wp_http_referer'] ) ) {
653
+        } elseif (isset($_POST['_wp_http_referer'])) {
654 654
 
655
-            $load_url = add_query_arg( array( 'message' => 'graded' ), $_POST['_wp_http_referer'] );
655
+            $load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']);
656 656
 
657 657
         } else {
658 658
 
659
-            $load_url = add_query_arg( array( 'message' => 'graded' ) );
659
+            $load_url = add_query_arg(array('message' => 'graded'));
660 660
 
661 661
         }
662 662
 
663
-        wp_safe_redirect( esc_url_raw( $load_url ) );
663
+        wp_safe_redirect(esc_url_raw($load_url));
664 664
         exit;
665 665
 
666 666
     } // end admin_process_grading_submission
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
 		$lesson_data = array();
672 672
 		parse_str($data, $lesson_data);
673 673
 
674
-		$lesson_id = intval( $lesson_data['lesson_id'] );
675
-		$course_id = intval( $lesson_data['course_id'] );
676
-		$grading_view = sanitize_text_field( $lesson_data['view'] );
674
+		$lesson_id = intval($lesson_data['lesson_id']);
675
+		$course_id = intval($lesson_data['course_id']);
676
+		$grading_view = sanitize_text_field($lesson_data['view']);
677 677
 
678 678
 		$redirect_url = '';
679
-		if ( 0 < $lesson_id && 0 < $course_id ) {
680
-			$redirect_url = esc_url_raw( apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view ), admin_url( 'admin.php' ) ) ) );
679
+		if (0 < $lesson_id && 0 < $course_id) {
680
+			$redirect_url = esc_url_raw(apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $lesson_id, 'course_id' => $course_id, 'view' => $grading_view), admin_url('admin.php'))));
681 681
 		} // End If Statement
682 682
 
683 683
 		echo $redirect_url;
@@ -685,11 +685,11 @@  discard block
 block discarded – undo
685 685
 	}
686 686
 
687 687
 	public function add_grading_notices() {
688
-		if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) {
689
-			if( 'graded' == $_GET['message'] ) {
688
+		if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) {
689
+			if ('graded' == $_GET['message']) {
690 690
 				$msg = array(
691 691
 					'updated',
692
-					__( 'Quiz Graded Successfully!', 'woothemes-sensei' ),
692
+					__('Quiz Graded Successfully!', 'woothemes-sensei'),
693 693
 				);
694 694
 			}
695 695
 			?>
@@ -701,9 +701,9 @@  discard block
 block discarded – undo
701 701
 	}
702 702
 
703 703
 	public function sensei_grading_notices() {
704
-		if ( isset( $_GET['action'] ) && 'graded' == $_GET['action'] ) {
704
+		if (isset($_GET['action']) && 'graded' == $_GET['action']) {
705 705
 			echo '<div class="grading-notice updated">';
706
-				echo '<p>' . __( 'Quiz Graded Successfully!', 'woothemes-sensei' ) . '</p>';
706
+				echo '<p>'.__('Quiz Graded Successfully!', 'woothemes-sensei').'</p>';
707 707
 			echo '</div>';
708 708
 		} // End If Statement
709 709
 	} // End sensei_grading_notices()
@@ -726,16 +726,16 @@  discard block
 block discarded – undo
726 726
      *
727 727
      * @return int $quiz_grade total sum of all question grades
728 728
      */
729
-    public static function grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
729
+    public static function grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') {
730 730
 
731
-        if( ! ( intval( $quiz_id ) > 0 )  || ! $submitted
732
-            || $quiz_grade_type != 'auto' ) {
731
+        if ( ! (intval($quiz_id) > 0) || ! $submitted
732
+            || $quiz_grade_type != 'auto') {
733 733
             return false; // exit early
734 734
         }
735 735
 
736 736
 
737 737
         $user_id = get_current_user_id();
738
-        $lesson_id =  Sensei()->quiz->get_lesson_id(  $quiz_id ) ;
738
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
739 739
         $quiz_autogradable = true;
740 740
 
741 741
         /**
@@ -749,23 +749,23 @@  discard block
 block discarded – undo
749 749
          *      'gap-fill'.
750 750
          * }
751 751
          */
752
-        $autogradable_question_types = apply_filters( 'sensei_autogradable_question_types', array( 'multiple-choice', 'boolean', 'gap-fill' ) );
752
+        $autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill'));
753 753
 
754 754
         $grade_total = 0;
755 755
         $all_question_grades = array();
756
-        foreach( $submitted as $question_id => $answer ) {
756
+        foreach ($submitted as $question_id => $answer) {
757 757
 
758 758
             // check if the question is autogradable, either by type, or because the grade is 0
759
-            $question_type = Sensei()->question->get_question_type( $question_id );
760
-			$achievable_grade = Sensei()->question->get_question_grade( $question_id );
759
+            $question_type = Sensei()->question->get_question_type($question_id);
760
+			$achievable_grade = Sensei()->question->get_question_grade($question_id);
761 761
 			// Question has a zero grade, so skip grading
762
-			if ( 0 == $achievable_grade ) {
763
-				$all_question_grades[ $question_id ] = $achievable_grade;
762
+			if (0 == $achievable_grade) {
763
+				$all_question_grades[$question_id] = $achievable_grade;
764 764
 			}
765
-            elseif ( in_array( $question_type, $autogradable_question_types ) ) {
765
+            elseif (in_array($question_type, $autogradable_question_types)) {
766 766
                 // Get user question grade
767
-                $question_grade = Sensei_Utils::sensei_grade_question_auto( $question_id, $question_type, $answer, $user_id );
768
-                $all_question_grades[ $question_id ] = $question_grade;
767
+                $question_grade = Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id);
768
+                $all_question_grades[$question_id] = $question_grade;
769 769
                 $grade_total += $question_grade;
770 770
 
771 771
             } else {
@@ -778,27 +778,27 @@  discard block
 block discarded – undo
778 778
         }// end for each question
779 779
 
780 780
         // Only if the whole quiz was autogradable do we set a grade
781
-        if ( $quiz_autogradable ) {
781
+        if ($quiz_autogradable) {
782 782
 
783
-            $quiz_total = Sensei_Utils::sensei_get_quiz_total( $quiz_id );
783
+            $quiz_total = Sensei_Utils::sensei_get_quiz_total($quiz_id);
784 784
 			// Check for zero total from grades
785
-			if ( 0 < $quiz_total ) {
786
-            $grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );
785
+			if (0 < $quiz_total) {
786
+            $grade = abs(round((doubleval($grade_total) * 100) / ($quiz_total), 2));
787 787
 			}
788 788
 			else {
789 789
 				$grade = 0;
790 790
 			}
791
-            Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade, $user_id, $quiz_grade_type );
791
+            Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type);
792 792
 
793 793
         } else {
794 794
 
795
-            $grade = new WP_Error( 'autograde', __( 'This quiz is not able to be automatically graded.', 'woothemes-sensei' ) );
795
+            $grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei'));
796 796
 
797 797
         }
798 798
 
799 799
         // store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
800 800
         // when doing manual grading.
801
-        Sensei()->quiz-> set_user_grades( $all_question_grades, $lesson_id, $user_id );
801
+        Sensei()->quiz-> set_user_grades($all_question_grades, $lesson_id, $user_id);
802 802
 
803 803
         return $grade;
804 804
 
@@ -818,22 +818,22 @@  discard block
 block discarded – undo
818 818
      *
819 819
      * @return int $question_grade
820 820
      */
821
-    public static function grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
821
+    public static function grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) {
822 822
 
823
-        if( intval( $user_id ) == 0 ) {
823
+        if (intval($user_id) == 0) {
824 824
 
825 825
             $user_id = get_current_user_id();
826 826
 
827 827
         }
828 828
 
829
-        if( ! ( intval( $question_id ) > 0 ) ) {
829
+        if ( ! (intval($question_id) > 0)) {
830 830
 
831 831
             return false;
832 832
 
833 833
         }
834 834
 
835 835
 
836
-        Sensei()->question->get_question_type( $question_id );
836
+        Sensei()->question->get_question_type($question_id);
837 837
 
838 838
         /**
839 839
          * Applying a grade before the auto grading takes place.
@@ -847,42 +847,42 @@  discard block
 block discarded – undo
847 847
          * @param string $question_type one of the Sensei question type.
848 848
          * @param string $answer user supplied question answer
849 849
          */
850
-        $question_grade = apply_filters( 'sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer );
850
+        $question_grade = apply_filters('sensei_pre_grade_question_auto', false, $question_id, $question_type, $answer);
851 851
 
852
-        if ( false !== $question_grade ) {
852
+        if (false !== $question_grade) {
853 853
 
854 854
             return $question_grade;
855 855
 
856 856
         }
857 857
 
858 858
         // auto grading core
859
-        if( in_array( $question_type ,  array( 'multiple-choice'  , 'boolean'  ) )   ){
859
+        if (in_array($question_type, array('multiple-choice', 'boolean'))) {
860 860
 
861
-            $right_answer = (array) get_post_meta( $question_id, '_question_right_answer', true );
861
+            $right_answer = (array) get_post_meta($question_id, '_question_right_answer', true);
862 862
 
863
-            if( 0 == get_magic_quotes_gpc() ) {
864
-                $answer = wp_unslash( $answer );
863
+            if (0 == get_magic_quotes_gpc()) {
864
+                $answer = wp_unslash($answer);
865 865
             }
866 866
             $answer = (array) $answer;
867
-            if ( is_array( $right_answer ) && count( $right_answer ) == count( $answer ) ) {
867
+            if (is_array($right_answer) && count($right_answer) == count($answer)) {
868 868
                 // Loop through all answers ensure none are 'missing'
869 869
                 $all_correct = true;
870
-                foreach ( $answer as $check_answer ) {
871
-                    if ( !in_array( $check_answer, $right_answer ) ) {
870
+                foreach ($answer as $check_answer) {
871
+                    if ( ! in_array($check_answer, $right_answer)) {
872 872
                         $all_correct = false;
873 873
                     }
874 874
                 }
875 875
                 // If all correct then grade
876
-                if ( $all_correct ) {
877
-                    $question_grade = Sensei()->question->get_question_grade( $question_id );
876
+                if ($all_correct) {
877
+                    $question_grade = Sensei()->question->get_question_grade($question_id);
878 878
                 }
879 879
             }
880 880
 
881
-        } elseif( 'gap-fill' == $question_type ){
881
+        } elseif ('gap-fill' == $question_type) {
882 882
 
883
-            $question_grade = self::grade_gap_fill_question( $question_id ,$answer );
883
+            $question_grade = self::grade_gap_fill_question($question_id, $answer);
884 884
 
885
-        } else{
885
+        } else {
886 886
 
887 887
             /**
888 888
              * Grading questions that are not auto gradable.
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
              * @param string $question_type one of the Sensei question type.
896 896
              * @param string $answer user supplied question answer
897 897
              */
898
-            $question_grade = ( int ) apply_filters( 'sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer );
898
+            $question_grade = (int) apply_filters('sensei_grade_question_auto', $question_grade, $question_id, $question_type, $answer);
899 899
 
900 900
         } // end if $question_type
901 901
 
@@ -911,13 +911,13 @@  discard block
 block discarded – undo
911 911
      *
912 912
      * @return bool | int false or the grade given to the user answer
913 913
      */
914
-    public static function grade_gap_fill_question( $question_id, $user_answer ){
914
+    public static function grade_gap_fill_question($question_id, $user_answer) {
915 915
 
916
-        $right_answer = get_post_meta( $question_id, '_question_right_answer', true );
917
-        $gapfill_array = explode( '||', $right_answer );
916
+        $right_answer = get_post_meta($question_id, '_question_right_answer', true);
917
+        $gapfill_array = explode('||', $right_answer);
918 918
 
919
-        if( 0 == get_magic_quotes_gpc() ) { // deprecated from PHP 5.4 but we still support PHP 5.2
920
-            $user_answer = wp_unslash( $user_answer );
919
+        if (0 == get_magic_quotes_gpc()) { // deprecated from PHP 5.4 but we still support PHP 5.2
920
+            $user_answer = wp_unslash($user_answer);
921 921
         }
922 922
 
923 923
         /**
@@ -930,53 +930,53 @@  discard block
 block discarded – undo
930 930
          *
931 931
          * @since 1.9.0
932 932
          */
933
-        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false );
933
+        $do_case_sensitive_comparison = apply_filters('sensei_gap_fill_case_sensitive_grading', false);
934 934
 
935
-        if( $do_case_sensitive_comparison ){
935
+        if ($do_case_sensitive_comparison) {
936 936
 
937 937
             // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
938
-            if ( trim(($gapfill_array[1])) == trim( $user_answer ) ) {
938
+            if (trim(($gapfill_array[1])) == trim($user_answer)) {
939 939
 
940
-                return Sensei()->question->get_question_grade( $question_id );
940
+                return Sensei()->question->get_question_grade($question_id);
941 941
 
942
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
942
+            } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) {
943 943
 
944
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
944
+                if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) {
945 945
 
946 946
                     return Sensei()->question->get_question_grade($question_id);
947 947
 
948
-                }else{
948
+                } else {
949 949
 
950 950
                     return false;
951 951
 
952 952
                 }
953 953
 
954
-            }else{
954
+            } else {
955 955
 
956 956
                 return false;
957 957
 
958 958
             }
959 959
 
960
-        }else{
960
+        } else {
961 961
 
962 962
             // Case Sensitive Check that the 'gap' is "exactly" equal to the given answer
963
-            if ( trim(strtolower($gapfill_array[1])) == trim(strtolower( $user_answer )) ) {
963
+            if (trim(strtolower($gapfill_array[1])) == trim(strtolower($user_answer))) {
964 964
 
965
-               return Sensei()->question->get_question_grade( $question_id );
965
+               return Sensei()->question->get_question_grade($question_id);
966 966
 
967
-            } else if (@preg_match('/' . $gapfill_array[1] . '/i', null) !== FALSE) {
967
+            } else if (@preg_match('/'.$gapfill_array[1].'/i', null) !== FALSE) {
968 968
 
969
-                if (preg_match('/' . $gapfill_array[1] . '/i', $user_answer)) {
969
+                if (preg_match('/'.$gapfill_array[1].'/i', $user_answer)) {
970 970
 
971
-                    return  Sensei()->question->get_question_grade( $question_id );
971
+                    return  Sensei()->question->get_question_grade($question_id);
972 972
 
973
-                }else{
973
+                } else {
974 974
 
975 975
                     return false;
976 976
 
977 977
                 }
978 978
 
979
-            }else{
979
+            } else {
980 980
 
981 981
                 return false;
982 982
 
@@ -993,4 +993,4 @@  discard block
 block discarded – undo
993 993
  * for backward compatibility
994 994
  * @since 1.9.0
995 995
  */
996
-class WooThemes_Sensei_Grading extends Sensei_Grading{}
996
+class WooThemes_Sensei_Grading extends Sensei_Grading {}
Please login to merge, or discard this patch.
includes/class-sensei-learners.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -21,6 +21,7 @@
 block discarded – undo
21 21
 	/**
22 22
 	 * Constructor
23 23
 	 * @since  1.6.0
24
+	 * @param string $file
24 25
 	 * @return  void
25 26
 	 */
26 27
 	public function __construct ( $file ) {
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -79,17 +79,17 @@  discard block
 block discarded – undo
79 79
 
80 80
 		// Load Learners JS
81 81
 		wp_enqueue_script( 'sensei-learners-general',
82
-            Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
83
-                            array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true );
82
+			Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
83
+							array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true );
84 84
 
85 85
 		$data = array(
86 86
 			'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ),
87 87
 			'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ),
88 88
 			'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ),
89
-            'remove_from_purchased_course_confirm' => __( 'Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei' ),
89
+			'remove_from_purchased_course_confirm' => __( 'Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei' ),
90 90
 			'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ),
91
-            'search_users_nonce' => wp_create_nonce( 'search-users' ),
92
-            'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
91
+			'search_users_nonce' => wp_create_nonce( 'search-users' ),
92
+			'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
93 93
 		);
94 94
 
95 95
 		wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data );
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 			$user_id = intval( $action_data['user_id'] );
275 275
 			$post_id = intval( $action_data['post_id'] );
276 276
 			$post_type = sanitize_text_field( $action_data['post_type'] );
277
-            $order_id = sanitize_text_field( $action_data['order_id'] );
277
+			$order_id = sanitize_text_field( $action_data['order_id'] );
278 278
 
279 279
 			$user = get_userdata( $user_id );
280 280
 
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
 				case 'course':
284 284
 					$removed = WooThemes_Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
285 285
 
286
-                    if( ! empty( $order_id ) && Sensei_WC::is_woocommerce_active()  ){
286
+					if( ! empty( $order_id ) && Sensei_WC::is_woocommerce_active()  ){
287 287
 
288
-                        $order = new WC_Order($order_id);
288
+						$order = new WC_Order($order_id);
289 289
 
290
-                        if (!empty($order)) {
291
-                            $order->update_status( 'cancelled' );
292
-                        }
290
+						if (!empty($order)) {
291
+							$order->update_status( 'cancelled' );
292
+						}
293 293
 
294
-                    }
294
+					}
295 295
 
296 296
 				break;
297 297
 
@@ -336,19 +336,19 @@  discard block
 block discarded – undo
336 336
 
337 337
 		if ( $users ) {
338 338
 			foreach ( $users as $user ) {
339
-                $full_name = Sensei()->learners->get_learner_full_name( $user->ID );
339
+				$full_name = Sensei()->learners->get_learner_full_name( $user->ID );
340 340
 
341
-                if( trim($user->display_name ) == trim( $full_name ) ){
341
+				if( trim($user->display_name ) == trim( $full_name ) ){
342 342
 
343
-                    $name = $full_name;
343
+					$name = $full_name;
344 344
 
345
-                }else{
345
+				}else{
346 346
 
347
-                    $name = $full_name . ' ['. $user->display_name .']';
347
+					$name = $full_name . ' ['. $user->display_name .']';
348 348
 
349
-                }
349
+				}
350 350
 
351
-                $found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' &ndash; ' . sanitize_email( $user->user_email ) . ')';
351
+				$found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' &ndash; ' . sanitize_email( $user->user_email ) . ')';
352 352
 			}
353 353
 		}
354 354
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 			break;
393 393
 
394 394
 			case 'lesson':
395
-                $lesson_id = absint( $_POST['add_lesson_id'] );
395
+				$lesson_id = absint( $_POST['add_lesson_id'] );
396 396
 				$complete = false;
397 397
 				if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) {
398 398
 					$complete = true;
@@ -452,49 +452,49 @@  discard block
 block discarded – undo
452 452
 		}
453 453
 	}
454 454
 
455
-    /**
456
-     * Return the full name and surname or the display name of the user.
457
-     *
458
-     * The user must have both name and surname otherwise display name will be returned.
459
-     *
460
-     * @since 1.8.0
461
-     *
462
-     * @param int $user_id | bool false for an invalid $user_id
463
-     *
464
-     * @return string $full_name
465
-     */
466
-    public function get_learner_full_name( $user_id ){
455
+	/**
456
+	 * Return the full name and surname or the display name of the user.
457
+	 *
458
+	 * The user must have both name and surname otherwise display name will be returned.
459
+	 *
460
+	 * @since 1.8.0
461
+	 *
462
+	 * @param int $user_id | bool false for an invalid $user_id
463
+	 *
464
+	 * @return string $full_name
465
+	 */
466
+	public function get_learner_full_name( $user_id ){
467 467
 
468
-        $full_name = '';
468
+		$full_name = '';
469 469
 
470
-        if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
471
-            || !( get_userdata( $user_id ) ) ){
472
-            return false;
473
-        }
470
+		if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
471
+			|| !( get_userdata( $user_id ) ) ){
472
+			return false;
473
+		}
474 474
 
475
-        // get the user details
476
-        $user = get_user_by( 'id', $user_id );
475
+		// get the user details
476
+		$user = get_user_by( 'id', $user_id );
477 477
 
478
-        if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
478
+		if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
479 479
 
480
-            $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
480
+			$full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
481 481
 
482
-        }else{
482
+		}else{
483 483
 
484
-            $full_name =  $user->display_name;
484
+			$full_name =  $user->display_name;
485 485
 
486
-        }
486
+		}
487 487
 
488
-        /**
489
-         * Filter the user full name from the get_learner_full_name function.
490
-         *
491
-         * @since 1.8.0
492
-         * @param $full_name
493
-         * @param $user_id
494
-         */
495
-        return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
488
+		/**
489
+		 * Filter the user full name from the get_learner_full_name function.
490
+		 *
491
+		 * @since 1.8.0
492
+		 * @param $full_name
493
+		 * @param $user_id
494
+		 */
495
+		return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
496 496
 
497
-    } // end get_learner_full_name
497
+	} // end get_learner_full_name
498 498
 
499 499
 } // End Class
500 500
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 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 Learners Class
@@ -342,7 +345,7 @@  discard block
 block discarded – undo
342 345
 
343 346
                     $name = $full_name;
344 347
 
345
-                }else{
348
+                } else{
346 349
 
347 350
                     $name = $full_name . ' ['. $user->display_name .']';
348 351
 
@@ -359,11 +362,17 @@  discard block
 block discarded – undo
359 362
 
360 363
 		$result = false;
361 364
 
362
-		if( ! isset( $_POST['add_learner_submit'] ) ) return $result;
365
+		if( ! isset( $_POST['add_learner_submit'] ) ) {
366
+			return $result;
367
+		}
363 368
 
364
-		if ( ! isset( $_POST['add_learner_nonce'] ) || ! wp_verify_nonce( $_POST['add_learner_nonce'], 'add_learner_to_sensei' ) ) return $result;
369
+		if ( ! isset( $_POST['add_learner_nonce'] ) || ! wp_verify_nonce( $_POST['add_learner_nonce'], 'add_learner_to_sensei' ) ) {
370
+			return $result;
371
+		}
365 372
 
366
-		if( ( ! isset( $_POST['add_user_id'] ) || '' ==  $_POST['add_user_id'] ) || ! isset( $_POST['add_post_type'] ) || ! isset( $_POST['add_course_id'] ) || ! isset( $_POST['add_lesson_id'] ) ) return $result;
373
+		if( ( ! isset( $_POST['add_user_id'] ) || '' ==  $_POST['add_user_id'] ) || ! isset( $_POST['add_post_type'] ) || ! isset( $_POST['add_course_id'] ) || ! isset( $_POST['add_lesson_id'] ) ) {
374
+			return $result;
375
+		}
367 376
 
368 377
 		$post_type = $_POST['add_post_type'];
369 378
 		$user_id = absint( $_POST['add_user_id'] );
@@ -479,7 +488,7 @@  discard block
 block discarded – undo
479 488
 
480 489
             $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
481 490
 
482
-        }else{
491
+        } else{
483 492
 
484 493
             $full_name =  $user->display_name;
485 494
 
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Learners Class
@@ -23,30 +23,30 @@  discard block
 block discarded – undo
23 23
 	 * @since  1.6.0
24 24
 	 * @return  void
25 25
 	 */
26
-	public function __construct ( $file ) {
27
-		$this->name = __( 'Learner Management', 'woothemes-sensei' );;
26
+	public function __construct($file) {
27
+		$this->name = __('Learner Management', 'woothemes-sensei'); ;
28 28
 		$this->file = $file;
29 29
 		$this->page_slug = 'sensei_learners';
30 30
 
31 31
 		// Admin functions
32
-		if ( is_admin() ) {
33
-			add_action( 'admin_menu', array( $this, 'learners_admin_menu' ), 30);
34
-			add_action( 'learners_wrapper_container', array( $this, 'wrapper_container'  ) );
35
-			if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
36
-				add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
37
-				add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
32
+		if (is_admin()) {
33
+			add_action('admin_menu', array($this, 'learners_admin_menu'), 30);
34
+			add_action('learners_wrapper_container', array($this, 'wrapper_container'));
35
+			if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
36
+				add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
37
+				add_action('admin_print_styles', array($this, 'enqueue_styles'));
38 38
 			}
39 39
 
40
-			add_action( 'admin_init', array( $this, 'add_new_learners' ) );
40
+			add_action('admin_init', array($this, 'add_new_learners'));
41 41
 
42
-			add_action( 'admin_notices', array( $this, 'add_learner_notices' ) );
42
+			add_action('admin_notices', array($this, 'add_learner_notices'));
43 43
 		} // End If Statement
44 44
 
45 45
 		// Ajax functions
46
-		if ( is_admin() ) {
47
-			add_action( 'wp_ajax_get_redirect_url_learners', array( $this, 'get_redirect_url' ) );
48
-			add_action( 'wp_ajax_remove_user_from_post', array( $this, 'remove_user_from_post' ) );
49
-			add_action( 'wp_ajax_sensei_json_search_users', array( $this, 'json_search_users' ) );
46
+		if (is_admin()) {
47
+			add_action('wp_ajax_get_redirect_url_learners', array($this, 'get_redirect_url'));
48
+			add_action('wp_ajax_remove_user_from_post', array($this, 'remove_user_from_post'));
49
+			add_action('wp_ajax_sensei_json_search_users', array($this, 'json_search_users'));
50 50
 		}
51 51
 	} // End __construct()
52 52
 
@@ -59,8 +59,8 @@  discard block
 block discarded – undo
59 59
 	public function learners_admin_menu() {
60 60
 		global $menu;
61 61
 
62
-		if ( current_user_can( 'manage_sensei_grades' ) ) {
63
-			$learners_page = add_submenu_page( 'sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array( $this, 'learners_page' ) );
62
+		if (current_user_can('manage_sensei_grades')) {
63
+			$learners_page = add_submenu_page('sensei', $this->name, $this->name, 'manage_sensei_grades', $this->page_slug, array($this, 'learners_page'));
64 64
 		}
65 65
 
66 66
 	} // End learners_admin_menu()
@@ -73,26 +73,26 @@  discard block
 block discarded – undo
73 73
 	 * @since 1.6.0
74 74
 	 * @return void
75 75
 	 */
76
-	public function enqueue_scripts () {
76
+	public function enqueue_scripts() {
77 77
 
78
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
78
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
79 79
 
80 80
 		// Load Learners JS
81
-		wp_enqueue_script( 'sensei-learners-general',
82
-            Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
83
-                            array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true );
81
+		wp_enqueue_script('sensei-learners-general',
82
+            Sensei()->plugin_url.'assets/js/learners-general'.$suffix.'.js',
83
+                            array('jquery', 'select2', 'sensei-chosen-ajax'), Sensei()->version, true);
84 84
 
85 85
 		$data = array(
86
-			'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ),
87
-			'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ),
88
-			'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ),
89
-            'remove_from_purchased_course_confirm' => __( 'Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei' ),
90
-			'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ),
91
-            'search_users_nonce' => wp_create_nonce( 'search-users' ),
92
-            'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
86
+			'remove_generic_confirm' => __('Are you sure you want to remove this user?', 'woothemes-sensei'),
87
+			'remove_from_lesson_confirm' => __('Are you sure you want to remove the user from this lesson?', 'woothemes-sensei'),
88
+			'remove_from_course_confirm' => __('Are you sure you want to remove the user from this course?', 'woothemes-sensei'),
89
+            'remove_from_purchased_course_confirm' => __('Are you sure you want to remove the user from this course? This order associate with this will also be set to canceled.', 'woothemes-sensei'),
90
+			'remove_user_from_post_nonce' => wp_create_nonce('remove_user_from_post_nonce'),
91
+            'search_users_nonce' => wp_create_nonce('search-users'),
92
+            'selectplaceholder'=> __('Select Learner', 'woothemes-sensei')
93 93
 		);
94 94
 
95
-		wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data );
95
+		wp_localize_script('sensei-learners-general', 'woo_learners_general_data', $data);
96 96
 
97 97
 	} // End enqueue_scripts()
98 98
 
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 	 * @since 1.6.0
105 105
 	 * @return void
106 106
 	 */
107
-	public function enqueue_styles () {
107
+	public function enqueue_styles() {
108 108
 
109
-		wp_enqueue_style( Sensei()->token . '-admin' );
109
+		wp_enqueue_style(Sensei()->token.'-admin');
110 110
 
111 111
 	} // End enqueue_styles()
112 112
 
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
 	public function load_data_table_files() {
119 119
 
120 120
 		// Load Learners Classes
121
-		$classes_to_load = array(	'list-table',
121
+		$classes_to_load = array('list-table',
122 122
 									'learners-main',
123 123
 									);
124
-		foreach ( $classes_to_load as $class_file ) {
125
-			Sensei()->load_class( $class_file );
124
+		foreach ($classes_to_load as $class_file) {
125
+			Sensei()->load_class($class_file);
126 126
 		} // End For Loop
127 127
 	} // End load_data_table_files()
128 128
 
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
 	 * @param  undefined  $optional_data optional constructor arguments
135 135
 	 * @return object                 class instance object
136 136
 	 */
137
-	public function load_data_object( $name = '', $data = 0, $optional_data = null ) {
137
+	public function load_data_object($name = '', $data = 0, $optional_data = null) {
138 138
 		// Load Analysis data
139
-		$object_name = 'WooThemes_Sensei_Learners_' . $name;
140
-		if ( is_null($optional_data) ) {
141
-			$sensei_learners_object = new $object_name( $data );
139
+		$object_name = 'WooThemes_Sensei_Learners_'.$name;
140
+		if (is_null($optional_data)) {
141
+			$sensei_learners_object = new $object_name($data);
142 142
 		} else {
143
-			$sensei_learners_object = new $object_name( $data, $optional_data );
143
+			$sensei_learners_object = new $object_name($data, $optional_data);
144 144
 		} // End If Statement
145
-		if ( 'Main' == $name ) {
145
+		if ('Main' == $name) {
146 146
 			$sensei_learners_object->prepare_items();
147 147
 		} // End If Statement
148 148
 		return $sensei_learners_object;
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
 		// Load Learners data
160 160
 		$course_id = 0;
161 161
 		$lesson_id = 0;
162
-		if( isset( $_GET['course_id'] ) ) {
163
-			$course_id = intval( $_GET['course_id'] );
162
+		if (isset($_GET['course_id'])) {
163
+			$course_id = intval($_GET['course_id']);
164 164
 		}
165
-		if( isset( $_GET['lesson_id'] ) ) {
166
-			$lesson_id = intval( $_GET['lesson_id'] );
165
+		if (isset($_GET['lesson_id'])) {
166
+			$lesson_id = intval($_GET['lesson_id']);
167 167
 		}
168
-		$sensei_learners_main = $this->load_data_object( 'Main', $course_id, $lesson_id );
168
+		$sensei_learners_main = $this->load_data_object('Main', $course_id, $lesson_id);
169 169
 		// Wrappers
170
-		do_action( 'learners_before_container' );
171
-		do_action( 'learners_wrapper_container', 'top' );
170
+		do_action('learners_before_container');
171
+		do_action('learners_wrapper_container', 'top');
172 172
 		$this->learners_headers();
173 173
 		?>
174 174
 		<div id="poststuff" class="sensei-learners-wrap">
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 				<?php $sensei_learners_main->display(); ?>
177 177
 			</div>
178 178
 			<div class="sensei-learners-extra">
179
-				<?php do_action( 'sensei_learners_extra' ); ?>
179
+				<?php do_action('sensei_learners_extra'); ?>
180 180
 			</div>
181 181
 		</div>
182 182
 		<?php
183
-		do_action( 'learners_wrapper_container', 'bottom' );
184
-		do_action( 'learners_after_container' );
183
+		do_action('learners_wrapper_container', 'bottom');
184
+		do_action('learners_after_container');
185 185
 	} // End learners_default_view()
186 186
 
187 187
 	/**
@@ -189,15 +189,15 @@  discard block
 block discarded – undo
189 189
 	 * @since  1.6.0
190 190
 	 * @return void
191 191
 	 */
192
-	public function learners_headers( $args = array( 'nav' => 'default' ) ) {
192
+	public function learners_headers($args = array('nav' => 'default')) {
193 193
 
194 194
 
195
-		$function = 'learners_' . $args['nav'] . '_nav';
195
+		$function = 'learners_'.$args['nav'].'_nav';
196 196
 		$this->$function();
197 197
 		?>
198
-			<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>
198
+			<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>
199 199
 		<?php
200
-		do_action( 'sensei_learners_after_headers' );
200
+		do_action('sensei_learners_after_headers');
201 201
 	} // End learners_headers()
202 202
 
203 203
 	/**
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
 	 * @param $which string
207 207
 	 * @return void
208 208
 	 */
209
-	public function wrapper_container( $which ) {
210
-		if ( 'top' == $which ) {
211
-			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>"><?php
212
-		} elseif ( 'bottom' == $which ) {
209
+	public function wrapper_container($which) {
210
+		if ('top' == $which) {
211
+			?><div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>"><?php
212
+		} elseif ('bottom' == $which) {
213 213
 			?></div><!--/#woothemes-sensei--><?php
214 214
 		} // End If Statement
215 215
 	} // End wrapper_container()
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
 	 * @return void
221 221
 	 */
222 222
 	public function learners_default_nav() {
223
-		$title = sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => $this->page_slug ), admin_url( 'admin.php' ) ) ), esc_html( $this->name ) );
224
-		if ( isset( $_GET['course_id'] ) ) { 
225
-			$course_id = intval( $_GET['course_id'] );
226
-			$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners' ), admin_url( 'admin.php' ) );
227
-			$title .= sprintf( '&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url( $url ), get_the_title( $course_id ) );
223
+		$title = sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('page' => $this->page_slug), admin_url('admin.php'))), esc_html($this->name));
224
+		if (isset($_GET['course_id'])) { 
225
+			$course_id = intval($_GET['course_id']);
226
+			$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id, 'view' => 'learners'), admin_url('admin.php'));
227
+			$title .= sprintf('&nbsp;&nbsp;<span class="course-title">&gt;&nbsp;&nbsp;<a href="%s">%s</a></span>', esc_url($url), get_the_title($course_id));
228 228
 		}
229
-		if ( isset( $_GET['lesson_id'] ) ) { 
230
-			$lesson_id = intval( $_GET['lesson_id'] );
231
-			$title .= '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;' . get_the_title( intval( $lesson_id ) ) . '</span>'; 
229
+		if (isset($_GET['lesson_id'])) { 
230
+			$lesson_id = intval($_GET['lesson_id']);
231
+			$title .= '&nbsp;&nbsp;<span class="lesson-title">&gt;&nbsp;&nbsp;'.get_the_title(intval($lesson_id)).'</span>'; 
232 232
 		}
233 233
 		?>
234
-			<h2><?php echo apply_filters( 'sensei_learners_nav_title', $title ); ?></h2>
234
+			<h2><?php echo apply_filters('sensei_learners_nav_title', $title); ?></h2>
235 235
 		<?php
236 236
 	} // End learners_default_nav()
237 237
 
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 		// Parse POST data
241 241
 		$data = $_POST['data'];
242 242
 		$course_data = array();
243
-		parse_str( $data, $course_data );
243
+		parse_str($data, $course_data);
244 244
 
245
-		$course_cat = intval( $course_data['course_cat'] );
245
+		$course_cat = intval($course_data['course_cat']);
246 246
 
247
-		$redirect_url = apply_filters( 'sensei_ajax_redirect_url', add_query_arg( array( 'page' => $this->page_slug, 'course_cat' => $course_cat ), admin_url( 'admin.php' ) ) );
247
+		$redirect_url = apply_filters('sensei_ajax_redirect_url', add_query_arg(array('page' => $this->page_slug, 'course_cat' => $course_cat), admin_url('admin.php')));
248 248
 
249
-		echo esc_url_raw( $redirect_url );
249
+		echo esc_url_raw($redirect_url);
250 250
 		die();
251 251
 	}
252 252
 
@@ -257,38 +257,38 @@  discard block
 block discarded – undo
257 257
 
258 258
 		// Security check
259 259
 		$nonce = '';
260
-		if ( isset($_POST['remove_user_from_post_nonce']) ) {
261
-			$nonce = esc_html( $_POST['remove_user_from_post_nonce'] );
260
+		if (isset($_POST['remove_user_from_post_nonce'])) {
261
+			$nonce = esc_html($_POST['remove_user_from_post_nonce']);
262 262
 		}
263
-		if ( ! wp_verify_nonce( $nonce, 'remove_user_from_post_nonce' ) ) {
264
-			die( $return );
263
+		if ( ! wp_verify_nonce($nonce, 'remove_user_from_post_nonce')) {
264
+			die($return);
265 265
 		}
266 266
 
267 267
 		// Parse POST data
268 268
 		$data = $_POST['data'];
269 269
 		$action_data = array();
270
-		parse_str( $data, $action_data );
270
+		parse_str($data, $action_data);
271 271
 
272
-		if( $action_data['user_id'] && $action_data['post_id'] && $action_data['post_type'] ) {
272
+		if ($action_data['user_id'] && $action_data['post_id'] && $action_data['post_type']) {
273 273
 
274
-			$user_id = intval( $action_data['user_id'] );
275
-			$post_id = intval( $action_data['post_id'] );
276
-			$post_type = sanitize_text_field( $action_data['post_type'] );
277
-            $order_id = sanitize_text_field( $action_data['order_id'] );
274
+			$user_id = intval($action_data['user_id']);
275
+			$post_id = intval($action_data['post_id']);
276
+			$post_type = sanitize_text_field($action_data['post_type']);
277
+            $order_id = sanitize_text_field($action_data['order_id']);
278 278
 
279
-			$user = get_userdata( $user_id );
279
+			$user = get_userdata($user_id);
280 280
 
281
-			switch( $post_type ) {
281
+			switch ($post_type) {
282 282
 
283 283
 				case 'course':
284
-					$removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
284
+					$removed = Sensei_Utils::sensei_remove_user_from_course($post_id, $user_id);
285 285
 
286
-                    if( ! empty( $order_id ) && Sensei_WC::is_woocommerce_active()  ){
286
+                    if ( ! empty($order_id) && Sensei_WC::is_woocommerce_active()) {
287 287
 
288 288
                         $order = new WC_Order($order_id);
289 289
 
290
-                        if (!empty($order)) {
291
-                            $order->update_status( 'cancelled' );
290
+                        if ( ! empty($order)) {
291
+                            $order->update_status('cancelled');
292 292
                         }
293 293
 
294 294
                     }
@@ -296,126 +296,126 @@  discard block
 block discarded – undo
296 296
 				break;
297 297
 
298 298
 				case 'lesson':
299
-					$removed = Sensei_Utils::sensei_remove_user_from_lesson( $post_id, $user_id );
299
+					$removed = Sensei_Utils::sensei_remove_user_from_lesson($post_id, $user_id);
300 300
 				break;
301 301
 
302 302
 			}
303 303
 
304
-			if( $removed ) {
304
+			if ($removed) {
305 305
 				$return = 'removed';
306 306
 			}
307 307
 
308 308
 		}
309 309
 
310
-		die( $return );
310
+		die($return);
311 311
 	}
312 312
 
313 313
 	public function json_search_users() {
314 314
 
315 315
 
316
-		check_ajax_referer( 'search-users', 'security' );
316
+		check_ajax_referer('search-users', 'security');
317 317
 
318
-		$term = sanitize_text_field( stripslashes( $_GET['term'] ) );
318
+		$term = sanitize_text_field(stripslashes($_GET['term']));
319 319
 
320
-		if ( empty( $term ) ) {
320
+		if (empty($term)) {
321 321
 			die();
322 322
 		}
323 323
 
324
-		$default = isset( $_GET['default'] ) ? $_GET['default'] : __( 'None', 'woocommerce' );
324
+		$default = isset($_GET['default']) ? $_GET['default'] : __('None', 'woocommerce');
325 325
 
326
-		$found_users = array( '' => $default );
326
+		$found_users = array('' => $default);
327 327
 
328
-		$users_query = new WP_User_Query( apply_filters( 'sensei_json_search_users_query', array(
328
+		$users_query = new WP_User_Query(apply_filters('sensei_json_search_users_query', array(
329 329
 			'fields'         => 'all',
330 330
 			'orderby'        => 'display_name',
331
-			'search'         => '*' . $term . '*',
332
-			'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename','user_firstname','user_lastname' )
333
-		), $term ) );
331
+			'search'         => '*'.$term.'*',
332
+			'search_columns' => array('ID', 'user_login', 'user_email', 'user_nicename', 'user_firstname', 'user_lastname')
333
+		), $term));
334 334
 
335 335
 		$users = $users_query->get_results();
336 336
 
337
-		if ( $users ) {
338
-			foreach ( $users as $user ) {
339
-                $full_name = Sensei()->learners->get_learner_full_name( $user->ID );
337
+		if ($users) {
338
+			foreach ($users as $user) {
339
+                $full_name = Sensei()->learners->get_learner_full_name($user->ID);
340 340
 
341
-                if( trim($user->display_name ) == trim( $full_name ) ){
341
+                if (trim($user->display_name) == trim($full_name)) {
342 342
 
343 343
                     $name = $full_name;
344 344
 
345
-                }else{
345
+                } else {
346 346
 
347
-                    $name = $full_name . ' ['. $user->display_name .']';
347
+                    $name = $full_name.' ['.$user->display_name.']';
348 348
 
349 349
                 }
350 350
 
351
-                $found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' &ndash; ' . sanitize_email( $user->user_email ) . ')';
351
+                $found_users[$user->ID] = $name.' (#'.$user->ID.' &ndash; '.sanitize_email($user->user_email).')';
352 352
 			}
353 353
 		}
354 354
 
355
-		wp_send_json( $found_users );
355
+		wp_send_json($found_users);
356 356
 	}
357 357
 
358 358
 	public function add_new_learners() {
359 359
 
360 360
 		$result = false;
361 361
 
362
-		if( ! isset( $_POST['add_learner_submit'] ) ) return $result;
362
+		if ( ! isset($_POST['add_learner_submit'])) return $result;
363 363
 
364
-		if ( ! isset( $_POST['add_learner_nonce'] ) || ! wp_verify_nonce( $_POST['add_learner_nonce'], 'add_learner_to_sensei' ) ) return $result;
364
+		if ( ! isset($_POST['add_learner_nonce']) || ! wp_verify_nonce($_POST['add_learner_nonce'], 'add_learner_to_sensei')) return $result;
365 365
 
366
-		if( ( ! isset( $_POST['add_user_id'] ) || '' ==  $_POST['add_user_id'] ) || ! isset( $_POST['add_post_type'] ) || ! isset( $_POST['add_course_id'] ) || ! isset( $_POST['add_lesson_id'] ) ) return $result;
366
+		if (( ! isset($_POST['add_user_id']) || '' == $_POST['add_user_id']) || ! isset($_POST['add_post_type']) || ! isset($_POST['add_course_id']) || ! isset($_POST['add_lesson_id'])) return $result;
367 367
 
368 368
 		$post_type = $_POST['add_post_type'];
369
-		$user_id = absint( $_POST['add_user_id'] );
370
-		$course_id = absint( $_POST['add_course_id'] );
369
+		$user_id = absint($_POST['add_user_id']);
370
+		$course_id = absint($_POST['add_course_id']);
371 371
 
372
-		switch( $post_type ) {
372
+		switch ($post_type) {
373 373
 			case 'course':
374 374
 
375
-				$result = Sensei_Utils::user_start_course( $user_id, $course_id );
375
+				$result = Sensei_Utils::user_start_course($user_id, $course_id);
376 376
 
377 377
 				// Complete each lesson if course is set to be completed
378
-				if( isset( $_POST['add_complete_course'] ) && 'yes' == $_POST['add_complete_course'] ) {
378
+				if (isset($_POST['add_complete_course']) && 'yes' == $_POST['add_complete_course']) {
379 379
 
380
-					$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
380
+					$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
381 381
 
382
-					foreach( $lesson_ids as $id ) {
383
-						Sensei_Utils::sensei_start_lesson( $id, $user_id, true );
382
+					foreach ($lesson_ids as $id) {
383
+						Sensei_Utils::sensei_start_lesson($id, $user_id, true);
384 384
 					}
385 385
 
386 386
 					// Updates the Course status and it's meta data
387
-					Sensei_Utils::user_complete_course( $course_id, $user_id );
387
+					Sensei_Utils::user_complete_course($course_id, $user_id);
388 388
 
389
-					do_action( 'sensei_user_course_end', $user_id, $course_id );
389
+					do_action('sensei_user_course_end', $user_id, $course_id);
390 390
 				}
391 391
 
392 392
 			break;
393 393
 
394 394
 			case 'lesson':
395
-                $lesson_id = absint( $_POST['add_lesson_id'] );
395
+                $lesson_id = absint($_POST['add_lesson_id']);
396 396
 				$complete = false;
397
-				if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) {
397
+				if (isset($_POST['add_complete_lesson']) && 'yes' == $_POST['add_complete_lesson']) {
398 398
 					$complete = true;
399 399
 				}
400 400
 
401
-				$result = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id, $complete );
401
+				$result = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id, $complete);
402 402
 
403 403
 				// Updates the Course status and it's meta data
404
-				Sensei_Utils::user_complete_course( $course_id, $user_id );
404
+				Sensei_Utils::user_complete_course($course_id, $user_id);
405 405
 
406 406
 			break;
407 407
 		}
408 408
 
409 409
 		// Set redirect URL after adding user to course/lesson
410
-		$query_args = array( 'page' => $this->page_slug, 'view' => 'learners' );
410
+		$query_args = array('page' => $this->page_slug, 'view' => 'learners');
411 411
 
412
-		if( $result ) {
412
+		if ($result) {
413 413
 
414
-			if( $course_id ) {
414
+			if ($course_id) {
415 415
 				$query_args['course_id'] = $course_id;
416 416
 			}
417 417
 
418
-			if( $lesson_id ) {
418
+			if ($lesson_id) {
419 419
 				$query_args['lesson_id'] = $lesson_id;
420 420
 			}
421 421
 
@@ -425,23 +425,23 @@  discard block
 block discarded – undo
425 425
 			$query_args['message'] = 'error';
426 426
 		}
427 427
 
428
-		$redirect_url = apply_filters( 'sensei_learners_add_learner_redirect_url', add_query_arg( $query_args, admin_url( 'admin.php' ) ) );
428
+		$redirect_url = apply_filters('sensei_learners_add_learner_redirect_url', add_query_arg($query_args, admin_url('admin.php')));
429 429
 
430
-		wp_safe_redirect( esc_url_raw( $redirect_url ) );
430
+		wp_safe_redirect(esc_url_raw($redirect_url));
431 431
 		exit;
432 432
 	}
433 433
 
434 434
 	public function add_learner_notices() {
435
-		if( isset( $_GET['page'] ) && $this->page_slug == $_GET['page'] && isset( $_GET['message'] ) && $_GET['message'] ) {
436
-			if( 'success' == $_GET['message'] ) {
435
+		if (isset($_GET['page']) && $this->page_slug == $_GET['page'] && isset($_GET['message']) && $_GET['message']) {
436
+			if ('success' == $_GET['message']) {
437 437
 				$msg = array(
438 438
 					'updated',
439
-					__( 'Learner added successfully!', 'woothemes-sensei' ),
439
+					__('Learner added successfully!', 'woothemes-sensei'),
440 440
 				);
441 441
 			} else {
442 442
 				$msg = array(
443 443
 					'error',
444
-					__( 'Error adding learner.', 'woothemes-sensei' ),
444
+					__('Error adding learner.', 'woothemes-sensei'),
445 445
 				);
446 446
 			}
447 447
 			?>
@@ -463,25 +463,25 @@  discard block
 block discarded – undo
463 463
      *
464 464
      * @return string $full_name
465 465
      */
466
-    public function get_learner_full_name( $user_id ){
466
+    public function get_learner_full_name($user_id) {
467 467
 
468 468
         $full_name = '';
469 469
 
470
-        if( empty( $user_id ) || ! ( 0 < intval( $user_id ) )
471
-            || !( get_userdata( $user_id ) ) ){
470
+        if (empty($user_id) || ! (0 < intval($user_id))
471
+            || ! (get_userdata($user_id))) {
472 472
             return false;
473 473
         }
474 474
 
475 475
         // get the user details
476
-        $user = get_user_by( 'id', $user_id );
476
+        $user = get_user_by('id', $user_id);
477 477
 
478
-        if( ! empty( $user->first_name  ) && ! empty( $user->last_name  )  ){
478
+        if ( ! empty($user->first_name) && ! empty($user->last_name)) {
479 479
 
480
-            $full_name = trim( $user->first_name   ) . ' ' . trim( $user->last_name  );
480
+            $full_name = trim($user->first_name).' '.trim($user->last_name);
481 481
 
482
-        }else{
482
+        } else {
483 483
 
484
-            $full_name =  $user->display_name;
484
+            $full_name = $user->display_name;
485 485
 
486 486
         }
487 487
 
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
          * @param $full_name
493 493
          * @param $user_id
494 494
          */
495
-        return apply_filters( 'sensei_learner_full_name' , $full_name , $user_id );
495
+        return apply_filters('sensei_learner_full_name', $full_name, $user_id);
496 496
 
497 497
     } // end get_learner_full_name
498 498
 
@@ -503,4 +503,4 @@  discard block
 block discarded – undo
503 503
  * for backward compatibility
504 504
  * @since 1.9.0
505 505
  */
506
-class WooThemes_Sensei_Learners extends Sensei_Learners{}
506
+class WooThemes_Sensei_Learners extends Sensei_Learners {}
Please login to merge, or discard this patch.
includes/class-sensei-list-table.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -44,6 +44,7 @@
 block discarded – undo
44 44
 	/**
45 45
 	 * Constructor
46 46
 	 * @since  1.2.0
47
+	 * @param string $token
47 48
 	 * @return  void
48 49
 	 */
49 50
 	public function __construct ( $token ) {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -162,8 +162,8 @@
 block discarded – undo
162 162
 			$sortable[$id] = $data;
163 163
 		}
164 164
 
165
-        $primary = $this->get_primary_column_name();
166
-        $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
165
+		$primary = $this->get_primary_column_name();
166
+		$this->_column_headers = array( $columns, $hidden, $sortable, $primary );
167 167
 
168 168
 		return $this->_column_headers;
169 169
 	}
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 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 Generic List Table Class
@@ -46,17 +46,17 @@  discard block
 block discarded – undo
46 46
 	 * @since  1.2.0
47 47
 	 * @return  void
48 48
 	 */
49
-	public function __construct ( $token ) {
49
+	public function __construct($token) {
50 50
 		// Class Variables
51 51
 		$this->token = $token;
52 52
 
53
-		parent::__construct( array(
54
-								'singular' => 'wp_list_table_' . $this->token, // Singular label
55
-								'plural'   => 'wp_list_table_' . $this->token . 's', // Plural label
53
+		parent::__construct(array(
54
+								'singular' => 'wp_list_table_'.$this->token, // Singular label
55
+								'plural'   => 'wp_list_table_'.$this->token.'s', // Plural label
56 56
 								'ajax'     => false // No Ajax for this table
57
-		) );
57
+		));
58 58
 		// Actions
59
-		add_action( 'sensei_before_list_table', array( $this, 'table_search_form' ), 5 );
59
+		add_action('sensei_before_list_table', array($this, 'table_search_form'), 5);
60 60
 	} // End __construct()
61 61
 
62 62
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param  array $columns Existing columns
65 65
 	 * @return array          Modified columns
66 66
 	 */
67
-	public function remove_sortable_columns( $columns ) {
67
+	public function remove_sortable_columns($columns) {
68 68
 		return array();
69 69
 	}
70 70
 
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
 	 * @since  1.2.0
74 74
 	 * @param string $which, helps you decide if you add the markup after (bottom) or before (top) the list
75 75
 	 */
76
-	public function extra_tablenav( $which ) {
77
-		if ( $which == "top" ){
76
+	public function extra_tablenav($which) {
77
+		if ($which == "top") {
78 78
 			//The code that goes before the table is here
79
-			do_action( 'sensei_before_list_table' );
79
+			do_action('sensei_before_list_table');
80 80
 		} // End If Statement
81
-		if ( $which == "bottom" ){
81
+		if ($which == "bottom") {
82 82
 			//The code that goes after the table is there
83
-			do_action( 'sensei_after_list_table' );
83
+			do_action('sensei_after_list_table');
84 84
 		} // End If Statement
85 85
 	} // End extra_tablenav()
86 86
 
@@ -90,20 +90,20 @@  discard block
 block discarded – undo
90 90
 	 * @return void
91 91
 	 */
92 92
 	public function table_search_form() {
93
-		if ( empty( $_REQUEST['s'] ) && !$this->has_items() ) {
93
+		if (empty($_REQUEST['s']) && ! $this->has_items()) {
94 94
 			return;
95 95
 		}
96 96
 		?><form method="get">
97 97
 			<?php
98
-			if( isset( $_GET ) && count( $_GET ) > 0 ) {
99
-				foreach( $_GET as $k => $v ) {
100
-					if( 's' != $k ) {
98
+			if (isset($_GET) && count($_GET) > 0) {
99
+				foreach ($_GET as $k => $v) {
100
+					if ('s' != $k) {
101 101
 						?><input type="hidden" name="<?php echo $k; ?>" value="<?php echo $v; ?>" /><?php
102 102
 					}
103 103
 				}
104 104
 			}
105 105
 			?>
106
-			<?php $this->search_box( __( 'Search Users' ,'woothemes-sensei' ), 'search_id'); ?>
106
+			<?php $this->search_box(__('Search Users', 'woothemes-sensei'), 'search_id'); ?>
107 107
 		</form><?php
108 108
 	} // End table_search_form()
109 109
 
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
 	 * @return array
132 132
 	 */
133 133
 	function get_column_info() {
134
-		if ( isset( $this->_column_headers ) )
134
+		if (isset($this->_column_headers))
135 135
 			return $this->_column_headers;
136 136
 
137 137
 		$columns = $this->get_columns();
138
-		$hidden = get_hidden_columns( $this->screen );
138
+		$hidden = get_hidden_columns($this->screen);
139 139
 
140 140
 		$sortable_columns = $this->get_sortable_columns();
141 141
 		/**
@@ -148,22 +148,22 @@  discard block
 block discarded – undo
148 148
 		 *
149 149
 		 * @param array $sortable_columns An array of sortable columns.
150 150
 		 */
151
-		$_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
151
+		$_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $sortable_columns);
152 152
 
153 153
 		$sortable = array();
154
-		foreach ( $_sortable as $id => $data ) {
155
-			if ( empty( $data ) )
154
+		foreach ($_sortable as $id => $data) {
155
+			if (empty($data))
156 156
 				continue;
157 157
 
158 158
 			$data = (array) $data;
159
-			if ( !isset( $data[1] ) )
159
+			if ( ! isset($data[1]))
160 160
 				$data[1] = false;
161 161
 
162 162
 			$sortable[$id] = $data;
163 163
 		}
164 164
 
165 165
         $primary = $this->get_primary_column_name();
166
-        $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
166
+        $this->_column_headers = array($columns, $hidden, $sortable, $primary);
167 167
 
168 168
 		return $this->_column_headers;
169 169
 	}
@@ -174,27 +174,27 @@  discard block
 block discarded – undo
174 174
 	 * @since  1.7.0
175 175
 	 * @param object $item The current item
176 176
 	 */
177
-	function single_row( $item ) {
177
+	function single_row($item) {
178 178
 		static $row_class = '';
179
-		$row_class = ( $row_class == '' ? ' class="alternate"' : '' );
179
+		$row_class = ($row_class == '' ? ' class="alternate"' : '');
180 180
 
181
-		echo '<tr' . $row_class . '>';
181
+		echo '<tr'.$row_class.'>';
182 182
 
183
-		$column_data = $this->get_row_data( $item );
183
+		$column_data = $this->get_row_data($item);
184 184
 
185
-		list( $columns, $hidden ) = $this->get_column_info();
185
+		list($columns, $hidden) = $this->get_column_info();
186 186
 
187
-		foreach ( $columns as $column_name => $column_display_name ) {
187
+		foreach ($columns as $column_name => $column_display_name) {
188 188
 			$class = "class='$column_name column-$column_name'";
189 189
 
190 190
 			$style = '';
191
-			if ( in_array( $column_name, $hidden ) )
191
+			if (in_array($column_name, $hidden))
192 192
 				$style = ' style="display:none;"';
193 193
 
194 194
 			$attributes = "$class$style";
195 195
 
196 196
 			echo "<td $attributes>";
197
-			if ( isset($column_data[$column_name]) ) {
197
+			if (isset($column_data[$column_name])) {
198 198
 				echo $column_data[$column_name];
199 199
 			}
200 200
 			echo "</td>";
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @access public
209 209
 	 * @abstract
210 210
 	 */
211
-	protected function get_row_data( $item ) {
212
-		die( 'either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.' );
211
+	protected function get_row_data($item) {
212
+		die('either function WooThemes_Sensei_List_Table::get_row_data() must be over-ridden in a sub-class or WooThemes_Sensei_List_Table::single_row() should be.');
213 213
 	}
214 214
 
215 215
 	/**
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 */
221 221
 	function no_items() {
222 222
 
223
-		 _e( 'No items found.', 'woothemes-sensei' );
223
+		 _e('No items found.', 'woothemes-sensei');
224 224
 
225 225
 	} // End no_items()
226 226
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	 * @since  1.2.0
239 239
 	 * @return void
240 240
 	 */
241
-	public function bulk_actions( $which = '' ) {
241
+	public function bulk_actions($which = '') {
242 242
 		// This will be output Above the table headers on the left
243
-		echo apply_filters( 'sensei_list_bulk_actions', '' );
243
+		echo apply_filters('sensei_list_bulk_actions', '');
244 244
 	} // End bulk_actions()
245 245
 
246 246
 } // End Class
Please login to merge, or discard this patch.
Braces   +16 added lines, -9 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 Generic List Table Class
@@ -131,8 +134,9 @@  discard block
 block discarded – undo
131 134
 	 * @return array
132 135
 	 */
133 136
 	function get_column_info() {
134
-		if ( isset( $this->_column_headers ) )
135
-			return $this->_column_headers;
137
+		if ( isset( $this->_column_headers ) ) {
138
+					return $this->_column_headers;
139
+		}
136 140
 
137 141
 		$columns = $this->get_columns();
138 142
 		$hidden = get_hidden_columns( $this->screen );
@@ -152,12 +156,14 @@  discard block
 block discarded – undo
152 156
 
153 157
 		$sortable = array();
154 158
 		foreach ( $_sortable as $id => $data ) {
155
-			if ( empty( $data ) )
156
-				continue;
159
+			if ( empty( $data ) ) {
160
+							continue;
161
+			}
157 162
 
158 163
 			$data = (array) $data;
159
-			if ( !isset( $data[1] ) )
160
-				$data[1] = false;
164
+			if ( !isset( $data[1] ) ) {
165
+							$data[1] = false;
166
+			}
161 167
 
162 168
 			$sortable[$id] = $data;
163 169
 		}
@@ -188,8 +194,9 @@  discard block
 block discarded – undo
188 194
 			$class = "class='$column_name column-$column_name'";
189 195
 
190 196
 			$style = '';
191
-			if ( in_array( $column_name, $hidden ) )
192
-				$style = ' style="display:none;"';
197
+			if ( in_array( $column_name, $hidden ) ) {
198
+							$style = ' style="display:none;"';
199
+			}
193 200
 
194 201
 			$attributes = "$class$style";
195 202
 
Please login to merge, or discard this patch.
includes/class-sensei-messages.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -299,7 +299,7 @@
 block discarded – undo
299 299
      * @param  integer $sender_id   ID of sender
300 300
      * @param  integer $receiver_id ID of receiver
301 301
      * @param  string  $message     Message content
302
-     * @param  string  $post_id     ID of post related to message
302
+     * @param  integer  $post_id     ID of post related to message
303 303
      * @return mixed                Message ID on success, boolean false on failure
304 304
      */
305 305
     private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 		// Monitor when new reply is posted
37 37
 		add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 );
38 38
 
39
-        // Block WordPress from sending comment update emails for the messages post type
40
-        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
39
+		// Block WordPress from sending comment update emails for the messages post type
40
+		add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
41 41
 
42
-        // Block WordPress from sending comment moderator emails on the sensei messages post types
43
-        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
42
+		// Block WordPress from sending comment moderator emails on the sensei messages post types
43
+		add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
44 44
 
45 45
 		// Process saving of message posts
46 46
 		add_action( 'save_post', array( $this, 'save_message' ) );
@@ -48,20 +48,20 @@  discard block
 block discarded – undo
48 48
 		// Add message links to courses & lessons
49 49
 		add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 );
50 50
 
51
-        // add message link to lesson
52
-        add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 );
51
+		// add message link to lesson
52
+		add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 );
53 53
 
54
-        // add message link to lesson
55
-        add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 );
54
+		// add message link to lesson
55
+		add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 );
56 56
 
57 57
 		// Hide messages and replies from users who do not have access
58
-        add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 );
59
-        add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 );
60
-        add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 );
61
-        add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 );
62
-        add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 );
63
-        add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 );
64
-        add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 );
58
+		add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 );
59
+		add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 );
60
+		add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 );
61
+		add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 );
62
+		add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 );
63
+		add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 );
64
+		add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 );
65 65
 	} // End __construct()
66 66
 
67 67
 	public function add_menu_item() {
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	public function send_message_link( $post_id = 0, $user_id = 0 ) {
163 163
 		global  $post;
164 164
 
165
-        // only show the link for the allowed post types:
166
-        $allowed_post_types = array('lesson', 'course', 'quiz');
165
+		// only show the link for the allowed post types:
166
+		$allowed_post_types = array('lesson', 'course', 'quiz');
167 167
 		if ( ! in_array( get_post_type() , $allowed_post_types ) ) {
168 168
 
169 169
 			return;
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
 				} elseif( 'course' == $post->post_type ) {
187 187
 					$contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' );
188 188
 				}else{
189
-                    $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
190
-                }
189
+					$contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
190
+				}
191 191
 
192 192
 				$html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>';
193 193
 			}
@@ -212,19 +212,19 @@  discard block
 block discarded – undo
212 212
 
213 213
 		if( ! isset( $post->ID ) ) return $html;
214 214
 
215
-        //confirm private message
216
-        $confirmation = '';
217
-        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) {
215
+		//confirm private message
216
+		$confirmation = '';
217
+		if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) {
218 218
 
219
-            $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei');
220
-            $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>';
219
+			$confirmation_message = __('Your private message has been sent.', 'woothemes-sensei');
220
+			$confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>';
221 221
 
222
-        }
222
+		}
223 223
 
224 224
 		$html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>';
225
-        $html .= '<p>';
226
-        $html .=  $confirmation;
227
-        $html .= '</p>';
225
+		$html .= '<p>';
226
+		$html .=  $confirmation;
227
+		$html .= '</p>';
228 228
 		$html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">';
229 229
 			$html .= '<p class="form-row form-row-wide">';
230 230
 				$html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>';
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	public function message_reply_received( $comment_id = 0 ) {
256 256
 
257 257
 		// Get comment object
258
-    	$comment = get_comment( $comment_id );
258
+		$comment = get_comment( $comment_id );
259 259
 
260 260
 		if( is_null( $comment ) ) return;
261 261
 
@@ -270,87 +270,87 @@  discard block
 block discarded – undo
270 270
 		do_action( 'sensei_private_message_reply', $comment, $message );
271 271
 	}
272 272
 
273
-    /**
274
-     * This function stops WordPress from sending the default comment update emails.
275
-     *
276
-     * This function is hooked into comment_notification_recipients. It will simply return
277
-     * an empty array if the current passed in comment is on a message post type.
278
-     *
279
-     * @param array $emails
280
-     * @param int $comment_id
281
-     * @return array;
282
-     */
283
-    public function stop_wp_comment_emails( $emails , $comment_id ){
273
+	/**
274
+	 * This function stops WordPress from sending the default comment update emails.
275
+	 *
276
+	 * This function is hooked into comment_notification_recipients. It will simply return
277
+	 * an empty array if the current passed in comment is on a message post type.
278
+	 *
279
+	 * @param array $emails
280
+	 * @param int $comment_id
281
+	 * @return array;
282
+	 */
283
+	public function stop_wp_comment_emails( $emails , $comment_id ){
284 284
 
285
-        $comment = get_comment( $comment_id );
286
-        if( isset( $comment->comment_post_ID ) &&
287
-            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){
285
+		$comment = get_comment( $comment_id );
286
+		if( isset( $comment->comment_post_ID ) &&
287
+			'sensei_message' == get_post_type( $comment->comment_post_ID )  ){
288 288
 
289
-            // empty the emails array to ensure no emails are sent for this comment
290
-            $emails = array();
289
+			// empty the emails array to ensure no emails are sent for this comment
290
+			$emails = array();
291 291
 
292
-        }
293
-        return $emails;
292
+		}
293
+		return $emails;
294 294
 
295
-    }// end stop_wp_comment_emails
295
+	}// end stop_wp_comment_emails
296 296
 
297 297
 	/**
298
-     * Save new message post
299
-     * @param  integer $sender_id   ID of sender
300
-     * @param  integer $receiver_id ID of receiver
301
-     * @param  string  $message     Message content
302
-     * @param  string  $post_id     ID of post related to message
303
-     * @return mixed                Message ID on success, boolean false on failure
304
-     */
305
-    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
298
+	 * Save new message post
299
+	 * @param  integer $sender_id   ID of sender
300
+	 * @param  integer $receiver_id ID of receiver
301
+	 * @param  string  $message     Message content
302
+	 * @param  string  $post_id     ID of post related to message
303
+	 * @return mixed                Message ID on success, boolean false on failure
304
+	 */
305
+	private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
306 306
 
307
-    	$message_id = false;
307
+		$message_id = false;
308 308
 
309
-    	if( $sender_id && $receiver_id && $message && $post_id ) {
309
+		if( $sender_id && $receiver_id && $message && $post_id ) {
310 310
 
311
-    		$title = wp_trim_words( $message, 8, '...' );
311
+			$title = wp_trim_words( $message, 8, '...' );
312 312
 
313
-    		// Set up post data for message
314
-	    	$message_data = array(
315
-	            'post_type'      => $this->post_type,
316
-	            'post_title'     => esc_html( $title ),
317
-	            'post_content'   => esc_html( $message ),
318
-	            'post_status'    => 'publish',
319
-	            'ping_status'    => 'closed',
320
-	            'comment_status' => 'open',
321
-	            'post_excerpt'   => '',
322
-	            'post_author'	 => intval( $sender_id )
323
-	        );
313
+			// Set up post data for message
314
+			$message_data = array(
315
+				'post_type'      => $this->post_type,
316
+				'post_title'     => esc_html( $title ),
317
+				'post_content'   => esc_html( $message ),
318
+				'post_status'    => 'publish',
319
+				'ping_status'    => 'closed',
320
+				'comment_status' => 'open',
321
+				'post_excerpt'   => '',
322
+				'post_author'	 => intval( $sender_id )
323
+			);
324 324
 
325
-	    	// Insert post
326
-	        $message_id = wp_insert_post( $message_data );
325
+			// Insert post
326
+			$message_id = wp_insert_post( $message_data );
327 327
 
328
-	        if( ! is_wp_error( $message_id ) ) {
328
+			if( ! is_wp_error( $message_id ) ) {
329 329
 
330
-	        	// Add sender to message meta
331
-	        	$sender = get_userdata( $sender_id );
332
-	        	add_post_meta( $message_id, '_sender', $sender->user_login );
330
+				// Add sender to message meta
331
+				$sender = get_userdata( $sender_id );
332
+				add_post_meta( $message_id, '_sender', $sender->user_login );
333 333
 
334
-	        	// Add receiver to message meta
335
-	        	$receiver = get_userdata( $receiver_id );
336
-		        add_post_meta( $message_id, '_receiver', $receiver->user_login );
334
+				// Add receiver to message meta
335
+				$receiver = get_userdata( $receiver_id );
336
+				add_post_meta( $message_id, '_receiver', $receiver->user_login );
337 337
 
338
-		        // Add lesson/course ID to message meta
339
-		        $post = get_post( $post_id );
340
-		        add_post_meta( $message_id, '_posttype', $post->post_type );
341
-		        add_post_meta( $message_id, '_post', $post->ID );
338
+				// Add lesson/course ID to message meta
339
+				$post = get_post( $post_id );
340
+				add_post_meta( $message_id, '_posttype', $post->post_type );
341
+				add_post_meta( $message_id, '_post', $post->ID );
342 342
 
343
-		        do_action( 'sensei_new_private_message', $message_id );
343
+				do_action( 'sensei_new_private_message', $message_id );
344 344
 
345
-		    } else {
345
+			} else {
346 346
 
347
-		    	$message_id = false;
347
+				$message_id = false;
348 348
 
349
-		    }
350
-	    }
349
+			}
350
+		}
351 351
 
352
-	    return $message_id;
353
-    }
352
+		return $message_id;
353
+	}
354 354
 
355 355
 	/**
356 356
 	 * Check if user has access to view this message
@@ -389,56 +389,56 @@  discard block
 block discarded – undo
389 389
 		remove_meta_box('commentstatusdiv', $this->post_type, 'normal');
390 390
 	}
391 391
 
392
-    /**
393
-     * Function message_login()
394
-     *
395
-     * Only show /messages/* to logged in users, and
396
-     * redirect logged out users to wp-login.php
397
-     *
398
-     * @since 1.9.0
399
-     * @param  none
400
-     * @return void
401
-     */
392
+	/**
393
+	 * Function message_login()
394
+	 *
395
+	 * Only show /messages/* to logged in users, and
396
+	 * redirect logged out users to wp-login.php
397
+	 *
398
+	 * @since 1.9.0
399
+	 * @param  none
400
+	 * @return void
401
+	 */
402 402
 
403
-    public function message_login () {
403
+	public function message_login () {
404 404
 
405
-        if ( is_user_logged_in() ) {
405
+		if ( is_user_logged_in() ) {
406 406
 
407
-            return;
408
-        }
407
+			return;
408
+		}
409 409
 
410
-        $settings = Sensei()->settings->get_settings();
411
-        if( isset( $settings[ 'my_course_page' ] )
412
-            && 0 < intval( $settings[ 'my_course_page' ] ) ){
410
+		$settings = Sensei()->settings->get_settings();
411
+		if( isset( $settings[ 'my_course_page' ] )
412
+			&& 0 < intval( $settings[ 'my_course_page' ] ) ){
413 413
 
414
-            $my_courses_page_id = $settings[ 'my_course_page' ];
414
+			$my_courses_page_id = $settings[ 'my_course_page' ];
415 415
 
416
-            $my_courses_url = get_permalink($my_courses_page_id);
416
+			$my_courses_url = get_permalink($my_courses_page_id);
417 417
 
418
-        }
418
+		}
419 419
 
420
-        if ( is_single() && is_singular( $this->post_type )
421
-            || is_post_type_archive( $this->post_type ) ) {
420
+		if ( is_single() && is_singular( $this->post_type )
421
+			|| is_post_type_archive( $this->post_type ) ) {
422 422
 
423
-            if ( isset($my_courses_url) ) {
423
+			if ( isset($my_courses_url) ) {
424 424
 
425
-                wp_redirect($my_courses_url, 303);
426
-                exit;
427
-            }
425
+				wp_redirect($my_courses_url, 303);
426
+				exit;
427
+			}
428 428
 
429
-            else {
429
+			else {
430 430
 
431
-                wp_redirect(home_url('/wp-login.php'), 303);
432
-                exit;
433
-            }
431
+				wp_redirect(home_url('/wp-login.php'), 303);
432
+				exit;
433
+			}
434 434
 
435
-        }
436
-    }
435
+		}
436
+	}
437 437
 	/**
438
-     * Only show allowed messages in messages archive
439
-     * @param  array $query Original query
440
-     * @return void
441
-     */
438
+	 * Only show allowed messages in messages archive
439
+	 * @param  array $query Original query
440
+	 * @return void
441
+	 */
442 442
 	public function message_list( $query ) {
443 443
 		global $current_user;
444 444
 
@@ -555,17 +555,17 @@  discard block
 block discarded – undo
555 555
 		return $open;
556 556
 	}
557 557
 
558
-    /**
559
-     * Print outthe message was sent by $sender_username on the
560
-     *
561
-     * @since 1.9.0
562
-     */
563
-    public static function the_message_sent_by_title(){
558
+	/**
559
+	 * Print outthe message was sent by $sender_username on the
560
+	 *
561
+	 * @since 1.9.0
562
+	 */
563
+	public static function the_message_sent_by_title(){
564 564
 
565
-        $sender_username = get_post_meta( get_the_ID() , '_sender', true );
566
-        if( $sender_username ) {
565
+		$sender_username = get_post_meta( get_the_ID() , '_sender', true );
566
+		if( $sender_username ) {
567 567
 
568
-            $sender = get_user_by( 'login', $sender_username ); ?>
568
+			$sender = get_user_by( 'login', $sender_username ); ?>
569 569
 
570 570
             <p class="message-meta">
571 571
                 <small>
@@ -577,41 +577,41 @@  discard block
 block discarded – undo
577 577
 
578 578
         <?php }
579 579
 
580
-    }
580
+	}
581 581
 
582
-    /**
583
-     * sensei_single_title output for single page title
584
-     * @since  1.1.0
585
-     * @return void
586
-     * @deprecate
587
-     */
588
-    public static function the_title() {
582
+	/**
583
+	 * sensei_single_title output for single page title
584
+	 * @since  1.1.0
585
+	 * @return void
586
+	 * @deprecate
587
+	 */
588
+	public static function the_title() {
589 589
 
590
-        global $post;
590
+		global $post;
591 591
 
592
-        $content_post_id = get_post_meta( $post->ID, '_post', true );
593
-        if( $content_post_id ) {
594
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' );
595
-        } else {
596
-            $title = get_the_title( $post->ID );
597
-        }
592
+		$content_post_id = get_post_meta( $post->ID, '_post', true );
593
+		if( $content_post_id ) {
594
+			$title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' );
595
+		} else {
596
+			$title = get_the_title( $post->ID );
597
+		}
598 598
 
599
-        ?>
599
+		?>
600 600
         <header>
601 601
 
602 602
             <h1>
603 603
 
604 604
                 <?php
605
-                /**
606
-                 * Filter Sensei single title
607
-                 *
608
-                 * @since 1.8.0
609
-                 * @param string $title
610
-                 * @param string $template
611
-                 * @param string $post_type
612
-                 */
613
-                echo apply_filters( 'sensei_single_title', $title, $post->post_type );
614
-                ?>
605
+				/**
606
+				 * Filter Sensei single title
607
+				 *
608
+				 * @since 1.8.0
609
+				 * @param string $title
610
+				 * @param string $template
611
+				 * @param string $post_type
612
+				 */
613
+				echo apply_filters( 'sensei_single_title', $title, $post->post_type );
614
+				?>
615 615
 
616 616
             </h1>
617 617
 
@@ -619,52 +619,52 @@  discard block
 block discarded – undo
619 619
 
620 620
         <?php
621 621
 
622
-    } // End sensei_single_title()
622
+	} // End sensei_single_title()
623 623
 
624
-    /**
625
-     * Generates the my messages
626
-     * archive header.
627
-     *
628
-     * @since 1.9.0
629
-     *
630
-     * @return string
631
-     */
632
-    public static function the_archive_header( ){
624
+	/**
625
+	 * Generates the my messages
626
+	 * archive header.
627
+	 *
628
+	 * @since 1.9.0
629
+	 *
630
+	 * @return string
631
+	 */
632
+	public static function the_archive_header( ){
633 633
 
634
-        $html = '';
635
-        $html .= '<header class="archive-header"><h1>';
636
-        $html .= __( 'My Messages', 'woothemes-sensei' );
637
-        $html .= '</h1></header>';
634
+		$html = '';
635
+		$html .= '<header class="archive-header"><h1>';
636
+		$html .= __( 'My Messages', 'woothemes-sensei' );
637
+		$html .= '</h1></header>';
638 638
 
639
-        /**
640
-         * Filter the sensei messages archive title.
641
-         * @since 1.0.0
642
-         */
643
-        echo apply_filters( 'sensei_message_archive_title', $html );
639
+		/**
640
+		 * Filter the sensei messages archive title.
641
+		 * @since 1.0.0
642
+		 */
643
+		echo apply_filters( 'sensei_message_archive_title', $html );
644 644
 
645
-    } // get_archive_header()
645
+	} // get_archive_header()
646 646
 
647
-    /**
648
-     * Output the title for a message given the post_id.
649
-     *
650
-     * @since 1.9.0
651
-     * @param $post_id
652
-     */
653
-    public static function the_message_title( $message_post_id ){
647
+	/**
648
+	 * Output the title for a message given the post_id.
649
+	 *
650
+	 * @since 1.9.0
651
+	 * @param $post_id
652
+	 */
653
+	public static function the_message_title( $message_post_id ){
654 654
 
655
-        $content_post_id = get_post_meta( $message_post_id, '_post', true );
655
+		$content_post_id = get_post_meta( $message_post_id, '_post', true );
656 656
 
657
-        if( $content_post_id ) {
657
+		if( $content_post_id ) {
658 658
 
659
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) );
659
+			$title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) );
660 660
 
661
-        } else {
661
+		} else {
662 662
 
663
-            $title = get_the_title( $message_post_id );
663
+			$title = get_the_title( $message_post_id );
664 664
 
665
-        }
665
+		}
666 666
 
667
-        ?>
667
+		?>
668 668
         <h2>
669 669
             <a href="<?php esc_url( get_permalink( $message_post_id ) );?>">
670 670
                 <?php echo  $title; ?>
@@ -673,21 +673,21 @@  discard block
 block discarded – undo
673 673
         </h2>
674 674
 
675 675
         <?php
676
-    } //end the_message_header
676
+	} //end the_message_header
677 677
 
678
-    /**
679
-     * Output the message sender given the post id.
680
-     *
681
-     * @param $message_post_id
682
-     */
683
-    public  static function the_message_sender( $message_post_id ){
678
+	/**
679
+	 * Output the message sender given the post id.
680
+	 *
681
+	 * @param $message_post_id
682
+	 */
683
+	public  static function the_message_sender( $message_post_id ){
684 684
 
685
-        $sender_username = get_post_meta( $message_post_id, '_sender', true );
686
-        $sender = get_user_by( 'login', $sender_username );
685
+		$sender_username = get_post_meta( $message_post_id, '_sender', true );
686
+		$sender = get_user_by( 'login', $sender_username );
687 687
 
688
-        if( $sender_username && $sender instanceof WP_User ) {
689
-            $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() );
690
-            ?>
688
+		if( $sender_username && $sender instanceof WP_User ) {
689
+			$sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() );
690
+			?>
691 691
             <p class="message-meta">
692 692
                 <small>
693 693
                     <em> <?php echo $sender_display_name; ?> </em>
@@ -695,18 +695,18 @@  discard block
 block discarded – undo
695 695
             </p>
696 696
 
697 697
             <?php
698
-        } // end if
699
-
700
-    } // end the_message_archive_sender
701
-
702
-    /**
703
-     * Link to the users my messages page
704
-     *
705
-     * @since 1.9.0
706
-     */
707
-    public static function the_my_messages_link(){
708
-        if( ! Sensei()->settings->get('messages_disable')  ) {
709
-            ?>
698
+		} // end if
699
+
700
+	} // end the_message_archive_sender
701
+
702
+	/**
703
+	 * Link to the users my messages page
704
+	 *
705
+	 * @since 1.9.0
706
+	 */
707
+	public static function the_my_messages_link(){
708
+		if( ! Sensei()->settings->get('messages_disable')  ) {
709
+			?>
710 710
             <p class="my-messages-link-container">
711 711
                 <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>"
712 712
                    title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>">
@@ -714,8 +714,8 @@  discard block
 block discarded – undo
714 714
                 </a>
715 715
             </p>
716 716
             <?php
717
-        }
718
-    }
717
+		}
718
+	}
719 719
 
720 720
 } // End Class
721 721
 
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 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 Messages Class
@@ -21,61 +21,61 @@  discard block
 block discarded – undo
21 21
 	 * Constructor.
22 22
 	 * @since  1.6.0
23 23
 	 */
24
-	public function __construct () {
24
+	public function __construct() {
25 25
 		$this->post_type = 'sensei_message';
26
-		$this->meta_fields = array( 'sender', 'receiver' );
26
+		$this->meta_fields = array('sender', 'receiver');
27 27
 
28 28
 		// Add Messages page to admin menu
29
-		add_action( 'admin_menu', array( $this, 'add_menu_item' ), 40 );
30
-		add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ), 10, 2 );
31
-		add_action( 'admin_menu', array( $this, 'remove_meta_box' ) );
29
+		add_action('admin_menu', array($this, 'add_menu_item'), 40);
30
+		add_action('add_meta_boxes', array($this, 'add_meta_box'), 10, 2);
31
+		add_action('admin_menu', array($this, 'remove_meta_box'));
32 32
 
33 33
 		// Save new private message
34
-		add_action( 'init', array( $this, 'save_new_message' ), 1 );
34
+		add_action('init', array($this, 'save_new_message'), 1);
35 35
 
36 36
 		// Monitor when new reply is posted
37
-		add_action( 'comment_post', array( $this, 'message_reply_received' ), 10, 1 );
37
+		add_action('comment_post', array($this, 'message_reply_received'), 10, 1);
38 38
 
39 39
         // Block WordPress from sending comment update emails for the messages post type
40
-        add_filter('comment_notification_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
40
+        add_filter('comment_notification_recipients', array($this, 'stop_wp_comment_emails'), 20, 2);
41 41
 
42 42
         // Block WordPress from sending comment moderator emails on the sensei messages post types
43
-        add_filter('comment_moderation_recipients', array( $this, 'stop_wp_comment_emails' ),  20, 2  );
43
+        add_filter('comment_moderation_recipients', array($this, 'stop_wp_comment_emails'), 20, 2);
44 44
 
45 45
 		// Process saving of message posts
46
-		add_action( 'save_post', array( $this, 'save_message' ) );
46
+		add_action('save_post', array($this, 'save_message'));
47 47
 
48 48
 		// Add message links to courses & lessons
49
-		add_action( 'sensei_single_course_content_inside_before', array( $this, 'send_message_link' ), 35 );
49
+		add_action('sensei_single_course_content_inside_before', array($this, 'send_message_link'), 35);
50 50
 
51 51
         // add message link to lesson
52
-        add_action( 'sensei_single_lesson_content_inside_before', array( $this, 'send_message_link' ), 30, 2 );
52
+        add_action('sensei_single_lesson_content_inside_before', array($this, 'send_message_link'), 30, 2);
53 53
 
54 54
         // add message link to lesson
55
-        add_action( 'sensei_single_quiz_questions_before', array( $this, 'send_message_link' ), 10, 2 );
55
+        add_action('sensei_single_quiz_questions_before', array($this, 'send_message_link'), 10, 2);
56 56
 
57 57
 		// Hide messages and replies from users who do not have access
58
-        add_action( 'template_redirect', array( $this, 'message_login' ), 10, 1 );
59
-        add_action( 'pre_get_posts', array( $this, 'message_list' ), 10, 1 );
60
-        add_filter( 'the_title', array( $this, 'message_title' ), 10, 2 );
61
-        add_filter( 'the_content', array( $this, 'message_content' ), 10, 1 );
62
-        add_filter( 'comments_array', array( $this, 'message_replies' ), 100, 1 );
63
-        add_filter( 'get_comments_number', array( $this, 'message_reply_count' ), 100, 2 );
64
-        add_filter( 'comments_open', array( $this, 'message_replies_open' ), 100, 2 );
58
+        add_action('template_redirect', array($this, 'message_login'), 10, 1);
59
+        add_action('pre_get_posts', array($this, 'message_list'), 10, 1);
60
+        add_filter('the_title', array($this, 'message_title'), 10, 2);
61
+        add_filter('the_content', array($this, 'message_content'), 10, 1);
62
+        add_filter('comments_array', array($this, 'message_replies'), 100, 1);
63
+        add_filter('get_comments_number', array($this, 'message_reply_count'), 100, 2);
64
+        add_filter('comments_open', array($this, 'message_replies_open'), 100, 2);
65 65
 	} // End __construct()
66 66
 
67 67
 	public function add_menu_item() {
68 68
 
69
-		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) {
70
-			add_submenu_page( 'sensei', __( 'Messages', 'woothemes-sensei'),  __( 'Messages', 'woothemes-sensei') , 'edit_courses', 'edit.php?post_type=sensei_message' );
69
+		if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) {
70
+			add_submenu_page('sensei', __('Messages', 'woothemes-sensei'), __('Messages', 'woothemes-sensei'), 'edit_courses', 'edit.php?post_type=sensei_message');
71 71
 		}
72 72
 	}
73 73
 
74
-	public function add_meta_box( $post_type, $post ) {
74
+	public function add_meta_box($post_type, $post) {
75 75
 
76
-		if( ! $post_type == $this->post_type ) return;
76
+		if ( ! $post_type == $this->post_type) return;
77 77
 
78
-		add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' );
78
+		add_meta_box($this->post_type.'-data', __('Message Information', 'woothemes-sensei'), array($this, 'meta_box_content'), $this->post_type, 'normal', 'default');
79 79
 
80 80
 	}
81 81
 
@@ -85,25 +85,25 @@  discard block
 block discarded – undo
85 85
 		$settings = array(
86 86
 			array(
87 87
 				'id' 			=> 'sender',
88
-				'label'			=> __( 'Message sent by:', 'woothemes-sensei' ),
89
-				'description'	=> __( 'The username of the learner who sent this message.', 'woothemes-sensei' ),
88
+				'label'			=> __('Message sent by:', 'woothemes-sensei'),
89
+				'description'	=> __('The username of the learner who sent this message.', 'woothemes-sensei'),
90 90
 				'type'			=> 'text',
91 91
 				'default'		=> '',
92
-				'placeholder'	=> __( 'Learner username', 'woothemes-sensei' ),
92
+				'placeholder'	=> __('Learner username', 'woothemes-sensei'),
93 93
 			),
94 94
 			array(
95 95
 				'id' 			=> 'receiver',
96
-				'label'			=> __( 'Message received by:', 'woothemes-sensei' ),
97
-				'description'	=> __( 'The username of the teacher who received this message.', 'woothemes-sensei' ),
96
+				'label'			=> __('Message received by:', 'woothemes-sensei'),
97
+				'description'	=> __('The username of the teacher who received this message.', 'woothemes-sensei'),
98 98
 				'type'			=> 'text',
99 99
 				'default'		=> '',
100
-				'placeholder'	=> __( 'Teacher username', 'woothemes-sensei' ),
100
+				'placeholder'	=> __('Teacher username', 'woothemes-sensei'),
101 101
 			),
102 102
 		);
103 103
 
104
-		$message_posttype = get_post_meta( $post->ID, '_posttype', true );
104
+		$message_posttype = get_post_meta($post->ID, '_posttype', true);
105 105
 
106
-		if( isset( $message_posttype ) && $message_posttype ) {
106
+		if (isset($message_posttype) && $message_posttype) {
107 107
 
108 108
 			$args = array(
109 109
 				'post_type' => $message_posttype,
@@ -113,58 +113,58 @@  discard block
 block discarded – undo
113 113
 				'post_status' => 'publish',
114 114
 			);
115 115
 
116
-			$posts = get_posts( $args );
116
+			$posts = get_posts($args);
117 117
 
118
-			$post_options[0] = sprintf( __( 'Select %1$s', 'woothemes-sensei' ), $message_posttype );
119
-			foreach( $posts as $post_item ) {
120
-				$post_options[ $post_item->ID ] = $post_item->post_title;
118
+			$post_options[0] = sprintf(__('Select %1$s', 'woothemes-sensei'), $message_posttype);
119
+			foreach ($posts as $post_item) {
120
+				$post_options[$post_item->ID] = $post_item->post_title;
121 121
 			}
122 122
 
123 123
 			$settings[] = array(
124 124
 				'id' 			=> 'post',
125
-				'label'			=> sprintf( __( 'Message from %1$s:', 'woothemes-sensei' ), $message_posttype ),
126
-				'description'	=> sprintf( __( 'The %1$s to which this message relates.', 'woothemes-sensei' ), $message_posttype ),
125
+				'label'			=> sprintf(__('Message from %1$s:', 'woothemes-sensei'), $message_posttype),
126
+				'description'	=> sprintf(__('The %1$s to which this message relates.', 'woothemes-sensei'), $message_posttype),
127 127
 				'type'			=> 'select',
128 128
 				'default'		=> 0,
129 129
 				'options'		=> $post_options,
130 130
 			);
131 131
 		}
132 132
 
133
-		$html = Sensei()->admin->render_settings( $settings, $post->ID, 'message-info' );
133
+		$html = Sensei()->admin->render_settings($settings, $post->ID, 'message-info');
134 134
 
135 135
 		echo $html;
136 136
 	}
137 137
 
138
-	public function save_message( $post_id = 0 ) {
138
+	public function save_message($post_id = 0) {
139 139
 		global $post;
140 140
 
141
-		if( $this->post_type != get_post_type() ) return;
141
+		if ($this->post_type != get_post_type()) return;
142 142
 
143
-		if( isset( $_POST['sender'] ) && $_POST['sender'] ) {
144
-			update_post_meta( $post_id, '_sender', $_POST['sender'] );
143
+		if (isset($_POST['sender']) && $_POST['sender']) {
144
+			update_post_meta($post_id, '_sender', $_POST['sender']);
145 145
 		}
146 146
 
147
-		if( isset( $_POST['receiver'] ) && $_POST['receiver'] ) {
148
-			update_post_meta( $post_id, '_receiver', $_POST['receiver'] );
147
+		if (isset($_POST['receiver']) && $_POST['receiver']) {
148
+			update_post_meta($post_id, '_receiver', $_POST['receiver']);
149 149
 		}
150 150
 
151
-		if( isset( $_POST['post'] ) && $_POST['post'] ) {
152
-			update_post_meta( $post_id, '_post', $_POST['post'] );
151
+		if (isset($_POST['post']) && $_POST['post']) {
152
+			update_post_meta($post_id, '_post', $_POST['post']);
153 153
 		}
154 154
 
155
-		remove_action( 'save_post', array( $this, 'save_message' ) );
155
+		remove_action('save_post', array($this, 'save_message'));
156 156
 
157
-		wp_update_post( array( 'ID' => $post_id, 'comment_status' => 'open' ) );
157
+		wp_update_post(array('ID' => $post_id, 'comment_status' => 'open'));
158 158
 
159
-		add_action( 'save_post', array( $this, 'save_message' ) );
159
+		add_action('save_post', array($this, 'save_message'));
160 160
 	}
161 161
 
162
-	public function send_message_link( $post_id = 0, $user_id = 0 ) {
162
+	public function send_message_link($post_id = 0, $user_id = 0) {
163 163
 		global  $post;
164 164
 
165 165
         // only show the link for the allowed post types:
166 166
         $allowed_post_types = array('lesson', 'course', 'quiz');
167
-		if ( ! in_array( get_post_type() , $allowed_post_types ) ) {
167
+		if ( ! in_array(get_post_type(), $allowed_post_types)) {
168 168
 
169 169
 			return;
170 170
 
@@ -172,28 +172,28 @@  discard block
 block discarded – undo
172 172
 
173 173
 		$html = '';
174 174
 
175
-		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) {
175
+		if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) {
176 176
 
177
-			if( ! is_user_logged_in() ) return;
177
+			if ( ! is_user_logged_in()) return;
178 178
 
179
-			if( isset( $_GET['contact'] ) ) {
180
-				$html .= $this->teacher_contact_form( $post );
179
+			if (isset($_GET['contact'])) {
180
+				$html .= $this->teacher_contact_form($post);
181 181
 			} else {
182
-				$href = add_query_arg( array( 'contact' => $post->post_type ) );
183
-
184
-				if( 'lesson' == $post->post_type ) {
185
-					$contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' );
186
-				} elseif( 'course' == $post->post_type ) {
187
-					$contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' );
188
-				}else{
189
-                    $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
182
+				$href = add_query_arg(array('contact' => $post->post_type));
183
+
184
+				if ('lesson' == $post->post_type) {
185
+					$contact_button_text = __('Contact Lesson Teacher', 'woothemes-sensei');
186
+				} elseif ('course' == $post->post_type) {
187
+					$contact_button_text = __('Contact Course Teacher', 'woothemes-sensei');
188
+				} else {
189
+                    $contact_button_text = __('Contact Teacher', 'woothemes-sensei');
190 190
                 }
191 191
 
192
-				$html .= '<p><a class="button send-message-button" href="' . esc_url($href) . '#private_message">' . $contact_button_text . '</a></p>';
192
+				$html .= '<p><a class="button send-message-button" href="'.esc_url($href).'#private_message">'.$contact_button_text.'</a></p>';
193 193
 			}
194 194
 
195
-			if( isset( $this->message_notice ) && isset( $this->message_notice['type'] ) && isset( $this->message_notice['notice'] ) ) {
196
-				$html .= '<div class="sensei-message ' . $this->message_notice['type'] . '">' . $this->message_notice['notice'] . '</div>';
195
+			if (isset($this->message_notice) && isset($this->message_notice['type']) && isset($this->message_notice['notice'])) {
196
+				$html .= '<div class="sensei-message '.$this->message_notice['type'].'">'.$this->message_notice['notice'].'</div>';
197 197
 			}
198 198
 
199 199
 		}
@@ -201,40 +201,40 @@  discard block
 block discarded – undo
201 201
 		echo $html;
202 202
 	}
203 203
 
204
-	public function teacher_contact_form( $post ) {
204
+	public function teacher_contact_form($post) {
205 205
 
206
-		if( ! is_user_logged_in() ) return;
206
+		if ( ! is_user_logged_in()) return;
207 207
 
208 208
 		global $current_user;
209 209
 		wp_get_current_user();
210 210
 
211 211
 		$html = '';
212 212
 
213
-		if( ! isset( $post->ID ) ) return $html;
213
+		if ( ! isset($post->ID)) return $html;
214 214
 
215 215
         //confirm private message
216 216
         $confirmation = '';
217
-        if( isset( $_GET[ 'send' ] ) && 'complete' == $_GET[ 'send' ] ) {
217
+        if (isset($_GET['send']) && 'complete' == $_GET['send']) {
218 218
 
219 219
             $confirmation_message = __('Your private message has been sent.', 'woothemes-sensei');
220
-            $confirmation = '<div class="sensei-message tick">' . $confirmation_message . '</div>';
220
+            $confirmation = '<div class="sensei-message tick">'.$confirmation_message.'</div>';
221 221
 
222 222
         }
223 223
 
224
-		$html .= '<h3 id="private_message">' . __( 'Send Private Message', 'woothemes-sensei' ) . '</h3>';
224
+		$html .= '<h3 id="private_message">'.__('Send Private Message', 'woothemes-sensei').'</h3>';
225 225
         $html .= '<p>';
226
-        $html .=  $confirmation;
226
+        $html .= $confirmation;
227 227
         $html .= '</p>';
228 228
 		$html .= '<form name="contact-teacher" action="" method="post" class="contact-teacher">';
229 229
 			$html .= '<p class="form-row form-row-wide">';
230
-				$html .= '<textarea name="contact_message" placeholder="' . __( 'Enter your private message.', 'woothemes-sensei' ) . '"></textarea>';
230
+				$html .= '<textarea name="contact_message" placeholder="'.__('Enter your private message.', 'woothemes-sensei').'"></textarea>';
231 231
 			$html .= '</p>';
232 232
 			$html .= '<p class="form-row">';
233
-				$html .= '<input type="hidden" name="post_id" value="' . $post->ID . '" />';
234
-				$html .= '<input type="hidden" name="sender_id" value="' . $current_user->ID . '" />';
235
-				$html .= '<input type="hidden" name="receiver_id" value="' . $post->post_author . '" />';
236
-				$html .= wp_nonce_field( 'message_teacher', 'sensei_message_teacher_nonce', true, false );
237
-				$html .= '<input type="submit" class="send_message" value="' . __( 'Send Message', 'woothemes-sensei' ) . '" />';
233
+				$html .= '<input type="hidden" name="post_id" value="'.$post->ID.'" />';
234
+				$html .= '<input type="hidden" name="sender_id" value="'.$current_user->ID.'" />';
235
+				$html .= '<input type="hidden" name="receiver_id" value="'.$post->post_author.'" />';
236
+				$html .= wp_nonce_field('message_teacher', 'sensei_message_teacher_nonce', true, false);
237
+				$html .= '<input type="submit" class="send_message" value="'.__('Send Message', 'woothemes-sensei').'" />';
238 238
 			$html .= '</p>';
239 239
 			$html .= '<div class="fix"></div>';
240 240
 		$html .= '</form>';
@@ -244,30 +244,30 @@  discard block
 block discarded – undo
244 244
 
245 245
 	public function save_new_message() {
246 246
 
247
-		if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return;
247
+		if ( ! isset($_POST['sensei_message_teacher_nonce'])) return;
248 248
 
249
-		if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return;
249
+		if ( ! wp_verify_nonce($_POST['sensei_message_teacher_nonce'], 'message_teacher')) return;
250 250
 
251
-		$message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] );
251
+		$message_id = $this->save_new_message_post($_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id']);
252 252
 
253 253
 	}
254 254
 
255
-	public function message_reply_received( $comment_id = 0 ) {
255
+	public function message_reply_received($comment_id = 0) {
256 256
 
257 257
 		// Get comment object
258
-    	$comment = get_comment( $comment_id );
258
+    	$comment = get_comment($comment_id);
259 259
 
260
-		if( is_null( $comment ) ) return;
260
+		if (is_null($comment)) return;
261 261
 
262 262
 		// Get message post object
263
-		$message = get_post( $comment->comment_post_ID );
263
+		$message = get_post($comment->comment_post_ID);
264 264
 
265
-		if( $message->post_type != $this->post_type ) return;
265
+		if ($message->post_type != $this->post_type) return;
266 266
 
267 267
 		// Force comment to be approved
268
-		wp_set_comment_status( $comment_id, 'approve' );
268
+		wp_set_comment_status($comment_id, 'approve');
269 269
 
270
-		do_action( 'sensei_private_message_reply', $comment, $message );
270
+		do_action('sensei_private_message_reply', $comment, $message);
271 271
 	}
272 272
 
273 273
     /**
@@ -280,11 +280,11 @@  discard block
 block discarded – undo
280 280
      * @param int $comment_id
281 281
      * @return array;
282 282
      */
283
-    public function stop_wp_comment_emails( $emails , $comment_id ){
283
+    public function stop_wp_comment_emails($emails, $comment_id) {
284 284
 
285
-        $comment = get_comment( $comment_id );
286
-        if( isset( $comment->comment_post_ID ) &&
287
-            'sensei_message' == get_post_type( $comment->comment_post_ID )  ){
285
+        $comment = get_comment($comment_id);
286
+        if (isset($comment->comment_post_ID) &&
287
+            'sensei_message' == get_post_type($comment->comment_post_ID)) {
288 288
 
289 289
             // empty the emails array to ensure no emails are sent for this comment
290 290
             $emails = array();
@@ -302,45 +302,45 @@  discard block
 block discarded – undo
302 302
      * @param  string  $post_id     ID of post related to message
303 303
      * @return mixed                Message ID on success, boolean false on failure
304 304
      */
305
-    private function save_new_message_post( $sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0 ) {
305
+    private function save_new_message_post($sender_id = 0, $receiver_id = 0, $message = '', $post_id = 0) {
306 306
 
307 307
     	$message_id = false;
308 308
 
309
-    	if( $sender_id && $receiver_id && $message && $post_id ) {
309
+    	if ($sender_id && $receiver_id && $message && $post_id) {
310 310
 
311
-    		$title = wp_trim_words( $message, 8, '...' );
311
+    		$title = wp_trim_words($message, 8, '...');
312 312
 
313 313
     		// Set up post data for message
314 314
 	    	$message_data = array(
315 315
 	            'post_type'      => $this->post_type,
316
-	            'post_title'     => esc_html( $title ),
317
-	            'post_content'   => esc_html( $message ),
316
+	            'post_title'     => esc_html($title),
317
+	            'post_content'   => esc_html($message),
318 318
 	            'post_status'    => 'publish',
319 319
 	            'ping_status'    => 'closed',
320 320
 	            'comment_status' => 'open',
321 321
 	            'post_excerpt'   => '',
322
-	            'post_author'	 => intval( $sender_id )
322
+	            'post_author'	 => intval($sender_id)
323 323
 	        );
324 324
 
325 325
 	    	// Insert post
326
-	        $message_id = wp_insert_post( $message_data );
326
+	        $message_id = wp_insert_post($message_data);
327 327
 
328
-	        if( ! is_wp_error( $message_id ) ) {
328
+	        if ( ! is_wp_error($message_id)) {
329 329
 
330 330
 	        	// Add sender to message meta
331
-	        	$sender = get_userdata( $sender_id );
332
-	        	add_post_meta( $message_id, '_sender', $sender->user_login );
331
+	        	$sender = get_userdata($sender_id);
332
+	        	add_post_meta($message_id, '_sender', $sender->user_login);
333 333
 
334 334
 	        	// Add receiver to message meta
335
-	        	$receiver = get_userdata( $receiver_id );
336
-		        add_post_meta( $message_id, '_receiver', $receiver->user_login );
335
+	        	$receiver = get_userdata($receiver_id);
336
+		        add_post_meta($message_id, '_receiver', $receiver->user_login);
337 337
 
338 338
 		        // Add lesson/course ID to message meta
339
-		        $post = get_post( $post_id );
340
-		        add_post_meta( $message_id, '_posttype', $post->post_type );
341
-		        add_post_meta( $message_id, '_post', $post->ID );
339
+		        $post = get_post($post_id);
340
+		        add_post_meta($message_id, '_posttype', $post->post_type);
341
+		        add_post_meta($message_id, '_post', $post->ID);
342 342
 
343
-		        do_action( 'sensei_new_private_message', $message_id );
343
+		        do_action('sensei_new_private_message', $message_id);
344 344
 
345 345
 		    } else {
346 346
 
@@ -358,22 +358,22 @@  discard block
 block discarded – undo
358 358
 	 * @param  integer $user_id    ID of user
359 359
 	 * @return boolean             True if user has access to this message
360 360
 	 */
361
-	private function view_message( $message_id, $user_id = 0) {
361
+	private function view_message($message_id, $user_id = 0) {
362 362
 
363
-		if( ! is_user_logged_in() ) return false;
363
+		if ( ! is_user_logged_in()) return false;
364 364
 
365
-		if( $user_id == 0 ) {
365
+		if ($user_id == 0) {
366 366
 			global $current_user;
367 367
 			wp_get_current_user();
368 368
 			$user_login = $current_user->user_login;
369 369
 		}
370 370
 
371 371
 		// Get allowed users
372
-		$receiver = get_post_meta( $message_id, '_receiver', true );
373
-		$sender = get_post_meta( $message_id, '_sender', true );
372
+		$receiver = get_post_meta($message_id, '_receiver', true);
373
+		$sender = get_post_meta($message_id, '_sender', true);
374 374
 
375 375
 		// Check if user is allowed to view the message
376
-		if( in_array( $user_login, array( $receiver, $sender ) ) ) {
376
+		if (in_array($user_login, array($receiver, $sender))) {
377 377
 			return true;
378 378
 		}
379 379
 
@@ -400,27 +400,27 @@  discard block
 block discarded – undo
400 400
      * @return void
401 401
      */
402 402
 
403
-    public function message_login () {
403
+    public function message_login() {
404 404
 
405
-        if ( is_user_logged_in() ) {
405
+        if (is_user_logged_in()) {
406 406
 
407 407
             return;
408 408
         }
409 409
 
410 410
         $settings = Sensei()->settings->get_settings();
411
-        if( isset( $settings[ 'my_course_page' ] )
412
-            && 0 < intval( $settings[ 'my_course_page' ] ) ){
411
+        if (isset($settings['my_course_page'])
412
+            && 0 < intval($settings['my_course_page'])) {
413 413
 
414
-            $my_courses_page_id = $settings[ 'my_course_page' ];
414
+            $my_courses_page_id = $settings['my_course_page'];
415 415
 
416 416
             $my_courses_url = get_permalink($my_courses_page_id);
417 417
 
418 418
         }
419 419
 
420
-        if ( is_single() && is_singular( $this->post_type )
421
-            || is_post_type_archive( $this->post_type ) ) {
420
+        if (is_single() && is_singular($this->post_type)
421
+            || is_post_type_archive($this->post_type)) {
422 422
 
423
-            if ( isset($my_courses_url) ) {
423
+            if (isset($my_courses_url)) {
424 424
 
425 425
                 wp_redirect($my_courses_url, 303);
426 426
                 exit;
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
      * @param  array $query Original query
440 440
      * @return void
441 441
      */
442
-	public function message_list( $query ) {
442
+	public function message_list($query) {
443 443
 		global $current_user;
444 444
 
445
-		if( is_admin() ) return;
445
+		if (is_admin()) return;
446 446
 
447
-		if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) {
447
+		if (is_post_type_archive($this->post_type) && $query->is_main_query()) {
448 448
 			wp_get_current_user();
449 449
 			$username = $current_user->user_login;
450 450
 
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 				'compare' => '='
463 463
 			);
464 464
 
465
-			$query->set( 'meta_query', $meta_query );
465
+			$query->set('meta_query', $meta_query);
466 466
 
467 467
 			return;
468 468
 		}
@@ -474,11 +474,11 @@  discard block
 block discarded – undo
474 474
 	 * @param  integer $post_id ID of post
475 475
 	 * @return string           Modified string if user does not have access to this message
476 476
 	 */
477
-	public function message_title( $title = '', $post_id = null ) {
477
+	public function message_title($title = '', $post_id = null) {
478 478
 
479
-		if( is_single() && is_singular( $this->post_type ) && in_the_loop() && get_post_type( $post_id ) == $this->post_type ) {
480
-			if( ! is_user_logged_in() || ! $this->view_message( $post_id ) ) {
481
-				$title = __( 'You are not allowed to view this message.', 'woothemes-sensei' );
479
+		if (is_single() && is_singular($this->post_type) && in_the_loop() && get_post_type($post_id) == $this->post_type) {
480
+			if ( ! is_user_logged_in() || ! $this->view_message($post_id)) {
481
+				$title = __('You are not allowed to view this message.', 'woothemes-sensei');
482 482
 			}
483 483
 		}
484 484
 
@@ -490,12 +490,12 @@  discard block
 block discarded – undo
490 490
 	 * @param  string $content Original message content
491 491
 	 * @return string          Empty string if user does not have access to this message
492 492
 	 */
493
-	public function message_content( $content ) {
493
+	public function message_content($content) {
494 494
 		global $post;
495 495
 
496
-		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) {
497
-			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) {
498
-				$content = __( 'Please log in to view your messages.', 'woothemes-sensei' );
496
+		if (is_single() && is_singular($this->post_type) && in_the_loop()) {
497
+			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) {
498
+				$content = __('Please log in to view your messages.', 'woothemes-sensei');
499 499
 			}
500 500
 		}
501 501
 
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
 	 * @param  array $comments Array of replies
508 508
 	 * @return array           Empty array if user does not have access to this message
509 509
 	 */
510
-	public function message_replies( $comments ) {
510
+	public function message_replies($comments) {
511 511
 		global $post;
512 512
 
513
-		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) {
514
-			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) {
513
+		if (is_single() && is_singular($this->post_type) && in_the_loop()) {
514
+			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) {
515 515
 				$comments = array();
516 516
 			}
517 517
 		}
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
 	 * @param  integer $post_id ID of post
526 526
 	 * @return integer          0 if user does not have access to this message
527 527
 	 */
528
-	public function message_reply_count( $count, $post_id ) {
528
+	public function message_reply_count($count, $post_id) {
529 529
 		global $post;
530 530
 
531
-		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) {
532
-			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) {
531
+		if (is_single() && is_singular($this->post_type) && in_the_loop()) {
532
+			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) {
533 533
 				$count = 0;
534 534
 			}
535 535
 		}
@@ -543,11 +543,11 @@  discard block
 block discarded – undo
543 543
 	 * @param  integer $post_id ID of post
544 544
 	 * @return boolean          False if user does not have access to this message
545 545
 	 */
546
-	public function message_replies_open( $open, $post_id ) {
546
+	public function message_replies_open($open, $post_id) {
547 547
 		global $post;
548 548
 
549
-		if( is_single() && is_singular( $this->post_type ) && in_the_loop() ) {
550
-			if( ! is_user_logged_in() || ! $this->view_message( $post->ID ) ) {
549
+		if (is_single() && is_singular($this->post_type) && in_the_loop()) {
550
+			if ( ! is_user_logged_in() || ! $this->view_message($post->ID)) {
551 551
 				$open = false;
552 552
 			}
553 553
 		}
@@ -560,17 +560,17 @@  discard block
 block discarded – undo
560 560
      *
561 561
      * @since 1.9.0
562 562
      */
563
-    public static function the_message_sent_by_title(){
563
+    public static function the_message_sent_by_title() {
564 564
 
565
-        $sender_username = get_post_meta( get_the_ID() , '_sender', true );
566
-        if( $sender_username ) {
565
+        $sender_username = get_post_meta(get_the_ID(), '_sender', true);
566
+        if ($sender_username) {
567 567
 
568
-            $sender = get_user_by( 'login', $sender_username ); ?>
568
+            $sender = get_user_by('login', $sender_username); ?>
569 569
 
570 570
             <p class="message-meta">
571 571
                 <small>
572 572
                     <em>
573
-                        <?php printf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() ); ?>
573
+                        <?php printf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date()); ?>
574 574
                     </em>
575 575
                 </small>
576 576
             </p>
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
 
590 590
         global $post;
591 591
 
592
-        $content_post_id = get_post_meta( $post->ID, '_post', true );
593
-        if( $content_post_id ) {
594
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), '<a href="' . get_permalink( $content_post_id ) . '">' . get_the_title( $content_post_id ) . '</a>' );
592
+        $content_post_id = get_post_meta($post->ID, '_post', true);
593
+        if ($content_post_id) {
594
+            $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), '<a href="'.get_permalink($content_post_id).'">'.get_the_title($content_post_id).'</a>');
595 595
         } else {
596
-            $title = get_the_title( $post->ID );
596
+            $title = get_the_title($post->ID);
597 597
         }
598 598
 
599 599
         ?>
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
                  * @param string $template
611 611
                  * @param string $post_type
612 612
                  */
613
-                echo apply_filters( 'sensei_single_title', $title, $post->post_type );
613
+                echo apply_filters('sensei_single_title', $title, $post->post_type);
614 614
                 ?>
615 615
 
616 616
             </h1>
@@ -629,18 +629,18 @@  discard block
 block discarded – undo
629 629
      *
630 630
      * @return string
631 631
      */
632
-    public static function the_archive_header( ){
632
+    public static function the_archive_header( ) {
633 633
 
634 634
         $html = '';
635 635
         $html .= '<header class="archive-header"><h1>';
636
-        $html .= __( 'My Messages', 'woothemes-sensei' );
636
+        $html .= __('My Messages', 'woothemes-sensei');
637 637
         $html .= '</h1></header>';
638 638
 
639 639
         /**
640 640
          * Filter the sensei messages archive title.
641 641
          * @since 1.0.0
642 642
          */
643
-        echo apply_filters( 'sensei_message_archive_title', $html );
643
+        echo apply_filters('sensei_message_archive_title', $html);
644 644
 
645 645
     } // get_archive_header()
646 646
 
@@ -650,23 +650,23 @@  discard block
 block discarded – undo
650 650
      * @since 1.9.0
651 651
      * @param $post_id
652 652
      */
653
-    public static function the_message_title( $message_post_id ){
653
+    public static function the_message_title($message_post_id) {
654 654
 
655
-        $content_post_id = get_post_meta( $message_post_id, '_post', true );
655
+        $content_post_id = get_post_meta($message_post_id, '_post', true);
656 656
 
657
-        if( $content_post_id ) {
657
+        if ($content_post_id) {
658 658
 
659
-            $title = sprintf( __( 'Re: %1$s', 'woothemes-sensei' ), get_the_title( $content_post_id ) );
659
+            $title = sprintf(__('Re: %1$s', 'woothemes-sensei'), get_the_title($content_post_id));
660 660
 
661 661
         } else {
662 662
 
663
-            $title = get_the_title( $message_post_id );
663
+            $title = get_the_title($message_post_id);
664 664
 
665 665
         }
666 666
 
667 667
         ?>
668 668
         <h2>
669
-            <a href="<?php esc_url( get_permalink( $message_post_id ) );?>">
669
+            <a href="<?php esc_url(get_permalink($message_post_id)); ?>">
670 670
                 <?php echo  $title; ?>
671 671
             </a>
672 672
 
@@ -680,13 +680,13 @@  discard block
 block discarded – undo
680 680
      *
681 681
      * @param $message_post_id
682 682
      */
683
-    public  static function the_message_sender( $message_post_id ){
683
+    public  static function the_message_sender($message_post_id) {
684 684
 
685
-        $sender_username = get_post_meta( $message_post_id, '_sender', true );
686
-        $sender = get_user_by( 'login', $sender_username );
685
+        $sender_username = get_post_meta($message_post_id, '_sender', true);
686
+        $sender = get_user_by('login', $sender_username);
687 687
 
688
-        if( $sender_username && $sender instanceof WP_User ) {
689
-            $sender_display_name = sprintf( __( 'Sent by %1$s on %2$s.', 'woothemes-sensei' ), $sender->display_name, get_the_date() );
688
+        if ($sender_username && $sender instanceof WP_User) {
689
+            $sender_display_name = sprintf(__('Sent by %1$s on %2$s.', 'woothemes-sensei'), $sender->display_name, get_the_date());
690 690
             ?>
691 691
             <p class="message-meta">
692 692
                 <small>
@@ -704,13 +704,13 @@  discard block
 block discarded – undo
704 704
      *
705 705
      * @since 1.9.0
706 706
      */
707
-    public static function the_my_messages_link(){
708
-        if( ! Sensei()->settings->get('messages_disable')  ) {
707
+    public static function the_my_messages_link() {
708
+        if ( ! Sensei()->settings->get('messages_disable')) {
709 709
             ?>
710 710
             <p class="my-messages-link-container">
711
-                <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>"
712
-                   title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>">
713
-                    <?php _e( 'My Messages', 'woothemes-sensei' ); ?>
711
+                <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>"
712
+                   title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>">
713
+                    <?php _e('My Messages', 'woothemes-sensei'); ?>
714 714
                 </a>
715 715
             </p>
716 716
             <?php
@@ -724,4 +724,4 @@  discard block
 block discarded – undo
724 724
  * for backward compatibility
725 725
  * @since 1.9.0
726 726
  */
727
-class WooThemes_Sensei_Messages extends Sensei_Messages{}
727
+class WooThemes_Sensei_Messages extends Sensei_Messages {}
Please login to merge, or discard this patch.
Braces   +39 added lines, -16 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 Messages Class
@@ -73,7 +76,9 @@  discard block
 block discarded – undo
73 76
 
74 77
 	public function add_meta_box( $post_type, $post ) {
75 78
 
76
-		if( ! $post_type == $this->post_type ) return;
79
+		if( ! $post_type == $this->post_type ) {
80
+			return;
81
+		}
77 82
 
78 83
 		add_meta_box( $this->post_type . '-data', __( 'Message Information', 'woothemes-sensei' ), array( $this, 'meta_box_content' ), $this->post_type, 'normal', 'default' );
79 84
 
@@ -138,7 +143,9 @@  discard block
 block discarded – undo
138 143
 	public function save_message( $post_id = 0 ) {
139 144
 		global $post;
140 145
 
141
-		if( $this->post_type != get_post_type() ) return;
146
+		if( $this->post_type != get_post_type() ) {
147
+			return;
148
+		}
142 149
 
143 150
 		if( isset( $_POST['sender'] ) && $_POST['sender'] ) {
144 151
 			update_post_meta( $post_id, '_sender', $_POST['sender'] );
@@ -174,7 +181,9 @@  discard block
 block discarded – undo
174 181
 
175 182
 		if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) {
176 183
 
177
-			if( ! is_user_logged_in() ) return;
184
+			if( ! is_user_logged_in() ) {
185
+				return;
186
+			}
178 187
 
179 188
 			if( isset( $_GET['contact'] ) ) {
180 189
 				$html .= $this->teacher_contact_form( $post );
@@ -185,7 +194,7 @@  discard block
 block discarded – undo
185 194
 					$contact_button_text = __( 'Contact Lesson Teacher', 'woothemes-sensei' );
186 195
 				} elseif( 'course' == $post->post_type ) {
187 196
 					$contact_button_text = __( 'Contact Course Teacher', 'woothemes-sensei' );
188
-				}else{
197
+				} else{
189 198
                     $contact_button_text = __( 'Contact Teacher', 'woothemes-sensei' );
190 199
                 }
191 200
 
@@ -203,14 +212,18 @@  discard block
 block discarded – undo
203 212
 
204 213
 	public function teacher_contact_form( $post ) {
205 214
 
206
-		if( ! is_user_logged_in() ) return;
215
+		if( ! is_user_logged_in() ) {
216
+			return;
217
+		}
207 218
 
208 219
 		global $current_user;
209 220
 		wp_get_current_user();
210 221
 
211 222
 		$html = '';
212 223
 
213
-		if( ! isset( $post->ID ) ) return $html;
224
+		if( ! isset( $post->ID ) ) {
225
+			return $html;
226
+		}
214 227
 
215 228
         //confirm private message
216 229
         $confirmation = '';
@@ -244,9 +257,13 @@  discard block
 block discarded – undo
244 257
 
245 258
 	public function save_new_message() {
246 259
 
247
-		if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) return;
260
+		if( ! isset( $_POST['sensei_message_teacher_nonce'] ) ) {
261
+			return;
262
+		}
248 263
 
249
-		if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) return;
264
+		if( ! wp_verify_nonce( $_POST['sensei_message_teacher_nonce'], 'message_teacher' ) ) {
265
+			return;
266
+		}
250 267
 
251 268
 		$message_id = $this->save_new_message_post( $_POST['sender_id'], $_POST['receiver_id'], $_POST['contact_message'], $_POST['post_id'] );
252 269
 
@@ -257,12 +274,16 @@  discard block
 block discarded – undo
257 274
 		// Get comment object
258 275
     	$comment = get_comment( $comment_id );
259 276
 
260
-		if( is_null( $comment ) ) return;
277
+		if( is_null( $comment ) ) {
278
+			return;
279
+		}
261 280
 
262 281
 		// Get message post object
263 282
 		$message = get_post( $comment->comment_post_ID );
264 283
 
265
-		if( $message->post_type != $this->post_type ) return;
284
+		if( $message->post_type != $this->post_type ) {
285
+			return;
286
+		}
266 287
 
267 288
 		// Force comment to be approved
268 289
 		wp_set_comment_status( $comment_id, 'approve' );
@@ -360,7 +381,9 @@  discard block
 block discarded – undo
360 381
 	 */
361 382
 	private function view_message( $message_id, $user_id = 0) {
362 383
 
363
-		if( ! is_user_logged_in() ) return false;
384
+		if( ! is_user_logged_in() ) {
385
+			return false;
386
+		}
364 387
 
365 388
 		if( $user_id == 0 ) {
366 389
 			global $current_user;
@@ -424,9 +447,7 @@  discard block
 block discarded – undo
424 447
 
425 448
                 wp_redirect($my_courses_url, 303);
426 449
                 exit;
427
-            }
428
-
429
-            else {
450
+            } else {
430 451
 
431 452
                 wp_redirect(home_url('/wp-login.php'), 303);
432 453
                 exit;
@@ -442,7 +463,9 @@  discard block
 block discarded – undo
442 463
 	public function message_list( $query ) {
443 464
 		global $current_user;
444 465
 
445
-		if( is_admin() ) return;
466
+		if( is_admin() ) {
467
+			return;
468
+		}
446 469
 
447 470
 		if( is_post_type_archive( $this->post_type ) && $query->is_main_query() ) {
448 471
 			wp_get_current_user();
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -1942,6 +1942,7 @@
 block discarded – undo
1942 1942
      * Hooked into 'get_terms'
1943 1943
      *
1944 1944
      * @since 1.8.0
1945
+     * @param string[] $taxonomies
1945 1946
      */
1946 1947
     public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947 1948
     {
Please login to merge, or discard this patch.
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 62
         // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
63
+        add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10);
64
+        add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10);
65
+        add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20);
66 66
 
67 67
         // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
68
+        add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+        add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+        add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+        add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
72 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 82
         // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 85
         //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 97
         // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
98
+        add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+        add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 102
         //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 105
         // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
106
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
107
+        add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3);
108 108
 
109 109
         // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 153
             // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 158
             // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 194
             // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
195
+            $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />';
196 196
             if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 199
                 foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 203
             } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
204
+                $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit');
205
+                $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>';
206 206
             } // End If Statement
207 207
 
208 208
         } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
209
+            $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>';
210 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 227
         // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
228
+        if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce'])
229
+            ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) {
230 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 257
             // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson') && WooThemes_Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = WooThemes_Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 483
                 $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 492
                 $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 733
         $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 818
         //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 822
         $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 845
             if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
846
+                $html .= '<div class="updated fade">'."\n";
847
+                $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n";
848
+                $html .= '</div>'."\n";
849 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 853
 
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
854
+        $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
855
+        $html .= '<input type="hidden" name="post_type" value="course" />'."\n";
856
+        $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n";
857
+        $html .= '<select id="module-order-course" name="course_id">'."\n";
858
+        $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
859 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 869
 
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
870
+        $html .= '</select>'."\n";
871
+        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
872
+        $html .= '</form>'."\n";
873 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 906
 
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
907
+                    $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n";
908
+                    $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
909
+                    $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n";
910
+                    $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n";
911 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 946
             if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
947
+                echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>';
948 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 1038
                 $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 1092
                 foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1093
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1094 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 1136
                 foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1137
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1138 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1172
+        if (empty($modules) || isset($modules['errors'])) {
1173 1173
             return false;
1174 1174
         }
1175 1175
 
1176 1176
        // get the last item in the array there should be only be 1 really.
1177 1177
        // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1178
+       foreach ($modules as $module) {
1179 1179
            break;
1180 1180
        }
1181 1181
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         if (isset($course_id) && 0 < $course_id) {
1189 1189
 
1190 1190
             // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1191
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1192 1192
                 return false;
1193 1193
             }
1194 1194
 
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
     {
1263 1263
 
1264 1264
 
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1266
+        wp_enqueue_style($this->taxonomy.'-frontend');
1267 1267
     }
1268 1268
 
1269 1269
     /**
@@ -1273,37 +1273,37 @@  discard block
 block discarded – undo
1273 1273
      *
1274 1274
      * @return void
1275 1275
      */
1276
-    public function admin_enqueue_scripts( $hook ) {
1276
+    public function admin_enqueue_scripts($hook) {
1277 1277
 
1278 1278
         /**
1279 1279
          * Filter the page hooks where modules admin script can be loaded on.
1280 1280
          *
1281 1281
          * @param array $white_listed_pages
1282 1282
          */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1284 1284
             'edit-tags.php',
1285 1285
             'course_page_module-order',
1286 1286
             'post-new.php',
1287 1287
             'post.php'
1288
-        ) );
1288
+        ));
1289 1289
 
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1291 1291
             return;
1292 1292
         }
1293 1293
 
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1295 1295
 
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1296
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1297
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1298
+        wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2'), Sensei()->version, true);
1299 1299
 
1300 1300
         // localized module data
1301 1301
         $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1302
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1303
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1304 1304
         );
1305 1305
 
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1307 1307
     }
1308 1308
 
1309 1309
     /**
@@ -1316,8 +1316,8 @@  discard block
 block discarded – undo
1316 1316
     public function admin_enqueue_styles() {
1317 1317
 
1318 1318
 
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1320
+        wp_enqueue_style($this->taxonomy.'-sortable');
1321 1321
 
1322 1322
     }
1323 1323
 
@@ -1331,9 +1331,9 @@  discard block
 block discarded – undo
1331 1331
      */
1332 1332
     public function course_modules_title( ) {
1333 1333
 
1334
-       if( sensei_module_has_lessons() ){
1334
+       if (sensei_module_has_lessons()) {
1335 1335
 
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1336
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1337 1337
 
1338 1338
         }
1339 1339
 
@@ -1346,18 +1346,18 @@  discard block
 block discarded – undo
1346 1346
      * @since 1.8.0
1347 1347
      * @return void
1348 1348
      */
1349
-    public function load_course_module_content_template(){
1349
+    public function load_course_module_content_template() {
1350 1350
 
1351 1351
         // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1352
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1353
+        if ($located_template) {
1354 1354
 
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1355
+            Sensei_Templates::get_template('single-course/course-modules.php');
1356 1356
             return;
1357 1357
 
1358 1358
         }
1359 1359
 
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1360
+        Sensei_Templates::get_template('single-course/modules.php');
1361 1361
 
1362 1362
     } // end course_module_content
1363 1363
 
@@ -1370,15 +1370,15 @@  discard block
 block discarded – undo
1370 1370
      * @param $term_id
1371 1371
      * @return array $lessons
1372 1372
      */
1373
-    public function get_lessons( $course_id , $term_id ){
1373
+    public function get_lessons($course_id, $term_id) {
1374 1374
 
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1375
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+        if (isset($lesson_query->posts)) {
1378 1378
 
1379 1379
             return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+        } else {
1382 1382
 
1383 1383
             return array();
1384 1384
 
@@ -1395,9 +1395,9 @@  discard block
 block discarded – undo
1395 1395
      * @param $term_id
1396 1396
      * @return WP_Query $lessons_query
1397 1397
      */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1398
+    public function get_lessons_query($course_id, $term_id) {
1399 1399
 
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1400
+        if (empty($term_id) || empty($course_id)) {
1401 1401
 
1402 1402
             return array();
1403 1403
 
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
                 array(
1419 1419
                     'taxonomy' => 'module',
1420 1420
                     'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1421
+                    'terms' => intval($term_id)
1422 1422
                 )
1423 1423
             ),
1424 1424
             'orderby' => 'menu_order',
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
             'suppress_filters' => 0
1427 1427
         );
1428 1428
 
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1430
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1431 1431
             $args['orderby'] = 'meta_value_num date';
1432 1432
         }
1433 1433
 
1434
-        $lessons_query = new WP_Query( $args );
1434
+        $lessons_query = new WP_Query($args);
1435 1435
 
1436 1436
         return $lessons_query;
1437 1437
 
@@ -1446,37 +1446,37 @@  discard block
 block discarded – undo
1446 1446
      *
1447 1447
      * @return array $non_module_lessons
1448 1448
      */
1449
-    public function get_none_module_lessons( $course_id ){
1449
+    public function get_none_module_lessons($course_id) {
1450 1450
 
1451 1451
         $non_module_lessons = array();
1452 1452
 
1453 1453
         //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1454
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1455 1455
 
1456 1456
             return $non_module_lessons;
1457 1457
         }
1458 1458
 
1459 1459
         //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1460
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1461 1461
 
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1462
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1463 1463
 
1464 1464
         }
1465 1465
 
1466 1466
         // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1467
+        $course_modules = $this->get_course_modules($course_id);
1468 1468
 
1469 1469
         //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1470
+        if (empty($course_modules) || ! is_array($course_modules)) {
1471 1471
 
1472
-            return  Sensei()->course->course_lessons( $course_id );
1472
+            return  Sensei()->course->course_lessons($course_id);
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         $terms = array();
1477
-        foreach( $course_modules as $module ){
1477
+        foreach ($course_modules as $module) {
1478 1478
 
1479
-            array_push( $terms ,  $module->term_id );
1479
+            array_push($terms, $module->term_id);
1480 1480
 
1481 1481
         }
1482 1482
 
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             'meta_query' => array(
1488 1488
                 array(
1489 1489
                     'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1490
+                    'value' => intval($course_id),
1491 1491
                     'compare' => '='
1492 1492
                 )
1493 1493
             ),
@@ -1504,11 +1504,11 @@  discard block
 block discarded – undo
1504 1504
             'suppress_filters' => 0
1505 1505
         );
1506 1506
 
1507
-        $wp_lessons_query = new WP_Query( $args );
1507
+        $wp_lessons_query = new WP_Query($args);
1508 1508
 
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1509
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1510 1510
             $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1511
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1512 1512
         }
1513 1513
 
1514 1514
         return $non_module_lessons;
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
      *
1520 1520
      * @since 1.8.0
1521 1521
      */
1522
-    public function setup_modules_taxonomy(){
1522
+    public function setup_modules_taxonomy() {
1523 1523
 
1524 1524
         $labels = array(
1525 1525
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1556,11 +1556,11 @@  discard block
 block discarded – undo
1556 1556
             'show_in_nav_menus' => false,
1557 1557
             'show_in_quick_edit' => false,
1558 1558
             'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1559
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1560 1560
             'labels' => $labels
1561 1561
         );
1562 1562
 
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1563
+        register_taxonomy('module', array('course', 'lesson'), $args);
1564 1564
 
1565 1565
     }// end setup_modules_taxonomy
1566 1566
 
@@ -1572,12 +1572,12 @@  discard block
 block discarded – undo
1572 1572
      * @since 1.8.0
1573 1573
      * @return void
1574 1574
      */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1575
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1576 1576
 
1577
-        global $typenow , $taxnow;
1577
+        global $typenow, $taxnow;
1578 1578
 
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1580
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1581 1581
         }
1582 1582
 
1583 1583
     }// end redirect to course taxonomy
@@ -1590,18 +1590,18 @@  discard block
 block discarded – undo
1590 1590
      * @since 1.8.0
1591 1591
      * @return void
1592 1592
      */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1593
+    public function remove_lessons_menu_model_taxonomy() {
1594 1594
         global $submenu;
1595 1595
 
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1596
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1597 1597
             return; // exit
1598 1598
         }
1599 1599
 
1600 1600
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1601
+        foreach ($lesson_main_menu as $index => $sub_item) {
1602 1602
 
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1604
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1605 1605
             }
1606 1606
         }
1607 1607
 
@@ -1615,18 +1615,18 @@  discard block
 block discarded – undo
1615 1615
      * @since 1.8.0
1616 1616
      * @return void
1617 1617
      */
1618
-    public function remove_courses_menu_model_taxonomy(){
1618
+    public function remove_courses_menu_model_taxonomy() {
1619 1619
         global $submenu;
1620 1620
 
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1621
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1622 1622
             return; // exit
1623 1623
         }
1624 1624
 
1625 1625
         $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1626
+        foreach ($course_main_menu as $index => $sub_item) {
1627 1627
 
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1629
+                unset($submenu['edit.php?post_type=course'][$index]);
1630 1630
             }
1631 1631
         }
1632 1632
 
@@ -1642,12 +1642,12 @@  discard block
 block discarded – undo
1642 1642
      * @param string $term_name
1643 1643
      * @return array $owners { type WP_User }. Empty array if none if found.
1644 1644
      */
1645
-    public static function get_term_authors( $term_name ){
1645
+    public static function get_term_authors($term_name) {
1646 1646
 
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1647
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1648 1648
 
1649 1649
         $owners = array();
1650
-        if( empty( $terms ) ){
1650
+        if (empty($terms)) {
1651 1651
 
1652 1652
             return $owners;
1653 1653
 
@@ -1657,11 +1657,11 @@  discard block
 block discarded – undo
1657 1657
 
1658 1658
 
1659 1659
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1660
+        foreach ($terms as $term) {
1661
+            if ($term->name == $term_name) {
1662 1662
 
1663 1663
                 // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1664
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1665 1665
 
1666 1666
             }// end if term name
1667 1667
 
@@ -1682,30 +1682,30 @@  discard block
 block discarded – undo
1682 1682
      * @param $slug
1683 1683
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684 1684
      */
1685
-    public static function get_term_author( $slug='' ){
1685
+    public static function get_term_author($slug = '') {
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+        if (empty($slug)) {
1690 1690
 
1691 1691
             return $term_owner;
1692 1692
 
1693 1693
         }
1694 1694
 
1695 1695
         // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1696
+        $slug_parts = explode('-', $slug);
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+        if (count($slug_parts) > 1) {
1699 1699
 
1700 1700
             // get the user data
1701 1701
             $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1702
+            $author = get_userdata($possible_user_id);
1703 1703
 
1704 1704
             // if the user doesnt exist for the first part of the slug
1705 1705
             // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1706
+            if (is_a($author, 'WP_User')) {
1707 1707
 
1708
-                $term_owner =  $author;
1708
+                $term_owner = $author;
1709 1709
 
1710 1710
             }
1711 1711
         }
@@ -1722,48 +1722,48 @@  discard block
 block discarded – undo
1722 1722
      *
1723 1723
      * @param WP_Post $post Post object.
1724 1724
      */
1725
-    public function course_module_metabox( $post ) {
1725
+    public function course_module_metabox($post) {
1726 1726
 
1727 1727
         $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1728
+        $taxonomy = get_taxonomy('module');
1729 1729
 
1730 1730
         ?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1734
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1734
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1735 1735
             </ul>
1736 1736
 
1737 1737
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1738 1738
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1739
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1739
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1740 1740
                 </ul>
1741 1741
             </div>
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1745
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1746 1746
                 echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747 1747
                 ?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1749
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1752
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1753 1753
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757 1757
                             /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1758
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1759 1759
                             ?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1763 1763
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1764
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1765
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1766
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1764
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1765
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1766
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1767 1767
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1768 1768
                     </p>
1769 1769
                 </div>
@@ -1783,55 +1783,55 @@  discard block
 block discarded – undo
1783 1783
     public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1787
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1788 1788
         }
1789 1789
 
1790 1790
         // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1791
+        $term_name = sanitize_text_field($_POST['newTerm']);
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+        if (current_user_can('manage_options')) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1796 1796
 
1797 1797
         } else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1800 1800
 
1801 1801
         }
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+        $course_id = sanitize_text_field($_POST['course_id']);
1804 1804
 
1805 1805
         // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1806
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1807 1807
 
1808 1808
         // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1809
+        if (is_wp_error($slug)) {
1810 1810
 
1811 1811
             // prepare for possible term name and id to be passed down if term exists
1812 1812
             $term_data = array();
1813 1813
 
1814 1814
             // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1815
+            if (isset($slug->errors['term_exists'])) {
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1817
+                $term = get_term_by('slug', $term_slug, 'module');
1818 1818
                 $term_data['name'] = $term_name;
1819 1819
                 $term_data['id'] = $term->term_id;
1820 1820
 
1821 1821
                 // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1822
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1823 1823
             }
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1826 1826
 
1827 1827
         }
1828 1828
 
1829 1829
         //make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1832 1832
 
1833 1833
         // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1834
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1835 1835
 
1836 1836
     }
1837 1837
 
@@ -1843,26 +1843,26 @@  discard block
 block discarded – undo
1843 1843
      *
1844 1844
      * @since 1.8.0
1845 1845
      */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1846
+    public function filter_module_terms($terms, $taxonomies, $args) {
1847 1847
 
1848 1848
         //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1849
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1850 1850
             return $terms;
1851 1851
         }
1852 1852
 
1853 1853
         // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1854
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1855 1855
 
1856 1856
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1857
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1858 1858
             // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1859
+            $terms = array_keys($terms);
1860 1860
         }
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1863 1863
 
1864 1864
         // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1866 1866
 
1867 1867
         return $teachers_terms;
1868 1868
     }// end filter_module_terms
@@ -1875,25 +1875,25 @@  discard block
 block discarded – undo
1875 1875
      *
1876 1876
      * @since 1.8.0
1877 1877
      */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1878
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1879 1879
 
1880 1880
         //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1881
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1882 1882
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1883
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1884 1884
             return $terms;
1885 1885
         }
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1888 1888
 
1889 1889
         // if term objects were passed in send back objects
1890 1890
         // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1891
+        if (is_object($terms[0])) {
1892 1892
             return $term_objects;
1893 1893
         }
1894 1894
 
1895 1895
         $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1896
+        foreach ($term_objects as $term_object) {
1897 1897
             $terms[] = $term_object->term_id;
1898 1898
         }
1899 1899
 
@@ -1911,20 +1911,20 @@  discard block
 block discarded – undo
1911 1911
      * @param $user_id
1912 1912
      * @return array
1913 1913
      */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1914
+    public function filter_terms_by_owner($terms, $user_id) {
1915 1915
 
1916 1916
         $users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+        foreach ($terms as $index => $term) {
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1920
+            if (is_numeric($term)) {
1921 1921
                 // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1922
+                $term = get_term($term, 'module');
1923 1923
             }
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1927
+            if ($user_id == $author->ID) {
1928 1928
                 // add the term to the teachers terms
1929 1929
                 $users_terms[] = $term;
1930 1930
             }
@@ -1943,34 +1943,34 @@  discard block
 block discarded – undo
1943 1943
      *
1944 1944
      * @since 1.8.0
1945 1945
      */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1946
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1947 1947
     {
1948 1948
 
1949 1949
         // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1950
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1951 1951
             return $terms;
1952 1952
         }
1953 1953
 
1954 1954
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955 1955
         // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1956
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958 1958
             return $terms;
1959 1959
 
1960 1960
         }
1961 1961
 
1962 1962
         // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1963
+        foreach ($terms as $index => $term) {
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1965
+            if (is_numeric($term)) {
1966 1966
                 // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1967
+                $term = get_term($term, 'module');
1968 1968
             }
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+            if ( ! user_can($author, 'manage_options')) {
1973
+                $term->name = $term->name.' ('.$author->display_name.') ';
1974 1974
             }
1975 1975
 
1976 1976
             // add the term to the teachers terms
@@ -1999,23 +1999,23 @@  discard block
 block discarded – undo
1999 1999
      * @sine 1.9.0
2000 2000
      * @param $post_id
2001 2001
      */
2002
-    public static function reset_none_modules_transient ( $post_id ){
2002
+    public static function reset_none_modules_transient($post_id) {
2003 2003
 
2004 2004
         // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2005
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2006 2006
 
2007 2007
             $course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+            if ('lesson' == get_post_type($post_id)) {
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2012 2012
 
2013 2013
             }
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+            if ( ! empty($course_id)) {
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2019 2019
 
2020 2020
             }
2021 2021
 
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
      * @deprecated since 1.9.0
2031 2031
      *
2032 2032
      */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2033
+    public static function deprecate_sensei_single_course_modules_content() {
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2036 2036
 
2037 2037
     }
2038 2038
 
@@ -2043,12 +2043,12 @@  discard block
 block discarded – undo
2043 2043
      *
2044 2044
      * @since 1.9.0
2045 2045
      */
2046
-    public static function setup_single_course_module_loop(){
2046
+    public static function setup_single_course_module_loop() {
2047 2047
 
2048 2048
         global $sensei_modules_loop, $post;
2049 2049
         $course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+        $modules = Sensei()->modules->get_course_modules($course_id);
2052 2052
 
2053 2053
         //initial setup
2054 2054
         $sensei_modules_loop['total'] = 0;
@@ -2056,22 +2056,22 @@  discard block
 block discarded – undo
2056 2056
         $sensei_modules_loop['current'] = -1;
2057 2057
 
2058 2058
         // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2059
+        if ( ! $modules || empty($modules)) {
2060 2060
             return;
2061 2061
         }
2062 2062
 
2063 2063
 
2064 2064
         $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2065
+        foreach ($modules as $term) {
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2068
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2069 2069
 
2070 2070
         }
2071 2071
 
2072 2072
 
2073 2073
         //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2074
+        $sensei_modules_loop['total'] = count($modules);
2075 2075
         $sensei_modules_loop['modules'] = $modules;
2076 2076
         $sensei_modules_loop['current'] = -1;
2077 2077
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
      * @since 1.9.0
2085 2085
      *
2086 2086
      */
2087
-    public static function teardown_single_course_module_loop(){
2087
+    public static function teardown_single_course_module_loop() {
2088 2088
 
2089 2089
         global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+	exit;
5
+}
4 6
 
5 7
 /**
6 8
  * Sensei Modules Class
@@ -401,8 +403,9 @@  discard block
 block discarded – undo
401 403
         $term = urldecode(stripslashes($_GET['term']));
402 404
 
403 405
         // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
+        if (empty($term)) {
407
+                    die();
408
+        }
406 409
 
407 410
         // Set a default if none is given
408 411
         $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
@@ -789,7 +792,9 @@  discard block
 block discarded – undo
789 792
         );
790 793
         $lessons = get_posts($args);
791 794
 
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
795
+        if (is_wp_error($lessons) || 0 >= count($lessons)) {
796
+        	return 0;
797
+        }
793 798
 
794 799
         $completed = false;
795 800
         $lesson_count = 0;
@@ -1378,7 +1383,7 @@  discard block
 block discarded – undo
1378 1383
 
1379 1384
             return $lesson_query->posts;
1380 1385
 
1381
-        }else{
1386
+        } else{
1382 1387
 
1383 1388
             return array();
1384 1389
 
Please login to merge, or discard this patch.
Indentation   +1881 added lines, -1881 removed lines patch added patch discarded remove patch
@@ -14,265 +14,265 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Core_Modules
16 16
 {
17
-    private $dir;
18
-    private $file;
19
-    private $assets_dir;
20
-    private $assets_url;
21
-    private $order_page_slug;
22
-    public $taxonomy;
23
-
24
-    public function __construct( $file )
25
-    {
26
-        $this->file = $file;
27
-        $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
29
-        $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
-        $this->taxonomy = 'module';
31
-        $this->order_page_slug = 'module-order';
32
-
33
-        // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
-
36
-        // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
-
39
-        // Save lesson meta box
40
-        add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
-
42
-        //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
-
45
-        // Frontend styling
46
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
-
48
-        // Admin styling
49
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
-
52
-        // Handle module completion record
53
-        add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
-        add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
-        add_action('wp', array($this, 'save_module_progress'), 10);
56
-
57
-        // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
-        add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
-        add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
-
62
-        // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
-
67
-        // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
-        add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
-
74
-        // Manage module taxonomy archive page
75
-        add_filter('template_include', array($this, 'module_archive_template'), 10);
76
-        add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
-        add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
-        add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
-        add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
-        add_filter('body_class', array($this, 'module_archive_body_class'));
81
-
82
-        // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
-
85
-        //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
-
88
-        // Set up display on single lesson page
89
-        add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
-
91
-        // Add 'Modules' columns to Analysis tables
92
-        add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
-        add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
-        add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
-        add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
-
97
-        // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
-        add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
-
102
-        //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
-
105
-        // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
-
109
-        // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
-
112
-        // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
-
115
-    } // end constructor
116
-
117
-    /**
118
-     * Alter a module term slug when a new taxonomy term is created
119
-     * This will add the creators user name to the slug for uniqueness.
120
-     *
121
-     * @since 1.8.0
122
-     *
123
-     * @param $term_id
124
-     * @param $tt_id
125
-     * @param $taxonomy
126
-     *
127
-     * @return void
128
-     * @deprecated since 1.9.0
129
-     */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
-
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
133
-
134
-    }// end add_module_term_group
135
-
136
-    /**
137
-     * Hook in all meta boxes related tot he modules taxonomy
138
-     *
139
-     * @since 1.8.0
140
-     *
141
-     * @param string $post_type
142
-     * @param WP_Post $post
143
-     *
144
-     * @return void
145
-     */
146
-    public function modules_metaboxes( $post_type, $post )
147
-    {
148
-        if ('lesson' == $post_type ) {
149
-
150
-            // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
-
153
-            // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
-        }
156
-
157
-        if( 'course' == $post_type ){
158
-            // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Build content for custom module meta box
165
-     *
166
-     * @since 1.8.0
167
-     * @param  object $post Current post object
168
-     * @return void
169
-     */
170
-    public function lesson_module_metabox($post)
171
-    {
172
-
173
-        // Get lesson course
174
-        $lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
-
176
-        $html = '';
177
-
178
-        // Only show module selection if this lesson is part of a course
179
-        if ($lesson_course && $lesson_course > 0) {
180
-
181
-            // Get existing lesson module
182
-            $lesson_module = 0;
183
-            $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
-                foreach ($lesson_module_list as $single_module) {
186
-                    $lesson_module = $single_module->term_id;
187
-                    break;
188
-                }
189
-            }
190
-
191
-            // Get the available modules for this lesson's course
192
-            $modules = $this->get_course_modules($lesson_course);
193
-
194
-            // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
-            if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
-                foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
-                }
202
-                $html .= '</select>' . "\n";
203
-            } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
-            } // End If Statement
207
-
208
-        } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
-        } // End If Statement
211
-
212
-        // Output the HTML
213
-        echo $html;
214
-    }
215
-
216
-    /**
217
-     * Save module to lesson
218
-     *
219
-     * @since 1.8.0
220
-     * @param  integer $post_id ID of post
221
-     * @return mixed            Post ID on permissions failure, boolean true on success
222
-     */
223
-    public function save_lesson_module($post_id)
224
-    {
225
-        global $post;
226
-
227
-        // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
-            return $post_id;
231
-        }
232
-
233
-        // Check if user has permissions to edit lessons
234
-        $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
-            return $post_id;
237
-        }
238
-
239
-        // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
241
-            return $post_id;
242
-        }
243
-
244
-        // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
246
-
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
-                return true;
250
-            }
251
-
252
-            $module_id = intval( $_POST['lesson_module'] );
253
-
254
-            // Assign lesson to selected module
255
-            wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
-
257
-            // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
-            }
261
-        }
262
-
263
-        return true;
264
-    }
265
-
266
-    /**
267
-     * Display course field on new module screen
268
-     *
269
-     * @since 1.8.0
270
-     * @param object $taxonomy Taxonomy object
271
-     * @return void
272
-     */
273
-    public function add_module_fields($taxonomy)
274
-    {
275
-        ?>
17
+	private $dir;
18
+	private $file;
19
+	private $assets_dir;
20
+	private $assets_url;
21
+	private $order_page_slug;
22
+	public $taxonomy;
23
+
24
+	public function __construct( $file )
25
+	{
26
+		$this->file = $file;
27
+		$this->dir = dirname($this->file);
28
+		$this->assets_dir = trailingslashit($this->dir) . 'assets';
29
+		$this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
+		$this->taxonomy = 'module';
31
+		$this->order_page_slug = 'module-order';
32
+
33
+		// setup taxonomy
34
+		add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
+
36
+		// Manage lesson meta boxes for taxonomy
37
+		add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
+
39
+		// Save lesson meta box
40
+		add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
+
42
+		//Reset the none modules lessons transient
43
+		add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
+
45
+		// Frontend styling
46
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
+
48
+		// Admin styling
49
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
+
52
+		// Handle module completion record
53
+		add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
+		add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
+		add_action('wp', array($this, 'save_module_progress'), 10);
56
+
57
+		// Handle module ordering
58
+		add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
+		add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
+		add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
+
62
+		// Ensure modules always show under courses
63
+		add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
+		add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
+		add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
+
67
+		// Add course field to taxonomy
68
+		add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+		add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+		add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+		add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
+		add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
+
74
+		// Manage module taxonomy archive page
75
+		add_filter('template_include', array($this, 'module_archive_template'), 10);
76
+		add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
+		add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
+		add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
+		add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
+		add_filter('body_class', array($this, 'module_archive_body_class'));
81
+
82
+		// add modules to the single course template
83
+		add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
+
85
+		//Single Course modules actions. Add to single-course/course-modules.php
86
+		add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
+
88
+		// Set up display on single lesson page
89
+		add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
+
91
+		// Add 'Modules' columns to Analysis tables
92
+		add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
+		add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
+		add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
+		add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
+
97
+		// Manage module taxonomy columns
98
+		add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+		add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
+		add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
+
102
+		//store new modules created on the course edit screen
103
+		add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
+
105
+		// for non admin users, only show taxonomies that belong to them
106
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
+		add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
+
109
+		// add the teacher name next to the module term in for admin users
110
+		add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
+
112
+		// remove the default modules  metabox
113
+		add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
+
115
+	} // end constructor
116
+
117
+	/**
118
+	 * Alter a module term slug when a new taxonomy term is created
119
+	 * This will add the creators user name to the slug for uniqueness.
120
+	 *
121
+	 * @since 1.8.0
122
+	 *
123
+	 * @param $term_id
124
+	 * @param $tt_id
125
+	 * @param $taxonomy
126
+	 *
127
+	 * @return void
128
+	 * @deprecated since 1.9.0
129
+	 */
130
+	public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
+
132
+		_deprecated_function('change_module_term_slug', '1.9.0' );
133
+
134
+	}// end add_module_term_group
135
+
136
+	/**
137
+	 * Hook in all meta boxes related tot he modules taxonomy
138
+	 *
139
+	 * @since 1.8.0
140
+	 *
141
+	 * @param string $post_type
142
+	 * @param WP_Post $post
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function modules_metaboxes( $post_type, $post )
147
+	{
148
+		if ('lesson' == $post_type ) {
149
+
150
+			// Remove default taxonomy meta box from Lesson edit screen
151
+			remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
+
153
+			// Add custom meta box to limit module selection to one per lesson
154
+			add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
+		}
156
+
157
+		if( 'course' == $post_type ){
158
+			// Course modules selection metabox
159
+			add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Build content for custom module meta box
165
+	 *
166
+	 * @since 1.8.0
167
+	 * @param  object $post Current post object
168
+	 * @return void
169
+	 */
170
+	public function lesson_module_metabox($post)
171
+	{
172
+
173
+		// Get lesson course
174
+		$lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
+
176
+		$html = '';
177
+
178
+		// Only show module selection if this lesson is part of a course
179
+		if ($lesson_course && $lesson_course > 0) {
180
+
181
+			// Get existing lesson module
182
+			$lesson_module = 0;
183
+			$lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
+				foreach ($lesson_module_list as $single_module) {
186
+					$lesson_module = $single_module->term_id;
187
+					break;
188
+				}
189
+			}
190
+
191
+			// Get the available modules for this lesson's course
192
+			$modules = $this->get_course_modules($lesson_course);
193
+
194
+			// Build the HTML to output
195
+			$html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
+			if (is_array($modules) && count($modules) > 0) {
197
+				$html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
+				$html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
+				foreach ($modules as $module) {
200
+					$html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
+				}
202
+				$html .= '</select>' . "\n";
203
+			} else {
204
+				$course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
+				$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
+			} // End If Statement
207
+
208
+		} else {
209
+			$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
+		} // End If Statement
211
+
212
+		// Output the HTML
213
+		echo $html;
214
+	}
215
+
216
+	/**
217
+	 * Save module to lesson
218
+	 *
219
+	 * @since 1.8.0
220
+	 * @param  integer $post_id ID of post
221
+	 * @return mixed            Post ID on permissions failure, boolean true on success
222
+	 */
223
+	public function save_lesson_module($post_id)
224
+	{
225
+		global $post;
226
+
227
+		// Verify post type and nonce
228
+		if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
+			||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
+			return $post_id;
231
+		}
232
+
233
+		// Check if user has permissions to edit lessons
234
+		$post_type = get_post_type_object($post->post_type);
235
+		if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
+			return $post_id;
237
+		}
238
+
239
+		// Check if user has permissions to edit this specific post
240
+		if (!current_user_can('edit_post', $post_id)) {
241
+			return $post_id;
242
+		}
243
+
244
+		// Cast module ID as an integer if selected, otherwise leave as empty string
245
+		if ( isset( $_POST['lesson_module'] ) ) {
246
+
247
+			if( empty ( $_POST['lesson_module'] ) ){
248
+				wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
+				return true;
250
+			}
251
+
252
+			$module_id = intval( $_POST['lesson_module'] );
253
+
254
+			// Assign lesson to selected module
255
+			wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
+
257
+			// Set default order for lesson inside module
258
+			if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
+				update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
+			}
261
+		}
262
+
263
+		return true;
264
+	}
265
+
266
+	/**
267
+	 * Display course field on new module screen
268
+	 *
269
+	 * @since 1.8.0
270
+	 * @param object $taxonomy Taxonomy object
271
+	 * @return void
272
+	 */
273
+	public function add_module_fields($taxonomy)
274
+	{
275
+		?>
276 276
         <div class="form-field">
277 277
             <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label>
278 278
             <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses"
@@ -281,44 +281,44 @@  discard block
 block discarded – undo
281 281
                 class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span>
282 282
         </div>
283 283
     <?php
284
-    }
285
-
286
-    /**
287
-     * Display course field on module edit screen
288
-     *
289
-     * @since 1.8.0
290
-     * @param  object $module Module term object
291
-     * @return void
292
-     */
293
-    public function edit_module_fields($module)
294
-    {
295
-
296
-        $module_id = $module->term_id;
297
-
298
-        // Get module's existing courses
299
-        $args = array(
300
-            'post_type' => 'course',
301
-            'post_status' => array('publish', 'draft', 'future', 'private'),
302
-            'posts_per_page' => -1,
303
-            'tax_query' => array(
304
-                array(
305
-                    'taxonomy' => $this->taxonomy,
306
-                    'field' => 'id',
307
-                    'terms' => $module_id
308
-                )
309
-            )
310
-        );
311
-        $courses = get_posts($args);
312
-
313
-        //build the defaults array
314
-        $module_courses = array();
315
-        if (isset($courses) && is_array($courses)) {
316
-            foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
-            }
319
-        }
320
-
321
-        ?>
284
+	}
285
+
286
+	/**
287
+	 * Display course field on module edit screen
288
+	 *
289
+	 * @since 1.8.0
290
+	 * @param  object $module Module term object
291
+	 * @return void
292
+	 */
293
+	public function edit_module_fields($module)
294
+	{
295
+
296
+		$module_id = $module->term_id;
297
+
298
+		// Get module's existing courses
299
+		$args = array(
300
+			'post_type' => 'course',
301
+			'post_status' => array('publish', 'draft', 'future', 'private'),
302
+			'posts_per_page' => -1,
303
+			'tax_query' => array(
304
+				array(
305
+					'taxonomy' => $this->taxonomy,
306
+					'field' => 'id',
307
+					'terms' => $module_id
308
+				)
309
+			)
310
+		);
311
+		$courses = get_posts($args);
312
+
313
+		//build the defaults array
314
+		$module_courses = array();
315
+		if (isset($courses) && is_array($courses)) {
316
+			foreach ($courses as $course) {
317
+				$module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
+			}
319
+		}
320
+
321
+		?>
322 322
         <tr class="form-field">
323 323
             <th scope="row" valign="top"><label
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
@@ -335,1399 +335,1399 @@  discard block
 block discarded – undo
335 335
             </td>
336 336
         </tr>
337 337
     <?php
338
-    }
339
-
340
-    /**
341
-     * Save module course on add/edit
342
-     *
343
-     * @since 1.8.0
344
-     * @param  integer $module_id ID of module
345
-     * @return void
346
-     */
347
-    public function save_module_course($module_id)
348
-    {
349
-
350
-        // Get module's existing courses
351
-        $args = array(
352
-            'post_type' => 'course',
353
-            'post_status' => array('publish', 'draft', 'future', 'private'),
354
-            'posts_per_page' => -1,
355
-            'tax_query' => array(
356
-                array(
357
-                    'taxonomy' => $this->taxonomy,
358
-                    'field' => 'id',
359
-                    'terms' => $module_id
360
-                )
361
-            )
362
-        );
363
-        $courses = get_posts($args);
364
-
365
-        // Remove module from existing courses
366
-        if (isset($courses) && is_array($courses)) {
367
-            foreach ($courses as $course) {
368
-                wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
-            }
370
-        }
371
-
372
-        // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
-
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
376
-
377
-            foreach ( $course_ids as $course_id ) {
378
-
379
-                wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
-
381
-            }
382
-        }
383
-    }
384
-
385
-    /**
386
-     * Ajax function to search for courses matching term
387
-     *
388
-     * @since 1.8.0
389
-     * @return void
390
-     */
391
-    public function search_courses_json()
392
-    {
393
-
394
-        // Security check
395
-        check_ajax_referer('search-courses', 'security');
396
-
397
-        // Set content type
398
-        header('Content-Type: application/json; charset=utf-8');
399
-
400
-        // Get user input
401
-        $term = urldecode(stripslashes($_GET['term']));
402
-
403
-        // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
-
407
-        // Set a default if none is given
408
-        $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
-
410
-        // Set up array of results
411
-        $found_courses = array('' => $default);
412
-
413
-        // Fetch results
414
-        $args = array(
415
-            'post_type' => 'course',
416
-            'post_status' => array('publish', 'draft', 'future', 'private'),
417
-            'posts_per_page' => -1,
418
-            'orderby' => 'title',
419
-            's' => $term
420
-        );
421
-        $courses = get_posts($args);
422
-
423
-        // Add results to array
424
-        if ($courses) {
425
-            foreach ($courses as $course) {
426
-                $found_courses[$course->ID] = $course->post_title;
427
-            }
428
-        }
429
-
430
-        // Encode and return results for processing & selection
431
-        echo json_encode($found_courses);
432
-        die();
433
-    }
434
-
435
-    /**
436
-     * display modules on single course pages
437
-     *
438
-     * @since 1.8.0
439
-     * @return void
440
-     */
441
-    public function single_course_modules(){
442
-
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
-        // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
-
447
-            $this->load_course_module_content_template();
448
-
449
-        }
450
-
451
-    } // end single_course_modules
452
-
453
-    public function sensei_course_preview_titles($title, $lesson_id)
454
-    {
455
-        global $post, $current_user;
456
-
457
-        $course_id = $post->ID;
458
-        $title_text = '';
459
-
460
-        if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
463
-                if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
-                    $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
-                    // Remove brackets for display here
466
-                    $title_text = str_replace('(', '', $title_text);
467
-                    $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
469
-                }
470
-                $title .= ' ' . $title_text;
471
-            }
472
-        }
473
-
474
-        return $title;
475
-    }
476
-
477
-    public function module_breadcrumb_link($html, $separator)
478
-    {
479
-        global $post;
480
-        // Lesson
481
-        if (is_singular('lesson')) {
482
-            if (has_term('', $this->taxonomy, $post->ID)) {
483
-                $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
-                }
487
-            }
488
-        }
489
-        // Module
490
-        if (is_tax($this->taxonomy)) {
491
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
-                $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
-            }
495
-        }
496
-        return $html;
497
-    }
498
-
499
-    /**
500
-     * Set lesson archive template to display on module taxonomy archive page
501
-     *
502
-     * @since 1.8.0
503
-     * @param  string $template Default template
504
-     * @return string           Modified template
505
-     */
506
-    public function module_archive_template($template) {
507
-
508
-        if ( ! is_tax($this->taxonomy) ) {
509
-            return $template;
510
-        }
511
-
512
-        $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
514
-
515
-        // locate the template file
516
-        $template = locate_template($find);
517
-        if (!$template) {
518
-
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
520
-
521
-        }
522
-
523
-
524
-        return $template;
525
-    }
526
-
527
-    /**
528
-     * Modify module taxonomy archive query
529
-     *
530
-     * @since 1.8.0
531
-     * @param  object $query The query object passed by reference
532
-     * @return void
533
-     */
534
-    public function module_archive_filter($query)
535
-    {
536
-        if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
-
538
-
539
-            // Limit to lessons only
540
-            $query->set('post_type', 'lesson');
541
-
542
-            // Set order of lessons
543
-            if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
-                $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
546
-                $query->set('orderby', 'meta_value_num date');
547
-            } else {
548
-                $query->set('orderby', 'menu_order');
549
-            }
550
-            $query->set('order', 'ASC');
551
-
552
-            // Limit to specific course if specified
553
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
-                $course_id = intval($_GET['course_id']);
555
-                $meta_query[] = array(
556
-                    'key' => '_lesson_course',
557
-                    'value' => intval($course_id)
558
-                );
559
-                $query->set('meta_query', $meta_query);
560
-            }
561
-
562
-        }
563
-    }
564
-
565
-    /**
566
-     * Modify archive page title
567
-     *
568
-     * @since 1.8.0
569
-     * @param  string $title Default title
570
-     * @return string        Modified title
571
-     */
572
-    public function module_archive_title($title)
573
-    {
574
-        if (is_tax($this->taxonomy)) {
575
-            $title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
-        }
577
-        return $title;
578
-    }
579
-
580
-    /**
581
-     * Display module description on taxonomy archive page
582
-     *
583
-     * @since 1.8.0
584
-     * @return void
585
-     */
586
-    public function module_archive_description()
587
-    {
588
-        if (is_tax($this->taxonomy)) {
589
-
590
-            $module = get_queried_object();
591
-
592
-            $module_progress = false;
593
-            if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
-                global $current_user;
595
-                wp_get_current_user();
596
-                $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
-            }
598
-
599
-            if ($module_progress && $module_progress > 0) {
600
-                $status = __('Completed', 'woothemes-sensei');
601
-                $class = 'completed';
602
-                if ($module_progress < 100) {
603
-                    $status = __('In progress', 'woothemes-sensei');
604
-                    $class = 'in-progress';
605
-                }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
-            }
608
-
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
-        }
611
-    }
612
-
613
-    public function module_archive_body_class($classes)
614
-    {
615
-        if (is_tax($this->taxonomy)) {
616
-            $classes[] = 'module-archive';
617
-        }
618
-        return $classes;
619
-    }
620
-
621
-    /**
622
-     * Display module navigation links on module taxonomy archive page
623
-     *
624
-     * @since 1.8.0
625
-     * @return void
626
-     */
627
-    public function module_navigation_links()
628
-    {
629
-        if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
-
631
-            $queried_module = get_queried_object();
632
-            $course_modules = $this->get_course_modules($_GET['course_id']);
633
-
634
-            $prev_module = false;
635
-            $next_module = false;
636
-            $on_current = false;
637
-            foreach ($course_modules as $module) {
638
-                $this_module = $module;
639
-                if ($on_current) {
640
-                    $next_module = $this_module;
641
-                    break;
642
-                }
643
-                if ($this_module == $queried_module) {
644
-                    $on_current = true;
645
-                } else {
646
-                    $prev_module = $module;
647
-                }
648
-            }
649
-
650
-            ?>
338
+	}
339
+
340
+	/**
341
+	 * Save module course on add/edit
342
+	 *
343
+	 * @since 1.8.0
344
+	 * @param  integer $module_id ID of module
345
+	 * @return void
346
+	 */
347
+	public function save_module_course($module_id)
348
+	{
349
+
350
+		// Get module's existing courses
351
+		$args = array(
352
+			'post_type' => 'course',
353
+			'post_status' => array('publish', 'draft', 'future', 'private'),
354
+			'posts_per_page' => -1,
355
+			'tax_query' => array(
356
+				array(
357
+					'taxonomy' => $this->taxonomy,
358
+					'field' => 'id',
359
+					'terms' => $module_id
360
+				)
361
+			)
362
+		);
363
+		$courses = get_posts($args);
364
+
365
+		// Remove module from existing courses
366
+		if (isset($courses) && is_array($courses)) {
367
+			foreach ($courses as $course) {
368
+				wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
+			}
370
+		}
371
+
372
+		// Add module to selected courses
373
+		if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
+
375
+			$course_ids = explode( ",", $_POST['module_courses'] );
376
+
377
+			foreach ( $course_ids as $course_id ) {
378
+
379
+				wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
+
381
+			}
382
+		}
383
+	}
384
+
385
+	/**
386
+	 * Ajax function to search for courses matching term
387
+	 *
388
+	 * @since 1.8.0
389
+	 * @return void
390
+	 */
391
+	public function search_courses_json()
392
+	{
393
+
394
+		// Security check
395
+		check_ajax_referer('search-courses', 'security');
396
+
397
+		// Set content type
398
+		header('Content-Type: application/json; charset=utf-8');
399
+
400
+		// Get user input
401
+		$term = urldecode(stripslashes($_GET['term']));
402
+
403
+		// Return nothing if term is empty
404
+		if (empty($term))
405
+			die();
406
+
407
+		// Set a default if none is given
408
+		$default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
+
410
+		// Set up array of results
411
+		$found_courses = array('' => $default);
412
+
413
+		// Fetch results
414
+		$args = array(
415
+			'post_type' => 'course',
416
+			'post_status' => array('publish', 'draft', 'future', 'private'),
417
+			'posts_per_page' => -1,
418
+			'orderby' => 'title',
419
+			's' => $term
420
+		);
421
+		$courses = get_posts($args);
422
+
423
+		// Add results to array
424
+		if ($courses) {
425
+			foreach ($courses as $course) {
426
+				$found_courses[$course->ID] = $course->post_title;
427
+			}
428
+		}
429
+
430
+		// Encode and return results for processing & selection
431
+		echo json_encode($found_courses);
432
+		die();
433
+	}
434
+
435
+	/**
436
+	 * display modules on single course pages
437
+	 *
438
+	 * @since 1.8.0
439
+	 * @return void
440
+	 */
441
+	public function single_course_modules(){
442
+
443
+		_deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
+		// only show modules on the course that has modules
445
+		if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
+
447
+			$this->load_course_module_content_template();
448
+
449
+		}
450
+
451
+	} // end single_course_modules
452
+
453
+	public function sensei_course_preview_titles($title, $lesson_id)
454
+	{
455
+		global $post, $current_user;
456
+
457
+		$course_id = $post->ID;
458
+		$title_text = '';
459
+
460
+		if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
+			if (!$is_user_taking_course) {
463
+				if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
+					$title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
+					// Remove brackets for display here
466
+					$title_text = str_replace('(', '', $title_text);
467
+					$title_text = str_replace(')', '', $title_text);
468
+					$title_text = '<span class="preview-label">' . $title_text . '</span>';
469
+				}
470
+				$title .= ' ' . $title_text;
471
+			}
472
+		}
473
+
474
+		return $title;
475
+	}
476
+
477
+	public function module_breadcrumb_link($html, $separator)
478
+	{
479
+		global $post;
480
+		// Lesson
481
+		if (is_singular('lesson')) {
482
+			if (has_term('', $this->taxonomy, $post->ID)) {
483
+				$module = $this->get_lesson_module($post->ID);
484
+				if( $module ) {
485
+					$html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
+				}
487
+			}
488
+		}
489
+		// Module
490
+		if (is_tax($this->taxonomy)) {
491
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
+				$course_id = intval($_GET['course_id']);
493
+				$html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
+			}
495
+		}
496
+		return $html;
497
+	}
498
+
499
+	/**
500
+	 * Set lesson archive template to display on module taxonomy archive page
501
+	 *
502
+	 * @since 1.8.0
503
+	 * @param  string $template Default template
504
+	 * @return string           Modified template
505
+	 */
506
+	public function module_archive_template($template) {
507
+
508
+		if ( ! is_tax($this->taxonomy) ) {
509
+			return $template;
510
+		}
511
+
512
+		$file = 'archive-lesson.php';
513
+		$find = array( $file, Sensei()->template_url . $file );
514
+
515
+		// locate the template file
516
+		$template = locate_template($find);
517
+		if (!$template) {
518
+
519
+			$template = Sensei()->plugin_path() . 'templates/' . $file;
520
+
521
+		}
522
+
523
+
524
+		return $template;
525
+	}
526
+
527
+	/**
528
+	 * Modify module taxonomy archive query
529
+	 *
530
+	 * @since 1.8.0
531
+	 * @param  object $query The query object passed by reference
532
+	 * @return void
533
+	 */
534
+	public function module_archive_filter($query)
535
+	{
536
+		if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
+
538
+
539
+			// Limit to lessons only
540
+			$query->set('post_type', 'lesson');
541
+
542
+			// Set order of lessons
543
+			if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
+				$module_id = $query->queried_object_id;
545
+				$query->set('meta_key', '_order_module_' . $module_id);
546
+				$query->set('orderby', 'meta_value_num date');
547
+			} else {
548
+				$query->set('orderby', 'menu_order');
549
+			}
550
+			$query->set('order', 'ASC');
551
+
552
+			// Limit to specific course if specified
553
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
+				$course_id = intval($_GET['course_id']);
555
+				$meta_query[] = array(
556
+					'key' => '_lesson_course',
557
+					'value' => intval($course_id)
558
+				);
559
+				$query->set('meta_query', $meta_query);
560
+			}
561
+
562
+		}
563
+	}
564
+
565
+	/**
566
+	 * Modify archive page title
567
+	 *
568
+	 * @since 1.8.0
569
+	 * @param  string $title Default title
570
+	 * @return string        Modified title
571
+	 */
572
+	public function module_archive_title($title)
573
+	{
574
+		if (is_tax($this->taxonomy)) {
575
+			$title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
+		}
577
+		return $title;
578
+	}
579
+
580
+	/**
581
+	 * Display module description on taxonomy archive page
582
+	 *
583
+	 * @since 1.8.0
584
+	 * @return void
585
+	 */
586
+	public function module_archive_description()
587
+	{
588
+		if (is_tax($this->taxonomy)) {
589
+
590
+			$module = get_queried_object();
591
+
592
+			$module_progress = false;
593
+			if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
+				global $current_user;
595
+				wp_get_current_user();
596
+				$module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
+			}
598
+
599
+			if ($module_progress && $module_progress > 0) {
600
+				$status = __('Completed', 'woothemes-sensei');
601
+				$class = 'completed';
602
+				if ($module_progress < 100) {
603
+					$status = __('In progress', 'woothemes-sensei');
604
+					$class = 'in-progress';
605
+				}
606
+				echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
+			}
608
+
609
+			echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
+		}
611
+	}
612
+
613
+	public function module_archive_body_class($classes)
614
+	{
615
+		if (is_tax($this->taxonomy)) {
616
+			$classes[] = 'module-archive';
617
+		}
618
+		return $classes;
619
+	}
620
+
621
+	/**
622
+	 * Display module navigation links on module taxonomy archive page
623
+	 *
624
+	 * @since 1.8.0
625
+	 * @return void
626
+	 */
627
+	public function module_navigation_links()
628
+	{
629
+		if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
+
631
+			$queried_module = get_queried_object();
632
+			$course_modules = $this->get_course_modules($_GET['course_id']);
633
+
634
+			$prev_module = false;
635
+			$next_module = false;
636
+			$on_current = false;
637
+			foreach ($course_modules as $module) {
638
+				$this_module = $module;
639
+				if ($on_current) {
640
+					$next_module = $this_module;
641
+					break;
642
+				}
643
+				if ($this_module == $queried_module) {
644
+					$on_current = true;
645
+				} else {
646
+					$prev_module = $module;
647
+				}
648
+			}
649
+
650
+			?>
651 651
             <div id="post-entries" class="post-entries module-navigation fix">
652 652
                 <?php if ($next_module) {
653
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
-                    ?>
653
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
+					?>
655 655
                     <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>"
656 656
                                                 title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?>
657 657
                             <span class="meta-nav"></span></a></div>
658 658
                 <?php } ?>
659 659
                 <?php if ($prev_module) {
660
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
-                    ?>
660
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
+					?>
662 662
                     <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>"
663 663
                                                 title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span
664 664
                                 class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div>
665 665
                 <?php } ?>
666 666
             </div>
667 667
         <?php
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
-     *
674
-     * @since 1.8.0
675
-     * @param  string $status Status of the lesson for the user
676
-     * @param  integer $user_id ID of user
677
-     * @param  integer $lesson_id ID of lesson
678
-     * @return void
679
-     */
680
-    public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
-    {
682
-        $this->save_lesson_module_progress($user_id, $lesson_id);
683
-    }
684
-
685
-    /**
686
-     * Save lesson's module progress for a specific user
687
-     *
688
-     * @since 1.8.0
689
-     * @param  integer $user_id ID of user
690
-     * @param  integer $lesson_id ID of lesson
691
-     * @return void
692
-     */
693
-    public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
-    {
695
-        $module = $this->get_lesson_module($lesson_id);
696
-        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
-        if ($module && $course_id) {
698
-            $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
-        }
700
-    }
701
-
702
-    /**
703
-     * Save progress of module for user
704
-     *
705
-     * @since 1.8.0
706
-     * @return void
707
-     */
708
-    public function save_module_progress()
709
-    {
710
-        if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
-            global $current_user;
712
-            wp_get_current_user();
713
-            $user_id = $current_user->ID;
714
-
715
-            $module = get_queried_object();
716
-
717
-            $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Save module progess for user
723
-     *
724
-     * @since 1.8.0
725
-     *
726
-     * @param  integer $module_id ID of module
727
-     * @param  integer $course_id ID of course
728
-     * @param  integer $user_id ID of user
729
-     * @return void
730
-     */
731
-    public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
-    {
733
-        $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
-
736
-        do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
-    }
738
-
739
-    /**
740
-     * Get module progress for a user
741
-     *
742
-     * @since 1.8.0
743
-     *
744
-     * @param  integer $module_id ID of module
745
-     * @param  integer $course_id ID of course
746
-     * @param  integer $user_id ID of user
747
-     * @return mixed              Module progress percentage on success, false on failure
748
-     */
749
-    public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
-    {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
-        if ($module_progress) {
753
-            return (float)$module_progress;
754
-        }
755
-        return false;
756
-    }
757
-
758
-    /**
759
-     * Calculate module progess for user
760
-     *
761
-     * @since 1.8.0
762
-     *
763
-     * @param  integer $user_id ID of user
764
-     * @param  integer $module_id ID of module
765
-     * @param  integer $course_id ID of course
766
-     * @return integer            Module progress percentage
767
-     */
768
-    public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
-    {
770
-
771
-        $args = array(
772
-            'post_type' => 'lesson',
773
-            'post_status' => 'publish',
774
-            'posts_per_page' => -1,
775
-            'tax_query' => array(
776
-                array(
777
-                    'taxonomy' => $this->taxonomy,
778
-                    'field' => 'id',
779
-                    'terms' => $module_id
780
-                )
781
-            ),
782
-            'meta_query' => array(
783
-                array(
784
-                    'key' => '_lesson_course',
785
-                    'value' => $course_id
786
-                )
787
-            ),
788
-            'fields' => 'ids'
789
-        );
790
-        $lessons = get_posts($args);
791
-
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
-
794
-        $completed = false;
795
-        $lesson_count = 0;
796
-        $completed_count = 0;
797
-        foreach ($lessons as $lesson_id) {
798
-            $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
-            ++$lesson_count;
800
-            if ($completed) {
801
-                ++$completed_count;
802
-            }
803
-        }
804
-        $module_progress = ($completed_count / $lesson_count) * 100;
805
-
806
-        return (float)$module_progress;
807
-    }
808
-
809
-    /**
810
-     * Register admin screen for ordering modules
811
-     *
812
-     * @since 1.8.0
813
-     *
814
-     * @return void
815
-     */
816
-    public function register_modules_admin_menu_items()
817
-    {
818
-        //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
-
821
-        // Regsiter new admin page for module ordering
822
-        $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
-
824
-    }
825
-
826
-    /**
827
-     * Display Module Order screen
828
-     *
829
-     * @since 1.8.0
830
-     *
831
-     * @return void
832
-     */
833
-    public function module_order_screen()
834
-    {
835
-        ?>
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
+	 *
674
+	 * @since 1.8.0
675
+	 * @param  string $status Status of the lesson for the user
676
+	 * @param  integer $user_id ID of user
677
+	 * @param  integer $lesson_id ID of lesson
678
+	 * @return void
679
+	 */
680
+	public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
+	{
682
+		$this->save_lesson_module_progress($user_id, $lesson_id);
683
+	}
684
+
685
+	/**
686
+	 * Save lesson's module progress for a specific user
687
+	 *
688
+	 * @since 1.8.0
689
+	 * @param  integer $user_id ID of user
690
+	 * @param  integer $lesson_id ID of lesson
691
+	 * @return void
692
+	 */
693
+	public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
+	{
695
+		$module = $this->get_lesson_module($lesson_id);
696
+		$course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
+		if ($module && $course_id) {
698
+			$this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
+		}
700
+	}
701
+
702
+	/**
703
+	 * Save progress of module for user
704
+	 *
705
+	 * @since 1.8.0
706
+	 * @return void
707
+	 */
708
+	public function save_module_progress()
709
+	{
710
+		if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
+			global $current_user;
712
+			wp_get_current_user();
713
+			$user_id = $current_user->ID;
714
+
715
+			$module = get_queried_object();
716
+
717
+			$this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Save module progess for user
723
+	 *
724
+	 * @since 1.8.0
725
+	 *
726
+	 * @param  integer $module_id ID of module
727
+	 * @param  integer $course_id ID of course
728
+	 * @param  integer $user_id ID of user
729
+	 * @return void
730
+	 */
731
+	public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
+	{
733
+		$module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
+		update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
+
736
+		do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
+	}
738
+
739
+	/**
740
+	 * Get module progress for a user
741
+	 *
742
+	 * @since 1.8.0
743
+	 *
744
+	 * @param  integer $module_id ID of module
745
+	 * @param  integer $course_id ID of course
746
+	 * @param  integer $user_id ID of user
747
+	 * @return mixed              Module progress percentage on success, false on failure
748
+	 */
749
+	public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
+	{
751
+		$module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
+		if ($module_progress) {
753
+			return (float)$module_progress;
754
+		}
755
+		return false;
756
+	}
757
+
758
+	/**
759
+	 * Calculate module progess for user
760
+	 *
761
+	 * @since 1.8.0
762
+	 *
763
+	 * @param  integer $user_id ID of user
764
+	 * @param  integer $module_id ID of module
765
+	 * @param  integer $course_id ID of course
766
+	 * @return integer            Module progress percentage
767
+	 */
768
+	public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
+	{
770
+
771
+		$args = array(
772
+			'post_type' => 'lesson',
773
+			'post_status' => 'publish',
774
+			'posts_per_page' => -1,
775
+			'tax_query' => array(
776
+				array(
777
+					'taxonomy' => $this->taxonomy,
778
+					'field' => 'id',
779
+					'terms' => $module_id
780
+				)
781
+			),
782
+			'meta_query' => array(
783
+				array(
784
+					'key' => '_lesson_course',
785
+					'value' => $course_id
786
+				)
787
+			),
788
+			'fields' => 'ids'
789
+		);
790
+		$lessons = get_posts($args);
791
+
792
+		if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
+
794
+		$completed = false;
795
+		$lesson_count = 0;
796
+		$completed_count = 0;
797
+		foreach ($lessons as $lesson_id) {
798
+			$completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
+			++$lesson_count;
800
+			if ($completed) {
801
+				++$completed_count;
802
+			}
803
+		}
804
+		$module_progress = ($completed_count / $lesson_count) * 100;
805
+
806
+		return (float)$module_progress;
807
+	}
808
+
809
+	/**
810
+	 * Register admin screen for ordering modules
811
+	 *
812
+	 * @since 1.8.0
813
+	 *
814
+	 * @return void
815
+	 */
816
+	public function register_modules_admin_menu_items()
817
+	{
818
+		//add the modules link under the Course main menu
819
+		add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
+
821
+		// Regsiter new admin page for module ordering
822
+		$hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
+
824
+	}
825
+
826
+	/**
827
+	 * Display Module Order screen
828
+	 *
829
+	 * @since 1.8.0
830
+	 *
831
+	 * @return void
832
+	 */
833
+	public function module_order_screen()
834
+	{
835
+		?>
836 836
         <div id="<?php echo esc_attr($this->order_page_slug); ?>"
837 837
              class="wrap <?php echo esc_attr($this->order_page_slug); ?>">
838 838
         <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php
839 839
 
840
-        $html = '';
841
-
842
-        if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
-            $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
-
845
-            if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
849
-            }
850
-        }
851
-
852
-        $courses = Sensei()->course->get_all_courses();
853
-
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
-
860
-        foreach ($courses as $course) {
861
-            if (has_term('', $this->taxonomy, $course->ID)) {
862
-                $course_id = '';
863
-                if (isset($_GET['course_id'])) {
864
-                    $course_id = intval($_GET['course_id']);
865
-                }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
-            }
868
-        }
869
-
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
873
-
874
-        if (isset($_GET['course_id'])) {
875
-            $course_id = intval($_GET['course_id']);
876
-            if ($course_id > 0) {
877
-                $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
-                if ($modules) {
880
-
881
-                    $order = $this->get_course_module_order($course_id);
882
-
883
-                    $order_string='';
884
-                    if ($order) {
885
-                        $order_string = implode(',', $order);
886
-                    }
887
-
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
890
-                    $count = 0;
891
-                    foreach ($modules as $module) {
892
-                        $count++;
893
-                        $class = $this->taxonomy;
894
-                        if ($count == 1) {
895
-                            $class .= ' first';
896
-                        }
897
-                        if ($count == count($module)) {
898
-                            $class .= ' last';
899
-                        }
900
-                        if ($count % 2 != 0) {
901
-                            $class .= ' alternate';
902
-                        }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
-                    }
905
-                    $html .= '</ul>' . "\n";
906
-
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
-                }
912
-            }
913
-        }
914
-
915
-        echo $html;
916
-
917
-        ?></div><?php
918
-    }
919
-
920
-    /**
921
-     * Add 'Module order' column to courses list table
922
-     *
923
-     * @since 1.8.0
924
-     *
925
-     * @param  array $columns Existing columns
926
-     * @return array           Modifed columns
927
-     */
928
-    public function course_columns($columns = array())
929
-    {
930
-        $columns['module_order'] = __('Module order', 'woothemes-sensei');
931
-        return $columns;
932
-    }
933
-
934
-    /**
935
-     * Load content in 'Module order' column
936
-     *
937
-     * @since 1.8.0
938
-     *
939
-     * @param  string $column Current column name
940
-     * @param  integer $course_id ID of course
941
-     * @return void
942
-     */
943
-    public function course_column_content($column = '', $course_id = 0)
944
-    {
945
-        if ($column == 'module_order') {
946
-            if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
-            }
949
-        }
950
-    }
951
-
952
-    /**
953
-     * Save module order for course
954
-     *
955
-     * @since 1.8.0
956
-     *
957
-     * @param  string $order_string Comma-separated string of module IDs
958
-     * @param  integer $course_id ID of course
959
-     * @return boolean                 True on success, false on failure
960
-     */
961
-    private function save_course_module_order($order_string = '', $course_id = 0)
962
-    {
963
-        if ($order_string && $course_id) {
964
-            $order = explode(',', $order_string);
965
-            update_post_meta(intval($course_id), '_module_order', $order);
966
-            return true;
967
-        }
968
-        return false;
969
-    }
970
-
971
-    /**
972
-     * Get module order for course
973
-     *
974
-     * @since 1.8.0
975
-     *
976
-     * @param  integer $course_id ID of course
977
-     * @return mixed              Module order on success, false if no module order has been saved
978
-     */
979
-    public function get_course_module_order($course_id = 0)
980
-    {
981
-        if ($course_id) {
982
-            $order = get_post_meta(intval($course_id), '_module_order', true);
983
-            return $order;
984
-        }
985
-        return false;
986
-    }
987
-
988
-    /**
989
-     * Modify module taxonomy columns
990
-     *
991
-     * @since 1.8.0
992
-     *
993
-     * @param  array $columns Default columns
994
-     * @return array          Modified columns
995
-     */
996
-    public function taxonomy_column_headings($columns)
997
-    {
998
-
999
-        unset($columns['posts']);
1000
-
1001
-        $columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
-
1003
-        return $columns;
1004
-    }
1005
-
1006
-    /**
1007
-     * Manage content in custom module taxonomy columns
1008
-     *
1009
-     * @since 1.8.0
1010
-     *
1011
-     * @param  string $column_data Default data for column
1012
-     * @param  string $column_name Name of current column
1013
-     * @param  integer $term_id ID of current term
1014
-     * @return string               Modified column data
1015
-     */
1016
-    public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
-    {
1018
-
1019
-        $args = array(
1020
-            'post_status' => 'publish',
1021
-            'posts_per_page' => -1,
1022
-            'tax_query' => array(
1023
-                array(
1024
-                    'taxonomy' => $this->taxonomy,
1025
-                    'field' => 'id',
1026
-                    'terms' => intval($term_id)
1027
-                )
1028
-            )
1029
-        );
1030
-
1031
-        $module = get_term($term_id, $this->taxonomy);
1032
-
1033
-        switch ($column_name) {
1034
-
1035
-            case 'lessons':
1036
-                $args['post_type'] = 'lesson';
1037
-                $lessons = get_posts($args);
1038
-                $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
-                break;
1041
-        }
1042
-
1043
-        return $column_data;
1044
-    }
1045
-
1046
-    /**
1047
-     * Add 'Module' columns to Analysis Lesson Overview table
1048
-     *
1049
-     * @since 1.8.0
1050
-     *
1051
-     * @param  array $columns Default columns
1052
-     * @return array          Modified columns
1053
-     */
1054
-    public function analysis_overview_column_title($columns)
1055
-    {
1056
-
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
-            $new_columns = array();
1059
-            if (is_array($columns) && 0 < count($columns)) {
1060
-                foreach ($columns as $column => $title) {
1061
-                    $new_columns[$column] = $title;
1062
-                    if ($column == 'title') {
1063
-                        $new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
-                    }
1065
-                }
1066
-            }
1067
-
1068
-            if (0 < count($new_columns)) {
1069
-                return $new_columns;
1070
-            }
1071
-        }
1072
-
1073
-        return $columns;
1074
-    }
1075
-
1076
-    /**
1077
-     * Data for 'Module' column Analysis Lesson Overview table
1078
-     *
1079
-     * @since 1.8.0
1080
-     *
1081
-     * @param  array $columns Table column data
1082
-     * @param  WP_Post $lesson
1083
-     * @return array              Updated column data
1084
-     */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1086
-    {
1087
-
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
-            $lesson_module = '';
1090
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
-                foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
-                    break;
1095
-                }
1096
-            }
1097
-
1098
-            $columns['lesson_module'] = $lesson_module;
1099
-        }
1100
-
1101
-        return $columns;
1102
-    }
1103
-
1104
-    /**
1105
-     * Add 'Module' columns to Analysis Course table
1106
-     *
1107
-     * @since 1.8.0
1108
-     *
1109
-     * @param  array $columns Default columns
1110
-     * @return array          Modified columns
1111
-     */
1112
-    public function analysis_course_column_title($columns)
1113
-    {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
-            $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
-        }
1117
-        return $columns;
1118
-    }
1119
-
1120
-    /**
1121
-     * Data for 'Module' column in Analysis Course table
1122
-     *
1123
-     * @since 1.8.0
1124
-     *
1125
-     * @param  array $columns Table column data
1126
-     * @param  WP_Post $lesson
1127
-     * @return array              Updated columns data
1128
-     */
1129
-    public function analysis_course_column_data($columns, $lesson )
1130
-    {
1131
-
1132
-        if ( isset( $_GET['course_id'] ) ) {
1133
-            $lesson_module = '';
1134
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
-                foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
-                    break;
1139
-                }
1140
-            }
1141
-
1142
-            $columns['lesson_module'] = $lesson_module;
1143
-        }
1144
-
1145
-        return $columns;
1146
-    }
1147
-
1148
-    /**
1149
-     * Get module for lesson
1150
-     *
1151
-     * This function also checks if the module still
1152
-     * exists on the course before returning it. Although
1153
-     * the lesson has a module the same module must exist on the
1154
-     * course for it to be valid.
1155
-     *
1156
-     * @since 1.8.0
1157
-     *
1158
-     * @param  integer $lesson_id ID of lesson
1159
-     * @return object             Module taxonomy term object
1160
-     */
1161
-    public function get_lesson_module($lesson_id = 0)
1162
-    {
1163
-        $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1165
-            return false;
1166
-        }
1167
-
1168
-        // get taxonomy terms on this lesson
1169
-        $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
-
1171
-        //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
-            return false;
1174
-        }
1175
-
1176
-       // get the last item in the array there should be only be 1 really.
1177
-       // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1179
-           break;
1180
-       }
1181
-
1182
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
-            return false;
1184
-        }
1185
-
1186
-        $module->url = get_term_link($module, $this->taxonomy);
1187
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
-        if (isset($course_id) && 0 < $course_id) {
1189
-
1190
-            // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
-                return false;
1193
-            }
1194
-
1195
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
-        }
1197
-        return $module;
1198
-
1199
-    }
1200
-
1201
-    /**
1202
-     * Get ordered array of all modules in course
1203
-     *
1204
-     * @since 1.8.0
1205
-     *
1206
-     * @param  integer $course_id ID of course
1207
-     * @return array              Ordered array of module taxonomy term objects
1208
-     */
1209
-    public function get_course_modules($course_id = 0)
1210
-    {
1211
-        $course_id = intval($course_id);
1212
-        if (0 < $course_id) {
1213
-
1214
-            // Get modules for course
1215
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
-
1217
-            // Get custom module order for course
1218
-            $order = $this->get_course_module_order($course_id);
1219
-
1220
-            // Sort by custom order if custom order exists
1221
-            if ($order) {
1222
-                $ordered_modules = array();
1223
-                $unordered_modules = array();
1224
-                foreach ($modules as $module) {
1225
-                    $order_key = array_search($module->term_id, $order);
1226
-                    if ($order_key !== false) {
1227
-                        $ordered_modules[$order_key] = $module;
1228
-                    } else {
1229
-                        $unordered_modules[] = $module;
1230
-                    }
1231
-                }
1232
-
1233
-                // Order modules correctly
1234
-                ksort($ordered_modules);
1235
-
1236
-                // Append modules that have not yet been ordered
1237
-                if (count($unordered_modules) > 0) {
1238
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
-                }
1240
-
1241
-            } else {
1242
-
1243
-                $ordered_modules = $modules;
1244
-
1245
-            }
1246
-
1247
-            return $ordered_modules;
1248
-
1249
-        }
1250
-
1251
-        return false;
1252
-    }
1253
-
1254
-    /**
1255
-     * Load frontend CSS
1256
-     *
1257
-     * @since 1.8.0
1258
-     *
1259
-     * @return void
1260
-     */
1261
-    public function enqueue_styles()
1262
-    {
1263
-
1264
-
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1267
-    }
1268
-
1269
-    /**
1270
-     * Load admin Javascript
1271
-     *
1272
-     * @since 1.8.0
1273
-     *
1274
-     * @return void
1275
-     */
1276
-    public function admin_enqueue_scripts( $hook ) {
1277
-
1278
-        /**
1279
-         * Filter the page hooks where modules admin script can be loaded on.
1280
-         *
1281
-         * @param array $white_listed_pages
1282
-         */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
-            'edit-tags.php',
1285
-            'course_page_module-order',
1286
-            'post-new.php',
1287
-            'post.php'
1288
-        ) );
1289
-
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
-            return;
1292
-        }
1293
-
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
-
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1299
-
1300
-        // localized module data
1301
-        $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
-        );
1305
-
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
-    }
1308
-
1309
-    /**
1310
-     * Load admin CSS
1311
-     *
1312
-     * @since 1.8.0
1313
-     *
1314
-     * @return void
1315
-     */
1316
-    public function admin_enqueue_styles() {
1317
-
1318
-
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1321
-
1322
-    }
1323
-
1324
-    /**
1325
-     * Show the title modules on the single course template.
1326
-     *
1327
-     * Function is hooked into sensei_single_course_modules_before.
1328
-     *
1329
-     * @since 1.8.0
1330
-     * @return void
1331
-     */
1332
-    public function course_modules_title( ) {
1333
-
1334
-       if( sensei_module_has_lessons() ){
1335
-
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
-
1338
-        }
1339
-
1340
-    }
1341
-
1342
-    /**
1343
-     * Display the single course modules content this will only show
1344
-     * if the course has modules.
1345
-     *
1346
-     * @since 1.8.0
1347
-     * @return void
1348
-     */
1349
-    public function load_course_module_content_template(){
1350
-
1351
-        // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1354
-
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
-            return;
1357
-
1358
-        }
1359
-
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1361
-
1362
-    } // end course_module_content
1363
-
1364
-    /**
1365
-     * Returns all lessons for the given module ID
1366
-     *
1367
-     * @since 1.8.0
1368
-     *
1369
-     * @param $course_id
1370
-     * @param $term_id
1371
-     * @return array $lessons
1372
-     */
1373
-    public function get_lessons( $course_id , $term_id ){
1374
-
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
840
+		$html = '';
841
+
842
+		if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
+			$ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
+
845
+			if ($ordered) {
846
+				$html .= '<div class="updated fade">' . "\n";
847
+				$html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
+				$html .= '</div>' . "\n";
849
+			}
850
+		}
851
+
852
+		$courses = Sensei()->course->get_all_courses();
853
+
854
+		$html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
+		$html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
+		$html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
+		$html .= '<select id="module-order-course" name="course_id">' . "\n";
858
+		$html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
+
860
+		foreach ($courses as $course) {
861
+			if (has_term('', $this->taxonomy, $course->ID)) {
862
+				$course_id = '';
863
+				if (isset($_GET['course_id'])) {
864
+					$course_id = intval($_GET['course_id']);
865
+				}
866
+				$html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
+			}
868
+		}
869
+
870
+		$html .= '</select>' . "\n";
871
+		$html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
+		$html .= '</form>' . "\n";
873
+
874
+		if (isset($_GET['course_id'])) {
875
+			$course_id = intval($_GET['course_id']);
876
+			if ($course_id > 0) {
877
+				$modules = $this->get_course_modules($course_id);
878
+				$modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
+				if ($modules) {
880
+
881
+					$order = $this->get_course_module_order($course_id);
882
+
883
+					$order_string='';
884
+					if ($order) {
885
+						$order_string = implode(',', $order);
886
+					}
887
+
888
+					$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
+					$html .= '<ul class="sortable-module-list">' . "\n";
890
+					$count = 0;
891
+					foreach ($modules as $module) {
892
+						$count++;
893
+						$class = $this->taxonomy;
894
+						if ($count == 1) {
895
+							$class .= ' first';
896
+						}
897
+						if ($count == count($module)) {
898
+							$class .= ' last';
899
+						}
900
+						if ($count % 2 != 0) {
901
+							$class .= ' alternate';
902
+						}
903
+						$html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
+					}
905
+					$html .= '</ul>' . "\n";
906
+
907
+					$html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
+					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
+					$html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
+					$html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
+				}
912
+			}
913
+		}
914
+
915
+		echo $html;
916
+
917
+		?></div><?php
918
+	}
919
+
920
+	/**
921
+	 * Add 'Module order' column to courses list table
922
+	 *
923
+	 * @since 1.8.0
924
+	 *
925
+	 * @param  array $columns Existing columns
926
+	 * @return array           Modifed columns
927
+	 */
928
+	public function course_columns($columns = array())
929
+	{
930
+		$columns['module_order'] = __('Module order', 'woothemes-sensei');
931
+		return $columns;
932
+	}
933
+
934
+	/**
935
+	 * Load content in 'Module order' column
936
+	 *
937
+	 * @since 1.8.0
938
+	 *
939
+	 * @param  string $column Current column name
940
+	 * @param  integer $course_id ID of course
941
+	 * @return void
942
+	 */
943
+	public function course_column_content($column = '', $course_id = 0)
944
+	{
945
+		if ($column == 'module_order') {
946
+			if (has_term('', $this->taxonomy, $course_id)) {
947
+				echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
+			}
949
+		}
950
+	}
951
+
952
+	/**
953
+	 * Save module order for course
954
+	 *
955
+	 * @since 1.8.0
956
+	 *
957
+	 * @param  string $order_string Comma-separated string of module IDs
958
+	 * @param  integer $course_id ID of course
959
+	 * @return boolean                 True on success, false on failure
960
+	 */
961
+	private function save_course_module_order($order_string = '', $course_id = 0)
962
+	{
963
+		if ($order_string && $course_id) {
964
+			$order = explode(',', $order_string);
965
+			update_post_meta(intval($course_id), '_module_order', $order);
966
+			return true;
967
+		}
968
+		return false;
969
+	}
970
+
971
+	/**
972
+	 * Get module order for course
973
+	 *
974
+	 * @since 1.8.0
975
+	 *
976
+	 * @param  integer $course_id ID of course
977
+	 * @return mixed              Module order on success, false if no module order has been saved
978
+	 */
979
+	public function get_course_module_order($course_id = 0)
980
+	{
981
+		if ($course_id) {
982
+			$order = get_post_meta(intval($course_id), '_module_order', true);
983
+			return $order;
984
+		}
985
+		return false;
986
+	}
987
+
988
+	/**
989
+	 * Modify module taxonomy columns
990
+	 *
991
+	 * @since 1.8.0
992
+	 *
993
+	 * @param  array $columns Default columns
994
+	 * @return array          Modified columns
995
+	 */
996
+	public function taxonomy_column_headings($columns)
997
+	{
998
+
999
+		unset($columns['posts']);
1000
+
1001
+		$columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
+
1003
+		return $columns;
1004
+	}
1005
+
1006
+	/**
1007
+	 * Manage content in custom module taxonomy columns
1008
+	 *
1009
+	 * @since 1.8.0
1010
+	 *
1011
+	 * @param  string $column_data Default data for column
1012
+	 * @param  string $column_name Name of current column
1013
+	 * @param  integer $term_id ID of current term
1014
+	 * @return string               Modified column data
1015
+	 */
1016
+	public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
+	{
1018
+
1019
+		$args = array(
1020
+			'post_status' => 'publish',
1021
+			'posts_per_page' => -1,
1022
+			'tax_query' => array(
1023
+				array(
1024
+					'taxonomy' => $this->taxonomy,
1025
+					'field' => 'id',
1026
+					'terms' => intval($term_id)
1027
+				)
1028
+			)
1029
+		);
1030
+
1031
+		$module = get_term($term_id, $this->taxonomy);
1032
+
1033
+		switch ($column_name) {
1034
+
1035
+			case 'lessons':
1036
+				$args['post_type'] = 'lesson';
1037
+				$lessons = get_posts($args);
1038
+				$total_lessons = count($lessons);
1039
+				$column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
+				break;
1041
+		}
1042
+
1043
+		return $column_data;
1044
+	}
1045
+
1046
+	/**
1047
+	 * Add 'Module' columns to Analysis Lesson Overview table
1048
+	 *
1049
+	 * @since 1.8.0
1050
+	 *
1051
+	 * @param  array $columns Default columns
1052
+	 * @return array          Modified columns
1053
+	 */
1054
+	public function analysis_overview_column_title($columns)
1055
+	{
1056
+
1057
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
+			$new_columns = array();
1059
+			if (is_array($columns) && 0 < count($columns)) {
1060
+				foreach ($columns as $column => $title) {
1061
+					$new_columns[$column] = $title;
1062
+					if ($column == 'title') {
1063
+						$new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
+					}
1065
+				}
1066
+			}
1067
+
1068
+			if (0 < count($new_columns)) {
1069
+				return $new_columns;
1070
+			}
1071
+		}
1072
+
1073
+		return $columns;
1074
+	}
1075
+
1076
+	/**
1077
+	 * Data for 'Module' column Analysis Lesson Overview table
1078
+	 *
1079
+	 * @since 1.8.0
1080
+	 *
1081
+	 * @param  array $columns Table column data
1082
+	 * @param  WP_Post $lesson
1083
+	 * @return array              Updated column data
1084
+	 */
1085
+	public function analysis_overview_column_data($columns, $lesson )
1086
+	{
1087
+
1088
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
+			$lesson_module = '';
1090
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
+				foreach ($lesson_module_list as $single_module) {
1093
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
+					break;
1095
+				}
1096
+			}
1097
+
1098
+			$columns['lesson_module'] = $lesson_module;
1099
+		}
1100
+
1101
+		return $columns;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Add 'Module' columns to Analysis Course table
1106
+	 *
1107
+	 * @since 1.8.0
1108
+	 *
1109
+	 * @param  array $columns Default columns
1110
+	 * @return array          Modified columns
1111
+	 */
1112
+	public function analysis_course_column_title($columns)
1113
+	{
1114
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
+			$columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
+		}
1117
+		return $columns;
1118
+	}
1119
+
1120
+	/**
1121
+	 * Data for 'Module' column in Analysis Course table
1122
+	 *
1123
+	 * @since 1.8.0
1124
+	 *
1125
+	 * @param  array $columns Table column data
1126
+	 * @param  WP_Post $lesson
1127
+	 * @return array              Updated columns data
1128
+	 */
1129
+	public function analysis_course_column_data($columns, $lesson )
1130
+	{
1131
+
1132
+		if ( isset( $_GET['course_id'] ) ) {
1133
+			$lesson_module = '';
1134
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
+				foreach ($lesson_module_list as $single_module) {
1137
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
+					break;
1139
+				}
1140
+			}
1141
+
1142
+			$columns['lesson_module'] = $lesson_module;
1143
+		}
1144
+
1145
+		return $columns;
1146
+	}
1147
+
1148
+	/**
1149
+	 * Get module for lesson
1150
+	 *
1151
+	 * This function also checks if the module still
1152
+	 * exists on the course before returning it. Although
1153
+	 * the lesson has a module the same module must exist on the
1154
+	 * course for it to be valid.
1155
+	 *
1156
+	 * @since 1.8.0
1157
+	 *
1158
+	 * @param  integer $lesson_id ID of lesson
1159
+	 * @return object             Module taxonomy term object
1160
+	 */
1161
+	public function get_lesson_module($lesson_id = 0)
1162
+	{
1163
+		$lesson_id = intval($lesson_id);
1164
+		if ( ! ( intval( $lesson_id > 0) ) ) {
1165
+			return false;
1166
+		}
1167
+
1168
+		// get taxonomy terms on this lesson
1169
+		$modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
+
1171
+		//check if error returned
1172
+		if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
+			return false;
1174
+		}
1175
+
1176
+	   // get the last item in the array there should be only be 1 really.
1177
+	   // this method works for all php versions.
1178
+	   foreach( $modules as $module ){
1179
+		   break;
1180
+	   }
1181
+
1182
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
+			return false;
1184
+		}
1185
+
1186
+		$module->url = get_term_link($module, $this->taxonomy);
1187
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
+		if (isset($course_id) && 0 < $course_id) {
1189
+
1190
+			// the course should contain the same module taxonomy term for this to be valid
1191
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
+				return false;
1193
+			}
1194
+
1195
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
+		}
1197
+		return $module;
1198
+
1199
+	}
1200
+
1201
+	/**
1202
+	 * Get ordered array of all modules in course
1203
+	 *
1204
+	 * @since 1.8.0
1205
+	 *
1206
+	 * @param  integer $course_id ID of course
1207
+	 * @return array              Ordered array of module taxonomy term objects
1208
+	 */
1209
+	public function get_course_modules($course_id = 0)
1210
+	{
1211
+		$course_id = intval($course_id);
1212
+		if (0 < $course_id) {
1213
+
1214
+			// Get modules for course
1215
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
+
1217
+			// Get custom module order for course
1218
+			$order = $this->get_course_module_order($course_id);
1219
+
1220
+			// Sort by custom order if custom order exists
1221
+			if ($order) {
1222
+				$ordered_modules = array();
1223
+				$unordered_modules = array();
1224
+				foreach ($modules as $module) {
1225
+					$order_key = array_search($module->term_id, $order);
1226
+					if ($order_key !== false) {
1227
+						$ordered_modules[$order_key] = $module;
1228
+					} else {
1229
+						$unordered_modules[] = $module;
1230
+					}
1231
+				}
1232
+
1233
+				// Order modules correctly
1234
+				ksort($ordered_modules);
1235
+
1236
+				// Append modules that have not yet been ordered
1237
+				if (count($unordered_modules) > 0) {
1238
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
+				}
1240
+
1241
+			} else {
1242
+
1243
+				$ordered_modules = $modules;
1244
+
1245
+			}
1246
+
1247
+			return $ordered_modules;
1248
+
1249
+		}
1250
+
1251
+		return false;
1252
+	}
1253
+
1254
+	/**
1255
+	 * Load frontend CSS
1256
+	 *
1257
+	 * @since 1.8.0
1258
+	 *
1259
+	 * @return void
1260
+	 */
1261
+	public function enqueue_styles()
1262
+	{
1263
+
1264
+
1265
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
+		wp_enqueue_style($this->taxonomy . '-frontend');
1267
+	}
1268
+
1269
+	/**
1270
+	 * Load admin Javascript
1271
+	 *
1272
+	 * @since 1.8.0
1273
+	 *
1274
+	 * @return void
1275
+	 */
1276
+	public function admin_enqueue_scripts( $hook ) {
1277
+
1278
+		/**
1279
+		 * Filter the page hooks where modules admin script can be loaded on.
1280
+		 *
1281
+		 * @param array $white_listed_pages
1282
+		 */
1283
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1284
+			'edit-tags.php',
1285
+			'course_page_module-order',
1286
+			'post-new.php',
1287
+			'post.php'
1288
+		) );
1289
+
1290
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1291
+			return;
1292
+		}
1293
+
1294
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1295
+
1296
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
+		wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1299
+
1300
+		// localized module data
1301
+		$localize_modulesAdmin = array(
1302
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1304
+		);
1305
+
1306
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1307
+	}
1308
+
1309
+	/**
1310
+	 * Load admin CSS
1311
+	 *
1312
+	 * @since 1.8.0
1313
+	 *
1314
+	 * @return void
1315
+	 */
1316
+	public function admin_enqueue_styles() {
1317
+
1318
+
1319
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
+		wp_enqueue_style($this->taxonomy . '-sortable');
1321
+
1322
+	}
1323
+
1324
+	/**
1325
+	 * Show the title modules on the single course template.
1326
+	 *
1327
+	 * Function is hooked into sensei_single_course_modules_before.
1328
+	 *
1329
+	 * @since 1.8.0
1330
+	 * @return void
1331
+	 */
1332
+	public function course_modules_title( ) {
1333
+
1334
+	   if( sensei_module_has_lessons() ){
1335
+
1336
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1337
+
1338
+		}
1339
+
1340
+	}
1341
+
1342
+	/**
1343
+	 * Display the single course modules content this will only show
1344
+	 * if the course has modules.
1345
+	 *
1346
+	 * @since 1.8.0
1347
+	 * @return void
1348
+	 */
1349
+	public function load_course_module_content_template(){
1350
+
1351
+		// load backwards compatible template name if it exists in the users theme
1352
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
+		if( $located_template ){
1354
+
1355
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1356
+			return;
1357
+
1358
+		}
1359
+
1360
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1361
+
1362
+	} // end course_module_content
1363
+
1364
+	/**
1365
+	 * Returns all lessons for the given module ID
1366
+	 *
1367
+	 * @since 1.8.0
1368
+	 *
1369
+	 * @param $course_id
1370
+	 * @param $term_id
1371
+	 * @return array $lessons
1372
+	 */
1373
+	public function get_lessons( $course_id , $term_id ){
1374
+
1375
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+		if( isset( $lesson_query->posts ) ){
1378 1378
 
1379
-            return $lesson_query->posts;
1379
+			return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+		}else{
1382 1382
 
1383
-            return array();
1383
+			return array();
1384 1384
 
1385
-        }
1385
+		}
1386 1386
 
1387
-    } // end get lessons
1387
+	} // end get lessons
1388 1388
 
1389
-    /**
1390
-     * Returns all lessons for the given module ID
1391
-     *
1392
-     * @since 1.8.0
1393
-     *
1394
-     * @param $course_id
1395
-     * @param $term_id
1396
-     * @return WP_Query $lessons_query
1397
-     */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1399
-
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1401
-
1402
-            return array();
1403
-
1404
-        }
1405
-
1406
-        $args = array(
1407
-            'post_type' => 'lesson',
1408
-            'post_status' => 'publish',
1409
-            'posts_per_page' => -1,
1410
-            'meta_query' => array(
1411
-                array(
1412
-                    'key' => '_lesson_course',
1413
-                    'value' => intval($course_id),
1414
-                    'compare' => '='
1415
-                )
1416
-            ),
1417
-            'tax_query' => array(
1418
-                array(
1419
-                    'taxonomy' => 'module',
1420
-                    'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1422
-                )
1423
-            ),
1424
-            'orderby' => 'menu_order',
1425
-            'order' => 'ASC',
1426
-            'suppress_filters' => 0
1427
-        );
1428
-
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1431
-            $args['orderby'] = 'meta_value_num date';
1432
-        }
1433
-
1434
-        $lessons_query = new WP_Query( $args );
1435
-
1436
-        return $lessons_query;
1437
-
1438
-    } // end get lessons
1439
-
1440
-    /**
1441
-     * Find the lesson in the given course that doesn't belong
1442
-     * to any of the courses modules
1443
-     *
1444
-     *
1445
-     * @param $course_id
1446
-     *
1447
-     * @return array $non_module_lessons
1448
-     */
1449
-    public function get_none_module_lessons( $course_id ){
1450
-
1451
-        $non_module_lessons = array();
1452
-
1453
-        //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
-
1456
-            return $non_module_lessons;
1457
-        }
1458
-
1459
-        //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
-
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
-
1464
-        }
1465
-
1466
-        // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1468
-
1469
-        //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
-
1472
-            return  Sensei()->course->course_lessons( $course_id );
1473
-
1474
-        }
1475
-
1476
-        $terms = array();
1477
-        foreach( $course_modules as $module ){
1478
-
1479
-            array_push( $terms ,  $module->term_id );
1480
-
1481
-        }
1482
-
1483
-        $args = array(
1484
-            'post_type' => 'lesson',
1485
-            'post_status' => 'publish',
1486
-            'posts_per_page' => -1,
1487
-            'meta_query' => array(
1488
-                array(
1489
-                    'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1491
-                    'compare' => '='
1492
-                )
1493
-            ),
1494
-            'tax_query' => array(
1495
-                array(
1496
-                    'taxonomy' => 'module',
1497
-                    'field' => 'id',
1498
-                    'terms' =>  $terms,
1499
-                    'operator' => 'NOT IN'
1500
-                )
1501
-            ),
1502
-            'orderby' => 'menu_order',
1503
-            'order' => 'ASC',
1504
-            'suppress_filters' => 0
1505
-        );
1506
-
1507
-        $wp_lessons_query = new WP_Query( $args );
1508
-
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
-            $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
-        }
1513
-
1514
-        return $non_module_lessons;
1515
-    } // end get_none_module_lessons
1516
-
1517
-    /**
1518
-     * Register the modules taxonomy
1519
-     *
1520
-     * @since 1.8.0
1521
-     */
1522
-    public function setup_modules_taxonomy(){
1523
-
1524
-        $labels = array(
1525
-            'name' => __('Modules', 'woothemes-sensei'),
1526
-            'singular_name' => __('Module', 'woothemes-sensei'),
1527
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1529
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1533
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1536
-        );
1537
-
1538
-        /**
1539
-         * Filter to alter the Sensei Modules rewrite slug
1540
-         *
1541
-         * @since 1.8.0
1542
-         * @param string default 'modules'
1543
-         */
1544
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
-
1546
-        $args = array(
1547
-            'public' => true,
1548
-            'hierarchical' => true,
1549
-            'show_admin_column' => true,
1550
-            'capabilities' => array(
1551
-                'manage_terms' => 'manage_categories',
1552
-                'edit_terms'   => 'edit_courses',
1553
-                'delete_terms' => 'manage_categories',
1554
-                'assign_terms' => 'edit_courses'
1555
-            ),
1556
-            'show_in_nav_menus' => false,
1557
-            'show_in_quick_edit' => false,
1558
-            'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
-            'labels' => $labels
1561
-        );
1562
-
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
-
1565
-    }// end setup_modules_taxonomy
1566
-
1567
-    /**
1568
-     * When the wants to edit the lesson modules redirect them to the course modules.
1569
-     *
1570
-     * This function is hooked into the admin_menu
1571
-     *
1572
-     * @since 1.8.0
1573
-     * @return void
1574
-     */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1576
-
1577
-        global $typenow , $taxnow;
1578
-
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
-        }
1582
-
1583
-    }// end redirect to course taxonomy
1584
-
1585
-    /**
1586
-     * Completely remove the module menu item under lessons.
1587
-     *
1588
-     * This function is hooked into the admin_menu
1589
-     *
1590
-     * @since 1.8.0
1591
-     * @return void
1592
-     */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1594
-        global $submenu;
1595
-
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
-            return; // exit
1598
-        }
1599
-
1600
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1602
-
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
-            }
1606
-        }
1607
-
1608
-    }// end remove lesson module tax
1609
-
1610
-    /**
1611
-     * Completely remove the second modules under courses
1612
-     *
1613
-     * This function is hooked into the admin_menu
1614
-     *
1615
-     * @since 1.8.0
1616
-     * @return void
1617
-     */
1618
-    public function remove_courses_menu_model_taxonomy(){
1619
-        global $submenu;
1620
-
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
-            return; // exit
1623
-        }
1624
-
1625
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1627
-
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
-            }
1631
-        }
1632
-
1633
-    }// end remove courses module tax
1634
-
1635
-    /**
1636
-     * Determine the author of a module term term by looking at
1637
-     * the prefixed author id. This function will query the full term object.
1638
-     * Will return the admin user author could not be determined.
1639
-     *
1640
-     * @since 1.8.0
1641
-     *
1642
-     * @param string $term_name
1643
-     * @return array $owners { type WP_User }. Empty array if none if found.
1644
-     */
1645
-    public static function get_term_authors( $term_name ){
1646
-
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
-
1649
-        $owners = array();
1650
-        if( empty( $terms ) ){
1651
-
1652
-            return $owners;
1389
+	/**
1390
+	 * Returns all lessons for the given module ID
1391
+	 *
1392
+	 * @since 1.8.0
1393
+	 *
1394
+	 * @param $course_id
1395
+	 * @param $term_id
1396
+	 * @return WP_Query $lessons_query
1397
+	 */
1398
+	public function get_lessons_query( $course_id , $term_id ){
1399
+
1400
+		if( empty( $term_id ) || empty( $course_id ) ){
1401
+
1402
+			return array();
1403
+
1404
+		}
1405
+
1406
+		$args = array(
1407
+			'post_type' => 'lesson',
1408
+			'post_status' => 'publish',
1409
+			'posts_per_page' => -1,
1410
+			'meta_query' => array(
1411
+				array(
1412
+					'key' => '_lesson_course',
1413
+					'value' => intval($course_id),
1414
+					'compare' => '='
1415
+				)
1416
+			),
1417
+			'tax_query' => array(
1418
+				array(
1419
+					'taxonomy' => 'module',
1420
+					'field' => 'id',
1421
+					'terms' => intval( $term_id )
1422
+				)
1423
+			),
1424
+			'orderby' => 'menu_order',
1425
+			'order' => 'ASC',
1426
+			'suppress_filters' => 0
1427
+		);
1428
+
1429
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1431
+			$args['orderby'] = 'meta_value_num date';
1432
+		}
1433
+
1434
+		$lessons_query = new WP_Query( $args );
1435
+
1436
+		return $lessons_query;
1437
+
1438
+	} // end get lessons
1439
+
1440
+	/**
1441
+	 * Find the lesson in the given course that doesn't belong
1442
+	 * to any of the courses modules
1443
+	 *
1444
+	 *
1445
+	 * @param $course_id
1446
+	 *
1447
+	 * @return array $non_module_lessons
1448
+	 */
1449
+	public function get_none_module_lessons( $course_id ){
1450
+
1451
+		$non_module_lessons = array();
1452
+
1453
+		//exit if there is no course id passed in
1454
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1455
+
1456
+			return $non_module_lessons;
1457
+		}
1458
+
1459
+		//save some time and check if we already have the saved
1460
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1461
+
1462
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1463
+
1464
+		}
1465
+
1466
+		// create terms array which must be excluded from other arrays
1467
+		$course_modules = $this->get_course_modules( $course_id );
1468
+
1469
+		//exit if there are no module on this course
1470
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1471
+
1472
+			return  Sensei()->course->course_lessons( $course_id );
1473
+
1474
+		}
1475
+
1476
+		$terms = array();
1477
+		foreach( $course_modules as $module ){
1478
+
1479
+			array_push( $terms ,  $module->term_id );
1480
+
1481
+		}
1482
+
1483
+		$args = array(
1484
+			'post_type' => 'lesson',
1485
+			'post_status' => 'publish',
1486
+			'posts_per_page' => -1,
1487
+			'meta_query' => array(
1488
+				array(
1489
+					'key' => '_lesson_course',
1490
+					'value' => intval( $course_id ),
1491
+					'compare' => '='
1492
+				)
1493
+			),
1494
+			'tax_query' => array(
1495
+				array(
1496
+					'taxonomy' => 'module',
1497
+					'field' => 'id',
1498
+					'terms' =>  $terms,
1499
+					'operator' => 'NOT IN'
1500
+				)
1501
+			),
1502
+			'orderby' => 'menu_order',
1503
+			'order' => 'ASC',
1504
+			'suppress_filters' => 0
1505
+		);
1506
+
1507
+		$wp_lessons_query = new WP_Query( $args );
1508
+
1509
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1510
+			$non_module_lessons = $wp_lessons_query->get_posts();
1511
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1512
+		}
1513
+
1514
+		return $non_module_lessons;
1515
+	} // end get_none_module_lessons
1516
+
1517
+	/**
1518
+	 * Register the modules taxonomy
1519
+	 *
1520
+	 * @since 1.8.0
1521
+	 */
1522
+	public function setup_modules_taxonomy(){
1523
+
1524
+		$labels = array(
1525
+			'name' => __('Modules', 'woothemes-sensei'),
1526
+			'singular_name' => __('Module', 'woothemes-sensei'),
1527
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1528
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1529
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1530
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1531
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1532
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1533
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1534
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1535
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1536
+		);
1537
+
1538
+		/**
1539
+		 * Filter to alter the Sensei Modules rewrite slug
1540
+		 *
1541
+		 * @since 1.8.0
1542
+		 * @param string default 'modules'
1543
+		 */
1544
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1545
+
1546
+		$args = array(
1547
+			'public' => true,
1548
+			'hierarchical' => true,
1549
+			'show_admin_column' => true,
1550
+			'capabilities' => array(
1551
+				'manage_terms' => 'manage_categories',
1552
+				'edit_terms'   => 'edit_courses',
1553
+				'delete_terms' => 'manage_categories',
1554
+				'assign_terms' => 'edit_courses'
1555
+			),
1556
+			'show_in_nav_menus' => false,
1557
+			'show_in_quick_edit' => false,
1558
+			'show_ui' => true,
1559
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1560
+			'labels' => $labels
1561
+		);
1562
+
1563
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1564
+
1565
+	}// end setup_modules_taxonomy
1566
+
1567
+	/**
1568
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1569
+	 *
1570
+	 * This function is hooked into the admin_menu
1571
+	 *
1572
+	 * @since 1.8.0
1573
+	 * @return void
1574
+	 */
1575
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1576
+
1577
+		global $typenow , $taxnow;
1578
+
1579
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1581
+		}
1582
+
1583
+	}// end redirect to course taxonomy
1584
+
1585
+	/**
1586
+	 * Completely remove the module menu item under lessons.
1587
+	 *
1588
+	 * This function is hooked into the admin_menu
1589
+	 *
1590
+	 * @since 1.8.0
1591
+	 * @return void
1592
+	 */
1593
+	public function remove_lessons_menu_model_taxonomy(){
1594
+		global $submenu;
1595
+
1596
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1597
+			return; // exit
1598
+		}
1599
+
1600
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
+		foreach( $lesson_main_menu as $index => $sub_item ){
1602
+
1603
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1605
+			}
1606
+		}
1607
+
1608
+	}// end remove lesson module tax
1609
+
1610
+	/**
1611
+	 * Completely remove the second modules under courses
1612
+	 *
1613
+	 * This function is hooked into the admin_menu
1614
+	 *
1615
+	 * @since 1.8.0
1616
+	 * @return void
1617
+	 */
1618
+	public function remove_courses_menu_model_taxonomy(){
1619
+		global $submenu;
1620
+
1621
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1622
+			return; // exit
1623
+		}
1624
+
1625
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1626
+		foreach( $course_main_menu as $index => $sub_item ){
1627
+
1628
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1630
+			}
1631
+		}
1632
+
1633
+	}// end remove courses module tax
1634
+
1635
+	/**
1636
+	 * Determine the author of a module term term by looking at
1637
+	 * the prefixed author id. This function will query the full term object.
1638
+	 * Will return the admin user author could not be determined.
1639
+	 *
1640
+	 * @since 1.8.0
1641
+	 *
1642
+	 * @param string $term_name
1643
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1644
+	 */
1645
+	public static function get_term_authors( $term_name ){
1646
+
1647
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1648
+
1649
+		$owners = array();
1650
+		if( empty( $terms ) ){
1651
+
1652
+			return $owners;
1653 1653
 
1654
-        }
1654
+		}
1655 1655
 
1656
-        // setup the admin user
1656
+		// setup the admin user
1657 1657
 
1658 1658
 
1659
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1659
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
+		foreach( $terms as $term){
1661
+			if( $term->name == $term_name ){
1662 1662
 
1663
-                // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1663
+				// look for the author in the slug
1664
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1665 1665
 
1666
-            }// end if term name
1666
+			}// end if term name
1667 1667
 
1668
-        } // end for each
1668
+		} // end for each
1669 1669
 
1670
-        return $owners;
1670
+		return $owners;
1671 1671
 
1672
-    }// end get_term_author
1672
+	}// end get_term_author
1673 1673
 
1674
-    /**
1675
-     * Looks at a term slug and figures out
1676
-     * which author created the slug. The author was
1677
-     * appended when the user saved the module term in the course edit
1678
-     * screen.
1679
-     *
1680
-     * @since 1.8.0
1681
-     *
1682
-     * @param $slug
1683
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
-     */
1685
-    public static function get_term_author( $slug='' ){
1674
+	/**
1675
+	 * Looks at a term slug and figures out
1676
+	 * which author created the slug. The author was
1677
+	 * appended when the user saved the module term in the course edit
1678
+	 * screen.
1679
+	 *
1680
+	 * @since 1.8.0
1681
+	 *
1682
+	 * @param $slug
1683
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684
+	 */
1685
+	public static function get_term_author( $slug='' ){
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+		if( empty( $slug ) ){
1690 1690
 
1691
-            return $term_owner;
1691
+			return $term_owner;
1692 1692
 
1693
-        }
1693
+		}
1694 1694
 
1695
-        // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1695
+		// look for the author in the slug
1696
+		$slug_parts = explode( '-', $slug );
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+		if( count( $slug_parts ) > 1 ){
1699 1699
 
1700
-            // get the user data
1701
-            $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1700
+			// get the user data
1701
+			$possible_user_id = $slug_parts[0];
1702
+			$author = get_userdata( $possible_user_id );
1703 1703
 
1704
-            // if the user doesnt exist for the first part of the slug
1705
-            // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1704
+			// if the user doesnt exist for the first part of the slug
1705
+			// then this slug was also created by admin
1706
+			if( is_a( $author, 'WP_User' ) ){
1707 1707
 
1708
-                $term_owner =  $author;
1708
+				$term_owner =  $author;
1709 1709
 
1710
-            }
1711
-        }
1710
+			}
1711
+		}
1712 1712
 
1713
-        return $term_owner;
1714
-    }
1713
+		return $term_owner;
1714
+	}
1715 1715
 
1716
-    /**
1717
-     * Display the Sensei modules taxonomy terms metabox
1718
-     *
1719
-     * @since 1.8.0
1720
-     *
1721
-     * @hooked into add_meta_box
1722
-     *
1723
-     * @param WP_Post $post Post object.
1724
-     */
1725
-    public function course_module_metabox( $post ) {
1716
+	/**
1717
+	 * Display the Sensei modules taxonomy terms metabox
1718
+	 *
1719
+	 * @since 1.8.0
1720
+	 *
1721
+	 * @hooked into add_meta_box
1722
+	 *
1723
+	 * @param WP_Post $post Post object.
1724
+	 */
1725
+	public function course_module_metabox( $post ) {
1726 1726
 
1727
-        $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1727
+		$tax_name = 'module';
1728
+		$taxonomy = get_taxonomy( 'module' );
1729 1729
 
1730
-        ?>
1730
+		?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1742,9 +1742,9 @@  discard block
 block discarded – undo
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
-                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747
-                ?>
1745
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1746
+				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747
+				?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749 1749
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1750 1750
                 </ul>
@@ -1754,9 +1754,9 @@  discard block
 block discarded – undo
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757
-                            /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
-                            ?>
1757
+							/* translators: %s: add new taxonomy label */
1758
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1759
+							?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1771,331 +1771,331 @@  discard block
 block discarded – undo
1771 1771
         </div>
1772 1772
     <?php
1773 1773
 
1774
-    } // end course_module_metabox
1774
+	} // end course_module_metabox
1775 1775
 
1776 1776
 
1777
-    /**
1778
-     * Submits a new module term prefixed with the
1779
-     * the current author id.
1780
-     *
1781
-     * @since 1.8.0
1782
-     */
1783
-    public static function add_new_module_term( ) {
1777
+	/**
1778
+	 * Submits a new module term prefixed with the
1779
+	 * the current author id.
1780
+	 *
1781
+	 * @since 1.8.0
1782
+	 */
1783
+	public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
-        }
1786
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1788
+		}
1789 1789
 
1790
-        // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1790
+		// get the term an create the new term storing infomration
1791
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+		if( current_user_can('manage_options' ) ) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1796 1796
 
1797
-        } else {
1797
+		} else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1800 1800
 
1801
-        }
1801
+		}
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1804 1804
 
1805
-        // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1805
+		// save the term
1806
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1807 1807
 
1808
-        // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1808
+		// send error for all errors except term exits
1809
+		if( is_wp_error( $slug ) ){
1810 1810
 
1811
-            // prepare for possible term name and id to be passed down if term exists
1812
-            $term_data = array();
1811
+			// prepare for possible term name and id to be passed down if term exists
1812
+			$term_data = array();
1813 1813
 
1814
-            // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1814
+			// if term exists also send back the term name and id
1815
+			if( isset( $slug->errors['term_exists'] ) ){
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1818
-                $term_data['name'] = $term_name;
1819
-                $term_data['id'] = $term->term_id;
1817
+				$term = get_term_by( 'slug', $term_slug, 'module');
1818
+				$term_data['name'] = $term_name;
1819
+				$term_data['id'] = $term->term_id;
1820 1820
 
1821
-                // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
-            }
1821
+				// set the object terms
1822
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1823
+			}
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1826 1826
 
1827
-        }
1827
+		}
1828 1828
 
1829
-        //make sure the new term is checked for this course
1829
+		//make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1832 1832
 
1833
-        // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1833
+		// Handle request then generate response using WP_Ajax_Response
1834
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1835 1835
 
1836
-    }
1836
+	}
1837 1837
 
1838
-    /**
1839
-     * Limit the course module metabox
1840
-     * term list to only those on courses belonging to current teacher.
1841
-     *
1842
-     * Hooked into 'get_terms'
1843
-     *
1844
-     * @since 1.8.0
1845
-     */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1838
+	/**
1839
+	 * Limit the course module metabox
1840
+	 * term list to only those on courses belonging to current teacher.
1841
+	 *
1842
+	 * Hooked into 'get_terms'
1843
+	 *
1844
+	 * @since 1.8.0
1845
+	 */
1846
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1847 1847
 
1848
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
-            return $terms;
1851
-        }
1848
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1849
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1850
+			return $terms;
1851
+		}
1852 1852
 
1853
-        // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1853
+		// avoid infinite call loop
1854
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1855 1855
 
1856
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
-            // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1860
-        }
1856
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1858
+			// change only scrub the terms ids form the array keys
1859
+			$terms = array_keys( $terms );
1860
+		}
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1863 1863
 
1864
-        // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864
+		// add filter again as removed above
1865
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1866 1866
 
1867
-        return $teachers_terms;
1868
-    }// end filter_module_terms
1867
+		return $teachers_terms;
1868
+	}// end filter_module_terms
1869 1869
 
1870
-    /**
1871
-     * For the selected items on a course module only return those
1872
-     * for the current user. This does not apply to admin and super admin users.
1873
-     *
1874
-     * hooked into get_object_terms
1875
-     *
1876
-     * @since 1.8.0
1877
-     */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1870
+	/**
1871
+	 * For the selected items on a course module only return those
1872
+	 * for the current user. This does not apply to admin and super admin users.
1873
+	 *
1874
+	 * hooked into get_object_terms
1875
+	 *
1876
+	 * @since 1.8.0
1877
+	 */
1878
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1879 1879
 
1880
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
-            return $terms;
1885
-        }
1880
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1881
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1882
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1883
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1884
+			return $terms;
1885
+		}
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1888 1888
 
1889
-        // if term objects were passed in send back objects
1890
-        // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1892
-            return $term_objects;
1893
-        }
1889
+		// if term objects were passed in send back objects
1890
+		// if term id were passed in send that back
1891
+		if( is_object( $terms[0] ) ){
1892
+			return $term_objects;
1893
+		}
1894 1894
 
1895
-        $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1897
-            $terms[] = $term_object->term_id;
1898
-        }
1895
+		$terms = array();
1896
+		foreach( $term_objects as $term_object ){
1897
+			$terms[] = $term_object->term_id;
1898
+		}
1899 1899
 
1900
-        return $terms;
1900
+		return $terms;
1901 1901
 
1902 1902
 
1903
-    }// end filter_course_selected_terms
1903
+	}// end filter_course_selected_terms
1904 1904
 
1905
-    /**
1906
-     * Filter the given terms and only return the
1907
-     * terms that belong to the given user id.
1908
-     *
1909
-     * @since 1.8.0
1910
-     * @param $terms
1911
-     * @param $user_id
1912
-     * @return array
1913
-     */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1905
+	/**
1906
+	 * Filter the given terms and only return the
1907
+	 * terms that belong to the given user id.
1908
+	 *
1909
+	 * @since 1.8.0
1910
+	 * @param $terms
1911
+	 * @param $user_id
1912
+	 * @return array
1913
+	 */
1914
+	public function filter_terms_by_owner( $terms, $user_id ){
1915 1915
 
1916
-        $users_terms = array();
1916
+		$users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+		foreach( $terms as $index => $term ){
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1921
-                // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1923
-            }
1920
+			if( is_numeric( $term ) ){
1921
+				// the term id was given, get the term object
1922
+				$term = get_term( $term, 'module' );
1923
+			}
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1928
-                // add the term to the teachers terms
1929
-                $users_terms[] = $term;
1930
-            }
1927
+			if ( $user_id == $author->ID ) {
1928
+				// add the term to the teachers terms
1929
+				$users_terms[] = $term;
1930
+			}
1931 1931
 
1932
-        }
1932
+		}
1933 1933
 
1934
-        return $users_terms;
1934
+		return $users_terms;
1935 1935
 
1936
-    } // end filter terms by owner
1936
+	} // end filter terms by owner
1937 1937
 
1938
-    /**
1939
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
-     * This will not add name to terms belonging to admin user.
1941
-     *
1942
-     * Hooked into 'get_terms'
1943
-     *
1944
-     * @since 1.8.0
1945
-     */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
-    {
1938
+	/**
1939
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1940
+	 * This will not add name to terms belonging to admin user.
1941
+	 *
1942
+	 * Hooked into 'get_terms'
1943
+	 *
1944
+	 * @since 1.8.0
1945
+	 */
1946
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947
+	{
1948 1948
 
1949
-        // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
-            return $terms;
1952
-        }
1949
+		// only for admin users ont he module taxonomy
1950
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1951
+			return $terms;
1952
+		}
1953 1953
 
1954
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
-        // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1954
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1955
+		// simply return this as wp doesn't need an array of stdObject Term
1956
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958
-            return $terms;
1958
+			return $terms;
1959 1959
 
1960
-        }
1960
+		}
1961 1961
 
1962
-        // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1962
+		// loop through and update all terms adding the author name
1963
+		foreach( $terms as $index => $term ){
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1966
-                // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1968
-            }
1965
+			if( is_numeric( $term ) ){
1966
+				// the term id was given, get the term object
1967
+				$term = get_term( $term, 'module' );
1968
+			}
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1974
-            }
1972
+			if( ! user_can( $author, 'manage_options' ) ) {
1973
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1974
+			}
1975 1975
 
1976
-            // add the term to the teachers terms
1977
-            $users_terms[] = $term;
1976
+			// add the term to the teachers terms
1977
+			$users_terms[] = $term;
1978 1978
 
1979
-        }
1979
+		}
1980 1980
 
1981
-        return $users_terms;
1982
-    }
1981
+		return $users_terms;
1982
+	}
1983 1983
 
1984
-    /**
1985
-     * Remove modules metabox that come by default
1986
-     * with the modules taxonomy. We are removing this as
1987
-     * we have created our own custom meta box.
1988
-     */
1989
-    public static function remove_default_modules_box() {
1984
+	/**
1985
+	 * Remove modules metabox that come by default
1986
+	 * with the modules taxonomy. We are removing this as
1987
+	 * we have created our own custom meta box.
1988
+	 */
1989
+	public static function remove_default_modules_box() {
1990 1990
 
1991
-        remove_meta_box('modulediv', 'course', 'side');
1991
+		remove_meta_box('modulediv', 'course', 'side');
1992 1992
 
1993
-    }
1993
+	}
1994 1994
 
1995
-    /**
1996
-     * When a course is save make sure to reset the transient set
1997
-     * for it when determining the none module lessons.
1998
-     *
1999
-     * @sine 1.9.0
2000
-     * @param $post_id
2001
-     */
2002
-    public static function reset_none_modules_transient ( $post_id ){
1995
+	/**
1996
+	 * When a course is save make sure to reset the transient set
1997
+	 * for it when determining the none module lessons.
1998
+	 *
1999
+	 * @sine 1.9.0
2000
+	 * @param $post_id
2001
+	 */
2002
+	public static function reset_none_modules_transient ( $post_id ){
2003 2003
 
2004
-        // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2004
+		// this should only apply to course and lesson post types
2005
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2006 2006
 
2007
-            $course_id = '';
2007
+			$course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+			if( 'lesson' == get_post_type( $post_id ) ){
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2012 2012
 
2013
-            }
2013
+			}
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+			if( !empty( $course_id ) ){
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2019 2019
 
2020
-            }
2020
+			}
2021 2021
 
2022
-        } // end if is a course or a lesson
2022
+		} // end if is a course or a lesson
2023 2023
 
2024
-    } // end reset_none_modules_transient
2024
+	} // end reset_none_modules_transient
2025 2025
 
2026
-    /**
2027
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
-     *
2029
-     * @since 1.9.0
2030
-     * @deprecated since 1.9.0
2031
-     *
2032
-     */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2026
+	/**
2027
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2028
+	 *
2029
+	 * @since 1.9.0
2030
+	 * @deprecated since 1.9.0
2031
+	 *
2032
+	 */
2033
+	public static function deprecate_sensei_single_course_modules_content(){
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2036 2036
 
2037
-    }
2037
+	}
2038 2038
 
2039
-    /**
2040
-     * Setup the single course module loop.
2041
-     *
2042
-     * Setup the global $sensei_modules_loop
2043
-     *
2044
-     * @since 1.9.0
2045
-     */
2046
-    public static function setup_single_course_module_loop(){
2039
+	/**
2040
+	 * Setup the single course module loop.
2041
+	 *
2042
+	 * Setup the global $sensei_modules_loop
2043
+	 *
2044
+	 * @since 1.9.0
2045
+	 */
2046
+	public static function setup_single_course_module_loop(){
2047 2047
 
2048
-        global $sensei_modules_loop, $post;
2049
-        $course_id = $post->ID;
2048
+		global $sensei_modules_loop, $post;
2049
+		$course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2052 2052
 
2053
-        //initial setup
2054
-        $sensei_modules_loop['total'] = 0;
2055
-        $sensei_modules_loop['modules'] = array();
2056
-        $sensei_modules_loop['current'] = -1;
2053
+		//initial setup
2054
+		$sensei_modules_loop['total'] = 0;
2055
+		$sensei_modules_loop['modules'] = array();
2056
+		$sensei_modules_loop['current'] = -1;
2057 2057
 
2058
-        // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2060
-            return;
2061
-        }
2058
+		// exit if this course doesn't have modules
2059
+		if( !$modules || empty( $modules )  ){
2060
+			return;
2061
+		}
2062 2062
 
2063 2063
 
2064
-        $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2064
+		$lessons_in_all_modules = array();
2065
+		foreach( $modules as $term ){
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2069 2069
 
2070
-        }
2070
+		}
2071 2071
 
2072 2072
 
2073
-        //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2075
-        $sensei_modules_loop['modules'] = $modules;
2076
-        $sensei_modules_loop['current'] = -1;
2077
-        $sensei_modules_loop['course_id'] = $course_id;
2073
+		//setup all of the modules loop variables
2074
+		$sensei_modules_loop['total'] = count( $modules );
2075
+		$sensei_modules_loop['modules'] = $modules;
2076
+		$sensei_modules_loop['current'] = -1;
2077
+		$sensei_modules_loop['course_id'] = $course_id;
2078 2078
 
2079
-    }// end setup_single_course_module_loop
2079
+	}// end setup_single_course_module_loop
2080 2080
 
2081
-    /**
2082
-     * Tear down the course module loop.
2083
-     *
2084
-     * @since 1.9.0
2085
-     *
2086
-     */
2087
-    public static function teardown_single_course_module_loop(){
2081
+	/**
2082
+	 * Tear down the course module loop.
2083
+	 *
2084
+	 * @since 1.9.0
2085
+	 *
2086
+	 */
2087
+	public static function teardown_single_course_module_loop(){
2088 2088
 
2089
-        global $sensei_modules_loop, $wp_query, $post;
2089
+		global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
2091
-        //reset all of the modules loop variables
2092
-        $sensei_modules_loop['total'] = 0;
2093
-        $sensei_modules_loop['modules'] = array();
2094
-        $sensei_modules_loop['current'] = -1;
2091
+		//reset all of the modules loop variables
2092
+		$sensei_modules_loop['total'] = 0;
2093
+		$sensei_modules_loop['modules'] = array();
2094
+		$sensei_modules_loop['current'] = -1;
2095 2095
 
2096
-        // set the current course to be the global post again
2097
-        wp_reset_query();
2098
-        $post = $wp_query->post;
2099
-    }// end teardown_single_course_module_loop
2096
+		// set the current course to be the global post again
2097
+		wp_reset_query();
2098
+		$post = $wp_query->post;
2099
+	}// end teardown_single_course_module_loop
2100 2100
 
2101 2101
 } // end modules class
Please login to merge, or discard this patch.
includes/class-sensei-notices.php 4 patches
Doc Comments   -8 removed lines patch added patch discarded remove patch
@@ -33,10 +33,6 @@  discard block
 block discarded – undo
33 33
 	* 
34 34
 	*
35 35
 	* 
36
-	* @param string $message 
37
-	* @param string $type defaults to alert options( alert, tick , download , note   )
38
-	*
39
-	* @return void
40 36
 	*/
41 37
 
42 38
 	public function add_notice( $content ,  $type = 'alert'   ){
@@ -47,10 +43,6 @@  discard block
 block discarded – undo
47 43
 	/**
48 44
 	*  Output all notices added 
49 45
 	* 
50
-	* @param string $message 
51
-	* @param string $type
52
-	*
53
-	* @return void
54 46
 	*/
55 47
 
56 48
 	public function print_notices(){
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@  discard block
 block discarded – undo
16 16
 class Sensei_Notices{
17 17
 
18 18
 	/**
19
-	*  @var $notices
20
-	*/
19
+	 *  @var $notices
20
+	 */
21 21
 	protected $notices;
22 22
 
23 23
 	/**
24
-	*  constructor 
25
- 	*/
24
+	 *  constructor 
25
+	 */
26 26
 	public function __construct(){
27 27
 		//initialize the notices variable
28 28
 		$this->notices = array();
29 29
 	}
30 30
 
31 31
 	/**
32
-	*  Add a notice to the array of notices for display at a later stage.
33
-	* 
34
-	*
35
-	* 
36
-	* @param string $message 
37
-	* @param string $type defaults to alert options( alert, tick , download , note   )
38
-	*
39
-	* @return void
40
-	*/
32
+	 *  Add a notice to the array of notices for display at a later stage.
33
+	 * 
34
+	 *
35
+	 * 
36
+	 * @param string $message 
37
+	 * @param string $type defaults to alert options( alert, tick , download , note   )
38
+	 *
39
+	 * @return void
40
+	 */
41 41
 
42 42
 	public function add_notice( $content ,  $type = 'alert'   ){
43 43
 		// append the new notice
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 	} // end add_notice()
46 46
 
47 47
 	/**
48
-	*  Output all notices added 
49
-	* 
50
-	* @param string $message 
51
-	* @param string $type
52
-	*
53
-	* @return void
54
-	*/
48
+	 *  Output all notices added 
49
+	 * 
50
+	 * @param string $message 
51
+	 * @param string $type
52
+	 *
53
+	 * @return void
54
+	 */
55 55
 
56 56
 	public function print_notices(){
57 57
 		if(  count( $this->notices ) > 0  ){
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	} // end print_notice()
69 69
 
70 70
 	/**
71
-	*  Clear all notices  
72
-	* 
73
-	* @return void
74
-	*/
71
+	 *  Clear all notices  
72
+	 * 
73
+	 * @return void
74
+	 */
75 75
 
76 76
 	public function clear_notices(){
77 77
 		// assign an empty array to clear all existing notices
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 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 Notices Class
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @since 1.6.3
14 14
  */
15 15
 
16
-class Sensei_Notices{
16
+class Sensei_Notices {
17 17
 
18 18
 	/**
19 19
 	*  @var $notices
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	/**
24 24
 	*  constructor 
25 25
  	*/
26
-	public function __construct(){
26
+	public function __construct() {
27 27
 		//initialize the notices variable
28 28
 		$this->notices = array();
29 29
 	}
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
 	* @return void
40 40
 	*/
41 41
 
42
-	public function add_notice( $content ,  $type = 'alert'   ){
42
+	public function add_notice($content, $type = 'alert') {
43 43
 		// append the new notice
44
-		$this->notices[] = array('content' => $content , 'type'=> $type );
44
+		$this->notices[] = array('content' => $content, 'type'=> $type);
45 45
 	} // end add_notice()
46 46
 
47 47
 	/**
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
 	* @return void
54 54
 	*/
55 55
 
56
-	public function print_notices(){
57
-		if(  count( $this->notices ) > 0  ){
56
+	public function print_notices() {
57
+		if (count($this->notices) > 0) {
58 58
 			foreach ($this->notices  as  $notice) {
59 59
 
60
-				$classes = 'sensei-message '. $notice['type'];
61
-				$html = '<div class="'. $classes . '">'. $notice['content'] . '</div>';
60
+				$classes = 'sensei-message '.$notice['type'];
61
+				$html = '<div class="'.$classes.'">'.$notice['content'].'</div>';
62 62
 
63 63
 				echo $html; 
64 64
 			}
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	* @return void
74 74
 	*/
75 75
 
76
-	public function clear_notices(){
76
+	public function clear_notices() {
77 77
 		// assign an empty array to clear all existing notices
78 78
 		$this->notices = array();
79 79
 	} // end clear_notices()
@@ -85,4 +85,4 @@  discard block
 block discarded – undo
85 85
  * for backward compatibility
86 86
  * @since 1.9.0
87 87
  */
88
-class Woothemes_Sensei_Notices extends Sensei_Notices{}
88
+class Woothemes_Sensei_Notices extends Sensei_Notices {}
Please login to merge, or discard this patch.
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.