Completed
Push — master ( ab9b7f...ec0479 )
by Dwain
04:39
created
includes/class-sensei-lesson.php 1 patch
Indentation   +1016 added lines, -1016 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 		// Setup meta fields for this post type
25 25
 		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
26 26
 
27
-        $this->question_order = '';
27
+		$this->question_order = '';
28 28
 
29 29
 		// Admin actions
30 30
 		if ( is_admin() ) {
@@ -82,18 +82,18 @@  discard block
 block discarded – undo
82 82
 			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
83 83
 			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
84 84
 
85
-            // output bulk edit fields
86
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
87
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
85
+			// output bulk edit fields
86
+			add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
87
+			add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
88 88
 
89
-            // load quick edit default values
90
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
89
+			// load quick edit default values
90
+			add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
91 91
 
92
-            // save bulk edit fields
93
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
92
+			// save bulk edit fields
93
+			add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
94 94
 
95
-            // flush rewrite rules when saving a lesson
96
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
95
+			// flush rewrite rules when saving a lesson
96
+			add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
97 97
 
98 98
 		} else {
99 99
 			// Frontend actions
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 		$post_args = array(	'post_type' 		=> 'lesson',
188 188
 							'posts_per_page' 		=> -1,
189 189
 							'orderby'         	=> 'title',
190
-    						'order'           	=> 'ASC',
191
-    						'exclude' 			=> $post->ID,
190
+							'order'           	=> 'ASC',
191
+							'exclude' 			=> $post->ID,
192 192
 							'suppress_filters' 	=> 0
193 193
 							);
194 194
 		$posts_array = get_posts( $post_args );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 
225 225
 		$checked = '';
226 226
 		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
227
-	 	    $checked = checked( 'preview', $lesson_preview, false );
227
+	 		$checked = checked( 'preview', $lesson_preview, false );
228 228
 	 	} // End If Statement
229 229
 
230 230
 	 	$html .= '<label for="lesson_preview">';
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 
275 275
 	/**
276
-     * Update the lesson quiz and all the post meta
276
+	 * Update the lesson quiz and all the post meta
277 277
 	 *
278 278
 	 * @access public
279 279
 	 * @return void
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 		}
295 295
 
296 296
 		// Temporarily disable the filter
297
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
297
+		remove_action( 'save_post', array( $this, 'quiz_update' ) );
298 298
 		// Save the Quiz
299 299
 		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
300 300
 
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
 
310 310
 		// Setup Query Arguments
311 311
 		$post_type_args = array(	'post_content' => $post_content,
312
-  		    						'post_status' => $post_status,
313
-  		    						'post_title' => $post_title,
314
-  		    						'post_type' => 'quiz',
315
-                                    'post_parent' => $post_id,
316
-  		    						);
312
+  									'post_status' => $post_status,
313
+  									'post_title' => $post_title,
314
+  									'post_type' => 'quiz',
315
+									'post_parent' => $post_id,
316
+  									);
317 317
 
318 318
 		$settings = $this->get_quiz_settings();
319 319
 
@@ -321,48 +321,48 @@  discard block
 block discarded – undo
321 321
 		if ( 0 < $quiz_id ) {
322 322
 			// Update the Quiz
323 323
 			$post_type_args[ 'ID' ] = $quiz_id;
324
-		    wp_update_post($post_type_args);
325
-
326
-		    // Update the post meta data
327
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
328
-
329
-		    foreach( $settings as $field ) {
330
-		    	if( 'random_question_order' != $field['id'] ) {
331
-			    	$value = $this->get_submitted_setting_value( $field );
332
-			    	if( isset( $value ) ) {
333
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
334
-			    	}
335
-			    }
336
-		    }
337
-
338
-		    // Set the post terms for quiz-type
339
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
324
+			wp_update_post($post_type_args);
325
+
326
+			// Update the post meta data
327
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
328
+
329
+			foreach( $settings as $field ) {
330
+				if( 'random_question_order' != $field['id'] ) {
331
+					$value = $this->get_submitted_setting_value( $field );
332
+					if( isset( $value ) ) {
333
+						update_post_meta( $quiz_id, '_' . $field['id'], $value );
334
+					}
335
+				}
336
+			}
337
+
338
+			// Set the post terms for quiz-type
339
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
340 340
 		} else {
341 341
 			// Create the Quiz
342
-		    $quiz_id = wp_insert_post($post_type_args);
343
-
344
-		    // Add the post meta data WP will add it if it doesn't exist
345
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
346
-
347
-		    foreach( $settings as $field ) {
348
-		    	if( 'random_question_order' != $field['id'] ) {
349
-
350
-                    //ignore values not posted to avoid
351
-                    // overwriting with empty or default values
352
-                    // when the values are posted from bulk edit or quick edit
353
-                    if( !isset( $_POST[ $field['id'] ] ) ){
354
-                        continue;
355
-                    }
356
-
357
-			    	$value = $this->get_submitted_setting_value( $field );
358
-			    	if( isset( $value ) ) {
359
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
360
-			    	}
361
-			    }
362
-		    }
363
-
364
-		    // Set the post terms for quiz-type
365
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
342
+			$quiz_id = wp_insert_post($post_type_args);
343
+
344
+			// Add the post meta data WP will add it if it doesn't exist
345
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
346
+
347
+			foreach( $settings as $field ) {
348
+				if( 'random_question_order' != $field['id'] ) {
349
+
350
+					//ignore values not posted to avoid
351
+					// overwriting with empty or default values
352
+					// when the values are posted from bulk edit or quick edit
353
+					if( !isset( $_POST[ $field['id'] ] ) ){
354
+						continue;
355
+					}
356
+
357
+					$value = $this->get_submitted_setting_value( $field );
358
+					if( isset( $value ) ) {
359
+						add_post_meta( $quiz_id, '_' . $field['id'], $value );
360
+					}
361
+				}
362
+			}
363
+
364
+			// Set the post terms for quiz-type
365
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
366 366
 		} // End If Statement
367 367
 
368 368
 		// Add default lesson order meta value
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
 		}
385 385
 
386 386
 		// Restore the previously disabled filter
387
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
387
+		add_action( 'save_post', array( $this, 'quiz_update' ) );
388 388
 
389 389
 	} // End post_updated()
390 390
 
@@ -424,22 +424,22 @@  discard block
 block discarded – undo
424 424
 		// Get the meta key.
425 425
 		$meta_key = '_' . $post_key;
426 426
 
427
-        //ignore fields are not posted
427
+		//ignore fields are not posted
428 428
 
429
-        if( !isset( $_POST[ $post_key ] ) ){
429
+		if( !isset( $_POST[ $post_key ] ) ){
430 430
 
431
-            // except for lesson preview checkbox field
432
-            if( 'lesson_preview' == $post_key ){
431
+			// except for lesson preview checkbox field
432
+			if( 'lesson_preview' == $post_key ){
433 433
 
434
-                $_POST[ $post_key ] = '';
434
+				$_POST[ $post_key ] = '';
435 435
 
436
-            } else {
436
+			} else {
437 437
 
438
-                return false;
438
+				return false;
439 439
 
440
-            }
440
+			}
441 441
 
442
-        }
442
+		}
443 443
 
444 444
 		// Get the posted data and sanitize it for use as an HTML class.
445 445
 		if ( 'lesson_video_embed' == $post_key) {
@@ -448,10 +448,10 @@  discard block
 block discarded – undo
448 448
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
449 449
 		} // End If Statement
450 450
 
451
-        // update field with the new value
452
-        if( -1 != $new_meta_value  ){
453
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
454
-        }
451
+		// update field with the new value
452
+		if( -1 != $new_meta_value  ){
453
+			return update_post_meta( $post_id, $meta_key, $new_meta_value );
454
+		}
455 455
 
456 456
 	} // End save_post_meta()
457 457
 
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
 		$post_args = array(	'post_type' 		=> 'course',
477 477
 							'posts_per_page' 		=> -1,
478 478
 							'orderby'         	=> 'title',
479
-    						'order'           	=> 'ASC',
480
-    						'post_status'      	=> 'any',
481
-    						'suppress_filters' 	=> 0,
479
+							'order'           	=> 'ASC',
480
+							'post_status'      	=> 'any',
481
+							'suppress_filters' 	=> 0,
482 482
 							);
483 483
 		$posts_array = get_posts( $post_args );
484 484
 		// Buid the HTML to Output
@@ -486,20 +486,20 @@  discard block
 block discarded – undo
486 486
 		// Nonce
487 487
 		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
488 488
 
489
-        // Select the course for the lesson
490
-        $drop_down_args = array(
491
-            'name'=>'lesson_course',
492
-            'id' => 'lesson-course-options'
493
-        );
489
+		// Select the course for the lesson
490
+		$drop_down_args = array(
491
+			'name'=>'lesson_course',
492
+			'id' => 'lesson-course-options'
493
+		);
494 494
 
495
-        $courses = WooThemes_Sensei_Course::get_all_courses();
496
-        $courses_options = array();
497
-        foreach( $courses as $course ){
498
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
499
-        }
500
-        $html .= WooThemes_Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
495
+		$courses = WooThemes_Sensei_Course::get_all_courses();
496
+		$courses_options = array();
497
+		foreach( $courses as $course ){
498
+			$courses_options[ $course->ID ] = get_the_title( $course ) ;
499
+		}
500
+		$html .= WooThemes_Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
501 501
 
502
-        // Course Actions Panel
502
+		// Course Actions Panel
503 503
 		if ( current_user_can( 'publish_courses' )) {
504 504
 				$html .= '<div id="lesson-course-actions">';
505 505
 					$html .= '<p>';
@@ -532,9 +532,9 @@  discard block
 block discarded – undo
532 532
 							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
533 533
 													'posts_per_page' 		=> -1,
534 534
 													'orderby'         	=> 'title',
535
-	    											'order'           	=> 'DESC',
536
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
537
-	    											'tax_query'			=> array(
535
+													'order'           	=> 'DESC',
536
+													'post_status'		=> array( 'publish', 'private', 'draft' ),
537
+													'tax_query'			=> array(
538 538
 														array(
539 539
 															'taxonomy'	=> 'product_type',
540 540
 															'field'		=> 'slug',
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
 															'operator'	=> 'NOT IN'
543 543
 														)
544 544
 													),
545
-	    											'suppress_filters' 	=> 0
545
+													'suppress_filters' 	=> 0
546 546
 													);
547 547
 							$products_array = get_posts( $product_args );
548 548
 							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
@@ -870,58 +870,58 @@  discard block
 block discarded – undo
870 870
 					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
871 871
 						$html .= '<td colspan="5">';
872 872
 							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
873
-					    	$html .= '<div class="question_required_fields">';
874
-
875
-						    	// Question title
876
-						    	$html .= '<div>';
877
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
878
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
879
-						    	$html .= '</div>';
880
-
881
-						    	// Question description
882
-						    	$html .= '<div>';
883
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
884
-						    	$html .= '</div>';
885
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
886
-
887
-						    	// Question grade
888
-						    	$html .= '<div>';
889
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
890
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
891
-						    	$html .= '</div>';
892
-
893
-						    	// Random order
894
-						    	if( $question_type == 'multiple-choice' ) {
895
-						    		$html .= '<div>';
896
-						    			$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>';
897
-						    		$html .= '</div>';
898
-						    	}
899
-
900
-						    	// Question media
901
-						    	$html .= '<div>';
902
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
903
-							    	$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>';
904
-							    	$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/>';
905
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
906
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
907
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
908
-						    	$html .= '</div>';
909
-
910
-						    $html .= '</div>';
911
-
912
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
913
-
914
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
873
+							$html .= '<div class="question_required_fields">';
874
+
875
+								// Question title
876
+								$html .= '<div>';
877
+									$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
878
+									$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
879
+								$html .= '</div>';
880
+
881
+								// Question description
882
+								$html .= '<div>';
883
+									$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
884
+								$html .= '</div>';
885
+									$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
886
+
887
+								// Question grade
888
+								$html .= '<div>';
889
+									$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
890
+									$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
891
+								$html .= '</div>';
892
+
893
+								// Random order
894
+								if( $question_type == 'multiple-choice' ) {
895
+									$html .= '<div>';
896
+										$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>';
897
+									$html .= '</div>';
898
+								}
899
+
900
+								// Question media
901
+								$html .= '<div>';
902
+									$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
903
+									$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>';
904
+									$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/>';
905
+									$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
906
+									$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
907
+									$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
908
+								$html .= '</div>';
909
+
910
+							$html .= '</div>';
911
+
912
+							$html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
913
+
914
+							$html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
915 915
 							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
916 916
 
917 917
 							if( 'quiz' == $context ) {
918
-					    		$html .= '<div class="update-question">';
919
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
920
-						    		$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>';
921
-					    		$html .= '</div>';
922
-					    	}
918
+								$html .= '<div class="update-question">';
919
+									$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
920
+									$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>';
921
+								$html .= '</div>';
922
+							}
923 923
 
924
-			    		$html .= '</td>';
924
+						$html .= '</td>';
925 925
 					$html .= '</tr>';
926 926
 				}
927 927
 
@@ -942,20 +942,20 @@  discard block
 block discarded – undo
942 942
 			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
943 943
 
944 944
 			if( 'quiz' == $context ) {
945
-	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
946
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
947
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
948
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
949
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
950
-	    			}
951
-	    		$html .= '</h2>';
952
-	    	}
945
+				$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
946
+					$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
947
+					$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
948
+					if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
949
+						$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
950
+					}
951
+				$html .= '</h2>';
952
+			}
953 953
 
954
-	    	$html .= '<div class="tab-content" id="tab-new-content">';
954
+			$html .= '<div class="tab-content" id="tab-new-content">';
955 955
 
956
-	    		if( 'quiz' == $context ) {
957
-	    			$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>';
958
-	    		}
956
+				if( 'quiz' == $context ) {
957
+					$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>';
958
+				}
959 959
 
960 960
 				$html .= '<div class="question">';
961 961
 					$html .= '<div class="question_required_fields">';
@@ -997,18 +997,18 @@  discard block
 block discarded – undo
997 997
 
998 998
 						// Random order
999 999
 						$html .= '<p class="add_question_random_order">';
1000
-			    			$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>';
1001
-			    		$html .= '</p>';
1000
+							$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>';
1001
+						$html .= '</p>';
1002 1002
 
1003
-			    		// Question media
1003
+						// Question media
1004 1004
 						$html .= '<p>';
1005
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1006
-					    	$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>';
1007
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1008
-					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1009
-					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1010
-					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1011
-				    	$html .= '</p>';
1005
+							$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1006
+							$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>';
1007
+							$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1008
+							$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1009
+							$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1010
+							$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1011
+						$html .= '</p>';
1012 1012
 
1013 1013
 					$html .= '</div>';
1014 1014
 				$html .= '</div>';
@@ -1019,19 +1019,19 @@  discard block
 block discarded – undo
1019 1019
 
1020 1020
 				if( 'quiz' == $context ) {
1021 1021
 					$html .= '<div class="add-question">';
1022
-			    		$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>';
1023
-		    		$html .= '</div>';
1024
-		    	}
1022
+						$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>';
1023
+					$html .= '</div>';
1024
+				}
1025 1025
 
1026
-		    $html .= '</div>';
1026
+			$html .= '</div>';
1027 1027
 
1028
-		    if( 'quiz' == $context ) {
1028
+			if( 'quiz' == $context ) {
1029 1029
 
1030
-			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1030
+				$html .= '<div class="tab-content hidden" id="tab-existing-content">';
1031 1031
 
1032
-			    	$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>';
1032
+					$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>';
1033 1033
 
1034
-			    	$html .= '<div id="existing-filters" class="alignleft actions">
1034
+					$html .= '<div id="existing-filters" class="alignleft actions">
1035 1035
 			    				<select id="existing-status">
1036 1036
 			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1037 1037
 			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
@@ -1039,23 +1039,23 @@  discard block
 block discarded – undo
1039 1039
 			    				</select>
1040 1040
 			    				<select id="existing-type">
1041 1041
 			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1042
-							    	foreach ( $question_types as $type => $label ) {
1042
+									foreach ( $question_types as $type => $label ) {
1043 1043
 										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1044 1044
 									}
1045
-    				$html .= '</select>
1045
+					$html .= '</select>
1046 1046
     							<select id="existing-category">
1047 1047
 			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1048
-				    				foreach( $question_cats as $cat ) {
1048
+									foreach( $question_cats as $cat ) {
1049 1049
 										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1050 1050
 									}
1051
-    				$html .= '</select>
1051
+					$html .= '</select>
1052 1052
     							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1053 1053
     							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1054 1054
 			    			</div>';
1055 1055
 
1056
-			    	$html .= '<table id="existing-table" class="widefat">';
1056
+					$html .= '<table id="existing-table" class="widefat">';
1057 1057
 
1058
-			    		$html .= '<thead>
1058
+						$html .= '<thead>
1059 1059
 									    <tr>
1060 1060
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1061 1061
 									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
@@ -1083,28 +1083,28 @@  discard block
 block discarded – undo
1083 1083
 
1084 1084
 						$html .= '</tbody>';
1085 1085
 
1086
-			    	$html .= '</table>';
1086
+					$html .= '</table>';
1087 1087
 
1088
-			    	$next_class = '';
1089
-			    	if( $questions['count'] <= 10 ) {
1090
-			    		$next_class = 'hidden';
1091
-			    	}
1088
+					$next_class = '';
1089
+					if( $questions['count'] <= 10 ) {
1090
+						$next_class = 'hidden';
1091
+					}
1092 1092
 
1093
-			    	$html .= '<div id="existing-pagination">';
1094
-			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1095
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1096
-			    	$html .= '</div>';
1093
+					$html .= '<div id="existing-pagination">';
1094
+						$html .= '<input type="hidden" id="existing-page" value="1" />';
1095
+						$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1096
+					$html .= '</div>';
1097 1097
 
1098
-			    	$html .= '<div class="existing-actions">';
1099
-			    		$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>';
1100
-			    	$html .= '</div>';
1098
+					$html .= '<div class="existing-actions">';
1099
+						$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>';
1100
+					$html .= '</div>';
1101 1101
 
1102
-			    $html .= '</div>';
1102
+				$html .= '</div>';
1103 1103
 
1104
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1105
-				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1104
+				if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1105
+					$html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1106 1106
 
1107
-				    	$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>';
1107
+						$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>';
1108 1108
 
1109 1109
 						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1110 1110
 						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
 
1118 1118
 						$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>';
1119 1119
 
1120
-				    $html .= '</div>';
1120
+					$html .= '</div>';
1121 1121
 				}
1122 1122
 			}
1123 1123
 
@@ -1190,14 +1190,14 @@  discard block
 block discarded – undo
1190 1190
 
1191 1191
 		$qry = new WP_Query( $args );
1192 1192
 
1193
-        /**
1194
-         * Filter existing questions query
1195
-         *
1196
-         * @since 1.8.0
1197
-         *
1198
-         * @param WP_Query $wp_query
1199
-         */
1200
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1193
+		/**
1194
+		 * Filter existing questions query
1195
+		 *
1196
+		 * @since 1.8.0
1197
+		 *
1198
+		 * @param WP_Query $wp_query
1199
+		 */
1200
+		$qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1201 1201
 
