Completed
Pull Request — master (#1257)
by
unknown
05:38
created
includes/class-sensei-course.php 2 patches
Indentation   +1489 added lines, -1489 removed lines patch added patch discarded remove patch
@@ -12,21 +12,21 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Sensei_Course {
14 14
 
15
-    /**
16
-     * @var $token
17
-     */
15
+	/**
16
+	 * @var $token
17
+	 */
18 18
 	public $token;
19 19
 
20
-    /**
21
-     * @var array $meta_fields
22
-     */
20
+	/**
21
+	 * @var array $meta_fields
22
+	 */
23 23
 	public $meta_fields;
24 24
 
25
-    /**
26
-     * @var string|bool $my_courses_page reference to the sites
27
-     * my courses page, false if none was set
28
-     */
29
-    public  $my_courses_page;
25
+	/**
26
+	 * @var string|bool $my_courses_page reference to the sites
27
+	 * my courses page, false if none was set
28
+	 */
29
+	public  $my_courses_page;
30 30
 
31 31
 	/**
32 32
 	 * Constructor.
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function __construct () {
36 36
 
37
-        $this->token = 'course';
37
+		$this->token = 'course';
38 38
 
39 39
 		// Setup meta fields for this post type
40 40
 		$this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' );
41 41
 		// Admin actions
42 42
 		if ( is_admin() ) {
43 43
 			// Metabox functions
44
-            add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
44
+			add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
45 45
 			add_action( 'save_post', array( $this, 'meta_box_save' ) );
46 46
 			// Custom Write Panel Columns
47 47
 			add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 );
@@ -57,47 +57,47 @@  discard block
 block discarded – undo
57 57
 		// Update course completion upon grading of a quiz
58 58
 		add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 );
59 59
 
60
-        // show the progress bar ont he single course page
61
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
62
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
60
+		// show the progress bar ont he single course page
61
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
62
+		add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
63 63
 
64
-        // provide an option to block all emails related to a selected course
65
-        add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
66
-        add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
64
+		// provide an option to block all emails related to a selected course
65
+		add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
66
+		add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
67 67
 
68
-        // preview lessons on the course content
69
-        add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
68
+		// preview lessons on the course content
69
+		add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
70 70
 
71
-        // the course meta
72
-        add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
71
+		// the course meta
72
+		add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
73 73
 
74
-        // backwards compatible template hooks
75
-        add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
76
-        add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
74
+		// backwards compatible template hooks
75
+		add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
76
+		add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
77 77
 
78
-        // add the user status on the course to the markup as a class
79
-        add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
78
+		// add the user status on the course to the markup as a class
79
+		add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
80 80
 
81
-        //filter the course query in Sensei specific instances
82
-        add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
81
+		//filter the course query in Sensei specific instances
82
+		add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
83 83
 
84
-        //attache the sorting to the course archive
85
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
84
+		//attache the sorting to the course archive
85
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
86 86
 
87
-        //attach the filter links to the course archive
88
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
87
+		//attach the filter links to the course archive
88
+		add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
89 89
 
90
-        //filter the course query when featured filter is applied
91
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
90
+		//filter the course query when featured filter is applied
91
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
92 92
 
93
-        // handle the order by title post submission
94
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
93
+		// handle the order by title post submission
94
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
95 95
 
96
-        // ensure the course category page respects the manual order set for courses
97
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
96
+		// ensure the course category page respects the manual order set for courses
97
+		add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
98 98
 
99
-        // flush rewrite rules when saving a course
100
-        add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
99
+		// flush rewrite rules when saving a course
100
+		add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
101 101
 
102 102
 	} // End __construct()
103 103
 
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 		add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' );
151 151
 		// Add Meta Box for Course Lessons
152 152
 		add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' );
153
-        // Add Meta Box to link to Manage Learners
154
-        add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
155
-        // Remove "Custom Settings" meta box.
153
+		// Add Meta Box to link to Manage Learners
154
+		add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
155
+		// Remove "Custom Settings" meta box.
156 156
 		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
157 157
 
158
-        // add Disable email notification box
159
-        add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
158
+		// add Disable email notification box
159
+		add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
160 160
 
161 161
 	} // End meta_box_setup()
162 162
 
@@ -174,10 +174,10 @@  discard block
 block discarded – undo
174 174
 		$post_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
175 175
 							'posts_per_page' 		=> -1,
176 176
 							'orderby'         	=> 'title',
177
-    						'order'           	=> 'DESC',
178
-    						'exclude' 			=> $post->ID,
179
-    						'post_status'		=> array( 'publish', 'private', 'draft' ),
180
-    						'tax_query'			=> array(
177
+							'order'           	=> 'DESC',
178
+							'exclude' 			=> $post->ID,
179
+							'post_status'		=> array( 'publish', 'private', 'draft' ),
180
+							'tax_query'			=> array(
181 181
 								array(
182 182
 									'taxonomy'	=> 'product_type',
183 183
 									'field'		=> 'slug',
@@ -205,21 +205,21 @@  discard block
 block discarded – undo
205 205
 						$product_object = get_product( $post_item->ID );
206 206
 						$parent_id = wp_get_post_parent_id( $post_item->ID );
207 207
 
208
-                        if( sensei_check_woocommerce_version( '2.1' ) ) {
208
+						if( sensei_check_woocommerce_version( '2.1' ) ) {
209 209
 							$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
210 210
 
211 211
 						} else {
212
-                            // fall back to pre wc 2.1
212
+							// fall back to pre wc 2.1
213 213
 							$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
214 214
 
215 215
 						}
216 216
 
217
-                        $product_name = ucwords( $formatted_variation );
218
-                        if( empty( $product_name ) ){
217
+						$product_name = ucwords( $formatted_variation );
218
+						if( empty( $product_name ) ){
219 219
 
220
-                            $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
220
+							$product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
221 221
 
222
-                        }
222
+						}
223 223
 
224 224
 					} else {
225 225
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 
270 270
 			} else {
271 271
 
272
-                $html .= '<p>' . "\n";
272
+				$html .= '<p>' . "\n";
273 273
 					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n";
274 274
 				$html .= '</p>'."\n";
275 275
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 		$post_args = array(	'post_type' 		=> 'course',
296 296
 							'posts_per_page' 		=> -1,
297 297
 							'orderby'         	=> 'title',
298
-    						'order'           	=> 'DESC',
299
-    						'exclude' 			=> $post->ID,
298
+							'order'           	=> 'DESC',
299
+							'exclude' 			=> $post->ID,
300 300
 							'suppress_filters' 	=> 0
301 301
 							);
302 302
 		$posts_array = get_posts( $post_args );
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
 		$checked = '';
339 339
 		if ( isset( $course_featured ) && ( '' != $course_featured ) ) {
340
-	 	    $checked = checked( 'featured', $course_featured, false );
340
+	 		$checked = checked( 'featured', $course_featured, false );
341 341
 	 	} // End If Statement
342 342
 
343 343
 	 	$html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '>&nbsp;' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>';
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
433 433
 		} // End If Statement
434 434
 
435
-        // update field with the new value
436
-        return update_post_meta( $post_id, $meta_key, $new_meta_value );
435
+		// update field with the new value
436
+		return update_post_meta( $post_id, $meta_key, $new_meta_value );
437 437
 
438 438
 	} // End save_post_meta()
439 439
 
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
 
458 458
 		$html = '';
459 459
 		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="'
460
-                 . esc_attr( 'woo_' . $this->token . '_noonce' )
461
-                 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
460
+				 . esc_attr( 'woo_' . $this->token . '_noonce' )
461
+				 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
462 462
 
463 463
 		if ( count( $posts_array ) > 0 ) {
464 464
 
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 			$html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n";
480 480
 
481 481
 				$html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id )
482
-                         . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
483
-                         . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
482
+						 . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
483
+						 . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
484 484
 
485 485
 			$html .= '</p>'."\n";
486 486
 		} // End If Statement
@@ -489,29 +489,29 @@  discard block
 block discarded – undo
489 489
 
490 490
 	} // End course_lessons_meta_box_content()
491 491
 
492
-    /**
493
-     * course_manage_meta_box_content function.
494
-     *
495
-     * @since 1.9.0
496
-     * @access public
497
-     * @return void
498
-     */
492
+	/**
493
+	 * course_manage_meta_box_content function.
494
+	 *
495
+	 * @since 1.9.0
496
+	 * @access public
497
+	 * @return void
498
+	 */
499 499
 
500
-    public function course_manage_meta_box_content () {
501
-        global $post;
500
+	public function course_manage_meta_box_content () {
501
+		global $post;
502 502
         
503
-        $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
503
+		$manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
504 504
 
505
-        $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
505
+		$grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
506 506
 
507 507
 
508
-        echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
508
+		echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
509 509
 
510
-        echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
510
+		echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>";
511 511
 
512 512
 
513 513
 
514
-    } // End course_manage_meta_box_content()
514
+	} // End course_manage_meta_box_content()
515 515
 
516 516
 	/**
517 517
 	 * Add column headings to the "lesson" post list screen.
@@ -652,92 +652,92 @@  discard block
 block discarded – undo
652 652
 			} // End If Statement
653 653
 		} // End If Statement
654 654
 
655
-        $stored_order = get_option( 'sensei_course_order', '' );
656
-        $order = 'ASC';
657
-        $orderby = 'menu_order';
658
-        if( empty( $stored_order ) ){
655
+		$stored_order = get_option( 'sensei_course_order', '' );
656
+		$order = 'ASC';
657
+		$orderby = 'menu_order';
658
+		if( empty( $stored_order ) ){
659 659
 
660
-            $order = 'DESC';
661
-            $orderby = 'date';
660
+			$order = 'DESC';
661
+			$orderby = 'date';
662 662
 
663
-        }
663
+		}
664 664
 
665 665
 		switch ($type) {
666 666
 
667 667
 			case 'usercourses':
668 668
 				$post_args = array(	'post_type' 		=> 'course',
669 669
 									'orderby'         	=> $orderby,
670
-    								'order'           	=> $order,
671
-    								'post_status'      	=> 'publish',
672
-    								'include'			=> $includes,
673
-    								'exclude'			=> $excludes,
674
-    								'suppress_filters' 	=> 0
670
+									'order'           	=> $order,
671
+									'post_status'      	=> 'publish',
672
+									'include'			=> $includes,
673
+									'exclude'			=> $excludes,
674
+									'suppress_filters' 	=> 0
675 675
 									);
676 676
 				break;
677 677
 			case 'freecourses':
678 678
 
679
-                $post_args = array(
680
-                    'post_type' 		=> 'course',
681
-                    'orderby'         	=> $orderby,
682
-                    'order'           	=> $order,
683
-                    'post_status'      	=> 'publish',
684
-                    'exclude'			=> $excludes,
685
-                    'suppress_filters' 	=> 0
686
-                );
687
-                // Sub Query to get all WooCommerce Products that have Zero price
688
-                $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
679
+				$post_args = array(
680
+					'post_type' 		=> 'course',
681
+					'orderby'         	=> $orderby,
682
+					'order'           	=> $order,
683
+					'post_status'      	=> 'publish',
684
+					'exclude'			=> $excludes,
685
+					'suppress_filters' 	=> 0
686
+				);
687
+				// Sub Query to get all WooCommerce Products that have Zero price
688
+				$post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args();
689 689
 
690
-                break;
690
+				break;
691 691
 
692 692
 			case 'paidcourses':
693 693
 
694
-                $post_args = array(
695
-                    'post_type' 		=> 'course',
696
-                    'orderby'         	=> $orderby,
697
-                    'order'           	=> $order,
698
-                    'post_status'      	=> 'publish',
699
-                    'exclude'			=> $excludes,
700
-                    'suppress_filters' 	=> 0
701
-                );
694
+				$post_args = array(
695
+					'post_type' 		=> 'course',
696
+					'orderby'         	=> $orderby,
697
+					'order'           	=> $order,
698
+					'post_status'      	=> 'publish',
699
+					'exclude'			=> $excludes,
700
+					'suppress_filters' 	=> 0
701
+				);
702 702
 
703
-                // Sub Query to get all WooCommerce Products that have price greater than zero
704
-                $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
703
+				// Sub Query to get all WooCommerce Products that have price greater than zero
704
+				$post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args();
705 705
 
706 706
 				break;
707 707
 
708 708
 			case 'featuredcourses':
709
-                $post_args = array(	'post_type' 		=> 'course',
710
-                                    'orderby'         	=> $orderby,
711
-                                    'order'           	=> $order,
712
-    								'post_status'      	=> 'publish',
713
-    								'meta_value' 		=> 'featured',
714
-    								'meta_key' 			=> '_course_featured',
715
-    								'meta_compare' 		=> '=',
716
-    								'exclude'			=> $excludes,
717
-    								'suppress_filters' 	=> 0
709
+				$post_args = array(	'post_type' 		=> 'course',
710
+									'orderby'         	=> $orderby,
711
+									'order'           	=> $order,
712
+									'post_status'      	=> 'publish',
713
+									'meta_value' 		=> 'featured',
714
+									'meta_key' 			=> '_course_featured',
715
+									'meta_compare' 		=> '=',
716
+									'exclude'			=> $excludes,
717
+									'suppress_filters' 	=> 0
718 718
 									);
719 719
 				break;
720 720
 			default:
721 721
 				$post_args = array(	'post_type' 		=> 'course',
722
-                                    'orderby'         	=> $orderby,
723
-                                    'order'           	=> $order,
724
-    								'post_status'      	=> 'publish',
725
-    								'exclude'			=> $excludes,
726
-    								'suppress_filters' 	=> 0
722
+									'orderby'         	=> $orderby,
723
+									'order'           	=> $order,
724
+									'post_status'      	=> 'publish',
725
+									'exclude'			=> $excludes,
726
+									'suppress_filters' 	=> 0
727 727
 									);
728 728
 				break;
729 729
 
730 730
 		}
731 731
 
732
-        $post_args['posts_per_page'] = $amount;
733
-        $paged = $wp_query->get( 'paged' );
734
-        $post_args['paged'] = empty( $paged) ? 1 : $paged;
732
+		$post_args['posts_per_page'] = $amount;
733
+		$paged = $wp_query->get( 'paged' );
734
+		$post_args['paged'] = empty( $paged) ? 1 : $paged;
735 735
 
736
-        if( 'newcourses' == $type ){
736
+		if( 'newcourses' == $type ){
737 737
 
738
-            $post_args[ 'orderby' ] = 'date';
739
-            $post_args[ 'order' ] = 'DESC';
740
-        }
738
+			$post_args[ 'orderby' ] = 'date';
739
+			$post_args[ 'order' ] = 'DESC';
740
+		}
741 741
 
742 742
 		return $post_args;
743 743
 	}
@@ -747,24 +747,24 @@  discard block
 block discarded – undo
747 747
 	 * course_image function.
748 748
 	 *
749 749
 	 * Outputs the courses image, or first image from a lesson within a course
750
-     *
751
-     * Will echo the image unless return true is specified.
750
+	 *
751
+	 * Will echo the image unless return true is specified.
752 752
 	 *
753 753
 	 * @access public
754 754
 	 * @param int | WP_Post $course_id (default: 0)
755 755
 	 * @param string $width (default: '100')
756 756
 	 * @param string $height (default: '100')
757
-     * @param bool $return default false
758
-     *
757
+	 * @param bool $return default false
758
+	 *
759 759
 	 * @return string | void
760 760
 	 */
761 761
 	public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) {
762 762
 
763
-        if ( is_a( $course_id, 'WP_Post' ) ) {
763
+		if ( is_a( $course_id, 'WP_Post' ) ) {
764 764
 
765
-	        $course_id = $course_id->ID;
765
+			$course_id = $course_id->ID;
766 766
 
767
-        }
767
+		}
768 768
 
769 769
 		if ( 'course' !== get_post_type( $course_id )  ){
770 770
 
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
  				// Display Image Placeholder if none
828 828
 				if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) {
829 829
                     
830
-                    $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
830
+					$img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
831 831
 
832 832
 				} // End If Statement
833 833
 
@@ -841,15 +841,15 @@  discard block
 block discarded – undo
841 841
 
842 842
 		} // End If Statement
843 843
 
844
-        if( $return ){
844
+		if( $return ){
845 845
 
846
-            return $html;
846
+			return $html;
847 847
 
848
-        }else{
848
+		}else{
849 849
 
850
-            echo $html;
850
+			echo $html;
851 851
 
852
-        }
852
+		}
853 853
 
854 854
 	} // End course_image()
855 855
 
@@ -893,9 +893,9 @@  discard block
 block discarded – undo
893 893
 	 */
894 894
 	public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) {
895 895
 
896
-        if( is_a( $course_id, 'WP_Post' ) ){
897
-            $course_id = $course_id->ID;
898
-        }
896
+		if( is_a( $course_id, 'WP_Post' ) ){
897
+			$course_id = $course_id->ID;
898
+		}
899 899
 
900 900
 		$post_args = array(	'post_type'         => 'lesson',
901 901
 							'posts_per_page'       => -1,
@@ -911,67 +911,67 @@  discard block
 block discarded – undo
911 911
 							'suppress_filters'  => 0,
912 912
 							);
913 913
 		$query_results = new WP_Query( $post_args );
914
-        $lessons = $query_results->posts;
915
-
916
-        // re order the lessons. This could not be done via the OR meta query as there may be lessons
917
-        // with the course order for a different course and this should not be included. It could also not
918
-        // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
919
-        // that have been added to the course.
920
-        if( count( $lessons) > 1  ){
921
-
922
-            foreach( $lessons as $lesson ){
923
-
924
-                $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
925
-                // for lessons with no order set it to be 10000 so that it show up at the end
926
-                $lesson->course_order = $order ? $order : 100000;
927
-            }
928
-
929
-            uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
930
-        }
931
-
932
-        /**
933
-         * Filter runs inside Sensei_Course::course_lessons function
934
-         *
935
-         * Returns all lessons for a given course
936
-         *
937
-         * @param array $lessons
938
-         * @param int $course_id
939
-         */
940
-        $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
941
-
942
-        //return the requested fields
943
-        // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
944
-        // objects
945
-        if( 'ids' == $fields ) {
946
-            $lesson_objects = $lessons;
947
-            $lessons = array();
948
-
949
-            foreach ($lesson_objects as $lesson) {
950
-                $lessons[] = $lesson->ID;
951
-            }
952
-        }
953
-
954
-        return $lessons;
914
+		$lessons = $query_results->posts;
915
+
916
+		// re order the lessons. This could not be done via the OR meta query as there may be lessons
917
+		// with the course order for a different course and this should not be included. It could also not
918
+		// be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
919
+		// that have been added to the course.
920
+		if( count( $lessons) > 1  ){
921
+
922
+			foreach( $lessons as $lesson ){
923
+
924
+				$order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
925
+				// for lessons with no order set it to be 10000 so that it show up at the end
926
+				$lesson->course_order = $order ? $order : 100000;
927
+			}
928
+
929
+			uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
930
+		}
931
+
932
+		/**
933
+		 * Filter runs inside Sensei_Course::course_lessons function
934
+		 *
935
+		 * Returns all lessons for a given course
936
+		 *
937
+		 * @param array $lessons
938
+		 * @param int $course_id
939
+		 */
940
+		$lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
941
+
942
+		//return the requested fields
943
+		// runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
944
+		// objects
945
+		if( 'ids' == $fields ) {
946
+			$lesson_objects = $lessons;
947
+			$lessons = array();
948
+
949
+			foreach ($lesson_objects as $lesson) {
950
+				$lessons[] = $lesson->ID;
951
+			}
952
+		}
953
+
954
+		return $lessons;
955 955
 
956 956
 	} // End course_lessons()
957 957
 
958
-    /**
959
-     * Used for the uasort in $this->course_lessons()
960
-     * @since 1.8.0
961
-     * @access protected
962
-     *
963
-     * @param array $lesson_1
964
-     * @param array $lesson_2
965
-     * @return int
966
-     */
967
-    protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
958
+	/**
959
+	 * Used for the uasort in $this->course_lessons()
960
+	 * @since 1.8.0
961
+	 * @access protected
962
+	 *
963
+	 * @param array $lesson_1
964
+	 * @param array $lesson_2
965
+	 * @return int
966
+	 */
967
+	protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
968 968
 
969
-        if ( $lesson_1->course_order == $lesson_2->course_order ) {
970
-            return 0;
971
-        }
969
+		if ( $lesson_1->course_order == $lesson_2->course_order ) {
970
+			return 0;
971
+		}
972 972
 
973
-        return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
974
-    }
973
+		return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1;
974
+	}
975 975
 
976 976
 	/**
977 977
 	 * Fetch all quiz ids in a course
@@ -1034,15 +1034,15 @@  discard block
 block discarded – undo
1034 1034
 	 */
1035 1035
 	public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
1036 1036
 
1037
-        $lesson_args = array(	'post_type' 		=> 'lesson',
1037
+		$lesson_args = array(	'post_type' 		=> 'lesson',
1038 1038
 								'posts_per_page' 		=> -1,
1039
-		    					'author'         	=> $author_id,
1040
-		    					'meta_key'        	=> '_lesson_course',
1041
-    							'meta_value'      	=> $course_id,
1042
-    	    					'post_status'      	=> 'publish',
1043
-    	    					'suppress_filters' 	=> 0,
1039
+								'author'         	=> $author_id,
1040
+								'meta_key'        	=> '_lesson_course',
1041
+								'meta_value'      	=> $course_id,
1042
+								'post_status'      	=> 'publish',
1043
+								'suppress_filters' 	=> 0,
1044 1044
 								'fields'            => 'ids', // less data to retrieve
1045
-		    				);
1045
+							);
1046 1046
 		$lessons_array = get_posts( $lesson_args );
1047 1047
 		$count = count( $lessons_array );
1048 1048
 		return $count;
@@ -1060,17 +1060,17 @@  discard block
 block discarded – undo
1060 1060
 
1061 1061
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1062 1062
 								'posts_per_page' 		=> -1,
1063
-		    					'meta_key'        	=> '_lesson_course',
1064
-    							'meta_value'      	=> $course_id,
1065
-    	    					'post_status'      	=> 'publish',
1066
-    	    					'suppress_filters' 	=> 0,
1063
+								'meta_key'        	=> '_lesson_course',
1064
+								'meta_value'      	=> $course_id,
1065
+								'post_status'      	=> 'publish',
1066
+								'suppress_filters' 	=> 0,
1067 1067
 								'fields'            => 'ids', // less data to retrieve
1068
-		    				);
1068
+							);
1069 1069
 		$lessons_array = get_posts( $lesson_args );
1070 1070
 
1071
-        $count = count( $lessons_array );
1071
+		$count = count( $lessons_array );
1072 1072
 
1073
-        return $count;
1073
+		return $count;
1074 1074
 
1075 1075
 	} // End course_lesson_count()
1076 1076
 
@@ -1085,9 +1085,9 @@  discard block
 block discarded – undo
1085 1085
 
1086 1086
 		$lesson_args = array(	'post_type' 		=> 'lesson',
1087 1087
 								'posts_per_page' 		=> -1,
1088
-    	    					'post_status'      	=> 'publish',
1089
-    	    					'suppress_filters' 	=> 0,
1090
-    	    					'meta_query' => array(
1088
+								'post_status'      	=> 'publish',
1089
+								'suppress_filters' 	=> 0,
1090
+								'meta_query' => array(
1091 1091
 									array(
1092 1092
 										'key' => '_lesson_course',
1093 1093
 										'value' => $course_id
@@ -1098,12 +1098,12 @@  discard block
 block discarded – undo
1098 1098
 									)
1099 1099
 								),
1100 1100
 								'fields'            => 'ids', // less data to retrieve
1101
-		    				);
1101
+							);
1102 1102
 		$lessons_array = get_posts( $lesson_args );
1103 1103
 
1104 1104
 		$count = count( $lessons_array );
1105 1105
 
1106
-        return $count;
1106
+		return $count;
1107 1107
 
1108 1108
 	} // End course_lesson_count()
1109 1109
 
@@ -1122,8 +1122,8 @@  discard block
 block discarded – undo
1122 1122
 			$post_args = array(	'post_type' 		=> 'course',
1123 1123
 								'posts_per_page' 		=> -1,
1124 1124
 								'meta_key'        	=> '_course_woocommerce_product',
1125
-	    						'meta_value'      	=> $product_id,
1126
-	    						'post_status'       => 'publish',
1125
+								'meta_value'      	=> $product_id,
1126
+								'post_status'       => 'publish',
1127 1127
 								'suppress_filters' 	=> 0,
1128 1128
 								'orderby' 			=> 'menu_order date',
1129 1129
 								'order' 			=> 'ASC',
@@ -1155,9 +1155,9 @@  discard block
 block discarded – undo
1155 1155
 
1156 1156
 	/**
1157 1157
 	 * load_user_courses_content generates HTML for user's active & completed courses
1158
-     *
1159
-     * This function also ouputs the html so no need to echo the content.
1160
-     *
1158
+	 *
1159
+	 * This function also ouputs the html so no need to echo the content.
1160
+	 *
1161 1161
 	 * @since  1.4.0
1162 1162
 	 * @param  object  $user   Queried user object
1163 1163
 	 * @param  boolean $manage Whether the user has permission to manage the courses
@@ -1166,17 +1166,17 @@  discard block
 block discarded – undo
1166 1166
 	public function load_user_courses_content( $user = false ) {
1167 1167
 		global $course, $my_courses_page, $my_courses_section;
1168 1168
 
1169
-        if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1170
-            || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1169
+		if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1170
+			|| ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1171 1171
 
1172
-            // do not show the content if the settings doesn't allow for it
1173
-            return;
1172
+			// do not show the content if the settings doesn't allow for it
1173
+			return;
1174 1174
 
1175
-        }
1175
+		}
1176 1176
 
1177
-        $manage = ( $user->ID == get_current_user_id() ) ? true : false;
1177
+		$manage = ( $user->ID == get_current_user_id() ) ? true : false;
1178 1178
 
1179
-        do_action( 'sensei_before_learner_course_content', $user );
1179
+		do_action( 'sensei_before_learner_course_content', $user );
1180 1180
 
1181 1181
 		// Build Output HTML
1182 1182
 		$complete_html = $active_html = '';
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 			// Logic for Active and Completed Courses
1192 1192
 			$per_page = 20;
1193 1193
 			if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] )
1194
-                && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1194
+				&& ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1195 1195
 
1196 1196
 				$per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1197 1197
 
@@ -1237,117 +1237,117 @@  discard block
 block discarded – undo
1237 1237
 					}
1238 1238
 				}
1239 1239
 
1240
-			    // Get Course Categories
1241
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1240
+				// Get Course Categories
1241
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1242 1242
 
1243
-                $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1243
+				$active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1244 1244
 
1245
-                // Image
1246
-                $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1245
+				// Image
1246
+				$active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1247 1247
 
1248
-                // Title
1249
-                $active_html .= '<header>';
1248
+				// Title
1249
+				$active_html .= '<header>';
1250 1250
 
1251
-                $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1251
+				$active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1252 1252
 
1253
-                $active_html .= '</header>';
1253
+				$active_html .= '</header>';
1254 1254
 
1255
-                $active_html .= '<section class="entry">';
1255
+				$active_html .= '<section class="entry">';
1256 1256
 
1257
-                $active_html .= '<p class="sensei-course-meta">';
1257
+				$active_html .= '<p class="sensei-course-meta">';
1258 1258
 
1259
-                // Author
1260
-                $user_info = get_userdata( absint( $course_item->post_author ) );
1261
-                if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1262
-                    && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1259
+				// Author
1260
+				$user_info = get_userdata( absint( $course_item->post_author ) );
1261
+				if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1262
+					&& ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1263 1263
 
1264
-                    $active_html .= '<span class="course-author">'
1265
-                        . __( 'by ', 'woothemes-sensei' )
1266
-                        . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1267
-                        . '" title="' . esc_attr( $user_info->display_name ) . '">'
1268
-                        . esc_html( $user_info->display_name )
1269
-                        . '</a></span>';
1264
+					$active_html .= '<span class="course-author">'
1265
+						. __( 'by ', 'woothemes-sensei' )
1266
+						. '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1267
+						. '" title="' . esc_attr( $user_info->display_name ) . '">'
1268
+						. esc_html( $user_info->display_name )
1269
+						. '</a></span>';
1270 1270
 
1271
-                } // End If Statement
1271
+				} // End If Statement
1272 1272
 
1273
-                // Lesson count for this author
1274
-                $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1275
-                // Handle Division by Zero
1276
-                if ( 0 == $lesson_count ) {
1273
+				// Lesson count for this author
1274
+				$lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1275
+				// Handle Division by Zero
1276
+				if ( 0 == $lesson_count ) {
1277 1277
 
1278
-                    $lesson_count = 1;
1278
+					$lesson_count = 1;
1279 1279
 
1280
-                } // End If Statement
1281
-                $active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1282
-                // Course Categories
1283
-                if ( '' != $category_output ) {
1280
+				} // End If Statement
1281
+				$active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1282
+				// Course Categories
1283
+				if ( '' != $category_output ) {
1284 1284
 
1285
-                    $active_html .= '<span class="course-category">' . sprintf( __( 'Categories: %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1285
+					$active_html .= '<span class="course-category">' . sprintf( __( 'Categories: %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1286 1286
 
1287
-                } // End If Statement
1288
-                $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1287
+				} // End If Statement
1288
+				$active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1289 1289
 
1290
-                $active_html .= '</p>';
1290
+				$active_html .= '</p>';
1291 1291
 
1292
-                $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1292
+				$active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1293 1293
 
1294 1294
 
1295 1295
 
1296
-                $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1296
+				$progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1297 1297
 
1298
-                $active_html .= $this->get_progress_meter( $progress_percentage );
1298
+				$active_html .= $this->get_progress_meter( $progress_percentage );
1299 1299
 
1300
-                $active_html .= '</section>';
1300
+				$active_html .= '</section>';
1301 1301
 
1302
-                if( is_user_logged_in() ) {
1302
+				if( is_user_logged_in() ) {
1303 1303
 
1304
-                    $active_html .= '<section class="entry-actions">';
1304
+					$active_html .= '<section class="entry-actions">';
1305 1305
 
1306
-                    $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1306
+					$active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1307 1307
 
1308
-                    $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1308
+					$active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1309 1309
 
1310
-                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1310
+					$active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1311 1311
 
1312
-                    if ( 0 < absint( count( $course_lessons ) )
1313
-                        && Sensei()->settings->settings['course_completion'] == 'complete' ){
1312
+					if ( 0 < absint( count( $course_lessons ) )
1313
+						&& Sensei()->settings->settings['course_completion'] == 'complete' ){
1314 1314
 
1315
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1316
-                            .  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1315
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1316
+							.  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1317 1317
 
1318
-                    } // End If Statement
1318
+					} // End If Statement
1319 1319
 
1320
-                    $course_purchased = false;
1321
-                    if ( Sensei_WC::is_woocommerce_active() ) {
1320
+					$course_purchased = false;
1321
+					if ( Sensei_WC::is_woocommerce_active() ) {
1322 1322
 
1323
-                        // Get the product ID
1324
-                        $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1325
-                        if ( 0 < $wc_post_id ) {
1323
+						// Get the product ID
1324
+						$wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1325
+						if ( 0 < $wc_post_id ) {
1326 1326
 
1327
-                            $course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1327
+							$course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1328 1328
 
1329
-                        } // End If Statement
1329
+						} // End If Statement
1330 1330
 
1331
-                    } // End If Statement
1331
+					} // End If Statement
1332 1332
 
1333
-	                /**
1334
-	                 * documented in class-sensei-course.php the_course_action_buttons function
1335
-	                 */
1336
-	                $show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
1333
+					/**
1334
+					 * documented in class-sensei-course.php the_course_action_buttons function
1335
+					 */
1336
+					$show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
1337 1337
 
1338
-                    if ( false == $course_purchased && $show_delete_course_button ) {
1338
+					if ( false == $course_purchased && $show_delete_course_button ) {
1339 1339
 
1340
-                        $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1341
-                            .  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1340
+						$active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1341
+							.  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1342 1342
 
1343
-                    } // End If Statement
1343
+					} // End If Statement
1344 1344
 
1345
-                    $active_html .= '</form>';
1345
+					$active_html .= '</form>';
1346 1346
 
1347
-                    $active_html .= '</section>';
1348
-                }
1347
+					$active_html .= '</section>';
1348
+				}
1349 1349
 
1350
-                $active_html .= '</article>';
1350
+				$active_html .= '</article>';
1351 1351
 			}
1352 1352
 
1353 1353
 			// Active pagination
@@ -1387,49 +1387,49 @@  discard block
 block discarded – undo
1387 1387
 			foreach ( $completed_courses as $course_item ) {
1388 1388
 				$course = $course_item;
1389 1389
 
1390
-			    // Get Course Categories
1391
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1390
+				// Get Course Categories
1391
+				$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1392 1392
 
1393
-		    	$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1393
+				$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1394 1394
 
1395
-		    	    // Image
1396
-		    		$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1395
+					// Image
1396
+					$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1397 1397
 
1398
-		    		// Title
1399
-		    		$complete_html .= '<header>';
1398
+					// Title
1399
+					$complete_html .= '<header>';
1400 1400
 
1401
-		    		    $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1401
+						$complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1402 1402
 
1403
-		    		$complete_html .= '</header>';
1403
+					$complete_html .= '</header>';
1404 1404
 
1405
-		    		$complete_html .= '<section class="entry">';
1405
+					$complete_html .= '<section class="entry">';
1406 1406
 
1407
-		    			$complete_html .= '<p class="sensei-course-meta">';
1407
+						$complete_html .= '<p class="sensei-course-meta">';
1408 1408
 
1409
-		    		    	// Author
1410
-		    		    	$user_info = get_userdata( absint( $course_item->post_author ) );
1411
-		    		    	if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1412
-		    		    		$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1413
-		    		    	} // End If Statement
1409
+							// Author
1410
+							$user_info = get_userdata( absint( $course_item->post_author ) );
1411
+							if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1412
+								$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1413
+							} // End If Statement
1414 1414
 
1415
-		    		    	// Lesson count for this author
1416
-		    		    	$complete_html .= '<span class="course-lesson-count">'
1417
-                                . Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1418
-                                . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1419
-                                . '</span>';
1415
+							// Lesson count for this author
1416
+							$complete_html .= '<span class="course-lesson-count">'
1417
+								. Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1418
+								. '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1419
+								. '</span>';
1420 1420
 
1421
-		    		    	// Course Categories
1422
-		    		    	if ( '' != $category_output ) {
1421
+							// Course Categories
1422
+							if ( '' != $category_output ) {
1423 1423
 
1424
-		    		    		$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1424
+								$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1425 1425
 
1426
-		    		    	} // End If Statement
1426
+							} // End If Statement
1427 1427
 
1428 1428
 						$complete_html .= '</p>';
1429 1429
 
1430 1430
 						$complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1431 1431
 
1432
-                        $complete_html .= $this->get_progress_meter( 100 );
1432
+						$complete_html .= $this->get_progress_meter( 100 );
1433 1433
 
1434 1434
 						if( $manage ) {
1435 1435
 							$has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
@@ -1442,22 +1442,22 @@  discard block
 block discarded – undo
1442 1442
 								if( $has_quizzes ) {
1443 1443
 
1444 1444
 									$results_link = '<a class="button view-results" href="'
1445
-                                        . Sensei()->course_results->get_permalink( $course_item->ID )
1446
-                                        . '">' . __( 'View results', 'woothemes-sensei' )
1447
-                                        . '</a>';
1445
+										. Sensei()->course_results->get_permalink( $course_item->ID )
1446
+										. '">' . __( 'View results', 'woothemes-sensei' )
1447
+										. '</a>';
1448 1448
 								}
1449
-                                /**
1450
-                                 * Filter documented in Sensei_Course::the_course_action_buttons
1451
-                                 */
1449
+								/**
1450
+								 * Filter documented in Sensei_Course::the_course_action_buttons
1451
+								 */
1452 1452
 								$complete_html .= apply_filters( 'sensei_results_links', $results_link, $course_item->ID );
1453 1453
 								$complete_html .= '</p>';
1454 1454
 
1455 1455
 							}
1456 1456
 						}
1457 1457
 
1458
-		    		$complete_html .= '</section>';
1458
+					$complete_html .= '</section>';
1459 1459
 
1460
-		    	$complete_html .= '</article>';
1460
+				$complete_html .= '</article>';
1461 1461
 			}
1462 1462
 
1463 1463
 			// Active pagination
@@ -1532,16 +1532,16 @@  discard block
 block discarded – undo
1532 1532
 		    <?php do_action( 'sensei_before_active_user_courses' ); ?>
1533 1533
 
1534 1534
 		    <?php
1535
-            $course_page_url = Sensei_Course::get_courses_page_url();
1536
-            ?>
1535
+			$course_page_url = Sensei_Course::get_courses_page_url();
1536
+			?>
1537 1537
 
1538 1538
 		    <div id="active-courses">
1539 1539
 
1540 1540
 		    	<?php if ( '' != $active_html ) {
1541 1541
 
1542
-		    		echo $active_html;
1542
+					echo $active_html;
1543 1543
 
1544
-		    	} else { ?>
1544
+				} else { ?>
1545 1545
 
1546 1546
 		    		<div class="sensei-message info">
1547 1547
 
@@ -1567,9 +1567,9 @@  discard block
 block discarded – undo
1567 1567
 
1568 1568
 		    	<?php if ( '' != $complete_html ) {
1569 1569
 
1570
-		    		echo $complete_html;
1570
+					echo $complete_html;
1571 1571
 
1572
-		    	} else { ?>
1572
+				} else { ?>
1573 1573
 
1574 1574
 		    		<div class="sensei-message info">
1575 1575
 
@@ -1588,356 +1588,356 @@  discard block
 block discarded – undo
1588 1588
 		<?php do_action( 'sensei_after_user_courses' ); ?>
1589 1589
 
1590 1590
 		<?php
1591
-        echo ob_get_clean();
1591
+		echo ob_get_clean();
1592 1592
 
1593
-        do_action( 'sensei_after_learner_course_content', $user );
1593
+		do_action( 'sensei_after_learner_course_content', $user );
1594 1594
 
1595 1595
 	} // end load_user_courses_content
1596 1596
 
1597
-    /**
1598
-     * Returns a list of all courses
1599
-     *
1600
-     * @since 1.8.0
1601
-     * @return array $courses{
1602
-     *  @type $course WP_Post
1603
-     * }
1604
-     */
1605
-    public static function get_all_courses(){
1606
-
1607
-        $args = array(
1608
-               'post_type' => 'course',
1609
-                'posts_per_page' 		=> -1,
1610
-                'orderby'         	=> 'title',
1611
-                'order'           	=> 'ASC',
1612
-                'post_status'      	=> 'any',
1613
-                'suppress_filters' 	=> 0,
1614
-        );
1615
-
1616
-        $wp_query_obj =  new WP_Query( $args );
1617
-
1618
-        /**
1619
-         * sensei_get_all_courses filter
1620
-         *
1621
-         * This filter runs inside Sensei_Course::get_all_courses.
1622
-         *
1623
-         * @param array $courses{
1624
-         *  @type WP_Post
1625
-         * }
1626
-         * @param array $attributes
1627
-         */
1628
-        return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1629
-
1630
-    }// end get_all_courses
1631
-
1632
-    /**
1633
-     * Generate the course meter component
1634
-     *
1635
-     * @since 1.8.0
1636
-     * @param int $progress_percentage 0 - 100
1637
-     * @return string $progress_bar_html
1638
-     */
1639
-    public function get_progress_meter( $progress_percentage ){
1640
-
1641
-        if ( 50 < $progress_percentage ) {
1642
-            $class = ' green completed';
1643
-        } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1644
-            $class = ' orange progressing';
1645
-        } else {
1646
-            $class = ' red starting';
1647
-        }
1648
-        $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1649
-
1650
-        return $progress_bar_html;
1651
-
1652
-    }// end get_progress_meter
1653
-
1654
-    /**
1655
-     * Generate a statement that tells users
1656
-     * how far they are in the course.
1657
-     *
1658
-     * @param int $course_id
1659
-     * @param int $user_id
1660
-     *
1661
-     * @return string $statement_html
1662
-     */
1663
-    public function get_progress_statement( $course_id, $user_id ){
1664
-
1665
-        if( empty( $course_id ) || empty( $user_id )
1666
-        || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1667
-            return '';
1668
-        }
1669
-
1670
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1671
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1672
-
1673
-        $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1674
-
1675
-        /**
1676
-         * Filter the course completion statement.
1677
-         * Default Currently completed $var lesson($plural) of $var in total
1678
-         *
1679
-         * @param string $statement
1680
-         */
1681
-        return apply_filters( 'sensei_course_completion_statement', $statement );
1682
-
1683
-    }// end generate_progress_statement
1684
-
1685
-    /**
1686
-     * Output the course progress statement
1687
-     *
1688
-     * @param $course_id
1689
-     * @return void
1690
-     */
1691
-    public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1692
-        if( empty( $course_id ) ){
1693
-            global $post;
1694
-            $course_id = $post->ID;
1695
-        }
1696
-
1697
-        if( empty( $user_id ) ){
1698
-            $user_id = get_current_user_id();
1699
-        }
1700
-
1701
-        echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1702
-    }
1703
-
1704
-    /**
1705
-     * Output the course progress bar
1706
-     *
1707
-     * @param $course_id
1708
-     * @return void
1709
-     */
1710
-    public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1711
-
1712
-        if( empty( $course_id ) ){
1713
-            global $post;
1714
-            $course_id = $post->ID;
1715
-        }
1716
-
1717
-        if( empty( $user_id ) ){
1718
-            $user_id = get_current_user_id();
1719
-        }
1720
-
1721
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1722
-            || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1723
-            return;
1724
-        }
1725
-        $percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1726
-
1727
-        echo $this->get_progress_meter( $percentage_completed );
1728
-
1729
-    }// end the_progress_meter
1730
-
1731
-    /**
1732
-     * Checks how many lessons are completed
1733
-     *
1734
-     * @since 1.8.0
1735
-     *
1736
-     * @param int $course_id
1737
-     * @param int $user_id
1738
-     * @return array $completed_lesson_ids
1739
-     */
1740
-    public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1741
-
1742
-        if( !( intval( $user_id ) ) > 0 ){
1743
-            $user_id = get_current_user_id();
1744
-        }
1597
+	/**
1598
+	 * Returns a list of all courses
1599
+	 *
1600
+	 * @since 1.8.0
1601
+	 * @return array $courses{
1602
+	 *  @type $course WP_Post
1603
+	 * }
1604
+	 */
1605
+	public static function get_all_courses(){
1606
+
1607
+		$args = array(
1608
+			   'post_type' => 'course',
1609
+				'posts_per_page' 		=> -1,
1610
+				'orderby'         	=> 'title',
1611
+				'order'           	=> 'ASC',
1612
+				'post_status'      	=> 'any',
1613
+				'suppress_filters' 	=> 0,
1614
+		);
1615
+
1616
+		$wp_query_obj =  new WP_Query( $args );
1617
+
1618
+		/**
1619
+		 * sensei_get_all_courses filter
1620
+		 *
1621
+		 * This filter runs inside Sensei_Course::get_all_courses.
1622
+		 *
1623
+		 * @param array $courses{
1624
+		 *  @type WP_Post
1625
+		 * }
1626
+		 * @param array $attributes
1627
+		 */
1628
+		return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1629
+
1630
+	}// end get_all_courses
1631
+
1632
+	/**
1633
+	 * Generate the course meter component
1634
+	 *
1635
+	 * @since 1.8.0
1636
+	 * @param int $progress_percentage 0 - 100
1637
+	 * @return string $progress_bar_html
1638
+	 */
1639
+	public function get_progress_meter( $progress_percentage ){
1640
+
1641
+		if ( 50 < $progress_percentage ) {
1642
+			$class = ' green completed';
1643
+		} elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1644
+			$class = ' orange progressing';
1645
+		} else {
1646
+			$class = ' red starting';
1647
+		}
1648
+		$progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1649
+
1650
+		return $progress_bar_html;
1651
+
1652
+	}// end get_progress_meter
1653
+
1654
+	/**
1655
+	 * Generate a statement that tells users
1656
+	 * how far they are in the course.
1657
+	 *
1658
+	 * @param int $course_id
1659
+	 * @param int $user_id
1660
+	 *
1661
+	 * @return string $statement_html
1662
+	 */
1663
+	public function get_progress_statement( $course_id, $user_id ){
1664
+
1665
+		if( empty( $course_id ) || empty( $user_id )
1666
+		|| ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1667
+			return '';
1668
+		}
1669
+
1670
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1671
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1672
+
1673
+		$statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1674
+
1675
+		/**
1676
+		 * Filter the course completion statement.
1677
+		 * Default Currently completed $var lesson($plural) of $var in total
1678
+		 *
1679
+		 * @param string $statement
1680
+		 */
1681
+		return apply_filters( 'sensei_course_completion_statement', $statement );
1682
+
1683
+	}// end generate_progress_statement
1684
+
1685
+	/**
1686
+	 * Output the course progress statement
1687
+	 *
1688
+	 * @param $course_id
1689
+	 * @return void
1690
+	 */
1691
+	public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1692
+		if( empty( $course_id ) ){
1693
+			global $post;
1694
+			$course_id = $post->ID;
1695
+		}
1696
+
1697
+		if( empty( $user_id ) ){
1698
+			$user_id = get_current_user_id();
1699
+		}
1700
+
1701
+		echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1702
+	}
1703
+
1704
+	/**
1705
+	 * Output the course progress bar
1706
+	 *
1707
+	 * @param $course_id
1708
+	 * @return void
1709
+	 */
1710
+	public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1711
+
1712
+		if( empty( $course_id ) ){
1713
+			global $post;
1714
+			$course_id = $post->ID;
1715
+		}
1716
+
1717
+		if( empty( $user_id ) ){
1718
+			$user_id = get_current_user_id();
1719
+		}
1720
+
1721
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1722
+			|| ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1723
+			return;
1724
+		}
1725
+		$percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1726
+
1727
+		echo $this->get_progress_meter( $percentage_completed );
1728
+
1729
+	}// end the_progress_meter
1730
+
1731
+	/**
1732
+	 * Checks how many lessons are completed
1733
+	 *
1734
+	 * @since 1.8.0
1735
+	 *
1736
+	 * @param int $course_id
1737
+	 * @param int $user_id
1738
+	 * @return array $completed_lesson_ids
1739
+	 */
1740
+	public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1741
+
1742
+		if( !( intval( $user_id ) ) > 0 ){
1743
+			$user_id = get_current_user_id();
1744
+		}
1745
+
1746
+		$completed_lesson_ids = array();
1747
+
1748
+		$course_lessons = $this->course_lessons( $course_id );
1749
+
1750
+		foreach( $course_lessons as $lesson ){
1751
+
1752
+			$is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1753
+			if( $is_lesson_completed ){
1754
+				$completed_lesson_ids[] = $lesson->ID;
1755
+			}
1756
+
1757
+		}
1758
+
1759
+		return $completed_lesson_ids;
1760
+
1761
+	}// end get_completed_lesson_ids
1762
+
1763
+	/**
1764
+	 * Calculate the perceantage completed in the course
1765
+	 *
1766
+	 * @since 1.8.0
1767
+	 *
1768
+	 * @param int $course_id
1769
+	 * @param int $user_id
1770
+	 * @return int $percentage
1771
+	 */
1772
+	public function get_completion_percentage( $course_id, $user_id = 0 ){
1773
+
1774
+		if( !( intval( $user_id ) ) > 0 ){
1775
+			$user_id = get_current_user_id();
1776
+		}
1777
+
1778
+		$completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1779
+
1780
+		if( ! (  $completed  > 0 ) ){
1781
+			return 0;
1782
+		}
1783
+
1784
+		$total_lessons = count( $this->course_lessons( $course_id ) );
1785
+		$percentage = $completed / $total_lessons * 100;
1786
+
1787
+		/**
1788
+		 *
1789
+		 * Filter the percentage returned for a users course.
1790
+		 *
1791
+		 * @param $percentage
1792
+		 * @param $course_id
1793
+		 * @param $user_id
1794
+		 * @since 1.8.0
1795
+		 */
1796
+		return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1797
+
1798
+	}// end get_completed_lesson_ids
1745 1799
 
1746
-        $completed_lesson_ids = array();
1800
+	/**
1801
+	 * Block email notifications for the specific courses
1802
+	 * that the user disabled the notifications.
1803
+	 *
1804
+	 * @since 1.8.0
1805
+	 * @param $should_send
1806
+	 * @return bool
1807
+	 */
1808
+	public function block_notification_emails( $should_send ){
1809
+		global $sensei_email_data;
1810
+		$email = $sensei_email_data;
1747 1811
 
1748
-        $course_lessons = $this->course_lessons( $course_id );
1812
+		$course_id = '';
1749 1813
 
1750
-        foreach( $course_lessons as $lesson ){
1814
+		if( isset( $email['course_id'] ) ){
1751 1815
 
1752
-            $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1753
-            if( $is_lesson_completed ){
1754
-                $completed_lesson_ids[] = $lesson->ID;
1755
-            }
1756
-
1757
-        }
1758
-
1759
-        return $completed_lesson_ids;
1816
+			$course_id = $email['course_id'];
1760 1817
 
1761
-    }// end get_completed_lesson_ids
1818
+		}elseif( isset( $email['lesson_id'] ) ){
1762 1819
 
1763
-    /**
1764
-     * Calculate the perceantage completed in the course
1765
-     *
1766
-     * @since 1.8.0
1767
-     *
1768
-     * @param int $course_id
1769
-     * @param int $user_id
1770
-     * @return int $percentage
1771
-     */
1772
-    public function get_completion_percentage( $course_id, $user_id = 0 ){
1773
-
1774
-        if( !( intval( $user_id ) ) > 0 ){
1775
-            $user_id = get_current_user_id();
1776
-        }
1777
-
1778
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1779
-
1780
-        if( ! (  $completed  > 0 ) ){
1781
-            return 0;
1782
-        }
1783
-
1784
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1785
-        $percentage = $completed / $total_lessons * 100;
1786
-
1787
-        /**
1788
-         *
1789
-         * Filter the percentage returned for a users course.
1790
-         *
1791
-         * @param $percentage
1792
-         * @param $course_id
1793
-         * @param $user_id
1794
-         * @since 1.8.0
1795
-         */
1796
-        return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1820
+			$course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1797 1821
 
1798
-    }// end get_completed_lesson_ids
1822
+		}elseif( isset( $email['quiz_id'] ) ){
1799 1823
 
1800
-    /**
1801
-     * Block email notifications for the specific courses
1802
-     * that the user disabled the notifications.
1803
-     *
1804
-     * @since 1.8.0
1805
-     * @param $should_send
1806
-     * @return bool
1807
-     */
1808
-    public function block_notification_emails( $should_send ){
1809
-        global $sensei_email_data;
1810
-        $email = $sensei_email_data;
1824
+			$lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1825
+			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1811 1826
 
1812
-        $course_id = '';
1827
+		}
1813 1828
 
1814
-        if( isset( $email['course_id'] ) ){
1829
+		if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1815 1830
 
1816
-            $course_id = $email['course_id'];
1817
-
1818
-        }elseif( isset( $email['lesson_id'] ) ){
1831
+			$course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1819 1832
 
1820
-            $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1833
+			if ($course_emails_disabled) {
1821 1834
 
1822
-        }elseif( isset( $email['quiz_id'] ) ){
1835
+				return false;
1823 1836
 
1824
-            $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1825
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1837
+			}
1826 1838
 
1827
-        }
1839
+		}// end if
1828 1840
 
1829
-        if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1830
-
1831
-            $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1832
-
1833
-            if ($course_emails_disabled) {
1834
-
1835
-                return false;
1836
-
1837
-            }
1838
-
1839
-        }// end if
1840
-
1841
-        return $should_send;
1842
-    }// end block_notification_emails
1843
-
1844
-    /**
1845
-     * Render the course notification setting meta box
1846
-     *
1847
-     * @since 1.8.0
1848
-     * @param $course
1849
-     */
1850
-    public function course_notification_meta_box_content( $course ){
1851
-
1852
-        $checked = get_post_meta( $course->ID , 'disable_notification', true );
1853
-
1854
-        // generate checked html
1855
-        $checked_html = '';
1856
-        if( $checked ){
1857
-            $checked_html = 'checked="checked"';
1858
-        }
1859
-        wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1860
-
1861
-        echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1862
-        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1863
-
1864
-    }// end course_notification_meta_box_content
1865
-
1866
-    /**
1867
-     * Store the setting for the course notification setting.
1868
-     *
1869
-     * @hooked int save_post
1870
-     * @since 1.8.0
1871
-     *
1872
-     * @param $course_id
1873
-     */
1874
-    public function save_course_notification_meta_box( $course_id ){
1875
-
1876
-        if( !isset( $_POST['_sensei_course_notification']  )
1877
-            || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1878
-            return;
1879
-        }
1880
-
1881
-        if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1882
-            $new_val = true;
1883
-        }else{
1884
-            $new_val = false;
1885
-        }
1886
-
1887
-       update_post_meta( $course_id , 'disable_notification', $new_val );
1888
-
1889
-    }// end save notification meta box
1890
-
1891
-    /**
1892
-     * Backwards compatibility hooks added to ensure that
1893
-     * plugins and other parts of sensei still works.
1894
-     *
1895
-     * This function hooks into `sensei_course_content_inside_before`
1896
-     *
1897
-     * @since 1.9
1898
-     *
1899
-     * @param WP_Post $post
1900
-     */
1901
-    public function content_before_backwards_compatibility_hooks( $post_id ){
1902
-
1903
-        sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1904
-        sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1905
-
1906
-    }
1841
+		return $should_send;
1842
+	}// end block_notification_emails
1907 1843
 
1908
-    /**
1909
-     * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1910
-     *
1911
-     * hooked into 'sensei_loop_course_before'
1912
-     *
1913
-     * @since 1.9
1914
-     *
1915
-     * @global WP_Post $post
1916
-     */
1917
-    public  function loop_before_backwards_compatibility_hooks( ){
1918
-
1919
-        global $post;
1920
-        sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1921
-
1922
-    }
1923
-
1924
-    /**
1925
-     * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1926
-     *
1927
-     * hooked into 'sensei_course_content_inside_after'
1928
-     *
1929
-     * @since 1.9.0
1930
-     *
1931
-     * @param integer $course_id
1932
-     */
1933
-    public function the_course_free_lesson_preview( $course_id ){
1934
-        // Meta data
1935
-        $course = get_post( $course_id );
1936
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1937
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1938
-
1939
-        if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1940
-            ?>
1844
+	/**
1845
+	 * Render the course notification setting meta box
1846
+	 *
1847
+	 * @since 1.8.0
1848
+	 * @param $course
1849
+	 */
1850
+	public function course_notification_meta_box_content( $course ){
1851
+
1852
+		$checked = get_post_meta( $course->ID , 'disable_notification', true );
1853
+
1854
+		// generate checked html
1855
+		$checked_html = '';
1856
+		if( $checked ){
1857
+			$checked_html = 'checked="checked"';
1858
+		}
1859
+		wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1860
+
1861
+		echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1862
+		echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1863
+
1864
+	}// end course_notification_meta_box_content
1865
+
1866
+	/**
1867
+	 * Store the setting for the course notification setting.
1868
+	 *
1869
+	 * @hooked int save_post
1870
+	 * @since 1.8.0
1871
+	 *
1872
+	 * @param $course_id
1873
+	 */
1874
+	public function save_course_notification_meta_box( $course_id ){
1875
+
1876
+		if( !isset( $_POST['_sensei_course_notification']  )
1877
+			|| ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1878
+			return;
1879
+		}
1880
+
1881
+		if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1882
+			$new_val = true;
1883
+		}else{
1884
+			$new_val = false;
1885
+		}
1886
+
1887
+	   update_post_meta( $course_id , 'disable_notification', $new_val );
1888
+
1889
+	}// end save notification meta box
1890
+
1891
+	/**
1892
+	 * Backwards compatibility hooks added to ensure that
1893
+	 * plugins and other parts of sensei still works.
1894
+	 *
1895
+	 * This function hooks into `sensei_course_content_inside_before`
1896
+	 *
1897
+	 * @since 1.9
1898
+	 *
1899
+	 * @param WP_Post $post
1900
+	 */
1901
+	public function content_before_backwards_compatibility_hooks( $post_id ){
1902
+
1903
+		sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1904
+		sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1905
+
1906
+	}
1907
+
1908
+	/**
1909
+	 * Backwards compatibility hooks that should be hooked into sensei_loop_course_before
1910
+	 *
1911
+	 * hooked into 'sensei_loop_course_before'
1912
+	 *
1913
+	 * @since 1.9
1914
+	 *
1915
+	 * @global WP_Post $post
1916
+	 */
1917
+	public  function loop_before_backwards_compatibility_hooks( ){
1918
+
1919
+		global $post;
1920
+		sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1921
+
1922
+	}
1923
+
1924
+	/**
1925
+	 * Output a link to view course. The button text is different depending on the amount of preview lesson available.
1926
+	 *
1927
+	 * hooked into 'sensei_course_content_inside_after'
1928
+	 *
1929
+	 * @since 1.9.0
1930
+	 *
1931
+	 * @param integer $course_id
1932
+	 */
1933
+	public function the_course_free_lesson_preview( $course_id ){
1934
+		// Meta data
1935
+		$course = get_post( $course_id );
1936
+		$preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1937
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1938
+
1939
+		if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1940
+			?>
1941 1941
             <p class="sensei-free-lessons">
1942 1942
                 <a href="<?php echo get_permalink(); ?>">
1943 1943
                     <?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
@@ -1946,23 +1946,23 @@  discard block
 block discarded – undo
1946 1946
             </p>
1947 1947
 
1948 1948
         <?php
1949
-        }
1950
-    }
1949
+		}
1950
+	}
1951 1951
 
1952
-    /**
1953
-     * Add course mata to the course meta hook
1954
-     *
1955
-     * @since 1.9.0
1956
-     * @param integer $course_id
1957
-     */
1958
-    public function the_course_meta( $course_id ){
1959
-        echo '<p class="sensei-course-meta">';
1952
+	/**
1953
+	 * Add course mata to the course meta hook
1954
+	 *
1955
+	 * @since 1.9.0
1956
+	 * @param integer $course_id
1957
+	 */
1958
+	public function the_course_meta( $course_id ){
1959
+		echo '<p class="sensei-course-meta">';
1960 1960
 
1961
-        $course = get_post( $course_id );
1962
-        $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1963
-        $author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1961
+		$course = get_post( $course_id );
1962
+		$category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1963
+		$author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1964 1964
 
1965
-        if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1965
+		if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1966 1966
 
1967 1967
             <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?>
1968 1968
 
@@ -1980,62 +1980,62 @@  discard block
 block discarded – undo
1980 1980
 
1981 1981
         <?php } // End If Statement
1982 1982
 
1983
-        // number of completed lessons
1984
-        if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1985
-            || Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1983
+		// number of completed lessons
1984
+		if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1985
+			|| Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1986 1986
 
1987
-            $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1988
-            $lesson_count = count( $this->course_lessons( $course->ID ) );
1989
-            echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1987
+			$completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1988
+			$lesson_count = count( $this->course_lessons( $course->ID ) );
1989
+			echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1990 1990
 
1991
-        }
1991
+		}
1992 1992
 
1993
-        sensei_simple_course_price( $course->ID );
1993
+		sensei_simple_course_price( $course->ID );
1994 1994
 
1995
-        echo '</p>';
1996
-    } // end the course meta
1995
+		echo '</p>';
1996
+	} // end the course meta
1997 1997
 
1998
-    /**
1999
-     * Filter the classes attached to a post types for courses
2000
-     * and add a status class for when the user is logged in.
2001
-     *
2002
-     * @param $classes
2003
-     * @param $class
2004
-     * @param $post_id
2005
-     *
2006
-     * @return array $classes
2007
-     */
2008
-    public static function add_course_user_status_class( $classes, $class, $course_id ){
1998
+	/**
1999
+	 * Filter the classes attached to a post types for courses
2000
+	 * and add a status class for when the user is logged in.
2001
+	 *
2002
+	 * @param $classes
2003
+	 * @param $class
2004
+	 * @param $post_id
2005
+	 *
2006
+	 * @return array $classes
2007
+	 */
2008
+	public static function add_course_user_status_class( $classes, $class, $course_id ){
2009 2009
 
2010
-        if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2010
+		if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2011 2011
 
2012
-            if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2012
+			if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2013 2013
 
2014
-                $classes[] = 'user-status-completed';
2014
+				$classes[] = 'user-status-completed';
2015 2015
 
2016
-            }else{
2016
+			}else{
2017 2017
 
2018
-                $classes[] = 'user-status-active';
2018
+				$classes[] = 'user-status-active';
2019 2019
 
2020
-            }
2020
+			}
2021 2021
 
2022
-        }
2022
+		}
2023 2023
 
2024
-        return $classes;
2024
+		return $classes;
2025 2025
 
2026
-    }// end add_course_user_status_class
2026
+	}// end add_course_user_status_class
2027 2027
 
2028
-    /**
2029
-     * Prints out the course action buttons links
2030
-     *
2031
-     * - complete course
2032
-     * - delete course
2033
-     *
2034
-     * @param WP_Post $course
2035
-     */
2036
-    public static function the_course_action_buttons( $course ){
2028
+	/**
2029
+	 * Prints out the course action buttons links
2030
+	 *
2031
+	 * - complete course
2032
+	 * - delete course
2033
+	 *
2034
+	 * @param WP_Post $course
2035
+	 */
2036
+	public static function the_course_action_buttons( $course ){
2037 2037
 
2038
-        if( is_user_logged_in() ) { ?>
2038
+		if( is_user_logged_in() ) { ?>
2039 2039
 
2040 2040
             <section class="entry-actions">
2041 2041
                 <form method="POST" action="<?php  echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>">
@@ -2049,63 +2049,63 @@  discard block
 block discarded – undo
2049 2049
                     <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e( intval( $course->ID ) ); ?>" />
2050 2050
 
2051 2051
                     <?php if ( 0 < absint( count( Sensei()->course->course_lessons( $course->ID ) ) )
2052
-                        && Sensei()->settings->settings['course_completion'] == 'complete'
2053
-                        && ! Sensei_Utils::user_completed_course( $course, get_current_user_id() )) { ?>
2052
+						&& Sensei()->settings->settings['course_completion'] == 'complete'
2053
+						&& ! Sensei_Utils::user_completed_course( $course, get_current_user_id() )) { ?>
2054 2054
 
2055 2055
                         <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e( 'Mark as Complete', 'woothemes-sensei' ); ?>" /></span>
2056 2056
 
2057 2057
                    <?php  } // End If Statement
2058 2058
 
2059
-                    $course_purchased = false;
2060
-                    if ( Sensei_WC::is_woocommerce_active() ) {
2061
-                        // Get the product ID
2062
-                        $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2063
-                        if ( 0 < $wc_post_id ) {
2064
-
2065
-                            $user = wp_get_current_user();
2066
-                            $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2067
-
2068
-                        } // End If Statement
2069
-                    } // End If Statement
2070
-
2071
-                    /**
2072
-                     * Hide or show the delete course button.
2073
-                     *
2074
-                     * This button on shows in certain instances, but this filter will hide it in those
2075
-                     * cases. For other instances the button will be hidden.
2076
-                     *
2077
-                     * @since 1.9.0
2078
-                     * @param bool $show_delete_course_button defaults to false
2079
-                     */
2080
-                    $show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
2081
-
2082
-                    if ( ! $course_purchased
2083
-                         && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() )
2084
-                         && $show_delete_course_button ) { ?>
2059
+					$course_purchased = false;
2060
+					if ( Sensei_WC::is_woocommerce_active() ) {
2061
+						// Get the product ID
2062
+						$wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2063
+						if ( 0 < $wc_post_id ) {
2064
+
2065
+							$user = wp_get_current_user();
2066
+							$course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2067
+
2068
+						} // End If Statement
2069
+					} // End If Statement
2070
+
2071
+					/**
2072
+					 * Hide or show the delete course button.
2073
+					 *
2074
+					 * This button on shows in certain instances, but this filter will hide it in those
2075
+					 * cases. For other instances the button will be hidden.
2076
+					 *
2077
+					 * @since 1.9.0
2078
+					 * @param bool $show_delete_course_button defaults to false
2079
+					 */
2080
+					$show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
2081
+
2082
+					if ( ! $course_purchased
2083
+						 && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() )
2084
+						 && $show_delete_course_button ) { ?>
2085 2085
 
2086 2086
                         <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span>
2087 2087
 
2088 2088
                     <?php } // End If Statement
2089 2089
 
2090
-                    $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2091
-                    $results_link = '';
2092
-                    if( $has_quizzes ){
2093
-                        $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2094
-                    }
2090
+					$has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2091
+					$results_link = '';
2092
+					if( $has_quizzes ){
2093
+						$results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2094
+					}
2095 2095
 
2096
-                    // Output only if there is content to display
2097
-                    if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2096
+					// Output only if there is content to display
2097
+					if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2098 2098
 
2099 2099
                         <p class="sensei-results-links">
2100 2100
                             <?php
2101
-                            /**
2102
-                             * Filter the results links
2103
-                             *
2104
-                             * @param string $results_links_html
2105
-                             * @param integer $course_id
2106
-                             */
2107
-                            echo apply_filters( 'sensei_results_links', $results_link, $course->ID );
2108
-                            ?>
2101
+							/**
2102
+							 * Filter the results links
2103
+							 *
2104
+							 * @param string $results_links_html
2105
+							 * @param integer $course_id
2106
+							 */
2107
+							echo apply_filters( 'sensei_results_links', $results_link, $course->ID );
2108
+							?>
2109 2109
                         </p>
2110 2110
 
2111 2111
                     <?php } // end if has filter  ?>
@@ -2114,476 +2114,476 @@  discard block
 block discarded – undo
2114 2114
 
2115 2115
         <?php  }// end if is user logged in
2116 2116
 
2117
-    }// end the_course_action_buttons
2118
-
2119
-    /**
2120
-     * This function alter the main query on the course archive page.
2121
-     * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2122
-     *
2123
-     * This function targets only the course archives and the my courses page. Shortcodes can set their own
2124
-     * query parameters via the arguments.
2125
-     *
2126
-     * This function is hooked into pre_get_posts filter
2127
-     *
2128
-     * @since 1.9.0
2129
-     *
2130
-     * @param WP_Query $query
2131
-     * @return WP_Query $query
2132
-     */
2133
-    public static function course_query_filter( $query ){
2134
-
2135
-        // exit early for no course queries and admin queries
2136
-        if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2137
-            return $query;
2138
-        }
2139
-
2140
-        global $post; // used to get the current page id for my courses
2141
-
2142
-        // for the course archive page
2143
-        if( $query->is_main_query() && is_post_type_archive('course') )
2144
-        {
2145
-            /**
2146
-             * sensei_archive_courses_per_page
2147
-             *
2148
-             * Sensei courses per page on the course
2149
-             * archive
2150
-             *
2151
-             * @since 1.9.0
2152
-             * @param integer $posts_per_page default 10
2153
-             */
2154
-            $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2155
-
2156
-        }
2157
-        // for the my courses page
2158
-        elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2159
-        {
2160
-            /**
2161
-             * sensei_my_courses_per_page
2162
-             *
2163
-             * Sensei courses per page on the my courses page
2164
-             * as set in the settings
2165
-             *
2166
-             * @since 1.9.0
2167
-             * @param integer $posts_per_page default 10
2168
-             */
2169
-            $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2170
-
2171
-        }
2172
-
2173
-        return $query;
2174
-
2175
-    }// end course_query_filter
2176
-
2177
-    /**
2178
-     * Determine the class of the course loop
2179
-     *
2180
-     * This will output .first or .last and .course-item-number-x
2181
-     *
2182
-     * @return array $extra_classes
2183
-     * @since 1.9.0
2184
-     */
2185
-    public static function get_course_loop_content_class ()
2186
-    {
2187
-
2188
-        global $sensei_course_loop;
2189
-
2190
-
2191
-        if( !isset( $sensei_course_loop ) ){
2192
-            $sensei_course_loop = array();
2193
-        }
2194
-
2195
-        if (!isset($sensei_course_loop['counter'])) {
2196
-            $sensei_course_loop['counter'] = 0;
2197
-        }
2198
-
2199
-        if (!isset($sensei_course_loop['columns'])) {
2200
-            $sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2201
-        }
2202
-
2203
-        // increment the counter
2204
-        $sensei_course_loop['counter']++;
2205
-
2206
-        $extra_classes = array();
2207
-        if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2208
-            $extra_classes[] = 'first';
2209
-        }
2210
-
2211
-        if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2212
-            $extra_classes[] = 'last';
2213
-        }
2214
-
2215
-        // add the item number to the classes as well.
2216
-        $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2217
-
2218
-        /**
2219
-         * Filter the course loop class the fires in the  in get_course_loop_content_class function
2220
-         * which is called from the course loop content-course.php
2221
-         *
2222
-         * @since 1.9.0
2223
-         *
2224
-         * @param array $extra_classes
2225
-         * @param WP_Post $loop_current_course
2226
-         */
2227
-        return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2228
-
2229
-    }// end get_course_loop_class
2230
-
2231
-    /**
2232
-     * Get the number of columns set for Sensei courses
2233
-     *
2234
-     * @since 1.9.0
2235
-     * @return mixed|void
2236
-     */
2237
-    public static function get_loop_number_of_columns(){
2238
-
2239
-        /**
2240
-         * Filter the number of columns on the course archive page.
2241
-         *
2242
-         * @since 1.9.0
2243
-         * @param int $number_of_columns default 1
2244
-         */
2245
-        return apply_filters('sensei_course_loop_number_of_columns', 1);
2246
-
2247
-    }
2248
-
2249
-    /**
2250
-     * Output the course archive filter markup
2251
-     *
2252
-     * hooked into sensei_loop_course_before
2253
-     *
2254
-     * @since 1.9.0
2255
-     * @param
2256
-     */
2257
-    public static function course_archive_sorting( $query ){
2258
-
2259
-        // don't show on category pages and other pages
2260
-        if( ! is_archive(  'course ') || is_tax('course-category') ){
2261
-            return;
2262
-        }
2263
-
2264
-        /**
2265
-         * Filter the sensei archive course order by values
2266
-         *
2267
-         * @since 1.9.0
2268
-         * @param array $options {
2269
-         *  @type string $option_value
2270
-         *  @type string $option_string
2271
-         * }
2272
-         */
2273
-        $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2274
-            "newness"     => __( "Sort by newest first", "woothemes-sensei"),
2275
-            "title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2276
-        ));
2277
-
2278
-        // setup the currently selected item
2279
-        $selected = 'newness';
2280
-        if( isset( $_GET['orderby'] ) ){
2281
-
2282
-            $selected =  $_GET[ 'orderby' ];
2283
-
2284
-        }
2285
-
2286
-        ?>
2117
+	}// end the_course_action_buttons
2118
+
2119
+	/**
2120
+	 * This function alter the main query on the course archive page.
2121
+	 * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive.
2122
+	 *
2123
+	 * This function targets only the course archives and the my courses page. Shortcodes can set their own
2124
+	 * query parameters via the arguments.
2125
+	 *
2126
+	 * This function is hooked into pre_get_posts filter
2127
+	 *
2128
+	 * @since 1.9.0
2129
+	 *
2130
+	 * @param WP_Query $query
2131
+	 * @return WP_Query $query
2132
+	 */
2133
+	public static function course_query_filter( $query ){
2134
+
2135
+		// exit early for no course queries and admin queries
2136
+		if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2137
+			return $query;
2138
+		}
2139
+
2140
+		global $post; // used to get the current page id for my courses
2141
+
2142
+		// for the course archive page
2143
+		if( $query->is_main_query() && is_post_type_archive('course') )
2144
+		{
2145
+			/**
2146
+			 * sensei_archive_courses_per_page
2147
+			 *
2148
+			 * Sensei courses per page on the course
2149
+			 * archive
2150
+			 *
2151
+			 * @since 1.9.0
2152
+			 * @param integer $posts_per_page default 10
2153
+			 */
2154
+			$query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2155
+
2156
+		}
2157
+		// for the my courses page
2158
+		elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2159
+		{
2160
+			/**
2161
+			 * sensei_my_courses_per_page
2162
+			 *
2163
+			 * Sensei courses per page on the my courses page
2164
+			 * as set in the settings
2165
+			 *
2166
+			 * @since 1.9.0
2167
+			 * @param integer $posts_per_page default 10
2168
+			 */
2169
+			$query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2170
+
2171
+		}
2172
+
2173
+		return $query;
2174
+
2175
+	}// end course_query_filter
2176
+
2177
+	/**
2178
+	 * Determine the class of the course loop
2179
+	 *
2180
+	 * This will output .first or .last and .course-item-number-x
2181
+	 *
2182
+	 * @return array $extra_classes
2183
+	 * @since 1.9.0
2184
+	 */
2185
+	public static function get_course_loop_content_class ()
2186
+	{
2187
+
2188
+		global $sensei_course_loop;
2189
+
2190
+
2191
+		if( !isset( $sensei_course_loop ) ){
2192
+			$sensei_course_loop = array();
2193
+		}
2194
+
2195
+		if (!isset($sensei_course_loop['counter'])) {
2196
+			$sensei_course_loop['counter'] = 0;
2197
+		}
2198
+
2199
+		if (!isset($sensei_course_loop['columns'])) {
2200
+			$sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2201
+		}
2202
+
2203
+		// increment the counter
2204
+		$sensei_course_loop['counter']++;
2205
+
2206
+		$extra_classes = array();
2207
+		if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2208
+			$extra_classes[] = 'first';
2209
+		}
2210
+
2211
+		if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2212
+			$extra_classes[] = 'last';
2213
+		}
2214
+
2215
+		// add the item number to the classes as well.
2216
+		$extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2217
+
2218
+		/**
2219
+		 * Filter the course loop class the fires in the  in get_course_loop_content_class function
2220
+		 * which is called from the course loop content-course.php
2221
+		 *
2222
+		 * @since 1.9.0
2223
+		 *
2224
+		 * @param array $extra_classes
2225
+		 * @param WP_Post $loop_current_course
2226
+		 */
2227
+		return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2228
+
2229
+	}// end get_course_loop_class
2230
+
2231
+	/**
2232
+	 * Get the number of columns set for Sensei courses
2233
+	 *
2234
+	 * @since 1.9.0
2235
+	 * @return mixed|void
2236
+	 */
2237
+	public static function get_loop_number_of_columns(){
2238
+
2239
+		/**
2240
+		 * Filter the number of columns on the course archive page.
2241
+		 *
2242
+		 * @since 1.9.0
2243
+		 * @param int $number_of_columns default 1
2244
+		 */
2245
+		return apply_filters('sensei_course_loop_number_of_columns', 1);
2246
+
2247
+	}
2248
+
2249
+	/**
2250
+	 * Output the course archive filter markup
2251
+	 *
2252
+	 * hooked into sensei_loop_course_before
2253
+	 *
2254
+	 * @since 1.9.0
2255
+	 * @param
2256
+	 */
2257
+	public static function course_archive_sorting( $query ){
2258
+
2259
+		// don't show on category pages and other pages
2260
+		if( ! is_archive(  'course ') || is_tax('course-category') ){
2261
+			return;
2262
+		}
2263
+
2264
+		/**
2265
+		 * Filter the sensei archive course order by values
2266
+		 *
2267
+		 * @since 1.9.0
2268
+		 * @param array $options {
2269
+		 *  @type string $option_value
2270
+		 *  @type string $option_string
2271
+		 * }
2272
+		 */
2273
+		$course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2274
+			"newness"     => __( "Sort by newest first", "woothemes-sensei"),
2275
+			"title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2276
+		));
2277
+
2278
+		// setup the currently selected item
2279
+		$selected = 'newness';
2280
+		if( isset( $_GET['orderby'] ) ){
2281
+
2282
+			$selected =  $_GET[ 'orderby' ];
2283
+
2284
+		}
2285
+
2286
+		?>
2287 2287
 
2288 2288
         <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST">
2289 2289
             <select name="course-orderby" class="orderby">
2290 2290
                 <?php
2291
-                foreach( $course_order_by_options as $value => $text ){
2291
+				foreach( $course_order_by_options as $value => $text ){
2292 2292
 
2293
-                    echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2293
+					echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2294 2294
 
2295
-                }
2296
-                ?>
2295
+				}
2296
+				?>
2297 2297
             </select>
2298 2298
         </form>
2299 2299
 
2300 2300
     <?php
2301
-    }// end course archive filters
2302
-
2303
-    /**
2304
-     * Output the course archive filter markup
2305
-     *
2306
-     * hooked into sensei_loop_course_before
2307
-     *
2308
-     * @since 1.9.0
2309
-     * @param
2310
-     */
2311
-    public static function course_archive_filters( $query ){
2312
-
2313
-        // don't show on category pages
2314
-        if( is_tax('course-category') ){
2315
-            return;
2316
-        }
2317
-
2318
-        /**
2319
-         * filter the course archive filter buttons
2320
-         *
2321
-         * @since 1.9.0
2322
-         * @param array $filters{
2323
-         *   @type array ( $id, $url , $title )
2324
-         * }
2325
-         *
2326
-         */
2327
-        $filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2328
-            array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2329
-            array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2330
-        ));
2331
-
2332
-
2333
-        ?>
2301
+	}// end course archive filters
2302
+
2303
+	/**
2304
+	 * Output the course archive filter markup
2305
+	 *
2306
+	 * hooked into sensei_loop_course_before
2307
+	 *
2308
+	 * @since 1.9.0
2309
+	 * @param
2310
+	 */
2311
+	public static function course_archive_filters( $query ){
2312
+
2313
+		// don't show on category pages
2314
+		if( is_tax('course-category') ){
2315
+			return;
2316
+		}
2317
+
2318
+		/**
2319
+		 * filter the course archive filter buttons
2320
+		 *
2321
+		 * @since 1.9.0
2322
+		 * @param array $filters{
2323
+		 *   @type array ( $id, $url , $title )
2324
+		 * }
2325
+		 *
2326
+		 */
2327
+		$filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2328
+			array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2329
+			array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2330
+		));
2331
+
2332
+
2333
+		?>
2334 2334
         <ul class="sensei-course-filters clearfix" >
2335 2335
             <?php
2336 2336
 
2337
-            //determine the current active url
2338
-            $current_url = Sensei_Utils::get_current_url();
2337
+			//determine the current active url
2338
+			$current_url = Sensei_Utils::get_current_url();
2339 2339
 
2340
-            foreach( $filters as $filter ) {
2340
+			foreach( $filters as $filter ) {
2341 2341
 
2342
-                $active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2342
+				$active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2343 2343
 
2344
-                echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2344
+				echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2345 2345
 
2346
-            }
2347
-            ?>
2346
+			}
2347
+			?>
2348 2348
 
2349 2349
         </ul>
2350 2350
 
2351 2351
         <?php
2352 2352
 
2353
-    }
2353
+	}
2354 2354
 
2355
-    /**
2356
-     * if the featured link is clicked on the course archive page
2357
-     * filter the courses returned to only show those featured
2358
-     *
2359
-     * Hooked into pre_get_posts
2360
-     *
2361
-     * @since 1.9.0
2362
-     * @param WP_Query $query
2363
-     * @return WP_Query $query
2364
-     */
2365
-    public static function course_archive_featured_filter( $query ){
2366
-
2367
-        if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2368
-            //setup meta query for featured courses
2369
-            $query->set( 'meta_value', 'featured'  );
2370
-            $query->set( 'meta_key', '_course_featured'  );
2371
-            $query->set( 'meta_compare', '='  );
2372
-        }
2373
-
2374
-        return $query;
2375
-    }
2376
-
2377
-    /**
2378
-     * if the course order drop down is changed
2379
-     *
2380
-     * Hooked into pre_get_posts
2381
-     *
2382
-     * @since 1.9.0
2383
-     * @param WP_Query $query
2384
-     * @return WP_Query $query
2385
-     */
2386
-    public static function course_archive_order_by_title( $query ){
2387
-
2388
-        if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2389
-            && 'course'== $query->get('post_type') && $query->is_main_query()  ){
2390
-            // setup the order by title for this query
2391
-            $query->set( 'orderby', 'title'  );
2392
-            $query->set( 'order', 'ASC'  );
2393
-        }
2394
-
2395
-        return $query;
2396
-    }
2397
-
2398
-
2399
-    /**
2400
-     * Get the link to the courses page. This will be the course post type archive
2401
-     * page link or the page the user set in their settings
2402
-     *
2403
-     * @since 1.9.0
2404
-     * @return string $course_page_url
2405
-     */
2406
-    public static function get_courses_page_url(){
2407
-
2408
-        $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2409
-        $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2355
+	/**
2356
+	 * if the featured link is clicked on the course archive page
2357
+	 * filter the courses returned to only show those featured
2358
+	 *
2359
+	 * Hooked into pre_get_posts
2360
+	 *
2361
+	 * @since 1.9.0
2362
+	 * @param WP_Query $query
2363
+	 * @return WP_Query $query
2364
+	 */
2365
+	public static function course_archive_featured_filter( $query ){
2410 2366
 
2411
-        return $course_page_url;
2412
-
2413
-    }// get_course_url
2367
+		if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2368
+			//setup meta query for featured courses
2369
+			$query->set( 'meta_value', 'featured'  );
2370
+			$query->set( 'meta_key', '_course_featured'  );
2371
+			$query->set( 'meta_compare', '='  );
2372
+		}
2414 2373
 
2415
-    /**
2416
-     * Output the headers on the course archive page
2417
-     *
2418
-     * Hooked into the sensei_archive_title
2419
-     *
2420
-     * @since 1.9.0
2421
-     * @param string $query_type
2422
-     * @param string $before_html
2423
-     * @param string $after_html
2424
-     * @return void
2425
-     */
2426
-    public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2374
+		return $query;
2375
+	}
2427 2376
 
2428
-        if( ! is_post_type_archive('course') ){
2429
-            return;
2430
-        }
2377
+	/**
2378
+	 * if the course order drop down is changed
2379
+	 *
2380
+	 * Hooked into pre_get_posts
2381
+	 *
2382
+	 * @since 1.9.0
2383
+	 * @param WP_Query $query
2384
+	 * @return WP_Query $query
2385
+	 */
2386
+	public static function course_archive_order_by_title( $query ){
2431 2387
 
2432
-        // deprecated since 1.9.0
2433
-        sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2388
+		if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2389
+			&& 'course'== $query->get('post_type') && $query->is_main_query()  ){
2390
+			// setup the order by title for this query
2391
+			$query->set( 'orderby', 'title'  );
2392
+			$query->set( 'order', 'ASC'  );
2393
+		}
2434 2394
 
2435
-        $html = '';
2395
+		return $query;
2396
+	}
2436 2397
 
2437
-        if( empty( $before_html ) ){
2438 2398
 
2439
-            $before_html = '<header class="archive-header"><h1>';
2399
+	/**
2400
+	 * Get the link to the courses page. This will be the course post type archive
2401
+	 * page link or the page the user set in their settings
2402
+	 *
2403
+	 * @since 1.9.0
2404
+	 * @return string $course_page_url
2405
+	 */
2406
+	public static function get_courses_page_url(){
2440 2407
 
2441
-        }
2408
+		$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2409
+		$course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2442 2410
 
2443
-        if( empty( $after_html ) ){
2411
+		return $course_page_url;
2444 2412
 
2445
-            $after_html = '</h1></header>';
2413
+	}// get_course_url
2446 2414
 
2447
-        }
2415
+	/**
2416
+	 * Output the headers on the course archive page
2417
+	 *
2418
+	 * Hooked into the sensei_archive_title
2419
+	 *
2420
+	 * @since 1.9.0
2421
+	 * @param string $query_type
2422
+	 * @param string $before_html
2423
+	 * @param string $after_html
2424
+	 * @return void
2425
+	 */
2426
+	public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2448 2427
 
2449
-        if ( is_tax( 'course-category' ) ) {
2428
+		if( ! is_post_type_archive('course') ){
2429
+			return;
2430
+		}
2450 2431
 
2451
-            global $wp_query;
2432
+		// deprecated since 1.9.0
2433
+		sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2452 2434
 
2453
-            $taxonomy_obj = $wp_query->get_queried_object();
2454
-            $taxonomy_short_name = $taxonomy_obj->taxonomy;
2455
-            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2456
-            $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2457
-            echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2458
-            return;
2435
+		$html = '';
2459 2436
 
2460
-        } // End If Statement
2437
+		if( empty( $before_html ) ){
2461 2438
 
2462
-        switch ( $query_type ) {
2463
-            case 'newcourses':
2464
-                $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2465
-                break;
2466
-            case 'featuredcourses':
2467
-                $html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2468
-                break;
2469
-            case 'freecourses':
2470
-                $html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2471
-                break;
2472
-            case 'paidcourses':
2473
-                $html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2474
-                break;
2475
-            default:
2476
-                $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2477
-                break;
2478
-        } // End Switch Statement
2439
+			$before_html = '<header class="archive-header"><h1>';
2479 2440
 
2480
-        echo apply_filters( 'course_archive_title', $html );
2441
+		}
2481 2442
 
2482
-    }//course_archive_header
2443
+		if( empty( $after_html ) ){
2483 2444
 
2445
+			$after_html = '</h1></header>';
2484 2446
 
2485
-    /**
2486
-     * Filter the single course content
2487
-     * taking into account if the user has access.
2488
-     *
2489
-     * @1.9.0
2490
-     *
2491
-     * @param string $content
2492
-     * @return string $content or $excerpt
2493
-     */
2494
-    public static function single_course_content( $content ){
2447
+		}
2495 2448
 
2496
-        if( ! is_singular('course') ){
2449
+		if ( is_tax( 'course-category' ) ) {
2497 2450
 
2498
-            return $content;
2451
+			global $wp_query;
2499 2452
 
2500
-        }
2453
+			$taxonomy_obj = $wp_query->get_queried_object();
2454
+			$taxonomy_short_name = $taxonomy_obj->taxonomy;
2455
+			$taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2456
+			$title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2457
+			echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2458
+			return;
2459
+
2460
+		} // End If Statement
2461
+
2462
+		switch ( $query_type ) {
2463
+			case 'newcourses':
2464
+				$html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2465
+				break;
2466
+			case 'featuredcourses':
2467
+				$html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2468
+				break;
2469
+			case 'freecourses':
2470
+				$html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2471
+				break;
2472
+			case 'paidcourses':
2473
+				$html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2474
+				break;
2475
+			default:
2476
+				$html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2477
+				break;
2478
+		} // End Switch Statement
2479
+
2480
+		echo apply_filters( 'course_archive_title', $html );
2501 2481
 
2502
-        // Content Access Permissions
2503
-        $access_permission = false;
2482
+	}//course_archive_header
2504 2483
 
2505
-        if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2506 2484
 
2507
-            $access_permission = true;
2485
+	/**
2486
+	 * Filter the single course content
2487
+	 * taking into account if the user has access.
2488
+	 *
2489
+	 * @1.9.0
2490
+	 *
2491
+	 * @param string $content
2492
+	 * @return string $content or $excerpt
2493
+	 */
2494
+	public static function single_course_content( $content ){
2495
+
2496
+		if( ! is_singular('course') ){
2497
+
2498
+			return $content;
2499
+
2500
+		}
2501
+
2502
+		// Content Access Permissions
2503
+		$access_permission = false;
2508 2504
 
2509
-        } // End If Statement
2505
+		if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2510 2506
 
2511
-        // Check if the user is taking the course
2512
-        $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2507
+			$access_permission = true;
2513 2508
 
2514
-        if(Sensei_WC::is_woocommerce_active()) {
2509
+		} // End If Statement
2515 2510
 
2516
-            $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2517
-            $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2511
+		// Check if the user is taking the course
2512
+		$is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2518 2513
 
2519
-            $has_product_attached = isset ( $product ) && is_object ( $product );
2514
+		if(Sensei_WC::is_woocommerce_active()) {
2520 2515
 
2521
-        } else {
2516
+			$wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2517
+			$product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2522 2518
 
2523
-            $has_product_attached = false;
2519
+			$has_product_attached = isset ( $product ) && is_object ( $product );
2524 2520
 
2525
-        }
2521
+		} else {
2522
+
2523
+			$has_product_attached = false;
2524
+
2525
+		}
2526 2526
 
2527
-        if ( ( is_user_logged_in() && $is_user_taking_course )
2528
-            || ( $access_permission && !$has_product_attached)
2529
-            || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2527
+		if ( ( is_user_logged_in() && $is_user_taking_course )
2528
+			|| ( $access_permission && !$has_product_attached)
2529
+			|| 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2530 2530
 
2531
-	        // compensate for core providing and empty $content
2531
+			// compensate for core providing and empty $content
2532 2532
 
2533
-	        if( empty( $content ) ){
2534
-		        remove_filter( 'the_content', array( 'Sensei_Course', 'single_course_content') );
2535
-		        $course = get_post( get_the_ID() );
2533
+			if( empty( $content ) ){
2534
+				remove_filter( 'the_content', array( 'Sensei_Course', 'single_course_content') );
2535
+				$course = get_post( get_the_ID() );
2536 2536
 
2537
-		        $content = apply_filters( 'the_content', $course->post_content );
2537
+				$content = apply_filters( 'the_content', $course->post_content );
2538 2538
 
2539
-	        }
2539
+			}
2540 2540
 
2541
-            return $content;
2541
+			return $content;
2542 2542
 
2543
-        } else {
2543
+		} else {
2544 2544
 
2545
-            return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2545
+			return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2546 2546
 
2547
-        }
2547
+		}
2548 2548
 
2549
-    }// end single_course_content
2549
+	}// end single_course_content
2550 2550
 
2551
-    /**
2552
-     * Output the the single course lessons title with markup.
2553
-     *
2554
-     * @since 1.9.0
2555
-     */
2556
-    public static function the_course_lessons_title(){
2551
+	/**
2552
+	 * Output the the single course lessons title with markup.
2553
+	 *
2554
+	 * @since 1.9.0
2555
+	 */
2556
+	public static function the_course_lessons_title(){
2557 2557
 
2558
-	    if ( ! is_singular( 'course' )  ) {
2559
-		    return;
2560
-	    }
2558
+		if ( ! is_singular( 'course' )  ) {
2559
+			return;
2560
+		}
2561 2561
 
2562
-        global $post;
2563
-        $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2564
-        $course_lessons = Sensei()->course->course_lessons( $post->ID );
2562
+		global $post;
2563
+		$none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2564
+		$course_lessons = Sensei()->course->course_lessons( $post->ID );
2565 2565
 
2566
-        // title should be Other Lessons if there are lessons belonging to models.
2567
-        $title = __('Other Lessons', 'woothemes-sensei');
2566
+		// title should be Other Lessons if there are lessons belonging to models.
2567
+		$title = __('Other Lessons', 'woothemes-sensei');
2568 2568
 
2569
-        // show lessons if the number of lesson in the course is the same as those that isn't assigned to a module
2570
-        if( count( $course_lessons ) == count( $none_module_lessons )  ){
2569
+		// show lessons if the number of lesson in the course is the same as those that isn't assigned to a module
2570
+		if( count( $course_lessons ) == count( $none_module_lessons )  ){
2571 2571
 
2572
-            $title = __('Lessons', 'woothemes-sensei');
2572
+			$title = __('Lessons', 'woothemes-sensei');
2573 2573
 
2574
-        }elseif( empty( $none_module_lessons ) ){ // if the none module lessons are simply empty the title should not be shown
2574
+		}elseif( empty( $none_module_lessons ) ){ // if the none module lessons are simply empty the title should not be shown
2575 2575
 
2576
-            $title = '';
2577
-        }
2576
+			$title = '';
2577
+		}
2578 2578
 
2579
-        /**
2580
-         * hook document in class-woothemes-sensei-message.php
2581
-         */
2582
-        $title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2579
+		/**
2580
+		 * hook document in class-woothemes-sensei-message.php
2581
+		 */
2582
+		$title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2583 2583
 
2584
-        ob_start(); // start capturing the following output.
2584
+		ob_start(); // start capturing the following output.
2585 2585
 
2586
-        ?>
2586
+		?>
2587 2587
 
2588 2588
             <header>
2589 2589
                 <h2> <?php echo $title; ?> </h2>
@@ -2591,323 +2591,323 @@  discard block
 block discarded – undo
2591 2591
 
2592 2592
         <?php
2593 2593
 
2594
-        /**
2595
-         * Filter the title and markup that appears above the lessons on a single course
2596
-         * page.
2597
-         *
2598
-         * @since 1.9.0
2599
-         * @param string $lessons_title_html
2600
-         */
2601
-        echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2602
-
2603
-    }// end the_course_lessons_title
2604
-
2605
-    /**
2606
-     * This function loads the global wp_query object with with lessons
2607
-     * of the current course. It is designed to be used on the single-course template
2608
-     * and expects the global post to be a singular course.
2609
-     *
2610
-     * This function excludes lessons belonging to modules as they are
2611
-     * queried separately.
2612
-     *
2613
-     * @since 1.9.0
2614
-     * @global $wp_query
2615
-     */
2616
-    public static function load_single_course_lessons_query(){
2594
+		/**
2595
+		 * Filter the title and markup that appears above the lessons on a single course
2596
+		 * page.
2597
+		 *
2598
+		 * @since 1.9.0
2599
+		 * @param string $lessons_title_html
2600
+		 */
2601
+		echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2617 2602
 
2618
-        global $post, $wp_query;
2603
+	}// end the_course_lessons_title
2619 2604
 
2620
-        $course_id = $post->ID;
2621
-
2622
-        if( 'course' != get_post_type( $course_id ) ){
2623
-            return;
2624
-        }
2605
+	/**
2606
+	 * This function loads the global wp_query object with with lessons
2607
+	 * of the current course. It is designed to be used on the single-course template
2608
+	 * and expects the global post to be a singular course.
2609
+	 *
2610
+	 * This function excludes lessons belonging to modules as they are
2611
+	 * queried separately.
2612
+	 *
2613
+	 * @since 1.9.0
2614
+	 * @global $wp_query
2615
+	 */
2616
+	public static function load_single_course_lessons_query(){
2625 2617
 
2626
-        $course_lesson_query_args = array(
2627
-            'post_type'         => 'lesson',
2628
-            'posts_per_page'    => 500,
2629
-            'orderby'           => 'date',
2630
-            'order'             => 'ASC',
2631
-            'meta_query'        => array(
2632
-                array(
2633
-                    'key' => '_lesson_course',
2634
-                    'value' => intval( $course_id ),
2635
-                ),
2636
-            ),
2637
-            'post_status'       => 'public',
2638
-            'suppress_filters'  => 0,
2639
-        );
2618
+		global $post, $wp_query;
2640 2619
 
2641
-        // Exclude lessons belonging to modules as they are queried along with the modules.
2642
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2643
-        if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2620
+		$course_id = $post->ID;
2644 2621
 
2645
-            $terms_ids = array();
2646
-            foreach( $modules as $term ){
2622
+		if( 'course' != get_post_type( $course_id ) ){
2623
+			return;
2624
+		}
2647 2625
 
2648
-                $terms_ids[] = $term->term_id;
2626
+		$course_lesson_query_args = array(
2627
+			'post_type'         => 'lesson',
2628
+			'posts_per_page'    => 500,
2629
+			'orderby'           => 'date',
2630
+			'order'             => 'ASC',
2631
+			'meta_query'        => array(
2632
+				array(
2633
+					'key' => '_lesson_course',
2634
+					'value' => intval( $course_id ),
2635
+				),
2636
+			),
2637
+			'post_status'       => 'public',
2638
+			'suppress_filters'  => 0,
2639
+		);
2640
+
2641
+		// Exclude lessons belonging to modules as they are queried along with the modules.
2642
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2643
+		if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2644
+
2645
+			$terms_ids = array();
2646
+			foreach( $modules as $term ){
2647
+
2648
+				$terms_ids[] = $term->term_id;
2649 2649
 
2650
-            }
2650
+			}
2651 2651
 
2652
-            $course_lesson_query_args[ 'tax_query'] = array(
2653
-                array(
2654
-                    'taxonomy' => 'module',
2655
-                    'field'    => 'id',
2656
-                    'terms'    => $terms_ids,
2657
-                    'operator' => 'NOT IN',
2658
-                ),
2659
-            );
2660
-        }
2652
+			$course_lesson_query_args[ 'tax_query'] = array(
2653
+				array(
2654
+					'taxonomy' => 'module',
2655
+					'field'    => 'id',
2656
+					'terms'    => $terms_ids,
2657
+					'operator' => 'NOT IN',
2658
+				),
2659
+			);
2660
+		}
2661 2661
 
2662
-        //setting lesson order
2663
-        $course_lesson_order = get_post_meta( $course_id, '_lesson_order', true);
2664
-        if( !empty( $course_lesson_order ) ){
2662
+		//setting lesson order
2663
+		$course_lesson_order = get_post_meta( $course_id, '_lesson_order', true);
2664
+		if( !empty( $course_lesson_order ) ){
2665 2665
 
2666
-            $course_lesson_query_args['post__in'] = explode( ',', $course_lesson_order );
2667
-            $course_lesson_query_args['orderby']= 'post__in' ;
2668
-            unset( $course_lesson_query_args['order'] );
2666
+			$course_lesson_query_args['post__in'] = explode( ',', $course_lesson_order );
2667
+			$course_lesson_query_args['orderby']= 'post__in' ;
2668
+			unset( $course_lesson_query_args['order'] );
2669 2669
 
2670
-        }
2670
+		}
2671 2671
 
2672
-        $wp_query = new WP_Query( $course_lesson_query_args );
2672
+		$wp_query = new WP_Query( $course_lesson_query_args );
2673 2673
 
2674
-    }// load_single_course_lessons
2674
+	}// load_single_course_lessons
2675 2675
 
2676
-    /**
2677
-     * Flush the rewrite rules for a course post type
2678
-     *
2679
-     * @since 1.9.0
2680
-     *
2681
-     * @param $post_id
2682
-     */
2683
-    public static function flush_rewrite_rules( $post_id ){
2676
+	/**
2677
+	 * Flush the rewrite rules for a course post type
2678
+	 *
2679
+	 * @since 1.9.0
2680
+	 *
2681
+	 * @param $post_id
2682
+	 */
2683
+	public static function flush_rewrite_rules( $post_id ){
2684 2684
 
2685
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2685
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2686 2686
 
2687
-            return;
2687
+			return;
2688 2688
 
2689
-        }
2689
+		}
2690 2690
 
2691 2691
 
2692
-        if( 'course' == get_post_type( $post_id )  ){
2692
+		if( 'course' == get_post_type( $post_id )  ){
2693 2693
 
2694
-            Sensei()->initiate_rewrite_rules_flush();
2694
+			Sensei()->initiate_rewrite_rules_flush();
2695 2695
 
2696
-        }
2696
+		}
2697 2697
 
2698
-    }
2698
+	}
2699 2699
 
2700
-    /**
2701
-     * Optionally return the full content on the single course pages
2702
-     * depending on the users course_single_content_display setting
2703
-     *
2704
-     * @since 1.9.0
2705
-     * @param $excerpt
2706
-     * @return string
2707
-     */
2708
-    public static function full_content_excerpt_override( $excerpt ){
2700
+	/**
2701
+	 * Optionally return the full content on the single course pages
2702
+	 * depending on the users course_single_content_display setting
2703
+	 *
2704
+	 * @since 1.9.0
2705
+	 * @param $excerpt
2706
+	 * @return string
2707
+	 */
2708
+	public static function full_content_excerpt_override( $excerpt ){
2709 2709
 
2710
-        if (   is_singular('course')  &&
2711
-                'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2710
+		if (   is_singular('course')  &&
2711
+				'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2712 2712
 
2713
-            return get_the_content();
2713
+			return get_the_content();
2714 2714
 
2715
-        } else {
2715
+		} else {
2716 2716
 
2717
-            return $excerpt;
2717
+			return $excerpt;
2718 2718
 
2719
-        }
2719
+		}
2720 2720
 
2721
-    }
2721
+	}
2722 2722
 
2723
-    /**
2724
-     * Output the course actions like start taking course, register, add to cart etc.
2725
-     *
2726
-     * @since 1.9.0
2727
-     */
2728
-    public static function the_course_enrolment_actions(){
2723
+	/**
2724
+	 * Output the course actions like start taking course, register, add to cart etc.
2725
+	 *
2726
+	 * @since 1.9.0
2727
+	 */
2728
+	public static function the_course_enrolment_actions(){
2729 2729
 
2730
-	    global $post;
2730
+		global $post;
2731 2731
 
2732
-	    if ( 'course' != $post->post_type ) {
2732
+		if ( 'course' != $post->post_type ) {
2733 2733
 			return;
2734
-	    }
2734
+		}
2735 2735
 
2736
-        ?>
2736
+		?>
2737 2737
         <section class="course-meta course-enrolment">
2738 2738
         <?php
2739
-        global  $post, $current_user;
2740
-        $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2739
+		global  $post, $current_user;
2740
+		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2741 2741
 
2742
-	    if ( is_user_logged_in() && ! $is_user_taking_course ) {
2742
+		if ( is_user_logged_in() && ! $is_user_taking_course ) {
2743 2743
 
2744
-	        // Check for woocommerce
2745
-	        if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2744
+			// Check for woocommerce
2745
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2746 2746
 
2747
-		        // Get the product ID
2748
-                Sensei_WC::the_add_to_cart_button_html($post->ID );
2747
+				// Get the product ID
2748
+				Sensei_WC::the_add_to_cart_button_html($post->ID );
2749 2749
 
2750
-            } else {
2750
+			} else {
2751 2751
 
2752
-                sensei_start_course_form($post->ID);
2752
+				sensei_start_course_form($post->ID);
2753 2753
 
2754
-            } // End If Statement
2754
+			} // End If Statement
2755 2755
 
2756
-        } elseif ( is_user_logged_in() ) {
2756
+		} elseif ( is_user_logged_in() ) {
2757 2757
 
2758
-            // Check if course is completed
2759
-            $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2760
-            $completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2761
-            // Success message
2762
-            if ( $completed_course ) { ?>
2758
+			// Check if course is completed
2759
+			$user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2760
+			$completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2761
+			// Success message
2762
+			if ( $completed_course ) { ?>
2763 2763
                 <div class="status completed"><?php  _e( 'Completed', 'woothemes-sensei' ); ?></div>
2764 2764
                 <?php
2765
-                $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2766
-                if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2765
+				$has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2766
+				if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2767 2767
                     <p class="sensei-results-links">
2768 2768
                         <?php
2769
-                        $results_link = '';
2770
-                        if( $has_quizzes ) {
2771
-                            $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2772
-                        }
2773
-                        /**
2774
-                         * Filter documented in Sensei_Course::the_course_action_buttons
2775
-                         */
2776
-                        $results_link = apply_filters( 'sensei_results_links', $results_link, $post->ID );
2777
-                        echo $results_link;
2778
-                        ?></p>
2769
+						$results_link = '';
2770
+						if( $has_quizzes ) {
2771
+							$results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2772
+						}
2773
+						/**
2774
+						 * Filter documented in Sensei_Course::the_course_action_buttons
2775
+						 */
2776
+						$results_link = apply_filters( 'sensei_results_links', $results_link, $post->ID );
2777
+						echo $results_link;
2778
+						?></p>
2779 2779
                 <?php } ?>
2780 2780
             <?php } else { ?>
2781 2781
                 <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div>
2782 2782
             <?php }
2783 2783
 
2784
-        } else {
2784
+		} else {
2785 2785
 
2786
-            // Check for woocommerce
2787
-		    if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2786
+			// Check for woocommerce
2787
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2788 2788
 
2789
-	            $login_link =  '<a href="' . sensei_user_login_url() . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
2790
-	            $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
2791
-	            Sensei()->notices->add_notice( $message, 'info' ) ;
2792
-	            Sensei_WC::the_add_to_cart_button_html( $post->ID );
2789
+				$login_link =  '<a href="' . sensei_user_login_url() . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
2790
+				$message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
2791
+				Sensei()->notices->add_notice( $message, 'info' ) ;
2792
+				Sensei_WC::the_add_to_cart_button_html( $post->ID );
2793 2793
 
2794
-            } else {
2794
+			} else {
2795 2795
 
2796
-                if( get_option( 'users_can_register') ) {
2796
+				if( get_option( 'users_can_register') ) {
2797 2797
 
2798
-	                // set the permissions message
2799
-	                $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
2800
-	                $anchor_after = '</a>';
2801
-	                $notice = sprintf(
2802
-		                __('or log in to view this courses. Click here to %slogin%s.'),
2803
-		                $anchor_before,
2804
-		                $anchor_after
2805
-	                );
2798
+					// set the permissions message
2799
+					$anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
2800
+					$anchor_after = '</a>';
2801
+					$notice = sprintf(
2802
+						__('or log in to view this courses. Click here to %slogin%s.'),
2803
+						$anchor_before,
2804
+						$anchor_after
2805
+					);
2806 2806
 
2807
-	                // register the notice to display
2808
-	                if( Sensei()->settings->get( 'access_permission' ) ){
2809
-		                Sensei()->notices->add_notice( $notice, 'info' ) ;
2810
-	                }
2807
+					// register the notice to display
2808
+					if( Sensei()->settings->get( 'access_permission' ) ){
2809
+						Sensei()->notices->add_notice( $notice, 'info' ) ;
2810
+					}
2811 2811
 
2812 2812
 
2813
-                    $my_courses_page_id = '';
2813
+					$my_courses_page_id = '';
2814 2814
 
2815
-                    /**
2816
-                     * Filter to force Sensei to output the default WordPress user
2817
-                     * registration link.
2818
-                     *
2819
-                     * @since 1.9.0
2820
-                     * @param bool $wp_register_link default false
2821
-                     */
2815
+					/**
2816
+					 * Filter to force Sensei to output the default WordPress user
2817
+					 * registration link.
2818
+					 *
2819
+					 * @since 1.9.0
2820
+					 * @param bool $wp_register_link default false
2821
+					 */
2822 2822
 
2823
-                    $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2823
+					$wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2824 2824
 
2825
-                    $settings = Sensei()->settings->get_settings();
2826
-                    if( isset( $settings[ 'my_course_page' ] )
2827
-                        && 0 < intval( $settings[ 'my_course_page' ] ) ){
2825
+					$settings = Sensei()->settings->get_settings();
2826
+					if( isset( $settings[ 'my_course_page' ] )
2827
+						&& 0 < intval( $settings[ 'my_course_page' ] ) ){
2828 2828
 
2829
-                        $my_courses_page_id = $settings[ 'my_course_page' ];
2829
+						$my_courses_page_id = $settings[ 'my_course_page' ];
2830 2830
 
2831
-                    }
2831
+					}
2832 2832
 
2833
-                    // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2834
-                    // is false, link to My Courses. If not, link to default WordPress registration page.
2835
-                    if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2833
+					// If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2834
+					// is false, link to My Courses. If not, link to default WordPress registration page.
2835
+					if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2836 2836
 
2837
-                        $my_courses_url = get_permalink( $my_courses_page_id  );
2838
-                        $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2839
-                        echo '<div class="status register">' . $register_link . '</div>' ;
2837
+						$my_courses_url = get_permalink( $my_courses_page_id  );
2838
+						$register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2839
+						echo '<div class="status register">' . $register_link . '</div>' ;
2840 2840
 
2841
-                    } else{
2841
+					} else{
2842 2842
 
2843
-                        wp_register( '<div class="status register">', '</div>' );
2843
+						wp_register( '<div class="status register">', '</div>' );
2844 2844
 
2845
-                    }
2845
+					}
2846 2846
 
2847
-                } // end if user can register
2847
+				} // end if user can register
2848 2848
 
2849
-            } // End If Statement
2849
+			} // End If Statement
2850 2850
 
2851
-        } // End If Statement ?>
2851
+		} // End If Statement ?>
2852 2852
 
2853 2853
         </section><?php
2854 2854
 
2855
-    }// end the_course_enrolment_actions
2855
+	}// end the_course_enrolment_actions
2856 2856
 
2857
-    /**
2858
-     * Output the course video inside the loop.
2859
-     *
2860
-     * @since 1.9.0
2861
-     */
2862
-    public static function the_course_video(){
2857
+	/**
2858
+	 * Output the course video inside the loop.
2859
+	 *
2860
+	 * @since 1.9.0
2861
+	 */
2862
+	public static function the_course_video(){
2863 2863
 
2864
-        global $post;
2864
+		global $post;
2865 2865
 
2866
-	    if ( ! is_singular( 'course' )  ) {
2867
-		    return;
2868
-	    }
2869
-        // Get the meta info
2870
-        $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2866
+		if ( ! is_singular( 'course' )  ) {
2867
+			return;
2868
+		}
2869
+		// Get the meta info
2870
+		$course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2871 2871
 
2872
-        if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2872
+		if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2873 2873
 
2874
-            $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2874
+			$course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2875 2875
 
2876
-        } // End If Statement
2876
+		} // End If Statement
2877 2877
 
2878
-        if ( '' != $course_video_embed ) { ?>
2878
+		if ( '' != $course_video_embed ) { ?>
2879 2879
 
2880 2880
             <div class="course-video">
2881 2881
                 <?php echo html_entity_decode($course_video_embed); ?>
2882 2882
             </div>
2883 2883
 
2884 2884
         <?php } // End If Statement
2885
-    }
2885
+	}
2886 2886
 
2887
-    /**
2888
-     * Output the title for the single lesson page
2889
-     *
2890
-     * @global $post
2891
-     * @since 1.9.0
2892
-     */
2893
-    public static function the_title(){
2887
+	/**
2888
+	 * Output the title for the single lesson page
2889
+	 *
2890
+	 * @global $post
2891
+	 * @since 1.9.0
2892
+	 */
2893
+	public static function the_title(){
2894 2894
 
2895
-	    if( ! is_singular( 'course' ) ){
2895
+		if( ! is_singular( 'course' ) ){
2896 2896
 			return;
2897
-	    }
2898
-        global $post;
2897
+		}
2898
+		global $post;
2899 2899
 
2900
-        ?>
2900
+		?>
2901 2901
         <header>
2902 2902
 
2903 2903
             <h1>
2904 2904
 
2905 2905
                 <?php
2906
-                /**
2907
-                 * Filter documented in class-sensei-messages.php the_title
2908
-                 */
2909
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2910
-                ?>
2906
+				/**
2907
+				 * Filter documented in class-sensei-messages.php the_title
2908
+				 */
2909
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2910
+				?>
2911 2911
 
2912 2912
             </h1>
2913 2913
 
@@ -2915,111 +2915,111 @@  discard block
 block discarded – undo
2915 2915
 
2916 2916
         <?php
2917 2917
 
2918
-    }//the_title
2919
-
2920
-    /**
2921
-     * Show the title on the course category pages
2922
-     *
2923
-     * @since 1.9.0
2924
-     */
2925
-    public static function course_category_title(){
2926
-
2927
-        if( ! is_tax( 'course-category' ) ){
2928
-            return;
2929
-        }
2930
-
2931
-        $category_slug = get_query_var('course-category');
2932
-        $term  = get_term_by('slug',$category_slug,'course-category');
2933
-
2934
-        if( ! empty($term) ){
2935
-
2936
-            $title = $term->name;
2937
-
2938
-        }else{
2939
-
2940
-            $title = 'Course Category';
2941
-
2942
-        }
2943
-
2944
-        $html = '<h2 class="sensei-category-title">';
2945
-        $html .= __('Category') . ' ' . $title;
2946
-        $html .= '</h2>';
2947
-
2948
-        echo apply_filters( 'course_category_title', $html , $term->term_id );
2949
-
2950
-    }// course_category_title
2951
-
2952
-    /**
2953
-     * Alter the course query to respect the order set for courses and apply
2954
-     * this on the course-category pages.
2955
-     *
2956
-     * @since 1.9.0
2957
-     *
2958
-     * @param WP_Query $query
2959
-     * @return WP_Query
2960
-     */
2961
-    public static function alter_course_category_order( $query ){
2962
-
2963
-        if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2964
-            return $query;
2965
-        }
2966
-
2967
-        $order = get_option( 'sensei_course_order', '' );
2968
-        if( !empty( $order )  ){
2969
-            $query->set('orderby', 'menu_order' );
2970
-            $query->set('order', 'ASC' );
2971
-        }
2972
-
2973
-        return $query;
2974
-
2975
-    }
2976
-
2977
-    /**
2978
-     * The very basic course query arguments
2979
-     * so we don't have to repeat this througout
2980
-     * the code base.
2981
-     *
2982
-     * Usage:
2983
-     * $args = Sensei_Course::get_default_query_args();
2984
-     * $args['custom_arg'] ='custom value';
2985
-     * $courses = get_posts( $args )
2986
-     *
2987
-     * @since 1.9.0
2988
-     *
2989
-     * @return array
2990
-     */
2991
-    public static function get_default_query_args(){
2992
-        return array(
2993
-            'post_type' 		=> 'course',
2994
-            'posts_per_page' 		=> 1000,
2995
-            'orderby'         	=> 'date',
2996
-            'order'           	=> 'DESC',
2997
-            'suppress_filters' 	=> 0
2998
-        );
2999
-    }
3000
-
3001
-    /**
3002
-     * Check if the prerequisite course is completed
3003
-     * Courses with no pre-requisite should always return true
3004
-     *
3005
-     * @since 1.9.0
3006
-     * @param $course_id
3007
-     * @return bool
3008
-     */
3009
-    public static function is_prerequisite_complete( $course_id ){
3010
-
3011
-        $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
3012
-
3013
-        // if it has a pre requisite course check it
3014
-        if( ! empty(  $course_prerequisite_id ) ){
3015
-
3016
-            return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
3017
-
3018
-        }
3019
-
3020
-        return true;
3021
-
3022
-    }// end is_prerequisite_complete
2918
+	}//the_title
2919
+
2920
+	/**
2921
+	 * Show the title on the course category pages
2922
+	 *
2923
+	 * @since 1.9.0
2924
+	 */
2925
+	public static function course_category_title(){
2926
+
2927
+		if( ! is_tax( 'course-category' ) ){
2928
+			return;
2929
+		}
2930
+
2931
+		$category_slug = get_query_var('course-category');
2932
+		$term  = get_term_by('slug',$category_slug,'course-category');
2933
+
2934
+		if( ! empty($term) ){
2935
+
2936
+			$title = $term->name;
2937
+
2938
+		}else{
2939
+
2940
+			$title = 'Course Category';
2941
+
2942
+		}
2943
+
2944
+		$html = '<h2 class="sensei-category-title">';
2945
+		$html .= __('Category') . ' ' . $title;
2946
+		$html .= '</h2>';
2947
+
2948
+		echo apply_filters( 'course_category_title', $html , $term->term_id );
2949
+
2950
+	}// course_category_title
2951
+
2952
+	/**
2953
+	 * Alter the course query to respect the order set for courses and apply
2954
+	 * this on the course-category pages.
2955
+	 *
2956
+	 * @since 1.9.0
2957
+	 *
2958
+	 * @param WP_Query $query
2959
+	 * @return WP_Query
2960
+	 */
2961
+	public static function alter_course_category_order( $query ){
2962
+
2963
+		if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2964
+			return $query;
2965
+		}
2966
+
2967
+		$order = get_option( 'sensei_course_order', '' );
2968
+		if( !empty( $order )  ){
2969
+			$query->set('orderby', 'menu_order' );
2970
+			$query->set('order', 'ASC' );
2971
+		}
2972
+
2973
+		return $query;
2974
+
2975
+	}
2976
+
2977
+	/**
2978
+	 * The very basic course query arguments
2979
+	 * so we don't have to repeat this througout
2980
+	 * the code base.
2981
+	 *
2982
+	 * Usage:
2983
+	 * $args = Sensei_Course::get_default_query_args();
2984
+	 * $args['custom_arg'] ='custom value';
2985
+	 * $courses = get_posts( $args )
2986
+	 *
2987
+	 * @since 1.9.0
2988
+	 *
2989
+	 * @return array
2990
+	 */
2991
+	public static function get_default_query_args(){
2992
+		return array(
2993
+			'post_type' 		=> 'course',
2994
+			'posts_per_page' 		=> 1000,
2995
+			'orderby'         	=> 'date',
2996
+			'order'           	=> 'DESC',
2997
+			'suppress_filters' 	=> 0
2998
+		);
2999
+	}
3000
+
3001
+	/**
3002
+	 * Check if the prerequisite course is completed
3003
+	 * Courses with no pre-requisite should always return true
3004
+	 *
3005
+	 * @since 1.9.0
3006
+	 * @param $course_id
3007
+	 * @return bool
3008
+	 */
3009
+	public static function is_prerequisite_complete( $course_id ){
3010
+
3011
+		$course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
3012
+
3013
+		// if it has a pre requisite course check it
3014
+		if( ! empty(  $course_prerequisite_id ) ){
3015
+
3016
+			return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
3017
+
3018
+		}
3019
+
3020
+		return true;
3021
+
3022
+	}// end is_prerequisite_complete
3023 3023
 
3024 3024
 
3025 3025
 }// End Class
Please login to merge, or discard this patch.
Spacing   +667 added lines, -667 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Course Class
@@ -32,72 +32,72 @@  discard block
 block discarded – undo
32 32
 	 * Constructor.
33 33
 	 * @since  1.0.0
34 34
 	 */
35
-	public function __construct () {
35
+	public function __construct() {
36 36
 
37 37
         $this->token = 'course';
38 38
 
39 39
 		// Setup meta fields for this post type
40
-		$this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' );
40
+		$this->meta_fields = array('course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product');
41 41
 		// Admin actions
42
-		if ( is_admin() ) {
42
+		if (is_admin()) {
43 43
 			// Metabox functions
44
-            add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 );
45
-			add_action( 'save_post', array( $this, 'meta_box_save' ) );
44
+            add_action('add_meta_boxes', array($this, 'meta_box_setup'), 20);
45
+			add_action('save_post', array($this, 'meta_box_save'));
46 46
 			// Custom Write Panel Columns
47
-			add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 );
48
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
47
+			add_filter('manage_edit-course_columns', array($this, 'add_column_headings'), 10, 1);
48
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
49 49
 		} else {
50 50
 			$this->my_courses_page = false;
51 51
 		} // End If Statement
52 52
 
53 53
 		// Update course completion upon completion of a lesson
54
-		add_action( 'sensei_user_lesson_end', array( $this, 'update_status_after_lesson_change' ), 10, 2 );
54
+		add_action('sensei_user_lesson_end', array($this, 'update_status_after_lesson_change'), 10, 2);
55 55
 		// Update course completion upon reset of a lesson
56
-		add_action( 'sensei_user_lesson_reset', array( $this, 'update_status_after_lesson_change' ), 10, 2 );
56
+		add_action('sensei_user_lesson_reset', array($this, 'update_status_after_lesson_change'), 10, 2);
57 57
 		// Update course completion upon grading of a quiz
58
-		add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 );
58
+		add_action('sensei_user_quiz_grade', array($this, 'update_status_after_quiz_submission'), 10, 2);
59 59
 
60 60
         // show the progress bar ont he single course page
61
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 );
62
-        add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 );
61
+        add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_statement'), 15);
62
+        add_action('sensei_single_course_content_inside_before', array($this, 'the_progress_meter'), 16);
63 63
 
64 64
         // provide an option to block all emails related to a selected course
65
-        add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) );
66
-        add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) );
65
+        add_filter('sensei_send_emails', array($this, 'block_notification_emails'));
66
+        add_action('save_post', array($this, 'save_course_notification_meta_box'));
67 67
 
68 68
         // preview lessons on the course content
69
-        add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) );
69
+        add_action('sensei_course_content_inside_after', array($this, 'the_course_free_lesson_preview'));
70 70
 
71 71
         // the course meta
72
-        add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) );
72
+        add_action('sensei_course_content_inside_before', array($this, 'the_course_meta'));
73 73
 
74 74
         // backwards compatible template hooks
75
-        add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' ));
76
-        add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) );
75
+        add_action('sensei_course_content_inside_before', array($this, 'content_before_backwards_compatibility_hooks'));
76
+        add_action('sensei_loop_course_before', array($this, 'loop_before_backwards_compatibility_hooks'));
77 77
 
78 78
         // add the user status on the course to the markup as a class
79
-        add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 );
79
+        add_filter('post_class', array(__CLASS__, 'add_course_user_status_class'), 20, 3);
80 80
 
81 81
         //filter the course query in Sensei specific instances
82
-        add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) );
82
+        add_filter('pre_get_posts', array(__CLASS__, 'course_query_filter'));
83 83
 
84 84
         //attache the sorting to the course archive
85
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) );
85
+        add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_sorting'));
86 86
 
87 87
         //attach the filter links to the course archive
88
-        add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) );
88
+        add_action('sensei_archive_before_course_loop', array('Sensei_Course', 'course_archive_filters'));
89 89
 
90 90
         //filter the course query when featured filter is applied
91
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_featured_filter'));
91
+        add_filter('pre_get_posts', array(__CLASS__, 'course_archive_featured_filter'));
92 92
 
93 93
         // handle the order by title post submission
94
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'course_archive_order_by_title'));
94
+        add_filter('pre_get_posts', array(__CLASS__, 'course_archive_order_by_title'));
95 95
 
96 96
         // ensure the course category page respects the manual order set for courses
97
-        add_filter( 'pre_get_posts',  array( __CLASS__, 'alter_course_category_order'));
97
+        add_filter('pre_get_posts', array(__CLASS__, 'alter_course_category_order'));
98 98
 
99 99
         // flush rewrite rules when saving a course
100
-        add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) );
100
+        add_action('save_post', array('Sensei_Course', 'flush_rewrite_rules'));
101 101
 
102 102
 	} // End __construct()
103 103
 
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
 	 * @param type $user_id
108 108
 	 * @param type $quiz_id
109 109
 	 */
110
-	public function update_status_after_quiz_submission( $user_id, $quiz_id ) {
111
-		if ( intval( $user_id ) > 0 && intval( $quiz_id ) > 0 ) {
112
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
113
-			$this->update_status_after_lesson_change( $user_id, $lesson_id );
110
+	public function update_status_after_quiz_submission($user_id, $quiz_id) {
111
+		if (intval($user_id) > 0 && intval($quiz_id) > 0) {
112
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
113
+			$this->update_status_after_lesson_change($user_id, $lesson_id);
114 114
 		}
115 115
 	}
116 116
 
@@ -120,12 +120,12 @@  discard block
 block discarded – undo
120 120
 	 * @param int $user_id
121 121
 	 * @param int $lesson_id
122 122
 	 */
123
-	public function update_status_after_lesson_change( $user_id, $lesson_id ) {
124
-		if ( intval( $user_id ) > 0 && intval( $lesson_id ) > 0 ) {
125
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
126
-			if ( intval( $course_id ) > 0 ) {
123
+	public function update_status_after_lesson_change($user_id, $lesson_id) {
124
+		if (intval($user_id) > 0 && intval($lesson_id) > 0) {
125
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
126
+			if (intval($course_id) > 0) {
127 127
 				// Updates the Course status and it's meta data
128
-				Sensei_Utils::user_complete_course( $course_id, $user_id );
128
+				Sensei_Utils::user_complete_course($course_id, $user_id);
129 129
 			}
130 130
 		}
131 131
 	}
@@ -136,27 +136,27 @@  discard block
 block discarded – undo
136 136
 	 * @access public
137 137
 	 * @return void
138 138
 	 */
139
-	public function meta_box_setup () {
139
+	public function meta_box_setup() {
140 140
 
141
-		if ( Sensei_WC::is_woocommerce_active() ) {
141
+		if (Sensei_WC::is_woocommerce_active()) {
142 142
 			// Add Meta Box for WooCommerce Course
143
-			add_meta_box( 'course-wc-product', __( 'WooCommerce Product', 'woothemes-sensei' ), array( $this, 'course_woocommerce_product_meta_box_content' ), $this->token, 'side', 'default' );
143
+			add_meta_box('course-wc-product', __('WooCommerce Product', 'woothemes-sensei'), array($this, 'course_woocommerce_product_meta_box_content'), $this->token, 'side', 'default');
144 144
 		} // End If Statement
145 145
 		// Add Meta Box for Prerequisite Course
146
-		add_meta_box( 'course-prerequisite', __( 'Course Prerequisite', 'woothemes-sensei' ), array( $this, 'course_prerequisite_meta_box_content' ), $this->token, 'side', 'default' );
146
+		add_meta_box('course-prerequisite', __('Course Prerequisite', 'woothemes-sensei'), array($this, 'course_prerequisite_meta_box_content'), $this->token, 'side', 'default');
147 147
 		// Add Meta Box for Featured Course
148
-		add_meta_box( 'course-featured', __( 'Featured Course', 'woothemes-sensei' ), array( $this, 'course_featured_meta_box_content' ), $this->token, 'side', 'default' );
148
+		add_meta_box('course-featured', __('Featured Course', 'woothemes-sensei'), array($this, 'course_featured_meta_box_content'), $this->token, 'side', 'default');
149 149
 		// Add Meta Box for Course Meta
150
-		add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' );
150
+		add_meta_box('course-video', __('Course Video', 'woothemes-sensei'), array($this, 'course_video_meta_box_content'), $this->token, 'normal', 'default');
151 151
 		// Add Meta Box for Course Lessons
152
-		add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' );
152
+		add_meta_box('course-lessons', __('Course Lessons', 'woothemes-sensei'), array($this, 'course_lessons_meta_box_content'), $this->token, 'normal', 'default');
153 153
         // Add Meta Box to link to Manage Learners
154
-        add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' );
154
+        add_meta_box('course-manage', __('Course Management', 'woothemes-sensei'), array($this, 'course_manage_meta_box_content'), $this->token, 'side', 'default');
155 155
         // Remove "Custom Settings" meta box.
156
-		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
156
+		remove_meta_box('woothemes-settings', $this->token, 'normal');
157 157
 
158 158
         // add Disable email notification box
159
-        add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' );
159
+        add_meta_box('course-notifications', __('Course Notifications', 'woothemes-sensei'), array($this, 'course_notification_meta_box_content'), 'course', 'normal', 'default');
160 160
 
161 161
 	} // End meta_box_setup()
162 162
 
@@ -166,58 +166,58 @@  discard block
 block discarded – undo
166 166
 	 * @access public
167 167
 	 * @return void
168 168
 	 */
169
-	public function course_woocommerce_product_meta_box_content () {
169
+	public function course_woocommerce_product_meta_box_content() {
170 170
 		global $post;
171 171
 
172
-		$select_course_woocommerce_product = get_post_meta( $post->ID, '_course_woocommerce_product', true );
172
+		$select_course_woocommerce_product = get_post_meta($post->ID, '_course_woocommerce_product', true);
173 173
 
174
-		$post_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
174
+		$post_args = array('post_type' 		=> array('product', 'product_variation'),
175 175
 							'posts_per_page' 		=> -1,
176 176
 							'orderby'         	=> 'title',
177 177
     						'order'           	=> 'DESC',
178 178
     						'exclude' 			=> $post->ID,
179
-    						'post_status'		=> array( 'publish', 'private', 'draft' ),
179
+    						'post_status'		=> array('publish', 'private', 'draft'),
180 180
     						'tax_query'			=> array(
181 181
 								array(
182 182
 									'taxonomy'	=> 'product_type',
183 183
 									'field'		=> 'slug',
184
-									'terms'		=> array( 'variable', 'grouped' ),
184
+									'terms'		=> array('variable', 'grouped'),
185 185
 									'operator'	=> 'NOT IN'
186 186
 								)
187 187
 							),
188 188
 							'suppress_filters' 	=> 0
189 189
 							);
190
-		$posts_array = get_posts( $post_args );
190
+		$posts_array = get_posts($post_args);
191 191
 
192 192
 		$html = '';
193 193
 
194
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
194
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
195 195
 
196
-		if ( count( $posts_array ) > 0 ) {
196
+		if (count($posts_array) > 0) {
197 197
 
198
-			$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n";
199
-			$html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>';
198
+			$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n";
199
+			$html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>';
200 200
 				$prev_parent_id = 0;
201
-				foreach ( $posts_array as $post_item ) {
201
+				foreach ($posts_array as $post_item) {
202 202
 
203
-					if ( 'product_variation' == $post_item->post_type ) {
203
+					if ('product_variation' == $post_item->post_type) {
204 204
 
205
-						$product_object = get_product( $post_item->ID );
206
-						$parent_id = wp_get_post_parent_id( $post_item->ID );
205
+						$product_object = get_product($post_item->ID);
206
+						$parent_id = wp_get_post_parent_id($post_item->ID);
207 207
 
208
-                        if( sensei_check_woocommerce_version( '2.1' ) ) {
209
-							$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
208
+                        if (sensei_check_woocommerce_version('2.1')) {
209
+							$formatted_variation = wc_get_formatted_variation($product_object->variation_data, true);
210 210
 
211 211
 						} else {
212 212
                             // fall back to pre wc 2.1
213
-							$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
213
+							$formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true);
214 214
 
215 215
 						}
216 216
 
217
-                        $product_name = ucwords( $formatted_variation );
218
-                        if( empty( $product_name ) ){
217
+                        $product_name = ucwords($formatted_variation);
218
+                        if (empty($product_name)) {
219 219
 
220
-                            $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id;
220
+                            $product_name = __('Variation #', 'woothemes-sensei').$product_object->variation_id;
221 221
 
222 222
                         }
223 223
 
@@ -230,47 +230,47 @@  discard block
 block discarded – undo
230 230
 					}
231 231
 
232 232
 					// Show variations in groups
233
-					if( $parent_id && $parent_id != $prev_parent_id ) {
233
+					if ($parent_id && $parent_id != $prev_parent_id) {
234 234
 
235
-						if( 0 != $prev_parent_id ) {
235
+						if (0 != $prev_parent_id) {
236 236
 
237 237
 							$html .= '</optgroup>';
238 238
 
239 239
 						}
240
-						$html .= '<optgroup label="' . get_the_title( $parent_id ) . '">';
240
+						$html .= '<optgroup label="'.get_the_title($parent_id).'">';
241 241
 						$prev_parent_id = $parent_id;
242 242
 
243
-					} elseif( ! $parent_id && 0 == $prev_parent_id ) {
243
+					} elseif ( ! $parent_id && 0 == $prev_parent_id) {
244 244
 
245 245
 						$html .= '</optgroup>';
246 246
 
247 247
 					}
248 248
 
249
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_woocommerce_product, false ) . '>' . esc_html( $product_name ) . '</option>' . "\n";
249
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_woocommerce_product, false).'>'.esc_html($product_name).'</option>'."\n";
250 250
 
251 251
 				} // End For Loop
252 252
 
253
-			$html .= '</select>' . "\n";
254
-			if ( current_user_can( 'publish_product' )) {
253
+			$html .= '</select>'."\n";
254
+			if (current_user_can('publish_product')) {
255 255
 
256
-				$html .= '<p>' . "\n";
257
-					$html .= '<a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Add a Product', 'woothemes-sensei' ) . '</a>' . "\n";
256
+				$html .= '<p>'."\n";
257
+					$html .= '<a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Add a Product', 'woothemes-sensei').'</a>'."\n";
258 258
 				$html .= '</p>'."\n";
259 259
 
260 260
 			} // End If Statement
261 261
 
262 262
 		} else {
263 263
 
264
-			if ( current_user_can( 'publish_product' )) {
264
+			if (current_user_can('publish_product')) {
265 265
 
266
-				$html .= '<p>' . "\n";
267
-					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . '&nbsp;<a href="' . admin_url( 'post-new.php?post_type=product' ) . '" title="' . esc_attr( __( 'Add a Product', 'woothemes-sensei' ) ) . '">' . __( 'Please add some first', 'woothemes-sensei' ) . '</a>' . "\n";
266
+				$html .= '<p>'."\n";
267
+					$html .= esc_html(__('No products exist yet.', 'woothemes-sensei')).'&nbsp;<a href="'.admin_url('post-new.php?post_type=product').'" title="'.esc_attr(__('Add a Product', 'woothemes-sensei')).'">'.__('Please add some first', 'woothemes-sensei').'</a>'."\n";
268 268
 				$html .= '</p>'."\n";
269 269
 
270 270
 			} else {
271 271
 
272
-                $html .= '<p>' . "\n";
273
-					$html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n";
272
+                $html .= '<p>'."\n";
273
+					$html .= esc_html(__('No products exist yet.', 'woothemes-sensei'))."\n";
274 274
 				$html .= '</p>'."\n";
275 275
 
276 276
 			} // End If Statement
@@ -287,33 +287,33 @@  discard block
 block discarded – undo
287 287
 	 * @access public
288 288
 	 * @return void
289 289
 	 */
290
-	public function course_prerequisite_meta_box_content () {
290
+	public function course_prerequisite_meta_box_content() {
291 291
 		global $post;
292 292
 
293
-		$select_course_prerequisite = get_post_meta( $post->ID, '_course_prerequisite', true );
293
+		$select_course_prerequisite = get_post_meta($post->ID, '_course_prerequisite', true);
294 294
 
295
-		$post_args = array(	'post_type' 		=> 'course',
295
+		$post_args = array('post_type' 		=> 'course',
296 296
 							'posts_per_page' 		=> -1,
297 297
 							'orderby'         	=> 'title',
298 298
     						'order'           	=> 'DESC',
299 299
     						'exclude' 			=> $post->ID,
300 300
 							'suppress_filters' 	=> 0
301 301
 							);
302
-		$posts_array = get_posts( $post_args );
302
+		$posts_array = get_posts($post_args);
303 303
 
304 304
 		$html = '';
305 305
 
306
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
306
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
307 307
 
308
-		if ( count( $posts_array ) > 0 ) {
309
-			$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n";
310
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
311
-				foreach ($posts_array as $post_item){
312
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_course_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
308
+		if (count($posts_array) > 0) {
309
+			$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n";
310
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
311
+				foreach ($posts_array as $post_item) {
312
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_course_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n";
313 313
 				} // End For Loop
314
-			$html .= '</select>' . "\n";
314
+			$html .= '</select>'."\n";
315 315
 		} else {
316
-			$html .= '<p>' . esc_html( __( 'No courses exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>';
316
+			$html .= '<p>'.esc_html(__('No courses exist yet. Please add some first.', 'woothemes-sensei')).'</p>';
317 317
 		} // End If Statement
318 318
 
319 319
 		echo $html;
@@ -326,21 +326,21 @@  discard block
 block discarded – undo
326 326
 	 * @access public
327 327
 	 * @return void
328 328
 	 */
329
-	public function course_featured_meta_box_content () {
329
+	public function course_featured_meta_box_content() {
330 330
 		global $post;
331 331
 
332
-		$course_featured = get_post_meta( $post->ID, '_course_featured', true );
332
+		$course_featured = get_post_meta($post->ID, '_course_featured', true);
333 333
 
334 334
 		$html = '';
335 335
 
336
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
336
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'.esc_attr('woo_'.$this->token.'_noonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
337 337
 
338 338
 		$checked = '';
339
-		if ( isset( $course_featured ) && ( '' != $course_featured ) ) {
340
-	 	    $checked = checked( 'featured', $course_featured, false );
339
+		if (isset($course_featured) && ('' != $course_featured)) {
340
+	 	    $checked = checked('featured', $course_featured, false);
341 341
 	 	} // End If Statement
342 342
 
343
-	 	$html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '>&nbsp;' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>';
343
+	 	$html .= '<input type="checkbox" name="course_featured" value="featured" '.$checked.'>&nbsp;'.__('Feature this course', 'woothemes-sensei').'<br>';
344 344
 
345 345
 		echo $html;
346 346
 
@@ -352,16 +352,16 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 * @return void
354 354
 	 */
355
-	public function course_video_meta_box_content () {
355
+	public function course_video_meta_box_content() {
356 356
 		global $post;
357 357
 
358
-		$course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
358
+		$course_video_embed = get_post_meta($post->ID, '_course_video_embed', true);
359 359
 
360 360
 		$html = '';
361 361
 
362
-		$html .= '<label class="screen-reader-text" for="course_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . '</label>';
363
-		$html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">' . $course_video_embed . '</textarea>';
364
-		$html .= '<p>' .  __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>';
362
+		$html .= '<label class="screen-reader-text" for="course_video_embed">'.__('Video Embed Code', 'woothemes-sensei').'</label>';
363
+		$html .= '<textarea rows="5" cols="50" name="course_video_embed" tabindex="6" id="course-video-embed">'.$course_video_embed.'</textarea>';
364
+		$html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>';
365 365
 
366 366
 		echo $html;
367 367
 
@@ -376,36 +376,36 @@  discard block
 block discarded – undo
376 376
 	 * @param int $post_id
377 377
 	 * @return int
378 378
 	 */
379
-	public function meta_box_save ( $post_id ) {
379
+	public function meta_box_save($post_id) {
380 380
 		global $post;
381 381
 
382 382
 		/* Verify the nonce before proceeding. */
383
-		if ( ( get_post_type() != $this->token ) || ! wp_verify_nonce( $_POST['woo_' . $this->token . '_noonce'], plugin_basename(__FILE__) ) ) {
383
+		if ((get_post_type() != $this->token) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_noonce'], plugin_basename(__FILE__))) {
384 384
 			return $post_id;
385 385
 		}
386 386
 
387 387
 		/* Get the post type object. */
388
-		$post_type = get_post_type_object( $post->post_type );
388
+		$post_type = get_post_type_object($post->post_type);
389 389
 
390 390
 		/* Check if the current user has permission to edit the post. */
391
-		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
391
+		if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
392 392
 			return $post_id;
393 393
 		} // End If Statement
394 394
 
395
-		if ( 'page' == $_POST['post_type'] ) {
396
-			if ( ! current_user_can( 'edit_page', $post_id ) ) {
395
+		if ('page' == $_POST['post_type']) {
396
+			if ( ! current_user_can('edit_page', $post_id)) {
397 397
 				return $post_id;
398 398
 			} // End If Statement
399 399
 		} else {
400
-			if ( ! current_user_can( 'edit_post', $post_id ) ) {
400
+			if ( ! current_user_can('edit_post', $post_id)) {
401 401
 				return $post_id;
402 402
 			} // End If Statement
403 403
 		} // End If Statement
404 404
 
405 405
 		// Save the post meta data fields
406
-		if ( isset($this->meta_fields) && is_array($this->meta_fields) ) {
407
-			foreach ( $this->meta_fields as $meta_key ) {
408
-				$this->save_post_meta( $meta_key, $post_id );
406
+		if (isset($this->meta_fields) && is_array($this->meta_fields)) {
407
+			foreach ($this->meta_fields as $meta_key) {
408
+				$this->save_post_meta($meta_key, $post_id);
409 409
 			} // End For Loop
410 410
 		} // End If Statement
411 411
 
@@ -422,18 +422,18 @@  discard block
 block discarded – undo
422 422
 	 * @param int $post_id (default: 0)
423 423
 	 * @return int new meta id | bool meta value saved status
424 424
 	 */
425
-	private function save_post_meta( $post_key = '', $post_id = 0 ) {
425
+	private function save_post_meta($post_key = '', $post_id = 0) {
426 426
 		// Get the meta key.
427
-		$meta_key = '_' . $post_key;
427
+		$meta_key = '_'.$post_key;
428 428
 		// Get the posted data and sanitize it for use as an HTML class.
429
-		if ( 'course_video_embed' == $post_key) {
430
-			$new_meta_value = esc_html( $_POST[$post_key] );
429
+		if ('course_video_embed' == $post_key) {
430
+			$new_meta_value = esc_html($_POST[$post_key]);
431 431
 		} else {
432
-			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
432
+			$new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : '');
433 433
 		} // End If Statement
434 434
 
435 435
         // update field with the new value
436
-        return update_post_meta( $post_id, $meta_key, $new_meta_value );
436
+        return update_post_meta($post_id, $meta_key, $new_meta_value);
437 437
 
438 438
 	} // End save_post_meta()
439 439
 
@@ -443,31 +443,31 @@  discard block
 block discarded – undo
443 443
 	 * @access public
444 444
 	 * @return void
445 445
 	 */
446
-	public function course_lessons_meta_box_content () {
446
+	public function course_lessons_meta_box_content() {
447 447
 
448 448
 		global $post;
449 449
 
450 450
 		// Setup Lesson Query
451 451
 		$posts_array = array();
452
-		if ( 0 < $post->ID ) {
452
+		if (0 < $post->ID) {
453 453
 
454
-			$posts_array = $this->course_lessons( $post->ID, 'any' );
454
+			$posts_array = $this->course_lessons($post->ID, 'any');
455 455
 
456 456
 		} // End If Statement
457 457
 
458 458
 		$html = '';
459
-		$html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="'
460
-                 . esc_attr( 'woo_' . $this->token . '_noonce' )
461
-                 . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />';
459
+		$html .= '<input type="hidden" name="'.esc_attr('woo_'.$this->token.'_noonce').'" id="'
460
+                 . esc_attr('woo_'.$this->token.'_noonce')
461
+                 . '" value="'.esc_attr(wp_create_nonce(plugin_basename(__FILE__))).'" />';
462 462
 
463
-		if ( count( $posts_array ) > 0 ) {
463
+		if (count($posts_array) > 0) {
464 464
 
465
-			foreach ($posts_array as $post_item){
465
+			foreach ($posts_array as $post_item) {
466 466
 
467 467
 				$html .= '<p>'."\n";
468 468
 
469 469
 					$html .= $post_item->post_title."\n";
470
-					$html .= '<a href="' . esc_url( get_edit_post_link( $post_item->ID ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $post_item->post_title ) ) . '" class="edit-lesson-action">' . __( 'Edit this lesson', 'woothemes-sensei' ) . '</a>';
470
+					$html .= '<a href="'.esc_url(get_edit_post_link($post_item->ID)).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $post_item->post_title)).'" class="edit-lesson-action">'.__('Edit this lesson', 'woothemes-sensei').'</a>';
471 471
 
472 472
 				$html .= '</p>'."\n";
473 473
 
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
 
476 476
 		} else {
477 477
 			$course_id = '';
478
-			if ( 0 < $post->ID ) { $course_id = '&course_id=' . $post->ID; }
479
-			$html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n";
478
+			if (0 < $post->ID) { $course_id = '&course_id='.$post->ID; }
479
+			$html .= '<p>'.esc_html(__('No lessons exist yet for this course.', 'woothemes-sensei'))."\n";
480 480
 
481
-				$html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id )
482
-                         . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">'
483
-                         . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n";
481
+				$html .= '<a href="'.admin_url('post-new.php?post_type=lesson'.$course_id)
482
+                         . '" title="'.esc_attr(__('Add a Lesson', 'woothemes-sensei')).'">'
483
+                         . __('Please add some.', 'woothemes-sensei').'</a>'."\n";
484 484
 
485 485
 			$html .= '</p>'."\n";
486 486
 		} // End If Statement
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
      * @return void
498 498
      */
499 499
 
500
-    public function course_manage_meta_box_content () {
500
+    public function course_manage_meta_box_content() {
501 501
         global $post;
502 502
         
503
-        $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
503
+        $manage_url = esc_url(add_query_arg(array('page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php')));
504 504
 
505
-        $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) );
505
+        $grading_url = esc_url(add_query_arg(array('page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners'), admin_url('admin.php')));
506 506
 
507 507
 
508 508
         echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>";
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
 	 * @param  array $defaults
521 521
 	 * @return array $new_columns
522 522
 	 */
523
-	public function add_column_headings ( $defaults ) {
523
+	public function add_column_headings($defaults) {
524 524
 		$new_columns['cb'] = '<input type="checkbox" />';
525 525
 		// $new_columns['id'] = __( 'ID' );
526
-		$new_columns['title'] = _x( 'Course Title', 'column name', 'woothemes-sensei' );
527
-		$new_columns['course-prerequisite'] = _x( 'Pre-requisite Course', 'column name', 'woothemes-sensei' );
528
-		if ( Sensei_WC::is_woocommerce_active() ) {
529
-			$new_columns['course-woocommerce-product'] = _x( 'WooCommerce Product', 'column name', 'woothemes-sensei' );
526
+		$new_columns['title'] = _x('Course Title', 'column name', 'woothemes-sensei');
527
+		$new_columns['course-prerequisite'] = _x('Pre-requisite Course', 'column name', 'woothemes-sensei');
528
+		if (Sensei_WC::is_woocommerce_active()) {
529
+			$new_columns['course-woocommerce-product'] = _x('WooCommerce Product', 'column name', 'woothemes-sensei');
530 530
 		} // End If Statement
531
-		$new_columns['course-category'] = _x( 'Category', 'column name', 'woothemes-sensei' );
532
-		if ( isset( $defaults['date'] ) ) {
531
+		$new_columns['course-category'] = _x('Category', 'column name', 'woothemes-sensei');
532
+		if (isset($defaults['date'])) {
533 533
 			$new_columns['date'] = $defaults['date'];
534 534
 		}
535 535
 
@@ -544,45 +544,45 @@  discard block
 block discarded – undo
544 544
 	 * @param  int $id
545 545
 	 * @return void
546 546
 	 */
547
-	public function add_column_data ( $column_name, $id ) {
547
+	public function add_column_data($column_name, $id) {
548 548
 		global $wpdb, $post;
549 549
 
550
-		switch ( $column_name ) {
550
+		switch ($column_name) {
551 551
 			case 'id':
552 552
 				echo $id;
553 553
 			break;
554 554
 
555 555
 			case 'course-prerequisite':
556
-				$course_prerequisite_id = get_post_meta( $id, '_course_prerequisite', true);
557
-				if ( 0 < absint( $course_prerequisite_id ) ) { echo '<a href="' . esc_url( get_edit_post_link( absint( $course_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $course_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $course_prerequisite_id ) ) . '</a>'; }
556
+				$course_prerequisite_id = get_post_meta($id, '_course_prerequisite', true);
557
+				if (0 < absint($course_prerequisite_id)) { echo '<a href="'.esc_url(get_edit_post_link(absint($course_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($course_prerequisite_id)))).'">'.get_the_title(absint($course_prerequisite_id)).'</a>'; }
558 558
 
559 559
 			break;
560 560
 
561 561
 			case 'course-woocommerce-product':
562
-				if ( Sensei_WC::is_woocommerce_active() ) {
563
-					$course_woocommerce_product_id = get_post_meta( $id, '_course_woocommerce_product', true);
564
-					if ( 0 < absint( $course_woocommerce_product_id ) ) {
565
-						if ( 'product_variation' == get_post_type( $course_woocommerce_product_id ) ) {
566
-							$product_object = get_product( $course_woocommerce_product_id );
567
-							if( sensei_check_woocommerce_version( '2.1' ) ) {
568
-								$formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true );
562
+				if (Sensei_WC::is_woocommerce_active()) {
563
+					$course_woocommerce_product_id = get_post_meta($id, '_course_woocommerce_product', true);
564
+					if (0 < absint($course_woocommerce_product_id)) {
565
+						if ('product_variation' == get_post_type($course_woocommerce_product_id)) {
566
+							$product_object = get_product($course_woocommerce_product_id);
567
+							if (sensei_check_woocommerce_version('2.1')) {
568
+								$formatted_variation = wc_get_formatted_variation($product_object->variation_data, true);
569 569
 							} else {
570
-								$formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true );
570
+								$formatted_variation = woocommerce_get_formatted_variation($product_object->variation_data, true);
571 571
 							}
572 572
 							$course_woocommerce_product_id = $product_object->parent->post->ID;
573
-							$product_name = $product_object->parent->post->post_title . '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . ucwords( $formatted_variation );
573
+							$product_name = $product_object->parent->post->post_title.'<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.ucwords($formatted_variation);
574 574
 						} else {
575
-							$product_name = get_the_title( absint( $course_woocommerce_product_id ) );
575
+							$product_name = get_the_title(absint($course_woocommerce_product_id));
576 576
 						} // End If Statement
577
-						echo '<a href="' . esc_url( get_edit_post_link( absint( $course_woocommerce_product_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), $product_name ) ) . '">' . $product_name . '</a>';
577
+						echo '<a href="'.esc_url(get_edit_post_link(absint($course_woocommerce_product_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), $product_name)).'">'.$product_name.'</a>';
578 578
 					} // End If Statement
579 579
 				} // End If Statement
580 580
 			break;
581 581
 
582 582
 			case 'course-category':
583
-				$output = get_the_term_list( $id, 'course-category', '', ', ', '' );
584
-				if ( '' == $output ) {
585
-					$output = __( 'None', 'woothemes-sensei' );
583
+				$output = get_the_term_list($id, 'course-category', '', ', ', '');
584
+				if ('' == $output) {
585
+					$output = __('None', 'woothemes-sensei');
586 586
 				} // End If Statement
587 587
 				echo $output;
588 588
 			break;
@@ -602,29 +602,29 @@  discard block
 block discarded – undo
602 602
 	 * @param array $includes (default: array())
603 603
 	 * @return array
604 604
 	 */
605
-	public function course_query( $amount = 0, $type = 'default', $includes = array(), $excludes = array() ) {
606
-		global $my_courses_page ;
605
+	public function course_query($amount = 0, $type = 'default', $includes = array(), $excludes = array()) {
606
+		global $my_courses_page;
607 607
 
608 608
 		$results_array = array();
609 609
 
610
-		if( $my_courses_page ) { add_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); }
610
+		if ($my_courses_page) { add_action('pre_get_posts', array($this, 'filter_my_courses')); }
611 611
 
612
-		$post_args = $this->get_archive_query_args( $type, $amount, $includes, $excludes );
612
+		$post_args = $this->get_archive_query_args($type, $amount, $includes, $excludes);
613 613
 
614 614
 		// get the posts
615
-		if( empty( $post_args ) ) {
615
+		if (empty($post_args)) {
616 616
 
617 617
 			return $results_array;
618 618
 
619
-		}else{
619
+		} else {
620 620
 
621 621
 			//reset the pagination as this widgets do not need it
622 622
 			$post_args['paged'] = 1;
623
-			$results_array = get_posts( $post_args );
623
+			$results_array = get_posts($post_args);
624 624
 
625 625
 		}
626 626
 
627
-		if( $my_courses_page ) { remove_action( 'pre_get_posts', array( $this, 'filter_my_courses' ) ); }
627
+		if ($my_courses_page) { remove_action('pre_get_posts', array($this, 'filter_my_courses')); }
628 628
 
629 629
 		return $results_array;
630 630
 
@@ -640,22 +640,22 @@  discard block
 block discarded – undo
640 640
 	 * @param array $includes (default: array())
641 641
 	 * @return array
642 642
 	 */
643
-	public function get_archive_query_args( $type = '', $amount = 0 , $includes = array(), $excludes = array() ) {
643
+	public function get_archive_query_args($type = '', $amount = 0, $includes = array(), $excludes = array()) {
644 644
 
645 645
 		global $wp_query;
646 646
 
647
-		if ( 0 == $amount && ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && 'usercourses' != $type && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) ) {
648
-			$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
647
+		if (0 == $amount && (isset(Sensei()->settings->settings['course_archive_amount']) && 'usercourses' != $type && (0 < absint(Sensei()->settings->settings['course_archive_amount'])))) {
648
+			$amount = absint(Sensei()->settings->settings['course_archive_amount']);
649 649
 		} else {
650
-			if ( 0 == $amount) {
651
-				$amount = $wp_query->get( 'posts_per_page' );
650
+			if (0 == $amount) {
651
+				$amount = $wp_query->get('posts_per_page');
652 652
 			} // End If Statement
653 653
 		} // End If Statement
654 654
 
655
-        $stored_order = get_option( 'sensei_course_order', '' );
655
+        $stored_order = get_option('sensei_course_order', '');
656 656
         $order = 'ASC';
657 657
         $orderby = 'menu_order';
658
-        if( empty( $stored_order ) ){
658
+        if (empty($stored_order)) {
659 659
 
660 660
             $order = 'DESC';
661 661
             $orderby = 'date';
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		switch ($type) {
666 666
 
667 667
 			case 'usercourses':
668
-				$post_args = array(	'post_type' 		=> 'course',
668
+				$post_args = array('post_type' 		=> 'course',
669 669
 									'orderby'         	=> $orderby,
670 670
     								'order'           	=> $order,
671 671
     								'post_status'      	=> 'publish',
@@ -706,7 +706,7 @@  discard block
 block discarded – undo
706 706
 				break;
707 707
 
708 708
 			case 'featuredcourses':
709
-                $post_args = array(	'post_type' 		=> 'course',
709
+                $post_args = array('post_type' 		=> 'course',
710 710
                                     'orderby'         	=> $orderby,
711 711
                                     'order'           	=> $order,
712 712
     								'post_status'      	=> 'publish',
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 									);
719 719
 				break;
720 720
 			default:
721
-				$post_args = array(	'post_type' 		=> 'course',
721
+				$post_args = array('post_type' 		=> 'course',
722 722
                                     'orderby'         	=> $orderby,
723 723
                                     'order'           	=> $order,
724 724
     								'post_status'      	=> 'publish',
@@ -730,13 +730,13 @@  discard block
 block discarded – undo
730 730
 		}
731 731
 
732 732
         $post_args['posts_per_page'] = $amount;
733
-        $paged = $wp_query->get( 'paged' );
734
-        $post_args['paged'] = empty( $paged) ? 1 : $paged;
733
+        $paged = $wp_query->get('paged');
734
+        $post_args['paged'] = empty($paged) ? 1 : $paged;
735 735
 
736
-        if( 'newcourses' == $type ){
736
+        if ('newcourses' == $type) {
737 737
 
738
-            $post_args[ 'orderby' ] = 'date';
739
-            $post_args[ 'order' ] = 'DESC';
738
+            $post_args['orderby'] = 'date';
739
+            $post_args['order'] = 'DESC';
740 740
         }
741 741
 
742 742
 		return $post_args;
@@ -758,15 +758,15 @@  discard block
 block discarded – undo
758 758
      *
759 759
 	 * @return string | void
760 760
 	 */
761
-	public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) {
761
+	public function course_image($course_id = 0, $width = '100', $height = '100', $return = false) {
762 762
 
763
-        if ( is_a( $course_id, 'WP_Post' ) ) {
763
+        if (is_a($course_id, 'WP_Post')) {
764 764
 
765 765
 	        $course_id = $course_id->ID;
766 766
 
767 767
         }
768 768
 
769
-		if ( 'course' !== get_post_type( $course_id )  ){
769
+		if ('course' !== get_post_type($course_id)) {
770 770
 
771 771
 			return;
772 772
 
@@ -775,26 +775,26 @@  discard block
 block discarded – undo
775 775
 		$html = '';
776 776
 
777 777
 		// Get Width and Height settings
778
-		if ( ( $width == '100' ) && ( $height == '100' ) ) {
778
+		if (($width == '100') && ($height == '100')) {
779 779
 
780
-			if ( is_singular( 'course' ) ) {
780
+			if (is_singular('course')) {
781 781
 
782
-				if ( !Sensei()->settings->settings[ 'course_single_image_enable' ] ) {
782
+				if ( ! Sensei()->settings->settings['course_single_image_enable']) {
783 783
 					return '';
784 784
 				} // End If Statement
785 785
 				$image_thumb_size = 'course_single_image';
786
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
786
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
787 787
 				$width = $dimensions['width'];
788 788
 				$height = $dimensions['height'];
789 789
 
790 790
 			} else {
791 791
 
792
-				if ( !Sensei()->settings->settings[ 'course_archive_image_enable' ] ) {
792
+				if ( ! Sensei()->settings->settings['course_archive_image_enable']) {
793 793
 					return '';
794 794
 				} // End If Statement
795 795
 
796 796
 				$image_thumb_size = 'course_archive_image';
797
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
797
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
798 798
 				$width = $dimensions['width'];
799 799
 				$height = $dimensions['height'];
800 800
 
@@ -803,31 +803,31 @@  discard block
 block discarded – undo
803 803
 		} // End If Statement
804 804
 
805 805
 		$img_url = '';
806
-		if ( has_post_thumbnail( $course_id ) ) {
806
+		if (has_post_thumbnail($course_id)) {
807 807
    			// Get Featured Image
808
-   			$img_url = get_the_post_thumbnail( $course_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
808
+   			$img_url = get_the_post_thumbnail($course_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
809 809
  		} else {
810 810
 
811 811
 			// Check for a Lesson Image
812
-			$course_lessons = $this->course_lessons( $course_id );
812
+			$course_lessons = $this->course_lessons($course_id);
813 813
 
814
-			foreach ($course_lessons as $lesson_item){
815
-				if ( has_post_thumbnail( $lesson_item->ID ) ) {
814
+			foreach ($course_lessons as $lesson_item) {
815
+				if (has_post_thumbnail($lesson_item->ID)) {
816 816
 					// Get Featured Image
817
-					$img_url = get_the_post_thumbnail( $lesson_item->ID, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
818
-					if ( '' != $img_url ) {
817
+					$img_url = get_the_post_thumbnail($lesson_item->ID, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
818
+					if ('' != $img_url) {
819 819
 						break;
820 820
 					} // End If Statement
821 821
 
822 822
 				} // End If Statement
823 823
 			} // End For Loop
824 824
 
825
- 			if ( '' == $img_url ) {
825
+ 			if ('' == $img_url) {
826 826
 
827 827
  				// Display Image Placeholder if none
828
-				if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) {
828
+				if (Sensei()->settings->get('placeholder_images_enable')) {
829 829
                     
830
-                    $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
830
+                    $img_url = apply_filters('sensei_course_placeholder_image_url', '<img src="'.Sensei()->plugin_url.'assets/images/placeholder.png" width="'.$width.'" height="'.$height.'" class="woo-image thumbnail alignleft" />');
831 831
 
832 832
 				} // End If Statement
833 833
 
@@ -835,17 +835,17 @@  discard block
 block discarded – undo
835 835
 
836 836
 		} // End If Statement
837 837
 
838
-		if ( '' != $img_url ) {
838
+		if ('' != $img_url) {
839 839
 
840
-			$html .= '<a href="' . get_permalink( $course_id ) . '" class="course-featured-image" title="' . esc_attr( get_post_field( 'post_title', $course_id ) ) . '">' . $img_url  .'</a>';
840
+			$html .= '<a href="'.get_permalink($course_id).'" class="course-featured-image" title="'.esc_attr(get_post_field('post_title', $course_id)).'">'.$img_url.'</a>';
841 841
 
842 842
 		} // End If Statement
843 843
 
844
-        if( $return ){
844
+        if ($return) {
845 845
 
846 846
             return $html;
847 847
 
848
-        }else{
848
+        } else {
849 849
 
850 850
             echo $html;
851 851
 
@@ -862,9 +862,9 @@  discard block
 block discarded – undo
862 862
 	 * @param string $post_status (default: 'publish')
863 863
 	 * @return int
864 864
 	 */
865
-	public function course_count( $post_status = 'publish' ) {
865
+	public function course_count($post_status = 'publish') {
866 866
 
867
-		$post_args = array(	'post_type'         => 'course',
867
+		$post_args = array('post_type'         => 'course',
868 868
 							'posts_per_page'    => -1,
869 869
 //							'orderby'           => 'menu_order date',
870 870
 //							'order'             => 'ASC',
@@ -875,10 +875,10 @@  discard block
 block discarded – undo
875 875
 
876 876
 		// Allow WP to generate the complex final query, just shortcut to only do an overall count
877 877
 //		add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
878
-		$courses_query = new WP_Query( apply_filters( 'sensei_course_count', $post_args ) );
878
+		$courses_query = new WP_Query(apply_filters('sensei_course_count', $post_args));
879 879
 //		remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
880 880
 
881
-		return count( $courses_query->posts );
881
+		return count($courses_query->posts);
882 882
 	} // End course_count()
883 883
 
884 884
 
@@ -891,42 +891,42 @@  discard block
 block discarded – undo
891 891
 	 * @param string $fields (default: 'all'). WP only allows 3 types, but we will limit it to only 'ids' or 'all'
892 892
 	 * @return array{ type WP_Post }  $posts_array
893 893
 	 */
894
-	public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) {
894
+	public function course_lessons($course_id = 0, $post_status = 'publish', $fields = 'all') {
895 895
 
896
-        if( is_a( $course_id, 'WP_Post' ) ){
896
+        if (is_a($course_id, 'WP_Post')) {
897 897
             $course_id = $course_id->ID;
898 898
         }
899 899
 
900
-		$post_args = array(	'post_type'         => 'lesson',
900
+		$post_args = array('post_type'         => 'lesson',
901 901
 							'posts_per_page'       => -1,
902 902
 							'orderby'           => 'date',
903 903
 							'order'             => 'ASC',
904 904
 							'meta_query'        => array(
905 905
 								array(
906 906
 									'key' => '_lesson_course',
907
-									'value' => intval( $course_id ),
907
+									'value' => intval($course_id),
908 908
 								),
909 909
 							),
910 910
 							'post_status'       => $post_status,
911 911
 							'suppress_filters'  => 0,
912 912
 							);
913
-		$query_results = new WP_Query( $post_args );
913
+		$query_results = new WP_Query($post_args);
914 914
         $lessons = $query_results->posts;
915 915
 
916 916
         // re order the lessons. This could not be done via the OR meta query as there may be lessons
917 917
         // with the course order for a different course and this should not be included. It could also not
918 918
         // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but
919 919
         // that have been added to the course.
920
-        if( count( $lessons) > 1  ){
920
+        if (count($lessons) > 1) {
921 921
 
922
-            foreach( $lessons as $lesson ){
922
+            foreach ($lessons as $lesson) {
923 923
 
924
-                $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) );
924
+                $order = intval(get_post_meta($lesson->ID, '_order_'.$course_id, true));
925 925
                 // for lessons with no order set it to be 10000 so that it show up at the end
926 926
                 $lesson->course_order = $order ? $order : 100000;
927 927
             }
928 928
 
929
-            uasort( $lessons, array( $this, '_short_course_lessons_callback' )   );
929
+            uasort($lessons, array($this, '_short_course_lessons_callback'));
930 930
         }
931 931
 
932 932
         /**
@@ -937,12 +937,12 @@  discard block
 block discarded – undo
937 937
          * @param array $lessons
938 938
          * @param int $course_id
939 939
          */
940
-        $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id  );
940
+        $lessons = apply_filters('sensei_course_get_lessons', $lessons, $course_id);
941 941
 
942 942
         //return the requested fields
943 943
         // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson
944 944
         // objects
945
-        if( 'ids' == $fields ) {
945
+        if ('ids' == $fields) {
946 946
             $lesson_objects = $lessons;
947 947
             $lessons = array();
948 948
 
@@ -964,9 +964,9 @@  discard block
 block discarded – undo
964 964
      * @param array $lesson_2
965 965
      * @return int
966 966
      */
967
-    protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){
967
+    protected function _short_course_lessons_callback($lesson_1, $lesson_2) {
968 968
 
969
-        if ( $lesson_1->course_order == $lesson_2->course_order ) {
969
+        if ($lesson_1->course_order == $lesson_2->course_order) {
970 970
             return 0;
971 971
         }
972 972
 
@@ -980,21 +980,21 @@  discard block
 block discarded – undo
980 980
 	 * @param  boolean $boolean_check True if a simple yes/no is required
981 981
 	 * @return array              Array of quiz post objects
982 982
 	 */
983
-	public function course_quizzes( $course_id = 0, $boolean_check = false ) {
983
+	public function course_quizzes($course_id = 0, $boolean_check = false) {
984 984
 
985 985
 
986 986
 		$course_quizzes = array();
987 987
 
988
-		if( $course_id ) {
989
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
988
+		if ($course_id) {
989
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
990 990
 
991
-			foreach( $lesson_ids as $lesson_id ) {
992
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
993
-				if ( $has_questions && $boolean_check ) {
991
+			foreach ($lesson_ids as $lesson_id) {
992
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
993
+				if ($has_questions && $boolean_check) {
994 994
 					return true;
995 995
 				}
996
-				elseif ( $has_questions ) {
997
-					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
996
+				elseif ($has_questions) {
997
+					$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
998 998
 //					$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
999 999
 //					if( count( $questions ) > 0 ) {
1000 1000
 						$course_quizzes[] = $quiz_id;
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
 				}
1003 1003
 			}
1004 1004
 		}
1005
-		if ( $boolean_check && empty($course_quizzes) ) {
1005
+		if ($boolean_check && empty($course_quizzes)) {
1006 1006
 			$course_quizzes = false;
1007 1007
 		}
1008 1008
 		return $course_quizzes;
@@ -1017,9 +1017,9 @@  discard block
 block discarded – undo
1017 1017
 	 * @param  string $post_status (default: 'publish')
1018 1018
 	 * @return array
1019 1019
 	 */
1020
-	public function course_lessons_completed( $course_id = 0, $post_status = 'publish' ) {
1020
+	public function course_lessons_completed($course_id = 0, $post_status = 'publish') {
1021 1021
 
1022
-		return $this->course_lessons( $course_id, $post_status );
1022
+		return $this->course_lessons($course_id, $post_status);
1023 1023
 
1024 1024
 	} // End course_lessons_completed()
1025 1025
 
@@ -1032,9 +1032,9 @@  discard block
 block discarded – undo
1032 1032
 	 * @param  int $course_id (default: 0)
1033 1033
 	 * @return int
1034 1034
 	 */
1035
-	public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) {
1035
+	public function course_author_lesson_count($author_id = 0, $course_id = 0) {
1036 1036
 
1037
-        $lesson_args = array(	'post_type' 		=> 'lesson',
1037
+        $lesson_args = array('post_type' 		=> 'lesson',
1038 1038
 								'posts_per_page' 		=> -1,
1039 1039
 		    					'author'         	=> $author_id,
1040 1040
 		    					'meta_key'        	=> '_lesson_course',
@@ -1043,8 +1043,8 @@  discard block
 block discarded – undo
1043 1043
     	    					'suppress_filters' 	=> 0,
1044 1044
 								'fields'            => 'ids', // less data to retrieve
1045 1045
 		    				);
1046
-		$lessons_array = get_posts( $lesson_args );
1047
-		$count = count( $lessons_array );
1046
+		$lessons_array = get_posts($lesson_args);
1047
+		$count = count($lessons_array);
1048 1048
 		return $count;
1049 1049
 
1050 1050
 	} // End course_author_lesson_count()
@@ -1056,9 +1056,9 @@  discard block
 block discarded – undo
1056 1056
 	 * @param  int $course_id (default: 0)
1057 1057
 	 * @return int
1058 1058
 	 */
1059
-	public function course_lesson_count( $course_id = 0 ) {
1059
+	public function course_lesson_count($course_id = 0) {
1060 1060
 
1061
-		$lesson_args = array(	'post_type' 		=> 'lesson',
1061
+		$lesson_args = array('post_type' 		=> 'lesson',
1062 1062
 								'posts_per_page' 		=> -1,
1063 1063
 		    					'meta_key'        	=> '_lesson_course',
1064 1064
     							'meta_value'      	=> $course_id,
@@ -1066,9 +1066,9 @@  discard block
 block discarded – undo
1066 1066
     	    					'suppress_filters' 	=> 0,
1067 1067
 								'fields'            => 'ids', // less data to retrieve
1068 1068
 		    				);
1069
-		$lessons_array = get_posts( $lesson_args );
1069
+		$lessons_array = get_posts($lesson_args);
1070 1070
 
1071
-        $count = count( $lessons_array );
1071
+        $count = count($lessons_array);
1072 1072
 
1073 1073
         return $count;
1074 1074
 
@@ -1081,9 +1081,9 @@  discard block
 block discarded – undo
1081 1081
 	 * @param  int $course_id (default: 0)
1082 1082
 	 * @return int
1083 1083
 	 */
1084
-	public function course_lesson_preview_count( $course_id = 0 ) {
1084
+	public function course_lesson_preview_count($course_id = 0) {
1085 1085
 
1086
-		$lesson_args = array(	'post_type' 		=> 'lesson',
1086
+		$lesson_args = array('post_type' 		=> 'lesson',
1087 1087
 								'posts_per_page' 		=> -1,
1088 1088
     	    					'post_status'      	=> 'publish',
1089 1089
     	    					'suppress_filters' 	=> 0,
@@ -1099,9 +1099,9 @@  discard block
 block discarded – undo
1099 1099
 								),
1100 1100
 								'fields'            => 'ids', // less data to retrieve
1101 1101
 		    				);
1102
-		$lessons_array = get_posts( $lesson_args );
1102
+		$lessons_array = get_posts($lesson_args);
1103 1103
 
1104
-		$count = count( $lessons_array );
1104
+		$count = count($lessons_array);
1105 1105
 
1106 1106
         return $count;
1107 1107
 
@@ -1114,12 +1114,12 @@  discard block
 block discarded – undo
1114 1114
 	 * @param  int $product_id (default: 0)
1115 1115
 	 * @return array
1116 1116
 	 */
1117
-	public function get_product_courses( $product_id = 0 ) {
1117
+	public function get_product_courses($product_id = 0) {
1118 1118
 
1119 1119
 		$posts_array = array();
1120 1120
 		// Check for WooCommerce
1121
-		if ( Sensei_WC::is_woocommerce_active() && 0 < $product_id ) {
1122
-			$post_args = array(	'post_type' 		=> 'course',
1121
+		if (Sensei_WC::is_woocommerce_active() && 0 < $product_id) {
1122
+			$post_args = array('post_type' 		=> 'course',
1123 1123
 								'posts_per_page' 		=> -1,
1124 1124
 								'meta_key'        	=> '_course_woocommerce_product',
1125 1125
 	    						'meta_value'      	=> $product_id,
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
 								'orderby' 			=> 'menu_order date',
1129 1129
 								'order' 			=> 'ASC',
1130 1130
 								);
1131
-			$posts_array = get_posts( $post_args );
1131
+			$posts_array = get_posts($post_args);
1132 1132
 		} // End If Statement
1133 1133
 		return $posts_array;
1134 1134
 
@@ -1139,17 +1139,17 @@  discard block
 block discarded – undo
1139 1139
 	 * @param  WP_Query $query
1140 1140
 	 * @return void
1141 1141
 	 */
1142
-	public function filter_my_courses( $query ) {
1142
+	public function filter_my_courses($query) {
1143 1143
 		global  $my_courses_section;
1144 1144
 
1145
-		if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1146
-			$amount = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1147
-			$query->set( 'posts_per_page', $amount );
1145
+		if (isset(Sensei()->settings->settings['my_course_amount']) && (0 < absint(Sensei()->settings->settings['my_course_amount']))) {
1146
+			$amount = absint(Sensei()->settings->settings['my_course_amount']);
1147
+			$query->set('posts_per_page', $amount);
1148 1148
 		}
1149 1149
 
1150
-		if( isset( $_GET[ $my_courses_section . '_page' ] ) && 0 < intval( $_GET[ $my_courses_section . '_page' ] ) ) {
1151
-			$page = intval( $_GET[ $my_courses_section . '_page' ] );
1152
-			$query->set( 'paged', $page );
1150
+		if (isset($_GET[$my_courses_section.'_page']) && 0 < intval($_GET[$my_courses_section.'_page'])) {
1151
+			$page = intval($_GET[$my_courses_section.'_page']);
1152
+			$query->set('paged', $page);
1153 1153
 		}
1154 1154
 	}
1155 1155
 
@@ -1163,48 +1163,48 @@  discard block
 block discarded – undo
1163 1163
 	 * @param  boolean $manage Whether the user has permission to manage the courses
1164 1164
 	 * @return string          HTML displayng course data
1165 1165
 	 */
1166
-	public function load_user_courses_content( $user = false ) {
1166
+	public function load_user_courses_content($user = false) {
1167 1167
 		global $course, $my_courses_page, $my_courses_section;
1168 1168
 
1169
-        if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] )
1170
-            || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) {
1169
+        if ( ! isset(Sensei()->settings->settings['learner_profile_show_courses'])
1170
+            || ! Sensei()->settings->settings['learner_profile_show_courses']) {
1171 1171
 
1172 1172
             // do not show the content if the settings doesn't allow for it
1173 1173
             return;
1174 1174
 
1175 1175
         }
1176 1176
 
1177
-        $manage = ( $user->ID == get_current_user_id() ) ? true : false;
1177
+        $manage = ($user->ID == get_current_user_id()) ? true : false;
1178 1178
 
1179
-        do_action( 'sensei_before_learner_course_content', $user );
1179
+        do_action('sensei_before_learner_course_content', $user);
1180 1180
 
1181 1181
 		// Build Output HTML
1182 1182
 		$complete_html = $active_html = '';
1183 1183
 
1184
-		if( is_a( $user, 'WP_User' ) ) {
1184
+		if (is_a($user, 'WP_User')) {
1185 1185
 
1186 1186
 			$my_courses_page = true;
1187 1187
 
1188 1188
 			// Allow action to be run before My Courses content has loaded
1189
-			do_action( 'sensei_before_my_courses', $user->ID );
1189
+			do_action('sensei_before_my_courses', $user->ID);
1190 1190
 
1191 1191
 			// Logic for Active and Completed Courses
1192 1192
 			$per_page = 20;
1193
-			if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] )
1194
-                && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) {
1193
+			if (isset(Sensei()->settings->settings['my_course_amount'])
1194
+                && (0 < absint(Sensei()->settings->settings['my_course_amount']))) {
1195 1195
 
1196
-				$per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] );
1196
+				$per_page = absint(Sensei()->settings->settings['my_course_amount']);
1197 1197
 
1198 1198
 			}
1199 1199
 
1200
-			$course_statuses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user->ID, 'type' => 'sensei_course_status' ), true );
1200
+			$course_statuses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user->ID, 'type' => 'sensei_course_status'), true);
1201 1201
 			// User may only be on 1 Course
1202
-			if ( !is_array($course_statuses) ) {
1203
-				$course_statuses = array( $course_statuses );
1202
+			if ( ! is_array($course_statuses)) {
1203
+				$course_statuses = array($course_statuses);
1204 1204
 			}
1205 1205
 			$completed_ids = $active_ids = array();
1206
-			foreach( $course_statuses as $course_status ) {
1207
-				if ( Sensei_Utils::user_completed_course( $course_status, $user->ID ) ) {
1206
+			foreach ($course_statuses as $course_status) {
1207
+				if (Sensei_Utils::user_completed_course($course_status, $user->ID)) {
1208 1208
 					$completed_ids[] = $course_status->comment_post_ID;
1209 1209
 				} else {
1210 1210
 					$active_ids[] = $course_status->comment_post_ID;
@@ -1214,41 +1214,41 @@  discard block
 block discarded – undo
1214 1214
 			$active_count = $completed_count = 0;
1215 1215
 
1216 1216
 			$active_courses = array();
1217
-			if ( 0 < intval( count( $active_ids ) ) ) {
1217
+			if (0 < intval(count($active_ids))) {
1218 1218
 				$my_courses_section = 'active';
1219
-				$active_courses = Sensei()->course->course_query( $per_page, 'usercourses', $active_ids );
1220
-				$active_count = count( $active_ids );
1219
+				$active_courses = Sensei()->course->course_query($per_page, 'usercourses', $active_ids);
1220
+				$active_count = count($active_ids);
1221 1221
 			} // End If Statement
1222 1222
 
1223 1223
 			$completed_courses = array();
1224
-			if ( 0 < intval( count( $completed_ids ) ) ) {
1224
+			if (0 < intval(count($completed_ids))) {
1225 1225
 				$my_courses_section = 'completed';
1226
-				$completed_courses = Sensei()->course->course_query( $per_page, 'usercourses', $completed_ids );
1227
-				$completed_count = count( $completed_ids );
1226
+				$completed_courses = Sensei()->course->course_query($per_page, 'usercourses', $completed_ids);
1227
+				$completed_count = count($completed_ids);
1228 1228
 			} // End If Statement
1229 1229
 
1230
-			foreach ( $active_courses as $course_item ) {
1230
+			foreach ($active_courses as $course_item) {
1231 1231
 
1232
-				$course_lessons =  Sensei()->course->course_lessons( $course_item->ID );
1232
+				$course_lessons = Sensei()->course->course_lessons($course_item->ID);
1233 1233
 				$lessons_completed = 0;
1234
-				foreach ( $course_lessons as $lesson ) {
1235
-					if ( Sensei_Utils::user_completed_lesson( $lesson->ID, $user->ID ) ) {
1234
+				foreach ($course_lessons as $lesson) {
1235
+					if (Sensei_Utils::user_completed_lesson($lesson->ID, $user->ID)) {
1236 1236
 						++$lessons_completed;
1237 1237
 					}
1238 1238
 				}
1239 1239
 
1240 1240
 			    // Get Course Categories
1241
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1241
+			    $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', '');
1242 1242
 
1243
-                $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">';
1243
+                $active_html .= '<article class="'.esc_attr(join(' ', get_post_class(array('course', 'post'), $course_item->ID))).'">';
1244 1244
 
1245 1245
                 // Image
1246
-                $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true );
1246
+                $active_html .= Sensei()->course->course_image(absint($course_item->ID), '100', '100', true);
1247 1247
 
1248 1248
                 // Title
1249 1249
                 $active_html .= '<header>';
1250 1250
 
1251
-                $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1251
+                $active_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>';
1252 1252
 
1253 1253
                 $active_html .= '</header>';
1254 1254
 
@@ -1257,74 +1257,74 @@  discard block
 block discarded – undo
1257 1257
                 $active_html .= '<p class="sensei-course-meta">';
1258 1258
 
1259 1259
                 // Author
1260
-                $user_info = get_userdata( absint( $course_item->post_author ) );
1261
-                if ( isset( Sensei()->settings->settings[ 'course_author' ] )
1262
-                    && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1260
+                $user_info = get_userdata(absint($course_item->post_author));
1261
+                if (isset(Sensei()->settings->settings['course_author'])
1262
+                    && (Sensei()->settings->settings['course_author'])) {
1263 1263
 
1264 1264
                     $active_html .= '<span class="course-author">'
1265
-                        . __( 'by ', 'woothemes-sensei' )
1266
-                        . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) )
1267
-                        . '" title="' . esc_attr( $user_info->display_name ) . '">'
1268
-                        . esc_html( $user_info->display_name )
1265
+                        . __('by ', 'woothemes-sensei')
1266
+                        . '<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author)))
1267
+                        . '" title="'.esc_attr($user_info->display_name).'">'
1268
+                        . esc_html($user_info->display_name)
1269 1269
                         . '</a></span>';
1270 1270
 
1271 1271
                 } // End If Statement
1272 1272
 
1273 1273
                 // Lesson count for this author
1274
-                $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) );
1274
+                $lesson_count = Sensei()->course->course_lesson_count(absint($course_item->ID));
1275 1275
                 // Handle Division by Zero
1276
-                if ( 0 == $lesson_count ) {
1276
+                if (0 == $lesson_count) {
1277 1277
 
1278 1278
                     $lesson_count = 1;
1279 1279
 
1280 1280
                 } // End If Statement
1281
-                $active_html .= '<span class="course-lesson-count">' . $lesson_count . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ) . '</span>';
1281
+                $active_html .= '<span class="course-lesson-count">'.$lesson_count.'&nbsp;'.__('Lessons', 'woothemes-sensei').'</span>';
1282 1282
                 // Course Categories
1283
-                if ( '' != $category_output ) {
1283
+                if ('' != $category_output) {
1284 1284
 
1285
-                    $active_html .= '<span class="course-category">' . sprintf( __( 'Categories: %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1285
+                    $active_html .= '<span class="course-category">'.sprintf(__('Categories: %s', 'woothemes-sensei'), $category_output).'</span>';
1286 1286
 
1287 1287
                 } // End If Statement
1288
-                $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count  ) . '</span>';
1288
+                $active_html .= '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $lessons_completed, $lesson_count).'</span>';
1289 1289
 
1290 1290
                 $active_html .= '</p>';
1291 1291
 
1292
-                $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1292
+                $active_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>';
1293 1293
 
1294 1294
 
1295 1295
 
1296
-                $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) );
1296
+                $progress_percentage = abs(round((doubleval($lessons_completed) * 100) / ($lesson_count), 0));
1297 1297
 
1298
-                $active_html .= $this->get_progress_meter( $progress_percentage );
1298
+                $active_html .= $this->get_progress_meter($progress_percentage);
1299 1299
 
1300 1300
                 $active_html .= '</section>';
1301 1301
 
1302
-                if( is_user_logged_in() ) {
1302
+                if (is_user_logged_in()) {
1303 1303
 
1304 1304
                     $active_html .= '<section class="entry-actions">';
1305 1305
 
1306
-                    $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">';
1306
+                    $active_html .= '<form method="POST" action="'.esc_url(remove_query_arg(array('active_page', 'completed_page'))).'">';
1307 1307
 
1308
-                    $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />';
1308
+                    $active_html .= '<input type="hidden" name="'.esc_attr('woothemes_sensei_complete_course_noonce').'" id="'.esc_attr('woothemes_sensei_complete_course_noonce').'" value="'.esc_attr(wp_create_nonce('woothemes_sensei_complete_course_noonce')).'" />';
1309 1309
 
1310
-                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />';
1310
+                    $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="'.esc_attr(absint($course_item->ID)).'" />';
1311 1311
 
1312
-                    if ( 0 < absint( count( $course_lessons ) )
1313
-                        && Sensei()->settings->settings['course_completion'] == 'complete' ){
1312
+                    if (0 < absint(count($course_lessons))
1313
+                        && Sensei()->settings->settings['course_completion'] == 'complete') {
1314 1314
 
1315 1315
                         $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="'
1316
-                            .  __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>';
1316
+                            .  __('Mark as Complete', 'woothemes-sensei').'"/> </span>';
1317 1317
 
1318 1318
                     } // End If Statement
1319 1319
 
1320 1320
                     $course_purchased = false;
1321
-                    if ( Sensei_WC::is_woocommerce_active() ) {
1321
+                    if (Sensei_WC::is_woocommerce_active()) {
1322 1322
 
1323 1323
                         // Get the product ID
1324
-                        $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true );
1325
-                        if ( 0 < $wc_post_id ) {
1324
+                        $wc_post_id = get_post_meta(absint($course_item->ID), '_course_woocommerce_product', true);
1325
+                        if (0 < $wc_post_id) {
1326 1326
 
1327
-                            $course_purchased = Sensei_WC::has_customer_bought_product(  $user->ID, $wc_post_id );
1327
+                            $course_purchased = Sensei_WC::has_customer_bought_product($user->ID, $wc_post_id);
1328 1328
 
1329 1329
                         } // End If Statement
1330 1330
 
@@ -1333,12 +1333,12 @@  discard block
 block discarded – undo
1333 1333
 	                /**
1334 1334
 	                 * documented in class-sensei-course.php the_course_action_buttons function
1335 1335
 	                 */
1336
-	                $show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
1336
+	                $show_delete_course_button = apply_filters('sensei_show_delete_course_button', false);
1337 1337
 
1338
-                    if ( false == $course_purchased && $show_delete_course_button ) {
1338
+                    if (false == $course_purchased && $show_delete_course_button) {
1339 1339
 
1340 1340
                         $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="'
1341
-                            .  __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>';
1341
+                            .  __('Delete Course', 'woothemes-sensei').'"/></span>';
1342 1342
 
1343 1343
                     } // End If Statement
1344 1344
 
@@ -1351,54 +1351,54 @@  discard block
 block discarded – undo
1351 1351
 			}
1352 1352
 
1353 1353
 			// Active pagination
1354
-			if( $active_count > $per_page ) {
1354
+			if ($active_count > $per_page) {
1355 1355
 
1356 1356
 				$current_page = 1;
1357
-				if( isset( $_GET['active_page'] ) && 0 < intval( $_GET['active_page'] ) ) {
1357
+				if (isset($_GET['active_page']) && 0 < intval($_GET['active_page'])) {
1358 1358
 					$current_page = $_GET['active_page'];
1359 1359
 				}
1360 1360
 
1361 1361
 				$active_html .= '<nav class="pagination woo-pagination">';
1362
-				$total_pages = ceil( $active_count / $per_page );
1362
+				$total_pages = ceil($active_count / $per_page);
1363 1363
 
1364
-				if( $current_page > 1 ) {
1365
-					$prev_link = add_query_arg( 'active_page', $current_page - 1 );
1366
-					$active_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> ';
1364
+				if ($current_page > 1) {
1365
+					$prev_link = add_query_arg('active_page', $current_page - 1);
1366
+					$active_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> ';
1367 1367
 				}
1368 1368
 
1369
-				for ( $i = 1; $i <= $total_pages; $i++ ) {
1370
-					$link = add_query_arg( 'active_page', $i );
1369
+				for ($i = 1; $i <= $total_pages; $i++) {
1370
+					$link = add_query_arg('active_page', $i);
1371 1371
 
1372
-					if( $i == $current_page ) {
1373
-						$active_html .= '<span class="page-numbers current">' . $i . '</span> ';
1372
+					if ($i == $current_page) {
1373
+						$active_html .= '<span class="page-numbers current">'.$i.'</span> ';
1374 1374
 					} else {
1375
-						$active_html .= '<a class="page-numbers" href="' . esc_url( $link ). '">' . $i . '</a> ';
1375
+						$active_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> ';
1376 1376
 					}
1377 1377
 				}
1378 1378
 
1379
-				if( $current_page < $total_pages ) {
1380
-					$next_link = add_query_arg( 'active_page', $current_page + 1 );
1381
-					$active_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> ';
1379
+				if ($current_page < $total_pages) {
1380
+					$next_link = add_query_arg('active_page', $current_page + 1);
1381
+					$active_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> ';
1382 1382
 				}
1383 1383
 
1384 1384
 				$active_html .= '</nav>';
1385 1385
 			}
1386 1386
 
1387
-			foreach ( $completed_courses as $course_item ) {
1387
+			foreach ($completed_courses as $course_item) {
1388 1388
 				$course = $course_item;
1389 1389
 
1390 1390
 			    // Get Course Categories
1391
-			    $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );
1391
+			    $category_output = get_the_term_list($course_item->ID, 'course-category', '', ', ', '');
1392 1392
 
1393
-		    	$complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">';
1393
+		    	$complete_html .= '<article class="'.join(' ', get_post_class(array('course', 'post'), $course_item->ID)).'">';
1394 1394
 
1395 1395
 		    	    // Image
1396
-		    		$complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true );
1396
+		    		$complete_html .= Sensei()->course->course_image(absint($course_item->ID), 100, 100, true);
1397 1397
 
1398 1398
 		    		// Title
1399 1399
 		    		$complete_html .= '<header>';
1400 1400
 
1401
-		    		    $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>';
1401
+		    		    $complete_html .= '<h2><a href="'.esc_url(get_permalink(absint($course_item->ID))).'" title="'.esc_attr($course_item->post_title).'">'.esc_html($course_item->post_title).'</a></h2>';
1402 1402
 
1403 1403
 		    		$complete_html .= '</header>';
1404 1404
 
@@ -1407,49 +1407,49 @@  discard block
 block discarded – undo
1407 1407
 		    			$complete_html .= '<p class="sensei-course-meta">';
1408 1408
 
1409 1409
 		    		    	// Author
1410
-		    		    	$user_info = get_userdata( absint( $course_item->post_author ) );
1411
-		    		    	if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {
1412
-		    		    		$complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
1410
+		    		    	$user_info = get_userdata(absint($course_item->post_author));
1411
+		    		    	if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) {
1412
+		    		    		$complete_html .= '<span class="course-author">'.__('by ', 'woothemes-sensei').'<a href="'.esc_url(get_author_posts_url(absint($course_item->post_author))).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>';
1413 1413
 		    		    	} // End If Statement
1414 1414
 
1415 1415
 		    		    	// Lesson count for this author
1416 1416
 		    		    	$complete_html .= '<span class="course-lesson-count">'
1417
-                                . Sensei()->course->course_lesson_count( absint( $course_item->ID ) )
1418
-                                . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' )
1417
+                                . Sensei()->course->course_lesson_count(absint($course_item->ID))
1418
+                                . '&nbsp;'.__('Lessons', 'woothemes-sensei')
1419 1419
                                 . '</span>';
1420 1420
 
1421 1421
 		    		    	// Course Categories
1422
-		    		    	if ( '' != $category_output ) {
1422
+		    		    	if ('' != $category_output) {
1423 1423
 
1424
-		    		    		$complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>';
1424
+		    		    		$complete_html .= '<span class="course-category">'.sprintf(__('in %s', 'woothemes-sensei'), $category_output).'</span>';
1425 1425
 
1426 1426
 		    		    	} // End If Statement
1427 1427
 
1428 1428
 						$complete_html .= '</p>';
1429 1429
 
1430
-						$complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>';
1430
+						$complete_html .= '<p class="course-excerpt">'.$course_item->post_excerpt.'</p>';
1431 1431
 
1432
-                        $complete_html .= $this->get_progress_meter( 100 );
1432
+                        $complete_html .= $this->get_progress_meter(100);
1433 1433
 
1434
-						if( $manage ) {
1435
-							$has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true );
1434
+						if ($manage) {
1435
+							$has_quizzes = Sensei()->course->course_quizzes($course_item->ID, true);
1436 1436
 							// Output only if there is content to display
1437
-							if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) {
1437
+							if (has_filter('sensei_results_links') || $has_quizzes) {
1438 1438
 
1439 1439
 
1440 1440
 								$complete_html .= '<p class="sensei-results-links">';
1441 1441
 								$results_link = '';
1442
-								if( $has_quizzes ) {
1442
+								if ($has_quizzes) {
1443 1443
 
1444 1444
 									$results_link = '<a class="button view-results" href="'
1445
-                                        . Sensei()->course_results->get_permalink( $course_item->ID )
1446
-                                        . '">' . __( 'View results', 'woothemes-sensei' )
1445
+                                        . Sensei()->course_results->get_permalink($course_item->ID)
1446
+                                        . '">'.__('View results', 'woothemes-sensei')
1447 1447
                                         . '</a>';
1448 1448
 								}
1449 1449
                                 /**
1450 1450
                                  * Filter documented in Sensei_Course::the_course_action_buttons
1451 1451
                                  */
1452
-								$complete_html .= apply_filters( 'sensei_results_links', $results_link, $course_item->ID );
1452
+								$complete_html .= apply_filters('sensei_results_links', $results_link, $course_item->ID);
1453 1453
 								$complete_html .= '</p>';
1454 1454
 
1455 1455
 							}
@@ -1461,35 +1461,35 @@  discard block
 block discarded – undo
1461 1461
 			}
1462 1462
 
1463 1463
 			// Active pagination
1464
-			if( $completed_count > $per_page ) {
1464
+			if ($completed_count > $per_page) {
1465 1465
 
1466 1466
 				$current_page = 1;
1467
-				if( isset( $_GET['completed_page'] ) && 0 < intval( $_GET['completed_page'] ) ) {
1467
+				if (isset($_GET['completed_page']) && 0 < intval($_GET['completed_page'])) {
1468 1468
 					$current_page = $_GET['completed_page'];
1469 1469
 				}
1470 1470
 
1471 1471
 				$complete_html .= '<nav class="pagination woo-pagination">';
1472
-				$total_pages = ceil( $completed_count / $per_page );
1472
+				$total_pages = ceil($completed_count / $per_page);
1473 1473
 
1474 1474
 
1475
-				if( $current_page > 1 ) {
1476
-					$prev_link = add_query_arg( 'completed_page', $current_page - 1 );
1477
-					$complete_html .= '<a class="prev page-numbers" href="' . esc_url( $prev_link ) . '">' . __( 'Previous' , 'woothemes-sensei' ) . '</a> ';
1475
+				if ($current_page > 1) {
1476
+					$prev_link = add_query_arg('completed_page', $current_page - 1);
1477
+					$complete_html .= '<a class="prev page-numbers" href="'.esc_url($prev_link).'">'.__('Previous', 'woothemes-sensei').'</a> ';
1478 1478
 				}
1479 1479
 
1480
-				for ( $i = 1; $i <= $total_pages; $i++ ) {
1481
-					$link = add_query_arg( 'completed_page', $i );
1480
+				for ($i = 1; $i <= $total_pages; $i++) {
1481
+					$link = add_query_arg('completed_page', $i);
1482 1482
 
1483
-					if( $i == $current_page ) {
1484
-						$complete_html .= '<span class="page-numbers current">' . $i . '</span> ';
1483
+					if ($i == $current_page) {
1484
+						$complete_html .= '<span class="page-numbers current">'.$i.'</span> ';
1485 1485
 					} else {
1486
-						$complete_html .= '<a class="page-numbers" href="' . esc_url( $link ) . '">' . $i . '</a> ';
1486
+						$complete_html .= '<a class="page-numbers" href="'.esc_url($link).'">'.$i.'</a> ';
1487 1487
 					}
1488 1488
 				}
1489 1489
 
1490
-				if( $current_page < $total_pages ) {
1491
-					$next_link = add_query_arg( 'completed_page', $current_page + 1 );
1492
-					$complete_html .= '<a class="next page-numbers" href="' . esc_url( $next_link ) . '">' . __( 'Next' , 'woothemes-sensei' ) . '</a> ';
1490
+				if ($current_page < $total_pages) {
1491
+					$next_link = add_query_arg('completed_page', $current_page + 1);
1492
+					$complete_html .= '<a class="next page-numbers" href="'.esc_url($next_link).'">'.__('Next', 'woothemes-sensei').'</a> ';
1493 1493
 				}
1494 1494
 
1495 1495
 				$complete_html .= '</nav>';
@@ -1497,26 +1497,26 @@  discard block
 block discarded – undo
1497 1497
 
1498 1498
 		} // End If Statement
1499 1499
 
1500
-		if( $manage ) {
1501
-			$no_active_message = __( 'You have no active courses.', 'woothemes-sensei' );
1502
-			$no_complete_message = __( 'You have not completed any courses yet.', 'woothemes-sensei' );
1500
+		if ($manage) {
1501
+			$no_active_message = __('You have no active courses.', 'woothemes-sensei');
1502
+			$no_complete_message = __('You have not completed any courses yet.', 'woothemes-sensei');
1503 1503
 		} else {
1504
-			$no_active_message =  __( 'This learner has no active courses.', 'woothemes-sensei' );
1505
-			$no_complete_message =  __( 'This learner has not completed any courses yet.', 'woothemes-sensei' );
1504
+			$no_active_message = __('This learner has no active courses.', 'woothemes-sensei');
1505
+			$no_complete_message = __('This learner has not completed any courses yet.', 'woothemes-sensei');
1506 1506
 		}
1507 1507
 
1508 1508
 		ob_start();
1509 1509
 		?>
1510 1510
 
1511
-		<?php do_action( 'sensei_before_user_courses' ); ?>
1511
+		<?php do_action('sensei_before_user_courses'); ?>
1512 1512
 
1513 1513
 		<?php
1514
-		if( $manage && ( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) ) {
1514
+		if ($manage && ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable'])) {
1515 1515
 			?>
1516 1516
 			<p class="my-messages-link-container">
1517
-                <a class="my-messages-link" href="<?php echo get_post_type_archive_link( 'sensei_message' ); ?>"
1518
-                   title="<?php _e( 'View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei' ); ?>">
1519
-                    <?php _e( 'My Messages', 'woothemes-sensei' ); ?>
1517
+                <a class="my-messages-link" href="<?php echo get_post_type_archive_link('sensei_message'); ?>"
1518
+                   title="<?php _e('View & reply to private messages sent to your course & lesson teachers.', 'woothemes-sensei'); ?>">
1519
+                    <?php _e('My Messages', 'woothemes-sensei'); ?>
1520 1520
                 </a>
1521 1521
             </p>
1522 1522
 			<?php
@@ -1525,11 +1525,11 @@  discard block
 block discarded – undo
1525 1525
 		<div id="my-courses">
1526 1526
 
1527 1527
 		    <ul>
1528
-		    	<li><a href="#active-courses"><?php  _e( 'Active Courses', 'woothemes-sensei' ); ?></a></li>
1529
-		    	<li><a href="#completed-courses"><?php  _e( 'Completed Courses', 'woothemes-sensei' ); ?></a></li>
1528
+		    	<li><a href="#active-courses"><?php  _e('Active Courses', 'woothemes-sensei'); ?></a></li>
1529
+		    	<li><a href="#completed-courses"><?php  _e('Completed Courses', 'woothemes-sensei'); ?></a></li>
1530 1530
 		    </ul>
1531 1531
 
1532
-		    <?php do_action( 'sensei_before_active_user_courses' ); ?>
1532
+		    <?php do_action('sensei_before_active_user_courses'); ?>
1533 1533
 
1534 1534
 		    <?php
1535 1535
             $course_page_url = Sensei_Course::get_courses_page_url();
@@ -1537,7 +1537,7 @@  discard block
 block discarded – undo
1537 1537
 
1538 1538
 		    <div id="active-courses">
1539 1539
 
1540
-		    	<?php if ( '' != $active_html ) {
1540
+		    	<?php if ('' != $active_html) {
1541 1541
 
1542 1542
 		    		echo $active_html;
1543 1543
 
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
 
1550 1550
                         <a href="<?php echo $course_page_url; ?>">
1551 1551
 
1552
-                            <?php  _e( 'Start a Course!', 'woothemes-sensei' ); ?>
1552
+                            <?php  _e('Start a Course!', 'woothemes-sensei'); ?>
1553 1553
 
1554 1554
                         </a>
1555 1555
 
@@ -1559,13 +1559,13 @@  discard block
 block discarded – undo
1559 1559
 
1560 1560
 		    </div>
1561 1561
 
1562
-		    <?php do_action( 'sensei_after_active_user_courses' ); ?>
1562
+		    <?php do_action('sensei_after_active_user_courses'); ?>
1563 1563
 
1564
-		    <?php do_action( 'sensei_before_completed_user_courses' ); ?>
1564
+		    <?php do_action('sensei_before_completed_user_courses'); ?>
1565 1565
 
1566 1566
 		    <div id="completed-courses">
1567 1567
 
1568
-		    	<?php if ( '' != $complete_html ) {
1568
+		    	<?php if ('' != $complete_html) {
1569 1569
 
1570 1570
 		    		echo $complete_html;
1571 1571
 
@@ -1581,16 +1581,16 @@  discard block
 block discarded – undo
1581 1581
 
1582 1582
 		    </div>
1583 1583
 
1584
-		    <?php do_action( 'sensei_after_completed_user_courses' ); ?>
1584
+		    <?php do_action('sensei_after_completed_user_courses'); ?>
1585 1585
 
1586 1586
 		</div>
1587 1587
 
1588
-		<?php do_action( 'sensei_after_user_courses' ); ?>
1588
+		<?php do_action('sensei_after_user_courses'); ?>
1589 1589
 
1590 1590
 		<?php
1591 1591
         echo ob_get_clean();
1592 1592
 
1593
-        do_action( 'sensei_after_learner_course_content', $user );
1593
+        do_action('sensei_after_learner_course_content', $user);
1594 1594
 
1595 1595
 	} // end load_user_courses_content
1596 1596
 
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
      *  @type $course WP_Post
1603 1603
      * }
1604 1604
      */
1605
-    public static function get_all_courses(){
1605
+    public static function get_all_courses() {
1606 1606
 
1607 1607
         $args = array(
1608 1608
                'post_type' => 'course',
@@ -1613,7 +1613,7 @@  discard block
 block discarded – undo
1613 1613
                 'suppress_filters' 	=> 0,
1614 1614
         );
1615 1615
 
1616
-        $wp_query_obj =  new WP_Query( $args );
1616
+        $wp_query_obj = new WP_Query($args);
1617 1617
 
1618 1618
         /**
1619 1619
          * sensei_get_all_courses filter
@@ -1625,7 +1625,7 @@  discard block
 block discarded – undo
1625 1625
          * }
1626 1626
          * @param array $attributes
1627 1627
          */
1628
-        return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts );
1628
+        return apply_filters('sensei_get_all_courses', $wp_query_obj->posts);
1629 1629
 
1630 1630
     }// end get_all_courses
1631 1631
 
@@ -1636,16 +1636,16 @@  discard block
 block discarded – undo
1636 1636
      * @param int $progress_percentage 0 - 100
1637 1637
      * @return string $progress_bar_html
1638 1638
      */
1639
-    public function get_progress_meter( $progress_percentage ){
1639
+    public function get_progress_meter($progress_percentage) {
1640 1640
 
1641
-        if ( 50 < $progress_percentage ) {
1641
+        if (50 < $progress_percentage) {
1642 1642
             $class = ' green completed';
1643
-        } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) {
1643
+        } elseif (25 <= $progress_percentage && 50 >= $progress_percentage) {
1644 1644
             $class = ' orange progressing';
1645 1645
         } else {
1646 1646
             $class = ' red starting';
1647 1647
         }
1648
-        $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>';
1648
+        $progress_bar_html = '<div class="meter'.esc_attr($class).'"><span style="width: '.$progress_percentage.'%">'.round($progress_percentage).'%</span></div>';
1649 1649
 
1650 1650
         return $progress_bar_html;
1651 1651
 
@@ -1660,17 +1660,17 @@  discard block
 block discarded – undo
1660 1660
      *
1661 1661
      * @return string $statement_html
1662 1662
      */
1663
-    public function get_progress_statement( $course_id, $user_id ){
1663
+    public function get_progress_statement($course_id, $user_id) {
1664 1664
 
1665
-        if( empty( $course_id ) || empty( $user_id )
1666
-        || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1665
+        if (empty($course_id) || empty($user_id)
1666
+        || ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1667 1667
             return '';
1668 1668
         }
1669 1669
 
1670
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1671
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1670
+        $completed = count($this->get_completed_lesson_ids($course_id, $user_id));
1671
+        $total_lessons = count($this->course_lessons($course_id));
1672 1672
 
1673
-        $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons );
1673
+        $statement = sprintf(_n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons);
1674 1674
 
1675 1675
         /**
1676 1676
          * Filter the course completion statement.
@@ -1678,7 +1678,7 @@  discard block
 block discarded – undo
1678 1678
          *
1679 1679
          * @param string $statement
1680 1680
          */
1681
-        return apply_filters( 'sensei_course_completion_statement', $statement );
1681
+        return apply_filters('sensei_course_completion_statement', $statement);
1682 1682
 
1683 1683
     }// end generate_progress_statement
1684 1684
 
@@ -1688,17 +1688,17 @@  discard block
 block discarded – undo
1688 1688
      * @param $course_id
1689 1689
      * @return void
1690 1690
      */
1691
-    public function the_progress_statement( $course_id = 0, $user_id = 0 ){
1692
-        if( empty( $course_id ) ){
1691
+    public function the_progress_statement($course_id = 0, $user_id = 0) {
1692
+        if (empty($course_id)) {
1693 1693
             global $post;
1694 1694
             $course_id = $post->ID;
1695 1695
         }
1696 1696
 
1697
-        if( empty( $user_id ) ){
1697
+        if (empty($user_id)) {
1698 1698
             $user_id = get_current_user_id();
1699 1699
         }
1700 1700
 
1701
-        echo '<span class="progress statement  course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id  ) . '</span>';
1701
+        echo '<span class="progress statement  course-completion-rate">'.$this->get_progress_statement($course_id, $user_id).'</span>';
1702 1702
     }
1703 1703
 
1704 1704
     /**
@@ -1707,24 +1707,24 @@  discard block
 block discarded – undo
1707 1707
      * @param $course_id
1708 1708
      * @return void
1709 1709
      */
1710
-    public function the_progress_meter( $course_id = 0, $user_id = 0 ){
1710
+    public function the_progress_meter($course_id = 0, $user_id = 0) {
1711 1711
 
1712
-        if( empty( $course_id ) ){
1712
+        if (empty($course_id)) {
1713 1713
             global $post;
1714 1714
             $course_id = $post->ID;
1715 1715
         }
1716 1716
 
1717
-        if( empty( $user_id ) ){
1717
+        if (empty($user_id)) {
1718 1718
             $user_id = get_current_user_id();
1719 1719
         }
1720 1720
 
1721
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id )
1722
-            || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){
1721
+        if ('course' != get_post_type($course_id) || ! get_userdata($user_id)
1722
+            || ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1723 1723
             return;
1724 1724
         }
1725
-        $percentage_completed = $this->get_completion_percentage( $course_id, $user_id );
1725
+        $percentage_completed = $this->get_completion_percentage($course_id, $user_id);
1726 1726
 
1727
-        echo $this->get_progress_meter( $percentage_completed );
1727
+        echo $this->get_progress_meter($percentage_completed);
1728 1728
 
1729 1729
     }// end the_progress_meter
1730 1730
 
@@ -1737,20 +1737,20 @@  discard block
 block discarded – undo
1737 1737
      * @param int $user_id
1738 1738
      * @return array $completed_lesson_ids
1739 1739
      */
1740
-    public function get_completed_lesson_ids( $course_id, $user_id = 0 ){
1740
+    public function get_completed_lesson_ids($course_id, $user_id = 0) {
1741 1741
 
1742
-        if( !( intval( $user_id ) ) > 0 ){
1742
+        if ( ! (intval($user_id)) > 0) {
1743 1743
             $user_id = get_current_user_id();
1744 1744
         }
1745 1745
 
1746 1746
         $completed_lesson_ids = array();
1747 1747
 
1748
-        $course_lessons = $this->course_lessons( $course_id );
1748
+        $course_lessons = $this->course_lessons($course_id);
1749 1749
 
1750
-        foreach( $course_lessons as $lesson ){
1750
+        foreach ($course_lessons as $lesson) {
1751 1751
 
1752
-            $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id );
1753
-            if( $is_lesson_completed ){
1752
+            $is_lesson_completed = Sensei_Utils::user_completed_lesson($lesson->ID, $user_id);
1753
+            if ($is_lesson_completed) {
1754 1754
                 $completed_lesson_ids[] = $lesson->ID;
1755 1755
             }
1756 1756
 
@@ -1769,19 +1769,19 @@  discard block
 block discarded – undo
1769 1769
      * @param int $user_id
1770 1770
      * @return int $percentage
1771 1771
      */
1772
-    public function get_completion_percentage( $course_id, $user_id = 0 ){
1772
+    public function get_completion_percentage($course_id, $user_id = 0) {
1773 1773
 
1774
-        if( !( intval( $user_id ) ) > 0 ){
1774
+        if ( ! (intval($user_id)) > 0) {
1775 1775
             $user_id = get_current_user_id();
1776 1776
         }
1777 1777
 
1778
-        $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) );
1778
+        $completed = count($this->get_completed_lesson_ids($course_id, $user_id));
1779 1779
 
1780
-        if( ! (  $completed  > 0 ) ){
1780
+        if ( ! ($completed > 0)) {
1781 1781
             return 0;
1782 1782
         }
1783 1783
 
1784
-        $total_lessons = count( $this->course_lessons( $course_id ) );
1784
+        $total_lessons = count($this->course_lessons($course_id));
1785 1785
         $percentage = $completed / $total_lessons * 100;
1786 1786
 
1787 1787
         /**
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
          * @param $user_id
1794 1794
          * @since 1.8.0
1795 1795
          */
1796
-        return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id );
1796
+        return apply_filters('sensei_course_completion_percentage', $percentage, $course_id, $user_id);
1797 1797
 
1798 1798
     }// end get_completed_lesson_ids
1799 1799
 
@@ -1805,28 +1805,28 @@  discard block
 block discarded – undo
1805 1805
      * @param $should_send
1806 1806
      * @return bool
1807 1807
      */
1808
-    public function block_notification_emails( $should_send ){
1808
+    public function block_notification_emails($should_send) {
1809 1809
         global $sensei_email_data;
1810 1810
         $email = $sensei_email_data;
1811 1811
 
1812 1812
         $course_id = '';
1813 1813
 
1814
-        if( isset( $email['course_id'] ) ){
1814
+        if (isset($email['course_id'])) {
1815 1815
 
1816 1816
             $course_id = $email['course_id'];
1817 1817
 
1818
-        }elseif( isset( $email['lesson_id'] ) ){
1818
+        }elseif (isset($email['lesson_id'])) {
1819 1819
 
1820
-            $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] );
1820
+            $course_id = Sensei()->lesson->get_course_id($email['lesson_id']);
1821 1821
 
1822
-        }elseif( isset( $email['quiz_id'] ) ){
1822
+        }elseif (isset($email['quiz_id'])) {
1823 1823
 
1824
-            $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] );
1825
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1824
+            $lesson_id = Sensei()->quiz->get_lesson_id($email['quiz_id']);
1825
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1826 1826
 
1827 1827
         }
1828 1828
 
1829
-        if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) {
1829
+        if ( ! empty($course_id) && 'course' == get_post_type($course_id)) {
1830 1830
 
1831 1831
             $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true);
1832 1832
 
@@ -1847,19 +1847,19 @@  discard block
 block discarded – undo
1847 1847
      * @since 1.8.0
1848 1848
      * @param $course
1849 1849
      */
1850
-    public function course_notification_meta_box_content( $course ){
1850
+    public function course_notification_meta_box_content($course) {
1851 1851
 
1852
-        $checked = get_post_meta( $course->ID , 'disable_notification', true );
1852
+        $checked = get_post_meta($course->ID, 'disable_notification', true);
1853 1853
 
1854 1854
         // generate checked html
1855 1855
         $checked_html = '';
1856
-        if( $checked ){
1856
+        if ($checked) {
1857 1857
             $checked_html = 'checked="checked"';
1858 1858
         }
1859
-        wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' );
1859
+        wp_nonce_field('update-course-notification-setting', '_sensei_course_notification');
1860 1860
 
1861
-        echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >';
1862
-        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>';
1861
+        echo '<input id="disable_sensei_course_notification" '.$checked_html.' type="checkbox" name="disable_sensei_course_notification" >';
1862
+        echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei').'</label>';
1863 1863
 
1864 1864
     }// end course_notification_meta_box_content
1865 1865
 
@@ -1871,20 +1871,20 @@  discard block
 block discarded – undo
1871 1871
      *
1872 1872
      * @param $course_id
1873 1873
      */
1874
-    public function save_course_notification_meta_box( $course_id ){
1874
+    public function save_course_notification_meta_box($course_id) {
1875 1875
 
1876
-        if( !isset( $_POST['_sensei_course_notification']  )
1877
-            || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){
1876
+        if ( ! isset($_POST['_sensei_course_notification'])
1877
+            || ! wp_verify_nonce($_POST['_sensei_course_notification'], 'update-course-notification-setting')) {
1878 1878
             return;
1879 1879
         }
1880 1880
 
1881
-        if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification']  ) {
1881
+        if (isset($_POST['disable_sensei_course_notification']) && 'on' == $_POST['disable_sensei_course_notification']) {
1882 1882
             $new_val = true;
1883
-        }else{
1883
+        } else {
1884 1884
             $new_val = false;
1885 1885
         }
1886 1886
 
1887
-       update_post_meta( $course_id , 'disable_notification', $new_val );
1887
+       update_post_meta($course_id, 'disable_notification', $new_val);
1888 1888
 
1889 1889
     }// end save notification meta box
1890 1890
 
@@ -1898,10 +1898,10 @@  discard block
 block discarded – undo
1898 1898
      *
1899 1899
      * @param WP_Post $post
1900 1900
      */
1901
-    public function content_before_backwards_compatibility_hooks( $post_id ){
1901
+    public function content_before_backwards_compatibility_hooks($post_id) {
1902 1902
 
1903
-        sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' );
1904
-        sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' );
1903
+        sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_course_content_inside_before');
1904
+        sensei_do_deprecated_action('sensei_course_archive_course_title', '1.9.0', 'sensei_course_content_inside_before');
1905 1905
 
1906 1906
     }
1907 1907
 
@@ -1914,10 +1914,10 @@  discard block
 block discarded – undo
1914 1914
      *
1915 1915
      * @global WP_Post $post
1916 1916
      */
1917
-    public  function loop_before_backwards_compatibility_hooks( ){
1917
+    public  function loop_before_backwards_compatibility_hooks( ) {
1918 1918
 
1919 1919
         global $post;
1920
-        sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type  );
1920
+        sensei_do_deprecated_action('sensei_course_archive_header', '1.9.0', 'sensei_course_content_inside_before', $post->post_type);
1921 1921
 
1922 1922
     }
1923 1923
 
@@ -1930,19 +1930,19 @@  discard block
 block discarded – undo
1930 1930
      *
1931 1931
      * @param integer $course_id
1932 1932
      */
1933
-    public function the_course_free_lesson_preview( $course_id ){
1933
+    public function the_course_free_lesson_preview($course_id) {
1934 1934
         // Meta data
1935
-        $course = get_post( $course_id );
1936
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) );
1937
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() );
1935
+        $course = get_post($course_id);
1936
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course->ID));
1937
+        $is_user_taking_course = Sensei_Utils::user_started_course($course->ID, get_current_user_id());
1938 1938
 
1939
-        if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
1939
+        if (0 < $preview_lesson_count && ! $is_user_taking_course) {
1940 1940
             ?>
1941 1941
             <p class="sensei-free-lessons">
1942 1942
                 <a href="<?php echo get_permalink(); ?>">
1943
-                    <?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
1943
+                    <?php _e('Preview this course', 'woothemes-sensei') ?>
1944 1944
                 </a>
1945
-                - <?php echo sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ) ; ?>
1945
+                - <?php echo sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
1946 1946
             </p>
1947 1947
 
1948 1948
         <?php
@@ -1955,42 +1955,42 @@  discard block
 block discarded – undo
1955 1955
      * @since 1.9.0
1956 1956
      * @param integer $course_id
1957 1957
      */
1958
-    public function the_course_meta( $course_id ){
1958
+    public function the_course_meta($course_id) {
1959 1959
         echo '<p class="sensei-course-meta">';
1960 1960
 
1961
-        $course = get_post( $course_id );
1962
-        $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' );
1963
-        $author_display_name = get_the_author_meta( 'display_name', $course->post_author  );
1961
+        $course = get_post($course_id);
1962
+        $category_output = get_the_term_list($course->ID, 'course-category', '', ', ', '');
1963
+        $author_display_name = get_the_author_meta('display_name', $course->post_author);
1964 1964
 
1965
-        if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?>
1965
+        if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) {?>
1966 1966
 
1967
-            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?>
1967
+            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?>
1968 1968
 
1969
-                <a href="<?php esc_attr_e( get_author_posts_url( $course->post_author ) ); ?>" title="<?php esc_attr_e( $author_display_name ); ?>"><?php esc_attr_e( $author_display_name   ); ?></a>
1969
+                <a href="<?php esc_attr_e(get_author_posts_url($course->post_author)); ?>" title="<?php esc_attr_e($author_display_name); ?>"><?php esc_attr_e($author_display_name); ?></a>
1970 1970
 
1971 1971
             </span>
1972 1972
 
1973 1973
         <?php } // End If Statement ?>
1974 1974
 
1975
-        <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $course->ID ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?></span>
1975
+        <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($course->ID).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?></span>
1976 1976
 
1977
-       <?php if ( '' != $category_output ) { ?>
1977
+       <?php if ('' != $category_output) { ?>
1978 1978
 
1979
-            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
1979
+            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
1980 1980
 
1981 1981
         <?php } // End If Statement
1982 1982
 
1983 1983
         // number of completed lessons
1984
-        if( Sensei_Utils::user_started_course( $course->ID,  get_current_user_id() )
1985
-            || Sensei_Utils::user_completed_course( $course->ID,  get_current_user_id() )  ){
1984
+        if (Sensei_Utils::user_started_course($course->ID, get_current_user_id())
1985
+            || Sensei_Utils::user_completed_course($course->ID, get_current_user_id())) {
1986 1986
 
1987
-            $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) );
1988
-            $lesson_count = count( $this->course_lessons( $course->ID ) );
1989
-            echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count  ) . '</span>';
1987
+            $completed = count($this->get_completed_lesson_ids($course->ID, get_current_user_id()));
1988
+            $lesson_count = count($this->course_lessons($course->ID));
1989
+            echo '<span class="course-lesson-progress">'.sprintf(__('%1$d of %2$d lessons completed', 'woothemes-sensei'), $completed, $lesson_count).'</span>';
1990 1990
 
1991 1991
         }
1992 1992
 
1993
-        sensei_simple_course_price( $course->ID );
1993
+        sensei_simple_course_price($course->ID);
1994 1994
 
1995 1995
         echo '</p>';
1996 1996
     } // end the course meta
@@ -2005,15 +2005,15 @@  discard block
 block discarded – undo
2005 2005
      *
2006 2006
      * @return array $classes
2007 2007
      */
2008
-    public static function add_course_user_status_class( $classes, $class, $course_id ){
2008
+    public static function add_course_user_status_class($classes, $class, $course_id) {
2009 2009
 
2010
-        if( 'course' == get_post_type( $course_id )  &&  is_user_logged_in() ){
2010
+        if ('course' == get_post_type($course_id) && is_user_logged_in()) {
2011 2011
 
2012
-            if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){
2012
+            if (Sensei_Utils::user_completed_course($course_id, get_current_user_id())) {
2013 2013
 
2014 2014
                 $classes[] = 'user-status-completed';
2015 2015
 
2016
-            }else{
2016
+            } else {
2017 2017
 
2018 2018
                 $classes[] = 'user-status-active';
2019 2019
 
@@ -2033,37 +2033,37 @@  discard block
 block discarded – undo
2033 2033
      *
2034 2034
      * @param WP_Post $course
2035 2035
      */
2036
-    public static function the_course_action_buttons( $course ){
2036
+    public static function the_course_action_buttons($course) {
2037 2037
 
2038
-        if( is_user_logged_in() ) { ?>
2038
+        if (is_user_logged_in()) { ?>
2039 2039
 
2040 2040
             <section class="entry-actions">
2041
-                <form method="POST" action="<?php  echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>">
2041
+                <form method="POST" action="<?php  echo esc_url(remove_query_arg(array('active_page', 'completed_page'))); ?>">
2042 2042
 
2043 2043
                     <input type="hidden"
2044
-                           name="<?php esc_attr_e( 'woothemes_sensei_complete_course_noonce' ) ?>"
2045
-                           id="<?php  esc_attr_e( 'woothemes_sensei_complete_course_noonce' ); ?>"
2046
-                           value="<?php esc_attr_e( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ); ?>"
2044
+                           name="<?php esc_attr_e('woothemes_sensei_complete_course_noonce') ?>"
2045
+                           id="<?php  esc_attr_e('woothemes_sensei_complete_course_noonce'); ?>"
2046
+                           value="<?php esc_attr_e(wp_create_nonce('woothemes_sensei_complete_course_noonce')); ?>"
2047 2047
                         />
2048 2048
 
2049
-                    <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e( intval( $course->ID ) ); ?>" />
2049
+                    <input type="hidden" name="course_complete_id" id="course-complete-id" value="<?php esc_attr_e(intval($course->ID)); ?>" />
2050 2050
 
2051
-                    <?php if ( 0 < absint( count( Sensei()->course->course_lessons( $course->ID ) ) )
2051
+                    <?php if (0 < absint(count(Sensei()->course->course_lessons($course->ID)))
2052 2052
                         && Sensei()->settings->settings['course_completion'] == 'complete'
2053
-                        && ! Sensei_Utils::user_completed_course( $course, get_current_user_id() )) { ?>
2053
+                        && ! Sensei_Utils::user_completed_course($course, get_current_user_id())) { ?>
2054 2054
 
2055
-                        <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e( 'Mark as Complete', 'woothemes-sensei' ); ?>" /></span>
2055
+                        <span><input name="course_complete" type="submit" class="course-complete" value="<?php  _e('Mark as Complete', 'woothemes-sensei'); ?>" /></span>
2056 2056
 
2057 2057
                    <?php  } // End If Statement
2058 2058
 
2059 2059
                     $course_purchased = false;
2060
-                    if ( Sensei_WC::is_woocommerce_active() ) {
2060
+                    if (Sensei_WC::is_woocommerce_active()) {
2061 2061
                         // Get the product ID
2062
-                        $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true );
2063
-                        if ( 0 < $wc_post_id ) {
2062
+                        $wc_post_id = get_post_meta(intval($course->ID), '_course_woocommerce_product', true);
2063
+                        if (0 < $wc_post_id) {
2064 2064
 
2065 2065
                             $user = wp_get_current_user();
2066
-                            $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id );
2066
+                            $course_purchased = Sensei_Utils::sensei_customer_bought_product($user->user_email, $user->ID, $wc_post_id);
2067 2067
 
2068 2068
                         } // End If Statement
2069 2069
                     } // End If Statement
@@ -2077,24 +2077,24 @@  discard block
 block discarded – undo
2077 2077
                      * @since 1.9.0
2078 2078
                      * @param bool $show_delete_course_button defaults to false
2079 2079
                      */
2080
-                    $show_delete_course_button = apply_filters( 'sensei_show_delete_course_button', false );
2080
+                    $show_delete_course_button = apply_filters('sensei_show_delete_course_button', false);
2081 2081
 
2082 2082
                     if ( ! $course_purchased
2083
-                         && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() )
2084
-                         && $show_delete_course_button ) { ?>
2083
+                         && ! Sensei_Utils::user_completed_course($course->ID, get_current_user_id())
2084
+                         && $show_delete_course_button) { ?>
2085 2085
 
2086
-                        <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span>
2086
+                        <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __('Delete Course', 'woothemes-sensei'); ?>"/></span>
2087 2087
 
2088 2088
                     <?php } // End If Statement
2089 2089
 
2090
-                    $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true );
2090
+                    $has_quizzes = Sensei()->course->course_quizzes($course->ID, true);
2091 2091
                     $results_link = '';
2092
-                    if( $has_quizzes ){
2093
-                        $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>';
2092
+                    if ($has_quizzes) {
2093
+                        $results_link = '<a class="button view-results" href="'.Sensei()->course_results->get_permalink($course->ID).'">'.__('View results', 'woothemes-sensei').'</a>';
2094 2094
                     }
2095 2095
 
2096 2096
                     // Output only if there is content to display
2097
-                    if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2097
+                    if (has_filter('sensei_results_links') || $has_quizzes) { ?>
2098 2098
 
2099 2099
                         <p class="sensei-results-links">
2100 2100
                             <?php
@@ -2104,7 +2104,7 @@  discard block
 block discarded – undo
2104 2104
                              * @param string $results_links_html
2105 2105
                              * @param integer $course_id
2106 2106
                              */
2107
-                            echo apply_filters( 'sensei_results_links', $results_link, $course->ID );
2107
+                            echo apply_filters('sensei_results_links', $results_link, $course->ID);
2108 2108
                             ?>
2109 2109
                         </p>
2110 2110
 
@@ -2130,17 +2130,17 @@  discard block
 block discarded – undo
2130 2130
      * @param WP_Query $query
2131 2131
      * @return WP_Query $query
2132 2132
      */
2133
-    public static function course_query_filter( $query ){
2133
+    public static function course_query_filter($query) {
2134 2134
 
2135 2135
         // exit early for no course queries and admin queries
2136
-        if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){
2136
+        if (is_admin( ) || 'course' != $query->get('post_type')) {
2137 2137
             return $query;
2138 2138
         }
2139 2139
 
2140 2140
         global $post; // used to get the current page id for my courses
2141 2141
 
2142 2142
         // for the course archive page
2143
-        if( $query->is_main_query() && is_post_type_archive('course') )
2143
+        if ($query->is_main_query() && is_post_type_archive('course'))
2144 2144
         {
2145 2145
             /**
2146 2146
              * sensei_archive_courses_per_page
@@ -2151,11 +2151,11 @@  discard block
 block discarded – undo
2151 2151
              * @since 1.9.0
2152 2152
              * @param integer $posts_per_page default 10
2153 2153
              */
2154
-            $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) );
2154
+            $query->set('posts_per_page', apply_filters('sensei_archive_courses_per_page', 10));
2155 2155
 
2156 2156
         }
2157 2157
         // for the my courses page
2158
-        elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID  )
2158
+        elseif (is_page() && Sensei()->settings->get('my_course_page') == $post->ID)
2159 2159
         {
2160 2160
             /**
2161 2161
              * sensei_my_courses_per_page
@@ -2166,7 +2166,7 @@  discard block
 block discarded – undo
2166 2166
              * @since 1.9.0
2167 2167
              * @param integer $posts_per_page default 10
2168 2168
              */
2169
-            $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) );
2169
+            $query->set('posts_per_page', apply_filters('sensei_my_courses_per_page', 10));
2170 2170
 
2171 2171
         }
2172 2172
 
@@ -2182,21 +2182,21 @@  discard block
 block discarded – undo
2182 2182
      * @return array $extra_classes
2183 2183
      * @since 1.9.0
2184 2184
      */
2185
-    public static function get_course_loop_content_class ()
2185
+    public static function get_course_loop_content_class()
2186 2186
     {
2187 2187
 
2188 2188
         global $sensei_course_loop;
2189 2189
 
2190 2190
 
2191
-        if( !isset( $sensei_course_loop ) ){
2191
+        if ( ! isset($sensei_course_loop)) {
2192 2192
             $sensei_course_loop = array();
2193 2193
         }
2194 2194
 
2195
-        if (!isset($sensei_course_loop['counter'])) {
2195
+        if ( ! isset($sensei_course_loop['counter'])) {
2196 2196
             $sensei_course_loop['counter'] = 0;
2197 2197
         }
2198 2198
 
2199
-        if (!isset($sensei_course_loop['columns'])) {
2199
+        if ( ! isset($sensei_course_loop['columns'])) {
2200 2200
             $sensei_course_loop['columns'] = self::get_loop_number_of_columns();
2201 2201
         }
2202 2202
 
@@ -2204,16 +2204,16 @@  discard block
 block discarded – undo
2204 2204
         $sensei_course_loop['counter']++;
2205 2205
 
2206 2206
         $extra_classes = array();
2207
-        if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']  ){
2207
+        if (0 == ($sensei_course_loop['counter'] - 1) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns']) {
2208 2208
             $extra_classes[] = 'first';
2209 2209
         }
2210 2210
 
2211
-        if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']  ){
2211
+        if (0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns']) {
2212 2212
             $extra_classes[] = 'last';
2213 2213
         }
2214 2214
 
2215 2215
         // add the item number to the classes as well.
2216
-        $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter'];
2216
+        $extra_classes[] = 'loop-item-number-'.$sensei_course_loop['counter'];
2217 2217
 
2218 2218
         /**
2219 2219
          * Filter the course loop class the fires in the  in get_course_loop_content_class function
@@ -2224,7 +2224,7 @@  discard block
 block discarded – undo
2224 2224
          * @param array $extra_classes
2225 2225
          * @param WP_Post $loop_current_course
2226 2226
          */
2227
-        return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() );
2227
+        return apply_filters('sensei_course_loop_content_class', $extra_classes, get_post());
2228 2228
 
2229 2229
     }// end get_course_loop_class
2230 2230
 
@@ -2234,7 +2234,7 @@  discard block
 block discarded – undo
2234 2234
      * @since 1.9.0
2235 2235
      * @return mixed|void
2236 2236
      */
2237
-    public static function get_loop_number_of_columns(){
2237
+    public static function get_loop_number_of_columns() {
2238 2238
 
2239 2239
         /**
2240 2240
          * Filter the number of columns on the course archive page.
@@ -2254,10 +2254,10 @@  discard block
 block discarded – undo
2254 2254
      * @since 1.9.0
2255 2255
      * @param
2256 2256
      */
2257
-    public static function course_archive_sorting( $query ){
2257
+    public static function course_archive_sorting($query) {
2258 2258
 
2259 2259
         // don't show on category pages and other pages
2260
-        if( ! is_archive(  'course ') || is_tax('course-category') ){
2260
+        if ( ! is_archive('course ') || is_tax('course-category')) {
2261 2261
             return;
2262 2262
         }
2263 2263
 
@@ -2270,27 +2270,27 @@  discard block
 block discarded – undo
2270 2270
          *  @type string $option_string
2271 2271
          * }
2272 2272
          */
2273
-        $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array(
2274
-            "newness"     => __( "Sort by newest first", "woothemes-sensei"),
2275
-            "title"       => __( "Sort by title A-Z", "woothemes-sensei" ),
2273
+        $course_order_by_options = apply_filters('sensei_archive_course_order_by_options', array(
2274
+            "newness"     => __("Sort by newest first", "woothemes-sensei"),
2275
+            "title"       => __("Sort by title A-Z", "woothemes-sensei"),
2276 2276
         ));
2277 2277
 
2278 2278
         // setup the currently selected item
2279 2279
         $selected = 'newness';
2280
-        if( isset( $_GET['orderby'] ) ){
2280
+        if (isset($_GET['orderby'])) {
2281 2281
 
2282
-            $selected =  $_GET[ 'orderby' ];
2282
+            $selected = $_GET['orderby'];
2283 2283
 
2284 2284
         }
2285 2285
 
2286 2286
         ?>
2287 2287
 
2288
-        <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST">
2288
+        <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr(Sensei_Utils::get_current_url()); ?>" method="POST">
2289 2289
             <select name="course-orderby" class="orderby">
2290 2290
                 <?php
2291
-                foreach( $course_order_by_options as $value => $text ){
2291
+                foreach ($course_order_by_options as $value => $text) {
2292 2292
 
2293
-                    echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>';
2293
+                    echo '<option value="'.$value.' "'.selected($selected, $value, false).'>'.$text.'</option>';
2294 2294
 
2295 2295
                 }
2296 2296
                 ?>
@@ -2308,10 +2308,10 @@  discard block
 block discarded – undo
2308 2308
      * @since 1.9.0
2309 2309
      * @param
2310 2310
      */
2311
-    public static function course_archive_filters( $query ){
2311
+    public static function course_archive_filters($query) {
2312 2312
 
2313 2313
         // don't show on category pages
2314
-        if( is_tax('course-category') ){
2314
+        if (is_tax('course-category')) {
2315 2315
             return;
2316 2316
         }
2317 2317
 
@@ -2324,9 +2324,9 @@  discard block
 block discarded – undo
2324 2324
          * }
2325 2325
          *
2326 2326
          */
2327
-        $filters = apply_filters( 'sensei_archive_course_filter_by_options', array(
2328
-            array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ),
2329
-            array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url()  ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ),
2327
+        $filters = apply_filters('sensei_archive_course_filter_by_options', array(
2328
+            array('id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __('All', 'woothemes-sensei')),
2329
+            array('id' => 'featured', 'url' => add_query_arg(array('course_filter'=>'featured'), self::get_courses_page_url()), 'title'=> __('Featured', 'woothemes-sensei')),
2330 2330
         ));
2331 2331
 
2332 2332
 
@@ -2337,11 +2337,11 @@  discard block
 block discarded – undo
2337 2337
             //determine the current active url
2338 2338
             $current_url = Sensei_Utils::get_current_url();
2339 2339
 
2340
-            foreach( $filters as $filter ) {
2340
+            foreach ($filters as $filter) {
2341 2341
 
2342
-                $active_class =  $current_url == $filter['url'] ? ' class="active" ' : '';
2342
+                $active_class = $current_url == $filter['url'] ? ' class="active" ' : '';
2343 2343
 
2344
-                echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title']  .'</a></li>';
2344
+                echo '<li><a '.$active_class.' id="'.$filter['id'].'" href="'.esc_url($filter['url']).'" >'.$filter['title'].'</a></li>';
2345 2345
 
2346 2346
             }
2347 2347
             ?>
@@ -2362,13 +2362,13 @@  discard block
 block discarded – undo
2362 2362
      * @param WP_Query $query
2363 2363
      * @return WP_Query $query
2364 2364
      */
2365
-    public static function course_archive_featured_filter( $query ){
2365
+    public static function course_archive_featured_filter($query) {
2366 2366
 
2367
-        if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query()  ){
2367
+        if (isset ($_GET['course_filter']) && 'featured' == $_GET['course_filter'] && $query->is_main_query()) {
2368 2368
             //setup meta query for featured courses
2369
-            $query->set( 'meta_value', 'featured'  );
2370
-            $query->set( 'meta_key', '_course_featured'  );
2371
-            $query->set( 'meta_compare', '='  );
2369
+            $query->set('meta_value', 'featured');
2370
+            $query->set('meta_key', '_course_featured');
2371
+            $query->set('meta_compare', '=');
2372 2372
         }
2373 2373
 
2374 2374
         return $query;
@@ -2383,13 +2383,13 @@  discard block
 block discarded – undo
2383 2383
      * @param WP_Query $query
2384 2384
      * @return WP_Query $query
2385 2385
      */
2386
-    public static function course_archive_order_by_title( $query ){
2386
+    public static function course_archive_order_by_title($query) {
2387 2387
 
2388
-        if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby']
2389
-            && 'course'== $query->get('post_type') && $query->is_main_query()  ){
2388
+        if (isset ($_POST['course-orderby']) && 'title ' == $_POST['course-orderby']
2389
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
2390 2390
             // setup the order by title for this query
2391
-            $query->set( 'orderby', 'title'  );
2392
-            $query->set( 'order', 'ASC'  );
2391
+            $query->set('orderby', 'title');
2392
+            $query->set('order', 'ASC');
2393 2393
         }
2394 2394
 
2395 2395
         return $query;
@@ -2403,10 +2403,10 @@  discard block
 block discarded – undo
2403 2403
      * @since 1.9.0
2404 2404
      * @return string $course_page_url
2405 2405
      */
2406
-    public static function get_courses_page_url(){
2406
+    public static function get_courses_page_url() {
2407 2407
 
2408
-        $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
2409
-        $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id );
2408
+        $course_page_id = intval(Sensei()->settings->settings['course_page']);
2409
+        $course_page_url = empty($course_page_id) ? get_post_type_archive_link('course') : get_permalink($course_page_id);
2410 2410
 
2411 2411
         return $course_page_url;
2412 2412
 
@@ -2423,61 +2423,61 @@  discard block
 block discarded – undo
2423 2423
      * @param string $after_html
2424 2424
      * @return void
2425 2425
      */
2426
-    public static function archive_header( $query_type ='' , $before_html='', $after_html =''  ){
2426
+    public static function archive_header($query_type = '', $before_html = '', $after_html = '') {
2427 2427
 
2428
-        if( ! is_post_type_archive('course') ){
2428
+        if ( ! is_post_type_archive('course')) {
2429 2429
             return;
2430 2430
         }
2431 2431
 
2432 2432
         // deprecated since 1.9.0
2433
-        sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop');
2433
+        sensei_do_deprecated_action('sensei_archive_title', '1.9.0', 'sensei_archive_before_course_loop');
2434 2434
 
2435 2435
         $html = '';
2436 2436
 
2437
-        if( empty( $before_html ) ){
2437
+        if (empty($before_html)) {
2438 2438
 
2439 2439
             $before_html = '<header class="archive-header"><h1>';
2440 2440
 
2441 2441
         }
2442 2442
 
2443
-        if( empty( $after_html ) ){
2443
+        if (empty($after_html)) {
2444 2444
 
2445 2445
             $after_html = '</h1></header>';
2446 2446
 
2447 2447
         }
2448 2448
 
2449
-        if ( is_tax( 'course-category' ) ) {
2449
+        if (is_tax('course-category')) {
2450 2450
 
2451 2451
             global $wp_query;
2452 2452
 
2453 2453
             $taxonomy_obj = $wp_query->get_queried_object();
2454 2454
             $taxonomy_short_name = $taxonomy_obj->taxonomy;
2455
-            $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name );
2456
-            $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name );
2457
-            echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html );
2455
+            $taxonomy_raw_obj = get_taxonomy($taxonomy_short_name);
2456
+            $title = sprintf(__('%1$s Archives: %2$s', 'woothemes-sensei'), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name);
2457
+            echo apply_filters('course_category_archive_title', $before_html.$title.$after_html);
2458 2458
             return;
2459 2459
 
2460 2460
         } // End If Statement
2461 2461
 
2462
-        switch ( $query_type ) {
2462
+        switch ($query_type) {
2463 2463
             case 'newcourses':
2464
-                $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html;
2464
+                $html .= $before_html.__('New Courses', 'woothemes-sensei').$after_html;
2465 2465
                 break;
2466 2466
             case 'featuredcourses':
2467
-                $html .= $before_html .  __( 'Featured Courses', 'woothemes-sensei' ) . $after_html;
2467
+                $html .= $before_html.__('Featured Courses', 'woothemes-sensei').$after_html;
2468 2468
                 break;
2469 2469
             case 'freecourses':
2470
-                $html .= $before_html .  __( 'Free Courses', 'woothemes-sensei' ) . $after_html;
2470
+                $html .= $before_html.__('Free Courses', 'woothemes-sensei').$after_html;
2471 2471
                 break;
2472 2472
             case 'paidcourses':
2473
-                $html .= $before_html .  __( 'Paid Courses', 'woothemes-sensei' ) . $after_html;
2473
+                $html .= $before_html.__('Paid Courses', 'woothemes-sensei').$after_html;
2474 2474
                 break;
2475 2475
             default:
2476
-                $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html;
2476
+                $html .= $before_html.__('Courses', 'woothemes-sensei').$after_html;
2477 2477
                 break;
2478 2478
         } // End Switch Statement
2479 2479
 
2480
-        echo apply_filters( 'course_archive_title', $html );
2480
+        echo apply_filters('course_archive_title', $html);
2481 2481
 
2482 2482
     }//course_archive_header
2483 2483
 
@@ -2491,9 +2491,9 @@  discard block
 block discarded – undo
2491 2491
      * @param string $content
2492 2492
      * @return string $content or $excerpt
2493 2493
      */
2494
-    public static function single_course_content( $content ){
2494
+    public static function single_course_content($content) {
2495 2495
 
2496
-        if( ! is_singular('course') ){
2496
+        if ( ! is_singular('course')) {
2497 2497
 
2498 2498
             return $content;
2499 2499
 
@@ -2502,21 +2502,21 @@  discard block
 block discarded – undo
2502 2502
         // Content Access Permissions
2503 2503
         $access_permission = false;
2504 2504
 
2505
-        if ( ! Sensei()->settings->get('access_permission')  || sensei_all_access() ) {
2505
+        if ( ! Sensei()->settings->get('access_permission') || sensei_all_access()) {
2506 2506
 
2507 2507
             $access_permission = true;
2508 2508
 
2509 2509
         } // End If Statement
2510 2510
 
2511 2511
         // Check if the user is taking the course
2512
-        $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() );
2512
+        $is_user_taking_course = Sensei_Utils::user_started_course(get_the_ID(), get_current_user_id());
2513 2513
 
2514
-        if(Sensei_WC::is_woocommerce_active()) {
2514
+        if (Sensei_WC::is_woocommerce_active()) {
2515 2515
 
2516
-            $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true );
2517
-            $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id );
2516
+            $wc_post_id = get_post_meta(get_the_ID(), '_course_woocommerce_product', true);
2517
+            $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
2518 2518
 
2519
-            $has_product_attached = isset ( $product ) && is_object ( $product );
2519
+            $has_product_attached = isset ($product) && is_object($product);
2520 2520
 
2521 2521
         } else {
2522 2522
 
@@ -2524,17 +2524,17 @@  discard block
 block discarded – undo
2524 2524
 
2525 2525
         }
2526 2526
 
2527
-        if ( ( is_user_logged_in() && $is_user_taking_course )
2528
-            || ( $access_permission && !$has_product_attached)
2529
-            || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) {
2527
+        if ((is_user_logged_in() && $is_user_taking_course)
2528
+            || ($access_permission && ! $has_product_attached)
2529
+            || 'full' == Sensei()->settings->get('course_single_content_display')) {
2530 2530
 
2531 2531
 	        // compensate for core providing and empty $content
2532 2532
 
2533
-	        if( empty( $content ) ){
2534
-		        remove_filter( 'the_content', array( 'Sensei_Course', 'single_course_content') );
2535
-		        $course = get_post( get_the_ID() );
2533
+	        if (empty($content)) {
2534
+		        remove_filter('the_content', array('Sensei_Course', 'single_course_content'));
2535
+		        $course = get_post(get_the_ID());
2536 2536
 
2537
-		        $content = apply_filters( 'the_content', $course->post_content );
2537
+		        $content = apply_filters('the_content', $course->post_content);
2538 2538
 
2539 2539
 	        }
2540 2540
 
@@ -2542,7 +2542,7 @@  discard block
 block discarded – undo
2542 2542
 
2543 2543
         } else {
2544 2544
 
2545
-            return '<p class="course-excerpt">' . get_post(  get_the_ID() )->post_excerpt . '</p>';
2545
+            return '<p class="course-excerpt">'.get_post(get_the_ID())->post_excerpt.'</p>';
2546 2546
 
2547 2547
         }
2548 2548
 
@@ -2553,25 +2553,25 @@  discard block
 block discarded – undo
2553 2553
      *
2554 2554
      * @since 1.9.0
2555 2555
      */
2556
-    public static function the_course_lessons_title(){
2556
+    public static function the_course_lessons_title() {
2557 2557
 
2558
-	    if ( ! is_singular( 'course' )  ) {
2558
+	    if ( ! is_singular('course')) {
2559 2559
 		    return;
2560 2560
 	    }
2561 2561
 
2562 2562
         global $post;
2563
-        $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID  );
2564
-        $course_lessons = Sensei()->course->course_lessons( $post->ID );
2563
+        $none_module_lessons = Sensei()->modules->get_none_module_lessons($post->ID);
2564
+        $course_lessons = Sensei()->course->course_lessons($post->ID);
2565 2565
 
2566 2566
         // title should be Other Lessons if there are lessons belonging to models.
2567 2567
         $title = __('Other Lessons', 'woothemes-sensei');
2568 2568
 
2569 2569
         // show lessons if the number of lesson in the course is the same as those that isn't assigned to a module
2570
-        if( count( $course_lessons ) == count( $none_module_lessons )  ){
2570
+        if (count($course_lessons) == count($none_module_lessons)) {
2571 2571
 
2572 2572
             $title = __('Lessons', 'woothemes-sensei');
2573 2573
 
2574
-        }elseif( empty( $none_module_lessons ) ){ // if the none module lessons are simply empty the title should not be shown
2574
+        }elseif (empty($none_module_lessons)) { // if the none module lessons are simply empty the title should not be shown
2575 2575
 
2576 2576
             $title = '';
2577 2577
         }
@@ -2579,7 +2579,7 @@  discard block
 block discarded – undo
2579 2579
         /**
2580 2580
          * hook document in class-woothemes-sensei-message.php
2581 2581
          */
2582
-        $title = apply_filters( 'sensei_single_title', $title, $post->post_type );
2582
+        $title = apply_filters('sensei_single_title', $title, $post->post_type);
2583 2583
 
2584 2584
         ob_start(); // start capturing the following output.
2585 2585
 
@@ -2598,7 +2598,7 @@  discard block
 block discarded – undo
2598 2598
          * @since 1.9.0
2599 2599
          * @param string $lessons_title_html
2600 2600
          */
2601
-        echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing.
2601
+        echo apply_filters('the_course_lessons_title', ob_get_clean()); // output and filter the captured output and stop capturing.
2602 2602
 
2603 2603
     }// end the_course_lessons_title
2604 2604
 
@@ -2613,13 +2613,13 @@  discard block
 block discarded – undo
2613 2613
      * @since 1.9.0
2614 2614
      * @global $wp_query
2615 2615
      */
2616
-    public static function load_single_course_lessons_query(){
2616
+    public static function load_single_course_lessons_query() {
2617 2617
 
2618 2618
         global $post, $wp_query;
2619 2619
 
2620 2620
         $course_id = $post->ID;
2621 2621
 
2622
-        if( 'course' != get_post_type( $course_id ) ){
2622
+        if ('course' != get_post_type($course_id)) {
2623 2623
             return;
2624 2624
         }
2625 2625
 
@@ -2631,7 +2631,7 @@  discard block
 block discarded – undo
2631 2631
             'meta_query'        => array(
2632 2632
                 array(
2633 2633
                     'key' => '_lesson_course',
2634
-                    'value' => intval( $course_id ),
2634
+                    'value' => intval($course_id),
2635 2635
                 ),
2636 2636
             ),
2637 2637
             'post_status'       => 'public',
@@ -2639,17 +2639,17 @@  discard block
 block discarded – undo
2639 2639
         );
2640 2640
 
2641 2641
         // Exclude lessons belonging to modules as they are queried along with the modules.
2642
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2643
-        if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){
2642
+        $modules = Sensei()->modules->get_course_modules($course_id);
2643
+        if ( ! is_wp_error($modules) && ! empty($modules) && is_array($modules)) {
2644 2644
 
2645 2645
             $terms_ids = array();
2646
-            foreach( $modules as $term ){
2646
+            foreach ($modules as $term) {
2647 2647
 
2648 2648
                 $terms_ids[] = $term->term_id;
2649 2649
 
2650 2650
             }
2651 2651
 
2652
-            $course_lesson_query_args[ 'tax_query'] = array(
2652
+            $course_lesson_query_args['tax_query'] = array(
2653 2653
                 array(
2654 2654
                     'taxonomy' => 'module',
2655 2655
                     'field'    => 'id',
@@ -2660,16 +2660,16 @@  discard block
 block discarded – undo
2660 2660
         }
2661 2661
 
2662 2662
         //setting lesson order
2663
-        $course_lesson_order = get_post_meta( $course_id, '_lesson_order', true);
2664
-        if( !empty( $course_lesson_order ) ){
2663
+        $course_lesson_order = get_post_meta($course_id, '_lesson_order', true);
2664
+        if ( ! empty($course_lesson_order)) {
2665 2665
 
2666
-            $course_lesson_query_args['post__in'] = explode( ',', $course_lesson_order );
2667
-            $course_lesson_query_args['orderby']= 'post__in' ;
2668
-            unset( $course_lesson_query_args['order'] );
2666
+            $course_lesson_query_args['post__in'] = explode(',', $course_lesson_order);
2667
+            $course_lesson_query_args['orderby'] = 'post__in';
2668
+            unset($course_lesson_query_args['order']);
2669 2669
 
2670 2670
         }
2671 2671
 
2672
-        $wp_query = new WP_Query( $course_lesson_query_args );
2672
+        $wp_query = new WP_Query($course_lesson_query_args);
2673 2673
 
2674 2674
     }// load_single_course_lessons
2675 2675
 
@@ -2680,16 +2680,16 @@  discard block
 block discarded – undo
2680 2680
      *
2681 2681
      * @param $post_id
2682 2682
      */
2683
-    public static function flush_rewrite_rules( $post_id ){
2683
+    public static function flush_rewrite_rules($post_id) {
2684 2684
 
2685
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
2685
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
2686 2686
 
2687 2687
             return;
2688 2688
 
2689 2689
         }
2690 2690
 
2691 2691
 
2692
-        if( 'course' == get_post_type( $post_id )  ){
2692
+        if ('course' == get_post_type($post_id)) {
2693 2693
 
2694 2694
             Sensei()->initiate_rewrite_rules_flush();
2695 2695
 
@@ -2705,10 +2705,10 @@  discard block
 block discarded – undo
2705 2705
      * @param $excerpt
2706 2706
      * @return string
2707 2707
      */
2708
-    public static function full_content_excerpt_override( $excerpt ){
2708
+    public static function full_content_excerpt_override($excerpt) {
2709 2709
 
2710
-        if (   is_singular('course')  &&
2711
-                'full' == Sensei()->settings->get( 'course_single_content_display' ) ){
2710
+        if (is_singular('course') &&
2711
+                'full' == Sensei()->settings->get('course_single_content_display')) {
2712 2712
 
2713 2713
             return get_the_content();
2714 2714
 
@@ -2725,11 +2725,11 @@  discard block
 block discarded – undo
2725 2725
      *
2726 2726
      * @since 1.9.0
2727 2727
      */
2728
-    public static function the_course_enrolment_actions(){
2728
+    public static function the_course_enrolment_actions() {
2729 2729
 
2730 2730
 	    global $post;
2731 2731
 
2732
-	    if ( 'course' != $post->post_type ) {
2732
+	    if ('course' != $post->post_type) {
2733 2733
 			return;
2734 2734
 	    }
2735 2735
 
@@ -2737,15 +2737,15 @@  discard block
 block discarded – undo
2737 2737
         <section class="course-meta course-enrolment">
2738 2738
         <?php
2739 2739
         global  $post, $current_user;
2740
-        $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
2740
+        $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID);
2741 2741
 
2742
-	    if ( is_user_logged_in() && ! $is_user_taking_course ) {
2742
+	    if (is_user_logged_in() && ! $is_user_taking_course) {
2743 2743
 
2744 2744
 	        // Check for woocommerce
2745
-	        if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2745
+	        if (Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable($post->ID)) {
2746 2746
 
2747 2747
 		        // Get the product ID
2748
-                Sensei_WC::the_add_to_cart_button_html($post->ID );
2748
+                Sensei_WC::the_add_to_cart_button_html($post->ID);
2749 2749
 
2750 2750
             } else {
2751 2751
 
@@ -2753,50 +2753,50 @@  discard block
 block discarded – undo
2753 2753
 
2754 2754
             } // End If Statement
2755 2755
 
2756
-        } elseif ( is_user_logged_in() ) {
2756
+        } elseif (is_user_logged_in()) {
2757 2757
 
2758 2758
             // Check if course is completed
2759
-            $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID );
2760
-            $completed_course = Sensei_Utils::user_completed_course( $user_course_status );
2759
+            $user_course_status = Sensei_Utils::user_course_status($post->ID, $current_user->ID);
2760
+            $completed_course = Sensei_Utils::user_completed_course($user_course_status);
2761 2761
             // Success message
2762
-            if ( $completed_course ) { ?>
2763
-                <div class="status completed"><?php  _e( 'Completed', 'woothemes-sensei' ); ?></div>
2762
+            if ($completed_course) { ?>
2763
+                <div class="status completed"><?php  _e('Completed', 'woothemes-sensei'); ?></div>
2764 2764
                 <?php
2765
-                $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true );
2766
-                if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?>
2765
+                $has_quizzes = Sensei()->course->course_quizzes($post->ID, true);
2766
+                if (has_filter('sensei_results_links') || $has_quizzes) { ?>
2767 2767
                     <p class="sensei-results-links">
2768 2768
                         <?php
2769 2769
                         $results_link = '';
2770
-                        if( $has_quizzes ) {
2771
-                            $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' .  __( 'View results', 'woothemes-sensei' ) . '</a>';
2770
+                        if ($has_quizzes) {
2771
+                            $results_link = '<a class="view-results" href="'.Sensei()->course_results->get_permalink($post->ID).'">'.__('View results', 'woothemes-sensei').'</a>';
2772 2772
                         }
2773 2773
                         /**
2774 2774
                          * Filter documented in Sensei_Course::the_course_action_buttons
2775 2775
                          */
2776
-                        $results_link = apply_filters( 'sensei_results_links', $results_link, $post->ID );
2776
+                        $results_link = apply_filters('sensei_results_links', $results_link, $post->ID);
2777 2777
                         echo $results_link;
2778 2778
                         ?></p>
2779 2779
                 <?php } ?>
2780 2780
             <?php } else { ?>
2781
-                <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div>
2781
+                <div class="status in-progress"><?php echo __('In Progress', 'woothemes-sensei'); ?></div>
2782 2782
             <?php }
2783 2783
 
2784 2784
         } else {
2785 2785
 
2786 2786
             // Check for woocommerce
2787
-		    if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $post->ID ) ) {
2787
+		    if (Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable($post->ID)) {
2788 2788
 
2789
-	            $login_link =  '<a href="' . sensei_user_login_url() . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
2790
-	            $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
2791
-	            Sensei()->notices->add_notice( $message, 'info' ) ;
2792
-	            Sensei_WC::the_add_to_cart_button_html( $post->ID );
2789
+	            $login_link = '<a href="'.sensei_user_login_url().'">'.__('log in', 'woothemes-sensei').'</a>';
2790
+	            $message = sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link);
2791
+	            Sensei()->notices->add_notice($message, 'info');
2792
+	            Sensei_WC::the_add_to_cart_button_html($post->ID);
2793 2793
 
2794 2794
             } else {
2795 2795
 
2796
-                if( get_option( 'users_can_register') ) {
2796
+                if (get_option('users_can_register')) {
2797 2797
 
2798 2798
 	                // set the permissions message
2799
-	                $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
2799
+	                $anchor_before = '<a href="'.esc_url(sensei_user_login_url()).'" >';
2800 2800
 	                $anchor_after = '</a>';
2801 2801
 	                $notice = sprintf(
2802 2802
 		                __('or log in to view this courses. Click here to %slogin%s.'),
@@ -2805,8 +2805,8 @@  discard block
 block discarded – undo
2805 2805
 	                );
2806 2806
 
2807 2807
 	                // register the notice to display
2808
-	                if( Sensei()->settings->get( 'access_permission' ) ){
2809
-		                Sensei()->notices->add_notice( $notice, 'info' ) ;
2808
+	                if (Sensei()->settings->get('access_permission')) {
2809
+		                Sensei()->notices->add_notice($notice, 'info');
2810 2810
 	                }
2811 2811
 
2812 2812
 
@@ -2823,24 +2823,24 @@  discard block
 block discarded – undo
2823 2823
                     $wp_register_link = apply_filters('sensei_use_wp_register_link', false);
2824 2824
 
2825 2825
                     $settings = Sensei()->settings->get_settings();
2826
-                    if( isset( $settings[ 'my_course_page' ] )
2827
-                        && 0 < intval( $settings[ 'my_course_page' ] ) ){
2826
+                    if (isset($settings['my_course_page'])
2827
+                        && 0 < intval($settings['my_course_page'])) {
2828 2828
 
2829
-                        $my_courses_page_id = $settings[ 'my_course_page' ];
2829
+                        $my_courses_page_id = $settings['my_course_page'];
2830 2830
 
2831 2831
                     }
2832 2832
 
2833 2833
                     // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link'
2834 2834
                     // is false, link to My Courses. If not, link to default WordPress registration page.
2835
-                    if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){
2835
+                    if ( ! empty($my_courses_page_id) && $my_courses_page_id && ! $wp_register_link) {
2836 2836
 
2837
-                        $my_courses_url = get_permalink( $my_courses_page_id  );
2838
-                        $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>';
2839
-                        echo '<div class="status register">' . $register_link . '</div>' ;
2837
+                        $my_courses_url = get_permalink($my_courses_page_id);
2838
+                        $register_link = '<a href="'.$my_courses_url.'">'.__('Register', 'woothemes-sensei').'</a>';
2839
+                        echo '<div class="status register">'.$register_link.'</div>';
2840 2840
 
2841
-                    } else{
2841
+                    } else {
2842 2842
 
2843
-                        wp_register( '<div class="status register">', '</div>' );
2843
+                        wp_register('<div class="status register">', '</div>');
2844 2844
 
2845 2845
                     }
2846 2846
 
@@ -2859,23 +2859,23 @@  discard block
 block discarded – undo
2859 2859
      *
2860 2860
      * @since 1.9.0
2861 2861
      */
2862
-    public static function the_course_video(){
2862
+    public static function the_course_video() {
2863 2863
 
2864 2864
         global $post;
2865 2865
 
2866
-	    if ( ! is_singular( 'course' )  ) {
2866
+	    if ( ! is_singular('course')) {
2867 2867
 		    return;
2868 2868
 	    }
2869 2869
         // Get the meta info
2870
-        $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true );
2870
+        $course_video_embed = get_post_meta($post->ID, '_course_video_embed', true);
2871 2871
 
2872
-        if ( 'http' == substr( $course_video_embed, 0, 4) ) {
2872
+        if ('http' == substr($course_video_embed, 0, 4)) {
2873 2873
 
2874
-            $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) );
2874
+            $course_video_embed = wp_oembed_get(esc_url($course_video_embed));
2875 2875
 
2876 2876
         } // End If Statement
2877 2877
 
2878
-        if ( '' != $course_video_embed ) { ?>
2878
+        if ('' != $course_video_embed) { ?>
2879 2879
 
2880 2880
             <div class="course-video">
2881 2881
                 <?php echo html_entity_decode($course_video_embed); ?>
@@ -2890,9 +2890,9 @@  discard block
 block discarded – undo
2890 2890
      * @global $post
2891 2891
      * @since 1.9.0
2892 2892
      */
2893
-    public static function the_title(){
2893
+    public static function the_title() {
2894 2894
 
2895
-	    if( ! is_singular( 'course' ) ){
2895
+	    if ( ! is_singular('course')) {
2896 2896
 			return;
2897 2897
 	    }
2898 2898
         global $post;
@@ -2906,7 +2906,7 @@  discard block
 block discarded – undo
2906 2906
                 /**
2907 2907
                  * Filter documented in class-sensei-messages.php the_title
2908 2908
                  */
2909
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
2909
+                echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type);
2910 2910
                 ?>
2911 2911
 
2912 2912
             </h1>
@@ -2922,30 +2922,30 @@  discard block
 block discarded – undo
2922 2922
      *
2923 2923
      * @since 1.9.0
2924 2924
      */
2925
-    public static function course_category_title(){
2925
+    public static function course_category_title() {
2926 2926
 
2927
-        if( ! is_tax( 'course-category' ) ){
2927
+        if ( ! is_tax('course-category')) {
2928 2928
             return;
2929 2929
         }
2930 2930
 
2931 2931
         $category_slug = get_query_var('course-category');
2932
-        $term  = get_term_by('slug',$category_slug,'course-category');
2932
+        $term = get_term_by('slug', $category_slug, 'course-category');
2933 2933
 
2934
-        if( ! empty($term) ){
2934
+        if ( ! empty($term)) {
2935 2935
 
2936 2936
             $title = $term->name;
2937 2937
 
2938
-        }else{
2938
+        } else {
2939 2939
 
2940 2940
             $title = 'Course Category';
2941 2941
 
2942 2942
         }
2943 2943
 
2944 2944
         $html = '<h2 class="sensei-category-title">';
2945
-        $html .= __('Category') . ' ' . $title;
2945
+        $html .= __('Category').' '.$title;
2946 2946
         $html .= '</h2>';
2947 2947
 
2948
-        echo apply_filters( 'course_category_title', $html , $term->term_id );
2948
+        echo apply_filters('course_category_title', $html, $term->term_id);
2949 2949
 
2950 2950
     }// course_category_title
2951 2951
 
@@ -2958,16 +2958,16 @@  discard block
 block discarded – undo
2958 2958
      * @param WP_Query $query
2959 2959
      * @return WP_Query
2960 2960
      */
2961
-    public static function alter_course_category_order( $query ){
2961
+    public static function alter_course_category_order($query) {
2962 2962
 
2963
-        if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){
2963
+        if ( ! is_tax('course-category') || ! $query->is_main_query()) {
2964 2964
             return $query;
2965 2965
         }
2966 2966
 
2967
-        $order = get_option( 'sensei_course_order', '' );
2968
-        if( !empty( $order )  ){
2969
-            $query->set('orderby', 'menu_order' );
2970
-            $query->set('order', 'ASC' );
2967
+        $order = get_option('sensei_course_order', '');
2968
+        if ( ! empty($order)) {
2969
+            $query->set('orderby', 'menu_order');
2970
+            $query->set('order', 'ASC');
2971 2971
         }
2972 2972
 
2973 2973
         return $query;
@@ -2988,7 +2988,7 @@  discard block
 block discarded – undo
2988 2988
      *
2989 2989
      * @return array
2990 2990
      */
2991
-    public static function get_default_query_args(){
2991
+    public static function get_default_query_args() {
2992 2992
         return array(
2993 2993
             'post_type' 		=> 'course',
2994 2994
             'posts_per_page' 		=> 1000,
@@ -3006,14 +3006,14 @@  discard block
 block discarded – undo
3006 3006
      * @param $course_id
3007 3007
      * @return bool
3008 3008
      */
3009
-    public static function is_prerequisite_complete( $course_id ){
3009
+    public static function is_prerequisite_complete($course_id) {
3010 3010
 
3011
-        $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true );
3011
+        $course_prerequisite_id = get_post_meta($course_id, '_course_prerequisite', true);
3012 3012
 
3013 3013
         // if it has a pre requisite course check it
3014
-        if( ! empty(  $course_prerequisite_id ) ){
3014
+        if ( ! empty($course_prerequisite_id)) {
3015 3015
 
3016
-            return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() );
3016
+            return Sensei_Utils::user_completed_course($course_prerequisite_id, get_current_user_id());
3017 3017
 
3018 3018
         }
3019 3019
 
@@ -3029,4 +3029,4 @@  discard block
 block discarded – undo
3029 3029
  * @ignore only for backward compatibility
3030 3030
  * @since 1.9.0
3031 3031
  */
3032
-class WooThemes_Sensei_Course extends Sensei_Course{}
3032
+class WooThemes_Sensei_Course extends Sensei_Course {}
Please login to merge, or discard this patch.
includes/class-sensei-lesson.php 2 patches
Indentation   +1070 added lines, -1070 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@  discard block
 block discarded – undo
21 21
 	 */
22 22
 	public function __construct () {
23 23
 
24
-        $this->token = 'lesson';
24
+		$this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27 27
 		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
28 28
 
29
-        $this->question_order = '';
29
+		$this->question_order = '';
30 30
 
31 31
 		// Admin actions
32 32
 		if ( is_admin() ) {
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
 			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85 85
 			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
86 86
 
87
-            // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
87
+			// output bulk edit fields
88
+			add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
+			add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
90 90
 
91
-            // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
91
+			// load quick edit default values
92
+			add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94
-            // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
94
+			// save bulk edit fields
95
+			add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
96 96
 
97
-            // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
97
+			// flush rewrite rules when saving a lesson
98
+			add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		$post_args = array(	'post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192
-    						'order'           	=> 'ASC',
193
-    						'exclude' 			=> $post->ID,
192
+							'order'           	=> 'ASC',
193
+							'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196 196
 		$posts_array = get_posts( $post_args );
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		$checked = '';
228 228
 		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
229
+	 		$checked = checked( 'preview', $lesson_preview, false );
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 
285 285
 
286 286
 	/**
287
-     * Update the lesson quiz and all the post meta
287
+	 * Update the lesson quiz and all the post meta
288 288
 	 *
289 289
 	 * @access public
290 290
 	 * @return integer|boolean $post_id or false
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		}
306 306
 
307 307
 		// Temporarily disable the filter
308
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
308
+		remove_action( 'save_post', array( $this, 'quiz_update' ) );
309 309
 		// Save the Quiz
310 310
 		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
311 311
 
@@ -320,11 +320,11 @@  discard block
 block discarded – undo
320 320
 
321 321
 		// Setup Query Arguments
322 322
 		$post_type_args = array(	'post_content' => $post_content,
323
-  		    						'post_status' => $post_status,
324
-  		    						'post_title' => $post_title,
325
-  		    						'post_type' => 'quiz',
326
-                                    'post_parent' => $post_id,
327
-  		    						);
323
+  									'post_status' => $post_status,
324
+  									'post_title' => $post_title,
325
+  									'post_type' => 'quiz',
326
+									'post_parent' => $post_id,
327
+  									);
328 328
 
329 329
 		$settings = $this->get_quiz_settings();
330 330
 
@@ -332,48 +332,48 @@  discard block
 block discarded – undo
332 332
 		if ( 0 < $quiz_id ) {
333 333
 			// Update the Quiz
334 334
 			$post_type_args[ 'ID' ] = $quiz_id;
335
-		    wp_update_post($post_type_args);
336
-
337
-		    // Update the post meta data
338
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
339
-
340
-		    foreach( $settings as $field ) {
341
-		    	if( 'random_question_order' != $field['id'] ) {
342
-			    	$value = $this->get_submitted_setting_value( $field );
343
-			    	if( isset( $value ) ) {
344
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
345
-			    	}
346
-			    }
347
-		    }
348
-
349
-		    // Set the post terms for quiz-type
350
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
335
+			wp_update_post($post_type_args);
336
+
337
+			// Update the post meta data
338
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
339
+
340
+			foreach( $settings as $field ) {
341
+				if( 'random_question_order' != $field['id'] ) {
342
+					$value = $this->get_submitted_setting_value( $field );
343
+					if( isset( $value ) ) {
344
+						update_post_meta( $quiz_id, '_' . $field['id'], $value );
345
+					}
346
+				}
347
+			}
348
+
349
+			// Set the post terms for quiz-type
350
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
351 351
 		} else {
352 352
 			// Create the Quiz
353
-		    $quiz_id = wp_insert_post($post_type_args);
354
-
355
-		    // Add the post meta data WP will add it if it doesn't exist
356
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
357
-
358
-		    foreach( $settings as $field ) {
359
-		    	if( 'random_question_order' != $field['id'] ) {
360
-
361
-                    //ignore values not posted to avoid
362
-                    // overwriting with empty or default values
363
-                    // when the values are posted from bulk edit or quick edit
364
-                    if( !isset( $_POST[ $field['id'] ] ) ){
365
-                        continue;
366
-                    }
367
-
368
-			    	$value = $this->get_submitted_setting_value( $field );
369
-			    	if( isset( $value ) ) {
370
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
371
-			    	}
372
-			    }
373
-		    }
374
-
375
-		    // Set the post terms for quiz-type
376
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
353
+			$quiz_id = wp_insert_post($post_type_args);
354
+
355
+			// Add the post meta data WP will add it if it doesn't exist
356
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
357
+
358
+			foreach( $settings as $field ) {
359
+				if( 'random_question_order' != $field['id'] ) {
360
+
361
+					//ignore values not posted to avoid
362
+					// overwriting with empty or default values
363
+					// when the values are posted from bulk edit or quick edit
364
+					if( !isset( $_POST[ $field['id'] ] ) ){
365
+						continue;
366
+					}
367
+
368
+					$value = $this->get_submitted_setting_value( $field );
369
+					if( isset( $value ) ) {
370
+						add_post_meta( $quiz_id, '_' . $field['id'], $value );
371
+					}
372
+				}
373
+			}
374
+
375
+			// Set the post terms for quiz-type
376
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
377 377
 		} // End If Statement
378 378
 
379 379
 		// Add default lesson order meta value
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 		}
396 396
 
397 397
 		// Restore the previously disabled filter
398
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
398
+		add_action( 'save_post', array( $this, 'quiz_update' ) );
399 399
 
400 400
 	} // End post_updated()
401 401
 
@@ -435,22 +435,22 @@  discard block
 block discarded – undo
435 435
 		// Get the meta key.
436 436
 		$meta_key = '_' . $post_key;
437 437
 
438
-        //ignore fields are not posted
438
+		//ignore fields are not posted
439 439
 
440
-        if( !isset( $_POST[ $post_key ] ) ){
440
+		if( !isset( $_POST[ $post_key ] ) ){
441 441
 
442
-            // except for lesson preview checkbox field
443
-            if( 'lesson_preview' == $post_key ){
442
+			// except for lesson preview checkbox field
443
+			if( 'lesson_preview' == $post_key ){
444 444
 
445
-                $_POST[ $post_key ] = '';
445
+				$_POST[ $post_key ] = '';
446 446
 
447
-            } else {
447
+			} else {
448 448
 
449
-                return false;
449
+				return false;
450 450
 
451
-            }
451
+			}
452 452
 
453
-        }
453
+		}
454 454
 
455 455
 		// Get the posted data and sanitize it for use as an HTML class.
456 456
 		if ( 'lesson_video_embed' == $post_key) {
@@ -459,10 +459,10 @@  discard block
 block discarded – undo
459 459
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
460 460
 		} // End If Statement
461 461
 
462
-        // update field with the new value
463
-        if( -1 != $new_meta_value  ){
464
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
465
-        }
462
+		// update field with the new value
463
+		if( -1 != $new_meta_value  ){
464
+			return update_post_meta( $post_id, $meta_key, $new_meta_value );
465
+		}
466 466
 
467 467
 	} // End save_post_meta()
468 468
 
@@ -487,9 +487,9 @@  discard block
 block discarded – undo
487 487
 		$post_args = array(	'post_type' 		=> 'course',
488 488
 							'posts_per_page' 		=> -1,
489 489
 							'orderby'         	=> 'title',
490
-    						'order'           	=> 'ASC',
491
-    						'post_status'      	=> 'any',
492
-    						'suppress_filters' 	=> 0,
490
+							'order'           	=> 'ASC',
491
+							'post_status'      	=> 'any',
492
+							'suppress_filters' 	=> 0,
493 493
 							);
494 494
 		$posts_array = get_posts( $post_args );
495 495
 		// Buid the HTML to Output
@@ -497,20 +497,20 @@  discard block
 block discarded – undo
497 497
 		// Nonce
498 498
 		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
499 499
 
500
-        // Select the course for the lesson
501
-        $drop_down_args = array(
502
-            'name'=>'lesson_course',
503
-            'id' => 'lesson-course-options'
504
-        );
500
+		// Select the course for the lesson
501
+		$drop_down_args = array(
502
+			'name'=>'lesson_course',
503
+			'id' => 'lesson-course-options'
504
+		);
505 505
 
506
-        $courses = WooThemes_Sensei_Course::get_all_courses();
507
-        $courses_options = array();
508
-        foreach( $courses as $course ){
509
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
510
-        }
511
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
506
+		$courses = WooThemes_Sensei_Course::get_all_courses();
507
+		$courses_options = array();
508
+		foreach( $courses as $course ){
509
+			$courses_options[ $course->ID ] = get_the_title( $course ) ;
510
+		}
511
+		$html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
512 512
 
513
-        // Course Actions Panel
513
+		// Course Actions Panel
514 514
 		if ( current_user_can( 'publish_courses' )) {
515 515
 				$html .= '<div id="lesson-course-actions">';
516 516
 					$html .= '<p>';
@@ -536,16 +536,16 @@  discard block
 block discarded – undo
536 536
 							} // End For Loop
537 537
 						$html .= '</select>' . "\n";
538 538
 						// Course Product
539
-                        if ( Sensei_WC::is_woocommerce_active() ) {
539
+						if ( Sensei_WC::is_woocommerce_active() ) {
540 540
 	  						// Get the Products
541 541
 							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
542 542
 
543 543
 							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
544 544
 													'posts_per_page' 		=> -1,
545 545
 													'orderby'         	=> 'title',
546
-	    											'order'           	=> 'DESC',
547
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
548
-	    											'tax_query'			=> array(
546
+													'order'           	=> 'DESC',
547
+													'post_status'		=> array( 'publish', 'private', 'draft' ),
548
+													'tax_query'			=> array(
549 549
 														array(
550 550
 															'taxonomy'	=> 'product_type',
551 551
 															'field'		=> 'slug',
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 															'operator'	=> 'NOT IN'
554 554
 														)
555 555
 													),
556
-	    											'suppress_filters' 	=> 0
556
+													'suppress_filters' 	=> 0
557 557
 													);
558 558
 							$products_array = get_posts( $product_args );
559 559
 							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
@@ -881,58 +881,58 @@  discard block
 block discarded – undo
881 881
 					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
882 882
 						$html .= '<td colspan="5">';
883 883
 							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
884
-					    	$html .= '<div class="question_required_fields">';
885
-
886
-						    	// Question title
887
-						    	$html .= '<div>';
888
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
889
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
890
-						    	$html .= '</div>';
891
-
892
-						    	// Question description
893
-						    	$html .= '<div>';
894
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
895
-						    	$html .= '</div>';
896
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
897
-
898
-						    	// Question grade
899
-						    	$html .= '<div>';
900
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
901
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
902
-						    	$html .= '</div>';
903
-
904
-						    	// Random order
905
-						    	if( $question_type == 'multiple-choice' ) {
906
-						    		$html .= '<div>';
907
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
908
-						    		$html .= '</div>';
909
-						    	}
910
-
911
-						    	// Question media
912
-						    	$html .= '<div>';
913
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
914
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
915
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
916
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
917
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
918
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
919
-						    	$html .= '</div>';
920
-
921
-						    $html .= '</div>';
922
-
923
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
924
-
925
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
884
+							$html .= '<div class="question_required_fields">';
885
+
886
+								// Question title
887
+								$html .= '<div>';
888
+									$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
889
+									$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
890
+								$html .= '</div>';
891
+
892
+								// Question description
893
+								$html .= '<div>';
894
+									$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
895
+								$html .= '</div>';
896
+									$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
897
+
898
+								// Question grade
899
+								$html .= '<div>';
900
+									$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
901
+									$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
902
+								$html .= '</div>';
903
+
904
+								// Random order
905
+								if( $question_type == 'multiple-choice' ) {
906
+									$html .= '<div>';
907
+										$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
908
+									$html .= '</div>';
909
+								}
910
+
911
+								// Question media
912
+								$html .= '<div>';
913
+									$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
914
+									$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
915
+									$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
916
+									$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
917
+									$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
918
+									$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
919
+								$html .= '</div>';
920
+
921
+							$html .= '</div>';
922
+
923
+							$html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
924
+
925
+							$html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
926 926
 							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
927 927
 
928 928
 							if( 'quiz' == $context ) {
929
-					    		$html .= '<div class="update-question">';
930
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
931
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
932
-					    		$html .= '</div>';
933
-					    	}
929
+								$html .= '<div class="update-question">';
930
+									$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
931
+									$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
932
+								$html .= '</div>';
933
+							}
934 934
 
935
-			    		$html .= '</td>';
935
+						$html .= '</td>';
936 936
 					$html .= '</tr>';
937 937
 				}
938 938
 
@@ -953,20 +953,20 @@  discard block
 block discarded – undo
953 953
 			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
954 954
 
955 955
 			if( 'quiz' == $context ) {
956
-	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
957
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
958
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
959
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
960
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
961
-	    			}
962
-	    		$html .= '</h2>';
963
-	    	}
956
+				$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
957
+					$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
958
+					$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
959
+					if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
960
+						$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
961
+					}
962
+				$html .= '</h2>';
963
+			}
964 964
 
965
-	    	$html .= '<div class="tab-content" id="tab-new-content">';
965
+			$html .= '<div class="tab-content" id="tab-new-content">';
966 966
 
967
-	    		if( 'quiz' == $context ) {
968
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
969
-	    		}
967
+				if( 'quiz' == $context ) {
968
+					$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
969
+				}
970 970
 
971 971
 				$html .= '<div class="question">';
972 972
 					$html .= '<div class="question_required_fields">';
@@ -1008,18 +1008,18 @@  discard block
 block discarded – undo
1008 1008
 
1009 1009
 						// Random order
1010 1010
 						$html .= '<p class="add_question_random_order">';
1011
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1012
-			    		$html .= '</p>';
1011
+							$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1012
+						$html .= '</p>';
1013 1013
 
1014
-			    		// Question media
1014
+						// Question media
1015 1015
 						$html .= '<p>';
1016
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1017
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1018
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1019
-					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1020
-					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1021
-					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1022
-				    	$html .= '</p>';
1016
+							$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1017
+							$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1018
+							$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1019
+							$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1020
+							$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1021
+							$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1022
+						$html .= '</p>';
1023 1023
 
1024 1024
 					$html .= '</div>';
1025 1025
 				$html .= '</div>';
@@ -1030,19 +1030,19 @@  discard block
 block discarded – undo
1030 1030
 
1031 1031
 				if( 'quiz' == $context ) {
1032 1032
 					$html .= '<div class="add-question">';
1033
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1034
-		    		$html .= '</div>';
1035
-		    	}
1033
+						$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1034
+					$html .= '</div>';
1035
+				}
1036 1036
 
1037
-		    $html .= '</div>';
1037
+			$html .= '</div>';
1038 1038
 
1039
-		    if( 'quiz' == $context ) {
1039
+			if( 'quiz' == $context ) {
1040 1040
 
1041
-			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1041
+				$html .= '<div class="tab-content hidden" id="tab-existing-content">';
1042 1042
 
1043
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1043
+					$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1044 1044
 
1045
-			    	$html .= '<div id="existing-filters" class="alignleft actions">
1045
+					$html .= '<div id="existing-filters" class="alignleft actions">
1046 1046
 			    				<select id="existing-status">
1047 1047
 			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1048 1048
 			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
@@ -1050,23 +1050,23 @@  discard block
 block discarded – undo
1050 1050
 			    				</select>
1051 1051
 			    				<select id="existing-type">
1052 1052
 			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1053
-							    	foreach ( $question_types as $type => $label ) {
1053
+									foreach ( $question_types as $type => $label ) {
1054 1054
 										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1055 1055
 									}
1056
-    				$html .= '</select>
1056
+					$html .= '</select>
1057 1057
     							<select id="existing-category">
1058 1058
 			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1059
-				    				foreach( $question_cats as $cat ) {
1059
+									foreach( $question_cats as $cat ) {
1060 1060
 										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1061 1061
 									}
1062
-    				$html .= '</select>
1062
+					$html .= '</select>
1063 1063
     							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1064 1064
     							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1065 1065
 			    			</div>';
1066 1066
 
1067
-			    	$html .= '<table id="existing-table" class="widefat">';
1067
+					$html .= '<table id="existing-table" class="widefat">';
1068 1068
 
1069
-			    		$html .= '<thead>
1069
+						$html .= '<thead>
1070 1070
 									    <tr>
1071 1071
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1072 1072
 									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
@@ -1094,28 +1094,28 @@  discard block
 block discarded – undo
1094 1094
 
1095 1095
 						$html .= '</tbody>';
1096 1096
 
1097
-			    	$html .= '</table>';
1097
+					$html .= '</table>';
1098 1098
 
1099
-			    	$next_class = '';
1100
-			    	if( $questions['count'] <= 10 ) {
1101
-			    		$next_class = 'hidden';
1102
-			    	}
1099
+					$next_class = '';
1100
+					if( $questions['count'] <= 10 ) {
1101
+						$next_class = 'hidden';
1102
+					}
1103 1103
 
1104
-			    	$html .= '<div id="existing-pagination">';
1105
-			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1106
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1107
-			    	$html .= '</div>';
1104
+					$html .= '<div id="existing-pagination">';
1105
+						$html .= '<input type="hidden" id="existing-page" value="1" />';
1106
+						$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1107
+					$html .= '</div>';
1108 1108
 
1109
-			    	$html .= '<div class="existing-actions">';
1110
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1111
-			    	$html .= '</div>';
1109
+					$html .= '<div class="existing-actions">';
1110
+						$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1111
+					$html .= '</div>';
1112 1112
 
1113
-			    $html .= '</div>';
1113
+				$html .= '</div>';
1114 1114
 
1115
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1116
-				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1115
+				if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1116
+					$html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1117 1117
 
1118
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1118
+						$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1119 1119
 
1120 1120
 						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1121 1121
 						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
 
1129 1129
 						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1130 1130
 
1131
-				    $html .= '</div>';
1131
+					$html .= '</div>';
1132 1132
 				}
1133 1133
 			}
1134 1134
 
@@ -1201,14 +1201,14 @@  discard block
 block discarded – undo
1201 1201
 
1202 1202
 		$qry = new WP_Query( $args );
1203 1203
 
1204
-        /**
1205
-         * Filter existing questions query
1206
-         *
1207
-         * @since 1.8.0
1208
-         *
1209
-         * @param WP_Query $wp_query
1210
-         */
1211
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1204
+		/**
1205
+		 * Filter existing questions query
1206
+		 *
1207
+		 * @since 1.8.0
1208
+		 *
1209
+		 * @param WP_Query $wp_query
1210
+		 */
1211
+		$qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1212 1212
 
1213 1213
 		$questions['questions'] = $qry->posts;
1214 1214
 		$questions['count'] = intval( $qry->found_posts );
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
 
1224 1224
 		if( ! $question_id ) {
1225 1225
 
1226
-            return;
1226
+			return;
1227 1227
 
1228
-        }
1228
+		}
1229 1229
 
1230 1230
 		$existing_class = '';
1231 1231
 		if( $row % 2 ) {
1232
-            $existing_class = 'alternate';
1233
-        }
1232
+			$existing_class = 'alternate';
1233
+		}
1234 1234
 
1235 1235
 		$question_type = Sensei()->question->get_question_type( $question_id );
1236 1236
 
@@ -1364,67 +1364,67 @@  discard block
 block discarded – undo
1364 1364
 							}
1365 1365
 						}
1366 1366
 
1367
-				    	// Calculate total wrong answers available (defaults to 4)
1368
-				    	$total_wrong = 0;
1369
-				    	if( $question_id ) {
1370
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1371
-				    	}
1372
-				    	if( 0 == intval( $total_wrong ) ) {
1373
-				    		$total_wrong = 1;
1374
-				    	}
1367
+						// Calculate total wrong answers available (defaults to 4)
1368
+						$total_wrong = 0;
1369
+						if( $question_id ) {
1370
+							$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1371
+						}
1372
+						if( 0 == intval( $total_wrong ) ) {
1373
+							$total_wrong = 1;
1374
+						}
1375 1375
 
1376
-                        // Setup Wrong Answer HTML
1377
-                        foreach ( $wrong_answers as $i => $answer ){
1376
+						// Setup Wrong Answer HTML
1377
+						foreach ( $wrong_answers as $i => $answer ){
1378 1378
 
1379
-                            $answer_id = $this->get_answer_id( $answer );
1380
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1381
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1382
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
-                            if( $question_id ) {
1379
+							$answer_id = $this->get_answer_id( $answer );
1380
+							$wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1381
+							$wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1382
+							$wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
+							if( $question_id ) {
1384 1384
 
1385
-                                $answers[ $answer_id ] = $wrong_answer;
1385
+								$answers[ $answer_id ] = $wrong_answer;
1386 1386
 
1387
-                            } else {
1387
+							} else {
1388 1388
 
1389
-                                $answers[] = $wrong_answer;
1389
+								$answers[] = $wrong_answer;
1390 1390
 
1391
-                            }
1391
+							}
1392 1392
 
1393
-                        } // end for each
1393
+						} // end for each
1394 1394
 
1395
-				    	$answers_sorted = $answers;
1396
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1397
-				    		$answers_sorted = array();
1398
-				    		foreach( $answer_order as $answer_id ) {
1399
-				    			if( isset( $answers[ $answer_id ] ) ) {
1400
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1401
-				    				unset( $answers[ $answer_id ] );
1402
-				    			}
1403
-				    		}
1395
+						$answers_sorted = $answers;
1396
+						if( $question_id && count( $answer_order ) > 0 ) {
1397
+							$answers_sorted = array();
1398
+							foreach( $answer_order as $answer_id ) {
1399
+								if( isset( $answers[ $answer_id ] ) ) {
1400
+									$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1401
+									unset( $answers[ $answer_id ] );
1402
+								}
1403
+							}
1404 1404
 
1405
-				    		if( count( $answers ) > 0 ) {
1406
-						    	foreach( $answers as $id => $answer ) {
1407
-						    		$answers_sorted[ $id ] = $answer;
1408
-						    	}
1409
-						    }
1410
-				    	}
1405
+							if( count( $answers ) > 0 ) {
1406
+								foreach( $answers as $id => $answer ) {
1407
+									$answers_sorted[ $id ] = $answer;
1408
+								}
1409
+							}
1410
+						}
1411 1411
 
1412 1412
 						foreach( $answers_sorted as $id => $answer ) {
1413
-				    		$html .= $answer;
1414
-				    	}
1413
+							$html .= $answer;
1414
+						}
1415 1415
 
1416
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1417
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1418
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1416
+						$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1417
+						$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1418
+						$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1419 1419
 
1420
-				    	$html .= '<div class="add_answer_options">';
1421
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1422
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1423
-				    	$html .= '</div>';
1420
+						$html .= '<div class="add_answer_options">';
1421
+							$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1422
+							$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1423
+						$html .= '</div>';
1424 1424
 
1425
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1425
+						$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1426 1426
 
1427
-			    	$html .= '</div>';
1427
+					$html .= '</div>';
1428 1428
 				break;
1429 1429
 				case 'boolean':
1430 1430
 					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
@@ -1437,7 +1437,7 @@  discard block
 block discarded – undo
1437 1437
 						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1438 1438
 						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1439 1439
 
1440
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1440
+					$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1441 1441
 
1442 1442
 					$html .= '</div>';
1443 1443
 				break;
@@ -1512,17 +1512,17 @@  discard block
 block discarded – undo
1512 1512
 
1513 1513
 	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1514 1514
 
1515
-        // default field name
1516
-        $field_name = 'answer_feedback';
1517
-        if( 'boolean' == $question_type ){
1515
+		// default field name
1516
+		$field_name = 'answer_feedback';
1517
+		if( 'boolean' == $question_type ){
1518 1518
 
1519
-            $field_name = 'answer_feedback_boolean';
1519
+			$field_name = 'answer_feedback_boolean';
1520 1520
 
1521
-        }elseif( 'multiple-choice' == $question_type ){
1521
+		}elseif( 'multiple-choice' == $question_type ){
1522 1522
 
1523
-            $field_name = 'answer_feedback_multiple_choice';
1523
+			$field_name = 'answer_feedback_multiple_choice';
1524 1524
 
1525
-        }// end if
1525
+		}// end if
1526 1526
 
1527 1527
 		if( $question_counter ) {
1528 1528
 			$field_name = 'answer_' . $question_counter . '_feedback';
@@ -1727,15 +1727,15 @@  discard block
 block discarded – undo
1727 1727
 			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1728 1728
 
1729 1729
 			// Load the lessons script
1730
-            wp_enqueue_media();
1730
+			wp_enqueue_media();
1731 1731
 			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'sensei-core-select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1732 1732
 			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1733 1733
 			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1734 1734
 
1735
-            // Load the bulk edit screen script
1736
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1737
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1738
-            }
1735
+			// Load the bulk edit screen script
1736
+			if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1737
+				wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1738
+			}
1739 1739
 
1740 1740
 			// Localise script
1741 1741
 			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
@@ -1836,7 +1836,7 @@  discard block
 block discarded – undo
1836 1836
 			$nonce = esc_html( $_POST['lesson_add_course_nonce'] );
1837 1837
 		} // End If Statement
1838 1838
 		if ( ! wp_verify_nonce( $nonce, 'lesson_add_course_nonce' )
1839
-            || ! current_user_can( 'edit_lessons' ) ) {
1839
+			|| ! current_user_can( 'edit_lessons' ) ) {
1840 1840
 			die('');
1841 1841
 		} // End If Statement
1842 1842
 		// Parse POST data
@@ -1865,7 +1865,7 @@  discard block
 block discarded – undo
1865 1865
 			$nonce = esc_html( $_POST['lesson_update_question_nonce'] );
1866 1866
 		} // End If Statement
1867 1867
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_nonce' )
1868
-            ||  ! current_user_can( 'edit_questions' )) {
1868
+			||  ! current_user_can( 'edit_questions' )) {
1869 1869
 
1870 1870
 			die('');
1871 1871
 
@@ -1918,7 +1918,7 @@  discard block
 block discarded – undo
1918 1918
 		} // End If Statement
1919 1919
 
1920 1920
 		if( ! wp_verify_nonce( $nonce, 'lesson_add_multiple_questions_nonce' )
1921
-            || ! current_user_can( 'edit_lessons' ) ) {
1921
+			|| ! current_user_can( 'edit_lessons' ) ) {
1922 1922
 			die( $return );
1923 1923
 		} // End If Statement
1924 1924
 
@@ -1974,7 +1974,7 @@  discard block
 block discarded – undo
1974 1974
 		} // End If Statement
1975 1975
 
1976 1976
 		if( ! wp_verify_nonce( $nonce, 'lesson_remove_multiple_questions_nonce' )
1977
-        || ! current_user_can( 'edit_lessons' ) ) {
1977
+		|| ! current_user_can( 'edit_lessons' ) ) {
1978 1978
 			die('');
1979 1979
 		} // End If Statement
1980 1980
 
@@ -2021,7 +2021,7 @@  discard block
 block discarded – undo
2021 2021
 		} // End If Statement
2022 2022
 
2023 2023
 		if( ! wp_verify_nonce( $nonce, 'lesson_add_existing_questions_nonce' )
2024
-        || ! current_user_can( 'edit_lessons' ) ) {
2024
+		|| ! current_user_can( 'edit_lessons' ) ) {
2025 2025
 			die('');
2026 2026
 		} // End If Statement
2027 2027
 
@@ -2046,12 +2046,12 @@  discard block
 block discarded – undo
2046 2046
 
2047 2047
 					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2048 2048
 					if( ! in_array( $quiz_id, $quizzes ) ) {
2049
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2049
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2050 2050
 						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2051 2051
 						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2052
-			    	}
2052
+					}
2053 2053
 
2054
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2054
+					add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2055 2055
 					$question_type = Sensei()->question->get_question_type( $question_id );
2056 2056
 
2057 2057
 					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
@@ -2073,7 +2073,7 @@  discard block
 block discarded – undo
2073 2073
 		} // End If Statement
2074 2074
 
2075 2075
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_grade_type_nonce' )
2076
-        || ! current_user_can( 'edit_lessons' ) ) {
2076
+		|| ! current_user_can( 'edit_lessons' ) ) {
2077 2077
 
2078 2078
 			die('');
2079 2079
 
@@ -2093,8 +2093,8 @@  discard block
 block discarded – undo
2093 2093
 			$nonce = esc_html( $_POST['lesson_update_question_order_nonce'] );
2094 2094
 		} // End If Statement
2095 2095
 
2096
-        if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2097
-            ||! current_user_can( 'edit_lessons' ) ) {
2096
+		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2097
+			||! current_user_can( 'edit_lessons' ) ) {
2098 2098
 			die('');
2099 2099
 		} // End If Statement
2100 2100
 
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
 			$nonce = esc_html( $_POST['lesson_update_question_order_random_nonce'] );
2121 2121
 		} // End If Statement
2122 2122
 		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_random_nonce' )
2123
-            || ! current_user_can( 'edit_lessons' ) ) {
2123
+			|| ! current_user_can( 'edit_lessons' ) ) {
2124 2124
 
2125 2125
 			die('');
2126 2126
 
@@ -2170,34 +2170,34 @@  discard block
 block discarded – undo
2170 2170
 		$post_content = $course_content;
2171 2171
 		// Course Query Arguments
2172 2172
 		$post_type_args = array(	'post_content' => $post_content,
2173
-  		    						'post_status' => $post_status,
2174
-  		    						'post_title' => $post_title,
2175
-  		    						'post_type' => $post_type
2176
-  		    						);
2173
+  									'post_status' => $post_status,
2174
+  									'post_title' => $post_title,
2175
+  									'post_type' => $post_type
2176
+  									);
2177 2177
   		// Only save if there is a valid title
2178 2178
   		if ( $post_title != '' ) {
2179
-  		    // Check for prerequisite courses & product id
2180
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2181
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2182
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2183
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2184
-  		    // Insert or Update the Lesson Quiz
2185
-		    if ( 0 < $course_id ) {
2186
-		    	$post_type_args[ 'ID' ] = $course_id;
2187
-		    	$course_id = wp_update_post($post_type_args);
2188
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2189
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2190
-		    	if ( 0 < $course_category_id ) {
2191
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2192
-		    	} // End If Statement
2193
-		    } else {
2194
-		    	$course_id = wp_insert_post($post_type_args);
2195
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2196
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2197
-		    	if ( 0 < $course_category_id ) {
2198
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2199
-		    	} // End If Statement
2200
-		    } // End If Statement
2179
+  			// Check for prerequisite courses & product id
2180
+  			$course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2181
+  			$course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2182
+  			$course_category_id = absint( $data[ 'course_category' ] );
2183
+  			if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2184
+  			// Insert or Update the Lesson Quiz
2185
+			if ( 0 < $course_id ) {
2186
+				$post_type_args[ 'ID' ] = $course_id;
2187
+				$course_id = wp_update_post($post_type_args);
2188
+				update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2189
+				update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2190
+				if ( 0 < $course_category_id ) {
2191
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2192
+				} // End If Statement
2193
+			} else {
2194
+				$course_id = wp_insert_post($post_type_args);
2195
+				add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2196
+				add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2197
+				if ( 0 < $course_category_id ) {
2198
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2199
+				} // End If Statement
2200
+			} // End If Statement
2201 2201
 		} // End If Statement
2202 2202
   		// Check that the insert or update saved by testing the post id
2203 2203
   		if ( 0 < $course_id ) {
@@ -2288,17 +2288,17 @@  discard block
 block discarded – undo
2288 2288
 		$answer_feedback = '';
2289 2289
 		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2290 2290
 
2291
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2291
+			$answer_feedback = $data[ 'answer_feedback_boolean' ];
2292 2292
 
2293 2293
 		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2294 2294
 
2295
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2295
+			$answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2296 2296
 
2297
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2297
+		}elseif( isset( $data[ 'answer_feedback' ] )  ){
2298 2298
 
2299
-            $answer_feedback = $data[ 'answer_feedback' ];
2299
+			$answer_feedback = $data[ 'answer_feedback' ];
2300 2300
 
2301
-        } // End If Statement
2301
+		} // End If Statement
2302 2302
 
2303 2303
 		$post_title = $question_text;
2304 2304
 		$post_author = $data[ 'post_author' ];
@@ -2313,10 +2313,10 @@  discard block
 block discarded – undo
2313 2313
 		}
2314 2314
 		// Question Query Arguments
2315 2315
 		$post_type_args = array(	'post_content' => $post_content,
2316
-  		    						'post_status' => $post_status,
2317
-  		    						'post_title' => $post_title,
2318
-  		    						'post_type' => $post_type
2319
-  		    						);
2316
+  									'post_status' => $post_status,
2317
+  									'post_title' => $post_title,
2318
+  									'post_type' => $post_type
2319
+  									);
2320 2320
 
2321 2321
   		// Remove empty values and reindex the array
2322 2322
   		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
@@ -2352,14 +2352,14 @@  discard block
 block discarded – undo
2352 2352
   		if ( $post_title != '' ) {
2353 2353
 
2354 2354
   			// Get Quiz ID for the question
2355
-  		    $quiz_id = $data['quiz_id'];
2355
+  			$quiz_id = $data['quiz_id'];
2356 2356
 
2357
-  		    // Get question media
2357
+  			// Get question media
2358 2358
 			$question_media = $data['question_media'];
2359 2359
 
2360
-  		    // Get answer order
2361
-  		    $answer_order = '';
2362
-  		    if( isset( $data['answer_order'] ) ) {
2360
+  			// Get answer order
2361
+  			$answer_order = '';
2362
+  			if( isset( $data['answer_order'] ) ) {
2363 2363
 				$answer_order = $data['answer_order'];
2364 2364
 			}
2365 2365
 
@@ -2369,38 +2369,38 @@  discard block
 block discarded – undo
2369 2369
 				$random_order = $data['random_order'];
2370 2370
 			}
2371 2371
 
2372
-  		    // Insert or Update the question
2373
-  		    if ( 0 < $question_id ) {
2374
-
2375
-  		    	$post_type_args[ 'ID' ] = $question_id;
2376
-		    	$question_id = wp_update_post( $post_type_args );
2377
-
2378
-		    	// Update poast meta
2379
-		    	if( 'quiz' == $context ) {
2380
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2381
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2382
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2383
-			    	}
2384
-		    	}
2385
-
2386
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2387
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2388
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2389
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2390
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2391
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2392
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2393
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2394
-
2395
-		    	if( 'quiz' != $context ) {
2396
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2397
-		    	}
2372
+  			// Insert or Update the question
2373
+  			if ( 0 < $question_id ) {
2374
+
2375
+  				$post_type_args[ 'ID' ] = $question_id;
2376
+				$question_id = wp_update_post( $post_type_args );
2377
+
2378
+				// Update poast meta
2379
+				if( 'quiz' == $context ) {
2380
+					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2381
+					if( ! in_array( $quiz_id, $quizzes ) ) {
2382
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2383
+					}
2384
+				}
2385
+
2386
+				update_post_meta( $question_id, '_question_grade', $question_grade );
2387
+				update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2388
+				update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2389
+				update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2390
+				update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2391
+				update_post_meta( $question_id, '_question_media', $question_media );
2392
+				update_post_meta( $question_id, '_answer_order', $answer_order );
2393
+				update_post_meta( $question_id, '_random_order', $random_order );
2394
+
2395
+				if( 'quiz' != $context ) {
2396
+					wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2397
+				}
2398 2398
 				// Don't store empty value, no point
2399 2399
 				if ( !empty($answer_feedback) ) {
2400 2400
 					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2401 2401
 				}
2402 2402
 
2403
-		    } else {
2403
+			} else {
2404 2404
 				$question_id = wp_insert_post( $post_type_args );
2405 2405
 				$question_count = intval( $data['question_count'] );
2406 2406
 				++$question_count;
@@ -2413,29 +2413,29 @@  discard block
 block discarded – undo
2413 2413
 				}
2414 2414
 
2415 2415
 				if( isset( $question_grade ) ) {
2416
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2417
-		    	}
2418
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2419
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2420
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2421
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2422
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2423
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2424
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2425
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2416
+					add_post_meta( $question_id, '_question_grade', $question_grade );
2417
+				}
2418
+				add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2419
+				add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2420
+				add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2421
+				add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2422
+				add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2423
+				add_post_meta( $question_id, '_question_media', $question_media );
2424
+				add_post_meta( $question_id, '_answer_order', $answer_order );
2425
+				add_post_meta( $question_id, '_random_order', $random_order );
2426 2426
 				// Don't store empty value, no point
2427 2427
 				if ( !empty($answer_feedback) ) {
2428 2428
 					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2429 2429
 				}
2430 2430
 
2431
-		    	// Set the post terms for question-type
2432
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2431
+				// Set the post terms for question-type
2432
+				wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2433 2433
 
2434
-			    if( $question_category ) {
2435
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2436
-	    		}
2434
+				if( $question_category ) {
2435
+					wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2436
+				}
2437 2437
 
2438
-		    } // End If Statement
2438
+			} // End If Statement
2439 2439
 		} // End If Statement
2440 2440
   		// Check that the insert or update saved by testing the post id
2441 2441
   		if ( 0 < $question_id ) {
@@ -2484,7 +2484,7 @@  discard block
 block discarded – undo
2484 2484
 	public function lesson_complexities() {
2485 2485
 
2486 2486
 		// V2 - make filter for this array
2487
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2487
+		$lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2488 2488
 									'std' => __( 'Standard', 'woothemes-sensei' ),
2489 2489
 									'hard' => __( 'Hard', 'woothemes-sensei' )
2490 2490
 									);
@@ -2551,14 +2551,14 @@  discard block
 block discarded – undo
2551 2551
 		$post_args = array(	'post_type' 		=> 'quiz',
2552 2552
 							'posts_per_page' 		=> 1,
2553 2553
 							'orderby'         	=> 'title',
2554
-    						'order'           	=> 'DESC',
2555
-    						'post_parent'      	=> $lesson_id,
2556
-    						'post_status'		=> $post_status,
2554
+							'order'           	=> 'DESC',
2555
+							'post_parent'      	=> $lesson_id,
2556
+							'post_status'		=> $post_status,
2557 2557
 							'suppress_filters' 	=> 0,
2558 2558
 							'fields'            => $fields
2559 2559
 							);
2560 2560
 		$posts_array = get_posts( $post_args );
2561
-        $quiz_id = array_shift($posts_array);
2561
+		$quiz_id = array_shift($posts_array);
2562 2562
 
2563 2563
 		return $quiz_id;
2564 2564
 	} // End lesson_quizzes()
@@ -2566,34 +2566,34 @@  discard block
 block discarded – undo
2566 2566
 
2567 2567
 	/**
2568 2568
 	 * Fetches all the questions for a quiz depending on certain conditions.
2569
-     *
2570
-     * Determine which questions should be shown depending on:
2571
-     * - admin/teacher selected questions to be shown
2572
-     * - questions shown to a user previously (saved as asked questions)
2573
-     * - limit number of questions lesson setting
2574 2569
 	 *
2575
-     * @since 1.0
2570
+	 * Determine which questions should be shown depending on:
2571
+	 * - admin/teacher selected questions to be shown
2572
+	 * - questions shown to a user previously (saved as asked questions)
2573
+	 * - limit number of questions lesson setting
2574
+	 *
2575
+	 * @since 1.0
2576 2576
 	 * @param int $quiz_id (default: 0)
2577 2577
 	 * @param string $post_status (default: 'publish')
2578 2578
 	 * @param string $orderby (default: 'meta_value_num title')
2579 2579
 	 * @param string $order (default: 'ASC')
2580
-     *
2580
+	 *
2581 2581
 	 * @return array $questions { $question type WP_Post }
2582 2582
 	 */
2583 2583
 	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2584 2584
 
2585 2585
 		$quiz_id = (string) $quiz_id;
2586
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2586
+		$quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2587 2587
 
2588
-        // setup the user id
2589
-        if( is_admin() ) {
2590
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2591
-        } else {
2592
-            $user_id = get_current_user_id();
2593
-        }
2588
+		// setup the user id
2589
+		if( is_admin() ) {
2590
+			$user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2591
+		} else {
2592
+			$user_id = get_current_user_id();
2593
+		}
2594 2594
 
2595
-        // get the users current status on the lesson
2596
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2595
+		// get the users current status on the lesson
2596
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2597 2597
 
2598 2598
 		// Set the default question order if it has not already been set for this quiz
2599 2599
 		$this->set_default_question_order( $quiz_id );
@@ -2623,14 +2623,14 @@  discard block
 block discarded – undo
2623 2623
 			'suppress_filters' 	=> 0
2624 2624
 		);
2625 2625
 
2626
-        //query the questions
2626
+		//query the questions
2627 2627
 		$questions_query = new WP_Query( $question_query_args );
2628 2628
 
2629
-        // Set return array to initially include all items
2630
-        $questions = $questions_query->posts;
2629
+		// Set return array to initially include all items
2630
+		$questions = $questions_query->posts;
2631 2631
 
2632
-        // set the questions array that will be manipulated within this function
2633
-        $questions_array = $questions_query->posts;
2632
+		// set the questions array that will be manipulated within this function
2633
+		$questions_array = $questions_query->posts;
2634 2634
 
2635 2635
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2636 2636
 		$selected_questions = false;
@@ -2743,36 +2743,36 @@  discard block
 block discarded – undo
2743 2743
 			}
2744 2744
 		}
2745 2745
 
2746
-        // Save the questions that will be asked for the current user
2747
-        // this happens only once per user/quiz, unless the user resets the quiz
2748
-        if( ! is_admin() ){
2746
+		// Save the questions that will be asked for the current user
2747
+		// this happens only once per user/quiz, unless the user resets the quiz
2748
+		if( ! is_admin() ){
2749 2749
 
2750
-            if( $user_lesson_status ) {
2750
+			if( $user_lesson_status ) {
2751 2751
 
2752
-                $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2753
-                if ( empty($questions_asked) && $user_lesson_status) {
2752
+				$questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2753
+				if ( empty($questions_asked) && $user_lesson_status) {
2754 2754
 
2755
-                    $questions_asked = array();
2756
-                    foreach ($questions as $question) {
2755
+					$questions_asked = array();
2756
+					foreach ($questions as $question) {
2757 2757
 
2758
-                        $questions_asked[] = $question->ID;
2758
+						$questions_asked[] = $question->ID;
2759 2759
 
2760
-                    }
2760
+					}
2761 2761
 
2762
-                    // save the questions asked id
2763
-                    $questions_asked_csv = implode(',', $questions_asked);
2764
-                    update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2762
+					// save the questions asked id
2763
+					$questions_asked_csv = implode(',', $questions_asked);
2764
+					update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2765 2765
 
2766
-                }
2767
-            }
2768
-        }
2766
+				}
2767
+			}
2768
+		}
2769 2769
 
2770
-        /**
2771
-         * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2772
-         *
2773
-         * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2774
-         * @since 1.8.0
2775
-         */
2770
+		/**
2771
+		 * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2772
+		 *
2773
+		 * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2774
+		 * @since 1.8.0
2775
+		 */
2776 2776
 		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2777 2777
 
2778 2778
 	} // End lesson_quiz_questions()
@@ -2876,7 +2876,7 @@  discard block
 block discarded – undo
2876 2876
  			// Display Image Placeholder if none
2877 2877
 			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2878 2878
              
2879
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
2879
+				$img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
2880 2880
 
2881 2881
 			} // End If Statement
2882 2882
 
@@ -2888,418 +2888,418 @@  discard block
 block discarded – undo
2888 2888
 
2889 2889
 	} // End lesson_image()
2890 2890
 
2891
-    /**
2892
-     * Ooutpu the lesson image
2893
-     *
2894
-     * @since 1.9.0
2895
-     * @param integer $lesson_id
2896
-     */
2897
-    public static function the_lesson_image( $lesson_id = 0 ){
2891
+	/**
2892
+	 * Ooutpu the lesson image
2893
+	 *
2894
+	 * @since 1.9.0
2895
+	 * @param integer $lesson_id
2896
+	 */
2897
+	public static function the_lesson_image( $lesson_id = 0 ){
2898 2898
 
2899
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2899
+		echo Sensei()->lesson->lesson_image( $lesson_id );
2900 2900
 
2901
-    }
2901
+	}
2902 2902
 
2903 2903
 	/**
2904 2904
 	 * Returns the the lesson excerpt.
2905 2905
 	 *
2906 2906
 	 * @param WP_Post $lesson
2907
-     * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2907
+	 * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2908 2908
 	 * @return string
2909 2909
 	 */
2910 2910
 	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2911 2911
 		$html = '';
2912 2912
 		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2913 2913
 
2914
-            $excerpt =  $lesson->post_excerpt;
2914
+			$excerpt =  $lesson->post_excerpt;
2915 2915
 
2916
-            // if $add_p_tags true wrap with <p> else return the excerpt as is
2917
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2916
+			// if $add_p_tags true wrap with <p> else return the excerpt as is
2917
+			$html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2918 2918
 
2919 2919
 		}
2920 2920
 		return apply_filters( 'sensei_lesson_excerpt', $html );
2921 2921
 
2922 2922
 	} // End lesson_excerpt()
2923 2923
 
2924
-    /**
2925
-     * Returns the course for a given lesson
2926
-     *
2927
-     * @since 1.7.4
2928
-     * @access public
2929
-     *
2930
-     * @param int $lesson_id
2931
-     * @return int|bool $course_id or bool when nothing is found.
2932
-     */
2933
-     public function get_course_id( $lesson_id ){
2934
-
2935
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2936
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2937
-             return false;
2938
-         }
2939
-
2940
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2941
-
2942
-         // make sure the course id is valid
2943
-         if( empty( $lesson_course_id )
2944
-             || is_array( $lesson_course_id )
2945
-             || intval( $lesson_course_id ) < 1
2946
-             || 'course' != get_post_type( $lesson_course_id ) ){
2947
-
2948
-             return false;
2949
-
2950
-         }
2951
-
2952
-         return $lesson_course_id;
2953
-
2954
-     }// en get_course_id
2955
-
2956
-    /**
2957
-     * Add the admin all lessons screen edit options.
2958
-     *
2959
-     * The fields in this function work for both quick and bulk edit. The ID attributes is used
2960
-     * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2961
-     * name attribute is will be used by the quick edit and submitted via standard POST. This
2962
-     * will use this classes save_post_meta function to save the new field data.
2963
-     *
2964
-     * @hooked quick_edit_custom_box
2965
-     * @hooked bulk_edit_custom_box
2966
-     *
2967
-     * @since 1.8.0
2968
-     *
2969
-     * @param string $column_name
2970
-     * @param string $post_type
2971
-     * @return void
2972
-     */
2973
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2974
-
2975
-        // only show these options ont he lesson post type edit screen
2976
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name
2977
-            || ! current_user_can( 'edit_lessons' ) ) {
2978
-            return;
2979
-        }
2980
-
2981
-        ?>
2924
+	/**
2925
+	 * Returns the course for a given lesson
2926
+	 *
2927
+	 * @since 1.7.4
2928
+	 * @access public
2929
+	 *
2930
+	 * @param int $lesson_id
2931
+	 * @return int|bool $course_id or bool when nothing is found.
2932
+	 */
2933
+	 public function get_course_id( $lesson_id ){
2934
+
2935
+		 if( ! isset( $lesson_id ) || empty( $lesson_id )
2936
+		 ||  'lesson' != get_post_type( $lesson_id ) ){
2937
+			 return false;
2938
+		 }
2939
+
2940
+		 $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2941
+
2942
+		 // make sure the course id is valid
2943
+		 if( empty( $lesson_course_id )
2944
+			 || is_array( $lesson_course_id )
2945
+			 || intval( $lesson_course_id ) < 1
2946
+			 || 'course' != get_post_type( $lesson_course_id ) ){
2947
+
2948
+			 return false;
2949
+
2950
+		 }
2951
+
2952
+		 return $lesson_course_id;
2953
+
2954
+	 }// en get_course_id
2955
+
2956
+	/**
2957
+	 * Add the admin all lessons screen edit options.
2958
+	 *
2959
+	 * The fields in this function work for both quick and bulk edit. The ID attributes is used
2960
+	 * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2961
+	 * name attribute is will be used by the quick edit and submitted via standard POST. This
2962
+	 * will use this classes save_post_meta function to save the new field data.
2963
+	 *
2964
+	 * @hooked quick_edit_custom_box
2965
+	 * @hooked bulk_edit_custom_box
2966
+	 *
2967
+	 * @since 1.8.0
2968
+	 *
2969
+	 * @param string $column_name
2970
+	 * @param string $post_type
2971
+	 * @return void
2972
+	 */
2973
+	public function all_lessons_edit_fields( $column_name, $post_type ) {
2974
+
2975
+		// only show these options ont he lesson post type edit screen
2976
+		if( 'lesson' != $post_type || 'lesson-course' != $column_name
2977
+			|| ! current_user_can( 'edit_lessons' ) ) {
2978
+			return;
2979
+		}
2980
+
2981
+		?>
2982 2982
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2983 2983
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2984 2984
                     <?php
2985
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2986
-                    // create a nonce field to be  used as a security measure when saving the data
2987
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2988
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2989
-
2990
-                    // unchanged option - we need this in because
2991
-                    // the default option in bulk edit should not be empty. If it is
2992
-                    // the user will erase data they didn't want to touch.
2993
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2994
-
2995
-                    //
2996
-                    //course selection
2997
-                    //
2998
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2999
-                    $course_options = array();
3000
-                    if ( count( $courses ) > 0 ) {
3001
-                        foreach ($courses as $course ){
3002
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
3003
-                        }
3004
-                    }
3005
-                    //pre-append the no change option
3006
-                    $course_options['-1']=  $no_change_text;
3007
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
3008
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3009
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3010
-
3011
-                    //
3012
-                    // lesson complexity selection
3013
-                    //
3014
-                    $lesson_complexities =  $this->lesson_complexities();
3015
-                    //pre-append the no change option
3016
-                    $lesson_complexities['-1']=  $no_change_text;
3017
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3018
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3019
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3020
-
3021
-                    ?>
2985
+					echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2986
+					// create a nonce field to be  used as a security measure when saving the data
2987
+					wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2988
+					wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2989
+
2990
+					// unchanged option - we need this in because
2991
+					// the default option in bulk edit should not be empty. If it is
2992
+					// the user will erase data they didn't want to touch.
2993
+					$no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2994
+
2995
+					//
2996
+					//course selection
2997
+					//
2998
+					$courses =  WooThemes_Sensei_Course::get_all_courses();
2999
+					$course_options = array();
3000
+					if ( count( $courses ) > 0 ) {
3001
+						foreach ($courses as $course ){
3002
+							$course_options[ $course->ID ] = get_the_title( $course->ID );
3003
+						}
3004
+					}
3005
+					//pre-append the no change option
3006
+					$course_options['-1']=  $no_change_text;
3007
+					$course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
3008
+					$course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3009
+					echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3010
+
3011
+					//
3012
+					// lesson complexity selection
3013
+					//
3014
+					$lesson_complexities =  $this->lesson_complexities();
3015
+					//pre-append the no change option
3016
+					$lesson_complexities['-1']=  $no_change_text;
3017
+					$complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3018
+					$complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3019
+					echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3020
+
3021
+					?>
3022 3022
 
3023 3023
                     <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4>
3024 3024
 
3025 3025
                     <?php
3026 3026
 
3027
-                    //
3028
-                    // Lesson require pass to complete
3029
-                    //
3030
-                    $pass_required_options = array(
3031
-                        '-1' => $no_change_text,
3032
-                         '0' => __('No','woothemes'),
3033
-                         '1' => __('Yes','woothemes'),
3034
-                    );
3035
-
3036
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3037
-                                                                'id'=> 'sensei-edit-lesson-pass-required',
3038
-                                                                'class'=>' '   );
3039
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3040
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3041
-
3042
-                    //
3043
-                    // Quiz pass percentage
3044
-                    //
3045
-                    $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3046
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3047
-
3048
-                    //
3049
-                    // Enable quiz reset button
3050
-                    //
3051
-                    $quiz_reset_select__options = array(
3052
-                        '-1' => $no_change_text,
3053
-                        '0' => __('No','woothemes'),
3054
-                        '1' => __('Yes','woothemes'),
3055
-                    );
3056
-                    $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3057
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3058
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3059
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3060
-
3061
-                    ?>
3027
+					//
3028
+					// Lesson require pass to complete
3029
+					//
3030
+					$pass_required_options = array(
3031
+						'-1' => $no_change_text,
3032
+						 '0' => __('No','woothemes'),
3033
+						 '1' => __('Yes','woothemes'),
3034
+					);
3035
+
3036
+					$pass_required_select_attributes = array( 'name'=> 'pass_required',
3037
+																'id'=> 'sensei-edit-lesson-pass-required',
3038
+																'class'=>' '   );
3039
+					$require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3040
+					echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3041
+
3042
+					//
3043
+					// Quiz pass percentage
3044
+					//
3045
+					$quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3046
+					echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3047
+
3048
+					//
3049
+					// Enable quiz reset button
3050
+					//
3051
+					$quiz_reset_select__options = array(
3052
+						'-1' => $no_change_text,
3053
+						'0' => __('No','woothemes'),
3054
+						'1' => __('Yes','woothemes'),
3055
+					);
3056
+					$quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3057
+					$quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3058
+					$quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3059
+					echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3060
+
3061
+					?>
3062 3062
             </div>
3063 3063
         </fieldset>
3064 3064
     <?php
3065
-    }// all_lessons_edit_fields
3066
-
3067
-    /**
3068
-     * Create the html for the edit field
3069
-     *
3070
-     * Wraps the passed in field and title combination with the correct html.
3071
-     *
3072
-     * @since 1.8.0
3073
-     *
3074
-     * @param string $title that will stand to the left of the field.
3075
-     * @param string $field type markup for the field that must be wrapped.
3076
-     * @return string $field_html
3077
-     */
3078
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3079
-
3080
-        $html = '';
3081
-        $html = '<div class="inline-edit-group" >';
3082
-        $html .=  '<span class="title">'. $title .'</span> ';
3083
-        $html .= '<span class="input-text-wrap">';
3084
-        $html .= $field;
3085
-        $html .= '</span>';
3086
-        $html .= '</label></div>';
3087
-
3088
-        return $html ;
3089
-
3090
-    }//end generate_all_lessons_edit_field
3091
-
3092
-    /**
3093
-     * Respond to the ajax call from the bulk edit save function. This comes
3094
-     * from the admin all lesson screen.
3095
-     *
3096
-     * @since 1.8.0
3097
-     * @return void
3098
-     */
3099
-    function save_all_lessons_edit_fields() {
3100
-
3101
-        // verify all the data before attempting to save
3102
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3103
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3104
-            die();
3105
-        }
3106
-
3107
-        // get our variables
3108
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3109
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3110
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3111
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3112
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3113
-        // store the values for all selected posts
3114
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3115
-
3116
-            // get the quiz id needed for the quiz meta
3117
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3118
-
3119
-            // do not save the items if the value is -1 as this
3120
-            // means it was not changed
3121
-
3122
-            // update lesson course
3123
-            if( -1 != $new_course ){
3124
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3125
-            }
3126
-            // update lesson complexity
3127
-            if( -1 != $new_complexity ){
3128
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3129
-            }
3130
-
3131
-            // Quiz Related settings
3132
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3133
-
3134
-                // update pass required
3135
-                if (-1 != $new_pass_required) {
3136
-
3137
-                    $checked = $new_pass_required  ? 'on' : '';
3138
-                    update_post_meta($quiz_id, '_pass_required', $checked);
3139
-                    unset( $checked );
3140
-                }
3065
+	}// all_lessons_edit_fields
3141 3066
 
3142
-                // update pass percentage
3143
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3067
+	/**
3068
+	 * Create the html for the edit field
3069
+	 *
3070
+	 * Wraps the passed in field and title combination with the correct html.
3071
+	 *
3072
+	 * @since 1.8.0
3073
+	 *
3074
+	 * @param string $title that will stand to the left of the field.
3075
+	 * @param string $field type markup for the field that must be wrapped.
3076
+	 * @return string $field_html
3077
+	 */
3078
+	public function generate_all_lessons_edit_field( $title  ,$field ){
3144 3079
 
3145
-                        update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3080
+		$html = '';
3081
+		$html = '<div class="inline-edit-group" >';
3082
+		$html .=  '<span class="title">'. $title .'</span> ';
3083
+		$html .= '<span class="input-text-wrap">';
3084
+		$html .= $field;
3085
+		$html .= '</span>';
3086
+		$html .= '</label></div>';
3146 3087
 
3147
-                }
3088
+		return $html ;
3148 3089
 
3149
-                //
3150
-                // update enable quiz reset
3151
-                //
3152
-                if (-1 != $new_enable_quiz_reset ) {
3090
+	}//end generate_all_lessons_edit_field
3153 3091
 
3154
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3155
-                    update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3156
-                    unset( $checked );
3092
+	/**
3093
+	 * Respond to the ajax call from the bulk edit save function. This comes
3094
+	 * from the admin all lesson screen.
3095
+	 *
3096
+	 * @since 1.8.0
3097
+	 * @return void
3098
+	 */
3099
+	function save_all_lessons_edit_fields() {
3157 3100
 
3158
-                }
3101
+		// verify all the data before attempting to save
3102
+		if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3103
+			||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3104
+			die();
3105
+		}
3159 3106
 
3107
+		// get our variables
3108
+		$new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3109
+		$new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3110
+		$new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3111
+		$new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3112
+		$new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3113
+		// store the values for all selected posts
3114
+		foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3160 3115
 
3161
-            } // end if quiz
3116
+			// get the quiz id needed for the quiz meta
3117
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3162 3118
 
3163
-        }// end for each
3119
+			// do not save the items if the value is -1 as this
3120
+			// means it was not changed
3164 3121
 
3165
-        die();
3122
+			// update lesson course
3123
+			if( -1 != $new_course ){
3124
+				update_post_meta( $lesson_id, '_lesson_course', $new_course );
3125
+			}
3126
+			// update lesson complexity
3127
+			if( -1 != $new_complexity ){
3128
+				update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3129
+			}
3166 3130
 
3167
-    } // end save_all_lessons_edit_fields
3131
+			// Quiz Related settings
3132
+			if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3168 3133
 
3169
-    /**
3170
-     * Loading the quick edit fields defaults.
3171
-     *
3172
-     * This function will localise the default values along with the script that will
3173
-     * add these values to the inputs.
3174
-     *
3175
-     * NOTE: this function runs for each row in the edit column
3176
-     *
3177
-     * @since 1.8.0
3178
-     * @return void
3179
-     */
3180
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3134
+				// update pass required
3135
+				if (-1 != $new_pass_required) {
3181 3136
 
3182
-        if( 'lesson-course' != $column_name ){
3183
-            return;
3184
-        }
3185
-        // load the script
3186
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3137
+					$checked = $new_pass_required  ? 'on' : '';
3138
+					update_post_meta($quiz_id, '_pass_required', $checked);
3139
+					unset( $checked );
3140
+				}
3188 3141
 
3189
-        // setup the values for all meta fields
3190
-        $data = array();
3191
-        foreach( $this->meta_fields as $field ){
3142
+				// update pass percentage
3143
+				if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3192 3144
 
3193
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3145
+						update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3194 3146
 
3195
-        }
3196
-        // add quiz meta fields
3197
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3198
-        foreach( Sensei()->quiz->meta_fields as $field ){
3147
+				}
3199 3148
 
3200
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3149
+				//
3150
+				// update enable quiz reset
3151
+				//
3152
+				if (-1 != $new_enable_quiz_reset ) {
3201 3153
 
3202
-        }
3154
+					$checked = $new_enable_quiz_reset ? 'on' : ''  ;
3155
+					update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3156
+					unset( $checked );
3203 3157
 
3204
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3158
+				}
3159
+
3160
+
3161
+			} // end if quiz
3162
+
3163
+		}// end for each
3164
+
3165
+		die();
3166
+
3167
+	} // end save_all_lessons_edit_fields
3168
+
3169
+	/**
3170
+	 * Loading the quick edit fields defaults.
3171
+	 *
3172
+	 * This function will localise the default values along with the script that will
3173
+	 * add these values to the inputs.
3174
+	 *
3175
+	 * NOTE: this function runs for each row in the edit column
3176
+	 *
3177
+	 * @since 1.8.0
3178
+	 * @return void
3179
+	 */
3180
+	public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3181
+
3182
+		if( 'lesson-course' != $column_name ){
3183
+			return;
3184
+		}
3185
+		// load the script
3186
+		$suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
+		wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3188
+
3189
+		// setup the values for all meta fields
3190
+		$data = array();
3191
+		foreach( $this->meta_fields as $field ){
3205 3192
 
3206
-    }// end quick edit admin defaults
3193
+			$data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3207 3194
 
3208
-    /**
3209
-     * Filter the classes for lessons on the single course page.
3210
-     *
3211
-     * Adds the nesecary classes depending on the user data
3212
-     *
3213
-     * @since 1.9.0
3214
-     * @param array $classes
3215
-     * @return array $classes
3216
-     */
3217
-    public static function single_course_lessons_classes( $classes ){
3195
+		}
3196
+		// add quiz meta fields
3197
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3198
+		foreach( Sensei()->quiz->meta_fields as $field ){
3218 3199
 
3219
-        if(  is_singular('course') ){
3200
+			$data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3220 3201
 
3221
-            global $post;
3222
-            $course_id = $post->ID;
3202
+		}
3223 3203
 
3224
-            $lesson_classes = array( 'course', 'post' );
3225
-            if ( is_user_logged_in() ) {
3204
+		wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3226 3205
 
3227
-                // Check if Lesson is complete
3228
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3229
-                if ( $single_lesson_complete ) {
3206
+	}// end quick edit admin defaults
3230 3207
 
3231
-                    $lesson_classes[] = 'lesson-completed';
3208
+	/**
3209
+	 * Filter the classes for lessons on the single course page.
3210
+	 *
3211
+	 * Adds the nesecary classes depending on the user data
3212
+	 *
3213
+	 * @since 1.9.0
3214
+	 * @param array $classes
3215
+	 * @return array $classes
3216
+	 */
3217
+	public static function single_course_lessons_classes( $classes ){
3232 3218
 
3233
-                } // End If Statement
3219
+		if(  is_singular('course') ){
3234 3220
 
3235
-            } // End If Statement
3221
+			global $post;
3222
+			$course_id = $post->ID;
3236 3223
 
3237
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3238
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3224
+			$lesson_classes = array( 'course', 'post' );
3225
+			if ( is_user_logged_in() ) {
3239 3226
 
3240
-                $lesson_classes[] = 'lesson-preview';
3227
+				// Check if Lesson is complete
3228
+				$single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3229
+				if ( $single_lesson_complete ) {
3241 3230
 
3242
-            }
3231
+					$lesson_classes[] = 'lesson-completed';
3243 3232
 
3244
-            $classes = array_merge( $classes, $lesson_classes  );
3233
+				} // End If Statement
3245 3234
 
3246
-        }
3235
+			} // End If Statement
3247 3236
 
3248
-        return $classes;
3237
+			$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3238
+			if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3249 3239
 
3250
-    }// end single_course_lessons_classes
3240
+				$lesson_classes[] = 'lesson-preview';
3251 3241
 
3252
-    /**
3253
-     * Output the lesson meta for the given lesson
3254
-     *
3255
-     * @since 1.9.0
3256
-     * @param $lesson_id
3257
-     */
3258
-    public static function the_lesson_meta( $lesson_id ){
3242
+			}
3243
+
3244
+			$classes = array_merge( $classes, $lesson_classes  );
3245
+
3246
+		}
3247
+
3248
+		return $classes;
3249
+
3250
+	}// end single_course_lessons_classes
3251
+
3252
+	/**
3253
+	 * Output the lesson meta for the given lesson
3254
+	 *
3255
+	 * @since 1.9.0
3256
+	 * @param $lesson_id
3257
+	 */
3258
+	public static function the_lesson_meta( $lesson_id ){
3259 3259
 
3260
-        global $wp_query;
3261
-        $loop_lesson_number = $wp_query->current_post + 1;
3260
+		global $wp_query;
3261
+		$loop_lesson_number = $wp_query->current_post + 1;
3262 3262
 
3263
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3264
-        $single_lesson_complete = false;
3265
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3263
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
3264
+		$single_lesson_complete = false;
3265
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3266 3266
 
3267
-        // Get Lesson data
3268
-        $complexity_array = Sensei()->lesson->lesson_complexities();
3267
+		// Get Lesson data
3268
+		$complexity_array = Sensei()->lesson->lesson_complexities();
3269 3269
 
3270
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3271
-        if ( '' != $lesson_complexity ) {
3270
+		$lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3271
+		if ( '' != $lesson_complexity ) {
3272 3272
 
3273
-            $lesson_complexity = $complexity_array[$lesson_complexity];
3273
+			$lesson_complexity = $complexity_array[$lesson_complexity];
3274 3274
 
3275
-        }
3276
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3277
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3278
-        $preview_label = '';
3279
-        if ( $is_preview && !$is_user_taking_course ) {
3275
+		}
3276
+		$user_info = get_userdata( absint( get_post()->post_author ) );
3277
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3278
+		$preview_label = '';
3279
+		if ( $is_preview && !$is_user_taking_course ) {
3280 3280
 
3281
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3282
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3281
+			$preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3282
+			$preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3283 3283
 
3284
-        }
3284
+		}
3285 3285
 
3286 3286
 
3287
-        $count_markup= '';
3288
-        /**
3289
-         * Filter for if you want the $lesson_count to show next to the lesson.
3290
-         *
3291
-         * @since 1.0
3292
-         * @param bool default false.
3293
-         */
3294
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3287
+		$count_markup= '';
3288
+		/**
3289
+		 * Filter for if you want the $lesson_count to show next to the lesson.
3290
+		 *
3291
+		 * @since 1.0
3292
+		 * @param bool default false.
3293
+		 */
3294
+		if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3295 3295
 
3296
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3296
+			$count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3297 3297
 
3298
-        }
3298
+		}
3299 3299
 
3300
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3300
+		$heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3301 3301
 
3302
-        ?>
3302
+		?>
3303 3303
         <header>
3304 3304
             <h2>
3305 3305
                 <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
@@ -3312,40 +3312,40 @@  discard block
 block discarded – undo
3312 3312
 
3313 3313
                 <?php
3314 3314
 
3315
-                $meta_html = '';
3316
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3315
+				$meta_html = '';
3316
+				$user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3317 3317
 
3318
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3319
-                if ( '' != $lesson_length ) {
3318
+				$lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3319
+				if ( '' != $lesson_length ) {
3320 3320
 
3321
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3321
+					$meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3322 3322
 
3323
-                }
3323
+				}
3324 3324
 
3325
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3325
+				if ( Sensei()->settings->get( 'lesson_author' ) ) {
3326 3326
 
3327
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3327
+					$meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3328 3328
 
3329
-                } // End If Statement
3330
-                if ( '' != $lesson_complexity ) {
3329
+				} // End If Statement
3330
+				if ( '' != $lesson_complexity ) {
3331 3331
 
3332
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3332
+					$meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3333 3333
 
3334
-                }
3334
+				}
3335 3335
 
3336
-                if ( $single_lesson_complete ) {
3336
+				if ( $single_lesson_complete ) {
3337 3337
 
3338
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3338
+					$meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3339 3339
 
3340
-                } elseif ( $user_lesson_status ) {
3340
+				} elseif ( $user_lesson_status ) {
3341 3341
 
3342
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3342
+					$meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3343 3343
 
3344
-                } // End If Statement
3344
+				} // End If Statement
3345 3345
 
3346
-                echo $meta_html;
3346
+				echo $meta_html;
3347 3347
 
3348
-                ?>
3348
+				?>
3349 3349
 
3350 3350
             </p> <!-- lesson meta -->
3351 3351
 
@@ -3353,192 +3353,192 @@  discard block
 block discarded – undo
3353 3353
 
3354 3354
     <?php
3355 3355
 
3356
-    } // end the_lesson_meta
3356
+	} // end the_lesson_meta
3357 3357
 
3358
-    /**
3359
-     * Output the lessons thumbnail
3360
-     *
3361
-     * 1.9.0
3362
-     *
3363
-     * @param $lesson_id
3364
-     */
3365
-    public static function the_lesson_thumbnail( $lesson_id ){
3358
+	/**
3359
+	 * Output the lessons thumbnail
3360
+	 *
3361
+	 * 1.9.0
3362
+	 *
3363
+	 * @param $lesson_id
3364
+	 */
3365
+	public static function the_lesson_thumbnail( $lesson_id ){
3366 3366
 
3367
-        if( empty( $lesson_id ) ){
3367
+		if( empty( $lesson_id ) ){
3368 3368
 
3369
-            $lesson_id = get_the_ID();
3369
+			$lesson_id = get_the_ID();
3370 3370
 
3371
-        }
3371
+		}
3372 3372
 
3373
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3374
-            return;
3375
-        }
3373
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3374
+			return;
3375
+		}
3376 3376
 
3377
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3378
-    }
3377
+		echo Sensei()->lesson->lesson_image( $lesson_id );
3378
+	}
3379 3379
 
3380 3380
 
3381
-    /**
3382
-     * Alter the sensei lesson excerpt.
3383
-     *
3384
-     * @since 1.9.0
3385
-     * @param string $excerpt
3386
-     * @return string $excerpt
3387
-     */
3388
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3381
+	/**
3382
+	 * Alter the sensei lesson excerpt.
3383
+	 *
3384
+	 * @since 1.9.0
3385
+	 * @param string $excerpt
3386
+	 * @return string $excerpt
3387
+	 */
3388
+	public static function alter_the_lesson_excerpt( $excerpt ) {
3389 3389
 
3390
-        if ('lesson' == get_post_type(get_the_ID())){
3390
+		if ('lesson' == get_post_type(get_the_ID())){
3391 3391
 
3392
-            // remove this hooks to avoid an infinite loop.
3393
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3392
+			// remove this hooks to avoid an infinite loop.
3393
+			remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3394 3394
 
3395
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3396
-        }
3395
+			return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3396
+		}
3397 3397
 
3398
-        return $excerpt;
3398
+		return $excerpt;
3399 3399
 
3400
-    }// end the_lesson_excerpt
3400
+	}// end the_lesson_excerpt
3401 3401
 
3402
-    /**
3403
-     * Returns the lesson prerequisite for the given lesson id.
3404
-     *
3405
-     * @since 1.9.0
3406
-     *
3407
-     * @param $current_lesson_id
3408
-     * @return mixed | bool | int $prerequisite_lesson_id or false
3409
-     */
3410
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3402
+	/**
3403
+	 * Returns the lesson prerequisite for the given lesson id.
3404
+	 *
3405
+	 * @since 1.9.0
3406
+	 *
3407
+	 * @param $current_lesson_id
3408
+	 * @return mixed | bool | int $prerequisite_lesson_id or false
3409
+	 */
3410
+	public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3411 3411
 
3412
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3412
+		$prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3413 3413
 
3414
-        // set ti to false if not a valid prerequisite lesson id
3415
-        if(  empty( $prerequisite_lesson_id )
3416
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3417
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3414
+		// set ti to false if not a valid prerequisite lesson id
3415
+		if(  empty( $prerequisite_lesson_id )
3416
+			|| 'lesson' != get_post_type( $prerequisite_lesson_id )
3417
+			|| $prerequisite_lesson_id == $current_lesson_id  ) {
3418 3418
 
3419
-            $prerequisite_lesson_id = false;
3419
+			$prerequisite_lesson_id = false;
3420 3420
 
3421
-        }
3421
+		}
3422 3422
 
3423
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3423
+		return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3424 3424
 
3425
-    }
3425
+	}
3426 3426
 
3427
-    /**
3428
-     * This function requires that you pass in the lesson you would like to check for
3429
-     * a pre-requisite and not the pre-requisite. It will check if the
3430
-     * lesson has a pre-requiste and then check if it is completed.
3431
-     *
3432
-     * @since 1.9.0
3433
-     *
3434
-     * @param $lesson_id
3435
-     * @param $user_id
3436
-     * @return bool
3437
-     */
3438
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3427
+	/**
3428
+	 * This function requires that you pass in the lesson you would like to check for
3429
+	 * a pre-requisite and not the pre-requisite. It will check if the
3430
+	 * lesson has a pre-requiste and then check if it is completed.
3431
+	 *
3432
+	 * @since 1.9.0
3433
+	 *
3434
+	 * @param $lesson_id
3435
+	 * @param $user_id
3436
+	 * @return bool
3437
+	 */
3438
+	public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3439 3439
 
3440
-        if( empty( $lesson_id ) || empty( $user_id )
3441
-        || 'lesson' != get_post_type( $lesson_id )
3442
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3440
+		if( empty( $lesson_id ) || empty( $user_id )
3441
+		|| 'lesson' != get_post_type( $lesson_id )
3442
+		||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3443 3443
 
3444
-            return false;
3444
+			return false;
3445 3445
 
3446
-        }
3446
+		}
3447 3447
 
3448
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3448
+		$pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3449 3449
 
3450
-        // not a valid pre-requisite so pre-requisite is completed
3451
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3452
-            || ! is_numeric( $pre_requisite_id ) ){
3450
+		// not a valid pre-requisite so pre-requisite is completed
3451
+		if( 'lesson' != get_post_type( $pre_requisite_id )
3452
+			|| ! is_numeric( $pre_requisite_id ) ){
3453 3453
 
3454
-            return true;
3454
+			return true;
3455 3455
 
3456
-        }
3456
+		}
3457 3457
 
3458
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3458
+		return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3459 3459
 
3460
-    }// end is_prerequisite_complete
3460
+	}// end is_prerequisite_complete
3461 3461
 
3462
-    /**
3463
-     * Show the user not taking course message if it is the case
3464
-     *
3465
-     * @since 1.9.0
3466
-     */
3467
-    public  static function user_not_taking_course_message(){
3462
+	/**
3463
+	 * Show the user not taking course message if it is the case
3464
+	 *
3465
+	 * @since 1.9.0
3466
+	 */
3467
+	public  static function user_not_taking_course_message(){
3468 3468
 
3469
-        $lesson_id = get_the_ID();
3469
+		$lesson_id = get_the_ID();
3470 3470
 
3471
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3472
-            return;
3473
-        }
3471
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3472
+			return;
3473
+		}
3474 3474
 
3475
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3476
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3477
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3478
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3475
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3476
+		$pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3477
+		$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3478
+		$user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3479 3479
 
3480
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3480
+		if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3481 3481
 
3482 3482
 
3483
-        }// end if
3483
+		}// end if
3484 3484
 
3485
-    } // end user_not_taking_course_message
3485
+	} // end user_not_taking_course_message
3486 3486
 
3487
-    /**
3488
-     * Outputs the lessons course signup lingk
3489
-     *
3490
-     * This hook runs inside the single lesson page.
3491
-     *
3492
-     * @since 1.9.0
3493
-     */
3494
-    public static function course_signup_link( ){
3487
+	/**
3488
+	 * Outputs the lessons course signup lingk
3489
+	 *
3490
+	 * This hook runs inside the single lesson page.
3491
+	 *
3492
+	 * @since 1.9.0
3493
+	 */
3494
+	public static function course_signup_link( ){
3495 3495
 
3496
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3496
+		$course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3497 3497
 
3498
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3498
+		if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3499 3499
 
3500
-            return;
3500
+			return;
3501 3501
 
3502
-        }
3502
+		}
3503 3503
 
3504
-        ?>
3504
+		?>
3505 3505
 
3506 3506
         <section class="course-signup lesson-meta">
3507 3507
 
3508 3508
             <?php
3509 3509
 
3510
-            global $current_user;
3511
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3510
+			global $current_user;
3511
+			$wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3512 3512
 
3513
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $course_id ) ) {
3513
+			if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $course_id ) ) {
3514 3514
 
3515
-                if( is_user_logged_in() && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID )  ) {
3515
+				if( is_user_logged_in() && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID )  ) {
3516 3516
 
3517
-	                    $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3518
-	                    $a_element .= __( 'course', 'woothemes-sensei' );
3519
-	                    $a_element .= '</a>';
3517
+						$a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3518
+						$a_element .= __( 'course', 'woothemes-sensei' );
3519
+						$a_element .= '</a>';
3520 3520
 
3521
-	                    if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3521
+						if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3522 3522
 
3523
-		                    $message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3523
+							$message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3524 3524
 
3525
-	                    }else{
3525
+						}else{
3526 3526
 
3527
-		                    $message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3527
+							$message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3528 3528
 
3529
-	                    }
3529
+						}
3530 3530
 
3531
-	                    Sensei()->notices->add_notice( $message, 'info' );
3531
+						Sensei()->notices->add_notice( $message, 'info' );
3532 3532
 
3533
-                }
3533
+				}
3534 3534
 
3535
-	            if( ! is_user_logged_in() ) {
3535
+				if( ! is_user_logged_in() ) {
3536 3536
 
3537
-	                $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3538
-	                $a_element .= __( 'course', 'woothemes-sensei' );
3539
-	                $a_element .= '</a>';
3537
+					$a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3538
+					$a_element .= __( 'course', 'woothemes-sensei' );
3539
+					$a_element .= '</a>';
3540 3540
 
3541
-	                if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3541
+					if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3542 3542
 
3543 3543
 						$message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3544 3544
 
@@ -3550,19 +3550,19 @@  discard block
 block discarded – undo
3550 3550
 
3551 3551
 					Sensei()->notices->add_notice( $message, 'alert' );
3552 3552
 
3553
-	            }
3553
+				}
3554 3554
 
3555
-            } else { ?>
3555
+			} else { ?>
3556 3556
 
3557 3557
 	            <?php if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) &&  sensei_is_login_required() )  : ?>
3558 3558
 
3559 3559
 	                <div class="sensei-message alert">
3560 3560
 	                    <?php
3561
-	                    $course_link =  '<a href="'
3562
-	                                        . esc_url( get_permalink( $course_id ) )
3563
-	                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3564
-	                                        . '">' . __( 'course', 'woothemes-sensei' )
3565
-	                                    . '</a>';
3561
+						$course_link =  '<a href="'
3562
+											. esc_url( get_permalink( $course_id ) )
3563
+											. '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3564
+											. '">' . __( 'course', 'woothemes-sensei' )
3565
+										. '</a>';
3566 3566
 
3567 3567
 						if ( Sensei_Utils::is_preview_lesson( get_the_ID( ) ) ) {
3568 3568
 
@@ -3574,7 +3574,7 @@  discard block
 block discarded – undo
3574 3574
 
3575 3575
 						}
3576 3576
 
3577
-	                    ?>
3577
+						?>
3578 3578
 	                </div>
3579 3579
 
3580 3580
 	            <?php endif; ?>
@@ -3584,75 +3584,75 @@  discard block
 block discarded – undo
3584 3584
         </section>
3585 3585
 
3586 3586
         <?php
3587
-    }// end course_signup_link
3587
+	}// end course_signup_link
3588 3588
 
3589
-    /**
3590
-     * Show a message telling the user to complete the previous message if they haven't done so yet
3591
-     *
3592
-     * @since 1.9.0
3593
-     */
3594
-    public  static function prerequisite_complete_message(){
3589
+	/**
3590
+	 * Show a message telling the user to complete the previous message if they haven't done so yet
3591
+	 *
3592
+	 * @since 1.9.0
3593
+	 */
3594
+	public  static function prerequisite_complete_message(){
3595 3595
 
3596
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3597
-        $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3598
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3596
+		$lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3597
+		$lesson_has_pre_requisite = $lesson_prerequisite > 0;
3598
+		if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3599 3599
 
3600
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3601
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3600
+			$prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3601
+			echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3602 3602
 
3603
-        }
3603
+		}
3604 3604
 
3605
-    }
3605
+	}
3606 3606
 
3607
-    /**
3608
-     * Deprecate the sensei_lesson_archive_header hook but keep it
3609
-     * active for backwards compatibility.
3610
-     *
3611
-     * @deprecated since 1.9.0
3612
-     */
3613
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3607
+	/**
3608
+	 * Deprecate the sensei_lesson_archive_header hook but keep it
3609
+	 * active for backwards compatibility.
3610
+	 *
3611
+	 * @deprecated since 1.9.0
3612
+	 */
3613
+	public static function deprecate_sensei_lesson_archive_header_hook(){
3614 3614
 
3615
-        sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3615
+		sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3616 3616
 
3617
-    }
3617
+	}
3618 3618
 
3619
-    /**
3620
-     * Outputs the the lesson archive header.
3621
-     *
3622
-     * @since  1.9.0
3623
-     * @return void
3624
-     */
3625
-    public function the_archive_header( ) {
3619
+	/**
3620
+	 * Outputs the the lesson archive header.
3621
+	 *
3622
+	 * @since  1.9.0
3623
+	 * @return void
3624
+	 */
3625
+	public function the_archive_header( ) {
3626 3626
 
3627
-        $before_html = '<header class="archive-header"><h1>';
3628
-        $after_html = '</h1></header>';
3629
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3627
+		$before_html = '<header class="archive-header"><h1>';
3628
+		$after_html = '</h1></header>';
3629
+		$html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3630 3630
 
3631
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3631
+		echo apply_filters( 'sensei_lesson_archive_title', $html );
3632 3632
 
3633
-    } // sensei_course_archive_header()
3633
+	} // sensei_course_archive_header()
3634 3634
 
3635
-    /**
3636
-     * Output the title for the single lesson page
3637
-     *
3638
-     * @global $post
3639
-     * @since 1.9.0
3640
-     */
3641
-    public static function the_title(){
3635
+	/**
3636
+	 * Output the title for the single lesson page
3637
+	 *
3638
+	 * @global $post
3639
+	 * @since 1.9.0
3640
+	 */
3641
+	public static function the_title(){
3642 3642
 
3643
-        global $post;
3643
+		global $post;
3644 3644
 
3645
-        ?>
3645
+		?>
3646 3646
         <header>
3647 3647
 
3648 3648
             <h1>
3649 3649
 
3650 3650
                 <?php
3651
-                /**
3652
-                 * Filter documented in class-sensei-messages.php the_title
3653
-                 */
3654
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3655
-                ?>
3651
+				/**
3652
+				 * Filter documented in class-sensei-messages.php the_title
3653
+				 */
3654
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3655
+				?>
3656 3656
 
3657 3657
             </h1>
3658 3658
 
@@ -3660,75 +3660,75 @@  discard block
 block discarded – undo
3660 3660
 
3661 3661
         <?php
3662 3662
 
3663
-    }//the_title
3663
+	}//the_title
3664 3664
 
3665
-    /**
3666
-     * Flush the rewrite rules for a lesson post type
3667
-     *
3668
-     * @since 1.9.0
3669
-     *
3670
-     * @param $post_id
3671
-     */
3672
-    public static function flush_rewrite_rules( $post_id ){
3665
+	/**
3666
+	 * Flush the rewrite rules for a lesson post type
3667
+	 *
3668
+	 * @since 1.9.0
3669
+	 *
3670
+	 * @param $post_id
3671
+	 */
3672
+	public static function flush_rewrite_rules( $post_id ){
3673 3673
 
3674
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3674
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3675 3675
 
3676
-            return;
3676
+			return;
3677 3677
 
3678
-        }
3678
+		}
3679 3679
 
3680 3680
 
3681
-        if( 'lesson' == get_post_type( $post_id )  ){
3681
+		if( 'lesson' == get_post_type( $post_id )  ){
3682 3682
 
3683
-            Sensei()->initiate_rewrite_rules_flush();
3683
+			Sensei()->initiate_rewrite_rules_flush();
3684 3684
 
3685
-        }
3685
+		}
3686 3686
 
3687
-    }
3687
+	}
3688 3688
 
3689
-    /**
3690
-     * Output the quiz specific buttons and messaging on the single lesson page
3691
-     *
3692
-     *
3693
-     * @since 1.0.0 moved here from frontend class
3694
-     *
3695
-     * @param int $lesson_id
3696
-     * @param int $user_id
3697
-     */
3698
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3689
+	/**
3690
+	 * Output the quiz specific buttons and messaging on the single lesson page
3691
+	 *
3692
+	 *
3693
+	 * @since 1.0.0 moved here from frontend class
3694
+	 *
3695
+	 * @param int $lesson_id
3696
+	 * @param int $user_id
3697
+	 */
3698
+	public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3699 3699
 
3700 3700
 
3701
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3702
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3701
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3702
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3703 3703
 
3704 3704
 
3705
-	    if ( ! sensei_can_user_view_lesson( $lesson_id, $user_id ) ) {
3706
-		    return;
3707
-	    }
3705
+		if ( ! sensei_can_user_view_lesson( $lesson_id, $user_id ) ) {
3706
+			return;
3707
+		}
3708 3708
 
3709
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3710
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3711
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3712
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3713
-        $show_actions              = is_user_logged_in() ? true : false;
3709
+		$lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3710
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3711
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3712
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3713
+		$show_actions              = is_user_logged_in() ? true : false;
3714 3714
 
3715
-        if( intval( $lesson_prerequisite ) > 0 ) {
3715
+		if( intval( $lesson_prerequisite ) > 0 ) {
3716 3716
 
3717
-            // If the user hasn't completed the prereq then hide the current actions
3718
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3717
+			// If the user hasn't completed the prereq then hide the current actions
3718
+			$show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3719 3719
 
3720
-        }
3720
+		}
3721 3721
 
3722
-        ?>
3722
+		?>
3723 3723
 
3724 3724
         <footer>
3725 3725
 
3726 3726
             <?php
3727
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3727
+			if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3728 3728
 
3729
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3730
-                if( $has_quiz_questions ) {
3731
-                    ?>
3729
+				$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3730
+				if( $has_quiz_questions ) {
3731
+					?>
3732 3732
 
3733 3733
                     <p>
3734 3734
 
@@ -3743,123 +3743,123 @@  discard block
 block discarded – undo
3743 3743
                     </p>
3744 3744
 
3745 3745
                     <?php
3746
-                }
3746
+				}
3747 3747
 
3748
-            } // End If Statement
3748
+			} // End If Statement
3749 3749
 
3750
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3750
+			if ( $show_actions && ! $has_user_completed_lesson ) {
3751 3751
 
3752
-                sensei_complete_lesson_button();
3752
+				sensei_complete_lesson_button();
3753 3753
 
3754
-            } elseif( $show_actions ) {
3754
+			} elseif( $show_actions ) {
3755 3755
 
3756
-                sensei_reset_lesson_button();
3756
+				sensei_reset_lesson_button();
3757 3757
 
3758
-            } // End If Statement
3759
-            ?>
3758
+			} // End If Statement
3759
+			?>
3760 3760
 
3761 3761
         </footer>
3762 3762
 
3763 3763
         <?php
3764
-    } // End sensei_lesson_quiz_meta()
3764
+	} // End sensei_lesson_quiz_meta()
3765 3765
 
3766
-    /**
3767
-     * Show the lesson comments. This should be used in the loop.
3768
-     *
3769
-     * @since 1.9.0
3770
-     */
3771
-    public static function output_comments(){
3766
+	/**
3767
+	 * Show the lesson comments. This should be used in the loop.
3768
+	 *
3769
+	 * @since 1.9.0
3770
+	 */
3771
+	public static function output_comments(){
3772 3772
 
3773
-        if( ! is_user_logged_in() ){
3774
-            return;
3775
-        }
3773
+		if( ! is_user_logged_in() ){
3774
+			return;
3775
+		}
3776 3776
 
3777
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3778
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3779
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3780
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3777
+		$pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3778
+		$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3779
+		$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3780
+		$user_taking_course = Sensei_Utils::user_started_course($course_id );
3781 3781
 
3782
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3782
+		$lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3783 3783
 
3784
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3784
+		if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3785 3785
 
3786
-            comments_template();
3786
+			comments_template();
3787 3787
 
3788
-        } // End If Statement
3788
+		} // End If Statement
3789 3789
 
3790
-    } //output_comments
3790
+	} //output_comments
3791 3791
 
3792
-    /**
3793
-     * Display the leeson quiz status if it should be shown
3794
-     *
3795
-     * @param int $lesson_id defaults to the global lesson id
3796
-     * @param int $user_id defaults to the current user id
3797
-     *
3798
-     * @since 1.9.0
3799
-     */
3800
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3792
+	/**
3793
+	 * Display the leeson quiz status if it should be shown
3794
+	 *
3795
+	 * @param int $lesson_id defaults to the global lesson id
3796
+	 * @param int $user_id defaults to the current user id
3797
+	 *
3798
+	 * @since 1.9.0
3799
+	 */
3800
+	public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3801 3801
 
3802
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3803
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3804
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3805
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3806
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3802
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3803
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3804
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3805
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3806
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3807 3807
 
3808 3808
 
3809
-        if ( $quiz_id && is_user_logged_in()
3810
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3809
+		if ( $quiz_id && is_user_logged_in()
3810
+			&& Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3811 3811
 
3812
-            $no_quiz_count = 0;
3813
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3812
+			$no_quiz_count = 0;
3813
+			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3814 3814
 
3815
-            // Display lesson quiz status message
3816
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3817
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3818
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3819
-                if( $has_quiz_questions ) {
3820
-                   // echo $status['extra'];
3821
-                } // End If Statement
3822
-            } // End If Statement
3815
+			// Display lesson quiz status message
3816
+			if ( $has_user_completed_lesson || $has_quiz_questions ) {
3817
+				$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3818
+				echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3819
+				if( $has_quiz_questions ) {
3820
+				   // echo $status['extra'];
3821
+				} // End If Statement
3822
+			} // End If Statement
3823 3823
 
3824
-        }
3824
+		}
3825 3825
 
3826
-    }
3826
+	}
3827 3827
 
3828
-    /**
3829
-     * On the lesson archive limit the number of words the show up if the access settings are enabled
3830
-     *
3831
-     * @since 1.9.0
3832
-     * @param $content
3833
-     * @return string
3834
-     */
3835
-    public static function limit_archive_content ( $content ){
3828
+	/**
3829
+	 * On the lesson archive limit the number of words the show up if the access settings are enabled
3830
+	 *
3831
+	 * @since 1.9.0
3832
+	 * @param $content
3833
+	 * @return string
3834
+	 */
3835
+	public static function limit_archive_content ( $content ){
3836 3836
 
3837
-        if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3837
+		if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3838 3838
 
3839
-            return wp_trim_words( $content, $num_words = 30, $more = '…' );
3840
-        }
3839
+			return wp_trim_words( $content, $num_words = 30, $more = '…' );
3840
+		}
3841 3841
 
3842
-        return $content;
3842
+		return $content;
3843 3843
 
3844
-    } // end limit_archive_content
3844
+	} // end limit_archive_content
3845 3845
 
3846
-    /**
3847
-     * Returns all publised lesson ID's
3848
-     *
3849
-     * @since 1.9.0
3850
-     * @return array
3851
-     */
3852
-    public static function get_all_lesson_ids(){
3846
+	/**
3847
+	 * Returns all publised lesson ID's
3848
+	 *
3849
+	 * @since 1.9.0
3850
+	 * @return array
3851
+	 */
3852
+	public static function get_all_lesson_ids(){
3853 3853
 
3854
-        return get_posts( array(
3855
-            'post_type'=>'lesson',
3856
-            'fields'=>'ids',
3857
-            'post_status' => 'publish',
3858
-            'numberposts' => 4000, // legacy support
3859
-            'post_per_page' => 4000
3860
-        ));
3854
+		return get_posts( array(
3855
+			'post_type'=>'lesson',
3856
+			'fields'=>'ids',
3857
+			'post_status' => 'publish',
3858
+			'numberposts' => 4000, // legacy support
3859
+			'post_per_page' => 4000
3860
+		));
3861 3861
 
3862
-    }
3862
+	}
3863 3863
 
3864 3864
 } // End Class
3865 3865
 
Please login to merge, or discard this patch.
Spacing   +1105 added lines, -1105 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Lessons Class
@@ -19,83 +19,83 @@  discard block
 block discarded – undo
19 19
 	 * Constructor.
20 20
 	 * @since  1.0.0
21 21
 	 */
22
-	public function __construct () {
22
+	public function __construct() {
23 23
 
24 24
         $this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27
-		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
27
+		$this->meta_fields = array('lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed');
28 28
 
29 29
         $this->question_order = '';
30 30
 
31 31
 		// Admin actions
32
-		if ( is_admin() ) {
32
+		if (is_admin()) {
33 33
 
34 34
 			// Metabox functions
35
-			add_action( 'admin_menu', array( $this, 'meta_box_setup' ), 20 );
36
-			add_action( 'save_post', array( $this, 'meta_box_save' ) );
37
-			add_action( 'save_post', array( $this, 'quiz_update' ) );
35
+			add_action('admin_menu', array($this, 'meta_box_setup'), 20);
36
+			add_action('save_post', array($this, 'meta_box_save'));
37
+			add_action('save_post', array($this, 'quiz_update'));
38 38
 
39 39
 			// Custom Write Panel Columns
40
-			add_filter( 'manage_edit-lesson_columns', array( $this, 'add_column_headings' ), 10, 1 );
41
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
40
+			add_filter('manage_edit-lesson_columns', array($this, 'add_column_headings'), 10, 1);
41
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
42 42
 
43 43
 			// Add/Update question
44
-			add_action( 'wp_ajax_lesson_update_question', array( $this, 'lesson_update_question' ) );
45
-			add_action( 'wp_ajax_nopriv_lesson_update_question', array( $this, 'lesson_update_question' ) );
44
+			add_action('wp_ajax_lesson_update_question', array($this, 'lesson_update_question'));
45
+			add_action('wp_ajax_nopriv_lesson_update_question', array($this, 'lesson_update_question'));
46 46
 
47 47
 			// Add course
48
-			add_action( 'wp_ajax_lesson_add_course', array( $this, 'lesson_add_course' ) );
49
-			add_action( 'wp_ajax_nopriv_lesson_add_course', array( $this, 'lesson_add_course' ) );
48
+			add_action('wp_ajax_lesson_add_course', array($this, 'lesson_add_course'));
49
+			add_action('wp_ajax_nopriv_lesson_add_course', array($this, 'lesson_add_course'));
50 50
 
51 51
 			// Update grade type
52
-			add_action( 'wp_ajax_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
53
-			add_action( 'wp_ajax_nopriv_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
52
+			add_action('wp_ajax_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
53
+			add_action('wp_ajax_nopriv_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
54 54
 
55 55
 			// Update question order
56
-			add_action( 'wp_ajax_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
57
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
56
+			add_action('wp_ajax_lesson_update_question_order', array($this, 'lesson_update_question_order'));
57
+			add_action('wp_ajax_nopriv_lesson_update_question_order', array($this, 'lesson_update_question_order'));
58 58
 
59 59
 			//Update question order
60
-			add_action( 'wp_ajax_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
61
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
60
+			add_action('wp_ajax_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
61
+			add_action('wp_ajax_nopriv_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
62 62
 
63 63
 			// Get answer ID
64
-			add_action( 'wp_ajax_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
65
-			add_action( 'wp_ajax_nopriv_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
64
+			add_action('wp_ajax_question_get_answer_id', array($this, 'question_get_answer_id'));
65
+			add_action('wp_ajax_nopriv_question_get_answer_id', array($this, 'question_get_answer_id'));
66 66
 
67 67
 			// Add multiple questions
68
-			add_action( 'wp_ajax_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
69
-			add_action( 'wp_ajax_nopriv_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
68
+			add_action('wp_ajax_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
69
+			add_action('wp_ajax_nopriv_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
70 70
 
71 71
 			// Remove multiple questions
72
-			add_action( 'wp_ajax_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
73
-			add_action( 'wp_ajax_nopriv_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
72
+			add_action('wp_ajax_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
73
+			add_action('wp_ajax_nopriv_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
74 74
 
75 75
 			// Get question category limit
76
-			add_action( 'wp_ajax_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
77
-			add_action( 'wp_ajax_nopriv_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
76
+			add_action('wp_ajax_get_question_category_limit', array($this, 'get_question_category_limit'));
77
+			add_action('wp_ajax_nopriv_get_question_category_limit', array($this, 'get_question_category_limit'));
78 78
 
79 79
 			// Add existing questions
80
-			add_action( 'wp_ajax_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
81
-			add_action( 'wp_ajax_nopriv_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
80
+			add_action('wp_ajax_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
81
+			add_action('wp_ajax_nopriv_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
82 82
 
83 83
 			// Filter existing questions
84
-			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85
-			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
84
+			add_action('wp_ajax_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
85
+			add_action('wp_ajax_nopriv_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
86 86
 
87 87
             // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
88
+            add_action('bulk_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
89
+            add_action('quick_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
90 90
 
91 91
             // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
92
+            add_action('manage_lesson_posts_custom_column', array($this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94 94
             // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
95
+            add_action('wp_ajax_save_bulk_edit_book', array($this, 'save_all_lessons_edit_fields'));
96 96
 
97 97
             // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
98
+            add_action('save_post', array(__CLASS__, 'flush_rewrite_rules'));
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
 	 * @access public
109 109
 	 * @return void
110 110
 	 */
111
-	public function meta_box_setup () {
111
+	public function meta_box_setup() {
112 112
 
113 113
 		// Add Meta Box for Prerequisite Lesson
114
-		add_meta_box( 'lesson-prerequisite', __( 'Lesson Prerequisite', 'woothemes-sensei' ), array( $this, 'lesson_prerequisite_meta_box_content' ), $this->token, 'side', 'default' );
114
+		add_meta_box('lesson-prerequisite', __('Lesson Prerequisite', 'woothemes-sensei'), array($this, 'lesson_prerequisite_meta_box_content'), $this->token, 'side', 'default');
115 115
 
116 116
 		// Add Meta Box for Lesson Course
117
-		add_meta_box( 'lesson-course', __( 'Lesson Course', 'woothemes-sensei' ), array( $this, 'lesson_course_meta_box_content' ), $this->token, 'side', 'default' );
117
+		add_meta_box('lesson-course', __('Lesson Course', 'woothemes-sensei'), array($this, 'lesson_course_meta_box_content'), $this->token, 'side', 'default');
118 118
 
119 119
 		// Add Meta Box for Lesson Preview
120
-		add_meta_box( 'lesson-preview', __( 'Lesson Preview', 'woothemes-sensei' ), array( $this, 'lesson_preview_meta_box_content' ), $this->token, 'side', 'default' );
120
+		add_meta_box('lesson-preview', __('Lesson Preview', 'woothemes-sensei'), array($this, 'lesson_preview_meta_box_content'), $this->token, 'side', 'default');
121 121
 
122 122
 		// Add Meta Box for Lesson Information
123
-		add_meta_box( 'lesson-info', __( 'Lesson Information', 'woothemes-sensei' ), array( $this, 'lesson_info_meta_box_content' ), $this->token, 'normal', 'default' );
123
+		add_meta_box('lesson-info', __('Lesson Information', 'woothemes-sensei'), array($this, 'lesson_info_meta_box_content'), $this->token, 'normal', 'default');
124 124
 
125 125
 		// Add Meta Box for Quiz Settings
126
-		add_meta_box( 'lesson-quiz-settings', __( 'Quiz Settings', 'woothemes-sensei' ), array( $this, 'lesson_quiz_settings_meta_box_content' ), $this->token, 'normal', 'default' );
126
+		add_meta_box('lesson-quiz-settings', __('Quiz Settings', 'woothemes-sensei'), array($this, 'lesson_quiz_settings_meta_box_content'), $this->token, 'normal', 'default');
127 127
 
128 128
 		// Add Meta Box for Lesson Quiz Questions
129
-		add_meta_box( 'lesson-quiz', __( 'Quiz Questions', 'woothemes-sensei' ), array( $this, 'lesson_quiz_meta_box_content' ), $this->token, 'normal', 'default' );
129
+		add_meta_box('lesson-quiz', __('Quiz Questions', 'woothemes-sensei'), array($this, 'lesson_quiz_meta_box_content'), $this->token, 'normal', 'default');
130 130
 
131 131
 		// Remove "Custom Settings" meta box.
132
-		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
132
+		remove_meta_box('woothemes-settings', $this->token, 'normal');
133 133
 
134 134
 		// Add JS scripts
135
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
135
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
136 136
 
137 137
 		// Add CSS
138
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
138
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
139 139
 
140 140
 	} // End meta_box_setup()
141 141
 
@@ -146,30 +146,30 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 * @return void
148 148
 	 */
149
-	public function lesson_info_meta_box_content () {
149
+	public function lesson_info_meta_box_content() {
150 150
 		global $post;
151 151
 
152
-		$lesson_length = get_post_meta( $post->ID, '_lesson_length', true );
153
-		$lesson_complexity = get_post_meta( $post->ID, '_lesson_complexity', true );
152
+		$lesson_length = get_post_meta($post->ID, '_lesson_length', true);
153
+		$lesson_complexity = get_post_meta($post->ID, '_lesson_complexity', true);
154 154
 		$complexity_array = $this->lesson_complexities();
155
-		$lesson_video_embed = get_post_meta( $post->ID, '_lesson_video_embed', true );
155
+		$lesson_video_embed = get_post_meta($post->ID, '_lesson_video_embed', true);
156 156
 
157 157
 		$html = '';
158 158
 		// Lesson Length
159
-		$html .= '<p><label for="lesson_length">' . __( 'Lesson Length in minutes', 'woothemes-sensei' ) . ': </label>';
160
-		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="' . esc_attr( $lesson_length ) . '" /></p>' . "\n";
159
+		$html .= '<p><label for="lesson_length">'.__('Lesson Length in minutes', 'woothemes-sensei').': </label>';
160
+		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="'.esc_attr($lesson_length).'" /></p>'."\n";
161 161
 		// Lesson Complexity
162
-		$html .= '<p><label for="lesson_complexity">' . __( 'Lesson Complexity', 'woothemes-sensei' ) . ': </label>';
162
+		$html .= '<p><label for="lesson_complexity">'.__('Lesson Complexity', 'woothemes-sensei').': </label>';
163 163
 		$html .= '<select id="lesson-complexity-options" name="lesson_complexity" class="chosen_select lesson-complexity-select">';
164
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
165
-			foreach ($complexity_array as $key => $value){
166
-				$html .= '<option value="' . esc_attr( $key ) . '"' . selected( $key, $lesson_complexity, false ) . '>' . esc_html( $value ) . '</option>' . "\n";
164
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
165
+			foreach ($complexity_array as $key => $value) {
166
+				$html .= '<option value="'.esc_attr($key).'"'.selected($key, $lesson_complexity, false).'>'.esc_html($value).'</option>'."\n";
167 167
 			} // End For Loop
168
-		$html .= '</select></p>' . "\n";
168
+		$html .= '</select></p>'."\n";
169 169
 
170
-		$html .= '<p><label for="lesson_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . ':</label><br/>' . "\n";
171
-		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">' . $lesson_video_embed . '</textarea></p>' . "\n";
172
-		$html .= '<p>' .  __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>';
170
+		$html .= '<p><label for="lesson_video_embed">'.__('Video Embed Code', 'woothemes-sensei').':</label><br/>'."\n";
171
+		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">'.$lesson_video_embed.'</textarea></p>'."\n";
172
+		$html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>';
173 173
 
174 174
 		echo $html;
175 175
 
@@ -181,31 +181,31 @@  discard block
 block discarded – undo
181 181
 	 * @access public
182 182
 	 * @return void
183 183
 	 */
184
-	public function lesson_prerequisite_meta_box_content () {
184
+	public function lesson_prerequisite_meta_box_content() {
185 185
 		global $post;
186 186
 		// Get existing post meta
187
-		$select_lesson_prerequisite = get_post_meta( $post->ID, '_lesson_prerequisite', true );
187
+		$select_lesson_prerequisite = get_post_meta($post->ID, '_lesson_prerequisite', true);
188 188
 		// Get the Lesson Posts
189
-		$post_args = array(	'post_type' 		=> 'lesson',
189
+		$post_args = array('post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192 192
     						'order'           	=> 'ASC',
193 193
     						'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196
-		$posts_array = get_posts( $post_args );
196
+		$posts_array = get_posts($post_args);
197 197
 		// Build the HTML to Output
198 198
 		$html = '';
199
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
200
-		if ( count( $posts_array ) > 0 ) {
201
-			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">' . "\n";
202
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
203
-				foreach ($posts_array as $post_item){
204
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_lesson_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
199
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
200
+		if (count($posts_array) > 0) {
201
+			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">'."\n";
202
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
203
+				foreach ($posts_array as $post_item) {
204
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_lesson_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n";
205 205
 				} // End For Loop
206
-			$html .= '</select>' . "\n";
206
+			$html .= '</select>'."\n";
207 207
 		} else {
208
-			$html .= '<p>' . esc_html( __( 'No lessons exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>';
208
+			$html .= '<p>'.esc_html(__('No lessons exist yet. Please add some first.', 'woothemes-sensei')).'</p>';
209 209
 		} // End If Statement
210 210
 		// Output the HTML
211 211
 		echo $html;
@@ -217,20 +217,20 @@  discard block
 block discarded – undo
217 217
 	 * @access public
218 218
 	 * @return void
219 219
 	 */
220
-	public function lesson_preview_meta_box_content () {
220
+	public function lesson_preview_meta_box_content() {
221 221
 		global $post;
222 222
 		// Get existing post meta
223
-		$lesson_preview = get_post_meta( $post->ID, '_lesson_preview', true );
223
+		$lesson_preview = get_post_meta($post->ID, '_lesson_preview', true);
224 224
 		$html = '';
225
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
225
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
226 226
 
227 227
 		$checked = '';
228
-		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
228
+		if (isset($lesson_preview) && ('' != $lesson_preview)) {
229
+	 	    $checked = checked('preview', $lesson_preview, false);
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
233
-	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" ' . $checked . '>&nbsp;' . __( 'Allow this lesson to be viewed without purchase/login', 'woothemes-sensei' ) . '<br>';
233
+	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" '.$checked.'>&nbsp;'.__('Allow this lesson to be viewed without purchase/login', 'woothemes-sensei').'<br>';
234 234
 
235 235
 		// Output the HTML
236 236
 		echo $html;
@@ -243,40 +243,40 @@  discard block
 block discarded – undo
243 243
 	 * @param int $post_id
244 244
 	 * @return integer $post_id
245 245
 	 */
246
-	public function meta_box_save ( $post_id ) {
246
+	public function meta_box_save($post_id) {
247 247
 
248 248
 		// Verify the nonce before proceeding.
249
-		if ( ( get_post_type( $post_id ) != $this->token ) || !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta' ) ) {
249
+		if ((get_post_type($post_id) != $this->token) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
250 250
 			return $post_id;
251 251
 		} // End If Statement
252 252
 		// Get the post type object.
253
-		$post_type = get_post_type_object( get_post_type( $post_id ) );
253
+		$post_type = get_post_type_object(get_post_type($post_id));
254 254
 		// Check if the current user has permission to edit the post.
255
-		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
255
+		if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
256 256
 			return $post_id;
257 257
 		} // End If Statement
258 258
 
259 259
 		// Check if the current post type is a page
260
-		if ( 'page' == $_POST[ 'post_type' ] ) {
260
+		if ('page' == $_POST['post_type']) {
261 261
 
262
-			if ( ! current_user_can( 'edit_page', $post_id ) ) {
262
+			if ( ! current_user_can('edit_page', $post_id)) {
263 263
 
264 264
 				return $post_id;
265 265
 
266 266
 			} // End If Statement
267 267
 		} else {
268
-			if ( ! current_user_can( 'edit_post', $post_id ) ) {
268
+			if ( ! current_user_can('edit_post', $post_id)) {
269 269
 				return $post_id;
270 270
 			} // End If Statement
271 271
 		} // End If Statement
272 272
 
273 273
 		// Save the post meta data fields
274
-		if ( isset($this->meta_fields) && is_array($this->meta_fields) ) {
274
+		if (isset($this->meta_fields) && is_array($this->meta_fields)) {
275 275
 
276
-			foreach ( $this->meta_fields as $meta_key ) {
276
+			foreach ($this->meta_fields as $meta_key) {
277 277
 
278
-				remove_action( 'save_post', array( $this, 'meta_box_save') );
279
-				$this->save_post_meta( $meta_key, $post_id );
278
+				remove_action('save_post', array($this, 'meta_box_save'));
279
+				$this->save_post_meta($meta_key, $post_id);
280 280
 
281 281
 			} // End For Loop
282 282
 		} // End If Statement
@@ -289,37 +289,37 @@  discard block
 block discarded – undo
289 289
 	 * @access public
290 290
 	 * @return integer|boolean $post_id or false
291 291
 	 */
292
-	public function quiz_update( $post_id ) {
292
+	public function quiz_update($post_id) {
293 293
 		global $post;
294 294
 		// Verify the nonce before proceeding.
295
-		if ( ( 'lesson' != get_post_type( $post_id ) )|| !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta') ) {
296
-			if ( isset($post->ID) ) {
295
+		if (('lesson' != get_post_type($post_id)) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
296
+			if (isset($post->ID)) {
297 297
 				return $post->ID;
298 298
 			} else {
299 299
 				return false;
300 300
 			} // End If Statement
301 301
 		} // End If Statement
302 302
 
303
-		if( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
303
+		if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
304 304
 			return false;
305 305
 		}
306 306
 
307 307
 		// Temporarily disable the filter
308
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
308
+        remove_action('save_post', array($this, 'quiz_update'));
309 309
 		// Save the Quiz
310
-		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
310
+		$quiz_id = $this->lesson_quizzes($post_id, 'any');
311 311
 
312 312
 		 // Sanitize and setup the post data
313
-		$_POST = stripslashes_deep( $_POST );
314
-		if ( isset( $_POST[ 'quiz_id' ] ) && ( 0 < absint( $_POST[ 'quiz_id' ] ) ) ) {
315
-			$quiz_id = absint( $_POST[ 'quiz_id' ] );
313
+		$_POST = stripslashes_deep($_POST);
314
+		if (isset($_POST['quiz_id']) && (0 < absint($_POST['quiz_id']))) {
315
+			$quiz_id = absint($_POST['quiz_id']);
316 316
 		} // End If Statement
317
-		$post_title = esc_html( $_POST[ 'post_title' ] );
318
-		$post_status = esc_html( $_POST[ 'post_status' ] );
317
+		$post_title = esc_html($_POST['post_title']);
318
+		$post_status = esc_html($_POST['post_status']);
319 319
 		$post_content = '';
320 320
 
321 321
 		// Setup Query Arguments
322
-		$post_type_args = array(	'post_content' => $post_content,
322
+		$post_type_args = array('post_content' => $post_content,
323 323
   		    						'post_status' => $post_status,
324 324
   		    						'post_title' => $post_title,
325 325
   		    						'post_type' => 'quiz',
@@ -329,84 +329,84 @@  discard block
 block discarded – undo
329 329
 		$settings = $this->get_quiz_settings();
330 330
 
331 331
   		// Update or Insert the Lesson Quiz
332
-		if ( 0 < $quiz_id ) {
332
+		if (0 < $quiz_id) {
333 333
 			// Update the Quiz
334
-			$post_type_args[ 'ID' ] = $quiz_id;
334
+			$post_type_args['ID'] = $quiz_id;
335 335
 		    wp_update_post($post_type_args);
336 336
 
337 337
 		    // Update the post meta data
338
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
338
+		    update_post_meta($quiz_id, '_quiz_lesson', $post_id);
339 339
 
340
-		    foreach( $settings as $field ) {
341
-		    	if( 'random_question_order' != $field['id'] ) {
342
-			    	$value = $this->get_submitted_setting_value( $field );
343
-			    	if( isset( $value ) ) {
344
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
340
+		    foreach ($settings as $field) {
341
+		    	if ('random_question_order' != $field['id']) {
342
+			    	$value = $this->get_submitted_setting_value($field);
343
+			    	if (isset($value)) {
344
+			    		update_post_meta($quiz_id, '_'.$field['id'], $value);
345 345
 			    	}
346 346
 			    }
347 347
 		    }
348 348
 
349 349
 		    // Set the post terms for quiz-type
350
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
350
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
351 351
 		} else {
352 352
 			// Create the Quiz
353 353
 		    $quiz_id = wp_insert_post($post_type_args);
354 354
 
355 355
 		    // Add the post meta data WP will add it if it doesn't exist
356
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
356
+            update_post_meta($quiz_id, '_quiz_lesson', $post_id);
357 357
 
358
-		    foreach( $settings as $field ) {
359
-		    	if( 'random_question_order' != $field['id'] ) {
358
+		    foreach ($settings as $field) {
359
+		    	if ('random_question_order' != $field['id']) {
360 360
 
361 361
                     //ignore values not posted to avoid
362 362
                     // overwriting with empty or default values
363 363
                     // when the values are posted from bulk edit or quick edit
364
-                    if( !isset( $_POST[ $field['id'] ] ) ){
364
+                    if ( ! isset($_POST[$field['id']])) {
365 365
                         continue;
366 366
                     }
367 367
 
368
-			    	$value = $this->get_submitted_setting_value( $field );
369
-			    	if( isset( $value ) ) {
370
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
368
+			    	$value = $this->get_submitted_setting_value($field);
369
+			    	if (isset($value)) {
370
+			    		add_post_meta($quiz_id, '_'.$field['id'], $value);
371 371
 			    	}
372 372
 			    }
373 373
 		    }
374 374
 
375 375
 		    // Set the post terms for quiz-type
376
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
376
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
377 377
 		} // End If Statement
378 378
 
379 379
 		// Add default lesson order meta value
380
-		$course_id = get_post_meta( $post_id, '_lesson_course', true );
381
-		if( $course_id ) {
382
-			if( ! get_post_meta( $post_id, '_order_' . $course_id, true ) ) {
383
-				update_post_meta( $post_id, '_order_' . $course_id, 0 );
380
+		$course_id = get_post_meta($post_id, '_lesson_course', true);
381
+		if ($course_id) {
382
+			if ( ! get_post_meta($post_id, '_order_'.$course_id, true)) {
383
+				update_post_meta($post_id, '_order_'.$course_id, 0);
384 384
 			}
385 385
 		}
386 386
 		// Add reference back to the Quiz
387
-		update_post_meta( $post_id, '_lesson_quiz', $quiz_id );
387
+		update_post_meta($post_id, '_lesson_quiz', $quiz_id);
388 388
 		// Mark if the Lesson Quiz has questions
389
-		$quiz_questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
390
-		if( 0 < count( $quiz_questions ) ) {
391
-			update_post_meta( $post_id, '_quiz_has_questions', '1' );
389
+		$quiz_questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
390
+		if (0 < count($quiz_questions)) {
391
+			update_post_meta($post_id, '_quiz_has_questions', '1');
392 392
 		}
393 393
 		else {
394
-			delete_post_meta( $post_id, '_quiz_has_questions' );
394
+			delete_post_meta($post_id, '_quiz_has_questions');
395 395
 		}
396 396
 
397 397
 		// Restore the previously disabled filter
398
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
398
+        add_action('save_post', array($this, 'quiz_update'));
399 399
 
400 400
 	} // End post_updated()
401 401
 
402
-	public function get_submitted_setting_value( $field = false ) {
402
+	public function get_submitted_setting_value($field = false) {
403 403
 
404
-		if( ! $field ) return;
404
+		if ( ! $field) return;
405 405
 
406 406
 		$value = false;
407 407
 
408
-		if( 'quiz_grade_type' == $field['id'] ) {
409
-			if( isset( $_POST[ $field['id'] ] ) && 'on' == $_POST[ $field['id'] ] ) {
408
+		if ('quiz_grade_type' == $field['id']) {
409
+			if (isset($_POST[$field['id']]) && 'on' == $_POST[$field['id']]) {
410 410
 				$value = 'auto';
411 411
 			} else {
412 412
 				$value = 'manual';
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 			return $value;
415 415
 		}
416 416
 
417
-		if ( isset( $_POST[ $field['id'] ] ) ) {
418
-			$value = $_POST[ $field['id'] ];
417
+		if (isset($_POST[$field['id']])) {
418
+			$value = $_POST[$field['id']];
419 419
 		} else {
420 420
 			$value = $field['default'];
421 421
 		}
@@ -431,18 +431,18 @@  discard block
 block discarded – undo
431 431
 	 * @param int $post_id (default: 0)
432 432
 	 * @return int|bool meta id or saved status
433 433
 	 */
434
-	private function save_post_meta( $post_key = '', $post_id = 0 ) {
434
+	private function save_post_meta($post_key = '', $post_id = 0) {
435 435
 		// Get the meta key.
436
-		$meta_key = '_' . $post_key;
436
+		$meta_key = '_'.$post_key;
437 437
 
438 438
         //ignore fields are not posted
439 439
 
440
-        if( !isset( $_POST[ $post_key ] ) ){
440
+        if ( ! isset($_POST[$post_key])) {
441 441
 
442 442
             // except for lesson preview checkbox field
443
-            if( 'lesson_preview' == $post_key ){
443
+            if ('lesson_preview' == $post_key) {
444 444
 
445
-                $_POST[ $post_key ] = '';
445
+                $_POST[$post_key] = '';
446 446
 
447 447
             } else {
448 448
 
@@ -453,15 +453,15 @@  discard block
 block discarded – undo
453 453
         }
454 454
 
455 455
 		// Get the posted data and sanitize it for use as an HTML class.
456
-		if ( 'lesson_video_embed' == $post_key) {
457
-			$new_meta_value = esc_html( $_POST[$post_key] );
456
+		if ('lesson_video_embed' == $post_key) {
457
+			$new_meta_value = esc_html($_POST[$post_key]);
458 458
 		} else {
459
-			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
459
+			$new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : '');
460 460
 		} // End If Statement
461 461
 
462 462
         // update field with the new value
463
-        if( -1 != $new_meta_value  ){
464
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
463
+        if ( -1 != $new_meta_value  ) {
464
+            return update_post_meta($post_id, $meta_key, $new_meta_value);
465 465
         }
466 466
 
467 467
 	} // End save_post_meta()
@@ -472,30 +472,30 @@  discard block
 block discarded – undo
472 472
 	 * @access public
473 473
 	 * @return void
474 474
 	 */
475
-	public function lesson_course_meta_box_content () {
475
+	public function lesson_course_meta_box_content() {
476 476
 		global $post;
477 477
 		// Setup Lesson Meta Data
478 478
 		$selected_lesson_course = 0;
479
-		if ( 0 < $post->ID ) {
480
-			$selected_lesson_course = get_post_meta( $post->ID, '_lesson_course', true );
479
+		if (0 < $post->ID) {
480
+			$selected_lesson_course = get_post_meta($post->ID, '_lesson_course', true);
481 481
 		} // End If Statement
482 482
 		// Handle preselected course
483
-		if ( isset( $_GET[ 'course_id' ] ) && ( 0 < absint( $_GET[ 'course_id' ] ) ) ) {
484
-			$selected_lesson_course = absint( $_GET[ 'course_id' ] );
483
+		if (isset($_GET['course_id']) && (0 < absint($_GET['course_id']))) {
484
+			$selected_lesson_course = absint($_GET['course_id']);
485 485
 		} // End If Statement
486 486
 		// Get the Lesson Posts
487
-		$post_args = array(	'post_type' 		=> 'course',
487
+		$post_args = array('post_type' 		=> 'course',
488 488
 							'posts_per_page' 		=> -1,
489 489
 							'orderby'         	=> 'title',
490 490
     						'order'           	=> 'ASC',
491 491
     						'post_status'      	=> 'any',
492 492
     						'suppress_filters' 	=> 0,
493 493
 							);
494
-		$posts_array = get_posts( $post_args );
494
+		$posts_array = get_posts($post_args);
495 495
 		// Buid the HTML to Output
496 496
 		$html = '';
497 497
 		// Nonce
498
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
498
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
499 499
 
500 500
         // Select the course for the lesson
501 501
         $drop_down_args = array(
@@ -505,67 +505,67 @@  discard block
 block discarded – undo
505 505
 
506 506
         $courses = WooThemes_Sensei_Course::get_all_courses();
507 507
         $courses_options = array();
508
-        foreach( $courses as $course ){
509
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
508
+        foreach ($courses as $course) {
509
+            $courses_options[$course->ID] = get_the_title($course);
510 510
         }
511
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
511
+        $html .= Sensei_Utils::generate_drop_down($selected_lesson_course, $courses_options, $drop_down_args);
512 512
 
513 513
         // Course Actions Panel
514
-		if ( current_user_can( 'publish_courses' )) {
514
+		if (current_user_can('publish_courses')) {
515 515
 				$html .= '<div id="lesson-course-actions">';
516 516
 					$html .= '<p>';
517 517
 						// Add a course action link
518
-						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ ' . __('Add New Course', 'woothemes-sensei' ) . '</a>';
518
+						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ '.__('Add New Course', 'woothemes-sensei').'</a>';
519 519
 					$html .= '</p>';
520 520
 				$html .= '</div>';
521 521
 				// Add a course input fields
522 522
 				$html .= '<div id="lesson-course-details" class="hidden">';
523 523
 					$html .= '<p>';
524 524
 						// Course Title input
525
-						$html .= '<label>' . __( 'Course Title' , 'woothemes-sensei' ) . '</label> ';
525
+						$html .= '<label>'.__('Course Title', 'woothemes-sensei').'</label> ';
526 526
 	  					$html .= '<input type="text" id="course-title" name="course_title" value="" size="25" class="widefat" />';
527 527
 	  					// Course Description input
528
-	  					$html .= '<label>' . __( 'Description' , 'woothemes-sensei' ) . '</label> ';
528
+	  					$html .= '<label>'.__('Description', 'woothemes-sensei').'</label> ';
529 529
 	  					$html .= '<textarea rows="10" cols="40" id="course-content" name="course_content" value="" size="300" class="widefat"></textarea>';
530 530
 	  					// Course Prerequisite
531
-	  					$html .= '<label>' . __( 'Course Prerequisite' , 'woothemes-sensei' ) . '</label> ';
532
-	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n";
533
-							$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
534
-							foreach ($posts_array as $post_item){
535
-								$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '">' . esc_html( $post_item->post_title ) . '</option>' . "\n";
531
+	  					$html .= '<label>'.__('Course Prerequisite', 'woothemes-sensei').'</label> ';
532
+	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n";
533
+							$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
534
+							foreach ($posts_array as $post_item) {
535
+								$html .= '<option value="'.esc_attr(absint($post_item->ID)).'">'.esc_html($post_item->post_title).'</option>'."\n";
536 536
 							} // End For Loop
537
-						$html .= '</select>' . "\n";
537
+						$html .= '</select>'."\n";
538 538
 						// Course Product
539
-                        if ( Sensei_WC::is_woocommerce_active() ) {
539
+                        if (Sensei_WC::is_woocommerce_active()) {
540 540
 	  						// Get the Products
541
-							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
541
+							$select_course_woocommerce_product = get_post_meta($post_item->ID, '_course_woocommerce_product', true);
542 542
 
543
-							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
543
+							$product_args = array('post_type' 		=> array('product', 'product_variation'),
544 544
 													'posts_per_page' 		=> -1,
545 545
 													'orderby'         	=> 'title',
546 546
 	    											'order'           	=> 'DESC',
547
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
547
+	    											'post_status'		=> array('publish', 'private', 'draft'),
548 548
 	    											'tax_query'			=> array(
549 549
 														array(
550 550
 															'taxonomy'	=> 'product_type',
551 551
 															'field'		=> 'slug',
552
-															'terms'		=> array( 'variable', 'grouped' ),
552
+															'terms'		=> array('variable', 'grouped'),
553 553
 															'operator'	=> 'NOT IN'
554 554
 														)
555 555
 													),
556 556
 	    											'suppress_filters' 	=> 0
557 557
 													);
558
-							$products_array = get_posts( $product_args );
559
-							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
560
-	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n";
561
-								$html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>';
558
+							$products_array = get_posts($product_args);
559
+							$html .= '<label>'.__('WooCommerce Product', 'woothemes-sensei').'</label> ';
560
+	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n";
561
+								$html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>';
562 562
 								$prev_parent_id = 0;
563
-								foreach ($products_array as $products_item){
563
+								foreach ($products_array as $products_item) {
564 564
 
565
-									if ( 'product_variation' == $products_item->post_type ) {
566
-										$product_object = get_product( $products_item->ID );
567
-										$parent_id = wp_get_post_parent_id( $products_item->ID );
568
-										$product_name = ucwords( woocommerce_get_formatted_variation( $product_object->variation_data, true ) );
565
+									if ('product_variation' == $products_item->post_type) {
566
+										$product_object = get_product($products_item->ID);
567
+										$parent_id = wp_get_post_parent_id($products_item->ID);
568
+										$product_name = ucwords(woocommerce_get_formatted_variation($product_object->variation_data, true));
569 569
 									} else {
570 570
 										$parent_id = false;
571 571
 										$prev_parent_id = 0;
@@ -573,32 +573,32 @@  discard block
 block discarded – undo
573 573
 									}
574 574
 
575 575
 									// Show variations in groups
576
-									if( $parent_id && $parent_id != $prev_parent_id ) {
577
-										if( 0 != $prev_parent_id ) {
576
+									if ($parent_id && $parent_id != $prev_parent_id) {
577
+										if (0 != $prev_parent_id) {
578 578
 											$html .= '</optgroup>';
579 579
 										}
580
-										$html .= '<optgroup label="' . get_the_title( $parent_id ) . '">';
580
+										$html .= '<optgroup label="'.get_the_title($parent_id).'">';
581 581
 										$prev_parent_id = $parent_id;
582
-									} elseif( ! $parent_id && 0 == $prev_parent_id ) {
582
+									} elseif ( ! $parent_id && 0 == $prev_parent_id) {
583 583
 										$html .= '</optgroup>';
584 584
 									}
585 585
 
586
-									$html .= '<option value="' . esc_attr( absint( $products_item->ID ) ) . '">' . esc_html( $products_item->post_title ) . '</option>' . "\n";
586
+									$html .= '<option value="'.esc_attr(absint($products_item->ID)).'">'.esc_html($products_item->post_title).'</option>'."\n";
587 587
 								} // End For Loop
588
-							$html .= '</select>' . "\n";
588
+							$html .= '</select>'."\n";
589 589
 						} else {
590 590
 							// Default
591 591
 							$html .= '<input type="hidden" name="course_woocommerce_product" id="course-woocommerce-product-options" value="-" />';
592 592
 						}
593 593
 						// Course Category
594
-	  					$html .= '<label>' . __( 'Course Category' , 'woothemes-sensei' ) . '</label> ';
595
-	  					$cat_args = array( 'echo' => false, 'hierarchical' => true, 'show_option_none' => __( 'None', 'woothemes-sensei' ), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat' );
596
-						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args)) . "\n";
594
+	  					$html .= '<label>'.__('Course Category', 'woothemes-sensei').'</label> ';
595
+	  					$cat_args = array('echo' => false, 'hierarchical' => true, 'show_option_none' => __('None', 'woothemes-sensei'), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat');
596
+						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args))."\n";
597 597
 	  					// Save the course action button
598
-	  					$html .= '<a title="' . esc_attr( __( 'Save Course', 'woothemes-sensei' ) ) . '" href="#add-course-metadata" class="lesson_course_save button button-highlighted">' . esc_html( __( 'Add Course', 'woothemes-sensei' ) ) . '</a>';
598
+	  					$html .= '<a title="'.esc_attr(__('Save Course', 'woothemes-sensei')).'" href="#add-course-metadata" class="lesson_course_save button button-highlighted">'.esc_html(__('Add Course', 'woothemes-sensei')).'</a>';
599 599
 						$html .= '&nbsp;&nbsp;&nbsp;';
600 600
 						// Cancel action link
601
-						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">' . __( 'Cancel', 'woothemes-sensei' ) . '</a>';
601
+						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">'.__('Cancel', 'woothemes-sensei').'</a>';
602 602
 					$html .= '</p>';
603 603
 				$html .= '</div>';
604 604
 			} // End If Statement
@@ -607,20 +607,20 @@  discard block
 block discarded – undo
607 607
 		echo $html;
608 608
 	} // End lesson_course_meta_box_content()
609 609
 
610
-	public function quiz_panel( $quiz_id = 0 ) {
610
+	public function quiz_panel($quiz_id = 0) {
611 611
 
612
-		$html = wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
612
+		$html = wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
613 613
 		$html .= '<div id="add-quiz-main">';
614
-			if ( 0 == $quiz_id ) {
614
+			if (0 == $quiz_id) {
615 615
 				$html .= '<p>';
616 616
 					// Default message and Add a Quiz button
617
-					$html .= esc_html( __( 'Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei' ) );
617
+					$html .= esc_html(__('Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei'));
618 618
 				$html .= '</p>';
619 619
 			}
620 620
 
621 621
 			// Quiz Panel CSS Class
622 622
 			$quiz_class = '';
623
-			if ( 0 == $quiz_id ) {
623
+			if (0 == $quiz_id) {
624 624
 				$quiz_class = ' class="hidden"';
625 625
 			} // End If Statement
626 626
 			// Build the HTML to Output
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 
629 629
 			// Setup Questions Query
630 630
 			$questions = array();
631
-			if ( 0 < $quiz_id ) {
632
-				$questions = $this->lesson_quiz_questions( $quiz_id );
631
+			if (0 < $quiz_id) {
632
+				$questions = $this->lesson_quiz_questions($quiz_id);
633 633
 			} // End If Statement
634 634
 
635 635
 			$question_count = 0;
636
-			foreach( $questions as $question ) {
636
+			foreach ($questions as $question) {
637 637
 
638
-				if( $question->post_type == 'multiple_question' ) {
639
-					$question_number = get_post_meta( $question->ID, 'number', true );
638
+				if ($question->post_type == 'multiple_question') {
639
+					$question_number = get_post_meta($question->ID, 'number', true);
640 640
 					$question_count += $question_number;
641 641
 				} else {
642 642
 					++$question_count;
@@ -645,68 +645,68 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 
647 647
 			// Inner DIV
648
-			$html .= '<div id="add-quiz-metadata"' . $quiz_class . '>';
648
+			$html .= '<div id="add-quiz-metadata"'.$quiz_class.'>';
649 649
 
650 650
 				// Quiz ID
651
-				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="' . esc_attr( $quiz_id ) . '" />';
651
+				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="'.esc_attr($quiz_id).'" />';
652 652
 
653 653
 				// Default Message
654
-				if ( 0 == $quiz_id ) {
654
+				if (0 == $quiz_id) {
655 655
 					$html .= '<p class="save-note">';
656
-						$html .= esc_html( __( 'Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei' ) );
656
+						$html .= esc_html(__('Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei'));
657 657
 					$html .= '</p>';
658 658
 				} // End If Statement
659 659
 
660 660
 			$html .= '</div>';
661 661
 
662 662
 			// Question Container DIV
663
-			$html .= '<div id="add-question-main"' . $quiz_class . '>';
663
+			$html .= '<div id="add-question-main"'.$quiz_class.'>';
664 664
 				// Inner DIV
665 665
 				$html .= '<div id="add-question-metadata">';
666 666
 
667 667
 					// Count of questions
668
-					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="' . esc_attr( $question_count ) . '" />';
668
+					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="'.esc_attr($question_count).'" />';
669 669
 					// Table headers
670 670
 					$html .= '<table class="widefat" id="sortable-questions">
671 671
 								<thead>
672 672
 								    <tr>
673 673
 								        <th class="question-count-column">#</th>
674
-								        <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
675
-								        <th style="width:45px;">' . __( 'Grade', 'woothemes-sensei' ) . '</th>
676
-								        <th style="width:125px;">' . __( 'Type', 'woothemes-sensei' ) . '</th>
677
-								        <th style="width:125px;">' . __( 'Action', 'woothemes-sensei' ) . '</th>
674
+								        <th>' . __('Question', 'woothemes-sensei').'</th>
675
+								        <th style="width:45px;">' . __('Grade', 'woothemes-sensei').'</th>
676
+								        <th style="width:125px;">' . __('Type', 'woothemes-sensei').'</th>
677
+								        <th style="width:125px;">' . __('Action', 'woothemes-sensei').'</th>
678 678
 								    </tr>
679 679
 								</thead>
680 680
 								<tfoot>
681 681
 								    <tr>
682 682
 									    <th class="question-count-column">#</th>
683
-									    <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
684
-									    <th>' . __( 'Grade', 'woothemes-sensei' ) . '</th>
685
-									    <th>' . __( 'Type', 'woothemes-sensei' ) . '</th>
686
-									    <th>' . __( 'Action', 'woothemes-sensei' ) . '</th>
683
+									    <th>' . __('Question', 'woothemes-sensei').'</th>
684
+									    <th>' . __('Grade', 'woothemes-sensei').'</th>
685
+									    <th>' . __('Type', 'woothemes-sensei').'</th>
686
+									    <th>' . __('Action', 'woothemes-sensei').'</th>
687 687
 								    </tr>
688 688
 								</tfoot>';
689 689
 
690 690
 					$message_class = '';
691
-					if ( 0 < $question_count ) { $message_class = 'hidden'; }
691
+					if (0 < $question_count) { $message_class = 'hidden'; }
692 692
 
693
-					$html .= '<tbody id="no-questions-message" class="' . esc_attr( $message_class ) . '">';
693
+					$html .= '<tbody id="no-questions-message" class="'.esc_attr($message_class).'">';
694 694
 						$html .= '<tr>';
695
-							$html .= '<td colspan="5">' . __( 'There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei' ) . '</td>';
695
+							$html .= '<td colspan="5">'.__('There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei').'</td>';
696 696
 						$html .= '</tr>';
697 697
 					$html .= '</tbody>';
698 698
 
699
-					if( 0 < $question_count ) {
700
-						$html .= $this->quiz_panel_questions( $questions );
699
+					if (0 < $question_count) {
700
+						$html .= $this->quiz_panel_questions($questions);
701 701
 					}
702 702
 
703 703
 					$html .= '</table>';
704 704
 
705
-					if( ! isset( $this->question_order ) ) {
705
+					if ( ! isset($this->question_order)) {
706 706
 						$this->question_order = '';
707 707
 					}
708 708
 
709
-					$html .= '<input type="hidden" id="question-order" name="question-order" value="' . $this->question_order . '" />';
709
+					$html .= '<input type="hidden" id="question-order" name="question-order" value="'.$this->question_order.'" />';
710 710
 
711 711
 				$html .= '</div>';
712 712
 
@@ -725,47 +725,47 @@  discard block
 block discarded – undo
725 725
 
726 726
 	}
727 727
 
728
-	public function quiz_panel_questions( $questions = array() ) {
728
+	public function quiz_panel_questions($questions = array()) {
729 729
 		global $quiz_questions;
730 730
 
731 731
 		$quiz_questions = $questions;
732 732
 
733 733
 		$html = '';
734 734
 
735
-		if( count( $questions ) > 0 ) {
735
+		if (count($questions) > 0) {
736 736
 
737 737
 			$question_class = '';
738 738
 			$question_counter = 1;
739 739
 
740
-			foreach ( $questions as $question ) {
740
+			foreach ($questions as $question) {
741 741
 
742 742
 				$question_id = $question->ID;
743 743
 
744
-				$question_type = Sensei()->question->get_question_type( $question_id );
744
+				$question_type = Sensei()->question->get_question_type($question_id);
745 745
 
746 746
 				$multiple_data = array();
747 747
 				$question_increment = 1;
748
-				if( 'multiple_question' == $question->post_type ) {
748
+				if ('multiple_question' == $question->post_type) {
749 749
 					$question_type = 'category';
750 750
 
751
-					$question_category = get_post_meta( $question->ID, 'category', true );
752
-					$question_cat = get_term( $question_category, 'question-category' );
751
+					$question_category = get_post_meta($question->ID, 'category', true);
752
+					$question_cat = get_term($question_category, 'question-category');
753 753
 
754
-					$question_number = get_post_meta( $question->ID, 'number', true );
754
+					$question_number = get_post_meta($question->ID, 'number', true);
755 755
 					$question_increment = $question_number;
756 756
 
757
-					$multiple_data = array( $question_cat->name, $question_number );
757
+					$multiple_data = array($question_cat->name, $question_number);
758 758
 				}
759 759
 
760
-				if( ! $question_type ) {
760
+				if ( ! $question_type) {
761 761
 					$question_type = 'multiple-choice';
762 762
 				}
763 763
 
764 764
 				// Row with question and actions
765
-				$html .= $this->quiz_panel_question( $question_type, $question_counter, $question_id, 'quiz', $multiple_data );
765
+				$html .= $this->quiz_panel_question($question_type, $question_counter, $question_id, 'quiz', $multiple_data);
766 766
 				$question_counter += $question_increment;
767 767
 
768
-				if( isset( $this->question_order ) && strlen( $this->question_order ) > 0 ) { $this->question_order .= ','; }
768
+				if (isset($this->question_order) && strlen($this->question_order) > 0) { $this->question_order .= ','; }
769 769
 				$this->question_order .= $question_id;
770 770
 			} // End For Loop
771 771
 		}
@@ -774,161 +774,161 @@  discard block
 block discarded – undo
774 774
 
775 775
 	}
776 776
 
777
-	public function quiz_panel_question( $question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array() ) {
778
-		global $row_counter,  $quiz_questions;
777
+	public function quiz_panel_question($question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array()) {
778
+		global $row_counter, $quiz_questions;
779 779
 
780 780
 		$html = '';
781 781
 
782 782
 		$question_class = '';
783
-		if( 'quiz' == $context ) {
784
-			if( ! $row_counter || ! isset( $row_counter ) ) {
783
+		if ('quiz' == $context) {
784
+			if ( ! $row_counter || ! isset($row_counter)) {
785 785
 				$row_counter = 1;
786 786
 			}
787
-			if( $row_counter % 2 ) { $question_class = 'alternate'; }
787
+			if ($row_counter % 2) { $question_class = 'alternate'; }
788 788
 			++$row_counter;
789 789
 		}
790 790
 
791
-		if( $question_id ) {
791
+		if ($question_id) {
792 792
 
793
-			if( $question_type != 'category' ) {
793
+			if ($question_type != 'category') {
794 794
 
795
-				$question_grade = Sensei()->question->get_question_grade( $question_id );
795
+				$question_grade = Sensei()->question->get_question_grade($question_id);
796 796
 
797
-				$question_media = get_post_meta( $question_id, '_question_media', true );
797
+				$question_media = get_post_meta($question_id, '_question_media', true);
798 798
 				$question_media_type = $question_media_thumb = $question_media_link = $question_media_title = '';
799 799
 				$question_media_thumb_class = $question_media_link_class = $question_media_delete_class = 'hidden';
800
-				$question_media_add_button = __( 'Add file', 'woothemes-sensei' );
801
-				if( 0 < intval( $question_media ) ) {
802
-					$mimetype = get_post_mime_type( $question_media );
803
-					if( $mimetype ) {
804
-						$mimetype_array = explode( '/', $mimetype);
805
-						if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
800
+				$question_media_add_button = __('Add file', 'woothemes-sensei');
801
+				if (0 < intval($question_media)) {
802
+					$mimetype = get_post_mime_type($question_media);
803
+					if ($mimetype) {
804
+						$mimetype_array = explode('/', $mimetype);
805
+						if (isset($mimetype_array[0]) && $mimetype_array[0]) {
806 806
 							$question_media_delete_class = '';
807 807
 							$question_media_type = $mimetype_array[0];
808
-							if( 'image' == $question_media_type ) {
809
-								$question_media_thumb = wp_get_attachment_thumb_url( $question_media );
810
-								if( $question_media_thumb ) {
808
+							if ('image' == $question_media_type) {
809
+								$question_media_thumb = wp_get_attachment_thumb_url($question_media);
810
+								if ($question_media_thumb) {
811 811
 									$question_media_thumb_class = '';
812 812
 								}
813 813
 							}
814
-							$question_media_url = wp_get_attachment_url( $question_media );
815
-							if( $question_media_url ) {
816
-								$attachment = get_post( $question_media );
814
+							$question_media_url = wp_get_attachment_url($question_media);
815
+							if ($question_media_url) {
816
+								$attachment = get_post($question_media);
817 817
 								$question_media_title = $attachment->post_title;
818 818
 
819
-								if( ! $question_media_title ) {
820
-									$question_media_filename = basename( $question_media_url );
819
+								if ( ! $question_media_title) {
820
+									$question_media_filename = basename($question_media_url);
821 821
 									$question_media_title = $question_media_filename;
822 822
 								}
823
-								$question_media_link = '<a class="' . $question_media_type . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_title . '</a>';
823
+								$question_media_link = '<a class="'.$question_media_type.'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_title.'</a>';
824 824
 								$question_media_link_class = '';
825 825
 							}
826 826
 
827
-							$question_media_add_button = __( 'Change file', 'woothemes-sensei' );
827
+							$question_media_add_button = __('Change file', 'woothemes-sensei');
828 828
 						}
829 829
 					}
830 830
 				}
831 831
 
832
-				$random_order = get_post_meta( $question_id, '_random_order', true );
833
-				if( ! $random_order ) {
832
+				$random_order = get_post_meta($question_id, '_random_order', true);
833
+				if ( ! $random_order) {
834 834
 					$random_order = 'yes';
835 835
 				}
836 836
 
837
-				if( ! $question_type ) { $question_type = 'multiple-choice'; }
837
+				if ( ! $question_type) { $question_type = 'multiple-choice'; }
838 838
 			}
839 839
 
840
-			$html .= '<tbody class="' . $question_class . '">';
840
+			$html .= '<tbody class="'.$question_class.'">';
841 841
 
842
-				if( 'quiz' == $context ) {
842
+				if ('quiz' == $context) {
843 843
 					$html .= '<tr>';
844
-						if( $question_type != 'category' ) {
845
-							$question = get_post( $question_id );
846
-							$html .= '<td class="table-count question-number question-count-column"><span class="number">' . $question_counter . '</span></td>';
847
-							$html .= '<td>' . esc_html( $question->post_title ) . '</td>';
848
-							$html .= '<td class="question-grade-column">' . esc_html( $question_grade ) . '</td>';
849
-							$question_types_filtered = ucwords( str_replace( array( '-', 'boolean' ), array( ' ', __( 'True/False', 'woothemes-sensei' ) ), $question_type ) );
850
-							$html .= '<td>' . esc_html( $question_types_filtered ) . '</td>';
851
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_delete">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
844
+						if ($question_type != 'category') {
845
+							$question = get_post($question_id);
846
+							$html .= '<td class="table-count question-number question-count-column"><span class="number">'.$question_counter.'</span></td>';
847
+							$html .= '<td>'.esc_html($question->post_title).'</td>';
848
+							$html .= '<td class="question-grade-column">'.esc_html($question_grade).'</td>';
849
+							$question_types_filtered = ucwords(str_replace(array('-', 'boolean'), array(' ', __('True/False', 'woothemes-sensei')), $question_type));
850
+							$html .= '<td>'.esc_html($question_types_filtered).'</td>';
851
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_delete">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
852 852
 
853 853
 						} else {
854 854
 
855
-							$end_number = intval( $question_counter ) + intval( $multiple_data[1] ) - 1;
856
-							if( $question_counter == $end_number ) {
855
+							$end_number = intval($question_counter) + intval($multiple_data[1]) - 1;
856
+							if ($question_counter == $end_number) {
857 857
 								$row_numbers = $question_counter;
858 858
 							} else {
859
-								$row_numbers = $question_counter . ' - ' . $end_number;
859
+								$row_numbers = $question_counter.' - '.$end_number;
860 860
 							}
861
-							$row_title = sprintf( __( 'Selected from \'%1$s\' ', 'woothemes-sensei' ), $multiple_data[0] );
861
+							$row_title = sprintf(__('Selected from \'%1$s\' ', 'woothemes-sensei'), $multiple_data[0]);
862 862
 
863
-							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">' . $question_counter . '</span><span class="hidden total-number">' . $multiple_data[1] . '</span><span class="row-numbers">' . esc_html( $row_numbers ) . '</span></td>';
864
-							$html .= '<td>' . esc_html( $row_title ) . '</td>';
863
+							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">'.$question_counter.'</span><span class="hidden total-number">'.$multiple_data[1].'</span><span class="row-numbers">'.esc_html($row_numbers).'</span></td>';
864
+							$html .= '<td>'.esc_html($row_title).'</td>';
865 865
 							$html .= '<td class="question-grade-column"></td>';
866
-							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" /></td>';
867
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit" style="visibility:hidden;">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question(s)', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_multiple_delete" rel="' . $question_id . '">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
866
+							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" /></td>';
867
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit" style="visibility:hidden;">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question(s)', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_multiple_delete" rel="'.$question_id.'">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
868 868
 
869 869
 						}
870 870
 					$html .= '</tr>';
871 871
 				}
872 872
 
873
-				if( $question_type != 'category' ) {
873
+				if ($question_type != 'category') {
874 874
 
875 875
 					$edit_class = '';
876
-					if( 'quiz' == $context ) {
876
+					if ('quiz' == $context) {
877 877
 						$edit_class = 'hidden';
878 878
 					}
879 879
 
880
-					$question = get_post( $question_id );
881
-					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
880
+					$question = get_post($question_id);
881
+					$html .= '<tr class="question-quick-edit '.esc_attr($edit_class).'">';
882 882
 						$html .= '<td colspan="5">';
883
-							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
883
+							$html .= '<span class="hidden question_original_counter">'.$question_counter.'</span>';
884 884
 					    	$html .= '<div class="question_required_fields">';
885 885
 
886 886
 						    	// Question title
887 887
 						    	$html .= '<div>';
888
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
889
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
888
+							    	$html .= '<label for="question_'.$question_counter.'">'.__('Question:', 'woothemes-sensei').'</label> ';
889
+							    	$html .= '<input type="text" id="question_'.$question_counter.'" name="question" value="'.esc_attr(htmlspecialchars($question->post_title)).'" size="25" class="widefat" />';
890 890
 						    	$html .= '</div>';
891 891
 
892 892
 						    	// Question description
893 893
 						    	$html .= '<div>';
894
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
894
+							    	$html .= '<label for="question_'.$question_counter.'_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
895 895
 						    	$html .= '</div>';
896
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
896
+							    	$html .= '<textarea id="question_'.$question_counter.'_desc" name="question_description" class="widefat" rows="4">'.esc_textarea($question->post_content).'</textarea>';
897 897
 
898 898
 						    	// Question grade
899 899
 						    	$html .= '<div>';
900
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
901
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
900
+							    	$html .= '<label for="question_'.$question_counter.'_grade">'.__('Question grade:', 'woothemes-sensei').'</label> ';
901
+							    	$html .= '<input type="number" id="question_'.$question_counter.'_grade" class="question_grade small-text" name="question_grade" min="0" value="'.$question_grade.'" />';
902 902
 						    	$html .= '</div>';
903 903
 
904 904
 						    	// Random order
905
-						    	if( $question_type == 'multiple-choice' ) {
905
+						    	if ($question_type == 'multiple-choice') {
906 906
 						    		$html .= '<div>';
907
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
907
+						    			$html .= '<label for="'.$question_counter.'_random_order"><input type="checkbox" name="random_order" class="random_order" id="'.$question_counter.'_random_order" value="yes" '.checked($random_order, 'yes', false).' /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
908 908
 						    		$html .= '</div>';
909 909
 						    	}
910 910
 
911 911
 						    	// Question media
912 912
 						    	$html .= '<div>';
913
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
914
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
915
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
916
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
917
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
918
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
913
+							    	$html .= '<label for="question_'.$question_counter.'_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
914
+							    	$html .= '<button id="question_'.$question_counter.'_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.$question_media_add_button.'</button>';
915
+							    	$html .= '<button id="question_'.$question_counter.'_media_button_delete" class="delete_media_file_button button-secondary '.$question_media_delete_class.'">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
916
+							    	$html .= '<span id="question_'.$question_counter.'_media_link" class="question_media_link '.$question_media_link_class.'">'.$question_media_link.'</span>';
917
+							    	$html .= '<br/><img id="question_'.$question_counter.'_media_preview" class="question_media_preview '.$question_media_thumb_class.'" src="'.$question_media_thumb.'" /><br/>';
918
+							    	$html .= '<input type="hidden" id="question_'.$question_counter.'_media" class="question_media" name="question_media" value="'.$question_media.'" />';
919 919
 						    	$html .= '</div>';
920 920
 
921 921
 						    $html .= '</div>';
922 922
 
923
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
923
+						    $html .= $this->quiz_panel_question_field($question_type, $question_id, $question_counter);
924 924
 
925
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
926
-							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
925
+						    $html .= '<input type="hidden" id="question_'.$question_counter.'_question_type" class="question_type" name="question_type" value="'.$question_type.'" />';
926
+							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" />';
927 927
 
928
-							if( 'quiz' == $context ) {
928
+							if ('quiz' == $context) {
929 929
 					    		$html .= '<div class="update-question">';
930
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
931
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
930
+						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="'.esc_attr(__('Cancel', 'woothemes-sensei')).'">'.__('Cancel', 'woothemes-sensei').'</a> ';
931
+						    		$html .= '<a title="'.esc_attr(__('Update Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_save button button-highlighted">'.esc_html(__('Update', 'woothemes-sensei')).'</a>';
932 932
 					    		$html .= '</div>';
933 933
 					    	}
934 934
 
@@ -943,79 +943,79 @@  discard block
 block discarded – undo
943 943
 		return $html;
944 944
 	}
945 945
 
946
-	public function quiz_panel_add( $context = 'quiz' ) {
946
+	public function quiz_panel_add($context = 'quiz') {
947 947
 
948 948
 
949 949
 		$html = '<div id="add-new-question">';
950 950
 
951 951
 			$question_types = Sensei()->question->question_types();
952 952
 
953
-			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
953
+			$question_cats = get_terms('question-category', array('hide_empty' => false));
954 954
 
955
-			if( 'quiz' == $context ) {
955
+			if ('quiz' == $context) {
956 956
 	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
957
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
958
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
959
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
960
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
957
+	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">'.__('New Question', 'woothemes-sensei').'</a>';
958
+	    			$html .= '<a id="tab-existing" class="nav-tab">'.__('Existing Questions', 'woothemes-sensei').'</a>';
959
+                    if ( ! empty($question_cats) && ! is_wp_error($question_cats) && ! Sensei()->teacher->is_admin_teacher()) {
960
+	    				$html .= '<a id="tab-multiple" class="nav-tab">'.__('Category Questions', 'woothemes-sensei').'</a>';
961 961
 	    			}
962 962
 	    		$html .= '</h2>';
963 963
 	    	}
964 964
 
965 965
 	    	$html .= '<div class="tab-content" id="tab-new-content">';
966 966
 
967
-	    		if( 'quiz' == $context ) {
968
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
967
+	    		if ('quiz' == $context) {
968
+	    			$html .= '<p><em>'.sprintf(__('Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
969 969
 	    		}
970 970
 
971 971
 				$html .= '<div class="question">';
972 972
 					$html .= '<div class="question_required_fields">';
973 973
 
974 974
 						// Question title
975
-						$html .= '<p><label>' . __( 'Question:'  , 'woothemes-sensei' ) . '</label> ';
975
+						$html .= '<p><label>'.__('Question:', 'woothemes-sensei').'</label> ';
976 976
 	  					$html .= '<input type="text" id="add_question" name="question" value="" size="25" class="widefat" /></p>';
977 977
 
978 978
 						// Question description
979 979
 						$html .= '<p>';
980
-							$html .= '<label for="question_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
980
+							$html .= '<label for="question_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
981 981
 						$html .= '</p>';
982 982
 						$html .= '<textarea id="question_desc" name="question_description" class="widefat" rows="4"></textarea>';
983 983
 
984 984
 	  					// Question type
985
-						$html .= '<p><label>' . __( 'Question Type:' , 'woothemes-sensei' ) . '</label> ';
986
-						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">' . "\n";
987
-							foreach ( $question_types as $type => $label ) {
988
-								$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>' . "\n";
985
+						$html .= '<p><label>'.__('Question Type:', 'woothemes-sensei').'</label> ';
986
+						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">'."\n";
987
+							foreach ($question_types as $type => $label) {
988
+								$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>'."\n";
989 989
 							} // End For Loop
990
-						$html .= '</select></p>' . "\n";
990
+						$html .= '</select></p>'."\n";
991 991
 
992 992
 						// Question category
993
-						if( 'quiz' == $context ) {
994
-							if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
995
-								$html .= '<p><label>' . __( 'Question Category:' , 'woothemes-sensei' ) . '</label> ';
996
-								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">' . "\n";
997
-								$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>' . "\n";
998
-								foreach( $question_cats as $cat ) {
999
-									$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
993
+						if ('quiz' == $context) {
994
+							if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
995
+								$html .= '<p><label>'.__('Question Category:', 'woothemes-sensei').'</label> ';
996
+								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">'."\n";
997
+								$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'."\n";
998
+								foreach ($question_cats as $cat) {
999
+									$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1000 1000
 								} // End For Loop
1001
-								$html .= '</select></p>' . "\n";
1001
+								$html .= '</select></p>'."\n";
1002 1002
 							}
1003 1003
 						}
1004 1004
 
1005 1005
 	  					// Question grade
1006
-						$html .= '<p><label>' . __( 'Question Grade:'  , 'woothemes-sensei' ) . '</label> ';
1007
-						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>' . "\n";
1006
+						$html .= '<p><label>'.__('Question Grade:', 'woothemes-sensei').'</label> ';
1007
+						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>'."\n";
1008 1008
 
1009 1009
 						// Random order
1010 1010
 						$html .= '<p class="add_question_random_order">';
1011
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1011
+			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
1012 1012
 			    		$html .= '</p>';
1013 1013
 
1014 1014
 			    		// Question media
1015 1015
 						$html .= '<p>';
1016
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1017
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1018
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1016
+					    	$html .= '<label for="question_add_new_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
1017
+					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.__('Add file', 'woothemes-sensei').'</button>';
1018
+					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
1019 1019
 					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1020 1020
 					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1021 1021
 					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
@@ -1024,44 +1024,44 @@  discard block
 block discarded – undo
1024 1024
 					$html .= '</div>';
1025 1025
 				$html .= '</div>';
1026 1026
 
1027
-				foreach ( $question_types as $type => $label ) {
1028
-					$html .= $this->quiz_panel_question_field( $type );
1027
+				foreach ($question_types as $type => $label) {
1028
+					$html .= $this->quiz_panel_question_field($type);
1029 1029
 				}
1030 1030
 
1031
-				if( 'quiz' == $context ) {
1031
+				if ('quiz' == $context) {
1032 1032
 					$html .= '<div class="add-question">';
1033
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1033
+			    		$html .= '<a title="'.esc_attr(__('Add Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">'.esc_html(__('Add Question', 'woothemes-sensei')).'</a>';
1034 1034
 		    		$html .= '</div>';
1035 1035
 		    	}
1036 1036
 
1037 1037
 		    $html .= '</div>';
1038 1038
 
1039
-		    if( 'quiz' == $context ) {
1039
+		    if ('quiz' == $context) {
1040 1040
 
1041 1041
 			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1042 1042
 
1043
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1043
+			    	$html .= '<p><em>'.sprintf(__('Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
1044 1044
 
1045 1045
 			    	$html .= '<div id="existing-filters" class="alignleft actions">
1046 1046
 			    				<select id="existing-status">
1047
-			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1048
-			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
1049
-			    					<option value="used">' . __( 'Used', 'woothemes-sensei' ) . '</option>
1047
+			    					<option value="all">' . __('All', 'woothemes-sensei').'</option>
1048
+			    					<option value="unused">' . __('Unused', 'woothemes-sensei').'</option>
1049
+			    					<option value="used">' . __('Used', 'woothemes-sensei').'</option>
1050 1050
 			    				</select>
1051 1051
 			    				<select id="existing-type">
1052
-			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1053
-							    	foreach ( $question_types as $type => $label ) {
1054
-										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1052
+			    					<option value="">' . __('All Types', 'woothemes-sensei').'</option>';
1053
+							    	foreach ($question_types as $type => $label) {
1054
+										$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>';
1055 1055
 									}
1056 1056
     				$html .= '</select>
1057 1057
     							<select id="existing-category">
1058
-			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1059
-				    				foreach( $question_cats as $cat ) {
1060
-										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1058
+			    					<option value="">' . __('All Categories', 'woothemes-sensei').'</option>';
1059
+				    				foreach ($question_cats as $cat) {
1060
+										$html .= '<option value="'.esc_attr($cat->slug).'">'.esc_html($cat->name).'</option>';
1061 1061
 									}
1062 1062
     				$html .= '</select>
1063
-    							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1064
-    							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1063
+    							<input type="text" id="existing-search" placeholder="' . __('Search', 'woothemes-sensei').'" />
1064
+    							<a class="button" id="existing-filter-button">' . __('Filter', 'woothemes-sensei').'</a>
1065 1065
 			    			</div>';
1066 1066
 
1067 1067
 			    	$html .= '<table id="existing-table" class="widefat">';
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
 			    		$html .= '<thead>
1070 1070
 									    <tr>
1071 1071
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1072
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1073
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1074
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1072
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1073
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1074
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1075 1075
 									    </tr>
1076 1076
 									</thead>
1077 1077
 									<tfoot>
1078 1078
 									    <tr>
1079 1079
 										    <th scope="col" class="check-column"><input type="checkbox" /></th>
1080
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1081
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1082
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1080
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1081
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1082
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1083 1083
 									    </tr>
1084 1084
 									</tfoot>';
1085 1085
 						$html .= '<tbody id="existing-questions">';
@@ -1087,8 +1087,8 @@  discard block
 block discarded – undo
1087 1087
 						$questions = $this->quiz_panel_get_existing_questions();
1088 1088
 
1089 1089
 						$row = 1;
1090
-						foreach( $questions['questions'] as $question ) {
1091
-							$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1090
+						foreach ($questions['questions'] as $question) {
1091
+							$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1092 1092
 							++$row;
1093 1093
 						}
1094 1094
 
@@ -1097,36 +1097,36 @@  discard block
 block discarded – undo
1097 1097
 			    	$html .= '</table>';
1098 1098
 
1099 1099
 			    	$next_class = '';
1100
-			    	if( $questions['count'] <= 10 ) {
1100
+			    	if ($questions['count'] <= 10) {
1101 1101
 			    		$next_class = 'hidden';
1102 1102
 			    	}
1103 1103
 
1104 1104
 			    	$html .= '<div id="existing-pagination">';
1105 1105
 			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1106
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1106
+			    		$html .= '<a class="prev no-paging">&larr; '.__('Previous', 'woothemes-sensei').'</a> <a class="next '.esc_attr($next_class).'">'.__('Next', 'woothemes-sensei').' &rarr;</a>';
1107 1107
 			    	$html .= '</div>';
1108 1108
 
1109 1109
 			    	$html .= '<div class="existing-actions">';
1110
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1110
+			    		$html .= '<a title="'.esc_attr(__('Add Selected Question(s)', 'woothemes-sensei')).'" class="add_existing_save button button-primary button-highlighted">'.esc_html(__('Add Selected Question(s)', 'woothemes-sensei')).'</a></p>';
1111 1111
 			    	$html .= '</div>';
1112 1112
 
1113 1113
 			    $html .= '</div>';
1114 1114
 
1115
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1115
+			    if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
1116 1116
 				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1117 1117
 
1118
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1118
+				    	$html .= '<p><em>'.sprintf(__('Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit-tags.php?taxonomy=question-category&post_type=question').'">', '</a>').'</em></p>';
1119 1119
 
1120
-						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1121
-						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
1122
-						foreach( $question_cats as $cat ) {
1123
-							$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
1120
+						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">'."\n";
1121
+						$html .= '<option value="">'.__('Select a Question Category', 'woothemes-sensei').'</option>'."\n";
1122
+						foreach ($question_cats as $cat) {
1123
+							$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1124 1124
 						} // End For Loop
1125
-						$html .= '</select></p>' . "\n";
1125
+						$html .= '</select></p>'."\n";
1126 1126
 
1127
-						$html .= '<p>' . __( 'Number of questions:', 'woothemes-sensei' ) . ' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1127
+						$html .= '<p>'.__('Number of questions:', 'woothemes-sensei').' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1128 1128
 
1129
-						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1129
+						$html .= '<a title="'.esc_attr(__('Add Question(s)', 'woothemes-sensei')).'" class="add_multiple_save button button-primary button-highlighted">'.esc_html(__('Add Question(s)', 'woothemes-sensei')).'</a></p>';
1130 1130
 
1131 1131
 				    $html .= '</div>';
1132 1132
 				}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 		return $html;
1138 1138
 	}
1139 1139
 
1140
-	public function quiz_panel_get_existing_questions( $question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1 ) {
1140
+	public function quiz_panel_get_existing_questions($question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1) {
1141 1141
 
1142 1142
 		$args = array(
1143 1143
 			'post_type' => 'question',
@@ -1146,14 +1146,14 @@  discard block
 block discarded – undo
1146 1146
 			'suppress_filters' => 0,
1147 1147
 		);
1148 1148
 
1149
-		switch( $question_status ) {
1149
+		switch ($question_status) {
1150 1150
 			case 'unused': $quiz_status = 'NOT EXISTS'; break;
1151 1151
 			case 'used': $quiz_status = 'EXISTS'; break;
1152 1152
 			default: $quiz_status = ''; break;
1153 1153
 		}
1154 1154
 
1155
-		if( $quiz_status ) {
1156
-			switch( $quiz_status ) {
1155
+		if ($quiz_status) {
1156
+			switch ($quiz_status) {
1157 1157
 				case 'EXISTS':
1158 1158
 					$args['meta_query'][] = array(
1159 1159
 						'key' => '_quiz_id',
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
 			}
1172 1172
 		}
1173 1173
 
1174
-		if( $question_type ) {
1174
+		if ($question_type) {
1175 1175
 			$args['tax_query'][] = array(
1176 1176
 				'taxonomy' => 'question-type',
1177 1177
 				'field' => 'slug',
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 			);
1180 1180
 		}
1181 1181
 
1182
-		if( $question_category ) {
1182
+		if ($question_category) {
1183 1183
 			$args['tax_query'][] = array(
1184 1184
 				'taxonomy' => 'question-category',
1185 1185
 				'field' => 'slug',
@@ -1187,19 +1187,19 @@  discard block
 block discarded – undo
1187 1187
 			);
1188 1188
 		}
1189 1189
 
1190
-		if( $question_type && $question_category ) {
1190
+		if ($question_type && $question_category) {
1191 1191
 			$args['tax_query']['relation'] = 'AND';
1192 1192
 		}
1193 1193
 
1194
-		if( $question_search ) {
1194
+		if ($question_search) {
1195 1195
 			$args['s'] = $question_search;
1196 1196
 		}
1197 1197
 
1198
-		if( $page ) {
1198
+		if ($page) {
1199 1199
 			$args['paged'] = $page;
1200 1200
 		}
1201 1201
 
1202
-		$qry = new WP_Query( $args );
1202
+		$qry = new WP_Query($args);
1203 1203
 
1204 1204
         /**
1205 1205
          * Filter existing questions query
@@ -1208,39 +1208,39 @@  discard block
 block discarded – undo
1208 1208
          *
1209 1209
          * @param WP_Query $wp_query
1210 1210
          */
1211
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1211
+        $qry = apply_filters('sensei_existing_questions_query_results', $qry);
1212 1212
 
1213 1213
 		$questions['questions'] = $qry->posts;
1214
-		$questions['count'] = intval( $qry->found_posts );
1214
+		$questions['count'] = intval($qry->found_posts);
1215 1215
 		$questions['page'] = $page;
1216 1216
 
1217 1217
 		return $questions;
1218 1218
 	}
1219 1219
 
1220
-	public function quiz_panel_add_existing_question( $question_id = 0, $row = 1 ) {
1220
+	public function quiz_panel_add_existing_question($question_id = 0, $row = 1) {
1221 1221
 
1222 1222
 		$html = '';
1223 1223
 
1224
-		if( ! $question_id ) {
1224
+		if ( ! $question_id) {
1225 1225
 
1226 1226
             return;
1227 1227
 
1228 1228
         }
1229 1229
 
1230 1230
 		$existing_class = '';
1231
-		if( $row % 2 ) {
1231
+		if ($row % 2) {
1232 1232
             $existing_class = 'alternate';
1233 1233
         }
1234 1234
 
1235
-		$question_type = Sensei()->question->get_question_type( $question_id );
1235
+		$question_type = Sensei()->question->get_question_type($question_id);
1236 1236
 
1237
-		$question_cat_list = strip_tags( get_the_term_list( $question_id, 'question-category', '', ', ', '' ) );
1237
+		$question_cat_list = strip_tags(get_the_term_list($question_id, 'question-category', '', ', ', ''));
1238 1238
 
1239
-		$html .= '<tr class="' . esc_attr( $existing_class ) . '">
1240
-					<td class="cb"><input type="checkbox" value="' . $question_id . '" class="existing-item" /></td>
1241
-					<td>' . get_the_title( $question_id ) . '</td>
1242
-					<td>' . esc_html( $question_type ) . '</td>
1243
-					<td>' . esc_html( $question_cat_list ) . '</td>
1239
+		$html .= '<tr class="'.esc_attr($existing_class).'">
1240
+					<td class="cb"><input type="checkbox" value="' . $question_id.'" class="existing-item" /></td>
1241
+					<td>' . get_the_title($question_id).'</td>
1242
+					<td>' . esc_html($question_type).'</td>
1243
+					<td>' . esc_html($question_cat_list).'</td>
1244 1244
 				  </tr>';
1245 1245
 
1246 1246
 		return $html;
@@ -1253,58 +1253,58 @@  discard block
 block discarded – undo
1253 1253
 
1254 1254
 		//Add nonce security to the request
1255 1255
 		$nonce = '';
1256
-		if( isset( $_POST['filter_existing_questions_nonce'] ) ) {
1257
-			$nonce = esc_html( $_POST['filter_existing_questions_nonce'] );
1256
+		if (isset($_POST['filter_existing_questions_nonce'])) {
1257
+			$nonce = esc_html($_POST['filter_existing_questions_nonce']);
1258 1258
 		} // End If Statement
1259 1259
 
1260
-		if( ! wp_verify_nonce( $nonce, 'filter_existing_questions_nonce' ) ) {
1261
-			die( $return );
1260
+		if ( ! wp_verify_nonce($nonce, 'filter_existing_questions_nonce')) {
1261
+			die($return);
1262 1262
 		} // End If Statement
1263 1263
 
1264 1264
 		// Parse POST data
1265 1265
 		$data = $_POST['data'];
1266 1266
 		$question_data = array();
1267
-		parse_str( $data, $question_data );
1267
+		parse_str($data, $question_data);
1268 1268
 
1269
-		if( 0 < count( $question_data ) ) {
1269
+		if (0 < count($question_data)) {
1270 1270
 
1271 1271
 			$question_status = '';
1272
-			if( isset( $question_data['question_status'] ) ) {
1272
+			if (isset($question_data['question_status'])) {
1273 1273
 				$question_status = $question_data['question_status'];
1274 1274
 			}
1275 1275
 
1276 1276
 			$question_type = '';
1277
-			if( isset( $question_data['question_type'] ) ) {
1277
+			if (isset($question_data['question_type'])) {
1278 1278
 				$question_type = $question_data['question_type'];
1279 1279
 			}
1280 1280
 
1281 1281
 			$question_category = '';
1282
-			if( isset( $question_data['question_category'] ) ) {
1282
+			if (isset($question_data['question_category'])) {
1283 1283
 				$question_category = $question_data['question_category'];
1284 1284
 			}
1285 1285
 
1286 1286
 			$question_search = '';
1287
-			if( isset( $question_data['question_search'] ) ) {
1287
+			if (isset($question_data['question_search'])) {
1288 1288
 				$question_search = $question_data['question_search'];
1289 1289
 			}
1290 1290
 
1291 1291
 			$question_page = 1;
1292
-			if( isset( $question_data['question_page'] ) ) {
1293
-				$question_page = intval( $question_data['question_page'] );
1292
+			if (isset($question_data['question_page'])) {
1293
+				$question_page = intval($question_data['question_page']);
1294 1294
 			}
1295 1295
 
1296
-			$questions = $this->quiz_panel_get_existing_questions( $question_status, $question_type, $question_category, $question_search, $question_page );
1296
+			$questions = $this->quiz_panel_get_existing_questions($question_status, $question_type, $question_category, $question_search, $question_page);
1297 1297
 
1298 1298
 			$row = 1;
1299 1299
 			$html = '';
1300
-			foreach( $questions['questions'] as $question ) {
1301
-				$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1300
+			foreach ($questions['questions'] as $question) {
1301
+				$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1302 1302
 				++$row;
1303 1303
 			}
1304 1304
 
1305
-			if( ! $html ) {
1305
+			if ( ! $html) {
1306 1306
 				$html = '<tr class="alternate">
1307
-								<td class="no-results" colspan="4"><em>' . __( 'There are no questions matching your search.', 'woothemes-sensei' ) . '</em></td>
1307
+								<td class="no-results" colspan="4"><em>' . __('There are no questions matching your search.', 'woothemes-sensei').'</em></td>
1308 1308
 							  </tr>';
1309 1309
 			}
1310 1310
 
@@ -1312,53 +1312,53 @@  discard block
 block discarded – undo
1312 1312
 			$return['count'] = $questions['count'];
1313 1313
 			$return['page'] = $questions['page'];
1314 1314
 
1315
-			wp_send_json( $return );
1315
+			wp_send_json($return);
1316 1316
 		}
1317 1317
 
1318
-		die( $return );
1318
+		die($return);
1319 1319
 	}
1320 1320
 
1321
-	public function quiz_panel_question_field( $question_type = '', $question_id = 0, $question_counter = 0 ) {
1321
+	public function quiz_panel_question_field($question_type = '', $question_id = 0, $question_counter = 0) {
1322 1322
 
1323 1323
 		$html = '';
1324 1324
 
1325
-		if( $question_type ) {
1325
+		if ($question_type) {
1326 1326
 
1327 1327
 			$right_answer = '';
1328 1328
 			$wrong_answers = array();
1329 1329
 			$answer_order_string = '';
1330 1330
 			$answer_order = array();
1331
-			if( $question_id ) {
1332
-				$right_answer = get_post_meta( $question_id, '_question_right_answer', true);
1333
-				$wrong_answers = get_post_meta( $question_id, '_question_wrong_answers', true);
1334
-				$answer_order_string = get_post_meta( $question_id, '_answer_order', true );
1335
-				$answer_order = array_filter( explode( ',', $answer_order_string ) );
1331
+			if ($question_id) {
1332
+				$right_answer = get_post_meta($question_id, '_question_right_answer', true);
1333
+				$wrong_answers = get_post_meta($question_id, '_question_wrong_answers', true);
1334
+				$answer_order_string = get_post_meta($question_id, '_answer_order', true);
1335
+				$answer_order = array_filter(explode(',', $answer_order_string));
1336 1336
 				$question_class = '';
1337 1337
 			} else {
1338 1338
 				$question_id = '';
1339 1339
 				$question_class = 'answer-fields question_required_fields hidden';
1340 1340
 			}
1341 1341
 
1342
-			switch ( $question_type ) {
1342
+			switch ($question_type) {
1343 1343
 				case 'multiple-choice':
1344
-					$html .= '<div class="question_default_fields multiple-choice-answers ' . str_replace( ' hidden', '', $question_class ) . '">';
1344
+					$html .= '<div class="question_default_fields multiple-choice-answers '.str_replace(' hidden', '', $question_class).'">';
1345 1345
 
1346 1346
 						$right_answers = (array) $right_answer;
1347 1347
 						// Calculate total right answers available (defaults to 1)
1348 1348
 						$total_right = 0;
1349
-						if( $question_id ) {
1350
-							$total_right = get_post_meta( $question_id, '_right_answer_count', true );
1349
+						if ($question_id) {
1350
+							$total_right = get_post_meta($question_id, '_right_answer_count', true);
1351 1351
 						}
1352
-						if( 0 == intval( $total_right ) ) {
1352
+						if (0 == intval($total_right)) {
1353 1353
 							$total_right = 1;
1354 1354
 						}
1355
-						for ( $i = 0; $i < $total_right; $i++ ) {
1356
-							if ( !isset( $right_answers[ $i ] ) ) { $right_answers[ $i ] = ''; }
1357
-							$right_answer_id = $this->get_answer_id( $right_answers[ $i ] );
1355
+						for ($i = 0; $i < $total_right; $i++) {
1356
+							if ( ! isset($right_answers[$i])) { $right_answers[$i] = ''; }
1357
+							$right_answer_id = $this->get_answer_id($right_answers[$i]);
1358 1358
 							// Right Answer
1359
-							$right_answer = '<label class="answer" for="question_' . $question_counter . '_right_answer_' . $i . '"><span>' . __( 'Right:' , 'woothemes-sensei' ) . '</span> <input rel="' . esc_attr( $right_answer_id ) . '" type="text" id="question_' . $question_counter . '_right_answer_' . $i . '" name="question_right_answers[]" value="' . esc_attr( $right_answers[ $i ] ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
-							if( $question_id ) {
1361
-								$answers[ $right_answer_id ] = $right_answer;
1359
+							$right_answer = '<label class="answer" for="question_'.$question_counter.'_right_answer_'.$i.'"><span>'.__('Right:', 'woothemes-sensei').'</span> <input rel="'.esc_attr($right_answer_id).'" type="text" id="question_'.$question_counter.'_right_answer_'.$i.'" name="question_right_answers[]" value="'.esc_attr($right_answers[$i]).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
+							if ($question_id) {
1361
+								$answers[$right_answer_id] = $right_answer;
1362 1362
 							} else {
1363 1363
 								$answers[] = $right_answer;
1364 1364
 							}
@@ -1366,23 +1366,23 @@  discard block
 block discarded – undo
1366 1366
 
1367 1367
 				    	// Calculate total wrong answers available (defaults to 4)
1368 1368
 				    	$total_wrong = 0;
1369
-				    	if( $question_id ) {
1370
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1369
+				    	if ($question_id) {
1370
+				    		$total_wrong = get_post_meta($question_id, '_wrong_answer_count', true);
1371 1371
 				    	}
1372
-				    	if( 0 == intval( $total_wrong ) ) {
1372
+				    	if (0 == intval($total_wrong)) {
1373 1373
 				    		$total_wrong = 1;
1374 1374
 				    	}
1375 1375
 
1376 1376
                         // Setup Wrong Answer HTML
1377
-                        foreach ( $wrong_answers as $i => $answer ){
1377
+                        foreach ($wrong_answers as $i => $answer) {
1378 1378
 
1379
-                            $answer_id = $this->get_answer_id( $answer );
1380
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1381
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1382
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
-                            if( $question_id ) {
1379
+                            $answer_id = $this->get_answer_id($answer);
1380
+                            $wrong_answer = '<label class="answer" for="question_'.$question_counter.'_wrong_answer_'.$i.'"><span>'.__('Wrong:', 'woothemes-sensei');
1381
+                            $wrong_answer .= '</span> <input rel="'.esc_attr($answer_id).'" type="text" id="question_'.$question_counter.'_wrong_answer_'.$i;
1382
+                            $wrong_answer .= '" name="question_wrong_answers[]" value="'.esc_attr($answer).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
+                            if ($question_id) {
1384 1384
 
1385
-                                $answers[ $answer_id ] = $wrong_answer;
1385
+                                $answers[$answer_id] = $wrong_answer;
1386 1386
 
1387 1387
                             } else {
1388 1388
 
@@ -1393,115 +1393,115 @@  discard block
 block discarded – undo
1393 1393
                         } // end for each
1394 1394
 
1395 1395
 				    	$answers_sorted = $answers;
1396
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1396
+				    	if ($question_id && count($answer_order) > 0) {
1397 1397
 				    		$answers_sorted = array();
1398
-				    		foreach( $answer_order as $answer_id ) {
1399
-				    			if( isset( $answers[ $answer_id ] ) ) {
1400
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1401
-				    				unset( $answers[ $answer_id ] );
1398
+				    		foreach ($answer_order as $answer_id) {
1399
+				    			if (isset($answers[$answer_id])) {
1400
+				    				$answers_sorted[$answer_id] = $answers[$answer_id];
1401
+				    				unset($answers[$answer_id]);
1402 1402
 				    			}
1403 1403
 				    		}
1404 1404
 
1405
-				    		if( count( $answers ) > 0 ) {
1406
-						    	foreach( $answers as $id => $answer ) {
1407
-						    		$answers_sorted[ $id ] = $answer;
1405
+				    		if (count($answers) > 0) {
1406
+						    	foreach ($answers as $id => $answer) {
1407
+						    		$answers_sorted[$id] = $answer;
1408 1408
 						    	}
1409 1409
 						    }
1410 1410
 				    	}
1411 1411
 
1412
-						foreach( $answers_sorted as $id => $answer ) {
1412
+						foreach ($answers_sorted as $id => $answer) {
1413 1413
 				    		$html .= $answer;
1414 1414
 				    	}
1415 1415
 
1416
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1417
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1418
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1416
+				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="'.$answer_order_string.'" />';
1417
+				    	$html .= '<span class="hidden right_answer_count">'.$total_right.'</span>';
1418
+				    	$html .= '<span class="hidden wrong_answer_count">'.$total_wrong.'</span>';
1419 1419
 
1420 1420
 				    	$html .= '<div class="add_answer_options">';
1421
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1422
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1421
+					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add right answer', 'woothemes-sensei').'</a>';
1422
+					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add wrong answer', 'woothemes-sensei').'</a>';
1423 1423
 				    	$html .= '</div>';
1424 1424
 
1425
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1425
+                        $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'multiple-choice');
1426 1426
 
1427 1427
 			    	$html .= '</div>';
1428 1428
 				break;
1429 1429
 				case 'boolean':
1430
-					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
1431
-						if( $question_id ) {
1432
-							$field_name = 'question_' . $question_id . '_right_answer_boolean';
1430
+					$html .= '<div class="question_boolean_fields '.$question_class.'">';
1431
+						if ($question_id) {
1432
+							$field_name = 'question_'.$question_id.'_right_answer_boolean';
1433 1433
 						} else {
1434 1434
 							$field_name = 'question_right_answer_boolean';
1435 1435
 							$right_answer = 'true';
1436 1436
 						}
1437
-						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1438
-						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1437
+						$html .= '<label for="question_'.$question_id.'_boolean_true"><input id="question_'.$question_id.'_boolean_true" type="radio" name="'.$field_name.'" value="true" '.checked($right_answer, 'true', false).' /> '.__('True', 'woothemes-sensei').'</label>';
1438
+						$html .= '<label for="question_'.$question_id.'_boolean_false"><input id="question_'.$question_id.'_boolean_false" type="radio" name="'.$field_name.'" value="false" '.checked($right_answer, 'false', false).' /> '.__('False', 'woothemes-sensei').'</label>';
1439 1439
 
1440
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1440
+                    $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'boolean');
1441 1441
 
1442 1442
 					$html .= '</div>';
1443 1443
 				break;
1444 1444
 				case 'gap-fill':
1445
-					$gapfill_array = explode( '||', $right_answer );
1446
-					if ( isset( $gapfill_array[0] ) ) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
-					if ( isset( $gapfill_array[1] ) ) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
-					if ( isset( $gapfill_array[2] ) ) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
-					$html .= '<div class="question_gapfill_fields ' . $question_class . '">';
1445
+					$gapfill_array = explode('||', $right_answer);
1446
+					if (isset($gapfill_array[0])) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
+					if (isset($gapfill_array[1])) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
+					if (isset($gapfill_array[2])) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
+					$html .= '<div class="question_gapfill_fields '.$question_class.'">';
1450 1450
 						// Fill in the Gaps
1451
-						$html .= '<label>' . __( 'Text before the Gap:' , 'woothemes-sensei' ) . '</label> ';
1452
-						$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="' . $gapfill_pre . '" size="25" class="widefat gapfill-field" />';
1453
-	  					$html .= '<label>' . __( 'The Gap:' , 'woothemes-sensei' ) . '</label> ';
1454
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="' . $gapfill_gap . '" size="25" class="widefat gapfill-field" />';
1455
-	  					$html .= '<label>' . __( 'Text after the Gap:' , 'woothemes-sensei' ) . '</label> ';
1456
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="' . $gapfill_post . '" size="25" class="widefat gapfill-field" />';
1457
-	  					$html .= '<label>' . __( 'Preview:' , 'woothemes-sensei' ) . '</label> ';
1458
-	  					$html .= '<p class="gapfill-preview">' . $gapfill_pre . '&nbsp;<u>' . $gapfill_gap . '</u>&nbsp;' . $gapfill_post . '</p>';
1451
+						$html .= '<label>'.__('Text before the Gap:', 'woothemes-sensei').'</label> ';
1452
+						$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="'.$gapfill_pre.'" size="25" class="widefat gapfill-field" />';
1453
+	  					$html .= '<label>'.__('The Gap:', 'woothemes-sensei').'</label> ';
1454
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="'.$gapfill_gap.'" size="25" class="widefat gapfill-field" />';
1455
+	  					$html .= '<label>'.__('Text after the Gap:', 'woothemes-sensei').'</label> ';
1456
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="'.$gapfill_post.'" size="25" class="widefat gapfill-field" />';
1457
+	  					$html .= '<label>'.__('Preview:', 'woothemes-sensei').'</label> ';
1458
+	  					$html .= '<p class="gapfill-preview">'.$gapfill_pre.'&nbsp;<u>'.$gapfill_gap.'</u>&nbsp;'.$gapfill_post.'</p>';
1459 1459
 	  				$html .= '</div>';
1460 1460
 				break;
1461 1461
 				case 'multi-line':
1462
-					$html .= '<div class="question_multiline_fields ' . $question_class . '">';
1462
+					$html .= '<div class="question_multiline_fields '.$question_class.'">';
1463 1463
 						// Guides for grading
1464
-						if( $question_counter ) {
1465
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_multiline';
1464
+						if ($question_counter) {
1465
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_multiline';
1466 1466
 						} else {
1467 1467
 							$field_id = 'add_question_right_answer_multiline';
1468 1468
 						}
1469
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the answer' , 'woothemes-sensei' ) . '</label> ';
1470
-						$html .= '<textarea id="' . $field_id . '" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1469
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the answer', 'woothemes-sensei').'</label> ';
1470
+						$html .= '<textarea id="'.$field_id.'" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1471 1471
 					$html .= '</div>';
1472 1472
 				break;
1473 1473
 				case 'single-line':
1474
-					$html .= '<div class="question_singleline_fields ' . $question_class . '">';
1474
+					$html .= '<div class="question_singleline_fields '.$question_class.'">';
1475 1475
 						// Recommended Answer
1476
-						if( $question_counter ) {
1477
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_singleline';
1476
+						if ($question_counter) {
1477
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_singleline';
1478 1478
 						} else {
1479 1479
 							$field_id = 'add_question_right_answer_singleline';
1480 1480
 						}
1481
-						$html .= '<label>' . __( 'Recommended Answer' , 'woothemes-sensei' ) . '</label> ';
1482
-						$html .= '<input type="text" id="' . $field_id . '" name="add_question_right_answer_singleline" value="' . $right_answer . '" size="25" class="widefat" />';
1481
+						$html .= '<label>'.__('Recommended Answer', 'woothemes-sensei').'</label> ';
1482
+						$html .= '<input type="text" id="'.$field_id.'" name="add_question_right_answer_singleline" value="'.$right_answer.'" size="25" class="widefat" />';
1483 1483
 					$html .= '</div>';
1484 1484
 				break;
1485 1485
 				case 'file-upload':
1486
-					$html .= '<div class="question_fileupload_fields ' . $question_class . '">';
1487
-						if( $question_counter ) {
1488
-							$right_field_id = 'question_' . $question_counter . '_add_question_right_answer_fileupload';
1489
-							$wrong_field_id = 'question_' . $question_counter . '_add_question_wrong_answer_fileupload';
1486
+					$html .= '<div class="question_fileupload_fields '.$question_class.'">';
1487
+						if ($question_counter) {
1488
+							$right_field_id = 'question_'.$question_counter.'_add_question_right_answer_fileupload';
1489
+							$wrong_field_id = 'question_'.$question_counter.'_add_question_wrong_answer_fileupload';
1490 1490
 						} else {
1491 1491
 							$right_field_id = 'add_question_right_answer_fileupload';
1492 1492
 							$wrong_field_id = 'add_question_wrong_answer_fileupload';
1493 1493
 						}
1494 1494
 
1495 1495
 						$wrong_answer = '';
1496
-						if( isset( $wrong_answers[0] ) ) {
1496
+						if (isset($wrong_answers[0])) {
1497 1497
 							$wrong_answer = $wrong_answers[0];
1498 1498
 						}
1499
-						$html .= '<label>' . __( 'Description for student explaining what needs to be uploaded' , 'woothemes-sensei' ) . '</label> ';
1500
-						$html .= '<textarea id="' . $wrong_field_id . '" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">' . $wrong_answer . '</textarea>';
1499
+						$html .= '<label>'.__('Description for student explaining what needs to be uploaded', 'woothemes-sensei').'</label> ';
1500
+						$html .= '<textarea id="'.$wrong_field_id.'" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">'.$wrong_answer.'</textarea>';
1501 1501
 
1502 1502
 						// Guides for grading
1503
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the upload' , 'woothemes-sensei' ) . '</label> ';
1504
-						$html .= '<textarea id="' . $right_field_id . '" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1503
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the upload', 'woothemes-sensei').'</label> ';
1504
+						$html .= '<textarea id="'.$right_field_id.'" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1505 1505
 					$html .= '</div>';
1506 1506
 				break;
1507 1507
 			}
@@ -1510,32 +1510,32 @@  discard block
 block discarded – undo
1510 1510
 		return $html;
1511 1511
 	}
1512 1512
 
1513
-	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1513
+	public function quiz_panel_question_feedback($question_counter = 0, $question_id = 0, $question_type = '') {
1514 1514
 
1515 1515
         // default field name
1516 1516
         $field_name = 'answer_feedback';
1517
-        if( 'boolean' == $question_type ){
1517
+        if ('boolean' == $question_type) {
1518 1518
 
1519 1519
             $field_name = 'answer_feedback_boolean';
1520 1520
 
1521
-        }elseif( 'multiple-choice' == $question_type ){
1521
+        }elseif ('multiple-choice' == $question_type) {
1522 1522
 
1523 1523
             $field_name = 'answer_feedback_multiple_choice';
1524 1524
 
1525 1525
         }// end if
1526 1526
 
1527
-		if( $question_counter ) {
1528
-			$field_name = 'answer_' . $question_counter . '_feedback';
1527
+		if ($question_counter) {
1528
+			$field_name = 'answer_'.$question_counter.'_feedback';
1529 1529
 		}
1530 1530
 
1531 1531
 		$feedback = '';
1532
-		if( $question_id ) {
1533
-			$feedback = get_post_meta( $question_id, '_answer_feedback', true );
1532
+		if ($question_id) {
1533
+			$feedback = get_post_meta($question_id, '_answer_feedback', true);
1534 1534
 		}
1535 1535
 
1536
-		$html = '<p title="' . __( 'This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei' ) . '">';
1537
-		$html .= '<label for="' . $field_name . '">' . __( 'Answer Feedback' , 'woothemes-sensei' ) . ':</label>';
1538
-		$html .= '<textarea id="' . $field_name . '" name="' . $field_name . '" rows="4" cols="40" class="answer_feedback widefat">' . $feedback . '</textarea>';
1536
+		$html = '<p title="'.__('This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei').'">';
1537
+		$html .= '<label for="'.$field_name.'">'.__('Answer Feedback', 'woothemes-sensei').':</label>';
1538
+		$html .= '<textarea id="'.$field_name.'" name="'.$field_name.'" rows="4" cols="40" class="answer_feedback widefat">'.$feedback.'</textarea>';
1539 1539
 		$html .= '</p>';
1540 1540
 
1541 1541
 		return $html;
@@ -1544,19 +1544,19 @@  discard block
 block discarded – undo
1544 1544
 	public function question_get_answer_id() {
1545 1545
 		$data = $_POST['data'];
1546 1546
 		$answer_data = array();
1547
-		parse_str( $data, $answer_data );
1547
+		parse_str($data, $answer_data);
1548 1548
 		$answer = $answer_data['answer_value'];
1549
-		$answer_id = $this->get_answer_id( $answer );
1549
+		$answer_id = $this->get_answer_id($answer);
1550 1550
 		echo $answer_id;
1551 1551
 		die();
1552 1552
 	}
1553 1553
 
1554
-	public function get_answer_id( $answer = '' ) {
1554
+	public function get_answer_id($answer = '') {
1555 1555
 
1556 1556
 		$answer_id = '';
1557 1557
 
1558
-		if( $answer ) {
1559
-			$answer_id = md5( $answer );
1558
+		if ($answer) {
1559
+			$answer_id = md5($answer);
1560 1560
 		}
1561 1561
 
1562 1562
 		return $answer_id;
@@ -1569,17 +1569,17 @@  discard block
 block discarded – undo
1569 1569
 	 * @access public
1570 1570
 	 * @return void
1571 1571
 	 */
1572
-	public function lesson_quiz_meta_box_content () {
1572
+	public function lesson_quiz_meta_box_content() {
1573 1573
 		global $post;
1574 1574
 
1575 1575
 		// Get quiz panel
1576 1576
 		$quiz_id = 0;
1577 1577
 		$quizzes = array();
1578
-		if ( 0 < $post->ID ) {
1579
-			$quiz_id = $this->lesson_quizzes( $post->ID, 'any' );
1578
+		if (0 < $post->ID) {
1579
+			$quiz_id = $this->lesson_quizzes($post->ID, 'any');
1580 1580
 		}
1581 1581
 
1582
-		echo $this->quiz_panel( $quiz_id );
1582
+		echo $this->quiz_panel($quiz_id);
1583 1583
 
1584 1584
 	} // End lesson_quiz_meta_box_content()
1585 1585
 
@@ -1596,53 +1596,53 @@  discard block
 block discarded – undo
1596 1596
 		$quiz_id = 0;
1597 1597
 		$lesson_id = $post->ID;
1598 1598
 		$quizzes = array();
1599
-		if ( 0 < $lesson_id ) {
1600
-			$quiz_id = $this->lesson_quizzes( $lesson_id, 'any' );
1599
+		if (0 < $lesson_id) {
1600
+			$quiz_id = $this->lesson_quizzes($lesson_id, 'any');
1601 1601
 		}
1602 1602
 
1603
-		if( $quiz_id ) {
1604
-			$html .= $this->quiz_settings_panel( $lesson_id, $quiz_id );
1603
+		if ($quiz_id) {
1604
+			$html .= $this->quiz_settings_panel($lesson_id, $quiz_id);
1605 1605
 		} else {
1606
-			$html .= '<p><em>' . __( 'There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei' ) . '</em></p>';
1606
+			$html .= '<p><em>'.__('There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei').'</em></p>';
1607 1607
 		}
1608 1608
 
1609 1609
 		echo $html;
1610 1610
 	}
1611 1611
 
1612
-	public function quiz_settings_panel( $lesson_id = 0, $quiz_id = 0 ) {
1612
+	public function quiz_settings_panel($lesson_id = 0, $quiz_id = 0) {
1613 1613
 
1614 1614
 
1615 1615
 		$html = '';
1616 1616
 
1617
-		if( ! $lesson_id && ! $quiz_id ) return $html;
1617
+		if ( ! $lesson_id && ! $quiz_id) return $html;
1618 1618
 
1619
-		$settings = $this->get_quiz_settings( $quiz_id );
1619
+		$settings = $this->get_quiz_settings($quiz_id);
1620 1620
 
1621
-		$html = Sensei()->admin->render_settings( $settings, $quiz_id, 'quiz-settings' );
1621
+		$html = Sensei()->admin->render_settings($settings, $quiz_id, 'quiz-settings');
1622 1622
 
1623 1623
 		return $html;
1624 1624
 
1625 1625
 	}
1626 1626
 
1627
-	public function get_quiz_settings( $quiz_id = 0 ) {
1627
+	public function get_quiz_settings($quiz_id = 0) {
1628 1628
 
1629 1629
 		$disable_passmark = '';
1630
-		$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1631
-		if( ! $pass_required ) {
1630
+		$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1631
+		if ( ! $pass_required) {
1632 1632
 			$disable_passmark = 'hidden';
1633 1633
 		}
1634 1634
 
1635 1635
 		// Setup Questions Query
1636 1636
 		$questions = array();
1637
-		if ( 0 < $quiz_id ) {
1638
-			$questions = $this->lesson_quiz_questions( $quiz_id );
1637
+		if (0 < $quiz_id) {
1638
+			$questions = $this->lesson_quiz_questions($quiz_id);
1639 1639
 		}
1640 1640
 
1641 1641
 		// Count questions
1642 1642
 		$question_count = 0;
1643
-		foreach( $questions as $question ) {
1644
-			if( $question->post_type == 'multiple_question' ) {
1645
-				$question_number = get_post_meta( $question->ID, 'number', true );
1643
+		foreach ($questions as $question) {
1644
+			if ($question->post_type == 'multiple_question') {
1645
+				$question_number = get_post_meta($question->ID, 'number', true);
1646 1646
 				$question_count += $question_number;
1647 1647
 			} else {
1648 1648
 				++$question_count;
@@ -1652,15 +1652,15 @@  discard block
 block discarded – undo
1652 1652
 		$settings = array(
1653 1653
 			array(
1654 1654
 				'id' 			=> 'pass_required',
1655
-				'label'			=> __( 'Pass required to complete lesson', 'woothemes-sensei' ),
1656
-				'description'	=> __( 'The passmark must be achieved before the lesson is complete.', 'woothemes-sensei' ),
1655
+				'label'			=> __('Pass required to complete lesson', 'woothemes-sensei'),
1656
+				'description'	=> __('The passmark must be achieved before the lesson is complete.', 'woothemes-sensei'),
1657 1657
 				'type'			=> 'checkbox',
1658 1658
 				'default'		=> '',
1659 1659
 				'checked'		=> 'on',
1660 1660
 			),
1661 1661
 			array(
1662 1662
 				'id' 			=> 'quiz_passmark',
1663
-				'label'			=> __( 'Quiz passmark percentage', 'woothemes-sensei' ),
1663
+				'label'			=> __('Quiz passmark percentage', 'woothemes-sensei'),
1664 1664
 				'description'	=> '',
1665 1665
 				'type'			=> 'number',
1666 1666
 				'default'		=> 0,
@@ -1671,17 +1671,17 @@  discard block
 block discarded – undo
1671 1671
 			),
1672 1672
 			array(
1673 1673
 				'id' 			=> 'show_questions',
1674
-				'label'			=> __( 'Number of questions to show', 'woothemes-sensei' ),
1675
-				'description'	=> __( 'Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei' ),
1674
+				'label'			=> __('Number of questions to show', 'woothemes-sensei'),
1675
+				'description'	=> __('Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei'),
1676 1676
 				'type'			=> 'number',
1677 1677
 				'default'		=> '',
1678
-				'placeholder'	=> __( 'All', 'woothemes-sensei' ),
1678
+				'placeholder'	=> __('All', 'woothemes-sensei'),
1679 1679
 				'min'			=> 1,
1680 1680
 				'max'			=> $question_count,
1681 1681
 			),
1682 1682
 			array(
1683 1683
 				'id' 			=> 'random_question_order',
1684
-				'label'			=> __( 'Randomise question order', 'woothemes-sensei' ),
1684
+				'label'			=> __('Randomise question order', 'woothemes-sensei'),
1685 1685
 				'description'	=> '',
1686 1686
 				'type'			=> 'checkbox',
1687 1687
 				'default'		=> 'no',
@@ -1689,23 +1689,23 @@  discard block
 block discarded – undo
1689 1689
 			),
1690 1690
 			array(
1691 1691
 				'id' 			=> 'quiz_grade_type',
1692
-				'label'			=> __( 'Grade quiz automatically', 'woothemes-sensei' ),
1693
-				'description'	=> __( 'Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei' ),
1692
+				'label'			=> __('Grade quiz automatically', 'woothemes-sensei'),
1693
+				'description'	=> __('Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei'),
1694 1694
 				'type'			=> 'checkbox',
1695 1695
 				'default'		=> 'auto',
1696 1696
 				'checked'		=> 'auto',
1697 1697
 			),
1698 1698
 			array(
1699 1699
 				'id' 			=> 'enable_quiz_reset',
1700
-				'label'			=> __( 'Allow user to retake the quiz', 'woothemes-sensei' ),
1701
-				'description'	=> __( 'Enables the quiz reset button.', 'woothemes-sensei' ),
1700
+				'label'			=> __('Allow user to retake the quiz', 'woothemes-sensei'),
1701
+				'description'	=> __('Enables the quiz reset button.', 'woothemes-sensei'),
1702 1702
 				'type'			=> 'checkbox',
1703 1703
 				'default'		=> '',
1704 1704
 				'checked'		=> 'on',
1705 1705
 			),
1706 1706
 		);
1707 1707
 
1708
-		return apply_filters( 'sensei_quiz_settings', $settings );
1708
+		return apply_filters('sensei_quiz_settings', $settings);
1709 1709
 	}
1710 1710
 
1711 1711
 	/**
@@ -1714,38 +1714,38 @@  discard block
 block discarded – undo
1714 1714
 	 * @access public
1715 1715
 	 * @return void
1716 1716
 	 */
1717
-	public function enqueue_scripts( $hook ) {
1717
+	public function enqueue_scripts($hook) {
1718 1718
 		global  $post_type;
1719 1719
 
1720
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) );
1721
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1722
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order' ) );
1720
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question'));
1721
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1722
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order'));
1723 1723
 
1724 1724
 		// Test for Write Panel Pages
1725
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1725
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1726 1726
 
1727
-			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1727
+			$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1728 1728
 
1729 1729
 			// Load the lessons script
1730 1730
             wp_enqueue_media();
1731
-			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'sensei-core-select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1732
-			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1733
-			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1731
+			wp_enqueue_script('sensei-lesson-metadata', Sensei()->plugin_url.'assets/js/lesson-metadata'.$suffix.'.js', array('jquery', 'sensei-core-select2', 'jquery-ui-sortable'), Sensei()->version, true);
1732
+			wp_enqueue_script('sensei-lesson-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1733
+			wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-lesson-chosen'), Sensei()->version, true);
1734 1734
 
1735 1735
             // Load the bulk edit screen script
1736
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1737
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1736
+            if ('edit.php' == $hook && 'lesson' == $_GET['post_type']) {
1737
+                wp_enqueue_script('sensei-lessons-bulk-edit', Sensei()->plugin_url.'assets/js/admin/lesson-bulk-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1738 1738
             }
1739 1739
 
1740 1740
 			// Localise script
1741
-			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
1742
-			$ajax_vars = array( 'lesson_update_question_nonce' => wp_create_nonce( 'lesson_update_question_nonce' ), 'lesson_add_course_nonce' => wp_create_nonce( 'lesson_add_course_nonce' ), 'lesson_update_grade_type_nonce' => wp_create_nonce( 'lesson_update_grade_type_nonce' ), 'lesson_update_question_order_nonce' => wp_create_nonce( 'lesson_update_question_order_nonce' ), 'lesson_update_question_order_random_nonce' => wp_create_nonce( 'lesson_update_question_order_random_nonce' ), 'lesson_add_multiple_questions_nonce' => wp_create_nonce( 'lesson_add_multiple_questions_nonce' ), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce( 'lesson_remove_multiple_questions_nonce' ), 'lesson_add_existing_questions_nonce' => wp_create_nonce( 'lesson_add_existing_questions_nonce' ), 'filter_existing_questions_nonce' => wp_create_nonce( 'filter_existing_questions_nonce' ) );
1743
-			$data = array_merge( $translation_strings, $ajax_vars );
1744
-			wp_localize_script( 'sensei-lesson-metadata', 'woo_localized_data', $data );
1741
+			$translation_strings = array('right_colon' => __('Right:', 'woothemes-sensei'), 'wrong_colon' => __('Wrong:', 'woothemes-sensei'), 'add_file' => __('Add file', 'woothemes-sensei'), 'change_file' => __('Change file', 'woothemes-sensei'), 'confirm_remove' => __('Are you sure you want to remove this question?', 'woothemes-sensei'), 'confirm_remove_multiple' => __('Are you sure you want to remove these questions?', 'woothemes-sensei'), 'too_many_for_cat' => __('You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei'));
1742
+			$ajax_vars = array('lesson_update_question_nonce' => wp_create_nonce('lesson_update_question_nonce'), 'lesson_add_course_nonce' => wp_create_nonce('lesson_add_course_nonce'), 'lesson_update_grade_type_nonce' => wp_create_nonce('lesson_update_grade_type_nonce'), 'lesson_update_question_order_nonce' => wp_create_nonce('lesson_update_question_order_nonce'), 'lesson_update_question_order_random_nonce' => wp_create_nonce('lesson_update_question_order_random_nonce'), 'lesson_add_multiple_questions_nonce' => wp_create_nonce('lesson_add_multiple_questions_nonce'), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce('lesson_remove_multiple_questions_nonce'), 'lesson_add_existing_questions_nonce' => wp_create_nonce('lesson_add_existing_questions_nonce'), 'filter_existing_questions_nonce' => wp_create_nonce('filter_existing_questions_nonce'));
1743
+			$data = array_merge($translation_strings, $ajax_vars);
1744
+			wp_localize_script('sensei-lesson-metadata', 'woo_localized_data', $data);
1745 1745
 
1746 1746
 			// Chosen RTL
1747
-			if ( is_rtl() ) {
1748
-				wp_enqueue_script( 'sensei-chosen-rtl', Sensei()->plugin_url . 'assets/chosen/chosen-rtl' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1747
+			if (is_rtl()) {
1748
+				wp_enqueue_script('sensei-chosen-rtl', Sensei()->plugin_url.'assets/chosen/chosen-rtl'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1749 1749
 			}
1750 1750
 
1751 1751
 		}
@@ -1759,16 +1759,16 @@  discard block
 block discarded – undo
1759 1759
 	 * @since  1.4.0
1760 1760
 	 * @return void
1761 1761
 	 */
1762
-	public function enqueue_styles ( $hook ) {
1762
+	public function enqueue_styles($hook) {
1763 1763
 		global  $post_type;
1764 1764
 
1765
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question', 'sensei_message' ) );
1766
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1767
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings' ) );
1765
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question', 'sensei_message'));
1766
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1767
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings'));
1768 1768
 
1769 1769
 		// Test for Write Panel Pages
1770
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1771
-			wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), '', Sensei()->version );
1770
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1771
+			wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), '', Sensei()->version);
1772 1772
 		}
1773 1773
 
1774 1774
 	} // End enqueue_styles()
@@ -1780,12 +1780,12 @@  discard block
 block discarded – undo
1780 1780
 	 * @param  array $defaults
1781 1781
 	 * @return array $new_columns
1782 1782
 	 */
1783
-	public function add_column_headings ( $defaults ) {
1783
+	public function add_column_headings($defaults) {
1784 1784
 		$new_columns['cb'] = '<input type="checkbox" />';
1785
-		$new_columns['title'] = _x( 'Lesson Title', 'column name', 'woothemes-sensei' );
1786
-		$new_columns['lesson-course'] = _x( 'Course', 'column name', 'woothemes-sensei' );
1787
-		$new_columns['lesson-prerequisite'] = _x( 'Pre-requisite Lesson', 'column name', 'woothemes-sensei' );
1788
-		if ( isset( $defaults['date'] ) ) {
1785
+		$new_columns['title'] = _x('Lesson Title', 'column name', 'woothemes-sensei');
1786
+		$new_columns['lesson-course'] = _x('Course', 'column name', 'woothemes-sensei');
1787
+		$new_columns['lesson-prerequisite'] = _x('Pre-requisite Lesson', 'column name', 'woothemes-sensei');
1788
+		if (isset($defaults['date'])) {
1789 1789
 			$new_columns['date'] = $defaults['date'];
1790 1790
 		}
1791 1791
 		return $new_columns;
@@ -1799,23 +1799,23 @@  discard block
 block discarded – undo
1799 1799
 	 * @param  int $id
1800 1800
 	 * @return void
1801 1801
 	 */
1802
-	public function add_column_data ( $column_name, $id ) {
1802
+	public function add_column_data($column_name, $id) {
1803 1803
 		global $wpdb, $post;
1804 1804
 
1805
-		switch ( $column_name ) {
1805
+		switch ($column_name) {
1806 1806
 			case 'id':
1807 1807
 				echo $id;
1808 1808
 			break;
1809 1809
 			case 'lesson-course':
1810
-				$lesson_course_id = get_post_meta( $id, '_lesson_course', true);
1811
-				if ( 0 < absint( $lesson_course_id ) ) {
1812
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_course_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_course_id ) ) ) ) . '">' . get_the_title( absint( $lesson_course_id ) ) . '</a>';
1810
+				$lesson_course_id = get_post_meta($id, '_lesson_course', true);
1811
+				if (0 < absint($lesson_course_id)) {
1812
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_course_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_course_id)))).'">'.get_the_title(absint($lesson_course_id)).'</a>';
1813 1813
 				} // End If Statement
1814 1814
 			break;
1815 1815
 			case 'lesson-prerequisite':
1816
-				$lesson_prerequisite_id = get_post_meta( $id, '_lesson_prerequisite', true);
1817
-				if ( 0 < absint( $lesson_prerequisite_id ) ) {
1818
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $lesson_prerequisite_id ) ) . '</a>';
1816
+				$lesson_prerequisite_id = get_post_meta($id, '_lesson_prerequisite', true);
1817
+				if (0 < absint($lesson_prerequisite_id)) {
1818
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_prerequisite_id)))).'">'.get_the_title(absint($lesson_prerequisite_id)).'</a>';
1819 1819
 				} // End If Statement
1820 1820
 			break;
1821 1821
 			default:
@@ -1829,14 +1829,14 @@  discard block
 block discarded – undo
1829 1829
 	 * @access public
1830 1830
 	 * @return void
1831 1831
 	 */
1832
-	public function lesson_add_course () {
1832
+	public function lesson_add_course() {
1833 1833
 		global $current_user;
1834 1834
 		//Add nonce security to the request
1835
-		if ( isset($_POST['lesson_add_course_nonce']) ) {
1836
-			$nonce = esc_html( $_POST['lesson_add_course_nonce'] );
1835
+		if (isset($_POST['lesson_add_course_nonce'])) {
1836
+			$nonce = esc_html($_POST['lesson_add_course_nonce']);
1837 1837
 		} // End If Statement
1838
-		if ( ! wp_verify_nonce( $nonce, 'lesson_add_course_nonce' )
1839
-            || ! current_user_can( 'edit_lessons' ) ) {
1838
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_course_nonce')
1839
+            || ! current_user_can('edit_lessons')) {
1840 1840
 			die('');
1841 1841
 		} // End If Statement
1842 1842
 		// Parse POST data
@@ -1858,14 +1858,14 @@  discard block
 block discarded – undo
1858 1858
 	 * @access public
1859 1859
 	 * @return void
1860 1860
 	 */
1861
-	public function lesson_update_question () {
1861
+	public function lesson_update_question() {
1862 1862
 		global $current_user;
1863 1863
 		//Add nonce security to the request
1864
-		if ( isset($_POST['lesson_update_question_nonce']) ) {
1865
-			$nonce = esc_html( $_POST['lesson_update_question_nonce'] );
1864
+		if (isset($_POST['lesson_update_question_nonce'])) {
1865
+			$nonce = esc_html($_POST['lesson_update_question_nonce']);
1866 1866
 		} // End If Statement
1867
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_nonce' )
1868
-            ||  ! current_user_can( 'edit_questions' )) {
1867
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_nonce')
1868
+            ||  ! current_user_can('edit_questions')) {
1869 1869
 
1870 1870
 			die('');
1871 1871
 
@@ -1875,30 +1875,30 @@  discard block
 block discarded – undo
1875 1875
 		// WP slashes all incoming data regardless of Magic Quotes setting (see wp_magic_quotes()), which means that
1876 1876
 		// even the $_POST['data'] encoded with encodeURIComponent has it's apostrophes slashed.
1877 1877
 		// So first restore the original unslashed apostrophes by removing those slashes
1878
-		$data = wp_unslash( $_POST['data'] );
1878
+		$data = wp_unslash($_POST['data']);
1879 1879
 		// Then parse the string to an array (note that parse_str automatically urldecodes all the variables)
1880 1880
 		$question_data = array();
1881 1881
 		parse_str($data, $question_data);
1882 1882
 		// Finally re-slash all elements to ensure consistancy for lesson_save_question()
1883
-		$question_data = wp_slash( $question_data );
1883
+		$question_data = wp_slash($question_data);
1884 1884
 		// Save the question
1885 1885
 		$return = false;
1886 1886
 		// Question Save and Delete logic
1887
-		if ( isset( $question_data['action'] ) && ( $question_data['action'] == 'delete' ) ) {
1887
+		if (isset($question_data['action']) && ($question_data['action'] == 'delete')) {
1888 1888
 			// Delete the Question
1889 1889
 			$return = $this->lesson_delete_question($question_data);
1890 1890
 		} else {
1891 1891
 			// Save the Question
1892
-			if ( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1892
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1893 1893
 				$current_user = wp_get_current_user();
1894 1894
 				$question_data['post_author'] = $current_user->ID;
1895
-				$question_id = $this->lesson_save_question( $question_data );
1896
-				$question_type = Sensei()->question->get_question_type( $question_id );
1895
+				$question_id = $this->lesson_save_question($question_data);
1896
+				$question_type = Sensei()->question->get_question_type($question_id);
1897 1897
 
1898
-				$question_count = intval( $question_data['question_count'] );
1898
+				$question_count = intval($question_data['question_count']);
1899 1899
 				++$question_count;
1900 1900
 
1901
-				$return = $this->quiz_panel_question( $question_type, $question_count, $question_id );
1901
+				$return = $this->quiz_panel_question($question_type, $question_count, $question_id);
1902 1902
 			} // End If Statement
1903 1903
 		} // End If Statement
1904 1904
 
@@ -1913,49 +1913,49 @@  discard block
 block discarded – undo
1913 1913
 
1914 1914
 		//Add nonce security to the request
1915 1915
 		$nonce = '';
1916
-		if( isset( $_POST['lesson_add_multiple_questions_nonce'] ) ) {
1917
-			$nonce = esc_html( $_POST['lesson_add_multiple_questions_nonce'] );
1916
+		if (isset($_POST['lesson_add_multiple_questions_nonce'])) {
1917
+			$nonce = esc_html($_POST['lesson_add_multiple_questions_nonce']);
1918 1918
 		} // End If Statement
1919 1919
 
1920
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_multiple_questions_nonce' )
1921
-            || ! current_user_can( 'edit_lessons' ) ) {
1922
-			die( $return );
1920
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_multiple_questions_nonce')
1921
+            || ! current_user_can('edit_lessons')) {
1922
+			die($return);
1923 1923
 		} // End If Statement
1924 1924
 
1925 1925
 		// Parse POST data
1926 1926
 		$data = $_POST['data'];
1927 1927
 		$question_data = array();
1928
-		parse_str( $data, $question_data );
1928
+		parse_str($data, $question_data);
1929 1929
 
1930
-		if( is_array( $question_data ) ) {
1931
-			if( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1930
+		if (is_array($question_data)) {
1931
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1932 1932
 
1933
-				$quiz_id = intval( $question_data['quiz_id'] );
1934
-				$question_number = intval( $question_data['question_number'] );
1935
-				$question_category = intval( $question_data['question_category'] );
1933
+				$quiz_id = intval($question_data['quiz_id']);
1934
+				$question_number = intval($question_data['question_number']);
1935
+				$question_category = intval($question_data['question_category']);
1936 1936
 
1937
-				$question_counter = intval( $question_data['question_count'] );
1937
+				$question_counter = intval($question_data['question_count']);
1938 1938
 				++$question_counter;
1939 1939
 
1940
-				$cat = get_term( $question_category, 'question-category' );
1940
+				$cat = get_term($question_category, 'question-category');
1941 1941
 
1942 1942
 				$post_data = array(
1943 1943
 					'post_content' => '',
1944 1944
 					'post_status' => 'publish',
1945
-					'post_title' => sprintf( __( '%1$s Question(s) from %2$s', 'woothemes-sensei' ), $question_number, $cat->name ),
1945
+					'post_title' => sprintf(__('%1$s Question(s) from %2$s', 'woothemes-sensei'), $question_number, $cat->name),
1946 1946
 					'post_type' => 'multiple_question'
1947 1947
 				);
1948 1948
 
1949
-				$multiple_id = wp_insert_post( $post_data );
1949
+				$multiple_id = wp_insert_post($post_data);
1950 1950
 
1951
-				if( $multiple_id && ! is_wp_error( $multiple_id ) ) {
1952
-					add_post_meta( $multiple_id, 'category', $question_category );
1953
-					add_post_meta( $multiple_id, 'number', $question_number );
1954
-					add_post_meta( $multiple_id, '_quiz_id', $quiz_id, false );
1955
-					add_post_meta( $multiple_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_counter );
1956
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1957
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
1958
-					$return = $this->quiz_panel_question( 'category', $question_counter, $multiple_id, 'quiz', array( $cat->name, $question_number ) );
1951
+				if ($multiple_id && ! is_wp_error($multiple_id)) {
1952
+					add_post_meta($multiple_id, 'category', $question_category);
1953
+					add_post_meta($multiple_id, 'number', $question_number);
1954
+					add_post_meta($multiple_id, '_quiz_id', $quiz_id, false);
1955
+					add_post_meta($multiple_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_counter);
1956
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1957
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
1958
+					$return = $this->quiz_panel_question('category', $question_counter, $multiple_id, 'quiz', array($cat->name, $question_number));
1959 1959
 				}
1960 1960
 			}
1961 1961
 		}
@@ -1969,25 +1969,25 @@  discard block
 block discarded – undo
1969 1969
 
1970 1970
 		//Add nonce security to the request
1971 1971
 		$nonce = '';
1972
-		if( isset( $_POST['lesson_remove_multiple_questions_nonce'] ) ) {
1973
-			$nonce = esc_html( $_POST['lesson_remove_multiple_questions_nonce'] );
1972
+		if (isset($_POST['lesson_remove_multiple_questions_nonce'])) {
1973
+			$nonce = esc_html($_POST['lesson_remove_multiple_questions_nonce']);
1974 1974
 		} // End If Statement
1975 1975
 
1976
-		if( ! wp_verify_nonce( $nonce, 'lesson_remove_multiple_questions_nonce' )
1977
-        || ! current_user_can( 'edit_lessons' ) ) {
1976
+		if ( ! wp_verify_nonce($nonce, 'lesson_remove_multiple_questions_nonce')
1977
+        || ! current_user_can('edit_lessons')) {
1978 1978
 			die('');
1979 1979
 		} // End If Statement
1980 1980
 
1981 1981
 		// Parse POST data
1982 1982
 		$data = $_POST['data'];
1983 1983
 		$question_data = array();
1984
-		parse_str( $data, $question_data );
1984
+		parse_str($data, $question_data);
1985 1985
 
1986
-		if( is_array( $question_data ) ) {
1987
-			wp_delete_post( $question_data['question_id'], true );
1986
+		if (is_array($question_data)) {
1987
+			wp_delete_post($question_data['question_id'], true);
1988 1988
 		}
1989 1989
 
1990
-		die( 'Deleted' );
1990
+		die('Deleted');
1991 1991
 	}
1992 1992
 
1993 1993
 	public function get_question_category_limit() {
@@ -1998,11 +1998,11 @@  discard block
 block discarded – undo
1998 1998
 		// Parse POST data
1999 1999
 		$data = $_POST['data'];
2000 2000
 		$cat_data = array();
2001
-		parse_str( $data, $cat_data );
2001
+		parse_str($data, $cat_data);
2002 2002
 
2003
-		if( isset( $cat_data['cat'] ) && '' != $cat_data['cat'] ) {
2004
-			$cat = get_term( $cat_data['cat'], 'question-category' );
2005
-			if( isset( $cat->count ) ) {
2003
+		if (isset($cat_data['cat']) && '' != $cat_data['cat']) {
2004
+			$cat = get_term($cat_data['cat'], 'question-category');
2005
+			if (isset($cat->count)) {
2006 2006
 				$return = $cat->count;
2007 2007
 			}
2008 2008
 		}
@@ -2016,45 +2016,45 @@  discard block
 block discarded – undo
2016 2016
 
2017 2017
 		//Add nonce security to the request
2018 2018
 		$nonce = '';
2019
-		if( isset( $_POST['lesson_add_existing_questions_nonce'] ) ) {
2020
-			$nonce = esc_html( $_POST['lesson_add_existing_questions_nonce'] );
2019
+		if (isset($_POST['lesson_add_existing_questions_nonce'])) {
2020
+			$nonce = esc_html($_POST['lesson_add_existing_questions_nonce']);
2021 2021
 		} // End If Statement
2022 2022
 
2023
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_existing_questions_nonce' )
2024
-        || ! current_user_can( 'edit_lessons' ) ) {
2023
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_existing_questions_nonce')
2024
+        || ! current_user_can('edit_lessons')) {
2025 2025
 			die('');
2026 2026
 		} // End If Statement
2027 2027
 
2028 2028
 		// Parse POST data
2029 2029
 		$data = $_POST['data'];
2030 2030
 		$question_data = array();
2031
-		parse_str( $data, $question_data );
2031
+		parse_str($data, $question_data);
2032 2032
 
2033 2033
 		$return = '';
2034 2034
 
2035
-		if( is_array( $question_data ) ) {
2035
+		if (is_array($question_data)) {
2036 2036
 
2037
-			if( isset( $question_data['questions'] ) && '' != $question_data['questions'] ) {
2037
+			if (isset($question_data['questions']) && '' != $question_data['questions']) {
2038 2038
 
2039
-				$questions = explode( ',', trim( $question_data['questions'], ',' ) );
2039
+				$questions = explode(',', trim($question_data['questions'], ','));
2040 2040
 				$quiz_id = $question_data['quiz_id'];
2041
-				$question_count = intval( $question_data['question_count'] );
2041
+				$question_count = intval($question_data['question_count']);
2042 2042
 
2043
-				foreach( $questions as $question_id ) {
2043
+				foreach ($questions as $question_id) {
2044 2044
 
2045 2045
 					++$question_count;
2046 2046
 
2047
-					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2048
-					if( ! in_array( $quiz_id, $quizzes ) ) {
2049
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2050
-						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2051
-						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2047
+					$quizzes = get_post_meta($question_id, '_quiz_id', false);
2048
+					if ( ! in_array($quiz_id, $quizzes)) {
2049
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2050
+						$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2051
+						update_post_meta($lesson_id, '_quiz_has_questions', '1');
2052 2052
 			    	}
2053 2053
 
2054
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2055
-					$question_type = Sensei()->question->get_question_type( $question_id );
2054
+			    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2055
+					$question_type = Sensei()->question->get_question_type($question_id);
2056 2056
 
2057
-					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
2057
+					$return .= $this->quiz_panel_question($question_type, $question_count, $question_id);
2058 2058
 				}
2059 2059
 			}
2060 2060
 		}
@@ -2066,14 +2066,14 @@  discard block
 block discarded – undo
2066 2066
 
2067 2067
 	public function lesson_update_grade_type() {
2068 2068
 		//Add nonce security to the request
2069
-		if ( isset($_POST['lesson_update_grade_type_nonce']) ) {
2069
+		if (isset($_POST['lesson_update_grade_type_nonce'])) {
2070 2070
 
2071
-			$nonce = esc_html( $_POST['lesson_update_grade_type_nonce'] );
2071
+			$nonce = esc_html($_POST['lesson_update_grade_type_nonce']);
2072 2072
 
2073 2073
 		} // End If Statement
2074 2074
 
2075
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_grade_type_nonce' )
2076
-        || ! current_user_can( 'edit_lessons' ) ) {
2075
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_grade_type_nonce')
2076
+        || ! current_user_can('edit_lessons')) {
2077 2077
 
2078 2078
 			die('');
2079 2079
 
@@ -2083,18 +2083,18 @@  discard block
 block discarded – undo
2083 2083
 		$data = $_POST['data'];
2084 2084
 		$quiz_data = array();
2085 2085
 		parse_str($data, $quiz_data);
2086
-		update_post_meta( $quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type'] );
2086
+		update_post_meta($quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type']);
2087 2087
 		die();
2088 2088
 	}
2089 2089
 
2090 2090
 	public function lesson_update_question_order() {
2091 2091
 		// Add nonce security to the request
2092
-		if ( isset($_POST['lesson_update_question_order_nonce']) ) {
2093
-			$nonce = esc_html( $_POST['lesson_update_question_order_nonce'] );
2092
+		if (isset($_POST['lesson_update_question_order_nonce'])) {
2093
+			$nonce = esc_html($_POST['lesson_update_question_order_nonce']);
2094 2094
 		} // End If Statement
2095 2095
 
2096
-        if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2097
-            ||! current_user_can( 'edit_lessons' ) ) {
2096
+        if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_nonce')
2097
+            ||! current_user_can('edit_lessons')) {
2098 2098
 			die('');
2099 2099
 		} // End If Statement
2100 2100
 
@@ -2102,25 +2102,25 @@  discard block
 block discarded – undo
2102 2102
 		$data = $_POST['data'];
2103 2103
 		$quiz_data = array();
2104 2104
 		parse_str($data, $quiz_data);
2105
-		if( strlen( $quiz_data['question_order'] ) > 0 ) {
2106
-			$questions = explode( ',', $quiz_data['question_order'] );
2105
+		if (strlen($quiz_data['question_order']) > 0) {
2106
+			$questions = explode(',', $quiz_data['question_order']);
2107 2107
 			$o = 1;
2108
-			foreach( $questions as $question_id ) {
2109
-				update_post_meta( $question_id, '_quiz_question_order' . $quiz_data['quiz_id'], $quiz_data['quiz_id'] . '000' . $o );
2108
+			foreach ($questions as $question_id) {
2109
+				update_post_meta($question_id, '_quiz_question_order'.$quiz_data['quiz_id'], $quiz_data['quiz_id'].'000'.$o);
2110 2110
 				++$o;
2111 2111
 			}
2112
-			update_post_meta( $quiz_data['quiz_id'], '_question_order', $questions );
2112
+			update_post_meta($quiz_data['quiz_id'], '_question_order', $questions);
2113 2113
 		}
2114 2114
 		die();
2115 2115
 	}
2116 2116
 
2117 2117
 	public function lesson_update_question_order_random() {
2118 2118
 		//Add nonce security to the request
2119
-		if ( isset($_POST['lesson_update_question_order_random_nonce']) ) {
2120
-			$nonce = esc_html( $_POST['lesson_update_question_order_random_nonce'] );
2119
+		if (isset($_POST['lesson_update_question_order_random_nonce'])) {
2120
+			$nonce = esc_html($_POST['lesson_update_question_order_random_nonce']);
2121 2121
 		} // End If Statement
2122
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_random_nonce' )
2123
-            || ! current_user_can( 'edit_lessons' ) ) {
2122
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_random_nonce')
2123
+            || ! current_user_can('edit_lessons')) {
2124 2124
 
2125 2125
 			die('');
2126 2126
 
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
 		$data = $_POST['data'];
2130 2130
 		$quiz_data = array();
2131 2131
 		parse_str($data, $quiz_data);
2132
-		update_post_meta( $quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order'] );
2132
+		update_post_meta($quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order']);
2133 2133
 		die();
2134 2134
 	}
2135 2135
 
@@ -2140,7 +2140,7 @@  discard block
 block discarded – undo
2140 2140
 	 * @param array $data (default: array())
2141 2141
 	 * @return integer|boolean $course_id or false
2142 2142
 	 */
2143
-	private function lesson_save_course( $data = array() ) {
2143
+	private function lesson_save_course($data = array()) {
2144 2144
 		global $current_user;
2145 2145
 		$return = false;
2146 2146
 		// Setup the course data
@@ -2149,58 +2149,58 @@  discard block
 block discarded – undo
2149 2149
 		$course_title = '';
2150 2150
 		$course_prerequisite = 0;
2151 2151
 		$course_category = 0;
2152
-		if ( isset( $data[ 'course_id' ] ) && ( 0 < absint( $data[ 'course_id' ] ) ) ) {
2153
-			$course_id = absint( $data[ 'course_id' ] );
2152
+		if (isset($data['course_id']) && (0 < absint($data['course_id']))) {
2153
+			$course_id = absint($data['course_id']);
2154 2154
 		} // End If Statement
2155
-		if ( isset( $data[ 'course_title' ] ) && ( '' != $data[ 'course_title' ] ) ) {
2156
-			$course_title = $data[ 'course_title' ];
2155
+		if (isset($data['course_title']) && ('' != $data['course_title'])) {
2156
+			$course_title = $data['course_title'];
2157 2157
 		} // End If Statement
2158 2158
 		$post_title = $course_title;
2159
-		if ( isset($data[ 'post_author' ]) ) {
2160
-			$post_author = $data[ 'post_author' ];
2159
+		if (isset($data['post_author'])) {
2160
+			$post_author = $data['post_author'];
2161 2161
 		} else {
2162 2162
 			$current_user = wp_get_current_user();
2163 2163
 			$post_author = $current_user->ID;
2164 2164
 		} // End If Statement
2165 2165
 		$post_status = 'publish';
2166 2166
 		$post_type = 'course';
2167
-		if ( isset( $data[ 'course_content' ] ) && ( '' != $data[ 'course_content' ] ) ) {
2168
-			$course_content = $data[ 'course_content' ];
2167
+		if (isset($data['course_content']) && ('' != $data['course_content'])) {
2168
+			$course_content = $data['course_content'];
2169 2169
 		} // End If Statement
2170 2170
 		$post_content = $course_content;
2171 2171
 		// Course Query Arguments
2172
-		$post_type_args = array(	'post_content' => $post_content,
2172
+		$post_type_args = array('post_content' => $post_content,
2173 2173
   		    						'post_status' => $post_status,
2174 2174
   		    						'post_title' => $post_title,
2175 2175
   		    						'post_type' => $post_type
2176 2176
   		    						);
2177 2177
   		// Only save if there is a valid title
2178
-  		if ( $post_title != '' ) {
2178
+  		if ($post_title != '') {
2179 2179
   		    // Check for prerequisite courses & product id
2180
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2181
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2182
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2183
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2180
+  		    $course_prerequisite_id = absint($data['course_prerequisite']);
2181
+  		    $course_woocommerce_product_id = absint($data['course_woocommerce_product']);
2182
+  		    $course_category_id = absint($data['course_category']);
2183
+  		    if (0 == $course_woocommerce_product_id) { $course_woocommerce_product_id = '-'; }
2184 2184
   		    // Insert or Update the Lesson Quiz
2185
-		    if ( 0 < $course_id ) {
2186
-		    	$post_type_args[ 'ID' ] = $course_id;
2185
+		    if (0 < $course_id) {
2186
+		    	$post_type_args['ID'] = $course_id;
2187 2187
 		    	$course_id = wp_update_post($post_type_args);
2188
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2189
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2190
-		    	if ( 0 < $course_category_id ) {
2191
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2188
+		    	update_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2189
+		    	update_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2190
+		    	if (0 < $course_category_id) {
2191
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2192 2192
 		    	} // End If Statement
2193 2193
 		    } else {
2194 2194
 		    	$course_id = wp_insert_post($post_type_args);
2195
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2196
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2197
-		    	if ( 0 < $course_category_id ) {
2198
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2195
+		    	add_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2196
+		    	add_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2197
+		    	if (0 < $course_category_id) {
2198
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2199 2199
 		    	} // End If Statement
2200 2200
 		    } // End If Statement
2201 2201
 		} // End If Statement
2202 2202
   		// Check that the insert or update saved by testing the post id
2203
-  		if ( 0 < $course_id ) {
2203
+  		if (0 < $course_id) {
2204 2204
   			$return = $course_id;
2205 2205
   		} // End If Statement
2206 2206
   		return $return;
@@ -2214,7 +2214,7 @@  discard block
 block discarded – undo
2214 2214
 	 * @param array $data (default: array())
2215 2215
 	 * @return integer|boolean $question_id or false
2216 2216
 	 */
2217
-	public function lesson_save_question( $data = array(), $context = 'quiz' ) {
2217
+	public function lesson_save_question($data = array(), $context = 'quiz') {
2218 2218
 		$return = false;
2219 2219
 		// Save the Questions
2220 2220
 		// Setup the Question data
@@ -2226,130 +2226,130 @@  discard block
 block discarded – undo
2226 2226
 		$question_category = '';
2227 2227
 
2228 2228
 		// Handle Question Type
2229
-		if ( isset( $data[ 'question_type' ] ) && ( '' != $data[ 'question_type' ] ) ) {
2230
-			$question_type = $data[ 'question_type' ];
2229
+		if (isset($data['question_type']) && ('' != $data['question_type'])) {
2230
+			$question_type = $data['question_type'];
2231 2231
 		} // End If Statement
2232 2232
 
2233
-		if ( isset( $data[ 'question_category' ] ) && ( '' != $data[ 'question_category' ] ) ) {
2234
-			$question_category = $data[ 'question_category' ];
2233
+		if (isset($data['question_category']) && ('' != $data['question_category'])) {
2234
+			$question_category = $data['question_category'];
2235 2235
 		} // End If Statement
2236 2236
 
2237
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2238
-			$question_id = absint( $data[ 'question_id' ] );
2237
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2238
+			$question_id = absint($data['question_id']);
2239 2239
 		} // End If Statement
2240
-		if ( isset( $data[ 'question' ] ) && ( '' != $data[ 'question' ] ) ) {
2241
-			$question_text = $data[ 'question' ];
2240
+		if (isset($data['question']) && ('' != $data['question'])) {
2241
+			$question_text = $data['question'];
2242 2242
 		} // End If Statement
2243 2243
 		$post_title = $question_text;
2244 2244
 		// Handle Default Fields (multiple choice)
2245
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answers' ] ) && ( '' != $data[ 'question_right_answers' ] ) ) {
2246
-			$question_right_answers = $data[ 'question_right_answers' ];
2245
+		if ('multiple-choice' == $question_type && isset($data['question_right_answers']) && ('' != $data['question_right_answers'])) {
2246
+			$question_right_answers = $data['question_right_answers'];
2247 2247
 		} // End If Statement
2248
-		elseif ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answer' ] ) && ( '' != $data[ 'question_right_answer' ] ) ) {
2249
-			$question_right_answer = $data[ 'question_right_answer' ];
2248
+		elseif ('multiple-choice' == $question_type && isset($data['question_right_answer']) && ('' != $data['question_right_answer'])) {
2249
+			$question_right_answer = $data['question_right_answer'];
2250 2250
 		} // End If Statement
2251
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_wrong_answers' ] ) && ( '' != $data[ 'question_wrong_answers' ] ) ) {
2252
-			$question_wrong_answers = $data[ 'question_wrong_answers' ];
2251
+		if ('multiple-choice' == $question_type && isset($data['question_wrong_answers']) && ('' != $data['question_wrong_answers'])) {
2252
+			$question_wrong_answers = $data['question_wrong_answers'];
2253 2253
 		} // End If Statement
2254 2254
 		// Handle Boolean Fields - Edit
2255
-		if ( 'boolean' == $question_type && isset( $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) && ( '' != $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) ) {
2256
-			$question_right_answer = $data[ 'question_' . $question_id . '_right_answer_boolean' ];
2255
+		if ('boolean' == $question_type && isset($data['question_'.$question_id.'_right_answer_boolean']) && ('' != $data['question_'.$question_id.'_right_answer_boolean'])) {
2256
+			$question_right_answer = $data['question_'.$question_id.'_right_answer_boolean'];
2257 2257
 		} // End If Statement
2258 2258
 		// Handle Boolean Fields - Add
2259
-		if ( 'boolean' == $question_type && isset( $data[ 'question_right_answer_boolean' ] ) && ( '' != $data[ 'question_right_answer_boolean' ] ) ) {
2260
-			$question_right_answer = $data[ 'question_right_answer_boolean' ];
2259
+		if ('boolean' == $question_type && isset($data['question_right_answer_boolean']) && ('' != $data['question_right_answer_boolean'])) {
2260
+			$question_right_answer = $data['question_right_answer_boolean'];
2261 2261
 		} // End If Statement
2262 2262
 		// Handle Gap Fill Fields
2263
-		if ( 'gap-fill' == $question_type && isset( $data[ 'add_question_right_answer_gapfill_gap' ] ) && '' != $data[ 'add_question_right_answer_gapfill_gap' ] ) {
2264
-			$question_right_answer = $data[ 'add_question_right_answer_gapfill_pre' ] . '||' . $data[ 'add_question_right_answer_gapfill_gap' ] . '||' . $data[ 'add_question_right_answer_gapfill_post' ];
2263
+		if ('gap-fill' == $question_type && isset($data['add_question_right_answer_gapfill_gap']) && '' != $data['add_question_right_answer_gapfill_gap']) {
2264
+			$question_right_answer = $data['add_question_right_answer_gapfill_pre'].'||'.$data['add_question_right_answer_gapfill_gap'].'||'.$data['add_question_right_answer_gapfill_post'];
2265 2265
 		} // End If Statement
2266 2266
 		// Handle Multi Line Fields
2267
-		if ( 'multi-line' == $question_type && isset( $data[ 'add_question_right_answer_multiline' ] ) && ( '' != $data[ 'add_question_right_answer_multiline' ] ) ) {
2268
-			$question_right_answer = $data[ 'add_question_right_answer_multiline' ];
2267
+		if ('multi-line' == $question_type && isset($data['add_question_right_answer_multiline']) && ('' != $data['add_question_right_answer_multiline'])) {
2268
+			$question_right_answer = $data['add_question_right_answer_multiline'];
2269 2269
 		} // End If Statement
2270 2270
 		// Handle Single Line Fields
2271
-		if ( 'single-line' == $question_type && isset( $data[ 'add_question_right_answer_singleline' ] ) && ( '' != $data[ 'add_question_right_answer_singleline' ] ) ) {
2272
-			$question_right_answer = $data[ 'add_question_right_answer_singleline' ];
2271
+		if ('single-line' == $question_type && isset($data['add_question_right_answer_singleline']) && ('' != $data['add_question_right_answer_singleline'])) {
2272
+			$question_right_answer = $data['add_question_right_answer_singleline'];
2273 2273
 		} // End If Statement
2274 2274
 		// Handle File Upload Fields
2275
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_right_answer_fileupload' ] ) && ( '' != $data[ 'add_question_right_answer_fileupload' ] ) ) {
2276
-			$question_right_answer = $data[ 'add_question_right_answer_fileupload' ];
2275
+		if ('file-upload' == $question_type && isset($data['add_question_right_answer_fileupload']) && ('' != $data['add_question_right_answer_fileupload'])) {
2276
+			$question_right_answer = $data['add_question_right_answer_fileupload'];
2277 2277
 		} // End If Statement
2278
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_wrong_answer_fileupload' ] ) && ( '' != $data[ 'add_question_wrong_answer_fileupload' ] ) ) {
2279
-			$question_wrong_answers = array( $data[ 'add_question_wrong_answer_fileupload' ] );
2278
+		if ('file-upload' == $question_type && isset($data['add_question_wrong_answer_fileupload']) && ('' != $data['add_question_wrong_answer_fileupload'])) {
2279
+			$question_wrong_answers = array($data['add_question_wrong_answer_fileupload']);
2280 2280
 		} // End If Statement
2281 2281
 
2282 2282
 		// Handle Question Grade
2283
-		if ( isset( $data[ 'question_grade' ] ) && ( '' != $data[ 'question_grade' ] ) ) {
2284
-			$question_grade = $data[ 'question_grade' ];
2283
+		if (isset($data['question_grade']) && ('' != $data['question_grade'])) {
2284
+			$question_grade = $data['question_grade'];
2285 2285
 		} // End If Statement
2286 2286
 
2287 2287
 		// Handle Answer Feedback
2288 2288
 		$answer_feedback = '';
2289
-		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2289
+		if (isset($data['answer_feedback_boolean']) && ! empty($data['answer_feedback_boolean'])) {
2290 2290
 
2291
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2291
+            $answer_feedback = $data['answer_feedback_boolean'];
2292 2292
 
2293
-		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2293
+		}elseif (isset($data['answer_feedback_multiple_choice']) && ! empty($data['answer_feedback_multiple_choice'])) {
2294 2294
 
2295
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2295
+            $answer_feedback = $data['answer_feedback_multiple_choice'];
2296 2296
 
2297
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2297
+        }elseif (isset($data['answer_feedback'])) {
2298 2298
 
2299
-            $answer_feedback = $data[ 'answer_feedback' ];
2299
+            $answer_feedback = $data['answer_feedback'];
2300 2300
 
2301 2301
         } // End If Statement
2302 2302
 
2303 2303
 		$post_title = $question_text;
2304
-		$post_author = $data[ 'post_author' ];
2304
+		$post_author = $data['post_author'];
2305 2305
 		$post_status = 'publish';
2306 2306
 		$post_type = 'question';
2307 2307
 		// Handle the extended question text
2308
-		if ( isset( $data[ 'question_description' ] ) && ( '' != $data[ 'question_description' ] ) ) {
2309
-			$post_content = $data[ 'question_description' ];
2308
+		if (isset($data['question_description']) && ('' != $data['question_description'])) {
2309
+			$post_content = $data['question_description'];
2310 2310
 		}
2311 2311
 		else {
2312 2312
 			$post_content = '';
2313 2313
 		}
2314 2314
 		// Question Query Arguments
2315
-		$post_type_args = array(	'post_content' => $post_content,
2315
+		$post_type_args = array('post_content' => $post_content,
2316 2316
   		    						'post_status' => $post_status,
2317 2317
   		    						'post_title' => $post_title,
2318 2318
   		    						'post_type' => $post_type
2319 2319
   		    						);
2320 2320
 
2321 2321
   		// Remove empty values and reindex the array
2322
-  		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
2323
-  			$question_right_answers_array = array_values( array_filter( $question_right_answers, 'strlen' ) );
2322
+  		if (is_array($question_right_answers) && 0 < count($question_right_answers)) {
2323
+  			$question_right_answers_array = array_values(array_filter($question_right_answers, 'strlen'));
2324 2324
   			$question_right_answers = array();
2325 2325
 
2326
-  			foreach( $question_right_answers_array as $answer ) {
2327
-  				if( ! in_array( $answer, $question_right_answers ) ) {
2326
+  			foreach ($question_right_answers_array as $answer) {
2327
+  				if ( ! in_array($answer, $question_right_answers)) {
2328 2328
   					$question_right_answers[] = $answer;
2329 2329
   				}
2330 2330
   			}
2331
-  			if ( 0 < count($question_right_answers) ) {
2331
+  			if (0 < count($question_right_answers)) {
2332 2332
   				$question_right_answer = $question_right_answers;
2333 2333
   			}
2334 2334
   		} // End If Statement
2335
-  		$right_answer_count = count( $question_right_answer );
2335
+  		$right_answer_count = count($question_right_answer);
2336 2336
 
2337 2337
 		// Remove empty values and reindex the array
2338
-  		if ( is_array( $question_wrong_answers ) ) {
2339
-  			$question_wrong_answers_array = array_values( array_filter( $question_wrong_answers, 'strlen' ) );
2338
+  		if (is_array($question_wrong_answers)) {
2339
+  			$question_wrong_answers_array = array_values(array_filter($question_wrong_answers, 'strlen'));
2340 2340
   			$question_wrong_answers = array();
2341 2341
   		} // End If Statement
2342 2342
 
2343
-  		foreach( $question_wrong_answers_array as $answer ) {
2344
-  			if( ! in_array( $answer, $question_wrong_answers ) ) {
2343
+  		foreach ($question_wrong_answers_array as $answer) {
2344
+  			if ( ! in_array($answer, $question_wrong_answers)) {
2345 2345
   				$question_wrong_answers[] = $answer;
2346 2346
   			}
2347 2347
   		}
2348 2348
 
2349
-  		$wrong_answer_count = count( $question_wrong_answers );
2349
+  		$wrong_answer_count = count($question_wrong_answers);
2350 2350
 
2351 2351
   		// Only save if there is a valid title
2352
-  		if ( $post_title != '' ) {
2352
+  		if ($post_title != '') {
2353 2353
 
2354 2354
   			// Get Quiz ID for the question
2355 2355
   		    $quiz_id = $data['quiz_id'];
@@ -2359,86 +2359,86 @@  discard block
 block discarded – undo
2359 2359
 
2360 2360
   		    // Get answer order
2361 2361
   		    $answer_order = '';
2362
-  		    if( isset( $data['answer_order'] ) ) {
2362
+  		    if (isset($data['answer_order'])) {
2363 2363
 				$answer_order = $data['answer_order'];
2364 2364
 			}
2365 2365
 
2366 2366
 			// Get random order selection
2367 2367
 			$random_order = 'no';
2368
-			if( isset( $data['random_order'] ) ) {
2368
+			if (isset($data['random_order'])) {
2369 2369
 				$random_order = $data['random_order'];
2370 2370
 			}
2371 2371
 
2372 2372
   		    // Insert or Update the question
2373
-  		    if ( 0 < $question_id ) {
2373
+  		    if (0 < $question_id) {
2374 2374
 
2375
-  		    	$post_type_args[ 'ID' ] = $question_id;
2376
-		    	$question_id = wp_update_post( $post_type_args );
2375
+  		    	$post_type_args['ID'] = $question_id;
2376
+		    	$question_id = wp_update_post($post_type_args);
2377 2377
 
2378 2378
 		    	// Update poast meta
2379
-		    	if( 'quiz' == $context ) {
2380
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2381
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2382
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2379
+		    	if ('quiz' == $context) {
2380
+		    		$quizzes = get_post_meta($question_id, '_quiz_id', false);
2381
+		    		if ( ! in_array($quiz_id, $quizzes)) {
2382
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2383 2383
 			    	}
2384 2384
 		    	}
2385 2385
 
2386
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2387
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2388
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2389
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2390
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2391
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2392
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2393
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2394
-
2395
-		    	if( 'quiz' != $context ) {
2396
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2386
+		    	update_post_meta($question_id, '_question_grade', $question_grade);
2387
+		    	update_post_meta($question_id, '_question_right_answer', $question_right_answer);
2388
+		    	update_post_meta($question_id, '_right_answer_count', $right_answer_count);
2389
+		    	update_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2390
+		    	update_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2391
+		    	update_post_meta($question_id, '_question_media', $question_media);
2392
+		    	update_post_meta($question_id, '_answer_order', $answer_order);
2393
+		    	update_post_meta($question_id, '_random_order', $random_order);
2394
+
2395
+		    	if ('quiz' != $context) {
2396
+		    		wp_set_post_terms($question_id, array($question_type), 'question-type', false);
2397 2397
 		    	}
2398 2398
 				// Don't store empty value, no point
2399
-				if ( !empty($answer_feedback) ) {
2400
-					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2399
+				if ( ! empty($answer_feedback)) {
2400
+					update_post_meta($question_id, '_answer_feedback', $answer_feedback);
2401 2401
 				}
2402 2402
 
2403 2403
 		    } else {
2404
-				$question_id = wp_insert_post( $post_type_args );
2405
-				$question_count = intval( $data['question_count'] );
2404
+				$question_id = wp_insert_post($post_type_args);
2405
+				$question_count = intval($data['question_count']);
2406 2406
 				++$question_count;
2407 2407
 
2408 2408
 				// Set post meta
2409
-				if( 'quiz' == $context ) {
2410
-					add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2411
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2412
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2409
+				if ('quiz' == $context) {
2410
+					add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2411
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2412
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
2413 2413
 				}
2414 2414
 
2415
-				if( isset( $question_grade ) ) {
2416
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2415
+				if (isset($question_grade)) {
2416
+		    		add_post_meta($question_id, '_question_grade', $question_grade);
2417 2417
 		    	}
2418
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2419
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2420
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2421
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2422
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2423
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2424
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2425
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2418
+		    	add_post_meta($question_id, '_question_right_answer', $question_right_answer);
2419
+		    	add_post_meta($question_id, '_right_answer_count', $right_answer_count);
2420
+		    	add_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2421
+		    	add_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2422
+		    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2423
+		    	add_post_meta($question_id, '_question_media', $question_media);
2424
+		    	add_post_meta($question_id, '_answer_order', $answer_order);
2425
+		    	add_post_meta($question_id, '_random_order', $random_order);
2426 2426
 				// Don't store empty value, no point
2427
-				if ( !empty($answer_feedback) ) {
2428
-					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2427
+				if ( ! empty($answer_feedback)) {
2428
+					add_post_meta($question_id, '_answer_feedback', $answer_feedback);
2429 2429
 				}
2430 2430
 
2431 2431
 		    	// Set the post terms for question-type
2432
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2432
+			    wp_set_post_terms($question_id, array($question_type), 'question-type');
2433 2433
 
2434
-			    if( $question_category ) {
2435
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2434
+			    if ($question_category) {
2435
+	    			wp_set_post_terms($question_id, array($question_category), 'question-category');
2436 2436
 	    		}
2437 2437
 
2438 2438
 		    } // End If Statement
2439 2439
 		} // End If Statement
2440 2440
   		// Check that the insert or update saved by testing the post id
2441
-  		if ( 0 < $question_id ) {
2441
+  		if (0 < $question_id) {
2442 2442
   			$return = $question_id;
2443 2443
   		} // End If Statement
2444 2444
   		return $return;
@@ -2452,20 +2452,20 @@  discard block
 block discarded – undo
2452 2452
 	 * @param array $data (default: array())
2453 2453
 	 * @return boolean
2454 2454
 	 */
2455
-	private function lesson_delete_question( $data = array() ) {
2455
+	private function lesson_delete_question($data = array()) {
2456 2456
 
2457 2457
 		// Get which question to delete
2458 2458
 		$question_id = 0;
2459
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2460
-			$question_id = absint( $data[ 'question_id' ] );
2459
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2460
+			$question_id = absint($data['question_id']);
2461 2461
 		} // End If Statement
2462 2462
 		// Delete the question
2463
-		if ( 0 < $question_id ) {
2464
-			$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2463
+		if (0 < $question_id) {
2464
+			$quizzes = get_post_meta($question_id, '_quiz_id', false);
2465 2465
 
2466
-			foreach( $quizzes as $quiz_id ) {
2467
-				if( $quiz_id == $data['quiz_id'] ) {
2468
-					delete_post_meta( $question_id, '_quiz_id', $quiz_id );
2466
+			foreach ($quizzes as $quiz_id) {
2467
+				if ($quiz_id == $data['quiz_id']) {
2468
+					delete_post_meta($question_id, '_quiz_id', $quiz_id);
2469 2469
 				}
2470 2470
 			}
2471 2471
 
@@ -2484,9 +2484,9 @@  discard block
 block discarded – undo
2484 2484
 	public function lesson_complexities() {
2485 2485
 
2486 2486
 		// V2 - make filter for this array
2487
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2488
-									'std' => __( 'Standard', 'woothemes-sensei' ),
2489
-									'hard' => __( 'Hard', 'woothemes-sensei' )
2487
+        $lesson_complexities = array('easy' => __('Easy', 'woothemes-sensei'),
2488
+									'std' => __('Standard', 'woothemes-sensei'),
2489
+									'hard' => __('Hard', 'woothemes-sensei')
2490 2490
 									);
2491 2491
 
2492 2492
 		return $lesson_complexities;
@@ -2501,9 +2501,9 @@  discard block
 block discarded – undo
2501 2501
 	 * @param string $post_status (default: 'publish')
2502 2502
 	 * @return int
2503 2503
 	 */
2504
-	public function lesson_count( $post_status = 'publish', $course_id = false ) {
2504
+	public function lesson_count($post_status = 'publish', $course_id = false) {
2505 2505
 
2506
-		$post_args = array(	'post_type'         => 'lesson',
2506
+		$post_args = array('post_type'         => 'lesson',
2507 2507
 							'posts_per_page'    => -1,
2508 2508
 //							'orderby'           => 'menu_order date',
2509 2509
 //							'order'             => 'ASC',
@@ -2511,7 +2511,7 @@  discard block
 block discarded – undo
2511 2511
 							'suppress_filters'  => 0,
2512 2512
 							'fields'            => 'ids',
2513 2513
 							);
2514
-		if( $course_id ) {
2514
+		if ($course_id) {
2515 2515
 			$post_args['meta_query'][] = array(
2516 2516
 				'key' => '_lesson_course',
2517 2517
 				'value' => $course_id,
@@ -2528,10 +2528,10 @@  discard block
 block discarded – undo
2528 2528
 
2529 2529
 		// Allow WP to generate the complex final query, just shortcut to only do an overall count
2530 2530
 //		add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2531
-		$lessons_query = new WP_Query( apply_filters( 'sensei_lesson_count', $post_args ) );
2531
+		$lessons_query = new WP_Query(apply_filters('sensei_lesson_count', $post_args));
2532 2532
 //		remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2533 2533
 
2534
-		return count( $lessons_query->posts );
2534
+		return count($lessons_query->posts);
2535 2535
 	} // End lesson_count()
2536 2536
 
2537 2537
 
@@ -2544,11 +2544,11 @@  discard block
 block discarded – undo
2544 2544
 	 * @param string $fields (default: 'ids')
2545 2545
 	 * @return int $quiz_id
2546 2546
 	 */
2547
-	public function lesson_quizzes( $lesson_id = 0, $post_status = 'any', $fields = 'ids' ) {
2547
+	public function lesson_quizzes($lesson_id = 0, $post_status = 'any', $fields = 'ids') {
2548 2548
 
2549 2549
 		$posts_array = array();
2550 2550
 
2551
-		$post_args = array(	'post_type' 		=> 'quiz',
2551
+		$post_args = array('post_type' 		=> 'quiz',
2552 2552
 							'posts_per_page' 		=> 1,
2553 2553
 							'orderby'         	=> 'title',
2554 2554
     						'order'           	=> 'DESC',
@@ -2557,7 +2557,7 @@  discard block
 block discarded – undo
2557 2557
 							'suppress_filters' 	=> 0,
2558 2558
 							'fields'            => $fields
2559 2559
 							);
2560
-		$posts_array = get_posts( $post_args );
2560
+		$posts_array = get_posts($post_args);
2561 2561
         $quiz_id = array_shift($posts_array);
2562 2562
 
2563 2563
 		return $quiz_id;
@@ -2580,37 +2580,37 @@  discard block
 block discarded – undo
2580 2580
      *
2581 2581
 	 * @return array $questions { $question type WP_Post }
2582 2582
 	 */
2583
-	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2583
+	public function lesson_quiz_questions($quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC') {
2584 2584
 
2585 2585
 		$quiz_id = (string) $quiz_id;
2586
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2586
+        $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
2587 2587
 
2588 2588
         // setup the user id
2589
-        if( is_admin() ) {
2590
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2589
+        if (is_admin()) {
2590
+            $user_id = isset($_GET['user']) ? $_GET['user'] : '';
2591 2591
         } else {
2592 2592
             $user_id = get_current_user_id();
2593 2593
         }
2594 2594
 
2595 2595
         // get the users current status on the lesson
2596
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2596
+        $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $user_id);
2597 2597
 
2598 2598
 		// Set the default question order if it has not already been set for this quiz
2599
-		$this->set_default_question_order( $quiz_id );
2599
+		$this->set_default_question_order($quiz_id);
2600 2600
 
2601 2601
 		// If viewing quiz on the frontend then show questions in random order if set
2602
-		if ( ! is_admin() ) {
2603
-			$random_order = get_post_meta( $quiz_id, '_random_question_order', true );
2604
-			if( $random_order && $random_order == 'yes' ) {
2602
+		if ( ! is_admin()) {
2603
+			$random_order = get_post_meta($quiz_id, '_random_question_order', true);
2604
+			if ($random_order && $random_order == 'yes') {
2605 2605
 				$orderby = 'rand';
2606 2606
 			}
2607 2607
 		}
2608 2608
 
2609 2609
 		// Get all questions and multiple questions
2610 2610
 		$question_query_args = array(
2611
-			'post_type' 		=> array( 'question', 'multiple_question' ),
2611
+			'post_type' 		=> array('question', 'multiple_question'),
2612 2612
 			'posts_per_page' 	=> -1,
2613
-			'meta_key'        	=> '_quiz_question_order' . $quiz_id,
2613
+			'meta_key'        	=> '_quiz_question_order'.$quiz_id,
2614 2614
 			'orderby'         	=> $orderby,
2615 2615
 			'order'           	=> $order,
2616 2616
 			'meta_query'		=> array(
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
 		);
2625 2625
 
2626 2626
         //query the questions
2627
-		$questions_query = new WP_Query( $question_query_args );
2627
+		$questions_query = new WP_Query($question_query_args);
2628 2628
 
2629 2629
         // Set return array to initially include all items
2630 2630
         $questions = $questions_query->posts;
@@ -2634,20 +2634,20 @@  discard block
 block discarded – undo
2634 2634
 
2635 2635
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2636 2636
 		$selected_questions = false;
2637
-		if( ! is_admin() || ( is_admin() && isset( $_GET['page'] ) && 'sensei_grading' == $_GET['page'] && isset( $_GET['user'] ) && isset( $_GET['quiz_id'] ) ) ) {
2637
+		if ( ! is_admin() || (is_admin() && isset($_GET['page']) && 'sensei_grading' == $_GET['page'] && isset($_GET['user']) && isset($_GET['quiz_id']))) {
2638 2638
 
2639 2639
 			// Fetch the questions that the user was asked in their quiz if they have already completed it
2640
-			$questions_asked_string = !empty( $user_lesson_status->comment_ID) ? get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ) : false;
2641
-			if( !empty($questions_asked_string) ) {
2640
+			$questions_asked_string = ! empty($user_lesson_status->comment_ID) ? get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true) : false;
2641
+			if ( ! empty($questions_asked_string)) {
2642 2642
 
2643
-				$selected_questions = explode( ',', $questions_asked_string );
2643
+				$selected_questions = explode(',', $questions_asked_string);
2644 2644
 
2645 2645
 				// Fetch each question in the order in which they were asked
2646 2646
 				$questions = array();
2647
-				foreach( $selected_questions as $question_id ) {
2648
-					if( ! $question_id ) continue;
2649
-					$question = get_post( $question_id );
2650
-					if( ! isset( $question ) || ! isset( $question->ID ) ) continue;
2647
+				foreach ($selected_questions as $question_id) {
2648
+					if ( ! $question_id) continue;
2649
+					$question = get_post($question_id);
2650
+					if ( ! isset($question) || ! isset($question->ID)) continue;
2651 2651
 					$questions[] = $question;
2652 2652
 				}
2653 2653
 
@@ -2659,24 +2659,24 @@  discard block
 block discarded – undo
2659 2659
 				$existing_questions = array();
2660 2660
 
2661 2661
 				// Set array of questions that already exist so we can prevent duplicates from appearing
2662
-				foreach( $questions_array as $question ) {
2663
-					if( 'question' != $question->post_type ) continue;
2662
+				foreach ($questions_array as $question) {
2663
+					if ('question' != $question->post_type) continue;
2664 2664
 					$existing_questions[] = $question->ID;
2665 2665
 				}
2666 2666
 
2667 2667
 				// Include only single questions in the return array
2668 2668
 				$questions_loop = $questions_array;
2669 2669
 				$questions_array = array();
2670
-				foreach( $questions_loop as $k => $question ) {
2670
+				foreach ($questions_loop as $k => $question) {
2671 2671
 
2672 2672
 					// If this is a single question then include it
2673
-					if( 'question' == $question->post_type ) {
2673
+					if ('question' == $question->post_type) {
2674 2674
 						$questions_array[] = $question;
2675 2675
 					} else {
2676 2676
 
2677 2677
 						// If this is a multiple question then get the specified amount of questions from the specified category
2678
-						$question_cat = intval( get_post_meta( $question->ID, 'category', true ) );
2679
-						$question_number = intval( get_post_meta( $question->ID, 'number', true ) );
2678
+						$question_cat = intval(get_post_meta($question->ID, 'category', true));
2679
+						$question_number = intval(get_post_meta($question->ID, 'number', true));
2680 2680
 
2681 2681
 						$qargs = array(
2682 2682
 							'post_type' 		=> 'question',
@@ -2693,14 +2693,14 @@  discard block
 block discarded – undo
2693 2693
 							'suppress_filters' 	=> 0,
2694 2694
 							'post__not_in'		=> $existing_questions,
2695 2695
 						);
2696
-						$cat_questions = get_posts( $qargs );
2696
+						$cat_questions = get_posts($qargs);
2697 2697
 
2698 2698
 						// Merge results into return array
2699
-						$questions_array = array_merge( $questions_array, $cat_questions );
2699
+						$questions_array = array_merge($questions_array, $cat_questions);
2700 2700
 
2701 2701
 						// Add selected questions to existing questions array to prevent duplicates from being added
2702
-						foreach( $questions_array as $cat_question ) {
2703
-							if( in_array( $cat_question->ID, $existing_questions ) ) continue;
2702
+						foreach ($questions_array as $cat_question) {
2703
+							if (in_array($cat_question->ID, $existing_questions)) continue;
2704 2704
 							$existing_questions[] = $cat_question->ID;
2705 2705
 						}
2706 2706
 					}
@@ -2712,29 +2712,29 @@  discard block
 block discarded – undo
2712 2712
 		}
2713 2713
 
2714 2714
 		// If user has not already taken the quiz and a limited number of questions are to be shown, then show a random selection of the specified amount of questions
2715
-		if( ! $selected_questions ) {
2715
+		if ( ! $selected_questions) {
2716 2716
 
2717 2717
 			// Only limit questions like this on the frontend
2718
-			if( ! is_admin() ) {
2718
+			if ( ! is_admin()) {
2719 2719
 
2720 2720
 				// Get number of questions to show
2721
-				$show_questions = intval( get_post_meta( $quiz_id, '_show_questions', true ) );
2722
-				if( $show_questions ) {
2721
+				$show_questions = intval(get_post_meta($quiz_id, '_show_questions', true));
2722
+				if ($show_questions) {
2723 2723
 
2724 2724
 					// Get random set of array keys from selected questions array
2725
-					$selected_questions = array_rand( $questions_array, $show_questions );
2725
+					$selected_questions = array_rand($questions_array, $show_questions);
2726 2726
 
2727 2727
 					// Loop through all questions and pick the the ones to be shown based on the random key selection
2728 2728
 					$questions = array();
2729
-					foreach( $questions_array as $k => $question ) {
2729
+					foreach ($questions_array as $k => $question) {
2730 2730
 
2731 2731
 						// Random keys will always be an array, unless only one question is to be shown
2732
-						if( is_array( $selected_questions ) ) {
2733
-							if( in_array( $k, $selected_questions ) ) {
2732
+						if (is_array($selected_questions)) {
2733
+							if (in_array($k, $selected_questions)) {
2734 2734
 								$questions[] = $question;
2735 2735
 							}
2736
-						} elseif( 1 == $show_questions ) {
2737
-							if ( $selected_questions == $k ) {
2736
+						} elseif (1 == $show_questions) {
2737
+							if ($selected_questions == $k) {
2738 2738
 								$questions[] = $question;
2739 2739
 							}
2740 2740
 						}
@@ -2745,12 +2745,12 @@  discard block
 block discarded – undo
2745 2745
 
2746 2746
         // Save the questions that will be asked for the current user
2747 2747
         // this happens only once per user/quiz, unless the user resets the quiz
2748
-        if( ! is_admin() ){
2748
+        if ( ! is_admin()) {
2749 2749
 
2750
-            if( $user_lesson_status ) {
2750
+            if ($user_lesson_status) {
2751 2751
 
2752 2752
                 $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2753
-                if ( empty($questions_asked) && $user_lesson_status) {
2753
+                if (empty($questions_asked) && $user_lesson_status) {
2754 2754
 
2755 2755
                     $questions_asked = array();
2756 2756
                     foreach ($questions as $question) {
@@ -2773,7 +2773,7 @@  discard block
 block discarded – undo
2773 2773
          * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2774 2774
          * @since 1.8.0
2775 2775
          */
2776
-		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2776
+		return apply_filters('sensei_lesson_quiz_questions', $questions, $quiz_id);
2777 2777
 
2778 2778
 	} // End lesson_quiz_questions()
2779 2779
 
@@ -2781,13 +2781,13 @@  discard block
 block discarded – undo
2781 2781
 	 * Set the default quiz order
2782 2782
 	 * @param integer $quiz_id ID of quiz
2783 2783
 	 */
2784
-	public function set_default_question_order( $quiz_id = 0 ) {
2784
+	public function set_default_question_order($quiz_id = 0) {
2785 2785
 
2786
-		if( $quiz_id ) {
2786
+		if ($quiz_id) {
2787 2787
 
2788
-			$question_order = get_post_meta( $quiz_id, '_question_order', true );
2788
+			$question_order = get_post_meta($quiz_id, '_question_order', true);
2789 2789
 
2790
-			if( ! $question_order ) {
2790
+			if ( ! $question_order) {
2791 2791
 
2792 2792
 				$args = array(
2793 2793
 					'post_type' 		=> 'question',
@@ -2803,11 +2803,11 @@  discard block
 block discarded – undo
2803 2803
 					'post_status'		=> 'any',
2804 2804
 					'suppress_filters' 	=> 0
2805 2805
 				);
2806
-				$questions = get_posts( $args );
2806
+				$questions = get_posts($args);
2807 2807
 
2808 2808
 				$o = 1;
2809
-				foreach( $questions as $question ) {
2810
-					add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $o, true );
2809
+				foreach ($questions as $question) {
2810
+					add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$o, true);
2811 2811
 					$o++;
2812 2812
 				}
2813 2813
 			}
@@ -2826,36 +2826,36 @@  discard block
 block discarded – undo
2826 2826
 	 * @param string $height (default: '100')
2827 2827
 	 * @return string
2828 2828
 	 */
2829
-	public function lesson_image( $lesson_id = 0, $width = '100', $height = '100', $widget = false ) {
2829
+	public function lesson_image($lesson_id = 0, $width = '100', $height = '100', $widget = false) {
2830 2830
 
2831 2831
 		$html = '';
2832 2832
 
2833 2833
 		// Get Width and Height settings
2834
-		if ( ( $width == '100' ) && ( $height == '100' ) ) {
2834
+		if (($width == '100') && ($height == '100')) {
2835 2835
 
2836
-			if ( is_singular( 'lesson' ) ) {
2836
+			if (is_singular('lesson')) {
2837 2837
 
2838
-				if ( ! $widget && ! Sensei()->settings->settings[ 'lesson_single_image_enable' ] ) {
2838
+				if ( ! $widget && ! Sensei()->settings->settings['lesson_single_image_enable']) {
2839 2839
 
2840 2840
 					return '';
2841 2841
 
2842 2842
 				} // End If Statement
2843 2843
 
2844 2844
 				$image_thumb_size = 'lesson_single_image';
2845
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2845
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2846 2846
 				$width = $dimensions['width'];
2847 2847
 				$height = $dimensions['height'];
2848 2848
 				$crop = $dimensions['crop'];
2849 2849
 
2850 2850
 			} else {
2851 2851
 
2852
-				if ( ! $widget && ! Sensei()->settings->settings[ 'course_lesson_image_enable' ] ) {
2852
+				if ( ! $widget && ! Sensei()->settings->settings['course_lesson_image_enable']) {
2853 2853
 
2854 2854
 					return '';
2855 2855
 				} // End If Statement
2856 2856
 
2857 2857
 				$image_thumb_size = 'lesson_archive_image';
2858
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2858
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2859 2859
 				$width = $dimensions['width'];
2860 2860
 				$height = $dimensions['height'];
2861 2861
 				$crop = $dimensions['crop'];
@@ -2866,23 +2866,23 @@  discard block
 block discarded – undo
2866 2866
 
2867 2867
 		$img_url = '';
2868 2868
 
2869
-		if ( has_post_thumbnail( $lesson_id ) ) {
2869
+		if (has_post_thumbnail($lesson_id)) {
2870 2870
 
2871 2871
    			// Get Featured Image
2872
-   			$img_url = get_the_post_thumbnail( $lesson_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
2872
+   			$img_url = get_the_post_thumbnail($lesson_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
2873 2873
 
2874 2874
  		} else {
2875 2875
 
2876 2876
  			// Display Image Placeholder if none
2877
-			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2877
+			if (Sensei()->settings->settings['placeholder_images_enable']) {
2878 2878
              
2879
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="' . Sensei()->plugin_url . 'assets/images/placeholder.png" width="' . $width . '" height="' . $height . '" class="woo-image thumbnail alignleft" />' );
2879
+                $img_url = apply_filters('sensei_lesson_placeholder_image_url', '<img src="'.Sensei()->plugin_url.'assets/images/placeholder.png" width="'.$width.'" height="'.$height.'" class="woo-image thumbnail alignleft" />');
2880 2880
 
2881 2881
 			} // End If Statement
2882 2882
 
2883 2883
 		} // End If Statement
2884 2884
 
2885
-		$html .= '<a href="' . get_permalink( $lesson_id ) . '" class="course-featured-image" title="' . esc_attr( get_post_field( 'post_title', $lesson_id ) ) . '">' . $img_url . '</a>';
2885
+		$html .= '<a href="'.get_permalink($lesson_id).'" class="course-featured-image" title="'.esc_attr(get_post_field('post_title', $lesson_id)).'">'.$img_url.'</a>';
2886 2886
 
2887 2887
 		return $html;
2888 2888
 
@@ -2894,9 +2894,9 @@  discard block
 block discarded – undo
2894 2894
      * @since 1.9.0
2895 2895
      * @param integer $lesson_id
2896 2896
      */
2897
-    public static function the_lesson_image( $lesson_id = 0 ){
2897
+    public static function the_lesson_image($lesson_id = 0) {
2898 2898
 
2899
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2899
+        echo Sensei()->lesson->lesson_image($lesson_id);
2900 2900
 
2901 2901
     }
2902 2902
 
@@ -2907,17 +2907,17 @@  discard block
 block discarded – undo
2907 2907
      * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2908 2908
 	 * @return string
2909 2909
 	 */
2910
-	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2910
+	public static function lesson_excerpt($lesson = null, $add_p_tags = true) {
2911 2911
 		$html = '';
2912
-		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2912
+		if (is_a($lesson, 'WP_Post') && 'lesson' == $lesson->post_type) {
2913 2913
 
2914
-            $excerpt =  $lesson->post_excerpt;
2914
+            $excerpt = $lesson->post_excerpt;
2915 2915
 
2916 2916
             // if $add_p_tags true wrap with <p> else return the excerpt as is
2917
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2917
+            $html = $add_p_tags ? wpautop($excerpt) : $excerpt;
2918 2918
 
2919 2919
 		}
2920
-		return apply_filters( 'sensei_lesson_excerpt', $html );
2920
+		return apply_filters('sensei_lesson_excerpt', $html);
2921 2921
 
2922 2922
 	} // End lesson_excerpt()
2923 2923
 
@@ -2930,20 +2930,20 @@  discard block
 block discarded – undo
2930 2930
      * @param int $lesson_id
2931 2931
      * @return int|bool $course_id or bool when nothing is found.
2932 2932
      */
2933
-     public function get_course_id( $lesson_id ){
2933
+     public function get_course_id($lesson_id) {
2934 2934
 
2935
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2936
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2935
+         if ( ! isset($lesson_id) || empty($lesson_id)
2936
+         ||  'lesson' != get_post_type($lesson_id)) {
2937 2937
              return false;
2938 2938
          }
2939 2939
 
2940
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2940
+         $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
2941 2941
 
2942 2942
          // make sure the course id is valid
2943
-         if( empty( $lesson_course_id )
2944
-             || is_array( $lesson_course_id )
2945
-             || intval( $lesson_course_id ) < 1
2946
-             || 'course' != get_post_type( $lesson_course_id ) ){
2943
+         if (empty($lesson_course_id)
2944
+             || is_array($lesson_course_id)
2945
+             || intval($lesson_course_id) < 1
2946
+             || 'course' != get_post_type($lesson_course_id)) {
2947 2947
 
2948 2948
              return false;
2949 2949
 
@@ -2970,11 +2970,11 @@  discard block
 block discarded – undo
2970 2970
      * @param string $post_type
2971 2971
      * @return void
2972 2972
      */
2973
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2973
+    public function all_lessons_edit_fields($column_name, $post_type) {
2974 2974
 
2975 2975
         // only show these options ont he lesson post type edit screen
2976
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name
2977
-            || ! current_user_can( 'edit_lessons' ) ) {
2976
+        if ('lesson' != $post_type || 'lesson-course' != $column_name
2977
+            || ! current_user_can('edit_lessons')) {
2978 2978
             return;
2979 2979
         }
2980 2980
 
@@ -2982,41 +2982,41 @@  discard block
 block discarded – undo
2982 2982
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2983 2983
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2984 2984
                     <?php
2985
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2985
+                    echo '<h4>'.__('Lesson Information', 'woothemes-sensei').'</h4>';
2986 2986
                     // create a nonce field to be  used as a security measure when saving the data
2987
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2988
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2987
+                    wp_nonce_field('bulk-edit-lessons', '_edit_lessons_nonce');
2988
+                    wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce');
2989 2989
 
2990 2990
                     // unchanged option - we need this in because
2991 2991
                     // the default option in bulk edit should not be empty. If it is
2992 2992
                     // the user will erase data they didn't want to touch.
2993
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2993
+                    $no_change_text = '-- '.__('No Change', 'woothemes-sensei').' --';
2994 2994
 
2995 2995
                     //
2996 2996
                     //course selection
2997 2997
                     //
2998
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2998
+                    $courses = WooThemes_Sensei_Course::get_all_courses();
2999 2999
                     $course_options = array();
3000
-                    if ( count( $courses ) > 0 ) {
3001
-                        foreach ($courses as $course ){
3002
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
3000
+                    if (count($courses) > 0) {
3001
+                        foreach ($courses as $course) {
3002
+                            $course_options[$course->ID] = get_the_title($course->ID);
3003 3003
                         }
3004 3004
                     }
3005 3005
                     //pre-append the no change option
3006
-                    $course_options['-1']=  $no_change_text;
3007
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
3008
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3009
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3006
+                    $course_options['-1'] = $no_change_text;
3007
+                    $course_attributes = array('name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course', 'class'=>' ');
3008
+                    $course_field = Sensei_Utils::generate_drop_down('-1', $course_options, $course_attributes);
3009
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Course', 'woothemes-sensei'), $course_field);
3010 3010
 
3011 3011
                     //
3012 3012
                     // lesson complexity selection
3013 3013
                     //
3014
-                    $lesson_complexities =  $this->lesson_complexities();
3014
+                    $lesson_complexities = $this->lesson_complexities();
3015 3015
                     //pre-append the no change option
3016
-                    $lesson_complexities['-1']=  $no_change_text;
3017
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3018
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3019
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3016
+                    $lesson_complexities['-1'] = $no_change_text;
3017
+                    $complexity_dropdown_attributes = array('name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity', 'class'=>' ');
3018
+                    $complexity_filed = Sensei_Utils::generate_drop_down('-1', $lesson_complexities, $complexity_dropdown_attributes);
3019
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Complexity', 'woothemes-sensei'), $complexity_filed);
3020 3020
 
3021 3021
                     ?>
3022 3022
 
@@ -3029,34 +3029,34 @@  discard block
 block discarded – undo
3029 3029
                     //
3030 3030
                     $pass_required_options = array(
3031 3031
                         '-1' => $no_change_text,
3032
-                         '0' => __('No','woothemes'),
3033
-                         '1' => __('Yes','woothemes'),
3032
+                         '0' => __('No', 'woothemes'),
3033
+                         '1' => __('Yes', 'woothemes'),
3034 3034
                     );
3035 3035
 
3036
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3036
+                    $pass_required_select_attributes = array('name'=> 'pass_required',
3037 3037
                                                                 'id'=> 'sensei-edit-lesson-pass-required',
3038
-                                                                'class'=>' '   );
3039
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3040
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3038
+                                                                'class'=>' ');
3039
+                    $require_pass_field = Sensei_Utils::generate_drop_down('-1', $pass_required_options, $pass_required_select_attributes, false);
3040
+                    echo $this->generate_all_lessons_edit_field(__('Pass required', 'woothemes-sensei'), $require_pass_field);
3041 3041
 
3042 3042
                     //
3043 3043
                     // Quiz pass percentage
3044 3044
                     //
3045 3045
                     $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3046
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3046
+                    echo $this->generate_all_lessons_edit_field(__('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field);
3047 3047
 
3048 3048
                     //
3049 3049
                     // Enable quiz reset button
3050 3050
                     //
3051 3051
                     $quiz_reset_select__options = array(
3052 3052
                         '-1' => $no_change_text,
3053
-                        '0' => __('No','woothemes'),
3054
-                        '1' => __('Yes','woothemes'),
3053
+                        '0' => __('No', 'woothemes'),
3054
+                        '1' => __('Yes', 'woothemes'),
3055 3055
                     );
3056 3056
                     $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3057
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3058
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3059
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3057
+                    $quiz_reset_select_attributes = array('name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ');
3058
+                    $quiz_reset_field = Sensei_Utils::generate_drop_down('-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false);
3059
+                    echo $this->generate_all_lessons_edit_field(__('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field);
3060 3060
 
3061 3061
                     ?>
3062 3062
             </div>
@@ -3075,17 +3075,17 @@  discard block
 block discarded – undo
3075 3075
      * @param string $field type markup for the field that must be wrapped.
3076 3076
      * @return string $field_html
3077 3077
      */
3078
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3078
+    public function generate_all_lessons_edit_field($title, $field) {
3079 3079
 
3080 3080
         $html = '';
3081 3081
         $html = '<div class="inline-edit-group" >';
3082
-        $html .=  '<span class="title">'. $title .'</span> ';
3082
+        $html .= '<span class="title">'.$title.'</span> ';
3083 3083
         $html .= '<span class="input-text-wrap">';
3084 3084
         $html .= $field;
3085 3085
         $html .= '</span>';
3086 3086
         $html .= '</label></div>';
3087 3087
 
3088
-        return $html ;
3088
+        return $html;
3089 3089
 
3090 3090
     }//end generate_all_lessons_edit_field
3091 3091
 
@@ -3099,48 +3099,48 @@  discard block
 block discarded – undo
3099 3099
     function save_all_lessons_edit_fields() {
3100 3100
 
3101 3101
         // verify all the data before attempting to save
3102
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3103
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3102
+        if ( ! isset($_POST['security']) || ! check_ajax_referer('bulk-edit-lessons', 'security')
3103
+            ||  empty($_POST['post_ids']) || ! is_array($_POST['post_ids'])) {
3104 3104
             die();
3105 3105
         }
3106 3106
 
3107 3107
         // get our variables
3108
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3109
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3110
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3111
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3112
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3108
+        $new_course = sanitize_text_field($_POST['sensei_edit_lesson_course']);
3109
+        $new_complexity = sanitize_text_field($_POST['sensei_edit_complexity']);
3110
+        $new_pass_required = sanitize_text_field($_POST['sensei_edit_pass_required']);
3111
+        $new_pass_percentage = sanitize_text_field($_POST['sensei_edit_pass_percentage']);
3112
+        $new_enable_quiz_reset = sanitize_text_field($_POST['sensei_edit_enable_quiz_reset']);
3113 3113
         // store the values for all selected posts
3114
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3114
+        foreach ($_POST['post_ids'] as $lesson_id) {
3115 3115
 
3116 3116
             // get the quiz id needed for the quiz meta
3117
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3117
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
3118 3118
 
3119 3119
             // do not save the items if the value is -1 as this
3120 3120
             // means it was not changed
3121 3121
 
3122 3122
             // update lesson course
3123
-            if( -1 != $new_course ){
3124
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3123
+            if ( -1 != $new_course ) {
3124
+                update_post_meta($lesson_id, '_lesson_course', $new_course);
3125 3125
             }
3126 3126
             // update lesson complexity
3127
-            if( -1 != $new_complexity ){
3128
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3127
+            if ( -1 != $new_complexity ) {
3128
+                update_post_meta($lesson_id, '_lesson_complexity', $new_complexity);
3129 3129
             }
3130 3130
 
3131 3131
             // Quiz Related settings
3132
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3132
+            if (isset($quiz_id) && 0 < intval($quiz_id)) {
3133 3133
 
3134 3134
                 // update pass required
3135 3135
                 if (-1 != $new_pass_required) {
3136 3136
 
3137
-                    $checked = $new_pass_required  ? 'on' : '';
3137
+                    $checked = $new_pass_required ? 'on' : '';
3138 3138
                     update_post_meta($quiz_id, '_pass_required', $checked);
3139
-                    unset( $checked );
3139
+                    unset($checked);
3140 3140
                 }
3141 3141
 
3142 3142
                 // update pass percentage
3143
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3143
+                if ( ! empty($new_pass_percentage) && is_numeric($new_pass_percentage)) {
3144 3144
 
3145 3145
                         update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3146 3146
 
@@ -3151,9 +3151,9 @@  discard block
 block discarded – undo
3151 3151
                 //
3152 3152
                 if (-1 != $new_enable_quiz_reset ) {
3153 3153
 
3154
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3154
+                    $checked = $new_enable_quiz_reset ? 'on' : '';
3155 3155
                     update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3156
-                    unset( $checked );
3156
+                    unset($checked);
3157 3157
 
3158 3158
                 }
3159 3159
 
@@ -3177,31 +3177,31 @@  discard block
 block discarded – undo
3177 3177
      * @since 1.8.0
3178 3178
      * @return void
3179 3179
      */
3180
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3180
+    public function set_quick_edit_admin_defaults($column_name, $post_id) {
3181 3181
 
3182
-        if( 'lesson-course' != $column_name ){
3182
+        if ('lesson-course' != $column_name) {
3183 3183
             return;
3184 3184
         }
3185 3185
         // load the script
3186
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3186
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
+        wp_enqueue_script('sensei-lesson-quick-edit', Sensei()->plugin_url.'assets/js/admin/lesson-quick-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
3188 3188
 
3189 3189
         // setup the values for all meta fields
3190 3190
         $data = array();
3191
-        foreach( $this->meta_fields as $field ){
3191
+        foreach ($this->meta_fields as $field) {
3192 3192
 
3193
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3193
+            $data[$field] = get_post_meta($post_id, '_'.$field, true);
3194 3194
 
3195 3195
         }
3196 3196
         // add quiz meta fields
3197
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3198
-        foreach( Sensei()->quiz->meta_fields as $field ){
3197
+        $quiz_id = Sensei()->lesson->lesson_quizzes($post_id);
3198
+        foreach (Sensei()->quiz->meta_fields as $field) {
3199 3199
 
3200
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3200
+            $data[$field] = get_post_meta($quiz_id, '_'.$field, true);
3201 3201
 
3202 3202
         }
3203 3203
 
3204
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3204
+        wp_localize_script('sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data);
3205 3205
 
3206 3206
     }// end quick edit admin defaults
3207 3207
 
@@ -3214,19 +3214,19 @@  discard block
 block discarded – undo
3214 3214
      * @param array $classes
3215 3215
      * @return array $classes
3216 3216
      */
3217
-    public static function single_course_lessons_classes( $classes ){
3217
+    public static function single_course_lessons_classes($classes) {
3218 3218
 
3219
-        if(  is_singular('course') ){
3219
+        if (is_singular('course')) {
3220 3220
 
3221 3221
             global $post;
3222 3222
             $course_id = $post->ID;
3223 3223
 
3224
-            $lesson_classes = array( 'course', 'post' );
3225
-            if ( is_user_logged_in() ) {
3224
+            $lesson_classes = array('course', 'post');
3225
+            if (is_user_logged_in()) {
3226 3226
 
3227 3227
                 // Check if Lesson is complete
3228
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3229
-                if ( $single_lesson_complete ) {
3228
+                $single_lesson_complete = Sensei_Utils::user_completed_lesson(get_the_ID(), get_current_user_id());
3229
+                if ($single_lesson_complete) {
3230 3230
 
3231 3231
                     $lesson_classes[] = 'lesson-completed';
3232 3232
 
@@ -3234,14 +3234,14 @@  discard block
 block discarded – undo
3234 3234
 
3235 3235
             } // End If Statement
3236 3236
 
3237
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3238
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3237
+            $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3238
+            if (Sensei_Utils::is_preview_lesson(get_the_ID()) && ! $is_user_taking_course) {
3239 3239
 
3240 3240
                 $lesson_classes[] = 'lesson-preview';
3241 3241
 
3242 3242
             }
3243 3243
 
3244
-            $classes = array_merge( $classes, $lesson_classes  );
3244
+            $classes = array_merge($classes, $lesson_classes);
3245 3245
 
3246 3246
         }
3247 3247
 
@@ -3255,56 +3255,56 @@  discard block
 block discarded – undo
3255 3255
      * @since 1.9.0
3256 3256
      * @param $lesson_id
3257 3257
      */
3258
-    public static function the_lesson_meta( $lesson_id ){
3258
+    public static function the_lesson_meta($lesson_id) {
3259 3259
 
3260 3260
         global $wp_query;
3261 3261
         $loop_lesson_number = $wp_query->current_post + 1;
3262 3262
 
3263
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3263
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
3264 3264
         $single_lesson_complete = false;
3265
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3265
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3266 3266
 
3267 3267
         // Get Lesson data
3268 3268
         $complexity_array = Sensei()->lesson->lesson_complexities();
3269 3269
 
3270
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3271
-        if ( '' != $lesson_complexity ) {
3270
+        $lesson_complexity = get_post_meta($lesson_id, '_lesson_complexity', true);
3271
+        if ('' != $lesson_complexity) {
3272 3272
 
3273 3273
             $lesson_complexity = $complexity_array[$lesson_complexity];
3274 3274
 
3275 3275
         }
3276
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3277
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3276
+        $user_info = get_userdata(absint(get_post()->post_author));
3277
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3278 3278
         $preview_label = '';
3279
-        if ( $is_preview && !$is_user_taking_course ) {
3279
+        if ($is_preview && ! $is_user_taking_course) {
3280 3280
 
3281
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3282
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3281
+            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text($lesson_id);
3282
+            $preview_label = '<span class="preview-heading">'.$preview_label.'</span>';
3283 3283
 
3284 3284
         }
3285 3285
 
3286 3286
 
3287
-        $count_markup= '';
3287
+        $count_markup = '';
3288 3288
         /**
3289 3289
          * Filter for if you want the $lesson_count to show next to the lesson.
3290 3290
          *
3291 3291
          * @since 1.0
3292 3292
          * @param bool default false.
3293 3293
          */
3294
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3294
+        if (apply_filters('sensei_show_lesson_numbers', false)) {
3295 3295
 
3296
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3296
+            $count_markup = '<span class="lesson-number">'.$loop_lesson_number.'</span>';
3297 3297
 
3298 3298
         }
3299 3299
 
3300
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3300
+        $heading_link_title = sprintf(__('Start %s', 'woothemes-sensei'), get_the_title($lesson_id));
3301 3301
 
3302 3302
         ?>
3303 3303
         <header>
3304 3304
             <h2>
3305
-                <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
3306
-                   title="<?php esc_attr_e( $heading_link_title ) ?>" >
3307
-                    <?php echo $count_markup. get_the_title( $lesson_id ) . $preview_label; ?>
3305
+                <a href="<?php echo esc_url_raw(get_permalink($lesson_id)) ?>"
3306
+                   title="<?php esc_attr_e($heading_link_title) ?>" >
3307
+                    <?php echo $count_markup.get_the_title($lesson_id).$preview_label; ?>
3308 3308
                 </a>
3309 3309
             </h2>
3310 3310
 
@@ -3313,33 +3313,33 @@  discard block
 block discarded – undo
3313 3313
                 <?php
3314 3314
 
3315 3315
                 $meta_html = '';
3316
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3316
+                $user_lesson_status = Sensei_Utils::user_lesson_status(get_the_ID(), get_current_user_id());
3317 3317
 
3318
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3319
-                if ( '' != $lesson_length ) {
3318
+                $lesson_length = get_post_meta($lesson_id, '_lesson_length', true);
3319
+                if ('' != $lesson_length) {
3320 3320
 
3321
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3321
+                    $meta_html .= '<span class="lesson-length">'.__('Length: ', 'woothemes-sensei').$lesson_length.__(' minutes', 'woothemes-sensei').'</span>';
3322 3322
 
3323 3323
                 }
3324 3324
 
3325
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3325
+                if (Sensei()->settings->get('lesson_author')) {
3326 3326
 
3327
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3327
+                    $meta_html .= '<span class="lesson-author">'.__('Author: ', 'woothemes-sensei').'<a href="'.get_author_posts_url(absint(get_post()->post_author)).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>';
3328 3328
 
3329 3329
                 } // End If Statement
3330
-                if ( '' != $lesson_complexity ) {
3330
+                if ('' != $lesson_complexity) {
3331 3331
 
3332
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3332
+                    $meta_html .= '<span class="lesson-complexity">'.__('Complexity: ', 'woothemes-sensei').$lesson_complexity.'</span>';
3333 3333
 
3334 3334
                 }
3335 3335
 
3336
-                if ( $single_lesson_complete ) {
3336
+                if ($single_lesson_complete) {
3337 3337
 
3338
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3338
+                    $meta_html .= '<span class="lesson-status complete">'.__('Complete', 'woothemes-sensei').'</span>';
3339 3339
 
3340
-                } elseif ( $user_lesson_status ) {
3340
+                } elseif ($user_lesson_status) {
3341 3341
 
3342
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3342
+                    $meta_html .= '<span class="lesson-status in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
3343 3343
 
3344 3344
                 } // End If Statement
3345 3345
 
@@ -3362,19 +3362,19 @@  discard block
 block discarded – undo
3362 3362
      *
3363 3363
      * @param $lesson_id
3364 3364
      */
3365
-    public static function the_lesson_thumbnail( $lesson_id ){
3365
+    public static function the_lesson_thumbnail($lesson_id) {
3366 3366
 
3367
-        if( empty( $lesson_id ) ){
3367
+        if (empty($lesson_id)) {
3368 3368
 
3369 3369
             $lesson_id = get_the_ID();
3370 3370
 
3371 3371
         }
3372 3372
 
3373
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3373
+        if ('lesson' != get_post_type($lesson_id)) {
3374 3374
             return;
3375 3375
         }
3376 3376
 
3377
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3377
+        echo Sensei()->lesson->lesson_image($lesson_id);
3378 3378
     }
3379 3379
 
3380 3380
 
@@ -3385,14 +3385,14 @@  discard block
 block discarded – undo
3385 3385
      * @param string $excerpt
3386 3386
      * @return string $excerpt
3387 3387
      */
3388
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3388
+    public static function alter_the_lesson_excerpt($excerpt) {
3389 3389
 
3390
-        if ('lesson' == get_post_type(get_the_ID())){
3390
+        if ('lesson' == get_post_type(get_the_ID())) {
3391 3391
 
3392 3392
             // remove this hooks to avoid an infinite loop.
3393
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3393
+            remove_filter('get_the_excerpt', array('WooThemes_Sensei_Lesson', 'alter_the_lesson_excerpt'));
3394 3394
 
3395
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3395
+            return WooThemes_Sensei_Lesson::lesson_excerpt(get_post(get_the_ID()));
3396 3396
         }
3397 3397
 
3398 3398
         return $excerpt;
@@ -3407,20 +3407,20 @@  discard block
 block discarded – undo
3407 3407
      * @param $current_lesson_id
3408 3408
      * @return mixed | bool | int $prerequisite_lesson_id or false
3409 3409
      */
3410
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3410
+    public static function get_lesson_prerequisite_id($current_lesson_id) {
3411 3411
 
3412
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3412
+        $prerequisite_lesson_id = get_post_meta($current_lesson_id, '_lesson_prerequisite', true);
3413 3413
 
3414 3414
         // set ti to false if not a valid prerequisite lesson id
3415
-        if(  empty( $prerequisite_lesson_id )
3416
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3417
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3415
+        if (empty($prerequisite_lesson_id)
3416
+            || 'lesson' != get_post_type($prerequisite_lesson_id)
3417
+            || $prerequisite_lesson_id == $current_lesson_id) {
3418 3418
 
3419 3419
             $prerequisite_lesson_id = false;
3420 3420
 
3421 3421
         }
3422 3422
 
3423
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3423
+        return apply_filters('sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id);
3424 3424
 
3425 3425
     }
3426 3426
 
@@ -3435,27 +3435,27 @@  discard block
 block discarded – undo
3435 3435
      * @param $user_id
3436 3436
      * @return bool
3437 3437
      */
3438
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3438
+    public  static function is_prerequisite_complete($lesson_id, $user_id) {
3439 3439
 
3440
-        if( empty( $lesson_id ) || empty( $user_id )
3441
-        || 'lesson' != get_post_type( $lesson_id )
3442
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3440
+        if (empty($lesson_id) || empty($user_id)
3441
+        || 'lesson' != get_post_type($lesson_id)
3442
+        ||  ! is_a(get_user_by('id', $user_id), 'WP_User')) {
3443 3443
 
3444 3444
             return false;
3445 3445
 
3446 3446
         }
3447 3447
 
3448
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3448
+        $pre_requisite_id = (string) self::get_lesson_prerequisite_id($lesson_id);
3449 3449
 
3450 3450
         // not a valid pre-requisite so pre-requisite is completed
3451
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3452
-            || ! is_numeric( $pre_requisite_id ) ){
3451
+        if ('lesson' != get_post_type($pre_requisite_id)
3452
+            || ! is_numeric($pre_requisite_id)) {
3453 3453
 
3454 3454
             return true;
3455 3455
 
3456 3456
         }
3457 3457
 
3458
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3458
+        return  Sensei_Utils::user_completed_lesson($pre_requisite_id, $user_id);
3459 3459
 
3460 3460
     }// end is_prerequisite_complete
3461 3461
 
@@ -3464,20 +3464,20 @@  discard block
 block discarded – undo
3464 3464
      *
3465 3465
      * @since 1.9.0
3466 3466
      */
3467
-    public  static function user_not_taking_course_message(){
3467
+    public  static function user_not_taking_course_message() {
3468 3468
 
3469 3469
         $lesson_id = get_the_ID();
3470 3470
 
3471
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3471
+        if ('lesson' != get_post_type($lesson_id)) {
3472 3472
             return;
3473 3473
         }
3474 3474
 
3475
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3476
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3477
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3478
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3475
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3476
+        $pre_requisite_complete = self::is_prerequisite_complete($lesson_id, get_current_user_id());
3477
+        $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
3478
+        $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, get_current_user_id());
3479 3479
 
3480
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3480
+        if ($pre_requisite_complete && $is_preview && ! $user_taking_course) {
3481 3481
 
3482 3482
 
3483 3483
         }// end if
@@ -3491,11 +3491,11 @@  discard block
 block discarded – undo
3491 3491
      *
3492 3492
      * @since 1.9.0
3493 3493
      */
3494
-    public static function course_signup_link( ){
3494
+    public static function course_signup_link( ) {
3495 3495
 
3496
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3496
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3497 3497
 
3498
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3498
+        if (empty($course_id) || 'course' != get_post_type($course_id) || sensei_all_access()) {
3499 3499
 
3500 3500
             return;
3501 3501
 
@@ -3508,69 +3508,69 @@  discard block
 block discarded – undo
3508 3508
             <?php
3509 3509
 
3510 3510
             global $current_user;
3511
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3511
+            $wc_post_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
3512 3512
 
3513
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $course_id ) ) {
3513
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable($course_id)) {
3514 3514
 
3515
-                if( is_user_logged_in() && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID )  ) {
3515
+                if (is_user_logged_in() && ! Sensei_Utils::user_started_course($course_id, $current_user->ID)) {
3516 3516
 
3517
-	                    $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3518
-	                    $a_element .= __( 'course', 'woothemes-sensei' );
3517
+	                    $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3518
+	                    $a_element .= __('course', 'woothemes-sensei');
3519 3519
 	                    $a_element .= '</a>';
3520 3520
 
3521
-	                    if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3521
+	                    if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3522 3522
 
3523
-		                    $message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3523
+		                    $message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3524 3524
 
3525
-	                    }else{
3525
+	                    } else {
3526 3526
 
3527
-		                    $message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3527
+		                    $message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3528 3528
 
3529 3529
 	                    }
3530 3530
 
3531
-	                    Sensei()->notices->add_notice( $message, 'info' );
3531
+	                    Sensei()->notices->add_notice($message, 'info');
3532 3532
 
3533 3533
                 }
3534 3534
 
3535
-	            if( ! is_user_logged_in() ) {
3535
+	            if ( ! is_user_logged_in()) {
3536 3536
 
3537
-	                $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3538
-	                $a_element .= __( 'course', 'woothemes-sensei' );
3537
+	                $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3538
+	                $a_element .= __('course', 'woothemes-sensei');
3539 3539
 	                $a_element .= '</a>';
3540 3540
 
3541
-	                if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3541
+	                if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3542 3542
 
3543
-						$message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3543
+						$message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3544 3544
 
3545
-					}else{
3545
+					} else {
3546 3546
 
3547
-						$message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3547
+						$message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3548 3548
 
3549 3549
 					}
3550 3550
 
3551
-					Sensei()->notices->add_notice( $message, 'alert' );
3551
+					Sensei()->notices->add_notice($message, 'alert');
3552 3552
 
3553 3553
 	            }
3554 3554
 
3555 3555
             } else { ?>
3556 3556
 
3557
-	            <?php if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) &&  sensei_is_login_required() )  : ?>
3557
+	            <?php if ( ! Sensei_Utils::user_started_course($course_id, get_current_user_id()) && sensei_is_login_required())  : ?>
3558 3558
 
3559 3559
 	                <div class="sensei-message alert">
3560 3560
 	                    <?php
3561
-	                    $course_link =  '<a href="'
3562
-	                                        . esc_url( get_permalink( $course_id ) )
3563
-	                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3564
-	                                        . '">' . __( 'course', 'woothemes-sensei' )
3561
+	                    $course_link = '<a href="'
3562
+	                                        . esc_url(get_permalink($course_id))
3563
+	                                        . '" title="'.__('Sign Up', 'woothemes-sensei')
3564
+	                                        . '">'.__('course', 'woothemes-sensei')
3565 3565
 	                                    . '</a>';
3566 3566
 
3567
-						if ( Sensei_Utils::is_preview_lesson( get_the_ID( ) ) ) {
3567
+						if (Sensei_Utils::is_preview_lesson(get_the_ID( ))) {
3568 3568
 
3569
-							echo sprintf( __( 'This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ),  $course_link );
3569
+							echo sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
3570 3570
 
3571 3571
 						} else {
3572 3572
 
3573
-							echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3573
+							echo sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
3574 3574
 
3575 3575
 						}
3576 3576
 
@@ -3591,14 +3591,14 @@  discard block
 block discarded – undo
3591 3591
      *
3592 3592
      * @since 1.9.0
3593 3593
      */
3594
-    public  static function prerequisite_complete_message(){
3594
+    public  static function prerequisite_complete_message() {
3595 3595
 
3596
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3596
+        $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id(get_the_ID());
3597 3597
         $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3598
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3598
+        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(get_the_ID(), get_current_user_id()) && $lesson_has_pre_requisite) {
3599 3599
 
3600
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3601
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3600
+            $prerequisite_lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite)).'" title="'.esc_attr(sprintf(__('You must first complete: %1$s', 'woothemes-sensei'), get_the_title($lesson_prerequisite))).'">'.get_the_title($lesson_prerequisite).'</a>';
3601
+            echo sprintf(__('You must first complete %1$s before viewing this Lesson', 'woothemes-sensei'), $prerequisite_lesson_link);
3602 3602
 
3603 3603
         }
3604 3604
 
@@ -3610,7 +3610,7 @@  discard block
 block discarded – undo
3610 3610
      *
3611 3611
      * @deprecated since 1.9.0
3612 3612
      */
3613
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3613
+    public static function deprecate_sensei_lesson_archive_header_hook() {
3614 3614
 
3615 3615
         sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3616 3616
 
@@ -3626,9 +3626,9 @@  discard block
 block discarded – undo
3626 3626
 
3627 3627
         $before_html = '<header class="archive-header"><h1>';
3628 3628
         $after_html = '</h1></header>';
3629
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3629
+        $html = $before_html.__('Lessons Archive', 'woothemes-sensei').$after_html;
3630 3630
 
3631
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3631
+        echo apply_filters('sensei_lesson_archive_title', $html);
3632 3632
 
3633 3633
     } // sensei_course_archive_header()
3634 3634
 
@@ -3638,7 +3638,7 @@  discard block
 block discarded – undo
3638 3638
      * @global $post
3639 3639
      * @since 1.9.0
3640 3640
      */
3641
-    public static function the_title(){
3641
+    public static function the_title() {
3642 3642
 
3643 3643
         global $post;
3644 3644
 
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
                 /**
3652 3652
                  * Filter documented in class-sensei-messages.php the_title
3653 3653
                  */
3654
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3654
+                echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type);
3655 3655
                 ?>
3656 3656
 
3657 3657
             </h1>
@@ -3669,16 +3669,16 @@  discard block
 block discarded – undo
3669 3669
      *
3670 3670
      * @param $post_id
3671 3671
      */
3672
-    public static function flush_rewrite_rules( $post_id ){
3672
+    public static function flush_rewrite_rules($post_id) {
3673 3673
 
3674
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3674
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
3675 3675
 
3676 3676
             return;
3677 3677
 
3678 3678
         }
3679 3679
 
3680 3680
 
3681
-        if( 'lesson' == get_post_type( $post_id )  ){
3681
+        if ('lesson' == get_post_type($post_id)) {
3682 3682
 
3683 3683
             Sensei()->initiate_rewrite_rules_flush();
3684 3684
 
@@ -3695,27 +3695,27 @@  discard block
 block discarded – undo
3695 3695
      * @param int $lesson_id
3696 3696
      * @param int $user_id
3697 3697
      */
3698
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3698
+    public static function footer_quiz_call_to_action($lesson_id = 0, $user_id = 0) {
3699 3699
 
3700 3700
 
3701
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3702
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3701
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3702
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3703 3703
 
3704 3704
 
3705
-	    if ( ! sensei_can_user_view_lesson( $lesson_id, $user_id ) ) {
3705
+	    if ( ! sensei_can_user_view_lesson($lesson_id, $user_id)) {
3706 3706
 		    return;
3707 3707
 	    }
3708 3708
 
3709
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3710
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3711
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3712
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3709
+        $lesson_prerequisite       = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
3710
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3711
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3712
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3713 3713
         $show_actions              = is_user_logged_in() ? true : false;
3714 3714
 
3715
-        if( intval( $lesson_prerequisite ) > 0 ) {
3715
+        if (intval($lesson_prerequisite) > 0) {
3716 3716
 
3717 3717
             // If the user hasn't completed the prereq then hide the current actions
3718
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3718
+            $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $user_id);
3719 3719
 
3720 3720
         }
3721 3721
 
@@ -3724,19 +3724,19 @@  discard block
 block discarded – undo
3724 3724
         <footer>
3725 3725
 
3726 3726
             <?php
3727
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3727
+            if ($show_actions && $quiz_id && Sensei()->access_settings()) {
3728 3728
 
3729
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3730
-                if( $has_quiz_questions ) {
3729
+                $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3730
+                if ($has_quiz_questions) {
3731 3731
                     ?>
3732 3732
 
3733 3733
                     <p>
3734 3734
 
3735 3735
                         <a class="button"
3736
-                           href="<?php echo esc_url_raw( get_permalink( $quiz_id ) ); ?>"
3737
-                           title="<?php _e( 'View the Lesson Quiz', 'woothemes-sensei'  ); ?>">
3736
+                           href="<?php echo esc_url_raw(get_permalink($quiz_id)); ?>"
3737
+                           title="<?php _e('View the Lesson Quiz', 'woothemes-sensei'); ?>">
3738 3738
 
3739
-                            <?php  _e( 'View the Lesson Quiz', 'woothemes-sensei' ); ?>
3739
+                            <?php  _e('View the Lesson Quiz', 'woothemes-sensei'); ?>
3740 3740
 
3741 3741
                         </a>
3742 3742
 
@@ -3747,11 +3747,11 @@  discard block
 block discarded – undo
3747 3747
 
3748 3748
             } // End If Statement
3749 3749
 
3750
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3750
+            if ($show_actions && ! $has_user_completed_lesson) {
3751 3751
 
3752 3752
                 sensei_complete_lesson_button();
3753 3753
 
3754
-            } elseif( $show_actions ) {
3754
+            } elseif ($show_actions) {
3755 3755
 
3756 3756
                 sensei_reset_lesson_button();
3757 3757
 
@@ -3768,20 +3768,20 @@  discard block
 block discarded – undo
3768 3768
      *
3769 3769
      * @since 1.9.0
3770 3770
      */
3771
-    public static function output_comments(){
3771
+    public static function output_comments() {
3772 3772
 
3773
-        if( ! is_user_logged_in() ){
3773
+        if ( ! is_user_logged_in()) {
3774 3774
             return;
3775 3775
         }
3776 3776
 
3777
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3778
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3779
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3780
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3777
+        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete(get_the_ID(), get_current_user_id());
3778
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3779
+        $allow_comments = Sensei()->settings->settings['lesson_comments'];
3780
+        $user_taking_course = Sensei_Utils::user_started_course($course_id);
3781 3781
 
3782
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3782
+        $lesson_allow_comments = $allow_comments && $pre_requisite_complete && $user_taking_course;
3783 3783
 
3784
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3784
+        if ($lesson_allow_comments || is_singular('sensei_message')) {
3785 3785
 
3786 3786
             comments_template();
3787 3787
 
@@ -3797,26 +3797,26 @@  discard block
 block discarded – undo
3797 3797
      *
3798 3798
      * @since 1.9.0
3799 3799
      */
3800
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3800
+    public static function user_lesson_quiz_status_message($lesson_id = 0, $user_id = 0) {
3801 3801
 
3802
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3803
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3804
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3805
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3806
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3802
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3803
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3804
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3805
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3806
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3807 3807
 
3808 3808
 
3809
-        if ( $quiz_id && is_user_logged_in()
3810
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3809
+        if ($quiz_id && is_user_logged_in()
3810
+            && Sensei_Utils::user_started_course($lesson_course_id, $user_id)) {
3811 3811
 
3812 3812
             $no_quiz_count = 0;
3813
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3813
+            $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3814 3814
 
3815 3815
             // Display lesson quiz status message
3816
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3817
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3818
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3819
-                if( $has_quiz_questions ) {
3816
+            if ($has_user_completed_lesson || $has_quiz_questions) {
3817
+                $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, $user_id, true);
3818
+                echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>';
3819
+                if ($has_quiz_questions) {
3820 3820
                    // echo $status['extra'];
3821 3821
                 } // End If Statement
3822 3822
             } // End If Statement
@@ -3832,11 +3832,11 @@  discard block
 block discarded – undo
3832 3832
      * @param $content
3833 3833
      * @return string
3834 3834
      */
3835
-    public static function limit_archive_content ( $content ){
3835
+    public static function limit_archive_content($content) {
3836 3836
 
3837
-        if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3837
+        if (is_archive('lesson') && Sensei()->settings->get('access_permission')) {
3838 3838
 
3839
-            return wp_trim_words( $content, $num_words = 30, $more = '…' );
3839
+            return wp_trim_words($content, $num_words = 30, $more = '…');
3840 3840
         }
3841 3841
 
3842 3842
         return $content;
@@ -3849,9 +3849,9 @@  discard block
 block discarded – undo
3849 3849
      * @since 1.9.0
3850 3850
      * @return array
3851 3851
      */
3852
-    public static function get_all_lesson_ids(){
3852
+    public static function get_all_lesson_ids() {
3853 3853
 
3854
-        return get_posts( array(
3854
+        return get_posts(array(
3855 3855
             'post_type'=>'lesson',
3856 3856
             'fields'=>'ids',
3857 3857
             'post_status' => 'publish',
@@ -3868,4 +3868,4 @@  discard block
 block discarded – undo
3868 3868
  * @ignore only for backward compatibility
3869 3869
  * @since 1.9.0
3870 3870
  */
3871
-class WooThemes_Sensei_Lesson extends Sensei_Lesson{}
3871
+class WooThemes_Sensei_Lesson extends Sensei_Lesson {}
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 2 patches
Indentation   +1833 added lines, -1833 removed lines patch added patch discarded remove patch
@@ -14,265 +14,265 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Core_Modules
16 16
 {
17
-    private $dir;
18
-    private $file;
19
-    private $assets_dir;
20
-    private $assets_url;
21
-    private $order_page_slug;
22
-    public $taxonomy;
23
-
24
-    public function __construct( $file )
25
-    {
26
-        $this->file = $file;
27
-        $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
29
-        $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
-        $this->taxonomy = 'module';
31
-        $this->order_page_slug = 'module-order';
32
-
33
-        // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
-
36
-        // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
-
39
-        // Save lesson meta box
40
-        add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
-
42
-        //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
-
45
-        // Frontend styling
46
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
-
48
-        // Admin styling
49
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
-
52
-        // Handle module completion record
53
-        add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
-        add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
-        add_action('wp', array($this, 'save_module_progress'), 10);
56
-
57
-        // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
-        add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
-        add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
-
62
-        // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
-
67
-        // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
-        add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
-
74
-        // Manage module taxonomy archive page
75
-        add_filter('template_include', array($this, 'module_archive_template'), 10);
76
-        add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
-        add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
-        add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
-        add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
-        add_filter('body_class', array($this, 'module_archive_body_class'));
81
-
82
-        // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
-
85
-        //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
-
88
-        // Set up display on single lesson page
89
-        add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
-
91
-        // Add 'Modules' columns to Analysis tables
92
-        add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
-        add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
-        add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
-        add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
-
97
-        // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
-        add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
-
102
-        //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
-
105
-        // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
-
109
-        // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
-
112
-        // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
-
115
-    } // end constructor
116
-
117
-    /**
118
-     * Alter a module term slug when a new taxonomy term is created
119
-     * This will add the creators user name to the slug for uniqueness.
120
-     *
121
-     * @since 1.8.0
122
-     *
123
-     * @param $term_id
124
-     * @param $tt_id
125
-     * @param $taxonomy
126
-     *
127
-     * @return void
128
-     * @deprecated since 1.9.0
129
-     */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
-
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
133
-
134
-    }// end add_module_term_group
135
-
136
-    /**
137
-     * Hook in all meta boxes related tot he modules taxonomy
138
-     *
139
-     * @since 1.8.0
140
-     *
141
-     * @param string $post_type
142
-     * @param WP_Post $post
143
-     *
144
-     * @return void
145
-     */
146
-    public function modules_metaboxes( $post_type, $post )
147
-    {
148
-        if ('lesson' == $post_type ) {
149
-
150
-            // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
-
153
-            // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
-        }
156
-
157
-        if( 'course' == $post_type ){
158
-            // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Build content for custom module meta box
165
-     *
166
-     * @since 1.8.0
167
-     * @param  object $post Current post object
168
-     * @return void
169
-     */
170
-    public function lesson_module_metabox($post)
171
-    {
172
-
173
-        // Get lesson course
174
-        $lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
-
176
-        $html = '';
177
-
178
-        // Only show module selection if this lesson is part of a course
179
-        if ($lesson_course && $lesson_course > 0) {
180
-
181
-            // Get existing lesson module
182
-            $lesson_module = 0;
183
-            $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
-                foreach ($lesson_module_list as $single_module) {
186
-                    $lesson_module = $single_module->term_id;
187
-                    break;
188
-                }
189
-            }
190
-
191
-            // Get the available modules for this lesson's course
192
-            $modules = $this->get_course_modules($lesson_course);
193
-
194
-            // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
-            if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
-                foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
-                }
202
-                $html .= '</select>' . "\n";
203
-            } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
-            } // End If Statement
207
-
208
-        } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
-        } // End If Statement
211
-
212
-        // Output the HTML
213
-        echo $html;
214
-    }
215
-
216
-    /**
217
-     * Save module to lesson
218
-     *
219
-     * @since 1.8.0
220
-     * @param  integer $post_id ID of post
221
-     * @return mixed            Post ID on permissions failure, boolean true on success
222
-     */
223
-    public function save_lesson_module($post_id)
224
-    {
225
-        global $post;
226
-
227
-        // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
-            return $post_id;
231
-        }
232
-
233
-        // Check if user has permissions to edit lessons
234
-        $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
-            return $post_id;
237
-        }
238
-
239
-        // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
241
-            return $post_id;
242
-        }
243
-
244
-        // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
246
-
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
-                return true;
250
-            }
251
-
252
-            $module_id = intval( $_POST['lesson_module'] );
253
-
254
-            // Assign lesson to selected module
255
-            wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
-
257
-            // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
-            }
261
-        }
262
-
263
-        return true;
264
-    }
265
-
266
-    /**
267
-     * Display course field on new module screen
268
-     *
269
-     * @since 1.8.0
270
-     * @param object $taxonomy Taxonomy object
271
-     * @return void
272
-     */
273
-    public function add_module_fields($taxonomy)
274
-    {
275
-        ?>
17
+	private $dir;
18
+	private $file;
19
+	private $assets_dir;
20
+	private $assets_url;
21
+	private $order_page_slug;
22
+	public $taxonomy;
23
+
24
+	public function __construct( $file )
25
+	{
26
+		$this->file = $file;
27
+		$this->dir = dirname($this->file);
28
+		$this->assets_dir = trailingslashit($this->dir) . 'assets';
29
+		$this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
+		$this->taxonomy = 'module';
31
+		$this->order_page_slug = 'module-order';
32
+
33
+		// setup taxonomy
34
+		add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
+
36
+		// Manage lesson meta boxes for taxonomy
37
+		add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
+
39
+		// Save lesson meta box
40
+		add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
+
42
+		//Reset the none modules lessons transient
43
+		add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
+
45
+		// Frontend styling
46
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
+
48
+		// Admin styling
49
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
+
52
+		// Handle module completion record
53
+		add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
+		add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
+		add_action('wp', array($this, 'save_module_progress'), 10);
56
+
57
+		// Handle module ordering
58
+		add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
+		add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
+		add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
+
62
+		// Ensure modules always show under courses
63
+		add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
+		add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
+		add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
+
67
+		// Add course field to taxonomy
68
+		add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+		add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+		add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+		add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
+		add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
+
74
+		// Manage module taxonomy archive page
75
+		add_filter('template_include', array($this, 'module_archive_template'), 10);
76
+		add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
+		add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
+		add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
+		add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
+		add_filter('body_class', array($this, 'module_archive_body_class'));
81
+
82
+		// add modules to the single course template
83
+		add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
+
85
+		//Single Course modules actions. Add to single-course/course-modules.php
86
+		add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
+
88
+		// Set up display on single lesson page
89
+		add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
+
91
+		// Add 'Modules' columns to Analysis tables
92
+		add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
+		add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
+		add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
+		add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
+
97
+		// Manage module taxonomy columns
98
+		add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+		add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
+		add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
+
102
+		//store new modules created on the course edit screen
103
+		add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
+
105
+		// for non admin users, only show taxonomies that belong to them
106
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
+		add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
+
109
+		// add the teacher name next to the module term in for admin users
110
+		add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
+
112
+		// remove the default modules  metabox
113
+		add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
+
115
+	} // end constructor
116
+
117
+	/**
118
+	 * Alter a module term slug when a new taxonomy term is created
119
+	 * This will add the creators user name to the slug for uniqueness.
120
+	 *
121
+	 * @since 1.8.0
122
+	 *
123
+	 * @param $term_id
124
+	 * @param $tt_id
125
+	 * @param $taxonomy
126
+	 *
127
+	 * @return void
128
+	 * @deprecated since 1.9.0
129
+	 */
130
+	public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
+
132
+		_deprecated_function('change_module_term_slug', '1.9.0' );
133
+
134
+	}// end add_module_term_group
135
+
136
+	/**
137
+	 * Hook in all meta boxes related tot he modules taxonomy
138
+	 *
139
+	 * @since 1.8.0
140
+	 *
141
+	 * @param string $post_type
142
+	 * @param WP_Post $post
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function modules_metaboxes( $post_type, $post )
147
+	{
148
+		if ('lesson' == $post_type ) {
149
+
150
+			// Remove default taxonomy meta box from Lesson edit screen
151
+			remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
+
153
+			// Add custom meta box to limit module selection to one per lesson
154
+			add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
+		}
156
+
157
+		if( 'course' == $post_type ){
158
+			// Course modules selection metabox
159
+			add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Build content for custom module meta box
165
+	 *
166
+	 * @since 1.8.0
167
+	 * @param  object $post Current post object
168
+	 * @return void
169
+	 */
170
+	public function lesson_module_metabox($post)
171
+	{
172
+
173
+		// Get lesson course
174
+		$lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
+
176
+		$html = '';
177
+
178
+		// Only show module selection if this lesson is part of a course
179
+		if ($lesson_course && $lesson_course > 0) {
180
+
181
+			// Get existing lesson module
182
+			$lesson_module = 0;
183
+			$lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
+				foreach ($lesson_module_list as $single_module) {
186
+					$lesson_module = $single_module->term_id;
187
+					break;
188
+				}
189
+			}
190
+
191
+			// Get the available modules for this lesson's course
192
+			$modules = $this->get_course_modules($lesson_course);
193
+
194
+			// Build the HTML to output
195
+			$html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
+			if (is_array($modules) && count($modules) > 0) {
197
+				$html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
+				$html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
+				foreach ($modules as $module) {
200
+					$html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
+				}
202
+				$html .= '</select>' . "\n";
203
+			} else {
204
+				$course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
+				$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
+			} // End If Statement
207
+
208
+		} else {
209
+			$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
+		} // End If Statement
211
+
212
+		// Output the HTML
213
+		echo $html;
214
+	}
215
+
216
+	/**
217
+	 * Save module to lesson
218
+	 *
219
+	 * @since 1.8.0
220
+	 * @param  integer $post_id ID of post
221
+	 * @return mixed            Post ID on permissions failure, boolean true on success
222
+	 */
223
+	public function save_lesson_module($post_id)
224
+	{
225
+		global $post;
226
+
227
+		// Verify post type and nonce
228
+		if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
+			||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
+			return $post_id;
231
+		}
232
+
233
+		// Check if user has permissions to edit lessons
234
+		$post_type = get_post_type_object($post->post_type);
235
+		if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
+			return $post_id;
237
+		}
238
+
239
+		// Check if user has permissions to edit this specific post
240
+		if (!current_user_can('edit_post', $post_id)) {
241
+			return $post_id;
242
+		}
243
+
244
+		// Cast module ID as an integer if selected, otherwise leave as empty string
245
+		if ( isset( $_POST['lesson_module'] ) ) {
246
+
247
+			if( empty ( $_POST['lesson_module'] ) ){
248
+				wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
+				return true;
250
+			}
251
+
252
+			$module_id = intval( $_POST['lesson_module'] );
253
+
254
+			// Assign lesson to selected module
255
+			wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
+
257
+			// Set default order for lesson inside module
258
+			if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
+				update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
+			}
261
+		}
262
+
263
+		return true;
264
+	}
265
+
266
+	/**
267
+	 * Display course field on new module screen
268
+	 *
269
+	 * @since 1.8.0
270
+	 * @param object $taxonomy Taxonomy object
271
+	 * @return void
272
+	 */
273
+	public function add_module_fields($taxonomy)
274
+	{
275
+		?>
276 276
         <div class="form-field">
277 277
             <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label>
278 278
             <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses"
@@ -281,44 +281,44 @@  discard block
 block discarded – undo
281 281
                 class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span>
282 282
         </div>
283 283
     <?php
284
-    }
285
-
286
-    /**
287
-     * Display course field on module edit screen
288
-     *
289
-     * @since 1.8.0
290
-     * @param  object $module Module term object
291
-     * @return void
292
-     */
293
-    public function edit_module_fields($module)
294
-    {
295
-
296
-        $module_id = $module->term_id;
297
-
298
-        // Get module's existing courses
299
-        $args = array(
300
-            'post_type' => 'course',
301
-            'post_status' => array('publish', 'draft', 'future', 'private'),
302
-            'posts_per_page' => -1,
303
-            'tax_query' => array(
304
-                array(
305
-                    'taxonomy' => $this->taxonomy,
306
-                    'field' => 'id',
307
-                    'terms' => $module_id
308
-                )
309
-            )
310
-        );
311
-        $courses = get_posts($args);
312
-
313
-        //build the defaults array
314
-        $module_courses = array();
315
-        if (isset($courses) && is_array($courses)) {
316
-            foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
-            }
319
-        }
320
-
321
-        ?>
284
+	}
285
+
286
+	/**
287
+	 * Display course field on module edit screen
288
+	 *
289
+	 * @since 1.8.0
290
+	 * @param  object $module Module term object
291
+	 * @return void
292
+	 */
293
+	public function edit_module_fields($module)
294
+	{
295
+
296
+		$module_id = $module->term_id;
297
+
298
+		// Get module's existing courses
299
+		$args = array(
300
+			'post_type' => 'course',
301
+			'post_status' => array('publish', 'draft', 'future', 'private'),
302
+			'posts_per_page' => -1,
303
+			'tax_query' => array(
304
+				array(
305
+					'taxonomy' => $this->taxonomy,
306
+					'field' => 'id',
307
+					'terms' => $module_id
308
+				)
309
+			)
310
+		);
311
+		$courses = get_posts($args);
312
+
313
+		//build the defaults array
314
+		$module_courses = array();
315
+		if (isset($courses) && is_array($courses)) {
316
+			foreach ($courses as $course) {
317
+				$module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
+			}
319
+		}
320
+
321
+		?>
322 322
         <tr class="form-field">
323 323
             <th scope="row" valign="top"><label
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
@@ -335,872 +335,872 @@  discard block
 block discarded – undo
335 335
             </td>
336 336
         </tr>
337 337
     <?php
338
-    }
339
-
340
-    /**
341
-     * Save module course on add/edit
342
-     *
343
-     * @since 1.8.0
344
-     * @param  integer $module_id ID of module
345
-     * @return void
346
-     */
347
-    public function save_module_course($module_id)
348
-    {
349
-
350
-        // Get module's existing courses
351
-        $args = array(
352
-            'post_type' => 'course',
353
-            'post_status' => array('publish', 'draft', 'future', 'private'),
354
-            'posts_per_page' => -1,
355
-            'tax_query' => array(
356
-                array(
357
-                    'taxonomy' => $this->taxonomy,
358
-                    'field' => 'id',
359
-                    'terms' => $module_id
360
-                )
361
-            )
362
-        );
363
-        $courses = get_posts($args);
364
-
365
-        // Remove module from existing courses
366
-        if (isset($courses) && is_array($courses)) {
367
-            foreach ($courses as $course) {
368
-                wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
-            }
370
-        }
371
-
372
-        // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
-
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
376
-
377
-            foreach ( $course_ids as $course_id ) {
378
-
379
-                wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
-
381
-            }
382
-        }
383
-    }
384
-
385
-    /**
386
-     * Ajax function to search for courses matching term
387
-     *
388
-     * @since 1.8.0
389
-     * @return void
390
-     */
391
-    public function search_courses_json()
392
-    {
393
-
394
-        // Security check
395
-        check_ajax_referer('search-courses', 'security');
396
-
397
-        // Set content type
398
-        header('Content-Type: application/json; charset=utf-8');
399
-
400
-        // Get user input
401
-        $term = urldecode(stripslashes($_GET['term']));
402
-
403
-        // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
-
407
-        // Set a default if none is given
408
-        $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
-
410
-        // Set up array of results
411
-        $found_courses = array('' => $default);
412
-
413
-        // Fetch results
414
-        $args = array(
415
-            'post_type' => 'course',
416
-            'post_status' => array('publish', 'draft', 'future', 'private'),
417
-            'posts_per_page' => -1,
418
-            'orderby' => 'title',
419
-            's' => $term
420
-        );
421
-        $courses = get_posts($args);
422
-
423
-        // Add results to array
424
-        if ($courses) {
425
-            foreach ($courses as $course) {
426
-                $found_courses[$course->ID] = $course->post_title;
427
-            }
428
-        }
429
-
430
-        // Encode and return results for processing & selection
431
-        echo json_encode($found_courses);
432
-        die();
433
-    }
434
-
435
-    /**
436
-     * display modules on single course pages
437
-     *
438
-     * @since 1.8.0
439
-     * @return void
440
-     */
441
-    public function single_course_modules(){
442
-
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
-        // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
-
447
-            $this->load_course_module_content_template();
448
-
449
-        }
450
-
451
-    } // end single_course_modules
452
-
453
-    public function sensei_course_preview_titles($title, $lesson_id)
454
-    {
455
-        global $post, $current_user;
456
-
457
-        $course_id = $post->ID;
458
-        $title_text = '';
459
-
460
-        if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
463
-                if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
-                    $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
-                    // Remove brackets for display here
466
-                    $title_text = str_replace('(', '', $title_text);
467
-                    $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
469
-                }
470
-                $title .= ' ' . $title_text;
471
-            }
472
-        }
473
-
474
-        return $title;
475
-    }
476
-
477
-    public function module_breadcrumb_link($html, $separator)
478
-    {
479
-        global $post;
480
-        // Lesson
481
-        if (is_singular('lesson')) {
482
-            if (has_term('', $this->taxonomy, $post->ID)) {
483
-                $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
-                }
487
-            }
488
-        }
489
-        // Module
490
-        if (is_tax($this->taxonomy)) {
491
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
-                $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
-            }
495
-        }
496
-        return $html;
497
-    }
498
-
499
-    /**
500
-     * Set lesson archive template to display on module taxonomy archive page
501
-     *
502
-     * @since 1.8.0
503
-     * @param  string $template Default template
504
-     * @return string           Modified template
505
-     */
506
-    public function module_archive_template($template) {
507
-
508
-        if ( ! is_tax($this->taxonomy) ) {
509
-            return $template;
510
-        }
511
-
512
-        $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
514
-
515
-        // locate the template file
516
-        $template = locate_template($find);
517
-        if (!$template) {
518
-
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
520
-
521
-        }
522
-
523
-
524
-        return $template;
525
-    }
526
-
527
-    /**
528
-     * Modify module taxonomy archive query
529
-     *
530
-     * @since 1.8.0
531
-     * @param  object $query The query object passed by reference
532
-     * @return void
533
-     */
534
-    public function module_archive_filter($query)
535
-    {
536
-        if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
-
538
-
539
-            // Limit to lessons only
540
-            $query->set('post_type', 'lesson');
541
-
542
-            // Set order of lessons
543
-            if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
-                $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
546
-                $query->set('orderby', 'meta_value_num date');
547
-            } else {
548
-                $query->set('orderby', 'menu_order');
549
-            }
550
-            $query->set('order', 'ASC');
551
-
552
-            // Limit to specific course if specified
553
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
-                $course_id = intval($_GET['course_id']);
555
-                $meta_query[] = array(
556
-                    'key' => '_lesson_course',
557
-                    'value' => intval($course_id)
558
-                );
559
-                $query->set('meta_query', $meta_query);
560
-            }
561
-
562
-        }
563
-    }
564
-
565
-    /**
566
-     * Modify archive page title
567
-     *
568
-     * @since 1.8.0
569
-     * @param  string $title Default title
570
-     * @return string        Modified title
571
-     */
572
-    public function module_archive_title($title)
573
-    {
574
-        if (is_tax($this->taxonomy)) {
575
-            $title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
-        }
577
-        return $title;
578
-    }
579
-
580
-    /**
581
-     * Display module description on taxonomy archive page
582
-     *
583
-     * @since 1.8.0
584
-     * @return void
585
-     */
586
-    public function module_archive_description()
587
-    {
588
-        if (is_tax($this->taxonomy)) {
589
-
590
-            $module = get_queried_object();
591
-
592
-            $module_progress = false;
593
-            if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
-                global $current_user;
595
-                wp_get_current_user();
596
-                $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
-            }
598
-
599
-            if ($module_progress && $module_progress > 0) {
600
-                $status = __('Completed', 'woothemes-sensei');
601
-                $class = 'completed';
602
-                if ($module_progress < 100) {
603
-                    $status = __('In progress', 'woothemes-sensei');
604
-                    $class = 'in-progress';
605
-                }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
-            }
608
-
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
-        }
611
-    }
612
-
613
-    public function module_archive_body_class($classes)
614
-    {
615
-        if (is_tax($this->taxonomy)) {
616
-            $classes[] = 'module-archive';
617
-        }
618
-        return $classes;
619
-    }
620
-
621
-    /**
622
-     * Display module navigation links on module taxonomy archive page
623
-     *
624
-     * @since 1.8.0
625
-     * @return void
626
-     */
627
-    public function module_navigation_links()
628
-    {
629
-        if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
-
631
-            $queried_module = get_queried_object();
632
-            $course_modules = $this->get_course_modules($_GET['course_id']);
633
-
634
-            $prev_module = false;
635
-            $next_module = false;
636
-            $on_current = false;
637
-            foreach ($course_modules as $module) {
638
-                $this_module = $module;
639
-                if ($on_current) {
640
-                    $next_module = $this_module;
641
-                    break;
642
-                }
643
-                if ($this_module == $queried_module) {
644
-                    $on_current = true;
645
-                } else {
646
-                    $prev_module = $module;
647
-                }
648
-            }
649
-
650
-            ?>
338
+	}
339
+
340
+	/**
341
+	 * Save module course on add/edit
342
+	 *
343
+	 * @since 1.8.0
344
+	 * @param  integer $module_id ID of module
345
+	 * @return void
346
+	 */
347
+	public function save_module_course($module_id)
348
+	{
349
+
350
+		// Get module's existing courses
351
+		$args = array(
352
+			'post_type' => 'course',
353
+			'post_status' => array('publish', 'draft', 'future', 'private'),
354
+			'posts_per_page' => -1,
355
+			'tax_query' => array(
356
+				array(
357
+					'taxonomy' => $this->taxonomy,
358
+					'field' => 'id',
359
+					'terms' => $module_id
360
+				)
361
+			)
362
+		);
363
+		$courses = get_posts($args);
364
+
365
+		// Remove module from existing courses
366
+		if (isset($courses) && is_array($courses)) {
367
+			foreach ($courses as $course) {
368
+				wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
+			}
370
+		}
371
+
372
+		// Add module to selected courses
373
+		if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
+
375
+			$course_ids = explode( ",", $_POST['module_courses'] );
376
+
377
+			foreach ( $course_ids as $course_id ) {
378
+
379
+				wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
+
381
+			}
382
+		}
383
+	}
384
+
385
+	/**
386
+	 * Ajax function to search for courses matching term
387
+	 *
388
+	 * @since 1.8.0
389
+	 * @return void
390
+	 */
391
+	public function search_courses_json()
392
+	{
393
+
394
+		// Security check
395
+		check_ajax_referer('search-courses', 'security');
396
+
397
+		// Set content type
398
+		header('Content-Type: application/json; charset=utf-8');
399
+
400
+		// Get user input
401
+		$term = urldecode(stripslashes($_GET['term']));
402
+
403
+		// Return nothing if term is empty
404
+		if (empty($term))
405
+			die();
406
+
407
+		// Set a default if none is given
408
+		$default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
+
410
+		// Set up array of results
411
+		$found_courses = array('' => $default);
412
+
413
+		// Fetch results
414
+		$args = array(
415
+			'post_type' => 'course',
416
+			'post_status' => array('publish', 'draft', 'future', 'private'),
417
+			'posts_per_page' => -1,
418
+			'orderby' => 'title',
419
+			's' => $term
420
+		);
421
+		$courses = get_posts($args);
422
+
423
+		// Add results to array
424
+		if ($courses) {
425
+			foreach ($courses as $course) {
426
+				$found_courses[$course->ID] = $course->post_title;
427
+			}
428
+		}
429
+
430
+		// Encode and return results for processing & selection
431
+		echo json_encode($found_courses);
432
+		die();
433
+	}
434
+
435
+	/**
436
+	 * display modules on single course pages
437
+	 *
438
+	 * @since 1.8.0
439
+	 * @return void
440
+	 */
441
+	public function single_course_modules(){
442
+
443
+		_deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
+		// only show modules on the course that has modules
445
+		if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
+
447
+			$this->load_course_module_content_template();
448
+
449
+		}
450
+
451
+	} // end single_course_modules
452
+
453
+	public function sensei_course_preview_titles($title, $lesson_id)
454
+	{
455
+		global $post, $current_user;
456
+
457
+		$course_id = $post->ID;
458
+		$title_text = '';
459
+
460
+		if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
+			if (!$is_user_taking_course) {
463
+				if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
+					$title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
+					// Remove brackets for display here
466
+					$title_text = str_replace('(', '', $title_text);
467
+					$title_text = str_replace(')', '', $title_text);
468
+					$title_text = '<span class="preview-label">' . $title_text . '</span>';
469
+				}
470
+				$title .= ' ' . $title_text;
471
+			}
472
+		}
473
+
474
+		return $title;
475
+	}
476
+
477
+	public function module_breadcrumb_link($html, $separator)
478
+	{
479
+		global $post;
480
+		// Lesson
481
+		if (is_singular('lesson')) {
482
+			if (has_term('', $this->taxonomy, $post->ID)) {
483
+				$module = $this->get_lesson_module($post->ID);
484
+				if( $module ) {
485
+					$html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
+				}
487
+			}
488
+		}
489
+		// Module
490
+		if (is_tax($this->taxonomy)) {
491
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
+				$course_id = intval($_GET['course_id']);
493
+				$html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
+			}
495
+		}
496
+		return $html;
497
+	}
498
+
499
+	/**
500
+	 * Set lesson archive template to display on module taxonomy archive page
501
+	 *
502
+	 * @since 1.8.0
503
+	 * @param  string $template Default template
504
+	 * @return string           Modified template
505
+	 */
506
+	public function module_archive_template($template) {
507
+
508
+		if ( ! is_tax($this->taxonomy) ) {
509
+			return $template;
510
+		}
511
+
512
+		$file = 'archive-lesson.php';
513
+		$find = array( $file, Sensei()->template_url . $file );
514
+
515
+		// locate the template file
516
+		$template = locate_template($find);
517
+		if (!$template) {
518
+
519
+			$template = Sensei()->plugin_path() . 'templates/' . $file;
520
+
521
+		}
522
+
523
+
524
+		return $template;
525
+	}
526
+
527
+	/**
528
+	 * Modify module taxonomy archive query
529
+	 *
530
+	 * @since 1.8.0
531
+	 * @param  object $query The query object passed by reference
532
+	 * @return void
533
+	 */
534
+	public function module_archive_filter($query)
535
+	{
536
+		if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
+
538
+
539
+			// Limit to lessons only
540
+			$query->set('post_type', 'lesson');
541
+
542
+			// Set order of lessons
543
+			if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
+				$module_id = $query->queried_object_id;
545
+				$query->set('meta_key', '_order_module_' . $module_id);
546
+				$query->set('orderby', 'meta_value_num date');
547
+			} else {
548
+				$query->set('orderby', 'menu_order');
549
+			}
550
+			$query->set('order', 'ASC');
551
+
552
+			// Limit to specific course if specified
553
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
+				$course_id = intval($_GET['course_id']);
555
+				$meta_query[] = array(
556
+					'key' => '_lesson_course',
557
+					'value' => intval($course_id)
558
+				);
559
+				$query->set('meta_query', $meta_query);
560
+			}
561
+
562
+		}
563
+	}
564
+
565
+	/**
566
+	 * Modify archive page title
567
+	 *
568
+	 * @since 1.8.0
569
+	 * @param  string $title Default title
570
+	 * @return string        Modified title
571
+	 */
572
+	public function module_archive_title($title)
573
+	{
574
+		if (is_tax($this->taxonomy)) {
575
+			$title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
+		}
577
+		return $title;
578
+	}
579
+
580
+	/**
581
+	 * Display module description on taxonomy archive page
582
+	 *
583
+	 * @since 1.8.0
584
+	 * @return void
585
+	 */
586
+	public function module_archive_description()
587
+	{
588
+		if (is_tax($this->taxonomy)) {
589
+
590
+			$module = get_queried_object();
591
+
592
+			$module_progress = false;
593
+			if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
+				global $current_user;
595
+				wp_get_current_user();
596
+				$module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
+			}
598
+
599
+			if ($module_progress && $module_progress > 0) {
600
+				$status = __('Completed', 'woothemes-sensei');
601
+				$class = 'completed';
602
+				if ($module_progress < 100) {
603
+					$status = __('In progress', 'woothemes-sensei');
604
+					$class = 'in-progress';
605
+				}
606
+				echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
+			}
608
+
609
+			echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
+		}
611
+	}
612
+
613
+	public function module_archive_body_class($classes)
614
+	{
615
+		if (is_tax($this->taxonomy)) {
616
+			$classes[] = 'module-archive';
617
+		}
618
+		return $classes;
619
+	}
620
+
621
+	/**
622
+	 * Display module navigation links on module taxonomy archive page
623
+	 *
624
+	 * @since 1.8.0
625
+	 * @return void
626
+	 */
627
+	public function module_navigation_links()
628
+	{
629
+		if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
+
631
+			$queried_module = get_queried_object();
632
+			$course_modules = $this->get_course_modules($_GET['course_id']);
633
+
634
+			$prev_module = false;
635
+			$next_module = false;
636
+			$on_current = false;
637
+			foreach ($course_modules as $module) {
638
+				$this_module = $module;
639
+				if ($on_current) {
640
+					$next_module = $this_module;
641
+					break;
642
+				}
643
+				if ($this_module == $queried_module) {
644
+					$on_current = true;
645
+				} else {
646
+					$prev_module = $module;
647
+				}
648
+			}
649
+
650
+			?>
651 651
             <div id="post-entries" class="post-entries module-navigation fix">
652 652
                 <?php if ($next_module) {
653
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
-                    ?>
653
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
+					?>
655 655
                     <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>"
656 656
                                                 title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?>
657 657
                             <span class="meta-nav"></span></a></div>
658 658
                 <?php } ?>
659 659
                 <?php if ($prev_module) {
660
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
-                    ?>
660
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
+					?>
662 662
                     <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>"
663 663
                                                 title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span
664 664
                                 class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div>
665 665
                 <?php } ?>
666 666
             </div>
667 667
         <?php
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
-     *
674
-     * @since 1.8.0
675
-     * @param  string $status Status of the lesson for the user
676
-     * @param  integer $user_id ID of user
677
-     * @param  integer $lesson_id ID of lesson
678
-     * @return void
679
-     */
680
-    public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
-    {
682
-        $this->save_lesson_module_progress($user_id, $lesson_id);
683
-    }
684
-
685
-    /**
686
-     * Save lesson's module progress for a specific user
687
-     *
688
-     * @since 1.8.0
689
-     * @param  integer $user_id ID of user
690
-     * @param  integer $lesson_id ID of lesson
691
-     * @return void
692
-     */
693
-    public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
-    {
695
-        $module = $this->get_lesson_module($lesson_id);
696
-        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
-        if ($module && $course_id) {
698
-            $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
-        }
700
-    }
701
-
702
-    /**
703
-     * Save progress of module for user
704
-     *
705
-     * @since 1.8.0
706
-     * @return void
707
-     */
708
-    public function save_module_progress()
709
-    {
710
-        if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
-            global $current_user;
712
-            wp_get_current_user();
713
-            $user_id = $current_user->ID;
714
-
715
-            $module = get_queried_object();
716
-
717
-            $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Save module progess for user
723
-     *
724
-     * @since 1.8.0
725
-     *
726
-     * @param  integer $module_id ID of module
727
-     * @param  integer $course_id ID of course
728
-     * @param  integer $user_id ID of user
729
-     * @return void
730
-     */
731
-    public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
-    {
733
-        $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
-
736
-        do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
-    }
738
-
739
-    /**
740
-     * Get module progress for a user
741
-     *
742
-     * @since 1.8.0
743
-     *
744
-     * @param  integer $module_id ID of module
745
-     * @param  integer $course_id ID of course
746
-     * @param  integer $user_id ID of user
747
-     * @return mixed              Module progress percentage on success, false on failure
748
-     */
749
-    public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
-    {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
-        if ($module_progress) {
753
-            return (float)$module_progress;
754
-        }
755
-        return false;
756
-    }
757
-
758
-    /**
759
-     * Calculate module progess for user
760
-     *
761
-     * @since 1.8.0
762
-     *
763
-     * @param  integer $user_id ID of user
764
-     * @param  integer $module_id ID of module
765
-     * @param  integer $course_id ID of course
766
-     * @return integer            Module progress percentage
767
-     */
768
-    public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
-    {
770
-
771
-        $args = array(
772
-            'post_type' => 'lesson',
773
-            'post_status' => 'publish',
774
-            'posts_per_page' => -1,
775
-            'tax_query' => array(
776
-                array(
777
-                    'taxonomy' => $this->taxonomy,
778
-                    'field' => 'id',
779
-                    'terms' => $module_id
780
-                )
781
-            ),
782
-            'meta_query' => array(
783
-                array(
784
-                    'key' => '_lesson_course',
785
-                    'value' => $course_id
786
-                )
787
-            ),
788
-            'fields' => 'ids'
789
-        );
790
-        $lessons = get_posts($args);
791
-
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
-
794
-        $completed = false;
795
-        $lesson_count = 0;
796
-        $completed_count = 0;
797
-        foreach ($lessons as $lesson_id) {
798
-            $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
-            ++$lesson_count;
800
-            if ($completed) {
801
-                ++$completed_count;
802
-            }
803
-        }
804
-        $module_progress = ($completed_count / $lesson_count) * 100;
805
-
806
-        return (float)$module_progress;
807
-    }
808
-
809
-    /**
810
-     * Register admin screen for ordering modules
811
-     *
812
-     * @since 1.8.0
813
-     *
814
-     * @return void
815
-     */
816
-    public function register_modules_admin_menu_items()
817
-    {
818
-        //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
-
821
-        // Regsiter new admin page for module ordering
822
-        $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
-
824
-    }
825
-
826
-    /**
827
-     * Display Module Order screen
828
-     *
829
-     * @since 1.8.0
830
-     *
831
-     * @return void
832
-     */
833
-    public function module_order_screen()
834
-    {
835
-        ?>
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
+	 *
674
+	 * @since 1.8.0
675
+	 * @param  string $status Status of the lesson for the user
676
+	 * @param  integer $user_id ID of user
677
+	 * @param  integer $lesson_id ID of lesson
678
+	 * @return void
679
+	 */
680
+	public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
+	{
682
+		$this->save_lesson_module_progress($user_id, $lesson_id);
683
+	}
684
+
685
+	/**
686
+	 * Save lesson's module progress for a specific user
687
+	 *
688
+	 * @since 1.8.0
689
+	 * @param  integer $user_id ID of user
690
+	 * @param  integer $lesson_id ID of lesson
691
+	 * @return void
692
+	 */
693
+	public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
+	{
695
+		$module = $this->get_lesson_module($lesson_id);
696
+		$course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
+		if ($module && $course_id) {
698
+			$this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
+		}
700
+	}
701
+
702
+	/**
703
+	 * Save progress of module for user
704
+	 *
705
+	 * @since 1.8.0
706
+	 * @return void
707
+	 */
708
+	public function save_module_progress()
709
+	{
710
+		if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
+			global $current_user;
712
+			wp_get_current_user();
713
+			$user_id = $current_user->ID;
714
+
715
+			$module = get_queried_object();
716
+
717
+			$this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Save module progess for user
723
+	 *
724
+	 * @since 1.8.0
725
+	 *
726
+	 * @param  integer $module_id ID of module
727
+	 * @param  integer $course_id ID of course
728
+	 * @param  integer $user_id ID of user
729
+	 * @return void
730
+	 */
731
+	public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
+	{
733
+		$module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
+		update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
+
736
+		do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
+	}
738
+
739
+	/**
740
+	 * Get module progress for a user
741
+	 *
742
+	 * @since 1.8.0
743
+	 *
744
+	 * @param  integer $module_id ID of module
745
+	 * @param  integer $course_id ID of course
746
+	 * @param  integer $user_id ID of user
747
+	 * @return mixed              Module progress percentage on success, false on failure
748
+	 */
749
+	public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
+	{
751
+		$module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
+		if ($module_progress) {
753
+			return (float)$module_progress;
754
+		}
755
+		return false;
756
+	}
757
+
758
+	/**
759
+	 * Calculate module progess for user
760
+	 *
761
+	 * @since 1.8.0
762
+	 *
763
+	 * @param  integer $user_id ID of user
764
+	 * @param  integer $module_id ID of module
765
+	 * @param  integer $course_id ID of course
766
+	 * @return integer            Module progress percentage
767
+	 */
768
+	public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
+	{
770
+
771
+		$args = array(
772
+			'post_type' => 'lesson',
773
+			'post_status' => 'publish',
774
+			'posts_per_page' => -1,
775
+			'tax_query' => array(
776
+				array(
777
+					'taxonomy' => $this->taxonomy,
778
+					'field' => 'id',
779
+					'terms' => $module_id
780
+				)
781
+			),
782
+			'meta_query' => array(
783
+				array(
784
+					'key' => '_lesson_course',
785
+					'value' => $course_id
786
+				)
787
+			),
788
+			'fields' => 'ids'
789
+		);
790
+		$lessons = get_posts($args);
791
+
792
+		if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
+
794
+		$completed = false;
795
+		$lesson_count = 0;
796
+		$completed_count = 0;
797
+		foreach ($lessons as $lesson_id) {
798
+			$completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
+			++$lesson_count;
800
+			if ($completed) {
801
+				++$completed_count;
802
+			}
803
+		}
804
+		$module_progress = ($completed_count / $lesson_count) * 100;
805
+
806
+		return (float)$module_progress;
807
+	}
808
+
809
+	/**
810
+	 * Register admin screen for ordering modules
811
+	 *
812
+	 * @since 1.8.0
813
+	 *
814
+	 * @return void
815
+	 */
816
+	public function register_modules_admin_menu_items()
817
+	{
818
+		//add the modules link under the Course main menu
819
+		add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
+
821
+		// Regsiter new admin page for module ordering
822
+		$hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
+
824
+	}
825
+
826
+	/**
827
+	 * Display Module Order screen
828
+	 *
829
+	 * @since 1.8.0
830
+	 *
831
+	 * @return void
832
+	 */
833
+	public function module_order_screen()
834
+	{
835
+		?>
836 836
         <div id="<?php echo esc_attr($this->order_page_slug); ?>"
837 837
              class="wrap <?php echo esc_attr($this->order_page_slug); ?>">
838 838
         <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php
839 839
 
840
-        $html = '';
841
-
842
-        if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
-            $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
-
845
-            if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
849
-            }
850
-        }
851
-
852
-        $courses = Sensei()->course->get_all_courses();
853
-
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
-
860
-        foreach ($courses as $course) {
861
-            if (has_term('', $this->taxonomy, $course->ID)) {
862
-                $course_id = '';
863
-                if (isset($_GET['course_id'])) {
864
-                    $course_id = intval($_GET['course_id']);
865
-                }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
-            }
868
-        }
869
-
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
873
-
874
-        if (isset($_GET['course_id'])) {
875
-            $course_id = intval($_GET['course_id']);
876
-            if ($course_id > 0) {
877
-                $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
-                if ($modules) {
880
-
881
-                    $order = $this->get_course_module_order($course_id);
882
-
883
-                    $order_string='';
884
-                    if ($order) {
885
-                        $order_string = implode(',', $order);
886
-                    }
887
-
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
890
-                    $count = 0;
891
-                    foreach ($modules as $module) {
892
-                        $count++;
893
-                        $class = $this->taxonomy;
894
-                        if ($count == 1) {
895
-                            $class .= ' first';
896
-                        }
897
-                        if ($count == count($module)) {
898
-                            $class .= ' last';
899
-                        }
900
-                        if ($count % 2 != 0) {
901
-                            $class .= ' alternate';
902
-                        }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
-                    }
905
-                    $html .= '</ul>' . "\n";
906
-
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
-                }
912
-            }
913
-        }
914
-
915
-        echo $html;
916
-
917
-        ?></div><?php
918
-    }
919
-
920
-    /**
921
-     * Add 'Module order' column to courses list table
922
-     *
923
-     * @since 1.8.0
924
-     *
925
-     * @param  array $columns Existing columns
926
-     * @return array           Modifed columns
927
-     */
928
-    public function course_columns($columns = array())
929
-    {
930
-        $columns['module_order'] = __('Module order', 'woothemes-sensei');
931
-        return $columns;
932
-    }
933
-
934
-    /**
935
-     * Load content in 'Module order' column
936
-     *
937
-     * @since 1.8.0
938
-     *
939
-     * @param  string $column Current column name
940
-     * @param  integer $course_id ID of course
941
-     * @return void
942
-     */
943
-    public function course_column_content($column = '', $course_id = 0)
944
-    {
945
-        if ($column == 'module_order') {
946
-            if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
-            }
949
-        }
950
-    }
951
-
952
-    /**
953
-     * Save module order for course
954
-     *
955
-     * @since 1.8.0
956
-     *
957
-     * @param  string $order_string Comma-separated string of module IDs
958
-     * @param  integer $course_id ID of course
959
-     * @return boolean                 True on success, false on failure
960
-     */
961
-    private function save_course_module_order($order_string = '', $course_id = 0)
962
-    {
963
-        if ($order_string && $course_id) {
964
-            $order = explode(',', $order_string);
965
-            update_post_meta(intval($course_id), '_module_order', $order);
966
-            return true;
967
-        }
968
-        return false;
969
-    }
970
-
971
-    /**
972
-     * Get module order for course
973
-     *
974
-     * @since 1.8.0
975
-     *
976
-     * @param  integer $course_id ID of course
977
-     * @return mixed              Module order on success, false if no module order has been saved
978
-     */
979
-    public function get_course_module_order($course_id = 0)
980
-    {
981
-        if ($course_id) {
982
-            $order = get_post_meta(intval($course_id), '_module_order', true);
983
-            return $order;
984
-        }
985
-        return false;
986
-    }
987
-
988
-    /**
989
-     * Modify module taxonomy columns
990
-     *
991
-     * @since 1.8.0
992
-     *
993
-     * @param  array $columns Default columns
994
-     * @return array          Modified columns
995
-     */
996
-    public function taxonomy_column_headings($columns)
997
-    {
998
-
999
-        unset($columns['posts']);
1000
-
1001
-        $columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
-
1003
-        return $columns;
1004
-    }
1005
-
1006
-    /**
1007
-     * Manage content in custom module taxonomy columns
1008
-     *
1009
-     * @since 1.8.0
1010
-     *
1011
-     * @param  string $column_data Default data for column
1012
-     * @param  string $column_name Name of current column
1013
-     * @param  integer $term_id ID of current term
1014
-     * @return string               Modified column data
1015
-     */
1016
-    public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
-    {
1018
-
1019
-        $args = array(
1020
-            'post_status' => 'publish',
1021
-            'posts_per_page' => -1,
1022
-            'tax_query' => array(
1023
-                array(
1024
-                    'taxonomy' => $this->taxonomy,
1025
-                    'field' => 'id',
1026
-                    'terms' => intval($term_id)
1027
-                )
1028
-            )
1029
-        );
1030
-
1031
-        $module = get_term($term_id, $this->taxonomy);
1032
-
1033
-        switch ($column_name) {
1034
-
1035
-            case 'lessons':
1036
-                $args['post_type'] = 'lesson';
1037
-                $lessons = get_posts($args);
1038
-                $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
-                break;
1041
-        }
1042
-
1043
-        return $column_data;
1044
-    }
1045
-
1046
-    /**
1047
-     * Add 'Module' columns to Analysis Lesson Overview table
1048
-     *
1049
-     * @since 1.8.0
1050
-     *
1051
-     * @param  array $columns Default columns
1052
-     * @return array          Modified columns
1053
-     */
1054
-    public function analysis_overview_column_title($columns)
1055
-    {
1056
-
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
-            $new_columns = array();
1059
-            if (is_array($columns) && 0 < count($columns)) {
1060
-                foreach ($columns as $column => $title) {
1061
-                    $new_columns[$column] = $title;
1062
-                    if ($column == 'title') {
1063
-                        $new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
-                    }
1065
-                }
1066
-            }
1067
-
1068
-            if (0 < count($new_columns)) {
1069
-                return $new_columns;
1070
-            }
1071
-        }
1072
-
1073
-        return $columns;
1074
-    }
1075
-
1076
-    /**
1077
-     * Data for 'Module' column Analysis Lesson Overview table
1078
-     *
1079
-     * @since 1.8.0
1080
-     *
1081
-     * @param  array $columns Table column data
1082
-     * @param  WP_Post $lesson
1083
-     * @return array              Updated column data
1084
-     */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1086
-    {
1087
-
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
-            $lesson_module = '';
1090
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
-                foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
-                    break;
1095
-                }
1096
-            }
1097
-
1098
-            $columns['lesson_module'] = $lesson_module;
1099
-        }
1100
-
1101
-        return $columns;
1102
-    }
1103
-
1104
-    /**
1105
-     * Add 'Module' columns to Analysis Course table
1106
-     *
1107
-     * @since 1.8.0
1108
-     *
1109
-     * @param  array $columns Default columns
1110
-     * @return array          Modified columns
1111
-     */
1112
-    public function analysis_course_column_title($columns)
1113
-    {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
-            $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
-        }
1117
-        return $columns;
1118
-    }
1119
-
1120
-    /**
1121
-     * Data for 'Module' column in Analysis Course table
1122
-     *
1123
-     * @since 1.8.0
1124
-     *
1125
-     * @param  array $columns Table column data
1126
-     * @param  WP_Post $lesson
1127
-     * @return array              Updated columns data
1128
-     */
1129
-    public function analysis_course_column_data($columns, $lesson )
1130
-    {
1131
-
1132
-        if ( isset( $_GET['course_id'] ) ) {
1133
-            $lesson_module = '';
1134
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
-                foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
-                    break;
1139
-                }
1140
-            }
1141
-
1142
-            $columns['lesson_module'] = $lesson_module;
1143
-        }
1144
-
1145
-        return $columns;
1146
-    }
1147
-
1148
-    /**
1149
-     * Get module for lesson
1150
-     *
1151
-     * This function also checks if the module still
1152
-     * exists on the course before returning it. Although
1153
-     * the lesson has a module the same module must exist on the
1154
-     * course for it to be valid.
1155
-     *
1156
-     * @since 1.8.0
1157
-     *
1158
-     * @param  integer $lesson_id ID of lesson
1159
-     * @return object             Module taxonomy term object
1160
-     */
1161
-    public function get_lesson_module($lesson_id = 0)
1162
-    {
1163
-        $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1165
-            return false;
1166
-        }
1167
-
1168
-        // get taxonomy terms on this lesson
1169
-        $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
-
1171
-        //check if error returned
1172
-        if(    empty( $modules )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1175
-
1176
-            return false;
1177
-
1178
-        }
1179
-
1180
-       // get the last item in the array there should be only be 1 really.
1181
-       // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1183
-           break;
1184
-       }
1185
-
1186
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
-            return false;
1188
-        }
1189
-
1190
-        $module->url = get_term_link($module, $this->taxonomy);
1191
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
-        if (isset($course_id) && 0 < $course_id) {
1193
-
1194
-            // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
-                return false;
1197
-            }
1198
-
1199
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
-        }
1201
-        return $module;
1202
-
1203
-    }
840
+		$html = '';
841
+
842
+		if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
+			$ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
+
845
+			if ($ordered) {
846
+				$html .= '<div class="updated fade">' . "\n";
847
+				$html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
+				$html .= '</div>' . "\n";
849
+			}
850
+		}
851
+
852
+		$courses = Sensei()->course->get_all_courses();
853
+
854
+		$html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
+		$html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
+		$html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
+		$html .= '<select id="module-order-course" name="course_id">' . "\n";
858
+		$html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
+
860
+		foreach ($courses as $course) {
861
+			if (has_term('', $this->taxonomy, $course->ID)) {
862
+				$course_id = '';
863
+				if (isset($_GET['course_id'])) {
864
+					$course_id = intval($_GET['course_id']);
865
+				}
866
+				$html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
+			}
868
+		}
869
+
870
+		$html .= '</select>' . "\n";
871
+		$html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
+		$html .= '</form>' . "\n";
873
+
874
+		if (isset($_GET['course_id'])) {
875
+			$course_id = intval($_GET['course_id']);
876
+			if ($course_id > 0) {
877
+				$modules = $this->get_course_modules($course_id);
878
+				$modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
+				if ($modules) {
880
+
881
+					$order = $this->get_course_module_order($course_id);
882
+
883
+					$order_string='';
884
+					if ($order) {
885
+						$order_string = implode(',', $order);
886
+					}
887
+
888
+					$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
+					$html .= '<ul class="sortable-module-list">' . "\n";
890
+					$count = 0;
891
+					foreach ($modules as $module) {
892
+						$count++;
893
+						$class = $this->taxonomy;
894
+						if ($count == 1) {
895
+							$class .= ' first';
896
+						}
897
+						if ($count == count($module)) {
898
+							$class .= ' last';
899
+						}
900
+						if ($count % 2 != 0) {
901
+							$class .= ' alternate';
902
+						}
903
+						$html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
+					}
905
+					$html .= '</ul>' . "\n";
906
+
907
+					$html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
+					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
+					$html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
+					$html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
+				}
912
+			}
913
+		}
914
+
915
+		echo $html;
916
+
917
+		?></div><?php
918
+	}
919
+
920
+	/**
921
+	 * Add 'Module order' column to courses list table
922
+	 *
923
+	 * @since 1.8.0
924
+	 *
925
+	 * @param  array $columns Existing columns
926
+	 * @return array           Modifed columns
927
+	 */
928
+	public function course_columns($columns = array())
929
+	{
930
+		$columns['module_order'] = __('Module order', 'woothemes-sensei');
931
+		return $columns;
932
+	}
933
+
934
+	/**
935
+	 * Load content in 'Module order' column
936
+	 *
937
+	 * @since 1.8.0
938
+	 *
939
+	 * @param  string $column Current column name
940
+	 * @param  integer $course_id ID of course
941
+	 * @return void
942
+	 */
943
+	public function course_column_content($column = '', $course_id = 0)
944
+	{
945
+		if ($column == 'module_order') {
946
+			if (has_term('', $this->taxonomy, $course_id)) {
947
+				echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
+			}
949
+		}
950
+	}
951
+
952
+	/**
953
+	 * Save module order for course
954
+	 *
955
+	 * @since 1.8.0
956
+	 *
957
+	 * @param  string $order_string Comma-separated string of module IDs
958
+	 * @param  integer $course_id ID of course
959
+	 * @return boolean                 True on success, false on failure
960
+	 */
961
+	private function save_course_module_order($order_string = '', $course_id = 0)
962
+	{
963
+		if ($order_string && $course_id) {
964
+			$order = explode(',', $order_string);
965
+			update_post_meta(intval($course_id), '_module_order', $order);
966
+			return true;
967
+		}
968
+		return false;
969
+	}
970
+
971
+	/**
972
+	 * Get module order for course
973
+	 *
974
+	 * @since 1.8.0
975
+	 *
976
+	 * @param  integer $course_id ID of course
977
+	 * @return mixed              Module order on success, false if no module order has been saved
978
+	 */
979
+	public function get_course_module_order($course_id = 0)
980
+	{
981
+		if ($course_id) {
982
+			$order = get_post_meta(intval($course_id), '_module_order', true);
983
+			return $order;
984
+		}
985
+		return false;
986
+	}
987
+
988
+	/**
989
+	 * Modify module taxonomy columns
990
+	 *
991
+	 * @since 1.8.0
992
+	 *
993
+	 * @param  array $columns Default columns
994
+	 * @return array          Modified columns
995
+	 */
996
+	public function taxonomy_column_headings($columns)
997
+	{
998
+
999
+		unset($columns['posts']);
1000
+
1001
+		$columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
+
1003
+		return $columns;
1004
+	}
1005
+
1006
+	/**
1007
+	 * Manage content in custom module taxonomy columns
1008
+	 *
1009
+	 * @since 1.8.0
1010
+	 *
1011
+	 * @param  string $column_data Default data for column
1012
+	 * @param  string $column_name Name of current column
1013
+	 * @param  integer $term_id ID of current term
1014
+	 * @return string               Modified column data
1015
+	 */
1016
+	public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
+	{
1018
+
1019
+		$args = array(
1020
+			'post_status' => 'publish',
1021
+			'posts_per_page' => -1,
1022
+			'tax_query' => array(
1023
+				array(
1024
+					'taxonomy' => $this->taxonomy,
1025
+					'field' => 'id',
1026
+					'terms' => intval($term_id)
1027
+				)
1028
+			)
1029
+		);
1030
+
1031
+		$module = get_term($term_id, $this->taxonomy);
1032
+
1033
+		switch ($column_name) {
1034
+
1035
+			case 'lessons':
1036
+				$args['post_type'] = 'lesson';
1037
+				$lessons = get_posts($args);
1038
+				$total_lessons = count($lessons);
1039
+				$column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
+				break;
1041
+		}
1042
+
1043
+		return $column_data;
1044
+	}
1045
+
1046
+	/**
1047
+	 * Add 'Module' columns to Analysis Lesson Overview table
1048
+	 *
1049
+	 * @since 1.8.0
1050
+	 *
1051
+	 * @param  array $columns Default columns
1052
+	 * @return array          Modified columns
1053
+	 */
1054
+	public function analysis_overview_column_title($columns)
1055
+	{
1056
+
1057
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
+			$new_columns = array();
1059
+			if (is_array($columns) && 0 < count($columns)) {
1060
+				foreach ($columns as $column => $title) {
1061
+					$new_columns[$column] = $title;
1062
+					if ($column == 'title') {
1063
+						$new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
+					}
1065
+				}
1066
+			}
1067
+
1068
+			if (0 < count($new_columns)) {
1069
+				return $new_columns;
1070
+			}
1071
+		}
1072
+
1073
+		return $columns;
1074
+	}
1075
+
1076
+	/**
1077
+	 * Data for 'Module' column Analysis Lesson Overview table
1078
+	 *
1079
+	 * @since 1.8.0
1080
+	 *
1081
+	 * @param  array $columns Table column data
1082
+	 * @param  WP_Post $lesson
1083
+	 * @return array              Updated column data
1084
+	 */
1085
+	public function analysis_overview_column_data($columns, $lesson )
1086
+	{
1087
+
1088
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
+			$lesson_module = '';
1090
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
+				foreach ($lesson_module_list as $single_module) {
1093
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
+					break;
1095
+				}
1096
+			}
1097
+
1098
+			$columns['lesson_module'] = $lesson_module;
1099
+		}
1100
+
1101
+		return $columns;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Add 'Module' columns to Analysis Course table
1106
+	 *
1107
+	 * @since 1.8.0
1108
+	 *
1109
+	 * @param  array $columns Default columns
1110
+	 * @return array          Modified columns
1111
+	 */
1112
+	public function analysis_course_column_title($columns)
1113
+	{
1114
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
+			$columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
+		}
1117
+		return $columns;
1118
+	}
1119
+
1120
+	/**
1121
+	 * Data for 'Module' column in Analysis Course table
1122
+	 *
1123
+	 * @since 1.8.0
1124
+	 *
1125
+	 * @param  array $columns Table column data
1126
+	 * @param  WP_Post $lesson
1127
+	 * @return array              Updated columns data
1128
+	 */
1129
+	public function analysis_course_column_data($columns, $lesson )
1130
+	{
1131
+
1132
+		if ( isset( $_GET['course_id'] ) ) {
1133
+			$lesson_module = '';
1134
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
+				foreach ($lesson_module_list as $single_module) {
1137
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
+					break;
1139
+				}
1140
+			}
1141
+
1142
+			$columns['lesson_module'] = $lesson_module;
1143
+		}
1144
+
1145
+		return $columns;
1146
+	}
1147
+
1148
+	/**
1149
+	 * Get module for lesson
1150
+	 *
1151
+	 * This function also checks if the module still
1152
+	 * exists on the course before returning it. Although
1153
+	 * the lesson has a module the same module must exist on the
1154
+	 * course for it to be valid.
1155
+	 *
1156
+	 * @since 1.8.0
1157
+	 *
1158
+	 * @param  integer $lesson_id ID of lesson
1159
+	 * @return object             Module taxonomy term object
1160
+	 */
1161
+	public function get_lesson_module($lesson_id = 0)
1162
+	{
1163
+		$lesson_id = intval($lesson_id);
1164
+		if ( ! ( intval( $lesson_id > 0) ) ) {
1165
+			return false;
1166
+		}
1167
+
1168
+		// get taxonomy terms on this lesson
1169
+		$modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
+
1171
+		//check if error returned
1172
+		if(    empty( $modules )
1173
+			|| is_wp_error( $modules )
1174
+			|| isset( $modules['errors'] ) ){
1175
+
1176
+			return false;
1177
+
1178
+		}
1179
+
1180
+	   // get the last item in the array there should be only be 1 really.
1181
+	   // this method works for all php versions.
1182
+	   foreach( $modules as $module ){
1183
+		   break;
1184
+	   }
1185
+
1186
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
+			return false;
1188
+		}
1189
+
1190
+		$module->url = get_term_link($module, $this->taxonomy);
1191
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
+		if (isset($course_id) && 0 < $course_id) {
1193
+
1194
+			// the course should contain the same module taxonomy term for this to be valid
1195
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
+				return false;
1197
+			}
1198
+
1199
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
+		}
1201
+		return $module;
1202
+
1203
+	}
1204 1204
 
1205 1205
 	/**
1206 1206
 	 * Get ordered array of all modules in course
@@ -1259,485 +1259,485 @@  discard block
 block discarded – undo
1259 1259
 
1260 1260
 	}
1261 1261
 
1262
-    /**
1263
-     * Load frontend CSS
1264
-     *
1265
-     * @since 1.8.0
1266
-     *
1267
-     * @return void
1268
-     */
1269
-    public function enqueue_styles() {
1270
-
1271
-        // wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1272
-        // wp_enqueue_style($this->taxonomy . '-frontend');
1273
-
1274
-    }
1275
-
1276
-    /**
1277
-     * Load admin Javascript
1278
-     *
1279
-     * @since 1.8.0
1280
-     *
1281
-     * @return void
1282
-     */
1283
-    public function admin_enqueue_scripts( $hook ) {
1284
-
1285
-        /**
1286
-         * Filter the page hooks where modules admin script can be loaded on.
1287
-         *
1288
-         * @param array $white_listed_pages
1289
-         */
1290
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1291
-            'edit-tags.php',
1292
-            'course_page_module-order',
1293
-            'post-new.php',
1294
-            'post.php'
1295
-        ) );
1296
-
1297
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1298
-            return;
1299
-        }
1300
-
1301
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1302
-
1303
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1306
-
1307
-        // localized module data
1308
-        $localize_modulesAdmin = array(
1309
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1311
-        );
1312
-
1313
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1314
-    }
1262
+	/**
1263
+	 * Load frontend CSS
1264
+	 *
1265
+	 * @since 1.8.0
1266
+	 *
1267
+	 * @return void
1268
+	 */
1269
+	public function enqueue_styles() {
1270
+
1271
+		// wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1272
+		// wp_enqueue_style($this->taxonomy . '-frontend');
1273
+
1274
+	}
1275
+
1276
+	/**
1277
+	 * Load admin Javascript
1278
+	 *
1279
+	 * @since 1.8.0
1280
+	 *
1281
+	 * @return void
1282
+	 */
1283
+	public function admin_enqueue_scripts( $hook ) {
1284
+
1285
+		/**
1286
+		 * Filter the page hooks where modules admin script can be loaded on.
1287
+		 *
1288
+		 * @param array $white_listed_pages
1289
+		 */
1290
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1291
+			'edit-tags.php',
1292
+			'course_page_module-order',
1293
+			'post-new.php',
1294
+			'post.php'
1295
+		) );
1296
+
1297
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1298
+			return;
1299
+		}
1300
+
1301
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1302
+
1303
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
+		wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1306
+
1307
+		// localized module data
1308
+		$localize_modulesAdmin = array(
1309
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1311
+		);
1312
+
1313
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1314
+	}
1315
+
1316
+	/**
1317
+	 * Load admin CSS
1318
+	 *
1319
+	 * @since 1.8.0
1320
+	 *
1321
+	 * @return void
1322
+	 */
1323
+	public function admin_enqueue_styles() {
1324
+
1325
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
+		wp_enqueue_style($this->taxonomy . '-sortable');
1327
+
1328
+	}
1329
+
1330
+	/**
1331
+	 * Show the title modules on the single course template.
1332
+	 *
1333
+	 * Function is hooked into sensei_single_course_modules_before.
1334
+	 *
1335
+	 * @since 1.8.0
1336
+	 * @return void
1337
+	 */
1338
+	public function course_modules_title( ) {
1339
+
1340
+	   if( sensei_module_has_lessons() ){
1341
+
1342
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1343
+
1344
+		}
1345
+
1346
+	}
1347
+
1348
+	/**
1349
+	 * Display the single course modules content this will only show
1350
+	 * if the course has modules.
1351
+	 *
1352
+	 * @since 1.8.0
1353
+	 * @return void
1354
+	 */
1355
+	public function load_course_module_content_template(){
1356
+
1357
+		if ( ! is_singular( 'course' )  ) {
1358
+			return;
1359
+		}
1360
+
1361
+		// load backwards compatible template name if it exists in the users theme
1362
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
+		if( $located_template ){
1364
+
1365
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1366
+			return;
1367
+
1368
+		}
1369
+
1370
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1371
+
1372
+	} // end course_module_content
1373
+
1374
+	/**
1375
+	 * Returns all lessons for the given module ID
1376
+	 *
1377
+	 * @since 1.8.0
1378
+	 *
1379
+	 * @param $course_id
1380
+	 * @param $term_id
1381
+	 * @return array $lessons
1382
+	 */
1383
+	public function get_lessons( $course_id , $term_id ){
1384
+
1385
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1386
+
1387
+		if( isset( $lesson_query->posts ) ){
1388
+
1389
+			return $lesson_query->posts;
1390
+
1391
+		}else{
1392
+
1393
+			return array();
1394
+
1395
+		}
1396
+
1397
+	} // end get lessons
1398
+
1399
+	/**
1400
+	 * Returns all lessons for the given module ID
1401
+	 *
1402
+	 * @since 1.8.0
1403
+	 *
1404
+	 * @param $course_id
1405
+	 * @param $term_id
1406
+	 * @return WP_Query $lessons_query
1407
+	 */
1408
+	public function get_lessons_query( $course_id , $term_id ){
1409
+
1410
+		if( empty( $term_id ) || empty( $course_id ) ){
1411
+
1412
+			return array();
1413
+
1414
+		}
1415
+
1416
+		$args = array(
1417
+			'post_type' => 'lesson',
1418
+			'post_status' => 'publish',
1419
+			'posts_per_page' => -1,
1420
+			'meta_query' => array(
1421
+				array(
1422
+					'key' => '_lesson_course',
1423
+					'value' => intval($course_id),
1424
+					'compare' => '='
1425
+				)
1426
+			),
1427
+			'tax_query' => array(
1428
+				array(
1429
+					'taxonomy' => 'module',
1430
+					'field' => 'id',
1431
+					'terms' => intval( $term_id )
1432
+				)
1433
+			),
1434
+			'orderby' => 'menu_order',
1435
+			'order' => 'ASC',
1436
+			'suppress_filters' => 0
1437
+		);
1438
+
1439
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1441
+			$args['orderby'] = 'meta_value_num date';
1442
+		}
1443
+
1444
+		$lessons_query = new WP_Query( $args );
1445
+
1446
+		return $lessons_query;
1447
+
1448
+	} // end get lessons
1449
+
1450
+	/**
1451
+	 * Find the lesson in the given course that doesn't belong
1452
+	 * to any of the courses modules
1453
+	 *
1454
+	 *
1455
+	 * @param $course_id
1456
+	 *
1457
+	 * @return array $non_module_lessons
1458
+	 */
1459
+	public function get_none_module_lessons( $course_id ){
1460
+
1461
+		$non_module_lessons = array();
1462
+
1463
+		//exit if there is no course id passed in
1464
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1465
+
1466
+			return $non_module_lessons;
1467
+		}
1468
+
1469
+		//save some time and check if we already have the saved
1470
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1471
+
1472
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1473
+
1474
+		}
1475
+
1476
+		// create terms array which must be excluded from other arrays
1477
+		$course_modules = $this->get_course_modules( $course_id );
1478
+
1479
+		//exit if there are no module on this course
1480
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1481
+
1482
+			return  Sensei()->course->course_lessons( $course_id );
1483
+
1484
+		}
1485
+
1486
+		$terms = array();
1487
+		foreach( $course_modules as $module ){
1488
+
1489
+			array_push( $terms ,  $module->term_id );
1490
+
1491
+		}
1492
+
1493
+		$args = array(
1494
+			'post_type' => 'lesson',
1495
+			'post_status' => 'publish',
1496
+			'posts_per_page' => -1,
1497
+			'meta_query' => array(
1498
+				array(
1499
+					'key' => '_lesson_course',
1500
+					'value' => intval( $course_id ),
1501
+					'compare' => '='
1502
+				)
1503
+			),
1504
+			'tax_query' => array(
1505
+				array(
1506
+					'taxonomy' => 'module',
1507
+					'field' => 'id',
1508
+					'terms' =>  $terms,
1509
+					'operator' => 'NOT IN'
1510
+				)
1511
+			),
1512
+			'orderby' => 'menu_order',
1513
+			'order' => 'ASC',
1514
+			'suppress_filters' => 0
1515
+		);
1516
+
1517
+		$wp_lessons_query = new WP_Query( $args );
1518
+
1519
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1520
+			$non_module_lessons = $wp_lessons_query->get_posts();
1521
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1522
+		}
1523
+
1524
+		return $non_module_lessons;
1525
+	} // end get_none_module_lessons
1526
+
1527
+	/**
1528
+	 * Register the modules taxonomy
1529
+	 *
1530
+	 * @since 1.8.0
1531
+	 */
1532
+	public function setup_modules_taxonomy(){
1533
+
1534
+		$labels = array(
1535
+			'name' => __('Modules', 'woothemes-sensei'),
1536
+			'singular_name' => __('Module', 'woothemes-sensei'),
1537
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1538
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1539
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1540
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1541
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1542
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1543
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1544
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1545
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1546
+		);
1547
+
1548
+		/**
1549
+		 * Filter to alter the Sensei Modules rewrite slug
1550
+		 *
1551
+		 * @since 1.8.0
1552
+		 * @param string default 'modules'
1553
+		 */
1554
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1555
+
1556
+		$args = array(
1557
+			'public' => true,
1558
+			'hierarchical' => true,
1559
+			'show_admin_column' => true,
1560
+			'capabilities' => array(
1561
+				'manage_terms' => 'manage_categories',
1562
+				'edit_terms'   => 'edit_courses',
1563
+				'delete_terms' => 'manage_categories',
1564
+				'assign_terms' => 'edit_courses'
1565
+			),
1566
+			'show_in_nav_menus' => false,
1567
+			'show_in_quick_edit' => false,
1568
+			'show_ui' => true,
1569
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1570
+			'labels' => $labels
1571
+		);
1572
+
1573
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1574
+
1575
+	}// end setup_modules_taxonomy
1576
+
1577
+	/**
1578
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1579
+	 *
1580
+	 * This function is hooked into the admin_menu
1581
+	 *
1582
+	 * @since 1.8.0
1583
+	 * @return void
1584
+	 */
1585
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1586
+
1587
+		global $typenow , $taxnow;
1588
+
1589
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1591
+		}
1592
+
1593
+	}// end redirect to course taxonomy
1594
+
1595
+	/**
1596
+	 * Completely remove the module menu item under lessons.
1597
+	 *
1598
+	 * This function is hooked into the admin_menu
1599
+	 *
1600
+	 * @since 1.8.0
1601
+	 * @return void
1602
+	 */
1603
+	public function remove_lessons_menu_model_taxonomy(){
1604
+		global $submenu;
1605
+
1606
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1607
+			return; // exit
1608
+		}
1609
+
1610
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
+		foreach( $lesson_main_menu as $index => $sub_item ){
1612
+
1613
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1615
+			}
1616
+		}
1617
+
1618
+	}// end remove lesson module tax
1315 1619
 
1316
-    /**
1317
-     * Load admin CSS
1318
-     *
1319
-     * @since 1.8.0
1320
-     *
1321
-     * @return void
1322
-     */
1323
-    public function admin_enqueue_styles() {
1324
-
1325
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
-        wp_enqueue_style($this->taxonomy . '-sortable');
1327
-
1328
-    }
1329
-
1330
-    /**
1331
-     * Show the title modules on the single course template.
1332
-     *
1333
-     * Function is hooked into sensei_single_course_modules_before.
1334
-     *
1335
-     * @since 1.8.0
1336
-     * @return void
1337
-     */
1338
-    public function course_modules_title( ) {
1339
-
1340
-       if( sensei_module_has_lessons() ){
1341
-
1342
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1343
-
1344
-        }
1345
-
1346
-    }
1347
-
1348
-    /**
1349
-     * Display the single course modules content this will only show
1350
-     * if the course has modules.
1351
-     *
1352
-     * @since 1.8.0
1353
-     * @return void
1354
-     */
1355
-    public function load_course_module_content_template(){
1356
-
1357
-	    if ( ! is_singular( 'course' )  ) {
1358
-		    return;
1359
-	    }
1360
-
1361
-        // load backwards compatible template name if it exists in the users theme
1362
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
-        if( $located_template ){
1364
-
1365
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1366
-            return;
1367
-
1368
-        }
1369
-
1370
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1371
-
1372
-    } // end course_module_content
1373
-
1374
-    /**
1375
-     * Returns all lessons for the given module ID
1376
-     *
1377
-     * @since 1.8.0
1378
-     *
1379
-     * @param $course_id
1380
-     * @param $term_id
1381
-     * @return array $lessons
1382
-     */
1383
-    public function get_lessons( $course_id , $term_id ){
1384
-
1385
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1386
-
1387
-        if( isset( $lesson_query->posts ) ){
1620
+	/**
1621
+	 * Completely remove the second modules under courses
1622
+	 *
1623
+	 * This function is hooked into the admin_menu
1624
+	 *
1625
+	 * @since 1.8.0
1626
+	 * @return void
1627
+	 */
1628
+	public function remove_courses_menu_model_taxonomy(){
1629
+		global $submenu;
1630
+
1631
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1632
+			return; // exit
1633
+		}
1634
+
1635
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1636
+		foreach( $course_main_menu as $index => $sub_item ){
1388 1637
 
1389
-            return $lesson_query->posts;
1638
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1640
+			}
1641
+		}
1390 1642
 
1391
-        }else{
1643
+	}// end remove courses module tax
1392 1644
 
1393
-            return array();
1645
+	/**
1646
+	 * Determine the author of a module term term by looking at
1647
+	 * the prefixed author id. This function will query the full term object.
1648
+	 * Will return the admin user author could not be determined.
1649
+	 *
1650
+	 * @since 1.8.0
1651
+	 *
1652
+	 * @param string $term_name
1653
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1654
+	 */
1655
+	public static function get_term_authors( $term_name ){
1394 1656
 
1395
-        }
1657
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1396 1658
 
1397
-    } // end get lessons
1659
+		$owners = array();
1660
+		if( empty( $terms ) ){
1398 1661
 
1399
-    /**
1400
-     * Returns all lessons for the given module ID
1401
-     *
1402
-     * @since 1.8.0
1403
-     *
1404
-     * @param $course_id
1405
-     * @param $term_id
1406
-     * @return WP_Query $lessons_query
1407
-     */
1408
-    public function get_lessons_query( $course_id , $term_id ){
1409
-
1410
-        if( empty( $term_id ) || empty( $course_id ) ){
1411
-
1412
-            return array();
1413
-
1414
-        }
1415
-
1416
-        $args = array(
1417
-            'post_type' => 'lesson',
1418
-            'post_status' => 'publish',
1419
-            'posts_per_page' => -1,
1420
-            'meta_query' => array(
1421
-                array(
1422
-                    'key' => '_lesson_course',
1423
-                    'value' => intval($course_id),
1424
-                    'compare' => '='
1425
-                )
1426
-            ),
1427
-            'tax_query' => array(
1428
-                array(
1429
-                    'taxonomy' => 'module',
1430
-                    'field' => 'id',
1431
-                    'terms' => intval( $term_id )
1432
-                )
1433
-            ),
1434
-            'orderby' => 'menu_order',
1435
-            'order' => 'ASC',
1436
-            'suppress_filters' => 0
1437
-        );
1438
-
1439
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1441
-            $args['orderby'] = 'meta_value_num date';
1442
-        }
1443
-
1444
-        $lessons_query = new WP_Query( $args );
1445
-
1446
-        return $lessons_query;
1447
-
1448
-    } // end get lessons
1449
-
1450
-    /**
1451
-     * Find the lesson in the given course that doesn't belong
1452
-     * to any of the courses modules
1453
-     *
1454
-     *
1455
-     * @param $course_id
1456
-     *
1457
-     * @return array $non_module_lessons
1458
-     */
1459
-    public function get_none_module_lessons( $course_id ){
1460
-
1461
-        $non_module_lessons = array();
1462
-
1463
-        //exit if there is no course id passed in
1464
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1465
-
1466
-            return $non_module_lessons;
1467
-        }
1468
-
1469
-        //save some time and check if we already have the saved
1470
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1471
-
1472
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1473
-
1474
-        }
1475
-
1476
-        // create terms array which must be excluded from other arrays
1477
-        $course_modules = $this->get_course_modules( $course_id );
1478
-
1479
-        //exit if there are no module on this course
1480
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1481
-
1482
-            return  Sensei()->course->course_lessons( $course_id );
1483
-
1484
-        }
1485
-
1486
-        $terms = array();
1487
-        foreach( $course_modules as $module ){
1488
-
1489
-            array_push( $terms ,  $module->term_id );
1490
-
1491
-        }
1492
-
1493
-        $args = array(
1494
-            'post_type' => 'lesson',
1495
-            'post_status' => 'publish',
1496
-            'posts_per_page' => -1,
1497
-            'meta_query' => array(
1498
-                array(
1499
-                    'key' => '_lesson_course',
1500
-                    'value' => intval( $course_id ),
1501
-                    'compare' => '='
1502
-                )
1503
-            ),
1504
-            'tax_query' => array(
1505
-                array(
1506
-                    'taxonomy' => 'module',
1507
-                    'field' => 'id',
1508
-                    'terms' =>  $terms,
1509
-                    'operator' => 'NOT IN'
1510
-                )
1511
-            ),
1512
-            'orderby' => 'menu_order',
1513
-            'order' => 'ASC',
1514
-            'suppress_filters' => 0
1515
-        );
1516
-
1517
-        $wp_lessons_query = new WP_Query( $args );
1518
-
1519
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1520
-            $non_module_lessons = $wp_lessons_query->get_posts();
1521
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1522
-        }
1523
-
1524
-        return $non_module_lessons;
1525
-    } // end get_none_module_lessons
1526
-
1527
-    /**
1528
-     * Register the modules taxonomy
1529
-     *
1530
-     * @since 1.8.0
1531
-     */
1532
-    public function setup_modules_taxonomy(){
1533
-
1534
-        $labels = array(
1535
-            'name' => __('Modules', 'woothemes-sensei'),
1536
-            'singular_name' => __('Module', 'woothemes-sensei'),
1537
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1538
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1539
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1540
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1541
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1542
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1543
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1544
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1545
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1546
-        );
1547
-
1548
-        /**
1549
-         * Filter to alter the Sensei Modules rewrite slug
1550
-         *
1551
-         * @since 1.8.0
1552
-         * @param string default 'modules'
1553
-         */
1554
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1555
-
1556
-        $args = array(
1557
-            'public' => true,
1558
-            'hierarchical' => true,
1559
-            'show_admin_column' => true,
1560
-            'capabilities' => array(
1561
-                'manage_terms' => 'manage_categories',
1562
-                'edit_terms'   => 'edit_courses',
1563
-                'delete_terms' => 'manage_categories',
1564
-                'assign_terms' => 'edit_courses'
1565
-            ),
1566
-            'show_in_nav_menus' => false,
1567
-            'show_in_quick_edit' => false,
1568
-            'show_ui' => true,
1569
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1570
-            'labels' => $labels
1571
-        );
1572
-
1573
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1574
-
1575
-    }// end setup_modules_taxonomy
1576
-
1577
-    /**
1578
-     * When the wants to edit the lesson modules redirect them to the course modules.
1579
-     *
1580
-     * This function is hooked into the admin_menu
1581
-     *
1582
-     * @since 1.8.0
1583
-     * @return void
1584
-     */
1585
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1586
-
1587
-        global $typenow , $taxnow;
1588
-
1589
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1591
-        }
1592
-
1593
-    }// end redirect to course taxonomy
1594
-
1595
-    /**
1596
-     * Completely remove the module menu item under lessons.
1597
-     *
1598
-     * This function is hooked into the admin_menu
1599
-     *
1600
-     * @since 1.8.0
1601
-     * @return void
1602
-     */
1603
-    public function remove_lessons_menu_model_taxonomy(){
1604
-        global $submenu;
1605
-
1606
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1607
-            return; // exit
1608
-        }
1609
-
1610
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
-        foreach( $lesson_main_menu as $index => $sub_item ){
1612
-
1613
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1615
-            }
1616
-        }
1617
-
1618
-    }// end remove lesson module tax
1619
-
1620
-    /**
1621
-     * Completely remove the second modules under courses
1622
-     *
1623
-     * This function is hooked into the admin_menu
1624
-     *
1625
-     * @since 1.8.0
1626
-     * @return void
1627
-     */
1628
-    public function remove_courses_menu_model_taxonomy(){
1629
-        global $submenu;
1630
-
1631
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1632
-            return; // exit
1633
-        }
1634
-
1635
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1636
-        foreach( $course_main_menu as $index => $sub_item ){
1637
-
1638
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1640
-            }
1641
-        }
1642
-
1643
-    }// end remove courses module tax
1644
-
1645
-    /**
1646
-     * Determine the author of a module term term by looking at
1647
-     * the prefixed author id. This function will query the full term object.
1648
-     * Will return the admin user author could not be determined.
1649
-     *
1650
-     * @since 1.8.0
1651
-     *
1652
-     * @param string $term_name
1653
-     * @return array $owners { type WP_User }. Empty array if none if found.
1654
-     */
1655
-    public static function get_term_authors( $term_name ){
1656
-
1657
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1658
-
1659
-        $owners = array();
1660
-        if( empty( $terms ) ){
1661
-
1662
-            return $owners;
1662
+			return $owners;
1663 1663
 
1664
-        }
1664
+		}
1665 1665
 
1666
-        // setup the admin user
1666
+		// setup the admin user
1667 1667
 
1668 1668
 
1669
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
-        foreach( $terms as $term){
1671
-            if( $term->name == $term_name ){
1669
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
+		foreach( $terms as $term){
1671
+			if( $term->name == $term_name ){
1672 1672
 
1673
-                // look for the author in the slug
1674
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1673
+				// look for the author in the slug
1674
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1675 1675
 
1676
-            }// end if term name
1676
+			}// end if term name
1677 1677
 
1678
-        } // end for each
1678
+		} // end for each
1679 1679
 
1680
-        return $owners;
1680
+		return $owners;
1681 1681
 
1682
-    }// end get_term_author
1682
+	}// end get_term_author
1683 1683
 
1684
-    /**
1685
-     * Looks at a term slug and figures out
1686
-     * which author created the slug. The author was
1687
-     * appended when the user saved the module term in the course edit
1688
-     * screen.
1689
-     *
1690
-     * @since 1.8.0
1691
-     *
1692
-     * @param $slug
1693
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694
-     */
1695
-    public static function get_term_author( $slug='' ){
1684
+	/**
1685
+	 * Looks at a term slug and figures out
1686
+	 * which author created the slug. The author was
1687
+	 * appended when the user saved the module term in the course edit
1688
+	 * screen.
1689
+	 *
1690
+	 * @since 1.8.0
1691
+	 *
1692
+	 * @param $slug
1693
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694
+	 */
1695
+	public static function get_term_author( $slug='' ){
1696 1696
 
1697
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1697
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1698 1698
 
1699
-        if( empty( $slug ) ){
1699
+		if( empty( $slug ) ){
1700 1700
 
1701
-            return $term_owner;
1701
+			return $term_owner;
1702 1702
 
1703
-        }
1703
+		}
1704 1704
 
1705
-        // look for the author in the slug
1706
-        $slug_parts = explode( '-', $slug );
1705
+		// look for the author in the slug
1706
+		$slug_parts = explode( '-', $slug );
1707 1707
 
1708
-        if( count( $slug_parts ) > 1 ){
1708
+		if( count( $slug_parts ) > 1 ){
1709 1709
 
1710
-            // get the user data
1711
-            $possible_user_id = $slug_parts[0];
1712
-            $author = get_userdata( $possible_user_id );
1710
+			// get the user data
1711
+			$possible_user_id = $slug_parts[0];
1712
+			$author = get_userdata( $possible_user_id );
1713 1713
 
1714
-            // if the user doesnt exist for the first part of the slug
1715
-            // then this slug was also created by admin
1716
-            if( is_a( $author, 'WP_User' ) ){
1714
+			// if the user doesnt exist for the first part of the slug
1715
+			// then this slug was also created by admin
1716
+			if( is_a( $author, 'WP_User' ) ){
1717 1717
 
1718
-                $term_owner =  $author;
1718
+				$term_owner =  $author;
1719 1719
 
1720
-            }
1721
-        }
1720
+			}
1721
+		}
1722 1722
 
1723
-        return $term_owner;
1724
-    }
1723
+		return $term_owner;
1724
+	}
1725 1725
 
1726
-    /**
1727
-     * Display the Sensei modules taxonomy terms metabox
1728
-     *
1729
-     * @since 1.8.0
1730
-     *
1731
-     * @hooked into add_meta_box
1732
-     *
1733
-     * @param WP_Post $post Post object.
1734
-     */
1735
-    public function course_module_metabox( $post ) {
1726
+	/**
1727
+	 * Display the Sensei modules taxonomy terms metabox
1728
+	 *
1729
+	 * @since 1.8.0
1730
+	 *
1731
+	 * @hooked into add_meta_box
1732
+	 *
1733
+	 * @param WP_Post $post Post object.
1734
+	 */
1735
+	public function course_module_metabox( $post ) {
1736 1736
 
1737
-        $tax_name = 'module';
1738
-        $taxonomy = get_taxonomy( 'module' );
1737
+		$tax_name = 'module';
1738
+		$taxonomy = get_taxonomy( 'module' );
1739 1739
 
1740
-        ?>
1740
+		?>
1741 1741
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1742 1742
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1743 1743
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1752,9 +1752,9 @@  discard block
 block discarded – undo
1752 1752
 
1753 1753
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1754 1754
                 <?php
1755
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1756
-                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1757
-                ?>
1755
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1756
+				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1757
+				?>
1758 1758
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1759 1759
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1760 1760
                 </ul>
@@ -1764,9 +1764,9 @@  discard block
 block discarded – undo
1764 1764
                     <h4>
1765 1765
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1766 1766
                             <?php
1767
-                            /* translators: %s: add new taxonomy label */
1768
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1769
-                            ?>
1767
+							/* translators: %s: add new taxonomy label */
1768
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1769
+							?>
1770 1770
                         </a>
1771 1771
                     </h4>
1772 1772
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1781,331 +1781,331 @@  discard block
 block discarded – undo
1781 1781
         </div>
1782 1782
     <?php
1783 1783
 
1784
-    } // end course_module_metabox
1784
+	} // end course_module_metabox
1785 1785
 
1786 1786
 
1787
-    /**
1788
-     * Submits a new module term prefixed with the
1789
-     * the current author id.
1790
-     *
1791
-     * @since 1.8.0
1792
-     */
1793
-    public static function add_new_module_term( ) {
1787
+	/**
1788
+	 * Submits a new module term prefixed with the
1789
+	 * the current author id.
1790
+	 *
1791
+	 * @since 1.8.0
1792
+	 */
1793
+	public static function add_new_module_term( ) {
1794 1794
 
1795 1795
 
1796
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1798
-        }
1796
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1798
+		}
1799 1799
 
1800
-        // get the term an create the new term storing infomration
1801
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1800
+		// get the term an create the new term storing infomration
1801
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1802 1802
 
1803
-        if( current_user_can('manage_options' ) ) {
1803
+		if( current_user_can('manage_options' ) ) {
1804 1804
 
1805
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1805
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1806 1806
 
1807
-        } else {
1807
+		} else {
1808 1808
 
1809
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1809
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1810 1810
 
1811
-        }
1811
+		}
1812 1812
 
1813
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1813
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1814 1814
 
1815
-        // save the term
1816
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1815
+		// save the term
1816
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1817 1817
 
1818
-        // send error for all errors except term exits
1819
-        if( is_wp_error( $slug ) ){
1818
+		// send error for all errors except term exits
1819
+		if( is_wp_error( $slug ) ){
1820 1820
 
1821
-            // prepare for possible term name and id to be passed down if term exists
1822
-            $term_data = array();
1821
+			// prepare for possible term name and id to be passed down if term exists
1822
+			$term_data = array();
1823 1823
 
1824
-            // if term exists also send back the term name and id
1825
-            if( isset( $slug->errors['term_exists'] ) ){
1824
+			// if term exists also send back the term name and id
1825
+			if( isset( $slug->errors['term_exists'] ) ){
1826 1826
 
1827
-                $term = get_term_by( 'slug', $term_slug, 'module');
1828
-                $term_data['name'] = $term_name;
1829
-                $term_data['id'] = $term->term_id;
1827
+				$term = get_term_by( 'slug', $term_slug, 'module');
1828
+				$term_data['name'] = $term_name;
1829
+				$term_data['id'] = $term->term_id;
1830 1830
 
1831
-                // set the object terms
1832
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1833
-            }
1831
+				// set the object terms
1832
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1833
+			}
1834 1834
 
1835
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1835
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1836 1836
 
1837
-        }
1837
+		}
1838 1838
 
1839
-        //make sure the new term is checked for this course
1839
+		//make sure the new term is checked for this course
1840 1840
 
1841
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1841
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1842 1842
 
1843
-        // Handle request then generate response using WP_Ajax_Response
1844
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1843
+		// Handle request then generate response using WP_Ajax_Response
1844
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1845 1845
 
1846
-    }
1846
+	}
1847 1847
 
1848
-    /**
1849
-     * Limit the course module metabox
1850
-     * term list to only those on courses belonging to current teacher.
1851
-     *
1852
-     * Hooked into 'get_terms'
1853
-     *
1854
-     * @since 1.8.0
1855
-     */
1856
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1848
+	/**
1849
+	 * Limit the course module metabox
1850
+	 * term list to only those on courses belonging to current teacher.
1851
+	 *
1852
+	 * Hooked into 'get_terms'
1853
+	 *
1854
+	 * @since 1.8.0
1855
+	 */
1856
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1857 1857
 
1858
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1859
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1860
-            return $terms;
1861
-        }
1858
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1859
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1860
+			return $terms;
1861
+		}
1862 1862
 
1863
-        // avoid infinite call loop
1864
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1863
+		// avoid infinite call loop
1864
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865 1865
 
1866
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1868
-            // change only scrub the terms ids form the array keys
1869
-            $terms = array_keys( $terms );
1870
-        }
1866
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1868
+			// change only scrub the terms ids form the array keys
1869
+			$terms = array_keys( $terms );
1870
+		}
1871 1871
 
1872
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1872
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1873 1873
 
1874
-        // add filter again as removed above
1875
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1874
+		// add filter again as removed above
1875
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1876 1876
 
1877
-        return $teachers_terms;
1878
-    }// end filter_module_terms
1877
+		return $teachers_terms;
1878
+	}// end filter_module_terms
1879 1879
 
1880
-    /**
1881
-     * For the selected items on a course module only return those
1882
-     * for the current user. This does not apply to admin and super admin users.
1883
-     *
1884
-     * hooked into get_object_terms
1885
-     *
1886
-     * @since 1.8.0
1887
-     */
1888
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1880
+	/**
1881
+	 * For the selected items on a course module only return those
1882
+	 * for the current user. This does not apply to admin and super admin users.
1883
+	 *
1884
+	 * hooked into get_object_terms
1885
+	 *
1886
+	 * @since 1.8.0
1887
+	 */
1888
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1889 1889
 
1890
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1891
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1892
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1893
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1894
-            return $terms;
1895
-        }
1890
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1891
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1892
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1893
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1894
+			return $terms;
1895
+		}
1896 1896
 
1897
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1897
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1898 1898
 
1899
-        // if term objects were passed in send back objects
1900
-        // if term id were passed in send that back
1901
-        if( is_object( $terms[0] ) ){
1902
-            return $term_objects;
1903
-        }
1899
+		// if term objects were passed in send back objects
1900
+		// if term id were passed in send that back
1901
+		if( is_object( $terms[0] ) ){
1902
+			return $term_objects;
1903
+		}
1904 1904
 
1905
-        $terms = array();
1906
-        foreach( $term_objects as $term_object ){
1907
-            $terms[] = $term_object->term_id;
1908
-        }
1905
+		$terms = array();
1906
+		foreach( $term_objects as $term_object ){
1907
+			$terms[] = $term_object->term_id;
1908
+		}
1909 1909
 
1910
-        return $terms;
1910
+		return $terms;
1911 1911
 
1912 1912
 
1913
-    }// end filter_course_selected_terms
1913
+	}// end filter_course_selected_terms
1914 1914
 
1915
-    /**
1916
-     * Filter the given terms and only return the
1917
-     * terms that belong to the given user id.
1918
-     *
1919
-     * @since 1.8.0
1920
-     * @param $terms
1921
-     * @param $user_id
1922
-     * @return array
1923
-     */
1924
-    public function filter_terms_by_owner( $terms, $user_id ){
1915
+	/**
1916
+	 * Filter the given terms and only return the
1917
+	 * terms that belong to the given user id.
1918
+	 *
1919
+	 * @since 1.8.0
1920
+	 * @param $terms
1921
+	 * @param $user_id
1922
+	 * @return array
1923
+	 */
1924
+	public function filter_terms_by_owner( $terms, $user_id ){
1925 1925
 
1926
-        $users_terms = array();
1926
+		$users_terms = array();
1927 1927
 
1928
-        foreach( $terms as $index => $term ){
1928
+		foreach( $terms as $index => $term ){
1929 1929
 
1930
-            if( is_numeric( $term ) ){
1931
-                // the term id was given, get the term object
1932
-                $term = get_term( $term, 'module' );
1933
-            }
1930
+			if( is_numeric( $term ) ){
1931
+				// the term id was given, get the term object
1932
+				$term = get_term( $term, 'module' );
1933
+			}
1934 1934
 
1935
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1935
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1936 1936
 
1937
-            if ( $user_id == $author->ID ) {
1938
-                // add the term to the teachers terms
1939
-                $users_terms[] = $term;
1940
-            }
1937
+			if ( $user_id == $author->ID ) {
1938
+				// add the term to the teachers terms
1939
+				$users_terms[] = $term;
1940
+			}
1941 1941
 
1942
-        }
1942
+		}
1943 1943
 
1944
-        return $users_terms;
1944
+		return $users_terms;
1945 1945
 
1946
-    } // end filter terms by owner
1946
+	} // end filter terms by owner
1947 1947
 
1948
-    /**
1949
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1950
-     * This will not add name to terms belonging to admin user.
1951
-     *
1952
-     * Hooked into 'get_terms'
1953
-     *
1954
-     * @since 1.8.0
1955
-     */
1956
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1957
-    {
1948
+	/**
1949
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1950
+	 * This will not add name to terms belonging to admin user.
1951
+	 *
1952
+	 * Hooked into 'get_terms'
1953
+	 *
1954
+	 * @since 1.8.0
1955
+	 */
1956
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1957
+	{
1958 1958
 
1959
-        // only for admin users ont he module taxonomy
1960
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1961
-            return $terms;
1962
-        }
1959
+		// only for admin users ont he module taxonomy
1960
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1961
+			return $terms;
1962
+		}
1963 1963
 
1964
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1965
-        // simply return this as wp doesn't need an array of stdObject Term
1966
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1964
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1965
+		// simply return this as wp doesn't need an array of stdObject Term
1966
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1967 1967
 
1968
-            return $terms;
1968
+			return $terms;
1969 1969
 
1970
-        }
1970
+		}
1971 1971
 
1972
-        // loop through and update all terms adding the author name
1973
-        foreach( $terms as $index => $term ){
1972
+		// loop through and update all terms adding the author name
1973
+		foreach( $terms as $index => $term ){
1974 1974
 
1975
-            if( is_numeric( $term ) ){
1976
-                // the term id was given, get the term object
1977
-                $term = get_term( $term, 'module' );
1978
-            }
1975
+			if( is_numeric( $term ) ){
1976
+				// the term id was given, get the term object
1977
+				$term = get_term( $term, 'module' );
1978
+			}
1979 1979
 
1980
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1980
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1981 1981
 
1982
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1984
-            }
1982
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1984
+			}
1985 1985
 
1986
-            // add the term to the teachers terms
1987
-            $users_terms[] = $term;
1986
+			// add the term to the teachers terms
1987
+			$users_terms[] = $term;
1988 1988
 
1989
-        }
1989
+		}
1990 1990
 
1991
-        return $users_terms;
1992
-    }
1991
+		return $users_terms;
1992
+	}
1993 1993
 
1994
-    /**
1995
-     * Remove modules metabox that come by default
1996
-     * with the modules taxonomy. We are removing this as
1997
-     * we have created our own custom meta box.
1998
-     */
1999
-    public static function remove_default_modules_box() {
1994
+	/**
1995
+	 * Remove modules metabox that come by default
1996
+	 * with the modules taxonomy. We are removing this as
1997
+	 * we have created our own custom meta box.
1998
+	 */
1999
+	public static function remove_default_modules_box() {
2000 2000
 
2001
-        remove_meta_box('modulediv', 'course', 'side');
2001
+		remove_meta_box('modulediv', 'course', 'side');
2002 2002
 
2003
-    }
2003
+	}
2004 2004
 
2005
-    /**
2006
-     * When a course is save make sure to reset the transient set
2007
-     * for it when determining the none module lessons.
2008
-     *
2009
-     * @sine 1.9.0
2010
-     * @param $post_id
2011
-     */
2012
-    public static function reset_none_modules_transient ( $post_id ){
2005
+	/**
2006
+	 * When a course is save make sure to reset the transient set
2007
+	 * for it when determining the none module lessons.
2008
+	 *
2009
+	 * @sine 1.9.0
2010
+	 * @param $post_id
2011
+	 */
2012
+	public static function reset_none_modules_transient ( $post_id ){
2013 2013
 
2014
-        // this should only apply to course and lesson post types
2015
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2014
+		// this should only apply to course and lesson post types
2015
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2016 2016
 
2017
-            $course_id = '';
2017
+			$course_id = '';
2018 2018
 
2019
-            if( 'lesson' == get_post_type( $post_id ) ){
2019
+			if( 'lesson' == get_post_type( $post_id ) ){
2020 2020
 
2021
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2021
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2022 2022
 
2023
-            }
2023
+			}
2024 2024
 
2025 2025
 
2026
-            if( !empty( $course_id ) ){
2026
+			if( !empty( $course_id ) ){
2027 2027
 
2028
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2028
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2029 2029
 
2030
-            }
2030
+			}
2031 2031
 
2032
-        } // end if is a course or a lesson
2032
+		} // end if is a course or a lesson
2033 2033
 
2034
-    } // end reset_none_modules_transient
2034
+	} // end reset_none_modules_transient
2035 2035
 
2036
-    /**
2037
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2038
-     *
2039
-     * @since 1.9.0
2040
-     * @deprecated since 1.9.0
2041
-     *
2042
-     */
2043
-    public static function deprecate_sensei_single_course_modules_content(){
2036
+	/**
2037
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2038
+	 *
2039
+	 * @since 1.9.0
2040
+	 * @deprecated since 1.9.0
2041
+	 *
2042
+	 */
2043
+	public static function deprecate_sensei_single_course_modules_content(){
2044 2044
 
2045
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2045
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2046 2046
 
2047
-    }
2047
+	}
2048 2048
 
2049
-    /**
2050
-     * Setup the single course module loop.
2051
-     *
2052
-     * Setup the global $sensei_modules_loop
2053
-     *
2054
-     * @since 1.9.0
2055
-     */
2056
-    public static function setup_single_course_module_loop(){
2049
+	/**
2050
+	 * Setup the single course module loop.
2051
+	 *
2052
+	 * Setup the global $sensei_modules_loop
2053
+	 *
2054
+	 * @since 1.9.0
2055
+	 */
2056
+	public static function setup_single_course_module_loop(){
2057 2057
 
2058
-        global $sensei_modules_loop, $post;
2059
-        $course_id = $post->ID;
2058
+		global $sensei_modules_loop, $post;
2059
+		$course_id = $post->ID;
2060 2060
 
2061
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2061
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2062 2062
 
2063
-        //initial setup
2064
-        $sensei_modules_loop['total'] = 0;
2065
-        $sensei_modules_loop['modules'] = array();
2066
-        $sensei_modules_loop['current'] = -1;
2063
+		//initial setup
2064
+		$sensei_modules_loop['total'] = 0;
2065
+		$sensei_modules_loop['modules'] = array();
2066
+		$sensei_modules_loop['current'] = -1;
2067 2067
 
2068
-        // exit if this course doesn't have modules
2069
-        if( !$modules || empty( $modules )  ){
2070
-            return;
2071
-        }
2068
+		// exit if this course doesn't have modules
2069
+		if( !$modules || empty( $modules )  ){
2070
+			return;
2071
+		}
2072 2072
 
2073 2073
 
2074
-        $lessons_in_all_modules = array();
2075
-        foreach( $modules as $term ){
2074
+		$lessons_in_all_modules = array();
2075
+		foreach( $modules as $term ){
2076 2076
 
2077
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2077
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2079 2079
 
2080
-        }
2080
+		}
2081 2081
 
2082 2082
 
2083
-        //setup all of the modules loop variables
2084
-        $sensei_modules_loop['total'] = count( $modules );
2085
-        $sensei_modules_loop['modules'] = $modules;
2086
-        $sensei_modules_loop['current'] = -1;
2087
-        $sensei_modules_loop['course_id'] = $course_id;
2083
+		//setup all of the modules loop variables
2084
+		$sensei_modules_loop['total'] = count( $modules );
2085
+		$sensei_modules_loop['modules'] = $modules;
2086
+		$sensei_modules_loop['current'] = -1;
2087
+		$sensei_modules_loop['course_id'] = $course_id;
2088 2088
 
2089
-    }// end setup_single_course_module_loop
2089
+	}// end setup_single_course_module_loop
2090 2090
 
2091
-    /**
2092
-     * Tear down the course module loop.
2093
-     *
2094
-     * @since 1.9.0
2095
-     *
2096
-     */
2097
-    public static function teardown_single_course_module_loop(){
2091
+	/**
2092
+	 * Tear down the course module loop.
2093
+	 *
2094
+	 * @since 1.9.0
2095
+	 *
2096
+	 */
2097
+	public static function teardown_single_course_module_loop(){
2098 2098
 
2099
-        global $sensei_modules_loop, $wp_query, $post;
2099
+		global $sensei_modules_loop, $wp_query, $post;
2100 2100
 
2101
-        //reset all of the modules loop variables
2102
-        $sensei_modules_loop['total'] = 0;
2103
-        $sensei_modules_loop['modules'] = array();
2104
-        $sensei_modules_loop['current'] = -1;
2101
+		//reset all of the modules loop variables
2102
+		$sensei_modules_loop['total'] = 0;
2103
+		$sensei_modules_loop['modules'] = array();
2104
+		$sensei_modules_loop['current'] = -1;
2105 2105
 
2106
-        // set the current course to be the global post again
2107
-        wp_reset_query();
2108
-        $post = $wp_query->post;
2109
-    }// end teardown_single_course_module_loop
2106
+		// set the current course to be the global post again
2107
+		wp_reset_query();
2108
+		$post = $wp_query->post;
2109
+	}// end teardown_single_course_module_loop
2110 2110
 
2111 2111
 } // end modules class
Please login to merge, or discard this patch.
Spacing   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 62
         // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
63
+        add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10);
64
+        add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10);
65
+        add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20);
66 66
 
67 67
         // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
68
+        add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+        add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+        add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+        add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
72 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 82
         // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 85
         //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 97
         // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
98
+        add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+        add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 102
         //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 105
         // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
106
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
107
+        add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3);
108 108
 
109 109
         // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 153
             // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 158
             // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 194
             // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
195
+            $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />';
196 196
             if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 199
                 foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 203
             } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
204
+                $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit');
205
+                $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>';
206 206
             } // End If Statement
207 207
 
208 208
         } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
209
+            $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>';
210 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 227
         // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
228
+        if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce'])
229
+            ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) {
230 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 257
             // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 483
                 $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 492
                 $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 733
         $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 818
         //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 822
         $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 845
             if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
846
+                $html .= '<div class="updated fade">'."\n";
847
+                $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n";
848
+                $html .= '</div>'."\n";
849 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 853
 
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
854
+        $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
855
+        $html .= '<input type="hidden" name="post_type" value="course" />'."\n";
856
+        $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n";
857
+        $html .= '<select id="module-order-course" name="course_id">'."\n";
858
+        $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
859 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 869
 
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
870
+        $html .= '</select>'."\n";
871
+        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
872
+        $html .= '</form>'."\n";
873 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 906
 
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
907
+                    $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n";
908
+                    $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
909
+                    $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n";
910
+                    $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n";
911 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 946
             if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
947
+                echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>';
948 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 1038
                 $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 1092
                 foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1093
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1094 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 1136
                 foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1137
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1138 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,9 +1169,9 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if(    empty( $modules )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1172
+        if (empty($modules)
1173
+            || is_wp_error($modules)
1174
+            || isset($modules['errors'])) {
1175 1175
 
1176 1176
             return false;
1177 1177
 
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
        // get the last item in the array there should be only be 1 really.
1181 1181
        // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1182
+       foreach ($modules as $module) {
1183 1183
            break;
1184 1184
        }
1185 1185
 
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
         if (isset($course_id) && 0 < $course_id) {
1193 1193
 
1194 1194
             // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1195
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1196 1196
                 return false;
1197 1197
             }
1198 1198
 
@@ -1213,12 +1213,12 @@  discard block
 block discarded – undo
1213 1213
 	public function get_course_modules($course_id = 0) {
1214 1214
 
1215 1215
 		$course_id = intval($course_id);
1216
-		if ( empty(  $course_id ) ) {
1216
+		if (empty($course_id)) {
1217 1217
 			return array();
1218 1218
 		}
1219 1219
 
1220 1220
 		// Get modules for course
1221
-		$modules = wp_get_post_terms( $course_id, $this->taxonomy );
1221
+		$modules = wp_get_post_terms($course_id, $this->taxonomy);
1222 1222
 
1223 1223
 		// Get custom module order for course
1224 1224
 		$order = $this->get_course_module_order($course_id);
@@ -1230,7 +1230,7 @@  discard block
 block discarded – undo
1230 1230
 		// Sort by custom order
1231 1231
 		$ordered_modules = array();
1232 1232
 		$unordered_modules = array();
1233
-		foreach ( $modules as $module ) {
1233
+		foreach ($modules as $module) {
1234 1234
 			$order_key = array_search($module->term_id, $order);
1235 1235
 			if ($order_key !== false) {
1236 1236
 				$ordered_modules[$order_key] = $module;
@@ -1240,16 +1240,16 @@  discard block
 block discarded – undo
1240 1240
 		}
1241 1241
 
1242 1242
 		// Order modules correctly
1243
-		ksort( $ordered_modules );
1243
+		ksort($ordered_modules);
1244 1244
 
1245 1245
 		// Append modules that have not yet been ordered
1246
-		if ( count($unordered_modules) > 0 ) {
1246
+		if (count($unordered_modules) > 0) {
1247 1247
 			$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1248 1248
 		}
1249 1249
 
1250 1250
 		// remove order key but maintain order
1251 1251
 		$ordered_modules_with_keys_in_sequence = array();
1252
-		foreach ( $ordered_modules as $key => $module ) {
1252
+		foreach ($ordered_modules as $key => $module) {
1253 1253
 
1254 1254
 			$ordered_modules_with_keys_in_sequence[] = $module;
1255 1255
 
@@ -1280,37 +1280,37 @@  discard block
 block discarded – undo
1280 1280
      *
1281 1281
      * @return void
1282 1282
      */
1283
-    public function admin_enqueue_scripts( $hook ) {
1283
+    public function admin_enqueue_scripts($hook) {
1284 1284
 
1285 1285
         /**
1286 1286
          * Filter the page hooks where modules admin script can be loaded on.
1287 1287
          *
1288 1288
          * @param array $white_listed_pages
1289 1289
          */
1290
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1290
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1291 1291
             'edit-tags.php',
1292 1292
             'course_page_module-order',
1293 1293
             'post-new.php',
1294 1294
             'post.php'
1295
-        ) );
1295
+        ));
1296 1296
 
1297
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1297
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1298 1298
             return;
1299 1299
         }
1300 1300
 
1301
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1301
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1302 1302
 
1303
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1303
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1304
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1305
+        wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2'), Sensei()->version, true);
1306 1306
 
1307 1307
         // localized module data
1308 1308
         $localize_modulesAdmin = array(
1309
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1309
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1310
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1311 1311
         );
1312 1312
 
1313
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1313
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1314 1314
     }
1315 1315
 
1316 1316
     /**
@@ -1322,8 +1322,8 @@  discard block
 block discarded – undo
1322 1322
      */
1323 1323
     public function admin_enqueue_styles() {
1324 1324
 
1325
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
-        wp_enqueue_style($this->taxonomy . '-sortable');
1325
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1326
+        wp_enqueue_style($this->taxonomy.'-sortable');
1327 1327
 
1328 1328
     }
1329 1329
 
@@ -1337,9 +1337,9 @@  discard block
 block discarded – undo
1337 1337
      */
1338 1338
     public function course_modules_title( ) {
1339 1339
 
1340
-       if( sensei_module_has_lessons() ){
1340
+       if (sensei_module_has_lessons()) {
1341 1341
 
1342
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1342
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1343 1343
 
1344 1344
         }
1345 1345
 
@@ -1352,22 +1352,22 @@  discard block
 block discarded – undo
1352 1352
      * @since 1.8.0
1353 1353
      * @return void
1354 1354
      */
1355
-    public function load_course_module_content_template(){
1355
+    public function load_course_module_content_template() {
1356 1356
 
1357
-	    if ( ! is_singular( 'course' )  ) {
1357
+	    if ( ! is_singular('course')) {
1358 1358
 		    return;
1359 1359
 	    }
1360 1360
 
1361 1361
         // load backwards compatible template name if it exists in the users theme
1362
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
-        if( $located_template ){
1362
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1363
+        if ($located_template) {
1364 1364
 
1365
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1365
+            Sensei_Templates::get_template('single-course/course-modules.php');
1366 1366
             return;
1367 1367
 
1368 1368
         }
1369 1369
 
1370
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1370
+        Sensei_Templates::get_template('single-course/modules.php');
1371 1371
 
1372 1372
     } // end course_module_content
1373 1373
 
@@ -1380,15 +1380,15 @@  discard block
 block discarded – undo
1380 1380
      * @param $term_id
1381 1381
      * @return array $lessons
1382 1382
      */
1383
-    public function get_lessons( $course_id , $term_id ){
1383
+    public function get_lessons($course_id, $term_id) {
1384 1384
 
1385
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1385
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1386 1386
 
1387
-        if( isset( $lesson_query->posts ) ){
1387
+        if (isset($lesson_query->posts)) {
1388 1388
 
1389 1389
             return $lesson_query->posts;
1390 1390
 
1391
-        }else{
1391
+        } else {
1392 1392
 
1393 1393
             return array();
1394 1394
 
@@ -1405,9 +1405,9 @@  discard block
 block discarded – undo
1405 1405
      * @param $term_id
1406 1406
      * @return WP_Query $lessons_query
1407 1407
      */
1408
-    public function get_lessons_query( $course_id , $term_id ){
1408
+    public function get_lessons_query($course_id, $term_id) {
1409 1409
 
1410
-        if( empty( $term_id ) || empty( $course_id ) ){
1410
+        if (empty($term_id) || empty($course_id)) {
1411 1411
 
1412 1412
             return array();
1413 1413
 
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
                 array(
1429 1429
                     'taxonomy' => 'module',
1430 1430
                     'field' => 'id',
1431
-                    'terms' => intval( $term_id )
1431
+                    'terms' => intval($term_id)
1432 1432
                 )
1433 1433
             ),
1434 1434
             'orderby' => 'menu_order',
@@ -1436,12 +1436,12 @@  discard block
 block discarded – undo
1436 1436
             'suppress_filters' => 0
1437 1437
         );
1438 1438
 
1439
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1439
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1440
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1441 1441
             $args['orderby'] = 'meta_value_num date';
1442 1442
         }
1443 1443
 
1444
-        $lessons_query = new WP_Query( $args );
1444
+        $lessons_query = new WP_Query($args);
1445 1445
 
1446 1446
         return $lessons_query;
1447 1447
 
@@ -1456,37 +1456,37 @@  discard block
 block discarded – undo
1456 1456
      *
1457 1457
      * @return array $non_module_lessons
1458 1458
      */
1459
-    public function get_none_module_lessons( $course_id ){
1459
+    public function get_none_module_lessons($course_id) {
1460 1460
 
1461 1461
         $non_module_lessons = array();
1462 1462
 
1463 1463
         //exit if there is no course id passed in
1464
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1464
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1465 1465
 
1466 1466
             return $non_module_lessons;
1467 1467
         }
1468 1468
 
1469 1469
         //save some time and check if we already have the saved
1470
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1470
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1471 1471
 
1472
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1472
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         // create terms array which must be excluded from other arrays
1477
-        $course_modules = $this->get_course_modules( $course_id );
1477
+        $course_modules = $this->get_course_modules($course_id);
1478 1478
 
1479 1479
         //exit if there are no module on this course
1480
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1480
+        if (empty($course_modules) || ! is_array($course_modules)) {
1481 1481
 
1482
-            return  Sensei()->course->course_lessons( $course_id );
1482
+            return  Sensei()->course->course_lessons($course_id);
1483 1483
 
1484 1484
         }
1485 1485
 
1486 1486
         $terms = array();
1487
-        foreach( $course_modules as $module ){
1487
+        foreach ($course_modules as $module) {
1488 1488
 
1489
-            array_push( $terms ,  $module->term_id );
1489
+            array_push($terms, $module->term_id);
1490 1490
 
1491 1491
         }
1492 1492
 
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
             'meta_query' => array(
1498 1498
                 array(
1499 1499
                     'key' => '_lesson_course',
1500
-                    'value' => intval( $course_id ),
1500
+                    'value' => intval($course_id),
1501 1501
                     'compare' => '='
1502 1502
                 )
1503 1503
             ),
@@ -1514,11 +1514,11 @@  discard block
 block discarded – undo
1514 1514
             'suppress_filters' => 0
1515 1515
         );
1516 1516
 
1517
-        $wp_lessons_query = new WP_Query( $args );
1517
+        $wp_lessons_query = new WP_Query($args);
1518 1518
 
1519
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1519
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1520 1520
             $non_module_lessons = $wp_lessons_query->get_posts();
1521
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1521
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1522 1522
         }
1523 1523
 
1524 1524
         return $non_module_lessons;
@@ -1529,7 +1529,7 @@  discard block
 block discarded – undo
1529 1529
      *
1530 1530
      * @since 1.8.0
1531 1531
      */
1532
-    public function setup_modules_taxonomy(){
1532
+    public function setup_modules_taxonomy() {
1533 1533
 
1534 1534
         $labels = array(
1535 1535
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1566,11 +1566,11 @@  discard block
 block discarded – undo
1566 1566
             'show_in_nav_menus' => false,
1567 1567
             'show_in_quick_edit' => false,
1568 1568
             'show_ui' => true,
1569
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1569
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1570 1570
             'labels' => $labels
1571 1571
         );
1572 1572
 
1573
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1573
+        register_taxonomy('module', array('course', 'lesson'), $args);
1574 1574
 
1575 1575
     }// end setup_modules_taxonomy
1576 1576
 
@@ -1582,12 +1582,12 @@  discard block
 block discarded – undo
1582 1582
      * @since 1.8.0
1583 1583
      * @return void
1584 1584
      */
1585
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1585
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1586 1586
 
1587
-        global $typenow , $taxnow;
1587
+        global $typenow, $taxnow;
1588 1588
 
1589
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1589
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1590
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1591 1591
         }
1592 1592
 
1593 1593
     }// end redirect to course taxonomy
@@ -1600,18 +1600,18 @@  discard block
 block discarded – undo
1600 1600
      * @since 1.8.0
1601 1601
      * @return void
1602 1602
      */
1603
-    public function remove_lessons_menu_model_taxonomy(){
1603
+    public function remove_lessons_menu_model_taxonomy() {
1604 1604
         global $submenu;
1605 1605
 
1606
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1606
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1607 1607
             return; // exit
1608 1608
         }
1609 1609
 
1610 1610
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
-        foreach( $lesson_main_menu as $index => $sub_item ){
1611
+        foreach ($lesson_main_menu as $index => $sub_item) {
1612 1612
 
1613
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1613
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1614
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1615 1615
             }
1616 1616
         }
1617 1617
 
@@ -1625,18 +1625,18 @@  discard block
 block discarded – undo
1625 1625
      * @since 1.8.0
1626 1626
      * @return void
1627 1627
      */
1628
-    public function remove_courses_menu_model_taxonomy(){
1628
+    public function remove_courses_menu_model_taxonomy() {
1629 1629
         global $submenu;
1630 1630
 
1631
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1631
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1632 1632
             return; // exit
1633 1633
         }
1634 1634
 
1635 1635
         $course_main_menu = $submenu['edit.php?post_type=course'];
1636
-        foreach( $course_main_menu as $index => $sub_item ){
1636
+        foreach ($course_main_menu as $index => $sub_item) {
1637 1637
 
1638
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1638
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1639
+                unset($submenu['edit.php?post_type=course'][$index]);
1640 1640
             }
1641 1641
         }
1642 1642
 
@@ -1652,12 +1652,12 @@  discard block
 block discarded – undo
1652 1652
      * @param string $term_name
1653 1653
      * @return array $owners { type WP_User }. Empty array if none if found.
1654 1654
      */
1655
-    public static function get_term_authors( $term_name ){
1655
+    public static function get_term_authors($term_name) {
1656 1656
 
1657
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1657
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1658 1658
 
1659 1659
         $owners = array();
1660
-        if( empty( $terms ) ){
1660
+        if (empty($terms)) {
1661 1661
 
1662 1662
             return $owners;
1663 1663
 
@@ -1667,11 +1667,11 @@  discard block
 block discarded – undo
1667 1667
 
1668 1668
 
1669 1669
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
-        foreach( $terms as $term){
1671
-            if( $term->name == $term_name ){
1670
+        foreach ($terms as $term) {
1671
+            if ($term->name == $term_name) {
1672 1672
 
1673 1673
                 // look for the author in the slug
1674
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1674
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1675 1675
 
1676 1676
             }// end if term name
1677 1677
 
@@ -1692,30 +1692,30 @@  discard block
 block discarded – undo
1692 1692
      * @param $slug
1693 1693
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694 1694
      */
1695
-    public static function get_term_author( $slug='' ){
1695
+    public static function get_term_author($slug = '') {
1696 1696
 
1697
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1697
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1698 1698
 
1699
-        if( empty( $slug ) ){
1699
+        if (empty($slug)) {
1700 1700
 
1701 1701
             return $term_owner;
1702 1702
 
1703 1703
         }
1704 1704
 
1705 1705
         // look for the author in the slug
1706
-        $slug_parts = explode( '-', $slug );
1706
+        $slug_parts = explode('-', $slug);
1707 1707
 
1708
-        if( count( $slug_parts ) > 1 ){
1708
+        if (count($slug_parts) > 1) {
1709 1709
 
1710 1710
             // get the user data
1711 1711
             $possible_user_id = $slug_parts[0];
1712
-            $author = get_userdata( $possible_user_id );
1712
+            $author = get_userdata($possible_user_id);
1713 1713
 
1714 1714
             // if the user doesnt exist for the first part of the slug
1715 1715
             // then this slug was also created by admin
1716
-            if( is_a( $author, 'WP_User' ) ){
1716
+            if (is_a($author, 'WP_User')) {
1717 1717
 
1718
-                $term_owner =  $author;
1718
+                $term_owner = $author;
1719 1719
 
1720 1720
             }
1721 1721
         }
@@ -1732,48 +1732,48 @@  discard block
 block discarded – undo
1732 1732
      *
1733 1733
      * @param WP_Post $post Post object.
1734 1734
      */
1735
-    public function course_module_metabox( $post ) {
1735
+    public function course_module_metabox($post) {
1736 1736
 
1737 1737
         $tax_name = 'module';
1738
-        $taxonomy = get_taxonomy( 'module' );
1738
+        $taxonomy = get_taxonomy('module');
1739 1739
 
1740 1740
         ?>
1741 1741
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1742 1742
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1743 1743
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1744
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1744
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1745 1745
             </ul>
1746 1746
 
1747 1747
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1749
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1749
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752 1752
 
1753 1753
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1754 1754
                 <?php
1755
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1755
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1756 1756
                 echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1757 1757
                 ?>
1758 1758
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1759
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1759
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1760 1760
                 </ul>
1761 1761
             </div>
1762
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1762
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1763 1763
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1764 1764
                     <h4>
1765 1765
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1766 1766
                             <?php
1767 1767
                             /* translators: %s: add new taxonomy label */
1768
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1768
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1769 1769
                             ?>
1770 1770
                         </a>
1771 1771
                     </h4>
1772 1772
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1773 1773
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1774
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1775
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1776
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1774
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1775
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1776
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1777 1777
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1778 1778
                     </p>
1779 1779
                 </div>
@@ -1793,55 +1793,55 @@  discard block
 block discarded – undo
1793 1793
     public static function add_new_module_term( ) {
1794 1794
 
1795 1795
 
1796
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1796
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1797
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1798 1798
         }
1799 1799
 
1800 1800
         // get the term an create the new term storing infomration
1801
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1801
+        $term_name = sanitize_text_field($_POST['newTerm']);
1802 1802
 
1803
-        if( current_user_can('manage_options' ) ) {
1803
+        if (current_user_can('manage_options')) {
1804 1804
 
1805
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1805
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1806 1806
 
1807 1807
         } else {
1808 1808
 
1809
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1809
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1810 1810
 
1811 1811
         }
1812 1812
 
1813
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1813
+        $course_id = sanitize_text_field($_POST['course_id']);
1814 1814
 
1815 1815
         // save the term
1816
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1816
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1817 1817
 
1818 1818
         // send error for all errors except term exits
1819
-        if( is_wp_error( $slug ) ){
1819
+        if (is_wp_error($slug)) {
1820 1820
 
1821 1821
             // prepare for possible term name and id to be passed down if term exists
1822 1822
             $term_data = array();
1823 1823
 
1824 1824
             // if term exists also send back the term name and id
1825
-            if( isset( $slug->errors['term_exists'] ) ){
1825
+            if (isset($slug->errors['term_exists'])) {
1826 1826
 
1827
-                $term = get_term_by( 'slug', $term_slug, 'module');
1827
+                $term = get_term_by('slug', $term_slug, 'module');
1828 1828
                 $term_data['name'] = $term_name;
1829 1829
                 $term_data['id'] = $term->term_id;
1830 1830
 
1831 1831
                 // set the object terms
1832
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1832
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1833 1833
             }
1834 1834
 
1835
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1835
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1836 1836
 
1837 1837
         }
1838 1838
 
1839 1839
         //make sure the new term is checked for this course
1840 1840
 
1841
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1841
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1842 1842
 
1843 1843
         // Handle request then generate response using WP_Ajax_Response
1844
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1844
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1845 1845
 
1846 1846
     }
1847 1847
 
@@ -1853,26 +1853,26 @@  discard block
 block discarded – undo
1853 1853
      *
1854 1854
      * @since 1.8.0
1855 1855
      */
1856
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1856
+    public function filter_module_terms($terms, $taxonomies, $args) {
1857 1857
 
1858 1858
         //dont limit for admins and other taxonomies. This should also only apply to admin
1859
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1859
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1860 1860
             return $terms;
1861 1861
         }
1862 1862
 
1863 1863
         // avoid infinite call loop
1864
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1865 1865
 
1866 1866
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1867
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1868 1868
             // change only scrub the terms ids form the array keys
1869
-            $terms = array_keys( $terms );
1869
+            $terms = array_keys($terms);
1870 1870
         }
1871 1871
 
1872
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1872
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1873 1873
 
1874 1874
         // add filter again as removed above
1875
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1875
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1876 1876
 
1877 1877
         return $teachers_terms;
1878 1878
     }// end filter_module_terms
@@ -1885,25 +1885,25 @@  discard block
 block discarded – undo
1885 1885
      *
1886 1886
      * @since 1.8.0
1887 1887
      */
1888
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1888
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1889 1889
 
1890 1890
         //dont limit for admins and other taxonomies. This should also only apply to admin
1891
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1891
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1892 1892
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1893
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1893
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1894 1894
             return $terms;
1895 1895
         }
1896 1896
 
1897
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1897
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1898 1898
 
1899 1899
         // if term objects were passed in send back objects
1900 1900
         // if term id were passed in send that back
1901
-        if( is_object( $terms[0] ) ){
1901
+        if (is_object($terms[0])) {
1902 1902
             return $term_objects;
1903 1903
         }
1904 1904
 
1905 1905
         $terms = array();
1906
-        foreach( $term_objects as $term_object ){
1906
+        foreach ($term_objects as $term_object) {
1907 1907
             $terms[] = $term_object->term_id;
1908 1908
         }
1909 1909
 
@@ -1921,20 +1921,20 @@  discard block
 block discarded – undo
1921 1921
      * @param $user_id
1922 1922
      * @return array
1923 1923
      */
1924
-    public function filter_terms_by_owner( $terms, $user_id ){
1924
+    public function filter_terms_by_owner($terms, $user_id) {
1925 1925
 
1926 1926
         $users_terms = array();
1927 1927
 
1928
-        foreach( $terms as $index => $term ){
1928
+        foreach ($terms as $index => $term) {
1929 1929
 
1930
-            if( is_numeric( $term ) ){
1930
+            if (is_numeric($term)) {
1931 1931
                 // the term id was given, get the term object
1932
-                $term = get_term( $term, 'module' );
1932
+                $term = get_term($term, 'module');
1933 1933
             }
1934 1934
 
1935
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1935
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1936 1936
 
1937
-            if ( $user_id == $author->ID ) {
1937
+            if ($user_id == $author->ID) {
1938 1938
                 // add the term to the teachers terms
1939 1939
                 $users_terms[] = $term;
1940 1940
             }
@@ -1953,34 +1953,34 @@  discard block
 block discarded – undo
1953 1953
      *
1954 1954
      * @since 1.8.0
1955 1955
      */
1956
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1956
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1957 1957
     {
1958 1958
 
1959 1959
         // only for admin users ont he module taxonomy
1960
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1960
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1961 1961
             return $terms;
1962 1962
         }
1963 1963
 
1964 1964
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1965 1965
         // simply return this as wp doesn't need an array of stdObject Term
1966
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1966
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1967 1967
 
1968 1968
             return $terms;
1969 1969
 
1970 1970
         }
1971 1971
 
1972 1972
         // loop through and update all terms adding the author name
1973
-        foreach( $terms as $index => $term ){
1973
+        foreach ($terms as $index => $term) {
1974 1974
 
1975
-            if( is_numeric( $term ) ){
1975
+            if (is_numeric($term)) {
1976 1976
                 // the term id was given, get the term object
1977
-                $term = get_term( $term, 'module' );
1977
+                $term = get_term($term, 'module');
1978 1978
             }
1979 1979
 
1980
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1980
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1981 1981
 
1982
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1982
+            if ( ! user_can($author, 'manage_options') && isset($term->name)) {
1983
+                $term->name = $term->name.' ('.$author->display_name.') ';
1984 1984
             }
1985 1985
 
1986 1986
             // add the term to the teachers terms
@@ -2009,23 +2009,23 @@  discard block
 block discarded – undo
2009 2009
      * @sine 1.9.0
2010 2010
      * @param $post_id
2011 2011
      */
2012
-    public static function reset_none_modules_transient ( $post_id ){
2012
+    public static function reset_none_modules_transient($post_id) {
2013 2013
 
2014 2014
         // this should only apply to course and lesson post types
2015
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2015
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2016 2016
 
2017 2017
             $course_id = '';
2018 2018
 
2019
-            if( 'lesson' == get_post_type( $post_id ) ){
2019
+            if ('lesson' == get_post_type($post_id)) {
2020 2020
 
2021
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2021
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2022 2022
 
2023 2023
             }
2024 2024
 
2025 2025
 
2026
-            if( !empty( $course_id ) ){
2026
+            if ( ! empty($course_id)) {
2027 2027
 
2028
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2028
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2029 2029
 
2030 2030
             }
2031 2031
 
@@ -2040,9 +2040,9 @@  discard block
 block discarded – undo
2040 2040
      * @deprecated since 1.9.0
2041 2041
      *
2042 2042
      */
2043
-    public static function deprecate_sensei_single_course_modules_content(){
2043
+    public static function deprecate_sensei_single_course_modules_content() {
2044 2044
 
2045
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2045
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2046 2046
 
2047 2047
     }
2048 2048
 
@@ -2053,12 +2053,12 @@  discard block
 block discarded – undo
2053 2053
      *
2054 2054
      * @since 1.9.0
2055 2055
      */
2056
-    public static function setup_single_course_module_loop(){
2056
+    public static function setup_single_course_module_loop() {
2057 2057
 
2058 2058
         global $sensei_modules_loop, $post;
2059 2059
         $course_id = $post->ID;
2060 2060
 
2061
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2061
+        $modules = Sensei()->modules->get_course_modules($course_id);
2062 2062
 
2063 2063
         //initial setup
2064 2064
         $sensei_modules_loop['total'] = 0;
@@ -2066,22 +2066,22 @@  discard block
 block discarded – undo
2066 2066
         $sensei_modules_loop['current'] = -1;
2067 2067
 
2068 2068
         // exit if this course doesn't have modules
2069
-        if( !$modules || empty( $modules )  ){
2069
+        if ( ! $modules || empty($modules)) {
2070 2070
             return;
2071 2071
         }
2072 2072
 
2073 2073
 
2074 2074
         $lessons_in_all_modules = array();
2075
-        foreach( $modules as $term ){
2075
+        foreach ($modules as $term) {
2076 2076
 
2077
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2077
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2078
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2079 2079
 
2080 2080
         }
2081 2081
 
2082 2082
 
2083 2083
         //setup all of the modules loop variables
2084
-        $sensei_modules_loop['total'] = count( $modules );
2084
+        $sensei_modules_loop['total'] = count($modules);
2085 2085
         $sensei_modules_loop['modules'] = $modules;
2086 2086
         $sensei_modules_loop['current'] = -1;
2087 2087
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2094,7 +2094,7 @@  discard block
 block discarded – undo
2094 2094
      * @since 1.9.0
2095 2095
      *
2096 2096
      */
2097
-    public static function teardown_single_course_module_loop(){
2097
+    public static function teardown_single_course_module_loop() {
2098 2098
 
2099 2099
         global $sensei_modules_loop, $wp_query, $post;
2100 2100
 
Please login to merge, or discard this patch.
includes/theme-integrations/theme-integration-loader.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -14,99 +14,99 @@
 block discarded – undo
14 14
  */
15 15
 class Sensei_Theme_Integration_Loader {
16 16
 
17
-    /**
18
-     * @var array
19
-     * Holding a reference core supported themes
20
-     */
21
-    protected $themes;
22
-
23
-    /**
24
-     * @var string
25
-     * reference to the theme currently active on this site
26
-     */
27
-    protected $active_theme;
28
-
29
-    public function __construct() {
30
-
31
-        $this->setup_themes();
32
-        $this->setup_currently_active_theme();
33
-        $this->possibly_load_supported_theme_wrappers();
34
-
35
-    }
36
-
37
-    /**
38
-     * Setup the theme slugs supported by Sensei Core
39
-     *
40
-     * @since 1.9.0
41
-     */
42
-    private function setup_themes(){
43
-
44
-        $this->themes = array(
45
-            'twentyeleven',
46
-            'twentytwelve',
47
-            'twentythirteen',
48
-            'twentyfourteen',
49
-            'twentyfifteen',
50
-            'twentysixteen',
51
-            'storefront',
52
-        );
53
-
54
-    }// end setup themes
55
-
56
-    /**
57
-     * Setup the currently active theme
58
-     *
59
-     * @since 1.9.0
60
-     */
61
-    private function setup_currently_active_theme(){
62
-
63
-        $this->active_theme = get_option('template');
64
-
65
-    }
66
-
67
-    /**
68
-     * Remove default Sensei wrappers and load
69
-     * supported wrappers if the current theme is
70
-     * a theme we have an integration for within core.
71
-     *
72
-     * @since 1.9.0
73
-     */
74
-    private function possibly_load_supported_theme_wrappers(){
75
-
76
-        if ( in_array( $this->active_theme, $this->themes ) ){
77
-
78
-            // setup file and class names
79
-            $supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
80
-            $supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
81
-
82
-            // add name of theme as body class for detailed styling.
83
-            add_filter( 'body_class', 'sensei_current_theme' );
84
-            function sensei_current_theme( $classes ) {
85
-                $sensei_template = get_option( 'template' );
86
-                $classes[] = 'sensei-'. $sensei_template;
87
-                return $classes;
88
-            }
89
-
90
-            // load the file or exit if there is no file for this theme
91
-            if( ! file_exists( $supported_theme_class_file ) ){
92
-                return;
93
-            }
94
-            include_once( $supported_theme_class_file );
95
-            include_once( 'twentytwelve.php' );
96
-            //initialize the class or exit if there is no class for this theme
97
-            if( ! class_exists( $supported_theme_class_name ) ){
98
-                return;
99
-            }
100
-            $supported_theme = new $supported_theme_class_name;
101
-
102
-            // remove default wrappers
103
-            remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
104
-            remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
105
-
106
-            // load the supported theme wrappers
107
-            add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
108
-            add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
109
-        }
110
-    }
17
+	/**
18
+	 * @var array
19
+	 * Holding a reference core supported themes
20
+	 */
21
+	protected $themes;
22
+
23
+	/**
24
+	 * @var string
25
+	 * reference to the theme currently active on this site
26
+	 */
27
+	protected $active_theme;
28
+
29
+	public function __construct() {
30
+
31
+		$this->setup_themes();
32
+		$this->setup_currently_active_theme();
33
+		$this->possibly_load_supported_theme_wrappers();
34
+
35
+	}
36
+
37
+	/**
38
+	 * Setup the theme slugs supported by Sensei Core
39
+	 *
40
+	 * @since 1.9.0
41
+	 */
42
+	private function setup_themes(){
43
+
44
+		$this->themes = array(
45
+			'twentyeleven',
46
+			'twentytwelve',
47
+			'twentythirteen',
48
+			'twentyfourteen',
49
+			'twentyfifteen',
50
+			'twentysixteen',
51
+			'storefront',
52
+		);
53
+
54
+	}// end setup themes
55
+
56
+	/**
57
+	 * Setup the currently active theme
58
+	 *
59
+	 * @since 1.9.0
60
+	 */
61
+	private function setup_currently_active_theme(){
62
+
63
+		$this->active_theme = get_option('template');
64
+
65
+	}
66
+
67
+	/**
68
+	 * Remove default Sensei wrappers and load
69
+	 * supported wrappers if the current theme is
70
+	 * a theme we have an integration for within core.
71
+	 *
72
+	 * @since 1.9.0
73
+	 */
74
+	private function possibly_load_supported_theme_wrappers(){
75
+
76
+		if ( in_array( $this->active_theme, $this->themes ) ){
77
+
78
+			// setup file and class names
79
+			$supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
80
+			$supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
81
+
82
+			// add name of theme as body class for detailed styling.
83
+			add_filter( 'body_class', 'sensei_current_theme' );
84
+			function sensei_current_theme( $classes ) {
85
+				$sensei_template = get_option( 'template' );
86
+				$classes[] = 'sensei-'. $sensei_template;
87
+				return $classes;
88
+			}
89
+
90
+			// load the file or exit if there is no file for this theme
91
+			if( ! file_exists( $supported_theme_class_file ) ){
92
+				return;
93
+			}
94
+			include_once( $supported_theme_class_file );
95
+			include_once( 'twentytwelve.php' );
96
+			//initialize the class or exit if there is no class for this theme
97
+			if( ! class_exists( $supported_theme_class_name ) ){
98
+				return;
99
+			}
100
+			$supported_theme = new $supported_theme_class_name;
101
+
102
+			// remove default wrappers
103
+			remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
104
+			remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
105
+
106
+			// load the supported theme wrappers
107
+			add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
108
+			add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
109
+		}
110
+	}
111 111
 
112 112
 } /// end class
113 113
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      *
40 40
      * @since 1.9.0
41 41
      */
42
-    private function setup_themes(){
42
+    private function setup_themes() {
43 43
 
44 44
         $this->themes = array(
45 45
             'twentyeleven',
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @since 1.9.0
60 60
      */
61
-    private function setup_currently_active_theme(){
61
+    private function setup_currently_active_theme() {
62 62
 
63 63
         $this->active_theme = get_option('template');
64 64
 
@@ -71,41 +71,41 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @since 1.9.0
73 73
      */
74
-    private function possibly_load_supported_theme_wrappers(){
74
+    private function possibly_load_supported_theme_wrappers() {
75 75
 
76
-        if ( in_array( $this->active_theme, $this->themes ) ){
76
+        if (in_array($this->active_theme, $this->themes)) {
77 77
 
78 78
             // setup file and class names
79
-            $supported_theme_class_file = trailingslashit( Sensei()->plugin_path ) . 'includes/theme-integrations/' . $this->active_theme . '.php';
80
-            $supported_theme_class_name  = 'Sensei_'. ucfirst( $this->active_theme  );
79
+            $supported_theme_class_file = trailingslashit(Sensei()->plugin_path).'includes/theme-integrations/'.$this->active_theme.'.php';
80
+            $supported_theme_class_name = 'Sensei_'.ucfirst($this->active_theme);
81 81
 
82 82
             // add name of theme as body class for detailed styling.
83
-            add_filter( 'body_class', 'sensei_current_theme' );
84
-            function sensei_current_theme( $classes ) {
85
-                $sensei_template = get_option( 'template' );
86
-                $classes[] = 'sensei-'. $sensei_template;
83
+            add_filter('body_class', 'sensei_current_theme');
84
+            function sensei_current_theme($classes) {
85
+                $sensei_template = get_option('template');
86
+                $classes[] = 'sensei-'.$sensei_template;
87 87
                 return $classes;
88 88
             }
89 89
 
90 90
             // load the file or exit if there is no file for this theme
91
-            if( ! file_exists( $supported_theme_class_file ) ){
91
+            if ( ! file_exists($supported_theme_class_file)) {
92 92
                 return;
93 93
             }
94
-            include_once( $supported_theme_class_file );
95
-            include_once( 'twentytwelve.php' );
94
+            include_once($supported_theme_class_file);
95
+            include_once('twentytwelve.php');
96 96
             //initialize the class or exit if there is no class for this theme
97
-            if( ! class_exists( $supported_theme_class_name ) ){
97
+            if ( ! class_exists($supported_theme_class_name)) {
98 98
                 return;
99 99
             }
100 100
             $supported_theme = new $supported_theme_class_name;
101 101
 
102 102
             // remove default wrappers
103
-            remove_action( 'sensei_before_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper' ), 10 );
104
-            remove_action( 'sensei_after_main_content', array( Sensei()->frontend, 'sensei_output_content_wrapper_end' ), 10 );
103
+            remove_action('sensei_before_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper'), 10);
104
+            remove_action('sensei_after_main_content', array(Sensei()->frontend, 'sensei_output_content_wrapper_end'), 10);
105 105
 
106 106
             // load the supported theme wrappers
107
-            add_action( 'sensei_before_main_content', array( $supported_theme, 'wrapper_start' ), 10 );
108
-            add_action( 'sensei_after_main_content', array( $supported_theme, 'wrapper_end' ), 10 );
107
+            add_action('sensei_before_main_content', array($supported_theme, 'wrapper_start'), 10);
108
+            add_action('sensei_after_main_content', array($supported_theme, 'wrapper_end'), 10);
109 109
         }
110 110
     }
111 111
 
Please login to merge, or discard this patch.
includes/theme-integrations/twentyfifteen.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 */
14 14
 Class Sensei_Twentyfifteen extends Sensei__S {
15 15
 
16
-    /**
17
-     * Output opening wrappers
18
-     * @since 1.9.0
19
-     */
20
-    public function wrapper_start(){
16
+	/**
17
+	 * Output opening wrappers
18
+	 * @since 1.9.0
19
+	 */
20
+	public function wrapper_start(){
21 21
 
22
-        // call the parent starting wrappers
23
-        parent::wrapper_start();
22
+		// call the parent starting wrappers
23
+		parent::wrapper_start();
24 24
 
25
-    }
25
+	}
26 26
 
27 27
 } // end class
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
      * Output opening wrappers
18 18
      * @since 1.9.0
19 19
      */
20
-    public function wrapper_start(){
20
+    public function wrapper_start() {
21 21
 
22 22
         // call the parent starting wrappers
23 23
         parent::wrapper_start();
Please login to merge, or discard this patch.