Completed
Push — master ( f4562a...1bc7ca )
by Dwain
10:11
created
includes/class-sensei-lesson.php 1 patch
Spacing   +1105 added lines, -1105 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 Lessons Class
@@ -19,83 +19,83 @@  discard block
 block discarded – undo
19 19
 	 * Constructor.
20 20
 	 * @since  1.0.0
21 21
 	 */
22
-	public function __construct () {
22
+	public function __construct() {
23 23
 
24 24
         $this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27
-		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
27
+		$this->meta_fields = array('lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed');
28 28
 
29 29
         $this->question_order = '';
30 30
 
31 31
 		// Admin actions
32
-		if ( is_admin() ) {
32
+		if (is_admin()) {
33 33
 
34 34
 			// Metabox functions
35
-			add_action( 'admin_menu', array( $this, 'meta_box_setup' ), 20 );
36
-			add_action( 'save_post', array( $this, 'meta_box_save' ) );
37
-			add_action( 'save_post', array( $this, 'quiz_update' ) );
35
+			add_action('admin_menu', array($this, 'meta_box_setup'), 20);
36
+			add_action('save_post', array($this, 'meta_box_save'));
37
+			add_action('save_post', array($this, 'quiz_update'));
38 38
 
39 39
 			// Custom Write Panel Columns
40
-			add_filter( 'manage_edit-lesson_columns', array( $this, 'add_column_headings' ), 10, 1 );
41
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
40
+			add_filter('manage_edit-lesson_columns', array($this, 'add_column_headings'), 10, 1);
41
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
42 42
 
43 43
 			// Add/Update question
44
-			add_action( 'wp_ajax_lesson_update_question', array( $this, 'lesson_update_question' ) );
45
-			add_action( 'wp_ajax_nopriv_lesson_update_question', array( $this, 'lesson_update_question' ) );
44
+			add_action('wp_ajax_lesson_update_question', array($this, 'lesson_update_question'));
45
+			add_action('wp_ajax_nopriv_lesson_update_question', array($this, 'lesson_update_question'));
46 46
 
47 47
 			// Add course
48
-			add_action( 'wp_ajax_lesson_add_course', array( $this, 'lesson_add_course' ) );
49
-			add_action( 'wp_ajax_nopriv_lesson_add_course', array( $this, 'lesson_add_course' ) );
48
+			add_action('wp_ajax_lesson_add_course', array($this, 'lesson_add_course'));
49
+			add_action('wp_ajax_nopriv_lesson_add_course', array($this, 'lesson_add_course'));
50 50
 
51 51
 			// Update grade type
52
-			add_action( 'wp_ajax_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
53
-			add_action( 'wp_ajax_nopriv_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
52
+			add_action('wp_ajax_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
53
+			add_action('wp_ajax_nopriv_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
54 54
 
55 55
 			// Update question order
56
-			add_action( 'wp_ajax_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
57
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
56
+			add_action('wp_ajax_lesson_update_question_order', array($this, 'lesson_update_question_order'));
57
+			add_action('wp_ajax_nopriv_lesson_update_question_order', array($this, 'lesson_update_question_order'));
58 58
 
59 59
 			//Update question order
60
-			add_action( 'wp_ajax_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
61
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
60
+			add_action('wp_ajax_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
61
+			add_action('wp_ajax_nopriv_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
62 62
 
63 63
 			// Get answer ID
64
-			add_action( 'wp_ajax_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
65
-			add_action( 'wp_ajax_nopriv_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
64
+			add_action('wp_ajax_question_get_answer_id', array($this, 'question_get_answer_id'));
65
+			add_action('wp_ajax_nopriv_question_get_answer_id', array($this, 'question_get_answer_id'));
66 66
 
67 67
 			// Add multiple questions
68
-			add_action( 'wp_ajax_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
69
-			add_action( 'wp_ajax_nopriv_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
68
+			add_action('wp_ajax_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
69
+			add_action('wp_ajax_nopriv_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
70 70
 
71 71
 			// Remove multiple questions
72
-			add_action( 'wp_ajax_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
73
-			add_action( 'wp_ajax_nopriv_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
72
+			add_action('wp_ajax_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
73
+			add_action('wp_ajax_nopriv_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
74 74
 
75 75
 			// Get question category limit
76
-			add_action( 'wp_ajax_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
77
-			add_action( 'wp_ajax_nopriv_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
76
+			add_action('wp_ajax_get_question_category_limit', array($this, 'get_question_category_limit'));
77
+			add_action('wp_ajax_nopriv_get_question_category_limit', array($this, 'get_question_category_limit'));
78 78
 
79 79
 			// Add existing questions
80
-			add_action( 'wp_ajax_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
81
-			add_action( 'wp_ajax_nopriv_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
80
+			add_action('wp_ajax_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
81
+			add_action('wp_ajax_nopriv_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
82 82
 
83 83
 			// Filter existing questions
84
-			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85
-			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
84
+			add_action('wp_ajax_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
85
+			add_action('wp_ajax_nopriv_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
86 86
 
87 87
             // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
88
+            add_action('bulk_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
89
+            add_action('quick_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
90 90
 
91 91
             // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
92
+            add_action('manage_lesson_posts_custom_column', array($this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94 94
             // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
95
+            add_action('wp_ajax_save_bulk_edit_book', array($this, 'save_all_lessons_edit_fields'));
96 96
 
97 97
             // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
98
+            add_action('save_post', array(__CLASS__, 'flush_rewrite_rules'));
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
 	 * @access public
109 109
 	 * @return void
110 110
 	 */
111
-	public function meta_box_setup () {
111
+	public function meta_box_setup() {
112 112
 
113 113
 		// Add Meta Box for Prerequisite Lesson
114
-		add_meta_box( 'lesson-prerequisite', __( 'Lesson Prerequisite', 'woothemes-sensei' ), array( $this, 'lesson_prerequisite_meta_box_content' ), $this->token, 'side', 'default' );
114
+		add_meta_box('lesson-prerequisite', __('Lesson Prerequisite', 'woothemes-sensei'), array($this, 'lesson_prerequisite_meta_box_content'), $this->token, 'side', 'default');
115 115
 
116 116
 		// Add Meta Box for Lesson Course
117
-		add_meta_box( 'lesson-course', __( 'Lesson Course', 'woothemes-sensei' ), array( $this, 'lesson_course_meta_box_content' ), $this->token, 'side', 'default' );
117
+		add_meta_box('lesson-course', __('Lesson Course', 'woothemes-sensei'), array($this, 'lesson_course_meta_box_content'), $this->token, 'side', 'default');
118 118
 
119 119
 		// Add Meta Box for Lesson Preview
120
-		add_meta_box( 'lesson-preview', __( 'Lesson Preview', 'woothemes-sensei' ), array( $this, 'lesson_preview_meta_box_content' ), $this->token, 'side', 'default' );
120
+		add_meta_box('lesson-preview', __('Lesson Preview', 'woothemes-sensei'), array($this, 'lesson_preview_meta_box_content'), $this->token, 'side', 'default');
121 121
 
122 122
 		// Add Meta Box for Lesson Information
123
-		add_meta_box( 'lesson-info', __( 'Lesson Information', 'woothemes-sensei' ), array( $this, 'lesson_info_meta_box_content' ), $this->token, 'normal', 'default' );
123
+		add_meta_box('lesson-info', __('Lesson Information', 'woothemes-sensei'), array($this, 'lesson_info_meta_box_content'), $this->token, 'normal', 'default');
124 124
 
125 125
 		// Add Meta Box for Quiz Settings
126
-		add_meta_box( 'lesson-quiz-settings', __( 'Quiz Settings', 'woothemes-sensei' ), array( $this, 'lesson_quiz_settings_meta_box_content' ), $this->token, 'normal', 'default' );
126
+		add_meta_box('lesson-quiz-settings', __('Quiz Settings', 'woothemes-sensei'), array($this, 'lesson_quiz_settings_meta_box_content'), $this->token, 'normal', 'default');
127 127
 
128 128
 		// Add Meta Box for Lesson Quiz Questions
129
-		add_meta_box( 'lesson-quiz', __( 'Quiz Questions', 'woothemes-sensei' ), array( $this, 'lesson_quiz_meta_box_content' ), $this->token, 'normal', 'default' );
129
+		add_meta_box('lesson-quiz', __('Quiz Questions', 'woothemes-sensei'), array($this, 'lesson_quiz_meta_box_content'), $this->token, 'normal', 'default');
130 130
 
131 131
 		// Remove "Custom Settings" meta box.
132
-		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
132
+		remove_meta_box('woothemes-settings', $this->token, 'normal');
133 133
 
134 134
 		// Add JS scripts
135
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
135
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
136 136
 
137 137
 		// Add CSS
138
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
138
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
139 139
 
140 140
 	} // End meta_box_setup()
141 141
 
@@ -146,30 +146,30 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 * @return void
148 148
 	 */
149
-	public function lesson_info_meta_box_content () {
149
+	public function lesson_info_meta_box_content() {
150 150
 		global $post;
151 151
 
152
-		$lesson_length = get_post_meta( $post->ID, '_lesson_length', true );
153
-		$lesson_complexity = get_post_meta( $post->ID, '_lesson_complexity', true );
152
+		$lesson_length = get_post_meta($post->ID, '_lesson_length', true);
153
+		$lesson_complexity = get_post_meta($post->ID, '_lesson_complexity', true);
154 154
 		$complexity_array = $this->lesson_complexities();
155
-		$lesson_video_embed = get_post_meta( $post->ID, '_lesson_video_embed', true );
155
+		$lesson_video_embed = get_post_meta($post->ID, '_lesson_video_embed', true);
156 156
 
157 157
 		$html = '';
158 158
 		// Lesson Length
159
-		$html .= '<p><label for="lesson_length">' . __( 'Lesson Length in minutes', 'woothemes-sensei' ) . ': </label>';
160
-		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="' . esc_attr( $lesson_length ) . '" /></p>' . "\n";
159
+		$html .= '<p><label for="lesson_length">'.__('Lesson Length in minutes', 'woothemes-sensei').': </label>';
160
+		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="'.esc_attr($lesson_length).'" /></p>'."\n";
161 161
 		// Lesson Complexity
162
-		$html .= '<p><label for="lesson_complexity">' . __( 'Lesson Complexity', 'woothemes-sensei' ) . ': </label>';
162
+		$html .= '<p><label for="lesson_complexity">'.__('Lesson Complexity', 'woothemes-sensei').': </label>';
163 163
 		$html .= '<select id="lesson-complexity-options" name="lesson_complexity" class="chosen_select lesson-complexity-select">';
164
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
165
-			foreach ($complexity_array as $key => $value){
166
-				$html .= '<option value="' . esc_attr( $key ) . '"' . selected( $key, $lesson_complexity, false ) . '>' . esc_html( $value ) . '</option>' . "\n";
164
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
165
+			foreach ($complexity_array as $key => $value) {
166
+				$html .= '<option value="'.esc_attr($key).'"'.selected($key, $lesson_complexity, false).'>'.esc_html($value).'</option>'."\n";
167 167
 			} // End For Loop
168
-		$html .= '</select></p>' . "\n";
168
+		$html .= '</select></p>'."\n";
169 169
 
170
-		$html .= '<p><label for="lesson_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . ':</label><br/>' . "\n";
171
-		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">' . $lesson_video_embed . '</textarea></p>' . "\n";
172
-		$html .= '<p>' .  __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>';
170
+		$html .= '<p><label for="lesson_video_embed">'.__('Video Embed Code', 'woothemes-sensei').':</label><br/>'."\n";
171
+		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">'.$lesson_video_embed.'</textarea></p>'."\n";
172
+		$html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>';
173 173
 
174 174
 		echo $html;
175 175
 
@@ -181,31 +181,31 @@  discard block
 block discarded – undo
181 181
 	 * @access public
182 182
 	 * @return void
183 183
 	 */
184
-	public function lesson_prerequisite_meta_box_content () {
184
+	public function lesson_prerequisite_meta_box_content() {
185 185
 		global $post;
186 186
 		// Get existing post meta
187
-		$select_lesson_prerequisite = get_post_meta( $post->ID, '_lesson_prerequisite', true );
187
+		$select_lesson_prerequisite = get_post_meta($post->ID, '_lesson_prerequisite', true);
188 188
 		// Get the Lesson Posts
189
-		$post_args = array(	'post_type' 		=> 'lesson',
189
+		$post_args = array('post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192 192
     						'order'           	=> 'ASC',
193 193
     						'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196
-		$posts_array = get_posts( $post_args );
196
+		$posts_array = get_posts($post_args);
197 197
 		// Build the HTML to Output
198 198
 		$html = '';
199
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
200
-		if ( count( $posts_array ) > 0 ) {
201
-			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">' . "\n";
202
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
203
-				foreach ($posts_array as $post_item){
204
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_lesson_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
199
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
200
+		if (count($posts_array) > 0) {
201
+			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">'."\n";
202
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
203
+				foreach ($posts_array as $post_item) {
204
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_lesson_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n";
205 205
 				} // End For Loop
206
-			$html .= '</select>' . "\n";
206
+			$html .= '</select>'."\n";
207 207
 		} else {
208
-			$html .= '<p>' . esc_html( __( 'No lessons exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>';
208
+			$html .= '<p>'.esc_html(__('No lessons exist yet. Please add some first.', 'woothemes-sensei')).'</p>';
209 209
 		} // End If Statement
210 210
 		// Output the HTML
211 211
 		echo $html;
@@ -217,20 +217,20 @@  discard block
 block discarded – undo
217 217
 	 * @access public
218 218
 	 * @return void
219 219
 	 */
220
-	public function lesson_preview_meta_box_content () {
220
+	public function lesson_preview_meta_box_content() {
221 221
 		global $post;
222 222
 		// Get existing post meta
223
-		$lesson_preview = get_post_meta( $post->ID, '_lesson_preview', true );
223
+		$lesson_preview = get_post_meta($post->ID, '_lesson_preview', true);
224 224
 		$html = '';
225
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
225
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
226 226
 
227 227
 		$checked = '';
228
-		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
228
+		if (isset($lesson_preview) && ('' != $lesson_preview)) {
229
+	 	    $checked = checked('preview', $lesson_preview, false);
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
233
-	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" ' . $checked . '>&nbsp;' . __( 'Allow this lesson to be viewed without purchase/login', 'woothemes-sensei' ) . '<br>';
233
+	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" '.$checked.'>&nbsp;'.__('Allow this lesson to be viewed without purchase/login', 'woothemes-sensei').'<br>';
234 234
 
235 235
 		// Output the HTML
236 236
 		echo $html;
@@ -243,40 +243,40 @@  discard block
 block discarded – undo
243 243
 	 * @param int $post_id
244 244
 	 * @return integer $post_id
245 245
 	 */
246
-	public function meta_box_save ( $post_id ) {
246
+	public function meta_box_save($post_id) {
247 247
 
248 248
 		// Verify the nonce before proceeding.
249
-		if ( ( get_post_type( $post_id ) != $this->token ) || !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta' ) ) {
249
+		if ((get_post_type($post_id) != $this->token) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
250 250
 			return $post_id;
251 251
 		} // End If Statement
252 252
 		// Get the post type object.
253
-		$post_type = get_post_type_object( get_post_type( $post_id ) );
253
+		$post_type = get_post_type_object(get_post_type($post_id));
254 254
 		// Check if the current user has permission to edit the post.
255
-		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
255
+		if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
256 256
 			return $post_id;
257 257
 		} // End If Statement
258 258
 
259 259
 		// Check if the current post type is a page
260
-		if ( 'page' == $_POST[ 'post_type' ] ) {
260
+		if ('page' == $_POST['post_type']) {
261 261
 
262
-			if ( ! current_user_can( 'edit_page', $post_id ) ) {
262
+			if ( ! current_user_can('edit_page', $post_id)) {
263 263
 
264 264
 				return $post_id;
265 265
 
266 266
 			} // End If Statement
267 267
 		} else {
268
-			if ( ! current_user_can( 'edit_post', $post_id ) ) {
268
+			if ( ! current_user_can('edit_post', $post_id)) {
269 269
 				return $post_id;
270 270
 			} // End If Statement
271 271
 		} // End If Statement
272 272
 
273 273
 		// Save the post meta data fields
274
-		if ( isset($this->meta_fields) && is_array($this->meta_fields) ) {
274
+		if (isset($this->meta_fields) && is_array($this->meta_fields)) {
275 275
 
276
-			foreach ( $this->meta_fields as $meta_key ) {
276
+			foreach ($this->meta_fields as $meta_key) {
277 277
 
278
-				remove_action( 'save_post', array( $this, 'meta_box_save') );
279
-				$this->save_post_meta( $meta_key, $post_id );
278
+				remove_action('save_post', array($this, 'meta_box_save'));
279
+				$this->save_post_meta($meta_key, $post_id);
280 280
 
281 281
 			} // End For Loop
282 282
 		} // End If Statement
@@ -289,37 +289,37 @@  discard block
 block discarded – undo
289 289
 	 * @access public
290 290
 	 * @return integer|boolean $post_id or false
291 291
 	 */
292
-	public function quiz_update( $post_id ) {
292
+	public function quiz_update($post_id) {
293 293
 		global $post;
294 294
 		// Verify the nonce before proceeding.
295
-		if ( ( 'lesson' != get_post_type( $post_id ) )|| !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta') ) {
296
-			if ( isset($post->ID) ) {
295
+		if (('lesson' != get_post_type($post_id)) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
296
+			if (isset($post->ID)) {
297 297
 				return $post->ID;
298 298
 			} else {
299 299
 				return false;
300 300
 			} // End If Statement
301 301
 		} // End If Statement
302 302
 
303
-		if( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
303
+		if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
304 304
 			return false;
305 305
 		}
306 306
 
307 307
 		// Temporarily disable the filter
308
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
308
+        remove_action('save_post', array($this, 'quiz_update'));
309 309
 		// Save the Quiz
310
-		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
310
+		$quiz_id = $this->lesson_quizzes($post_id, 'any');
311 311
 
312 312
 		 // Sanitize and setup the post data
313
-		$_POST = stripslashes_deep( $_POST );
314
-		if ( isset( $_POST[ 'quiz_id' ] ) && ( 0 < absint( $_POST[ 'quiz_id' ] ) ) ) {
315
-			$quiz_id = absint( $_POST[ 'quiz_id' ] );
313
+		$_POST = stripslashes_deep($_POST);
314
+		if (isset($_POST['quiz_id']) && (0 < absint($_POST['quiz_id']))) {
315
+			$quiz_id = absint($_POST['quiz_id']);
316 316
 		} // End If Statement
317
-		$post_title = esc_html( $_POST[ 'post_title' ] );
318
-		$post_status = esc_html( $_POST[ 'post_status' ] );
317
+		$post_title = esc_html($_POST['post_title']);
318
+		$post_status = esc_html($_POST['post_status']);
319 319
 		$post_content = '';
320 320
 
321 321
 		// Setup Query Arguments
322
-		$post_type_args = array(	'post_content' => $post_content,
322
+		$post_type_args = array('post_content' => $post_content,
323 323
   		    						'post_status' => $post_status,
324 324
   		    						'post_title' => $post_title,
325 325
   		    						'post_type' => 'quiz',
@@ -329,84 +329,84 @@  discard block
 block discarded – undo
329 329
 		$settings = $this->get_quiz_settings();
330 330
 
331 331
   		// Update or Insert the Lesson Quiz
332
-		if ( 0 < $quiz_id ) {
332
+		if (0 < $quiz_id) {
333 333
 			// Update the Quiz
334
-			$post_type_args[ 'ID' ] = $quiz_id;
334
+			$post_type_args['ID'] = $quiz_id;
335 335
 		    wp_update_post($post_type_args);
336 336
 
337 337
 		    // Update the post meta data
338
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
338
+		    update_post_meta($quiz_id, '_quiz_lesson', $post_id);
339 339
 
340
-		    foreach( $settings as $field ) {
341
-		    	if( 'random_question_order' != $field['id'] ) {
342
-			    	$value = $this->get_submitted_setting_value( $field );
343
-			    	if( isset( $value ) ) {
344
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
340
+		    foreach ($settings as $field) {
341
+		    	if ('random_question_order' != $field['id']) {
342
+			    	$value = $this->get_submitted_setting_value($field);
343
+			    	if (isset($value)) {
344
+			    		update_post_meta($quiz_id, '_'.$field['id'], $value);
345 345
 			    	}
346 346
 			    }
347 347
 		    }
348 348
 
349 349
 		    // Set the post terms for quiz-type
350
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
350
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
351 351
 		} else {
352 352
 			// Create the Quiz
353 353
 		    $quiz_id = wp_insert_post($post_type_args);
354 354
 
355 355
 		    // Add the post meta data WP will add it if it doesn't exist
356
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
356
+            update_post_meta($quiz_id, '_quiz_lesson', $post_id);
357 357
 
358
-		    foreach( $settings as $field ) {
359
-		    	if( 'random_question_order' != $field['id'] ) {
358
+		    foreach ($settings as $field) {
359
+		    	if ('random_question_order' != $field['id']) {
360 360
 
361 361
                     //ignore values not posted to avoid
362 362
                     // overwriting with empty or default values
363 363
                     // when the values are posted from bulk edit or quick edit
364
-                    if( !isset( $_POST[ $field['id'] ] ) ){
364
+                    if ( ! isset($_POST[$field['id']])) {
365 365
                         continue;
366 366
                     }
367 367
 
368
-			    	$value = $this->get_submitted_setting_value( $field );
369
-			    	if( isset( $value ) ) {
370
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
368
+			    	$value = $this->get_submitted_setting_value($field);
369
+			    	if (isset($value)) {
370
+			    		add_post_meta($quiz_id, '_'.$field['id'], $value);
371 371
 			    	}
372 372
 			    }
373 373
 		    }
374 374
 
375 375
 		    // Set the post terms for quiz-type
376
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
376
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
377 377
 		} // End If Statement
378 378
 
379 379
 		// Add default lesson order meta value
380
-		$course_id = get_post_meta( $post_id, '_lesson_course', true );
381
-		if( $course_id ) {
382
-			if( ! get_post_meta( $post_id, '_order_' . $course_id, true ) ) {
383
-				update_post_meta( $post_id, '_order_' . $course_id, 0 );
380
+		$course_id = get_post_meta($post_id, '_lesson_course', true);
381
+		if ($course_id) {
382
+			if ( ! get_post_meta($post_id, '_order_'.$course_id, true)) {
383
+				update_post_meta($post_id, '_order_'.$course_id, 0);
384 384
 			}
385 385
 		}
386 386
 		// Add reference back to the Quiz
387
-		update_post_meta( $post_id, '_lesson_quiz', $quiz_id );
387
+		update_post_meta($post_id, '_lesson_quiz', $quiz_id);
388 388
 		// Mark if the Lesson Quiz has questions
389
-		$quiz_questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
390
-		if( 0 < count( $quiz_questions ) ) {
391
-			update_post_meta( $post_id, '_quiz_has_questions', '1' );
389
+		$quiz_questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
390
+		if (0 < count($quiz_questions)) {
391
+			update_post_meta($post_id, '_quiz_has_questions', '1');
392 392
 		}
393 393
 		else {
394
-			delete_post_meta( $post_id, '_quiz_has_questions' );
394
+			delete_post_meta($post_id, '_quiz_has_questions');
395 395
 		}
396 396
 
397 397
 		// Restore the previously disabled filter
398
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
398
+        add_action('save_post', array($this, 'quiz_update'));
399 399
 
400 400
 	} // End post_updated()
401 401
 
402
-	public function get_submitted_setting_value( $field = false ) {
402
+	public function get_submitted_setting_value($field = false) {
403 403
 
404
-		if( ! $field ) return;
404
+		if ( ! $field) return;
405 405
 
406 406
 		$value = false;
407 407
 
408
-		if( 'quiz_grade_type' == $field['id'] ) {
409
-			if( isset( $_POST[ $field['id'] ] ) && 'on' == $_POST[ $field['id'] ] ) {
408
+		if ('quiz_grade_type' == $field['id']) {
409
+			if (isset($_POST[$field['id']]) && 'on' == $_POST[$field['id']]) {
410 410
 				$value = 'auto';
411 411
 			} else {
412 412
 				$value = 'manual';
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 			return $value;
415 415
 		}
416 416
 
417
-		if ( isset( $_POST[ $field['id'] ] ) ) {
418
-			$value = $_POST[ $field['id'] ];
417
+		if (isset($_POST[$field['id']])) {
418
+			$value = $_POST[$field['id']];
419 419
 		} else {
420 420
 			$value = $field['default'];
421 421
 		}
@@ -431,18 +431,18 @@  discard block
 block discarded – undo
431 431
 	 * @param int $post_id (default: 0)
432 432
 	 * @return int|bool meta id or saved status
433 433
 	 */
434
-	private function save_post_meta( $post_key = '', $post_id = 0 ) {
434
+	private function save_post_meta($post_key = '', $post_id = 0) {
435 435
 		// Get the meta key.
436
-		$meta_key = '_' . $post_key;
436
+		$meta_key = '_'.$post_key;
437 437
 
438 438
         //ignore fields are not posted
439 439
 
440
-        if( !isset( $_POST[ $post_key ] ) ){
440
+        if ( ! isset($_POST[$post_key])) {
441 441
 
442 442
             // except for lesson preview checkbox field
443
-            if( 'lesson_preview' == $post_key ){
443
+            if ('lesson_preview' == $post_key) {
444 444
 
445
-                $_POST[ $post_key ] = '';
445
+                $_POST[$post_key] = '';
446 446
 
447 447
             } else {
448 448
 
@@ -453,15 +453,15 @@  discard block
 block discarded – undo
453 453
         }
454 454
 
455 455
 		// Get the posted data and sanitize it for use as an HTML class.
456
-		if ( 'lesson_video_embed' == $post_key) {
457
-			$new_meta_value = esc_html( $_POST[$post_key] );
456
+		if ('lesson_video_embed' == $post_key) {
457
+			$new_meta_value = esc_html($_POST[$post_key]);
458 458
 		} else {
459
-			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
459
+			$new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : '');
460 460
 		} // End If Statement
461 461
 
462 462
         // update field with the new value
463
-        if( -1 != $new_meta_value  ){
464
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
463
+        if ( -1 != $new_meta_value  ) {
464
+            return update_post_meta($post_id, $meta_key, $new_meta_value);
465 465
         }
466 466
 
467 467
 	} // End save_post_meta()
@@ -472,30 +472,30 @@  discard block
 block discarded – undo
472 472
 	 * @access public
473 473
 	 * @return void
474 474
 	 */
475
-	public function lesson_course_meta_box_content () {
475
+	public function lesson_course_meta_box_content() {
476 476
 		global $post;
477 477
 		// Setup Lesson Meta Data
478 478
 		$selected_lesson_course = 0;
479
-		if ( 0 < $post->ID ) {
480
-			$selected_lesson_course = get_post_meta( $post->ID, '_lesson_course', true );
479
+		if (0 < $post->ID) {
480
+			$selected_lesson_course = get_post_meta($post->ID, '_lesson_course', true);
481 481
 		} // End If Statement
482 482
 		// Handle preselected course
483
-		if ( isset( $_GET[ 'course_id' ] ) && ( 0 < absint( $_GET[ 'course_id' ] ) ) ) {
484
-			$selected_lesson_course = absint( $_GET[ 'course_id' ] );
483
+		if (isset($_GET['course_id']) && (0 < absint($_GET['course_id']))) {
484
+			$selected_lesson_course = absint($_GET['course_id']);
485 485
 		} // End If Statement
486 486
 		// Get the Lesson Posts
487
-		$post_args = array(	'post_type' 		=> 'course',
487
+		$post_args = array('post_type' 		=> 'course',
488 488
 							'posts_per_page' 		=> -1,
489 489
 							'orderby'         	=> 'title',
490 490
     						'order'           	=> 'ASC',
491 491
     						'post_status'      	=> 'any',
492 492
     						'suppress_filters' 	=> 0,
493 493
 							);
494
-		$posts_array = get_posts( $post_args );
494
+		$posts_array = get_posts($post_args);
495 495
 		// Buid the HTML to Output
496 496
 		$html = '';
497 497
 		// Nonce
498
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
498
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
499 499
 
500 500
         // Select the course for the lesson
501 501
         $drop_down_args = array(
@@ -505,67 +505,67 @@  discard block
 block discarded – undo
505 505
 
506 506
         $courses = WooThemes_Sensei_Course::get_all_courses();
507 507
         $courses_options = array();
508
-        foreach( $courses as $course ){
509
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
508
+        foreach ($courses as $course) {
509
+            $courses_options[$course->ID] = get_the_title($course);
510 510
         }
511
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
511
+        $html .= Sensei_Utils::generate_drop_down($selected_lesson_course, $courses_options, $drop_down_args);
512 512
 
513 513
         // Course Actions Panel
514
-		if ( current_user_can( 'publish_courses' )) {
514
+		if (current_user_can('publish_courses')) {
515 515
 				$html .= '<div id="lesson-course-actions">';
516 516
 					$html .= '<p>';
517 517
 						// Add a course action link
518
-						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ ' . __('Add New Course', 'woothemes-sensei' ) . '</a>';
518
+						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ '.__('Add New Course', 'woothemes-sensei').'</a>';
519 519
 					$html .= '</p>';
520 520
 				$html .= '</div>';
521 521
 				// Add a course input fields
522 522
 				$html .= '<div id="lesson-course-details" class="hidden">';
523 523
 					$html .= '<p>';
524 524
 						// Course Title input
525
-						$html .= '<label>' . __( 'Course Title' , 'woothemes-sensei' ) . '</label> ';
525
+						$html .= '<label>'.__('Course Title', 'woothemes-sensei').'</label> ';
526 526
 	  					$html .= '<input type="text" id="course-title" name="course_title" value="" size="25" class="widefat" />';
527 527
 	  					// Course Description input
528
-	  					$html .= '<label>' . __( 'Description' , 'woothemes-sensei' ) . '</label> ';
528
+	  					$html .= '<label>'.__('Description', 'woothemes-sensei').'</label> ';
529 529
 	  					$html .= '<textarea rows="10" cols="40" id="course-content" name="course_content" value="" size="300" class="widefat"></textarea>';
530 530
 	  					// Course Prerequisite
531
-	  					$html .= '<label>' . __( 'Course Prerequisite' , 'woothemes-sensei' ) . '</label> ';
532
-	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n";
533
-							$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
534
-							foreach ($posts_array as $post_item){
535
-								$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '">' . esc_html( $post_item->post_title ) . '</option>' . "\n";
531
+	  					$html .= '<label>'.__('Course Prerequisite', 'woothemes-sensei').'</label> ';
532
+	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n";
533
+							$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
534
+							foreach ($posts_array as $post_item) {
535
+								$html .= '<option value="'.esc_attr(absint($post_item->ID)).'">'.esc_html($post_item->post_title).'</option>'."\n";
536 536
 							} // End For Loop
537
-						$html .= '</select>' . "\n";
537
+						$html .= '</select>'."\n";
538 538
 						// Course Product
539
-                        if ( Sensei_WC::is_woocommerce_active() ) {
539
+                        if (Sensei_WC::is_woocommerce_active()) {
540 540
 	  						// Get the Products
541
-							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
541
+							$select_course_woocommerce_product = get_post_meta($post_item->ID, '_course_woocommerce_product', true);
542 542
 
543
-							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
543
+							$product_args = array('post_type' 		=> array('product', 'product_variation'),
544 544
 													'posts_per_page' 		=> -1,
545 545
 													'orderby'         	=> 'title',
546 546
 	    											'order'           	=> 'DESC',
547
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
547
+	    											'post_status'		=> array('publish', 'private', 'draft'),
548 548
 	    											'tax_query'			=> array(
549 549
 														array(
550 550
 															'taxonomy'	=> 'product_type',
551 551
 															'field'		=> 'slug',
552
-															'terms'		=> array( 'variable', 'grouped' ),
552
+															'terms'		=> array('variable', 'grouped'),
553 553
 															'operator'	=> 'NOT IN'
554 554
 														)
555 555
 													),
556 556
 	    											'suppress_filters' 	=> 0
557 557
 													);
558
-							$products_array = get_posts( $product_args );
559
-							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
560
-	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n";
561
-								$html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>';
558
+							$products_array = get_posts($product_args);
559
+							$html .= '<label>'.__('WooCommerce Product', 'woothemes-sensei').'</label> ';
560
+	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n";
561
+								$html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>';
562 562
 								$prev_parent_id = 0;
563
-								foreach ($products_array as $products_item){
563
+								foreach ($products_array as $products_item) {
564 564
 
565
-									if ( 'product_variation' == $products_item->post_type ) {
566
-										$product_object = get_product( $products_item->ID );
567
-										$parent_id = wp_get_post_parent_id( $products_item->ID );
568
-										$product_name = ucwords( woocommerce_get_formatted_variation( $product_object->variation_data, true ) );
565
+									if ('product_variation' == $products_item->post_type) {
566
+										$product_object = get_product($products_item->ID);
567
+										$parent_id = wp_get_post_parent_id($products_item->ID);
568
+										$product_name = ucwords(woocommerce_get_formatted_variation($product_object->variation_data, true));
569 569
 									} else {
570 570
 										$parent_id = false;
571 571
 										$prev_parent_id = 0;
@@ -573,32 +573,32 @@  discard block
 block discarded – undo
573 573
 									}
574 574
 
575 575
 									// Show variations in groups
576
-									if( $parent_id && $parent_id != $prev_parent_id ) {
577
-										if( 0 != $prev_parent_id ) {
576
+									if ($parent_id && $parent_id != $prev_parent_id) {
577
+										if (0 != $prev_parent_id) {
578 578
 											$html .= '</optgroup>';
579 579
 										}
580
-										$html .= '<optgroup label="' . get_the_title( $parent_id ) . '">';
580
+										$html .= '<optgroup label="'.get_the_title($parent_id).'">';
581 581
 										$prev_parent_id = $parent_id;
582
-									} elseif( ! $parent_id && 0 == $prev_parent_id ) {
582
+									} elseif ( ! $parent_id && 0 == $prev_parent_id) {
583 583
 										$html .= '</optgroup>';
584 584
 									}
585 585
 
586
-									$html .= '<option value="' . esc_attr( absint( $products_item->ID ) ) . '">' . esc_html( $products_item->post_title ) . '</option>' . "\n";
586
+									$html .= '<option value="'.esc_attr(absint($products_item->ID)).'">'.esc_html($products_item->post_title).'</option>'."\n";
587 587
 								} // End For Loop
588
-							$html .= '</select>' . "\n";
588
+							$html .= '</select>'."\n";
589 589
 						} else {
590 590
 							// Default
591 591
 							$html .= '<input type="hidden" name="course_woocommerce_product" id="course-woocommerce-product-options" value="-" />';
592 592
 						}
593 593
 						// Course Category
594
-	  					$html .= '<label>' . __( 'Course Category' , 'woothemes-sensei' ) . '</label> ';
595
-	  					$cat_args = array( 'echo' => false, 'hierarchical' => true, 'show_option_none' => __( 'None', 'woothemes-sensei' ), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat' );
596
-						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args)) . "\n";
594
+	  					$html .= '<label>'.__('Course Category', 'woothemes-sensei').'</label> ';
595
+	  					$cat_args = array('echo' => false, 'hierarchical' => true, 'show_option_none' => __('None', 'woothemes-sensei'), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat');
596
+						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args))."\n";
597 597
 	  					// Save the course action button
598
-	  					$html .= '<a title="' . esc_attr( __( 'Save Course', 'woothemes-sensei' ) ) . '" href="#add-course-metadata" class="lesson_course_save button button-highlighted">' . esc_html( __( 'Add Course', 'woothemes-sensei' ) ) . '</a>';
598
+	  					$html .= '<a title="'.esc_attr(__('Save Course', 'woothemes-sensei')).'" href="#add-course-metadata" class="lesson_course_save button button-highlighted">'.esc_html(__('Add Course', 'woothemes-sensei')).'</a>';
599 599
 						$html .= '&nbsp;&nbsp;&nbsp;';
600 600
 						// Cancel action link
601
-						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">' . __( 'Cancel', 'woothemes-sensei' ) . '</a>';
601
+						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">'.__('Cancel', 'woothemes-sensei').'</a>';
602 602
 					$html .= '</p>';
603 603
 				$html .= '</div>';
604 604
 			} // End If Statement
@@ -607,20 +607,20 @@  discard block
 block discarded – undo
607 607
 		echo $html;
608 608
 	} // End lesson_course_meta_box_content()
609 609
 
610
-	public function quiz_panel( $quiz_id = 0 ) {
610
+	public function quiz_panel($quiz_id = 0) {
611 611
 
612
-		$html = wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
612
+		$html = wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
613 613
 		$html .= '<div id="add-quiz-main">';
614
-			if ( 0 == $quiz_id ) {
614
+			if (0 == $quiz_id) {
615 615
 				$html .= '<p>';
616 616
 					// Default message and Add a Quiz button
617
-					$html .= esc_html( __( 'Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei' ) );
617
+					$html .= esc_html(__('Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei'));
618 618
 				$html .= '</p>';
619 619
 			}
620 620
 
621 621
 			// Quiz Panel CSS Class
622 622
 			$quiz_class = '';
623
-			if ( 0 == $quiz_id ) {
623
+			if (0 == $quiz_id) {
624 624
 				$quiz_class = ' class="hidden"';
625 625
 			} // End If Statement
626 626
 			// Build the HTML to Output
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 
629 629
 			// Setup Questions Query
630 630
 			$questions = array();
631
-			if ( 0 < $quiz_id ) {
632
-				$questions = $this->lesson_quiz_questions( $quiz_id );
631
+			if (0 < $quiz_id) {
632
+				$questions = $this->lesson_quiz_questions($quiz_id);
633 633
 			} // End If Statement
634 634
 
635 635
 			$question_count = 0;
636
-			foreach( $questions as $question ) {
636
+			foreach ($questions as $question) {
637 637
 
638
-				if( $question->post_type == 'multiple_question' ) {
639
-					$question_number = get_post_meta( $question->ID, 'number', true );
638
+				if ($question->post_type == 'multiple_question') {
639
+					$question_number = get_post_meta($question->ID, 'number', true);
640 640
 					$question_count += $question_number;
641 641
 				} else {
642 642
 					++$question_count;
@@ -645,68 +645,68 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 
647 647
 			// Inner DIV
648
-			$html .= '<div id="add-quiz-metadata"' . $quiz_class . '>';
648
+			$html .= '<div id="add-quiz-metadata"'.$quiz_class.'>';
649 649
 
650 650
 				// Quiz ID
651
-				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="' . esc_attr( $quiz_id ) . '" />';
651
+				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="'.esc_attr($quiz_id).'" />';
652 652
 
653 653
 				// Default Message
654
-				if ( 0 == $quiz_id ) {
654
+				if (0 == $quiz_id) {
655 655
 					$html .= '<p class="save-note">';
656
-						$html .= esc_html( __( 'Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei' ) );
656
+						$html .= esc_html(__('Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei'));
657 657
 					$html .= '</p>';
658 658
 				} // End If Statement
659 659
 
660 660
 			$html .= '</div>';
661 661
 
662 662
 			// Question Container DIV
663
-			$html .= '<div id="add-question-main"' . $quiz_class . '>';
663
+			$html .= '<div id="add-question-main"'.$quiz_class.'>';
664 664
 				// Inner DIV
665 665
 				$html .= '<div id="add-question-metadata">';
666 666
 
667 667
 					// Count of questions
668
-					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="' . esc_attr( $question_count ) . '" />';
668
+					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="'.esc_attr($question_count).'" />';
669 669
 					// Table headers
670 670
 					$html .= '<table class="widefat" id="sortable-questions">
671 671
 								<thead>
672 672
 								    <tr>
673 673
 								        <th class="question-count-column">#</th>
674
-								        <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
675
-								        <th style="width:45px;">' . __( 'Grade', 'woothemes-sensei' ) . '</th>
676
-								        <th style="width:125px;">' . __( 'Type', 'woothemes-sensei' ) . '</th>
677
-								        <th style="width:125px;">' . __( 'Action', 'woothemes-sensei' ) . '</th>
674
+								        <th>' . __('Question', 'woothemes-sensei').'</th>
675
+								        <th style="width:45px;">' . __('Grade', 'woothemes-sensei').'</th>
676
+								        <th style="width:125px;">' . __('Type', 'woothemes-sensei').'</th>
677
+								        <th style="width:125px;">' . __('Action', 'woothemes-sensei').'</th>
678 678
 								    </tr>
679 679
 								</thead>
680 680
 								<tfoot>
681 681
 								    <tr>
682 682
 									    <th class="question-count-column">#</th>
683
-									    <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
684
-									    <th>' . __( 'Grade', 'woothemes-sensei' ) . '</th>
685
-									    <th>' . __( 'Type', 'woothemes-sensei' ) . '</th>
686
-									    <th>' . __( 'Action', 'woothemes-sensei' ) . '</th>
683
+									    <th>' . __('Question', 'woothemes-sensei').'</th>
684
+									    <th>' . __('Grade', 'woothemes-sensei').'</th>
685
+									    <th>' . __('Type', 'woothemes-sensei').'</th>
686
+									    <th>' . __('Action', 'woothemes-sensei').'</th>
687 687
 								    </tr>
688 688
 								</tfoot>';
689 689
 
690 690
 					$message_class = '';
691
-					if ( 0 < $question_count ) { $message_class = 'hidden'; }
691
+					if (0 < $question_count) { $message_class = 'hidden'; }
692 692
 
693
-					$html .= '<tbody id="no-questions-message" class="' . esc_attr( $message_class ) . '">';
693
+					$html .= '<tbody id="no-questions-message" class="'.esc_attr($message_class).'">';
694 694
 						$html .= '<tr>';
695
-							$html .= '<td colspan="5">' . __( 'There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei' ) . '</td>';
695
+							$html .= '<td colspan="5">'.__('There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei').'</td>';
696 696
 						$html .= '</tr>';
697 697
 					$html .= '</tbody>';
698 698
 
699
-					if( 0 < $question_count ) {
700
-						$html .= $this->quiz_panel_questions( $questions );
699
+					if (0 < $question_count) {
700
+						$html .= $this->quiz_panel_questions($questions);
701 701
 					}
702 702
 
703 703
 					$html .= '</table>';
704 704
 
705
-					if( ! isset( $this->question_order ) ) {
705
+					if ( ! isset($this->question_order)) {
706 706
 						$this->question_order = '';
707 707
 					}
708 708
 
709
-					$html .= '<input type="hidden" id="question-order" name="question-order" value="' . $this->question_order . '" />';
709
+					$html .= '<input type="hidden" id="question-order" name="question-order" value="'.$this->question_order.'" />';
710 710
 
711 711
 				$html .= '</div>';
712 712
 
@@ -725,47 +725,47 @@  discard block
 block discarded – undo
725 725
 
726 726
 	}
727 727
 
728
-	public function quiz_panel_questions( $questions = array() ) {
728
+	public function quiz_panel_questions($questions = array()) {
729 729
 		global $quiz_questions;
730 730
 
731 731
 		$quiz_questions = $questions;
732 732
 
733 733
 		$html = '';
734 734
 
735
-		if( count( $questions ) > 0 ) {
735
+		if (count($questions) > 0) {
736 736
 
737 737
 			$question_class = '';
738 738
 			$question_counter = 1;
739 739
 
740
-			foreach ( $questions as $question ) {
740
+			foreach ($questions as $question) {
741 741
 
742 742
 				$question_id = $question->ID;
743 743
 
744
-				$question_type = Sensei()->question->get_question_type( $question_id );
744
+				$question_type = Sensei()->question->get_question_type($question_id);
745 745
 
746 746
 				$multiple_data = array();
747 747
 				$question_increment = 1;
748
-				if( 'multiple_question' == $question->post_type ) {
748
+				if ('multiple_question' == $question->post_type) {
749 749
 					$question_type = 'category';
750 750
 
751
-					$question_category = get_post_meta( $question->ID, 'category', true );
752
-					$question_cat = get_term( $question_category, 'question-category' );
751
+					$question_category = get_post_meta($question->ID, 'category', true);
752
+					$question_cat = get_term($question_category, 'question-category');
753 753
 
754
-					$question_number = get_post_meta( $question->ID, 'number', true );
754
+					$question_number = get_post_meta($question->ID, 'number', true);
755 755
 					$question_increment = $question_number;
756 756
 
757
-					$multiple_data = array( $question_cat->name, $question_number );
757
+					$multiple_data = array($question_cat->name, $question_number);
758 758
 				}
759 759
 
760
-				if( ! $question_type ) {
760
+				if ( ! $question_type) {
761 761
 					$question_type = 'multiple-choice';
762 762
 				}
763 763
 
764 764
 				// Row with question and actions
765
-				$html .= $this->quiz_panel_question( $question_type, $question_counter, $question_id, 'quiz', $multiple_data );
765
+				$html .= $this->quiz_panel_question($question_type, $question_counter, $question_id, 'quiz', $multiple_data);
766 766
 				$question_counter += $question_increment;
767 767
 
768
-				if( isset( $this->question_order ) && strlen( $this->question_order ) > 0 ) { $this->question_order .= ','; }
768
+				if (isset($this->question_order) && strlen($this->question_order) > 0) { $this->question_order .= ','; }
769 769
 				$this->question_order .= $question_id;
770 770
 			} // End For Loop
771 771
 		}
@@ -774,161 +774,161 @@  discard block
 block discarded – undo
774 774
 
775 775
 	}
776 776
 
777
-	public function quiz_panel_question( $question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array() ) {
778
-		global $row_counter,  $quiz_questions;
777
+	public function quiz_panel_question($question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array()) {
778
+		global $row_counter, $quiz_questions;
779 779
 
780 780
 		$html = '';
781 781
 
782 782
 		$question_class = '';
783
-		if( 'quiz' == $context ) {
784
-			if( ! $row_counter || ! isset( $row_counter ) ) {
783
+		if ('quiz' == $context) {
784
+			if ( ! $row_counter || ! isset($row_counter)) {
785 785
 				$row_counter = 1;
786 786
 			}
787
-			if( $row_counter % 2 ) { $question_class = 'alternate'; }
787
+			if ($row_counter % 2) { $question_class = 'alternate'; }
788 788
 			++$row_counter;
789 789
 		}
790 790
 
791
-		if( $question_id ) {
791
+		if ($question_id) {
792 792
 
793
-			if( $question_type != 'category' ) {
793
+			if ($question_type != 'category') {
794 794
 
795
-				$question_grade = Sensei()->question->get_question_grade( $question_id );
795
+				$question_grade = Sensei()->question->get_question_grade($question_id);
796 796
 
797
-				$question_media = get_post_meta( $question_id, '_question_media', true );
797
+				$question_media = get_post_meta($question_id, '_question_media', true);
798 798
 				$question_media_type = $question_media_thumb = $question_media_link = $question_media_title = '';
799 799
 				$question_media_thumb_class = $question_media_link_class = $question_media_delete_class = 'hidden';
800
-				$question_media_add_button = __( 'Add file', 'woothemes-sensei' );
801
-				if( 0 < intval( $question_media ) ) {
802
-					$mimetype = get_post_mime_type( $question_media );
803
-					if( $mimetype ) {
804
-						$mimetype_array = explode( '/', $mimetype);
805
-						if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
800
+				$question_media_add_button = __('Add file', 'woothemes-sensei');
801
+				if (0 < intval($question_media)) {
802
+					$mimetype = get_post_mime_type($question_media);
803
+					if ($mimetype) {
804
+						$mimetype_array = explode('/', $mimetype);
805
+						if (isset($mimetype_array[0]) && $mimetype_array[0]) {
806 806
 							$question_media_delete_class = '';
807 807
 							$question_media_type = $mimetype_array[0];
808
-							if( 'image' == $question_media_type ) {
809
-								$question_media_thumb = wp_get_attachment_thumb_url( $question_media );
810
-								if( $question_media_thumb ) {
808
+							if ('image' == $question_media_type) {
809
+								$question_media_thumb = wp_get_attachment_thumb_url($question_media);
810
+								if ($question_media_thumb) {
811 811
 									$question_media_thumb_class = '';
812 812
 								}
813 813
 							}
814
-							$question_media_url = wp_get_attachment_url( $question_media );
815
-							if( $question_media_url ) {
816
-								$attachment = get_post( $question_media );
814
+							$question_media_url = wp_get_attachment_url($question_media);
815
+							if ($question_media_url) {
816
+								$attachment = get_post($question_media);
817 817
 								$question_media_title = $attachment->post_title;
818 818
 
819
-								if( ! $question_media_title ) {
820
-									$question_media_filename = basename( $question_media_url );
819
+								if ( ! $question_media_title) {
820
+									$question_media_filename = basename($question_media_url);
821 821
 									$question_media_title = $question_media_filename;
822 822
 								}
823
-								$question_media_link = '<a class="' . $question_media_type . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_title . '</a>';
823
+								$question_media_link = '<a class="'.$question_media_type.'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_title.'</a>';
824 824
 								$question_media_link_class = '';
825 825
 							}
826 826
 
827
-							$question_media_add_button = __( 'Change file', 'woothemes-sensei' );
827
+							$question_media_add_button = __('Change file', 'woothemes-sensei');
828 828
 						}
829 829
 					}
830 830
 				}
831 831
 
832
-				$random_order = get_post_meta( $question_id, '_random_order', true );
833
-				if( ! $random_order ) {
832
+				$random_order = get_post_meta($question_id, '_random_order', true);
833
+				if ( ! $random_order) {
834 834
 					$random_order = 'yes';
835 835
 				}
836 836
 
837
-				if( ! $question_type ) { $question_type = 'multiple-choice'; }
837
+				if ( ! $question_type) { $question_type = 'multiple-choice'; }
838 838
 			}
839 839
 
840
-			$html .= '<tbody class="' . $question_class . '">';
840
+			$html .= '<tbody class="'.$question_class.'">';
841 841
 
842
-				if( 'quiz' == $context ) {
842
+				if ('quiz' == $context) {
843 843
 					$html .= '<tr>';
844
-						if( $question_type != 'category' ) {
845
-							$question = get_post( $question_id );
846
-							$html .= '<td class="table-count question-number question-count-column"><span class="number">' . $question_counter . '</span></td>';
847
-							$html .= '<td>' . esc_html( $question->post_title ) . '</td>';
848
-							$html .= '<td class="question-grade-column">' . esc_html( $question_grade ) . '</td>';
849
-							$question_types_filtered = ucwords( str_replace( array( '-', 'boolean' ), array( ' ', __( 'True/False', 'woothemes-sensei' ) ), $question_type ) );
850
-							$html .= '<td>' . esc_html( $question_types_filtered ) . '</td>';
851
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_delete">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
844
+						if ($question_type != 'category') {
845
+							$question = get_post($question_id);
846
+							$html .= '<td class="table-count question-number question-count-column"><span class="number">'.$question_counter.'</span></td>';
847
+							$html .= '<td>'.esc_html($question->post_title).'</td>';
848
+							$html .= '<td class="question-grade-column">'.esc_html($question_grade).'</td>';
849
+							$question_types_filtered = ucwords(str_replace(array('-', 'boolean'), array(' ', __('True/False', 'woothemes-sensei')), $question_type));
850
+							$html .= '<td>'.esc_html($question_types_filtered).'</td>';
851
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_delete">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
852 852
 
853 853
 						} else {
854 854
 
855
-							$end_number = intval( $question_counter ) + intval( $multiple_data[1] ) - 1;
856
-							if( $question_counter == $end_number ) {
855
+							$end_number = intval($question_counter) + intval($multiple_data[1]) - 1;
856
+							if ($question_counter == $end_number) {
857 857
 								$row_numbers = $question_counter;
858 858
 							} else {
859
-								$row_numbers = $question_counter . ' - ' . $end_number;
859
+								$row_numbers = $question_counter.' - '.$end_number;
860 860
 							}
861
-							$row_title = sprintf( __( 'Selected from \'%1$s\' ', 'woothemes-sensei' ), $multiple_data[0] );
861
+							$row_title = sprintf(__('Selected from \'%1$s\' ', 'woothemes-sensei'), $multiple_data[0]);
862 862
 
863
-							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">' . $question_counter . '</span><span class="hidden total-number">' . $multiple_data[1] . '</span><span class="row-numbers">' . esc_html( $row_numbers ) . '</span></td>';
864
-							$html .= '<td>' . esc_html( $row_title ) . '</td>';
863
+							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">'.$question_counter.'</span><span class="hidden total-number">'.$multiple_data[1].'</span><span class="row-numbers">'.esc_html($row_numbers).'</span></td>';
864
+							$html .= '<td>'.esc_html($row_title).'</td>';
865 865
 							$html .= '<td class="question-grade-column"></td>';
866
-							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" /></td>';
867
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit" style="visibility:hidden;">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question(s)', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_multiple_delete" rel="' . $question_id . '">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
866
+							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" /></td>';
867
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit" style="visibility:hidden;">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question(s)', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_multiple_delete" rel="'.$question_id.'">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
868 868
 
869 869
 						}
870 870
 					$html .= '</tr>';
871 871
 				}
872 872
 
873
-				if( $question_type != 'category' ) {
873
+				if ($question_type != 'category') {
874 874
 
875 875
 					$edit_class = '';
876
-					if( 'quiz' == $context ) {
876
+					if ('quiz' == $context) {
877 877
 						$edit_class = 'hidden';
878 878
 					}
879 879
 
880
-					$question = get_post( $question_id );
881
-					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
880
+					$question = get_post($question_id);
881
+					$html .= '<tr class="question-quick-edit '.esc_attr($edit_class).'">';
882 882
 						$html .= '<td colspan="5">';
883
-							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
883
+							$html .= '<span class="hidden question_original_counter">'.$question_counter.'</span>';
884 884
 					    	$html .= '<div class="question_required_fields">';
885 885
 
886 886
 						    	// Question title
887 887
 						    	$html .= '<div>';
888
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
889
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
888
+							    	$html .= '<label for="question_'.$question_counter.'">'.__('Question:', 'woothemes-sensei').'</label> ';
889
+							    	$html .= '<input type="text" id="question_'.$question_counter.'" name="question" value="'.esc_attr(htmlspecialchars($question->post_title)).'" size="25" class="widefat" />';
890 890
 						    	$html .= '</div>';
891 891
 
892 892
 						    	// Question description
893 893
 						    	$html .= '<div>';
894
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
894
+							    	$html .= '<label for="question_'.$question_counter.'_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
895 895
 						    	$html .= '</div>';
896
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
896
+							    	$html .= '<textarea id="question_'.$question_counter.'_desc" name="question_description" class="widefat" rows="4">'.esc_textarea($question->post_content).'</textarea>';
897 897
 
898 898
 						    	// Question grade
899 899
 						    	$html .= '<div>';
900
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
901
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
900
+							    	$html .= '<label for="question_'.$question_counter.'_grade">'.__('Question grade:', 'woothemes-sensei').'</label> ';
901
+							    	$html .= '<input type="number" id="question_'.$question_counter.'_grade" class="question_grade small-text" name="question_grade" min="0" value="'.$question_grade.'" />';
902 902
 						    	$html .= '</div>';
903 903
 
904 904
 						    	// Random order
905
-						    	if( $question_type == 'multiple-choice' ) {
905
+						    	if ($question_type == 'multiple-choice') {
906 906
 						    		$html .= '<div>';
907
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
907
+						    			$html .= '<label for="'.$question_counter.'_random_order"><input type="checkbox" name="random_order" class="random_order" id="'.$question_counter.'_random_order" value="yes" '.checked($random_order, 'yes', false).' /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
908 908
 						    		$html .= '</div>';
909 909
 						    	}
910 910
 
911 911
 						    	// Question media
912 912
 						    	$html .= '<div>';
913
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
914
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
915
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
916
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
917
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
918
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
913
+							    	$html .= '<label for="question_'.$question_counter.'_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
914
+							    	$html .= '<button id="question_'.$question_counter.'_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.$question_media_add_button.'</button>';
915
+							    	$html .= '<button id="question_'.$question_counter.'_media_button_delete" class="delete_media_file_button button-secondary '.$question_media_delete_class.'">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
916
+							    	$html .= '<span id="question_'.$question_counter.'_media_link" class="question_media_link '.$question_media_link_class.'">'.$question_media_link.'</span>';
917
+							    	$html .= '<br/><img id="question_'.$question_counter.'_media_preview" class="question_media_preview '.$question_media_thumb_class.'" src="'.$question_media_thumb.'" /><br/>';
918
+							    	$html .= '<input type="hidden" id="question_'.$question_counter.'_media" class="question_media" name="question_media" value="'.$question_media.'" />';
919 919
 						    	$html .= '</div>';
920 920
 
921 921
 						    $html .= '</div>';
922 922
 
923
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
923
+						    $html .= $this->quiz_panel_question_field($question_type, $question_id, $question_counter);
924 924
 
925
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
926
-							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
925
+						    $html .= '<input type="hidden" id="question_'.$question_counter.'_question_type" class="question_type" name="question_type" value="'.$question_type.'" />';
926
+							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" />';
927 927
 
928
-							if( 'quiz' == $context ) {
928
+							if ('quiz' == $context) {
929 929
 					    		$html .= '<div class="update-question">';
930
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
931
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
930
+						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="'.esc_attr(__('Cancel', 'woothemes-sensei')).'">'.__('Cancel', 'woothemes-sensei').'</a> ';
931
+						    		$html .= '<a title="'.esc_attr(__('Update Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_save button button-highlighted">'.esc_html(__('Update', 'woothemes-sensei')).'</a>';
932 932
 					    		$html .= '</div>';
933 933
 					    	}
934 934
 
@@ -943,79 +943,79 @@  discard block
 block discarded – undo
943 943
 		return $html;
944 944
 	}
945 945
 
946
-	public function quiz_panel_add( $context = 'quiz' ) {
946
+	public function quiz_panel_add($context = 'quiz') {
947 947
 
948 948
 
949 949
 		$html = '<div id="add-new-question">';
950 950
 
951 951
 			$question_types = Sensei()->question->question_types();
952 952
 
953
-			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
953
+			$question_cats = get_terms('question-category', array('hide_empty' => false));
954 954
 
955
-			if( 'quiz' == $context ) {
955
+			if ('quiz' == $context) {
956 956
 	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
957
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
958
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
959
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
960
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
957
+	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">'.__('New Question', 'woothemes-sensei').'</a>';
958
+	    			$html .= '<a id="tab-existing" class="nav-tab">'.__('Existing Questions', 'woothemes-sensei').'</a>';
959
+                    if ( ! empty($question_cats) && ! is_wp_error($question_cats) && ! Sensei()->teacher->is_admin_teacher()) {
960
+	    				$html .= '<a id="tab-multiple" class="nav-tab">'.__('Category Questions', 'woothemes-sensei').'</a>';
961 961
 	    			}
962 962
 	    		$html .= '</h2>';
963 963
 	    	}
964 964
 
965 965
 	    	$html .= '<div class="tab-content" id="tab-new-content">';
966 966
 
967
-	    		if( 'quiz' == $context ) {
968
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
967
+	    		if ('quiz' == $context) {
968
+	    			$html .= '<p><em>'.sprintf(__('Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
969 969
 	    		}
970 970
 
971 971
 				$html .= '<div class="question">';
972 972
 					$html .= '<div class="question_required_fields">';
973 973
 
974 974
 						// Question title
975
-						$html .= '<p><label>' . __( 'Question:'  , 'woothemes-sensei' ) . '</label> ';
975
+						$html .= '<p><label>'.__('Question:', 'woothemes-sensei').'</label> ';
976 976
 	  					$html .= '<input type="text" id="add_question" name="question" value="" size="25" class="widefat" /></p>';
977 977
 
978 978
 						// Question description
979 979
 						$html .= '<p>';
980
-							$html .= '<label for="question_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
980
+							$html .= '<label for="question_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
981 981
 						$html .= '</p>';
982 982
 						$html .= '<textarea id="question_desc" name="question_description" class="widefat" rows="4"></textarea>';
983 983
 
984 984
 	  					// Question type
985
-						$html .= '<p><label>' . __( 'Question Type:' , 'woothemes-sensei' ) . '</label> ';
986
-						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">' . "\n";
987
-							foreach ( $question_types as $type => $label ) {
988
-								$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>' . "\n";
985
+						$html .= '<p><label>'.__('Question Type:', 'woothemes-sensei').'</label> ';
986
+						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">'."\n";
987
+							foreach ($question_types as $type => $label) {
988
+								$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>'."\n";
989 989
 							} // End For Loop
990
-						$html .= '</select></p>' . "\n";
990
+						$html .= '</select></p>'."\n";
991 991
 
992 992
 						// Question category
993
-						if( 'quiz' == $context ) {
994
-							if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
995
-								$html .= '<p><label>' . __( 'Question Category:' , 'woothemes-sensei' ) . '</label> ';
996
-								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">' . "\n";
997
-								$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>' . "\n";
998
-								foreach( $question_cats as $cat ) {
999
-									$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
993
+						if ('quiz' == $context) {
994
+							if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
995
+								$html .= '<p><label>'.__('Question Category:', 'woothemes-sensei').'</label> ';
996
+								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">'."\n";
997
+								$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'."\n";
998
+								foreach ($question_cats as $cat) {
999
+									$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1000 1000
 								} // End For Loop
1001
-								$html .= '</select></p>' . "\n";
1001
+								$html .= '</select></p>'."\n";
1002 1002
 							}
1003 1003
 						}
1004 1004
 
1005 1005
 	  					// Question grade
1006
-						$html .= '<p><label>' . __( 'Question Grade:'  , 'woothemes-sensei' ) . '</label> ';
1007
-						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>' . "\n";
1006
+						$html .= '<p><label>'.__('Question Grade:', 'woothemes-sensei').'</label> ';
1007
+						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>'."\n";
1008 1008
 
1009 1009
 						// Random order
1010 1010
 						$html .= '<p class="add_question_random_order">';
1011
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1011
+			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
1012 1012
 			    		$html .= '</p>';
1013 1013
 
1014 1014
 			    		// Question media
1015 1015
 						$html .= '<p>';
1016
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1017
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1018
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1016
+					    	$html .= '<label for="question_add_new_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
1017
+					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.__('Add file', 'woothemes-sensei').'</button>';
1018
+					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
1019 1019
 					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1020 1020
 					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1021 1021
 					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
@@ -1024,44 +1024,44 @@  discard block
 block discarded – undo
1024 1024
 					$html .= '</div>';
1025 1025
 				$html .= '</div>';
1026 1026
 
1027
-				foreach ( $question_types as $type => $label ) {
1028
-					$html .= $this->quiz_panel_question_field( $type );
1027
+				foreach ($question_types as $type => $label) {
1028
+					$html .= $this->quiz_panel_question_field($type);
1029 1029
 				}
1030 1030
 
1031
-				if( 'quiz' == $context ) {
1031
+				if ('quiz' == $context) {
1032 1032
 					$html .= '<div class="add-question">';
1033
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1033
+			    		$html .= '<a title="'.esc_attr(__('Add Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">'.esc_html(__('Add Question', 'woothemes-sensei')).'</a>';
1034 1034
 		    		$html .= '</div>';
1035 1035
 		    	}
1036 1036
 
1037 1037
 		    $html .= '</div>';
1038 1038
 
1039
-		    if( 'quiz' == $context ) {
1039
+		    if ('quiz' == $context) {
1040 1040
 
1041 1041
 			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1042 1042
 
1043
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1043
+			    	$html .= '<p><em>'.sprintf(__('Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
1044 1044
 
1045 1045
 			    	$html .= '<div id="existing-filters" class="alignleft actions">
1046 1046
 			    				<select id="existing-status">
1047
-			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1048
-			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
1049
-			    					<option value="used">' . __( 'Used', 'woothemes-sensei' ) . '</option>
1047
+			    					<option value="all">' . __('All', 'woothemes-sensei').'</option>
1048
+			    					<option value="unused">' . __('Unused', 'woothemes-sensei').'</option>
1049
+			    					<option value="used">' . __('Used', 'woothemes-sensei').'</option>
1050 1050
 			    				</select>
1051 1051
 			    				<select id="existing-type">
1052
-			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1053
-							    	foreach ( $question_types as $type => $label ) {
1054
-										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1052
+			    					<option value="">' . __('All Types', 'woothemes-sensei').'</option>';
1053
+							    	foreach ($question_types as $type => $label) {
1054
+										$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>';
1055 1055
 									}
1056 1056
     				$html .= '</select>
1057 1057
     							<select id="existing-category">
1058
-			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1059
-				    				foreach( $question_cats as $cat ) {
1060
-										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1058
+			    					<option value="">' . __('All Categories', 'woothemes-sensei').'</option>';
1059
+				    				foreach ($question_cats as $cat) {
1060
+										$html .= '<option value="'.esc_attr($cat->slug).'">'.esc_html($cat->name).'</option>';
1061 1061
 									}
1062 1062
     				$html .= '</select>
1063
-    							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1064
-    							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1063
+    							<input type="text" id="existing-search" placeholder="' . __('Search', 'woothemes-sensei').'" />
1064
+    							<a class="button" id="existing-filter-button">' . __('Filter', 'woothemes-sensei').'</a>
1065 1065
 			    			</div>';
1066 1066
 
1067 1067
 			    	$html .= '<table id="existing-table" class="widefat">';
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
 			    		$html .= '<thead>
1070 1070
 									    <tr>
1071 1071
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1072
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1073
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1074
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1072
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1073
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1074
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1075 1075
 									    </tr>
1076 1076
 									</thead>
1077 1077
 									<tfoot>
1078 1078
 									    <tr>
1079 1079
 										    <th scope="col" class="check-column"><input type="checkbox" /></th>
1080
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1081
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1082
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1080
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1081
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1082
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1083 1083
 									    </tr>
1084 1084
 									</tfoot>';
1085 1085
 						$html .= '<tbody id="existing-questions">';
@@ -1087,8 +1087,8 @@  discard block
 block discarded – undo
1087 1087
 						$questions = $this->quiz_panel_get_existing_questions();
1088 1088
 
1089 1089
 						$row = 1;
1090
-						foreach( $questions['questions'] as $question ) {
1091
-							$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1090
+						foreach ($questions['questions'] as $question) {
1091
+							$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1092 1092
 							++$row;
1093 1093
 						}
1094 1094
 
@@ -1097,36 +1097,36 @@  discard block
 block discarded – undo
1097 1097
 			    	$html .= '</table>';
1098 1098
 
1099 1099
 			    	$next_class = '';
1100
-			    	if( $questions['count'] <= 10 ) {
1100
+			    	if ($questions['count'] <= 10) {
1101 1101
 			    		$next_class = 'hidden';
1102 1102
 			    	}
1103 1103
 
1104 1104
 			    	$html .= '<div id="existing-pagination">';
1105 1105
 			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1106
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1106
+			    		$html .= '<a class="prev no-paging">&larr; '.__('Previous', 'woothemes-sensei').'</a> <a class="next '.esc_attr($next_class).'">'.__('Next', 'woothemes-sensei').' &rarr;</a>';
1107 1107
 			    	$html .= '</div>';
1108 1108
 
1109 1109
 			    	$html .= '<div class="existing-actions">';
1110
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1110
+			    		$html .= '<a title="'.esc_attr(__('Add Selected Question(s)', 'woothemes-sensei')).'" class="add_existing_save button button-primary button-highlighted">'.esc_html(__('Add Selected Question(s)', 'woothemes-sensei')).'</a></p>';
1111 1111
 			    	$html .= '</div>';
1112 1112
 
1113 1113
 			    $html .= '</div>';
1114 1114
 
1115
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1115
+			    if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
1116 1116
 				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1117 1117
 
1118
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1118
+				    	$html .= '<p><em>'.sprintf(__('Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit-tags.php?taxonomy=question-category&post_type=question').'">', '</a>').'</em></p>';
1119 1119
 
1120
-						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1121
-						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
1122
-						foreach( $question_cats as $cat ) {
1123
-							$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
1120
+						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">'."\n";
1121
+						$html .= '<option value="">'.__('Select a Question Category', 'woothemes-sensei').'</option>'."\n";
1122
+						foreach ($question_cats as $cat) {
1123
+							$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1124 1124
 						} // End For Loop
1125
-						$html .= '</select></p>' . "\n";
1125
+						$html .= '</select></p>'."\n";
1126 1126
 
1127
-						$html .= '<p>' . __( 'Number of questions:', 'woothemes-sensei' ) . ' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1127
+						$html .= '<p>'.__('Number of questions:', 'woothemes-sensei').' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1128 1128
 
1129
-						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1129
+						$html .= '<a title="'.esc_attr(__('Add Question(s)', 'woothemes-sensei')).'" class="add_multiple_save button button-primary button-highlighted">'.esc_html(__('Add Question(s)', 'woothemes-sensei')).'</a></p>';
1130 1130
 
1131 1131
 				    $html .= '</div>';
1132 1132
 				}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 		return $html;
1138 1138
 	}
1139 1139
 
1140
-	public function quiz_panel_get_existing_questions( $question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1 ) {
1140
+	public function quiz_panel_get_existing_questions($question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1) {
1141 1141
 
1142 1142
 		$args = array(
1143 1143
 			'post_type' => 'question',
@@ -1146,14 +1146,14 @@  discard block
 block discarded – undo
1146 1146
 			'suppress_filters' => 0,
1147 1147
 		);
1148 1148
 
1149
-		switch( $question_status ) {
1149
+		switch ($question_status) {
1150 1150
 			case 'unused': $quiz_status = 'NOT EXISTS'; break;
1151 1151
 			case 'used': $quiz_status = 'EXISTS'; break;
1152 1152
 			default: $quiz_status = ''; break;
1153 1153
 		}
1154 1154
 
1155
-		if( $quiz_status ) {
1156
-			switch( $quiz_status ) {
1155
+		if ($quiz_status) {
1156
+			switch ($quiz_status) {
1157 1157
 				case 'EXISTS':
1158 1158
 					$args['meta_query'][] = array(
1159 1159
 						'key' => '_quiz_id',
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
 			}
1172 1172
 		}
1173 1173
 
1174
-		if( $question_type ) {
1174
+		if ($question_type) {
1175 1175
 			$args['tax_query'][] = array(
1176 1176
 				'taxonomy' => 'question-type',
1177 1177
 				'field' => 'slug',
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 			);
1180 1180
 		}
1181 1181
 
1182
-		if( $question_category ) {
1182
+		if ($question_category) {
1183 1183
 			$args['tax_query'][] = array(
1184 1184
 				'taxonomy' => 'question-category',
1185 1185
 				'field' => 'slug',
@@ -1187,19 +1187,19 @@  discard block
 block discarded – undo
1187 1187
 			);
1188 1188
 		}
1189 1189
 
1190
-		if( $question_type && $question_category ) {
1190
+		if ($question_type && $question_category) {
1191 1191
 			$args['tax_query']['relation'] = 'AND';
1192 1192
 		}
1193 1193
 
1194
-		if( $question_search ) {
1194
+		if ($question_search) {
1195 1195
 			$args['s'] = $question_search;
1196 1196
 		}
1197 1197
 
1198
-		if( $page ) {
1198
+		if ($page) {
1199 1199
 			$args['paged'] = $page;
1200 1200
 		}
1201 1201
 
1202
-		$qry = new WP_Query( $args );
1202
+		$qry = new WP_Query($args);
1203 1203
 
1204 1204
         /**
1205 1205
          * Filter existing questions query
@@ -1208,39 +1208,39 @@  discard block
 block discarded – undo
1208 1208
          *
1209 1209
          * @param WP_Query $wp_query
1210 1210
          */
1211
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1211
+        $qry = apply_filters('sensei_existing_questions_query_results', $qry);
1212 1212
 
1213 1213
 		$questions['questions'] = $qry->posts;
1214
-		$questions['count'] = intval( $qry->found_posts );
1214
+		$questions['count'] = intval($qry->found_posts);
1215 1215
 		$questions['page'] = $page;
1216 1216
 
1217 1217
 		return $questions;
1218 1218
 	}
1219 1219
 
1220
-	public function quiz_panel_add_existing_question( $question_id = 0, $row = 1 ) {
1220
+	public function quiz_panel_add_existing_question($question_id = 0, $row = 1) {
1221 1221
 
1222 1222
 		$html = '';
1223 1223
 
1224
-		if( ! $question_id ) {
1224
+		if ( ! $question_id) {
1225 1225
 
1226 1226
             return;
1227 1227
 
1228 1228
         }
1229 1229
 
1230 1230
 		$existing_class = '';
1231
-		if( $row % 2 ) {
1231
+		if ($row % 2) {
1232 1232
             $existing_class = 'alternate';
1233 1233
         }
1234 1234
 
1235
-		$question_type = Sensei()->question->get_question_type( $question_id );
1235
+		$question_type = Sensei()->question->get_question_type($question_id);
1236 1236
 
1237
-		$question_cat_list = strip_tags( get_the_term_list( $question_id, 'question-category', '', ', ', '' ) );
1237
+		$question_cat_list = strip_tags(get_the_term_list($question_id, 'question-category', '', ', ', ''));
1238 1238
 
1239
-		$html .= '<tr class="' . esc_attr( $existing_class ) . '">
1240
-					<td class="cb"><input type="checkbox" value="' . $question_id . '" class="existing-item" /></td>
1241
-					<td>' . get_the_title( $question_id ) . '</td>
1242
-					<td>' . esc_html( $question_type ) . '</td>
1243
-					<td>' . esc_html( $question_cat_list ) . '</td>
1239
+		$html .= '<tr class="'.esc_attr($existing_class).'">
1240
+					<td class="cb"><input type="checkbox" value="' . $question_id.'" class="existing-item" /></td>
1241
+					<td>' . get_the_title($question_id).'</td>
1242
+					<td>' . esc_html($question_type).'</td>
1243
+					<td>' . esc_html($question_cat_list).'</td>
1244 1244
 				  </tr>';
1245 1245
 
1246 1246
 		return $html;
@@ -1253,58 +1253,58 @@  discard block
 block discarded – undo
1253 1253
 
1254 1254
 		//Add nonce security to the request
1255 1255
 		$nonce = '';
1256
-		if( isset( $_POST['filter_existing_questions_nonce'] ) ) {
1257
-			$nonce = esc_html( $_POST['filter_existing_questions_nonce'] );
1256
+		if (isset($_POST['filter_existing_questions_nonce'])) {
1257
+			$nonce = esc_html($_POST['filter_existing_questions_nonce']);
1258 1258
 		} // End If Statement
1259 1259
 
1260
-		if( ! wp_verify_nonce( $nonce, 'filter_existing_questions_nonce' ) ) {
1261
-			die( $return );
1260
+		if ( ! wp_verify_nonce($nonce, 'filter_existing_questions_nonce')) {
1261
+			die($return);
1262 1262
 		} // End If Statement
1263 1263
 
1264 1264
 		// Parse POST data
1265 1265
 		$data = $_POST['data'];
1266 1266
 		$question_data = array();
1267
-		parse_str( $data, $question_data );
1267
+		parse_str($data, $question_data);
1268 1268
 
1269
-		if( 0 < count( $question_data ) ) {
1269
+		if (0 < count($question_data)) {
1270 1270
 
1271 1271
 			$question_status = '';
1272
-			if( isset( $question_data['question_status'] ) ) {
1272
+			if (isset($question_data['question_status'])) {
1273 1273
 				$question_status = $question_data['question_status'];
1274 1274
 			}
1275 1275
 
1276 1276
 			$question_type = '';
1277
-			if( isset( $question_data['question_type'] ) ) {
1277
+			if (isset($question_data['question_type'])) {
1278 1278
 				$question_type = $question_data['question_type'];
1279 1279
 			}
1280 1280
 
1281 1281
 			$question_category = '';
1282
-			if( isset( $question_data['question_category'] ) ) {
1282
+			if (isset($question_data['question_category'])) {
1283 1283
 				$question_category = $question_data['question_category'];
1284 1284
 			}
1285 1285
 
1286 1286
 			$question_search = '';
1287
-			if( isset( $question_data['question_search'] ) ) {
1287
+			if (isset($question_data['question_search'])) {
1288 1288
 				$question_search = $question_data['question_search'];
1289 1289
 			}
1290 1290
 
1291 1291
 			$question_page = 1;
1292
-			if( isset( $question_data['question_page'] ) ) {
1293
-				$question_page = intval( $question_data['question_page'] );
1292
+			if (isset($question_data['question_page'])) {
1293
+				$question_page = intval($question_data['question_page']);
1294 1294
 			}
1295 1295
 
1296
-			$questions = $this->quiz_panel_get_existing_questions( $question_status, $question_type, $question_category, $question_search, $question_page );
1296
+			$questions = $this->quiz_panel_get_existing_questions($question_status, $question_type, $question_category, $question_search, $question_page);
1297 1297
 
1298 1298
 			$row = 1;
1299 1299
 			$html = '';
1300
-			foreach( $questions['questions'] as $question ) {
1301
-				$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1300
+			foreach ($questions['questions'] as $question) {
1301
+				$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1302 1302
 				++$row;
1303 1303
 			}
1304 1304
 
1305
-			if( ! $html ) {
1305
+			if ( ! $html) {
1306 1306
 				$html = '<tr class="alternate">
1307
-								<td class="no-results" colspan="4"><em>' . __( 'There are no questions matching your search.', 'woothemes-sensei' ) . '</em></td>
1307
+								<td class="no-results" colspan="4"><em>' . __('There are no questions matching your search.', 'woothemes-sensei').'</em></td>
1308 1308
 							  </tr>';
1309 1309
 			}
1310 1310
 
@@ -1312,53 +1312,53 @@  discard block
 block discarded – undo
1312 1312
 			$return['count'] = $questions['count'];
1313 1313
 			$return['page'] = $questions['page'];
1314 1314
 
1315
-			wp_send_json( $return );
1315
+			wp_send_json($return);
1316 1316
 		}
1317 1317
 
1318
-		die( $return );
1318
+		die($return);
1319 1319
 	}
1320 1320
 
1321
-	public function quiz_panel_question_field( $question_type = '', $question_id = 0, $question_counter = 0 ) {
1321
+	public function quiz_panel_question_field($question_type = '', $question_id = 0, $question_counter = 0) {
1322 1322
 
1323 1323
 		$html = '';
1324 1324
 
1325
-		if( $question_type ) {
1325
+		if ($question_type) {
1326 1326
 
1327 1327
 			$right_answer = '';
1328 1328
 			$wrong_answers = array();
1329 1329
 			$answer_order_string = '';
1330 1330
 			$answer_order = array();
1331
-			if( $question_id ) {
1332
-				$right_answer = get_post_meta( $question_id, '_question_right_answer', true);
1333
-				$wrong_answers = get_post_meta( $question_id, '_question_wrong_answers', true);
1334
-				$answer_order_string = get_post_meta( $question_id, '_answer_order', true );
1335
-				$answer_order = array_filter( explode( ',', $answer_order_string ) );
1331
+			if ($question_id) {
1332
+				$right_answer = get_post_meta($question_id, '_question_right_answer', true);
1333
+				$wrong_answers = get_post_meta($question_id, '_question_wrong_answers', true);
1334
+				$answer_order_string = get_post_meta($question_id, '_answer_order', true);
1335
+				$answer_order = array_filter(explode(',', $answer_order_string));
1336 1336
 				$question_class = '';
1337 1337
 			} else {
1338 1338
 				$question_id = '';
1339 1339
 				$question_class = 'answer-fields question_required_fields hidden';
1340 1340
 			}
1341 1341
 
1342
-			switch ( $question_type ) {
1342
+			switch ($question_type) {
1343 1343
 				case 'multiple-choice':
1344
-					$html .= '<div class="question_default_fields multiple-choice-answers ' . str_replace( ' hidden', '', $question_class ) . '">';
1344
+					$html .= '<div class="question_default_fields multiple-choice-answers '.str_replace(' hidden', '', $question_class).'">';
1345 1345
 
1346 1346
 						$right_answers = (array) $right_answer;
1347 1347
 						// Calculate total right answers available (defaults to 1)
1348 1348
 						$total_right = 0;
1349
-						if( $question_id ) {
1350
-							$total_right = get_post_meta( $question_id, '_right_answer_count', true );
1349
+						if ($question_id) {
1350
+							$total_right = get_post_meta($question_id, '_right_answer_count', true);
1351 1351
 						}
1352
-						if( 0 == intval( $total_right ) ) {
1352
+						if (0 == intval($total_right)) {
1353 1353
 							$total_right = 1;
1354 1354
 						}
1355
-						for ( $i = 0; $i < $total_right; $i++ ) {
1356
-							if ( !isset( $right_answers[ $i ] ) ) { $right_answers[ $i ] = ''; }
1357
-							$right_answer_id = $this->get_answer_id( $right_answers[ $i ] );
1355
+						for ($i = 0; $i < $total_right; $i++) {
1356
+							if ( ! isset($right_answers[$i])) { $right_answers[$i] = ''; }
1357
+							$right_answer_id = $this->get_answer_id($right_answers[$i]);
1358 1358
 							// Right Answer
1359
-							$right_answer = '<label class="answer" for="question_' . $question_counter . '_right_answer_' . $i . '"><span>' . __( 'Right:' , 'woothemes-sensei' ) . '</span> <input rel="' . esc_attr( $right_answer_id ) . '" type="text" id="question_' . $question_counter . '_right_answer_' . $i . '" name="question_right_answers[]" value="' . esc_attr( $right_answers[ $i ] ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
-							if( $question_id ) {
1361
-								$answers[ $right_answer_id ] = $right_answer;
1359
+							$right_answer = '<label class="answer" for="question_'.$question_counter.'_right_answer_'.$i.'"><span>'.__('Right:', 'woothemes-sensei').'</span> <input rel="'.esc_attr($right_answer_id).'" type="text" id="question_'.$question_counter.'_right_answer_'.$i.'" name="question_right_answers[]" value="'.esc_attr($right_answers[$i]).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
+							if ($question_id) {
1361
+								$answers[$right_answer_id] = $right_answer;
1362 1362
 							} else {
1363 1363
 								$answers[] = $right_answer;
1364 1364
 							}
@@ -1366,23 +1366,23 @@  discard block
 block discarded – undo
1366 1366
 
1367 1367
 				    	// Calculate total wrong answers available (defaults to 4)
1368 1368
 				    	$total_wrong = 0;
1369
-				    	if( $question_id ) {
1370
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1369
+				    	if ($question_id) {
1370
+				    		$total_wrong = get_post_meta($question_id, '_wrong_answer_count', true);
1371 1371
 				    	}
1372
-				    	if( 0 == intval( $total_wrong ) ) {
1372
+				    	if (0 == intval($total_wrong)) {
1373 1373
 				    		$total_wrong = 1;
1374 1374
 				    	}
1375 1375
 
1376 1376
                         // Setup Wrong Answer HTML
1377
-                        foreach ( $wrong_answers as $i => $answer ){
1377
+                        foreach ($wrong_answers as $i => $answer) {
1378 1378
 
1379
-                            $answer_id = $this->get_answer_id( $answer );
1380
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1381
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1382
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
-                            if( $question_id ) {
1379
+                            $answer_id = $this->get_answer_id($answer);
1380
+                            $wrong_answer = '<label class="answer" for="question_'.$question_counter.'_wrong_answer_'.$i.'"><span>'.__('Wrong:', 'woothemes-sensei');
1381
+                            $wrong_answer .= '</span> <input rel="'.esc_attr($answer_id).'" type="text" id="question_'.$question_counter.'_wrong_answer_'.$i;
1382
+                            $wrong_answer .= '" name="question_wrong_answers[]" value="'.esc_attr($answer).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
+                            if ($question_id) {
1384 1384
 
1385
-                                $answers[ $answer_id ] = $wrong_answer;
1385
+                                $answers[$answer_id] = $wrong_answer;
1386 1386
 
1387 1387
                             } else {
1388 1388
 
@@ -1393,115 +1393,115 @@  discard block
 block discarded – undo
1393 1393
                         } // end for each
1394 1394
 
1395 1395
 				    	$answers_sorted = $answers;
1396
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1396
+				    	if ($question_id && count($answer_order) > 0) {
1397 1397
 				    		$answers_sorted = array();
1398
-				    		foreach( $answer_order as $answer_id ) {
1399
-				    			if( isset( $answers[ $answer_id ] ) ) {
1400
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1401
-				    				unset( $answers[ $answer_id ] );
1398
+				    		foreach ($answer_order as $answer_id) {
1399
+				    			if (isset($answers[$answer_id])) {
1400
+				    				$answers_sorted[$answer_id] = $answers[$answer_id];
1401
+				    				unset($answers[$answer_id]);
1402 1402
 				    			}
1403 1403
 				    		}
1404 1404
 
1405
-				    		if( count( $answers ) > 0 ) {
1406
-						    	foreach( $answers as $id => $answer ) {
1407
-						    		$answers_sorted[ $id ] = $answer;
1405
+				    		if (count($answers) > 0) {
1406
+						    	foreach ($answers as $id => $answer) {
1407
+						    		$answers_sorted[$id] = $answer;
1408 1408
 						    	}
1409 1409
 						    }
1410 1410
 				    	}
1411 1411
 
1412
-						foreach( $answers_sorted as $id => $answer ) {
1412
+						foreach ($answers_sorted as $id => $answer) {
1413 1413
 				    		$html .= $answer;
1414 1414
 				    	}
1415 1415
 
1416
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1417
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1418
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1416
+				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="'.$answer_order_string.'" />';
1417
+				    	$html .= '<span class="hidden right_answer_count">'.$total_right.'</span>';
1418
+				    	$html .= '<span class="hidden wrong_answer_count">'.$total_wrong.'</span>';
1419 1419
 
1420 1420
 				    	$html .= '<div class="add_answer_options">';
1421
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1422
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1421
+					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add right answer', 'woothemes-sensei').'</a>';
1422
+					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add wrong answer', 'woothemes-sensei').'</a>';
1423 1423
 				    	$html .= '</div>';
1424 1424
 
1425
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1425
+                        $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'multiple-choice');
1426 1426
 
1427 1427
 			    	$html .= '</div>';
1428 1428
 				break;
1429 1429
 				case 'boolean':
1430
-					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
1431
-						if( $question_id ) {
1432
-							$field_name = 'question_' . $question_id . '_right_answer_boolean';
1430
+					$html .= '<div class="question_boolean_fields '.$question_class.'">';
1431
+						if ($question_id) {
1432
+							$field_name = 'question_'.$question_id.'_right_answer_boolean';
1433 1433
 						} else {
1434 1434
 							$field_name = 'question_right_answer_boolean';
1435 1435
 							$right_answer = 'true';
1436 1436
 						}
1437
-						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1438
-						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1437
+						$html .= '<label for="question_'.$question_id.'_boolean_true"><input id="question_'.$question_id.'_boolean_true" type="radio" name="'.$field_name.'" value="true" '.checked($right_answer, 'true', false).' /> '.__('True', 'woothemes-sensei').'</label>';
1438
+						$html .= '<label for="question_'.$question_id.'_boolean_false"><input id="question_'.$question_id.'_boolean_false" type="radio" name="'.$field_name.'" value="false" '.checked($right_answer, 'false', false).' /> '.__('False', 'woothemes-sensei').'</label>';
1439 1439
 
1440
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1440
+                    $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'boolean');
1441 1441
 
1442 1442
 					$html .= '</div>';
1443 1443
 				break;
1444 1444
 				case 'gap-fill':
1445
-					$gapfill_array = explode( '||', $right_answer );
1446
-					if ( isset( $gapfill_array[0] ) ) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
-					if ( isset( $gapfill_array[1] ) ) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
-					if ( isset( $gapfill_array[2] ) ) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
-					$html .= '<div class="question_gapfill_fields ' . $question_class . '">';
1445
+					$gapfill_array = explode('||', $right_answer);
1446
+					if (isset($gapfill_array[0])) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
+					if (isset($gapfill_array[1])) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
+					if (isset($gapfill_array[2])) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
+					$html .= '<div class="question_gapfill_fields '.$question_class.'">';
1450 1450
 						// Fill in the Gaps
1451
-						$html .= '<label>' . __( 'Text before the Gap:' , 'woothemes-sensei' ) . '</label> ';
1452
-						$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="' . $gapfill_pre . '" size="25" class="widefat gapfill-field" />';
1453
-	  					$html .= '<label>' . __( 'The Gap:' , 'woothemes-sensei' ) . '</label> ';
1454
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="' . $gapfill_gap . '" size="25" class="widefat gapfill-field" />';
1455
-	  					$html .= '<label>' . __( 'Text after the Gap:' , 'woothemes-sensei' ) . '</label> ';
1456
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="' . $gapfill_post . '" size="25" class="widefat gapfill-field" />';
1457
-	  					$html .= '<label>' . __( 'Preview:' , 'woothemes-sensei' ) . '</label> ';
1458
-	  					$html .= '<p class="gapfill-preview">' . $gapfill_pre . '&nbsp;<u>' . $gapfill_gap . '</u>&nbsp;' . $gapfill_post . '</p>';
1451
+						$html .= '<label>'.__('Text before the Gap:', 'woothemes-sensei').'</label> ';
1452
+						$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="'.$gapfill_pre.'" size="25" class="widefat gapfill-field" />';
1453
+	  					$html .= '<label>'.__('The Gap:', 'woothemes-sensei').'</label> ';
1454
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="'.$gapfill_gap.'" size="25" class="widefat gapfill-field" />';
1455
+	  					$html .= '<label>'.__('Text after the Gap:', 'woothemes-sensei').'</label> ';
1456
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="'.$gapfill_post.'" size="25" class="widefat gapfill-field" />';
1457
+	  					$html .= '<label>'.__('Preview:', 'woothemes-sensei').'</label> ';
1458
+	  					$html .= '<p class="gapfill-preview">'.$gapfill_pre.'&nbsp;<u>'.$gapfill_gap.'</u>&nbsp;'.$gapfill_post.'</p>';
1459 1459
 	  				$html .= '</div>';
1460 1460
 				break;
1461 1461
 				case 'multi-line':
1462
-					$html .= '<div class="question_multiline_fields ' . $question_class . '">';
1462
+					$html .= '<div class="question_multiline_fields '.$question_class.'">';
1463 1463
 						// Guides for grading
1464
-						if( $question_counter ) {
1465
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_multiline';
1464
+						if ($question_counter) {
1465
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_multiline';
1466 1466
 						} else {
1467 1467
 							$field_id = 'add_question_right_answer_multiline';
1468 1468
 						}
1469
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the answer' , 'woothemes-sensei' ) . '</label> ';
1470
-						$html .= '<textarea id="' . $field_id . '" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1469
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the answer', 'woothemes-sensei').'</label> ';
1470
+						$html .= '<textarea id="'.$field_id.'" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1471 1471
 					$html .= '</div>';
1472 1472
 				break;
1473 1473
 				case 'single-line':
1474
-					$html .= '<div class="question_singleline_fields ' . $question_class . '">';
1474
+					$html .= '<div class="question_singleline_fields '.$question_class.'">';
1475 1475
 						// Recommended Answer
1476
-						if( $question_counter ) {
1477
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_singleline';
1476
+						if ($question_counter) {
1477
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_singleline';
1478 1478
 						} else {
1479 1479
 							$field_id = 'add_question_right_answer_singleline';
1480 1480
 						}
1481
-						$html .= '<label>' . __( 'Recommended Answer' , 'woothemes-sensei' ) . '</label> ';
1482
-						$html .= '<input type="text" id="' . $field_id . '" name="add_question_right_answer_singleline" value="' . $right_answer . '" size="25" class="widefat" />';
1481
+						$html .= '<label>'.__('Recommended Answer', 'woothemes-sensei').'</label> ';
1482
+						$html .= '<input type="text" id="'.$field_id.'" name="add_question_right_answer_singleline" value="'.$right_answer.'" size="25" class="widefat" />';
1483 1483
 					$html .= '</div>';
1484 1484
 				break;
1485 1485
 				case 'file-upload':
1486
-					$html .= '<div class="question_fileupload_fields ' . $question_class . '">';
1487
-						if( $question_counter ) {
1488
-							$right_field_id = 'question_' . $question_counter . '_add_question_right_answer_fileupload';
1489
-							$wrong_field_id = 'question_' . $question_counter . '_add_question_wrong_answer_fileupload';
1486
+					$html .= '<div class="question_fileupload_fields '.$question_class.'">';
1487
+						if ($question_counter) {
1488
+							$right_field_id = 'question_'.$question_counter.'_add_question_right_answer_fileupload';
1489
+							$wrong_field_id = 'question_'.$question_counter.'_add_question_wrong_answer_fileupload';
1490 1490
 						} else {
1491 1491
 							$right_field_id = 'add_question_right_answer_fileupload';
1492 1492
 							$wrong_field_id = 'add_question_wrong_answer_fileupload';
1493 1493
 						}
1494 1494
 
1495 1495
 						$wrong_answer = '';
1496
-						if( isset( $wrong_answers[0] ) ) {
1496
+						if (isset($wrong_answers[0])) {
1497 1497
 							$wrong_answer = $wrong_answers[0];
1498 1498
 						}
1499
-						$html .= '<label>' . __( 'Description for student explaining what needs to be uploaded' , 'woothemes-sensei' ) . '</label> ';
1500
-						$html .= '<textarea id="' . $wrong_field_id . '" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">' . $wrong_answer . '</textarea>';
1499
+						$html .= '<label>'.__('Description for student explaining what needs to be uploaded', 'woothemes-sensei').'</label> ';
1500
+						$html .= '<textarea id="'.$wrong_field_id.'" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">'.$wrong_answer.'</textarea>';
1501 1501
 
1502 1502
 						// Guides for grading
1503
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the upload' , 'woothemes-sensei' ) . '</label> ';
1504
-						$html .= '<textarea id="' . $right_field_id . '" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1503
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the upload', 'woothemes-sensei').'</label> ';
1504
+						$html .= '<textarea id="'.$right_field_id.'" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1505 1505
 					$html .= '</div>';
1506 1506
 				break;
1507 1507
 			}
@@ -1510,32 +1510,32 @@  discard block
 block discarded – undo
1510 1510
 		return $html;
1511 1511
 	}
1512 1512
 
1513
-	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1513
+	public function quiz_panel_question_feedback($question_counter = 0, $question_id = 0, $question_type = '') {
1514 1514
 
1515 1515
         // default field name
1516 1516
         $field_name = 'answer_feedback';
1517
-        if( 'boolean' == $question_type ){
1517
+        if ('boolean' == $question_type) {
1518 1518
 
1519 1519
             $field_name = 'answer_feedback_boolean';
1520 1520
 
1521
-        }elseif( 'multiple-choice' == $question_type ){
1521
+        }elseif ('multiple-choice' == $question_type) {
1522 1522
 
1523 1523
             $field_name = 'answer_feedback_multiple_choice';
1524 1524
 
1525 1525
         }// end if
1526 1526
 
1527
-		if( $question_counter ) {
1528
-			$field_name = 'answer_' . $question_counter . '_feedback';
1527
+		if ($question_counter) {
1528
+			$field_name = 'answer_'.$question_counter.'_feedback';
1529 1529
 		}
1530 1530
 
1531 1531
 		$feedback = '';
1532
-		if( $question_id ) {
1533
-			$feedback = get_post_meta( $question_id, '_answer_feedback', true );
1532
+		if ($question_id) {
1533
+			$feedback = get_post_meta($question_id, '_answer_feedback', true);
1534 1534
 		}
1535 1535
 
1536
-		$html = '<p title="' . __( 'This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei' ) . '">';
1537
-		$html .= '<label for="' . $field_name . '">' . __( 'Answer Feedback' , 'woothemes-sensei' ) . ':</label>';
1538
-		$html .= '<textarea id="' . $field_name . '" name="' . $field_name . '" rows="4" cols="40" class="answer_feedback widefat">' . $feedback . '</textarea>';
1536
+		$html = '<p title="'.__('This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei').'">';
1537
+		$html .= '<label for="'.$field_name.'">'.__('Answer Feedback', 'woothemes-sensei').':</label>';
1538
+		$html .= '<textarea id="'.$field_name.'" name="'.$field_name.'" rows="4" cols="40" class="answer_feedback widefat">'.$feedback.'</textarea>';
1539 1539
 		$html .= '</p>';
1540 1540
 
1541 1541
 		return $html;
@@ -1544,19 +1544,19 @@  discard block
 block discarded – undo
1544 1544
 	public function question_get_answer_id() {
1545 1545
 		$data = $_POST['data'];
1546 1546
 		$answer_data = array();
1547
-		parse_str( $data, $answer_data );
1547
+		parse_str($data, $answer_data);
1548 1548
 		$answer = $answer_data['answer_value'];
1549
-		$answer_id = $this->get_answer_id( $answer );
1549
+		$answer_id = $this->get_answer_id($answer);
1550 1550
 		echo $answer_id;
1551 1551
 		die();
1552 1552
 	}
1553 1553
 
1554
-	public function get_answer_id( $answer = '' ) {
1554
+	public function get_answer_id($answer = '') {
1555 1555
 
1556 1556
 		$answer_id = '';
1557 1557
 
1558
-		if( $answer ) {
1559
-			$answer_id = md5( $answer );
1558
+		if ($answer) {
1559
+			$answer_id = md5($answer);
1560 1560
 		}
1561 1561
 
1562 1562
 		return $answer_id;
@@ -1569,17 +1569,17 @@  discard block
 block discarded – undo
1569 1569
 	 * @access public
1570 1570
 	 * @return void
1571 1571
 	 */
1572
-	public function lesson_quiz_meta_box_content () {
1572
+	public function lesson_quiz_meta_box_content() {
1573 1573
 		global $post;
1574 1574
 
1575 1575
 		// Get quiz panel
1576 1576
 		$quiz_id = 0;
1577 1577
 		$quizzes = array();
1578
-		if ( 0 < $post->ID ) {
1579
-			$quiz_id = $this->lesson_quizzes( $post->ID, 'any' );
1578
+		if (0 < $post->ID) {
1579
+			$quiz_id = $this->lesson_quizzes($post->ID, 'any');
1580 1580
 		}
1581 1581
 
1582
-		echo $this->quiz_panel( $quiz_id );
1582
+		echo $this->quiz_panel($quiz_id);
1583 1583
 
1584 1584
 	} // End lesson_quiz_meta_box_content()
1585 1585
 
@@ -1596,53 +1596,53 @@  discard block
 block discarded – undo
1596 1596
 		$quiz_id = 0;
1597 1597
 		$lesson_id = $post->ID;
1598 1598
 		$quizzes = array();
1599
-		if ( 0 < $lesson_id ) {
1600
-			$quiz_id = $this->lesson_quizzes( $lesson_id, 'any' );
1599
+		if (0 < $lesson_id) {
1600
+			$quiz_id = $this->lesson_quizzes($lesson_id, 'any');
1601 1601
 		}
1602 1602
 
1603
-		if( $quiz_id ) {
1604
-			$html .= $this->quiz_settings_panel( $lesson_id, $quiz_id );
1603
+		if ($quiz_id) {
1604
+			$html .= $this->quiz_settings_panel($lesson_id, $quiz_id);
1605 1605
 		} else {
1606
-			$html .= '<p><em>' . __( 'There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei' ) . '</em></p>';
1606
+			$html .= '<p><em>'.__('There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei').'</em></p>';
1607 1607
 		}
1608 1608
 
1609 1609
 		echo $html;
1610 1610
 	}
1611 1611
 
1612
-	public function quiz_settings_panel( $lesson_id = 0, $quiz_id = 0 ) {
1612
+	public function quiz_settings_panel($lesson_id = 0, $quiz_id = 0) {
1613 1613
 
1614 1614
 
1615 1615
 		$html = '';
1616 1616
 
1617
-		if( ! $lesson_id && ! $quiz_id ) return $html;
1617
+		if ( ! $lesson_id && ! $quiz_id) return $html;
1618 1618
 
1619
-		$settings = $this->get_quiz_settings( $quiz_id );
1619
+		$settings = $this->get_quiz_settings($quiz_id);
1620 1620
 
1621
-		$html = Sensei()->admin->render_settings( $settings, $quiz_id, 'quiz-settings' );
1621
+		$html = Sensei()->admin->render_settings($settings, $quiz_id, 'quiz-settings');
1622 1622
 
1623 1623
 		return $html;
1624 1624
 
1625 1625
 	}
1626 1626
 
1627
-	public function get_quiz_settings( $quiz_id = 0 ) {
1627
+	public function get_quiz_settings($quiz_id = 0) {
1628 1628
 
1629 1629
 		$disable_passmark = '';
1630
-		$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1631
-		if( ! $pass_required ) {
1630
+		$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1631
+		if ( ! $pass_required) {
1632 1632
 			$disable_passmark = 'hidden';
1633 1633
 		}
1634 1634
 
1635 1635
 		// Setup Questions Query
1636 1636
 		$questions = array();
1637
-		if ( 0 < $quiz_id ) {
1638
-			$questions = $this->lesson_quiz_questions( $quiz_id );
1637
+		if (0 < $quiz_id) {
1638
+			$questions = $this->lesson_quiz_questions($quiz_id);
1639 1639
 		}
1640 1640
 
1641 1641
 		// Count questions
1642 1642
 		$question_count = 0;
1643
-		foreach( $questions as $question ) {
1644
-			if( $question->post_type == 'multiple_question' ) {
1645
-				$question_number = get_post_meta( $question->ID, 'number', true );
1643
+		foreach ($questions as $question) {
1644
+			if ($question->post_type == 'multiple_question') {
1645
+				$question_number = get_post_meta($question->ID, 'number', true);
1646 1646
 				$question_count += $question_number;
1647 1647
 			} else {
1648 1648
 				++$question_count;
@@ -1652,15 +1652,15 @@  discard block
 block discarded – undo
1652 1652
 		$settings = array(
1653 1653
 			array(
1654 1654
 				'id' 			=> 'pass_required',
1655
-				'label'			=> __( 'Pass required to complete lesson', 'woothemes-sensei' ),
1656
-				'description'	=> __( 'The passmark must be achieved before the lesson is complete.', 'woothemes-sensei' ),
1655
+				'label'			=> __('Pass required to complete lesson', 'woothemes-sensei'),
1656
+				'description'	=> __('The passmark must be achieved before the lesson is complete.', 'woothemes-sensei'),
1657 1657
 				'type'			=> 'checkbox',
1658 1658
 				'default'		=> '',
1659 1659
 				'checked'		=> 'on',
1660 1660
 			),
1661 1661
 			array(
1662 1662
 				'id' 			=> 'quiz_passmark',
1663
-				'label'			=> __( 'Quiz passmark percentage', 'woothemes-sensei' ),
1663
+				'label'			=> __('Quiz passmark percentage', 'woothemes-sensei'),
1664 1664
 				'description'	=> '',
1665 1665
 				'type'			=> 'number',
1666 1666
 				'default'		=> 0,
@@ -1671,17 +1671,17 @@  discard block
 block discarded – undo
1671 1671
 			),
1672 1672
 			array(
1673 1673
 				'id' 			=> 'show_questions',
1674
-				'label'			=> __( 'Number of questions to show', 'woothemes-sensei' ),
1675
-				'description'	=> __( 'Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei' ),
1674
+				'label'			=> __('Number of questions to show', 'woothemes-sensei'),
1675
+				'description'	=> __('Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei'),
1676 1676
 				'type'			=> 'number',
1677 1677
 				'default'		=> '',
1678
-				'placeholder'	=> __( 'All', 'woothemes-sensei' ),
1678
+				'placeholder'	=> __('All', 'woothemes-sensei'),
1679 1679
 				'min'			=> 1,
1680 1680
 				'max'			=> $question_count,
1681 1681
 			),
1682 1682
 			array(
1683 1683
 				'id' 			=> 'random_question_order',
1684
-				'label'			=> __( 'Randomise question order', 'woothemes-sensei' ),
1684
+				'label'			=> __('Randomise question order', 'woothemes-sensei'),
1685 1685
 				'description'	=> '',
1686 1686
 				'type'			=> 'checkbox',
1687 1687
 				'default'		=> 'no',
@@ -1689,23 +1689,23 @@  discard block
 block discarded – undo
1689 1689
 			),
1690 1690
 			array(
1691 1691
 				'id' 			=> 'quiz_grade_type',
1692
-				'label'			=> __( 'Grade quiz automatically', 'woothemes-sensei' ),
1693
-				'description'	=> __( 'Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei' ),
1692
+				'label'			=> __('Grade quiz automatically', 'woothemes-sensei'),
1693
+				'description'	=> __('Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei'),
1694 1694
 				'type'			=> 'checkbox',
1695 1695
 				'default'		=> 'auto',
1696 1696
 				'checked'		=> 'auto',
1697 1697
 			),
1698 1698
 			array(
1699 1699
 				'id' 			=> 'enable_quiz_reset',
1700
-				'label'			=> __( 'Allow user to retake the quiz', 'woothemes-sensei' ),
1701
-				'description'	=> __( 'Enables the quiz reset button.', 'woothemes-sensei' ),
1700
+				'label'			=> __('Allow user to retake the quiz', 'woothemes-sensei'),
1701
+				'description'	=> __('Enables the quiz reset button.', 'woothemes-sensei'),
1702 1702
 				'type'			=> 'checkbox',
1703 1703
 				'default'		=> '',
1704 1704
 				'checked'		=> 'on',
1705 1705
 			),
1706 1706
 		);
1707 1707
 
1708
-		return apply_filters( 'sensei_quiz_settings', $settings );
1708
+		return apply_filters('sensei_quiz_settings', $settings);
1709 1709
 	}
1710 1710
 
1711 1711
 	/**
@@ -1714,38 +1714,38 @@  discard block
 block discarded – undo
1714 1714
 	 * @access public
1715 1715
 	 * @return void
1716 1716
 	 */
1717
-	public function enqueue_scripts( $hook ) {
1717
+	public function enqueue_scripts($hook) {
1718 1718
 		global  $post_type;
1719 1719
 
1720
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) );
1721
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1722
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order' ) );
1720
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question'));
1721
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1722
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order'));
1723 1723
 
1724 1724
 		// Test for Write Panel Pages
1725
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1725
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1726 1726
 
1727
-			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1727
+			$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1728 1728
 
1729 1729
 			// Load the lessons script
1730 1730
             wp_enqueue_media();
1731
-			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'sensei-core-select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1732
-			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1733
-			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1731
+			wp_enqueue_script('sensei-lesson-metadata', Sensei()->plugin_url.'assets/js/lesson-metadata'.$suffix.'.js', array('jquery', 'sensei-core-select2', 'jquery-ui-sortable'), Sensei()->version, true);
1732
+			wp_enqueue_script('sensei-lesson-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1733
+			wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-lesson-chosen'), Sensei()->version, true);
1734 1734
 
1735 1735
             // Load the bulk edit screen script
1736
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1737
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1736
+            if ('edit.php' == $hook && 'lesson' == $_GET['post_type']) {
1737
+                wp_enqueue_script('sensei-lessons-bulk-edit', Sensei()->plugin_url.'assets/js/admin/lesson-bulk-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1738 1738
             }
1739 1739
 
1740 1740
 			// Localise script
1741
-			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
1742
-			$ajax_vars = array( 'lesson_update_question_nonce' => wp_create_nonce( 'lesson_update_question_nonce' ), 'lesson_add_course_nonce' => wp_create_nonce( 'lesson_add_course_nonce' ), 'lesson_update_grade_type_nonce' => wp_create_nonce( 'lesson_update_grade_type_nonce' ), 'lesson_update_question_order_nonce' => wp_create_nonce( 'lesson_update_question_order_nonce' ), 'lesson_update_question_order_random_nonce' => wp_create_nonce( 'lesson_update_question_order_random_nonce' ), 'lesson_add_multiple_questions_nonce' => wp_create_nonce( 'lesson_add_multiple_questions_nonce' ), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce( 'lesson_remove_multiple_questions_nonce' ), 'lesson_add_existing_questions_nonce' => wp_create_nonce( 'lesson_add_existing_questions_nonce' ), 'filter_existing_questions_nonce' => wp_create_nonce( 'filter_existing_questions_nonce' ) );
1743
-			$data = array_merge( $translation_strings, $ajax_vars );
1744
-			wp_localize_script( 'sensei-lesson-metadata', 'woo_localized_data', $data );
1741
+			$translation_strings = array('right_colon' => __('Right:', 'woothemes-sensei'), 'wrong_colon' => __('Wrong:', 'woothemes-sensei'), 'add_file' => __('Add file', 'woothemes-sensei'), 'change_file' => __('Change file', 'woothemes-sensei'), 'confirm_remove' => __('Are you sure you want to remove this question?', 'woothemes-sensei'), 'confirm_remove_multiple' => __('Are you sure you want to remove these questions?', 'woothemes-sensei'), 'too_many_for_cat' => __('You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei'));
1742
+			$ajax_vars = array('lesson_update_question_nonce' => wp_create_nonce('lesson_update_question_nonce'), 'lesson_add_course_nonce' => wp_create_nonce('lesson_add_course_nonce'), 'lesson_update_grade_type_nonce' => wp_create_nonce('lesson_update_grade_type_nonce'), 'lesson_update_question_order_nonce' => wp_create_nonce('lesson_update_question_order_nonce'), 'lesson_update_question_order_random_nonce' => wp_create_nonce('lesson_update_question_order_random_nonce'), 'lesson_add_multiple_questions_nonce' => wp_create_nonce('lesson_add_multiple_questions_nonce'), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce('lesson_remove_multiple_questions_nonce'), 'lesson_add_existing_questions_nonce' => wp_create_nonce('lesson_add_existing_questions_nonce'), 'filter_existing_questions_nonce' => wp_create_nonce('filter_existing_questions_nonce'));
1743
+			$data = array_merge($translation_strings, $ajax_vars);
1744
+			wp_localize_script('sensei-lesson-metadata', 'woo_localized_data', $data);
1745 1745
 
1746 1746
 			// Chosen RTL
1747
-			if ( is_rtl() ) {
1748
-				wp_enqueue_script( 'sensei-chosen-rtl', Sensei()->plugin_url . 'assets/chosen/chosen-rtl' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1747
+			if (is_rtl()) {
1748
+				wp_enqueue_script('sensei-chosen-rtl', Sensei()->plugin_url.'assets/chosen/chosen-rtl'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1749 1749
 			}
1750 1750
 
1751 1751
 		}
@@ -1759,16 +1759,16 @@  discard block
 block discarded – undo
1759 1759
 	 * @since  1.4.0
1760 1760
 	 * @return void
1761 1761
 	 */
1762
-	public function enqueue_styles ( $hook ) {
1762
+	public function enqueue_styles($hook) {
1763 1763
 		global  $post_type;
1764 1764
 
1765
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question', 'sensei_message' ) );
1766
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1767
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings' ) );
1765
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question', 'sensei_message'));
1766
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1767
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings'));
1768 1768
 
1769 1769
 		// Test for Write Panel Pages
1770
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1771
-			wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), '', Sensei()->version );
1770
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1771
+			wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), '', Sensei()->version);
1772 1772
 		}
1773 1773
 
1774 1774
 	} // End enqueue_styles()
@@ -1780,12 +1780,12 @@  discard block
 block discarded – undo
1780 1780
 	 * @param  array $defaults
1781 1781
 	 * @return array $new_columns
1782 1782
 	 */
1783
-	public function add_column_headings ( $defaults ) {
1783
+	public function add_column_headings($defaults) {
1784 1784
 		$new_columns['cb'] = '<input type="checkbox" />';
1785
-		$new_columns['title'] = _x( 'Lesson Title', 'column name', 'woothemes-sensei' );
1786
-		$new_columns['lesson-course'] = _x( 'Course', 'column name', 'woothemes-sensei' );
1787
-		$new_columns['lesson-prerequisite'] = _x( 'Pre-requisite Lesson', 'column name', 'woothemes-sensei' );
1788
-		if ( isset( $defaults['date'] ) ) {
1785
+		$new_columns['title'] = _x('Lesson Title', 'column name', 'woothemes-sensei');
1786
+		$new_columns['lesson-course'] = _x('Course', 'column name', 'woothemes-sensei');
1787
+		$new_columns['lesson-prerequisite'] = _x('Pre-requisite Lesson', 'column name', 'woothemes-sensei');
1788
+		if (isset($defaults['date'])) {
1789 1789
 			$new_columns['date'] = $defaults['date'];
1790 1790
 		}
1791 1791
 		return $new_columns;
@@ -1799,23 +1799,23 @@  discard block
 block discarded – undo
1799 1799
 	 * @param  int $id
1800 1800
 	 * @return void
1801 1801
 	 */
1802
-	public function add_column_data ( $column_name, $id ) {
1802
+	public function add_column_data($column_name, $id) {
1803 1803
 		global $wpdb, $post;
1804 1804
 
1805
-		switch ( $column_name ) {
1805
+		switch ($column_name) {
1806 1806
 			case 'id':
1807 1807
 				echo $id;
1808 1808
 			break;
1809 1809
 			case 'lesson-course':
1810
-				$lesson_course_id = get_post_meta( $id, '_lesson_course', true);
1811
-				if ( 0 < absint( $lesson_course_id ) ) {
1812
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_course_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_course_id ) ) ) ) . '">' . get_the_title( absint( $lesson_course_id ) ) . '</a>';
1810
+				$lesson_course_id = get_post_meta($id, '_lesson_course', true);
1811
+				if (0 < absint($lesson_course_id)) {
1812
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_course_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_course_id)))).'">'.get_the_title(absint($lesson_course_id)).'</a>';
1813 1813
 				} // End If Statement
1814 1814
 			break;
1815 1815
 			case 'lesson-prerequisite':
1816
-				$lesson_prerequisite_id = get_post_meta( $id, '_lesson_prerequisite', true);
1817
-				if ( 0 < absint( $lesson_prerequisite_id ) ) {
1818
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $lesson_prerequisite_id ) ) . '</a>';
1816
+				$lesson_prerequisite_id = get_post_meta($id, '_lesson_prerequisite', true);
1817
+				if (0 < absint($lesson_prerequisite_id)) {
1818
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_prerequisite_id)))).'">'.get_the_title(absint($lesson_prerequisite_id)).'</a>';
1819 1819
 				} // End If Statement
1820 1820
 			break;
1821 1821
 			default:
@@ -1829,14 +1829,14 @@  discard block
 block discarded – undo
1829 1829
 	 * @access public
1830 1830
 	 * @return void
1831 1831
 	 */
1832
-	public function lesson_add_course () {
1832
+	public function lesson_add_course() {
1833 1833
 		global $current_user;
1834 1834
 		//Add nonce security to the request
1835
-		if ( isset($_POST['lesson_add_course_nonce']) ) {
1836
-			$nonce = esc_html( $_POST['lesson_add_course_nonce'] );
1835
+		if (isset($_POST['lesson_add_course_nonce'])) {
1836
+			$nonce = esc_html($_POST['lesson_add_course_nonce']);
1837 1837
 		} // End If Statement
1838
-		if ( ! wp_verify_nonce( $nonce, 'lesson_add_course_nonce' )
1839
-            || ! current_user_can( 'edit_lessons' ) ) {
1838
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_course_nonce')
1839
+            || ! current_user_can('edit_lessons')) {
1840 1840
 			die('');
1841 1841
 		} // End If Statement
1842 1842
 		// Parse POST data
@@ -1858,14 +1858,14 @@  discard block
 block discarded – undo
1858 1858
 	 * @access public
1859 1859
 	 * @return void
1860 1860
 	 */
1861
-	public function lesson_update_question () {
1861
+	public function lesson_update_question() {
1862 1862
 		global $current_user;
1863 1863
 		//Add nonce security to the request
1864
-		if ( isset($_POST['lesson_update_question_nonce']) ) {
1865
-			$nonce = esc_html( $_POST['lesson_update_question_nonce'] );
1864
+		if (isset($_POST['lesson_update_question_nonce'])) {
1865
+			$nonce = esc_html($_POST['lesson_update_question_nonce']);
1866 1866
 		} // End If Statement
1867
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_nonce' )
1868
-            ||  ! current_user_can( 'edit_questions' )) {
1867
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_nonce')
1868
+            ||  ! current_user_can('edit_questions')) {
1869 1869
 
1870 1870
 			die('');
1871 1871
 
@@ -1875,30 +1875,30 @@  discard block
 block discarded – undo
1875 1875
 		// WP slashes all incoming data regardless of Magic Quotes setting (see wp_magic_quotes()), which means that
1876 1876
 		// even the $_POST['data'] encoded with encodeURIComponent has it's apostrophes slashed.
1877 1877
 		// So first restore the original unslashed apostrophes by removing those slashes
1878
-		$data = wp_unslash( $_POST['data'] );
1878
+		$data = wp_unslash($_POST['data']);
1879 1879
 		// Then parse the string to an array (note that parse_str automatically urldecodes all the variables)
1880 1880
 		$question_data = array();
1881 1881
 		parse_str($data, $question_data);
1882 1882
 		// Finally re-slash all elements to ensure consistancy for lesson_save_question()
1883
-		$question_data = wp_slash( $question_data );
1883
+		$question_data = wp_slash($question_data);
1884 1884
 		// Save the question
1885 1885
 		$return = false;
1886 1886
 		// Question Save and Delete logic
1887
-		if ( isset( $question_data['action'] ) && ( $question_data['action'] == 'delete' ) ) {
1887
+		if (isset($question_data['action']) && ($question_data['action'] == 'delete')) {
1888 1888
 			// Delete the Question
1889 1889
 			$return = $this->lesson_delete_question($question_data);
1890 1890
 		} else {
1891 1891
 			// Save the Question
1892
-			if ( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1892
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1893 1893
 				$current_user = wp_get_current_user();
1894 1894
 				$question_data['post_author'] = $current_user->ID;
1895
-				$question_id = $this->lesson_save_question( $question_data );
1896
-				$question_type = Sensei()->question->get_question_type( $question_id );
1895
+				$question_id = $this->lesson_save_question($question_data);
1896
+				$question_type = Sensei()->question->get_question_type($question_id);
1897 1897
 
1898
-				$question_count = intval( $question_data['question_count'] );
1898
+				$question_count = intval($question_data['question_count']);
1899 1899
 				++$question_count;
1900 1900
 
1901
-				$return = $this->quiz_panel_question( $question_type, $question_count, $question_id );
1901
+				$return = $this->quiz_panel_question($question_type, $question_count, $question_id);
1902 1902
 			} // End If Statement
1903 1903
 		} // End If Statement
1904 1904
 
@@ -1913,49 +1913,49 @@  discard block
 block discarded – undo
1913 1913
 
1914 1914
 		//Add nonce security to the request
1915 1915
 		$nonce = '';
1916
-		if( isset( $_POST['lesson_add_multiple_questions_nonce'] ) ) {
1917
-			$nonce = esc_html( $_POST['lesson_add_multiple_questions_nonce'] );
1916
+		if (isset($_POST['lesson_add_multiple_questions_nonce'])) {
1917
+			$nonce = esc_html($_POST['lesson_add_multiple_questions_nonce']);
1918 1918
 		} // End If Statement
1919 1919
 
1920
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_multiple_questions_nonce' )
1921
-            || ! current_user_can( 'edit_lessons' ) ) {
1922
-			die( $return );
1920
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_multiple_questions_nonce')
1921
+            || ! current_user_can('edit_lessons')) {
1922
+			die($return);
1923 1923
 		} // End If Statement
1924 1924
 
1925 1925
 		// Parse POST data
1926 1926
 		$data = $_POST['data'];
1927 1927
 		$question_data = array();
1928
-		parse_str( $data, $question_data );
1928
+		parse_str($data, $question_data);
1929 1929
 
1930
-		if( is_array( $question_data ) ) {
1931
-			if( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1930
+		if (is_array($question_data)) {
1931
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1932 1932
 
1933
-				$quiz_id = intval( $question_data['quiz_id'] );
1934
-				$question_number = intval( $question_data['question_number'] );
1935
-				$question_category = intval( $question_data['question_category'] );
1933
+				$quiz_id = intval($question_data['quiz_id']);
1934
+				$question_number = intval($question_data['question_number']);
1935
+				$question_category = intval($question_data['question_category']);
1936 1936
 
1937
-				$question_counter = intval( $question_data['question_count'] );
1937
+				$question_counter = intval($question_data['question_count']);
1938 1938
 				++$question_counter;
1939 1939
 
1940
-				$cat = get_term( $question_category, 'question-category' );
1940
+				$cat = get_term($question_category, 'question-category');
1941 1941
 
1942 1942
 				$post_data = array(
1943 1943
 					'post_content' => '',
1944 1944
 					'post_status' => 'publish',
1945
-					'post_title' => sprintf( __( '%1$s Question(s) from %2$s', 'woothemes-sensei' ), $question_number, $cat->name ),
1945
+					'post_title' => sprintf(__('%1$s Question(s) from %2$s', 'woothemes-sensei'), $question_number, $cat->name),
1946 1946
 					'post_type' => 'multiple_question'
1947 1947
 				);
1948 1948
 
1949
-				$multiple_id = wp_insert_post( $post_data );
1949
+				$multiple_id = wp_insert_post($post_data);
1950 1950
 
1951
-				if( $multiple_id && ! is_wp_error( $multiple_id ) ) {
1952
-					add_post_meta( $multiple_id, 'category', $question_category );
1953
-					add_post_meta( $multiple_id, 'number', $question_number );
1954
-					add_post_meta( $multiple_id, '_quiz_id', $quiz_id, false );
1955
-					add_post_meta( $multiple_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_counter );
1956
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1957
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
1958
-					$return = $this->quiz_panel_question( 'category', $question_counter, $multiple_id, 'quiz', array( $cat->name, $question_number ) );
1951
+				if ($multiple_id && ! is_wp_error($multiple_id)) {
1952
+					add_post_meta($multiple_id, 'category', $question_category);
1953
+					add_post_meta($multiple_id, 'number', $question_number);
1954
+					add_post_meta($multiple_id, '_quiz_id', $quiz_id, false);
1955
+					add_post_meta($multiple_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_counter);
1956
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1957
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
1958
+					$return = $this->quiz_panel_question('category', $question_counter, $multiple_id, 'quiz', array($cat->name, $question_number));
1959 1959
 				}
1960 1960
 			}
1961 1961
 		}
@@ -1969,25 +1969,25 @@  discard block
 block discarded – undo
1969 1969
 
1970 1970
 		//Add nonce security to the request
1971 1971
 		$nonce = '';
1972
-		if( isset( $_POST['lesson_remove_multiple_questions_nonce'] ) ) {
1973
-			$nonce = esc_html( $_POST['lesson_remove_multiple_questions_nonce'] );
1972
+		if (isset($_POST['lesson_remove_multiple_questions_nonce'])) {
1973
+			$nonce = esc_html($_POST['lesson_remove_multiple_questions_nonce']);
1974 1974
 		} // End If Statement
1975 1975
 
1976
-		if( ! wp_verify_nonce( $nonce, 'lesson_remove_multiple_questions_nonce' )
1977
-        || ! current_user_can( 'edit_lessons' ) ) {
1976
+		if ( ! wp_verify_nonce($nonce, 'lesson_remove_multiple_questions_nonce')
1977
+        || ! current_user_can('edit_lessons')) {
1978 1978
 			die('');
1979 1979
 		} // End If Statement
1980 1980
 
1981 1981
 		// Parse POST data
1982 1982
 		$data = $_POST['data'];
1983 1983
 		$question_data = array();
1984
-		parse_str( $data, $question_data );
1984
+		parse_str($data, $question_data);
1985 1985
 
1986
-		if( is_array( $question_data ) ) {
1987
-			wp_delete_post( $question_data['question_id'], true );
1986
+		if (is_array($question_data)) {
1987
+			wp_delete_post($question_data['question_id'], true);
1988 1988
 		}
1989 1989
 
1990
-		die( 'Deleted' );
1990
+		die('Deleted');
1991 1991
 	}
1992 1992
 
1993 1993
 	public function get_question_category_limit() {
@@ -1998,11 +1998,11 @@  discard block
 block discarded – undo
1998 1998
 		// Parse POST data
1999 1999
 		$data = $_POST['data'];
2000 2000
 		$cat_data = array();
2001
-		parse_str( $data, $cat_data );
2001
+		parse_str($data, $cat_data);
2002 2002
 
2003
-		if( isset( $cat_data['cat'] ) && '' != $cat_data['cat'] ) {
2004
-			$cat = get_term( $cat_data['cat'], 'question-category' );
2005
-			if( isset( $cat->count ) ) {
2003
+		if (isset($cat_data['cat']) && '' != $cat_data['cat']) {
2004
+			$cat = get_term($cat_data['cat'], 'question-category');
2005
+			if (isset($cat->count)) {
2006 2006
 				$return = $cat->count;
2007 2007
 			}
2008 2008
 		}
@@ -2016,45 +2016,45 @@  discard block
 block discarded – undo
2016 2016
 
2017 2017
 		//Add nonce security to the request
2018 2018
 		$nonce = '';
2019
-		if( isset( $_POST['lesson_add_existing_questions_nonce'] ) ) {
2020
-			$nonce = esc_html( $_POST['lesson_add_existing_questions_nonce'] );
2019
+		if (isset($_POST['lesson_add_existing_questions_nonce'])) {
2020
+			$nonce = esc_html($_POST['lesson_add_existing_questions_nonce']);
2021 2021
 		} // End If Statement
2022 2022
 
2023
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_existing_questions_nonce' )
2024
-        || ! current_user_can( 'edit_lessons' ) ) {
2023
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_existing_questions_nonce')
2024
+        || ! current_user_can('edit_lessons')) {
2025 2025
 			die('');
2026 2026
 		} // End If Statement
2027 2027
 
2028 2028
 		// Parse POST data
2029 2029
 		$data = $_POST['data'];
2030 2030
 		$question_data = array();
2031
-		parse_str( $data, $question_data );
2031
+		parse_str($data, $question_data);
2032 2032
 
2033 2033
 		$return = '';
2034 2034
 
2035
-		if( is_array( $question_data ) ) {
2035
+		if (is_array($question_data)) {
2036 2036
 
2037
-			if( isset( $question_data['questions'] ) && '' != $question_data['questions'] ) {
2037
+			if (isset($question_data['questions']) && '' != $question_data['questions']) {
2038 2038
 
2039
-				$questions = explode( ',', trim( $question_data['questions'], ',' ) );
2039
+				$questions = explode(',', trim($question_data['questions'], ','));
2040 2040
 				$quiz_id = $question_data['quiz_id'];
2041
-				$question_count = intval( $question_data['question_count'] );
2041
+				$question_count = intval($question_data['question_count']);
2042 2042
 
2043
-				foreach( $questions as $question_id ) {
2043
+				foreach ($questions as $question_id) {
2044 2044
 
2045 2045
 					++$question_count;
2046 2046
 
2047
-					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2048
-					if( ! in_array( $quiz_id, $quizzes ) ) {
2049
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2050
-						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2051
-						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2047
+					$quizzes = get_post_meta($question_id, '_quiz_id', false);
2048
+					if ( ! in_array($quiz_id, $quizzes)) {
2049
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2050
+						$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2051
+						update_post_meta($lesson_id, '_quiz_has_questions', '1');
2052 2052
 			    	}
2053 2053
 
2054
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2055
-					$question_type = Sensei()->question->get_question_type( $question_id );
2054
+			    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2055
+					$question_type = Sensei()->question->get_question_type($question_id);
2056 2056
 
2057
-					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
2057
+					$return .= $this->quiz_panel_question($question_type, $question_count, $question_id);
2058 2058
 				}
2059 2059
 			}
2060 2060
 		}
@@ -2066,14 +2066,14 @@  discard block
 block discarded – undo
2066 2066
 
2067 2067
 	public function lesson_update_grade_type() {
2068 2068
 		//Add nonce security to the request
2069
-		if ( isset($_POST['lesson_update_grade_type_nonce']) ) {
2069
+		if (isset($_POST['lesson_update_grade_type_nonce'])) {
2070 2070
 
2071
-			$nonce = esc_html( $_POST['lesson_update_grade_type_nonce'] );
2071
+			$nonce = esc_html($_POST['lesson_update_grade_type_nonce']);
2072 2072
 
2073 2073
 		} // End If Statement
2074 2074
 
2075
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_grade_type_nonce' )
2076
-        || ! current_user_can( 'edit_lessons' ) ) {
2075
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_grade_type_nonce')
2076
+        || ! current_user_can('edit_lessons')) {
2077 2077
 
2078 2078
 			die('');
2079 2079
 
@@ -2083,18 +2083,18 @@  discard block
 block discarded – undo
2083 2083
 		$data = $_POST['data'];
2084 2084
 		$quiz_data = array();
2085 2085
 		parse_str($data, $quiz_data);
2086
-		update_post_meta( $quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type'] );
2086
+		update_post_meta($quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type']);
2087 2087
 		die();
2088 2088
 	}
2089 2089
 
2090 2090
 	public function lesson_update_question_order() {
2091 2091
 		// Add nonce security to the request
2092
-		if ( isset($_POST['lesson_update_question_order_nonce']) ) {
2093
-			$nonce = esc_html( $_POST['lesson_update_question_order_nonce'] );
2092
+		if (isset($_POST['lesson_update_question_order_nonce'])) {
2093
+			$nonce = esc_html($_POST['lesson_update_question_order_nonce']);
2094 2094
 		} // End If Statement
2095 2095
 
2096
-        if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2097
-            ||! current_user_can( 'edit_lessons' ) ) {
2096
+        if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_nonce')
2097
+            ||! current_user_can('edit_lessons')) {
2098 2098
 			die('');
2099 2099
 		} // End If Statement
2100 2100
 
@@ -2102,25 +2102,25 @@  discard block
 block discarded – undo
2102 2102
 		$data = $_POST['data'];
2103 2103
 		$quiz_data = array();
2104 2104
 		parse_str($data, $quiz_data);
2105
-		if( strlen( $quiz_data['question_order'] ) > 0 ) {
2106
-			$questions = explode( ',', $quiz_data['question_order'] );
2105
+		if (strlen($quiz_data['question_order']) > 0) {
2106
+			$questions = explode(',', $quiz_data['question_order']);
2107 2107
 			$o = 1;
2108
-			foreach( $questions as $question_id ) {
2109
-				update_post_meta( $question_id, '_quiz_question_order' . $quiz_data['quiz_id'], $quiz_data['quiz_id'] . '000' . $o );
2108
+			foreach ($questions as $question_id) {
2109
+				update_post_meta($question_id, '_quiz_question_order'.$quiz_data['quiz_id'], $quiz_data['quiz_id'].'000'.$o);
2110 2110
 				++$o;
2111 2111
 			}
2112
-			update_post_meta( $quiz_data['quiz_id'], '_question_order', $questions );
2112
+			update_post_meta($quiz_data['quiz_id'], '_question_order', $questions);
2113 2113
 		}
2114 2114
 		die();
2115 2115
 	}
2116 2116
 
2117 2117
 	public function lesson_update_question_order_random() {
2118 2118
 		//Add nonce security to the request
2119
-		if ( isset($_POST['lesson_update_question_order_random_nonce']) ) {
2120
-			$nonce = esc_html( $_POST['lesson_update_question_order_random_nonce'] );
2119
+		if (isset($_POST['lesson_update_question_order_random_nonce'])) {
2120
+			$nonce = esc_html($_POST['lesson_update_question_order_random_nonce']);
2121 2121
 		} // End If Statement
2122
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_random_nonce' )
2123
-            || ! current_user_can( 'edit_lessons' ) ) {
2122
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_random_nonce')
2123
+            || ! current_user_can('edit_lessons')) {
2124 2124
 
2125 2125
 			die('');
2126 2126
 
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
 		$data = $_POST['data'];
2130 2130
 		$quiz_data = array();
2131 2131
 		parse_str($data, $quiz_data);
2132
-		update_post_meta( $quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order'] );
2132
+		update_post_meta($quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order']);
2133 2133
 		die();
2134 2134
 	}
2135 2135
 
@@ -2140,7 +2140,7 @@  discard block
 block discarded – undo
2140 2140
 	 * @param array $data (default: array())
2141 2141
 	 * @return integer|boolean $course_id or false
2142 2142
 	 */
2143
-	private function lesson_save_course( $data = array() ) {
2143
+	private function lesson_save_course($data = array()) {
2144 2144
 		global $current_user;
2145 2145
 		$return = false;
2146 2146
 		// Setup the course data
@@ -2149,58 +2149,58 @@  discard block
 block discarded – undo
2149 2149
 		$course_title = '';
2150 2150
 		$course_prerequisite = 0;
2151 2151
 		$course_category = 0;
2152
-		if ( isset( $data[ 'course_id' ] ) && ( 0 < absint( $data[ 'course_id' ] ) ) ) {
2153
-			$course_id = absint( $data[ 'course_id' ] );
2152
+		if (isset($data['course_id']) && (0 < absint($data['course_id']))) {
2153
+			$course_id = absint($data['course_id']);
2154 2154
 		} // End If Statement
2155
-		if ( isset( $data[ 'course_title' ] ) && ( '' != $data[ 'course_title' ] ) ) {
2156
-			$course_title = $data[ 'course_title' ];
2155
+		if (isset($data['course_title']) && ('' != $data['course_title'])) {
2156
+			$course_title = $data['course_title'];
2157 2157
 		} // End If Statement
2158 2158
 		$post_title = $course_title;
2159
-		if ( isset($data[ 'post_author' ]) ) {
2160
-			$post_author = $data[ 'post_author' ];
2159
+		if (isset($data['post_author'])) {
2160
+			$post_author = $data['post_author'];
2161 2161
 		} else {
2162 2162
 			$current_user = wp_get_current_user();
2163 2163
 			$post_author = $current_user->ID;
2164 2164
 		} // End If Statement
2165 2165
 		$post_status = 'publish';
2166 2166
 		$post_type = 'course';
2167
-		if ( isset( $data[ 'course_content' ] ) && ( '' != $data[ 'course_content' ] ) ) {
2168
-			$course_content = $data[ 'course_content' ];
2167
+		if (isset($data['course_content']) && ('' != $data['course_content'])) {
2168
+			$course_content = $data['course_content'];
2169 2169
 		} // End If Statement
2170 2170
 		$post_content = $course_content;
2171 2171
 		// Course Query Arguments
2172
-		$post_type_args = array(	'post_content' => $post_content,
2172
+		$post_type_args = array('post_content' => $post_content,
2173 2173
   		    						'post_status' => $post_status,
2174 2174
   		    						'post_title' => $post_title,
2175 2175
   		    						'post_type' => $post_type
2176 2176
   		    						);
2177 2177
   		// Only save if there is a valid title
2178
-  		if ( $post_title != '' ) {
2178
+  		if ($post_title != '') {
2179 2179
   		    // Check for prerequisite courses & product id
2180
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2181
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2182
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2183
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2180
+  		    $course_prerequisite_id = absint($data['course_prerequisite']);
2181
+  		    $course_woocommerce_product_id = absint($data['course_woocommerce_product']);
2182
+  		    $course_category_id = absint($data['course_category']);
2183
+  		    if (0 == $course_woocommerce_product_id) { $course_woocommerce_product_id = '-'; }
2184 2184
   		    // Insert or Update the Lesson Quiz
2185
-		    if ( 0 < $course_id ) {
2186
-		    	$post_type_args[ 'ID' ] = $course_id;
2185
+		    if (0 < $course_id) {
2186
+		    	$post_type_args['ID'] = $course_id;
2187 2187
 		    	$course_id = wp_update_post($post_type_args);
2188
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2189
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2190
-		    	if ( 0 < $course_category_id ) {
2191
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2188
+		    	update_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2189
+		    	update_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2190
+		    	if (0 < $course_category_id) {
2191
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2192 2192
 		    	} // End If Statement
2193 2193
 		    } else {
2194 2194
 		    	$course_id = wp_insert_post($post_type_args);
2195
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2196
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2197
-		    	if ( 0 < $course_category_id ) {
2198
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2195
+		    	add_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2196
+		    	add_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2197
+		    	if (0 < $course_category_id) {
2198
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2199 2199
 		    	} // End If Statement
2200 2200
 		    } // End If Statement
2201 2201
 		} // End If Statement
2202 2202
   		// Check that the insert or update saved by testing the post id
2203
-  		if ( 0 < $course_id ) {
2203
+  		if (0 < $course_id) {
2204 2204
   			$return = $course_id;
2205 2205
   		} // End If Statement
2206 2206
   		return $return;
@@ -2214,7 +2214,7 @@  discard block
 block discarded – undo
2214 2214
 	 * @param array $data (default: array())
2215 2215
 	 * @return integer|boolean $question_id or false
2216 2216
 	 */
2217
-	public function lesson_save_question( $data = array(), $context = 'quiz' ) {
2217
+	public function lesson_save_question($data = array(), $context = 'quiz') {
2218 2218
 		$return = false;
2219 2219
 		// Save the Questions
2220 2220
 		// Setup the Question data
@@ -2226,130 +2226,130 @@  discard block
 block discarded – undo
2226 2226
 		$question_category = '';
2227 2227
 
2228 2228
 		// Handle Question Type
2229
-		if ( isset( $data[ 'question_type' ] ) && ( '' != $data[ 'question_type' ] ) ) {
2230
-			$question_type = $data[ 'question_type' ];
2229
+		if (isset($data['question_type']) && ('' != $data['question_type'])) {
2230
+			$question_type = $data['question_type'];
2231 2231
 		} // End If Statement
2232 2232
 
2233
-		if ( isset( $data[ 'question_category' ] ) && ( '' != $data[ 'question_category' ] ) ) {
2234
-			$question_category = $data[ 'question_category' ];
2233
+		if (isset($data['question_category']) && ('' != $data['question_category'])) {
2234
+			$question_category = $data['question_category'];
2235 2235
 		} // End If Statement
2236 2236
 
2237
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2238
-			$question_id = absint( $data[ 'question_id' ] );
2237
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2238
+			$question_id = absint($data['question_id']);
2239 2239
 		} // End If Statement
2240
-		if ( isset( $data[ 'question' ] ) && ( '' != $data[ 'question' ] ) ) {
2241
-			$question_text = $data[ 'question' ];
2240
+		if (isset($data['question']) && ('' != $data['question'])) {
2241
+			$question_text = $data['question'];
2242 2242
 		} // End If Statement
2243 2243
 		$post_title = $question_text;
2244 2244
 		// Handle Default Fields (multiple choice)
2245
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answers' ] ) && ( '' != $data[ 'question_right_answers' ] ) ) {
2246
-			$question_right_answers = $data[ 'question_right_answers' ];
2245
+		if ('multiple-choice' == $question_type && isset($data['question_right_answers']) && ('' != $data['question_right_answers'])) {
2246
+			$question_right_answers = $data['question_right_answers'];
2247 2247
 		} // End If Statement
2248
-		elseif ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answer' ] ) && ( '' != $data[ 'question_right_answer' ] ) ) {
2249
-			$question_right_answer = $data[ 'question_right_answer' ];
2248
+		elseif ('multiple-choice' == $question_type && isset($data['question_right_answer']) && ('' != $data['question_right_answer'])) {
2249
+			$question_right_answer = $data['question_right_answer'];
2250 2250
 		} // End If Statement
2251
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_wrong_answers' ] ) && ( '' != $data[ 'question_wrong_answers' ] ) ) {
2252
-			$question_wrong_answers = $data[ 'question_wrong_answers' ];
2251
+		if ('multiple-choice' == $question_type && isset($data['question_wrong_answers']) && ('' != $data['question_wrong_answers'])) {
2252
+			$question_wrong_answers = $data['question_wrong_answers'];
2253 2253
 		} // End If Statement
2254 2254
 		// Handle Boolean Fields - Edit
2255
-		if ( 'boolean' == $question_type && isset( $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) && ( '' != $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) ) {
2256
-			$question_right_answer = $data[ 'question_' . $question_id . '_right_answer_boolean' ];
2255
+		if ('boolean' == $question_type && isset($data['question_'.$question_id.'_right_answer_boolean']) && ('' != $data['question_'.$question_id.'_right_answer_boolean'])) {
2256
+			$question_right_answer = $data['question_'.$question_id.'_right_answer_boolean'];
2257 2257
 		} // End If Statement
2258 2258
 		// Handle Boolean Fields - Add
2259
-		if ( 'boolean' == $question_type && isset( $data[ 'question_right_answer_boolean' ] ) && ( '' != $data[ 'question_right_answer_boolean' ] ) ) {
2260
-			$question_right_answer = $data[ 'question_right_answer_boolean' ];
2259
+		if ('boolean' == $question_type && isset($data['question_right_answer_boolean']) && ('' != $data['question_right_answer_boolean'])) {
2260
+			$question_right_answer = $data['question_right_answer_boolean'];
2261 2261
 		} // End If Statement
2262 2262
 		// Handle Gap Fill Fields
2263
-		if ( 'gap-fill' == $question_type && isset( $data[ 'add_question_right_answer_gapfill_gap' ] ) && '' != $data[ 'add_question_right_answer_gapfill_gap' ] ) {
2264
-			$question_right_answer = $data[ 'add_question_right_answer_gapfill_pre' ] . '||' . $data[ 'add_question_right_answer_gapfill_gap' ] . '||' . $data[ 'add_question_right_answer_gapfill_post' ];
2263
+		if ('gap-fill' == $question_type && isset($data['add_question_right_answer_gapfill_gap']) && '' != $data['add_question_right_answer_gapfill_gap']) {
2264
+			$question_right_answer = $data['add_question_right_answer_gapfill_pre'].'||'.$data['add_question_right_answer_gapfill_gap'].'||'.$data['add_question_right_answer_gapfill_post'];
2265 2265
 		} // End If Statement
2266 2266
 		// Handle Multi Line Fields
2267
-		if ( 'multi-line' == $question_type && isset( $data[ 'add_question_right_answer_multiline' ] ) && ( '' != $data[ 'add_question_right_answer_multiline' ] ) ) {
2268
-			$question_right_answer = $data[ 'add_question_right_answer_multiline' ];
2267
+		if ('multi-line' == $question_type && isset($data['add_question_right_answer_multiline']) && ('' != $data['add_question_right_answer_multiline'])) {
2268
+			$question_right_answer = $data['add_question_right_answer_multiline'];
2269 2269
 		} // End If Statement
2270 2270
 		// Handle Single Line Fields
2271
-		if ( 'single-line' == $question_type && isset( $data[ 'add_question_right_answer_singleline' ] ) && ( '' != $data[ 'add_question_right_answer_singleline' ] ) ) {
2272
-			$question_right_answer = $data[ 'add_question_right_answer_singleline' ];
2271
+		if ('single-line' == $question_type && isset($data['add_question_right_answer_singleline']) && ('' != $data['add_question_right_answer_singleline'])) {
2272
+			$question_right_answer = $data['add_question_right_answer_singleline'];
2273 2273
 		} // End If Statement
2274 2274
 		// Handle File Upload Fields
2275
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_right_answer_fileupload' ] ) && ( '' != $data[ 'add_question_right_answer_fileupload' ] ) ) {
2276
-			$question_right_answer = $data[ 'add_question_right_answer_fileupload' ];
2275
+		if ('file-upload' == $question_type && isset($data['add_question_right_answer_fileupload']) && ('' != $data['add_question_right_answer_fileupload'])) {
2276
+			$question_right_answer = $data['add_question_right_answer_fileupload'];
2277 2277
 		} // End If Statement
2278
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_wrong_answer_fileupload' ] ) && ( '' != $data[ 'add_question_wrong_answer_fileupload' ] ) ) {
2279
-			$question_wrong_answers = array( $data[ 'add_question_wrong_answer_fileupload' ] );
2278
+		if ('file-upload' == $question_type && isset($data['add_question_wrong_answer_fileupload']) && ('' != $data['add_question_wrong_answer_fileupload'])) {
2279
+			$question_wrong_answers = array($data['add_question_wrong_answer_fileupload']);
2280 2280
 		} // End If Statement
2281 2281
 
2282 2282
 		// Handle Question Grade
2283
-		if ( isset( $data[ 'question_grade' ] ) && ( '' != $data[ 'question_grade' ] ) ) {
2284
-			$question_grade = $data[ 'question_grade' ];
2283
+		if (isset($data['question_grade']) && ('' != $data['question_grade'])) {
2284
+			$question_grade = $data['question_grade'];
2285 2285
 		} // End If Statement
2286 2286
 
2287 2287
 		// Handle Answer Feedback
2288 2288
 		$answer_feedback = '';
2289
-		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2289
+		if (isset($data['answer_feedback_boolean']) && ! empty($data['answer_feedback_boolean'])) {
2290 2290
 
2291
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2291
+            $answer_feedback = $data['answer_feedback_boolean'];
2292 2292
 
2293
-		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2293
+		}elseif (isset($data['answer_feedback_multiple_choice']) && ! empty($data['answer_feedback_multiple_choice'])) {
2294 2294
 
2295
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2295
+            $answer_feedback = $data['answer_feedback_multiple_choice'];
2296 2296
 
2297
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2297
+        }elseif (isset($data['answer_feedback'])) {
2298 2298
 
2299
-            $answer_feedback = $data[ 'answer_feedback' ];
2299
+            $answer_feedback = $data['answer_feedback'];
2300 2300
 
2301 2301
         } // End If Statement
2302 2302
 
2303 2303
 		$post_title = $question_text;
2304
-		$post_author = $data[ 'post_author' ];
2304
+		$post_author = $data['post_author'];
2305 2305
 		$post_status = 'publish';
2306 2306
 		$post_type = 'question';
2307 2307
 		// Handle the extended question text
2308
-		if ( isset( $data[ 'question_description' ] ) && ( '' != $data[ 'question_description' ] ) ) {
2309
-			$post_content = $data[ 'question_description' ];
2308
+		if (isset($data['question_description']) && ('' != $data['question_description'])) {
2309
+			$post_content = $data['question_description'];
2310 2310
 		}
2311 2311
 		else {
2312 2312
 			$post_content = '';
2313 2313
 		}
2314 2314
 		// Question Query Arguments
2315
-		$post_type_args = array(	'post_content' => $post_content,
2315
+		$post_type_args = array('post_content' => $post_content,
2316 2316
   		    						'post_status' => $post_status,
2317 2317
   		    						'post_title' => $post_title,
2318 2318
   		    						'post_type' => $post_type
2319 2319
   		    						);
2320 2320
 
2321 2321
   		// Remove empty values and reindex the array
2322
-  		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
2323
-  			$question_right_answers_array = array_values( array_filter( $question_right_answers, 'strlen' ) );
2322
+  		if (is_array($question_right_answers) && 0 < count($question_right_answers)) {
2323
+  			$question_right_answers_array = array_values(array_filter($question_right_answers, 'strlen'));
2324 2324
   			$question_right_answers = array();
2325 2325
 
2326
-  			foreach( $question_right_answers_array as $answer ) {
2327
-  				if( ! in_array( $answer, $question_right_answers ) ) {
2326
+  			foreach ($question_right_answers_array as $answer) {
2327
+  				if ( ! in_array($answer, $question_right_answers)) {
2328 2328
   					$question_right_answers[] = $answer;
2329 2329
   				}
2330 2330
   			}
2331
-  			if ( 0 < count($question_right_answers) ) {
2331
+  			if (0 < count($question_right_answers)) {
2332 2332
   				$question_right_answer = $question_right_answers;
2333 2333
   			}
2334 2334
   		} // End If Statement
2335
-  		$right_answer_count = count( $question_right_answer );
2335
+  		$right_answer_count = count($question_right_answer);
2336 2336
 
2337 2337
 		// Remove empty values and reindex the array
2338
-  		if ( is_array( $question_wrong_answers ) ) {
2339
-  			$question_wrong_answers_array = array_values( array_filter( $question_wrong_answers, 'strlen' ) );
2338
+  		if (is_array($question_wrong_answers)) {
2339
+  			$question_wrong_answers_array = array_values(array_filter($question_wrong_answers, 'strlen'));
2340 2340
   			$question_wrong_answers = array();
2341 2341
   		} // End If Statement
2342 2342
 
2343
-  		foreach( $question_wrong_answers_array as $answer ) {
2344
-  			if( ! in_array( $answer, $question_wrong_answers ) ) {
2343
+  		foreach ($question_wrong_answers_array as $answer) {
2344
+  			if ( ! in_array($answer, $question_wrong_answers)) {
2345 2345
   				$question_wrong_answers[] = $answer;
2346 2346
   			}
2347 2347
   		}
2348 2348
 
2349
-  		$wrong_answer_count = count( $question_wrong_answers );
2349
+  		$wrong_answer_count = count($question_wrong_answers);
2350 2350
 
2351 2351
   		// Only save if there is a valid title
2352
-  		if ( $post_title != '' ) {
2352
+  		if ($post_title != '') {
2353 2353
 
2354 2354
   			// Get Quiz ID for the question
2355 2355
   		    $quiz_id = $data['quiz_id'];
@@ -2359,86 +2359,86 @@  discard block
 block discarded – undo
2359 2359
 
2360 2360
   		    // Get answer order
2361 2361
   		    $answer_order = '';
2362
-  		    if( isset( $data['answer_order'] ) ) {
2362
+  		    if (isset($data['answer_order'])) {
2363 2363
 				$answer_order = $data['answer_order'];
2364 2364
 			}
2365 2365
 
2366 2366
 			// Get random order selection
2367 2367
 			$random_order = 'no';
2368
-			if( isset( $data['random_order'] ) ) {
2368
+			if (isset($data['random_order'])) {
2369 2369
 				$random_order = $data['random_order'];
2370 2370
 			}
2371 2371
 
2372 2372
   		    // Insert or Update the question
2373
-  		    if ( 0 < $question_id ) {
2373
+  		    if (0 < $question_id) {
2374 2374
 
2375
-  		    	$post_type_args[ 'ID' ] = $question_id;
2376
-		    	$question_id = wp_update_post( $post_type_args );
2375
+  		    	$post_type_args['ID'] = $question_id;
2376
+		    	$question_id = wp_update_post($post_type_args);
2377 2377
 
2378 2378
 		    	// Update poast meta
2379
-		    	if( 'quiz' == $context ) {
2380
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2381
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2382
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2379
+		    	if ('quiz' == $context) {
2380
+		    		$quizzes = get_post_meta($question_id, '_quiz_id', false);
2381
+		    		if ( ! in_array($quiz_id, $quizzes)) {
2382
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2383 2383
 			    	}
2384 2384
 		    	}
2385 2385
 
2386
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2387
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2388
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2389
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2390
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2391
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2392
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2393
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2394
-
2395
-		    	if( 'quiz' != $context ) {
2396
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2386
+		    	update_post_meta($question_id, '_question_grade', $question_grade);
2387
+		    	update_post_meta($question_id, '_question_right_answer', $question_right_answer);
2388
+		    	update_post_meta($question_id, '_right_answer_count', $right_answer_count);
2389
+		    	update_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2390
+		    	update_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2391
+		    	update_post_meta($question_id, '_question_media', $question_media);
2392
+		    	update_post_meta($question_id, '_answer_order', $answer_order);
2393
+		    	update_post_meta($question_id, '_random_order', $random_order);
2394
+
2395
+		    	if ('quiz' != $context) {
2396
+		    		wp_set_post_terms($question_id, array($question_type), 'question-type', false);
2397 2397
 		    	}
2398 2398
 				// Don't store empty value, no point
2399
-				if ( !empty($answer_feedback) ) {
2400
-					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2399
+				if ( ! empty($answer_feedback)) {
2400
+					update_post_meta($question_id, '_answer_feedback', $answer_feedback);
2401 2401
 				}
2402 2402
 
2403 2403
 		    } else {
2404
-				$question_id = wp_insert_post( $post_type_args );
2405
-				$question_count = intval( $data['question_count'] );
2404
+				$question_id = wp_insert_post($post_type_args);
2405
+				$question_count = intval($data['question_count']);
2406 2406
 				++$question_count;
2407 2407
 
2408 2408
 				// Set post meta
2409
-				if( 'quiz' == $context ) {
2410
-					add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2411
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2412
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2409
+				if ('quiz' == $context) {
2410
+					add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2411
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2412
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
2413 2413
 				}
2414 2414
 
2415
-				if( isset( $question_grade ) ) {
2416
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2415
+				if (isset($question_grade)) {
2416
+		    		add_post_meta($question_id, '_question_grade', $question_grade);
2417 2417
 		    	}
2418
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2419
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2420
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2421
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2422
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2423
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2424
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2425
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2418
+		    	add_post_meta($question_id, '_question_right_answer', $question_right_answer);
2419
+		    	add_post_meta($question_id, '_right_answer_count', $right_answer_count);
2420
+		    	add_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2421
+		    	add_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2422
+		    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2423
+		    	add_post_meta($question_id, '_question_media', $question_media);
2424
+		    	add_post_meta($question_id, '_answer_order', $answer_order);
2425
+		    	add_post_meta($question_id, '_random_order', $random_order);
2426 2426
 				// Don't store empty value, no point
2427
-				if ( !empty($answer_feedback) ) {
2428
-					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2427
+				if ( ! empty($answer_feedback)) {
2428
+					add_post_meta($question_id, '_answer_feedback', $answer_feedback);
2429 2429
 				}
2430 2430
 
2431 2431
 		    	// Set the post terms for question-type
2432
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2432
+			    wp_set_post_terms($question_id, array($question_type), 'question-type');
2433 2433
 
2434
-			    if( $question_category ) {
2435
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2434
+			    if ($question_category) {
2435
+	    			wp_set_post_terms($question_id, array($question_category), 'question-category');
2436 2436
 	    		}
2437 2437
 
2438 2438
 		    } // End If Statement
2439 2439
 		} // End If Statement
2440 2440
   		// Check that the insert or update saved by testing the post id
2441
-  		if ( 0 < $question_id ) {
2441
+  		if (0 < $question_id) {
2442 2442
   			$return = $question_id;
2443 2443
   		} // End If Statement
2444 2444
   		return $return;
@@ -2452,20 +2452,20 @@  discard block
 block discarded – undo
2452 2452
 	 * @param array $data (default: array())
2453 2453
 	 * @return boolean
2454 2454
 	 */
2455
-	private function lesson_delete_question( $data = array() ) {
2455
+	private function lesson_delete_question($data = array()) {
2456 2456
 
2457 2457
 		// Get which question to delete
2458 2458
 		$question_id = 0;
2459
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2460
-			$question_id = absint( $data[ 'question_id' ] );
2459
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2460
+			$question_id = absint($data['question_id']);
2461 2461
 		} // End If Statement
2462 2462
 		// Delete the question
2463
-		if ( 0 < $question_id ) {
2464
-			$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2463
+		if (0 < $question_id) {
2464
+			$quizzes = get_post_meta($question_id, '_quiz_id', false);
2465 2465
 
2466
-			foreach( $quizzes as $quiz_id ) {
2467
-				if( $quiz_id == $data['quiz_id'] ) {
2468
-					delete_post_meta( $question_id, '_quiz_id', $quiz_id );
2466
+			foreach ($quizzes as $quiz_id) {
2467
+				if ($quiz_id == $data['quiz_id']) {
2468
+					delete_post_meta($question_id, '_quiz_id', $quiz_id);
2469 2469
 				}
2470 2470
 			}
2471 2471
 
@@ -2484,9 +2484,9 @@  discard block
 block discarded – undo
2484 2484
 	public function lesson_complexities() {
2485 2485
 
2486 2486
 		// V2 - make filter for this array
2487
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2488
-									'std' => __( 'Standard', 'woothemes-sensei' ),
2489
-									'hard' => __( 'Hard', 'woothemes-sensei' )
2487
+        $lesson_complexities = array('easy' => __('Easy', 'woothemes-sensei'),
2488
+									'std' => __('Standard', 'woothemes-sensei'),
2489
+									'hard' => __('Hard', 'woothemes-sensei')
2490 2490
 									);
2491 2491
 
2492 2492
 		return $lesson_complexities;
@@ -2501,9 +2501,9 @@  discard block
 block discarded – undo
2501 2501
 	 * @param string $post_status (default: 'publish')
2502 2502
 	 * @return int
2503 2503
 	 */
2504
-	public function lesson_count( $post_status = 'publish', $course_id = false ) {
2504
+	public function lesson_count($post_status = 'publish', $course_id = false) {
2505 2505
 
2506
-		$post_args = array(	'post_type'         => 'lesson',
2506
+		$post_args = array('post_type'         => 'lesson',
2507 2507
 							'posts_per_page'    => -1,
2508 2508
 //							'orderby'           => 'menu_order date',
2509 2509
 //							'order'             => 'ASC',
@@ -2511,7 +2511,7 @@  discard block
 block discarded – undo
2511 2511
 							'suppress_filters'  => 0,
2512 2512
 							'fields'            => 'ids',
2513 2513
 							);
2514
-		if( $course_id ) {
2514
+		if ($course_id) {
2515 2515
 			$post_args['meta_query'][] = array(
2516 2516
 				'key' => '_lesson_course',
2517 2517
 				'value' => $course_id,
@@ -2528,10 +2528,10 @@  discard block
 block discarded – undo
2528 2528
 
2529 2529
 		// Allow WP to generate the complex final query, just shortcut to only do an overall count
2530 2530
 //		add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2531
-		$lessons_query = new WP_Query( apply_filters( 'sensei_lesson_count', $post_args ) );
2531
+		$lessons_query = new WP_Query(apply_filters('sensei_lesson_count', $post_args));
2532 2532
 //		remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2533 2533
 
2534
-		return count( $lessons_query->posts );
2534
+		return count($lessons_query->posts);
2535 2535
 	} // End lesson_count()
2536 2536
 
2537 2537
 
@@ -2544,11 +2544,11 @@  discard block
 block discarded – undo
2544 2544
 	 * @param string $fields (default: 'ids')
2545 2545
 	 * @return int $quiz_id
2546 2546
 	 */
2547
-	public function lesson_quizzes( $lesson_id = 0, $post_status = 'any', $fields = 'ids' ) {
2547
+	public function lesson_quizzes($lesson_id = 0, $post_status = 'any', $fields = 'ids') {
2548 2548
 
2549 2549
 		$posts_array = array();
2550 2550
 
2551
-		$post_args = array(	'post_type' 		=> 'quiz',
2551
+		$post_args = array('post_type' 		=> 'quiz',
2552 2552
 							'posts_per_page' 		=> 1,
2553 2553
 							'orderby'         	=> 'title',
2554 2554
     						'order'           	=> 'DESC',
@@ -2557,7 +2557,7 @@  discard block
 block discarded – undo
2557 2557
 							'suppress_filters' 	=> 0,
2558 2558
 							'fields'            => $fields
2559 2559
 							);
2560
-		$posts_array = get_posts( $post_args );
2560
+		$posts_array = get_posts($post_args);
2561 2561
         $quiz_id = array_shift($posts_array);
2562 2562
 
2563 2563
 		return $quiz_id;
@@ -2580,37 +2580,37 @@  discard block
 block discarded – undo
2580 2580
      *
2581 2581
 	 * @return array $questions { $question type WP_Post }
2582 2582
 	 */
2583
-	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2583
+	public function lesson_quiz_questions($quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC') {
2584 2584
 
2585 2585
 		$quiz_id = (string) $quiz_id;
2586
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2586
+        $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
2587 2587
 
2588 2588
         // setup the user id
2589
-        if( is_admin() ) {
2590
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2589
+        if (is_admin()) {
2590
+            $user_id = isset($_GET['user']) ? $_GET['user'] : '';
2591 2591
         } else {
2592 2592
             $user_id = get_current_user_id();
2593 2593
         }
2594 2594
 
2595 2595
         // get the users current status on the lesson
2596
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2596
+        $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $user_id);
2597 2597
 
2598 2598
 		// Set the default question order if it has not already been set for this quiz
2599
-		$this->set_default_question_order( $quiz_id );
2599
+		$this->set_default_question_order($quiz_id);
2600 2600
 
2601 2601
 		// If viewing quiz on the frontend then show questions in random order if set
2602
-		if ( ! is_admin() ) {
2603
-			$random_order = get_post_meta( $quiz_id, '_random_question_order', true );
2604
-			if( $random_order && $random_order == 'yes' ) {
2602
+		if ( ! is_admin()) {
2603
+			$random_order = get_post_meta($quiz_id, '_random_question_order', true);
2604
+			if ($random_order && $random_order == 'yes') {
2605 2605
 				$orderby = 'rand';
2606 2606
 			}
2607 2607
 		}
2608 2608
 
2609 2609
 		// Get all questions and multiple questions
2610 2610
 		$question_query_args = array(
2611
-			'post_type' 		=> array( 'question', 'multiple_question' ),
2611
+			'post_type' 		=> array('question', 'multiple_question'),
2612 2612
 			'posts_per_page' 	=> -1,
2613
-			'meta_key'        	=> '_quiz_question_order' . $quiz_id,
2613
+			'meta_key'        	=> '_quiz_question_order'.$quiz_id,
2614 2614
 			'orderby'         	=> $orderby,
2615 2615
 			'order'           	=> $order,
2616 2616
 			'meta_query'		=> array(
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
 		);
2625 2625
 
2626 2626
         //query the questions
2627
-		$questions_query = new WP_Query( $question_query_args );
2627
+		$questions_query = new WP_Query($question_query_args);
2628 2628
 
2629 2629
         // Set return array to initially include all items
2630 2630
         $questions = $questions_query->posts;
@@ -2634,20 +2634,20 @@  discard block
 block discarded – undo
2634 2634
 
2635 2635
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2636 2636
 		$selected_questions = false;
2637
-		if( ! is_admin() || ( is_admin() && isset( $_GET['page'] ) && 'sensei_grading' == $_GET['page'] && isset( $_GET['user'] ) && isset( $_GET['quiz_id'] ) ) ) {
2637
+		if ( ! is_admin() || (is_admin() && isset($_GET['page']) && 'sensei_grading' == $_GET['page'] && isset($_GET['user']) && isset($_GET['quiz_id']))) {
2638 2638
 
2639 2639
 			// Fetch the questions that the user was asked in their quiz if they have already completed it
2640
-			$questions_asked_string = !empty( $user_lesson_status->comment_ID) ? get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ) : false;
2641
-			if( !empty($questions_asked_string) ) {
2640
+			$questions_asked_string = ! empty($user_lesson_status->comment_ID) ? get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true) : false;
2641
+			if ( ! empty($questions_asked_string)) {
2642 2642
 
2643
-				$selected_questions = explode( ',', $questions_asked_string );
2643
+				$selected_questions = explode(',', $questions_asked_string);
2644 2644
 
2645 2645
 				// Fetch each question in the order in which they were asked
2646 2646
 				$questions = array();
2647
-				foreach( $selected_questions as $question_id ) {
2648
-					if( ! $question_id ) continue;
2649
-					$question = get_post( $question_id );
2650
-					if( ! isset( $question ) || ! isset( $question->ID ) ) continue;
2647
+				foreach ($selected_questions as $question_id) {
2648
+					if ( ! $question_id) continue;
2649
+					$question = get_post($question_id);
2650
+					if ( ! isset($question) || ! isset($question->ID)) continue;
2651 2651
 					$questions[] = $question;
2652 2652
 				}
2653 2653
 
@@ -2659,24 +2659,24 @@  discard block
 block discarded – undo
2659 2659
 				$existing_questions = array();
2660 2660
 
2661 2661
 				// Set array of questions that already exist so we can prevent duplicates from appearing
2662
-				foreach( $questions_array as $question ) {
2663
-					if( 'question' != $question->post_type ) continue;
2662
+				foreach ($questions_array as $question) {
2663
+					if ('question' != $question->post_type) continue;
2664 2664
 					$existing_questions[] = $question->ID;
2665 2665
 				}
2666 2666
 
2667 2667
 				// Include only single questions in the return array
2668 2668
 				$questions_loop = $questions_array;
2669 2669
 				$questions_array = array();
2670
-				foreach( $questions_loop as $k => $question ) {
2670
+				foreach ($questions_loop as $k => $question) {
2671 2671
 
2672 2672
 					// If this is a single question then include it
2673
-					if( 'question' == $question->post_type ) {
2673
+					if ('question' == $question->post_type) {
2674 2674
 						$questions_array[] = $question;
2675 2675
 					} else {
2676 2676
 
2677 2677
 						// If this is a multiple question then get the specified amount of questions from the specified category
2678
-						$question_cat = intval( get_post_meta( $question->ID, 'category', true ) );
2679
-						$question_number = intval( get_post_meta( $question->ID, 'number', true ) );
2678
+						$question_cat = intval(get_post_meta($question->ID, 'category', true));
2679
+						$question_number = intval(get_post_meta($question->ID, 'number', true));
2680 2680
 
2681 2681
 						$qargs = array(
2682 2682
 							'post_type' 		=> 'question',
@@ -2693,14 +2693,14 @@  discard block
 block discarded – undo
2693 2693
 							'suppress_filters' 	=> 0,
2694 2694
 							'post__not_in'		=> $existing_questions,
2695 2695
 						);
2696
-						$cat_questions = get_posts( $qargs );
2696
+						$cat_questions = get_posts($qargs);
2697 2697
 
2698 2698
 						// Merge results into return array
2699
-						$questions_array = array_merge( $questions_array, $cat_questions );
2699
+						$questions_array = array_merge($questions_array, $cat_questions);
2700 2700
 
2701 2701
 						// Add selected questions to existing questions array to prevent duplicates from being added
2702
-						foreach( $questions_array as $cat_question ) {
2703
-							if( in_array( $cat_question->ID, $existing_questions ) ) continue;
2702
+						foreach ($questions_array as $cat_question) {
2703
+							if (in_array($cat_question->ID, $existing_questions)) continue;
2704 2704
 							$existing_questions[] = $cat_question->ID;
2705 2705
 						}
2706 2706
 					}
@@ -2712,29 +2712,29 @@  discard block
 block discarded – undo
2712 2712
 		}
2713 2713
 
2714 2714
 		// If user has not already taken the quiz and a limited number of questions are to be shown, then show a random selection of the specified amount of questions
2715
-		if( ! $selected_questions ) {
2715
+		if ( ! $selected_questions) {
2716 2716
 
2717 2717
 			// Only limit questions like this on the frontend
2718
-			if( ! is_admin() ) {
2718
+			if ( ! is_admin()) {
2719 2719
 
2720 2720
 				// Get number of questions to show
2721
-				$show_questions = intval( get_post_meta( $quiz_id, '_show_questions', true ) );
2722
-				if( $show_questions ) {
2721
+				$show_questions = intval(get_post_meta($quiz_id, '_show_questions', true));
2722
+				if ($show_questions) {
2723 2723
 
2724 2724
 					// Get random set of array keys from selected questions array
2725
-					$selected_questions = array_rand( $questions_array, $show_questions );
2725
+					$selected_questions = array_rand($questions_array, $show_questions);
2726 2726
 
2727 2727
 					// Loop through all questions and pick the the ones to be shown based on the random key selection
2728 2728
 					$questions = array();
2729
-					foreach( $questions_array as $k => $question ) {
2729
+					foreach ($questions_array as $k => $question) {
2730 2730
 
2731 2731
 						// Random keys will always be an array, unless only one question is to be shown
2732
-						if( is_array( $selected_questions ) ) {
2733
-							if( in_array( $k, $selected_questions ) ) {
2732
+						if (is_array($selected_questions)) {
2733
+							if (in_array($k, $selected_questions)) {
2734 2734
 								$questions[] = $question;
2735 2735
 							}
2736
-						} elseif( 1 == $show_questions ) {
2737
-							if ( $selected_questions == $k ) {
2736
+						} elseif (1 == $show_questions) {
2737
+							if ($selected_questions == $k) {
2738 2738
 								$questions[] = $question;
2739 2739
 							}
2740 2740
 						}
@@ -2745,12 +2745,12 @@  discard block
 block discarded – undo
2745 2745
 
2746 2746
         // Save the questions that will be asked for the current user
2747 2747
         // this happens only once per user/quiz, unless the user resets the quiz
2748
-        if( ! is_admin() ){
2748
+        if ( ! is_admin()) {
2749 2749
 
2750
-            if( $user_lesson_status ) {
2750
+            if ($user_lesson_status) {
2751 2751
 
2752 2752
                 $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2753
-                if ( empty($questions_asked) && $user_lesson_status) {
2753
+                if (empty($questions_asked) && $user_lesson_status) {
2754 2754
 
2755 2755
                     $questions_asked = array();
2756 2756
                     foreach ($questions as $question) {
@@ -2773,7 +2773,7 @@  discard block
 block discarded – undo
2773 2773
          * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2774 2774
          * @since 1.8.0
2775 2775
          */
2776
-		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2776
+		return apply_filters('sensei_lesson_quiz_questions', $questions, $quiz_id);
2777 2777
 
2778 2778
 	} // End lesson_quiz_questions()
2779 2779
 
@@ -2781,13 +2781,13 @@  discard block
 block discarded – undo
2781 2781
 	 * Set the default quiz order
2782 2782
 	 * @param integer $quiz_id ID of quiz
2783 2783
 	 */
2784
-	public function set_default_question_order( $quiz_id = 0 ) {
2784
+	public function set_default_question_order($quiz_id = 0) {
2785 2785
 
2786
-		if( $quiz_id ) {
2786
+		if ($quiz_id) {
2787 2787
 
2788
-			$question_order = get_post_meta( $quiz_id, '_question_order', true );
2788
+			$question_order = get_post_meta($quiz_id, '_question_order', true);
2789 2789
 
2790
-			if( ! $question_order ) {
2790
+			if ( ! $question_order) {
2791 2791
 
2792 2792
 				$args = array(
2793 2793
 					'post_type' 		=> 'question',
@@ -2803,11 +2803,11 @@  discard block
 block discarded – undo
2803 2803
 					'post_status'		=> 'any',
2804 2804
 					'suppress_filters' 	=> 0
2805 2805
 				);
2806
-				$questions = get_posts( $args );
2806
+				$questions = get_posts($args);
2807 2807
 
2808 2808
 				$o = 1;
2809
-				foreach( $questions as $question ) {
2810
-					add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $o, true );
2809
+				foreach ($questions as $question) {
2810
+					add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$o, true);
2811 2811
 					$o++;
2812 2812
 				}
2813 2813
 			}
@@ -2826,36 +2826,36 @@  discard block
 block discarded – undo
2826 2826
 	 * @param string $height (default: '100')
2827 2827
 	 * @return string
2828 2828
 	 */
2829
-	public function lesson_image( $lesson_id = 0, $width = '100', $height = '100', $widget = false ) {
2829
+	public function lesson_image($lesson_id = 0, $width = '100', $height = '100', $widget = false) {
2830 2830
 
2831 2831
 		$html = '';
2832 2832
 
2833 2833
 		// Get Width and Height settings
2834
-		if ( ( $width == '100' ) && ( $height == '100' ) ) {
2834
+		if (($width == '100') && ($height == '100')) {
2835 2835
 
2836
-			if ( is_singular( 'lesson' ) ) {
2836
+			if (is_singular('lesson')) {
2837 2837
 
2838
-				if ( ! $widget && ! Sensei()->settings->settings[ 'lesson_single_image_enable' ] ) {
2838
+				if ( ! $widget && ! Sensei()->settings->settings['lesson_single_image_enable']) {
2839 2839
 
2840 2840
 					return '';
2841 2841
 
2842 2842
 				} // End If Statement
2843 2843
 
2844 2844
 				$image_thumb_size = 'lesson_single_image';
2845
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2845
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2846 2846
 				$width = $dimensions['width'];
2847 2847
 				$height = $dimensions['height'];
2848 2848
 				$crop = $dimensions['crop'];
2849 2849
 
2850 2850
 			} else {
2851 2851
 
2852
-				if ( ! $widget && ! Sensei()->settings->settings[ 'course_lesson_image_enable' ] ) {
2852
+				if ( ! $widget && ! Sensei()->settings->settings['course_lesson_image_enable']) {
2853 2853
 
2854 2854
 					return '';
2855 2855
 				} // End If Statement
2856 2856
 
2857 2857
 				$image_thumb_size = 'lesson_archive_image';
2858
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2858
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2859 2859
 				$width = $dimensions['width'];
2860 2860
 				$height = $dimensions['height'];
2861 2861
 				$crop = $dimensions['crop'];
@@ -2866,23 +2866,23 @@  discard block
 block discarded – undo
2866 2866
 
2867 2867
 		$img_url = '';
2868 2868
 
2869
-		if ( has_post_thumbnail( $lesson_id ) ) {
2869
+		if (has_post_thumbnail($lesson_id)) {
2870 2870
 
2871 2871
    			// Get Featured Image
2872
-   			$img_url = get_the_post_thumbnail( $lesson_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
2872
+   			$img_url = get_the_post_thumbnail($lesson_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
2873 2873
 
2874 2874
  		} else {
2875 2875
 
2876 2876
  			// Display Image Placeholder if none
2877
-			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2877
+			if (Sensei()->settings->settings['placeholder_images_enable']) {
2878 2878
 
2879
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2879
+                $img_url = apply_filters('sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/'.$width.'x'.$height.'" class="woo-image thumbnail alignleft" />');
2880 2880
 
2881 2881
 			} // End If Statement
2882 2882
 
2883 2883
 		} // End If Statement
2884 2884
 
2885
-		$html .= '<a href="' . get_permalink( $lesson_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $lesson_id ) ) . '">' . $img_url . '</a>';
2885
+		$html .= '<a href="'.get_permalink($lesson_id).'" title="'.esc_attr(get_post_field('post_title', $lesson_id)).'">'.$img_url.'</a>';
2886 2886
 
2887 2887
 		return $html;
2888 2888
 
@@ -2894,9 +2894,9 @@  discard block
 block discarded – undo
2894 2894
      * @since 1.9.0
2895 2895
      * @param integer $lesson_id
2896 2896
      */
2897
-    public static function the_lesson_image( $lesson_id = 0 ){
2897
+    public static function the_lesson_image($lesson_id = 0) {
2898 2898
 
2899
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2899
+        echo Sensei()->lesson->lesson_image($lesson_id);
2900 2900
 
2901 2901
     }
2902 2902
 
@@ -2907,17 +2907,17 @@  discard block
 block discarded – undo
2907 2907
      * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2908 2908
 	 * @return string
2909 2909
 	 */
2910
-	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2910
+	public static function lesson_excerpt($lesson = null, $add_p_tags = true) {
2911 2911
 		$html = '';
2912
-		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2912
+		if (is_a($lesson, 'WP_Post') && 'lesson' == $lesson->post_type) {
2913 2913
 
2914
-            $excerpt =  $lesson->post_excerpt;
2914
+            $excerpt = $lesson->post_excerpt;
2915 2915
 
2916 2916
             // if $add_p_tags true wrap with <p> else return the excerpt as is
2917
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2917
+            $html = $add_p_tags ? wpautop($excerpt) : $excerpt;
2918 2918
 
2919 2919
 		}
2920
-		return apply_filters( 'sensei_lesson_excerpt', $html );
2920
+		return apply_filters('sensei_lesson_excerpt', $html);
2921 2921
 
2922 2922
 	} // End lesson_excerpt()
2923 2923
 
@@ -2930,20 +2930,20 @@  discard block
 block discarded – undo
2930 2930
      * @param int $lesson_id
2931 2931
      * @return int|bool $course_id or bool when nothing is found.
2932 2932
      */
2933
-     public function get_course_id( $lesson_id ){
2933
+     public function get_course_id($lesson_id) {
2934 2934
 
2935
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2936
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2935
+         if ( ! isset($lesson_id) || empty($lesson_id)
2936
+         ||  'lesson' != get_post_type($lesson_id)) {
2937 2937
              return false;
2938 2938
          }
2939 2939
 
2940
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2940
+         $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
2941 2941
 
2942 2942
          // make sure the course id is valid
2943
-         if( empty( $lesson_course_id )
2944
-             || is_array( $lesson_course_id )
2945
-             || intval( $lesson_course_id ) < 1
2946
-             || 'course' != get_post_type( $lesson_course_id ) ){
2943
+         if (empty($lesson_course_id)
2944
+             || is_array($lesson_course_id)
2945
+             || intval($lesson_course_id) < 1
2946
+             || 'course' != get_post_type($lesson_course_id)) {
2947 2947
 
2948 2948
              return false;
2949 2949
 
@@ -2970,11 +2970,11 @@  discard block
 block discarded – undo
2970 2970
      * @param string $post_type
2971 2971
      * @return void
2972 2972
      */
2973
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2973
+    public function all_lessons_edit_fields($column_name, $post_type) {
2974 2974
 
2975 2975
         // only show these options ont he lesson post type edit screen
2976
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name
2977
-            || ! current_user_can( 'edit_lessons' ) ) {
2976
+        if ('lesson' != $post_type || 'lesson-course' != $column_name
2977
+            || ! current_user_can('edit_lessons')) {
2978 2978
             return;
2979 2979
         }
2980 2980
 
@@ -2982,41 +2982,41 @@  discard block
 block discarded – undo
2982 2982
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2983 2983
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2984 2984
                     <?php
2985
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2985
+                    echo '<h4>'.__('Lesson Information', 'woothemes-sensei').'</h4>';
2986 2986
                     // create a nonce field to be  used as a security measure when saving the data
2987
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2988
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2987
+                    wp_nonce_field('bulk-edit-lessons', '_edit_lessons_nonce');
2988
+                    wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce');
2989 2989
 
2990 2990
                     // unchanged option - we need this in because
2991 2991
                     // the default option in bulk edit should not be empty. If it is
2992 2992
                     // the user will erase data they didn't want to touch.
2993
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2993
+                    $no_change_text = '-- '.__('No Change', 'woothemes-sensei').' --';
2994 2994
 
2995 2995
                     //
2996 2996
                     //course selection
2997 2997
                     //
2998
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2998
+                    $courses = WooThemes_Sensei_Course::get_all_courses();
2999 2999
                     $course_options = array();
3000
-                    if ( count( $courses ) > 0 ) {
3001
-                        foreach ($courses as $course ){
3002
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
3000
+                    if (count($courses) > 0) {
3001
+                        foreach ($courses as $course) {
3002
+                            $course_options[$course->ID] = get_the_title($course->ID);
3003 3003
                         }
3004 3004
                     }
3005 3005
                     //pre-append the no change option
3006
-                    $course_options['-1']=  $no_change_text;
3007
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
3008
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3009
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3006
+                    $course_options['-1'] = $no_change_text;
3007
+                    $course_attributes = array('name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course', 'class'=>' ');
3008
+                    $course_field = Sensei_Utils::generate_drop_down('-1', $course_options, $course_attributes);
3009
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Course', 'woothemes-sensei'), $course_field);
3010 3010
 
3011 3011
                     //
3012 3012
                     // lesson complexity selection
3013 3013
                     //
3014
-                    $lesson_complexities =  $this->lesson_complexities();
3014
+                    $lesson_complexities = $this->lesson_complexities();
3015 3015
                     //pre-append the no change option
3016
-                    $lesson_complexities['-1']=  $no_change_text;
3017
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3018
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3019
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3016
+                    $lesson_complexities['-1'] = $no_change_text;
3017
+                    $complexity_dropdown_attributes = array('name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity', 'class'=>' ');
3018
+                    $complexity_filed = Sensei_Utils::generate_drop_down('-1', $lesson_complexities, $complexity_dropdown_attributes);
3019
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Complexity', 'woothemes-sensei'), $complexity_filed);
3020 3020
 
3021 3021
                     ?>
3022 3022
 
@@ -3029,34 +3029,34 @@  discard block
 block discarded – undo
3029 3029
                     //
3030 3030
                     $pass_required_options = array(
3031 3031
                         '-1' => $no_change_text,
3032
-                         '0' => __('No','woothemes'),
3033
-                         '1' => __('Yes','woothemes'),
3032
+                         '0' => __('No', 'woothemes'),
3033
+                         '1' => __('Yes', 'woothemes'),
3034 3034
                     );
3035 3035
 
3036
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3036
+                    $pass_required_select_attributes = array('name'=> 'pass_required',
3037 3037
                                                                 'id'=> 'sensei-edit-lesson-pass-required',
3038
-                                                                'class'=>' '   );
3039
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3040
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3038
+                                                                'class'=>' ');
3039
+                    $require_pass_field = Sensei_Utils::generate_drop_down('-1', $pass_required_options, $pass_required_select_attributes, false);
3040
+                    echo $this->generate_all_lessons_edit_field(__('Pass required', 'woothemes-sensei'), $require_pass_field);
3041 3041
 
3042 3042
                     //
3043 3043
                     // Quiz pass percentage
3044 3044
                     //
3045 3045
                     $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3046
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3046
+                    echo $this->generate_all_lessons_edit_field(__('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field);
3047 3047
 
3048 3048
                     //
3049 3049
                     // Enable quiz reset button
3050 3050
                     //
3051 3051
                     $quiz_reset_select__options = array(
3052 3052
                         '-1' => $no_change_text,
3053
-                        '0' => __('No','woothemes'),
3054
-                        '1' => __('Yes','woothemes'),
3053
+                        '0' => __('No', 'woothemes'),
3054
+                        '1' => __('Yes', 'woothemes'),
3055 3055
                     );
3056 3056
                     $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3057
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3058
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3059
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3057
+                    $quiz_reset_select_attributes = array('name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ');
3058
+                    $quiz_reset_field = Sensei_Utils::generate_drop_down('-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false);
3059
+                    echo $this->generate_all_lessons_edit_field(__('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field);
3060 3060
 
3061 3061
                     ?>
3062 3062
             </div>
@@ -3075,17 +3075,17 @@  discard block
 block discarded – undo
3075 3075
      * @param string $field type markup for the field that must be wrapped.
3076 3076
      * @return string $field_html
3077 3077
      */
3078
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3078
+    public function generate_all_lessons_edit_field($title, $field) {
3079 3079
 
3080 3080
         $html = '';
3081 3081
         $html = '<div class="inline-edit-group" >';
3082
-        $html .=  '<span class="title">'. $title .'</span> ';
3082
+        $html .= '<span class="title">'.$title.'</span> ';
3083 3083
         $html .= '<span class="input-text-wrap">';
3084 3084
         $html .= $field;
3085 3085
         $html .= '</span>';
3086 3086
         $html .= '</label></div>';
3087 3087
 
3088
-        return $html ;
3088
+        return $html;
3089 3089
 
3090 3090
     }//end generate_all_lessons_edit_field
3091 3091
 
@@ -3099,48 +3099,48 @@  discard block
 block discarded – undo
3099 3099
     function save_all_lessons_edit_fields() {
3100 3100
 
3101 3101
         // verify all the data before attempting to save
3102
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3103
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3102
+        if ( ! isset($_POST['security']) || ! check_ajax_referer('bulk-edit-lessons', 'security')
3103
+            ||  empty($_POST['post_ids']) || ! is_array($_POST['post_ids'])) {
3104 3104
             die();
3105 3105
         }
3106 3106
 
3107 3107
         // get our variables
3108
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3109
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3110
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3111
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3112
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3108
+        $new_course = sanitize_text_field($_POST['sensei_edit_lesson_course']);
3109
+        $new_complexity = sanitize_text_field($_POST['sensei_edit_complexity']);
3110
+        $new_pass_required = sanitize_text_field($_POST['sensei_edit_pass_required']);
3111
+        $new_pass_percentage = sanitize_text_field($_POST['sensei_edit_pass_percentage']);
3112
+        $new_enable_quiz_reset = sanitize_text_field($_POST['sensei_edit_enable_quiz_reset']);
3113 3113
         // store the values for all selected posts
3114
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3114
+        foreach ($_POST['post_ids'] as $lesson_id) {
3115 3115
 
3116 3116
             // get the quiz id needed for the quiz meta
3117
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3117
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
3118 3118
 
3119 3119
             // do not save the items if the value is -1 as this
3120 3120
             // means it was not changed
3121 3121
 
3122 3122
             // update lesson course
3123
-            if( -1 != $new_course ){
3124
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3123
+            if ( -1 != $new_course ) {
3124
+                update_post_meta($lesson_id, '_lesson_course', $new_course);
3125 3125
             }
3126 3126
             // update lesson complexity
3127
-            if( -1 != $new_complexity ){
3128
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3127
+            if ( -1 != $new_complexity ) {
3128
+                update_post_meta($lesson_id, '_lesson_complexity', $new_complexity);
3129 3129
             }
3130 3130
 
3131 3131
             // Quiz Related settings
3132
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3132
+            if (isset($quiz_id) && 0 < intval($quiz_id)) {
3133 3133
 
3134 3134
                 // update pass required
3135 3135
                 if (-1 != $new_pass_required) {
3136 3136
 
3137
-                    $checked = $new_pass_required  ? 'on' : '';
3137
+                    $checked = $new_pass_required ? 'on' : '';
3138 3138
                     update_post_meta($quiz_id, '_pass_required', $checked);
3139
-                    unset( $checked );
3139
+                    unset($checked);
3140 3140
                 }
3141 3141
 
3142 3142
                 // update pass percentage
3143
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3143
+                if ( ! empty($new_pass_percentage) && is_numeric($new_pass_percentage)) {
3144 3144
 
3145 3145
                         update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3146 3146
 
@@ -3151,9 +3151,9 @@  discard block
 block discarded – undo
3151 3151
                 //
3152 3152
                 if (-1 != $new_enable_quiz_reset ) {
3153 3153
 
3154
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3154
+                    $checked = $new_enable_quiz_reset ? 'on' : '';
3155 3155
                     update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3156
-                    unset( $checked );
3156
+                    unset($checked);
3157 3157
 
3158 3158
                 }
3159 3159
 
@@ -3177,31 +3177,31 @@  discard block
 block discarded – undo
3177 3177
      * @since 1.8.0
3178 3178
      * @return void
3179 3179
      */
3180
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3180
+    public function set_quick_edit_admin_defaults($column_name, $post_id) {
3181 3181
 
3182
-        if( 'lesson-course' != $column_name ){
3182
+        if ('lesson-course' != $column_name) {
3183 3183
             return;
3184 3184
         }
3185 3185
         // load the script
3186
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3186
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
+        wp_enqueue_script('sensei-lesson-quick-edit', Sensei()->plugin_url.'assets/js/admin/lesson-quick-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
3188 3188
 
3189 3189
         // setup the values for all meta fields
3190 3190
         $data = array();
3191
-        foreach( $this->meta_fields as $field ){
3191
+        foreach ($this->meta_fields as $field) {
3192 3192
 
3193
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3193
+            $data[$field] = get_post_meta($post_id, '_'.$field, true);
3194 3194
 
3195 3195
         }
3196 3196
         // add quiz meta fields
3197
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3198
-        foreach( Sensei()->quiz->meta_fields as $field ){
3197
+        $quiz_id = Sensei()->lesson->lesson_quizzes($post_id);
3198
+        foreach (Sensei()->quiz->meta_fields as $field) {
3199 3199
 
3200
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3200
+            $data[$field] = get_post_meta($quiz_id, '_'.$field, true);
3201 3201
 
3202 3202
         }
3203 3203
 
3204
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3204
+        wp_localize_script('sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data);
3205 3205
 
3206 3206
     }// end quick edit admin defaults
3207 3207
 
@@ -3214,19 +3214,19 @@  discard block
 block discarded – undo
3214 3214
      * @param array $classes
3215 3215
      * @return array $classes
3216 3216
      */
3217
-    public static function single_course_lessons_classes( $classes ){
3217
+    public static function single_course_lessons_classes($classes) {
3218 3218
 
3219
-        if(  is_singular('course') ){
3219
+        if (is_singular('course')) {
3220 3220
 
3221 3221
             global $post;
3222 3222
             $course_id = $post->ID;
3223 3223
 
3224
-            $lesson_classes = array( 'course', 'post' );
3225
-            if ( is_user_logged_in() ) {
3224
+            $lesson_classes = array('course', 'post');
3225
+            if (is_user_logged_in()) {
3226 3226
 
3227 3227
                 // Check if Lesson is complete
3228
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3229
-                if ( $single_lesson_complete ) {
3228
+                $single_lesson_complete = Sensei_Utils::user_completed_lesson(get_the_ID(), get_current_user_id());
3229
+                if ($single_lesson_complete) {
3230 3230
 
3231 3231
                     $lesson_classes[] = 'lesson-completed';
3232 3232
 
@@ -3234,14 +3234,14 @@  discard block
 block discarded – undo
3234 3234
 
3235 3235
             } // End If Statement
3236 3236
 
3237
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3238
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3237
+            $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3238
+            if (Sensei_Utils::is_preview_lesson(get_the_ID()) && ! $is_user_taking_course) {
3239 3239
 
3240 3240
                 $lesson_classes[] = 'lesson-preview';
3241 3241
 
3242 3242
             }
3243 3243
 
3244
-            $classes = array_merge( $classes, $lesson_classes  );
3244
+            $classes = array_merge($classes, $lesson_classes);
3245 3245
 
3246 3246
         }
3247 3247
 
@@ -3255,56 +3255,56 @@  discard block
 block discarded – undo
3255 3255
      * @since 1.9.0
3256 3256
      * @param $lesson_id
3257 3257
      */
3258
-    public static function the_lesson_meta( $lesson_id ){
3258
+    public static function the_lesson_meta($lesson_id) {
3259 3259
 
3260 3260
         global $wp_query;
3261 3261
         $loop_lesson_number = $wp_query->current_post + 1;
3262 3262
 
3263
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3263
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
3264 3264
         $single_lesson_complete = false;
3265
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3265
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3266 3266
 
3267 3267
         // Get Lesson data
3268 3268
         $complexity_array = Sensei()->lesson->lesson_complexities();
3269 3269
 
3270
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3271
-        if ( '' != $lesson_complexity ) {
3270
+        $lesson_complexity = get_post_meta($lesson_id, '_lesson_complexity', true);
3271
+        if ('' != $lesson_complexity) {
3272 3272
 
3273 3273
             $lesson_complexity = $complexity_array[$lesson_complexity];
3274 3274
 
3275 3275
         }
3276
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3277
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3276
+        $user_info = get_userdata(absint(get_post()->post_author));
3277
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3278 3278
         $preview_label = '';
3279
-        if ( $is_preview && !$is_user_taking_course ) {
3279
+        if ($is_preview && ! $is_user_taking_course) {
3280 3280
 
3281
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3282
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3281
+            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text($lesson_id);
3282
+            $preview_label = '<span class="preview-heading">'.$preview_label.'</span>';
3283 3283
 
3284 3284
         }
3285 3285
 
3286 3286
 
3287
-        $count_markup= '';
3287
+        $count_markup = '';
3288 3288
         /**
3289 3289
          * Filter for if you want the $lesson_count to show next to the lesson.
3290 3290
          *
3291 3291
          * @since 1.0
3292 3292
          * @param bool default false.
3293 3293
          */
3294
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3294
+        if (apply_filters('sensei_show_lesson_numbers', false)) {
3295 3295
 
3296
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3296
+            $count_markup = '<span class="lesson-number">'.$loop_lesson_number.'</span>';
3297 3297
 
3298 3298
         }
3299 3299
 
3300
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3300
+        $heading_link_title = sprintf(__('Start %s', 'woothemes-sensei'), get_the_title($lesson_id));
3301 3301
 
3302 3302
         ?>
3303 3303
         <header>
3304 3304
             <h2>
3305
-                <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
3306
-                   title="<?php esc_attr_e( $heading_link_title ) ?>" >
3307
-                    <?php echo $count_markup. get_the_title( $lesson_id ) . $preview_label; ?>
3305
+                <a href="<?php echo esc_url_raw(get_permalink($lesson_id)) ?>"
3306
+                   title="<?php esc_attr_e($heading_link_title) ?>" >
3307
+                    <?php echo $count_markup.get_the_title($lesson_id).$preview_label; ?>
3308 3308
                 </a>
3309 3309
             </h2>
3310 3310
 
@@ -3313,33 +3313,33 @@  discard block
 block discarded – undo
3313 3313
                 <?php
3314 3314
 
3315 3315
                 $meta_html = '';
3316
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3316
+                $user_lesson_status = Sensei_Utils::user_lesson_status(get_the_ID(), get_current_user_id());
3317 3317
 
3318
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3319
-                if ( '' != $lesson_length ) {
3318
+                $lesson_length = get_post_meta($lesson_id, '_lesson_length', true);
3319
+                if ('' != $lesson_length) {
3320 3320
 
3321
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3321
+                    $meta_html .= '<span class="lesson-length">'.__('Length: ', 'woothemes-sensei').$lesson_length.__(' minutes', 'woothemes-sensei').'</span>';
3322 3322
 
3323 3323
                 }
3324 3324
 
3325
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3325
+                if (Sensei()->settings->get('lesson_author')) {
3326 3326
 
3327
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3327
+                    $meta_html .= '<span class="lesson-author">'.__('Author: ', 'woothemes-sensei').'<a href="'.get_author_posts_url(absint(get_post()->post_author)).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>';
3328 3328
 
3329 3329
                 } // End If Statement
3330
-                if ( '' != $lesson_complexity ) {
3330
+                if ('' != $lesson_complexity) {
3331 3331
 
3332
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3332
+                    $meta_html .= '<span class="lesson-complexity">'.__('Complexity: ', 'woothemes-sensei').$lesson_complexity.'</span>';
3333 3333
 
3334 3334
                 }
3335 3335
 
3336
-                if ( $single_lesson_complete ) {
3336
+                if ($single_lesson_complete) {
3337 3337
 
3338
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3338
+                    $meta_html .= '<span class="lesson-status complete">'.__('Complete', 'woothemes-sensei').'</span>';
3339 3339
 
3340
-                } elseif ( $user_lesson_status ) {
3340
+                } elseif ($user_lesson_status) {
3341 3341
 
3342
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3342
+                    $meta_html .= '<span class="lesson-status in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
3343 3343
 
3344 3344
                 } // End If Statement
3345 3345
 
@@ -3362,19 +3362,19 @@  discard block
 block discarded – undo
3362 3362
      *
3363 3363
      * @param $lesson_id
3364 3364
      */
3365
-    public static function the_lesson_thumbnail( $lesson_id ){
3365
+    public static function the_lesson_thumbnail($lesson_id) {
3366 3366
 
3367
-        if( empty( $lesson_id ) ){
3367
+        if (empty($lesson_id)) {
3368 3368
 
3369 3369
             $lesson_id = get_the_ID();
3370 3370
 
3371 3371
         }
3372 3372
 
3373
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3373
+        if ('lesson' != get_post_type($lesson_id)) {
3374 3374
             return;
3375 3375
         }
3376 3376
 
3377
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3377
+        echo Sensei()->lesson->lesson_image($lesson_id);
3378 3378
     }
3379 3379
 
3380 3380
 
@@ -3385,14 +3385,14 @@  discard block
 block discarded – undo
3385 3385
      * @param string $excerpt
3386 3386
      * @return string $excerpt
3387 3387
      */
3388
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3388
+    public static function alter_the_lesson_excerpt($excerpt) {
3389 3389
 
3390
-        if ('lesson' == get_post_type(get_the_ID())){
3390
+        if ('lesson' == get_post_type(get_the_ID())) {
3391 3391
 
3392 3392
             // remove this hooks to avoid an infinite loop.
3393
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3393
+            remove_filter('get_the_excerpt', array('WooThemes_Sensei_Lesson', 'alter_the_lesson_excerpt'));
3394 3394
 
3395
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3395
+            return WooThemes_Sensei_Lesson::lesson_excerpt(get_post(get_the_ID()));
3396 3396
         }
3397 3397
 
3398 3398
         return $excerpt;
@@ -3407,20 +3407,20 @@  discard block
 block discarded – undo
3407 3407
      * @param $current_lesson_id
3408 3408
      * @return mixed | bool | int $prerequisite_lesson_id or false
3409 3409
      */
3410
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3410
+    public static function get_lesson_prerequisite_id($current_lesson_id) {
3411 3411
 
3412
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3412
+        $prerequisite_lesson_id = get_post_meta($current_lesson_id, '_lesson_prerequisite', true);
3413 3413
 
3414 3414
         // set ti to false if not a valid prerequisite lesson id
3415
-        if(  empty( $prerequisite_lesson_id )
3416
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3417
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3415
+        if (empty($prerequisite_lesson_id)
3416
+            || 'lesson' != get_post_type($prerequisite_lesson_id)
3417
+            || $prerequisite_lesson_id == $current_lesson_id) {
3418 3418
 
3419 3419
             $prerequisite_lesson_id = false;
3420 3420
 
3421 3421
         }
3422 3422
 
3423
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3423
+        return apply_filters('sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id);
3424 3424
 
3425 3425
     }
3426 3426
 
@@ -3435,27 +3435,27 @@  discard block
 block discarded – undo
3435 3435
      * @param $user_id
3436 3436
      * @return bool
3437 3437
      */
3438
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3438
+    public  static function is_prerequisite_complete($lesson_id, $user_id) {
3439 3439
 
3440
-        if( empty( $lesson_id ) || empty( $user_id )
3441
-        || 'lesson' != get_post_type( $lesson_id )
3442
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3440
+        if (empty($lesson_id) || empty($user_id)
3441
+        || 'lesson' != get_post_type($lesson_id)
3442
+        ||  ! is_a(get_user_by('id', $user_id), 'WP_User')) {
3443 3443
 
3444 3444
             return false;
3445 3445
 
3446 3446
         }
3447 3447
 
3448
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3448
+        $pre_requisite_id = (string) self::get_lesson_prerequisite_id($lesson_id);
3449 3449
 
3450 3450
         // not a valid pre-requisite so pre-requisite is completed
3451
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3452
-            || ! is_numeric( $pre_requisite_id ) ){
3451
+        if ('lesson' != get_post_type($pre_requisite_id)
3452
+            || ! is_numeric($pre_requisite_id)) {
3453 3453
 
3454 3454
             return true;
3455 3455
 
3456 3456
         }
3457 3457
 
3458
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3458
+        return  Sensei_Utils::user_completed_lesson($pre_requisite_id, $user_id);
3459 3459
 
3460 3460
     }// end is_prerequisite_complete
3461 3461
 
@@ -3464,20 +3464,20 @@  discard block
 block discarded – undo
3464 3464
      *
3465 3465
      * @since 1.9.0
3466 3466
      */
3467
-    public  static function user_not_taking_course_message(){
3467
+    public  static function user_not_taking_course_message() {
3468 3468
 
3469 3469
         $lesson_id = get_the_ID();
3470 3470
 
3471
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3471
+        if ('lesson' != get_post_type($lesson_id)) {
3472 3472
             return;
3473 3473
         }
3474 3474
 
3475
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3476
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3477
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3478
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3475
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3476
+        $pre_requisite_complete = self::is_prerequisite_complete($lesson_id, get_current_user_id());
3477
+        $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
3478
+        $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, get_current_user_id());
3479 3479
 
3480
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3480
+        if ($pre_requisite_complete && $is_preview && ! $user_taking_course) {
3481 3481
 
3482 3482
 
3483 3483
         }// end if
@@ -3491,11 +3491,11 @@  discard block
 block discarded – undo
3491 3491
      *
3492 3492
      * @since 1.9.0
3493 3493
      */
3494
-    public static function course_signup_link( ){
3494
+    public static function course_signup_link( ) {
3495 3495
 
3496
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3496
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3497 3497
 
3498
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3498
+        if (empty($course_id) || 'course' != get_post_type($course_id) || sensei_all_access()) {
3499 3499
 
3500 3500
             return;
3501 3501
 
@@ -3508,69 +3508,69 @@  discard block
 block discarded – undo
3508 3508
             <?php
3509 3509
 
3510 3510
             global $current_user;
3511
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3511
+            $wc_post_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
3512 3512
 
3513
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $course_id ) ) {
3513
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable($course_id)) {
3514 3514
 
3515
-                if( is_user_logged_in() && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID )  ) {
3515
+                if (is_user_logged_in() && ! Sensei_Utils::user_started_course($course_id, $current_user->ID)) {
3516 3516
 
3517
-	                    $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3518
-	                    $a_element .= __( 'course', 'woothemes-sensei' );
3517
+	                    $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3518
+	                    $a_element .= __('course', 'woothemes-sensei');
3519 3519
 	                    $a_element .= '</a>';
3520 3520
 
3521
-	                    if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3521
+	                    if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3522 3522
 
3523
-		                    $message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3523
+		                    $message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3524 3524
 
3525
-	                    }else{
3525
+	                    } else {
3526 3526
 
3527
-		                    $message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3527
+		                    $message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3528 3528
 
3529 3529
 	                    }
3530 3530
 
3531
-	                    Sensei()->notices->add_notice( $message, 'info' );
3531
+	                    Sensei()->notices->add_notice($message, 'info');
3532 3532
 
3533 3533
                 }
3534 3534
 
3535
-	            if( ! is_user_logged_in() ) {
3535
+	            if ( ! is_user_logged_in()) {
3536 3536
 
3537
-	                $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3538
-	                $a_element .= __( 'course', 'woothemes-sensei' );
3537
+	                $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3538
+	                $a_element .= __('course', 'woothemes-sensei');
3539 3539
 	                $a_element .= '</a>';
3540 3540
 
3541
-	                if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3541
+	                if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3542 3542
 
3543
-						$message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3543
+						$message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3544 3544
 
3545
-					}else{
3545
+					} else {
3546 3546
 
3547
-						$message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3547
+						$message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3548 3548
 
3549 3549
 					}
3550 3550
 
3551
-					Sensei()->notices->add_notice( $message, 'alert' );
3551
+					Sensei()->notices->add_notice($message, 'alert');
3552 3552
 
3553 3553
 	            }
3554 3554
 
3555 3555
             } else { ?>
3556 3556
 
3557
-	            <?php if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) &&  sensei_is_login_required() )  : ?>
3557
+	            <?php if ( ! Sensei_Utils::user_started_course($course_id, get_current_user_id()) && sensei_is_login_required())  : ?>
3558 3558
 
3559 3559
 	                <div class="sensei-message alert">
3560 3560
 	                    <?php
3561
-	                    $course_link =  '<a href="'
3562
-	                                        . esc_url( get_permalink( $course_id ) )
3563
-	                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3564
-	                                        . '">' . __( 'course', 'woothemes-sensei' )
3561
+	                    $course_link = '<a href="'
3562
+	                                        . esc_url(get_permalink($course_id))
3563
+	                                        . '" title="'.__('Sign Up', 'woothemes-sensei')
3564
+	                                        . '">'.__('course', 'woothemes-sensei')
3565 3565
 	                                    . '</a>';
3566 3566
 
3567
-						if ( Sensei_Utils::is_preview_lesson( get_the_ID( ) ) ) {
3567
+						if (Sensei_Utils::is_preview_lesson(get_the_ID( ))) {
3568 3568
 
3569
-							echo sprintf( __( 'This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ),  $course_link );
3569
+							echo sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
3570 3570
 
3571 3571
 						} else {
3572 3572
 
3573
-							echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3573
+							echo sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
3574 3574
 
3575 3575
 						}
3576 3576
 
@@ -3591,14 +3591,14 @@  discard block
 block discarded – undo
3591 3591
      *
3592 3592
      * @since 1.9.0
3593 3593
      */
3594
-    public  static function prerequisite_complete_message(){
3594
+    public  static function prerequisite_complete_message() {
3595 3595
 
3596
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3596
+        $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id(get_the_ID());
3597 3597
         $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3598
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3598
+        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(get_the_ID(), get_current_user_id()) && $lesson_has_pre_requisite) {
3599 3599
 
3600
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3601
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3600
+            $prerequisite_lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite)).'" title="'.esc_attr(sprintf(__('You must first complete: %1$s', 'woothemes-sensei'), get_the_title($lesson_prerequisite))).'">'.get_the_title($lesson_prerequisite).'</a>';
3601
+            echo sprintf(__('You must first complete %1$s before viewing this Lesson', 'woothemes-sensei'), $prerequisite_lesson_link);
3602 3602
 
3603 3603
         }
3604 3604
 
@@ -3610,7 +3610,7 @@  discard block
 block discarded – undo
3610 3610
      *
3611 3611
      * @deprecated since 1.9.0
3612 3612
      */
3613
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3613
+    public static function deprecate_sensei_lesson_archive_header_hook() {
3614 3614
 
3615 3615
         sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3616 3616
 
@@ -3626,9 +3626,9 @@  discard block
 block discarded – undo
3626 3626
 
3627 3627
         $before_html = '<header class="archive-header"><h1>';
3628 3628
         $after_html = '</h1></header>';
3629
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3629
+        $html = $before_html.__('Lessons Archive', 'woothemes-sensei').$after_html;
3630 3630
 
3631
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3631
+        echo apply_filters('sensei_lesson_archive_title', $html);
3632 3632
 
3633 3633
     } // sensei_course_archive_header()
3634 3634
 
@@ -3638,7 +3638,7 @@  discard block
 block discarded – undo
3638 3638
      * @global $post
3639 3639
      * @since 1.9.0
3640 3640
      */
3641
-    public static function the_title(){
3641
+    public static function the_title() {
3642 3642
 
3643 3643
         global $post;
3644 3644
 
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
                 /**
3652 3652
                  * Filter documented in class-sensei-messages.php the_title
3653 3653
                  */
3654
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3654
+                echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type);
3655 3655
                 ?>
3656 3656
 
3657 3657
             </h1>
@@ -3669,16 +3669,16 @@  discard block
 block discarded – undo
3669 3669
      *
3670 3670
      * @param $post_id
3671 3671
      */
3672
-    public static function flush_rewrite_rules( $post_id ){
3672
+    public static function flush_rewrite_rules($post_id) {
3673 3673
 
3674
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3674
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
3675 3675
 
3676 3676
             return;
3677 3677
 
3678 3678
         }
3679 3679
 
3680 3680
 
3681
-        if( 'lesson' == get_post_type( $post_id )  ){
3681
+        if ('lesson' == get_post_type($post_id)) {
3682 3682
 
3683 3683
             Sensei()->initiate_rewrite_rules_flush();
3684 3684
 
@@ -3695,27 +3695,27 @@  discard block
 block discarded – undo
3695 3695
      * @param int $lesson_id
3696 3696
      * @param int $user_id
3697 3697
      */
3698
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3698
+    public static function footer_quiz_call_to_action($lesson_id = 0, $user_id = 0) {
3699 3699
 
3700 3700
 
3701
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3702
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3701
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3702
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3703 3703
 
3704 3704
 
3705
-	    if ( ! sensei_can_user_view_lesson( $lesson_id, $user_id ) ) {
3705
+	    if ( ! sensei_can_user_view_lesson($lesson_id, $user_id)) {
3706 3706
 		    return;
3707 3707
 	    }
3708 3708
 
3709
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3710
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3711
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3712
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3709
+        $lesson_prerequisite       = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
3710
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3711
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3712
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3713 3713
         $show_actions              = is_user_logged_in() ? true : false;
3714 3714
 
3715
-        if( intval( $lesson_prerequisite ) > 0 ) {
3715
+        if (intval($lesson_prerequisite) > 0) {
3716 3716
 
3717 3717
             // If the user hasn't completed the prereq then hide the current actions
3718
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3718
+            $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $user_id);
3719 3719
 
3720 3720
         }
3721 3721
 
@@ -3724,19 +3724,19 @@  discard block
 block discarded – undo
3724 3724
         <footer>
3725 3725
 
3726 3726
             <?php
3727
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3727
+            if ($show_actions && $quiz_id && Sensei()->access_settings()) {
3728 3728
 
3729
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3730
-                if( $has_quiz_questions ) {
3729
+                $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3730
+                if ($has_quiz_questions) {
3731 3731
                     ?>
3732 3732
 
3733 3733
                     <p>
3734 3734
 
3735 3735
                         <a class="button"
3736
-                           href="<?php echo esc_url_raw( get_permalink( $quiz_id ) ); ?>"
3737
-                           title="<?php _e( 'View the Lesson Quiz', 'woothemes-sensei'  ); ?>">
3736
+                           href="<?php echo esc_url_raw(get_permalink($quiz_id)); ?>"
3737
+                           title="<?php _e('View the Lesson Quiz', 'woothemes-sensei'); ?>">
3738 3738
 
3739
-                            <?php  _e( 'View the Lesson Quiz', 'woothemes-sensei' ); ?>
3739
+                            <?php  _e('View the Lesson Quiz', 'woothemes-sensei'); ?>
3740 3740
 
3741 3741
                         </a>
3742 3742
 
@@ -3747,11 +3747,11 @@  discard block
 block discarded – undo
3747 3747
 
3748 3748
             } // End If Statement
3749 3749
 
3750
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3750
+            if ($show_actions && ! $has_user_completed_lesson) {
3751 3751
 
3752 3752
                 sensei_complete_lesson_button();
3753 3753
 
3754
-            } elseif( $show_actions ) {
3754
+            } elseif ($show_actions) {
3755 3755
 
3756 3756
                 sensei_reset_lesson_button();
3757 3757
 
@@ -3768,20 +3768,20 @@  discard block
 block discarded – undo
3768 3768
      *
3769 3769
      * @since 1.9.0
3770 3770
      */
3771
-    public static function output_comments(){
3771
+    public static function output_comments() {
3772 3772
 
3773
-        if( ! is_user_logged_in() ){
3773
+        if ( ! is_user_logged_in()) {
3774 3774
             return;
3775 3775
         }
3776 3776
 
3777
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3778
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3779
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3780
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3777
+        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete(get_the_ID(), get_current_user_id());
3778
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3779
+        $allow_comments = Sensei()->settings->settings['lesson_comments'];
3780
+        $user_taking_course = Sensei_Utils::user_started_course($course_id);
3781 3781
 
3782
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3782
+        $lesson_allow_comments = $allow_comments && $pre_requisite_complete && $user_taking_course;
3783 3783
 
3784
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3784
+        if ($lesson_allow_comments || is_singular('sensei_message')) {
3785 3785
 
3786 3786
             comments_template();
3787 3787
 
@@ -3797,26 +3797,26 @@  discard block
 block discarded – undo
3797 3797
      *
3798 3798
      * @since 1.9.0
3799 3799
      */
3800
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3800
+    public static function user_lesson_quiz_status_message($lesson_id = 0, $user_id = 0) {
3801 3801
 
3802
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3803
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3804
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3805
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3806
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3802
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3803
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3804
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3805
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3806
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3807 3807
 
3808 3808
 
3809
-        if ( $quiz_id && is_user_logged_in()
3810
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3809
+        if ($quiz_id && is_user_logged_in()
3810
+            && Sensei_Utils::user_started_course($lesson_course_id, $user_id)) {
3811 3811
 
3812 3812
             $no_quiz_count = 0;
3813
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3813
+            $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3814 3814
 
3815 3815
             // Display lesson quiz status message
3816
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3817
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3818
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3819
-                if( $has_quiz_questions ) {
3816
+            if ($has_user_completed_lesson || $has_quiz_questions) {
3817
+                $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, $user_id, true);
3818
+                echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>';
3819
+                if ($has_quiz_questions) {
3820 3820
                    // echo $status['extra'];
3821 3821
                 } // End If Statement
3822 3822
             } // End If Statement
@@ -3832,11 +3832,11 @@  discard block
 block discarded – undo
3832 3832
      * @param $content
3833 3833
      * @return string
3834 3834
      */
3835
-    public static function limit_archive_content ( $content ){
3835
+    public static function limit_archive_content($content) {
3836 3836
 
3837
-        if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3837
+        if (is_archive('lesson') && Sensei()->settings->get('access_permission')) {
3838 3838
 
3839
-            return wp_trim_words( $content, $num_words = 30, $more = '…' );
3839
+            return wp_trim_words($content, $num_words = 30, $more = '…');
3840 3840
         }
3841 3841
 
3842 3842
         return $content;
@@ -3849,9 +3849,9 @@  discard block
 block discarded – undo
3849 3849
      * @since 1.9.0
3850 3850
      * @return array
3851 3851
      */
3852
-    public static function get_all_lesson_ids(){
3852
+    public static function get_all_lesson_ids() {
3853 3853
 
3854
-        return get_posts( array(
3854
+        return get_posts(array(
3855 3855
             'post_type'=>'lesson',
3856 3856
             'fields'=>'ids',
3857 3857
             'post_status' => 'publish',
@@ -3868,4 +3868,4 @@  discard block
 block discarded – undo
3868 3868
  * @ignore only for backward compatibility
3869 3869
  * @since 1.9.0
3870 3870
  */
3871
-class WooThemes_Sensei_Lesson extends Sensei_Lesson{}
3871
+class WooThemes_Sensei_Lesson extends Sensei_Lesson {}
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 1 patch
Indentation   +1833 added lines, -1833 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,872 +335,872 @@  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 )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1175
-
1176
-            return false;
1177
-
1178
-        }
1179
-
1180
-       // get the last item in the array there should be only be 1 really.
1181
-       // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1183
-           break;
1184
-       }
1185
-
1186
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
-            return false;
1188
-        }
1189
-
1190
-        $module->url = get_term_link($module, $this->taxonomy);
1191
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
-        if (isset($course_id) && 0 < $course_id) {
1193
-
1194
-            // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
-                return false;
1197
-            }
1198
-
1199
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
-        }
1201
-        return $module;
1202
-
1203
-    }
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 )
1173
+			|| is_wp_error( $modules )
1174
+			|| isset( $modules['errors'] ) ){
1175
+
1176
+			return false;
1177
+
1178
+		}
1179
+
1180
+	   // get the last item in the array there should be only be 1 really.
1181
+	   // this method works for all php versions.
1182
+	   foreach( $modules as $module ){
1183
+		   break;
1184
+	   }
1185
+
1186
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
+			return false;
1188
+		}
1189
+
1190
+		$module->url = get_term_link($module, $this->taxonomy);
1191
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
+		if (isset($course_id) && 0 < $course_id) {
1193
+
1194
+			// the course should contain the same module taxonomy term for this to be valid
1195
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
+				return false;
1197
+			}
1198
+
1199
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
+		}
1201
+		return $module;
1202
+
1203
+	}
1204 1204
 
1205 1205
 	/**
1206 1206
 	 * Get ordered array of all modules in course
@@ -1259,485 +1259,485 @@  discard block
 block discarded – undo
1259 1259
 
1260 1260
 	}
1261 1261
 
1262
-    /**
1263
-     * Load frontend CSS
1264
-     *
1265
-     * @since 1.8.0
1266
-     *
1267
-     * @return void
1268
-     */
1269
-    public function enqueue_styles() {
1270
-
1271
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1272
-        wp_enqueue_style($this->taxonomy . '-frontend');
1273
-
1274
-    }
1275
-
1276
-    /**
1277
-     * Load admin Javascript
1278
-     *
1279
-     * @since 1.8.0
1280
-     *
1281
-     * @return void
1282
-     */
1283
-    public function admin_enqueue_scripts( $hook ) {
1284
-
1285
-        /**
1286
-         * Filter the page hooks where modules admin script can be loaded on.
1287
-         *
1288
-         * @param array $white_listed_pages
1289
-         */
1290
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1291
-            'edit-tags.php',
1292
-            'course_page_module-order',
1293
-            'post-new.php',
1294
-            'post.php'
1295
-        ) );
1296
-
1297
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1298
-            return;
1299
-        }
1300
-
1301
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1302
-
1303
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
-        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', 'sensei-core-select2' ), Sensei()->version, true );
1306
-
1307
-        // localized module data
1308
-        $localize_modulesAdmin = array(
1309
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1311
-        );
1312
-
1313
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1314
-    }
1262
+	/**
1263
+	 * Load frontend CSS
1264
+	 *
1265
+	 * @since 1.8.0
1266
+	 *
1267
+	 * @return void
1268
+	 */
1269
+	public function enqueue_styles() {
1270
+
1271
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1272
+		wp_enqueue_style($this->taxonomy . '-frontend');
1273
+
1274
+	}
1275
+
1276
+	/**
1277
+	 * Load admin Javascript
1278
+	 *
1279
+	 * @since 1.8.0
1280
+	 *
1281
+	 * @return void
1282
+	 */
1283
+	public function admin_enqueue_scripts( $hook ) {
1284
+
1285
+		/**
1286
+		 * Filter the page hooks where modules admin script can be loaded on.
1287
+		 *
1288
+		 * @param array $white_listed_pages
1289
+		 */
1290
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1291
+			'edit-tags.php',
1292
+			'course_page_module-order',
1293
+			'post-new.php',
1294
+			'post.php'
1295
+		) );
1296
+
1297
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1298
+			return;
1299
+		}
1300
+
1301
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1302
+
1303
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
+		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', 'sensei-core-select2' ), Sensei()->version, true );
1306
+
1307
+		// localized module data
1308
+		$localize_modulesAdmin = array(
1309
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1311
+		);
1312
+
1313
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1314
+	}
1315
+
1316
+	/**
1317
+	 * Load admin CSS
1318
+	 *
1319
+	 * @since 1.8.0
1320
+	 *
1321
+	 * @return void
1322
+	 */
1323
+	public function admin_enqueue_styles() {
1324
+
1325
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
+		wp_enqueue_style($this->taxonomy . '-sortable');
1327
+
1328
+	}
1329
+
1330
+	/**
1331
+	 * Show the title modules on the single course template.
1332
+	 *
1333
+	 * Function is hooked into sensei_single_course_modules_before.
1334
+	 *
1335
+	 * @since 1.8.0
1336
+	 * @return void
1337
+	 */
1338
+	public function course_modules_title( ) {
1339
+
1340
+	   if( sensei_module_has_lessons() ){
1341
+
1342
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1343
+
1344
+		}
1345
+
1346
+	}
1347
+
1348
+	/**
1349
+	 * Display the single course modules content this will only show
1350
+	 * if the course has modules.
1351
+	 *
1352
+	 * @since 1.8.0
1353
+	 * @return void
1354
+	 */
1355
+	public function load_course_module_content_template(){
1356
+
1357
+		if ( ! is_singular( 'course' )  ) {
1358
+			return;
1359
+		}
1360
+
1361
+		// load backwards compatible template name if it exists in the users theme
1362
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
+		if( $located_template ){
1364
+
1365
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1366
+			return;
1367
+
1368
+		}
1369
+
1370
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1371
+
1372
+	} // end course_module_content
1373
+
1374
+	/**
1375
+	 * Returns all lessons for the given module ID
1376
+	 *
1377
+	 * @since 1.8.0
1378
+	 *
1379
+	 * @param $course_id
1380
+	 * @param $term_id
1381
+	 * @return array $lessons
1382
+	 */
1383
+	public function get_lessons( $course_id , $term_id ){
1384
+
1385
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1386
+
1387
+		if( isset( $lesson_query->posts ) ){
1388
+
1389
+			return $lesson_query->posts;
1390
+
1391
+		}else{
1392
+
1393
+			return array();
1394
+
1395
+		}
1396
+
1397
+	} // end get lessons
1398
+
1399
+	/**
1400
+	 * Returns all lessons for the given module ID
1401
+	 *
1402
+	 * @since 1.8.0
1403
+	 *
1404
+	 * @param $course_id
1405
+	 * @param $term_id
1406
+	 * @return WP_Query $lessons_query
1407
+	 */
1408
+	public function get_lessons_query( $course_id , $term_id ){
1409
+
1410
+		if( empty( $term_id ) || empty( $course_id ) ){
1411
+
1412
+			return array();
1413
+
1414
+		}
1415
+
1416
+		$args = array(
1417
+			'post_type' => 'lesson',
1418
+			'post_status' => 'publish',
1419
+			'posts_per_page' => -1,
1420
+			'meta_query' => array(
1421
+				array(
1422
+					'key' => '_lesson_course',
1423
+					'value' => intval($course_id),
1424
+					'compare' => '='
1425
+				)
1426
+			),
1427
+			'tax_query' => array(
1428
+				array(
1429
+					'taxonomy' => 'module',
1430
+					'field' => 'id',
1431
+					'terms' => intval( $term_id )
1432
+				)
1433
+			),
1434
+			'orderby' => 'menu_order',
1435
+			'order' => 'ASC',
1436
+			'suppress_filters' => 0
1437
+		);
1438
+
1439
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1441
+			$args['orderby'] = 'meta_value_num date';
1442
+		}
1443
+
1444
+		$lessons_query = new WP_Query( $args );
1445
+
1446
+		return $lessons_query;
1447
+
1448
+	} // end get lessons
1449
+
1450
+	/**
1451
+	 * Find the lesson in the given course that doesn't belong
1452
+	 * to any of the courses modules
1453
+	 *
1454
+	 *
1455
+	 * @param $course_id
1456
+	 *
1457
+	 * @return array $non_module_lessons
1458
+	 */
1459
+	public function get_none_module_lessons( $course_id ){
1460
+
1461
+		$non_module_lessons = array();
1462
+
1463
+		//exit if there is no course id passed in
1464
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1465
+
1466
+			return $non_module_lessons;
1467
+		}
1468
+
1469
+		//save some time and check if we already have the saved
1470
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1471
+
1472
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1473
+
1474
+		}
1475
+
1476
+		// create terms array which must be excluded from other arrays
1477
+		$course_modules = $this->get_course_modules( $course_id );
1478
+
1479
+		//exit if there are no module on this course
1480
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1481
+
1482
+			return  Sensei()->course->course_lessons( $course_id );
1483
+
1484
+		}
1485
+
1486
+		$terms = array();
1487
+		foreach( $course_modules as $module ){
1488
+
1489
+			array_push( $terms ,  $module->term_id );
1490
+
1491
+		}
1492
+
1493
+		$args = array(
1494
+			'post_type' => 'lesson',
1495
+			'post_status' => 'publish',
1496
+			'posts_per_page' => -1,
1497
+			'meta_query' => array(
1498
+				array(
1499
+					'key' => '_lesson_course',
1500
+					'value' => intval( $course_id ),
1501
+					'compare' => '='
1502
+				)
1503
+			),
1504
+			'tax_query' => array(
1505
+				array(
1506
+					'taxonomy' => 'module',
1507
+					'field' => 'id',
1508
+					'terms' =>  $terms,
1509
+					'operator' => 'NOT IN'
1510
+				)
1511
+			),
1512
+			'orderby' => 'menu_order',
1513
+			'order' => 'ASC',
1514
+			'suppress_filters' => 0
1515
+		);
1516
+
1517
+		$wp_lessons_query = new WP_Query( $args );
1518
+
1519
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1520
+			$non_module_lessons = $wp_lessons_query->get_posts();
1521
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1522
+		}
1523
+
1524
+		return $non_module_lessons;
1525
+	} // end get_none_module_lessons
1526
+
1527
+	/**
1528
+	 * Register the modules taxonomy
1529
+	 *
1530
+	 * @since 1.8.0
1531
+	 */
1532
+	public function setup_modules_taxonomy(){
1533
+
1534
+		$labels = array(
1535
+			'name' => __('Modules', 'woothemes-sensei'),
1536
+			'singular_name' => __('Module', 'woothemes-sensei'),
1537
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1538
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1539
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1540
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1541
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1542
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1543
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1544
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1545
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1546
+		);
1547
+
1548
+		/**
1549
+		 * Filter to alter the Sensei Modules rewrite slug
1550
+		 *
1551
+		 * @since 1.8.0
1552
+		 * @param string default 'modules'
1553
+		 */
1554
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1555
+
1556
+		$args = array(
1557
+			'public' => true,
1558
+			'hierarchical' => true,
1559
+			'show_admin_column' => true,
1560
+			'capabilities' => array(
1561
+				'manage_terms' => 'manage_categories',
1562
+				'edit_terms'   => 'edit_courses',
1563
+				'delete_terms' => 'manage_categories',
1564
+				'assign_terms' => 'edit_courses'
1565
+			),
1566
+			'show_in_nav_menus' => false,
1567
+			'show_in_quick_edit' => false,
1568
+			'show_ui' => true,
1569
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1570
+			'labels' => $labels
1571
+		);
1572
+
1573
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1574
+
1575
+	}// end setup_modules_taxonomy
1576
+
1577
+	/**
1578
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1579
+	 *
1580
+	 * This function is hooked into the admin_menu
1581
+	 *
1582
+	 * @since 1.8.0
1583
+	 * @return void
1584
+	 */
1585
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1586
+
1587
+		global $typenow , $taxnow;
1588
+
1589
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1591
+		}
1592
+
1593
+	}// end redirect to course taxonomy
1594
+
1595
+	/**
1596
+	 * Completely remove the module menu item under lessons.
1597
+	 *
1598
+	 * This function is hooked into the admin_menu
1599
+	 *
1600
+	 * @since 1.8.0
1601
+	 * @return void
1602
+	 */
1603
+	public function remove_lessons_menu_model_taxonomy(){
1604
+		global $submenu;
1605
+
1606
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1607
+			return; // exit
1608
+		}
1609
+
1610
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
+		foreach( $lesson_main_menu as $index => $sub_item ){
1612
+
1613
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1615
+			}
1616
+		}
1617
+
1618
+	}// end remove lesson module tax
1315 1619
 
1316
-    /**
1317
-     * Load admin CSS
1318
-     *
1319
-     * @since 1.8.0
1320
-     *
1321
-     * @return void
1322
-     */
1323
-    public function admin_enqueue_styles() {
1324
-
1325
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
-        wp_enqueue_style($this->taxonomy . '-sortable');
1327
-
1328
-    }
1329
-
1330
-    /**
1331
-     * Show the title modules on the single course template.
1332
-     *
1333
-     * Function is hooked into sensei_single_course_modules_before.
1334
-     *
1335
-     * @since 1.8.0
1336
-     * @return void
1337
-     */
1338
-    public function course_modules_title( ) {
1339
-
1340
-       if( sensei_module_has_lessons() ){
1341
-
1342
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1343
-
1344
-        }
1345
-
1346
-    }
1347
-
1348
-    /**
1349
-     * Display the single course modules content this will only show
1350
-     * if the course has modules.
1351
-     *
1352
-     * @since 1.8.0
1353
-     * @return void
1354
-     */
1355
-    public function load_course_module_content_template(){
1356
-
1357
-	    if ( ! is_singular( 'course' )  ) {
1358
-		    return;
1359
-	    }
1360
-
1361
-        // load backwards compatible template name if it exists in the users theme
1362
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
-        if( $located_template ){
1364
-
1365
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1366
-            return;
1367
-
1368
-        }
1369
-
1370
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1371
-
1372
-    } // end course_module_content
1373
-
1374
-    /**
1375
-     * Returns all lessons for the given module ID
1376
-     *
1377
-     * @since 1.8.0
1378
-     *
1379
-     * @param $course_id
1380
-     * @param $term_id
1381
-     * @return array $lessons
1382
-     */
1383
-    public function get_lessons( $course_id , $term_id ){
1384
-
1385
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1386
-
1387
-        if( isset( $lesson_query->posts ) ){
1620
+	/**
1621
+	 * Completely remove the second modules under courses
1622
+	 *
1623
+	 * This function is hooked into the admin_menu
1624
+	 *
1625
+	 * @since 1.8.0
1626
+	 * @return void
1627
+	 */
1628
+	public function remove_courses_menu_model_taxonomy(){
1629
+		global $submenu;
1630
+
1631
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1632
+			return; // exit
1633
+		}
1634
+
1635
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1636
+		foreach( $course_main_menu as $index => $sub_item ){
1388 1637
 
1389
-            return $lesson_query->posts;
1638
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1640
+			}
1641
+		}
1390 1642
 
1391
-        }else{
1643
+	}// end remove courses module tax
1392 1644
 
1393
-            return array();
1645
+	/**
1646
+	 * Determine the author of a module term term by looking at
1647
+	 * the prefixed author id. This function will query the full term object.
1648
+	 * Will return the admin user author could not be determined.
1649
+	 *
1650
+	 * @since 1.8.0
1651
+	 *
1652
+	 * @param string $term_name
1653
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1654
+	 */
1655
+	public static function get_term_authors( $term_name ){
1394 1656
 
1395
-        }
1657
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1396 1658
 
1397
-    } // end get lessons
1659
+		$owners = array();
1660
+		if( empty( $terms ) ){
1398 1661
 
1399
-    /**
1400
-     * Returns all lessons for the given module ID
1401
-     *
1402
-     * @since 1.8.0
1403
-     *
1404
-     * @param $course_id
1405
-     * @param $term_id
1406
-     * @return WP_Query $lessons_query
1407
-     */
1408
-    public function get_lessons_query( $course_id , $term_id ){
1409
-
1410
-        if( empty( $term_id ) || empty( $course_id ) ){
1411
-
1412
-            return array();
1413
-
1414
-        }
1415
-
1416
-        $args = array(
1417
-            'post_type' => 'lesson',
1418
-            'post_status' => 'publish',
1419
-            'posts_per_page' => -1,
1420
-            'meta_query' => array(
1421
-                array(
1422
-                    'key' => '_lesson_course',
1423
-                    'value' => intval($course_id),
1424
-                    'compare' => '='
1425
-                )
1426
-            ),
1427
-            'tax_query' => array(
1428
-                array(
1429
-                    'taxonomy' => 'module',
1430
-                    'field' => 'id',
1431
-                    'terms' => intval( $term_id )
1432
-                )
1433
-            ),
1434
-            'orderby' => 'menu_order',
1435
-            'order' => 'ASC',
1436
-            'suppress_filters' => 0
1437
-        );
1438
-
1439
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1441
-            $args['orderby'] = 'meta_value_num date';
1442
-        }
1443
-
1444
-        $lessons_query = new WP_Query( $args );
1445
-
1446
-        return $lessons_query;
1447
-
1448
-    } // end get lessons
1449
-
1450
-    /**
1451
-     * Find the lesson in the given course that doesn't belong
1452
-     * to any of the courses modules
1453
-     *
1454
-     *
1455
-     * @param $course_id
1456
-     *
1457
-     * @return array $non_module_lessons
1458
-     */
1459
-    public function get_none_module_lessons( $course_id ){
1460
-
1461
-        $non_module_lessons = array();
1462
-
1463
-        //exit if there is no course id passed in
1464
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1465
-
1466
-            return $non_module_lessons;
1467
-        }
1468
-
1469
-        //save some time and check if we already have the saved
1470
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1471
-
1472
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1473
-
1474
-        }
1475
-
1476
-        // create terms array which must be excluded from other arrays
1477
-        $course_modules = $this->get_course_modules( $course_id );
1478
-
1479
-        //exit if there are no module on this course
1480
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1481
-
1482
-            return  Sensei()->course->course_lessons( $course_id );
1483
-
1484
-        }
1485
-
1486
-        $terms = array();
1487
-        foreach( $course_modules as $module ){
1488
-
1489
-            array_push( $terms ,  $module->term_id );
1490
-
1491
-        }
1492
-
1493
-        $args = array(
1494
-            'post_type' => 'lesson',
1495
-            'post_status' => 'publish',
1496
-            'posts_per_page' => -1,
1497
-            'meta_query' => array(
1498
-                array(
1499
-                    'key' => '_lesson_course',
1500
-                    'value' => intval( $course_id ),
1501
-                    'compare' => '='
1502
-                )
1503
-            ),
1504
-            'tax_query' => array(
1505
-                array(
1506
-                    'taxonomy' => 'module',
1507
-                    'field' => 'id',
1508
-                    'terms' =>  $terms,
1509
-                    'operator' => 'NOT IN'
1510
-                )
1511
-            ),
1512
-            'orderby' => 'menu_order',
1513
-            'order' => 'ASC',
1514
-            'suppress_filters' => 0
1515
-        );
1516
-
1517
-        $wp_lessons_query = new WP_Query( $args );
1518
-
1519
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1520
-            $non_module_lessons = $wp_lessons_query->get_posts();
1521
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1522
-        }
1523
-
1524
-        return $non_module_lessons;
1525
-    } // end get_none_module_lessons
1526
-
1527
-    /**
1528
-     * Register the modules taxonomy
1529
-     *
1530
-     * @since 1.8.0
1531
-     */
1532
-    public function setup_modules_taxonomy(){
1533
-
1534
-        $labels = array(
1535
-            'name' => __('Modules', 'woothemes-sensei'),
1536
-            'singular_name' => __('Module', 'woothemes-sensei'),
1537
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1538
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1539
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1540
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1541
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1542
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1543
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1544
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1545
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1546
-        );
1547
-
1548
-        /**
1549
-         * Filter to alter the Sensei Modules rewrite slug
1550
-         *
1551
-         * @since 1.8.0
1552
-         * @param string default 'modules'
1553
-         */
1554
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1555
-
1556
-        $args = array(
1557
-            'public' => true,
1558
-            'hierarchical' => true,
1559
-            'show_admin_column' => true,
1560
-            'capabilities' => array(
1561
-                'manage_terms' => 'manage_categories',
1562
-                'edit_terms'   => 'edit_courses',
1563
-                'delete_terms' => 'manage_categories',
1564
-                'assign_terms' => 'edit_courses'
1565
-            ),
1566
-            'show_in_nav_menus' => false,
1567
-            'show_in_quick_edit' => false,
1568
-            'show_ui' => true,
1569
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1570
-            'labels' => $labels
1571
-        );
1572
-
1573
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1574
-
1575
-    }// end setup_modules_taxonomy
1576
-
1577
-    /**
1578
-     * When the wants to edit the lesson modules redirect them to the course modules.
1579
-     *
1580
-     * This function is hooked into the admin_menu
1581
-     *
1582
-     * @since 1.8.0
1583
-     * @return void
1584
-     */
1585
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1586
-
1587
-        global $typenow , $taxnow;
1588
-
1589
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1591
-        }
1592
-
1593
-    }// end redirect to course taxonomy
1594
-
1595
-    /**
1596
-     * Completely remove the module menu item under lessons.
1597
-     *
1598
-     * This function is hooked into the admin_menu
1599
-     *
1600
-     * @since 1.8.0
1601
-     * @return void
1602
-     */
1603
-    public function remove_lessons_menu_model_taxonomy(){
1604
-        global $submenu;
1605
-
1606
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1607
-            return; // exit
1608
-        }
1609
-
1610
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
-        foreach( $lesson_main_menu as $index => $sub_item ){
1612
-
1613
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1615
-            }
1616
-        }
1617
-
1618
-    }// end remove lesson module tax
1619
-
1620
-    /**
1621
-     * Completely remove the second modules under courses
1622
-     *
1623
-     * This function is hooked into the admin_menu
1624
-     *
1625
-     * @since 1.8.0
1626
-     * @return void
1627
-     */
1628
-    public function remove_courses_menu_model_taxonomy(){
1629
-        global $submenu;
1630
-
1631
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1632
-            return; // exit
1633
-        }
1634
-
1635
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1636
-        foreach( $course_main_menu as $index => $sub_item ){
1637
-
1638
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1640
-            }
1641
-        }
1642
-
1643
-    }// end remove courses module tax
1644
-
1645
-    /**
1646
-     * Determine the author of a module term term by looking at
1647
-     * the prefixed author id. This function will query the full term object.
1648
-     * Will return the admin user author could not be determined.
1649
-     *
1650
-     * @since 1.8.0
1651
-     *
1652
-     * @param string $term_name
1653
-     * @return array $owners { type WP_User }. Empty array if none if found.
1654
-     */
1655
-    public static function get_term_authors( $term_name ){
1656
-
1657
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1658
-
1659
-        $owners = array();
1660
-        if( empty( $terms ) ){
1661
-
1662
-            return $owners;
1662
+			return $owners;
1663 1663
 
1664
-        }
1664
+		}
1665 1665
 
1666
-        // setup the admin user
1666
+		// setup the admin user
1667 1667
 
1668 1668
 
1669
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
-        foreach( $terms as $term){
1671
-            if( $term->name == $term_name ){
1669
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
+		foreach( $terms as $term){
1671
+			if( $term->name == $term_name ){
1672 1672
 
1673
-                // look for the author in the slug
1674
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1673
+				// look for the author in the slug
1674
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1675 1675
 
1676
-            }// end if term name
1676
+			}// end if term name
1677 1677
 
1678
-        } // end for each
1678
+		} // end for each
1679 1679
 
1680
-        return $owners;
1680
+		return $owners;
1681 1681
 
1682
-    }// end get_term_author
1682
+	}// end get_term_author
1683 1683
 
1684
-    /**
1685
-     * Looks at a term slug and figures out
1686
-     * which author created the slug. The author was
1687
-     * appended when the user saved the module term in the course edit
1688
-     * screen.
1689
-     *
1690
-     * @since 1.8.0
1691
-     *
1692
-     * @param $slug
1693
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694
-     */
1695
-    public static function get_term_author( $slug='' ){
1684
+	/**
1685
+	 * Looks at a term slug and figures out
1686
+	 * which author created the slug. The author was
1687
+	 * appended when the user saved the module term in the course edit
1688
+	 * screen.
1689
+	 *
1690
+	 * @since 1.8.0
1691
+	 *
1692
+	 * @param $slug
1693
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694
+	 */
1695
+	public static function get_term_author( $slug='' ){
1696 1696
 
1697
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1697
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1698 1698
 
1699
-        if( empty( $slug ) ){
1699
+		if( empty( $slug ) ){
1700 1700
 
1701
-            return $term_owner;
1701
+			return $term_owner;
1702 1702
 
1703
-        }
1703
+		}
1704 1704
 
1705
-        // look for the author in the slug
1706
-        $slug_parts = explode( '-', $slug );
1705
+		// look for the author in the slug
1706
+		$slug_parts = explode( '-', $slug );
1707 1707
 
1708
-        if( count( $slug_parts ) > 1 ){
1708
+		if( count( $slug_parts ) > 1 ){
1709 1709
 
1710
-            // get the user data
1711
-            $possible_user_id = $slug_parts[0];
1712
-            $author = get_userdata( $possible_user_id );
1710
+			// get the user data
1711
+			$possible_user_id = $slug_parts[0];
1712
+			$author = get_userdata( $possible_user_id );
1713 1713
 
1714
-            // if the user doesnt exist for the first part of the slug
1715
-            // then this slug was also created by admin
1716
-            if( is_a( $author, 'WP_User' ) ){
1714
+			// if the user doesnt exist for the first part of the slug
1715
+			// then this slug was also created by admin
1716
+			if( is_a( $author, 'WP_User' ) ){
1717 1717
 
1718
-                $term_owner =  $author;
1718
+				$term_owner =  $author;
1719 1719
 
1720
-            }
1721
-        }
1720
+			}
1721
+		}
1722 1722
 
1723
-        return $term_owner;
1724
-    }
1723
+		return $term_owner;
1724
+	}
1725 1725
 
1726
-    /**
1727
-     * Display the Sensei modules taxonomy terms metabox
1728
-     *
1729
-     * @since 1.8.0
1730
-     *
1731
-     * @hooked into add_meta_box
1732
-     *
1733
-     * @param WP_Post $post Post object.
1734
-     */
1735
-    public function course_module_metabox( $post ) {
1726
+	/**
1727
+	 * Display the Sensei modules taxonomy terms metabox
1728
+	 *
1729
+	 * @since 1.8.0
1730
+	 *
1731
+	 * @hooked into add_meta_box
1732
+	 *
1733
+	 * @param WP_Post $post Post object.
1734
+	 */
1735
+	public function course_module_metabox( $post ) {
1736 1736
 
1737
-        $tax_name = 'module';
1738
-        $taxonomy = get_taxonomy( 'module' );
1737
+		$tax_name = 'module';
1738
+		$taxonomy = get_taxonomy( 'module' );
1739 1739
 
1740
-        ?>
1740
+		?>
1741 1741
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1742 1742
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1743 1743
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1752,9 +1752,9 @@  discard block
 block discarded – undo
1752 1752
 
1753 1753
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1754 1754
                 <?php
1755
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1756
-                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.
1757
-                ?>
1755
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1756
+				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.
1757
+				?>
1758 1758
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1759 1759
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1760 1760
                 </ul>
@@ -1764,9 +1764,9 @@  discard block
 block discarded – undo
1764 1764
                     <h4>
1765 1765
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1766 1766
                             <?php
1767
-                            /* translators: %s: add new taxonomy label */
1768
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1769
-                            ?>
1767
+							/* translators: %s: add new taxonomy label */
1768
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1769
+							?>
1770 1770
                         </a>
1771 1771
                     </h4>
1772 1772
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1781,331 +1781,331 @@  discard block
 block discarded – undo
1781 1781
         </div>
1782 1782
     <?php
1783 1783
 
1784
-    } // end course_module_metabox
1784
+	} // end course_module_metabox
1785 1785
 
1786 1786
 
1787
-    /**
1788
-     * Submits a new module term prefixed with the
1789
-     * the current author id.
1790
-     *
1791
-     * @since 1.8.0
1792
-     */
1793
-    public static function add_new_module_term( ) {
1787
+	/**
1788
+	 * Submits a new module term prefixed with the
1789
+	 * the current author id.
1790
+	 *
1791
+	 * @since 1.8.0
1792
+	 */
1793
+	public static function add_new_module_term( ) {
1794 1794
 
1795 1795
 
1796
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1798
-        }
1796
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1798
+		}
1799 1799
 
1800
-        // get the term an create the new term storing infomration
1801
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1800
+		// get the term an create the new term storing infomration
1801
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1802 1802
 
1803
-        if( current_user_can('manage_options' ) ) {
1803
+		if( current_user_can('manage_options' ) ) {
1804 1804
 
1805
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1805
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1806 1806
 
1807
-        } else {
1807
+		} else {
1808 1808
 
1809
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1809
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1810 1810
 
1811
-        }
1811
+		}
1812 1812
 
1813
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1813
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1814 1814
 
1815
-        // save the term
1816
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1815
+		// save the term
1816
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1817 1817
 
1818
-        // send error for all errors except term exits
1819
-        if( is_wp_error( $slug ) ){
1818
+		// send error for all errors except term exits
1819
+		if( is_wp_error( $slug ) ){
1820 1820
 
1821
-            // prepare for possible term name and id to be passed down if term exists
1822
-            $term_data = array();
1821
+			// prepare for possible term name and id to be passed down if term exists
1822
+			$term_data = array();
1823 1823
 
1824
-            // if term exists also send back the term name and id
1825
-            if( isset( $slug->errors['term_exists'] ) ){
1824
+			// if term exists also send back the term name and id
1825
+			if( isset( $slug->errors['term_exists'] ) ){
1826 1826
 
1827
-                $term = get_term_by( 'slug', $term_slug, 'module');
1828
-                $term_data['name'] = $term_name;
1829
-                $term_data['id'] = $term->term_id;
1827
+				$term = get_term_by( 'slug', $term_slug, 'module');
1828
+				$term_data['name'] = $term_name;
1829
+				$term_data['id'] = $term->term_id;
1830 1830
 
1831
-                // set the object terms
1832
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1833
-            }
1831
+				// set the object terms
1832
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1833
+			}
1834 1834
 
1835
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1835
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1836 1836
 
1837
-        }
1837
+		}
1838 1838
 
1839
-        //make sure the new term is checked for this course
1839
+		//make sure the new term is checked for this course
1840 1840
 
1841
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1841
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1842 1842
 
1843
-        // Handle request then generate response using WP_Ajax_Response
1844
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1843
+		// Handle request then generate response using WP_Ajax_Response
1844
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1845 1845
 
1846
-    }
1846
+	}
1847 1847
 
1848
-    /**
1849
-     * Limit the course module metabox
1850
-     * term list to only those on courses belonging to current teacher.
1851
-     *
1852
-     * Hooked into 'get_terms'
1853
-     *
1854
-     * @since 1.8.0
1855
-     */
1856
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1848
+	/**
1849
+	 * Limit the course module metabox
1850
+	 * term list to only those on courses belonging to current teacher.
1851
+	 *
1852
+	 * Hooked into 'get_terms'
1853
+	 *
1854
+	 * @since 1.8.0
1855
+	 */
1856
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1857 1857
 
1858
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1859
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1860
-            return $terms;
1861
-        }
1858
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1859
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1860
+			return $terms;
1861
+		}
1862 1862
 
1863
-        // avoid infinite call loop
1864
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1863
+		// avoid infinite call loop
1864
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865 1865
 
1866
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1868
-            // change only scrub the terms ids form the array keys
1869
-            $terms = array_keys( $terms );
1870
-        }
1866
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1868
+			// change only scrub the terms ids form the array keys
1869
+			$terms = array_keys( $terms );
1870
+		}
1871 1871
 
1872
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1872
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1873 1873
 
1874
-        // add filter again as removed above
1875
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1874
+		// add filter again as removed above
1875
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1876 1876
 
1877
-        return $teachers_terms;
1878
-    }// end filter_module_terms
1877
+		return $teachers_terms;
1878
+	}// end filter_module_terms
1879 1879
 
1880
-    /**
1881
-     * For the selected items on a course module only return those
1882
-     * for the current user. This does not apply to admin and super admin users.
1883
-     *
1884
-     * hooked into get_object_terms
1885
-     *
1886
-     * @since 1.8.0
1887
-     */
1888
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1880
+	/**
1881
+	 * For the selected items on a course module only return those
1882
+	 * for the current user. This does not apply to admin and super admin users.
1883
+	 *
1884
+	 * hooked into get_object_terms
1885
+	 *
1886
+	 * @since 1.8.0
1887
+	 */
1888
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1889 1889
 
1890
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1891
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1892
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1893
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1894
-            return $terms;
1895
-        }
1890
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1891
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1892
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1893
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1894
+			return $terms;
1895
+		}
1896 1896
 
1897
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1897
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1898 1898
 
1899
-        // if term objects were passed in send back objects
1900
-        // if term id were passed in send that back
1901
-        if( is_object( $terms[0] ) ){
1902
-            return $term_objects;
1903
-        }
1899
+		// if term objects were passed in send back objects
1900
+		// if term id were passed in send that back
1901
+		if( is_object( $terms[0] ) ){
1902
+			return $term_objects;
1903
+		}
1904 1904
 
1905
-        $terms = array();
1906
-        foreach( $term_objects as $term_object ){
1907
-            $terms[] = $term_object->term_id;
1908
-        }
1905
+		$terms = array();
1906
+		foreach( $term_objects as $term_object ){
1907
+			$terms[] = $term_object->term_id;
1908
+		}
1909 1909
 
1910
-        return $terms;
1910
+		return $terms;
1911 1911
 
1912 1912
 
1913
-    }// end filter_course_selected_terms
1913
+	}// end filter_course_selected_terms
1914 1914
 
1915
-    /**
1916
-     * Filter the given terms and only return the
1917
-     * terms that belong to the given user id.
1918
-     *
1919
-     * @since 1.8.0
1920
-     * @param $terms
1921
-     * @param $user_id
1922
-     * @return array
1923
-     */
1924
-    public function filter_terms_by_owner( $terms, $user_id ){
1915
+	/**
1916
+	 * Filter the given terms and only return the
1917
+	 * terms that belong to the given user id.
1918
+	 *
1919
+	 * @since 1.8.0
1920
+	 * @param $terms
1921
+	 * @param $user_id
1922
+	 * @return array
1923
+	 */
1924
+	public function filter_terms_by_owner( $terms, $user_id ){
1925 1925
 
1926
-        $users_terms = array();
1926
+		$users_terms = array();
1927 1927
 
1928
-        foreach( $terms as $index => $term ){
1928
+		foreach( $terms as $index => $term ){
1929 1929
 
1930
-            if( is_numeric( $term ) ){
1931
-                // the term id was given, get the term object
1932
-                $term = get_term( $term, 'module' );
1933
-            }
1930
+			if( is_numeric( $term ) ){
1931
+				// the term id was given, get the term object
1932
+				$term = get_term( $term, 'module' );
1933
+			}
1934 1934
 
1935
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1935
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1936 1936
 
1937
-            if ( $user_id == $author->ID ) {
1938
-                // add the term to the teachers terms
1939
-                $users_terms[] = $term;
1940
-            }
1937
+			if ( $user_id == $author->ID ) {
1938
+				// add the term to the teachers terms
1939
+				$users_terms[] = $term;
1940
+			}
1941 1941
 
1942
-        }
1942
+		}
1943 1943
 
1944
-        return $users_terms;
1944
+		return $users_terms;
1945 1945
 
1946
-    } // end filter terms by owner
1946
+	} // end filter terms by owner
1947 1947
 
1948
-    /**
1949
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1950
-     * This will not add name to terms belonging to admin user.
1951
-     *
1952
-     * Hooked into 'get_terms'
1953
-     *
1954
-     * @since 1.8.0
1955
-     */
1956
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1957
-    {
1948
+	/**
1949
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1950
+	 * This will not add name to terms belonging to admin user.
1951
+	 *
1952
+	 * Hooked into 'get_terms'
1953
+	 *
1954
+	 * @since 1.8.0
1955
+	 */
1956
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1957
+	{
1958 1958
 
1959
-        // only for admin users ont he module taxonomy
1960
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1961
-            return $terms;
1962
-        }
1959
+		// only for admin users ont he module taxonomy
1960
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1961
+			return $terms;
1962
+		}
1963 1963
 
1964
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1965
-        // simply return this as wp doesn't need an array of stdObject Term
1966
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1964
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1965
+		// simply return this as wp doesn't need an array of stdObject Term
1966
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1967 1967
 
1968
-            return $terms;
1968
+			return $terms;
1969 1969
 
1970
-        }
1970
+		}
1971 1971
 
1972
-        // loop through and update all terms adding the author name
1973
-        foreach( $terms as $index => $term ){
1972
+		// loop through and update all terms adding the author name
1973
+		foreach( $terms as $index => $term ){
1974 1974
 
1975
-            if( is_numeric( $term ) ){
1976
-                // the term id was given, get the term object
1977
-                $term = get_term( $term, 'module' );
1978
-            }
1975
+			if( is_numeric( $term ) ){
1976
+				// the term id was given, get the term object
1977
+				$term = get_term( $term, 'module' );
1978
+			}
1979 1979
 
1980
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1980
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1981 1981
 
1982
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1984
-            }
1982
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1984
+			}
1985 1985
 
1986
-            // add the term to the teachers terms
1987
-            $users_terms[] = $term;
1986
+			// add the term to the teachers terms
1987
+			$users_terms[] = $term;
1988 1988
 
1989
-        }
1989
+		}
1990 1990
 
1991
-        return $users_terms;
1992
-    }
1991
+		return $users_terms;
1992
+	}
1993 1993
 
1994
-    /**
1995
-     * Remove modules metabox that come by default
1996
-     * with the modules taxonomy. We are removing this as
1997
-     * we have created our own custom meta box.
1998
-     */
1999
-    public static function remove_default_modules_box() {
1994
+	/**
1995
+	 * Remove modules metabox that come by default
1996
+	 * with the modules taxonomy. We are removing this as
1997
+	 * we have created our own custom meta box.
1998
+	 */
1999
+	public static function remove_default_modules_box() {
2000 2000
 
2001
-        remove_meta_box('modulediv', 'course', 'side');
2001
+		remove_meta_box('modulediv', 'course', 'side');
2002 2002
 
2003
-    }
2003
+	}
2004 2004
 
2005
-    /**
2006
-     * When a course is save make sure to reset the transient set
2007
-     * for it when determining the none module lessons.
2008
-     *
2009
-     * @sine 1.9.0
2010
-     * @param $post_id
2011
-     */
2012
-    public static function reset_none_modules_transient ( $post_id ){
2005
+	/**
2006
+	 * When a course is save make sure to reset the transient set
2007
+	 * for it when determining the none module lessons.
2008
+	 *
2009
+	 * @sine 1.9.0
2010
+	 * @param $post_id
2011
+	 */
2012
+	public static function reset_none_modules_transient ( $post_id ){
2013 2013
 
2014
-        // this should only apply to course and lesson post types
2015
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2014
+		// this should only apply to course and lesson post types
2015
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2016 2016
 
2017
-            $course_id = '';
2017
+			$course_id = '';
2018 2018
 
2019
-            if( 'lesson' == get_post_type( $post_id ) ){
2019
+			if( 'lesson' == get_post_type( $post_id ) ){
2020 2020
 
2021
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2021
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2022 2022
 
2023
-            }
2023
+			}
2024 2024
 
2025 2025
 
2026
-            if( !empty( $course_id ) ){
2026
+			if( !empty( $course_id ) ){
2027 2027
 
2028
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2028
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2029 2029
 
2030
-            }
2030
+			}
2031 2031
 
2032
-        } // end if is a course or a lesson
2032
+		} // end if is a course or a lesson
2033 2033
 
2034
-    } // end reset_none_modules_transient
2034
+	} // end reset_none_modules_transient
2035 2035
 
2036
-    /**
2037
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2038
-     *
2039
-     * @since 1.9.0
2040
-     * @deprecated since 1.9.0
2041
-     *
2042
-     */
2043
-    public static function deprecate_sensei_single_course_modules_content(){
2036
+	/**
2037
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2038
+	 *
2039
+	 * @since 1.9.0
2040
+	 * @deprecated since 1.9.0
2041
+	 *
2042
+	 */
2043
+	public static function deprecate_sensei_single_course_modules_content(){
2044 2044
 
2045
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2045
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2046 2046
 
2047
-    }
2047
+	}
2048 2048
 
2049
-    /**
2050
-     * Setup the single course module loop.
2051
-     *
2052
-     * Setup the global $sensei_modules_loop
2053
-     *
2054
-     * @since 1.9.0
2055
-     */
2056
-    public static function setup_single_course_module_loop(){
2049
+	/**
2050
+	 * Setup the single course module loop.
2051
+	 *
2052
+	 * Setup the global $sensei_modules_loop
2053
+	 *
2054
+	 * @since 1.9.0
2055
+	 */
2056
+	public static function setup_single_course_module_loop(){
2057 2057
 
2058
-        global $sensei_modules_loop, $post;
2059
-        $course_id = $post->ID;
2058
+		global $sensei_modules_loop, $post;
2059
+		$course_id = $post->ID;
2060 2060
 
2061
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2061
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2062 2062
 
2063
-        //initial setup
2064
-        $sensei_modules_loop['total'] = 0;
2065
-        $sensei_modules_loop['modules'] = array();
2066
-        $sensei_modules_loop['current'] = -1;
2063
+		//initial setup
2064
+		$sensei_modules_loop['total'] = 0;
2065
+		$sensei_modules_loop['modules'] = array();
2066
+		$sensei_modules_loop['current'] = -1;
2067 2067
 
2068
-        // exit if this course doesn't have modules
2069
-        if( !$modules || empty( $modules )  ){
2070
-            return;
2071
-        }
2068
+		// exit if this course doesn't have modules
2069
+		if( !$modules || empty( $modules )  ){
2070
+			return;
2071
+		}
2072 2072
 
2073 2073
 
2074
-        $lessons_in_all_modules = array();
2075
-        foreach( $modules as $term ){
2074
+		$lessons_in_all_modules = array();
2075
+		foreach( $modules as $term ){
2076 2076
 
2077
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2077
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2079 2079
 
2080
-        }
2080
+		}
2081 2081
 
2082 2082
 
2083
-        //setup all of the modules loop variables
2084
-        $sensei_modules_loop['total'] = count( $modules );
2085
-        $sensei_modules_loop['modules'] = $modules;
2086
-        $sensei_modules_loop['current'] = -1;
2087
-        $sensei_modules_loop['course_id'] = $course_id;
2083
+		//setup all of the modules loop variables
2084
+		$sensei_modules_loop['total'] = count( $modules );
2085
+		$sensei_modules_loop['modules'] = $modules;
2086
+		$sensei_modules_loop['current'] = -1;
2087
+		$sensei_modules_loop['course_id'] = $course_id;
2088 2088
 
2089
-    }// end setup_single_course_module_loop
2089
+	}// end setup_single_course_module_loop
2090 2090
 
2091
-    /**
2092
-     * Tear down the course module loop.
2093
-     *
2094
-     * @since 1.9.0
2095
-     *
2096
-     */
2097
-    public static function teardown_single_course_module_loop(){
2091
+	/**
2092
+	 * Tear down the course module loop.
2093
+	 *
2094
+	 * @since 1.9.0
2095
+	 *
2096
+	 */
2097
+	public static function teardown_single_course_module_loop(){
2098 2098
 
2099
-        global $sensei_modules_loop, $wp_query, $post;
2099
+		global $sensei_modules_loop, $wp_query, $post;
2100 2100
 
2101
-        //reset all of the modules loop variables
2102
-        $sensei_modules_loop['total'] = 0;
2103
-        $sensei_modules_loop['modules'] = array();
2104
-        $sensei_modules_loop['current'] = -1;
2101
+		//reset all of the modules loop variables
2102
+		$sensei_modules_loop['total'] = 0;
2103
+		$sensei_modules_loop['modules'] = array();
2104
+		$sensei_modules_loop['current'] = -1;
2105 2105
 
2106
-        // set the current course to be the global post again
2107
-        wp_reset_query();
2108
-        $post = $wp_query->post;
2109
-    }// end teardown_single_course_module_loop
2106
+		// set the current course to be the global post again
2107
+		wp_reset_query();
2108
+		$post = $wp_query->post;
2109
+	}// end teardown_single_course_module_loop
2110 2110
 
2111 2111
 } // end modules class
Please login to merge, or discard this patch.