1202 1202
 		$questions['questions'] = $qry->posts;
1203 1203
 		$questions['count'] = intval( $qry->found_posts );
@@ -1212,14 +1212,14 @@  discard block
 block discarded – undo
1212 1212
 
1213 1213
 		if( ! $question_id ) {
1214 1214
 
1215
-            return;
1215
+			return;
1216 1216
 
1217
-        }
1217
+		}
1218 1218
 
1219 1219
 		$existing_class = '';
1220 1220
 		if( $row % 2 ) {
1221
-            $existing_class = 'alternate';
1222
-        }
1221
+			$existing_class = 'alternate';
1222
+		}
1223 1223
 
1224 1224
 		$question_type = Sensei()->question->get_question_type( $question_id );
1225 1225
 
@@ -1353,67 +1353,67 @@  discard block
 block discarded – undo
1353 1353
 							}
1354 1354
 						}
1355 1355
 
1356
-				    	// Calculate total wrong answers available (defaults to 4)
1357
-				    	$total_wrong = 0;
1358
-				    	if( $question_id ) {
1359
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1360
-				    	}
1361
-				    	if( 0 == intval( $total_wrong ) ) {
1362
-				    		$total_wrong = 1;
1363
-				    	}
1356
+						// Calculate total wrong answers available (defaults to 4)
1357
+						$total_wrong = 0;
1358
+						if( $question_id ) {
1359
+							$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1360
+						}
1361
+						if( 0 == intval( $total_wrong ) ) {
1362
+							$total_wrong = 1;
1363
+						}
1364 1364
 
1365
-                        // Setup Wrong Answer HTML
1366
-                        foreach ( $wrong_answers as $i => $answer ){
1365
+						// Setup Wrong Answer HTML
1366
+						foreach ( $wrong_answers as $i => $answer ){
1367 1367
 
1368
-                            $answer_id = $this->get_answer_id( $answer );
1369
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1370
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1371
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1372
-                            if( $question_id ) {
1368
+							$answer_id = $this->get_answer_id( $answer );
1369
+							$wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1370
+							$wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1371
+							$wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1372
+							if( $question_id ) {
1373 1373
 
1374
-                                $answers[ $answer_id ] = $wrong_answer;
1374
+								$answers[ $answer_id ] = $wrong_answer;
1375 1375
 
1376
-                            } else {
1376
+							} else {
1377 1377
 
1378
-                                $answers[] = $wrong_answer;
1378
+								$answers[] = $wrong_answer;
1379 1379
 
1380
-                            }
1380
+							}
1381 1381
 
1382
-                        } // end for each
1382
+						} // end for each
1383 1383
 
1384
-				    	$answers_sorted = $answers;
1385
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1386
-				    		$answers_sorted = array();
1387
-				    		foreach( $answer_order as $answer_id ) {
1388
-				    			if( isset( $answers[ $answer_id ] ) ) {
1389
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1390
-				    				unset( $answers[ $answer_id ] );
1391
-				    			}
1392
-				    		}
1384
+						$answers_sorted = $answers;
1385
+						if( $question_id && count( $answer_order ) > 0 ) {
1386
+							$answers_sorted = array();
1387
+							foreach( $answer_order as $answer_id ) {
1388
+								if( isset( $answers[ $answer_id ] ) ) {
1389
+									$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1390
+									unset( $answers[ $answer_id ] );
1391
+								}
1392
+							}
1393 1393
 
1394
-				    		if( count( $answers ) > 0 ) {
1395
-						    	foreach( $answers as $id => $answer ) {
1396
-						    		$answers_sorted[ $id ] = $answer;
1397
-						    	}
1398
-						    }
1399
-				    	}
1394
+							if( count( $answers ) > 0 ) {
1395
+								foreach( $answers as $id => $answer ) {
1396
+									$answers_sorted[ $id ] = $answer;
1397
+								}
1398
+							}
1399
+						}
1400 1400
 
1401 1401
 						foreach( $answers_sorted as $id => $answer ) {
1402
-				    		$html .= $answer;
1403
-				    	}
1402
+							$html .= $answer;
1403
+						}
1404 1404
 
1405
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1406
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1407
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1405
+						$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1406
+						$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1407
+						$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1408 1408
 
1409
-				    	$html .= '<div class="add_answer_options">';
1410
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1411
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1412
-				    	$html .= '</div>';
1409
+						$html .= '<div class="add_answer_options">';
1410
+							$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1411
+							$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1412
+						$html .= '</div>';
1413 1413
 
1414
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1414
+						$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1415 1415
 
1416
-			    	$html .= '</div>';
1416
+					$html .= '</div>';
1417 1417
 				break;
1418 1418
 				case 'boolean':
1419 1419
 					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
 						$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>';
1427 1427
 						$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>';
1428 1428
 
1429
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1429
+					$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1430 1430
 
1431 1431
 					$html .= '</div>';
1432 1432
 				break;
@@ -1501,17 +1501,17 @@  discard block
 block discarded – undo
1501 1501
 
1502 1502
 	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1503 1503
 
1504
-        // default field name
1505
-        $field_name = 'answer_feedback';
1506
-        if( 'boolean' == $question_type ){
1504
+		// default field name
1505
+		$field_name = 'answer_feedback';
1506
+		if( 'boolean' == $question_type ){
1507 1507
 
1508
-            $field_name = 'answer_feedback_boolean';
1508
+			$field_name = 'answer_feedback_boolean';
1509 1509
 
1510
-        }elseif( 'multiple-choice' == $question_type ){
1510
+		}elseif( 'multiple-choice' == $question_type ){
1511 1511
 
1512
-            $field_name = 'answer_feedback_multiple_choice';
1512
+			$field_name = 'answer_feedback_multiple_choice';
1513 1513
 
1514
-        }// end if
1514
+		}// end if
1515 1515
 
1516 1516
 		if( $question_counter ) {
1517 1517
 			$field_name = 'answer_' . $question_counter . '_feedback';
@@ -1716,15 +1716,15 @@  discard block
 block discarded – undo
1716 1716
 			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1717 1717
 
1718 1718
 			// Load the lessons script
1719
-            wp_enqueue_media();
1719
+			wp_enqueue_media();
1720 1720
 			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1721 1721
 			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1722 1722
 			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1723 1723
 
1724
-            // Load the bulk edit screen script
1725
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1726
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1727
-            }
1724
+			// Load the bulk edit screen script
1725
+			if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1726
+				wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1727
+			}
1728 1728
 
1729 1729
 			// Localise script
1730 1730
 			$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' ) );
@@ -2027,12 +2027,12 @@  discard block
 block discarded – undo
2027 2027
 
2028 2028
 					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2029 2029
 					if( ! in_array( $quiz_id, $quizzes ) ) {
2030
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2030
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2031 2031
 						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2032 2032
 						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2033
-			    	}
2033
+					}
2034 2034
 
2035
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2035
+					add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2036 2036
 					$question_type = Sensei()->question->get_question_type( $question_id );
2037 2037
 
2038 2038
 					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
@@ -2138,34 +2138,34 @@  discard block
 block discarded – undo
2138 2138
 		$post_content = $course_content;
2139 2139
 		// Course Query Arguments
2140 2140
 		$post_type_args = array(	'post_content' => $post_content,
2141
-  		    						'post_status' => $post_status,
2142
-  		    						'post_title' => $post_title,
2143
-  		    						'post_type' => $post_type
2144
-  		    						);
2141
+  									'post_status' => $post_status,
2142
+  									'post_title' => $post_title,
2143
+  									'post_type' => $post_type
2144
+  									);
2145 2145
   		// Only save if there is a valid title
2146 2146
   		if ( $post_title != '' ) {
2147
-  		    // Check for prerequisite courses & product id
2148
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2149
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2150
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2151
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2152
-  		    // Insert or Update the Lesson Quiz
2153
-		    if ( 0 < $course_id ) {
2154
-		    	$post_type_args[ 'ID' ] = $course_id;
2155
-		    	$course_id = wp_update_post($post_type_args);
2156
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2157
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2158
-		    	if ( 0 < $course_category_id ) {
2159
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2160
-		    	} // End If Statement
2161
-		    } else {
2162
-		    	$course_id = wp_insert_post($post_type_args);
2163
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2164
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2165
-		    	if ( 0 < $course_category_id ) {
2166
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2167
-		    	} // End If Statement
2168
-		    } // End If Statement
2147
+  			// Check for prerequisite courses & product id
2148
+  			$course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2149
+  			$course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2150
+  			$course_category_id = absint( $data[ 'course_category' ] );
2151
+  			if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2152
+  			// Insert or Update the Lesson Quiz
2153
+			if ( 0 < $course_id ) {
2154
+				$post_type_args[ 'ID' ] = $course_id;
2155
+				$course_id = wp_update_post($post_type_args);
2156
+				update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2157
+				update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2158
+				if ( 0 < $course_category_id ) {
2159
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2160
+				} // End If Statement
2161
+			} else {
2162
+				$course_id = wp_insert_post($post_type_args);
2163
+				add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2164
+				add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2165
+				if ( 0 < $course_category_id ) {
2166
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2167
+				} // End If Statement
2168
+			} // End If Statement
2169 2169
 		} // End If Statement
2170 2170
   		// Check that the insert or update saved by testing the post id
2171 2171
   		if ( 0 < $course_id ) {
@@ -2256,17 +2256,17 @@  discard block
 block discarded – undo
2256 2256
 		$answer_feedback = '';
2257 2257
 		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2258 2258
 
2259
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2259
+			$answer_feedback = $data[ 'answer_feedback_boolean' ];
2260 2260
 
2261 2261
 		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2262 2262
 
2263
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2263
+			$answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2264 2264
 
2265
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2265
+		}elseif( isset( $data[ 'answer_feedback' ] )  ){
2266 2266
 
2267
-            $answer_feedback = $data[ 'answer_feedback' ];
2267
+			$answer_feedback = $data[ 'answer_feedback' ];
2268 2268
 
2269
-        } // End If Statement
2269
+		} // End If Statement
2270 2270
 
2271 2271
 		$post_title = $question_text;
2272 2272
 		$post_author = $data[ 'post_author' ];
@@ -2281,10 +2281,10 @@  discard block
 block discarded – undo
2281 2281
 		}
2282 2282
 		// Question Query Arguments
2283 2283
 		$post_type_args = array(	'post_content' => $post_content,
2284
-  		    						'post_status' => $post_status,
2285
-  		    						'post_title' => $post_title,
2286
-  		    						'post_type' => $post_type
2287
-  		    						);
2284
+  									'post_status' => $post_status,
2285
+  									'post_title' => $post_title,
2286
+  									'post_type' => $post_type
2287
+  									);
2288 2288
 
2289 2289
   		// Remove empty values and reindex the array
2290 2290
   		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
@@ -2320,14 +2320,14 @@  discard block
 block discarded – undo
2320 2320
   		if ( $post_title != '' ) {
2321 2321
 
2322 2322
   			// Get Quiz ID for the question
2323
-  		    $quiz_id = $data['quiz_id'];
2323
+  			$quiz_id = $data['quiz_id'];
2324 2324
 
2325
-  		    // Get question media
2325
+  			// Get question media
2326 2326
 			$question_media = $data['question_media'];
2327 2327
 
2328
-  		    // Get answer order
2329
-  		    $answer_order = '';
2330
-  		    if( isset( $data['answer_order'] ) ) {
2328
+  			// Get answer order
2329
+  			$answer_order = '';
2330
+  			if( isset( $data['answer_order'] ) ) {
2331 2331
 				$answer_order = $data['answer_order'];
2332 2332
 			}
2333 2333
 
@@ -2337,38 +2337,38 @@  discard block
 block discarded – undo
2337 2337
 				$random_order = $data['random_order'];
2338 2338
 			}
2339 2339
 
2340
-  		    // Insert or Update the question
2341
-  		    if ( 0 < $question_id ) {
2342
-
2343
-  		    	$post_type_args[ 'ID' ] = $question_id;
2344
-		    	$question_id = wp_update_post( $post_type_args );
2345
-
2346
-		    	// Update poast meta
2347
-		    	if( 'quiz' == $context ) {
2348
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2349
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2350
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2351
-			    	}
2352
-		    	}
2353
-
2354
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2355
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2356
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2357
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2358
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2359
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2360
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2361
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2362
-
2363
-		    	if( 'quiz' != $context ) {
2364
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2365
-		    	}
2340
+  			// Insert or Update the question
2341
+  			if ( 0 < $question_id ) {
2342
+
2343
+  				$post_type_args[ 'ID' ] = $question_id;
2344
+				$question_id = wp_update_post( $post_type_args );
2345
+
2346
+				// Update poast meta
2347
+				if( 'quiz' == $context ) {
2348
+					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2349
+					if( ! in_array( $quiz_id, $quizzes ) ) {
2350
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2351
+					}
2352
+				}
2353
+
2354
+				update_post_meta( $question_id, '_question_grade', $question_grade );
2355
+				update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2356
+				update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2357
+				update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2358
+				update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2359
+				update_post_meta( $question_id, '_question_media', $question_media );
2360
+				update_post_meta( $question_id, '_answer_order', $answer_order );
2361
+				update_post_meta( $question_id, '_random_order', $random_order );
2362
+
2363
+				if( 'quiz' != $context ) {
2364
+					wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2365
+				}
2366 2366
 				// Don't store empty value, no point
2367 2367
 				if ( !empty($answer_feedback) ) {
2368 2368
 					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2369 2369
 				}
2370 2370
 
2371
-		    } else {
2371
+			} else {
2372 2372
 				$question_id = wp_insert_post( $post_type_args );
2373 2373
 				$question_count = intval( $data['question_count'] );
2374 2374
 				++$question_count;
@@ -2381,29 +2381,29 @@  discard block
 block discarded – undo
2381 2381
 				}
2382 2382
 
2383 2383
 				if( isset( $question_grade ) ) {
2384
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2385
-		    	}
2386
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2387
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2388
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2389
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2390
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2391
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2392
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2393
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2384
+					add_post_meta( $question_id, '_question_grade', $question_grade );
2385
+				}
2386
+				add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2387
+				add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2388
+				add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2389
+				add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2390
+				add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2391
+				add_post_meta( $question_id, '_question_media', $question_media );
2392
+				add_post_meta( $question_id, '_answer_order', $answer_order );
2393
+				add_post_meta( $question_id, '_random_order', $random_order );
2394 2394
 				// Don't store empty value, no point
2395 2395
 				if ( !empty($answer_feedback) ) {
2396 2396
 					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2397 2397
 				}
2398 2398
 
2399
-		    	// Set the post terms for question-type
2400
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2399
+				// Set the post terms for question-type
2400
+				wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2401 2401
 
2402
-			    if( $question_category ) {
2403
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2404
-	    		}
2402
+				if( $question_category ) {
2403
+					wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2404
+				}
2405 2405
 
2406
-		    } // End If Statement
2406
+			} // End If Statement
2407 2407
 		} // End If Statement
2408 2408
   		// Check that the insert or update saved by testing the post id
2409 2409
   		if ( 0 < $question_id ) {
@@ -2452,7 +2452,7 @@  discard block
 block discarded – undo
2452 2452
 	public function lesson_complexities() {
2453 2453
 
2454 2454
 		// V2 - make filter for this array
2455
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2455
+		$lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2456 2456
 									'std' => __( 'Standard', 'woothemes-sensei' ),
2457 2457
 									'hard' => __( 'Hard', 'woothemes-sensei' )
2458 2458
 									);
@@ -2519,14 +2519,14 @@  discard block
 block discarded – undo
2519 2519
 		$post_args = array(	'post_type' 		=> 'quiz',
2520 2520
 							'posts_per_page' 		=> 1,
2521 2521
 							'orderby'         	=> 'title',
2522
-    						'order'           	=> 'DESC',
2523
-    						'post_parent'      	=> $lesson_id,
2524
-    						'post_status'		=> $post_status,
2522
+							'order'           	=> 'DESC',
2523
+							'post_parent'      	=> $lesson_id,
2524
+							'post_status'		=> $post_status,
2525 2525
 							'suppress_filters' 	=> 0,
2526 2526
 							'fields'            => $fields
2527 2527
 							);
2528 2528
 		$posts_array = get_posts( $post_args );
2529
-        $quiz_id = array_shift($posts_array);
2529
+		$quiz_id = array_shift($posts_array);
2530 2530
 
2531 2531
 		return $quiz_id;
2532 2532
 	} // End lesson_quizzes()
@@ -2534,34 +2534,34 @@  discard block
 block discarded – undo
2534 2534
 
2535 2535
 	/**
2536 2536
 	 * Fetches all the questions for a quiz depending on certain conditions.
2537
-     *
2538
-     * Determine which questions should be shown depending on:
2539
-     * - admin/teacher selected questions to be shown
2540
-     * - questions shown to a user previously (saved as asked questions)
2541
-     * - limit number of questions lesson setting
2542 2537
 	 *
2543
-     * @since 1.0
2538
+	 * Determine which questions should be shown depending on:
2539
+	 * - admin/teacher selected questions to be shown
2540
+	 * - questions shown to a user previously (saved as asked questions)
2541
+	 * - limit number of questions lesson setting
2542
+	 *
2543
+	 * @since 1.0
2544 2544
 	 * @param int $quiz_id (default: 0)
2545 2545
 	 * @param string $post_status (default: 'publish')
2546 2546
 	 * @param string $orderby (default: 'meta_value_num title')
2547 2547
 	 * @param string $order (default: 'ASC')
2548
-     *
2548
+	 *
2549 2549
 	 * @return array $questions { $question type WP_Post }
2550 2550
 	 */
2551 2551
 	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2552 2552
 
2553 2553
 		$quiz_id = (string) $quiz_id;
2554
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2554
+		$quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2555 2555
 
2556
-        // setup the user id
2557
-        if( is_admin() ) {
2558
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2559
-        } else {
2560
-            $user_id = get_current_user_id();
2561
-        }
2556
+		// setup the user id
2557
+		if( is_admin() ) {
2558
+			$user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2559
+		} else {
2560
+			$user_id = get_current_user_id();
2561
+		}
2562 2562
 
2563
-        // get the users current status on the lesson
2564
-        $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2563
+		// get the users current status on the lesson
2564
+		$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2565 2565
 
2566 2566
 		// Set the default question order if it has not already been set for this quiz
2567 2567
 		$this->set_default_question_order( $quiz_id );
@@ -2591,14 +2591,14 @@  discard block
 block discarded – undo
2591 2591
 			'suppress_filters' 	=> 0
2592 2592
 		);
2593 2593
 
2594
-        //query the questions
2594
+		//query the questions
2595 2595
 		$questions_query = new WP_Query( $question_query_args );
2596 2596
 
2597
-        // Set return array to initially include all items
2598
-        $questions = $questions_query->posts;
2597
+		// Set return array to initially include all items
2598
+		$questions = $questions_query->posts;
2599 2599
 
2600
-        // set the questions array that will be manipulated within this function
2601
-        $questions_array = $questions_query->posts;
2600
+		// set the questions array that will be manipulated within this function
2601
+		$questions_array = $questions_query->posts;
2602 2602
 
2603 2603
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2604 2604
 		$selected_questions = false;
@@ -2711,36 +2711,36 @@  discard block
 block discarded – undo
2711 2711
 			}
2712 2712
 		}
2713 2713
 
2714
-        // Save the questions that will be asked for the current user
2715
-        // this happens only once per user/quiz, unless the user resets the quiz
2716
-        if( ! is_admin() ){
2714
+		// Save the questions that will be asked for the current user
2715
+		// this happens only once per user/quiz, unless the user resets the quiz
2716
+		if( ! is_admin() ){
2717 2717
 
2718
-            if( $user_lesson_status ) {
2718
+			if( $user_lesson_status ) {
2719 2719
 
2720
-                $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2721
-                if ( empty($questions_asked) && $user_lesson_status) {
2720
+				$questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2721
+				if ( empty($questions_asked) && $user_lesson_status) {
2722 2722
 
2723
-                    $questions_asked = array();
2724
-                    foreach ($questions as $question) {
2723
+					$questions_asked = array();
2724
+					foreach ($questions as $question) {
2725 2725
 
2726
-                        $questions_asked[] = $question->ID;
2726
+						$questions_asked[] = $question->ID;
2727 2727
 
2728
-                    }
2728
+					}
2729 2729
 
2730
-                    // save the questions asked id
2731
-                    $questions_asked_csv = implode(',', $questions_asked);
2732
-                    update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2730
+					// save the questions asked id
2731
+					$questions_asked_csv = implode(',', $questions_asked);
2732
+					update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2733 2733
 
2734
-                }
2735
-            }
2736
-        }
2734
+				}
2735
+			}
2736
+		}
2737 2737
 
2738
-        /**
2739
-         * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2740
-         *
2741
-         * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2742
-         * @since 1.8.0
2743
-         */
2738
+		/**
2739
+		 * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2740
+		 *
2741
+		 * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2742
+		 * @since 1.8.0
2743
+		 */
2744 2744
 		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2745 2745
 
2746 2746
 	} // End lesson_quiz_questions()
@@ -2844,7 +2844,7 @@  discard block
 block discarded – undo
2844 2844
  			// Display Image Placeholder if none
2845 2845
 			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2846 2846
 
2847
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2847
+				$img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2848 2848
 
2849 2849
 			} // End If Statement
2850 2850
 
@@ -2860,401 +2860,401 @@  discard block
 block discarded – undo
2860 2860
 	 * Returns the the lesson excerpt.
2861 2861
 	 *
2862 2862
 	 * @param WP_Post $lesson
2863
-     * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2863
+	 * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2864 2864
 	 * @return string
2865 2865
 	 */
2866 2866
 	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2867 2867
 		$html = '';
2868 2868
 		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2869 2869
 
2870
-            $excerpt =  $lesson->post_excerpt;
2870
+			$excerpt =  $lesson->post_excerpt;
2871 2871
 
2872
-            // if $add_p_tags true wrap with <p> else return the excerpt as is
2873
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2872
+			// if $add_p_tags true wrap with <p> else return the excerpt as is
2873
+			$html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2874 2874
 
2875 2875
 		}
2876 2876
 		return apply_filters( 'sensei_lesson_excerpt', $html );
2877 2877
 
2878 2878
 	} // End lesson_excerpt()
2879 2879
 
2880
-    /**
2881
-     * Returns the course for a given lesson
2882
-     *
2883
-     * @since 1.7.4
2884
-     * @access public
2885
-     *
2886
-     * @param int $lesson_id
2887
-     * @return int|bool $course_id or bool when nothing is found.
2888
-     */
2889
-     public function get_course_id( $lesson_id ){
2890
-
2891
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2892
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2893
-             return false;
2894
-         }
2895
-
2896
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2897
-
2898
-         // make sure the course id is valid
2899
-         if( empty( $lesson_course_id )
2900
-             || is_array( $lesson_course_id )
2901
-             || intval( $lesson_course_id ) < 1
2902
-             || 'course' != get_post_type( $lesson_course_id ) ){
2903
-
2904
-             return false;
2905
-
2906
-         }
2907
-
2908
-         return $lesson_course_id;
2909
-
2910
-     }// en get_course_id
2911
-
2912
-    /**
2913
-     * Add the admin all lessons screen edit options.
2914
-     *
2915
-     * The fields in this function work for both quick and bulk edit. The ID attributes is used
2916
-     * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2917
-     * name attribute is will be used by the quick edit and submitted via standard POST. This
2918
-     * will use this classes save_post_meta function to save the new field data.
2919
-     *
2920
-     * @hooked quick_edit_custom_box
2921
-     * @hooked bulk_edit_custom_box
2922
-     *
2923
-     * @since 1.8.0
2924
-     *
2925
-     * @param string $column_name
2926
-     * @param string $post_type
2927
-     * @return void
2928
-     */
2929
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2930
-
2931
-        // only show these options ont he lesson post type edit screen
2932
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2933
-            return;
2934
-        }
2935
-
2936
-        ?>
2880
+	/**
2881
+	 * Returns the course for a given lesson
2882
+	 *
2883
+	 * @since 1.7.4
2884
+	 * @access public
2885
+	 *
2886
+	 * @param int $lesson_id
2887
+	 * @return int|bool $course_id or bool when nothing is found.
2888
+	 */
2889
+	 public function get_course_id( $lesson_id ){
2890
+
2891
+		 if( ! isset( $lesson_id ) || empty( $lesson_id )
2892
+		 ||  'lesson' != get_post_type( $lesson_id ) ){
2893
+			 return false;
2894
+		 }
2895
+
2896
+		 $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2897
+
2898
+		 // make sure the course id is valid
2899
+		 if( empty( $lesson_course_id )
2900
+			 || is_array( $lesson_course_id )
2901
+			 || intval( $lesson_course_id ) < 1
2902
+			 || 'course' != get_post_type( $lesson_course_id ) ){
2903
+
2904
+			 return false;
2905
+
2906
+		 }
2907
+
2908
+		 return $lesson_course_id;
2909
+
2910
+	 }// en get_course_id
2911
+
2912
+	/**
2913
+	 * Add the admin all lessons screen edit options.
2914
+	 *
2915
+	 * The fields in this function work for both quick and bulk edit. The ID attributes is used
2916
+	 * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2917
+	 * name attribute is will be used by the quick edit and submitted via standard POST. This
2918
+	 * will use this classes save_post_meta function to save the new field data.
2919
+	 *
2920
+	 * @hooked quick_edit_custom_box
2921
+	 * @hooked bulk_edit_custom_box
2922
+	 *
2923
+	 * @since 1.8.0
2924
+	 *
2925
+	 * @param string $column_name
2926
+	 * @param string $post_type
2927
+	 * @return void
2928
+	 */
2929
+	public function all_lessons_edit_fields( $column_name, $post_type ) {
2930
+
2931
+		// only show these options ont he lesson post type edit screen
2932
+		if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2933
+			return;
2934
+		}
2935
+
2936
+		?>
2937 2937
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2938 2938
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2939 2939
                     <?php
2940
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2941
-                    // create a nonce field to be  used as a security measure when saving the data
2942
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2943
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2944
-
2945
-                    // unchanged option - we need this in because
2946
-                    // the default option in bulk edit should not be empty. If it is
2947
-                    // the user will erase data they didn't want to touch.
2948
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2949
-
2950
-                    //
2951
-                    //course selection
2952
-                    //
2953
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2954
-                    $course_options = array();
2955
-                    if ( count( $courses ) > 0 ) {
2956
-                        foreach ($courses as $course ){
2957
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
2958
-                        }
2959
-                    }
2960
-                    //pre-append the no change option
2961
-                    $course_options['-1']=  $no_change_text;
2962
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2963
-                    $course_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2964
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2965
-
2966
-                    //
2967
-                    // lesson complexity selection
2968
-                    //
2969
-                    $lesson_complexities =  $this->lesson_complexities();
2970
-                    //pre-append the no change option
2971
-                    $lesson_complexities['-1']=  $no_change_text;
2972
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2973
-                    $complexity_filed =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2974
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2975
-
2976
-                    ?>
2940
+					echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2941
+					// create a nonce field to be  used as a security measure when saving the data
2942
+					wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2943
+					wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2944
+
2945
+					// unchanged option - we need this in because
2946
+					// the default option in bulk edit should not be empty. If it is
2947
+					// the user will erase data they didn't want to touch.
2948
+					$no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2949
+
2950
+					//
2951
+					//course selection
2952
+					//
2953
+					$courses =  WooThemes_Sensei_Course::get_all_courses();
2954
+					$course_options = array();
2955
+					if ( count( $courses ) > 0 ) {
2956
+						foreach ($courses as $course ){
2957
+							$course_options[ $course->ID ] = get_the_title( $course->ID );
2958
+						}
2959
+					}
2960
+					//pre-append the no change option
2961
+					$course_options['-1']=  $no_change_text;
2962
+					$course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2963
+					$course_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2964
+					echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2965
+
2966
+					//
2967
+					// lesson complexity selection
2968
+					//
2969
+					$lesson_complexities =  $this->lesson_complexities();
2970
+					//pre-append the no change option
2971
+					$lesson_complexities['-1']=  $no_change_text;
2972
+					$complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2973
+					$complexity_filed =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2974
+					echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2975
+
2976
+					?>
2977 2977
 
2978 2978
                     <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4>
2979 2979
 
2980 2980
                     <?php
2981 2981
 
2982
-                    //
2983
-                    // Lesson require pass to complete
2984
-                    //
2985
-                    $pass_required_options = array(
2986
-                        '-1' => $no_change_text,
2987
-                         '0' => __('No','woothemes'),
2988
-                         '1' => __('Yes','woothemes'),
2989
-                    );
2990
-
2991
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
2992
-                                                                'id'=> 'sensei-edit-lesson-pass-required',
2993
-                                                                'class'=>' '   );
2994
-                    $require_pass_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
2995
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
2996
-
2997
-                    //
2998
-                    // Quiz pass percentage
2999
-                    //
3000
-                    $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3001
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3002
-
3003
-                    //
3004
-                    // Enable quiz reset button
3005
-                    //
3006
-                    $quiz_reset_select__options = array(
3007
-                        '-1' => $no_change_text,
3008
-                        '0' => __('No','woothemes'),
3009
-                        '1' => __('Yes','woothemes'),
3010
-                    );
3011
-                    $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3012
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3013
-                    $quiz_reset_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3014
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3015
-
3016
-                    ?>
2982
+					//
2983
+					// Lesson require pass to complete
2984
+					//
2985
+					$pass_required_options = array(
2986
+						'-1' => $no_change_text,
2987
+						 '0' => __('No','woothemes'),
2988
+						 '1' => __('Yes','woothemes'),
2989
+					);
2990
+
2991
+					$pass_required_select_attributes = array( 'name'=> 'pass_required',
2992
+																'id'=> 'sensei-edit-lesson-pass-required',
2993
+																'class'=>' '   );
2994
+					$require_pass_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
2995
+					echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
2996
+
2997
+					//
2998
+					// Quiz pass percentage
2999
+					//
3000
+					$quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3001
+					echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3002
+
3003
+					//
3004
+					// Enable quiz reset button
3005
+					//
3006
+					$quiz_reset_select__options = array(
3007
+						'-1' => $no_change_text,
3008
+						'0' => __('No','woothemes'),
3009
+						'1' => __('Yes','woothemes'),
3010
+					);
3011
+					$quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3012
+					$quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3013
+					$quiz_reset_field =  WooThemes_Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3014
+					echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3015
+
3016
+					?>
3017 3017
             </div>
3018 3018
         </fieldset>
3019 3019
     <?php
3020
-    }// all_lessons_edit_fields
3021
-
3022
-    /**
3023
-     * Create the html for the edit field
3024
-     *
3025
-     * Wraps the passed in field and title combination with the correct html.
3026
-     *
3027
-     * @since 1.8.0
3028
-     *
3029
-     * @param string $title that will stand to the left of the field.
3030
-     * @param string $field type markup for the field that must be wrapped.
3031
-     * @return string $field_html
3032
-     */
3033
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3034
-
3035
-        $html = '';
3036
-        $html = '<div class="inline-edit-group" >';
3037
-        $html .=  '<span class="title">'. $title .'</span> ';
3038
-        $html .= '<span class="input-text-wrap">';
3039
-        $html .= $field;
3040
-        $html .= '</span>';
3041
-        $html .= '</label></div>';
3042
-
3043
-        return $html ;
3044
-
3045
-    }//end generate_all_lessons_edit_field
3046
-
3047
-    /**
3048
-     * Respond to the ajax call from the bulk edit save function. This comes
3049
-     * from the admin all lesson screen.
3050
-     *
3051
-     * @since 1.8.0
3052
-     * @return void
3053
-     */
3054
-    function save_all_lessons_edit_fields() {
3055
-
3056
-        // verify all the data before attempting to save
3057
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3058
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3059
-            die();
3060
-        }
3061
-
3062
-        // get our variables
3063
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3064
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3065
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3066
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3067
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3068
-        // store the values for all selected posts
3069
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3070
-
3071
-            // get the quiz id needed for the quiz meta
3072
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3073
-
3074
-            // do not save the items if the value is -1 as this
3075
-            // means it was not changed
3076
-
3077
-            // update lesson course
3078
-            if( -1 != $new_course ){
3079
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3080
-            }
3081
-            // update lesson complexity
3082
-            if( -1 != $new_complexity ){
3083
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3084
-            }
3085
-
3086
-            // Quiz Related settings
3087
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3088
-
3089
-                // update pass required
3090
-                if (-1 != $new_pass_required) {
3091
-
3092
-                    $checked = $new_pass_required  ? 'on' : '';
3093
-                    update_post_meta($quiz_id, '_pass_required', $checked);
3094
-                    unset( $checked );
3095
-                }
3020
+	}// all_lessons_edit_fields
3021
+
3022
+	/**
3023
+	 * Create the html for the edit field
3024
+	 *
3025
+	 * Wraps the passed in field and title combination with the correct html.
3026
+	 *
3027
+	 * @since 1.8.0
3028
+	 *
3029
+	 * @param string $title that will stand to the left of the field.
3030
+	 * @param string $field type markup for the field that must be wrapped.
3031
+	 * @return string $field_html
3032
+	 */
3033
+	public function generate_all_lessons_edit_field( $title  ,$field ){
3034
+
3035
+		$html = '';
3036
+		$html = '<div class="inline-edit-group" >';
3037
+		$html .=  '<span class="title">'. $title .'</span> ';
3038
+		$html .= '<span class="input-text-wrap">';
3039
+		$html .= $field;
3040
+		$html .= '</span>';
3041
+		$html .= '</label></div>';
3042
+
3043
+		return $html ;
3044
+
3045
+	}//end generate_all_lessons_edit_field
3046
+
3047
+	/**
3048
+	 * Respond to the ajax call from the bulk edit save function. This comes
3049
+	 * from the admin all lesson screen.
3050
+	 *
3051
+	 * @since 1.8.0
3052
+	 * @return void
3053
+	 */
3054
+	function save_all_lessons_edit_fields() {
3096 3055
 
3097
-                // update pass percentage
3098
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3056
+		// verify all the data before attempting to save
3057
+		if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3058
+			||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3059
+			die();
3060
+		}
3099 3061
 
3100
-                        update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3062
+		// get our variables
3063
+		$new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3064
+		$new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3065
+		$new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3066
+		$new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3067
+		$new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3068
+		// store the values for all selected posts
3069
+		foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3101 3070
 
3102
-                }
3071
+			// get the quiz id needed for the quiz meta
3072
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3103 3073
 
3104
-                //
3105
-                // update enable quiz reset
3106
-                //
3107
-                if (-1 != $new_enable_quiz_reset ) {
3074
+			// do not save the items if the value is -1 as this
3075
+			// means it was not changed
3108 3076
 
3109
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3110
-                    update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3111
-                    unset( $checked );
3077
+			// update lesson course
3078
+			if( -1 != $new_course ){
3079
+				update_post_meta( $lesson_id, '_lesson_course', $new_course );
3080
+			}
3081
+			// update lesson complexity
3082
+			if( -1 != $new_complexity ){
3083
+				update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3084
+			}
3112 3085
 
3113
-                }
3086
+			// Quiz Related settings
3087
+			if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3114 3088
 
3089
+				// update pass required
3090
+				if (-1 != $new_pass_required) {
3115 3091
 
3116
-            } // end if quiz
3092
+					$checked = $new_pass_required  ? 'on' : '';
3093
+					update_post_meta($quiz_id, '_pass_required', $checked);
3094
+					unset( $checked );
3095
+				}
3117 3096
 
3118
-        }// end for each
3097
+				// update pass percentage
3098
+				if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3119 3099
 
3120
-        die();
3100
+						update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3121 3101
 
3122
-    } // end save_all_lessons_edit_fields
3102
+				}
3123 3103
 
3124
-    /**
3125
-     * Loading the quick edit fields defaults.
3126
-     *
3127
-     * This function will localise the default values along with the script that will
3128
-     * add these values to the inputs.
3129
-     *
3130
-     * NOTE: this function runs for each row in the edit column
3131
-     *
3132
-     * @since 1.8.0
3133
-     * @return void
3134
-     */
3135
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3104
+				//
3105
+				// update enable quiz reset
3106
+				//
3107
+				if (-1 != $new_enable_quiz_reset ) {
3136 3108
 
3137
-        if( 'lesson-course' != $column_name ){
3138
-            return;
3139
-        }
3140
-        // load the script
3141
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3142
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3109
+					$checked = $new_enable_quiz_reset ? 'on' : ''  ;
3110
+					update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3111
+					unset( $checked );
3143 3112
 
3144
-        // setup the values for all meta fields
3145
-        $data = array();
3146
-        foreach( $this->meta_fields as $field ){
3113
+				}
3147 3114
 
3148
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3149 3115
 
3150
-        }
3151
-        // add quiz meta fields
3152
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3153
-        foreach( Sensei()->quiz->meta_fields as $field ){
3116
+			} // end if quiz
3154 3117
 
3155
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3118
+		}// end for each
3156 3119
 
3157
-        }
3120
+		die();
3158 3121
 
3159
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3122
+	} // end save_all_lessons_edit_fields
3160 3123
 
3161
-    }// end quick edit admin defaults
3124
+	/**
3125
+	 * Loading the quick edit fields defaults.
3126
+	 *
3127
+	 * This function will localise the default values along with the script that will
3128
+	 * add these values to the inputs.
3129
+	 *
3130
+	 * NOTE: this function runs for each row in the edit column
3131
+	 *
3132
+	 * @since 1.8.0
3133
+	 * @return void
3134
+	 */
3135
+	public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3162 3136
 
3163
-    /**
3164
-     * Filter the classes for lessons on the single course page.
3165
-     *
3166
-     * Adds the nesecary classes depending on the user data
3167
-     *
3168
-     * @since 1.9.0
3169
-     * @param array $classes
3170
-     * @return array $classes
3171
-     */
3172
-    public static function single_course_lessons_classes( $classes ){
3137
+		if( 'lesson-course' != $column_name ){
3138
+			return;
3139
+		}
3140
+		// load the script
3141
+		$suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3142
+		wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3143
+
3144
+		// setup the values for all meta fields
3145
+		$data = array();
3146
+		foreach( $this->meta_fields as $field ){
3147
+
3148
+			$data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3149
+
3150
+		}
3151
+		// add quiz meta fields
3152
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3153
+		foreach( Sensei()->quiz->meta_fields as $field ){
3154
+
3155
+			$data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3156
+
3157
+		}
3158
+
3159
+		wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3160
+
3161
+	}// end quick edit admin defaults
3162
+
3163
+	/**
3164
+	 * Filter the classes for lessons on the single course page.
3165
+	 *
3166
+	 * Adds the nesecary classes depending on the user data
3167
+	 *
3168
+	 * @since 1.9.0
3169
+	 * @param array $classes
3170
+	 * @return array $classes
3171
+	 */
3172
+	public static function single_course_lessons_classes( $classes ){
3173 3173
 
3174
-        if(  is_singular('course') ){
3174
+		if(  is_singular('course') ){
3175 3175
 
3176
-            global $post;
3177
-            $course_id = $post->ID;
3176
+			global $post;
3177
+			$course_id = $post->ID;
3178 3178
 
3179
-            $lesson_classes = array( 'course', 'post' );
3180
-            if ( is_user_logged_in() ) {
3179
+			$lesson_classes = array( 'course', 'post' );
3180
+			if ( is_user_logged_in() ) {
3181 3181
 
3182
-                // Check if Lesson is complete
3183
-                $single_lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3184
-                if ( $single_lesson_complete ) {
3182
+				// Check if Lesson is complete
3183
+				$single_lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3184
+				if ( $single_lesson_complete ) {
3185 3185
 
3186
-                    $lesson_classes[] = 'lesson-completed';
3186
+					$lesson_classes[] = 'lesson-completed';
3187 3187
 
3188
-                } // End If Statement
3188
+				} // End If Statement
3189 3189
 
3190
-            } // End If Statement
3190
+			} // End If Statement
3191 3191
 
3192
-            $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3193
-            if (  WooThemes_Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3192
+			$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3193
+			if (  WooThemes_Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3194 3194
 
3195
-                $lesson_classes[] = 'lesson-preview';
3195
+				$lesson_classes[] = 'lesson-preview';
3196 3196
 
3197
-            }
3197
+			}
3198 3198
 
3199
-            $classes = array_merge( $classes, $lesson_classes  );
3199
+			$classes = array_merge( $classes, $lesson_classes  );
3200 3200
 
3201
-        }
3201
+		}
3202 3202
 
3203
-        return $classes;
3203
+		return $classes;
3204 3204
 
3205
-    }// end single_course_lessons_classes
3205
+	}// end single_course_lessons_classes
3206 3206
 
3207
-    /**
3208
-     * Output the lesson meta for the given lesson
3209
-     *
3210
-     * @since 1.9.0
3211
-     * @param $lesson_id
3212
-     */
3213
-    public static function the_lesson_meta( $lesson_id ){
3207
+	/**
3208
+	 * Output the lesson meta for the given lesson
3209
+	 *
3210
+	 * @since 1.9.0
3211
+	 * @param $lesson_id
3212
+	 */
3213
+	public static function the_lesson_meta( $lesson_id ){
3214 3214
 
3215
-        global $wp_query;
3216
-        $loop_lesson_number = $wp_query->current_post + 1;
3215
+		global $wp_query;
3216
+		$loop_lesson_number = $wp_query->current_post + 1;
3217 3217
 
3218
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3219
-        $single_lesson_complete = false;
3220
-        $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3218
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
3219
+		$single_lesson_complete = false;
3220
+		$is_user_taking_course = WooThemes_Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3221 3221
 
3222
-        // Get Lesson data
3223
-        $complexity_array = Sensei()->lesson->lesson_complexities();
3222
+		// Get Lesson data
3223
+		$complexity_array = Sensei()->lesson->lesson_complexities();
3224 3224
 
3225
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3226
-        if ( '' != $lesson_complexity ) {
3225
+		$lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3226
+		if ( '' != $lesson_complexity ) {
3227 3227
 
3228
-            $lesson_complexity = $complexity_array[$lesson_complexity];
3228
+			$lesson_complexity = $complexity_array[$lesson_complexity];
3229 3229
 
3230
-        }
3231
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3232
-        $is_preview = WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id);
3233
-        $preview_label = '';
3234
-        if ( $is_preview && !$is_user_taking_course ) {
3230
+		}
3231
+		$user_info = get_userdata( absint( get_post()->post_author ) );
3232
+		$is_preview = WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id);
3233
+		$preview_label = '';
3234
+		if ( $is_preview && !$is_user_taking_course ) {
3235 3235
 
3236
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3237
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3236
+			$preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3237
+			$preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3238 3238
 
3239
-        }
3239
+		}
3240 3240
 
3241 3241
 
3242
-        $count_markup= '';
3243
-        /**
3244
-         * Filter for if you want the $lesson_count to show next to the lesson.
3245
-         *
3246
-         * @since 1.0
3247
-         * @param bool default false.
3248
-         */
3249
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3242
+		$count_markup= '';
3243
+		/**
3244
+		 * Filter for if you want the $lesson_count to show next to the lesson.
3245
+		 *
3246
+		 * @since 1.0
3247
+		 * @param bool default false.
3248
+		 */
3249
+		if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3250 3250
 
3251
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3251
+			$count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3252 3252
 
3253
-        }
3253
+		}
3254 3254
 
3255
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3255
+		$heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3256 3256
 
3257
-        ?>
3257
+		?>
3258 3258
         <header>
3259 3259
             <h2>
3260 3260
                 <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
@@ -3267,40 +3267,40 @@  discard block
 block discarded – undo
3267 3267
 
3268 3268
                 <?php
3269 3269
 
3270
-                $meta_html = '';
3271
-                $user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3270
+				$meta_html = '';
3271
+				$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3272 3272
 
3273
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3274
-                if ( '' != $lesson_length ) {
3273
+				$lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3274
+				if ( '' != $lesson_length ) {
3275 3275
 
3276
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3276
+					$meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3277 3277
 
3278
-                }
3278
+				}
3279 3279
 
3280
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3280
+				if ( Sensei()->settings->get( 'lesson_author' ) ) {
3281 3281
 
3282
-                    $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>';
3282
+					$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>';
3283 3283
 
3284
-                } // End If Statement
3285
-                if ( '' != $lesson_complexity ) {
3284
+				} // End If Statement
3285
+				if ( '' != $lesson_complexity ) {
3286 3286
 
3287
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3287
+					$meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3288 3288
 
3289
-                }
3289
+				}
3290 3290
 
3291
-                if ( $single_lesson_complete ) {
3291
+				if ( $single_lesson_complete ) {
3292 3292
 
3293
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3293
+					$meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3294 3294
 
3295
-                } elseif ( $user_lesson_status ) {
3295
+				} elseif ( $user_lesson_status ) {
3296 3296
 
3297
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3297
+					$meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3298 3298
 
3299
-                } // End If Statement
3299
+				} // End If Statement
3300 3300
 
3301
-                echo $meta_html;
3301
+				echo $meta_html;
3302 3302
 
3303
-                ?>
3303
+				?>
3304 3304
 
3305 3305
             </p> <!-- lesson meta -->
3306 3306
 
@@ -3308,132 +3308,132 @@  discard block
 block discarded – undo
3308 3308
 
3309 3309
     <?php
3310 3310
 
3311
-    } // end the_lesson_meta
3311
+	} // end the_lesson_meta
3312 3312
 
3313
-    /**
3314
-     * Output the lessons thumbnail
3315
-     *
3316
-     * 1.9.0
3317
-     *
3318
-     * @param $lesson_id
3319
-     */
3320
-    public static function the_lesson_thumbnail( $lesson_id ){
3313
+	/**
3314
+	 * Output the lessons thumbnail
3315
+	 *
3316
+	 * 1.9.0
3317
+	 *
3318
+	 * @param $lesson_id
3319
+	 */
3320
+	public static function the_lesson_thumbnail( $lesson_id ){
3321 3321
 
3322
-        if( empty( $lesson_id ) ){
3322
+		if( empty( $lesson_id ) ){
3323 3323
 
3324
-            $lesson_id = get_the_ID();
3324
+			$lesson_id = get_the_ID();
3325 3325
 
3326
-        }
3326
+		}
3327 3327
 
3328
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3329
-            return;
3330
-        }
3328
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3329
+			return;
3330
+		}
3331 3331
 
3332
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3333
-    }
3332
+		echo Sensei()->lesson->lesson_image( $lesson_id );
3333
+	}
3334 3334
 
3335 3335
 
3336
-    /**
3337
-     * Alter the sensei lesson excerpt.
3338
-     *
3339
-     * @since 1.9.0
3340
-     * @param string $excerpt
3341
-     * @return string $excerpt
3342
-     */
3343
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3336
+	/**
3337
+	 * Alter the sensei lesson excerpt.
3338
+	 *
3339
+	 * @since 1.9.0
3340
+	 * @param string $excerpt
3341
+	 * @return string $excerpt
3342
+	 */
3343
+	public static function alter_the_lesson_excerpt( $excerpt ) {
3344 3344
 
3345
-        if ('lesson' == get_post_type(get_the_ID())){
3345
+		if ('lesson' == get_post_type(get_the_ID())){
3346 3346
 
3347
-            // remove this hooks to avoid an infinite loop.
3348
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3347
+			// remove this hooks to avoid an infinite loop.
3348
+			remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3349 3349
 
3350
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3351
-        }
3350
+			return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3351
+		}
3352 3352
 
3353
-        return $excerpt;
3353
+		return $excerpt;
3354 3354
 
3355
-    }// end the_lesson_excerpt
3355
+	}// end the_lesson_excerpt
3356 3356
 
3357
-    /**
3358
-     * Returns the lesson prerequisite for the given lesson id.
3359
-     *
3360
-     * @since 1.9.0
3361
-     *
3362
-     * @param $current_lesson_id
3363
-     * @return mixed | bool | int $prerequisite_lesson_id or false
3364
-     */
3365
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3357
+	/**
3358
+	 * Returns the lesson prerequisite for the given lesson id.
3359
+	 *
3360
+	 * @since 1.9.0
3361
+	 *
3362
+	 * @param $current_lesson_id
3363
+	 * @return mixed | bool | int $prerequisite_lesson_id or false
3364
+	 */
3365
+	public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3366 3366
 
3367
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3367
+		$prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3368 3368
 
3369
-        // set ti to false if not a valid prerequisite lesson id
3370
-        if(  empty( $prerequisite_lesson_id )
3371
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3372
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3369
+		// set ti to false if not a valid prerequisite lesson id
3370
+		if(  empty( $prerequisite_lesson_id )
3371
+			|| 'lesson' != get_post_type( $prerequisite_lesson_id )
3372
+			|| $prerequisite_lesson_id == $current_lesson_id  ) {
3373 3373
 
3374
-            $prerequisite_lesson_id = false;
3374
+			$prerequisite_lesson_id = false;
3375 3375
 
3376
-        }
3376
+		}
3377 3377
 
3378
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3378
+		return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3379 3379
 
3380
-    }
3380
+	}
3381 3381
 
3382
-    /**
3383
-     * This function requires that you pass in the lesson you would like to check for
3384
-     * a pre-requisite and not the pre-requisite. It will check if the
3385
-     * lesson has a pre-requiste and then check if it is completed.
3386
-     *
3387
-     * @since 1.9.0
3388
-     *
3389
-     * @param $lesson_id
3390
-     * @param $user_id
3391
-     * @return bool
3392
-     */
3393
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3382
+	/**
3383
+	 * This function requires that you pass in the lesson you would like to check for
3384
+	 * a pre-requisite and not the pre-requisite. It will check if the
3385
+	 * lesson has a pre-requiste and then check if it is completed.
3386
+	 *
3387
+	 * @since 1.9.0
3388
+	 *
3389
+	 * @param $lesson_id
3390
+	 * @param $user_id
3391
+	 * @return bool
3392
+	 */
3393
+	public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3394 3394
 
3395
-        if( empty( $lesson_id ) || empty( $user_id )
3396
-        || 'lesson' != get_post_type( $lesson_id )
3397
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3395
+		if( empty( $lesson_id ) || empty( $user_id )
3396
+		|| 'lesson' != get_post_type( $lesson_id )
3397
+		||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3398 3398
 
3399
-            return false;
3399
+			return false;
3400 3400
 
3401
-        }
3401
+		}
3402 3402
 
3403
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3403
+		$pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3404 3404
 
3405
-        // not a valid pre-requisite so pre-requisite is completed
3406
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3407
-            || ! is_numeric( $pre_requisite_id ) ){
3405
+		// not a valid pre-requisite so pre-requisite is completed
3406
+		if( 'lesson' != get_post_type( $pre_requisite_id )
3407
+			|| ! is_numeric( $pre_requisite_id ) ){
3408 3408
 
3409
-            return true;
3409
+			return true;
3410 3410
 
3411
-        }
3411
+		}
3412 3412
 
3413
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3413
+		return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3414 3414
 
3415
-    }// end is_prerequisite_complete
3415
+	}// end is_prerequisite_complete
3416 3416
 
3417
-    /**
3418
-     * Show the user not taking course message if it is the case
3419
-     *
3420
-     * @since 1.9.0
3421
-     */
3422
-    public  static function user_not_taking_course_message(){
3417
+	/**
3418
+	 * Show the user not taking course message if it is the case
3419
+	 *
3420
+	 * @since 1.9.0
3421
+	 */
3422
+	public  static function user_not_taking_course_message(){
3423 3423
 
3424
-        $lesson_id = get_the_ID();
3424
+		$lesson_id = get_the_ID();
3425 3425
 
3426
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3427
-            return;
3428
-        }
3426
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3427
+			return;
3428
+		}
3429 3429
 
3430
-        $is_preview = WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id );
3431
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3432
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3433
-        $user_taking_course = WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3430
+		$is_preview = WooThemes_Sensei_Utils::is_preview_lesson( $lesson_id );
3431
+		$pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3432
+		$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3433
+		$user_taking_course = WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3434 3434
 
3435
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3436
-            ?>
3435
+		if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3436
+			?>
3437 3437
 
3438 3438
             <div class="sensei-message alert">
3439 3439
                 <?php echo Sensei()->permissions_message['message']; ?>
@@ -3441,46 +3441,46 @@  discard block
 block discarded – undo
3441 3441
 
3442 3442
             <?php
3443 3443
 
3444
-        }// end if
3444
+		}// end if
3445 3445
 
3446
-    } // end user_not_taking_course_message
3446
+	} // end user_not_taking_course_message
3447 3447
 
3448
-    /**
3449
-     * Outputs the lessons course signup lingk
3450
-     *
3451
-     * This hook runs inside the single lesson page.
3452
-     *
3453
-     * @since 1.9.0
3454
-     */
3455
-    public static function course_signup_link( ){
3448
+	/**
3449
+	 * Outputs the lessons course signup lingk
3450
+	 *
3451
+	 * This hook runs inside the single lesson page.
3452
+	 *
3453
+	 * @since 1.9.0
3454
+	 */
3455
+	public static function course_signup_link( ){
3456 3456
 
3457
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3457
+		$course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3458 3458
 
3459
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3459
+		if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3460 3460
 
3461
-            return;
3461
+			return;
3462 3462
 
3463
-        }
3464
-        ?>
3463
+		}
3464
+		?>
3465 3465
 
3466 3466
         <section class="course-signup lesson-meta">
3467 3467
 
3468 3468
             <?php
3469
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3469
+			$wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3470 3470
 
3471
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3471
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3472 3472
 
3473
-                global $current_user;
3474
-                if( is_user_logged_in() ) {
3475
-                    wp_get_current_user();
3473
+				global $current_user;
3474
+				if( is_user_logged_in() ) {
3475
+					wp_get_current_user();
3476 3476
 
3477
-                    $course_purchased = WooThemes_Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3477
+					$course_purchased = WooThemes_Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3478 3478
 
3479
-                    if( $course_purchased ) {
3479
+					if( $course_purchased ) {
3480 3480
 
3481
-                        $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3482
-                        $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3483
-                        ?>
3481
+						$prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3482
+						$course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3483
+						?>
3484 3484
                             <div class="sensei-message info">
3485 3485
 
3486 3486
                                 <?php  echo sprintf( __( 'Please complete %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); ?>
@@ -3492,14 +3492,14 @@  discard block
 block discarded – undo
3492 3492
                         <div class="sensei-message info">
3493 3493
 
3494 3494
                             <?php
3495
-                            $course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3496
-                                            . '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3497
-                                            . '">' . __( 'course', 'woothemes-sensei' )
3498
-                                            . '</a>';
3495
+							$course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3496
+											. '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3497
+											. '">' . __( 'course', 'woothemes-sensei' )
3498
+											. '</a>';
3499 3499
 
3500
-                            echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3500
+							echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3501 3501
 
3502
-                            ?>
3502
+							?>
3503 3503
 
3504 3504
                         </div>
3505 3505
                     <?php } ?>
@@ -3516,14 +3516,14 @@  discard block
 block discarded – undo
3516 3516
 
3517 3517
                 <div class="sensei-message info">
3518 3518
                     <?php
3519
-                    $course_link =  '<a href="'
3520
-                                        . esc_url( get_permalink( $course_id ) )
3521
-                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3522
-                                        . '">' . __( 'course', 'woothemes-sensei' )
3523
-                                    . '</a>';
3524
-
3525
-                    echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3526
-                    ?>
3519
+					$course_link =  '<a href="'
3520
+										. esc_url( get_permalink( $course_id ) )
3521
+										. '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3522
+										. '">' . __( 'course', 'woothemes-sensei' )
3523
+									. '</a>';
3524
+
3525
+					echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3526
+					?>
3527 3527
                 </div>
3528 3528
 
3529 3529
             <?php endif; ?>
@@ -3533,75 +3533,75 @@  discard block
 block discarded – undo
3533 3533
         </section>
3534 3534
 
3535 3535
         <?php
3536
-    }// end course_signup_link
3536
+	}// end course_signup_link
3537 3537
 
3538
-    /**
3539
-     * Show a message telling the user to complete the previous message if they haven't done so yet
3540
-     *
3541
-     * @since 1.9.0
3542
-     */
3543
-    public  static function prerequisite_complete_message(){
3538
+	/**
3539
+	 * Show a message telling the user to complete the previous message if they haven't done so yet
3540
+	 *
3541
+	 * @since 1.9.0
3542
+	 */
3543
+	public  static function prerequisite_complete_message(){
3544 3544
 
3545
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3546
-        $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3547
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3545
+		$lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3546
+		$lesson_has_pre_requisite = $lesson_prerequisite > 0;
3547
+		if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3548 3548
 
3549
-            $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>';
3550
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3549
+			$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>';
3550
+			echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3551 3551
 
3552
-        }
3552
+		}
3553 3553
 
3554
-    }
3554
+	}
3555 3555
 
3556
-    /**
3557
-     * Deprecate the sensei_lesson_archive_header hook but keep it
3558
-     * active for backwards compatibility.
3559
-     *
3560
-     * @deprecated since 1.9.0
3561
-     */
3562
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3556
+	/**
3557
+	 * Deprecate the sensei_lesson_archive_header hook but keep it
3558
+	 * active for backwards compatibility.
3559
+	 *
3560
+	 * @deprecated since 1.9.0
3561
+	 */
3562
+	public static function deprecate_sensei_lesson_archive_header_hook(){
3563 3563
 
3564
-        sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3564
+		sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3565 3565
 
3566
-    }
3566
+	}
3567 3567
 
3568
-    /**
3569
-     * Outputs the the lesson archive header.
3570
-     *
3571
-     * @since  1.9.0
3572
-     * @return void
3573
-     */
3574
-    public function the_archive_header( ) {
3568
+	/**
3569
+	 * Outputs the the lesson archive header.
3570
+	 *
3571
+	 * @since  1.9.0
3572
+	 * @return void
3573
+	 */
3574
+	public function the_archive_header( ) {
3575 3575
 
3576
-        $before_html = '<header class="archive-header"><h1>';
3577
-        $after_html = '</h1></header>';
3578
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3576
+		$before_html = '<header class="archive-header"><h1>';
3577
+		$after_html = '</h1></header>';
3578
+		$html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3579 3579
 
3580
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3580
+		echo apply_filters( 'sensei_lesson_archive_title', $html );
3581 3581
 
3582
-    } // sensei_course_archive_header()
3582
+	} // sensei_course_archive_header()
3583 3583
 
3584
-    /**
3585
-     * Output the title for the single lesson page
3586
-     *
3587
-     * @global $post
3588
-     * @since 1.9.0
3589
-     */
3590
-    public static function the_title(){
3584
+	/**
3585
+	 * Output the title for the single lesson page
3586
+	 *
3587
+	 * @global $post
3588
+	 * @since 1.9.0
3589
+	 */
3590
+	public static function the_title(){
3591 3591
 
3592
-        global $post;
3592
+		global $post;
3593 3593
 
3594
-        ?>
3594
+		?>
3595 3595
         <header>
3596 3596
 
3597 3597
             <h1>
3598 3598
 
3599 3599
                 <?php
3600
-                /**
3601
-                 * Filter documented in class-sensei-messages.php the_title
3602
-                 */
3603
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3604
-                ?>
3600
+				/**
3601
+				 * Filter documented in class-sensei-messages.php the_title
3602
+				 */
3603
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3604
+				?>
3605 3605
 
3606 3606
             </h1>
3607 3607
 
@@ -3609,68 +3609,68 @@  discard block
 block discarded – undo
3609 3609
 
3610 3610
         <?php
3611 3611
 
3612
-    }//the_title
3612
+	}//the_title
3613 3613
 
3614
-    /**
3615
-     * Flush the rewrite rules for a lesson post type
3616
-     *
3617
-     * @since 1.9.0
3618
-     *
3619
-     * @param $post_id
3620
-     */
3621
-    public static function flush_rewrite_rules( $post_id ){
3614
+	/**
3615
+	 * Flush the rewrite rules for a lesson post type
3616
+	 *
3617
+	 * @since 1.9.0
3618
+	 *
3619
+	 * @param $post_id
3620
+	 */
3621
+	public static function flush_rewrite_rules( $post_id ){
3622 3622
 
3623
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3623
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3624 3624
 
3625
-            return;
3625
+			return;
3626 3626
 
3627
-        }
3627
+		}
3628 3628
 
3629 3629
 
3630
-        if( 'lesson' == get_post_type( $post_id )  ){
3630
+		if( 'lesson' == get_post_type( $post_id )  ){
3631 3631
 
3632
-            Sensei()->initiate_rewrite_rules_flush();
3632
+			Sensei()->initiate_rewrite_rules_flush();
3633 3633
 
3634
-        }
3634
+		}
3635 3635
 
3636
-    }
3636
+	}
3637 3637
 
3638
-    /**
3639
-     * Output the quiz specific buttons and messaging on the single lesson page
3640
-     *
3641
-     *
3642
-     * @since 1.0.0 moved here from frontend class
3643
-     *
3644
-     * @param int $lesson_id
3645
-     * @param int $user_id
3646
-     */
3647
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3638
+	/**
3639
+	 * Output the quiz specific buttons and messaging on the single lesson page
3640
+	 *
3641
+	 *
3642
+	 * @since 1.0.0 moved here from frontend class
3643
+	 *
3644
+	 * @param int $lesson_id
3645
+	 * @param int $user_id
3646
+	 */
3647
+	public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3648 3648
 
3649 3649
 
3650
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3651
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3652
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3653
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3654
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3655
-        $has_user_completed_lesson = WooThemes_Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3656
-        $show_actions              = is_user_logged_in() ? true : false;
3650
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3651
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3652
+		$lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3653
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3654
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3655
+		$has_user_completed_lesson = WooThemes_Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3656
+		$show_actions              = is_user_logged_in() ? true : false;
3657 3657
 
3658
-        if( intval( $lesson_prerequisite ) > 0 ) {
3658
+		if( intval( $lesson_prerequisite ) > 0 ) {
3659 3659
 
3660
-            // If the user hasn't completed the prereq then hide the current actions
3661
-            $show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3660
+			// If the user hasn't completed the prereq then hide the current actions
3661
+			$show_actions = WooThemes_Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3662 3662
 
3663
-        }
3664
-        ?>
3663
+		}
3664
+		?>
3665 3665
 
3666 3666
         <footer>
3667 3667
 
3668 3668
             <?php
3669
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3669
+			if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3670 3670
 
3671
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3672
-                if( $has_quiz_questions ) {
3673
-                    ?>
3671
+				$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3672
+				if( $has_quiz_questions ) {
3673
+					?>
3674 3674
 
3675 3675
                     <p>
3676 3676
 
@@ -3685,87 +3685,87 @@  discard block
 block discarded – undo
3685 3685
                     </p>
3686 3686
 
3687 3687
                     <?php
3688
-                }
3688
+				}
3689 3689
 
3690
-            } // End If Statement
3690
+			} // End If Statement
3691 3691
 
3692
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3692
+			if ( $show_actions && ! $has_user_completed_lesson ) {
3693 3693
 
3694
-                sensei_complete_lesson_button();
3694
+				sensei_complete_lesson_button();
3695 3695
 
3696
-            } elseif( $show_actions ) {
3696
+			} elseif( $show_actions ) {
3697 3697
 
3698
-                sensei_reset_lesson_button();
3698
+				sensei_reset_lesson_button();
3699 3699
 
3700
-            } // End If Statement
3701
-            ?>
3700
+			} // End If Statement
3701
+			?>
3702 3702
 
3703 3703
         </footer>
3704 3704
 
3705 3705
         <?php
3706
-    } // End sensei_lesson_quiz_meta()
3706
+	} // End sensei_lesson_quiz_meta()
3707 3707
 
3708
-    /**
3709
-     * Show the lesson comments. This should be used in the loop.
3710
-     *
3711
-     * @since 1.9.0
3712
-     */
3713
-    public static function output_comments(){
3708
+	/**
3709
+	 * Show the lesson comments. This should be used in the loop.
3710
+	 *
3711
+	 * @since 1.9.0
3712
+	 */
3713
+	public static function output_comments(){
3714 3714
 
3715
-        if( ! is_user_logged_in() ){
3716
-            return;
3717
-        }
3715
+		if( ! is_user_logged_in() ){
3716
+			return;
3717
+		}
3718 3718
 
3719
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3720
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3721
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3722
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3719
+		$pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3720
+		$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3721
+		$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3722
+		$user_taking_course = Sensei_Utils::user_started_course($course_id );
3723 3723
 
3724
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3724
+		$lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3725 3725
 
3726
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3726
+		if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3727 3727
 
3728
-            comments_template();
3728
+			comments_template();
3729 3729
 
3730
-        } // End If Statement
3730
+		} // End If Statement
3731 3731
 
3732
-    } //output_comments
3732
+	} //output_comments
3733 3733
 
3734
-    /**
3735
-     * Display the leeson quiz status if it should be shown
3736
-     *
3737
-     * @param int $lesson_id defaults to the global lesson id
3738
-     * @param int $user_id defaults to the current user id
3739
-     *
3740
-     * @since 1.9.0
3741
-     */
3742
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3734
+	/**
3735
+	 * Display the leeson quiz status if it should be shown
3736
+	 *
3737
+	 * @param int $lesson_id defaults to the global lesson id
3738
+	 * @param int $user_id defaults to the current user id
3739
+	 *
3740
+	 * @since 1.9.0
3741
+	 */
3742
+	public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3743 3743
 
3744
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3745
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3746
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3747
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3748
-        $has_user_completed_lesson = WooThemes_Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3744
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3745
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3746
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3747
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3748
+		$has_user_completed_lesson = WooThemes_Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3749 3749
 
3750 3750
 
3751
-        if ( $quiz_id && is_user_logged_in()
3752
-            && WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3751
+		if ( $quiz_id && is_user_logged_in()
3752
+			&& WooThemes_Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3753 3753
 
3754
-            $no_quiz_count = 0;
3755
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3754
+			$no_quiz_count = 0;
3755
+			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3756 3756
 
3757
-            // Display lesson quiz status message
3758
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3759
-                $status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3760
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3761
-                if( $has_quiz_questions ) {
3762
-                   // echo $status['extra'];
3763
-                } // End If Statement
3764
-            } // End If Statement
3757
+			// Display lesson quiz status message
3758
+			if ( $has_user_completed_lesson || $has_quiz_questions ) {
3759
+				$status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3760
+				echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3761
+				if( $has_quiz_questions ) {
3762
+				   // echo $status['extra'];
3763
+				} // End If Statement
3764
+			} // End If Statement
3765 3765
 
3766
-        }
3766
+		}
3767 3767
 
3768
-    }
3768
+	}
3769 3769
 
3770 3770
 } // End Class
3771 3771
 
Please login to merge, or discard this patch.
includes/class-sensei-utils.php 1 patch
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
 	/**
48 48
 	 * Check if WooCommerce is active.
49
-     *
49
+	 *
50 50
 	 * @access public
51 51
 	 * @since  1.0.2
52 52
 	 * @static
@@ -191,15 +191,15 @@  discard block
 block discarded – undo
191 191
 			add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
192 192
 		}
193 193
 
194
-        //Get the comments
195
-        /**
196
-         * This filter runs inside Sensei_Utils::sensei_check_for_activity
197
-         *
198
-         * It runs while getting the comments for the given request.
199
-         *
200
-         * @param int|array $comments
201
-         */
202
-        $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
194
+		//Get the comments
195
+		/**
196
+		 * This filter runs inside Sensei_Utils::sensei_check_for_activity
197
+		 *
198
+		 * It runs while getting the comments for the given request.
199
+		 *
200
+		 * @param int|array $comments
201
+		 */
202
+		$comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
203 203
 
204 204
 		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
205 205
 		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
 		return $dataset_changes;
285 285
 	} // End sensei_delete_activities()
286 286
 
287
-    /**
288
-     * Delete all activity for specified user
289
-     * @access public
287
+	/**
288
+	 * Delete all activity for specified user
289
+	 * @access public
290 290
 	 * @since  1.5.0
291
-     * @param  integer $user_id User ID
292
-     * @return boolean
293
-     */
294
-    public static function delete_all_user_activity( $user_id = 0 ) {
291
+	 * @param  integer $user_id User ID
292
+	 * @return boolean
293
+	 */
294
+	public static function delete_all_user_activity( $user_id = 0 ) {
295 295
 
296
-    	$dataset_changes = false;
296
+		$dataset_changes = false;
297 297
 
298
-    	if( $user_id ) {
298
+		if( $user_id ) {
299 299
 
300 300
 			$activities = WooThemes_Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true );
301 301
 
@@ -366,11 +366,11 @@  discard block
 block discarded – undo
366 366
 			return false;
367 367
 
368 368
 		$orders = get_posts( array(
369
-		    'posts_per_page' => -1,
370
-		    'meta_key'    => '_customer_user',
371
-		    'meta_value'  => intval( $user_id ),
372
-		    'post_type'   => 'shop_order',
373
-		    'post_status' =>  array( 'wc-processing', 'wc-completed' ),
369
+			'posts_per_page' => -1,
370
+			'meta_key'    => '_customer_user',
371
+			'meta_value'  => intval( $user_id ),
372
+			'post_type'   => 'shop_order',
373
+			'post_status' =>  array( 'wc-processing', 'wc-completed' ),
374 374
 		) );
375 375
 
376 376
 		foreach ( $orders as $order_id ) {
@@ -511,72 +511,72 @@  discard block
 block discarded – undo
511 511
 
512 512
 		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
513 513
 
514
-        /**
515
-         * Filter the data array for the Sensei wp_handle_upload function call
516
-         *
517
-         * This filter was mainly added for Unit Testing purposes.
518
-         *
519
-         * @since 1.7.4
520
-         *
521
-         * @param array  $file_upload_args {
522
-         *      array of current values
523
-         *
524
-         *     @type string test_form set to false by default
525
-         * }
526
-         */
527
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
528
-
529
-        $file_return = wp_handle_upload( $file, $file_upload_args );
530
-
531
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
532
-            return false;
533
-        } else {
514
+		/**
515
+		 * Filter the data array for the Sensei wp_handle_upload function call
516
+		 *
517
+		 * This filter was mainly added for Unit Testing purposes.
518
+		 *
519
+		 * @since 1.7.4
520
+		 *
521
+		 * @param array  $file_upload_args {
522
+		 *      array of current values
523
+		 *
524
+		 *     @type string test_form set to false by default
525
+		 * }
526
+		 */
527
+		$file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
528
+
529
+		$file_return = wp_handle_upload( $file, $file_upload_args );
530
+
531
+		if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
532
+			return false;
533
+		} else {
534 534
 
535
-            $filename = $file_return['file'];
535
+			$filename = $file_return['file'];
536 536
 
537
-            $attachment = array(
538
-                'post_mime_type' => $file_return['type'],
539
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
540
-                'post_content' => '',
541
-                'post_status' => 'inherit',
542
-                'guid' => $file_return['url']
543
-            );
537
+			$attachment = array(
538
+				'post_mime_type' => $file_return['type'],
539
+				'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
540
+				'post_content' => '',
541
+				'post_status' => 'inherit',
542
+				'guid' => $file_return['url']
543
+			);
544 544
 
545
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
545
+			$attachment_id = wp_insert_attachment( $attachment, $filename );
546 546
 
547
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
548
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
549
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
547
+			require_once(ABSPATH . 'wp-admin/includes/image.php');
548
+			$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
549
+			wp_update_attachment_metadata( $attachment_id, $attachment_data );
550 550
 
551
-            if( 0 < intval( $attachment_id ) ) {
552
-            	return $attachment_id;
553
-            }
554
-        }
551
+			if( 0 < intval( $attachment_id ) ) {
552
+				return $attachment_id;
553
+			}
554
+		}
555 555
 
556
-        return false;
556
+		return false;
557 557
 	}
558 558
 
559 559
 	/**
560 560
 	 * Grade quiz automatically
561
-     *
562
-     * This function grades each question automatically if the are auto gradable.
563
-     * It store all question grades.
564
-     *
565
-     * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead
566
-     *
561
+	 *
562
+	 * This function grades each question automatically if the are auto gradable.
563
+	 * It store all question grades.
564
+	 *
565
+	 * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead
566
+	 *
567 567
 	 * @param  integer $quiz_id         ID of quiz
568 568
 	 * @param  array $submitted questions id ans answers {
569
-     *          @type int $question_id
570
-     *          @type mixed $answer
571
-     * }
569
+	 *          @type int $question_id
570
+	 *          @type mixed $answer
571
+	 * }
572 572
 	 * @param  integer $total_questions Total questions in quiz (not used)
573
-     * @param string $quiz_grade_type Optional defaults to auto
574
-     *
573
+	 * @param string $quiz_grade_type Optional defaults to auto
574
+	 *
575 575
 	 * @return int $quiz_grade total sum of all question grades
576 576
 	 */
577 577
 	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
578 578
 
579
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
579
+		return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
580 580
 
581 581
 	} // End sensei_grade_quiz_auto()
582 582
 
@@ -608,21 +608,21 @@  discard block
 block discarded – undo
608 608
 
609 609
 	/**
610 610
 	 * Grade question automatically
611
-     *
612
-     * This function checks the question typ and then grades it accordingly.
613
-     *
614
-     * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead
615
-     *
611
+	 *
612
+	 * This function checks the question typ and then grades it accordingly.
613
+	 *
614
+	 * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_question_auto instead
615
+	 *
616 616
 	 * @param integer $question_id
617
-     * @param string $question_type of the standard Sensei question types
617
+	 * @param string $question_type of the standard Sensei question types
618 618
 	 * @param string $answer
619
-     * @param int $user_id
620
-     *
619
+	 * @param int $user_id
620
+	 *
621 621
 	 * @return int $question_grade
622 622
 	 */
623 623
 	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
624 624
 
625
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
625
+	   return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
626 626
 
627 627
 	} // end sensei_grade_question_auto
628 628
 
@@ -668,35 +668,35 @@  discard block
 block discarded – undo
668 668
 	}
669 669
 
670 670
 
671
-    /**
672
-     * Alias to Woothemes_Sensei_Utils::sensei_start_lesson
673
-     *
674
-     * @since 1.7.4
675
-     *
676
-     * @param integer $user_id
677
-     * @param integer $lesson_id
678
-     * @param bool $complete
679
-     *
680
-     * @return mixed boolean or comment_ID
681
-     */
682
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
671
+	/**
672
+	 * Alias to Woothemes_Sensei_Utils::sensei_start_lesson
673
+	 *
674
+	 * @since 1.7.4
675
+	 *
676
+	 * @param integer $user_id
677
+	 * @param integer $lesson_id
678
+	 * @param bool $complete
679
+	 *
680
+	 * @return mixed boolean or comment_ID
681
+	 */
682
+	public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
683 683
 
684
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
684
+		return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
685 685
 
686
-    }// end user_start_lesson()
686
+	}// end user_start_lesson()
687 687
 
688 688
 	/**
689 689
 	 * Mark a lesson as started for user
690
-     *
691
-     * Will also start the lesson course for the user if the user hans't started taking it already.
692
-     *
693
-     * @since 1.6.0
694
-     *
690
+	 *
691
+	 * Will also start the lesson course for the user if the user hans't started taking it already.
692
+	 *
693
+	 * @since 1.6.0
694
+	 *
695 695
 	 * @param  integer $lesson_id ID of lesson
696 696
 	 * @param int| string $user_id default 0
697
-     * @param bool $complete default false
698
-     *
699
-     * @return mixed boolean or comment_ID
697
+	 * @param bool $complete default false
698
+	 *
699
+	 * @return mixed boolean or comment_ID
700 700
 	 */
701 701
 	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
702 702
 
@@ -742,21 +742,21 @@  discard block
 block discarded – undo
742 742
 				$metadata['start'] = current_time('mysql');
743 743
 				$activity_logged = WooThemes_Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
744 744
 
745
-            } else {
745
+			} else {
746 746
 
747
-                // if users is already taking the lesson  and the status changes to complete update it
748
-                $current_user_activity = get_comment($activity_logged);
749
-                if( $status=='complete' &&
750
-                    $status != $current_user_activity->comment_approved  ){
747
+				// if users is already taking the lesson  and the status changes to complete update it
748
+				$current_user_activity = get_comment($activity_logged);
749
+				if( $status=='complete' &&
750
+					$status != $current_user_activity->comment_approved  ){
751 751
 
752
-                    $comment = array();
753
-                    $comment['comment_ID'] = $activity_logged;
754
-                    $comment['comment_approved'] = $status;
755
-                    wp_update_comment( $comment );
752
+					$comment = array();
753
+					$comment['comment_ID'] = $activity_logged;
754
+					$comment['comment_approved'] = $status;
755
+					wp_update_comment( $comment );
756 756
 
757
-                }
757
+				}
758 758
 
759
-            }
759
+			}
760 760
 
761 761
 			if ( $complete ) {
762 762
 				// Run this *after* the lesson status has been created/updated
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
 	/**
903 903
 	 * Returns the answer_notes for a specific question and user, or sensei_user_answer entry
904 904
 	 *
905
-     * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead
905
+	 * @deprecated since 1.7.5 use Sensei()->quiz->get_user_question_feedback instead
906 906
 	 * @param mixed $question
907 907
 	 * @param int $user_id
908 908
 	 * @return string
@@ -1019,17 +1019,17 @@  discard block
 block discarded – undo
1019 1019
 	 * @return void
1020 1020
 	 */
1021 1021
 	public static function sort_array_by_key( $array, $key ) {
1022
-	    $sorter = array();
1023
-	    $ret = array();
1024
-	    reset( $array );
1025
-	    foreach ( $array as $ii => $va ) {
1026
-	        $sorter[$ii] = $va[$key];
1027
-	    } // End For Loop
1028
-	    asort( $sorter );
1029
-	    foreach ( $sorter as $ii => $va ) {
1030
-	        $ret[$ii] = $array[$ii];
1031
-	    } // End For Loop
1032
-	    $array = $ret;
1022
+		$sorter = array();
1023
+		$ret = array();
1024
+		reset( $array );
1025
+		foreach ( $array as $ii => $va ) {
1026
+			$sorter[$ii] = $va[$key];
1027
+		} // End For Loop
1028
+		asort( $sorter );
1029
+		foreach ( $sorter as $ii => $va ) {
1030
+			$ret[$ii] = $array[$ii];
1031
+		} // End For Loop
1032
+		$array = $ret;
1033 1033
 	} // End sort_array_by_key()
1034 1034
 
1035 1035
 	/**
@@ -1042,21 +1042,21 @@  discard block
 block discarded – undo
1042 1042
 		$questions_array = array();
1043 1043
 		if ( 0 < $quiz_id ) {
1044 1044
 			$question_args = array( 'post_type'         => 'question',
1045
-                                    'posts_per_page'       => -1,
1046
-                                    'orderby'           => 'ID',
1047
-                                    'order'             => 'ASC',
1048
-                                    'meta_query'		=> array(
1045
+									'posts_per_page'       => -1,
1046
+									'orderby'           => 'ID',
1047
+									'order'             => 'ASC',
1048
+									'meta_query'		=> array(
1049 1049
 										array(
1050 1050
 											'key'       => '_quiz_id',
1051 1051
 											'value'     => $quiz_id,
1052 1052
 										)
1053 1053
 									),
1054
-                                    'post_status'       => 'any',
1055
-                                    'suppress_filters'  => 0
1056
-                                );
1057
-            $questions_array = get_posts( $question_args );
1058
-        } // End If Statement
1059
-        return $questions_array;
1054
+									'post_status'       => 'any',
1055
+									'suppress_filters'  => 0
1056
+								);
1057
+			$questions_array = get_posts( $question_args );
1058
+		} // End If Statement
1059
+		return $questions_array;
1060 1060
 	} // End lesson_quiz_questions()
1061 1061
 
1062 1062
 	/**
@@ -1296,20 +1296,20 @@  discard block
 block discarded – undo
1296 1296
 					}
1297 1297
 				}
1298 1298
 
1299
-                // add next lesson button
1300
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1301
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1299
+				// add next lesson button
1300
+				$nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1301
+				$next_lesson_id = absint( $nav_id_array['next_lesson'] );
1302 1302
 
1303
-                // Output HTML
1304
-                if ( ( 0 < $next_lesson_id ) ) {
1305
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1306
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1307
-                                .'</a>';
1303
+				// Output HTML
1304
+				if ( ( 0 < $next_lesson_id ) ) {
1305
+					$message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1306
+								. '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1307
+								.'</a>';
1308 1308
 
1309
-                }
1309
+				}
1310 1310
 
1311 1311
 			}
1312
-            // Lesson/Quiz not complete
1312
+			// Lesson/Quiz not complete
1313 1313
 			else {
1314 1314
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1315 1315
 				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
@@ -1406,9 +1406,9 @@  discard block
 block discarded – undo
1406 1406
 				$user_id = get_current_user_id();
1407 1407
 			}
1408 1408
 
1409
-            if( ! $user_id > 0 ){
1410
-                return false;
1411
-            }
1409
+			if( ! $user_id > 0 ){
1410
+				return false;
1411
+			}
1412 1412
 
1413 1413
 			$user_course_status_id = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status', 'field' => 'comment_ID' ) );
1414 1414
 			if( $user_course_status_id ) {
@@ -1549,14 +1549,14 @@  discard block
 block discarded – undo
1549 1549
 					$user_id = get_current_user_id();
1550 1550
 				}
1551 1551
 
1552
-                if( is_a( $course, 'WP_Post' ) ){
1553
-                    $course =   $course->ID;
1554
-                }
1552
+				if( is_a( $course, 'WP_Post' ) ){
1553
+					$course =   $course->ID;
1554
+				}
1555 1555
 
1556 1556
 				$user_course_status = WooThemes_Sensei_Utils::user_course_status( $course , $user_id );
1557 1557
 				if( isset( $user_course_status->comment_approved ) ){
1558
-                    $user_course_status = $user_course_status->comment_approved;
1559
-                }
1558
+					$user_course_status = $user_course_status->comment_approved;
1559
+				}
1560 1560
 
1561 1561
 			}
1562 1562
 			if( $user_course_status && 'complete' == $user_course_status ) {
@@ -1592,7 +1592,7 @@  discard block
 block discarded – undo
1592 1592
 	/**
1593 1593
 	 * Check if a user has completed a lesson or not
1594 1594
 	 *
1595
-     * @uses  Sensei()
1595
+	 * @uses  Sensei()
1596 1596
 	 * @param mixed $lesson lesson_id or sensei_lesson_status entry
1597 1597
 	 * @param int $user_id
1598 1598
 	 * @return boolean
@@ -1613,10 +1613,10 @@  discard block
 block discarded – undo
1613 1613
 					$user_id = get_current_user_id();
1614 1614
 				}
1615 1615
 
1616
-                // the user is not logged in
1617
-                if( ! $user_id > 0 ){
1618
-                    return false;
1619
-                }
1616
+				// the user is not logged in
1617
+				if( ! $user_id > 0 ){
1618
+					return false;
1619
+				}
1620 1620
 				$_user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson, $user_id );
1621 1621
 
1622 1622
 				if ( $_user_lesson_status ) {
@@ -1695,9 +1695,9 @@  discard block
 block discarded – undo
1695 1695
 	 */
1696 1696
 	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1697 1697
 
1698
-        if( ! $user_id ) {
1699
-            $user_id = get_current_user_id();
1700
-        }
1698
+		if( ! $user_id ) {
1699
+			$user_id = get_current_user_id();
1700
+		}
1701 1701
 
1702 1702
 		if( $lesson_id > 0 && $user_id > 0 ) {
1703 1703
 
@@ -1748,12 +1748,12 @@  discard block
 block discarded – undo
1748 1748
 	 * Sets the status for the lesson
1749 1749
 	 *
1750 1750
 	 * @since  1.7.0
1751
-     *
1751
+	 *
1752 1752
 	 * @param int|string $user_id
1753 1753
 	 * @param int|string $lesson_id
1754 1754
 	 * @param string $status
1755 1755
 	 * @param array $metadata
1756
-     *
1756
+	 *
1757 1757
 	 * @return mixed false or comment_ID
1758 1758
 	 */
1759 1759
 	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
@@ -1903,360 +1903,360 @@  discard block
 block discarded – undo
1903 1903
 		return $pieces;
1904 1904
 	}
1905 1905
 
1906
-    /**
1907
-     *
1908
-     * Alias to Woothemes_Sensei_Utils::update_user_data
1909
-     * @since 1.7.4
1910
-     *
1911
-     * @param string $data_key maximum 39 characters allowed
1912
-     * @param int $post_id
1913
-     * @param mixed $value
1914
-     * @param int $user_id
1915
-     *
1916
-     * @return bool $success
1917
-     */
1918
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1919
-
1920
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1921
-
1922
-    }// end add_user_data
1923
-
1924
-    /**
1925
-     * add user specific data to the passed in sensei post type id
1926
-     *
1927
-     * This function saves comment meta on the users current status. If no status is available
1928
-     * status will be created. It only operates on the available sensei Post types: course, lesson, quiz.
1929
-     *
1930
-     * @since 1.7.4
1931
-     *
1932
-     * @param string $data_key maximum 39 characters allowed
1933
-     * @param int $post_id
1934
-     * @param mixed $value
1935
-     * @param int $user_id
1936
-     *
1937
-     * @return bool $success
1938
-     */
1939
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1940
-
1941
-        if( ! ( $user_id > 0 ) ){
1942
-            $user_id = get_current_user_id();
1943
-        }
1944
-
1945
-        $supported_post_types = array( 'course', 'lesson' );
1946
-        $post_type = get_post_type( $post_id );
1947
-        if( empty( $post_id ) || empty( $data_key )
1948
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1949
-            || !get_userdata( $user_id )
1950
-            || ! in_array( $post_type, $supported_post_types )  ){
1951
-
1952
-            return false;
1953
-        }
1954
-
1955
-        // check if there and existing Sensei status on this post type if not create it
1956
-        // and get the  activity ID
1957
-        $status_function = 'user_'.$post_type.'_status';
1958
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1959
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1960
-
1961
-            $start_function = 'user_start_'.$post_type;
1962
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1963
-
1964
-        }else{
1965
-
1966
-            $sensei_user_activity_id = $sensei_user_status->comment_ID;
1967
-
1968
-        }
1969
-
1970
-        // store the data
1971
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1972
-
1973
-       return $success;
1974
-
1975
-    }//update_user_data
1976
-
1977
-    /**
1978
-     * Get the user data stored on the passed in post type
1979
-     *
1980
-     * This function gets the comment meta on the lesson or course status
1981
-     *
1982
-     * @since 1.7.4
1983
-     *
1984
-     * @param $data_key
1985
-     * @param $post_id
1986
-     * @param int $user_id
1987
-     *
1988
-     * @return mixed $user_data_value
1989
-     */
1990
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
1991
-
1992
-        $user_data_value = true;
1993
-
1994
-        if( ! ( $user_id > 0 ) ){
1995
-            $user_id = get_current_user_id();
1996
-        }
1997
-
1998
-        $supported_post_types = array( 'course', 'lesson' );
1999
-        $post_type = get_post_type( $post_id );
2000
-        if( empty( $post_id ) || empty( $data_key )
2001
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2002
-            || ! get_userdata( $user_id )
2003
-            || !in_array( $post_type, $supported_post_types )  ){
2004
-
2005
-            return false;
2006
-        }
2007
-
2008
-        // check if there and existing Sensei status on this post type if not create it
2009
-        // and get the  activity ID
2010
-        $status_function = 'user_'.$post_type.'_status';
2011
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2012
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2013
-            return false;
2014
-        }
2015
-
2016
-        $sensei_user_activity_id = $sensei_user_status->comment_ID;
2017
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2018
-
2019
-        return $user_data_value;
2020
-
2021
-    }// end get_user_data
2022
-
2023
-    /**
2024
-     * Delete the Sensei user data for the given key, Sensei post type and user combination.
2025
-     *
2026
-     * @param int $data_key
2027
-     * @param int $post_id
2028
-     * @param int $user_id
2029
-     *
2030
-     * @return bool $deleted
2031
-     */
2032
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2033
-        $deleted = true;
1906
+	/**
1907
+	 *
1908
+	 * Alias to Woothemes_Sensei_Utils::update_user_data
1909
+	 * @since 1.7.4
1910
+	 *
1911
+	 * @param string $data_key maximum 39 characters allowed
1912
+	 * @param int $post_id
1913
+	 * @param mixed $value
1914
+	 * @param int $user_id
1915
+	 *
1916
+	 * @return bool $success
1917
+	 */
1918
+	public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
2034 1919
 
2035
-        if( ! ( $user_id > 0 ) ){
2036
-            $user_id = get_current_user_id();
2037
-        }
1920
+		return self::update_user_data( $data_key, $post_id, $value , $user_id );
2038 1921
 
2039
-        $supported_post_types = array( 'course', 'lesson' );
2040
-        $post_type = get_post_type( $post_id );
2041
-        if( empty( $post_id ) || empty( $data_key )
2042
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2043
-            || ! get_userdata( $user_id )
2044
-            || !in_array( $post_type, $supported_post_types )  ){
1922
+	}// end add_user_data
2045 1923
 
2046
-            return false;
2047
-        }
1924
+	/**
1925
+	 * add user specific data to the passed in sensei post type id
1926
+	 *
1927
+	 * This function saves comment meta on the users current status. If no status is available
1928
+	 * status will be created. It only operates on the available sensei Post types: course, lesson, quiz.
1929
+	 *
1930
+	 * @since 1.7.4
1931
+	 *
1932
+	 * @param string $data_key maximum 39 characters allowed
1933
+	 * @param int $post_id
1934
+	 * @param mixed $value
1935
+	 * @param int $user_id
1936
+	 *
1937
+	 * @return bool $success
1938
+	 */
1939
+	public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
2048 1940
 
2049
-        // check if there and existing Sensei status on this post type if not create it
2050
-        // and get the  activity ID
2051
-        $status_function = 'user_'.$post_type.'_status';
2052
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2053
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2054
-            return false;
2055
-        }
1941
+		if( ! ( $user_id > 0 ) ){
1942
+			$user_id = get_current_user_id();
1943
+		}
2056 1944
 
2057
-        $sensei_user_activity_id = $sensei_user_status->comment_ID;
2058
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
1945
+		$supported_post_types = array( 'course', 'lesson' );
1946
+		$post_type = get_post_type( $post_id );
1947
+		if( empty( $post_id ) || empty( $data_key )
1948
+			|| ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1949
+			|| !get_userdata( $user_id )
1950
+			|| ! in_array( $post_type, $supported_post_types )  ){
2059 1951
 
2060
-        return $deleted;
1952
+			return false;
1953
+		}
2061 1954
 
2062
-    }// end delete_user_data
1955
+		// check if there and existing Sensei status on this post type if not create it
1956
+		// and get the  activity ID
1957
+		$status_function = 'user_'.$post_type.'_status';
1958
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
1959
+		if( ! isset( $sensei_user_status->comment_ID ) ){
2063 1960
 
1961
+			$start_function = 'user_start_'.$post_type;
1962
+			$sensei_user_activity_id = self::$start_function( $user_id, $post_id );
2064 1963
 
2065
-    /**
2066
-     * The function creates a drop down. Never write up a Sensei select statement again.
2067
-     *
2068
-     * @since 1.8.0
2069
-     *
2070
-     * @param string $selected_value
2071
-     * @param $options{
2072
-     *    @type string $value the value saved in the database
2073
-     *    @type string $option what the user will see in the list of items
2074
-     * }
2075
-     * @param array $attributes{
2076
-     *   @type string $attribute  type such name or id etc.
2077
-     *  @type string $value
2078
-     * }
2079
-     * @param bool $enable_none_option
2080
-     *
2081
-     * @return string $drop_down_element
2082
-     */
2083
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
1964
+		}else{
2084 1965
 
2085
-        $drop_down_element = '';
1966
+			$sensei_user_activity_id = $sensei_user_status->comment_ID;
2086 1967
 
2087
-        // setup the basic attributes
2088
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
1968
+		}
2089 1969
 
2090
-            $attributes['name'] = 'sensei-options';
1970
+		// store the data
1971
+		$success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
2091 1972
 
2092
-        }
1973
+	   return $success;
2093 1974
 
2094
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
1975
+	}//update_user_data
2095 1976
 
2096
-            $attributes['id'] = 'sensei-options';
1977
+	/**
1978
+	 * Get the user data stored on the passed in post type
1979
+	 *
1980
+	 * This function gets the comment meta on the lesson or course status
1981
+	 *
1982
+	 * @since 1.7.4
1983
+	 *
1984
+	 * @param $data_key
1985
+	 * @param $post_id
1986
+	 * @param int $user_id
1987
+	 *
1988
+	 * @return mixed $user_data_value
1989
+	 */
1990
+	public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
2097 1991
 
2098
-        }
1992
+		$user_data_value = true;
2099 1993
 
2100
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
1994
+		if( ! ( $user_id > 0 ) ){
1995
+			$user_id = get_current_user_id();
1996
+		}
2101 1997
 
2102
-            $attributes['class'] ='chosen_select widefat';
1998
+		$supported_post_types = array( 'course', 'lesson' );
1999
+		$post_type = get_post_type( $post_id );
2000
+		if( empty( $post_id ) || empty( $data_key )
2001
+			|| ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2002
+			|| ! get_userdata( $user_id )
2003
+			|| !in_array( $post_type, $supported_post_types )  ){
2103 2004
 
2104
-        }
2005
+			return false;
2006
+		}
2007
+
2008
+		// check if there and existing Sensei status on this post type if not create it
2009
+		// and get the  activity ID
2010
+		$status_function = 'user_'.$post_type.'_status';
2011
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
2012
+		if( ! isset( $sensei_user_status->comment_ID ) ){
2013
+			return false;
2014
+		}
2015
+
2016
+		$sensei_user_activity_id = $sensei_user_status->comment_ID;
2017
+		$user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2018
+
2019
+		return $user_data_value;
2020
+
2021
+	}// end get_user_data
2022
+
2023
+	/**
2024
+	 * Delete the Sensei user data for the given key, Sensei post type and user combination.
2025
+	 *
2026
+	 * @param int $data_key
2027
+	 * @param int $post_id
2028
+	 * @param int $user_id
2029
+	 *
2030
+	 * @return bool $deleted
2031
+	 */
2032
+	public static function delete_user_data( $data_key, $post_id , $user_id ){
2033
+		$deleted = true;
2034
+
2035
+		if( ! ( $user_id > 0 ) ){
2036
+			$user_id = get_current_user_id();
2037
+		}
2038
+
2039
+		$supported_post_types = array( 'course', 'lesson' );
2040
+		$post_type = get_post_type( $post_id );
2041
+		if( empty( $post_id ) || empty( $data_key )
2042
+			|| ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2043
+			|| ! get_userdata( $user_id )
2044
+			|| !in_array( $post_type, $supported_post_types )  ){
2045
+
2046
+			return false;
2047
+		}
2048
+
2049
+		// check if there and existing Sensei status on this post type if not create it
2050
+		// and get the  activity ID
2051
+		$status_function = 'user_'.$post_type.'_status';
2052
+		$sensei_user_status = self::$status_function( $post_id ,$user_id  );
2053
+		if( ! isset( $sensei_user_status->comment_ID ) ){
2054
+			return false;
2055
+		}
2056
+
2057
+		$sensei_user_activity_id = $sensei_user_status->comment_ID;
2058
+		$deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2059
+
2060
+		return $deleted;
2061
+
2062
+	}// end delete_user_data
2063
+
2064
+
2065
+	/**
2066
+	 * The function creates a drop down. Never write up a Sensei select statement again.
2067
+	 *
2068
+	 * @since 1.8.0
2069
+	 *
2070
+	 * @param string $selected_value
2071
+	 * @param $options{
2072
+	 *    @type string $value the value saved in the database
2073
+	 *    @type string $option what the user will see in the list of items
2074
+	 * }
2075
+	 * @param array $attributes{
2076
+	 *   @type string $attribute  type such name or id etc.
2077
+	 *  @type string $value
2078
+	 * }
2079
+	 * @param bool $enable_none_option
2080
+	 *
2081
+	 * @return string $drop_down_element
2082
+	 */
2083
+	public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2084
+
2085
+		$drop_down_element = '';
2105 2086
 
2106
-        // create element attributes
2107
-        $combined_attributes = '';
2108
-        foreach( $attributes as $attribute => $value ){
2087
+		// setup the basic attributes
2088
+		if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2109 2089
 
2110
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2090
+			$attributes['name'] = 'sensei-options';
2111 2091
 
2112
-        }// end for each
2092
+		}
2113 2093
 
2094
+		if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2114 2095
 
2115
-        // create the select element
2116
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2096
+			$attributes['id'] = 'sensei-options';
2117 2097
 
2118
-        // show the none option if the client requested
2119
-        if( $enable_none_option ) {
2120
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2121
-        }
2098
+		}
2122 2099
 
2123
-        if ( count( $options ) > 0 ) {
2100
+		if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2124 2101
 
2125
-            foreach ($options as $value => $option ){
2102
+			$attributes['class'] ='chosen_select widefat';
2126 2103
 
2127
-                $element = '';
2128
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2129
-                $element .= selected( $value, $selected_value, false ) . '>';
2130
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2104
+		}
2131 2105
 
2132
-                // add the element to the select html
2133
-                $drop_down_element.= $element;
2134
-            } // End For Loop
2106
+		// create element attributes
2107
+		$combined_attributes = '';
2108
+		foreach( $attributes as $attribute => $value ){
2135 2109
 
2136
-        } // End If Statement
2110
+			$combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2137 2111
 
2138
-        $drop_down_element .= '</select>' . "\n";
2112
+		}// end for each
2139 2113
 
2140
-        return $drop_down_element;
2141 2114
 
2142
-    }// generate_drop_down
2115
+		// create the select element
2116
+		$drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2117
+
2118
+		// show the none option if the client requested
2119
+		if( $enable_none_option ) {
2120
+			$drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2121
+		}
2143 2122
 
2144
-    /**
2145
-     * Wrapper for the default php round() function.
2146
-     * This allows us to give more control to a user on how they can round Sensei
2147
-     * decimals passed through this function.
2148
-     *
2149
-     * @since 1.8.5
2150
-     *
2151
-     * @param double $val
2152
-     * @param int $precision
2153
-     * @param $mode
2154
-     * @param string $context
2155
-     *
2156
-     * @return double $val
2157
-     */
2158
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2123
+		if ( count( $options ) > 0 ) {
2159 2124
 
2160
-        /**å
2125
+			foreach ($options as $value => $option ){
2126
+
2127
+				$element = '';
2128
+				$element.= '<option value="' . esc_attr( $value ) . '"';
2129
+				$element .= selected( $value, $selected_value, false ) . '>';
2130
+				$element .= esc_html(  $option ) . '</option>' . "\n";
2131
+
2132
+				// add the element to the select html
2133
+				$drop_down_element.= $element;
2134
+			} // End For Loop
2135
+
2136
+		} // End If Statement
2137
+
2138
+		$drop_down_element .= '</select>' . "\n";
2139
+
2140
+		return $drop_down_element;
2141
+
2142
+	}// generate_drop_down
2143
+
2144
+	/**
2145
+	 * Wrapper for the default php round() function.
2146
+	 * This allows us to give more control to a user on how they can round Sensei
2147
+	 * decimals passed through this function.
2148
+	 *
2149
+	 * @since 1.8.5
2150
+	 *
2151
+	 * @param double $val
2152
+	 * @param int $precision
2153
+	 * @param $mode
2154
+	 * @param string $context
2155
+	 *
2156
+	 * @return double $val
2157
+	 */
2158
+	public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2159
+
2160
+		/**å
2161 2161
          * Change the precision for the Sensei_Utils::round function.
2162 2162
          * the precision given will be passed into the php round function
2163 2163
          * @since 1.8.5
2164 2164
          */
2165
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2166
-
2167
-        /**
2168
-         * Change the mode for the Sensei_Utils::round function.
2169
-         * the mode given will be passed into the php round function
2170
-         *
2171
-         * This applies only to PHP version 5.3.0 and greater
2172
-         *
2173
-         * @since 1.8.5
2174
-         */
2175
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2165
+		$precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2176 2166
 
2177
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2167
+		/**
2168
+		 * Change the mode for the Sensei_Utils::round function.
2169
+		 * the mode given will be passed into the php round function
2170
+		 *
2171
+		 * This applies only to PHP version 5.3.0 and greater
2172
+		 *
2173
+		 * @since 1.8.5
2174
+		 */
2175
+		$mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2178 2176
 
2179
-            return round( $val, $precision, $mode );
2177
+		if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2180 2178
 
2181
-        }else{
2179
+			return round( $val, $precision, $mode );
2182 2180
 
2183
-            return round( $val, $precision );
2181
+		}else{
2184 2182
 
2185
-        }
2183
+			return round( $val, $precision );
2186 2184
 
2187
-    }
2185
+		}
2188 2186
 
2189
-    /**
2190
-     * Returns the current url with all the query vars
2191
-     *
2192
-     * @since 1.9.0
2193
-     * @return string $url
2194
-     */
2195
-    public static function get_current_url(){
2187
+	}
2196 2188
 
2197
-        global $wp;
2198
-        $current_url = trailingslashit( home_url( $wp->request ) );
2199
-        if ( isset( $_GET ) ) {
2189
+	/**
2190
+	 * Returns the current url with all the query vars
2191
+	 *
2192
+	 * @since 1.9.0
2193
+	 * @return string $url
2194
+	 */
2195
+	public static function get_current_url(){
2200 2196
 
2201
-            foreach ($_GET as $param => $val ) {
2197
+		global $wp;
2198
+		$current_url = trailingslashit( home_url( $wp->request ) );
2199
+		if ( isset( $_GET ) ) {
2202 2200
 
2203
-                $current_url = add_query_arg( $param, $val , $current_url );
2201
+			foreach ($_GET as $param => $val ) {
2204 2202
 
2205
-            }
2206
-        }
2203
+				$current_url = add_query_arg( $param, $val , $current_url );
2207 2204
 
2208
-        return $current_url;
2209
-    }
2205
+			}
2206
+		}
2210 2207
 
2211
-    /**
2212
-     * Restore the global WP_Query
2213
-     *
2214
-     * @since 1.9.0
2215
-     */
2216
-    public static function restore_wp_query() {
2208
+		return $current_url;
2209
+	}
2217 2210
 
2218
-        wp_reset_query();
2211
+	/**
2212
+	 * Restore the global WP_Query
2213
+	 *
2214
+	 * @since 1.9.0
2215
+	 */
2216
+	public static function restore_wp_query() {
2219 2217
 
2220
-    }
2218
+		wp_reset_query();
2221 2219
 
2222
-    /**
2223
-     * Merge two arrays in a zip like fashion.
2224
-     * If one array is longer than the other the elements will be apended
2225
-     * to the end of the resulting array.
2226
-     *
2227
-     * @since 1.9.0
2228
-     *
2229
-     * @param array $array_a
2230
-     * @param array $array_b
2231
-     * @return array $merged_array
2232
-     */
2233
-    public static function array_zip_merge( $array_a, $array_b ){
2220
+	}
2234 2221
 
2235
-        if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2236
-            trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2237
-        }
2222
+	/**
2223
+	 * Merge two arrays in a zip like fashion.
2224
+	 * If one array is longer than the other the elements will be apended
2225
+	 * to the end of the resulting array.
2226
+	 *
2227
+	 * @since 1.9.0
2228
+	 *
2229
+	 * @param array $array_a
2230
+	 * @param array $array_b
2231
+	 * @return array $merged_array
2232
+	 */
2233
+	public static function array_zip_merge( $array_a, $array_b ){
2238 2234
 
2239
-        $merged_array = array();
2240
-        $total_elements = count( $array_a )  + count( $array_b );
2235
+		if( ! isset( $array_a[0]  ) || ! isset( $array_b[0] )  ){
2236
+			trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2237
+		}
2241 2238
 
2242
-        // Zip arrays
2243
-        for ( $i = 0; $i < $total_elements; $i++) {
2239
+		$merged_array = array();
2240
+		$total_elements = count( $array_a )  + count( $array_b );
2244 2241
 
2245
-            // if has an element at current index push a on top
2246
-            if( isset( $array_a[ $i ] ) ){
2247
-                $merged_array[] = $array_a[ $i ]  ;
2248
-            }
2242
+		// Zip arrays
2243
+		for ( $i = 0; $i < $total_elements; $i++) {
2249 2244
 
2250
-            // next if $array_b has an element at current index push a on top of the element
2251
-            // from a if there was one, if not the element before that.
2252
-            if( isset( $array_b[ $i ] ) ){
2253
-                $merged_array[] = $array_b[ $i ]  ;
2254
-            }
2245
+			// if has an element at current index push a on top
2246
+			if( isset( $array_a[ $i ] ) ){
2247
+				$merged_array[] = $array_a[ $i ]  ;
2248
+			}
2255 2249
 
2256
-        }
2250
+			// next if $array_b has an element at current index push a on top of the element
2251
+			// from a if there was one, if not the element before that.
2252
+			if( isset( $array_b[ $i ] ) ){
2253
+				$merged_array[] = $array_b[ $i ]  ;
2254
+			}
2255
+
2256
+		}
2257 2257
 
2258
-        return $merged_array;
2259
-    }
2258
+		return $merged_array;
2259
+	}
2260 2260
 
2261 2261
 } // End Class
2262 2262
 
Please login to merge, or discard this patch.