Completed
Push — master ( d51ce1...80c0ca )
by Dwain
05:52
created
includes/class-sensei-updates.php 1 patch
Spacing   +481 added lines, -481 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 Updates Class
@@ -27,59 +27,59 @@  discard block
 block discarded – undo
27 27
 	 * @param   string $parent The main Sensei object by Ref.
28 28
 	 * @return  void
29 29
 	 */
30
-	public function __construct ( $parent ) {
30
+	public function __construct($parent) {
31 31
 
32 32
 		// Setup object data
33 33
 		$this->parent = $parent;
34
-		$this->updates_run = get_option( 'woothemes-sensei-upgrades', array() );
34
+		$this->updates_run = get_option('woothemes-sensei-upgrades', array());
35 35
 
36 36
 		// The list of upgrades to run
37
-		$this->updates = array( '1.1.0' => array( 	'auto' 		=> array( 'assign_role_caps' => array( 'title' => __( 'Assign role capabilities', 'woothemes-sensei' ), 'desc' => __( 'Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei' ), 'product' => 'Sensei' ) ),
37
+		$this->updates = array('1.1.0' => array('auto' 		=> array('assign_role_caps' => array('title' => __('Assign role capabilities', 'woothemes-sensei'), 'desc' => __('Assigns Sensei capabilites to the relevant user roles.', 'woothemes-sensei'), 'product' => 'Sensei')),
38 38
 													'manual' 	=> array()
39 39
 												),
40
-								'1.3.0' => array( 	'auto' 		=> array( 'set_default_quiz_grade_type' => array( 'title' => __( 'Set default quiz grade type', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei' ) ),
41
-																		  'set_default_question_type' => array( 'title' => __( 'Set default question type', 'woothemes-sensei' ), 'desc' => __( 'Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei' ) )
40
+								'1.3.0' => array('auto' 		=> array('set_default_quiz_grade_type' => array('title' => __('Set default quiz grade type', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to the default \'auto\' grade type.', 'woothemes-sensei')),
41
+																		  'set_default_question_type' => array('title' => __('Set default question type', 'woothemes-sensei'), 'desc' => __('Sets all questions to the default \'multiple choice\' type.', 'woothemes-sensei'))
42 42
 													),
43
-													'manual' 	=> array( 'update_question_answer_data' => array( 'title' => __( 'Update question answer data', 'woothemes-sensei' ), 'desc' => __( 'Updates questions to use the new question types structure.', 'woothemes-sensei' ) ) )
43
+													'manual' 	=> array('update_question_answer_data' => array('title' => __('Update question answer data', 'woothemes-sensei'), 'desc' => __('Updates questions to use the new question types structure.', 'woothemes-sensei')))
44 44
 												),
45
-								'1.4.0' => array( 	'auto' 		=> array( 'update_question_grade_points' => array( 'title' => __( 'Update question grade points', 'woothemes-sensei' ), 'desc' => __( 'Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei' ) ) ),
45
+								'1.4.0' => array('auto' 		=> array('update_question_grade_points' => array('title' => __('Update question grade points', 'woothemes-sensei'), 'desc' => __('Sets all question grade points to the default value of \'1\'.', 'woothemes-sensei'))),
46 46
 													'manual' 	=> array()
47 47
 												),
48
-								'1.5.0' => array( 	'auto' 		=> array( 'convert_essay_paste_questions' => array( 'title' => __( 'Convert essay paste questions into multi-line questions', 'woothemes-sensei' ), 'desc' => __( 'Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei' ) ) ),
49
-													'manual' 	=> array( 'set_random_question_order' => array( 'title' => __( 'Set all quizzes to have a random question order', 'woothemes-sensei' ), 'desc' => __( 'Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei' ) ),
50
-																		  'set_default_show_question_count' => array( 'title' => __( 'Set all quizzes to show all questions', 'woothemes-sensei' ), 'desc' => __( 'Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei' ) ),
51
-																		  'remove_deleted_user_activity' => array( 'title' => __( 'Remove Sensei activity for deleted users', 'woothemes-sensei' ), 'desc' => __( 'Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei' ) ) )
48
+								'1.5.0' => array('auto' 		=> array('convert_essay_paste_questions' => array('title' => __('Convert essay paste questions into multi-line questions', 'woothemes-sensei'), 'desc' => __('Converts all essay paste questions into multi-line questions as the essay paste question type was removed in v1.5.0.', 'woothemes-sensei'))),
49
+													'manual' 	=> array('set_random_question_order' => array('title' => __('Set all quizzes to have a random question order', 'woothemes-sensei'), 'desc' => __('Sets the order all of questions in all quizzes to a random order, which can be switched off per quiz.', 'woothemes-sensei')),
50
+																		  'set_default_show_question_count' => array('title' => __('Set all quizzes to show all questions', 'woothemes-sensei'), 'desc' => __('Sets all quizzes to show all questions - this can be changed per quiz.', 'woothemes-sensei')),
51
+																		  'remove_deleted_user_activity' => array('title' => __('Remove Sensei activity for deleted users', 'woothemes-sensei'), 'desc' => __('Removes all course, lesson &amp; quiz activity for users that have already been deleted from the database. This will fix incorrect learner counts in the Analysis section.', 'woothemes-sensei')))
52 52
 												),
53
-								'1.6.0' => array( 	'auto' 		=> array( 'add_teacher_role' => array( 'title' => __( 'Add \'Teacher\' role', 'woothemes-sensei' ), 'desc' => __( 'Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei' ) ),
54
-																		  'add_sensei_caps' => array( 'title' => __( 'Add administrator capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei' ) ),
55
-																		  'restructure_question_meta' => array( 'title' => __( 'Restructure question meta data', 'woothemes-sensei' ), 'desc' => __( 'Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei' ) ),
56
-																		  'update_quiz_settings' => array( 'title' => __( 'Add new quiz settings', 'woothemes-sensei' ), 'desc' => __( 'Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei' ) ),
57
-																		  'reset_lesson_order_meta' => array( 'title' => __( 'Set default order of lessons', 'woothemes-sensei' ), 'desc' => __( 'Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei' ) ), ),
53
+								'1.6.0' => array('auto' 		=> array('add_teacher_role' => array('title' => __('Add \'Teacher\' role', 'woothemes-sensei'), 'desc' => __('Adds a \'Teacher\' role to your WordPress site that will allow users to mange the Grading and Analysis pages.', 'woothemes-sensei')),
54
+																		  'add_sensei_caps' => array('title' => __('Add administrator capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei\' and \'manage_sensei_grades\' capabilities to the Administrator role.', 'woothemes-sensei')),
55
+																		  'restructure_question_meta' => array('title' => __('Restructure question meta data', 'woothemes-sensei'), 'desc' => __('Restructures the question meta data as it relates to quizzes - this accounts for changes in the data structure in v1.6+.', 'woothemes-sensei')),
56
+																		  'update_quiz_settings' => array('title' => __('Add new quiz settings', 'woothemes-sensei'), 'desc' => __('Adds new settings to quizzes that were previously registered as global settings.', 'woothemes-sensei')),
57
+																		  'reset_lesson_order_meta' => array('title' => __('Set default order of lessons', 'woothemes-sensei'), 'desc' => __('Adds data to lessons to ensure that they show up on the \'Order Lessons\' screen - if this update has been run once before then it will reset all lessons to the default order.', 'woothemes-sensei')),),
58 58
 													'manual' 	=> array()
59 59
 												),
60
-								'1.7.0' => array( 	'auto' 		=> array( 'add_editor_caps' => array( 'title' => __( 'Add Editor capabilities', 'woothemes-sensei' ), 'desc' => __( 'Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei' ) ), ),
61
-													'forced' 	=> array(  'update_question_gap_fill_separators' => array( 'title' => __( 'Update Gap Fill questions', 'woothemes-sensei' ), 'desc' => __( 'Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei' ) ),
62
-																		  'update_quiz_lesson_relationship' => array( 'title' => __( 'Restructure quiz lesson relationship', 'woothemes-sensei' ), 'desc' => __( 'Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei' ) ),
63
-																		  'status_changes_fix_lessons' => array( 'title' => __( 'Update lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Update existing lesson statuses.', 'woothemes-sensei' ) ),
64
-																		  'status_changes_convert_lessons' => array( 'title' => __( 'Convert lesson statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new lesson statuses.', 'woothemes-sensei' ) ),
65
-																		  'status_changes_convert_courses' => array( 'title' => __( 'Convert course statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new course statuses.', 'woothemes-sensei' ) ),
66
-																		  'status_changes_convert_questions' => array( 'title' => __( 'Convert question statuses', 'woothemes-sensei' ), 'desc' => __( 'Convert to new question statuses.', 'woothemes-sensei' ) ),
67
-																		  'update_legacy_sensei_comments_status' => array( 'title' => __( 'Convert legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei' ) ),
68
-																		  'update_comment_course_lesson_comment_counts' => array( 'title' => __( 'Update comment counts', 'woothemes-sensei' ), 'desc' => __( 'Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei' ) ), ),
60
+								'1.7.0' => array('auto' 		=> array('add_editor_caps' => array('title' => __('Add Editor capabilities', 'woothemes-sensei'), 'desc' => __('Adds the \'manage_sensei_grades\' capability to the Editor role.', 'woothemes-sensei')),),
61
+													'forced' 	=> array('update_question_gap_fill_separators' => array('title' => __('Update Gap Fill questions', 'woothemes-sensei'), 'desc' => __('Updates the format of gap fill questions to allow auto grading and greater flexibility in matching.', 'woothemes-sensei')),
62
+																		  'update_quiz_lesson_relationship' => array('title' => __('Restructure quiz lesson relationship', 'woothemes-sensei'), 'desc' => __('Adds data to quizzes and lessons to ensure that they maintain their 1 to 1 relationship.', 'woothemes-sensei')),
63
+																		  'status_changes_fix_lessons' => array('title' => __('Update lesson statuses', 'woothemes-sensei'), 'desc' => __('Update existing lesson statuses.', 'woothemes-sensei')),
64
+																		  'status_changes_convert_lessons' => array('title' => __('Convert lesson statuses', 'woothemes-sensei'), 'desc' => __('Convert to new lesson statuses.', 'woothemes-sensei')),
65
+																		  'status_changes_convert_courses' => array('title' => __('Convert course statuses', 'woothemes-sensei'), 'desc' => __('Convert to new course statuses.', 'woothemes-sensei')),
66
+																		  'status_changes_convert_questions' => array('title' => __('Convert question statuses', 'woothemes-sensei'), 'desc' => __('Convert to new question statuses.', 'woothemes-sensei')),
67
+																		  'update_legacy_sensei_comments_status' => array('title' => __('Convert legacy Sensei activity types', 'woothemes-sensei'), 'desc' => __('Convert all legacy Sensei activity types such as \'sensei_lesson_start\' and \'sensei_user_answer\' to new status format.', 'woothemes-sensei')),
68
+																		  'update_comment_course_lesson_comment_counts' => array('title' => __('Update comment counts', 'woothemes-sensei'), 'desc' => __('Update comment counts on Courses and Lessons due to status changes.', 'woothemes-sensei')),),
69 69
 												),
70
-								'1.7.2' => array( 	'auto' 		=> array( 'index_comment_status_field' => array( 'title' => __( 'Add database index to comment statuses', 'woothemes-sensei' ), 'desc' => __( 'This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei' ) ), ),
70
+								'1.7.2' => array('auto' 		=> array('index_comment_status_field' => array('title' => __('Add database index to comment statuses', 'woothemes-sensei'), 'desc' => __('This indexes the comment statuses in the database, which will speed up all Sensei activity queries.', 'woothemes-sensei')),),
71 71
 													/*'manual' 		=> array( 'remove_legacy_comments' => array( 'title' => __( 'Remove legacy Sensei activity types', 'woothemes-sensei' ), 'desc' => __( 'This removes all legacy (pre-1.7) Sensei activity types - only run this update once the update to v1.7 is complete and everything is stable.', 'woothemes-sensei' ) ) )*/
72 72
 												),
73
-                                '1.8.0' => array(   'auto' => array( 'enhance_teacher_role' => array( 'title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.' ), ),
73
+                                '1.8.0' => array('auto' => array('enhance_teacher_role' => array('title' => 'Enhance the \'Teacher\' role', 'desc' => 'Adds the ability for a \'Teacher\' to create courses, lessons , quizes and manage their learners.'),),
74 74
                             						'manual' 	=> array()
75 75
                     							),
76 76
 							);
77 77
 
78
-		$this->updates = apply_filters( 'sensei_upgrade_functions', $this->updates, $this->updates );
79
-		$this->version = get_option( 'woothemes-sensei-version' );
78
+		$this->updates = apply_filters('sensei_upgrade_functions', $this->updates, $this->updates);
79
+		$this->version = get_option('woothemes-sensei-version');
80 80
 
81 81
 		// Manual Update Screen
82
-		add_action('admin_menu', array( $this, 'add_update_admin_screen' ), 50 );
82
+		add_action('admin_menu', array($this, 'add_update_admin_screen'), 50);
83 83
 
84 84
 	} // End __construct()
85 85
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 * @return void
92 92
 	 */
93 93
 	public function add_update_admin_screen() {
94
-		if ( current_user_can( 'manage_options' ) ) {
95
-			add_submenu_page( 'sensei', __( 'Sensei Updates', 'woothemes-sensei' ), __( 'Data Updates', 'woothemes-sensei' ), 'manage_options', 'sensei_updates', array( $this, 'sensei_updates_page' ) );
94
+		if (current_user_can('manage_options')) {
95
+			add_submenu_page('sensei', __('Sensei Updates', 'woothemes-sensei'), __('Data Updates', 'woothemes-sensei'), 'manage_options', 'sensei_updates', array($this, 'sensei_updates_page'));
96 96
 		}
97 97
 	} // End add_update_admin_screen()
98 98
 
@@ -106,80 +106,80 @@  discard block
 block discarded – undo
106 106
 	public function sensei_updates_page() {
107 107
 
108 108
 		// Only allow admins to load this page and run the update functions
109
-		if( current_user_can( 'manage_options' ) ) {
109
+		if (current_user_can('manage_options')) {
110 110
 			?>
111 111
 			<div class="wrap">
112 112
 
113 113
 				<div id="icon-woothemes-sensei" class="icon32"><br></div>
114
-				<h2><?php _e( 'Sensei Updates', 'woothemes-sensei' ); ?></h2>
114
+				<h2><?php _e('Sensei Updates', 'woothemes-sensei'); ?></h2>
115 115
 
116 116
 				<?php
117
-				if ( isset( $_GET['action'] ) && $_GET['action'] == 'update' && isset( $_GET['n'] ) && intval( $_GET['n'] ) >= 0 && ( ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) || ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) ) ) {
117
+				if (isset($_GET['action']) && $_GET['action'] == 'update' && isset($_GET['n']) && intval($_GET['n']) >= 0 && ((isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) || (isset($_GET['functions']) && '' != $_GET['functions']))) {
118 118
 
119 119
 					// Setup the data variables
120
-					$n = intval( $_GET['n'] );
120
+					$n = intval($_GET['n']);
121 121
 					$functions_list = '';
122 122
 					$done_processing = false;
123 123
 
124 124
 					// Check for updates to run
125
-					if ( isset( $_POST['checked'][0] ) && '' != $_POST['checked'][0] ) {
125
+					if (isset($_POST['checked'][0]) && '' != $_POST['checked'][0]) {
126 126
 
127
-						foreach ( $_POST['checked'] as $key => $value ) {
127
+						foreach ($_POST['checked'] as $key => $value) {
128 128
 
129 129
 							// Dynamic function call
130
-							if ( method_exists( $this, $value) ) {
131
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
130
+							if (method_exists($this, $value)) {
131
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
132 132
 							} else {
133
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
133
+								$done_processing = call_user_func_array($value, array(50, $n));
134 134
 							} // End If Statement
135 135
 
136 136
 							// Add to functions list get args
137
-							if ( '' == $functions_list ) {
137
+							if ('' == $functions_list) {
138 138
 								$functions_list .= $value;
139 139
 							} else {
140
-								$functions_list .= '+' . $value;
140
+								$functions_list .= '+'.$value;
141 141
 							} // End If Statement
142 142
 
143 143
 							// Mark update has having been run
144
-							$this->set_update_run( $value );
144
+							$this->set_update_run($value);
145 145
 
146 146
 						} // End For Loop
147 147
 
148 148
 					} // End If Statement
149 149
 
150 150
 					// Check for updates to run
151
-					if ( isset( $_GET['functions'] ) && '' != $_GET['functions'] ) {
151
+					if (isset($_GET['functions']) && '' != $_GET['functions']) {
152 152
 
153 153
 						// Existing functions from GET variables instead of POST
154 154
 						$functions_array = $_GET['functions'];
155 155
 
156
-						foreach ( $functions_array as $key => $value ) {
156
+						foreach ($functions_array as $key => $value) {
157 157
 
158 158
 							// Dynamic function call
159
-							if ( method_exists( $this, $value) ) {
160
-								$done_processing = call_user_func_array( array( $this, $value ), array( 50, $n ) );
159
+							if (method_exists($this, $value)) {
160
+								$done_processing = call_user_func_array(array($this, $value), array(50, $n));
161 161
 							} else {
162
-								$done_processing = call_user_func_array( $value, array( 50, $n ) );
162
+								$done_processing = call_user_func_array($value, array(50, $n));
163 163
 							} // End If Statement
164 164
 
165 165
 							// Add to functions list get args
166
-							if ( '' == $functions_list ) {
166
+							if ('' == $functions_list) {
167 167
 								$functions_list .= $value;
168 168
 							} else {
169
-								$functions_list .= '+' . $value;
169
+								$functions_list .= '+'.$value;
170 170
 							} // End If Statement
171 171
 
172
-							$this->set_update_run( $value );
172
+							$this->set_update_run($value);
173 173
 
174 174
 						} // End For Loop
175 175
 
176 176
 					} // End If Statement
177 177
 
178
-					if ( ! $done_processing ) { ?>
178
+					if ( ! $done_processing) { ?>
179 179
 
180
-						<h3><?php _e( 'Processing Updates...', 'woothemes-sensei' ); ?></h3>
180
+						<h3><?php _e('Processing Updates...', 'woothemes-sensei'); ?></h3>
181 181
 
182
-						<p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei' ); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e( 'Next', 'woothemes-sensei' ); ?></a></p>
182
+						<p><?php _e('If your browser doesn&#8217;t start loading the next page automatically, click this button:', 'woothemes-sensei'); ?>&nbsp;&nbsp;<a class="button" href="admin.php?page=sensei_updates&action=update&n=<?php echo ($n + 50) ?>&functions[]=<?php echo $functions_list; ?>"><?php _e('Next', 'woothemes-sensei'); ?></a></p>
183 183
 						<script type='text/javascript'>
184 184
 						<!--
185 185
 						function sensei_nextpage() {
@@ -191,48 +191,48 @@  discard block
 block discarded – undo
191 191
 
192 192
 					} else { ?>
193 193
 
194
-						<p><strong><?php _e( 'Update completed successfully!', 'woothemes-sensei' ); ?></strong></p>
195
-						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e( 'Create a new lesson', 'woothemes-sensei' ); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e( 'run some more updates', 'woothemes-sensei' ); ?></a>.</p>
194
+						<p><strong><?php _e('Update completed successfully!', 'woothemes-sensei'); ?></strong></p>
195
+						<p><a href="<?php echo admin_url('edit.php?post_type=lesson'); ?>"><?php _e('Create a new lesson', 'woothemes-sensei'); ?></a> or <a href="<?php echo admin_url('admin.php?page=sensei_updates'); ?>"><?php _e('run some more updates', 'woothemes-sensei'); ?></a>.</p>
196 196
 
197 197
 					<?php } // End If Statement
198 198
 
199 199
 				} else { ?>
200 200
 
201
-					<h3><?php _e( 'Updates', 'woothemes-sensei' ); ?></h3>
202
-					<p><?php printf( __( 'These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei' ), '<code>', '</code>' ); ?></p>
201
+					<h3><?php _e('Updates', 'woothemes-sensei'); ?></h3>
202
+					<p><?php printf(__('These are updates that have been made available as new Sensei versions have been released. Updates of type %1$sAuto%2$s will run as you update Sensei to the relevant version - other updates need to be run manually and you can do that here.', 'woothemes-sensei'), '<code>', '</code>'); ?></p>
203 203
 
204
-					<div class="updated"><p><strong><?php _e( 'Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei' ); ?></strong></p></div>
204
+					<div class="updated"><p><strong><?php _e('Only run these updates if you have been instructed to do so by WooThemes support staff.', 'woothemes-sensei'); ?></strong></p></div>
205 205
 
206 206
 					<table class="widefat" cellspacing="0" id="update-plugins-table">
207 207
 
208 208
 						<thead>
209 209
 							<tr>
210
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
211
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
212
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
210
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
211
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
212
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
213 213
 							</tr>
214 214
 						</thead>
215 215
 
216 216
 						<tfoot>
217 217
 							<tr>
218
-								<th scope="col" class="manage-column"><?php _e( 'Update', 'woothemes-sensei' ); ?></th>
219
-								<th scope="col" class="manage-column"><?php _e( 'Type', 'woothemes-sensei' ); ?></th>
220
-								<th scope="col" class="manage-column"><?php _e( 'Action', 'woothemes-sensei' ); ?></th>
218
+								<th scope="col" class="manage-column"><?php _e('Update', 'woothemes-sensei'); ?></th>
219
+								<th scope="col" class="manage-column"><?php _e('Type', 'woothemes-sensei'); ?></th>
220
+								<th scope="col" class="manage-column"><?php _e('Action', 'woothemes-sensei'); ?></th>
221 221
 							</tr>
222 222
 						</tfoot>
223 223
 
224 224
 						<tbody class="updates">
225 225
 							<?php
226 226
 							// Sort updates with the latest at the top
227
-							uksort( $this->updates, array( $this, 'sort_updates' ) );
228
-							$this->updates = array_reverse( $this->updates, true );
227
+							uksort($this->updates, array($this, 'sort_updates'));
228
+							$this->updates = array_reverse($this->updates, true);
229 229
 							$class = 'alternate';
230
-							foreach( $this->updates as $version => $version_updates ) {
231
-								foreach( $version_updates as $type => $updates ) {
232
-									foreach( $updates as $update => $data ) {
233
-										$update_run = $this->has_update_run( $update );
230
+							foreach ($this->updates as $version => $version_updates) {
231
+								foreach ($version_updates as $type => $updates) {
232
+									foreach ($updates as $update => $data) {
233
+										$update_run = $this->has_update_run($update);
234 234
 										$product = 'Sensei';
235
-										if ( isset( $data['product'] ) && '' != $data['product'] ) {
235
+										if (isset($data['product']) && '' != $data['product']) {
236 236
 											$product = $data['product'];
237 237
 										} // End If Statement
238 238
 										?>
@@ -242,21 +242,21 @@  discard block
 block discarded – undo
242 242
 													<p>
243 243
 														<input type="hidden" name="checked[]" value="<?php echo $update; ?>">
244 244
 														<strong><?php echo $data['title']; ?></strong><br><?php echo $data['desc']; ?><br>
245
-														<em><?php printf( __( 'Originally included in %s v%s', 'woothemes-sensei' ), $product, $version ); ?></em>
245
+														<em><?php printf(__('Originally included in %s v%s', 'woothemes-sensei'), $product, $version); ?></em>
246 246
 													</p>
247 247
 												</td>
248 248
 												<?php
249
-												$type_label = __( 'Auto', 'woothemes-sensei' );
250
-												if( $type != 'auto' ) {
251
-													$type_label = __( 'Manual', 'woothemes-sensei' );
249
+												$type_label = __('Auto', 'woothemes-sensei');
250
+												if ($type != 'auto') {
251
+													$type_label = __('Manual', 'woothemes-sensei');
252 252
 												}
253 253
 												?>
254 254
 												<td><p><?php echo $type_label; ?></p></td>
255
-												<td><p><input onclick="javascript:return confirm('<?php echo addslashes( sprintf( __( 'Are you sure you want to run the \'%s\' update?', 'woothemes-sensei' ), $data['title'] ) ); ?>');" id="update-sensei" class="button<?php if( ! $update_run ) { echo ' button-primary'; } ?>" type="submit" value="<?php if( $update_run ) { _e( 'Re-run Update', 'woothemes-sensei' ); } else { _e( 'Run Update', 'woothemes-sensei' ); } ?>" name="update"></p></td>
255
+												<td><p><input onclick="javascript:return confirm('<?php echo addslashes(sprintf(__('Are you sure you want to run the \'%s\' update?', 'woothemes-sensei'), $data['title'])); ?>');" id="update-sensei" class="button<?php if ( ! $update_run) { echo ' button-primary'; } ?>" type="submit" value="<?php if ($update_run) { _e('Re-run Update', 'woothemes-sensei'); } else { _e('Run Update', 'woothemes-sensei'); } ?>" name="update"></p></td>
256 256
 											</tr>
257 257
 										</form>
258 258
 										<?php
259
-										if( 'alternate' == $class ) {
259
+										if ('alternate' == $class) {
260 260
 											$class = '';
261 261
 										} else {
262 262
 											$class = 'alternate';
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 	 * @param  string $b Second key
284 284
 	 * @return integer
285 285
 	 */
286
-	private function sort_updates( $a, $b ) {
287
-		return strcmp( $a, $b );
286
+	private function sort_updates($a, $b) {
287
+		return strcmp($a, $b);
288 288
 	}
289 289
 
290 290
 	/**
@@ -295,32 +295,32 @@  discard block
 block discarded – undo
295 295
 	 * @access public
296 296
 	 * @return boolean
297 297
 	 */
298
-	public function update ( $type = 'auto' ) {
298
+	public function update($type = 'auto') {
299 299
 
300 300
 		// Only allow admins to run update functions
301
-		if( current_user_can( 'manage_options' ) ) {
301
+		if (current_user_can('manage_options')) {
302 302
 
303 303
 			$this->force_updates();
304 304
 
305 305
 			// Run through all functions
306
-			foreach ( $this->updates as $version => $value ) {
307
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
308
-					if ( $upgrade_type == $type ) {
306
+			foreach ($this->updates as $version => $value) {
307
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
308
+					if ($upgrade_type == $type) {
309 309
 						$updated = false;
310 310
 						// Run the update function
311
-						foreach ( $function_to_run as $function_name => $update_data ) {
312
-							if ( isset( $function_name ) && '' != $function_name ) {
313
-								if ( ! in_array( $function_name, $this->updates_run ) ) {
311
+						foreach ($function_to_run as $function_name => $update_data) {
312
+							if (isset($function_name) && '' != $function_name) {
313
+								if ( ! in_array($function_name, $this->updates_run)) {
314 314
 									$updated = false;
315
-									if ( method_exists( $this, $function_name ) ) {
316
-										$updated = call_user_func( array( $this, $function_name ) );
317
-									} elseif( function_exists( $function_name ) ) {
318
-										$updated = call_user_func( $function_name );
315
+									if (method_exists($this, $function_name)) {
316
+										$updated = call_user_func(array($this, $function_name));
317
+									} elseif (function_exists($function_name)) {
318
+										$updated = call_user_func($function_name);
319 319
 									} else {
320 320
 										// Nothing to see here...
321 321
 									} // End If Statement
322
-									if ( $updated ) {
323
-										array_push( $this->updates_run, $function_name );
322
+									if ($updated) {
323
+										array_push($this->updates_run, $function_name);
324 324
 									} // End If Statement
325 325
 								}
326 326
 							} // End If Statement
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 				} // End For Loop
330 330
 			} // End For Loop
331 331
 
332
-            $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
333
-			update_option( Sensei()->token . '-upgrades', $this->updates_run );
332
+            $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
333
+			update_option(Sensei()->token.'-upgrades', $this->updates_run);
334 334
 			return true;
335 335
 
336 336
 		}
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 
340 340
 	private function force_updates() {
341 341
 
342
-		if( ! isset( $_GET['page'] ) || 'sensei_updates' != $_GET['page'] ) {
342
+		if ( ! isset($_GET['page']) || 'sensei_updates' != $_GET['page']) {
343 343
 
344 344
 			// $skip_forced_updates = false;
345 345
 			// if( ! get_option( 'woothemes-sensei-force-updates', false ) ) {
@@ -348,8 +348,8 @@  discard block
 block discarded – undo
348 348
 
349 349
 			// Force critical updates if only if lessons already exist
350 350
 			$skip_forced_updates = false;
351
-			$lesson_posts = wp_count_posts( 'lesson' );
352
-			if( ! isset( $lesson_posts->publish ) || ! $lesson_posts->publish ) {
351
+			$lesson_posts = wp_count_posts('lesson');
352
+			if ( ! isset($lesson_posts->publish) || ! $lesson_posts->publish) {
353 353
 				$skip_forced_updates = true;
354 354
 			}
355 355
 
@@ -357,69 +357,69 @@  discard block
 block discarded – undo
357 357
 
358 358
 			$updates_to_run = array();
359 359
 
360
-			foreach ( $this->updates as $version => $value ) {
361
-				foreach ( $this->updates[$version] as $upgrade_type => $function_to_run ) {
362
-					if ( $upgrade_type == 'forced' ) {
363
-						foreach ( $function_to_run as $function_name => $update_data ) {
360
+			foreach ($this->updates as $version => $value) {
361
+				foreach ($this->updates[$version] as $upgrade_type => $function_to_run) {
362
+					if ($upgrade_type == 'forced') {
363
+						foreach ($function_to_run as $function_name => $update_data) {
364 364
 
365
-							if( $skip_forced_updates ) {
366
-								$this->set_update_run( $function_name );
365
+							if ($skip_forced_updates) {
366
+								$this->set_update_run($function_name);
367 367
 								continue;
368 368
 							}
369 369
 
370
-							$update_run = $this->has_update_run( $function_name );
370
+							$update_run = $this->has_update_run($function_name);
371 371
 
372
-							if( ! $update_run ) {
372
+							if ( ! $update_run) {
373 373
 								$use_the_force = true;
374
-								$updates_to_run[ $function_name ] = $update_data;
374
+								$updates_to_run[$function_name] = $update_data;
375 375
 							}
376 376
 						}
377 377
 					}
378 378
 				}
379 379
 			}
380 380
 
381
-			if( $skip_forced_updates ) {
381
+			if ($skip_forced_updates) {
382 382
 				return;
383 383
 			}
384 384
 
385
-			if( $use_the_force && 0 < count( $updates_to_run ) ) {
385
+			if ($use_the_force && 0 < count($updates_to_run)) {
386 386
 
387
-				$update_title = __( 'Important Sensei updates required', 'woothemes-sensei' );
387
+				$update_title = __('Important Sensei updates required', 'woothemes-sensei');
388 388
 
389
-				$update_message = '<h1>' . __( 'Important Sensei upgrades required!', 'woothemes-sensei' ) . '</h1>' . "\n";
389
+				$update_message = '<h1>'.__('Important Sensei upgrades required!', 'woothemes-sensei').'</h1>'."\n";
390 390
 
391 391
 				// $update_message .= '<h4>' . sprintf( __( 'These updates are only required if you are updating from a previous version of Sensei. If you are installing Sensei for the first time, %1$syou can dismiss this page by clicking here%2$s.', 'woothemes-sensei' ), '<a href="' . add_query_arg( array( 'sensei_skip_forced_updates' => 'true' ) ) . '">', '</a>' ) . '</h4>' ."\n";
392 392
 
393
-				$update_message .= '<p>' . __( 'The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei' ) . '</p>' . "\n";
393
+				$update_message .= '<p>'.__('The latest version of Sensei requires some important database upgrades. In order to run these upgrades you will need to follow the step by step guide below. Your site will not function correctly unless you run these critical updates.', 'woothemes-sensei').'</p>'."\n";
394 394
 
395
-				$update_message .= '<p><b>' . __( 'To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei' ) . '</b></p>' . "\n";
395
+				$update_message .= '<p><b>'.__('To run the upgrades click on each of the links below in the order that they appear.', 'woothemes-sensei').'</b></p>'."\n";
396 396
 
397
-				$update_message .= '<p>' . __( 'Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei' ) . '</p>' . "\n";
397
+				$update_message .= '<p>'.__('Clicking each link will open up a new window/tab - do not close that window/tab until you see the message \'Update completed successfully\'. Once you see that message you can close the window/tab and start the next upgrade by clicking on the next link in the list.', 'woothemes-sensei').'</p>'."\n";
398 398
 
399
-				$update_message .= '<p><b>' . __( 'Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei' ) . '</b></p>' . "\n";
399
+				$update_message .= '<p><b>'.__('Once all the upgrades have been completed you will be able to use your WordPress site again.', 'woothemes-sensei').'</b></p>'."\n";
400 400
 
401
-				$update_message .= '<ol>' . "\n";
401
+				$update_message .= '<ol>'."\n";
402 402
 
403
-					foreach( $updates_to_run as $function => $data ) {
403
+					foreach ($updates_to_run as $function => $data) {
404 404
 
405
-						if( ! isset( $data['title'] ) ) {
405
+						if ( ! isset($data['title'])) {
406 406
 							break;
407 407
 						}
408 408
 
409
-						$update_message .= '<li style="margin:5px 0;"><a href="' . admin_url( 'admin.php?page=sensei_updates&action=update&n=0&functions[]=' . $function ) . '" target="_blank">' . $data['title'] . '</a></li>';
409
+						$update_message .= '<li style="margin:5px 0;"><a href="'.admin_url('admin.php?page=sensei_updates&action=update&n=0&functions[]='.$function).'" target="_blank">'.$data['title'].'</a></li>';
410 410
 					}
411 411
 
412
-				$update_message .= '</ol>' . "\n";
412
+				$update_message .= '</ol>'."\n";
413 413
 
414
-				switch( $version ) {
414
+				switch ($version) {
415 415
 
416 416
 					case '1.7.0':
417
-						$update_message .= '<p><em>' . sprintf( __( 'Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei' ), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>' ) . '</em></p>' . "\n";
417
+						$update_message .= '<p><em>'.sprintf(__('Want to know what these upgrades are all about? %1$sFind out more here%2$s.', 'woothemes-sensei'), '<a href="http://develop.woothemes.com/sensei/2014/12/03/important-information-about-sensei-1-7" target="_blank">', '</a>').'</em></p>'."\n";
418 418
 					break;
419 419
 
420 420
 				}
421 421
 
422
-				wp_die( $update_message, $update_title );
422
+				wp_die($update_message, $update_title);
423 423
 			}
424 424
 		}
425 425
 	}
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @since  1.4.0
432 432
 	 * @return boolean
433 433
 	 */
434
-	private function has_update_run( $update ) {
435
-		if ( in_array( $update, $this->updates_run ) ) {
434
+	private function has_update_run($update) {
435
+		if (in_array($update, $this->updates_run)) {
436 436
 			return true;
437 437
 		}
438 438
 		return false;
@@ -444,10 +444,10 @@  discard block
 block discarded – undo
444 444
 	 * @param string $update Update to process
445 445
 	 * @since  1.4.0
446 446
 	 */
447
-	private function set_update_run( $update ) {
448
-		array_push( $this->updates_run, $update );
449
-        $this->updates_run = array_unique( $this->updates_run ); // we only need one reference per update
450
-		update_option( Sensei()->token . '-upgrades', $this->updates_run );
447
+	private function set_update_run($update) {
448
+		array_push($this->updates_run, $update);
449
+        $this->updates_run = array_unique($this->updates_run); // we only need one reference per update
450
+		update_option(Sensei()->token.'-upgrades', $this->updates_run);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,15 +458,15 @@  discard block
 block discarded – undo
458 458
 	 * @return void
459 459
 	 */
460 460
 	public function assign_role_caps() {
461
-		foreach ( $this->parent->post_types->role_caps as $role_cap_set  ) {
462
-			foreach ( $role_cap_set as $role_key => $capabilities_array ) {
461
+		foreach ($this->parent->post_types->role_caps as $role_cap_set) {
462
+			foreach ($role_cap_set as $role_key => $capabilities_array) {
463 463
 				/* Get the role. */
464
-				$role = get_role( $role_key );
465
-				foreach ( $capabilities_array as $cap_name  ) {
464
+				$role = get_role($role_key);
465
+				foreach ($capabilities_array as $cap_name) {
466 466
 					/* If the role exists, add required capabilities for the plugin. */
467
-					if ( !empty( $role ) ) {
468
-						if ( !$role->has_cap( $cap_name ) ) {
469
-							$role->add_cap( $cap_name );
467
+					if ( ! empty($role)) {
468
+						if ( ! $role->has_cap($cap_name)) {
469
+							$role->add_cap($cap_name);
470 470
 						} // End If Statement
471 471
 					} // End If Statement
472 472
 				} // End For Loop
@@ -483,16 +483,16 @@  discard block
 block discarded – undo
483 483
 	 * @return void
484 484
 	 */
485 485
 	public function set_default_quiz_grade_type() {
486
-		$args = array(	'post_type' 		=> 'quiz',
486
+		$args = array('post_type' 		=> 'quiz',
487 487
 						'posts_per_page' 		=> -1,
488 488
 						'post_status'		=> 'publish',
489 489
 						'suppress_filters' 	=> 0
490 490
 						);
491
-		$quizzes = get_posts( $args );
491
+		$quizzes = get_posts($args);
492 492
 
493
-		foreach( $quizzes as $quiz ) {
494
-			update_post_meta( $quiz->ID, '_quiz_grade_type', 'auto' );
495
-			update_post_meta( $quiz->ID, '_quiz_grade_type_disabled', '' );
493
+		foreach ($quizzes as $quiz) {
494
+			update_post_meta($quiz->ID, '_quiz_grade_type', 'auto');
495
+			update_post_meta($quiz->ID, '_quiz_grade_type_disabled', '');
496 496
 		}
497 497
 		return true;
498 498
 	} // End set_default_quiz_grade_type
@@ -505,23 +505,23 @@  discard block
 block discarded – undo
505 505
 	 * @return void
506 506
 	 */
507 507
 	public function set_default_question_type() {
508
-		$args = array(	'post_type' 		=> 'question',
508
+		$args = array('post_type' 		=> 'question',
509 509
 						'posts_per_page' 		=> -1,
510 510
 						'post_status'		=> 'publish',
511 511
 						'suppress_filters' 	=> 0
512 512
 						);
513
-		$questions = get_posts( $args );
513
+		$questions = get_posts($args);
514 514
 
515 515
 		$already_run = true;
516
-		foreach( $questions as $question ) {
517
-			if( $already_run ) {
518
-				$terms = wp_get_post_terms( $question->ID, 'question-type' );
519
-				if( is_array( $terms ) && count( $terms ) > 0 ) {
516
+		foreach ($questions as $question) {
517
+			if ($already_run) {
518
+				$terms = wp_get_post_terms($question->ID, 'question-type');
519
+				if (is_array($terms) && count($terms) > 0) {
520 520
 					break;
521 521
 				}
522 522
 			}
523 523
 			$already_run = false;
524
-			wp_set_post_terms( $question->ID, array( 'multiple-choice' ), 'question-type' );
524
+			wp_set_post_terms($question->ID, array('multiple-choice'), 'question-type');
525 525
 		}
526 526
 
527 527
 		return true;
@@ -534,90 +534,90 @@  discard block
 block discarded – undo
534 534
 	 * @access public
535 535
 	 * @return void
536 536
 	 */
537
-	public function update_question_answer_data( $n = 50, $offset = 0 ) {
537
+	public function update_question_answer_data($n = 50, $offset = 0) {
538 538
 
539 539
 		// Get Total Number of Updates to run
540
-		$quiz_count_object = wp_count_posts( 'quiz' );
540
+		$quiz_count_object = wp_count_posts('quiz');
541 541
 		$quiz_count_published = $quiz_count_object->publish;
542 542
 
543 543
 		// Calculate if this is the last page
544
-		if ( 0 == $offset ) {
544
+		if (0 == $offset) {
545 545
 			$current_page = 1;
546 546
 		} else {
547
-			$current_page = intval( $offset / $n );
547
+			$current_page = intval($offset / $n);
548 548
 		} // End If Statement
549
-		$total_pages = intval( $quiz_count_published / $n );
549
+		$total_pages = intval($quiz_count_published / $n);
550 550
 
551 551
 
552
-		$args = array(	'post_type' 		=> 'quiz',
552
+		$args = array('post_type' 		=> 'quiz',
553 553
 						'posts_per_page' 		=> $n,
554 554
 						'offset'			=> $offset,
555 555
 						'post_status'		=> 'publish',
556 556
 						'suppress_filters' 	=> 0
557 557
 						);
558
-		$quizzes = get_posts( $args );
558
+		$quizzes = get_posts($args);
559 559
 
560 560
 		$old_answers = array();
561 561
 		$right_answers = array();
562 562
 		$old_user_answers = array();
563 563
 
564
-		if( is_array( $quizzes ) ) {
565
-			foreach( $quizzes as $quiz ) {
564
+		if (is_array($quizzes)) {
565
+			foreach ($quizzes as $quiz) {
566 566
 				$quiz_id = $quiz->ID;
567 567
 
568 568
 				// Get current user answers
569
-				$comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $quiz_id, 'type' => 'sensei_quiz_answers' ), true  );
569
+				$comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $quiz_id, 'type' => 'sensei_quiz_answers'), true);
570 570
 				// Need to always return an array, even with only 1 item
571
-				if ( !is_array($comments) ) {
572
-					$comments = array( $comments );
571
+				if ( ! is_array($comments)) {
572
+					$comments = array($comments);
573 573
 				}
574
-				foreach ( $comments as $comment ) {
574
+				foreach ($comments as $comment) {
575 575
 					$user_id = $comment->user_id;
576
-					$content = maybe_unserialize( base64_decode( $comment->comment_content ) );
577
-					$old_user_answers[ $quiz_id ][ $user_id ] = $content;
576
+					$content = maybe_unserialize(base64_decode($comment->comment_content));
577
+					$old_user_answers[$quiz_id][$user_id] = $content;
578 578
 				}
579 579
 
580 580
 				// Get correct answers
581
-				$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
582
-				if( is_array( $questions ) ) {
583
-					foreach( $questions as $question ) {
584
-						$right_answer = get_post_meta( $question->ID, '_question_right_answer', true );
585
-						$right_answers[ $quiz_id ][ $question->ID ] = $right_answer;
581
+				$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
582
+				if (is_array($questions)) {
583
+					foreach ($questions as $question) {
584
+						$right_answer = get_post_meta($question->ID, '_question_right_answer', true);
585
+						$right_answers[$quiz_id][$question->ID] = $right_answer;
586 586
 					}
587 587
 				}
588 588
 			}
589 589
 		}
590 590
 
591
-		if( is_array( $right_answers ) ) {
592
-			foreach( $right_answers as $quiz_id => $question ) {
591
+		if (is_array($right_answers)) {
592
+			foreach ($right_answers as $quiz_id => $question) {
593 593
 				$count = 0;
594
-				if( is_array( $question ) ) {
595
-					foreach( $question as $question_id => $answer ) {
594
+				if (is_array($question)) {
595
+					foreach ($question as $question_id => $answer) {
596 596
 						++$count;
597
-						if( isset( $old_user_answers[ $quiz_id ] ) ) {
598
-							$answers_linkup[ $quiz_id ][ $count ] = $question_id;
597
+						if (isset($old_user_answers[$quiz_id])) {
598
+							$answers_linkup[$quiz_id][$count] = $question_id;
599 599
 						}
600 600
 					}
601 601
 				}
602 602
 			}
603 603
 		}
604 604
 
605
-		if( is_array( $old_user_answers ) ) {
606
-			foreach( $old_user_answers as $quiz_id => $user_answers ) {
607
-				foreach( $user_answers as $user_id => $answers ) {
608
-					foreach( $answers as $answer_id => $user_answer ) {
609
-						$question_id = $answers_linkup[ $quiz_id ][ $answer_id ];
610
-						$new_user_answers[ $question_id ] = $user_answer;
611
-						Sensei_Utils::sensei_grade_question_auto( $question_id, '', $user_answer, $user_id );
605
+		if (is_array($old_user_answers)) {
606
+			foreach ($old_user_answers as $quiz_id => $user_answers) {
607
+				foreach ($user_answers as $user_id => $answers) {
608
+					foreach ($answers as $answer_id => $user_answer) {
609
+						$question_id = $answers_linkup[$quiz_id][$answer_id];
610
+						$new_user_answers[$question_id] = $user_answer;
611
+						Sensei_Utils::sensei_grade_question_auto($question_id, '', $user_answer, $user_id);
612 612
 					}
613
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
614
-					Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
615
-					Sensei_Utils::sensei_save_quiz_answers( $new_user_answers, $user_id );
613
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
614
+					Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
615
+					Sensei_Utils::sensei_save_quiz_answers($new_user_answers, $user_id);
616 616
 				}
617 617
 			}
618 618
 		}
619 619
 
620
-		if ( $current_page == $total_pages ) {
620
+		if ($current_page == $total_pages) {
621 621
 			return true;
622 622
 		} else {
623 623
 			return false;
@@ -632,15 +632,15 @@  discard block
 block discarded – undo
632 632
 	 * @return boolean
633 633
 	 */
634 634
 	public function update_question_grade_points() {
635
-		$args = array(	'post_type' 		=> 'question',
635
+		$args = array('post_type' 		=> 'question',
636 636
 						'posts_per_page' 		=> -1,
637 637
 						'post_status'		=> 'publish',
638 638
 						'suppress_filters' 	=> 0
639 639
 						);
640
-		$questions = get_posts( $args );
640
+		$questions = get_posts($args);
641 641
 
642
-		foreach( $questions as $question ) {
643
-			update_post_meta( $question->ID, '_question_grade', '1' );
642
+		foreach ($questions as $question) {
643
+			update_post_meta($question->ID, '_question_grade', '1');
644 644
 		}
645 645
 		return true;
646 646
 	} // End update_question_grade_points
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 	 * @return boolean
653 653
 	 */
654 654
 	public function convert_essay_paste_questions() {
655
-		$args = array(	'post_type' 		=> 'question',
655
+		$args = array('post_type' 		=> 'question',
656 656
 						'posts_per_page' 		=> -1,
657 657
 						'post_status'		=> 'publish',
658 658
 						'tax_query'			=> array(
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 						),
665 665
 						'suppress_filters' 	=> 0
666 666
 						);
667
-		$questions = get_posts( $args );
667
+		$questions = get_posts($args);
668 668
 
669
-		foreach( $questions as $question ) {
670
-			wp_set_object_terms( $question->ID, 'multi-line', 'question-type', false );
669
+		foreach ($questions as $question) {
670
+			wp_set_object_terms($question->ID, 'multi-line', 'question-type', false);
671 671
 
672
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
673
-			if( 0 < intval( $quiz_id ) ) {
674
-				add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '0000', true );
672
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
673
+			if (0 < intval($quiz_id)) {
674
+				add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'0000', true);
675 675
 			}
676 676
 		}
677 677
 		return true;
@@ -683,33 +683,33 @@  discard block
 block discarded – undo
683 683
 	 * @since  1.5.0
684 684
 	 * @return boolean
685 685
 	 */
686
-	public function set_random_question_order( $n = 50, $offset = 0 ) {
686
+	public function set_random_question_order($n = 50, $offset = 0) {
687 687
 
688 688
 		// Get Total Number of Updates to run
689
-		$quiz_count_object = wp_count_posts( 'quiz' );
689
+		$quiz_count_object = wp_count_posts('quiz');
690 690
 		$quiz_count_published = $quiz_count_object->publish;
691 691
 
692 692
 		// Calculate if this is the last page
693
-		if ( 0 == $offset ) {
693
+		if (0 == $offset) {
694 694
 			$current_page = 1;
695 695
 		} else {
696
-			$current_page = intval( $offset / $n );
696
+			$current_page = intval($offset / $n);
697 697
 		} // End If Statement
698
-		$total_pages = intval( $quiz_count_published / $n );
698
+		$total_pages = intval($quiz_count_published / $n);
699 699
 
700
-		$args = array(	'post_type' 		=> 'quiz',
700
+		$args = array('post_type' 		=> 'quiz',
701 701
 						'post_status'		=> 'any',
702 702
 						'posts_per_page' 		=> $n,
703 703
 						'offset'			=> $offset,
704 704
 						'suppress_filters' 	=> 0
705 705
 						);
706
-		$quizzes = get_posts( $args );
706
+		$quizzes = get_posts($args);
707 707
 
708
-		foreach( $quizzes as $quiz ) {
709
-			update_post_meta( $quiz->ID, '_random_question_order', 'yes' );
708
+		foreach ($quizzes as $quiz) {
709
+			update_post_meta($quiz->ID, '_random_question_order', 'yes');
710 710
 		}
711 711
 
712
-		if ( $current_page == $total_pages ) {
712
+		if ($current_page == $total_pages) {
713 713
 			return true;
714 714
 		} else {
715 715
 			return false;
@@ -723,37 +723,37 @@  discard block
 block discarded – undo
723 723
 	 * @since  1.5.0
724 724
 	 * @return boolean
725 725
 	 */
726
-	public function set_default_show_question_count( $n = 50, $offset = 0 ) {
726
+	public function set_default_show_question_count($n = 50, $offset = 0) {
727 727
 
728
-		$args = array(	'post_type' 		=> 'quiz',
728
+		$args = array('post_type' 		=> 'quiz',
729 729
 						'post_status'		=> 'any',
730 730
 						'posts_per_page' 		=> $n,
731 731
 						'offset'			=> $offset,
732 732
 						'meta_key'			=> '_show_questions',
733 733
 						'suppress_filters' 	=> 0
734 734
 						);
735
-		$quizzes = get_posts( $args );
735
+		$quizzes = get_posts($args);
736 736
 
737
-		$total_quizzes = count( $quizzes );
737
+		$total_quizzes = count($quizzes);
738 738
 
739
-		if( 0 == intval( $total_quizzes ) ) {
739
+		if (0 == intval($total_quizzes)) {
740 740
 			return true;
741 741
 		}
742 742
 
743
-		foreach( $quizzes as $quiz ) {
744
-			delete_post_meta( $quiz->ID, '_show_questions' );
743
+		foreach ($quizzes as $quiz) {
744
+			delete_post_meta($quiz->ID, '_show_questions');
745 745
 		}
746 746
 
747
-		$total_pages = intval( $total_quizzes / $n );
747
+		$total_pages = intval($total_quizzes / $n);
748 748
 
749 749
 		// Calculate if this is the last page
750
-		if ( 0 == $offset ) {
750
+		if (0 == $offset) {
751 751
 			$current_page = 1;
752 752
 		} else {
753
-			$current_page = intval( $offset / $n );
753
+			$current_page = intval($offset / $n);
754 754
 		} // End If Statement
755 755
 
756
-		if ( $current_page == $total_pages ) {
756
+		if ($current_page == $total_pages) {
757 757
 			return true;
758 758
 		} else {
759 759
 			return false;
@@ -761,17 +761,17 @@  discard block
 block discarded – undo
761 761
 
762 762
 	}
763 763
 
764
-	public function remove_deleted_user_activity( $n = 50, $offset = 0 ) {
764
+	public function remove_deleted_user_activity($n = 50, $offset = 0) {
765 765
 
766 766
 
767 767
 //		remove_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
768 768
 
769
-		$all_activity = get_comments( array( 'status' => 'approve' ) );
769
+		$all_activity = get_comments(array('status' => 'approve'));
770 770
 		$activity_count = array();
771
-		foreach( $all_activity as $activity ) {
772
-			if( '' == $activity->comment_type ) continue;
773
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
774
-			if( 0 == $activity->user_id ) continue;
771
+		foreach ($all_activity as $activity) {
772
+			if ('' == $activity->comment_type) continue;
773
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
774
+			if (0 == $activity->user_id) continue;
775 775
 			$activity_count[] = $activity->comment_ID;
776 776
 		}
777 777
 
@@ -781,35 +781,35 @@  discard block
 block discarded – undo
781 781
 			'status' => 'approve'
782 782
 		);
783 783
 
784
-		$activities = get_comments( $args );
784
+		$activities = get_comments($args);
785 785
 
786
-		foreach( $activities as $activity ) {
787
-			if( '' == $activity->comment_type ) continue;
788
-			if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
789
-			if( 0 == $activity->user_id ) continue;
786
+		foreach ($activities as $activity) {
787
+			if ('' == $activity->comment_type) continue;
788
+			if (strpos('sensei_', $activity->comment_type) != 0) continue;
789
+			if (0 == $activity->user_id) continue;
790 790
 
791
-			$user_exists = get_userdata( $activity->user_id );
791
+			$user_exists = get_userdata($activity->user_id);
792 792
 
793
-			if( ! $user_exists ) {
794
-				wp_delete_comment( intval( $activity->comment_ID ), true );
793
+			if ( ! $user_exists) {
794
+				wp_delete_comment(intval($activity->comment_ID), true);
795 795
 				wp_cache_flush();
796 796
 			}
797 797
 		}
798 798
 
799
-		$total_activities = count( $activity_count );
799
+		$total_activities = count($activity_count);
800 800
 
801
-		$total_pages = intval( $total_activities / $n );
801
+		$total_pages = intval($total_activities / $n);
802 802
 
803 803
 		// Calculate if this is the last page
804
-		if ( 0 == $offset ) {
804
+		if (0 == $offset) {
805 805
 			$current_page = 1;
806 806
 		} else {
807
-			$current_page = intval( $offset / $n );
807
+			$current_page = intval($offset / $n);
808 808
 		} // End If Statement
809 809
 
810 810
 //		add_filter( 'comments_clauses', array( Sensei()->admin, 'comments_admin_filter' ) );
811 811
 
812
-		if ( $current_page >= $total_pages ) {
812
+		if ($current_page >= $total_pages) {
813 813
 			return true;
814 814
 		} else {
815 815
 			return false;
@@ -818,16 +818,16 @@  discard block
 block discarded – undo
818 818
 	}
819 819
 
820 820
 	public function add_teacher_role() {
821
-		add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ), array( 'read' => true, 'manage_sensei_grades' => true ) );
821
+		add_role('teacher', __('Teacher', 'woothemes-sensei'), array('read' => true, 'manage_sensei_grades' => true));
822 822
 		return true;
823 823
 	}
824 824
 
825 825
 	public function add_sensei_caps() {
826
-		$role = get_role( 'administrator' );
826
+		$role = get_role('administrator');
827 827
 
828
-		if( ! is_null( $role ) ) {
829
-			$role->add_cap( 'manage_sensei' );
830
-			$role->add_cap( 'manage_sensei_grades' );
828
+		if ( ! is_null($role)) {
829
+			$role->add_cap('manage_sensei');
830
+			$role->add_cap('manage_sensei_grades');
831 831
 		}
832 832
 
833 833
 		return true;
@@ -841,16 +841,16 @@  discard block
 block discarded – undo
841 841
 			'suppress_filters' 	=> 0
842 842
 		);
843 843
 
844
-		$questions = get_posts( $args );
844
+		$questions = get_posts($args);
845 845
 
846
-		foreach( $questions as $question ) {
846
+		foreach ($questions as $question) {
847 847
 
848
-			if( ! isset( $question->ID ) ) continue;
848
+			if ( ! isset($question->ID)) continue;
849 849
 
850
-			$quiz_id = get_post_meta( $question->ID, '_quiz_id', true );
850
+			$quiz_id = get_post_meta($question->ID, '_quiz_id', true);
851 851
 
852
-			$question_order = get_post_meta( $question->ID, '_quiz_question_order', true );
853
-			update_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $question_order );
852
+			$question_order = get_post_meta($question->ID, '_quiz_question_order', true);
853
+			update_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $question_order);
854 854
 
855 855
 		}
856 856
 
@@ -859,15 +859,15 @@  discard block
 block discarded – undo
859 859
 
860 860
 	public function update_quiz_settings() {
861 861
 
862
-		$settings = get_option( 'woothemes-sensei-settings', array() );
862
+		$settings = get_option('woothemes-sensei-settings', array());
863 863
 
864 864
 		$lesson_completion = false;
865
-		if( isset( $settings['lesson_completion'] ) ) {
865
+		if (isset($settings['lesson_completion'])) {
866 866
 			$lesson_completion = $settings['lesson_completion'];
867 867
 		}
868 868
 
869 869
 		$reset_quiz_allowed = false;
870
-		if( isset( $settings['quiz_reset_allowed'] ) ) {
870
+		if (isset($settings['quiz_reset_allowed'])) {
871 871
 			$reset_quiz_allowed = $settings['quiz_reset_allowed'];
872 872
 		}
873 873
 
@@ -878,20 +878,20 @@  discard block
 block discarded – undo
878 878
 			'suppress_filters' 	=> 0
879 879
 		);
880 880
 
881
-		$quizzes = get_posts( $args );
881
+		$quizzes = get_posts($args);
882 882
 
883
-		foreach( $quizzes as $quiz ) {
883
+		foreach ($quizzes as $quiz) {
884 884
 
885
-			if( ! isset( $quiz->ID ) ) continue;
885
+			if ( ! isset($quiz->ID)) continue;
886 886
 
887
-			if( isset( $lesson_completion ) && 'passed' == $lesson_completion ) {
888
-				update_post_meta( $quiz->ID, '_pass_required', 'on' );
887
+			if (isset($lesson_completion) && 'passed' == $lesson_completion) {
888
+				update_post_meta($quiz->ID, '_pass_required', 'on');
889 889
 			} else {
890
-				update_post_meta( $quiz->ID, '_quiz_passmark', 0 );
890
+				update_post_meta($quiz->ID, '_quiz_passmark', 0);
891 891
 			}
892 892
 
893
-			if( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) {
894
-				update_post_meta( $quiz->ID, '_enable_quiz_reset', 'on' );
893
+			if (isset($reset_quiz_allowed) && $reset_quiz_allowed) {
894
+				update_post_meta($quiz->ID, '_enable_quiz_reset', 'on');
895 895
 			}
896 896
 		}
897 897
 
@@ -906,22 +906,22 @@  discard block
 block discarded – undo
906 906
 			'suppress_filters' 	=> 0
907 907
 		);
908 908
 
909
-		$lessons = get_posts( $args );
909
+		$lessons = get_posts($args);
910 910
 
911
-		foreach( $lessons as $lesson ) {
911
+		foreach ($lessons as $lesson) {
912 912
 
913
-			if( ! isset( $lesson->ID ) ) continue;
913
+			if ( ! isset($lesson->ID)) continue;
914 914
 
915
-			$course_id = get_post_meta( $lesson->ID, '_lesson_course', true);
915
+			$course_id = get_post_meta($lesson->ID, '_lesson_course', true);
916 916
 
917
-			if( $course_id ) {
918
-				update_post_meta( $lesson->ID, '_order_' . $course_id, 0 );
917
+			if ($course_id) {
918
+				update_post_meta($lesson->ID, '_order_'.$course_id, 0);
919 919
 			}
920 920
 
921
-            $module = Sensei()->modules->get_lesson_module( $lesson->ID );
921
+            $module = Sensei()->modules->get_lesson_module($lesson->ID);
922 922
 
923
-            if( $module ) {
924
-                update_post_meta( $lesson->ID, '_order_module_' . $module->term_id, 0 );
923
+            if ($module) {
924
+                update_post_meta($lesson->ID, '_order_module_'.$module->term_id, 0);
925 925
             }
926 926
 
927 927
 		}
@@ -930,10 +930,10 @@  discard block
 block discarded – undo
930 930
 	}
931 931
 
932 932
 	public function add_editor_caps() {
933
-		$role = get_role( 'editor' );
933
+		$role = get_role('editor');
934 934
 
935
-		if( ! is_null( $role ) ) {
936
-			$role->add_cap( 'manage_sensei_grades' );
935
+		if ( ! is_null($role)) {
936
+			$role->add_cap('manage_sensei_grades');
937 937
 		}
938 938
 
939 939
 		return true;
@@ -952,26 +952,26 @@  discard block
 block discarded – undo
952 952
 					WHERE m.meta_key = '_question_right_answer' AND m.meta_value LIKE '%|%' AND m.meta_value NOT LIKE '%||%'
953 953
 						AND m.post_id = tr.object_id AND tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = t.term_id
954 954
 						AND tt.taxonomy = 'question-type' AND t.slug = 'gap-fill'";
955
-		$wpdb->query( $sql );
955
+		$wpdb->query($sql);
956 956
 
957 957
 		return true;
958 958
 	}
959 959
 
960
-	public function update_quiz_lesson_relationship( $n = 50, $offset = 0 ) {
961
-		$count_object = wp_count_posts( 'quiz' );
960
+	public function update_quiz_lesson_relationship($n = 50, $offset = 0) {
961
+		$count_object = wp_count_posts('quiz');
962 962
 
963 963
 		$count_published = 0;
964
-		foreach ( $count_object AS $status => $count ) {
964
+		foreach ($count_object AS $status => $count) {
965 965
 			$count_published += $count;
966 966
 		}
967 967
 
968 968
 		// Calculate if this is the last page
969
-		if ( 0 == $offset ) {
969
+		if (0 == $offset) {
970 970
 			$current_page = 1;
971 971
 		} else {
972
-			$current_page = intval( $offset / $n );
972
+			$current_page = intval($offset / $n);
973 973
 		}
974
-		$total_pages = ceil( $count_published / $n );
974
+		$total_pages = ceil($count_published / $n);
975 975
 
976 976
 		$args = array(
977 977
 			'post_type' => 'quiz',
@@ -980,52 +980,52 @@  discard block
 block discarded – undo
980 980
 			'post_status' => 'any'
981 981
 		);
982 982
 
983
-		$quizzes = get_posts( $args );
983
+		$quizzes = get_posts($args);
984 984
 
985
-		foreach( $quizzes as $quiz ) {
985
+		foreach ($quizzes as $quiz) {
986 986
 
987
-			if( ! isset( $quiz->ID ) || 0 != $quiz->post_parent ) continue;
987
+			if ( ! isset($quiz->ID) || 0 != $quiz->post_parent) continue;
988 988
 
989
-			$lesson_id = get_post_meta( $quiz->ID, '_quiz_lesson', true );
989
+			$lesson_id = get_post_meta($quiz->ID, '_quiz_lesson', true);
990 990
 
991
-			if( empty( $lesson_id ) ) continue;
991
+			if (empty($lesson_id)) continue;
992 992
 
993 993
 			$data = array(
994 994
 				'ID' => $quiz->ID,
995 995
 				'post_parent' => $lesson_id,
996 996
 			);
997
-			wp_update_post( $data );
997
+			wp_update_post($data);
998 998
 
999
-			update_post_meta( $lesson_id, '_lesson_quiz', $quiz->ID );
999
+			update_post_meta($lesson_id, '_lesson_quiz', $quiz->ID);
1000 1000
 		}
1001 1001
 
1002
-		if ( $current_page == $total_pages || 0 == $total_pages ) {
1002
+		if ($current_page == $total_pages || 0 == $total_pages) {
1003 1003
 			return true;
1004 1004
 		} else {
1005 1005
 			return false;
1006 1006
 		}
1007 1007
 	}
1008 1008
 
1009
-	function status_changes_fix_lessons( $n = 50, $offset = 0 ) {
1009
+	function status_changes_fix_lessons($n = 50, $offset = 0) {
1010 1010
 		global $wpdb;
1011 1011
 
1012
-		$count_object = wp_count_posts( 'lesson' );
1012
+		$count_object = wp_count_posts('lesson');
1013 1013
 		$count_published = 0;
1014
-		foreach ( $count_object AS $status => $count ) {
1014
+		foreach ($count_object AS $status => $count) {
1015 1015
 			$count_published += $count;
1016 1016
 		}
1017 1017
 
1018
-		if ( 0 == $count_published ) {
1018
+		if (0 == $count_published) {
1019 1019
 			return true;
1020 1020
 		}
1021 1021
 
1022 1022
 		// Calculate if this is the last page
1023
-		if ( 0 == $offset ) {
1023
+		if (0 == $offset) {
1024 1024
 			$current_page = 1;
1025 1025
 		} else {
1026
-			$current_page = intval( $offset / $n );
1026
+			$current_page = intval($offset / $n);
1027 1027
 		}
1028
-		$total_pages = ceil( $count_published / $n );
1028
+		$total_pages = ceil($count_published / $n);
1029 1029
 
1030 1030
 		// Get all Lessons with (and without) Quizzes...
1031 1031
 		$args = array(
@@ -1035,26 +1035,26 @@  discard block
 block discarded – undo
1035 1035
 			'offset' => $offset,
1036 1036
 			'fields' => 'ids'
1037 1037
 		);
1038
-		$lesson_ids = get_posts( $args );
1038
+		$lesson_ids = get_posts($args);
1039 1039
 
1040 1040
 		// ...get all Quiz IDs for the above Lessons
1041
-		$id_list = join( ',', $lesson_ids );
1042
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1041
+		$id_list = join(',', $lesson_ids);
1042
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1043 1043
 		$lesson_quiz_ids = array();
1044
-		if ( !empty($meta_list) ) {
1045
-			foreach ( $meta_list as $metarow ) {
1044
+		if ( ! empty($meta_list)) {
1045
+			foreach ($meta_list as $metarow) {
1046 1046
 				$lesson_id = $metarow['meta_value'];
1047 1047
 				$quiz_id = $metarow['post_id'];
1048
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1048
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1049 1049
 			}
1050 1050
 		}
1051 1051
 
1052 1052
 		// ...check all Quiz IDs for questions
1053
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1054
-		$meta_list = $wpdb->get_results( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A );
1053
+		$id_list = join(',', array_values($lesson_quiz_ids));
1054
+		$meta_list = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_id' AND meta_value IN ($id_list)", ARRAY_A);
1055 1055
 		$lesson_quiz_ids_with_questions = array();
1056
-		if ( !empty($meta_list) ) {
1057
-			foreach ( $meta_list as $metarow ) {
1056
+		if ( ! empty($meta_list)) {
1057
+			foreach ($meta_list as $metarow) {
1058 1058
 				$quiz_id = $metarow['meta_value'];
1059 1059
 				$lesson_quiz_ids_with_questions[] = $quiz_id;
1060 1060
 			}
@@ -1062,49 +1062,49 @@  discard block
 block discarded – undo
1062 1062
 
1063 1063
 		// For each quiz check there are questions, if not remove the corresponding meta keys from Quizzes and Lessons
1064 1064
 		// if there are questions on the quiz add the corresponding meta keys to Quizzes and Lessons
1065
-		$d_count = $a_count =0;
1066
-		foreach ( $lesson_quiz_ids AS $lesson_id => $quiz_id ) {
1067
-			if ( !in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1065
+		$d_count = $a_count = 0;
1066
+		foreach ($lesson_quiz_ids AS $lesson_id => $quiz_id) {
1067
+			if ( ! in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1068 1068
 
1069 1069
 				// Quiz has no questions, drop the corresponding data
1070
-				delete_post_meta( $quiz_id, '_pass_required' );
1071
-				delete_post_meta( $quiz_id, '_quiz_passmark' );
1072
-				delete_post_meta( $lesson_id, '_quiz_has_questions' );
1070
+				delete_post_meta($quiz_id, '_pass_required');
1071
+				delete_post_meta($quiz_id, '_quiz_passmark');
1072
+				delete_post_meta($lesson_id, '_quiz_has_questions');
1073 1073
 				$d_count++;
1074 1074
 			}
1075
-			else if ( in_array( $quiz_id, $lesson_quiz_ids_with_questions ) ) {
1075
+			else if (in_array($quiz_id, $lesson_quiz_ids_with_questions)) {
1076 1076
 
1077 1077
 				// Quiz has no questions, drop the corresponding data
1078
-				update_post_meta( $lesson_id, '_quiz_has_questions', true );
1078
+				update_post_meta($lesson_id, '_quiz_has_questions', true);
1079 1079
 				$a_count++;
1080 1080
 			}
1081 1081
 		}
1082 1082
 
1083
-		if ( $current_page == $total_pages ) {
1083
+		if ($current_page == $total_pages) {
1084 1084
 			return true;
1085 1085
 		} else {
1086 1086
 			return false;
1087 1087
 		}
1088 1088
 	}
1089 1089
 
1090
-	function status_changes_convert_lessons( $n = 50, $offset = 0 ) {
1090
+	function status_changes_convert_lessons($n = 50, $offset = 0) {
1091 1091
 		global $wpdb;
1092 1092
 
1093
-		wp_defer_comment_counting( true );
1093
+		wp_defer_comment_counting(true);
1094 1094
 
1095
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1095
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1096 1096
 
1097
-		if ( 0 == $user_count_result ) {
1097
+		if (0 == $user_count_result) {
1098 1098
 			return true;
1099 1099
 		}
1100 1100
 
1101
-		if ( 0 == $offset ) {
1101
+		if (0 == $offset) {
1102 1102
 			$current_page = 1;
1103 1103
 		} else {
1104
-			$current_page = intval( $offset / $n );
1104
+			$current_page = intval($offset / $n);
1105 1105
 		}
1106 1106
 
1107
-		$total_pages = ceil( $user_count_result / $n );
1107
+		$total_pages = ceil($user_count_result / $n);
1108 1108
 
1109 1109
 		// Get all Lessons with Quizzes...
1110 1110
 		$args = array(
@@ -1119,34 +1119,34 @@  discard block
 block discarded – undo
1119 1119
 			),
1120 1120
 			'fields' => 'ids'
1121 1121
 		);
1122
-		$lesson_ids_with_quizzes = get_posts( $args );
1122
+		$lesson_ids_with_quizzes = get_posts($args);
1123 1123
 		// ...get all Quiz IDs for the above Lessons
1124
-		$id_list = join( ',', $lesson_ids_with_quizzes );
1125
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A );
1124
+		$id_list = join(',', $lesson_ids_with_quizzes);
1125
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_quiz_lesson' AND meta_value IN ($id_list)", ARRAY_A);
1126 1126
 		$lesson_quiz_ids = array();
1127
-		if ( !empty($meta_list) ) {
1128
-			foreach ( $meta_list as $metarow ) {
1127
+		if ( ! empty($meta_list)) {
1128
+			foreach ($meta_list as $metarow) {
1129 1129
 				$lesson_id = $metarow['meta_value'];
1130 1130
 				$quiz_id = $metarow['post_id'];
1131
-				$lesson_quiz_ids[ $lesson_id ] = $quiz_id;
1131
+				$lesson_quiz_ids[$lesson_id] = $quiz_id;
1132 1132
 			}
1133 1133
 		}
1134 1134
 
1135 1135
 		// ...get all Pass Required & Passmarks for the above Lesson/Quizzes
1136
-		$id_list = join( ',', array_values($lesson_quiz_ids) );
1137
-		$meta_list = $wpdb->get_results( "SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A );
1136
+		$id_list = join(',', array_values($lesson_quiz_ids));
1137
+		$meta_list = $wpdb->get_results("SELECT post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE ( meta_key = '_pass_required' OR meta_key = '_quiz_passmark' ) AND post_id IN ($id_list)", ARRAY_A);
1138 1138
 		$quizzes_pass_required = $quizzes_passmarks = array();
1139
-		if ( !empty($meta_list) ) {
1140
-			foreach ( $meta_list as $metarow ) {
1141
-				if ( !empty($metarow['meta_value']) ) {
1139
+		if ( ! empty($meta_list)) {
1140
+			foreach ($meta_list as $metarow) {
1141
+				if ( ! empty($metarow['meta_value'])) {
1142 1142
 					$quiz_id = $metarow['post_id'];
1143 1143
 					$key = $metarow['meta_key'];
1144 1144
 					$value = $metarow['meta_value'];
1145
-					if ( '_pass_required' == $key ) {
1146
-						$quizzes_pass_required[ $quiz_id ] = $value;
1145
+					if ('_pass_required' == $key) {
1146
+						$quizzes_pass_required[$quiz_id] = $value;
1147 1147
 					}
1148
-					if ( '_quiz_passmark' == $key ) {
1149
-						$quizzes_passmarks[ $quiz_id ] = $value;
1148
+					if ('_quiz_passmark' == $key) {
1149
+						$quizzes_passmarks[$quiz_id] = $value;
1150 1150
 					}
1151 1151
 				}
1152 1152
 			}
@@ -1160,41 +1160,41 @@  discard block
 block discarded – undo
1160 1160
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_lesson_status' ";
1161 1161
 
1162 1162
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1163
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1163
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1164 1164
 
1165
-		foreach ( $user_ids AS $user_id ) {
1165
+		foreach ($user_ids AS $user_id) {
1166 1166
 
1167 1167
 			$lesson_ends = $lesson_grades = $lesson_answers = array();
1168 1168
 
1169 1169
 			// Pre-process the lesson ends
1170
-			$_lesson_ends = $wpdb->get_results( $wpdb->prepare($end_sql, $user_id), ARRAY_A );
1171
-			foreach ( $_lesson_ends as $lesson_end ) {
1170
+			$_lesson_ends = $wpdb->get_results($wpdb->prepare($end_sql, $user_id), ARRAY_A);
1171
+			foreach ($_lesson_ends as $lesson_end) {
1172 1172
 				// This will overwrite existing entries with the newer ones
1173
-				$lesson_ends[ $lesson_end['comment_post_ID'] ] = $lesson_end['comment_date'];
1173
+				$lesson_ends[$lesson_end['comment_post_ID']] = $lesson_end['comment_date'];
1174 1174
 			}
1175
-			unset( $_lesson_ends );
1175
+			unset($_lesson_ends);
1176 1176
 
1177 1177
 			// Pre-process the lesson grades
1178
-			$_lesson_grades = $wpdb->get_results( $wpdb->prepare($grade_sql, $user_id), ARRAY_A );
1179
-			foreach ( $_lesson_grades as $lesson_grade ) {
1178
+			$_lesson_grades = $wpdb->get_results($wpdb->prepare($grade_sql, $user_id), ARRAY_A);
1179
+			foreach ($_lesson_grades as $lesson_grade) {
1180 1180
 				// This will overwrite existing entries with the newer ones (assuming the grade is higher)
1181
-				if ( empty($lesson_grades[ $lesson_grade['comment_post_ID'] ]) || $lesson_grades[ $lesson_grade['comment_post_ID'] ] < $lesson_grade['comment_content'] ) {
1182
-					$lesson_grades[ $lesson_grade['comment_post_ID'] ] = $lesson_grade['comment_content'];
1181
+				if (empty($lesson_grades[$lesson_grade['comment_post_ID']]) || $lesson_grades[$lesson_grade['comment_post_ID']] < $lesson_grade['comment_content']) {
1182
+					$lesson_grades[$lesson_grade['comment_post_ID']] = $lesson_grade['comment_content'];
1183 1183
 				}
1184 1184
 			}
1185
-			unset( $_lesson_grades );
1185
+			unset($_lesson_grades);
1186 1186
 
1187 1187
 			// Pre-process the lesson answers
1188
-			$_lesson_answers = $wpdb->get_results( $wpdb->prepare($answers_sql, $user_id), ARRAY_A );
1189
-			foreach ( $_lesson_answers as $lesson_answer ) {
1188
+			$_lesson_answers = $wpdb->get_results($wpdb->prepare($answers_sql, $user_id), ARRAY_A);
1189
+			foreach ($_lesson_answers as $lesson_answer) {
1190 1190
 				// This will overwrite existing entries with the newer ones
1191
-				$lesson_answers[ $lesson_answer['comment_post_ID'] ] = $lesson_answer['comment_content'];
1191
+				$lesson_answers[$lesson_answer['comment_post_ID']] = $lesson_answer['comment_content'];
1192 1192
 			}
1193
-			unset( $_lesson_answers );
1193
+			unset($_lesson_answers);
1194 1194
 
1195 1195
 			// Grab all the lesson starts for the user
1196
-			$lesson_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1197
-			foreach ( $lesson_starts as $lesson_log ) {
1196
+			$lesson_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1197
+			foreach ($lesson_starts as $lesson_log) {
1198 1198
 
1199 1199
 				$lesson_id = $lesson_log['comment_post_ID'];
1200 1200
 
@@ -1207,23 +1207,23 @@  discard block
 block discarded – undo
1207 1207
 					'start' => $status_date,
1208 1208
 				);
1209 1209
 				// Check if there is a lesson end
1210
-				if ( !empty($lesson_ends[$lesson_id]) ) {
1210
+				if ( ! empty($lesson_ends[$lesson_id])) {
1211 1211
 					$status_date = $lesson_ends[$lesson_id];
1212 1212
 					// Check lesson has quiz
1213
-					if ( !empty( $lesson_quiz_ids[$lesson_id] ) ) {
1213
+					if ( ! empty($lesson_quiz_ids[$lesson_id])) {
1214 1214
 						// Check for the quiz answers
1215
-						if ( !empty($lesson_answers[$quiz_id]) ) {
1215
+						if ( ! empty($lesson_answers[$quiz_id])) {
1216 1216
 							$meta_data['questions_asked'] = $lesson_answers[$quiz_id];
1217 1217
 						}
1218 1218
 						// Check if there is a quiz grade
1219 1219
 						$quiz_id = $lesson_quiz_ids[$lesson_id];
1220
-						if ( !empty($lesson_grades[$quiz_id]) ) {
1220
+						if ( ! empty($lesson_grades[$quiz_id])) {
1221 1221
 							$meta_data['grade'] = $quiz_grade = $lesson_grades[$quiz_id];
1222 1222
 							// Check if the user has to get the passmark and has or not
1223
-							if ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] <= $quiz_grade ) {
1223
+							if ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] <= $quiz_grade) {
1224 1224
 								$status = 'passed';
1225 1225
 							}
1226
-							elseif ( !empty( $quizzes_pass_required[$quiz_id] ) && $quizzes_passmarks[$quiz_id] > $quiz_grade ) {
1226
+							elseif ( ! empty($quizzes_pass_required[$quiz_id]) && $quizzes_passmarks[$quiz_id] > $quiz_grade) {
1227 1227
 								$status = 'failed';
1228 1228
 							}
1229 1229
 							else {
@@ -1251,26 +1251,26 @@  discard block
 block discarded – undo
1251 1251
 						'comment_author' => '',
1252 1252
 					);
1253 1253
 				// Check it doesn't already exist
1254
-				$sql = $wpdb->prepare( $check_existing_sql, $lesson_id, $user_id );
1255
-				$comment_ID = $wpdb->get_var( $sql );
1256
-				if ( !$comment_ID ) {
1254
+				$sql = $wpdb->prepare($check_existing_sql, $lesson_id, $user_id);
1255
+				$comment_ID = $wpdb->get_var($sql);
1256
+				if ( ! $comment_ID) {
1257 1257
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1258 1258
 					$wpdb->insert($wpdb->comments, $data);
1259 1259
 					$comment_ID = (int) $wpdb->insert_id;
1260 1260
 
1261
-					if ( $comment_ID && !empty($meta_data) ) {
1262
-						foreach ( $meta_data as $key => $value ) {
1261
+					if ($comment_ID && ! empty($meta_data)) {
1262
+						foreach ($meta_data as $key => $value) {
1263 1263
 							// Bypassing WP add_comment_meta(() so no actions/filters are run
1264
-							if ( $wpdb->get_var( $wpdb->prepare(
1264
+							if ($wpdb->get_var($wpdb->prepare(
1265 1265
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1266
-									$comment_ID, $key ) ) ) {
1266
+									$comment_ID, $key ))) {
1267 1267
 									continue; // Found the meta data already
1268 1268
 							}
1269
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1269
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1270 1270
 								'comment_id' => $comment_ID,
1271 1271
 								'meta_key' => $key,
1272 1272
 								'meta_value' => $value
1273
-							) );
1273
+							));
1274 1274
 						}
1275 1275
 					}
1276 1276
 				}
@@ -1278,40 +1278,40 @@  discard block
 block discarded – undo
1278 1278
 		}
1279 1279
 		$wpdb->flush();
1280 1280
 
1281
-		if ( $current_page == $total_pages ) {
1281
+		if ($current_page == $total_pages) {
1282 1282
 			return true;
1283 1283
 		} else {
1284 1284
 			return false;
1285 1285
 		}
1286 1286
 	}
1287 1287
 
1288
-	function status_changes_convert_courses( $n = 50, $offset = 0 ) {
1288
+	function status_changes_convert_courses($n = 50, $offset = 0) {
1289 1289
 		global $wpdb;
1290 1290
 
1291
-		wp_defer_comment_counting( true );
1291
+		wp_defer_comment_counting(true);
1292 1292
 
1293
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1293
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1294 1294
 
1295
-		if ( 0 == $user_count_result ) {
1295
+		if (0 == $user_count_result) {
1296 1296
 			return true;
1297 1297
 		}
1298 1298
 
1299
-		if ( 0 == $offset ) {
1299
+		if (0 == $offset) {
1300 1300
 			$current_page = 1;
1301 1301
 		} else {
1302
-			$current_page = intval( $offset / $n );
1302
+			$current_page = intval($offset / $n);
1303 1303
 		}
1304 1304
 
1305
-		$total_pages = ceil( $user_count_result / $n );
1305
+		$total_pages = ceil($user_count_result / $n);
1306 1306
 
1307 1307
 		// Get all Lesson => Course relationships
1308
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A );
1308
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course'", ARRAY_A);
1309 1309
 		$course_lesson_ids = array();
1310
-		if ( !empty($meta_list) ) {
1311
-			foreach ( $meta_list as $metarow ) {
1310
+		if ( ! empty($meta_list)) {
1311
+			foreach ($meta_list as $metarow) {
1312 1312
 				$lesson_id = $metarow['post_id'];
1313 1313
 				$course_id = $metarow['meta_value'];
1314
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1314
+				$course_lesson_ids[$course_id][] = $lesson_id;
1315 1315
 			}
1316 1316
 		}
1317 1317
 
@@ -1321,13 +1321,13 @@  discard block
 block discarded – undo
1321 1321
 		$check_existing_sql = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = 'sensei_course_status' ";
1322 1322
 
1323 1323
 		// $per_page users at a time, could be batch run via an admin ajax command, 1 user at a time?
1324
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1324
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1325 1325
 
1326
-		foreach ( $user_ids AS $user_id ) {
1326
+		foreach ($user_ids AS $user_id) {
1327 1327
 
1328 1328
 			// Grab all the course starts for the user
1329
-			$course_starts = $wpdb->get_results( $wpdb->prepare($start_sql, $user_id), ARRAY_A );
1330
-			foreach ( $course_starts as $course_log ) {
1329
+			$course_starts = $wpdb->get_results($wpdb->prepare($start_sql, $user_id), ARRAY_A);
1330
+			foreach ($course_starts as $course_log) {
1331 1331
 
1332 1332
 				$course_id = $course_log['comment_post_ID'];
1333 1333
 
@@ -1342,23 +1342,23 @@  discard block
 block discarded – undo
1342 1342
 					'percent' => 0,
1343 1343
 				);
1344 1344
 				// Check if the course has lessons
1345
-				if ( !empty( $course_lesson_ids[$course_id] ) ) {
1345
+				if ( ! empty($course_lesson_ids[$course_id])) {
1346 1346
 
1347 1347
 					$lessons_completed = 0;
1348
-					$total_lessons = count( $course_lesson_ids[ $course_id ] );
1348
+					$total_lessons = count($course_lesson_ids[$course_id]);
1349 1349
 
1350 1350
 					// Don't use prepare as we need to provide the id join
1351
-					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[ $course_id ]) );
1351
+					$sql = sprintf($lessons_sql, $user_id, join(', ', $course_lesson_ids[$course_id]));
1352 1352
 					// Get all lesson statuses for this Courses' lessons
1353
-					$lesson_statuses = $wpdb->get_results( $sql, ARRAY_A );
1353
+					$lesson_statuses = $wpdb->get_results($sql, ARRAY_A);
1354 1354
 					// Not enough lesson statuses, thus cannot be complete
1355
-					if ( $total_lessons > count($lesson_statuses) ) {
1355
+					if ($total_lessons > count($lesson_statuses)) {
1356 1356
 						$status = 'in-progress';
1357 1357
 					}
1358 1358
 					// Count each lesson to work out the overall percentage
1359
-					foreach ( $lesson_statuses as $lesson_status ) {
1359
+					foreach ($lesson_statuses as $lesson_status) {
1360 1360
 						$status_date = $lesson_status['comment_date'];
1361
-						switch ( $lesson_status['status'] ) {
1361
+						switch ($lesson_status['status']) {
1362 1362
 							case 'complete': // Lesson has no quiz/questions
1363 1363
 							case 'graded': // Lesson has quiz, but it's not important what the grade was
1364 1364
 							case 'passed':
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 						}
1374 1374
 					}
1375 1375
 					$meta_data['complete'] = $lessons_completed;
1376
-					$meta_data['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1376
+					$meta_data['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1377 1377
 				}
1378 1378
 				else {
1379 1379
 					// Course has no lessons, therefore cannot be 'complete'
@@ -1390,26 +1390,26 @@  discard block
 block discarded – undo
1390 1390
 						'comment_author' => '',
1391 1391
 					);
1392 1392
 				// Check it doesn't already exist
1393
-				$sql = $wpdb->prepare( $check_existing_sql, $course_id, $user_id );
1394
-				$comment_ID = $wpdb->get_var( $sql );
1395
-				if ( !$comment_ID ) {
1393
+				$sql = $wpdb->prepare($check_existing_sql, $course_id, $user_id);
1394
+				$comment_ID = $wpdb->get_var($sql);
1395
+				if ( ! $comment_ID) {
1396 1396
 					// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1397 1397
 					$wpdb->insert($wpdb->comments, $data);
1398 1398
 					$comment_ID = (int) $wpdb->insert_id;
1399 1399
 
1400
-					if ( $comment_ID && !empty($meta_data) ) {
1401
-						foreach ( $meta_data as $key => $value ) {
1400
+					if ($comment_ID && ! empty($meta_data)) {
1401
+						foreach ($meta_data as $key => $value) {
1402 1402
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1403
-							if ( $wpdb->get_var( $wpdb->prepare(
1403
+							if ($wpdb->get_var($wpdb->prepare(
1404 1404
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1405
-									$comment_ID, $key ) ) ) {
1405
+									$comment_ID, $key ))) {
1406 1406
 									continue; // Found the meta data already
1407 1407
 							}
1408
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1408
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1409 1409
 								'comment_id' => $comment_ID,
1410 1410
 								'meta_key' => $key,
1411 1411
 								'meta_value' => $value
1412
-							) );
1412
+							));
1413 1413
 						}
1414 1414
 					}
1415 1415
 				}
@@ -1417,7 +1417,7 @@  discard block
 block discarded – undo
1417 1417
 		}
1418 1418
 		$wpdb->flush();
1419 1419
 
1420
-		if ( $current_page == $total_pages ) {
1420
+		if ($current_page == $total_pages) {
1421 1421
 			return true;
1422 1422
 		} else {
1423 1423
 			return false;
@@ -1433,70 +1433,70 @@  discard block
 block discarded – undo
1433 1433
 	 * @param type $offset
1434 1434
 	 * @return boolean
1435 1435
 	 */
1436
-	function status_changes_repair_course_statuses( $n = 50, $offset = 0 ) {
1436
+	function status_changes_repair_course_statuses($n = 50, $offset = 0) {
1437 1437
 		global $wpdb;
1438 1438
 
1439
-		$count_object = wp_count_posts( 'lesson' );
1439
+		$count_object = wp_count_posts('lesson');
1440 1440
 		$count_published = $count_object->publish;
1441 1441
 
1442
-		if ( 0 == $count_published ) {
1442
+		if (0 == $count_published) {
1443 1443
 			return true;
1444 1444
 		}
1445 1445
 
1446 1446
 		// Calculate if this is the last page
1447
-		if ( 0 == $offset ) {
1447
+		if (0 == $offset) {
1448 1448
 			$current_page = 1;
1449 1449
 		} else {
1450
-			$current_page = intval( $offset / $n );
1450
+			$current_page = intval($offset / $n);
1451 1451
 		}
1452
-		$total_pages = ceil( $count_published / $n );
1452
+		$total_pages = ceil($count_published / $n);
1453 1453
 
1454 1454
 		$course_lesson_ids = $lesson_user_statuses = array();
1455 1455
 
1456 1456
 		// Get all Lesson => Course relationships
1457
-		$meta_list = $wpdb->get_results( "SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A );
1458
-		if ( !empty($meta_list) ) {
1459
-			foreach ( $meta_list as $metarow ) {
1457
+		$meta_list = $wpdb->get_results("SELECT $wpdb->postmeta.post_id, $wpdb->postmeta.meta_value FROM $wpdb->postmeta INNER JOIN $wpdb->posts ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE $wpdb->posts.post_type = 'lesson' AND $wpdb->postmeta.meta_key = '_lesson_course' LIMIT $n OFFSET $offset ", ARRAY_A);
1458
+		if ( ! empty($meta_list)) {
1459
+			foreach ($meta_list as $metarow) {
1460 1460
 				$lesson_id = $metarow['post_id'];
1461 1461
 				$course_id = $metarow['meta_value'];
1462
-				$course_lesson_ids[ $course_id ][] = $lesson_id;
1462
+				$course_lesson_ids[$course_id][] = $lesson_id;
1463 1463
 			}
1464 1464
 		}
1465 1465
 
1466 1466
 		// Get all Lesson => Course relationships
1467
-		$status_list = $wpdb->get_results( "SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A );
1468
-		if ( !empty($status_list) ) {
1469
-			foreach ( $status_list as $status ) {
1470
-				$lesson_user_statuses[ $status['comment_post_ID'] ][ $status['user_id'] ] = $status['comment_approved'];
1467
+		$status_list = $wpdb->get_results("SELECT user_id, comment_post_ID, comment_approved FROM $wpdb->comments WHERE comment_type = 'sensei_lesson_status' GROUP BY user_id, comment_post_ID ", ARRAY_A);
1468
+		if ( ! empty($status_list)) {
1469
+			foreach ($status_list as $status) {
1470
+				$lesson_user_statuses[$status['comment_post_ID']][$status['user_id']] = $status['comment_approved'];
1471 1471
 			}
1472 1472
 		}
1473 1473
 
1474
-		$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1474
+		$course_completion = Sensei()->settings->settings['course_completion'];
1475 1475
 
1476 1476
 		$per_page = 40;
1477 1477
 		$comment_id_offset = $count = 0;
1478 1478
 
1479 1479
 		$course_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_course_status' AND comment_ID > %d LIMIT $per_page";
1480 1480
 		// $per_page users at a time
1481
-		while ( $course_statuses = $wpdb->get_results( $wpdb->prepare($course_sql, $comment_id_offset) ) ) {
1481
+		while ($course_statuses = $wpdb->get_results($wpdb->prepare($course_sql, $comment_id_offset))) {
1482 1482
 
1483
-			foreach ( $course_statuses AS $course_status ) {
1483
+			foreach ($course_statuses AS $course_status) {
1484 1484
 				$user_id = $course_status->user_id;
1485 1485
 				$course_id = $course_status->comment_post_ID;
1486
-				$total_lessons = count( $course_lesson_ids[ $course_id ] );
1487
-				if ( $total_lessons <= 0 ) {
1486
+				$total_lessons = count($course_lesson_ids[$course_id]);
1487
+				if ($total_lessons <= 0) {
1488 1488
 					$total_lessons = 1; // Fix division of zero error, some courses have no lessons
1489 1489
 				}
1490 1490
 				$lessons_completed = 0;
1491 1491
 				$status = 'in-progress';
1492 1492
 
1493 1493
 				// Some Courses have no lessons... (can they ever be complete?)
1494
-				if ( !empty($course_lesson_ids[ $course_id ]) ) {
1495
-					foreach( $course_lesson_ids[ $course_id ] AS $lesson_id ) {
1496
-						$lesson_status = $lesson_user_statuses[ $lesson_id ][ $user_id ];
1494
+				if ( ! empty($course_lesson_ids[$course_id])) {
1495
+					foreach ($course_lesson_ids[$course_id] AS $lesson_id) {
1496
+						$lesson_status = $lesson_user_statuses[$lesson_id][$user_id];
1497 1497
 						// If lessons are complete without needing quizzes to be passed
1498
-						if ( 'passed' != $course_completion ) {
1499
-							switch ( $lesson_status ) {
1498
+						if ('passed' != $course_completion) {
1499
+							switch ($lesson_status) {
1500 1500
 								// A user cannot 'complete' a course if a lesson...
1501 1501
 								case 'in-progress': // ...is still in progress
1502 1502
 								case 'ungraded': // ...hasn't yet been graded
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 							}
1509 1509
 						}
1510 1510
 						else {
1511
-							switch ( $lesson_status ) {
1511
+							switch ($lesson_status) {
1512 1512
 								case 'complete': // Lesson has no quiz/questions
1513 1513
 								case 'graded': // Lesson has quiz, but it's not important what the grade was
1514 1514
 								case 'passed': // Lesson has quiz and the user passed
@@ -1523,79 +1523,79 @@  discard block
 block discarded – undo
1523 1523
 						}
1524 1524
 					} // Each lesson
1525 1525
 				} // Check for lessons
1526
-				if ( $lessons_completed == $total_lessons ) {
1526
+				if ($lessons_completed == $total_lessons) {
1527 1527
 					$status = 'complete';
1528 1528
 				}
1529 1529
 				// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1530 1530
 				$metadata = array(
1531 1531
 					'complete' => $lessons_completed,
1532
-					'percent' => abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) ),
1532
+					'percent' => abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0)),
1533 1533
 				);
1534
-				Sensei_Utils::update_course_status( $user_id, $course_id, $status, $metadata );
1534
+				Sensei_Utils::update_course_status($user_id, $course_id, $status, $metadata);
1535 1535
 				$count++;
1536 1536
 
1537 1537
 			} // per course status
1538 1538
 			$comment_id_offset = $course_status->comment_ID;
1539 1539
 		} // all course statuses
1540 1540
 
1541
-		if ( $current_page == $total_pages ) {
1541
+		if ($current_page == $total_pages) {
1542 1542
 			return true;
1543 1543
 		} else {
1544 1544
 			return false;
1545 1545
 		}
1546 1546
 	}
1547 1547
 
1548
-	function status_changes_convert_questions( $n = 50, $offset = 0 ) {
1548
+	function status_changes_convert_questions($n = 50, $offset = 0) {
1549 1549
 		global $wpdb;
1550 1550
 
1551
-		wp_defer_comment_counting( true );
1551
+		wp_defer_comment_counting(true);
1552 1552
 
1553
-		$user_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users " );
1553
+		$user_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users ");
1554 1554
 
1555
-		if ( 0 == $user_count_result ) {
1555
+		if (0 == $user_count_result) {
1556 1556
 			return true;
1557 1557
 		}
1558 1558
 
1559 1559
 		// Calculate if this is the last page
1560
-		if ( 0 == $offset ) {
1560
+		if (0 == $offset) {
1561 1561
 			$current_page = 1;
1562 1562
 		} else {
1563
-			$current_page = intval( $offset / $n );
1563
+			$current_page = intval($offset / $n);
1564 1564
 		}
1565 1565
 
1566
-		$total_pages = ceil( $user_count_result / $n );
1566
+		$total_pages = ceil($user_count_result / $n);
1567 1567
 
1568 1568
 		$users_sql = "SELECT ID FROM $wpdb->users ORDER BY ID ASC LIMIT %d OFFSET %d";
1569 1569
 		$answers_sql = "SELECT * FROM $wpdb->comments WHERE comment_type = 'sensei_user_answer' AND user_id = %d GROUP BY comment_post_ID ";
1570 1570
 		$grades_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_user_grade' AND user_id = %d GROUP BY comment_post_ID ";
1571 1571
 		$notes_sql = "SELECT comment_post_ID, comment_content FROM $wpdb->comments WHERE comment_type = 'sensei_answer_notes' AND user_id = %d GROUP BY comment_post_ID ";
1572 1572
 
1573
-		$user_ids = $wpdb->get_col( $wpdb->prepare($users_sql, $n, $offset) );
1573
+		$user_ids = $wpdb->get_col($wpdb->prepare($users_sql, $n, $offset));
1574 1574
 
1575
-		foreach ( $user_ids AS $user_id ) {
1575
+		foreach ($user_ids AS $user_id) {
1576 1576
 
1577 1577
 			$answer_grades = $answer_notes = array();
1578 1578
 
1579 1579
 			// Pre-process the answer grades
1580
-			$_answer_grades = $wpdb->get_results( $wpdb->prepare($grades_sql, $user_id), ARRAY_A );
1581
-			foreach ( $_answer_grades as $answer_grade ) {
1580
+			$_answer_grades = $wpdb->get_results($wpdb->prepare($grades_sql, $user_id), ARRAY_A);
1581
+			foreach ($_answer_grades as $answer_grade) {
1582 1582
 				// This will overwrite existing entries with the newer ones
1583
-				$answer_grades[ $answer_grade['comment_post_ID'] ] = $answer_grade['comment_content'];
1583
+				$answer_grades[$answer_grade['comment_post_ID']] = $answer_grade['comment_content'];
1584 1584
 			}
1585
-			unset( $_answer_grades );
1585
+			unset($_answer_grades);
1586 1586
 
1587 1587
 			// Pre-process the answer notes
1588
-			$_answer_notes = $wpdb->get_results( $wpdb->prepare($notes_sql, $user_id), ARRAY_A );
1589
-			foreach ( $_answer_notes as $answer_note ) {
1588
+			$_answer_notes = $wpdb->get_results($wpdb->prepare($notes_sql, $user_id), ARRAY_A);
1589
+			foreach ($_answer_notes as $answer_note) {
1590 1590
 				// This will overwrite existing entries with the newer ones
1591
-				$answer_notes[ $answer_note['comment_post_ID'] ] = $answer_note['comment_content'];
1591
+				$answer_notes[$answer_note['comment_post_ID']] = $answer_note['comment_content'];
1592 1592
 			}
1593
-			unset( $_answer_notes );
1593
+			unset($_answer_notes);
1594 1594
 
1595 1595
 			// Grab all the questions for the user
1596 1596
 			$sql = $wpdb->prepare($answers_sql, $user_id);
1597
-			$answers = $wpdb->get_results( $sql, ARRAY_A );
1598
-			foreach ( $answers as $answer ) {
1597
+			$answers = $wpdb->get_results($sql, ARRAY_A);
1598
+			foreach ($answers as $answer) {
1599 1599
 
1600 1600
 				// Excape data
1601 1601
 				$answer = wp_slash($answer);
@@ -1605,12 +1605,12 @@  discard block
 block discarded – undo
1605 1605
 				$meta_data = array();
1606 1606
 
1607 1607
 				// Check if the question has been graded, add as meta
1608
-				if ( !empty($answer_grades[ $answer['comment_post_ID'] ]) ) {
1609
-					$meta_data['user_grade'] = $answer_grades[ $answer['comment_post_ID'] ];
1608
+				if ( ! empty($answer_grades[$answer['comment_post_ID']])) {
1609
+					$meta_data['user_grade'] = $answer_grades[$answer['comment_post_ID']];
1610 1610
 				}
1611 1611
 				// Check if there is an answer note, add as meta
1612
-				if ( !empty($answer_notes[ $answer['comment_post_ID'] ]) ) {
1613
-					$meta_data['answer_note'] = $answer_notes[ $answer['comment_post_ID'] ];
1612
+				if ( ! empty($answer_notes[$answer['comment_post_ID']])) {
1613
+					$meta_data['answer_note'] = $answer_notes[$answer['comment_post_ID']];
1614 1614
 				}
1615 1615
 
1616 1616
 				// Wipe the unnessary data from the main comment
@@ -1623,21 +1623,21 @@  discard block
 block discarded – undo
1623 1623
 					);
1624 1624
 				$data = array_merge($answer, $data);
1625 1625
 
1626
-				$rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
1627
-				if ( $rval ) {
1628
-					if ( !empty($meta_data) ) {
1629
-						foreach ( $meta_data as $key => $value ) {
1626
+				$rval = $wpdb->update($wpdb->comments, $data, compact('comment_ID'));
1627
+				if ($rval) {
1628
+					if ( ! empty($meta_data)) {
1629
+						foreach ($meta_data as $key => $value) {
1630 1630
 							// Bypassing WP wp_insert_comment( $data ), so no actions/filters are run
1631
-							if ( $wpdb->get_var( $wpdb->prepare(
1631
+							if ($wpdb->get_var($wpdb->prepare(
1632 1632
 									"SELECT COUNT(*) FROM $wpdb->commentmeta WHERE comment_id = %d AND meta_key = %s ",
1633
-									$comment_ID, $key ) ) ) {
1633
+									$comment_ID, $key ))) {
1634 1634
 									continue; // Found the meta data already
1635 1635
 							}
1636
-							$result = $wpdb->insert( $wpdb->commentmeta, array(
1636
+							$result = $wpdb->insert($wpdb->commentmeta, array(
1637 1637
 								'comment_id' => $comment_ID,
1638 1638
 								'meta_key' => $key,
1639 1639
 								'meta_value' => $value
1640
-							) );
1640
+							));
1641 1641
 						}
1642 1642
 					}
1643 1643
 				}
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
 		}
1646 1646
 		$wpdb->flush();
1647 1647
 
1648
-		if ( $current_page == $total_pages ) {
1648
+		if ($current_page == $total_pages) {
1649 1649
 			return true;
1650 1650
 		} else {
1651 1651
 			return false;
@@ -1662,10 +1662,10 @@  discard block
 block discarded – undo
1662 1662
 		global $wpdb;
1663 1663
 
1664 1664
 		// Update 'sensei_user_answer' entries to use comment_approved = 'log' so they don't appear in counts
1665
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' " );
1665
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'log' WHERE comment_type = 'sensei_user_answer' ");
1666 1666
 
1667 1667
 		// Mark all old Sensei comment types with comment_approved = 'legacy' so they no longer appear in counts, but can be restored if required
1668
-		$wpdb->query( "UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') " );
1668
+		$wpdb->query("UPDATE $wpdb->comments SET comment_approved = 'legacy' WHERE comment_type IN ('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_answer_notes', 'sensei_quiz_grade') ");
1669 1669
 
1670 1670
 		return true;
1671 1671
 	}
@@ -1678,50 +1678,50 @@  discard block
 block discarded – undo
1678 1678
 	 * @param type $offset
1679 1679
 	 * @return boolean
1680 1680
 	 */
1681
-	public function update_comment_course_lesson_comment_counts( $n = 50, $offset = 0 ) {
1681
+	public function update_comment_course_lesson_comment_counts($n = 50, $offset = 0) {
1682 1682
 		global $wpdb;
1683 1683
 
1684
-		$item_count_result = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') " );
1684
+		$item_count_result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') ");
1685 1685
 
1686
-		if ( 0 == $item_count_result ) {
1686
+		if (0 == $item_count_result) {
1687 1687
 			return true;
1688 1688
 		}
1689 1689
 
1690 1690
 		// Calculate if this is the last page
1691
-		if ( 0 == $offset ) {
1691
+		if (0 == $offset) {
1692 1692
 			$current_page = 1;
1693 1693
 		} else {
1694
-			$current_page = intval( $offset / $n );
1694
+			$current_page = intval($offset / $n);
1695 1695
 		}
1696 1696
 
1697
-		$total_pages = ceil( $item_count_result / $n );
1697
+		$total_pages = ceil($item_count_result / $n);
1698 1698
 
1699 1699
 		// Recalculate all counts
1700
-		$items = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset ) );
1701
-		foreach ( (array) $items as $post ) {
1700
+		$items = $wpdb->get_results($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type IN ('course', 'lesson') LIMIT %d OFFSET %d", $n, $offset));
1701
+		foreach ((array) $items as $post) {
1702 1702
 			// Code copied from wp_update_comment_count_now()
1703
-			$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID) );
1704
-			$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID) );
1703
+			$new = (int) $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post->ID));
1704
+			$wpdb->update($wpdb->posts, array('comment_count' => $new), array('ID' => $post->ID));
1705 1705
 
1706
-			clean_post_cache( $post->ID );
1706
+			clean_post_cache($post->ID);
1707 1707
 		}
1708 1708
 
1709
-		if ( $current_page == $total_pages ) {
1709
+		if ($current_page == $total_pages) {
1710 1710
 			return true;
1711 1711
 		} else {
1712 1712
 			return false;
1713 1713
 		}
1714 1714
 	}
1715 1715
 
1716
-	public function remove_legacy_comments () {
1716
+	public function remove_legacy_comments() {
1717 1717
 		global $wpdb;
1718 1718
 
1719
-		$result = $wpdb->delete( $wpdb->comments, array( 'comment_approved' => 'legacy' ) );
1719
+		$result = $wpdb->delete($wpdb->comments, array('comment_approved' => 'legacy'));
1720 1720
 
1721 1721
 		return true;
1722 1722
 	}
1723 1723
 
1724
-	public function index_comment_status_field () {
1724
+	public function index_comment_status_field() {
1725 1725
 		global $wpdb;
1726 1726
 
1727 1727
 		$wpdb->query("ALTER TABLE `$wpdb->comments` ADD INDEX `comment_type` ( `comment_type` )");
@@ -1740,7 +1740,7 @@  discard block
 block discarded – undo
1740 1740
      * @since 1.8.0
1741 1741
      * @return bool;
1742 1742
      */
1743
-    public  function enhance_teacher_role ( ) {
1743
+    public  function enhance_teacher_role( ) {
1744 1744
 
1745 1745
         require_once('class-sensei-teacher.php');
1746 1746
         $teacher = new Sensei_Teacher();
Please login to merge, or discard this patch.
includes/class-sensei-lesson.php 1 patch
Indentation   +1018 added lines, -1018 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 	 */
23 23
 	public function __construct () {
24 24
 
25
-        $this->token = 'lesson';
25
+		$this->token = 'lesson';
26 26
 
27 27
 		// Setup meta fields for this post type
28 28
 		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
29 29
 
30
-        $this->question_order = '';
30
+		$this->question_order = '';
31 31
 
32 32
 		// Admin actions
33 33
 		if ( is_admin() ) {
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
 			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
86 86
 			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
87 87
 
88
-            // output bulk edit fields
89
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
90
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
88
+			// output bulk edit fields
89
+			add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
90
+			add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
91 91
 
92
-            // load quick edit default values
93
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
92
+			// load quick edit default values
93
+			add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
94 94
 
95
-            // save bulk edit fields
96
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
95
+			// save bulk edit fields
96
+			add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
97 97
 
98
-            // flush rewrite rules when saving a lesson
99
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
98
+			// flush rewrite rules when saving a lesson
99
+			add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
100 100
 
101 101
 		} else {
102 102
 			// Frontend actions
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 		$post_args = array(	'post_type' 		=> 'lesson',
191 191
 							'posts_per_page' 		=> -1,
192 192
 							'orderby'         	=> 'title',
193
-    						'order'           	=> 'ASC',
194
-    						'exclude' 			=> $post->ID,
193
+							'order'           	=> 'ASC',
194
+							'exclude' 			=> $post->ID,
195 195
 							'suppress_filters' 	=> 0
196 196
 							);
197 197
 		$posts_array = get_posts( $post_args );
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
 		$checked = '';
229 229
 		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
230
-	 	    $checked = checked( 'preview', $lesson_preview, false );
230
+	 		$checked = checked( 'preview', $lesson_preview, false );
231 231
 	 	} // End If Statement
232 232
 
233 233
 	 	$html .= '<label for="lesson_preview">';
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 
277 277
 
278 278
 	/**
279
-     * Update the lesson quiz and all the post meta
279
+	 * Update the lesson quiz and all the post meta
280 280
 	 *
281 281
 	 * @access public
282 282
 	 * @return void
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		}
298 298
 
299 299
 		// Temporarily disable the filter
300
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
300
+		remove_action( 'save_post', array( $this, 'quiz_update' ) );
301 301
 		// Save the Quiz
302 302
 		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
303 303
 
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
 
313 313
 		// Setup Query Arguments
314 314
 		$post_type_args = array(	'post_content' => $post_content,
315
-  		    						'post_status' => $post_status,
316
-  		    						'post_title' => $post_title,
317
-  		    						'post_type' => 'quiz',
318
-                                    'post_parent' => $post_id,
319
-  		    						);
315
+  									'post_status' => $post_status,
316
+  									'post_title' => $post_title,
317
+  									'post_type' => 'quiz',
318
+									'post_parent' => $post_id,
319
+  									);
320 320
 
321 321
 		$settings = $this->get_quiz_settings();
322 322
 
@@ -324,48 +324,48 @@  discard block
 block discarded – undo
324 324
 		if ( 0 < $quiz_id ) {
325 325
 			// Update the Quiz
326 326
 			$post_type_args[ 'ID' ] = $quiz_id;
327
-		    wp_update_post($post_type_args);
328
-
329
-		    // Update the post meta data
330
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
331
-
332
-		    foreach( $settings as $field ) {
333
-		    	if( 'random_question_order' != $field['id'] ) {
334
-			    	$value = $this->get_submitted_setting_value( $field );
335
-			    	if( isset( $value ) ) {
336
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
337
-			    	}
338
-			    }
339
-		    }
340
-
341
-		    // Set the post terms for quiz-type
342
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
327
+			wp_update_post($post_type_args);
328
+
329
+			// Update the post meta data
330
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
331
+
332
+			foreach( $settings as $field ) {
333
+				if( 'random_question_order' != $field['id'] ) {
334
+					$value = $this->get_submitted_setting_value( $field );
335
+					if( isset( $value ) ) {
336
+						update_post_meta( $quiz_id, '_' . $field['id'], $value );
337
+					}
338
+				}
339
+			}
340
+
341
+			// Set the post terms for quiz-type
342
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
343 343
 		} else {
344 344
 			// Create the Quiz
345
-		    $quiz_id = wp_insert_post($post_type_args);
346
-
347
-		    // Add the post meta data WP will add it if it doesn't exist
348
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
349
-
350
-		    foreach( $settings as $field ) {
351
-		    	if( 'random_question_order' != $field['id'] ) {
352
-
353
-                    //ignore values not posted to avoid
354
-                    // overwriting with empty or default values
355
-                    // when the values are posted from bulk edit or quick edit
356
-                    if( !isset( $_POST[ $field['id'] ] ) ){
357
-                        continue;
358
-                    }
359
-
360
-			    	$value = $this->get_submitted_setting_value( $field );
361
-			    	if( isset( $value ) ) {
362
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
363
-			    	}
364
-			    }
365
-		    }
366
-
367
-		    // Set the post terms for quiz-type
368
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
345
+			$quiz_id = wp_insert_post($post_type_args);
346
+
347
+			// Add the post meta data WP will add it if it doesn't exist
348
+			update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
349
+
350
+			foreach( $settings as $field ) {
351
+				if( 'random_question_order' != $field['id'] ) {
352
+
353
+					//ignore values not posted to avoid
354
+					// overwriting with empty or default values
355
+					// when the values are posted from bulk edit or quick edit
356
+					if( !isset( $_POST[ $field['id'] ] ) ){
357
+						continue;
358
+					}
359
+
360
+					$value = $this->get_submitted_setting_value( $field );
361
+					if( isset( $value ) ) {
362
+						add_post_meta( $quiz_id, '_' . $field['id'], $value );
363
+					}
364
+				}
365
+			}
366
+
367
+			// Set the post terms for quiz-type
368
+			wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
369 369
 		} // End If Statement
370 370
 
371 371
 		// Add default lesson order meta value
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 		}
388 388
 
389 389
 		// Restore the previously disabled filter
390
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
390
+		add_action( 'save_post', array( $this, 'quiz_update' ) );
391 391
 
392 392
 	} // End post_updated()
393 393
 
@@ -427,22 +427,22 @@  discard block
 block discarded – undo
427 427
 		// Get the meta key.
428 428
 		$meta_key = '_' . $post_key;
429 429
 
430
-        //ignore fields are not posted
430
+		//ignore fields are not posted
431 431
 
432
-        if( !isset( $_POST[ $post_key ] ) ){
432
+		if( !isset( $_POST[ $post_key ] ) ){
433 433
 
434
-            // except for lesson preview checkbox field
435
-            if( 'lesson_preview' == $post_key ){
434
+			// except for lesson preview checkbox field
435
+			if( 'lesson_preview' == $post_key ){
436 436
 
437
-                $_POST[ $post_key ] = '';
437
+				$_POST[ $post_key ] = '';
438 438
 
439
-            } else {
439
+			} else {
440 440
 
441
-                return false;
441
+				return false;
442 442
 
443
-            }
443
+			}
444 444
 
445
-        }
445
+		}
446 446
 
447 447
 		// Get the posted data and sanitize it for use as an HTML class.
448 448
 		if ( 'lesson_video_embed' == $post_key) {
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
 			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
452 452
 		} // End If Statement
453 453
 
454
-        // update field with the new value
455
-        if( -1 != $new_meta_value  ){
456
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
457
-        }
454
+		// update field with the new value
455
+		if( -1 != $new_meta_value  ){
456
+			return update_post_meta( $post_id, $meta_key, $new_meta_value );
457
+		}
458 458
 
459 459
 	} // End save_post_meta()
460 460
 
@@ -479,9 +479,9 @@  discard block
 block discarded – undo
479 479
 		$post_args = array(	'post_type' 		=> 'course',
480 480
 							'posts_per_page' 		=> -1,
481 481
 							'orderby'         	=> 'title',
482
-    						'order'           	=> 'ASC',
483
-    						'post_status'      	=> 'any',
484
-    						'suppress_filters' 	=> 0,
482
+							'order'           	=> 'ASC',
483
+							'post_status'      	=> 'any',
484
+							'suppress_filters' 	=> 0,
485 485
 							);
486 486
 		$posts_array = get_posts( $post_args );
487 487
 		// Buid the HTML to Output
@@ -489,20 +489,20 @@  discard block
 block discarded – undo
489 489
 		// Nonce
490 490
 		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
491 491
 
492
-        // Select the course for the lesson
493
-        $drop_down_args = array(
494
-            'name'=>'lesson_course',
495
-            'id' => 'lesson-course-options'
496
-        );
492
+		// Select the course for the lesson
493
+		$drop_down_args = array(
494
+			'name'=>'lesson_course',
495
+			'id' => 'lesson-course-options'
496
+		);
497 497
 
498
-        $courses = WooThemes_Sensei_Course::get_all_courses();
499
-        $courses_options = array();
500
-        foreach( $courses as $course ){
501
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
502
-        }
503
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
498
+		$courses = WooThemes_Sensei_Course::get_all_courses();
499
+		$courses_options = array();
500
+		foreach( $courses as $course ){
501
+			$courses_options[ $course->ID ] = get_the_title( $course ) ;
502
+		}
503
+		$html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
504 504
 
505
-        // Course Actions Panel
505
+		// Course Actions Panel
506 506
 		if ( current_user_can( 'publish_courses' )) {
507 507
 				$html .= '<div id="lesson-course-actions">';
508 508
 					$html .= '<p>';
@@ -528,16 +528,16 @@  discard block
 block discarded – undo
528 528
 							} // End For Loop
529 529
 						$html .= '</select>' . "\n";
530 530
 						// Course Product
531
-                        if ( Sensei_WC::is_woocommerce_active() ) {
531
+						if ( Sensei_WC::is_woocommerce_active() ) {
532 532
 	  						// Get the Products
533 533
 							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
534 534
 
535 535
 							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
536 536
 													'posts_per_page' 		=> -1,
537 537
 													'orderby'         	=> 'title',
538
-	    											'order'           	=> 'DESC',
539
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
540
-	    											'tax_query'			=> array(
538
+													'order'           	=> 'DESC',
539
+													'post_status'		=> array( 'publish', 'private', 'draft' ),
540
+													'tax_query'			=> array(
541 541
 														array(
542 542
 															'taxonomy'	=> 'product_type',
543 543
 															'field'		=> 'slug',
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
 															'operator'	=> 'NOT IN'
546 546
 														)
547 547
 													),
548
-	    											'suppress_filters' 	=> 0
548
+													'suppress_filters' 	=> 0
549 549
 													);
550 550
 							$products_array = get_posts( $product_args );
551 551
 							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
@@ -873,58 +873,58 @@  discard block
 block discarded – undo
873 873
 					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
874 874
 						$html .= '<td colspan="5">';
875 875
 							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
876
-					    	$html .= '<div class="question_required_fields">';
877
-
878
-						    	// Question title
879
-						    	$html .= '<div>';
880
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
881
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
882
-						    	$html .= '</div>';
883
-
884
-						    	// Question description
885
-						    	$html .= '<div>';
886
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
887
-						    	$html .= '</div>';
888
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
889
-
890
-						    	// Question grade
891
-						    	$html .= '<div>';
892
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
893
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
894
-						    	$html .= '</div>';
895
-
896
-						    	// Random order
897
-						    	if( $question_type == 'multiple-choice' ) {
898
-						    		$html .= '<div>';
899
-						    			$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>';
900
-						    		$html .= '</div>';
901
-						    	}
902
-
903
-						    	// Question media
904
-						    	$html .= '<div>';
905
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
906
-							    	$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>';
907
-							    	$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/>';
908
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
909
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
910
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
911
-						    	$html .= '</div>';
912
-
913
-						    $html .= '</div>';
914
-
915
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
916
-
917
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
876
+							$html .= '<div class="question_required_fields">';
877
+
878
+								// Question title
879
+								$html .= '<div>';
880
+									$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
881
+									$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
882
+								$html .= '</div>';
883
+
884
+								// Question description
885
+								$html .= '<div>';
886
+									$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
887
+								$html .= '</div>';
888
+									$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
889
+
890
+								// Question grade
891
+								$html .= '<div>';
892
+									$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
893
+									$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
894
+								$html .= '</div>';
895
+
896
+								// Random order
897
+								if( $question_type == 'multiple-choice' ) {
898
+									$html .= '<div>';
899
+										$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>';
900
+									$html .= '</div>';
901
+								}
902
+
903
+								// Question media
904
+								$html .= '<div>';
905
+									$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
906
+									$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>';
907
+									$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/>';
908
+									$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
909
+									$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
910
+									$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
911
+								$html .= '</div>';
912
+
913
+							$html .= '</div>';
914
+
915
+							$html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
916
+
917
+							$html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
918 918
 							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
919 919
 
920 920
 							if( 'quiz' == $context ) {
921
-					    		$html .= '<div class="update-question">';
922
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
923
-						    		$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>';
924
-					    		$html .= '</div>';
925
-					    	}
921
+								$html .= '<div class="update-question">';
922
+									$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
923
+									$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>';
924
+								$html .= '</div>';
925
+							}
926 926
 
927
-			    		$html .= '</td>';
927
+						$html .= '</td>';
928 928
 					$html .= '</tr>';
929 929
 				}
930 930
 
@@ -945,20 +945,20 @@  discard block
 block discarded – undo
945 945
 			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
946 946
 
947 947
 			if( 'quiz' == $context ) {
948
-	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
949
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
950
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
951
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
952
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
953
-	    			}
954
-	    		$html .= '</h2>';
955
-	    	}
948
+				$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
949
+					$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
950
+					$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
951
+					if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
952
+						$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
953
+					}
954
+				$html .= '</h2>';
955
+			}
956 956
 
957
-	    	$html .= '<div class="tab-content" id="tab-new-content">';
957
+			$html .= '<div class="tab-content" id="tab-new-content">';
958 958
 
959
-	    		if( 'quiz' == $context ) {
960
-	    			$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>';
961
-	    		}
959
+				if( 'quiz' == $context ) {
960
+					$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>';
961
+				}
962 962
 
963 963
 				$html .= '<div class="question">';
964 964
 					$html .= '<div class="question_required_fields">';
@@ -1000,18 +1000,18 @@  discard block
 block discarded – undo
1000 1000
 
1001 1001
 						// Random order
1002 1002
 						$html .= '<p class="add_question_random_order">';
1003
-			    			$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>';
1004
-			    		$html .= '</p>';
1003
+							$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>';
1004
+						$html .= '</p>';
1005 1005
 
1006
-			    		// Question media
1006
+						// Question media
1007 1007
 						$html .= '<p>';
1008
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1009
-					    	$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>';
1010
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1011
-					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1012
-					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1013
-					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1014
-				    	$html .= '</p>';
1008
+							$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1009
+							$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>';
1010
+							$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1011
+							$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1012
+							$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1013
+							$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
1014
+						$html .= '</p>';
1015 1015
 
1016 1016
 					$html .= '</div>';
1017 1017
 				$html .= '</div>';
@@ -1022,19 +1022,19 @@  discard block
 block discarded – undo
1022 1022
 
1023 1023
 				if( 'quiz' == $context ) {
1024 1024
 					$html .= '<div class="add-question">';
1025
-			    		$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>';
1026
-		    		$html .= '</div>';
1027
-		    	}
1025
+						$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>';
1026
+					$html .= '</div>';
1027
+				}
1028 1028
 
1029
-		    $html .= '</div>';
1029
+			$html .= '</div>';
1030 1030
 
1031
-		    if( 'quiz' == $context ) {
1031
+			if( 'quiz' == $context ) {
1032 1032
 
1033
-			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1033
+				$html .= '<div class="tab-content hidden" id="tab-existing-content">';
1034 1034
 
1035
-			    	$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>';
1035
+					$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>';
1036 1036
 
1037
-			    	$html .= '<div id="existing-filters" class="alignleft actions">
1037
+					$html .= '<div id="existing-filters" class="alignleft actions">
1038 1038
 			    				<select id="existing-status">
1039 1039
 			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1040 1040
 			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
@@ -1042,23 +1042,23 @@  discard block
 block discarded – undo
1042 1042
 			    				</select>
1043 1043
 			    				<select id="existing-type">
1044 1044
 			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1045
-							    	foreach ( $question_types as $type => $label ) {
1045
+									foreach ( $question_types as $type => $label ) {
1046 1046
 										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1047 1047
 									}
1048
-    				$html .= '</select>
1048
+					$html .= '</select>
1049 1049
     							<select id="existing-category">
1050 1050
 			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1051
-				    				foreach( $question_cats as $cat ) {
1051
+									foreach( $question_cats as $cat ) {
1052 1052
 										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1053 1053
 									}
1054
-    				$html .= '</select>
1054
+					$html .= '</select>
1055 1055
     							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1056 1056
     							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1057 1057
 			    			</div>';
1058 1058
 
1059
-			    	$html .= '<table id="existing-table" class="widefat">';
1059
+					$html .= '<table id="existing-table" class="widefat">';
1060 1060
 
1061
-			    		$html .= '<thead>
1061
+						$html .= '<thead>
1062 1062
 									    <tr>
1063 1063
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1064 1064
 									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
@@ -1086,28 +1086,28 @@  discard block
 block discarded – undo
1086 1086
 
1087 1087
 						$html .= '</tbody>';
1088 1088
 
1089
-			    	$html .= '</table>';
1089
+					$html .= '</table>';
1090 1090
 
1091
-			    	$next_class = '';
1092
-			    	if( $questions['count'] <= 10 ) {
1093
-			    		$next_class = 'hidden';
1094
-			    	}
1091
+					$next_class = '';
1092
+					if( $questions['count'] <= 10 ) {
1093
+						$next_class = 'hidden';
1094
+					}
1095 1095
 
1096
-			    	$html .= '<div id="existing-pagination">';
1097
-			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1098
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1099
-			    	$html .= '</div>';
1096
+					$html .= '<div id="existing-pagination">';
1097
+						$html .= '<input type="hidden" id="existing-page" value="1" />';
1098
+						$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1099
+					$html .= '</div>';
1100 1100
 
1101
-			    	$html .= '<div class="existing-actions">';
1102
-			    		$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>';
1103
-			    	$html .= '</div>';
1101
+					$html .= '<div class="existing-actions">';
1102
+						$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>';
1103
+					$html .= '</div>';
1104 1104
 
1105
-			    $html .= '</div>';
1105
+				$html .= '</div>';
1106 1106
 
1107
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1108
-				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1107
+				if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1108
+					$html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1109 1109
 
1110
-				    	$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>';
1110
+						$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>';
1111 1111
 
1112 1112
 						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1113 1113
 						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
 
1121 1121
 						$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>';
1122 1122
 
1123
-				    $html .= '</div>';
1123
+					$html .= '</div>';
1124 1124
 				}
1125 1125
 			}
1126 1126
 
@@ -1193,14 +1193,14 @@  discard block
 block discarded – undo
1193 1193
 
1194 1194
 		$qry = new WP_Query( $args );
1195 1195
 
1196
-        /**
1197
-         * Filter existing questions query
1198
-         *
1199
-         * @since 1.8.0
1200
-         *
1201
-         * @param WP_Query $wp_query
1202
-         */
1203
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1196
+		/**
1197
+		 * Filter existing questions query
1198
+		 *
1199
+		 * @since 1.8.0
1200
+		 *
1201
+		 * @param WP_Query $wp_query
1202
+		 */
1203
+		$qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1204 1204
 
1205 1205
 		$questions['questions'] = $qry->posts;
1206 1206
 		$questions['count'] = intval( $qry->found_posts );
@@ -1215,14 +1215,14 @@  discard block
 block discarded – undo
1215 1215
 
1216 1216
 		if( ! $question_id ) {
1217 1217
 
1218
-            return;
1218
+			return;
1219 1219
 
1220
-        }
1220
+		}
1221 1221
 
1222 1222
 		$existing_class = '';
1223 1223
 		if( $row % 2 ) {
1224
-            $existing_class = 'alternate';
1225
-        }
1224
+			$existing_class = 'alternate';
1225
+		}
1226 1226
 
1227 1227
 		$question_type = Sensei()->question->get_question_type( $question_id );
1228 1228
 
@@ -1356,67 +1356,67 @@  discard block
 block discarded – undo
1356 1356
 							}
1357 1357
 						}
1358 1358
 
1359
-				    	// Calculate total wrong answers available (defaults to 4)
1360
-				    	$total_wrong = 0;
1361
-				    	if( $question_id ) {
1362
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1363
-				    	}
1364
-				    	if( 0 == intval( $total_wrong ) ) {
1365
-				    		$total_wrong = 1;
1366
-				    	}
1359
+						// Calculate total wrong answers available (defaults to 4)
1360
+						$total_wrong = 0;
1361
+						if( $question_id ) {
1362
+							$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1363
+						}
1364
+						if( 0 == intval( $total_wrong ) ) {
1365
+							$total_wrong = 1;
1366
+						}
1367 1367
 
1368
-                        // Setup Wrong Answer HTML
1369
-                        foreach ( $wrong_answers as $i => $answer ){
1368
+						// Setup Wrong Answer HTML
1369
+						foreach ( $wrong_answers as $i => $answer ){
1370 1370
 
1371
-                            $answer_id = $this->get_answer_id( $answer );
1372
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1373
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1374
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1375
-                            if( $question_id ) {
1371
+							$answer_id = $this->get_answer_id( $answer );
1372
+							$wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1373
+							$wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1374
+							$wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1375
+							if( $question_id ) {
1376 1376
 
1377
-                                $answers[ $answer_id ] = $wrong_answer;
1377
+								$answers[ $answer_id ] = $wrong_answer;
1378 1378
 
1379
-                            } else {
1379
+							} else {
1380 1380
 
1381
-                                $answers[] = $wrong_answer;
1381
+								$answers[] = $wrong_answer;
1382 1382
 
1383
-                            }
1383
+							}
1384 1384
 
1385
-                        } // end for each
1385
+						} // end for each
1386 1386
 
1387
-				    	$answers_sorted = $answers;
1388
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1389
-				    		$answers_sorted = array();
1390
-				    		foreach( $answer_order as $answer_id ) {
1391
-				    			if( isset( $answers[ $answer_id ] ) ) {
1392
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1393
-				    				unset( $answers[ $answer_id ] );
1394
-				    			}
1395
-				    		}
1387
+						$answers_sorted = $answers;
1388
+						if( $question_id && count( $answer_order ) > 0 ) {
1389
+							$answers_sorted = array();
1390
+							foreach( $answer_order as $answer_id ) {
1391
+								if( isset( $answers[ $answer_id ] ) ) {
1392
+									$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1393
+									unset( $answers[ $answer_id ] );
1394
+								}
1395
+							}
1396 1396
 
1397
-				    		if( count( $answers ) > 0 ) {
1398
-						    	foreach( $answers as $id => $answer ) {
1399
-						    		$answers_sorted[ $id ] = $answer;
1400
-						    	}
1401
-						    }
1402
-				    	}
1397
+							if( count( $answers ) > 0 ) {
1398
+								foreach( $answers as $id => $answer ) {
1399
+									$answers_sorted[ $id ] = $answer;
1400
+								}
1401
+							}
1402
+						}
1403 1403
 
1404 1404
 						foreach( $answers_sorted as $id => $answer ) {
1405
-				    		$html .= $answer;
1406
-				    	}
1405
+							$html .= $answer;
1406
+						}
1407 1407
 
1408
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1409
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1410
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1408
+						$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1409
+						$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1410
+						$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1411 1411
 
1412
-				    	$html .= '<div class="add_answer_options">';
1413
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1414
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1415
-				    	$html .= '</div>';
1412
+						$html .= '<div class="add_answer_options">';
1413
+							$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1414
+							$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1415
+						$html .= '</div>';
1416 1416
 
1417
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1417
+						$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1418 1418
 
1419
-			    	$html .= '</div>';
1419
+					$html .= '</div>';
1420 1420
 				break;
1421 1421
 				case 'boolean':
1422 1422
 					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
@@ -1429,7 +1429,7 @@  discard block
 block discarded – undo
1429 1429
 						$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>';
1430 1430
 						$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>';
1431 1431
 
1432
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1432
+					$html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1433 1433
 
1434 1434
 					$html .= '</div>';
1435 1435
 				break;
@@ -1504,17 +1504,17 @@  discard block
 block discarded – undo
1504 1504
 
1505 1505
 	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1506 1506
 
1507
-        // default field name
1508
-        $field_name = 'answer_feedback';
1509
-        if( 'boolean' == $question_type ){
1507
+		// default field name
1508
+		$field_name = 'answer_feedback';
1509
+		if( 'boolean' == $question_type ){
1510 1510
 
1511
-            $field_name = 'answer_feedback_boolean';
1511
+			$field_name = 'answer_feedback_boolean';
1512 1512
 
1513
-        }elseif( 'multiple-choice' == $question_type ){
1513
+		}elseif( 'multiple-choice' == $question_type ){
1514 1514
 
1515
-            $field_name = 'answer_feedback_multiple_choice';
1515
+			$field_name = 'answer_feedback_multiple_choice';
1516 1516
 
1517
-        }// end if
1517
+		}// end if
1518 1518
 
1519 1519
 		if( $question_counter ) {
1520 1520
 			$field_name = 'answer_' . $question_counter . '_feedback';
@@ -1719,15 +1719,15 @@  discard block
 block discarded – undo
1719 1719
 			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1720 1720
 
1721 1721
 			// Load the lessons script
1722
-            wp_enqueue_media();
1722
+			wp_enqueue_media();
1723 1723
 			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1724 1724
 			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1725 1725
 			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1726 1726
 
1727
-            // Load the bulk edit screen script
1728
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1729
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1730
-            }
1727
+			// Load the bulk edit screen script
1728
+			if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1729
+				wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1730
+			}
1731 1731
 
1732 1732
 			// Localise script
1733 1733
 			$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' ) );
@@ -2030,12 +2030,12 @@  discard block
 block discarded – undo
2030 2030
 
2031 2031
 					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2032 2032
 					if( ! in_array( $quiz_id, $quizzes ) ) {
2033
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2033
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2034 2034
 						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2035 2035
 						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2036
-			    	}
2036
+					}
2037 2037
 
2038
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2038
+					add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2039 2039
 					$question_type = Sensei()->question->get_question_type( $question_id );
2040 2040
 
2041 2041
 					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
@@ -2141,34 +2141,34 @@  discard block
 block discarded – undo
2141 2141
 		$post_content = $course_content;
2142 2142
 		// Course Query Arguments
2143 2143
 		$post_type_args = array(	'post_content' => $post_content,
2144
-  		    						'post_status' => $post_status,
2145
-  		    						'post_title' => $post_title,
2146
-  		    						'post_type' => $post_type
2147
-  		    						);
2144
+  									'post_status' => $post_status,
2145
+  									'post_title' => $post_title,
2146
+  									'post_type' => $post_type
2147
+  									);
2148 2148
   		// Only save if there is a valid title
2149 2149
   		if ( $post_title != '' ) {
2150
-  		    // Check for prerequisite courses & product id
2151
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2152
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2153
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2154
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2155
-  		    // Insert or Update the Lesson Quiz
2156
-		    if ( 0 < $course_id ) {
2157
-		    	$post_type_args[ 'ID' ] = $course_id;
2158
-		    	$course_id = wp_update_post($post_type_args);
2159
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2160
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2161
-		    	if ( 0 < $course_category_id ) {
2162
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2163
-		    	} // End If Statement
2164
-		    } else {
2165
-		    	$course_id = wp_insert_post($post_type_args);
2166
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2167
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2168
-		    	if ( 0 < $course_category_id ) {
2169
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2170
-		    	} // End If Statement
2171
-		    } // End If Statement
2150
+  			// Check for prerequisite courses & product id
2151
+  			$course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2152
+  			$course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2153
+  			$course_category_id = absint( $data[ 'course_category' ] );
2154
+  			if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2155
+  			// Insert or Update the Lesson Quiz
2156
+			if ( 0 < $course_id ) {
2157
+				$post_type_args[ 'ID' ] = $course_id;
2158
+				$course_id = wp_update_post($post_type_args);
2159
+				update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2160
+				update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2161
+				if ( 0 < $course_category_id ) {
2162
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2163
+				} // End If Statement
2164
+			} else {
2165
+				$course_id = wp_insert_post($post_type_args);
2166
+				add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2167
+				add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2168
+				if ( 0 < $course_category_id ) {
2169
+					wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2170
+				} // End If Statement
2171
+			} // End If Statement
2172 2172
 		} // End If Statement
2173 2173
   		// Check that the insert or update saved by testing the post id
2174 2174
   		if ( 0 < $course_id ) {
@@ -2259,17 +2259,17 @@  discard block
 block discarded – undo
2259 2259
 		$answer_feedback = '';
2260 2260
 		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2261 2261
 
2262
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2262
+			$answer_feedback = $data[ 'answer_feedback_boolean' ];
2263 2263
 
2264 2264
 		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2265 2265
 
2266
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2266
+			$answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2267 2267
 
2268
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2268
+		}elseif( isset( $data[ 'answer_feedback' ] )  ){
2269 2269
 
2270
-            $answer_feedback = $data[ 'answer_feedback' ];
2270
+			$answer_feedback = $data[ 'answer_feedback' ];
2271 2271
 
2272
-        } // End If Statement
2272
+		} // End If Statement
2273 2273
 
2274 2274
 		$post_title = $question_text;
2275 2275
 		$post_author = $data[ 'post_author' ];
@@ -2284,10 +2284,10 @@  discard block
 block discarded – undo
2284 2284
 		}
2285 2285
 		// Question Query Arguments
2286 2286
 		$post_type_args = array(	'post_content' => $post_content,
2287
-  		    						'post_status' => $post_status,
2288
-  		    						'post_title' => $post_title,
2289
-  		    						'post_type' => $post_type
2290
-  		    						);
2287
+  									'post_status' => $post_status,
2288
+  									'post_title' => $post_title,
2289
+  									'post_type' => $post_type
2290
+  									);
2291 2291
 
2292 2292
   		// Remove empty values and reindex the array
2293 2293
   		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
@@ -2323,14 +2323,14 @@  discard block
 block discarded – undo
2323 2323
   		if ( $post_title != '' ) {
2324 2324
 
2325 2325
   			// Get Quiz ID for the question
2326
-  		    $quiz_id = $data['quiz_id'];
2326
+  			$quiz_id = $data['quiz_id'];
2327 2327
 
2328
-  		    // Get question media
2328
+  			// Get question media
2329 2329
 			$question_media = $data['question_media'];
2330 2330
 
2331
-  		    // Get answer order
2332
-  		    $answer_order = '';
2333
-  		    if( isset( $data['answer_order'] ) ) {
2331
+  			// Get answer order
2332
+  			$answer_order = '';
2333
+  			if( isset( $data['answer_order'] ) ) {
2334 2334
 				$answer_order = $data['answer_order'];
2335 2335
 			}
2336 2336
 
@@ -2340,38 +2340,38 @@  discard block
 block discarded – undo
2340 2340
 				$random_order = $data['random_order'];
2341 2341
 			}
2342 2342
 
2343
-  		    // Insert or Update the question
2344
-  		    if ( 0 < $question_id ) {
2345
-
2346
-  		    	$post_type_args[ 'ID' ] = $question_id;
2347
-		    	$question_id = wp_update_post( $post_type_args );
2348
-
2349
-		    	// Update poast meta
2350
-		    	if( 'quiz' == $context ) {
2351
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2352
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2353
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2354
-			    	}
2355
-		    	}
2356
-
2357
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2358
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2359
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2360
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2361
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2362
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2363
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2364
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2365
-
2366
-		    	if( 'quiz' != $context ) {
2367
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2368
-		    	}
2343
+  			// Insert or Update the question
2344
+  			if ( 0 < $question_id ) {
2345
+
2346
+  				$post_type_args[ 'ID' ] = $question_id;
2347
+				$question_id = wp_update_post( $post_type_args );
2348
+
2349
+				// Update poast meta
2350
+				if( 'quiz' == $context ) {
2351
+					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2352
+					if( ! in_array( $quiz_id, $quizzes ) ) {
2353
+						add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2354
+					}
2355
+				}
2356
+
2357
+				update_post_meta( $question_id, '_question_grade', $question_grade );
2358
+				update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2359
+				update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2360
+				update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2361
+				update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2362
+				update_post_meta( $question_id, '_question_media', $question_media );
2363
+				update_post_meta( $question_id, '_answer_order', $answer_order );
2364
+				update_post_meta( $question_id, '_random_order', $random_order );
2365
+
2366
+				if( 'quiz' != $context ) {
2367
+					wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2368
+				}
2369 2369
 				// Don't store empty value, no point
2370 2370
 				if ( !empty($answer_feedback) ) {
2371 2371
 					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2372 2372
 				}
2373 2373
 
2374
-		    } else {
2374
+			} else {
2375 2375
 				$question_id = wp_insert_post( $post_type_args );
2376 2376
 				$question_count = intval( $data['question_count'] );
2377 2377
 				++$question_count;
@@ -2384,29 +2384,29 @@  discard block
 block discarded – undo
2384 2384
 				}
2385 2385
 
2386 2386
 				if( isset( $question_grade ) ) {
2387
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2388
-		    	}
2389
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2390
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2391
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2392
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2393
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2394
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2395
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2396
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2387
+					add_post_meta( $question_id, '_question_grade', $question_grade );
2388
+				}
2389
+				add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2390
+				add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2391
+				add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2392
+				add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2393
+				add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2394
+				add_post_meta( $question_id, '_question_media', $question_media );
2395
+				add_post_meta( $question_id, '_answer_order', $answer_order );
2396
+				add_post_meta( $question_id, '_random_order', $random_order );
2397 2397
 				// Don't store empty value, no point
2398 2398
 				if ( !empty($answer_feedback) ) {
2399 2399
 					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2400 2400
 				}
2401 2401
 
2402
-		    	// Set the post terms for question-type
2403
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2402
+				// Set the post terms for question-type
2403
+				wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2404 2404
 
2405
-			    if( $question_category ) {
2406
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2407
-	    		}
2405
+				if( $question_category ) {
2406
+					wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2407
+				}
2408 2408
 
2409
-		    } // End If Statement
2409
+			} // End If Statement
2410 2410
 		} // End If Statement
2411 2411
   		// Check that the insert or update saved by testing the post id
2412 2412
   		if ( 0 < $question_id ) {
@@ -2455,7 +2455,7 @@  discard block
 block discarded – undo
2455 2455
 	public function lesson_complexities() {
2456 2456
 
2457 2457
 		// V2 - make filter for this array
2458
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2458
+		$lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2459 2459
 									'std' => __( 'Standard', 'woothemes-sensei' ),
2460 2460
 									'hard' => __( 'Hard', 'woothemes-sensei' )
2461 2461
 									);
@@ -2522,14 +2522,14 @@  discard block
 block discarded – undo
2522 2522
 		$post_args = array(	'post_type' 		=> 'quiz',
2523 2523
 							'posts_per_page' 		=> 1,
2524 2524
 							'orderby'         	=> 'title',
2525
-    						'order'           	=> 'DESC',
2526
-    						'post_parent'      	=> $lesson_id,
2527
-    						'post_status'		=> $post_status,
2525
+							'order'           	=> 'DESC',
2526
+							'post_parent'      	=> $lesson_id,
2527
+							'post_status'		=> $post_status,
2528 2528
 							'suppress_filters' 	=> 0,
2529 2529
 							'fields'            => $fields
2530 2530
 							);
2531 2531
 		$posts_array = get_posts( $post_args );
2532
-        $quiz_id = array_shift($posts_array);
2532
+		$quiz_id = array_shift($posts_array);
2533 2533
 
2534 2534
 		return $quiz_id;
2535 2535
 	} // End lesson_quizzes()
@@ -2537,34 +2537,34 @@  discard block
 block discarded – undo
2537 2537
 
2538 2538
 	/**
2539 2539
 	 * Fetches all the questions for a quiz depending on certain conditions.
2540
-     *
2541
-     * Determine which questions should be shown depending on:
2542
-     * - admin/teacher selected questions to be shown
2543
-     * - questions shown to a user previously (saved as asked questions)
2544
-     * - limit number of questions lesson setting
2545 2540
 	 *
2546
-     * @since 1.0
2541
+	 * Determine which questions should be shown depending on:
2542
+	 * - admin/teacher selected questions to be shown
2543
+	 * - questions shown to a user previously (saved as asked questions)
2544
+	 * - limit number of questions lesson setting
2545
+	 *
2546
+	 * @since 1.0
2547 2547
 	 * @param int $quiz_id (default: 0)
2548 2548
 	 * @param string $post_status (default: 'publish')
2549 2549
 	 * @param string $orderby (default: 'meta_value_num title')
2550 2550
 	 * @param string $order (default: 'ASC')
2551
-     *
2551
+	 *
2552 2552
 	 * @return array $questions { $question type WP_Post }
2553 2553
 	 */
2554 2554
 	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2555 2555
 
2556 2556
 		$quiz_id = (string) $quiz_id;
2557
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2557
+		$quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2558 2558
 
2559
-        // setup the user id
2560
-        if( is_admin() ) {
2561
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2562
-        } else {
2563
-            $user_id = get_current_user_id();
2564
-        }
2559
+		// setup the user id
2560
+		if( is_admin() ) {
2561
+			$user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2562
+		} else {
2563
+			$user_id = get_current_user_id();
2564
+		}
2565 2565
 
2566
-        // get the users current status on the lesson
2567
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2566
+		// get the users current status on the lesson
2567
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2568 2568
 
2569 2569
 		// Set the default question order if it has not already been set for this quiz
2570 2570
 		$this->set_default_question_order( $quiz_id );
@@ -2594,14 +2594,14 @@  discard block
 block discarded – undo
2594 2594
 			'suppress_filters' 	=> 0
2595 2595
 		);
2596 2596
 
2597
-        //query the questions
2597
+		//query the questions
2598 2598
 		$questions_query = new WP_Query( $question_query_args );
2599 2599
 
2600
-        // Set return array to initially include all items
2601
-        $questions = $questions_query->posts;
2600
+		// Set return array to initially include all items
2601
+		$questions = $questions_query->posts;
2602 2602
 
2603
-        // set the questions array that will be manipulated within this function
2604
-        $questions_array = $questions_query->posts;
2603
+		// set the questions array that will be manipulated within this function
2604
+		$questions_array = $questions_query->posts;
2605 2605
 
2606 2606
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2607 2607
 		$selected_questions = false;
@@ -2714,36 +2714,36 @@  discard block
 block discarded – undo
2714 2714
 			}
2715 2715
 		}
2716 2716
 
2717
-        // Save the questions that will be asked for the current user
2718
-        // this happens only once per user/quiz, unless the user resets the quiz
2719
-        if( ! is_admin() ){
2717
+		// Save the questions that will be asked for the current user
2718
+		// this happens only once per user/quiz, unless the user resets the quiz
2719
+		if( ! is_admin() ){
2720 2720
 
2721
-            if( $user_lesson_status ) {
2721
+			if( $user_lesson_status ) {
2722 2722
 
2723
-                $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2724
-                if ( empty($questions_asked) && $user_lesson_status) {
2723
+				$questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2724
+				if ( empty($questions_asked) && $user_lesson_status) {
2725 2725
 
2726
-                    $questions_asked = array();
2727
-                    foreach ($questions as $question) {
2726
+					$questions_asked = array();
2727
+					foreach ($questions as $question) {
2728 2728
 
2729
-                        $questions_asked[] = $question->ID;
2729
+						$questions_asked[] = $question->ID;
2730 2730
 
2731
-                    }
2731
+					}
2732 2732
 
2733
-                    // save the questions asked id
2734
-                    $questions_asked_csv = implode(',', $questions_asked);
2735
-                    update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2733
+					// save the questions asked id
2734
+					$questions_asked_csv = implode(',', $questions_asked);
2735
+					update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_csv);
2736 2736
 
2737
-                }
2738
-            }
2739
-        }
2737
+				}
2738
+			}
2739
+		}
2740 2740
 
2741
-        /**
2742
-         * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2743
-         *
2744
-         * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2745
-         * @since 1.8.0
2746
-         */
2741
+		/**
2742
+		 * Filter the questions returned by Sensei_Lesson::lessons_quiz_questions
2743
+		 *
2744
+		 * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2745
+		 * @since 1.8.0
2746
+		 */
2747 2747
 		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2748 2748
 
2749 2749
 	} // End lesson_quiz_questions()
@@ -2847,7 +2847,7 @@  discard block
 block discarded – undo
2847 2847
  			// Display Image Placeholder if none
2848 2848
 			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2849 2849
 
2850
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2850
+				$img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2851 2851
 
2852 2852
 			} // End If Statement
2853 2853
 
@@ -2863,401 +2863,401 @@  discard block
 block discarded – undo
2863 2863
 	 * Returns the the lesson excerpt.
2864 2864
 	 *
2865 2865
 	 * @param WP_Post $lesson
2866
-     * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2866
+	 * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2867 2867
 	 * @return string
2868 2868
 	 */
2869 2869
 	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2870 2870
 		$html = '';
2871 2871
 		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2872 2872
 
2873
-            $excerpt =  $lesson->post_excerpt;
2873
+			$excerpt =  $lesson->post_excerpt;
2874 2874
 
2875
-            // if $add_p_tags true wrap with <p> else return the excerpt as is
2876
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2875
+			// if $add_p_tags true wrap with <p> else return the excerpt as is
2876
+			$html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2877 2877
 
2878 2878
 		}
2879 2879
 		return apply_filters( 'sensei_lesson_excerpt', $html );
2880 2880
 
2881 2881
 	} // End lesson_excerpt()
2882 2882
 
2883
-    /**
2884
-     * Returns the course for a given lesson
2885
-     *
2886
-     * @since 1.7.4
2887
-     * @access public
2888
-     *
2889
-     * @param int $lesson_id
2890
-     * @return int|bool $course_id or bool when nothing is found.
2891
-     */
2892
-     public function get_course_id( $lesson_id ){
2893
-
2894
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2895
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2896
-             return false;
2897
-         }
2898
-
2899
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2900
-
2901
-         // make sure the course id is valid
2902
-         if( empty( $lesson_course_id )
2903
-             || is_array( $lesson_course_id )
2904
-             || intval( $lesson_course_id ) < 1
2905
-             || 'course' != get_post_type( $lesson_course_id ) ){
2906
-
2907
-             return false;
2908
-
2909
-         }
2910
-
2911
-         return $lesson_course_id;
2912
-
2913
-     }// en get_course_id
2914
-
2915
-    /**
2916
-     * Add the admin all lessons screen edit options.
2917
-     *
2918
-     * The fields in this function work for both quick and bulk edit. The ID attributes is used
2919
-     * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2920
-     * name attribute is will be used by the quick edit and submitted via standard POST. This
2921
-     * will use this classes save_post_meta function to save the new field data.
2922
-     *
2923
-     * @hooked quick_edit_custom_box
2924
-     * @hooked bulk_edit_custom_box
2925
-     *
2926
-     * @since 1.8.0
2927
-     *
2928
-     * @param string $column_name
2929
-     * @param string $post_type
2930
-     * @return void
2931
-     */
2932
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2933
-
2934
-        // only show these options ont he lesson post type edit screen
2935
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2936
-            return;
2937
-        }
2938
-
2939
-        ?>
2883
+	/**
2884
+	 * Returns the course for a given lesson
2885
+	 *
2886
+	 * @since 1.7.4
2887
+	 * @access public
2888
+	 *
2889
+	 * @param int $lesson_id
2890
+	 * @return int|bool $course_id or bool when nothing is found.
2891
+	 */
2892
+	 public function get_course_id( $lesson_id ){
2893
+
2894
+		 if( ! isset( $lesson_id ) || empty( $lesson_id )
2895
+		 ||  'lesson' != get_post_type( $lesson_id ) ){
2896
+			 return false;
2897
+		 }
2898
+
2899
+		 $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2900
+
2901
+		 // make sure the course id is valid
2902
+		 if( empty( $lesson_course_id )
2903
+			 || is_array( $lesson_course_id )
2904
+			 || intval( $lesson_course_id ) < 1
2905
+			 || 'course' != get_post_type( $lesson_course_id ) ){
2906
+
2907
+			 return false;
2908
+
2909
+		 }
2910
+
2911
+		 return $lesson_course_id;
2912
+
2913
+	 }// en get_course_id
2914
+
2915
+	/**
2916
+	 * Add the admin all lessons screen edit options.
2917
+	 *
2918
+	 * The fields in this function work for both quick and bulk edit. The ID attributes is used
2919
+	 * by bulk edit javascript in the front end to retrieve the new values set byt the user. Then
2920
+	 * name attribute is will be used by the quick edit and submitted via standard POST. This
2921
+	 * will use this classes save_post_meta function to save the new field data.
2922
+	 *
2923
+	 * @hooked quick_edit_custom_box
2924
+	 * @hooked bulk_edit_custom_box
2925
+	 *
2926
+	 * @since 1.8.0
2927
+	 *
2928
+	 * @param string $column_name
2929
+	 * @param string $post_type
2930
+	 * @return void
2931
+	 */
2932
+	public function all_lessons_edit_fields( $column_name, $post_type ) {
2933
+
2934
+		// only show these options ont he lesson post type edit screen
2935
+		if( 'lesson' != $post_type || 'lesson-course' != $column_name ){
2936
+			return;
2937
+		}
2938
+
2939
+		?>
2940 2940
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2941 2941
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2942 2942
                     <?php
2943
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2944
-                    // create a nonce field to be  used as a security measure when saving the data
2945
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2946
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2947
-
2948
-                    // unchanged option - we need this in because
2949
-                    // the default option in bulk edit should not be empty. If it is
2950
-                    // the user will erase data they didn't want to touch.
2951
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2952
-
2953
-                    //
2954
-                    //course selection
2955
-                    //
2956
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2957
-                    $course_options = array();
2958
-                    if ( count( $courses ) > 0 ) {
2959
-                        foreach ($courses as $course ){
2960
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
2961
-                        }
2962
-                    }
2963
-                    //pre-append the no change option
2964
-                    $course_options['-1']=  $no_change_text;
2965
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2966
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2967
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2968
-
2969
-                    //
2970
-                    // lesson complexity selection
2971
-                    //
2972
-                    $lesson_complexities =  $this->lesson_complexities();
2973
-                    //pre-append the no change option
2974
-                    $lesson_complexities['-1']=  $no_change_text;
2975
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2976
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2977
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2978
-
2979
-                    ?>
2943
+					echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2944
+					// create a nonce field to be  used as a security measure when saving the data
2945
+					wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2946
+					wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2947
+
2948
+					// unchanged option - we need this in because
2949
+					// the default option in bulk edit should not be empty. If it is
2950
+					// the user will erase data they didn't want to touch.
2951
+					$no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2952
+
2953
+					//
2954
+					//course selection
2955
+					//
2956
+					$courses =  WooThemes_Sensei_Course::get_all_courses();
2957
+					$course_options = array();
2958
+					if ( count( $courses ) > 0 ) {
2959
+						foreach ($courses as $course ){
2960
+							$course_options[ $course->ID ] = get_the_title( $course->ID );
2961
+						}
2962
+					}
2963
+					//pre-append the no change option
2964
+					$course_options['-1']=  $no_change_text;
2965
+					$course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
2966
+					$course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
2967
+					echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
2968
+
2969
+					//
2970
+					// lesson complexity selection
2971
+					//
2972
+					$lesson_complexities =  $this->lesson_complexities();
2973
+					//pre-append the no change option
2974
+					$lesson_complexities['-1']=  $no_change_text;
2975
+					$complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
2976
+					$complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
2977
+					echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
2978
+
2979
+					?>
2980 2980
 
2981 2981
                     <h4><?php _e('Quiz Settings', 'woothemes-sensei'); ?> </h4>
2982 2982
 
2983 2983
                     <?php
2984 2984
 
2985
-                    //
2986
-                    // Lesson require pass to complete
2987
-                    //
2988
-                    $pass_required_options = array(
2989
-                        '-1' => $no_change_text,
2990
-                         '0' => __('No','woothemes'),
2991
-                         '1' => __('Yes','woothemes'),
2992
-                    );
2993
-
2994
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
2995
-                                                                'id'=> 'sensei-edit-lesson-pass-required',
2996
-                                                                'class'=>' '   );
2997
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
2998
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
2999
-
3000
-                    //
3001
-                    // Quiz pass percentage
3002
-                    //
3003
-                    $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3004
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3005
-
3006
-                    //
3007
-                    // Enable quiz reset button
3008
-                    //
3009
-                    $quiz_reset_select__options = array(
3010
-                        '-1' => $no_change_text,
3011
-                        '0' => __('No','woothemes'),
3012
-                        '1' => __('Yes','woothemes'),
3013
-                    );
3014
-                    $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3015
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3016
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3017
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3018
-
3019
-                    ?>
2985
+					//
2986
+					// Lesson require pass to complete
2987
+					//
2988
+					$pass_required_options = array(
2989
+						'-1' => $no_change_text,
2990
+						 '0' => __('No','woothemes'),
2991
+						 '1' => __('Yes','woothemes'),
2992
+					);
2993
+
2994
+					$pass_required_select_attributes = array( 'name'=> 'pass_required',
2995
+																'id'=> 'sensei-edit-lesson-pass-required',
2996
+																'class'=>' '   );
2997
+					$require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
2998
+					echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
2999
+
3000
+					//
3001
+					// Quiz pass percentage
3002
+					//
3003
+					$quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3004
+					echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3005
+
3006
+					//
3007
+					// Enable quiz reset button
3008
+					//
3009
+					$quiz_reset_select__options = array(
3010
+						'-1' => $no_change_text,
3011
+						'0' => __('No','woothemes'),
3012
+						'1' => __('Yes','woothemes'),
3013
+					);
3014
+					$quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3015
+					$quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3016
+					$quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3017
+					echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3018
+
3019
+					?>
3020 3020
             </div>
3021 3021
         </fieldset>
3022 3022
     <?php
3023
-    }// all_lessons_edit_fields
3024
-
3025
-    /**
3026
-     * Create the html for the edit field
3027
-     *
3028
-     * Wraps the passed in field and title combination with the correct html.
3029
-     *
3030
-     * @since 1.8.0
3031
-     *
3032
-     * @param string $title that will stand to the left of the field.
3033
-     * @param string $field type markup for the field that must be wrapped.
3034
-     * @return string $field_html
3035
-     */
3036
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3037
-
3038
-        $html = '';
3039
-        $html = '<div class="inline-edit-group" >';
3040
-        $html .=  '<span class="title">'. $title .'</span> ';
3041
-        $html .= '<span class="input-text-wrap">';
3042
-        $html .= $field;
3043
-        $html .= '</span>';
3044
-        $html .= '</label></div>';
3045
-
3046
-        return $html ;
3047
-
3048
-    }//end generate_all_lessons_edit_field
3049
-
3050
-    /**
3051
-     * Respond to the ajax call from the bulk edit save function. This comes
3052
-     * from the admin all lesson screen.
3053
-     *
3054
-     * @since 1.8.0
3055
-     * @return void
3056
-     */
3057
-    function save_all_lessons_edit_fields() {
3058
-
3059
-        // verify all the data before attempting to save
3060
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3061
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3062
-            die();
3063
-        }
3064
-
3065
-        // get our variables
3066
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3067
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3068
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3069
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3070
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3071
-        // store the values for all selected posts
3072
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3073
-
3074
-            // get the quiz id needed for the quiz meta
3075
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3076
-
3077
-            // do not save the items if the value is -1 as this
3078
-            // means it was not changed
3079
-
3080
-            // update lesson course
3081
-            if( -1 != $new_course ){
3082
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3083
-            }
3084
-            // update lesson complexity
3085
-            if( -1 != $new_complexity ){
3086
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3087
-            }
3088
-
3089
-            // Quiz Related settings
3090
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3091
-
3092
-                // update pass required
3093
-                if (-1 != $new_pass_required) {
3094
-
3095
-                    $checked = $new_pass_required  ? 'on' : '';
3096
-                    update_post_meta($quiz_id, '_pass_required', $checked);
3097
-                    unset( $checked );
3098
-                }
3023
+	}// all_lessons_edit_fields
3024
+
3025
+	/**
3026
+	 * Create the html for the edit field
3027
+	 *
3028
+	 * Wraps the passed in field and title combination with the correct html.
3029
+	 *
3030
+	 * @since 1.8.0
3031
+	 *
3032
+	 * @param string $title that will stand to the left of the field.
3033
+	 * @param string $field type markup for the field that must be wrapped.
3034
+	 * @return string $field_html
3035
+	 */
3036
+	public function generate_all_lessons_edit_field( $title  ,$field ){
3037
+
3038
+		$html = '';
3039
+		$html = '<div class="inline-edit-group" >';
3040
+		$html .=  '<span class="title">'. $title .'</span> ';
3041
+		$html .= '<span class="input-text-wrap">';
3042
+		$html .= $field;
3043
+		$html .= '</span>';
3044
+		$html .= '</label></div>';
3045
+
3046
+		return $html ;
3047
+
3048
+	}//end generate_all_lessons_edit_field
3049
+
3050
+	/**
3051
+	 * Respond to the ajax call from the bulk edit save function. This comes
3052
+	 * from the admin all lesson screen.
3053
+	 *
3054
+	 * @since 1.8.0
3055
+	 * @return void
3056
+	 */
3057
+	function save_all_lessons_edit_fields() {
3099 3058
 
3100
-                // update pass percentage
3101
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3059
+		// verify all the data before attempting to save
3060
+		if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3061
+			||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3062
+			die();
3063
+		}
3102 3064
 
3103
-                        update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3065
+		// get our variables
3066
+		$new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3067
+		$new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3068
+		$new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3069
+		$new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3070
+		$new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3071
+		// store the values for all selected posts
3072
+		foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3104 3073
 
3105
-                }
3074
+			// get the quiz id needed for the quiz meta
3075
+			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3106 3076
 
3107
-                //
3108
-                // update enable quiz reset
3109
-                //
3110
-                if (-1 != $new_enable_quiz_reset ) {
3077
+			// do not save the items if the value is -1 as this
3078
+			// means it was not changed
3111 3079
 
3112
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3113
-                    update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3114
-                    unset( $checked );
3080
+			// update lesson course
3081
+			if( -1 != $new_course ){
3082
+				update_post_meta( $lesson_id, '_lesson_course', $new_course );
3083
+			}
3084
+			// update lesson complexity
3085
+			if( -1 != $new_complexity ){
3086
+				update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3087
+			}
3115 3088
 
3116
-                }
3089
+			// Quiz Related settings
3090
+			if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3117 3091
 
3092
+				// update pass required
3093
+				if (-1 != $new_pass_required) {
3118 3094
 
3119
-            } // end if quiz
3095
+					$checked = $new_pass_required  ? 'on' : '';
3096
+					update_post_meta($quiz_id, '_pass_required', $checked);
3097
+					unset( $checked );
3098
+				}
3120 3099
 
3121
-        }// end for each
3100
+				// update pass percentage
3101
+				if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3122 3102
 
3123
-        die();
3103
+						update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3124 3104
 
3125
-    } // end save_all_lessons_edit_fields
3105
+				}
3126 3106
 
3127
-    /**
3128
-     * Loading the quick edit fields defaults.
3129
-     *
3130
-     * This function will localise the default values along with the script that will
3131
-     * add these values to the inputs.
3132
-     *
3133
-     * NOTE: this function runs for each row in the edit column
3134
-     *
3135
-     * @since 1.8.0
3136
-     * @return void
3137
-     */
3138
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3107
+				//
3108
+				// update enable quiz reset
3109
+				//
3110
+				if (-1 != $new_enable_quiz_reset ) {
3139 3111
 
3140
-        if( 'lesson-course' != $column_name ){
3141
-            return;
3142
-        }
3143
-        // load the script
3144
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3145
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3112
+					$checked = $new_enable_quiz_reset ? 'on' : ''  ;
3113
+					update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3114
+					unset( $checked );
3146 3115
 
3147
-        // setup the values for all meta fields
3148
-        $data = array();
3149
-        foreach( $this->meta_fields as $field ){
3116
+				}
3150 3117
 
3151
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3152 3118
 
3153
-        }
3154
-        // add quiz meta fields
3155
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3156
-        foreach( Sensei()->quiz->meta_fields as $field ){
3119
+			} // end if quiz
3157 3120
 
3158
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3121
+		}// end for each
3159 3122
 
3160
-        }
3123
+		die();
3161 3124
 
3162
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3125
+	} // end save_all_lessons_edit_fields
3163 3126
 
3164
-    }// end quick edit admin defaults
3127
+	/**
3128
+	 * Loading the quick edit fields defaults.
3129
+	 *
3130
+	 * This function will localise the default values along with the script that will
3131
+	 * add these values to the inputs.
3132
+	 *
3133
+	 * NOTE: this function runs for each row in the edit column
3134
+	 *
3135
+	 * @since 1.8.0
3136
+	 * @return void
3137
+	 */
3138
+	public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3165 3139
 
3166
-    /**
3167
-     * Filter the classes for lessons on the single course page.
3168
-     *
3169
-     * Adds the nesecary classes depending on the user data
3170
-     *
3171
-     * @since 1.9.0
3172
-     * @param array $classes
3173
-     * @return array $classes
3174
-     */
3175
-    public static function single_course_lessons_classes( $classes ){
3140
+		if( 'lesson-course' != $column_name ){
3141
+			return;
3142
+		}
3143
+		// load the script
3144
+		$suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3145
+		wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3146
+
3147
+		// setup the values for all meta fields
3148
+		$data = array();
3149
+		foreach( $this->meta_fields as $field ){
3150
+
3151
+			$data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3152
+
3153
+		}
3154
+		// add quiz meta fields
3155
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3156
+		foreach( Sensei()->quiz->meta_fields as $field ){
3157
+
3158
+			$data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3159
+
3160
+		}
3161
+
3162
+		wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3163
+
3164
+	}// end quick edit admin defaults
3165
+
3166
+	/**
3167
+	 * Filter the classes for lessons on the single course page.
3168
+	 *
3169
+	 * Adds the nesecary classes depending on the user data
3170
+	 *
3171
+	 * @since 1.9.0
3172
+	 * @param array $classes
3173
+	 * @return array $classes
3174
+	 */
3175
+	public static function single_course_lessons_classes( $classes ){
3176 3176
 
3177
-        if(  is_singular('course') ){
3177
+		if(  is_singular('course') ){
3178 3178
 
3179
-            global $post;
3180
-            $course_id = $post->ID;
3179
+			global $post;
3180
+			$course_id = $post->ID;
3181 3181
 
3182
-            $lesson_classes = array( 'course', 'post' );
3183
-            if ( is_user_logged_in() ) {
3182
+			$lesson_classes = array( 'course', 'post' );
3183
+			if ( is_user_logged_in() ) {
3184 3184
 
3185
-                // Check if Lesson is complete
3186
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3187
-                if ( $single_lesson_complete ) {
3185
+				// Check if Lesson is complete
3186
+				$single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3187
+				if ( $single_lesson_complete ) {
3188 3188
 
3189
-                    $lesson_classes[] = 'lesson-completed';
3189
+					$lesson_classes[] = 'lesson-completed';
3190 3190
 
3191
-                } // End If Statement
3191
+				} // End If Statement
3192 3192
 
3193
-            } // End If Statement
3193
+			} // End If Statement
3194 3194
 
3195
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3196
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3195
+			$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3196
+			if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3197 3197
 
3198
-                $lesson_classes[] = 'lesson-preview';
3198
+				$lesson_classes[] = 'lesson-preview';
3199 3199
 
3200
-            }
3200
+			}
3201 3201
 
3202
-            $classes = array_merge( $classes, $lesson_classes  );
3202
+			$classes = array_merge( $classes, $lesson_classes  );
3203 3203
 
3204
-        }
3204
+		}
3205 3205
 
3206
-        return $classes;
3206
+		return $classes;
3207 3207
 
3208
-    }// end single_course_lessons_classes
3208
+	}// end single_course_lessons_classes
3209 3209
 
3210
-    /**
3211
-     * Output the lesson meta for the given lesson
3212
-     *
3213
-     * @since 1.9.0
3214
-     * @param $lesson_id
3215
-     */
3216
-    public static function the_lesson_meta( $lesson_id ){
3210
+	/**
3211
+	 * Output the lesson meta for the given lesson
3212
+	 *
3213
+	 * @since 1.9.0
3214
+	 * @param $lesson_id
3215
+	 */
3216
+	public static function the_lesson_meta( $lesson_id ){
3217 3217
 
3218
-        global $wp_query;
3219
-        $loop_lesson_number = $wp_query->current_post + 1;
3218
+		global $wp_query;
3219
+		$loop_lesson_number = $wp_query->current_post + 1;
3220 3220
 
3221
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3222
-        $single_lesson_complete = false;
3223
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3221
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
3222
+		$single_lesson_complete = false;
3223
+		$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3224 3224
 
3225
-        // Get Lesson data
3226
-        $complexity_array = Sensei()->lesson->lesson_complexities();
3225
+		// Get Lesson data
3226
+		$complexity_array = Sensei()->lesson->lesson_complexities();
3227 3227
 
3228
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3229
-        if ( '' != $lesson_complexity ) {
3228
+		$lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3229
+		if ( '' != $lesson_complexity ) {
3230 3230
 
3231
-            $lesson_complexity = $complexity_array[$lesson_complexity];
3231
+			$lesson_complexity = $complexity_array[$lesson_complexity];
3232 3232
 
3233
-        }
3234
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3235
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3236
-        $preview_label = '';
3237
-        if ( $is_preview && !$is_user_taking_course ) {
3233
+		}
3234
+		$user_info = get_userdata( absint( get_post()->post_author ) );
3235
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3236
+		$preview_label = '';
3237
+		if ( $is_preview && !$is_user_taking_course ) {
3238 3238
 
3239
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3240
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3239
+			$preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3240
+			$preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3241 3241
 
3242
-        }
3242
+		}
3243 3243
 
3244 3244
 
3245
-        $count_markup= '';
3246
-        /**
3247
-         * Filter for if you want the $lesson_count to show next to the lesson.
3248
-         *
3249
-         * @since 1.0
3250
-         * @param bool default false.
3251
-         */
3252
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3245
+		$count_markup= '';
3246
+		/**
3247
+		 * Filter for if you want the $lesson_count to show next to the lesson.
3248
+		 *
3249
+		 * @since 1.0
3250
+		 * @param bool default false.
3251
+		 */
3252
+		if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3253 3253
 
3254
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3254
+			$count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3255 3255
 
3256
-        }
3256
+		}
3257 3257
 
3258
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3258
+		$heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3259 3259
 
3260
-        ?>
3260
+		?>
3261 3261
         <header>
3262 3262
             <h2>
3263 3263
                 <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
@@ -3270,40 +3270,40 @@  discard block
 block discarded – undo
3270 3270
 
3271 3271
                 <?php
3272 3272
 
3273
-                $meta_html = '';
3274
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3273
+				$meta_html = '';
3274
+				$user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3275 3275
 
3276
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3277
-                if ( '' != $lesson_length ) {
3276
+				$lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3277
+				if ( '' != $lesson_length ) {
3278 3278
 
3279
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3279
+					$meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3280 3280
 
3281
-                }
3281
+				}
3282 3282
 
3283
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3283
+				if ( Sensei()->settings->get( 'lesson_author' ) ) {
3284 3284
 
3285
-                    $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>';
3285
+					$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>';
3286 3286
 
3287
-                } // End If Statement
3288
-                if ( '' != $lesson_complexity ) {
3287
+				} // End If Statement
3288
+				if ( '' != $lesson_complexity ) {
3289 3289
 
3290
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3290
+					$meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3291 3291
 
3292
-                }
3292
+				}
3293 3293
 
3294
-                if ( $single_lesson_complete ) {
3294
+				if ( $single_lesson_complete ) {
3295 3295
 
3296
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3296
+					$meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3297 3297
 
3298
-                } elseif ( $user_lesson_status ) {
3298
+				} elseif ( $user_lesson_status ) {
3299 3299
 
3300
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3300
+					$meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3301 3301
 
3302
-                } // End If Statement
3302
+				} // End If Statement
3303 3303
 
3304
-                echo $meta_html;
3304
+				echo $meta_html;
3305 3305
 
3306
-                ?>
3306
+				?>
3307 3307
 
3308 3308
             </p> <!-- lesson meta -->
3309 3309
 
@@ -3311,132 +3311,132 @@  discard block
 block discarded – undo
3311 3311
 
3312 3312
     <?php
3313 3313
 
3314
-    } // end the_lesson_meta
3314
+	} // end the_lesson_meta
3315 3315
 
3316
-    /**
3317
-     * Output the lessons thumbnail
3318
-     *
3319
-     * 1.9.0
3320
-     *
3321
-     * @param $lesson_id
3322
-     */
3323
-    public static function the_lesson_thumbnail( $lesson_id ){
3316
+	/**
3317
+	 * Output the lessons thumbnail
3318
+	 *
3319
+	 * 1.9.0
3320
+	 *
3321
+	 * @param $lesson_id
3322
+	 */
3323
+	public static function the_lesson_thumbnail( $lesson_id ){
3324 3324
 
3325
-        if( empty( $lesson_id ) ){
3325
+		if( empty( $lesson_id ) ){
3326 3326
 
3327
-            $lesson_id = get_the_ID();
3327
+			$lesson_id = get_the_ID();
3328 3328
 
3329
-        }
3329
+		}
3330 3330
 
3331
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3332
-            return;
3333
-        }
3331
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3332
+			return;
3333
+		}
3334 3334
 
3335
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3336
-    }
3335
+		echo Sensei()->lesson->lesson_image( $lesson_id );
3336
+	}
3337 3337
 
3338 3338
 
3339
-    /**
3340
-     * Alter the sensei lesson excerpt.
3341
-     *
3342
-     * @since 1.9.0
3343
-     * @param string $excerpt
3344
-     * @return string $excerpt
3345
-     */
3346
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3339
+	/**
3340
+	 * Alter the sensei lesson excerpt.
3341
+	 *
3342
+	 * @since 1.9.0
3343
+	 * @param string $excerpt
3344
+	 * @return string $excerpt
3345
+	 */
3346
+	public static function alter_the_lesson_excerpt( $excerpt ) {
3347 3347
 
3348
-        if ('lesson' == get_post_type(get_the_ID())){
3348
+		if ('lesson' == get_post_type(get_the_ID())){
3349 3349
 
3350
-            // remove this hooks to avoid an infinite loop.
3351
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3350
+			// remove this hooks to avoid an infinite loop.
3351
+			remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3352 3352
 
3353
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3354
-        }
3353
+			return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3354
+		}
3355 3355
 
3356
-        return $excerpt;
3356
+		return $excerpt;
3357 3357
 
3358
-    }// end the_lesson_excerpt
3358
+	}// end the_lesson_excerpt
3359 3359
 
3360
-    /**
3361
-     * Returns the lesson prerequisite for the given lesson id.
3362
-     *
3363
-     * @since 1.9.0
3364
-     *
3365
-     * @param $current_lesson_id
3366
-     * @return mixed | bool | int $prerequisite_lesson_id or false
3367
-     */
3368
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3360
+	/**
3361
+	 * Returns the lesson prerequisite for the given lesson id.
3362
+	 *
3363
+	 * @since 1.9.0
3364
+	 *
3365
+	 * @param $current_lesson_id
3366
+	 * @return mixed | bool | int $prerequisite_lesson_id or false
3367
+	 */
3368
+	public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3369 3369
 
3370
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3370
+		$prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3371 3371
 
3372
-        // set ti to false if not a valid prerequisite lesson id
3373
-        if(  empty( $prerequisite_lesson_id )
3374
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3375
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3372
+		// set ti to false if not a valid prerequisite lesson id
3373
+		if(  empty( $prerequisite_lesson_id )
3374
+			|| 'lesson' != get_post_type( $prerequisite_lesson_id )
3375
+			|| $prerequisite_lesson_id == $current_lesson_id  ) {
3376 3376
 
3377
-            $prerequisite_lesson_id = false;
3377
+			$prerequisite_lesson_id = false;
3378 3378
 
3379
-        }
3379
+		}
3380 3380
 
3381
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3381
+		return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3382 3382
 
3383
-    }
3383
+	}
3384 3384
 
3385
-    /**
3386
-     * This function requires that you pass in the lesson you would like to check for
3387
-     * a pre-requisite and not the pre-requisite. It will check if the
3388
-     * lesson has a pre-requiste and then check if it is completed.
3389
-     *
3390
-     * @since 1.9.0
3391
-     *
3392
-     * @param $lesson_id
3393
-     * @param $user_id
3394
-     * @return bool
3395
-     */
3396
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3385
+	/**
3386
+	 * This function requires that you pass in the lesson you would like to check for
3387
+	 * a pre-requisite and not the pre-requisite. It will check if the
3388
+	 * lesson has a pre-requiste and then check if it is completed.
3389
+	 *
3390
+	 * @since 1.9.0
3391
+	 *
3392
+	 * @param $lesson_id
3393
+	 * @param $user_id
3394
+	 * @return bool
3395
+	 */
3396
+	public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3397 3397
 
3398
-        if( empty( $lesson_id ) || empty( $user_id )
3399
-        || 'lesson' != get_post_type( $lesson_id )
3400
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3398
+		if( empty( $lesson_id ) || empty( $user_id )
3399
+		|| 'lesson' != get_post_type( $lesson_id )
3400
+		||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3401 3401
 
3402
-            return false;
3402
+			return false;
3403 3403
 
3404
-        }
3404
+		}
3405 3405
 
3406
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3406
+		$pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3407 3407
 
3408
-        // not a valid pre-requisite so pre-requisite is completed
3409
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3410
-            || ! is_numeric( $pre_requisite_id ) ){
3408
+		// not a valid pre-requisite so pre-requisite is completed
3409
+		if( 'lesson' != get_post_type( $pre_requisite_id )
3410
+			|| ! is_numeric( $pre_requisite_id ) ){
3411 3411
 
3412
-            return true;
3412
+			return true;
3413 3413
 
3414
-        }
3414
+		}
3415 3415
 
3416
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3416
+		return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3417 3417
 
3418
-    }// end is_prerequisite_complete
3418
+	}// end is_prerequisite_complete
3419 3419
 
3420
-    /**
3421
-     * Show the user not taking course message if it is the case
3422
-     *
3423
-     * @since 1.9.0
3424
-     */
3425
-    public  static function user_not_taking_course_message(){
3420
+	/**
3421
+	 * Show the user not taking course message if it is the case
3422
+	 *
3423
+	 * @since 1.9.0
3424
+	 */
3425
+	public  static function user_not_taking_course_message(){
3426 3426
 
3427
-        $lesson_id = get_the_ID();
3427
+		$lesson_id = get_the_ID();
3428 3428
 
3429
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3430
-            return;
3431
-        }
3429
+		if( 'lesson' != get_post_type( $lesson_id ) ){
3430
+			return;
3431
+		}
3432 3432
 
3433
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3434
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3435
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3436
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3433
+		$is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3434
+		$pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3435
+		$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3436
+		$user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3437 3437
 
3438
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3439
-            ?>
3438
+		if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3439
+			?>
3440 3440
 
3441 3441
             <div class="sensei-message alert">
3442 3442
                 <?php echo Sensei()->permissions_message['message']; ?>
@@ -3444,46 +3444,46 @@  discard block
 block discarded – undo
3444 3444
 
3445 3445
             <?php
3446 3446
 
3447
-        }// end if
3447
+		}// end if
3448 3448
 
3449
-    } // end user_not_taking_course_message
3449
+	} // end user_not_taking_course_message
3450 3450
 
3451
-    /**
3452
-     * Outputs the lessons course signup lingk
3453
-     *
3454
-     * This hook runs inside the single lesson page.
3455
-     *
3456
-     * @since 1.9.0
3457
-     */
3458
-    public static function course_signup_link( ){
3451
+	/**
3452
+	 * Outputs the lessons course signup lingk
3453
+	 *
3454
+	 * This hook runs inside the single lesson page.
3455
+	 *
3456
+	 * @since 1.9.0
3457
+	 */
3458
+	public static function course_signup_link( ){
3459 3459
 
3460
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3460
+		$course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3461 3461
 
3462
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3462
+		if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3463 3463
 
3464
-            return;
3464
+			return;
3465 3465
 
3466
-        }
3467
-        ?>
3466
+		}
3467
+		?>
3468 3468
 
3469 3469
         <section class="course-signup lesson-meta">
3470 3470
 
3471 3471
             <?php
3472
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3472
+			$wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3473 3473
 
3474
-            if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3474
+			if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) {
3475 3475
 
3476
-                global $current_user;
3477
-                if( is_user_logged_in() ) {
3478
-                    wp_get_current_user();
3476
+				global $current_user;
3477
+				if( is_user_logged_in() ) {
3478
+					wp_get_current_user();
3479 3479
 
3480
-                    $course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3480
+					$course_purchased = Sensei_Utils::sensei_customer_bought_product( $current_user->user_email, $current_user->ID, $wc_post_id );
3481 3481
 
3482
-                    if( $course_purchased ) {
3482
+					if( $course_purchased ) {
3483 3483
 
3484
-                        $prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3485
-                        $course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3486
-                        ?>
3484
+						$prereq_course_id = get_post_meta( $course_id, '_course_prerequisite',true );
3485
+						$course_link = '<a href="' . esc_url( get_permalink( $prereq_course_id ) ) . '" title="' . esc_attr( get_the_title( $prereq_course_id ) ) . '">' . __( 'the previous course', 'woothemes-sensei' )  . '</a>';
3486
+						?>
3487 3487
                             <div class="sensei-message info">
3488 3488
 
3489 3489
                                 <?php  echo sprintf( __( 'Please complete %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); ?>
@@ -3495,14 +3495,14 @@  discard block
 block discarded – undo
3495 3495
                         <div class="sensei-message info">
3496 3496
 
3497 3497
                             <?php
3498
-                            $course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3499
-                                            . '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3500
-                                            . '">' . __( 'course', 'woothemes-sensei' )
3501
-                                            . '</a>';
3498
+							$course_link = '<a href="' . esc_url( get_permalink( $course_id ) )
3499
+											. '"title="' . __( 'Sign Up', 'woothemes-sensei' )
3500
+											. '">' . __( 'course', 'woothemes-sensei' )
3501
+											. '</a>';
3502 3502
 
3503
-                            echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3503
+							echo  sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link );
3504 3504
 
3505
-                            ?>
3505
+							?>
3506 3506
 
3507 3507
                         </div>
3508 3508
                     <?php } ?>
@@ -3519,14 +3519,14 @@  discard block
 block discarded – undo
3519 3519
 
3520 3520
                 <div class="sensei-message info">
3521 3521
                     <?php
3522
-                    $course_link =  '<a href="'
3523
-                                        . esc_url( get_permalink( $course_id ) )
3524
-                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3525
-                                        . '">' . __( 'course', 'woothemes-sensei' )
3526
-                                    . '</a>';
3527
-
3528
-                    echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3529
-                    ?>
3522
+					$course_link =  '<a href="'
3523
+										. esc_url( get_permalink( $course_id ) )
3524
+										. '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3525
+										. '">' . __( 'course', 'woothemes-sensei' )
3526
+									. '</a>';
3527
+
3528
+					echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3529
+					?>
3530 3530
                 </div>
3531 3531
 
3532 3532
             <?php endif; ?>
@@ -3536,75 +3536,75 @@  discard block
 block discarded – undo
3536 3536
         </section>
3537 3537
 
3538 3538
         <?php
3539
-    }// end course_signup_link
3539
+	}// end course_signup_link
3540 3540
 
3541
-    /**
3542
-     * Show a message telling the user to complete the previous message if they haven't done so yet
3543
-     *
3544
-     * @since 1.9.0
3545
-     */
3546
-    public  static function prerequisite_complete_message(){
3541
+	/**
3542
+	 * Show a message telling the user to complete the previous message if they haven't done so yet
3543
+	 *
3544
+	 * @since 1.9.0
3545
+	 */
3546
+	public  static function prerequisite_complete_message(){
3547 3547
 
3548
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3549
-        $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3550
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3548
+		$lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3549
+		$lesson_has_pre_requisite = $lesson_prerequisite > 0;
3550
+		if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3551 3551
 
3552
-            $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>';
3553
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3552
+			$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>';
3553
+			echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3554 3554
 
3555
-        }
3555
+		}
3556 3556
 
3557
-    }
3557
+	}
3558 3558
 
3559
-    /**
3560
-     * Deprecate the sensei_lesson_archive_header hook but keep it
3561
-     * active for backwards compatibility.
3562
-     *
3563
-     * @deprecated since 1.9.0
3564
-     */
3565
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3559
+	/**
3560
+	 * Deprecate the sensei_lesson_archive_header hook but keep it
3561
+	 * active for backwards compatibility.
3562
+	 *
3563
+	 * @deprecated since 1.9.0
3564
+	 */
3565
+	public static function deprecate_sensei_lesson_archive_header_hook(){
3566 3566
 
3567
-        sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3567
+		sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3568 3568
 
3569
-    }
3569
+	}
3570 3570
 
3571
-    /**
3572
-     * Outputs the the lesson archive header.
3573
-     *
3574
-     * @since  1.9.0
3575
-     * @return void
3576
-     */
3577
-    public function the_archive_header( ) {
3571
+	/**
3572
+	 * Outputs the the lesson archive header.
3573
+	 *
3574
+	 * @since  1.9.0
3575
+	 * @return void
3576
+	 */
3577
+	public function the_archive_header( ) {
3578 3578
 
3579
-        $before_html = '<header class="archive-header"><h1>';
3580
-        $after_html = '</h1></header>';
3581
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3579
+		$before_html = '<header class="archive-header"><h1>';
3580
+		$after_html = '</h1></header>';
3581
+		$html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3582 3582
 
3583
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3583
+		echo apply_filters( 'sensei_lesson_archive_title', $html );
3584 3584
 
3585
-    } // sensei_course_archive_header()
3585
+	} // sensei_course_archive_header()
3586 3586
 
3587
-    /**
3588
-     * Output the title for the single lesson page
3589
-     *
3590
-     * @global $post
3591
-     * @since 1.9.0
3592
-     */
3593
-    public static function the_title(){
3587
+	/**
3588
+	 * Output the title for the single lesson page
3589
+	 *
3590
+	 * @global $post
3591
+	 * @since 1.9.0
3592
+	 */
3593
+	public static function the_title(){
3594 3594
 
3595
-        global $post;
3595
+		global $post;
3596 3596
 
3597
-        ?>
3597
+		?>
3598 3598
         <header>
3599 3599
 
3600 3600
             <h1>
3601 3601
 
3602 3602
                 <?php
3603
-                /**
3604
-                 * Filter documented in class-sensei-messages.php the_title
3605
-                 */
3606
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3607
-                ?>
3603
+				/**
3604
+				 * Filter documented in class-sensei-messages.php the_title
3605
+				 */
3606
+				echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3607
+				?>
3608 3608
 
3609 3609
             </h1>
3610 3610
 
@@ -3612,68 +3612,68 @@  discard block
 block discarded – undo
3612 3612
 
3613 3613
         <?php
3614 3614
 
3615
-    }//the_title
3615
+	}//the_title
3616 3616
 
3617
-    /**
3618
-     * Flush the rewrite rules for a lesson post type
3619
-     *
3620
-     * @since 1.9.0
3621
-     *
3622
-     * @param $post_id
3623
-     */
3624
-    public static function flush_rewrite_rules( $post_id ){
3617
+	/**
3618
+	 * Flush the rewrite rules for a lesson post type
3619
+	 *
3620
+	 * @since 1.9.0
3621
+	 *
3622
+	 * @param $post_id
3623
+	 */
3624
+	public static function flush_rewrite_rules( $post_id ){
3625 3625
 
3626
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3626
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3627 3627
 
3628
-            return;
3628
+			return;
3629 3629
 
3630
-        }
3630
+		}
3631 3631
 
3632 3632
 
3633
-        if( 'lesson' == get_post_type( $post_id )  ){
3633
+		if( 'lesson' == get_post_type( $post_id )  ){
3634 3634
 
3635
-            Sensei()->initiate_rewrite_rules_flush();
3635
+			Sensei()->initiate_rewrite_rules_flush();
3636 3636
 
3637
-        }
3637
+		}
3638 3638
 
3639
-    }
3639
+	}
3640 3640
 
3641
-    /**
3642
-     * Output the quiz specific buttons and messaging on the single lesson page
3643
-     *
3644
-     *
3645
-     * @since 1.0.0 moved here from frontend class
3646
-     *
3647
-     * @param int $lesson_id
3648
-     * @param int $user_id
3649
-     */
3650
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3641
+	/**
3642
+	 * Output the quiz specific buttons and messaging on the single lesson page
3643
+	 *
3644
+	 *
3645
+	 * @since 1.0.0 moved here from frontend class
3646
+	 *
3647
+	 * @param int $lesson_id
3648
+	 * @param int $user_id
3649
+	 */
3650
+	public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3651 3651
 
3652 3652
 
3653
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3654
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3655
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3656
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3657
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3658
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3659
-        $show_actions              = is_user_logged_in() ? true : false;
3653
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3654
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3655
+		$lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3656
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3657
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3658
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3659
+		$show_actions              = is_user_logged_in() ? true : false;
3660 3660
 
3661
-        if( intval( $lesson_prerequisite ) > 0 ) {
3661
+		if( intval( $lesson_prerequisite ) > 0 ) {
3662 3662
 
3663
-            // If the user hasn't completed the prereq then hide the current actions
3664
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3663
+			// If the user hasn't completed the prereq then hide the current actions
3664
+			$show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3665 3665
 
3666
-        }
3667
-        ?>
3666
+		}
3667
+		?>
3668 3668
 
3669 3669
         <footer>
3670 3670
 
3671 3671
             <?php
3672
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3672
+			if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3673 3673
 
3674
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3675
-                if( $has_quiz_questions ) {
3676
-                    ?>
3674
+				$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3675
+				if( $has_quiz_questions ) {
3676
+					?>
3677 3677
 
3678 3678
                     <p>
3679 3679
 
@@ -3688,87 +3688,87 @@  discard block
 block discarded – undo
3688 3688
                     </p>
3689 3689
 
3690 3690
                     <?php
3691
-                }
3691
+				}
3692 3692
 
3693
-            } // End If Statement
3693
+			} // End If Statement
3694 3694
 
3695
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3695
+			if ( $show_actions && ! $has_user_completed_lesson ) {
3696 3696
 
3697
-                sensei_complete_lesson_button();
3697
+				sensei_complete_lesson_button();
3698 3698
 
3699
-            } elseif( $show_actions ) {
3699
+			} elseif( $show_actions ) {
3700 3700
 
3701
-                sensei_reset_lesson_button();
3701
+				sensei_reset_lesson_button();
3702 3702
 
3703
-            } // End If Statement
3704
-            ?>
3703
+			} // End If Statement
3704
+			?>
3705 3705
 
3706 3706
         </footer>
3707 3707
 
3708 3708
         <?php
3709
-    } // End sensei_lesson_quiz_meta()
3709
+	} // End sensei_lesson_quiz_meta()
3710 3710
 
3711
-    /**
3712
-     * Show the lesson comments. This should be used in the loop.
3713
-     *
3714
-     * @since 1.9.0
3715
-     */
3716
-    public static function output_comments(){
3711
+	/**
3712
+	 * Show the lesson comments. This should be used in the loop.
3713
+	 *
3714
+	 * @since 1.9.0
3715
+	 */
3716
+	public static function output_comments(){
3717 3717
 
3718
-        if( ! is_user_logged_in() ){
3719
-            return;
3720
-        }
3718
+		if( ! is_user_logged_in() ){
3719
+			return;
3720
+		}
3721 3721
 
3722
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3723
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3724
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3725
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3722
+		$pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3723
+		$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3724
+		$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3725
+		$user_taking_course = Sensei_Utils::user_started_course($course_id );
3726 3726
 
3727
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3727
+		$lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3728 3728
 
3729
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3729
+		if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3730 3730
 
3731
-            comments_template();
3731
+			comments_template();
3732 3732
 
3733
-        } // End If Statement
3733
+		} // End If Statement
3734 3734
 
3735
-    } //output_comments
3735
+	} //output_comments
3736 3736
 
3737
-    /**
3738
-     * Display the leeson quiz status if it should be shown
3739
-     *
3740
-     * @param int $lesson_id defaults to the global lesson id
3741
-     * @param int $user_id defaults to the current user id
3742
-     *
3743
-     * @since 1.9.0
3744
-     */
3745
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3737
+	/**
3738
+	 * Display the leeson quiz status if it should be shown
3739
+	 *
3740
+	 * @param int $lesson_id defaults to the global lesson id
3741
+	 * @param int $user_id defaults to the current user id
3742
+	 *
3743
+	 * @since 1.9.0
3744
+	 */
3745
+	public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3746 3746
 
3747
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3748
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3749
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3750
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3751
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3747
+		$lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3748
+		$user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3749
+		$lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3750
+		$quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3751
+		$has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3752 3752
 
3753 3753
 
3754
-        if ( $quiz_id && is_user_logged_in()
3755
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3754
+		if ( $quiz_id && is_user_logged_in()
3755
+			&& Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3756 3756
 
3757
-            $no_quiz_count = 0;
3758
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3757
+			$no_quiz_count = 0;
3758
+			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3759 3759
 
3760
-            // Display lesson quiz status message
3761
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3762
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3763
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3764
-                if( $has_quiz_questions ) {
3765
-                   // echo $status['extra'];
3766
-                } // End If Statement
3767
-            } // End If Statement
3760
+			// Display lesson quiz status message
3761
+			if ( $has_user_completed_lesson || $has_quiz_questions ) {
3762
+				$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3763
+				echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3764
+				if( $has_quiz_questions ) {
3765
+				   // echo $status['extra'];
3766
+				} // End If Statement
3767
+			} // End If Statement
3768 3768
 
3769
-        }
3769
+		}
3770 3770
 
3771
-    }
3771
+	}
3772 3772
 
3773 3773
 } // End Class
3774 3774
 
Please login to merge, or discard this patch.
includes/class-sensei-settings.php 2 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -21,43 +21,43 @@  discard block
 block discarded – undo
21 21
 	 * @return void
22 22
 	 */
23 23
 	public function __construct () {
24
-	    parent::__construct(); // Required in extended classes.
24
+		parent::__construct(); // Required in extended classes.
25 25
 
26
-        $this->token = 'woothemes-sensei-settings';
27
-        add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) );
26
+		$this->token = 'woothemes-sensei-settings';
27
+		add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) );
28 28
 
29
-        // Setup Admin Settings data
30
-        if ( is_admin() ) {
29
+		// Setup Admin Settings data
30
+		if ( is_admin() ) {
31 31
 
32
-            $this->has_tabs 	= true;
33
-            $this->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
34
-            $this->menu_label	= __( 'Settings', 'woothemes-sensei' );
35
-            $this->page_slug	= 'woothemes-sensei-settings';
32
+			$this->has_tabs 	= true;
33
+			$this->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
34
+			$this->menu_label	= __( 'Settings', 'woothemes-sensei' );
35
+			$this->page_slug	= 'woothemes-sensei-settings';
36 36
 
37
-        } // End If Statement
37
+		} // End If Statement
38 38
 
39
-        $this->register_hook_listener();
40
-        $this->get_settings();
39
+		$this->register_hook_listener();
40
+		$this->get_settings();
41 41
 
42 42
 	} // End __construct()
43 43
 
44
-    /**
45
-     * Get settings value
46
-     *
47
-     * @since 1.9.0
48
-     * @param string $setting_name
49
-     * @return mixed
50
-     */
51
-    public function get( $setting_name ){
44
+	/**
45
+	 * Get settings value
46
+	 *
47
+	 * @since 1.9.0
48
+	 * @param string $setting_name
49
+	 * @return mixed
50
+	 */
51
+	public function get( $setting_name ){
52 52
 
53
-        if( isset( $this->settings[ $setting_name ] ) ){
53
+		if( isset( $this->settings[ $setting_name ] ) ){
54 54
 
55
-            return $this->settings[ $setting_name ];
55
+			return $this->settings[ $setting_name ];
56 56
 
57
-        }
57
+		}
58 58
 
59
-        return false;
60
-    }
59
+		return false;
60
+	}
61 61
 
62 62
 	/**
63 63
 	 * Register the settings screen within the WordPress admin.
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$complete_settings = array( 'passed' => __( 'Once all the course lessons have been completed', 'woothemes-sensei' ), 'complete' => __( 'At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei' ) );
146 146
 		$course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) );
147 147
 
148
-	    $fields = array();
148
+		$fields = array();
149 149
 
150 150
 		$fields['access_permission'] = array(
151 151
 								'name' => __( 'Access Permissions', 'woothemes-sensei' ),
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
 								'section' => 'default-settings'
208 208
 								);
209 209
 
210
-    	// Course Settings
210
+		// Course Settings
211 211
 
212
-    	$fields['course_completion'] = array(
212
+		$fields['course_completion'] = array(
213 213
 								'name' => __( 'Courses are complete:', 'woothemes-sensei' ),
214 214
 								'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ),
215 215
 								'type' => 'select',
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 								'options' => $complete_settings
220 220
 								);
221 221
 
222
-    	$fields['course_author'] = array(
222
+		$fields['course_author'] = array(
223 223
 								'name' => __( 'Display Course Author', 'woothemes-sensei' ),
224 224
 								'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ),
225 225
 								'type' => 'checkbox',
@@ -447,10 +447,10 @@  discard block
 block discarded – undo
447 447
 		);
448 448
 
449 449
 		$teacher_email_options = array(
450
-            'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ),
451
-            'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ),
452
-            'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ),
453
-            'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ),
450
+			'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ),
451
+			'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ),
452
+			'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ),
453
+			'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ),
454 454
 			'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ),
455 455
 		);
456 456
 
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 
560 560
 		if ( Sensei_WC::is_woocommerce_active() ) {
561 561
 			// WooCommerce Settings
562
-    		$fields['woocommerce_enabled'] = array(
562
+			$fields['woocommerce_enabled'] = array(
563 563
 									'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ),
564 564
 									'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ),
565 565
 									'type' => 'checkbox',
@@ -647,14 +647,14 @@  discard block
 block discarded – undo
647 647
 		$page_items[] = __( 'Select a Page:', 'woothemes-sensei' );
648 648
 
649 649
 		foreach ( $pages_split as $k => $v ) {
650
-		    $id = '';
651
-		    // Get the ID value.
652
-		    preg_match( '/value="(.*?)"/i', $v, $matches );
653
-
654
-		    if ( isset( $matches[1] ) ) {
655
-		        $id = $matches[1];
656
-		        $page_items[$id] = trim( strip_tags( $v ) );
657
-		    } // End If Statement
650
+			$id = '';
651
+			// Get the ID value.
652
+			preg_match( '/value="(.*?)"/i', $v, $matches );
653
+
654
+			if ( isset( $matches[1] ) ) {
655
+				$id = $matches[1];
656
+				$page_items[$id] = trim( strip_tags( $v ) );
657
+			} // End If Statement
658 658
 		} // End For Loop
659 659
 
660 660
 		$pages_array = $page_items;
@@ -671,22 +671,22 @@  discard block
 block discarded – undo
671 671
 		Sensei_Language_Pack_Manager::messages();
672 672
 	}
673 673
 
674
-    /**
675
-     * Flush the rewrite rules after the settings have been updated.
676
-     * This is to ensure that the
677
-     *
678
-     * @since 1.9.0
679
-     */
680
-    public static function flush_rewrite_rules(){
674
+	/**
675
+	 * Flush the rewrite rules after the settings have been updated.
676
+	 * This is to ensure that the
677
+	 *
678
+	 * @since 1.9.0
679
+	 */
680
+	public static function flush_rewrite_rules(){
681 681
 
682
-        if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ]
683
-            && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) {
682
+		if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ]
683
+			&& isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) {
684 684
 
685
-            Sensei()->initiate_rewrite_rules_flush();
685
+			Sensei()->initiate_rewrite_rules_flush();
686 686
 
687
-        }
687
+		}
688 688
 
689
-    }//end  flush_cache
689
+	}//end  flush_cache
690 690
 } // End Class
691 691
 
692 692
 /**
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /*
5 5
  * Sensei Settings Class
@@ -20,18 +20,18 @@  discard block
 block discarded – undo
20 20
 	 * @since 1.0.0
21 21
 	 * @return void
22 22
 	 */
23
-	public function __construct () {
23
+	public function __construct() {
24 24
 	    parent::__construct(); // Required in extended classes.
25 25
 
26 26
         $this->token = 'woothemes-sensei-settings';
27
-        add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) );
27
+        add_action('init', array(__CLASS__, 'flush_rewrite_rules'));
28 28
 
29 29
         // Setup Admin Settings data
30
-        if ( is_admin() ) {
30
+        if (is_admin()) {
31 31
 
32 32
             $this->has_tabs 	= true;
33
-            $this->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
34
-            $this->menu_label	= __( 'Settings', 'woothemes-sensei' );
33
+            $this->name = __('Sensei Settings', 'woothemes-sensei');
34
+            $this->menu_label = __('Settings', 'woothemes-sensei');
35 35
             $this->page_slug	= 'woothemes-sensei-settings';
36 36
 
37 37
         } // End If Statement
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
      * @param string $setting_name
49 49
      * @return mixed
50 50
      */
51
-    public function get( $setting_name ){
51
+    public function get($setting_name) {
52 52
 
53
-        if( isset( $this->settings[ $setting_name ] ) ){
53
+        if (isset($this->settings[$setting_name])) {
54 54
 
55
-            return $this->settings[ $setting_name ];
55
+            return $this->settings[$setting_name];
56 56
 
57 57
         }
58 58
 
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
 	 * @since  1.0.0
66 66
 	 * @return void
67 67
 	 */
68
-	public function register_settings_screen () {
68
+	public function register_settings_screen() {
69 69
 
70 70
 		$this->settings_version = Sensei()->version; // Use the global plugin version on this settings screen.
71
-		$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
71
+		$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
72 72
 		$this->hook = $hook;
73 73
 
74
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
75
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
76
-			add_action( 'admin_notices', array( $this, 'language_pack_notices' ) );
77
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
78
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
74
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
75
+			add_action('admin_notices', array($this, 'settings_errors'));
76
+			add_action('admin_notices', array($this, 'language_pack_notices'));
77
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
78
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
79 79
 		}
80 80
 	} // End register_settings_screen()
81 81
 
@@ -85,49 +85,49 @@  discard block
 block discarded – undo
85 85
 	 * @since  1.0.0
86 86
 	 * @return void
87 87
 	 */
88
-	public function init_sections () {
88
+	public function init_sections() {
89 89
 		$sections = array();
90 90
 
91 91
 		$sections['default-settings'] = array(
92
-			'name' 			=> __( 'General', 'woothemes-sensei' ),
93
-			'description'	=> __( 'Settings that apply to the entire plugin.', 'woothemes-sensei' )
92
+			'name' 			=> __('General', 'woothemes-sensei'),
93
+			'description'	=> __('Settings that apply to the entire plugin.', 'woothemes-sensei')
94 94
 		);
95 95
 
96 96
 		$sections['course-settings'] = array(
97
-			'name' 			=> __( 'Courses', 'woothemes-sensei' ),
98
-			'description'	=> __( 'Settings that apply to all Courses.', 'woothemes-sensei' )
97
+			'name' 			=> __('Courses', 'woothemes-sensei'),
98
+			'description'	=> __('Settings that apply to all Courses.', 'woothemes-sensei')
99 99
 		);
100 100
 
101 101
 		$sections['lesson-settings'] = array(
102
-			'name' 			=> __( 'Lessons', 'woothemes-sensei' ),
103
-			'description'	=> __( 'Settings that apply to all Lessons.', 'woothemes-sensei' )
102
+			'name' 			=> __('Lessons', 'woothemes-sensei'),
103
+			'description'	=> __('Settings that apply to all Lessons.', 'woothemes-sensei')
104 104
 		);
105 105
 
106 106
 		$sections['email-notification-settings'] = array(
107
-			'name' 			=> __( 'Email Notifications', 'woothemes-sensei' ),
108
-			'description'	=> __( 'Settings for email notifications sent from your site.', 'woothemes-sensei' )
107
+			'name' 			=> __('Email Notifications', 'woothemes-sensei'),
108
+			'description'	=> __('Settings for email notifications sent from your site.', 'woothemes-sensei')
109 109
 		);
110 110
 
111 111
 		$sections['learner-profile-settings'] = array(
112
-			'name' 			=> __( 'Learner Profiles', 'woothemes-sensei' ),
113
-			'description'	=> __( 'Settings for public Learner Profiles.', 'woothemes-sensei' )
112
+			'name' 			=> __('Learner Profiles', 'woothemes-sensei'),
113
+			'description'	=> __('Settings for public Learner Profiles.', 'woothemes-sensei')
114 114
 		);
115 115
 
116
-		if ( Sensei_WC::is_woocommerce_present() ) {
116
+		if (Sensei_WC::is_woocommerce_present()) {
117 117
 			$sections['woocommerce-settings'] = array(
118
-				'name' 			=> __( 'WooCommerce', 'woothemes-sensei' ),
119
-				'description'	=> __( 'Optional settings for WooCommerce functions.', 'woothemes-sensei' )
118
+				'name' 			=> __('WooCommerce', 'woothemes-sensei'),
119
+				'description'	=> __('Optional settings for WooCommerce functions.', 'woothemes-sensei')
120 120
 			);
121 121
 		} // End If Statement
122 122
 
123
-		if ( 'en_US' !== get_locale() ) {
123
+		if ('en_US' !== get_locale()) {
124 124
 			$sections['language-settings'] = array(
125
-				'name' 			=> __( 'Language', 'woothemes-sensei' ),
126
-				'description'	=> __( 'Language options.', 'woothemes-sensei' )
125
+				'name' 			=> __('Language', 'woothemes-sensei'),
126
+				'description'	=> __('Language options.', 'woothemes-sensei')
127 127
 			);
128 128
 		}
129 129
 
130
-		$this->sections = apply_filters( 'sensei_settings_tabs', $sections );
130
+		$this->sections = apply_filters('sensei_settings_tabs', $sections);
131 131
 	} // End init_sections()
132 132
 
133 133
 	/**
@@ -137,71 +137,71 @@  discard block
 block discarded – undo
137 137
 	 * @uses   Sensei_Utils::get_slider_types()
138 138
 	 * @return void
139 139
 	 */
140
-	public function init_fields () {
140
+	public function init_fields() {
141 141
 		global $pagenow;
142 142
 
143 143
 		$pages_array = $this->pages_array();
144
-		$posts_per_page_array = array( '0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20' );
145
-		$complete_settings = array( 'passed' => __( 'Once all the course lessons have been completed', 'woothemes-sensei' ), 'complete' => __( 'At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei' ) );
146
-		$course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) );
144
+		$posts_per_page_array = array('0' => '0', '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20');
145
+		$complete_settings = array('passed' => __('Once all the course lessons have been completed', 'woothemes-sensei'), 'complete' => __('At any time (by clicking the \'Complete Course\' button)', 'woothemes-sensei'));
146
+		$course_display_settings = array('excerpt' => __('Course Excerpt', 'woothemes-sensei'), 'full' => __('Full Course Content', 'woothemes-sensei'));
147 147
 
148 148
 	    $fields = array();
149 149
 
150 150
 		$fields['access_permission'] = array(
151
-								'name' => __( 'Access Permissions', 'woothemes-sensei' ),
152
-								'description' => __( 'Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei' ),
151
+								'name' => __('Access Permissions', 'woothemes-sensei'),
152
+								'description' => __('Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei'),
153 153
 								'type' => 'checkbox',
154 154
 								'default' => true,
155 155
 								'section' => 'default-settings'
156 156
 								);
157 157
 
158 158
 		$fields['messages_disable'] = array(
159
-								'name' => __( 'Disable Private Messages', 'woothemes-sensei' ),
160
-								'description' => __( 'Disable the private message functions between learners and teachers.', 'woothemes-sensei' ),
159
+								'name' => __('Disable Private Messages', 'woothemes-sensei'),
160
+								'description' => __('Disable the private message functions between learners and teachers.', 'woothemes-sensei'),
161 161
 								'type' => 'checkbox',
162 162
 								'default' => false,
163 163
 								'section' => 'default-settings'
164 164
 								);
165 165
 
166 166
 		$fields['course_page'] = array(
167
-								'name' => __( 'Course Archive Page', 'woothemes-sensei' ),
168
-								'description' => __( 'The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei' ),
167
+								'name' => __('Course Archive Page', 'woothemes-sensei'),
168
+								'description' => __('The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei'),
169 169
 								'type' => 'select',
170
-								'default' => get_option( 'woothemes-sensei_courses_page_id', 0 ),
170
+								'default' => get_option('woothemes-sensei_courses_page_id', 0),
171 171
 								'section' => 'default-settings',
172 172
 								'required' => 0,
173 173
 								'options' => $pages_array
174 174
 								);
175 175
 
176 176
 		$fields['my_course_page'] = array(
177
-								'name' => __( 'My Courses Page', 'woothemes-sensei' ),
178
-								'description' => __( 'The page to use to display the courses that a user is currently taking as well as the courses a user has complete.', 'woothemes-sensei' ),
177
+								'name' => __('My Courses Page', 'woothemes-sensei'),
178
+								'description' => __('The page to use to display the courses that a user is currently taking as well as the courses a user has complete.', 'woothemes-sensei'),
179 179
 								'type' => 'select',
180
-								'default' => get_option( 'woothemes-sensei_user_dashboard_page_id', 0 ),
180
+								'default' => get_option('woothemes-sensei_user_dashboard_page_id', 0),
181 181
 								'section' => 'default-settings',
182 182
 								'required' => 0,
183 183
 								'options' => $pages_array
184 184
 								);
185 185
 
186 186
 		$fields['placeholder_images_enable'] = array(
187
-								'name' => __( 'Use placeholder images', 'woothemes-sensei' ),
188
-								'description' => __( 'Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei' ),
187
+								'name' => __('Use placeholder images', 'woothemes-sensei'),
188
+								'description' => __('Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei'),
189 189
 								'type' => 'checkbox',
190 190
 								'default' => false,
191 191
 								'section' => 'default-settings'
192 192
 								);
193 193
 
194 194
 		$fields['styles_disable'] = array(
195
-								'name' => __( 'Disable Sensei Styles', 'woothemes-sensei' ),
196
-								'description' => __( 'Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei' ),
195
+								'name' => __('Disable Sensei Styles', 'woothemes-sensei'),
196
+								'description' => __('Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei'),
197 197
 								'type' => 'checkbox',
198 198
 								'default' => false,
199 199
 								'section' => 'default-settings'
200 200
 								);
201 201
 
202 202
 		$fields['js_disable'] = array(
203
-								'name' => __( 'Disable Sensei Javascript', 'woothemes-sensei' ),
204
-								'description' => __( 'Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei' ),
203
+								'name' => __('Disable Sensei Javascript', 'woothemes-sensei'),
204
+								'description' => __('Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei'),
205 205
 								'type' => 'checkbox',
206 206
 								'default' => false,
207 207
 								'section' => 'default-settings'
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
     	// Course Settings
211 211
 
212 212
     	$fields['course_completion'] = array(
213
-								'name' => __( 'Courses are complete:', 'woothemes-sensei' ),
214
-								'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ),
213
+								'name' => __('Courses are complete:', 'woothemes-sensei'),
214
+								'description' => __('This will determine when courses are marked as complete.', 'woothemes-sensei'),
215 215
 								'type' => 'select',
216 216
 								'default' => 'passed',
217 217
 								'section' => 'course-settings',
@@ -220,16 +220,16 @@  discard block
 block discarded – undo
220 220
 								);
221 221
 
222 222
     	$fields['course_author'] = array(
223
-								'name' => __( 'Display Course Author', 'woothemes-sensei' ),
224
-								'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ),
223
+								'name' => __('Display Course Author', 'woothemes-sensei'),
224
+								'description' => __('Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei'),
225 225
 								'type' => 'checkbox',
226 226
 								'default' => true,
227 227
 								'section' => 'course-settings'
228 228
 								);
229 229
 
230 230
 		$fields['my_course_amount'] = array(
231
-								'name' => __( 'My Courses Pagination', 'woothemes-sensei' ),
232
-								'description' => __( 'The number of courses to output for the my courses page.', 'woothemes-sensei' ),
231
+								'name' => __('My Courses Pagination', 'woothemes-sensei'),
232
+								'description' => __('The number of courses to output for the my courses page.', 'woothemes-sensei'),
233 233
 								'type' => 'range',
234 234
 								'default' => '0',
235 235
 								'section' => 'course-settings',
@@ -238,16 +238,16 @@  discard block
 block discarded – undo
238 238
 								);
239 239
 
240 240
 		$fields['course_archive_image_enable'] = array(
241
-								'name' => __( 'Course Archive Image', 'woothemes-sensei' ),
242
-								'description' => __( 'Output the Course Image on the Course Archive Page.', 'woothemes-sensei' ),
241
+								'name' => __('Course Archive Image', 'woothemes-sensei'),
242
+								'description' => __('Output the Course Image on the Course Archive Page.', 'woothemes-sensei'),
243 243
 								'type' => 'checkbox',
244 244
 								'default' => true,
245 245
 								'section' => 'course-settings'
246 246
 								);
247 247
 
248 248
 		$fields['course_archive_image_width'] = array(
249
-								'name' => __( 'Image Width - Archive', 'woothemes-sensei' ),
250
-								'description' => __( 'The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
249
+								'name' => __('Image Width - Archive', 'woothemes-sensei'),
250
+								'description' => __('The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
251 251
 								'type' => 'text',
252 252
 								'default' => '100',
253 253
 								'section' => 'course-settings',
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 								);
256 256
 
257 257
 		$fields['course_archive_image_height'] = array(
258
-								'name' => __( 'Image Height - Archive', 'woothemes-sensei' ),
259
-								'description' => __( 'The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
258
+								'name' => __('Image Height - Archive', 'woothemes-sensei'),
259
+								'description' => __('The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
260 260
 								'type' => 'text',
261 261
 								'default' => '100',
262 262
 								'section' => 'course-settings',
@@ -264,24 +264,24 @@  discard block
 block discarded – undo
264 264
 								);
265 265
 
266 266
 		$fields['course_archive_image_hard_crop'] = array(
267
-								'name' => __( 'Image Hard Crop - Archive', 'woothemes-sensei' ),
268
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
267
+								'name' => __('Image Hard Crop - Archive', 'woothemes-sensei'),
268
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
269 269
 								'type' => 'checkbox',
270 270
 								'default' => false,
271 271
 								'section' => 'course-settings'
272 272
 								);
273 273
 
274 274
 		$fields['course_single_image_enable'] = array(
275
-								'name' => __( 'Single Course Image', 'woothemes-sensei' ),
276
-								'description' => __( 'Output the Course Image on the Single Course Page.', 'woothemes-sensei' ),
275
+								'name' => __('Single Course Image', 'woothemes-sensei'),
276
+								'description' => __('Output the Course Image on the Single Course Page.', 'woothemes-sensei'),
277 277
 								'type' => 'checkbox',
278 278
 								'default' => false,
279 279
 								'section' => 'course-settings'
280 280
 								);
281 281
 
282 282
 		$fields['course_single_image_width'] = array(
283
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
284
-								'description' => __( 'The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
283
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
284
+								'description' => __('The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
285 285
 								'type' => 'text',
286 286
 								'default' => '100',
287 287
 								'section' => 'course-settings',
@@ -289,8 +289,8 @@  discard block
 block discarded – undo
289 289
 								);
290 290
 
291 291
 		$fields['course_single_image_height'] = array(
292
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
293
-								'description' => __( 'The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
292
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
293
+								'description' => __('The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
294 294
 								'type' => 'text',
295 295
 								'default' => '100',
296 296
 								'section' => 'course-settings',
@@ -298,16 +298,16 @@  discard block
 block discarded – undo
298 298
 								);
299 299
 
300 300
 		$fields['course_single_image_hard_crop'] = array(
301
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
302
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
301
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
302
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
303 303
 								'type' => 'checkbox',
304 304
 								'default' => false,
305 305
 								'section' => 'course-settings'
306 306
 								);
307 307
 
308 308
 		$fields['course_single_content_display'] = array(
309
-								'name' => __( 'Single Course page displays:', 'woothemes-sensei' ),
310
-								'description' => __( 'Determines what content to display on the single course page.', 'woothemes-sensei' ),
309
+								'name' => __('Single Course page displays:', 'woothemes-sensei'),
310
+								'description' => __('Determines what content to display on the single course page.', 'woothemes-sensei'),
311 311
 								'type' => 'select',
312 312
 								'default' => 'excerpt',
313 313
 								'section' => 'course-settings',
@@ -316,18 +316,18 @@  discard block
 block discarded – undo
316 316
 								);
317 317
 
318 318
 		$fields['course_archive_featured_enable'] = array(
319
-								'name' => __( 'Featured Courses Panel', 'woothemes-sensei' ),
320
-								'description' => __( 'Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
319
+								'name' => __('Featured Courses Panel', 'woothemes-sensei'),
320
+								'description' => __('Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
321 321
 								'type' => 'checkbox',
322 322
 								'default' => true,
323 323
 								'section' => 'course-settings'
324 324
 								);
325 325
 
326 326
 		$fields['course_archive_more_link_text'] = array(
327
-								'name' => __( 'More link text', 'woothemes-sensei' ),
328
-								'description' => __( 'The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei' ),
327
+								'name' => __('More link text', 'woothemes-sensei'),
328
+								'description' => __('The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei'),
329 329
 								'type' => 'text',
330
-								'default' => __ ( 'More', 'woothemes-sensei' ),
330
+								'default' => __('More', 'woothemes-sensei'),
331 331
 								'section' => 'course-settings',
332 332
 								'required' => 0
333 333
 								);
@@ -335,32 +335,32 @@  discard block
 block discarded – undo
335 335
 		// Lesson Settings
336 336
 
337 337
 		$fields['lesson_comments'] = array(
338
-								'name' => __( 'Allow Comments for Lessons', 'woothemes-sensei' ),
339
-								'description' => __( 'This will allow learners to post comments on the single Lesson page, only learner who have access to the Lesson will be allowed to comment.', 'woothemes-sensei' ),
338
+								'name' => __('Allow Comments for Lessons', 'woothemes-sensei'),
339
+								'description' => __('This will allow learners to post comments on the single Lesson page, only learner who have access to the Lesson will be allowed to comment.', 'woothemes-sensei'),
340 340
 								'type' => 'checkbox',
341 341
 								'default' => true,
342 342
 								'section' => 'lesson-settings'
343 343
 								);
344 344
 
345 345
 		$fields['lesson_author'] = array(
346
-								'name' => __( 'Display Lesson Author', 'woothemes-sensei' ),
347
-								'description' => __( 'Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei' ),
346
+								'name' => __('Display Lesson Author', 'woothemes-sensei'),
347
+								'description' => __('Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei'),
348 348
 								'type' => 'checkbox',
349 349
 								'default' => true,
350 350
 								'section' => 'lesson-settings'
351 351
 								);
352 352
 
353 353
 		$fields['course_lesson_image_enable'] = array(
354
-								'name' => __( 'Course Lesson Images', 'woothemes-sensei' ),
355
-								'description' => __( 'Output the Lesson Image on the Single Course Page.', 'woothemes-sensei' ),
354
+								'name' => __('Course Lesson Images', 'woothemes-sensei'),
355
+								'description' => __('Output the Lesson Image on the Single Course Page.', 'woothemes-sensei'),
356 356
 								'type' => 'checkbox',
357 357
 								'default' => false,
358 358
 								'section' => 'lesson-settings'
359 359
 								);
360 360
 
361 361
 		$fields['lesson_archive_image_width'] = array(
362
-								'name' => __( 'Image Width - Course Lessons', 'woothemes-sensei' ),
363
-								'description' => __( 'The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
362
+								'name' => __('Image Width - Course Lessons', 'woothemes-sensei'),
363
+								'description' => __('The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
364 364
 								'type' => 'text',
365 365
 								'default' => '100',
366 366
 								'section' => 'lesson-settings',
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 								);
369 369
 
370 370
 		$fields['lesson_archive_image_height'] = array(
371
-								'name' => __( 'Image Height - Course Lessons', 'woothemes-sensei' ),
372
-								'description' => __( 'The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
371
+								'name' => __('Image Height - Course Lessons', 'woothemes-sensei'),
372
+								'description' => __('The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
373 373
 								'type' => 'text',
374 374
 								'default' => '100',
375 375
 								'section' => 'lesson-settings',
@@ -377,24 +377,24 @@  discard block
 block discarded – undo
377 377
 								);
378 378
 
379 379
 		$fields['lesson_archive_image_hard_crop'] = array(
380
-								'name' => __( 'Image Hard Crop - Course Lessons', 'woothemes-sensei' ),
381
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
380
+								'name' => __('Image Hard Crop - Course Lessons', 'woothemes-sensei'),
381
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
382 382
 								'type' => 'checkbox',
383 383
 								'default' => false,
384 384
 								'section' => 'lesson-settings'
385 385
 								);
386 386
 
387 387
 		$fields['lesson_single_image_enable'] = array(
388
-								'name' => __( 'Single Lesson Images', 'woothemes-sensei' ),
389
-								'description' => __( 'Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei' ),
388
+								'name' => __('Single Lesson Images', 'woothemes-sensei'),
389
+								'description' => __('Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei'),
390 390
 								'type' => 'checkbox',
391 391
 								'default' => false,
392 392
 								'section' => 'lesson-settings'
393 393
 								);
394 394
 
395 395
 		$fields['lesson_single_image_width'] = array(
396
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
397
-								'description' => __( 'The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
396
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
397
+								'description' => __('The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
398 398
 								'type' => 'text',
399 399
 								'default' => '100',
400 400
 								'section' => 'lesson-settings',
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
 								);
403 403
 
404 404
 		$fields['lesson_single_image_height'] = array(
405
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
406
-								'description' => __( 'The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
405
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
406
+								'description' => __('The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
407 407
 								'type' => 'text',
408 408
 								'default' => '100',
409 409
 								'section' => 'lesson-settings',
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
 								);
412 412
 
413 413
 		$fields['lesson_single_image_hard_crop'] = array(
414
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
415
-								'description' => sprintf( __( 'After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/regenerate-thumbnails/' ) . '">', '</a>' ),
414
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
415
+								'description' => sprintf(__('After changing this setting, you may need to %1$sregenerate your thumbnails%2$s.', 'woothemes-sensei'), '<a href="'.esc_url('http://wordpress.org/extend/plugins/regenerate-thumbnails/').'">', '</a>'),
416 416
 								'type' => 'checkbox',
417 417
 								'default' => false,
418 418
 								'section' => 'lesson-settings'
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 
421 421
 		// Learner Profile settings
422 422
 
423
-		$profile_url_base = apply_filters( 'sensei_learner_profiles_url_base', __( 'learner', 'woothemes-sensei') );
424
-		$profile_url_example = trailingslashit( get_site_url() ) . $profile_url_base . '/%username%';
423
+		$profile_url_base = apply_filters('sensei_learner_profiles_url_base', __('learner', 'woothemes-sensei'));
424
+		$profile_url_example = trailingslashit(get_site_url()).$profile_url_base.'/%username%';
425 425
 
426 426
 		$fields['learner_profile_enable'] = array(
427
-							'name' => __( 'Public learner profiles', 'woothemes-sensei' ),
428
-							'description' => sprintf( __( 'Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei' ), $profile_url_example ),
427
+							'name' => __('Public learner profiles', 'woothemes-sensei'),
428
+							'description' => sprintf(__('Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei'), $profile_url_example),
429 429
 							'type' => 'checkbox',
430 430
 							'default' => true,
431 431
 							'section' => 'learner-profile-settings'
432 432
 							);
433 433
 
434 434
 		$fields['learner_profile_show_courses'] = array(
435
-							'name' => __( 'Show learner\'s courses', 'woothemes-sensei' ),
436
-							'description' => __( 'Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei' ),
435
+							'name' => __('Show learner\'s courses', 'woothemes-sensei'),
436
+							'description' => __('Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei'),
437 437
 							'type' => 'checkbox',
438 438
 							'default' => true,
439 439
 							'section' => 'learner-profile-settings'
@@ -442,70 +442,70 @@  discard block
 block discarded – undo
442 442
 		// Email notifications
443 443
 
444 444
 		$learner_email_options = array(
445
-			'learner-graded-quiz' => __( 'Their quiz is graded (auto and manual grading)', 'woothemes-sensei' ),
446
-			'learner-completed-course' => __( 'They complete a course', 'woothemes-sensei' ),
445
+			'learner-graded-quiz' => __('Their quiz is graded (auto and manual grading)', 'woothemes-sensei'),
446
+			'learner-completed-course' => __('They complete a course', 'woothemes-sensei'),
447 447
 		);
448 448
 
449 449
 		$teacher_email_options = array(
450
-            'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ),
451
-            'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ),
452
-            'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ),
453
-            'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ),
454
-			'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ),
450
+            'teacher-started-course' => __('A learner starts their course', 'woothemes-sensei'),
451
+            'teacher-completed-course' => __('A learner completes their course', 'woothemes-sensei'),
452
+            'teacher-completed-lesson' => __('A learner completes a lesson', 'woothemes-sensei'),
453
+            'teacher-quiz-submitted' => __('A learner submits a quiz for grading', 'woothemes-sensei'),
454
+			'teacher-new-message' => __('A learner sends a private message to a teacher', 'woothemes-sensei'),
455 455
 		);
456 456
 
457 457
 		$global_email_options = array(
458
-			'new-message-reply' => __( 'They receive a reply to their private message', 'woothemes-sensei' ),
458
+			'new-message-reply' => __('They receive a reply to their private message', 'woothemes-sensei'),
459 459
 		);
460 460
 
461 461
 		$fields['email_learners'] = array(
462
-								'name' => __( 'Emails Sent to Learners', 'woothemes-sensei' ),
463
-								'description' => __( 'Select the notifications that will be sent to learners.', 'woothemes-sensei' ),
462
+								'name' => __('Emails Sent to Learners', 'woothemes-sensei'),
463
+								'description' => __('Select the notifications that will be sent to learners.', 'woothemes-sensei'),
464 464
 								'type' => 'multicheck',
465 465
 								'options' => $learner_email_options,
466
-								'defaults' => array( 'learner-graded-quiz', 'learner-completed-course' ),
466
+								'defaults' => array('learner-graded-quiz', 'learner-completed-course'),
467 467
 								'section' => 'email-notification-settings'
468 468
 								);
469 469
 
470 470
 		$fields['email_teachers'] = array(
471
-								'name' => __( 'Emails Sent to Teachers', 'woothemes-sensei' ),
472
-								'description' => __( 'Select the notifications that will be sent to teachers.', 'woothemes-sensei' ),
471
+								'name' => __('Emails Sent to Teachers', 'woothemes-sensei'),
472
+								'description' => __('Select the notifications that will be sent to teachers.', 'woothemes-sensei'),
473 473
 								'type' => 'multicheck',
474 474
 								'options' => $teacher_email_options,
475
-								'defaults' => array( 'teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message' ),
475
+								'defaults' => array('teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message'),
476 476
 								'section' => 'email-notification-settings'
477 477
 								);
478 478
 
479 479
 		$fields['email_global'] = array(
480
-								'name' => __( 'Emails Sent to All Users', 'woothemes-sensei' ),
481
-								'description' => __( 'Select the notifications that will be sent to all users.', 'woothemes-sensei' ),
480
+								'name' => __('Emails Sent to All Users', 'woothemes-sensei'),
481
+								'description' => __('Select the notifications that will be sent to all users.', 'woothemes-sensei'),
482 482
 								'type' => 'multicheck',
483 483
 								'options' => $global_email_options,
484
-								'defaults' => array( 'new-message-reply' ),
484
+								'defaults' => array('new-message-reply'),
485 485
 								'section' => 'email-notification-settings'
486 486
 								);
487 487
 
488 488
 		$fields['email_from_name'] = array(
489
-								'name' => __( '"From" Name', 'woothemes-sensei' ),
490
-								'description' => __( 'The name from which all emails will be sent.', 'woothemes-sensei' ),
489
+								'name' => __('"From" Name', 'woothemes-sensei'),
490
+								'description' => __('The name from which all emails will be sent.', 'woothemes-sensei'),
491 491
 								'type' => 'text',
492
-								'default' => get_bloginfo( 'name' ),
492
+								'default' => get_bloginfo('name'),
493 493
 								'section' => 'email-notification-settings',
494 494
 								'required' => 1
495 495
 								);
496 496
 
497 497
 		$fields['email_from_address'] = array(
498
-								'name' => __( '"From" Address', 'woothemes-sensei' ),
499
-								'description' => __( 'The address from which all emails will be sent.', 'woothemes-sensei' ),
498
+								'name' => __('"From" Address', 'woothemes-sensei'),
499
+								'description' => __('The address from which all emails will be sent.', 'woothemes-sensei'),
500 500
 								'type' => 'text',
501
-								'default' => get_bloginfo( 'admin_email' ),
501
+								'default' => get_bloginfo('admin_email'),
502 502
 								'section' => 'email-notification-settings',
503 503
 								'required' => 1
504 504
 								);
505 505
 
506 506
 		$fields['email_header_image'] = array(
507
-								'name' => __( 'Header Image', 'woothemes-sensei' ),
508
-								'description' => sprintf( __( 'Enter a URL to an image you want to show in the email\'s header. Upload your image using the %1$smedia uploader%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'media-new.php' ) . '">', '</a>' ),
507
+								'name' => __('Header Image', 'woothemes-sensei'),
508
+								'description' => sprintf(__('Enter a URL to an image you want to show in the email\'s header. Upload your image using the %1$smedia uploader%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('media-new.php').'">', '</a>'),
509 509
 								'type' => 'text',
510 510
 								'default' => '',
511 511
 								'section' => 'email-notification-settings',
@@ -513,17 +513,17 @@  discard block
 block discarded – undo
513 513
 								);
514 514
 
515 515
 		$fields['email_footer_text'] = array(
516
-								'name' => __( 'Email Footer Text', 'woothemes-sensei' ),
517
-								'description' => __( 'The text to appear in the footer of Sensei emails.', 'woothemes-sensei' ),
516
+								'name' => __('Email Footer Text', 'woothemes-sensei'),
517
+								'description' => __('The text to appear in the footer of Sensei emails.', 'woothemes-sensei'),
518 518
 								'type' => 'textarea',
519
-								'default' => sprintf( __( '%1$s - Powered by Sensei', 'woothemes-sensei' ), get_bloginfo( 'name' ) ),
519
+								'default' => sprintf(__('%1$s - Powered by Sensei', 'woothemes-sensei'), get_bloginfo('name')),
520 520
 								'section' => 'email-notification-settings',
521 521
 								'required' => 0
522 522
 								);
523 523
 
524 524
 		$fields['email_base_color'] = array(
525
-								'name' => __( 'Base Colour', 'woothemes-sensei' ),
526
-								'description' => sprintf( __( 'The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
525
+								'name' => __('Base Colour', 'woothemes-sensei'),
526
+								'description' => sprintf(__('The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
527 527
 								'type' => 'color',
528 528
 								'default' => '#557da1',
529 529
 								'section' => 'email-notification-settings',
@@ -531,8 +531,8 @@  discard block
 block discarded – undo
531 531
 								);
532 532
 
533 533
 		$fields['email_background_color'] = array(
534
-								'name' => __( 'Background Colour', 'woothemes-sensei' ),
535
-								'description' => sprintf( __( 'The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
534
+								'name' => __('Background Colour', 'woothemes-sensei'),
535
+								'description' => sprintf(__('The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
536 536
 								'type' => 'color',
537 537
 								'default' => '#f5f5f5',
538 538
 								'section' => 'email-notification-settings',
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
 								);
541 541
 
542 542
 		$fields['email_body_background_color'] = array(
543
-								'name' => __( 'Body Background Colour', 'woothemes-sensei' ),
544
-								'description' => sprintf( __( 'The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
543
+								'name' => __('Body Background Colour', 'woothemes-sensei'),
544
+								'description' => sprintf(__('The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
545 545
 								'type' => 'color',
546 546
 								'default' => '#fdfdfd',
547 547
 								'section' => 'email-notification-settings',
@@ -549,35 +549,35 @@  discard block
 block discarded – undo
549 549
 								);
550 550
 
551 551
 		$fields['email_text_color'] = array(
552
-								'name' => __( 'Body Text Colour', 'woothemes-sensei' ),
553
-								'description' => sprintf( __( 'The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
552
+								'name' => __('Body Text Colour', 'woothemes-sensei'),
553
+								'description' => sprintf(__('The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
554 554
 								'type' => 'color',
555 555
 								'default' => '#505050',
556 556
 								'section' => 'email-notification-settings',
557 557
 								'required' => 1
558 558
 								);
559 559
 
560
-		if ( Sensei_WC::is_woocommerce_active() ) {
560
+		if (Sensei_WC::is_woocommerce_active()) {
561 561
 			// WooCommerce Settings
562 562
     		$fields['woocommerce_enabled'] = array(
563
-									'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ),
564
-									'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ),
563
+									'name' => __('Enable WooCommerce Courses', 'woothemes-sensei'),
564
+									'description' => __('Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei'),
565 565
 									'type' => 'checkbox',
566 566
 									'default' => true,
567 567
 									'section' => 'woocommerce-settings'
568 568
 									);
569 569
 
570 570
 			$fields['course_archive_free_enable'] = array(
571
-									'name' => __( 'Free Courses Panel', 'woothemes-sensei' ),
572
-									'description' => __( 'Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
571
+									'name' => __('Free Courses Panel', 'woothemes-sensei'),
572
+									'description' => __('Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
573 573
 									'type' => 'checkbox',
574 574
 									'default' => true,
575 575
 									'section' => 'woocommerce-settings'
576 576
 									);
577 577
 
578 578
 			$fields['course_archive_paid_enable'] = array(
579
-									'name' => __( 'Paid Courses Panel', 'woothemes-sensei' ),
580
-									'description' => __( 'Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
579
+									'name' => __('Paid Courses Panel', 'woothemes-sensei'),
580
+									'description' => __('Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
581 581
 									'type' => 'checkbox',
582 582
 									'default' => true,
583 583
 									'section' => 'woocommerce-settings'
@@ -585,18 +585,18 @@  discard block
 block discarded – undo
585 585
 
586 586
 		} // End If Statement
587 587
 
588
-		if ( 'en_US' !== get_locale() ) {
588
+		if ('en_US' !== get_locale()) {
589 589
 			$fields['install_language_pack'] = array(
590
-				'name'        => __( 'Install Language Pack', 'woothemes-sensei' ),
591
-				'description' => __( 'Use this action to install or re-install translation for your language if available.', 'woothemes-sensei' ),
590
+				'name'        => __('Install Language Pack', 'woothemes-sensei'),
591
+				'description' => __('Use this action to install or re-install translation for your language if available.', 'woothemes-sensei'),
592 592
 				'type'        => 'button',
593 593
 				'section'     => 'language-settings',
594 594
 				'target'      => Sensei_Language_Pack_Manager::get_install_uri(),
595
-				'label'       => __( 'Install', 'woothemes-sensei' )
595
+				'label'       => __('Install', 'woothemes-sensei')
596 596
 			);
597 597
 		}
598 598
 
599
-		$this->fields = apply_filters( 'sensei_settings_fields', $fields );
599
+		$this->fields = apply_filters('sensei_settings_fields', $fields);
600 600
 
601 601
 	} // End init_fields()
602 602
 
@@ -606,20 +606,20 @@  discard block
 block discarded – undo
606 606
 	 * @param  $include_milliseconds (default: true) Whether or not to include milliseconds between 0 and 1.
607 607
 	 * @return array Options between 0.1 and 10 seconds.
608 608
 	 */
609
-	private function get_duration_options ( $include_milliseconds = true ) {
610
-		$numbers = array( '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0', '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0' );
609
+	private function get_duration_options($include_milliseconds = true) {
610
+		$numbers = array('1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0', '5.5', '6.0', '6.5', '7.0', '7.5', '8.0', '8.5', '9.0', '9.5', '10.0');
611 611
 		$options = array();
612 612
 
613
-		if ( true == (bool)$include_milliseconds ) {
614
-			$milliseconds = array( '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9' );
615
-			foreach ( $milliseconds as $k => $v ) {
613
+		if (true == (bool) $include_milliseconds) {
614
+			$milliseconds = array('0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9');
615
+			foreach ($milliseconds as $k => $v) {
616 616
 				$options[$v] = $v;
617 617
 			}
618 618
 		} else {
619 619
 			$options['0.5'] = '0.5';
620 620
 		}
621 621
 
622
-		foreach ( $numbers as $k => $v ) {
622
+		foreach ($numbers as $k => $v) {
623 623
 			$options[$v] = $v;
624 624
 		}
625 625
 
@@ -635,25 +635,25 @@  discard block
 block discarded – undo
635 635
 	private function pages_array() {
636 636
 		// REFACTOR - Transform this into a field type instead.
637 637
 		// Setup an array of portfolio gallery terms for a dropdown.
638
-		$args = array( 'echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC' );
639
-		$pages_dropdown = wp_dropdown_pages( $args );
638
+		$args = array('echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC');
639
+		$pages_dropdown = wp_dropdown_pages($args);
640 640
 		$page_items = array();
641 641
 
642 642
 		// Quick string hack to make sure we get the pages with the indents.
643
-		$pages_dropdown = str_replace( "<select class='' name='page_id' id='page_id'>", '', $pages_dropdown );
644
-		$pages_dropdown = str_replace( '</select>', '', $pages_dropdown );
645
-		$pages_split = explode( '</option>', $pages_dropdown );
643
+		$pages_dropdown = str_replace("<select class='' name='page_id' id='page_id'>", '', $pages_dropdown);
644
+		$pages_dropdown = str_replace('</select>', '', $pages_dropdown);
645
+		$pages_split = explode('</option>', $pages_dropdown);
646 646
 
647
-		$page_items[] = __( 'Select a Page:', 'woothemes-sensei' );
647
+		$page_items[] = __('Select a Page:', 'woothemes-sensei');
648 648
 
649
-		foreach ( $pages_split as $k => $v ) {
649
+		foreach ($pages_split as $k => $v) {
650 650
 		    $id = '';
651 651
 		    // Get the ID value.
652
-		    preg_match( '/value="(.*?)"/i', $v, $matches );
652
+		    preg_match('/value="(.*?)"/i', $v, $matches);
653 653
 
654
-		    if ( isset( $matches[1] ) ) {
654
+		    if (isset($matches[1])) {
655 655
 		        $id = $matches[1];
656
-		        $page_items[$id] = trim( strip_tags( $v ) );
656
+		        $page_items[$id] = trim(strip_tags($v));
657 657
 		    } // End If Statement
658 658
 		} // End For Loop
659 659
 
@@ -677,10 +677,10 @@  discard block
 block discarded – undo
677 677
      *
678 678
      * @since 1.9.0
679 679
      */
680
-    public static function flush_rewrite_rules(){
680
+    public static function flush_rewrite_rules() {
681 681
 
682
-        if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ]
683
-            && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) {
682
+        if (isset($_POST['option_page']) && 'woothemes-sensei-settings' == $_POST['option_page']
683
+            && isset($_POST['action']) && 'update' == $_POST['action']) {
684 684
 
685 685
             Sensei()->initiate_rewrite_rules_flush();
686 686
 
@@ -694,4 +694,4 @@  discard block
 block discarded – undo
694 694
  * for backward compatibility
695 695
  * @since 1.9.0
696 696
  */
697
-class WooThemes_Sensei_Settings extends Sensei_Settings{}
697
+class WooThemes_Sensei_Settings extends Sensei_Settings {}
Please login to merge, or discard this patch.
includes/class-sensei-quiz.php 1 patch
Indentation   +883 added lines, -883 removed lines patch added patch discarded remove patch
@@ -25,70 +25,70 @@  discard block
 block discarded – undo
25 25
 	 */
26 26
 	public function __construct ( $file = __FILE__ ) {
27 27
 		$this->file = $file;
28
-        $this->token = 'quiz';
28
+		$this->token = 'quiz';
29 29
 		$this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' );
30 30
 		add_action( 'save_post', array( $this, 'update_author' ));
31 31
 
32 32
 		// listen to the reset button click
33 33
 		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
34 34
 
35
-        // fire the complete quiz button submit for grading action
36
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
35
+		// fire the complete quiz button submit for grading action
36
+		add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
37 37
 
38 38
 		// fire the save user answers quiz button click responder
39 39
 		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
40 40
 
41
-        // fire the load global data function
42
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
41
+		// fire the load global data function
42
+		add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
43 43
 
44
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
44
+		add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
45 45
 
46 46
 
47
-    } // End __construct()
47
+	} // End __construct()
48 48
 
49 49
 	/**
50
-	* Update the quiz author when the lesson post type is save
51
-	*
52
-	* @param int $post_id
53
-	* @return void
54
-	*/
50
+	 * Update the quiz author when the lesson post type is save
51
+	 *
52
+	 * @param int $post_id
53
+	 * @return void
54
+	 */
55 55
 	public function update_author( $post_id ){
56 56
 
57 57
 
58 58
 		// If this isn't a 'lesson' post, don't update it.
59
-        // if this is a revision don't save it
60
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
61
-            || wp_is_post_revision( $post_id ) ) {
59
+		// if this is a revision don't save it
60
+		if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
61
+			|| wp_is_post_revision( $post_id ) ) {
62 62
 
63
-                return;
63
+				return;
64 64
 
65
-        }
66
-	    // get the lesson author id to be use late
67
-	    $saved_post = get_post( $post_id );
68
-	    $new_lesson_author_id =  $saved_post->post_author;
65
+		}
66
+		// get the lesson author id to be use late
67
+		$saved_post = get_post( $post_id );
68
+		$new_lesson_author_id =  $saved_post->post_author;
69 69
 
70
-	    //get the lessons quiz
70
+		//get the lessons quiz
71 71
 		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
72
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
72
+		foreach ( (array) $lesson_quizzes as $quiz_item ) {
73 73
 
74
-	    	if( ! $quiz_item ) {
75
-	    		continue;
76
-	    	}
74
+			if( ! $quiz_item ) {
75
+				continue;
76
+			}
77 77
 
78
-		    // setup the quiz items new author value
78
+			// setup the quiz items new author value
79 79
 			$my_post = array(
80
-			      'ID'           => $quiz_item,
81
-			      'post_author' =>  $new_lesson_author_id
80
+				  'ID'           => $quiz_item,
81
+				  'post_author' =>  $new_lesson_author_id
82 82
 			);
83 83
 
84
-            // remove the action so that it doesn't fire again
85
-            remove_action( 'save_post', array( $this, 'update_author' ));
84
+			// remove the action so that it doesn't fire again
85
+			remove_action( 'save_post', array( $this, 'update_author' ));
86 86
 
87 87
 			// Update the post into the database
88 88
 		  	wp_update_post( $my_post );
89
-	    }
89
+		}
90 90
 
91
-	    return;
91
+		return;
92 92
 	}// end update_author
93 93
 
94 94
 
@@ -119,32 +119,32 @@  discard block
 block discarded – undo
119 119
 	} // end lesson
120 120
 
121 121
 
122
-    /**
123
-     * user_save_quiz_answers_listener
124
-     *
125
-     * This function hooks into the quiz page and accepts the answer form save post.
126
-     * @since 1.7.3
127
-     * @return bool $saved;
128
-     */
129
-    public function user_save_quiz_answers_listener(){
122
+	/**
123
+	 * user_save_quiz_answers_listener
124
+	 *
125
+	 * This function hooks into the quiz page and accepts the answer form save post.
126
+	 * @since 1.7.3
127
+	 * @return bool $saved;
128
+	 */
129
+	public function user_save_quiz_answers_listener(){
130 130
 
131
-        if( ! isset( $_POST[ 'quiz_save' ])
132
-            || !isset( $_POST[ 'sensei_question' ] )
133
-            || empty( $_POST[ 'sensei_question' ] )
134
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
135
-            return;
136
-        }
131
+		if( ! isset( $_POST[ 'quiz_save' ])
132
+			|| !isset( $_POST[ 'sensei_question' ] )
133
+			|| empty( $_POST[ 'sensei_question' ] )
134
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
135
+			return;
136
+		}
137 137
 
138
-        global $post;
139
-        $lesson_id = $this->get_lesson_id( $post->ID );
140
-        $quiz_answers = $_POST[ 'sensei_question' ];
141
-        // call the save function
142
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
138
+		global $post;
139
+		$lesson_id = $this->get_lesson_id( $post->ID );
140
+		$quiz_answers = $_POST[ 'sensei_question' ];
141
+		// call the save function
142
+		self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
143 143
 
144
-        // remove the hook as it should only fire once per click
145
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
144
+		// remove the hook as it should only fire once per click
145
+		remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
146 146
 
147
-    } // end user_save_quiz_answers_listener
147
+	} // end user_save_quiz_answers_listener
148 148
 
149 149
 	/**
150 150
 	 * Save the user answers for the given lesson's quiz
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @access public
156 156
 	 *
157 157
 	 * @param array $quiz_answers
158
-     * @param array $files from global $_FILES
158
+	 * @param array $files from global $_FILES
159 159
 	 * @param int $lesson_id
160 160
 	 * @param int $user_id
161 161
 	 *
@@ -163,11 +163,11 @@  discard block
 block discarded – undo
163 163
 	 */
164 164
 	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
165 165
 
166
-        if( ! ( $user_id > 0 ) ){
167
-            $user_id = get_current_user_id();
168
-        }
166
+		if( ! ( $user_id > 0 ) ){
167
+			$user_id = get_current_user_id();
168
+		}
169 169
 
170
-        // make sure the parameters are valid before continuing
170
+		// make sure the parameters are valid before continuing
171 171
 		if( empty( $lesson_id ) || empty( $user_id )
172 172
 			|| 'lesson' != get_post_type( $lesson_id )
173 173
 			||!get_userdata( $user_id )
@@ -178,25 +178,25 @@  discard block
 block discarded – undo
178 178
 		}
179 179
 
180 180
 
181
-        // start the lesson before saving the data in case the user has not started the lesson
182
-        $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
181
+		// start the lesson before saving the data in case the user has not started the lesson
182
+		$activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
183 183
 
184 184
 		//prepare the answers
185 185
 		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
186 186
 
187 187
 		// save the user data
188
-        $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
188
+		$answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
189 189
 
190 190
 		// were the answers saved correctly?
191 191
 		if( intval( $answers_saved ) > 0){
192 192
 
193
-            // save transient to make retrieval faster
194
-            $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
195
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
193
+			// save transient to make retrieval faster
194
+			$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
195
+			set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
196 196
 
197
-            // update the message showed to user
198
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
199
-        }
197
+			// update the message showed to user
198
+			Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
199
+		}
200 200
 
201 201
 		return $answers_saved;
202 202
 
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
 
205 205
 	/**
206 206
 	 * Get the user answers for the given lesson's quiz.
207
-     *
208
-     * This function returns the data that is stored on the lesson as meta and is not compatible with
209
-     * retrieving data for quiz answer before sensei 1.7.4
207
+	 *
208
+	 * This function returns the data that is stored on the lesson as meta and is not compatible with
209
+	 * retrieving data for quiz answer before sensei 1.7.4
210 210
 	 *
211 211
 	 *
212 212
 	 * @since 1.7.4
@@ -226,27 +226,27 @@  discard block
 block discarded – undo
226 226
 			return false;
227 227
 		}
228 228
 
229
-        // save some time and get the transient cached data
230
-        $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
231
-        $transient_cached_answers = get_transient( $transient_key );
229
+		// save some time and get the transient cached data
230
+		$transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
231
+		$transient_cached_answers = get_transient( $transient_key );
232 232
 
233
-        // return the transient or get the values get the values from the comment meta
234
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
233
+		// return the transient or get the values get the values from the comment meta
234
+		if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
235 235
 
236
-            $encoded_user_answers = $transient_cached_answers;
236
+			$encoded_user_answers = $transient_cached_answers;
237 237
 
238
-        }else{
238
+		}else{
239 239
 
240
-            $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
240
+			$encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
241 241
 
242
-        } // end if transient check
242
+		} // end if transient check
243 243
 
244 244
 		if( ! is_array( $encoded_user_answers ) ){
245 245
 			return false;
246 246
 		}
247 247
 
248
-        //set the transient with the new valid data for faster retrieval in future
249
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
248
+		//set the transient with the new valid data for faster retrieval in future
249
+		set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
250 250
 
251 251
 		// decode an unserialize all answers
252 252
 		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
 		$current_quiz_id = $post->ID;
281 281
 		$lesson_id = $this->get_lesson_id( $current_quiz_id );
282 282
 
283
-        // reset all user data
284
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
283
+		// reset all user data
284
+		$this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
285 285
 
286 286
 		//this function should only run once
287 287
 		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * Complete/ submit  quiz hooked function
293 293
 	 *
294 294
 	 * This function listens to the complete button submit action and processes the users submitted answers
295
-     * not that this function submits the given users quiz answers for grading.
295
+	 * not that this function submits the given users quiz answers for grading.
296 296
 	 *
297 297
 	 * @since  1.7.4
298 298
 	 * @access public
@@ -302,90 +302,90 @@  discard block
 block discarded – undo
302 302
 	 */
303 303
 	public function user_quiz_submit_listener() {
304 304
 
305
-        // only respond to valid quiz completion submissions
306
-        if( ! isset( $_POST[ 'quiz_complete' ])
307
-            || !isset( $_POST[ 'sensei_question' ] )
308
-            || empty( $_POST[ 'sensei_question' ] )
309
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
310
-            return;
311
-        }
305
+		// only respond to valid quiz completion submissions
306
+		if( ! isset( $_POST[ 'quiz_complete' ])
307
+			|| !isset( $_POST[ 'sensei_question' ] )
308
+			|| empty( $_POST[ 'sensei_question' ] )
309
+			||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
310
+			return;
311
+		}
312 312
 
313
-        global $post, $current_user;
314
-        $lesson_id = $this->get_lesson_id( $post->ID );
315
-        $quiz_answers = $_POST[ 'sensei_question' ];
313
+		global $post, $current_user;
314
+		$lesson_id = $this->get_lesson_id( $post->ID );
315
+		$quiz_answers = $_POST[ 'sensei_question' ];
316 316
 
317
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
317
+		self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
318 318
 
319 319
 	} // End sensei_complete_quiz()
320 320
 
321
-    /**
322
-     * This function set's up the data need for the quiz page
323
-     *
324
-     * This function hooks into sensei_complete_quiz and load the global data for the
325
-     * current quiz.
326
-     *
327
-     * @since 1.7.4
328
-     * @access public
329
-     *
330
-     */
331
-    public function load_global_quiz_data(){
321
+	/**
322
+	 * This function set's up the data need for the quiz page
323
+	 *
324
+	 * This function hooks into sensei_complete_quiz and load the global data for the
325
+	 * current quiz.
326
+	 *
327
+	 * @since 1.7.4
328
+	 * @access public
329
+	 *
330
+	 */
331
+	public function load_global_quiz_data(){
332 332
 
333
-        global  $post, $current_user;
334
-        $this->data = new stdClass();
333
+		global  $post, $current_user;
334
+		$this->data = new stdClass();
335 335
 
336
-        // Default grade
337
-        $grade = 0;
336
+		// Default grade
337
+		$grade = 0;
338 338
 
339
-        // Get Quiz Questions
340
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
339
+		// Get Quiz Questions
340
+		$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
341 341
 
342
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
342
+		$quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
343 343
 
344
-        // Get quiz grade type
345
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
344
+		// Get quiz grade type
345
+		$quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
346 346
 
347
-        // Get quiz pass setting
348
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
347
+		// Get quiz pass setting
348
+		$pass_required = get_post_meta( $post->ID, '_pass_required', true );
349 349
 
350
-        // Get quiz pass mark
351
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
350
+		// Get quiz pass mark
351
+		$quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
352 352
 
353
-        // Get latest quiz answers and grades
354
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
355
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
356
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
357
-        $user_quiz_grade = 0;
358
-        if( isset( $user_lesson_status->comment_ID ) ) {
359
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
360
-        }
353
+		// Get latest quiz answers and grades
354
+		$lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
355
+		$user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
356
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
357
+		$user_quiz_grade = 0;
358
+		if( isset( $user_lesson_status->comment_ID ) ) {
359
+			$user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
360
+		}
361 361
 
362
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
362
+		if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
363 363
 
364
-        // Check again that the lesson is complete
365
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
366
-        $user_lesson_complete = false;
367
-        if ( $user_lesson_end ) {
368
-            $user_lesson_complete = true;
369
-        } // End If Statement
364
+		// Check again that the lesson is complete
365
+		$user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
366
+		$user_lesson_complete = false;
367
+		if ( $user_lesson_end ) {
368
+			$user_lesson_complete = true;
369
+		} // End If Statement
370 370
 
371
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
372
-        //backwards compatibility
373
-        if( 'on' == $reset_allowed ) {
374
-            $reset_allowed = 1;
375
-        }
371
+		$reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
372
+		//backwards compatibility
373
+		if( 'on' == $reset_allowed ) {
374
+			$reset_allowed = 1;
375
+		}
376 376
 
377
-        // Build frontend data object for backwards compatibility
378
-        // using this is no longer recommended
379
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
380
-        $this->data->quiz_passmark = $quiz_passmark;
381
-        $this->data->quiz_lesson = $quiz_lesson_id;
382
-        $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
383
-        $this->data->user_lesson_end = $user_lesson_end;
384
-        $this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
385
-        $this->data->lesson_quiz_questions = $lesson_quiz_questions;
386
-        $this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
377
+		// Build frontend data object for backwards compatibility
378
+		// using this is no longer recommended
379
+		$this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
380
+		$this->data->quiz_passmark = $quiz_passmark;
381
+		$this->data->quiz_lesson = $quiz_lesson_id;
382
+		$this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
383
+		$this->data->user_lesson_end = $user_lesson_end;
384
+		$this->data->user_lesson_complete = $user_lesson_complete; //Sensei_Utils::user_completed_lesson( $lesson_id, get_current_user_id() );
385
+		$this->data->lesson_quiz_questions = $lesson_quiz_questions;
386
+		$this->data->reset_quiz_allowed = $reset_allowed; // Sensei_Quiz::is_reset_allowed( $lesson_id );
387 387
 
388
-    } // end load_global_quiz_data
388
+	} // end load_global_quiz_data
389 389
 
390 390
 
391 391
 	/**
@@ -415,25 +415,25 @@  discard block
 block discarded – undo
415 415
 		foreach( $unprepared_answers as $question_id => $answer ) {
416 416
 
417 417
 			//get the current questions question type
418
-            $question_type = Sensei()->question->get_question_type( $question_id );
418
+			$question_type = Sensei()->question->get_question_type( $question_id );
419 419
 
420 420
 			// Sanitise answer
421 421
 			if( 0 == get_magic_quotes_gpc() ) {
422 422
 				$answer = wp_unslash( $answer );
423 423
 			}
424 424
 
425
-            // compress the answer for saving
425
+			// compress the answer for saving
426 426
 			if( 'multi-line' == $question_type ) {
427
-                $answer = esc_html( $answer );
428
-            }elseif( 'file-upload' == $question_type  ){
429
-                $file_key = 'file_upload_' . $question_id;
430
-                if( isset( $files[ $file_key ] ) ) {
431
-                        $attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
432
-                        if( $attachment_id ) {
433
-                            $answer = $attachment_id;
434
-                        }
435
-                    }
436
-            } // end if
427
+				$answer = esc_html( $answer );
428
+			}elseif( 'file-upload' == $question_type  ){
429
+				$file_key = 'file_upload_' . $question_id;
430
+				if( isset( $files[ $file_key ] ) ) {
431
+						$attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
432
+						if( $attachment_id ) {
433
+							$answer = $attachment_id;
434
+						}
435
+					}
436
+			} // end if
437 437
 
438 438
 			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
439 439
 
@@ -442,814 +442,814 @@  discard block
 block discarded – undo
442 442
 		return $prepared_answers;
443 443
 	} // prepare_form_submitted_answers
444 444
 
445
-    /**
446
-     * Reset user submitted questions
447
-     *
448
-     * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
449
-     * the save_user_answers as currently the saved and submitted answers are stored differently.
450
-     *
451
-     * @since 1.7.4
452
-     * @access public
453
-     *
454
-     * @return bool $reset_success
455
-     * @param int $user_id
456
-     * @param int $lesson_id
457
-     */
458
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
445
+	/**
446
+	 * Reset user submitted questions
447
+	 *
448
+	 * This function resets the quiz data for a user that has been submitted fro grading already. It is different to
449
+	 * the save_user_answers as currently the saved and submitted answers are stored differently.
450
+	 *
451
+	 * @since 1.7.4
452
+	 * @access public
453
+	 *
454
+	 * @return bool $reset_success
455
+	 * @param int $user_id
456
+	 * @param int $lesson_id
457
+	 */
458
+	public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
459
+
460
+		//make sure the parameters are valid
461
+		if( empty( $lesson_id ) || empty( $user_id )
462
+			|| 'lesson' != get_post_type( $lesson_id )
463
+			|| ! get_userdata( $user_id ) ){
464
+			return false;
465
+		}
466
+
467
+
468
+
469
+		//get the users lesson status to make
470
+		$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
471
+		if( ! isset( $user_lesson_status->comment_ID ) ) {
472
+			// this user is not taking this lesson so this process is not needed
473
+			return false;
474
+		}
475
+
476
+		//get the lesson quiz and course
477
+		$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
478
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
479
+
480
+		// reset the transients
481
+		$answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
482
+		$grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
483
+		$answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
484
+		delete_transient( $answers_transient_key );
485
+		delete_transient( $grades_transient_key );
486
+		delete_transient( $answers_feedback_transient_key );
487
+
488
+		// reset the quiz answers and feedback notes
489
+		$deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
490
+		$deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
491
+		$deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
492
+
493
+		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
494
+		Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
495
+
496
+		Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
497
+
498
+		// Update course completion
499
+		Sensei_Utils::update_course_status( $user_id, $course_id );
459 500
 
460
-        //make sure the parameters are valid
461
-        if( empty( $lesson_id ) || empty( $user_id )
462
-            || 'lesson' != get_post_type( $lesson_id )
463
-            || ! get_userdata( $user_id ) ){
464
-            return false;
465
-        }
466
-
467
-
468
-
469
-        //get the users lesson status to make
470
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
471
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
472
-            // this user is not taking this lesson so this process is not needed
473
-            return false;
474
-        }
501
+		// Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
502
+		do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
503
+		Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
475 504
 
476
-        //get the lesson quiz and course
477
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
478
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
505
+		return ( $deleted_answers && $deleted_grades ) ;
479 506
 
480
-        // reset the transients
481
-        $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
482
-        $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
483
-        $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
484
-        delete_transient( $answers_transient_key );
485
-        delete_transient( $grades_transient_key );
486
-        delete_transient( $answers_feedback_transient_key );
507
+	} // end reset_user_lesson_data
487 508
 
488
-        // reset the quiz answers and feedback notes
489
-        $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
490
-        $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
491
-        $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
509
+	 /**
510
+	  * Submit the users quiz answers for grading
511
+	  *
512
+	  * This function accepts users answers and stores it but also initiates the grading
513
+	  * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
514
+	  *
515
+	  * @since 1.7.4
516
+	  * @access public
517
+	  *
518
+	  * @param array $quiz_answers
519
+	  * @param array $files from $_FILES
520
+	  * @param int $user_id
521
+	  * @param int $lesson_id
522
+	  *
523
+	  * @return bool $answers_submitted
524
+	  */
525
+	 public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
492 526
 
493
-        // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
494
-        Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
527
+		 $answers_submitted = false;
495 528
 
496
-        Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
529
+		 // get the user_id if none was passed in use the current logged in user
530
+		 if( ! intval( $user_id ) > 0 ) {
531
+			 $user_id = get_current_user_id();
532
+		 }
497 533
 
498
-        // Update course completion
499
-        Sensei_Utils::update_course_status( $user_id, $course_id );
534
+		 // make sure the parameters are valid before continuing
535
+		 if( empty( $lesson_id ) || empty( $user_id )
536
+			 || 'lesson' != get_post_type( $lesson_id )
537
+			 ||!get_userdata( $user_id )
538
+			 || !is_array( $quiz_answers ) ){
500 539
 
501
-        // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
502
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
503
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
540
+			 return false;
504 541
 
505
-        return ( $deleted_answers && $deleted_grades ) ;
542
+		 }
506 543
 
507
-    } // end reset_user_lesson_data
544
+		 // Default grade
545
+		 $grade = 0;
508 546
 
509
-     /**
510
-      * Submit the users quiz answers for grading
511
-      *
512
-      * This function accepts users answers and stores it but also initiates the grading
513
-      * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher.
514
-      *
515
-      * @since 1.7.4
516
-      * @access public
517
-      *
518
-      * @param array $quiz_answers
519
-      * @param array $files from $_FILES
520
-      * @param int $user_id
521
-      * @param int $lesson_id
522
-      *
523
-      * @return bool $answers_submitted
524
-      */
525
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
547
+		 // Get Quiz ID
548
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
526 549
 
527
-         $answers_submitted = false;
550
+		 // Get quiz grade type
551
+		 $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
528 552
 
529
-         // get the user_id if none was passed in use the current logged in user
530
-         if( ! intval( $user_id ) > 0 ) {
531
-             $user_id = get_current_user_id();
532
-         }
553
+		 // Get quiz pass setting
554
+		 $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
533 555
 
534
-         // make sure the parameters are valid before continuing
535
-         if( empty( $lesson_id ) || empty( $user_id )
536
-             || 'lesson' != get_post_type( $lesson_id )
537
-             ||!get_userdata( $user_id )
538
-             || !is_array( $quiz_answers ) ){
556
+		 // Get the minimum percentage need to pass this quiz
557
+		 $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
539 558
 
540
-             return false;
559
+		 // Handle Quiz Questions asked
560
+		 // This is to ensure we save the questions that we've asked this user and that this can't be change unless
561
+		 // the quiz is reset by admin or user( user: only if the setting is enabled ).
562
+		 // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
563
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
564
+		 $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
565
+		 if( empty( $questions_asked ) ){
541 566
 
542
-         }
567
+			 $questions_asked = array_keys( $quiz_answers );
568
+			 $questions_asked_string = implode( ',', $questions_asked );
543 569
 
544
-         // Default grade
545
-         $grade = 0;
570
+			 // Save questions that were asked in this quiz
571
+			 update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
546 572
 
547
-         // Get Quiz ID
548
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
573
+		 }
549 574
 
550
-         // Get quiz grade type
551
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
575
+		 // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
576
+		 self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
552 577
 
553
-         // Get quiz pass setting
554
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
578
+		 // Grade quiz
579
+		 $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
555 580
 
556
-         // Get the minimum percentage need to pass this quiz
557
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
581
+		 // Get Lesson Grading Setting
582
+		 $lesson_metadata = array();
583
+		 $lesson_status = 'ungraded'; // Default when completing a quiz
558 584
 
559
-         // Handle Quiz Questions asked
560
-         // This is to ensure we save the questions that we've asked this user and that this can't be change unless
561
-         // the quiz is reset by admin or user( user: only if the setting is enabled ).
562
-         // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
563
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
564
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
565
-         if( empty( $questions_asked ) ){
585
+		 // At this point the answers have been submitted
586
+		 $answers_submitted = true;
566 587
 
567
-             $questions_asked = array_keys( $quiz_answers );
568
-             $questions_asked_string = implode( ',', $questions_asked );
569
-
570
-             // Save questions that were asked in this quiz
571
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
588
+		 // if this condition is false the quiz should manually be graded by admin
589
+		 if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
572 590
 
573
-         }
591
+			 // Quiz has been automatically Graded
592
+			 if ( 'on' == $pass_required ) {
574 593
 
575
-         // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
576
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
594
+				 // Student has reached the pass mark and lesson is complete
595
+				 if ( $quiz_pass_percentage <= $grade ) {
577 596
 
578
-         // Grade quiz
579
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
597
+					 $lesson_status = 'passed';
580 598
 
581
-         // Get Lesson Grading Setting
582
-         $lesson_metadata = array();
583
-         $lesson_status = 'ungraded'; // Default when completing a quiz
599
+				 } else {
584 600
 
585
-         // At this point the answers have been submitted
586
-         $answers_submitted = true;
601
+					 $lesson_status = 'failed';
587 602
 
588
-         // if this condition is false the quiz should manually be graded by admin
589
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
603
+				 } // End If Statement
590 604
 
591
-             // Quiz has been automatically Graded
592
-             if ( 'on' == $pass_required ) {
605
+			 } else {
593 606
 
594
-                 // Student has reached the pass mark and lesson is complete
595
-                 if ( $quiz_pass_percentage <= $grade ) {
607
+				 // Student only has to partake the quiz
608
+				 $lesson_status = 'graded';
609
+
610
+			 }
611
+
612
+			 $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
613
+
614
+		 } // end if ! is_wp_error( $grade ...
615
+
616
+		 Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
596 617
 
597
-                     $lesson_status = 'passed';
618
+		 if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
598 619
 
599
-                 } else {
620
+			 /**
621
+			  * Lesson end action hook
622
+			  *
623
+			  * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
624
+			  *
625
+			  * @param int $user_id
626
+			  * @param int $lesson_id
627
+			  */
628
+			 do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
600 629
 
601
-                     $lesson_status = 'failed';
630
+		 }
602 631
 
603
-                 } // End If Statement
632
+		 /**
633
+		  * User quiz has been submitted
634
+		  *
635
+		  * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
636
+		  * results.
637
+		  *
638
+		  * @param int $user_id
639
+		  * @param int $quiz_id
640
+		  * @param string $grade
641
+		  * @param string $quiz_pass_percentage
642
+		  * @param string $quiz_grade_type
643
+		  */
644
+		 do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
604 645
 
605
-             } else {
646
+		 return $answers_submitted;
606 647
 
607
-                 // Student only has to partake the quiz
608
-                 $lesson_status = 'graded';
609
-
610
-             }
611
-
612
-             $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above
613
-
614
-         } // end if ! is_wp_error( $grade ...
615
-
616
-         Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
648
+	 }// end submit_answers_for_grading
617 649
 
618
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
650
+	 /**
651
+	  * Get the user question answer
652
+	  *
653
+	  * This function gets the the users saved answer on given quiz for the given question parameter
654
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
655
+	  *
656
+	  * @since 1.7.4
657
+	  *
658
+	  * @param int  $lesson_id
659
+	  * @param int $question_id
660
+	  * @param int  $user_id ( optional )
661
+	  *
662
+	  * @return bool $answers_submitted
663
+	  */
664
+	 public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
619 665
 
620
-             /**
621
-              * Lesson end action hook
622
-              *
623
-              * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded'
624
-              *
625
-              * @param int $user_id
626
-              * @param int $lesson_id
627
-              */
628
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
666
+		 // parameter validation
667
+		 if( empty( $lesson_id ) || empty( $question_id )
668
+			 || ! ( intval( $lesson_id  ) > 0 )
669
+			 || ! ( intval( $question_id  ) > 0 )
670
+			 || 'lesson' != get_post_type( $lesson_id )
671
+			 || 'question' != get_post_type( $question_id )) {
629 672
 
630
-         }
673
+			 return false;
674
+		 }
675
+
676
+		 if( ! ( intval( $user_id ) > 0 )   ){
677
+			 $user_id = get_current_user_id();
678
+		 }
679
+
680
+		 $users_answers = $this->get_user_answers( $lesson_id, $user_id );
681
+
682
+		 if( !$users_answers || empty( $users_answers )
683
+		 ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
684
+
685
+			 //Fallback for pre 1.7.4 data
686
+			 $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
687
+
688
+			 if( ! isset( $comment->comment_content ) ){
689
+				 return false;
690
+			 }
691
+
692
+			 return maybe_unserialize( base64_decode( $comment->comment_content ) );
693
+		 }
694
+
695
+		 return $users_answers[ $question_id ];
696
+
697
+	 }// end get_user_question_answer
698
+
699
+	 /**
700
+	  * Saving the users quiz question grades
701
+	  *
702
+	  * This function save all the grades for all the question in a given quiz on the lesson
703
+	  * comment meta. It makes use of transients to save the grades for easier access at a later stage
704
+	  *
705
+	  * @since 1.7.4
706
+	  *
707
+	  * @param array $quiz_grades{
708
+	  *      @type int $question_id
709
+	  *      @type int $question_grade
710
+	  * }
711
+	  * @param $lesson_id
712
+	  * @param $user_id (Optional) will use the current user if not supplied
713
+	  *
714
+	  * @return bool
715
+	  */
716
+	 public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
717
+
718
+		 // get the user_id if none was passed in use the current logged in user
719
+		 if( ! intval( $user_id ) > 0 ) {
720
+			 $user_id = get_current_user_id();
721
+		 }
722
+
723
+		 // make sure the parameters are valid before continuing
724
+		 if( empty( $lesson_id ) || empty( $user_id )
725
+			 || 'lesson' != get_post_type( $lesson_id )
726
+			 ||!get_userdata( $user_id )
727
+			 || !is_array( $quiz_grades ) ){
728
+
729
+			 return false;
730
+
731
+		 }
732
+
733
+		 $success = false;
734
+
735
+		 // save that data for the user on the lesson comment meta
736
+		 $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
737
+
738
+		 // were the grades save successfully ?
739
+		 if( intval( $comment_meta_id ) > 0 ) {
740
+
741
+			 $success = true;
742
+			 // save transient
743
+			 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
744
+			 set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
745
+		 }
746
+
747
+		 return $success;
748
+
749
+	 }// end set_user_grades
750
+
751
+	 /**
752
+	  * Retrieve the users quiz question grades
753
+	  *
754
+	  * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
755
+	  *
756
+	  * @since 1.7.4
757
+	  *
758
+	  * @param $lesson_id
759
+	  * @param $user_id (Optional) will use the current user if not supplied
760
+	  *
761
+	  * @return array $user_quiz_grades or false if none exists for this users
762
+	  */
763
+	 public function get_user_grades( $lesson_id, $user_id = 0 ){
764
+
765
+		 $user_grades = array();
766
+
767
+		 // get the user_id if none was passed in use the current logged in user
768
+		 if( ! intval( $user_id ) > 0 ) {
769
+			 $user_id = get_current_user_id();
770
+		 }
771
+
772
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
773
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
774
+			 return false;
775
+		 }
776
+
777
+		 // save some time and get the transient cached data
778
+		 $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
779
+		 $user_grades = get_transient( $transient_key );
780
+
781
+		 // get the data if nothing was stored in the transient
782
+		 if( empty( $user_grades  ) || false != $user_grades ){
783
+
784
+			 $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
785
+
786
+			 //set the transient with the new valid data for faster retrieval in future
787
+			 set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
788
+
789
+		 } // end if transient check
790
+
791
+		 // if there is no data for this user
792
+		 if( ! is_array( $user_grades ) ){
793
+			 return false;
794
+		 }
795
+
796
+		 return $user_grades;
797
+
798
+	 }// end  get_user_grades
799
+
800
+	 /**
801
+	  * Get the user question grade
802
+	  *
803
+	  * This function gets the grade on a quiz for the given question parameter
804
+	  * It does NOT do any grading. It simply retrieves the data that was stored during grading.
805
+	  * this function allows for a fallback to users still using the question saved data from before 1.7.4
806
+	  *
807
+	  * @since 1.7.4
808
+	  *
809
+	  * @param int  $lesson_id
810
+	  * @param int $question_id
811
+	  * @param int  $user_id ( optional )
812
+	  *
813
+	  * @return bool $question_grade
814
+	  */
815
+	 public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
816
+
817
+		 // parameter validation
818
+		 if( empty( $lesson_id ) || empty( $question_id )
819
+			 || ! ( intval( $lesson_id  ) > 0 )
820
+			 || ! ( intval( $question_id  ) > 0 )
821
+			 || 'lesson' != get_post_type( $lesson_id )
822
+			 || 'question' != get_post_type( $question_id )) {
823
+
824
+			 return false;
825
+		 }
826
+
827
+		 $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
828
+
829
+		 if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
830
+
831
+			 //fallback to data pre 1.7.4
832
+			 $args = array(
833
+				 'post_id' => $question_id,
834
+				 'user_id' => $user_id,
835
+				 'type'    => 'sensei_user_answer'
836
+			 );
837
+
838
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
839
+			 $fall_back_grade = false;
840
+			 if( isset( $question_activity->comment_ID ) ){
841
+				 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
842
+			 }
843
+
844
+			 return $fall_back_grade;
845
+
846
+		 } // end if $all_user_grades...
847
+
848
+		 return $all_user_grades[ $question_id ];
849
+
850
+	 }// end get_user_question_grade
851
+
852
+	 /**
853
+	  * Save the user's answers feedback
854
+	  *
855
+	  * For this function you must supply all three parameters. If will return false one is left out.
856
+	  * The data will be saved on the lesson ID supplied.
857
+	  *
858
+	  * @since 1.7.5
859
+	  * @access public
860
+	  *
861
+	  * @param array $answers_feedback{
862
+	  *  $type int $question_id
863
+	  *  $type string $question_feedback
864
+	  * }
865
+	  * @param int $lesson_id
866
+	  * @param int $user_id
867
+	  *
868
+	  * @return false or int $feedback_saved
869
+	  */
870
+	public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
871
+
872
+		// make sure the parameters are valid before continuing
873
+		if( empty( $lesson_id ) || empty( $user_id )
874
+			|| 'lesson' != get_post_type( $lesson_id )
875
+			||!get_userdata( $user_id )
876
+			|| !is_array( $answers_feedback ) ){
877
+
878
+			return false;
879
+
880
+		}
881
+
882
+
883
+		// check if the lesson is started before saving, if not start the lesson for the user
884
+		if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
885
+			Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
886
+		}
631 887
 
632
-         /**
633
-          * User quiz has been submitted
634
-          *
635
-          * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission
636
-          * results.
637
-          *
638
-          * @param int $user_id
639
-          * @param int $quiz_id
640
-          * @param string $grade
641
-          * @param string $quiz_pass_percentage
642
-          * @param string $quiz_grade_type
643
-          */
644
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
888
+		// encode the feedback
889
+		$encoded_answers_feedback =  array();
890
+		foreach( $answers_feedback as $question_id => $feedback ){
891
+			$encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
892
+		}
893
+
894
+		// save the user data
895
+		$feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
896
+
897
+		//Were the the question feedback save correctly?
898
+		if( intval( $feedback_saved ) > 0){
899
+
900
+			// save transient to make retrieval faster in future
901
+			 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
902
+			 set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
645 903
 
646
-         return $answers_submitted;
904
+		}
905
+
906
+		return $feedback_saved;
907
+
908
+	} // end save_user_answers_feedback
909
+
910
+	 /**
911
+	  * Get the user's answers feedback.
912
+	  *
913
+	  * This function returns the feedback submitted by the teacher/admin
914
+	  * during grading. Grading occurs manually or automatically.
915
+	  *
916
+	  * @since 1.7.5
917
+	  * @access public
918
+	  *
919
+	  * @param int $lesson_id
920
+	  * @param int $user_id
921
+	  *
922
+	  * @return false | array $answers_feedback{
923
+	  *  $type int $question_id
924
+	  *  $type string $question_feedback
925
+	  * }
926
+	  */
927
+	 public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
928
+
929
+		 $answers_feedback = array();
647 930
 
648
-     }// end submit_answers_for_grading
931
+		 // get the user_id if none was passed in use the current logged in user
932
+		 if( ! intval( $user_id ) > 0 ) {
933
+			 $user_id = get_current_user_id();
934
+		 }
649 935
 
650
-     /**
651
-      * Get the user question answer
652
-      *
653
-      * This function gets the the users saved answer on given quiz for the given question parameter
654
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
655
-      *
656
-      * @since 1.7.4
657
-      *
658
-      * @param int  $lesson_id
659
-      * @param int $question_id
660
-      * @param int  $user_id ( optional )
661
-      *
662
-      * @return bool $answers_submitted
663
-      */
664
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
936
+		 if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
937
+			 || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
938
+			 return false;
939
+		 }
940
+
941
+		 // first check the transient to save a few split seconds
942
+		 $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
943
+		 $encoded_feedback = get_transient( $transient_key );
944
+
945
+		 // get the data if nothing was stored in the transient
946
+		 if( empty( $encoded_feedback  ) || !$encoded_feedback ){
665 947
 
666
-         // parameter validation
667
-         if( empty( $lesson_id ) || empty( $question_id )
668
-             || ! ( intval( $lesson_id  ) > 0 )
669
-             || ! ( intval( $question_id  ) > 0 )
670
-             || 'lesson' != get_post_type( $lesson_id )
671
-             || 'question' != get_post_type( $question_id )) {
948
+			 $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
949
+
950
+			 //set the transient with the new valid data for faster retrieval in future
951
+			 set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
952
+
953
+		 } // end if transient check
672 954
 
673
-             return false;
674
-         }
675
-
676
-         if( ! ( intval( $user_id ) > 0 )   ){
677
-             $user_id = get_current_user_id();
678
-         }
679
-
680
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
681
-
682
-         if( !$users_answers || empty( $users_answers )
683
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
684
-
685
-             //Fallback for pre 1.7.4 data
686
-             $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
687
-
688
-             if( ! isset( $comment->comment_content ) ){
689
-                 return false;
690
-             }
691
-
692
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
693
-         }
694
-
695
-         return $users_answers[ $question_id ];
696
-
697
-     }// end get_user_question_answer
698
-
699
-     /**
700
-      * Saving the users quiz question grades
701
-      *
702
-      * This function save all the grades for all the question in a given quiz on the lesson
703
-      * comment meta. It makes use of transients to save the grades for easier access at a later stage
704
-      *
705
-      * @since 1.7.4
706
-      *
707
-      * @param array $quiz_grades{
708
-      *      @type int $question_id
709
-      *      @type int $question_grade
710
-      * }
711
-      * @param $lesson_id
712
-      * @param $user_id (Optional) will use the current user if not supplied
713
-      *
714
-      * @return bool
715
-      */
716
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
717
-
718
-         // get the user_id if none was passed in use the current logged in user
719
-         if( ! intval( $user_id ) > 0 ) {
720
-             $user_id = get_current_user_id();
721
-         }
722
-
723
-         // make sure the parameters are valid before continuing
724
-         if( empty( $lesson_id ) || empty( $user_id )
725
-             || 'lesson' != get_post_type( $lesson_id )
726
-             ||!get_userdata( $user_id )
727
-             || !is_array( $quiz_grades ) ){
728
-
729
-             return false;
730
-
731
-         }
732
-
733
-         $success = false;
734
-
735
-         // save that data for the user on the lesson comment meta
736
-         $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
737
-
738
-         // were the grades save successfully ?
739
-         if( intval( $comment_meta_id ) > 0 ) {
740
-
741
-             $success = true;
742
-             // save transient
743
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
744
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
745
-         }
746
-
747
-         return $success;
748
-
749
-     }// end set_user_grades
750
-
751
-     /**
752
-      * Retrieve the users quiz question grades
753
-      *
754
-      * This function gets all the grades for all the questions in the given lesson quiz for a specific user.
755
-      *
756
-      * @since 1.7.4
757
-      *
758
-      * @param $lesson_id
759
-      * @param $user_id (Optional) will use the current user if not supplied
760
-      *
761
-      * @return array $user_quiz_grades or false if none exists for this users
762
-      */
763
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
764
-
765
-         $user_grades = array();
766
-
767
-         // get the user_id if none was passed in use the current logged in user
768
-         if( ! intval( $user_id ) > 0 ) {
769
-             $user_id = get_current_user_id();
770
-         }
771
-
772
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
773
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
774
-             return false;
775
-         }
776
-
777
-         // save some time and get the transient cached data
778
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
779
-         $user_grades = get_transient( $transient_key );
780
-
781
-         // get the data if nothing was stored in the transient
782
-         if( empty( $user_grades  ) || false != $user_grades ){
783
-
784
-             $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
785
-
786
-             //set the transient with the new valid data for faster retrieval in future
787
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
788
-
789
-         } // end if transient check
790
-
791
-         // if there is no data for this user
792
-         if( ! is_array( $user_grades ) ){
793
-             return false;
794
-         }
795
-
796
-         return $user_grades;
797
-
798
-     }// end  get_user_grades
799
-
800
-     /**
801
-      * Get the user question grade
802
-      *
803
-      * This function gets the grade on a quiz for the given question parameter
804
-      * It does NOT do any grading. It simply retrieves the data that was stored during grading.
805
-      * this function allows for a fallback to users still using the question saved data from before 1.7.4
806
-      *
807
-      * @since 1.7.4
808
-      *
809
-      * @param int  $lesson_id
810
-      * @param int $question_id
811
-      * @param int  $user_id ( optional )
812
-      *
813
-      * @return bool $question_grade
814
-      */
815
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
816
-
817
-         // parameter validation
818
-         if( empty( $lesson_id ) || empty( $question_id )
819
-             || ! ( intval( $lesson_id  ) > 0 )
820
-             || ! ( intval( $question_id  ) > 0 )
821
-             || 'lesson' != get_post_type( $lesson_id )
822
-             || 'question' != get_post_type( $question_id )) {
823
-
824
-             return false;
825
-         }
826
-
827
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
828
-
829
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
830
-
831
-             //fallback to data pre 1.7.4
832
-             $args = array(
833
-                 'post_id' => $question_id,
834
-                 'user_id' => $user_id,
835
-                 'type'    => 'sensei_user_answer'
836
-             );
837
-
838
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
839
-             $fall_back_grade = false;
840
-             if( isset( $question_activity->comment_ID ) ){
841
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
842
-             }
843
-
844
-             return $fall_back_grade;
845
-
846
-         } // end if $all_user_grades...
847
-
848
-         return $all_user_grades[ $question_id ];
849
-
850
-     }// end get_user_question_grade
851
-
852
-     /**
853
-      * Save the user's answers feedback
854
-      *
855
-      * For this function you must supply all three parameters. If will return false one is left out.
856
-      * The data will be saved on the lesson ID supplied.
857
-      *
858
-      * @since 1.7.5
859
-      * @access public
860
-      *
861
-      * @param array $answers_feedback{
862
-      *  $type int $question_id
863
-      *  $type string $question_feedback
864
-      * }
865
-      * @param int $lesson_id
866
-      * @param int $user_id
867
-      *
868
-      * @return false or int $feedback_saved
869
-      */
870
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
871
-
872
-        // make sure the parameters are valid before continuing
873
-        if( empty( $lesson_id ) || empty( $user_id )
874
-            || 'lesson' != get_post_type( $lesson_id )
875
-            ||!get_userdata( $user_id )
876
-            || !is_array( $answers_feedback ) ){
877
-
878
-            return false;
879
-
880
-        }
881
-
882
-
883
-        // check if the lesson is started before saving, if not start the lesson for the user
884
-        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
885
-            Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
886
-        }
887
-
888
-        // encode the feedback
889
-        $encoded_answers_feedback =  array();
890
-        foreach( $answers_feedback as $question_id => $feedback ){
891
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
892
-        }
893
-
894
-        // save the user data
895
-        $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
896
-
897
-        //Were the the question feedback save correctly?
898
-        if( intval( $feedback_saved ) > 0){
899
-
900
-            // save transient to make retrieval faster in future
901
-             $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
902
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
903
-
904
-        }
905
-
906
-        return $feedback_saved;
907
-
908
-    } // end save_user_answers_feedback
909
-
910
-     /**
911
-      * Get the user's answers feedback.
912
-      *
913
-      * This function returns the feedback submitted by the teacher/admin
914
-      * during grading. Grading occurs manually or automatically.
915
-      *
916
-      * @since 1.7.5
917
-      * @access public
918
-      *
919
-      * @param int $lesson_id
920
-      * @param int $user_id
921
-      *
922
-      * @return false | array $answers_feedback{
923
-      *  $type int $question_id
924
-      *  $type string $question_feedback
925
-      * }
926
-      */
927
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
928
-
929
-         $answers_feedback = array();
930
-
931
-         // get the user_id if none was passed in use the current logged in user
932
-         if( ! intval( $user_id ) > 0 ) {
933
-             $user_id = get_current_user_id();
934
-         }
935
-
936
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
937
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
938
-             return false;
939
-         }
940
-
941
-         // first check the transient to save a few split seconds
942
-         $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
943
-         $encoded_feedback = get_transient( $transient_key );
944
-
945
-         // get the data if nothing was stored in the transient
946
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
947
-
948
-             $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
949
-
950
-             //set the transient with the new valid data for faster retrieval in future
951
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
952
-
953
-         } // end if transient check
954
-
955
-         // if there is no data for this user
956
-         if( ! is_array( $encoded_feedback ) ){
957
-             return false;
958
-         }
955
+		 // if there is no data for this user
956
+		 if( ! is_array( $encoded_feedback ) ){
957
+			 return false;
958
+		 }
959 959
 
960
-         foreach( $encoded_feedback as $question_id => $feedback ){
960
+		 foreach( $encoded_feedback as $question_id => $feedback ){
961 961
 
962
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
962
+			 $answers_feedback[ $question_id ] = base64_decode( $feedback );
963 963
 
964
-         }
964
+		 }
965 965
 
966
-         return $answers_feedback;
966
+		 return $answers_feedback;
967 967
 
968
-     } // end get_user_answers_feedback
968
+	 } // end get_user_answers_feedback
969 969
 
970
-     /**
971
-      * Get the user's answer feedback for a specific question.
972
-      *
973
-      * This function gives you a single answer note/feedback string
974
-      * for the user on the given question.
975
-      *
976
-      * @since 1.7.5
977
-      * @access public
978
-      *
979
-      * @param int $lesson_id
980
-      * @param int $question_id
981
-      * @param int $user_id
982
-      *
983
-      * @return string $feedback or bool if false
984
-      */
985
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
970
+	 /**
971
+	  * Get the user's answer feedback for a specific question.
972
+	  *
973
+	  * This function gives you a single answer note/feedback string
974
+	  * for the user on the given question.
975
+	  *
976
+	  * @since 1.7.5
977
+	  * @access public
978
+	  *
979
+	  * @param int $lesson_id
980
+	  * @param int $question_id
981
+	  * @param int $user_id
982
+	  *
983
+	  * @return string $feedback or bool if false
984
+	  */
985
+	 public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
986 986
 
987
-         $feedback = false;
987
+		 $feedback = false;
988 988
 
989
-         // parameter validation
990
-         if( empty( $lesson_id ) || empty( $question_id )
991
-             || ! ( intval( $lesson_id  ) > 0 )
992
-             || ! ( intval( $question_id  ) > 0 )
993
-             || 'lesson' != get_post_type( $lesson_id )
994
-             || 'question' != get_post_type( $question_id )) {
989
+		 // parameter validation
990
+		 if( empty( $lesson_id ) || empty( $question_id )
991
+			 || ! ( intval( $lesson_id  ) > 0 )
992
+			 || ! ( intval( $question_id  ) > 0 )
993
+			 || 'lesson' != get_post_type( $lesson_id )
994
+			 || 'question' != get_post_type( $question_id )) {
995 995
 
996
-             return false;
997
-         }
996
+			 return false;
997
+		 }
998 998
 
999
-         // get all the feedback for the user on the given lesson
1000
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
999
+		 // get all the feedback for the user on the given lesson
1000
+		 $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
1001 1001
 
1002
-         if( !$all_feedback || empty( $all_feedback )
1003
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1002
+		 if( !$all_feedback || empty( $all_feedback )
1003
+			 || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1004 1004
 
1005
-             //fallback to data pre 1.7.4
1005
+			 //fallback to data pre 1.7.4
1006 1006
 
1007
-             // setup the sensei data query
1008
-             $args = array(
1009
-                 'post_id' => $question_id,
1010
-                 'user_id' => $user_id,
1011
-                 'type'    => 'sensei_user_answer'
1012
-             );
1013
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1007
+			 // setup the sensei data query
1008
+			 $args = array(
1009
+				 'post_id' => $question_id,
1010
+				 'user_id' => $user_id,
1011
+				 'type'    => 'sensei_user_answer'
1012
+			 );
1013
+			 $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1014 1014
 
1015
-             // set the default to false and return that if no old data is available.
1016
-             if( isset( $question_activity->comment_ID ) ){
1017
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1018
-             }
1015
+			 // set the default to false and return that if no old data is available.
1016
+			 if( isset( $question_activity->comment_ID ) ){
1017
+				 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1018
+			 }
1019 1019
 
1020
-             // finally use the default question feedback
1021
-             if( empty( $feedback ) ){
1022
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1023
-             }
1020
+			 // finally use the default question feedback
1021
+			 if( empty( $feedback ) ){
1022
+				 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1023
+			 }
1024 1024
 
1025
-             return $feedback;
1025
+			 return $feedback;
1026 1026
 
1027
-         }
1027
+		 }
1028 1028
 
1029
-         return $all_feedback[ $question_id ];
1029
+		 return $all_feedback[ $question_id ];
1030 1030
 
1031
-     } // end get_user_question_feedback
1031
+	 } // end get_user_question_feedback
1032 1032
 
1033
-     /**
1034
-      * Check if a quiz has no questions, and redirect back to lesson.
1035
-      *
1036
-      * Though a quiz is created for each lesson, it should not be visible
1037
-      * unless it has questions.
1038
-      *
1039
-      * @since 1.9.0
1040
-      * @access public
1041
-      * @param none
1042
-      * @return void
1043
-      */
1033
+	 /**
1034
+	  * Check if a quiz has no questions, and redirect back to lesson.
1035
+	  *
1036
+	  * Though a quiz is created for each lesson, it should not be visible
1037
+	  * unless it has questions.
1038
+	  *
1039
+	  * @since 1.9.0
1040
+	  * @access public
1041
+	  * @param none
1042
+	  * @return void
1043
+	  */
1044 1044
 
1045
-     public function quiz_has_no_questions() {
1045
+	 public function quiz_has_no_questions() {
1046 1046
 
1047 1047
 
1048
-         if( ! is_singular( 'quiz' ) )  {
1049
-             return;
1050
-         }
1048
+		 if( ! is_singular( 'quiz' ) )  {
1049
+			 return;
1050
+		 }
1051 1051
 
1052
-         global $post;
1052
+		 global $post;
1053 1053
 
1054
-         $lesson_id = $this->get_lesson_id($post->ID);
1054
+		 $lesson_id = $this->get_lesson_id($post->ID);
1055 1055
 
1056
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1056
+		 $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1057 1057
 
1058
-         $lesson = get_post($lesson_id);
1058
+		 $lesson = get_post($lesson_id);
1059 1059
 
1060
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1060
+		 if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1061 1061
 
1062
-             wp_redirect(get_permalink($lesson->ID), 301);
1063
-             exit;
1062
+			 wp_redirect(get_permalink($lesson->ID), 301);
1063
+			 exit;
1064 1064
 
1065
-         }
1065
+		 }
1066 1066
 
1067
-     } // end quiz_has_no_questions
1067
+	 } // end quiz_has_no_questions
1068 1068
 
1069 1069
 /**
1070
-  * Deprecate the sensei_single_main_content on the single-quiz template.
1071
-  *
1072
-  * @deprecated since 1.9.0
1073
-  */
1070
+ * Deprecate the sensei_single_main_content on the single-quiz template.
1071
+ *
1072
+ * @deprecated since 1.9.0
1073
+ */
1074 1074
  public static function deprecate_quiz_sensei_single_main_content_hook(){
1075 1075
 
1076
-     sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1076
+	 sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1077 1077
 
1078 1078
  }
1079
-    /*
1079
+	/*
1080 1080
      * Deprecate the sensei_quiz_single_title on the single-quiz template.
1081 1081
      *
1082 1082
      * @deprecated since 1.9.0
1083 1083
      */
1084
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1084
+	 public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1085 1085
 
1086
-         sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1086
+		 sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1087 1087
 
1088
-     }
1088
+	 }
1089 1089
 
1090
-     /**
1091
-      * Filter the single title and add the Quiz to it.
1092
-      *
1093
-      * @param string $title
1094
-      * @param int $id title post id
1095
-      * @return string $quiz_title
1096
-      */
1097
-     public static function single_quiz_title( $title, $post_id ){
1090
+	 /**
1091
+	  * Filter the single title and add the Quiz to it.
1092
+	  *
1093
+	  * @param string $title
1094
+	  * @param int $id title post id
1095
+	  * @return string $quiz_title
1096
+	  */
1097
+	 public static function single_quiz_title( $title, $post_id ){
1098 1098
 
1099
-         if( 'quiz' == get_post_type( $post_id ) ){
1099
+		 if( 'quiz' == get_post_type( $post_id ) ){
1100 1100
 
1101
-             $title_with_no_quizzes = $title;
1101
+			 $title_with_no_quizzes = $title;
1102 1102
 
1103
-             // if the title has quiz, remove it: legacy titles have the word quiz stored.
1104
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1103
+			 // if the title has quiz, remove it: legacy titles have the word quiz stored.
1104
+			 if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1105 1105
 
1106
-                 // remove all possible appearances of quiz
1107
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1108
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1109
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1106
+				 // remove all possible appearances of quiz
1107
+				 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1108
+				 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1109
+				 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1110 1110
 
1111
-             }
1111
+			 }
1112 1112
 
1113
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1114
-         }
1113
+			 $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1114
+		 }
1115 1115
 
1116
-         /**
1117
-          * hook document in class-woothemes-sensei-message.php
1118
-          */
1119
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1116
+		 /**
1117
+		  * hook document in class-woothemes-sensei-message.php
1118
+		  */
1119
+		 return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1120 1120
 
1121
-     }
1121
+	 }
1122 1122
 
1123
-     /**
1124
-      * Initialize the quiz question loop on the single quiz template
1125
-      *
1126
-      * The function will create a global quiz loop varialbe.
1127
-      *
1128
-      * @since 1.9.0
1129
-      *
1130
-      */
1131
-     public static function start_quiz_questions_loop(){
1123
+	 /**
1124
+	  * Initialize the quiz question loop on the single quiz template
1125
+	  *
1126
+	  * The function will create a global quiz loop varialbe.
1127
+	  *
1128
+	  * @since 1.9.0
1129
+	  *
1130
+	  */
1131
+	 public static function start_quiz_questions_loop(){
1132 1132
 
1133
-         global $sensei_question_loop;
1133
+		 global $sensei_question_loop;
1134 1134
 
1135
-         //intialize the questions loop object
1136
-         $sensei_question_loop['current'] = -1;
1137
-         $sensei_question_loop['total']   =  0;
1138
-         $sensei_question_loop['questions'] = array();
1135
+		 //intialize the questions loop object
1136
+		 $sensei_question_loop['current'] = -1;
1137
+		 $sensei_question_loop['total']   =  0;
1138
+		 $sensei_question_loop['questions'] = array();
1139 1139
 
1140 1140
 
1141
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1141
+		 $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1142 1142
 
1143
-         if( count( $questions  ) > 0  ){
1143
+		 if( count( $questions  ) > 0  ){
1144 1144
 
1145
-             $sensei_question_loop['total']   =  count( $questions );
1146
-             $sensei_question_loop['questions'] = $questions;
1147
-             $sensei_question_loop['quiz_id'] = get_the_ID();
1145
+			 $sensei_question_loop['total']   =  count( $questions );
1146
+			 $sensei_question_loop['questions'] = $questions;
1147
+			 $sensei_question_loop['quiz_id'] = get_the_ID();
1148 1148
 
1149
-         }
1149
+		 }
1150 1150
 
1151
-     }// static function
1151
+	 }// static function
1152 1152
 
1153
-     /**
1154
-      * Initialize the quiz question loop on the single quiz template
1155
-      *
1156
-      * The function will create a global quiz loop varialbe.
1157
-      *
1158
-      * @since 1.9.0
1159
-      *
1160
-      */
1161
-     public static function stop_quiz_questions_loop(){
1153
+	 /**
1154
+	  * Initialize the quiz question loop on the single quiz template
1155
+	  *
1156
+	  * The function will create a global quiz loop varialbe.
1157
+	  *
1158
+	  * @since 1.9.0
1159
+	  *
1160
+	  */
1161
+	 public static function stop_quiz_questions_loop(){
1162 1162
 
1163
-         $sensei_question_loop['total']   =  0;
1164
-         $sensei_question_loop['questions'] = array();
1165
-         $sensei_question_loop['quiz_id'] = '';
1163
+		 $sensei_question_loop['total']   =  0;
1164
+		 $sensei_question_loop['questions'] = array();
1165
+		 $sensei_question_loop['quiz_id'] = '';
1166 1166
 
1167
-     }
1167
+	 }
1168 1168
 
1169
-     /**
1170
-      * Output the title for the single quiz page
1171
-      *
1172
-      * @since 1.9.0
1173
-      */
1174
-     public static function the_title(){
1175
-         ?>
1169
+	 /**
1170
+	  * Output the title for the single quiz page
1171
+	  *
1172
+	  * @since 1.9.0
1173
+	  */
1174
+	 public static function the_title(){
1175
+		 ?>
1176 1176
          <header>
1177 1177
 
1178 1178
              <h1>
1179 1179
 
1180 1180
                  <?php
1181
-                 /**
1182
-                  * Filter documented in class-sensei-messages.php the_title
1183
-                  */
1184
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1185
-                 ?>
1181
+				 /**
1182
+				  * Filter documented in class-sensei-messages.php the_title
1183
+				  */
1184
+				 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1185
+				 ?>
1186 1186
 
1187 1187
              </h1>
1188 1188
 
1189 1189
          </header>
1190 1190
 
1191 1191
          <?php
1192
-     }//the_title
1192
+	 }//the_title
1193 1193
 
1194
-     /**
1195
-      * Output the sensei quiz status message.
1196
-      *
1197
-      * @param $quiz_id
1198
-      */
1199
-    public static function  the_user_status_message( $quiz_id ){
1194
+	 /**
1195
+	  * Output the sensei quiz status message.
1196
+	  *
1197
+	  * @param $quiz_id
1198
+	  */
1199
+	public static function  the_user_status_message( $quiz_id ){
1200 1200
 
1201
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1202
-        $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1203
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1201
+		$lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1202
+		$status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1203
+		echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1204 1204
 
1205
-    }
1205
+	}
1206 1206
 
1207
-     /**
1208
-      * This functions runs the old sensei_quiz_action_buttons action
1209
-      * for backwards compatiblity sake.
1210
-      *
1211
-      * @since 1.9.0
1212
-      * @deprecated
1213
-      */
1214
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1207
+	 /**
1208
+	  * This functions runs the old sensei_quiz_action_buttons action
1209
+	  * for backwards compatiblity sake.
1210
+	  *
1211
+	  * @since 1.9.0
1212
+	  * @deprecated
1213
+	  */
1214
+	 public static function deprecate_sensei_quiz_action_buttons_hook(){
1215 1215
 
1216
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1216
+		 sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1217 1217
 
1218
-     }
1218
+	 }
1219 1219
 
1220
-     /**
1221
-      * The quiz action buttons needed to ouput quiz
1222
-      * action such as reset complete and save.
1223
-      *
1224
-      * @since 1.3.0
1225
-      */
1226
-     public static function action_buttons() {
1220
+	 /**
1221
+	  * The quiz action buttons needed to ouput quiz
1222
+	  * action such as reset complete and save.
1223
+	  *
1224
+	  * @since 1.3.0
1225
+	  */
1226
+	 public static function action_buttons() {
1227 1227
 
1228
-         global $post, $current_user;
1228
+		 global $post, $current_user;
1229 1229
 
1230
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1231
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1232
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1233
-         $show_actions = true;
1234
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1230
+		 $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1231
+		 $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1232
+		 $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1233
+		 $show_actions = true;
1234
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1235 1235
 
1236
-         //setup quiz grade
1237
-         $user_quiz_grade = '';
1238
-         if( ! empty( $user_lesson_status  ) ){
1239
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1240
-         }
1236
+		 //setup quiz grade
1237
+		 $user_quiz_grade = '';
1238
+		 if( ! empty( $user_lesson_status  ) ){
1239
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1240
+		 }
1241 1241
 
1242 1242
 
1243
-         if( intval( $lesson_prerequisite ) > 0 ) {
1243
+		 if( intval( $lesson_prerequisite ) > 0 ) {
1244 1244
 
1245
-             // If the user hasn't completed the prereq then hide the current actions
1246
-             $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1245
+			 // If the user hasn't completed the prereq then hide the current actions
1246
+			 $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1247 1247
 
1248
-         }
1249
-         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1248
+		 }
1249
+		 if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1250 1250
 
1251
-             // Get Reset Settings
1252
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1251
+			 // Get Reset Settings
1252
+			 $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1253 1253
 
1254 1254
              <!-- Action Nonce's -->
1255 1255
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
@@ -1276,55 +1276,55 @@  discard block
 block discarded – undo
1276 1276
 
1277 1277
          <?php }
1278 1278
 
1279
-     } // End sensei_quiz_action_buttons()
1280
-
1281
-     /**
1282
-      * Fetch the quiz grade
1283
-      *
1284
-      * @since 1.9.0
1285
-      *
1286
-      * @param int $lesson_id
1287
-      * @param int $user_id
1288
-      *
1289
-      * @return double $user_quiz_grade
1290
-      */
1291
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1292
-
1293
-         // get the quiz grade
1294
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1295
-         $user_quiz_grade = 0;
1296
-         if( isset( $user_lesson_status->comment_ID ) ) {
1297
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1298
-         }
1299
-
1300
-         return (double) $user_quiz_grade;
1301
-
1302
-     }
1303
-
1304
-     /**
1305
-      * Check the quiz reset property for a given lesson's quiz.
1306
-      *
1307
-      * The data is stored on the quiz but going forward the quiz post
1308
-      * type will be retired, hence the lesson_id is a require parameter.
1309
-      *
1310
-      * @since 1.9.0
1311
-      *
1312
-      * @param int $lesson_id
1313
-      * @return bool
1314
-      */
1315
-     public static function is_reset_allowed( $lesson_id ){
1316
-
1317
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1318
-
1319
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1320
-         //backwards compatibility
1321
-         if( 'on' == $reset_allowed ) {
1322
-             $reset_allowed = 1;
1323
-         }
1324
-
1325
-         return (bool) $reset_allowed;
1326
-
1327
-     }
1279
+	 } // End sensei_quiz_action_buttons()
1280
+
1281
+	 /**
1282
+	  * Fetch the quiz grade
1283
+	  *
1284
+	  * @since 1.9.0
1285
+	  *
1286
+	  * @param int $lesson_id
1287
+	  * @param int $user_id
1288
+	  *
1289
+	  * @return double $user_quiz_grade
1290
+	  */
1291
+	 public static function get_user_quiz_grade( $lesson_id, $user_id ){
1292
+
1293
+		 // get the quiz grade
1294
+		 $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1295
+		 $user_quiz_grade = 0;
1296
+		 if( isset( $user_lesson_status->comment_ID ) ) {
1297
+			 $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1298
+		 }
1299
+
1300
+		 return (double) $user_quiz_grade;
1301
+
1302
+	 }
1303
+
1304
+	 /**
1305
+	  * Check the quiz reset property for a given lesson's quiz.
1306
+	  *
1307
+	  * The data is stored on the quiz but going forward the quiz post
1308
+	  * type will be retired, hence the lesson_id is a require parameter.
1309
+	  *
1310
+	  * @since 1.9.0
1311
+	  *
1312
+	  * @param int $lesson_id
1313
+	  * @return bool
1314
+	  */
1315
+	 public static function is_reset_allowed( $lesson_id ){
1316
+
1317
+		 $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1318
+
1319
+		 $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1320
+		 //backwards compatibility
1321
+		 if( 'on' == $reset_allowed ) {
1322
+			 $reset_allowed = 1;
1323
+		 }
1324
+
1325
+		 return (bool) $reset_allowed;
1326
+
1327
+	 }
1328 1328
 
1329 1329
  } // End Class WooThemes_Sensei_Quiz
1330 1330
 
Please login to merge, or discard this patch.
includes/class-sensei-settings-api.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function register_hook_listener() {
61 61
 
62
-        add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
62
+		add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
63 63
 		add_action( 'admin_init', array( $this, 'settings_fields' ) );
64 64
 		add_action( 'init', array( $this, 'general_init' ) );
65 65
 
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 		echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n";
420 420
 		if ( $has_description ) {
421 421
 			echo wp_kses( $args['data']['description'], array( 'a' => array(
422
-																	        'href' => array(),
423
-																	        'title' => array()
424
-																	    )
422
+																			'href' => array(),
423
+																			'title' => array()
424
+																		)
425 425
 															)
426 426
 						) . '</label>' . "\n";
427 427
 		}
Please login to merge, or discard this patch.
Spacing   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Settings API Class
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @since  1.0.0
35 35
 	 * @return void
36 36
 	 */
37
-	public function __construct () {
37
+	public function __construct() {
38 38
 		$this->token = 'woothemes-sensei-settings';
39 39
 		$this->page_slug = 'woothemes-sensei-settings-api';
40 40
 
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
 	 */
60 60
 	public function register_hook_listener() {
61 61
 
62
-        add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 60 );
63
-		add_action( 'admin_init', array( $this, 'settings_fields' ) );
64
-		add_action( 'init', array( $this, 'general_init' ) );
62
+        add_action('admin_menu', array($this, 'register_settings_screen'), 60);
63
+		add_action('admin_init', array($this, 'settings_fields'));
64
+		add_action('init', array($this, 'general_init'));
65 65
 
66 66
 	} // End setup_settings()
67 67
 
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		$this->init_sections();
76 76
 		$this->init_fields();
77 77
 		$this->get_settings();
78
-		if ( $this->has_tabs == true ) {
78
+		if ($this->has_tabs == true) {
79 79
 			$this->create_tabs();
80 80
 		} // End If Statement
81 81
 	} // End general_init()
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 	 * @since  1.0.0
87 87
 	 * @return void
88 88
 	 */
89
-	public function init_sections () {
89
+	public function init_sections() {
90 90
 		// Override this function in your class and assign the array of sections to $this->sections.
91
-		_e( 'Override init_sections() in your class.', 'woothemes-sensei' );
91
+		_e('Override init_sections() in your class.', 'woothemes-sensei');
92 92
 	} // End init_sections()
93 93
 
94 94
 	/**
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 	 * @since  1.0.0
98 98
 	 * @return void
99 99
 	 */
100
-	public function init_fields () {
100
+	public function init_fields() {
101 101
 		// Override this function in your class and assign the array of sections to $this->fields.
102
-		_e( 'Override init_fields() in your class.', 'woothemes-sensei' );
102
+		_e('Override init_fields() in your class.', 'woothemes-sensei');
103 103
 	} // End init_fields()
104 104
 
105 105
 	/**
@@ -108,33 +108,33 @@  discard block
 block discarded – undo
108 108
 	 * @since  1.1.0
109 109
 	 * @return void
110 110
 	 */
111
-	public function settings_tabs () {
112
-		if ( ! $this->has_tabs ) { return; }
111
+	public function settings_tabs() {
112
+		if ( ! $this->has_tabs) { return; }
113 113
 
114
-		if ( count( $this->tabs ) > 0 ) {
114
+		if (count($this->tabs) > 0) {
115 115
 			$html = '';
116 116
 
117
-			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">' . "\n";
117
+			$html .= '<ul id="settings-sections" class="subsubsub hide-if-no-js">'."\n";
118 118
 
119 119
 			$sections = array(
120
-						'all' => array( 'href' => '#all', 'name' => __( 'All', 'woothemes-sensei' ), 'class' => 'current all tab' )
120
+						'all' => array('href' => '#all', 'name' => __('All', 'woothemes-sensei'), 'class' => 'current all tab')
121 121
 					);
122 122
 
123
-			foreach ( $this->tabs as $k => $v ) {
124
-				$sections[$k] = array( 'href' => '#' . esc_attr( $k ), 'name' => esc_attr( $v['name'] ), 'class' => 'tab' );
123
+			foreach ($this->tabs as $k => $v) {
124
+				$sections[$k] = array('href' => '#'.esc_attr($k), 'name' => esc_attr($v['name']), 'class' => 'tab');
125 125
 			}
126 126
 
127 127
 			$count = 1;
128
-			foreach ( $sections as $k => $v ) {
128
+			foreach ($sections as $k => $v) {
129 129
 				$count++;
130
-				$html .= '<li><a href="' . $v['href'] . '"';
131
-				if ( isset( $v['class'] ) && ( $v['class'] != '' ) ) { $html .= ' class="' . esc_attr( $v['class'] ) . '"'; }
132
-				$html .= '>' . esc_attr( $v['name'] ) . '</a>';
133
-				if ( $count <= count( $sections ) ) { $html .= ' | '; }
134
-				$html .= '</li>' . "\n";
130
+				$html .= '<li><a href="'.$v['href'].'"';
131
+				if (isset($v['class']) && ($v['class'] != '')) { $html .= ' class="'.esc_attr($v['class']).'"'; }
132
+				$html .= '>'.esc_attr($v['name']).'</a>';
133
+				if ($count <= count($sections)) { $html .= ' | '; }
134
+				$html .= '</li>'."\n";
135 135
 			}
136 136
 
137
-			$html .= '</ul><div class="clear"></div>' . "\n";
137
+			$html .= '</ul><div class="clear"></div>'."\n";
138 138
 
139 139
 			echo $html;
140 140
 		}
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 	 * @since  1.1.0
147 147
 	 * @return void
148 148
 	 */
149
-	private function create_tabs () {
150
-		if ( count( $this->sections ) > 0 ) {
149
+	private function create_tabs() {
150
+		if (count($this->sections) > 0) {
151 151
 			$tabs = array();
152
-			foreach ( $this->sections as $k => $v ) {
152
+			foreach ($this->sections as $k => $v) {
153 153
 				$tabs[$k] = $v;
154 154
 			}
155 155
 
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 	 * @since  1.0.0
164 164
 	 * @return void
165 165
 	 */
166
-	public function create_sections () {
167
-		if ( count( $this->sections ) > 0 ) {
168
-			foreach ( $this->sections as $k => $v ) {
169
-				add_settings_section( $k, $v['name'], array( $this, 'section_description' ), $this->token );
166
+	public function create_sections() {
167
+		if (count($this->sections) > 0) {
168
+			foreach ($this->sections as $k => $v) {
169
+				add_settings_section($k, $v['name'], array($this, 'section_description'), $this->token);
170 170
 			}
171 171
 		}
172 172
 	} // End create_sections()
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
 	 * @since  1.0.0
178 178
 	 * @return void
179 179
 	 */
180
-	public function create_fields () {
181
-		if ( count( $this->sections ) > 0 ) {
180
+	public function create_fields() {
181
+		if (count($this->sections) > 0) {
182 182
 			// $this->parse_fields( $this->fields );
183 183
 
184
-			foreach ( $this->fields as $k => $v ) {
185
-				$method = $this->determine_method( $v, 'form' );
184
+			foreach ($this->fields as $k => $v) {
185
+				$method = $this->determine_method($v, 'form');
186 186
 				$name = $v['name'];
187
-				if ( $v['type'] == 'info' ) { $name = ''; }
188
-				add_settings_field( $k, $name, $method, $this->token, $v['section'], array( 'key' => $k, 'data' => $v ) );
187
+				if ($v['type'] == 'info') { $name = ''; }
188
+				add_settings_field($k, $name, $method, $this->token, $v['section'], array('key' => $k, 'data' => $v));
189 189
 
190 190
 				// Let the API know that we have a colourpicker field.
191
-				if ( $v['type'] == 'range' && $this->has_range == false ) { $this->has_range = true; }
191
+				if ($v['type'] == 'range' && $this->has_range == false) { $this->has_range = true; }
192 192
 			}
193 193
 		}
194 194
 	} // End create_fields()
@@ -200,43 +200,43 @@  discard block
 block discarded – undo
200 200
 	 * @param  array $data
201 201
 	 * @return callable,  array or string
202 202
 	 */
203
-	protected function determine_method ( $data, $type = 'form' ) {
203
+	protected function determine_method($data, $type = 'form') {
204 204
 		$method = '';
205 205
 
206
-		if ( ! in_array( $type, array( 'form', 'validate', 'check' ) ) ) { return; }
206
+		if ( ! in_array($type, array('form', 'validate', 'check'))) { return; }
207 207
 
208 208
 		// Check for custom functions.
209
-		if ( isset( $data[$type] ) ) {
210
-			if ( function_exists( $data[$type] ) ) {
209
+		if (isset($data[$type])) {
210
+			if (function_exists($data[$type])) {
211 211
 				$method = $data[$type];
212 212
 			}
213 213
 
214
-			if ( $method == '' && method_exists( $this, $data[$type] ) ) {
215
-				if ( $type == 'form' ) {
216
-					$method = array( $this, $data[$type] );
214
+			if ($method == '' && method_exists($this, $data[$type])) {
215
+				if ($type == 'form') {
216
+					$method = array($this, $data[$type]);
217 217
 				} else {
218 218
 					$method = $data[$type];
219 219
 				}
220 220
 			}
221 221
 		}
222 222
 
223
-		if ( $method == '' && method_exists ( $this, $type . '_field_' . $data['type'] ) ) {
224
-			if ( $type == 'form' ) {
225
-				$method = array( $this, $type . '_field_' . $data['type'] );
223
+		if ($method == '' && method_exists($this, $type.'_field_'.$data['type'])) {
224
+			if ($type == 'form') {
225
+				$method = array($this, $type.'_field_'.$data['type']);
226 226
 			} else {
227
-				$method = $type . '_field_' . $data['type'];
227
+				$method = $type.'_field_'.$data['type'];
228 228
 			}
229 229
 		}
230 230
 
231
-		if ( $method == '' && function_exists ( $this->token . '_' . $type . '_field_' . $data['type'] ) ) {
232
-			$method = $this->token . '_' . $type . '_field_' . $data['type'];
231
+		if ($method == '' && function_exists($this->token.'_'.$type.'_field_'.$data['type'])) {
232
+			$method = $this->token.'_'.$type.'_field_'.$data['type'];
233 233
 		}
234 234
 
235
-		if ( $method == '' ) {
236
-			if ( $type == 'form' ) {
237
-				$method = array( $this, $type . '_field_text' );
235
+		if ($method == '') {
236
+			if ($type == 'form') {
237
+				$method = array($this, $type.'_field_text');
238 238
 			} else {
239
-				$method = $type . '_field_text';
239
+				$method = $type.'_field_text';
240 240
 			}
241 241
 		}
242 242
 
@@ -250,10 +250,10 @@  discard block
 block discarded – undo
250 250
 	 * @param  array $fields
251 251
 	 * @return void
252 252
 	 */
253
-	public function parse_fields ( $fields ) {
254
-		foreach ( $fields as $k => $v ) {
255
-			if ( isset( $v['section'] ) && ( $v['section'] != '' ) && ( isset( $this->sections[$v['section']] ) ) ) {
256
-				if ( ! isset( $this->sections[$v['section']]['fields'] ) ) {
253
+	public function parse_fields($fields) {
254
+		foreach ($fields as $k => $v) {
255
+			if (isset($v['section']) && ($v['section'] != '') && (isset($this->sections[$v['section']]))) {
256
+				if ( ! isset($this->sections[$v['section']]['fields'])) {
257 257
 					$this->sections[$v['section']]['fields'] = array();
258 258
 				}
259 259
 
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
 	 * @since 1.0.0
271 271
 	 * @return void
272 272
 	 */
273
-	public function register_settings_screen () {
273
+	public function register_settings_screen() {
274 274
 
275 275
 
276
-		if ( current_user_can( 'manage_sensei' ) ) {
277
-			$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
276
+		if (current_user_can('manage_sensei')) {
277
+			$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
278 278
 
279 279
 			$this->hook = $hook;
280 280
 		}
281 281
 
282
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
283
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
284
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
285
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
282
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
283
+			add_action('admin_notices', array($this, 'settings_errors'));
284
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
285
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
286 286
 		}
287 287
 	} // End register_settings_screen()
288 288
 
@@ -292,21 +292,21 @@  discard block
 block discarded – undo
292 292
 	 * @since  1.0.0
293 293
 	 * @return void
294 294
 	 */
295
-	public function settings_screen () {
295
+	public function settings_screen() {
296 296
 
297 297
 ?>
298
-<div id="woothemes-sensei" class="wrap <?php echo esc_attr( $this->token ); ?>">
299
-	<?php screen_icon( 'woothemes-sensei' ); ?>
300
-	<h2><?php echo esc_html( $this->name ); ?><?php if ( '' != $this->settings_version ) { echo ' <span class="version">' . $this->settings_version . '</span>'; } ?></h2>
301
-	<p class="powered-by-woo"><?php _e( 'Powered by', 'woothemes-sensei' ); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
302
-	<?php do_action( 'settings_before_form' ); ?>
298
+<div id="woothemes-sensei" class="wrap <?php echo esc_attr($this->token); ?>">
299
+	<?php screen_icon('woothemes-sensei'); ?>
300
+	<h2><?php echo esc_html($this->name); ?><?php if ('' != $this->settings_version) { echo ' <span class="version">'.$this->settings_version.'</span>'; } ?></h2>
301
+	<p class="powered-by-woo"><?php _e('Powered by', 'woothemes-sensei'); ?><a href="http://www.woothemes.com/" title="WooThemes"><img src="<?php echo Sensei()->plugin_url; ?>assets/images/woothemes.png" alt="WooThemes" /></a></p>
302
+	<?php do_action('settings_before_form'); ?>
303 303
 	<form action="options.php" method="post">
304 304
 		<?php $this->settings_tabs(); ?>
305
-		<?php settings_fields( $this->token ); ?>
306
-		<?php do_settings_sections( $this->token ); ?>
305
+		<?php settings_fields($this->token); ?>
306
+		<?php do_settings_sections($this->token); ?>
307 307
 		<?php submit_button(); ?>
308 308
 	</form>
309
-	<?php do_action( 'settings_after_form' ); ?>
309
+	<?php do_action('settings_after_form'); ?>
310 310
 </div><!--/#woothemes-sensei-->
311 311
 <?php
312 312
 	} // End settings_screen()
@@ -317,16 +317,16 @@  discard block
 block discarded – undo
317 317
 	 * @since  1.0.0
318 318
 	 * @return array
319 319
 	 */
320
-	public function get_settings () {
321
-		if ( ! is_array( $this->settings ) ) {
322
-			$this->settings = get_option( $this->token, array() );
320
+	public function get_settings() {
321
+		if ( ! is_array($this->settings)) {
322
+			$this->settings = get_option($this->token, array());
323 323
 		}
324 324
 
325
-		foreach ( $this->fields as $k => $v ) {
326
-			if ( ! isset( $this->settings[$k] ) && isset( $v['default'] ) ) {
325
+		foreach ($this->fields as $k => $v) {
326
+			if ( ! isset($this->settings[$k]) && isset($v['default'])) {
327 327
 				$this->settings[$k] = $v['default'];
328 328
 			}
329
-			if ( $v['type'] == 'checkbox' && $this->settings[$k] != true ) {
329
+			if ($v['type'] == 'checkbox' && $this->settings[$k] != true) {
330 330
 				$this->settings[$k] = 0;
331 331
 			}
332 332
 		}
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 * @since  1.0.0
341 341
 	 * @return void
342 342
 	 */
343
-	public function settings_fields () {
344
-		register_setting( $this->token, $this->token, array( $this, 'validate_fields' ) );
343
+	public function settings_fields() {
344
+		register_setting($this->token, $this->token, array($this, 'validate_fields'));
345 345
 		$this->create_sections();
346 346
 		$this->create_fields();
347 347
 	} // End settings_fields()
@@ -352,8 +352,8 @@  discard block
 block discarded – undo
352 352
 	 * @since  1.0.0
353 353
 	 * @return void
354 354
 	 */
355
-	public function settings_errors () {
356
-		echo settings_errors( $this->token . '-errors' );
355
+	public function settings_errors() {
356
+		echo settings_errors($this->token.'-errors');
357 357
 	} // End settings_errors()
358 358
 
359 359
 	/**
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	 * @since  1.0.0
363 363
 	 * @return void
364 364
 	 */
365
-	public function section_description ( $section ) {
366
-		if ( isset( $this->sections[$section['id']]['description'] ) ) {
367
-			echo wpautop( $this->sections[$section['id']]['description'] );
365
+	public function section_description($section) {
366
+		if (isset($this->sections[$section['id']]['description'])) {
367
+			echo wpautop($this->sections[$section['id']]['description']);
368 368
 		}
369 369
 	} // End section_description_main()
370 370
 
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
 	 * @param  array $args
376 376
 	 * @return void
377 377
 	 */
378
-	public function form_field_text ( $args ) {
378
+	public function form_field_text($args) {
379 379
 		$options = $this->get_settings();
380 380
 
381
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
382
-		if ( isset( $args['data']['description'] ) ) {
383
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
381
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" value="'.esc_attr($options[$args['key']]).'" />'."\n";
382
+		if (isset($args['data']['description'])) {
383
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
384 384
 		}
385 385
 	} // End form_field_text()
386 386
 
@@ -391,13 +391,13 @@  discard block
 block discarded – undo
391 391
 	 * @param  array $args
392 392
 	 * @return void
393 393
 	 */
394
-	public function form_field_color ( $args ) {
394
+	public function form_field_color($args) {
395 395
 		$options = $this->get_settings();
396 396
 
397
-		echo '<input id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" size="40" type="text" class="color" value="' . esc_attr( $options[$args['key']] ) . '" />' . "\n";
397
+		echo '<input id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" size="40" type="text" class="color" value="'.esc_attr($options[$args['key']]).'" />'."\n";
398 398
 		echo '<div style="position:absolute;background:#FFF;z-index:99;border-radius:100%;" class="colorpicker"></div>';
399
-		if ( isset( $args['data']['description'] ) ) {
400
-			echo '<span class="description">' . $args['data']['description'] . '</span>' . "\n";
399
+		if (isset($args['data']['description'])) {
400
+			echo '<span class="description">'.$args['data']['description'].'</span>'."\n";
401 401
 		}
402 402
 	} // End form_field_text()
403 403
 
@@ -408,22 +408,22 @@  discard block
 block discarded – undo
408 408
 	 * @param  array $args
409 409
 	 * @return void
410 410
 	 */
411
-	public function form_field_checkbox ( $args ) {
411
+	public function form_field_checkbox($args) {
412 412
 		$options = $this->get_settings();
413 413
 
414 414
 		$has_description = false;
415
-		if ( isset( $args['data']['description'] ) ) {
415
+		if (isset($args['data']['description'])) {
416 416
 			$has_description = true;
417
-			echo '<label for="' . esc_attr( $args['key'] ) . '">' . "\n";
417
+			echo '<label for="'.esc_attr($args['key']).'">'."\n";
418 418
 		}
419
-		echo '<input id="' . $args['key'] . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" type="checkbox" value="1"' . checked( esc_attr( $options[$args['key']] ), '1', false ) . ' />' . "\n";
420
-		if ( $has_description ) {
421
-			echo wp_kses( $args['data']['description'], array( 'a' => array(
419
+		echo '<input id="'.$args['key'].'" name="'.$this->token.'['.esc_attr($args['key']).']" type="checkbox" value="1"'.checked(esc_attr($options[$args['key']]), '1', false).' />'."\n";
420
+		if ($has_description) {
421
+			echo wp_kses($args['data']['description'], array('a' => array(
422 422
 																	        'href' => array(),
423 423
 																	        'title' => array()
424 424
 																	    )
425 425
 															)
426
-						) . '</label>' . "\n";
426
+						).'</label>'."\n";
427 427
 		}
428 428
 	} // End form_field_checkbox()
429 429
 
@@ -434,12 +434,12 @@  discard block
 block discarded – undo
434 434
 	 * @param  array $args
435 435
 	 * @return void
436 436
 	 */
437
-	public function form_field_textarea ( $args ) {
437
+	public function form_field_textarea($args) {
438 438
 		$options = $this->get_settings();
439 439
 
440
-		echo '<textarea id="' . esc_attr( $args['key'] ) . '" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" cols="42" rows="5">' . esc_html( $options[$args['key']] ) . '</textarea>' . "\n";
441
-		if ( isset( $args['data']['description'] ) ) {
442
-			echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
440
+		echo '<textarea id="'.esc_attr($args['key']).'" name="'.$this->token.'['.esc_attr($args['key']).']" cols="42" rows="5">'.esc_html($options[$args['key']]).'</textarea>'."\n";
441
+		if (isset($args['data']['description'])) {
442
+			echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
443 443
 		}
444 444
 	} // End form_field_textarea()
445 445
 
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
 	 * @param  array $args
451 451
 	 * @return void
452 452
 	 */
453
-	public function form_field_select ( $args ) {
453
+	public function form_field_select($args) {
454 454
 		$options = $this->get_settings();
455 455
 
456
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
456
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
457 457
 			$html = '';
458
-			$html .= '<select class="" id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']">' . "\n";
459
-				foreach ( $args['data']['options'] as $k => $v ) {
460
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
458
+			$html .= '<select class="" id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']">'."\n";
459
+				foreach ($args['data']['options'] as $k => $v) {
460
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
461 461
 				}
462
-			$html .= '</select>' . "\n";
462
+			$html .= '</select>'."\n";
463 463
 			echo $html;
464 464
 
465
-			if ( isset( $args['data']['description'] ) ) {
466
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
465
+			if (isset($args['data']['description'])) {
466
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
467 467
 			}
468 468
 		}
469 469
 	} // End form_field_select()
@@ -475,18 +475,18 @@  discard block
 block discarded – undo
475 475
 	 * @param  array $args
476 476
 	 * @return void
477 477
 	 */
478
-	public function form_field_radio ( $args ) {
478
+	public function form_field_radio($args) {
479 479
 		$options = $this->get_settings();
480 480
 
481
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
481
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
482 482
 			$html = '';
483
-			foreach ( $args['data']['options'] as $k => $v ) {
484
-				$html .= '<input type="radio" name="' . $this->token . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
483
+			foreach ($args['data']['options'] as $k => $v) {
484
+				$html .= '<input type="radio" name="'.$this->token.'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
485 485
 			}
486 486
 			echo $html;
487 487
 
488
-			if ( isset( $args['data']['description'] ) ) {
489
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
488
+			if (isset($args['data']['description'])) {
489
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
490 490
 			}
491 491
 		}
492 492
 	} // End form_field_radio()
@@ -498,28 +498,28 @@  discard block
 block discarded – undo
498 498
 	 * @param  array $args
499 499
 	 * @return void
500 500
 	 */
501
-	public function form_field_multicheck ( $args ) {
501
+	public function form_field_multicheck($args) {
502 502
 		$options = $this->get_settings();
503 503
 
504
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
505
-			$html = '<div class="multicheck-container" style="margin-bottom:10px;">' . "\n";
506
-			foreach ( $args['data']['options'] as $k => $v ) {
504
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
505
+			$html = '<div class="multicheck-container" style="margin-bottom:10px;">'."\n";
506
+			foreach ($args['data']['options'] as $k => $v) {
507 507
 				$checked = '';
508 508
 
509
-				if( isset( $options[ $args['key'] ] ) ) {
510
-					if ( in_array( $k, (array)$options[ $args['key'] ] ) ) { $checked = ' checked="checked"'; }
509
+				if (isset($options[$args['key']])) {
510
+					if (in_array($k, (array) $options[$args['key']])) { $checked = ' checked="checked"'; }
511 511
 				} else {
512
-					if ( in_array( $k, $args['data']['defaults'] ) ) { $checked = ' checked="checked"'; }
512
+					if (in_array($k, $args['data']['defaults'])) { $checked = ' checked="checked"'; }
513 513
 				}
514
-				$html .= '<label for="checkbox-' . esc_attr( $k ) . '">' . "\n";
515
-				$html .= '<input type="checkbox" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . '][]" class="multicheck multicheck-' . esc_attr( $args['key'] ) . '" value="' . esc_attr( $k ) . '" id="checkbox-' . esc_attr( $k ) . '" ' . $checked . ' /> ' . $v . "\n";
516
-				$html .= '</label><br />' . "\n";
514
+				$html .= '<label for="checkbox-'.esc_attr($k).'">'."\n";
515
+				$html .= '<input type="checkbox" name="'.esc_attr($this->token).'['.esc_attr($args['key']).'][]" class="multicheck multicheck-'.esc_attr($args['key']).'" value="'.esc_attr($k).'" id="checkbox-'.esc_attr($k).'" '.$checked.' /> '.$v."\n";
516
+				$html .= '</label><br />'."\n";
517 517
 			}
518
-			$html .= '</div>' . "\n";
518
+			$html .= '</div>'."\n";
519 519
 			echo $html;
520 520
 
521
-			if ( isset( $args['data']['description'] ) ) {
522
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
521
+			if (isset($args['data']['description'])) {
522
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
523 523
 			}
524 524
 		}
525 525
 	} // End form_field_multicheck()
@@ -531,20 +531,20 @@  discard block
 block discarded – undo
531 531
 	 * @param  array $args
532 532
 	 * @return void
533 533
 	 */
534
-	public function form_field_range ( $args ) {
534
+	public function form_field_range($args) {
535 535
 		$options = $this->get_settings();
536 536
 
537
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
537
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
538 538
 			$html = '';
539
-			$html .= '<select id="' . esc_attr( $args['key'] ) . '" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" class="range-input">' . "\n";
540
-				foreach ( $args['data']['options'] as $k => $v ) {
541
-					$html .= '<option value="' . esc_attr( $k ) . '"' . selected( esc_attr( $options[$args['key']] ), $k, false ) . '>' . $v . '</option>' . "\n";
539
+			$html .= '<select id="'.esc_attr($args['key']).'" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" class="range-input">'."\n";
540
+				foreach ($args['data']['options'] as $k => $v) {
541
+					$html .= '<option value="'.esc_attr($k).'"'.selected(esc_attr($options[$args['key']]), $k, false).'>'.$v.'</option>'."\n";
542 542
 				}
543
-			$html .= '</select>' . "\n";
543
+			$html .= '</select>'."\n";
544 544
 			echo $html;
545 545
 
546
-			if ( isset( $args['data']['description'] ) ) {
547
-				echo '<p><span class="description">' . esc_html( $args['data']['description'] ) . '</span></p>' . "\n";
546
+			if (isset($args['data']['description'])) {
547
+				echo '<p><span class="description">'.esc_html($args['data']['description']).'</span></p>'."\n";
548 548
 			}
549 549
 		}
550 550
 	} // End form_field_range()
@@ -556,18 +556,18 @@  discard block
 block discarded – undo
556 556
 	 * @param  array $args
557 557
 	 * @return void
558 558
 	 */
559
-	public function form_field_images ( $args ) {
559
+	public function form_field_images($args) {
560 560
 		$options = $this->get_settings();
561 561
 
562
-		if ( isset( $args['data']['options'] ) && ( count( (array)$args['data']['options'] ) > 0 ) ) {
562
+		if (isset($args['data']['options']) && (count((array) $args['data']['options']) > 0)) {
563 563
 			$html = '';
564
-			foreach ( $args['data']['options'] as $k => $v ) {
565
-				$html .= '<input type="radio" name="' . esc_attr( $this->token ) . '[' . esc_attr( $args['key'] ) . ']" value="' . esc_attr( $k ) . '"' . checked( esc_attr( $options[$args['key']] ), $k, false ) . ' /> ' . $v . '<br />' . "\n";
564
+			foreach ($args['data']['options'] as $k => $v) {
565
+				$html .= '<input type="radio" name="'.esc_attr($this->token).'['.esc_attr($args['key']).']" value="'.esc_attr($k).'"'.checked(esc_attr($options[$args['key']]), $k, false).' /> '.$v.'<br />'."\n";
566 566
 			}
567 567
 			echo $html;
568 568
 
569
-			if ( isset( $args['data']['description'] ) ) {
570
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
569
+			if (isset($args['data']['description'])) {
570
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
571 571
 			}
572 572
 		}
573 573
 	} // End form_field_images()
@@ -579,19 +579,19 @@  discard block
 block discarded – undo
579 579
 	 * @param  array $args
580 580
 	 * @return void
581 581
 	 */
582
-	public function form_field_info ( $args ) {
582
+	public function form_field_info($args) {
583 583
 		$class = '';
584
-		if ( isset( $args['data']['class'] ) ) {
585
-			$class = ' ' . esc_attr( $args['data']['class'] );
584
+		if (isset($args['data']['class'])) {
585
+			$class = ' '.esc_attr($args['data']['class']);
586 586
 		}
587
-		$html = '<div id="' . $args['key'] . '" class="info-box' . $class . '">' . "\n";
588
-		if ( isset( $args['data']['name'] ) && ( $args['data']['name'] != '' ) ) {
589
-			$html .= '<h3 class="title">' . esc_html( $args['data']['name'] ) . '</h3>' . "\n";
587
+		$html = '<div id="'.$args['key'].'" class="info-box'.$class.'">'."\n";
588
+		if (isset($args['data']['name']) && ($args['data']['name'] != '')) {
589
+			$html .= '<h3 class="title">'.esc_html($args['data']['name']).'</h3>'."\n";
590 590
 		}
591
-		if ( isset( $args['data']['description'] ) && ( $args['data']['description'] != '' ) ) {
592
-			$html .= '<p>' . esc_html( $args['data']['description'] ) . '</p>' . "\n";
591
+		if (isset($args['data']['description']) && ($args['data']['description'] != '')) {
592
+			$html .= '<p>'.esc_html($args['data']['description']).'</p>'."\n";
593 593
 		}
594
-		$html .= '</div>' . "\n";
594
+		$html .= '</div>'."\n";
595 595
 
596 596
 		echo $html;
597 597
 	} // End form_field_info()
@@ -603,14 +603,14 @@  discard block
 block discarded – undo
603 603
 	 * @since  1.9.0
604 604
 	 * @param  array $args
605 605
 	 */
606
-	public function form_field_button( $args ) {
606
+	public function form_field_button($args) {
607 607
 		$options = $this->get_settings();
608 608
 
609
-		if ( isset( $args['data']['target'] ) && isset( $args['data']['label'] ) ) {
610
-			printf( '<a href="%s" class="button button-secondary">%s</a> ', esc_url( $args['data']['target'] ), esc_html( $args['data']['label'] ) );
609
+		if (isset($args['data']['target']) && isset($args['data']['label'])) {
610
+			printf('<a href="%s" class="button button-secondary">%s</a> ', esc_url($args['data']['target']), esc_html($args['data']['label']));
611 611
 
612
-			if ( isset( $args['data']['description'] ) ) {
613
-				echo '<span class="description">' . esc_html( $args['data']['description'] ) . '</span>' . "\n";
612
+			if (isset($args['data']['description'])) {
613
+				echo '<span class="description">'.esc_html($args['data']['description']).'</span>'."\n";
614 614
 			}
615 615
 		}
616 616
 	} // End form_field_button()
@@ -624,23 +624,23 @@  discard block
 block discarded – undo
624 624
 	 * @uses   $this->parse_errors()
625 625
 	 * @return array $options
626 626
 	 */
627
-	public function validate_fields ( $input ) {
627
+	public function validate_fields($input) {
628 628
 		$options = $this->get_settings();
629 629
 
630
-		foreach ( $this->fields as $k => $v ) {
630
+		foreach ($this->fields as $k => $v) {
631 631
 			// Make sure checkboxes are present even when false.
632
-			if ( $v['type'] == 'checkbox' && ! isset( $input[$k] ) ) { $input[$k] = false; }
633
-			if ( $v['type'] == 'multicheck' && ! isset( $input[$k] ) ) { $input[$k] = false; }
632
+			if ($v['type'] == 'checkbox' && ! isset($input[$k])) { $input[$k] = false; }
633
+			if ($v['type'] == 'multicheck' && ! isset($input[$k])) { $input[$k] = false; }
634 634
 
635
-			if ( isset( $input[$k] ) ) {
635
+			if (isset($input[$k])) {
636 636
 				// Perform checks on required fields.
637
-				if ( isset( $v['required'] ) && ( $v['required'] == true ) ) {
638
-					if ( in_array( $v['type'], $this->get_array_field_types() ) && ( count( (array) $input[$k] ) <= 0 ) ) {
639
-						$this->add_error( $k, $v );
637
+				if (isset($v['required']) && ($v['required'] == true)) {
638
+					if (in_array($v['type'], $this->get_array_field_types()) && (count((array) $input[$k]) <= 0)) {
639
+						$this->add_error($k, $v);
640 640
 						continue;
641 641
 					} else {
642
-						if ( $input[$k] == '' ) {
643
-							$this->add_error( $k, $v );
642
+						if ($input[$k] == '') {
643
+							$this->add_error($k, $v);
644 644
 							continue;
645 645
 						}
646 646
 					}
@@ -649,28 +649,28 @@  discard block
 block discarded – undo
649 649
 				$value = $input[$k];
650 650
 
651 651
 				// Check if the field is valid.
652
-				$method = $this->determine_method( $v, 'check' );
652
+				$method = $this->determine_method($v, 'check');
653 653
 
654
-				if ( function_exists ( $method ) ) {
655
-					$is_valid = $method( $value );
654
+				if (function_exists($method)) {
655
+					$is_valid = $method($value);
656 656
 				} else {
657
-					if ( method_exists( $this, $method ) ) {
658
-						$is_valid = $this->$method( $value );
657
+					if (method_exists($this, $method)) {
658
+						$is_valid = $this->$method($value);
659 659
 					}
660 660
 				}
661 661
 
662
-				if ( ! $is_valid ) {
663
-					$this->add_error( $k, $v );
662
+				if ( ! $is_valid) {
663
+					$this->add_error($k, $v);
664 664
 					continue;
665 665
 				}
666 666
 
667
-				$method = $this->determine_method( $v, 'validate' );
667
+				$method = $this->determine_method($v, 'validate');
668 668
 
669
-				if ( function_exists ( $method ) ) {
670
-					$options[$k] = $method( $value );
669
+				if (function_exists($method)) {
670
+					$options[$k] = $method($value);
671 671
 				} else {
672
-					if ( method_exists( $this, $method ) ) {
673
-						$options[$k] = $this->$method( $value );
672
+					if (method_exists($this, $method)) {
673
+						$options[$k] = $this->$method($value);
674 674
 					}
675 675
 				}
676 676
 			}
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 	 * @param  string $input
689 689
 	 * @return string
690 690
 	 */
691
-	public function validate_field_text ( $input ) {
692
-		return trim( esc_attr( $input ) );
691
+	public function validate_field_text($input) {
692
+		return trim(esc_attr($input));
693 693
 	} // End validate_field_text()
694 694
 
695 695
 	/**
@@ -699,11 +699,11 @@  discard block
 block discarded – undo
699 699
 	 * @param  string $input
700 700
 	 * @return string
701 701
 	 */
702
-	public function validate_field_checkbox ( $input ) {
703
-		if ( ! isset( $input ) ) {
702
+	public function validate_field_checkbox($input) {
703
+		if ( ! isset($input)) {
704 704
 			return 0;
705 705
 		} else {
706
-			return (bool)$input;
706
+			return (bool) $input;
707 707
 		}
708 708
 	} // End validate_field_checkbox()
709 709
 
@@ -714,10 +714,10 @@  discard block
 block discarded – undo
714 714
 	 * @param  string $input
715 715
 	 * @return string
716 716
 	 */
717
-	public function validate_field_multicheck ( $input ) {
717
+	public function validate_field_multicheck($input) {
718 718
 		$input = (array) $input;
719 719
 
720
-		$input = array_map( 'esc_attr', $input );
720
+		$input = array_map('esc_attr', $input);
721 721
 
722 722
 		return $input;
723 723
 	} // End validate_field_multicheck()
@@ -729,8 +729,8 @@  discard block
 block discarded – undo
729 729
 	 * @param  string $input
730 730
 	 * @return string
731 731
 	 */
732
-	public function validate_field_range ( $input ) {
733
-		$input = number_format( floatval( $input ), 0 );
732
+	public function validate_field_range($input) {
733
+		$input = number_format(floatval($input), 0);
734 734
 
735 735
 		return $input;
736 736
 	} // End validate_field_range()
@@ -742,8 +742,8 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $input
743 743
 	 * @return string
744 744
 	 */
745
-	public function validate_field_url ( $input ) {
746
-		return trim( esc_url( $input ) );
745
+	public function validate_field_url($input) {
746
+		return trim(esc_url($input));
747 747
 	} // End validate_field_url()
748 748
 
749 749
 	/**
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 	 * @since  1.1.0
753 753
 	 * @return boolean Is the value valid?
754 754
 	 */
755
-	public function check_field_text ( $input ) {
755
+	public function check_field_text($input) {
756 756
 		$is_valid = true;
757 757
 
758 758
 		return $is_valid;
@@ -766,11 +766,11 @@  discard block
 block discarded – undo
766 766
 	 * @param  array $data
767 767
 	 * @return void
768 768
 	 */
769
-	protected function add_error ( $key, $data ) {
770
-		if ( isset( $data['error_message'] ) ) {
769
+	protected function add_error($key, $data) {
770
+		if (isset($data['error_message'])) {
771 771
 			$message = $data['error_message'];
772 772
 		} else {
773
-			$message = sprintf( __( '%s is a required field', 'woothemes-sensei' ), $data['name'] );
773
+			$message = sprintf(__('%s is a required field', 'woothemes-sensei'), $data['name']);
774 774
 		}
775 775
 		$this->errors[$key] = $message;
776 776
 	} // End add_error()
@@ -781,14 +781,14 @@  discard block
 block discarded – undo
781 781
 	 * @since   1.0.0
782 782
 	 * @return  void
783 783
 	 */
784
-	protected function parse_errors () {
785
-		if ( count ( $this->errors ) > 0 ) {
786
-			foreach ( $this->errors as $k => $v ) {
787
-				add_settings_error( $this->token . '-errors', $k, $v, 'error' );
784
+	protected function parse_errors() {
785
+		if (count($this->errors) > 0) {
786
+			foreach ($this->errors as $k => $v) {
787
+				add_settings_error($this->token.'-errors', $k, $v, 'error');
788 788
 			}
789 789
 		} else {
790
-			$message = sprintf( __( '%s updated', 'woothemes-sensei' ), $this->name );
791
-			add_settings_error( $this->token . '-errors', $this->token, $message, 'updated' );
790
+			$message = sprintf(__('%s updated', 'woothemes-sensei'), $this->name);
791
+			add_settings_error($this->token.'-errors', $this->token, $message, 'updated');
792 792
 		}
793 793
 	} // End parse_errors()
794 794
 
@@ -798,8 +798,8 @@  discard block
 block discarded – undo
798 798
 	 * @since  1.0.0
799 799
 	 * @return void
800 800
 	 */
801
-	protected function get_array_field_types () {
802
-		return array( 'multicheck' );
801
+	protected function get_array_field_types() {
802
+		return array('multicheck');
803 803
 	} // End get_array_field_types()
804 804
 
805 805
 	/**
@@ -808,22 +808,22 @@  discard block
 block discarded – undo
808 808
 	 * @since  1.0.0
809 809
 	 * @return void
810 810
 	 */
811
-	public function enqueue_scripts () {
811
+	public function enqueue_scripts() {
812 812
 
813 813
 
814
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
814
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
815 815
 
816
-		wp_enqueue_script( 'farbtastic' );
817
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'farbtastic' ), Sensei()->version );
816
+		wp_enqueue_script('farbtastic');
817
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'farbtastic'), Sensei()->version);
818 818
 
819
-		if ( $this->has_range ) {
820
-			wp_enqueue_script( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/js/ranges' . $suffix . '.js' ), array( 'jquery-ui-slider' ), Sensei()->version );
819
+		if ($this->has_range) {
820
+			wp_enqueue_script('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/js/ranges'.$suffix.'.js'), array('jquery-ui-slider'), Sensei()->version);
821 821
 		}
822 822
 
823
-		wp_register_script( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/js/image-selectors' . $suffix . '.js' ), array( 'jquery' ), Sensei()->version );
823
+		wp_register_script('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/js/image-selectors'.$suffix.'.js'), array('jquery'), Sensei()->version);
824 824
 
825
-		if ( $this->has_imageselector ) {
826
-			wp_enqueue_script( 'woothemes-sensei-settings-imageselectors' );
825
+		if ($this->has_imageselector) {
826
+			wp_enqueue_script('woothemes-sensei-settings-imageselectors');
827 827
 		}
828 828
 
829 829
 	} // End enqueue_scripts()
@@ -834,12 +834,12 @@  discard block
 block discarded – undo
834 834
 	 * @since  1.0.0
835 835
 	 * @return void
836 836
 	 */
837
-	public function enqueue_styles () {
837
+	public function enqueue_styles() {
838 838
 
839
-		wp_enqueue_style( $this->token . '-admin' );
839
+		wp_enqueue_style($this->token.'-admin');
840 840
 
841
-		wp_enqueue_style( 'farbtastic' );
842
-		wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), array( 'farbtastic' ), Sensei()->version );
841
+		wp_enqueue_style('farbtastic');
842
+		wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), array('farbtastic'), Sensei()->version);
843 843
 
844 844
 		$this->enqueue_field_styles();
845 845
 	} // End enqueue_styles()
@@ -850,17 +850,17 @@  discard block
 block discarded – undo
850 850
 	 * @since  1.0.0
851 851
 	 * @return void
852 852
 	 */
853
-	public function enqueue_field_styles () {
853
+	public function enqueue_field_styles() {
854 854
 
855 855
 
856
-		if ( $this->has_range ) {
857
-			wp_enqueue_style( 'woothemes-sensei-settings-ranges', esc_url( Sensei()->plugin_url . 'assets/css/ranges.css' ), '', Sensei()->version );
856
+		if ($this->has_range) {
857
+			wp_enqueue_style('woothemes-sensei-settings-ranges', esc_url(Sensei()->plugin_url.'assets/css/ranges.css'), '', Sensei()->version);
858 858
 		}
859 859
 
860
-		wp_register_style( 'woothemes-sensei-settings-imageselectors', esc_url( Sensei()->plugin_url . 'assets/css/image-selectors.css' ), '', Sensei()->version );
860
+		wp_register_style('woothemes-sensei-settings-imageselectors', esc_url(Sensei()->plugin_url.'assets/css/image-selectors.css'), '', Sensei()->version);
861 861
 
862
-		if ( $this->has_imageselector ) {
863
-			wp_enqueue_style( 'woothemes-sensei-settings-imageselectors' );
862
+		if ($this->has_imageselector) {
863
+			wp_enqueue_style('woothemes-sensei-settings-imageselectors');
864 864
 		}
865 865
 	} // End enqueue_field_styles()
866 866
 } // End Class
@@ -870,4 +870,4 @@  discard block
 block discarded – undo
870 870
  * for backward compatibility
871 871
  * @since 1.9.0
872 872
  */
873
-class WooThemes_Sensei_Settings_API extends Sensei_Settings_API{}
873
+class WooThemes_Sensei_Settings_API extends Sensei_Settings_API {}
Please login to merge, or discard this patch.
includes/class-sensei-admin.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	public function __construct () {
22 22
 
23
-        //register admin styles
23
+		//register admin styles
24 24
 		add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) );
25 25
 
26
-        //register admin scripts
27
-        add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
26
+		//register admin scripts
27
+		add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
28 28
 
29 29
 		add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) );
30 30
 		add_action( 'settings_before_form', array( $this, 'install_pages_output' ) );
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) );
34 34
 		add_action( 'admin_init', array( $this, 'page_redirect' ) );
35 35
 		add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) );
36
-        add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
36
+		add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
37 37
 
38 38
 		// Duplicate lesson & courses
39 39
 		add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 );
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 		if( $menu_cap ) {
86 86
 			$menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' );
87
-            add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
87
+			add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
88 88
 		}
89 89
 
90 90
 		add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) );
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 			$submenu_file = 'edit-tags.php?taxonomy=course-category&amp;post_type=course';
142 142
 			$parent_file  = 'edit.php?post_type=course';
143 143
 
144
-        } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
144
+		} elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
145 145
 
146
-            $submenu_file = 'edit-tags.php?taxonomy=module';
147
-            $parent_file  = 'edit.php?post_type=course';
146
+			$submenu_file = 'edit-tags.php?taxonomy=module';
147
+			$parent_file  = 'edit.php?post_type=course';
148 148
 
149 149
 		} elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) {
150 150
 
151
-            $submenu_file = 'edit.php?post_type=sensei_message';
151
+			$submenu_file = 'edit.php?post_type=sensei_message';
152 152
 			$parent_file  = 'sensei';
153 153
 
154 154
 		}
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	function install_pages_output() {
178 178
 
179
-        if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
179
+		if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
180 180
 
181
-            ?>
181
+			?>
182 182
             <div id="message" class="updated sensei-message sensei-connect">
183 183
                 <p><?php _e( '<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p>
184 184
                 <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a>
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             </div>
187 187
             <?php
188 188
 
189
-        }
189
+		}
190 190
 
191 191
 	} // End install_pages_output()
192 192
 
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
 		endif;
219 219
 
220 220
 		$page_data = array(
221
-	        'post_status' 		=> 'publish',
222
-	        'post_type' 		=> 'page',
223
-	        'post_author' 		=> 1,
224
-	        'post_name' 		=> $slug,
225
-	        'post_title' 		=> $page_title,
226
-	        'post_content' 		=> $page_content,
227
-	        'post_parent' 		=> $post_parent,
228
-	        'comment_status' 	=> 'closed'
229
-	    );
230
-	    $page_id = wp_insert_post( $page_data );
231
-
232
-	    update_option( $option, $page_id );
221
+			'post_status' 		=> 'publish',
222
+			'post_type' 		=> 'page',
223
+			'post_author' 		=> 1,
224
+			'post_name' 		=> $slug,
225
+			'post_title' 		=> $page_title,
226
+			'post_content' 		=> $page_content,
227
+			'post_parent' 		=> $post_parent,
228
+			'comment_status' 	=> 'closed'
229
+		);
230
+		$page_id = wp_insert_post( $page_data );
231
+
232
+		update_option( $option, $page_id );
233 233
 	} // End create_page()
234 234
 
235 235
 
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
 	function create_pages() {
243 243
 
244 244
 		// Courses page
245
-	    $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' );
245
+		$this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' );
246 246
 
247 247
 		// User Dashboard page
248
-	    $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' );
248
+		$this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' );
249 249
 
250 250
 	} // End create_pages()
251 251
 
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 		wp_register_style( 'woothemes-sensei-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' );
267 267
 		wp_enqueue_style( 'woothemes-sensei-global' );
268 268
 
269
-        // Select 2 styles
270
-        wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
269
+		// Select 2 styles
270
+		wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
271 271
 
272 272
 		// Test for Write Panel Pages
273 273
 		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 ) ) ) {
@@ -280,32 +280,32 @@  discard block
 block discarded – undo
280 280
 	} // End admin_styles_global()
281 281
 
282 282
 
283
-    /**
284
-     * Globally register all scripts needed in admin.
285
-     *
286
-     * The script users should enqueue the script when needed.
287
-     *
288
-     * @since 1.8.2
289
-     * @access public
290
-     */
291
-    public function register_scripts( $hook ){
283
+	/**
284
+	 * Globally register all scripts needed in admin.
285
+	 *
286
+	 * The script users should enqueue the script when needed.
287
+	 *
288
+	 * @since 1.8.2
289
+	 * @access public
290
+	 */
291
+	public function register_scripts( $hook ){
292 292
 
293
-        $screen = get_current_screen();
293
+		$screen = get_current_screen();
294 294
 
295
-        // Allow developers to load non-minified versions of scripts
296
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
295
+		// Allow developers to load non-minified versions of scripts
296
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
297 297
 
298
-        // Select2 script used to enhance all select boxes
299
-        wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
298
+		// Select2 script used to enhance all select boxes
299
+		wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
300 300
 
301
-        // load edit module scripts
302
-        if( 'edit-module' ==  $screen->id ){
301
+		// load edit module scripts
302
+		if( 'edit-module' ==  $screen->id ){
303 303
 
304
-            wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
304
+			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
305 305
 
306
-        }
306
+		}
307 307
 
308
-    }
308
+	}
309 309
 
310 310
 
311 311
 	/**
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 * @return void
316 316
 	 */
317 317
 	function admin_install_notice() {
318
-	    ?>
318
+		?>
319 319
 	    <div id="message" class="updated sensei-message sensei-connect">
320 320
 
321 321
             <p>
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	 * @return void
351 351
 	 */
352 352
 	function admin_installed_notice() {
353
-	    ?>
353
+		?>
354 354
 	    <div id="message" class="updated sensei-message sensei-connect">
355 355
 
356 356
 	    	<p>
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 	    </div>
379 379
 	    <?php
380 380
 
381
-	    // Set installed option
382
-	    update_option('sensei_installed', 0);
381
+		// Set installed option
382
+		update_option('sensei_installed', 0);
383 383
 	} // End admin_installed_notice()
384 384
 
385 385
 
@@ -411,21 +411,21 @@  discard block
 block discarded – undo
411 411
 	function admin_notices_styles() {
412 412
 
413 413
 		// Installed notices
414
-	    if ( 1 == get_option( 'sensei_installed' ) ) {
414
+		if ( 1 == get_option( 'sensei_installed' ) ) {
415 415
 
416
-	    	wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
416
+			wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
417 417
 
418
-	    	if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
419
-	    		add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
420
-	    	} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
421
-	    		add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
422
-	    	} // End If Statement
418
+			if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
419
+				add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
420
+			} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
421
+				add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
422
+			} // End If Statement
423 423
 
424
-	    } // End If Statement
424
+		} // End If Statement
425 425
 
426
-	    if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
427
-	    	add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
428
-	    }
426
+		if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
427
+			add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
428
+		}
429 429
 
430 430
 	} // End admin_notices_styles()
431 431
 
@@ -541,30 +541,30 @@  discard block
 block discarded – undo
541 541
 	 */
542 542
 	private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) {
543 543
 
544
-        $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
545
-        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
544
+		$old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
545
+		$old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
546 546
 
547
-        // duplicate the generic wp post information
547
+		// duplicate the generic wp post information
548 548
 		$new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' );
549 549
 
550 550
 		//update the new lesson data
551
-        add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
551
+		add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
552 552
 
553 553
 		//update the new quiz data
554
-        add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
555
-        wp_update_post(
556
-            array(
557
-                'ID' => $new_quiz->ID,
558
-                'post_parent' => $new_lesson_id
559
-            )
560
-        );
554
+		add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
555
+		wp_update_post(
556
+			array(
557
+				'ID' => $new_quiz->ID,
558
+				'post_parent' => $new_lesson_id
559
+			)
560
+		);
561 561
 
562 562
 		foreach( $old_quiz_questions as $question ) {
563 563
 
564 564
 			// copy the question order over to the new quiz
565 565
 			$old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true );
566
-            $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
567
-            add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
566
+			$new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
567
+			add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
568 568
 
569 569
 			// Add question to quiz
570 570
 			add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false );
@@ -886,21 +886,21 @@  discard block
 block discarded – undo
886 886
 								break;
887 887
 
888 888
 								case 'checkbox':
889
-                                    //backwards compatibility
890
-                                    if( empty( $data ) || 'on' == $data ){
891
-                                        $checked_value = 'on';
892
-                                    }elseif( 'yes' == $data  ) {
889
+									//backwards compatibility
890
+									if( empty( $data ) || 'on' == $data ){
891
+										$checked_value = 'on';
892
+									}elseif( 'yes' == $data  ) {
893 893
 
894
-                                        $checked_value = 'yes';
894
+										$checked_value = 'yes';
895 895
 
896
-                                    }elseif( 'auto' == $data  ) {
896
+									}elseif( 'auto' == $data  ) {
897 897
 
898
-                                        $checked_value = 'auto';
898
+										$checked_value = 'auto';
899 899
 
900
-                                    } else {
901
-                                        $checked_value = 1;
902
-                                        $data = intval( $data );
903
-                                    }
900
+									} else {
901
+										$checked_value = 1;
902
+										$data = intval( $data );
903
+									}
904 904
 									$checked = checked( $checked_value, $data, false );
905 905
 									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n";
906 906
 								break;
@@ -1004,26 +1004,26 @@  discard block
 block discarded – undo
1004 1004
 
1005 1005
 		if( 0 < count( $courses ) ) {
1006 1006
 
1007
-            // order the courses as set by the users
1008
-            $all_course_ids = array();
1009
-            foreach( $courses as $course ){
1007
+			// order the courses as set by the users
1008
+			$all_course_ids = array();
1009
+			foreach( $courses as $course ){
1010 1010
 
1011
-                $all_course_ids[] = (string)$course->ID;
1011
+				$all_course_ids[] = (string)$course->ID;
1012 1012
 
1013
-            }
1014
-            $order_string = $this->get_course_order();
1013
+			}
1014
+			$order_string = $this->get_course_order();
1015 1015
 
1016
-            if( !empty( $order_string ) ){
1017
-                $ordered_course_ids = explode(',' , $order_string );
1018
-                $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1019
-            }
1016
+			if( !empty( $order_string ) ){
1017
+				$ordered_course_ids = explode(',' , $order_string );
1018
+				$all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1019
+			}
1020 1020
 
1021 1021
 
1022 1022
 			$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1023 1023
 			$html .= '<ul class="sortable-course-list">' . "\n";
1024 1024
 			$count = 0;
1025 1025
 			foreach ( $all_course_ids as $course_id ) {
1026
-                $course = get_post( $course_id );
1026
+				$course = get_post( $course_id );
1027 1027
 				$count++;
1028 1028
 				$class = 'course';
1029 1029
 				if ( $count == 1 ) { $class .= ' first'; }
@@ -1138,73 +1138,73 @@  discard block
 block discarded – undo
1138 1138
 
1139 1139
 				$displayed_lessons = array();
1140 1140
 
1141
-                $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1142
-
1143
-                foreach( $modules as $module ) {
1144
-
1145
-                    $args = array(
1146
-                        'post_type' => 'lesson',
1147
-                        'post_status' => 'publish',
1148
-                        'posts_per_page' => -1,
1149
-                        'meta_query' => array(
1150
-                            array(
1151
-                                'key' => '_lesson_course',
1152
-                                'value' => intval( $course_id ),
1153
-                                'compare' => '='
1154
-                            )
1155
-                        ),
1156
-                        'tax_query' => array(
1157
-                            array(
1158
-                                'taxonomy' => Sensei()->modules->taxonomy,
1159
-                                'field' => 'id',
1160
-                                'terms' => intval( $module->term_id )
1161
-                            )
1162
-                        ),
1163
-                        'meta_key' => '_order_module_' . $module->term_id,
1164
-                        'orderby' => 'meta_value_num date',
1165
-                        'order' => 'ASC',
1166
-                        'suppress_filters' => 0
1167
-                    );
1168
-
1169
-                    $lessons = get_posts( $args );
1170
-
1171
-                    if( count( $lessons ) > 0 ) {
1172
-                        $html .= '<h3>' . $module->name . '</h3>' . "\n";
1173
-                        $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1174
-
1175
-                        $count = 0;
1176
-                        foreach( $lessons as $lesson ) {
1177
-                            $count++;
1178
-                            $class = 'lesson';
1179
-                            if ( $count == 1 ) { $class .= ' first'; }
1180
-                            if ( $count == count( $lesson ) ) { $class .= ' last'; }
1181
-                            if ( $count % 2 != 0 ) {
1182
-                                $class .= ' alternate';
1183
-                            }
1184
-
1185
-                            $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1186
-
1187
-                            $displayed_lessons[] = $lesson->ID;
1188
-                        }
1189
-
1190
-                        $html .= '</ul>' . "\n";
1191
-
1192
-                        $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1193
-                    }
1194
-                }
1195
-
1196
-
1197
-                $lessons = Sensei()->course->course_lessons( $course_id );
1141
+				$modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1142
+
1143
+				foreach( $modules as $module ) {
1144
+
1145
+					$args = array(
1146
+						'post_type' => 'lesson',
1147
+						'post_status' => 'publish',
1148
+						'posts_per_page' => -1,
1149
+						'meta_query' => array(
1150
+							array(
1151
+								'key' => '_lesson_course',
1152
+								'value' => intval( $course_id ),
1153
+								'compare' => '='
1154
+							)
1155
+						),
1156
+						'tax_query' => array(
1157
+							array(
1158
+								'taxonomy' => Sensei()->modules->taxonomy,
1159
+								'field' => 'id',
1160
+								'terms' => intval( $module->term_id )
1161
+							)
1162
+						),
1163
+						'meta_key' => '_order_module_' . $module->term_id,
1164
+						'orderby' => 'meta_value_num date',
1165
+						'order' => 'ASC',
1166
+						'suppress_filters' => 0
1167
+					);
1168
+
1169
+					$lessons = get_posts( $args );
1170
+
1171
+					if( count( $lessons ) > 0 ) {
1172
+						$html .= '<h3>' . $module->name . '</h3>' . "\n";
1173
+						$html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1174
+
1175
+						$count = 0;
1176
+						foreach( $lessons as $lesson ) {
1177
+							$count++;
1178
+							$class = 'lesson';
1179
+							if ( $count == 1 ) { $class .= ' first'; }
1180
+							if ( $count == count( $lesson ) ) { $class .= ' last'; }
1181
+							if ( $count % 2 != 0 ) {
1182
+								$class .= ' alternate';
1183
+							}
1184
+
1185
+							$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1186
+
1187
+							$displayed_lessons[] = $lesson->ID;
1188
+						}
1189
+
1190
+						$html .= '</ul>' . "\n";
1191
+
1192
+						$html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1193
+					}
1194
+				}
1195
+
1196
+
1197
+				$lessons = Sensei()->course->course_lessons( $course_id );
1198 1198
 
1199 1199
 				if( 0 < count( $lessons ) ) {
1200 1200
 
1201
-                    //get module term ids, will be used to exclude lessons
1202
-                    $module_items_ids = array();
1203
-                    if( ! empty( $modules ) ) {
1204
-                        foreach ($modules as $module) {
1205
-                            $module_items_ids[] = $module->term_id;
1206
-                        }
1207
-                    }
1201
+					//get module term ids, will be used to exclude lessons
1202
+					$module_items_ids = array();
1203
+					if( ! empty( $modules ) ) {
1204
+						foreach ($modules as $module) {
1205
+							$module_items_ids[] = $module->term_id;
1206
+						}
1207
+					}
1208 1208
 
1209 1209
 					if( 0 < count( $displayed_lessons ) ) {
1210 1210
 						$html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n";
@@ -1214,13 +1214,13 @@  discard block
 block discarded – undo
1214 1214
 					$count = 0;
1215 1215
 					foreach ( $lessons as $lesson ) {
1216 1216
 
1217
-                        // if lesson belongs to one fo the course modules then exclude it here
1218
-                        // as it is listed above
1219
-                        if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1217
+						// if lesson belongs to one fo the course modules then exclude it here
1218
+						// as it is listed above
1219
+						if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1220 1220
 
1221
-                            continue;
1221
+							continue;
1222 1222
 
1223
-                        }
1223
+						}
1224 1224
 
1225 1225
 						$count++;
1226 1226
 						$class = 'lesson';
@@ -1264,23 +1264,23 @@  discard block
 block discarded – undo
1264 1264
 
1265 1265
 		if( $course_id ) {
1266 1266
 
1267
-            $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1267
+			$modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1268 1268
 
1269
-            foreach( $modules as $module ) {
1269
+			foreach( $modules as $module ) {
1270 1270
 
1271
-                $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ];
1271
+				$module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ];
1272 1272
 
1273
-                if( $module_order_string ) {
1274
-                    $order = explode( ',', $module_order_string );
1275
-                    $i = 1;
1276
-                    foreach( $order as $lesson_id ) {
1277
-                        if( $lesson_id ) {
1278
-                            update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1279
-                            ++$i;
1280
-                        }
1281
-                    }
1282
-                }
1283
-            }
1273
+				if( $module_order_string ) {
1274
+					$order = explode( ',', $module_order_string );
1275
+					$i = 1;
1276
+					foreach( $order as $lesson_id ) {
1277
+						if( $lesson_id ) {
1278
+							update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1279
+							++$i;
1280
+						}
1281
+					}
1282
+				}
1283
+			}
1284 1284
 
1285 1285
 
1286 1286
 			if( $order_string ) {
@@ -1363,47 +1363,47 @@  discard block
 block discarded – undo
1363 1363
 
1364 1364
 	/**
1365 1365
 	 * Adding admin notice if the current
1366
-     * installed theme is not compatible
1367
-     *
1366
+	 * installed theme is not compatible
1367
+	 *
1368 1368
 	 * @return void
1369 1369
 	 */
1370 1370
 	public function theme_compatibility_notices() {
1371 1371
 
1372
-        if( isset( $_GET['sensei_hide_notice'] ) ) {
1373
-        	switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1372
+		if( isset( $_GET['sensei_hide_notice'] ) ) {
1373
+			switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1374 1374
 				case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break;
1375 1375
 				case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break;
1376 1376
 			}
1377
-        }
1377
+		}
1378 1378
 
1379
-        // white list templates that are already support by default and do not show notice for them
1380
-        $template = get_option( 'template' );
1379
+		// white list templates that are already support by default and do not show notice for them
1380
+		$template = get_option( 'template' );
1381 1381
 
1382
-        $white_list = array(    'twentyeleven',
1383
-                                'twentytwelve',
1384
-                                'twentyfourteen',
1385
-                                'twentyfifteen',
1386
-                                'twentysixteen',
1387
-                                'storefront',
1388
-                                                );
1382
+		$white_list = array(    'twentyeleven',
1383
+								'twentytwelve',
1384
+								'twentyfourteen',
1385
+								'twentyfifteen',
1386
+								'twentysixteen',
1387
+								'storefront',
1388
+												);
1389 1389
 
1390
-        if ( in_array( $template, $white_list ) ) {
1390
+		if ( in_array( $template, $white_list ) ) {
1391 1391
 
1392
-            return;
1392
+			return;
1393 1393
 
1394
-        }
1394
+		}
1395 1395
 
1396
-        // don't show the notice if the user chose to hide it
1397
-        $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1398
-        if(  $hide_theme_check_notice ) {
1396
+		// don't show the notice if the user chose to hide it
1397
+		$hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1398
+		if(  $hide_theme_check_notice ) {
1399 1399
 
1400
-            return;
1400
+			return;
1401 1401
 
1402
-        }
1402
+		}
1403 1403
 
1404
-        // show the notice for themes not supporting sensei
1405
-	    if ( ! current_theme_supports( 'sensei' ) ) {
1406
-            ?>
1404
+		// show the notice for themes not supporting sensei
1405
+		if ( ! current_theme_supports( 'sensei' ) ) {
1406
+			?>
1407 1407
 
1408 1408
             <div id="message" class="error sensei-message sensei-connect">
1409 1409
                     <p>
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 	public function reset_theme_check_notices() {
1440 1440
 		global $current_user;
1441 1441
 		wp_get_current_user();
1442
-        $user_id = $current_user->ID;
1442
+		$user_id = $current_user->ID;
1443 1443
 
1444 1444
 		delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' );
1445 1445
 	}
@@ -1459,60 +1459,60 @@  discard block
 block discarded – undo
1459 1459
 		return $prevent_access;
1460 1460
 	}
1461 1461
 
1462
-    /**
1463
-     * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args
1464
-     * on the sensei settings page.
1465
-     *
1466
-     * The function
1467
-     *
1468
-     * @since 1.8.7
1469
-     */
1470
-    public  static function install_pages(){
1462
+	/**
1463
+	 * Hooked onto admin_init. Listens for install_sensei_pages and skip_install_sensei_pages query args
1464
+	 * on the sensei settings page.
1465
+	 *
1466
+	 * The function
1467
+	 *
1468
+	 * @since 1.8.7
1469
+	 */
1470
+	public  static function install_pages(){
1471 1471
 
1472
-        // only fire on the settings page
1473
-        if( ! isset( $_GET['page'] )
1474
-            || 'woothemes-sensei-settings' != $_GET['page']
1475
-            || 1 == get_option('skip_install_sensei_pages') ){
1472
+		// only fire on the settings page
1473
+		if( ! isset( $_GET['page'] )
1474
+			|| 'woothemes-sensei-settings' != $_GET['page']
1475
+			|| 1 == get_option('skip_install_sensei_pages') ){
1476 1476
 
1477
-            return;
1477
+			return;
1478 1478
 
1479
-        }
1479
+		}
1480 1480
 
1481
-        // Install/page installer
1482
-        $install_complete = false;
1481
+		// Install/page installer
1482
+		$install_complete = false;
1483 1483
 
1484
-        // Add pages button
1485
-        $settings_url = '';
1486
-        if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) {
1484
+		// Add pages button
1485
+		$settings_url = '';
1486
+		if (isset($_GET['install_sensei_pages']) && $_GET['install_sensei_pages']) {
1487 1487
 
1488
-            Sensei()->admin->create_pages();
1489
-            update_option('skip_install_sensei_pages', 1);
1490
-            $install_complete = true;
1491
-            $settings_url = remove_query_arg('install_sensei_pages');
1488
+			Sensei()->admin->create_pages();
1489
+			update_option('skip_install_sensei_pages', 1);
1490
+			$install_complete = true;
1491
+			$settings_url = remove_query_arg('install_sensei_pages');
1492 1492
 
1493
-            // Skip button
1494
-        } elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) {
1493
+			// Skip button
1494
+		} elseif (isset($_GET['skip_install_sensei_pages']) && $_GET['skip_install_sensei_pages']) {
1495 1495
 
1496
-            update_option('skip_install_sensei_pages', 1);
1497
-            $install_complete = true;
1498
-            $settings_url = remove_query_arg('skip_install_sensei_pages');
1496
+			update_option('skip_install_sensei_pages', 1);
1497
+			$install_complete = true;
1498
+			$settings_url = remove_query_arg('skip_install_sensei_pages');
1499 1499
 
1500
-        }
1500
+		}
1501 1501
 
1502
-        if ($install_complete) {
1502
+		if ($install_complete) {
1503 1503
 
1504
-            // Flush rules after install
1505
-            flush_rewrite_rules( true );
1504
+			// Flush rules after install
1505
+			flush_rewrite_rules( true );
1506 1506
 
1507
-            // Set installed option
1508
-            update_option('sensei_installed', 0);
1507
+			// Set installed option
1508
+			update_option('sensei_installed', 0);
1509 1509
 
1510
-            $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1511
-            wp_redirect( $complete_url );
1510
+			$complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1511
+			wp_redirect( $complete_url );
1512 1512
 
1513
-        }
1513
+		}
1514 1514
 
1515
-    }// end install_pages
1515
+	}// end install_pages
1516 1516
 
1517 1517
 } // End Class
1518 1518
 
Please login to merge, or discard this patch.
Spacing   +419 added lines, -419 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 Administration Class
@@ -18,51 +18,51 @@  discard block
 block discarded – undo
18 18
 	 * Constructor.
19 19
 	 * @since  1.0.0
20 20
 	 */
21
-	public function __construct () {
21
+	public function __construct() {
22 22
 
23 23
         //register admin styles
24
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) );
24
+		add_action('admin_enqueue_scripts', array($this, 'admin_styles_global'));
25 25
 
26 26
         //register admin scripts
27
-        add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
27
+        add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
28 28
 
29
-		add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) );
30
-		add_action( 'settings_before_form', array( $this, 'install_pages_output' ) );
31
-		add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
32
-		add_action( 'menu_order', array( $this, 'admin_menu_order' ) );
33
-		add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) );
34
-		add_action( 'admin_init', array( $this, 'page_redirect' ) );
35
-		add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) );
36
-        add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
29
+		add_action('admin_print_styles', array($this, 'admin_notices_styles'));
30
+		add_action('settings_before_form', array($this, 'install_pages_output'));
31
+		add_action('admin_menu', array($this, 'admin_menu'), 10);
32
+		add_action('menu_order', array($this, 'admin_menu_order'));
33
+		add_action('admin_head', array($this, 'admin_menu_highlight'));
34
+		add_action('admin_init', array($this, 'page_redirect'));
35
+		add_action('admin_init', array($this, 'sensei_add_custom_menu_items'));
36
+        add_action('admin_init', array(__CLASS__, 'install_pages'));
37 37
 
38 38
 		// Duplicate lesson & courses
39
-		add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 );
40
-		add_action( 'admin_action_duplicate_lesson', array( $this, 'duplicate_lesson_action' ) );
41
-		add_action( 'admin_action_duplicate_course', array( $this, 'duplicate_course_action' ) );
42
-		add_action( 'admin_action_duplicate_course_with_lessons', array( $this, 'duplicate_course_with_lessons_action' ) );
39
+		add_filter('post_row_actions', array($this, 'duplicate_action_link'), 10, 2);
40
+		add_action('admin_action_duplicate_lesson', array($this, 'duplicate_lesson_action'));
41
+		add_action('admin_action_duplicate_course', array($this, 'duplicate_course_action'));
42
+		add_action('admin_action_duplicate_course_with_lessons', array($this, 'duplicate_course_with_lessons_action'));
43 43
 
44 44
 		// Handle lessons list table filtering
45
-		add_action( 'restrict_manage_posts', array( $this, 'lesson_filter_options' ) );
46
-		add_filter( 'request', array( $this, 'lesson_filter_actions' ) );
45
+		add_action('restrict_manage_posts', array($this, 'lesson_filter_options'));
46
+		add_filter('request', array($this, 'lesson_filter_actions'));
47 47
 
48 48
 		// Add Sensei items to 'at a glance' widget
49
-		add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
49
+		add_filter('dashboard_glance_items', array($this, 'glance_items'), 10, 1);
50 50
 
51 51
 		// Handle course and lesson deletions
52
-		add_action( 'trash_course', array( $this, 'delete_content' ), 10, 2 );
53
-		add_action( 'trash_lesson', array( $this, 'delete_content' ), 10, 2 );
52
+		add_action('trash_course', array($this, 'delete_content'), 10, 2);
53
+		add_action('trash_lesson', array($this, 'delete_content'), 10, 2);
54 54
 
55 55
 		// Delete user activity when user is deleted
56
-		add_action( 'deleted_user', array( $this, 'delete_user_activity' ), 10, 1 );
56
+		add_action('deleted_user', array($this, 'delete_user_activity'), 10, 1);
57 57
 
58 58
 		// Add notices to WP dashboard
59
-		add_action( 'admin_notices', array( $this, 'theme_compatibility_notices' ) );
59
+		add_action('admin_notices', array($this, 'theme_compatibility_notices'));
60 60
 
61 61
 		// Reset theme notices when switching themes
62
-		add_action( 'switch_theme', array( $this, 'reset_theme_check_notices' ) );
62
+		add_action('switch_theme', array($this, 'reset_theme_check_notices'));
63 63
 
64 64
 		// Allow Teacher access the admin area
65
-		add_filter( 'woocommerce_prevent_admin_access', array( $this, 'admin_access' ) );
65
+		add_filter('woocommerce_prevent_admin_access', array($this, 'admin_access'));
66 66
 
67 67
 	} // End __construct()
68 68
 
@@ -74,21 +74,21 @@  discard block
 block discarded – undo
74 74
 	public function admin_menu() {
75 75
 		global $menu;
76 76
 		$menu_cap = '';
77
-		if( current_user_can( 'manage_sensei' ) ) {
77
+		if (current_user_can('manage_sensei')) {
78 78
 			$menu_cap = 'manage_sensei';
79 79
 		} else {
80
-			if( current_user_can( 'manage_sensei_grades' ) ) {
80
+			if (current_user_can('manage_sensei_grades')) {
81 81
 				$menu_cap = 'manage_sensei_grades';
82 82
 			}
83 83
 		}
84 84
 
85
-		if( $menu_cap ) {
86
-			$menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' );
87
-            add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
85
+		if ($menu_cap) {
86
+			$menu[] = array('', 'read', 'separator-sensei', '', 'wp-menu-separator sensei');
87
+            add_menu_page('Sensei', 'Sensei', $menu_cap, 'sensei', array(Sensei()->analysis, 'analysis_page'), '', '50');
88 88
 		}
89 89
 
90
-		add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) );
91
-		add_submenu_page( 'edit.php?post_type=lesson', __( 'Order Lessons', 'woothemes-sensei' ), __( 'Order Lessons', 'woothemes-sensei' ), 'edit_lessons', 'lesson-order', array( $this, 'lesson_order_screen' ) );
90
+		add_submenu_page('edit.php?post_type=course', __('Order Courses', 'woothemes-sensei'), __('Order Courses', 'woothemes-sensei'), 'manage_sensei', 'course-order', array($this, 'course_order_screen'));
91
+		add_submenu_page('edit.php?post_type=lesson', __('Order Lessons', 'woothemes-sensei'), __('Order Lessons', 'woothemes-sensei'), 'edit_lessons', 'lesson-order', array($this, 'lesson_order_screen'));
92 92
 	}
93 93
 
94 94
 	/**
@@ -97,22 +97,22 @@  discard block
 block discarded – undo
97 97
 	 * @param  array $menu_order Existing menu order
98 98
 	 * @return array 			 Modified menu order for Sensei
99 99
 	 */
100
-	public function admin_menu_order( $menu_order ) {
100
+	public function admin_menu_order($menu_order) {
101 101
 
102 102
 		// Initialize our custom order array
103 103
 		$sensei_menu_order = array();
104 104
 
105 105
 		// Get the index of our custom separator
106
-		$sensei_separator = array_search( 'separator-sensei', $menu_order );
106
+		$sensei_separator = array_search('separator-sensei', $menu_order);
107 107
 
108 108
 		// Loop through menu order and do some rearranging
109
-		foreach ( $menu_order as $index => $item ) :
109
+		foreach ($menu_order as $index => $item) :
110 110
 
111
-			if ( ( ( 'sensei' ) == $item ) ) :
111
+			if ((('sensei') == $item)) :
112 112
 				$sensei_menu_order[] = 'separator-sensei';
113 113
 				$sensei_menu_order[] = $item;
114
-				unset( $menu_order[$sensei_separator] );
115
-			elseif ( !in_array( $item, array( 'separator-sensei' ) ) ) :
114
+				unset($menu_order[$sensei_separator]);
115
+			elseif ( ! in_array($item, array('separator-sensei'))) :
116 116
 				$sensei_menu_order[] = $item;
117 117
 			endif;
118 118
 
@@ -132,24 +132,24 @@  discard block
 block discarded – undo
132 132
 
133 133
 		$screen = get_current_screen();
134 134
 
135
-		if ( $screen->base == 'post' && $post_type == 'course' ) {
135
+		if ($screen->base == 'post' && $post_type == 'course') {
136 136
 
137
-			$parent_file  = 'edit.php?post_type=course';
137
+			$parent_file = 'edit.php?post_type=course';
138 138
 
139
-		} elseif ( $screen->base == 'edit-tags' && $taxonomy == 'course-category' ) {
139
+		} elseif ($screen->base == 'edit-tags' && $taxonomy == 'course-category') {
140 140
 
141 141
 			$submenu_file = 'edit-tags.php?taxonomy=course-category&amp;post_type=course';
142 142
 			$parent_file  = 'edit.php?post_type=course';
143 143
 
144
-        } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
144
+        } elseif ($screen->base == 'edit-tags' && $taxonomy == 'module') {
145 145
 
146 146
             $submenu_file = 'edit-tags.php?taxonomy=module';
147 147
             $parent_file  = 'edit.php?post_type=course';
148 148
 
149
-		} elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) {
149
+		} elseif (in_array($screen->id, array('sensei_message', 'edit-sensei_message'))) {
150 150
 
151 151
             $submenu_file = 'edit.php?post_type=sensei_message';
152
-			$parent_file  = 'sensei';
152
+			$parent_file = 'sensei';
153 153
 
154 154
 		}
155 155
 	}
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 	 * @return void
161 161
 	 */
162 162
 	public function page_redirect() {
163
-		if( isset( $_GET['page'] ) && $_GET['page'] == 'sensei' ) {
164
-			wp_safe_redirect( 'admin.php?page=sensei_analysis' );
163
+		if (isset($_GET['page']) && $_GET['page'] == 'sensei') {
164
+			wp_safe_redirect('admin.php?page=sensei_analysis');
165 165
 			exit;
166 166
 		}
167 167
 	}
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	function install_pages_output() {
178 178
 
179
-        if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
179
+        if (isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
180 180
 
181 181
             ?>
182 182
             <div id="message" class="updated sensei-message sensei-connect">
183
-                <p><?php _e( '<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p>
183
+                <p><?php _e('<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei'); ?></p>
184 184
                 <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a>
185 185
                 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
186 186
             </div>
@@ -202,18 +202,18 @@  discard block
 block discarded – undo
202 202
 	 * @param int $post_parent (default: 0)
203 203
 	 * @return void
204 204
 	 */
205
-	function create_page( $slug, $option, $page_title = '', $page_content = '', $post_parent = 0 ) {
205
+	function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0) {
206 206
 		global $wpdb;
207 207
 
208
-		$option_value = get_option( $option );
208
+		$option_value = get_option($option);
209 209
 
210
-		if ( $option_value > 0 && get_post( $option_value ) )
210
+		if ($option_value > 0 && get_post($option_value))
211 211
 			return;
212 212
 
213
-		$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) );
214
-		if ( $page_found ) :
215
-			if ( ! $option_value )
216
-				update_option( $option, $page_found );
213
+		$page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->posts." WHERE post_name = %s LIMIT 1;", $slug));
214
+		if ($page_found) :
215
+			if ( ! $option_value)
216
+				update_option($option, $page_found);
217 217
 			return;
218 218
 		endif;
219 219
 
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 	        'post_parent' 		=> $post_parent,
228 228
 	        'comment_status' 	=> 'closed'
229 229
 	    );
230
-	    $page_id = wp_insert_post( $page_data );
230
+	    $page_id = wp_insert_post($page_data);
231 231
 
232
-	    update_option( $option, $page_id );
232
+	    update_option($option, $page_id);
233 233
 	} // End create_page()
234 234
 
235 235
 
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
 	function create_pages() {
243 243
 
244 244
 		// Courses page
245
-	    $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' );
245
+	    $this->create_page(esc_sql(_x('courses-overview', 'page_slug', 'woothemes-sensei')), 'woothemes-sensei_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]');
246 246
 
247 247
 		// User Dashboard page
248
-	    $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), 'woothemes-sensei_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' );
248
+	    $this->create_page(esc_sql(_x('my-courses', 'page_slug', 'woothemes-sensei')), 'woothemes-sensei_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]');
249 249
 
250 250
 	} // End create_pages()
251 251
 
@@ -255,25 +255,25 @@  discard block
 block discarded – undo
255 255
 	 * @since 1.0.0
256 256
 	 * @return void
257 257
 	 */
258
-	public function admin_styles_global ( $hook ) {
258
+	public function admin_styles_global($hook) {
259 259
 		global $post_type;
260 260
 
261
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) );
262
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
263
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order' ) );
261
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question'));
262
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
263
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order'));
264 264
 
265 265
 		// Global Styles for icons and menu items
266
-		wp_register_style( 'woothemes-sensei-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' );
267
-		wp_enqueue_style( 'woothemes-sensei-global' );
266
+		wp_register_style('woothemes-sensei-global', Sensei()->plugin_url.'assets/css/global.css', '', Sensei()->version, 'screen');
267
+		wp_enqueue_style('woothemes-sensei-global');
268 268
 
269 269
         // Select 2 styles
270
-        wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
270
+        wp_enqueue_style('select2', Sensei()->plugin_url.'assets/css/select2/select2.css', '', Sensei()->version, 'screen');
271 271
 
272 272
 		// Test for Write Panel Pages
273
-		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 ) ) ) {
273
+		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))) {
274 274
 
275
-			wp_register_style( 'woothemes-sensei-admin-custom', Sensei()->plugin_url . 'assets/css/admin-custom.css', '', Sensei()->version, 'screen' );
276
-			wp_enqueue_style( 'woothemes-sensei-admin-custom' );
275
+			wp_register_style('woothemes-sensei-admin-custom', Sensei()->plugin_url.'assets/css/admin-custom.css', '', Sensei()->version, 'screen');
276
+			wp_enqueue_style('woothemes-sensei-admin-custom');
277 277
 
278 278
 		}
279 279
 
@@ -288,20 +288,20 @@  discard block
 block discarded – undo
288 288
      * @since 1.8.2
289 289
      * @access public
290 290
      */
291
-    public function register_scripts( $hook ){
291
+    public function register_scripts($hook) {
292 292
 
293 293
         $screen = get_current_screen();
294 294
 
295 295
         // Allow developers to load non-minified versions of scripts
296
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
296
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
297 297
 
298 298
         // Select2 script used to enhance all select boxes
299
-        wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
299
+        wp_register_script('select2', Sensei()->plugin_url.'/assets/js/select2/select2'.$suffix.'.js', array('jquery'), Sensei()->version);
300 300
 
301 301
         // load edit module scripts
302
-        if( 'edit-module' ==  $screen->id ){
302
+        if ('edit-module' == $screen->id) {
303 303
 
304
-            wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
304
+            wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery.min.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
305 305
 
306 306
         }
307 307
 
@@ -319,19 +319,19 @@  discard block
 block discarded – undo
319 319
 	    <div id="message" class="updated sensei-message sensei-connect">
320 320
 
321 321
             <p>
322
-                <?php _e( '<strong>Welcome to Sensei</strong> &#8211; You\'re almost ready to create some courses!', 'woothemes-sensei' ); ?>
322
+                <?php _e('<strong>Welcome to Sensei</strong> &#8211; You\'re almost ready to create some courses!', 'woothemes-sensei'); ?>
323 323
             </p>
324 324
 
325 325
             <p class="submit">
326 326
 
327
-                <a href="<?php echo esc_url( add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings') ) ); ?>"
327
+                <a href="<?php echo esc_url(add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>"
328 328
                    class="button-primary">
329 329
 
330
-                    <?php _e( 'Install Sensei Pages', 'woothemes-sensei' ); ?>
330
+                    <?php _e('Install Sensei Pages', 'woothemes-sensei'); ?>
331 331
 
332 332
                 </a>
333 333
 
334
-                <a class="skip button" href="<?php echo esc_url( add_query_arg( 'skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings' ) ) ); ?>">
334
+                <a class="skip button" href="<?php echo esc_url(add_query_arg('skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>">
335 335
 
336 336
                     <?php _e('Skip setup', 'woothemes-sensei'); ?>
337 337
 
@@ -354,11 +354,11 @@  discard block
 block discarded – undo
354 354
 	    <div id="message" class="updated sensei-message sensei-connect">
355 355
 
356 356
 	    	<p>
357
-                <?php _e( '<strong>Sensei has been installed</strong> &#8211; You\'re ready to start creating courses!', 'woothemes-sensei' ); ?>
357
+                <?php _e('<strong>Sensei has been installed</strong> &#8211; You\'re ready to start creating courses!', 'woothemes-sensei'); ?>
358 358
             </p>
359 359
 
360 360
 			<p class="submit">
361
-                <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woothemes-sensei' ); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/">
361
+                <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e('Settings', 'woothemes-sensei'); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/">
362 362
                     <?php _e('Documentation', 'woothemes-sensei'); ?>
363 363
                 </a>
364 364
             </p>
@@ -391,11 +391,11 @@  discard block
 block discarded – undo
391 391
 	public function language_pack_install_notice() {
392 392
 		?>
393 393
 		<div id="message" class="updated sensei-message sensei-connect">
394
-				<p><?php _e( '<strong>Sensei in your language</strong> &#8211; There is a translation available for your language.', 'woothemes-sensei' ); ?><p>
394
+				<p><?php _e('<strong>Sensei in your language</strong> &#8211; There is a translation available for your language.', 'woothemes-sensei'); ?><p>
395 395
 
396 396
 				<p class="submit">
397
-					<a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_install_uri() ); ?>" class="button-primary"><?php _e( 'Install', 'woothemes-sensei' ); ?></a>
398
-					<a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_dismiss_uri() ) ?>" class="docs button"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?></a>
397
+					<a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_install_uri()); ?>" class="button-primary"><?php _e('Install', 'woothemes-sensei'); ?></a>
398
+					<a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_dismiss_uri()) ?>" class="docs button"><?php _e('Hide this notice', 'woothemes-sensei'); ?></a>
399 399
 				</p>
400 400
 		</div>
401 401
 		<?php
@@ -411,20 +411,20 @@  discard block
 block discarded – undo
411 411
 	function admin_notices_styles() {
412 412
 
413 413
 		// Installed notices
414
-	    if ( 1 == get_option( 'sensei_installed' ) ) {
414
+	    if (1 == get_option('sensei_installed')) {
415 415
 
416
-	    	wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
416
+	    	wp_enqueue_style('sensei-activation', plugins_url('/assets/css/activation.css', dirname(__FILE__)), '', Sensei()->version);
417 417
 
418
-	    	if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
419
-	    		add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
420
-	    	} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
421
-	    		add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
418
+	    	if (get_option('skip_install_sensei_pages') != 1 && Sensei()->get_page_id('course') < 1 && ! isset($_GET['install_sensei_pages']) && ! isset($_GET['skip_install_sensei_pages'])) {
419
+	    		add_action('admin_notices', array($this, 'admin_install_notice'));
420
+	    	} elseif ( ! isset($_GET['page']) || $_GET['page'] != 'woothemes-sensei-settings') {
421
+	    		add_action('admin_notices', array($this, 'admin_installed_notice'));
422 422
 	    	} // End If Statement
423 423
 
424 424
 	    } // End If Statement
425 425
 
426
-	    if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
427
-	    	add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
426
+	    if (Sensei_Language_Pack_Manager::has_language_pack_available()) {
427
+	    	add_action('admin_notices', array($this, 'language_pack_install_notice'));
428 428
 	    }
429 429
 
430 430
 	} // End admin_notices_styles()
@@ -435,17 +435,17 @@  discard block
 block discarded – undo
435 435
 	 * @param  object $post    Current post
436 436
 	 * @return array           Modified actions
437 437
 	 */
438
-	public function duplicate_action_link( $actions, $post ) {
439
-		switch( $post->post_type ) {
438
+	public function duplicate_action_link($actions, $post) {
439
+		switch ($post->post_type) {
440 440
 			case 'lesson':
441
-				$confirm = __( 'This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei' );
442
-				$actions['duplicate'] = "<a onclick='return confirm(\"" . $confirm . "\");' href='" . $this->get_duplicate_link( $post->ID ) . "' title='" . esc_attr(__( 'Duplicate this lesson', 'woothemes-sensei' ) ) . "'>" .  __('Duplicate', 'woothemes-sensei' ) . "</a>";
441
+				$confirm = __('This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei');
442
+				$actions['duplicate'] = "<a onclick='return confirm(\"".$confirm."\");' href='".$this->get_duplicate_link($post->ID)."' title='".esc_attr(__('Duplicate this lesson', 'woothemes-sensei'))."'>".__('Duplicate', 'woothemes-sensei')."</a>";
443 443
 			break;
444 444
 
445 445
 			case 'course':
446
-				$confirm = __( 'This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei' );
447
-				$actions['duplicate'] = '<a href="' . $this->get_duplicate_link( $post->ID ) . '" title="' . esc_attr(__( 'Duplicate this course', 'woothemes-sensei' ) ) . '">' .  __('Duplicate', 'woothemes-sensei' ) . '</a>';
448
-				$actions['duplicate_with_lessons'] = '<a onclick="return confirm(\'' . $confirm . '\');" href="' . $this->get_duplicate_link( $post->ID, true ) . '" title="' . esc_attr(__( 'Duplicate this course with its lessons', 'woothemes-sensei' ) ) . '">' .  __('Duplicate (with lessons)', 'woothemes-sensei' ) . '</a>';
446
+				$confirm = __('This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei');
447
+				$actions['duplicate'] = '<a href="'.$this->get_duplicate_link($post->ID).'" title="'.esc_attr(__('Duplicate this course', 'woothemes-sensei')).'">'.__('Duplicate', 'woothemes-sensei').'</a>';
448
+				$actions['duplicate_with_lessons'] = '<a onclick="return confirm(\''.$confirm.'\');" href="'.$this->get_duplicate_link($post->ID, true).'" title="'.esc_attr(__('Duplicate this course with its lessons', 'woothemes-sensei')).'">'.__('Duplicate (with lessons)', 'woothemes-sensei').'</a>';
449 449
 			break;
450 450
 		}
451 451
 
@@ -458,17 +458,17 @@  discard block
 block discarded – undo
458 458
 	 * @param  boolean $with_lessons Include lessons or not
459 459
 	 * @return string                Duplication link
460 460
 	 */
461
-	private function get_duplicate_link( $post_id = 0, $with_lessons = false ) {
461
+	private function get_duplicate_link($post_id = 0, $with_lessons = false) {
462 462
 
463
-		$post = get_post( $post_id );
463
+		$post = get_post($post_id);
464 464
 
465
-		$action = 'duplicate_' . $post->post_type;
465
+		$action = 'duplicate_'.$post->post_type;
466 466
 
467
-		if( 'course' == $post->post_type && $with_lessons ) {
467
+		if ('course' == $post->post_type && $with_lessons) {
468 468
 			$action .= '_with_lessons';
469 469
 		}
470 470
 
471
-		return apply_filters( $action . '_link', admin_url( 'admin.php?action=' . $action . '&post=' . $post_id ), $post_id );
471
+		return apply_filters($action.'_link', admin_url('admin.php?action='.$action.'&post='.$post_id), $post_id);
472 472
 	}
473 473
 
474 474
 	/**
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
 	 * @return void
477 477
 	 */
478 478
 	public function duplicate_lesson_action() {
479
-		$this->duplicate_content( 'lesson' );
479
+		$this->duplicate_content('lesson');
480 480
 	}
481 481
 
482 482
 	/**
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 * @return void
485 485
 	 */
486 486
 	public function duplicate_course_action() {
487
-		$this->duplicate_content( 'course' );
487
+		$this->duplicate_content('course');
488 488
 	}
489 489
 
490 490
 	/**
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @return void
493 493
 	 */
494 494
 	public function duplicate_course_with_lessons_action() {
495
-		$this->duplicate_content( 'course', true );
495
+		$this->duplicate_content('course', true);
496 496
 	}
497 497
 
498 498
 	/**
@@ -501,34 +501,34 @@  discard block
 block discarded – undo
501 501
 	 * @param  boolean $with_lessons Include lessons or not
502 502
 	 * @return void
503 503
 	 */
504
-	private function duplicate_content( $post_type = 'lesson', $with_lessons = false ) {
505
-		if ( ! isset( $_GET['post'] ) ) {
506
-			wp_die( sprintf( __( 'Please supply a %1$s ID.', 'woothemes-sensei' ) ), $post_type );
504
+	private function duplicate_content($post_type = 'lesson', $with_lessons = false) {
505
+		if ( ! isset($_GET['post'])) {
506
+			wp_die(sprintf(__('Please supply a %1$s ID.', 'woothemes-sensei')), $post_type);
507 507
 		}
508 508
 
509 509
 		$post_id = $_GET['post'];
510
-		$post = get_post( $post_id );
510
+		$post = get_post($post_id);
511 511
 
512
-		if( ! is_wp_error( $post ) ) {
512
+		if ( ! is_wp_error($post)) {
513 513
 
514
-			$new_post = $this->duplicate_post( $post );
514
+			$new_post = $this->duplicate_post($post);
515 515
 
516
-			if( $new_post && ! is_wp_error( $new_post ) ) {
516
+			if ($new_post && ! is_wp_error($new_post)) {
517 517
 
518
-				if( 'lesson' == $new_post->post_type ) {
519
-					$this->duplicate_lesson_quizzes( $post_id, $new_post->ID );
518
+				if ('lesson' == $new_post->post_type) {
519
+					$this->duplicate_lesson_quizzes($post_id, $new_post->ID);
520 520
 				}
521 521
 
522
-				if( 'course' == $new_post->post_type && $with_lessons ) {
523
-					$this->duplicate_course_lessons( $post_id, $new_post->ID );
522
+				if ('course' == $new_post->post_type && $with_lessons) {
523
+					$this->duplicate_course_lessons($post_id, $new_post->ID);
524 524
 				}
525 525
 
526
-				$redirect_url = admin_url( 'post.php?post=' . $new_post->ID . '&action=edit' );
526
+				$redirect_url = admin_url('post.php?post='.$new_post->ID.'&action=edit');
527 527
 			} else {
528
-				$redirect_url = admin_url( 'edit.php?post_type=' . $post->post_type . '&message=duplicate_failed' );
528
+				$redirect_url = admin_url('edit.php?post_type='.$post->post_type.'&message=duplicate_failed');
529 529
 			}
530 530
 
531
-			wp_safe_redirect( esc_url_raw( $redirect_url ) );
531
+			wp_safe_redirect(esc_url_raw($redirect_url));
532 532
 			exit;
533 533
 		}
534 534
 	}
@@ -539,19 +539,19 @@  discard block
 block discarded – undo
539 539
 	 * @param  integer $new_lesson_id ID of duplicate lesson
540 540
 	 * @return void
541 541
 	 */
542
-	private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) {
542
+	private function duplicate_lesson_quizzes($old_lesson_id, $new_lesson_id) {
543 543
 
544
-        $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
545
-        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
544
+        $old_quiz_id = Sensei()->lesson->lesson_quizzes($old_lesson_id);
545
+        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions($old_quiz_id);
546 546
 
547 547
         // duplicate the generic wp post information
548
-		$new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' );
548
+		$new_quiz = $this->duplicate_post(get_post($old_quiz_id), '');
549 549
 
550 550
 		//update the new lesson data
551
-        add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
551
+        add_post_meta($new_lesson_id, '_lesson_quiz', $new_quiz->ID);
552 552
 
553 553
 		//update the new quiz data
554
-        add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
554
+        add_post_meta($new_quiz->ID, '_quiz_lesson', $new_lesson_id);
555 555
         wp_update_post(
556 556
             array(
557 557
                 'ID' => $new_quiz->ID,
@@ -559,15 +559,15 @@  discard block
 block discarded – undo
559 559
             )
560 560
         );
561 561
 
562
-		foreach( $old_quiz_questions as $question ) {
562
+		foreach ($old_quiz_questions as $question) {
563 563
 
564 564
 			// copy the question order over to the new quiz
565
-			$old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true );
566
-            $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
567
-            add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
565
+			$old_question_order = get_post_meta($question->ID, '_quiz_question_order'.$old_quiz_id, true);
566
+            $new_question_order = str_ireplace($old_quiz_id, $new_quiz->ID, $old_question_order);
567
+            add_post_meta($question->ID, '_quiz_question_order'.$new_quiz->ID, $new_question_order);
568 568
 
569 569
 			// Add question to quiz
570
-			add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false );
570
+			add_post_meta($question->ID, '_quiz_id', $new_quiz->ID, false);
571 571
 
572 572
 		}
573 573
 	}
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 	 * @param  integer $new_course_id ID of duplicated course
579 579
 	 * @return void
580 580
 	 */
581
-	private function duplicate_course_lessons( $old_course_id, $new_course_id ) {
581
+	private function duplicate_course_lessons($old_course_id, $new_course_id) {
582 582
 		$lesson_args = array(
583 583
 			'post_type' => 'lesson',
584 584
 			'posts_per_page' => -1,
@@ -586,13 +586,13 @@  discard block
 block discarded – undo
586 586
 			'meta_value' => $old_course_id,
587 587
 			'suppress_filters' 	=> 0
588 588
 		);
589
-		$lessons = get_posts( $lesson_args );
589
+		$lessons = get_posts($lesson_args);
590 590
 
591
-		foreach( $lessons as $lesson ) {
592
-			$new_lesson = $this->duplicate_post( $lesson, '', true );
593
-			add_post_meta( $new_lesson->ID, '_lesson_course', $new_course_id );
591
+		foreach ($lessons as $lesson) {
592
+			$new_lesson = $this->duplicate_post($lesson, '', true);
593
+			add_post_meta($new_lesson->ID, '_lesson_course', $new_course_id);
594 594
 
595
-			$this->duplicate_lesson_quizzes( $lesson->ID, $new_lesson->ID );
595
+			$this->duplicate_lesson_quizzes($lesson->ID, $new_lesson->ID);
596 596
 		}
597 597
 	}
598 598
 
@@ -603,24 +603,24 @@  discard block
 block discarded – undo
603 603
 	 * @param  boolean $ignore_course Ignore lesson course when dulicating
604 604
 	 * @return object                 Duplicate post object
605 605
 	 */
606
-	private function duplicate_post( $post, $suffix = ' (Duplicate)', $ignore_course = false ) {
606
+	private function duplicate_post($post, $suffix = ' (Duplicate)', $ignore_course = false) {
607 607
 
608 608
 		$new_post = array();
609 609
 
610
-		foreach( $post as $k => $v ) {
611
-			if( ! in_array( $k, array( 'ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count' ) ) ) {
612
-				$new_post[ $k ] = $v;
610
+		foreach ($post as $k => $v) {
611
+			if ( ! in_array($k, array('ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count'))) {
612
+				$new_post[$k] = $v;
613 613
 			}
614 614
 		}
615 615
 
616
-		$new_post['post_title'] .= __( $suffix, 'woothemes-sensei' );
616
+		$new_post['post_title'] .= __($suffix, 'woothemes-sensei');
617 617
 
618
-		$new_post['post_date'] = current_time( 'mysql' );
619
-		$new_post['post_date_gmt'] = get_gmt_from_date( $new_post['post_date'] );
618
+		$new_post['post_date'] = current_time('mysql');
619
+		$new_post['post_date_gmt'] = get_gmt_from_date($new_post['post_date']);
620 620
 		$new_post['post_modified'] = $new_post['post_date'];
621 621
 		$new_post['post_modified_gmt'] = $new_post['post_date_gmt'];
622 622
 
623
-		switch( $post->post_type ) {
623
+		switch ($post->post_type) {
624 624
 			case 'course': $new_post['post_status'] = 'draft'; break;
625 625
 			case 'lesson': $new_post['post_status'] = 'draft'; break;
626 626
 			case 'quiz': $new_post['post_status'] = 'publish'; break;
@@ -628,45 +628,45 @@  discard block
 block discarded – undo
628 628
 		}
629 629
 
630 630
 		// As per wp_update_post() we need to escape the data from the db.
631
-		$new_post = wp_slash( $new_post );
631
+		$new_post = wp_slash($new_post);
632 632
 
633
-		$new_post_id = wp_insert_post( $new_post );
633
+		$new_post_id = wp_insert_post($new_post);
634 634
 
635
-		if( ! is_wp_error( $new_post_id ) ) {
635
+		if ( ! is_wp_error($new_post_id)) {
636 636
 
637
-			$post_meta = get_post_custom( $post->ID );
638
-			if( $post_meta && count( $post_meta ) > 0 ) {
637
+			$post_meta = get_post_custom($post->ID);
638
+			if ($post_meta && count($post_meta) > 0) {
639 639
 
640
-				$ignore_meta = array( '_quiz_lesson', '_quiz_id', '_lesson_quiz' );
640
+				$ignore_meta = array('_quiz_lesson', '_quiz_id', '_lesson_quiz');
641 641
 
642
-				if( $ignore_course ) {
642
+				if ($ignore_course) {
643 643
 					$ignore_meta[] = '_lesson_course';
644 644
 				}
645 645
 
646
-				foreach( $post_meta as $key => $meta ) {
647
-					foreach( $meta as $value ) {
648
-						$value = maybe_unserialize( $value );
649
-						if( ! in_array( $key, $ignore_meta ) ) {
650
-							add_post_meta( $new_post_id, $key, $value );
646
+				foreach ($post_meta as $key => $meta) {
647
+					foreach ($meta as $value) {
648
+						$value = maybe_unserialize($value);
649
+						if ( ! in_array($key, $ignore_meta)) {
650
+							add_post_meta($new_post_id, $key, $value);
651 651
 						}
652 652
 					}
653 653
 				}
654 654
 			}
655 655
 
656
-			add_post_meta( $new_post_id, '_duplicate', $post->ID );
656
+			add_post_meta($new_post_id, '_duplicate', $post->ID);
657 657
 
658
-			$taxonomies = get_object_taxonomies( $post->post_type, 'objects' );
658
+			$taxonomies = get_object_taxonomies($post->post_type, 'objects');
659 659
 
660
-			foreach ( $taxonomies as $slug => $tax ) {
661
-				$terms = get_the_terms( $post->ID, $slug );
662
-				if( isset( $terms ) && is_array( $terms ) && 0 < count( $terms ) ) {
663
-					foreach( $terms as $term ) {
664
-						wp_set_object_terms( $new_post_id, $term->term_id, $slug, true );
660
+			foreach ($taxonomies as $slug => $tax) {
661
+				$terms = get_the_terms($post->ID, $slug);
662
+				if (isset($terms) && is_array($terms) && 0 < count($terms)) {
663
+					foreach ($terms as $term) {
664
+						wp_set_object_terms($new_post_id, $term->term_id, $slug, true);
665 665
 					}
666 666
 				}
667 667
 			}
668 668
 
669
-			$new_post = get_post( $new_post_id );
669
+			$new_post = get_post($new_post_id);
670 670
 
671 671
 			return $new_post;
672 672
 		}
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 	public function lesson_filter_options() {
682 682
 		global $typenow;
683 683
 
684
-		if( is_admin() && 'lesson' == $typenow ) {
684
+		if (is_admin() && 'lesson' == $typenow) {
685 685
 
686 686
 			$args = array(
687 687
 				'post_type' => 'course',
@@ -691,16 +691,16 @@  discard block
 block discarded – undo
691 691
 				'orderby' => 'menu_order date',
692 692
 				'order' => 'ASC',
693 693
 			);
694
-			$courses = get_posts( $args );
694
+			$courses = get_posts($args);
695 695
 
696
-			$selected = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : '';
696
+			$selected = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : '';
697 697
 			$course_options = '';
698
-			foreach( $courses as $course ) {
699
-				$course_options .= '<option value="' . esc_attr( $course->ID ) . '" ' . selected( $selected, $course->ID, false ) . '>' . get_the_title( $course->ID ) . '</option>';
698
+			foreach ($courses as $course) {
699
+				$course_options .= '<option value="'.esc_attr($course->ID).'" '.selected($selected, $course->ID, false).'>'.get_the_title($course->ID).'</option>';
700 700
 			}
701 701
 
702 702
 			$output = '<select name="lesson_course" id="dropdown_lesson_course">';
703
-			$output .= '<option value="">'.__( 'Show all courses', 'woothemes-sensei' ).'</option>';
703
+			$output .= '<option value="">'.__('Show all courses', 'woothemes-sensei').'</option>';
704 704
 			$output .= $course_options;
705 705
 			$output .= '</select>';
706 706
 
@@ -713,13 +713,13 @@  discard block
 block discarded – undo
713 713
 	 * @param  array $request Current request
714 714
 	 * @return array          Modified request
715 715
 	 */
716
-	public function lesson_filter_actions( $request ) {
716
+	public function lesson_filter_actions($request) {
717 717
 		global $typenow;
718 718
 
719
-		if( is_admin() && 'lesson' == $typenow ) {
720
-			$lesson_course = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : '';
719
+		if (is_admin() && 'lesson' == $typenow) {
720
+			$lesson_course = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : '';
721 721
 
722
-			if( $lesson_course ) {
722
+			if ($lesson_course) {
723 723
 				$request['meta_key'] = '_lesson_course';
724 724
 				$request['meta_value'] = $lesson_course;
725 725
 				$request['meta_compare'] = '=';
@@ -734,27 +734,27 @@  discard block
 block discarded – undo
734 734
 	 * @param  array $items Existing items
735 735
 	 * @return array        Updated items
736 736
 	 */
737
-	public function glance_items( $items = array() ) {
737
+	public function glance_items($items = array()) {
738 738
 
739
-		$types = array( 'course', 'lesson', 'question' );
739
+		$types = array('course', 'lesson', 'question');
740 740
 
741
-		foreach( $types as $type ) {
742
-			if( ! post_type_exists( $type ) ) continue;
741
+		foreach ($types as $type) {
742
+			if ( ! post_type_exists($type)) continue;
743 743
 
744
-			$num_posts = wp_count_posts( $type );
744
+			$num_posts = wp_count_posts($type);
745 745
 
746
-			if( $num_posts ) {
746
+			if ($num_posts) {
747 747
 
748
-				$published = intval( $num_posts->publish );
749
-				$post_type = get_post_type_object( $type );
748
+				$published = intval($num_posts->publish);
749
+				$post_type = get_post_type_object($type);
750 750
 
751
-				$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'woothemes-sensei' );
752
-				$text = sprintf( $text, number_format_i18n( $published ) );
751
+				$text = _n('%s '.$post_type->labels->singular_name, '%s '.$post_type->labels->name, $published, 'woothemes-sensei');
752
+				$text = sprintf($text, number_format_i18n($published));
753 753
 
754
-				if ( current_user_can( $post_type->cap->edit_posts ) ) {
755
-					$items[] = sprintf( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text ) . "\n";
754
+				if (current_user_can($post_type->cap->edit_posts)) {
755
+					$items[] = sprintf('<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text)."\n";
756 756
 				} else {
757
-					$items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n";
757
+					$items[] = sprintf('<span class="%1$s-count">%2$s</span>', $type, $text)."\n";
758 758
 				}
759 759
 			}
760 760
 		}
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 	 * @param  object  $post    Post object
769 769
 	 * @return void
770 770
 	 */
771
-	public function delete_content( $post_id, $post ) {
771
+	public function delete_content($post_id, $post) {
772 772
 
773 773
 		$type = $post->post_type;
774 774
 
775
-		if( in_array( $type, array( 'lesson', 'course' ) ) ) {
775
+		if (in_array($type, array('lesson', 'course'))) {
776 776
 
777
-			$meta_key = '_' . $type . '_prerequisite';
777
+			$meta_key = '_'.$type.'_prerequisite';
778 778
 
779 779
 			$args = array(
780 780
 				'post_type' => $type,
@@ -784,10 +784,10 @@  discard block
 block discarded – undo
784 784
 				'meta_value' => $post_id
785 785
 			);
786 786
 
787
-			$posts = get_posts( $args );
787
+			$posts = get_posts($args);
788 788
 
789
-			foreach( $posts as $post ) {
790
-				delete_post_meta( $post->ID, $meta_key );
789
+			foreach ($posts as $post) {
790
+				delete_post_meta($post->ID, $meta_key);
791 791
 			}
792 792
 		}
793 793
 	}
@@ -797,181 +797,181 @@  discard block
 block discarded – undo
797 797
 	 * @param  integer $user_id User ID
798 798
 	 * @return void
799 799
 	 */
800
-	public function delete_user_activity( $user_id = 0 ) {
801
-		if( $user_id ) {
802
-			Sensei_Utils::delete_all_user_activity( $user_id );
800
+	public function delete_user_activity($user_id = 0) {
801
+		if ($user_id) {
802
+			Sensei_Utils::delete_all_user_activity($user_id);
803 803
 		}
804 804
 	}
805 805
 
806
-	public function render_settings( $settings = array(), $post_id = 0, $group_id = '' ) {
806
+	public function render_settings($settings = array(), $post_id = 0, $group_id = '') {
807 807
 
808 808
 		$html = '';
809 809
 
810
-		if( 0 == count( $settings ) ) return $html;
810
+		if (0 == count($settings)) return $html;
811 811
 
812
-		$html .= '<div class="sensei-options-panel">' . "\n";
812
+		$html .= '<div class="sensei-options-panel">'."\n";
813 813
 
814
-			$html .= '<div class="options_group" id="' . esc_attr( $group_id ) . '">' . "\n";
814
+			$html .= '<div class="options_group" id="'.esc_attr($group_id).'">'."\n";
815 815
 
816
-				foreach( $settings as $field ) {
816
+				foreach ($settings as $field) {
817 817
 
818 818
 					$data = '';
819 819
 
820
-					if( $post_id ) {
821
-						$data = get_post_meta( $post_id, '_' . $field['id'], true );
822
-						if( ! $data && isset( $field['default'] ) ) {
820
+					if ($post_id) {
821
+						$data = get_post_meta($post_id, '_'.$field['id'], true);
822
+						if ( ! $data && isset($field['default'])) {
823 823
 							$data = $field['default'];
824 824
 						}
825 825
 					} else {
826
-						$option = get_option( $field['id'] );
827
-						if( isset( $field['default'] ) ) {
826
+						$option = get_option($field['id']);
827
+						if (isset($field['default'])) {
828 828
 							$data = $field['default'];
829
-							if( $option ) {
829
+							if ($option) {
830 830
 								$data = $option;
831 831
 							}
832 832
 						}
833 833
 					}
834 834
 
835 835
 					$disabled = '';
836
-					if( isset( $field['disabled'] ) && $field['disabled'] ) {
837
-						$disabled = disabled( $field['disabled'], true, false );
836
+					if (isset($field['disabled']) && $field['disabled']) {
837
+						$disabled = disabled($field['disabled'], true, false);
838 838
 					}
839 839
 
840
-					if( 'hidden' != $field['type'] ) {
840
+					if ('hidden' != $field['type']) {
841 841
 
842 842
 						$class_tail = '';
843 843
 
844
-						if( isset( $field['class'] ) ) {
844
+						if (isset($field['class'])) {
845 845
 							$class_tail .= $field['class'];
846 846
 						}
847 847
 
848
-						if( isset( $field['disabled'] ) && $field['disabled'] ) {
848
+						if (isset($field['disabled']) && $field['disabled']) {
849 849
 							$class_tail .= ' disabled';
850 850
 						}
851 851
 
852
-						$html .= '<p class="form-field ' . esc_attr( $field['id'] ) . ' ' . esc_attr( $class_tail ) . '">' . "\n";
852
+						$html .= '<p class="form-field '.esc_attr($field['id']).' '.esc_attr($class_tail).'">'."\n";
853 853
 					}
854 854
 
855
-						if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) {
856
-							$html .= '<label for="' . esc_attr( $field['id'] ) . '">' . "\n";
855
+						if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) {
856
+							$html .= '<label for="'.esc_attr($field['id']).'">'."\n";
857 857
 						}
858 858
 
859
-							if( $field['label'] ) {
860
-								$html .= '<span class="label">' . esc_html( $field['label'] ) . '</span>';
859
+							if ($field['label']) {
860
+								$html .= '<span class="label">'.esc_html($field['label']).'</span>';
861 861
 							}
862 862
 
863
-							switch( $field['type'] ) {
863
+							switch ($field['type']) {
864 864
 								case 'text':
865 865
 								case 'password':
866
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $disabled . ' />' . "\n";
866
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$disabled.' />'."\n";
867 867
 								break;
868 868
 
869 869
 								case 'number':
870 870
 
871 871
 									$min = '';
872
-									if( isset( $field['min'] ) ) {
873
-										$min = 'min="' . esc_attr( $field['min'] ) . '"';
872
+									if (isset($field['min'])) {
873
+										$min = 'min="'.esc_attr($field['min']).'"';
874 874
 									}
875 875
 
876 876
 									$max = '';
877
-									if( isset( $field['max'] ) ) {
878
-										$max = 'max="' . esc_attr( $field['max'] ) . '"';
877
+									if (isset($field['max'])) {
878
+										$max = 'max="'.esc_attr($field['max']).'"';
879 879
 									}
880 880
 
881
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $min . '  ' . $max . ' class="small-text" ' . $disabled . ' />' . "\n";
881
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$min.'  '.$max.' class="small-text" '.$disabled.' />'."\n";
882 882
 								break;
883 883
 
884 884
 								case 'textarea':
885
-									$html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . $disabled . '>' . $data . '</textarea><br/>'. "\n";
885
+									$html .= '<textarea id="'.esc_attr($field['id']).'" rows="5" cols="50" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" '.$disabled.'>'.$data.'</textarea><br/>'."\n";
886 886
 								break;
887 887
 
888 888
 								case 'checkbox':
889 889
                                     //backwards compatibility
890
-                                    if( empty( $data ) || 'on' == $data ){
890
+                                    if (empty($data) || 'on' == $data) {
891 891
                                         $checked_value = 'on';
892
-                                    }elseif( 'yes' == $data  ) {
892
+                                    }elseif ('yes' == $data) {
893 893
 
894 894
                                         $checked_value = 'yes';
895 895
 
896
-                                    }elseif( 'auto' == $data  ) {
896
+                                    }elseif ('auto' == $data) {
897 897
 
898 898
                                         $checked_value = 'auto';
899 899
 
900 900
                                     } else {
901 901
                                         $checked_value = 1;
902
-                                        $data = intval( $data );
902
+                                        $data = intval($data);
903 903
                                     }
904
-									$checked = checked( $checked_value, $data, false );
905
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n";
904
+									$checked = checked($checked_value, $data, false);
905
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" '.$checked.' '.$disabled.'/>'."\n";
906 906
 								break;
907 907
 
908 908
 								case 'checkbox_multi':
909
-									foreach( $field['options'] as $k => $v ) {
909
+									foreach ($field['options'] as $k => $v) {
910 910
 										$checked = false;
911
-										if( in_array( $k, $data ) ) {
911
+										if (in_array($k, $data)) {
912 912
 											$checked = true;
913 913
 										}
914
-										$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n";
914
+										$html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="checkbox" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'[]" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n";
915 915
 									}
916 916
 								break;
917 917
 
918 918
 								case 'radio':
919
-									foreach( $field['options'] as $k => $v ) {
919
+									foreach ($field['options'] as $k => $v) {
920 920
 										$checked = false;
921
-										if( $k == $data ) {
921
+										if ($k == $data) {
922 922
 											$checked = true;
923 923
 										}
924
-										$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n";
924
+										$html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="radio" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n";
925 925
 									}
926 926
 								break;
927 927
 
928 928
 								case 'select':
929
-									$html .= '<select name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" ' . $disabled . '>' . "\n";
930
-									foreach( $field['options'] as $k => $v ) {
929
+									$html .= '<select name="'.esc_attr($field['id']).'" id="'.esc_attr($field['id']).'" '.$disabled.'>'."\n";
930
+									foreach ($field['options'] as $k => $v) {
931 931
 										$selected = false;
932
-										if( $k == $data ) {
932
+										if ($k == $data) {
933 933
 											$selected = true;
934 934
 										}
935
-										$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>' . "\n";
935
+										$html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'">'.$v.'</option>'."\n";
936 936
 									}
937
-									$html .= '</select><br/>' . "\n";
937
+									$html .= '</select><br/>'."\n";
938 938
 								break;
939 939
 
940 940
 								case 'select_multi':
941
-									$html .= '<select name="' . esc_attr( $field['id'] ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple" ' . $disabled . '>' . "\n";
942
-									foreach( $field['options'] as $k => $v ) {
941
+									$html .= '<select name="'.esc_attr($field['id']).'[]" id="'.esc_attr($field['id']).'" multiple="multiple" '.$disabled.'>'."\n";
942
+									foreach ($field['options'] as $k => $v) {
943 943
 										$selected = false;
944
-										if( in_array( $k, $data ) ) {
944
+										if (in_array($k, $data)) {
945 945
 											$selected = true;
946 946
 										}
947
-										$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '" />' . $v . '</option>' . "\n";
947
+										$html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'" />'.$v.'</option>'."\n";
948 948
 									}
949 949
 									$html .= '</select> . "\n"';
950 950
 								break;
951 951
 
952 952
 								case 'hidden':
953
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" value="' . $data . '" ' . $disabled . '/>' . "\n";
953
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" value="'.$data.'" '.$disabled.'/>'."\n";
954 954
 								break;
955 955
 
956 956
 							}
957 957
 
958
-							if( $field['description'] ) {
959
-								$html .= ' <span class="description">' . esc_html( $field['description'] ) . '</span>' . "\n";
958
+							if ($field['description']) {
959
+								$html .= ' <span class="description">'.esc_html($field['description']).'</span>'."\n";
960 960
 							}
961 961
 
962
-						if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) {
963
-							$html .= '</label>' . "\n";
962
+						if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) {
963
+							$html .= '</label>'."\n";
964 964
 						}
965 965
 
966
-					if( 'hidden' != $field['type'] ) {
967
-						$html .= '</p>' . "\n";
966
+					if ('hidden' != $field['type']) {
967
+						$html .= '</p>'."\n";
968 968
 					}
969 969
 
970 970
 				}
971 971
 
972
-			$html .= '</div>' . "\n";
972
+			$html .= '</div>'."\n";
973 973
 
974
-		$html .= '</div>' . "\n";
974
+		$html .= '</div>'."\n";
975 975
 
976 976
 		return $html;
977 977
 	}
@@ -982,61 +982,61 @@  discard block
 block discarded – undo
982 982
 	 */
983 983
 	public function course_order_screen() {
984 984
 
985
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
986
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version );
985
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
986
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version);
987 987
 
988 988
 		?><div id="course-order" class="wrap course-order">
989
-		<h2><?php _e( 'Order Courses', 'woothemes-sensei' ); ?></h2><?php
989
+		<h2><?php _e('Order Courses', 'woothemes-sensei'); ?></h2><?php
990 990
 
991 991
 		$html = '';
992 992
 
993
-		if( isset( $_POST['course-order'] ) && 0 < strlen( $_POST['course-order'] ) ) {
994
-			$ordered = $this->save_course_order( esc_attr( $_POST['course-order'] ) );
993
+		if (isset($_POST['course-order']) && 0 < strlen($_POST['course-order'])) {
994
+			$ordered = $this->save_course_order(esc_attr($_POST['course-order']));
995 995
 
996
-			if( $ordered ) {
997
-				$html .= '<div class="updated fade">' . "\n";
998
-				$html .= '<p>' . __( 'The course order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n";
999
-				$html .= '</div>' . "\n";
996
+			if ($ordered) {
997
+				$html .= '<div class="updated fade">'."\n";
998
+				$html .= '<p>'.__('The course order has been saved.', 'woothemes-sensei').'</p>'."\n";
999
+				$html .= '</div>'."\n";
1000 1000
 			}
1001 1001
 		}
1002 1002
 
1003 1003
 		$courses = Sensei()->course->get_all_courses();
1004 1004
 
1005
-		if( 0 < count( $courses ) ) {
1005
+		if (0 < count($courses)) {
1006 1006
 
1007 1007
             // order the courses as set by the users
1008 1008
             $all_course_ids = array();
1009
-            foreach( $courses as $course ){
1009
+            foreach ($courses as $course) {
1010 1010
 
1011
-                $all_course_ids[] = (string)$course->ID;
1011
+                $all_course_ids[] = (string) $course->ID;
1012 1012
 
1013 1013
             }
1014 1014
             $order_string = $this->get_course_order();
1015 1015
 
1016
-            if( !empty( $order_string ) ){
1017
-                $ordered_course_ids = explode(',' , $order_string );
1018
-                $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1016
+            if ( ! empty($order_string)) {
1017
+                $ordered_course_ids = explode(',', $order_string);
1018
+                $all_course_ids = array_unique(array_merge($ordered_course_ids, $all_course_ids));
1019 1019
             }
1020 1020
 
1021 1021
 
1022
-			$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1023
-			$html .= '<ul class="sortable-course-list">' . "\n";
1022
+			$html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
1023
+			$html .= '<ul class="sortable-course-list">'."\n";
1024 1024
 			$count = 0;
1025
-			foreach ( $all_course_ids as $course_id ) {
1026
-                $course = get_post( $course_id );
1025
+			foreach ($all_course_ids as $course_id) {
1026
+                $course = get_post($course_id);
1027 1027
 				$count++;
1028 1028
 				$class = 'course';
1029
-				if ( $count == 1 ) { $class .= ' first'; }
1030
-				if ( $count == count( $course ) ) { $class .= ' last'; }
1031
-				if ( $count % 2 != 0 ) {
1029
+				if ($count == 1) { $class .= ' first'; }
1030
+				if ($count == count($course)) { $class .= ' last'; }
1031
+				if ($count % 2 != 0) {
1032 1032
 					$class .= ' alternate';
1033 1033
 				}
1034
-				$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $course->ID ) . '" style="width: 100%;"> ' . $course->post_title . '</span></li>' . "\n";
1034
+				$html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($course->ID).'" style="width: 100%;"> '.$course->post_title.'</span></li>'."\n";
1035 1035
 			}
1036
-			$html .= '</ul>' . "\n";
1036
+			$html .= '</ul>'."\n";
1037 1037
 
1038
-			$html .= '<input type="hidden" name="course-order" value="' . esc_attr( $order_string ) . '" />' . "\n";
1039
-			$html .= '<input type="submit" class="button-primary" value="' . __( 'Save course order', 'woothemes-sensei' ) . '" />' . "\n";
1038
+			$html .= '<input type="hidden" name="course-order" value="'.esc_attr($order_string).'" />'."\n";
1039
+			$html .= '<input type="submit" class="button-primary" value="'.__('Save course order', 'woothemes-sensei').'" />'."\n";
1040 1040
 		}
1041 1041
 
1042 1042
 		echo $html;
@@ -1045,25 +1045,25 @@  discard block
 block discarded – undo
1045 1045
 	}
1046 1046
 
1047 1047
 	public function get_course_order() {
1048
-		return get_option( 'sensei_course_order', '' );
1048
+		return get_option('sensei_course_order', '');
1049 1049
 	}
1050 1050
 
1051
-	public function save_course_order( $order_string = '' ) {
1052
-		$order = explode( ',', $order_string );
1051
+	public function save_course_order($order_string = '') {
1052
+		$order = explode(',', $order_string);
1053 1053
 
1054
-		update_option( 'sensei_course_order', $order_string );
1054
+		update_option('sensei_course_order', $order_string);
1055 1055
 
1056 1056
 		$i = 1;
1057
-		foreach( $order as $course_id ) {
1057
+		foreach ($order as $course_id) {
1058 1058
 
1059
-			if( $course_id ) {
1059
+			if ($course_id) {
1060 1060
 
1061 1061
 				$update_args = array(
1062 1062
 					'ID' => $course_id,
1063 1063
 					'menu_order' => $i,
1064 1064
 				);
1065 1065
 
1066
-				wp_update_post( $update_args );
1066
+				wp_update_post($update_args);
1067 1067
 
1068 1068
 				++$i;
1069 1069
 			}
@@ -1078,22 +1078,22 @@  discard block
 block discarded – undo
1078 1078
 	 */
1079 1079
 	public function lesson_order_screen() {
1080 1080
 
1081
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1082
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version );
1081
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1082
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version);
1083 1083
 
1084 1084
 		?><div id="lesson-order" class="wrap lesson-order">
1085
-		<h2><?php _e( 'Order Lessons', 'woothemes-sensei' ); ?></h2><?php
1085
+		<h2><?php _e('Order Lessons', 'woothemes-sensei'); ?></h2><?php
1086 1086
 
1087 1087
 		$html = '';
1088 1088
 
1089
-		if( isset( $_POST['lesson-order'] ) ) {
1089
+		if (isset($_POST['lesson-order'])) {
1090 1090
 
1091
-			$ordered = $this->save_lesson_order( esc_attr( $_POST['lesson-order'] ), esc_attr( $_POST['course_id'] ) );
1091
+			$ordered = $this->save_lesson_order(esc_attr($_POST['lesson-order']), esc_attr($_POST['course_id']));
1092 1092
 
1093
-			if( $ordered ) {
1094
-				$html .= '<div class="updated fade">' . "\n";
1095
-				$html .= '<p>' . __( 'The lesson order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n";
1096
-				$html .= '</div>' . "\n";
1093
+			if ($ordered) {
1094
+				$html .= '<div class="updated fade">'."\n";
1095
+				$html .= '<p>'.__('The lesson order has been saved.', 'woothemes-sensei').'</p>'."\n";
1096
+				$html .= '</div>'."\n";
1097 1097
 			}
1098 1098
 		}
1099 1099
 
@@ -1104,43 +1104,43 @@  discard block
 block discarded – undo
1104 1104
 			'orderby' => 'name',
1105 1105
 			'order' => 'ASC',
1106 1106
 		);
1107
-		$courses = get_posts( $args );
1107
+		$courses = get_posts($args);
1108 1108
 
1109
-		$html .= '<form action="' . admin_url( 'edit.php' ) . '" method="get">' . "\n";
1110
-		$html .= '<input type="hidden" name="post_type" value="lesson" />' . "\n";
1111
-		$html .= '<input type="hidden" name="page" value="lesson-order" />' . "\n";
1112
-		$html .= '<select id="lesson-order-course" name="course_id">' . "\n";
1113
-		$html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>' . "\n";
1109
+		$html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
1110
+		$html .= '<input type="hidden" name="post_type" value="lesson" />'."\n";
1111
+		$html .= '<input type="hidden" name="page" value="lesson-order" />'."\n";
1112
+		$html .= '<select id="lesson-order-course" name="course_id">'."\n";
1113
+		$html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
1114 1114
 
1115
-		foreach( $courses as $course ) {
1115
+		foreach ($courses as $course) {
1116 1116
 			$course_id = '';
1117
-			if( isset( $_GET['course_id'] ) ) {
1118
-				$course_id = intval( $_GET['course_id'] );
1117
+			if (isset($_GET['course_id'])) {
1118
+				$course_id = intval($_GET['course_id']);
1119 1119
 			}
1120
-			$html .= '<option value="' . esc_attr( intval( $course->ID ) ) . '" ' . selected( $course->ID, $course_id, false ) .'>' . get_the_title( $course->ID ) . '</option>' . "\n";
1120
+			$html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
1121 1121
 		}
1122 1122
 
1123
-		$html .= '</select>' . "\n";
1124
-		$html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="' . __( 'Select', 'woothemes-sensei' ) . '" />' . "\n";
1125
-		$html .= '</form>' . "\n";
1123
+		$html .= '</select>'."\n";
1124
+		$html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
1125
+		$html .= '</form>'."\n";
1126 1126
 
1127
-		$html .= '<script type="text/javascript">' . "\n";
1128
-		$html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});' . "\n";
1129
-		$html .= '</script>' . "\n";
1127
+		$html .= '<script type="text/javascript">'."\n";
1128
+		$html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});'."\n";
1129
+		$html .= '</script>'."\n";
1130 1130
 
1131
-		if( isset( $_GET['course_id'] ) ) {
1132
-			$course_id = intval( $_GET['course_id'] );
1133
-			if( $course_id > 0 ) {
1131
+		if (isset($_GET['course_id'])) {
1132
+			$course_id = intval($_GET['course_id']);
1133
+			if ($course_id > 0) {
1134 1134
 
1135
-				$order_string = $this->get_lesson_order( $course_id );
1135
+				$order_string = $this->get_lesson_order($course_id);
1136 1136
 
1137
-				$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1137
+				$html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
1138 1138
 
1139 1139
 				$displayed_lessons = array();
1140 1140
 
1141
-                $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1141
+                $modules = Sensei()->modules->get_course_modules(intval($course_id));
1142 1142
 
1143
-                foreach( $modules as $module ) {
1143
+                foreach ($modules as $module) {
1144 1144
 
1145 1145
                     $args = array(
1146 1146
                         'post_type' => 'lesson',
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
                         'meta_query' => array(
1150 1150
                             array(
1151 1151
                                 'key' => '_lesson_course',
1152
-                                'value' => intval( $course_id ),
1152
+                                'value' => intval($course_id),
1153 1153
                                 'compare' => '='
1154 1154
                             )
1155 1155
                         ),
@@ -1157,66 +1157,66 @@  discard block
 block discarded – undo
1157 1157
                             array(
1158 1158
                                 'taxonomy' => Sensei()->modules->taxonomy,
1159 1159
                                 'field' => 'id',
1160
-                                'terms' => intval( $module->term_id )
1160
+                                'terms' => intval($module->term_id)
1161 1161
                             )
1162 1162
                         ),
1163
-                        'meta_key' => '_order_module_' . $module->term_id,
1163
+                        'meta_key' => '_order_module_'.$module->term_id,
1164 1164
                         'orderby' => 'meta_value_num date',
1165 1165
                         'order' => 'ASC',
1166 1166
                         'suppress_filters' => 0
1167 1167
                     );
1168 1168
 
1169
-                    $lessons = get_posts( $args );
1169
+                    $lessons = get_posts($args);
1170 1170
 
1171
-                    if( count( $lessons ) > 0 ) {
1172
-                        $html .= '<h3>' . $module->name . '</h3>' . "\n";
1173
-                        $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1171
+                    if (count($lessons) > 0) {
1172
+                        $html .= '<h3>'.$module->name.'</h3>'."\n";
1173
+                        $html .= '<ul class="sortable-lesson-list" data-module_id="'.$module->term_id.'">'."\n";
1174 1174
 
1175 1175
                         $count = 0;
1176
-                        foreach( $lessons as $lesson ) {
1176
+                        foreach ($lessons as $lesson) {
1177 1177
                             $count++;
1178 1178
                             $class = 'lesson';
1179
-                            if ( $count == 1 ) { $class .= ' first'; }
1180
-                            if ( $count == count( $lesson ) ) { $class .= ' last'; }
1181
-                            if ( $count % 2 != 0 ) {
1179
+                            if ($count == 1) { $class .= ' first'; }
1180
+                            if ($count == count($lesson)) { $class .= ' last'; }
1181
+                            if ($count % 2 != 0) {
1182 1182
                                 $class .= ' alternate';
1183 1183
                             }
1184 1184
 
1185
-                            $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1185
+                            $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n";
1186 1186
 
1187 1187
                             $displayed_lessons[] = $lesson->ID;
1188 1188
                         }
1189 1189
 
1190
-                        $html .= '</ul>' . "\n";
1190
+                        $html .= '</ul>'."\n";
1191 1191
 
1192
-                        $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1192
+                        $html .= '<input type="hidden" name="lesson-order-module-'.$module->term_id.'" value="" />'."\n";
1193 1193
                     }
1194 1194
                 }
1195 1195
 
1196 1196
 
1197
-                $lessons = Sensei()->course->course_lessons( $course_id );
1197
+                $lessons = Sensei()->course->course_lessons($course_id);
1198 1198
 
1199
-				if( 0 < count( $lessons ) ) {
1199
+				if (0 < count($lessons)) {
1200 1200
 
1201 1201
                     //get module term ids, will be used to exclude lessons
1202 1202
                     $module_items_ids = array();
1203
-                    if( ! empty( $modules ) ) {
1203
+                    if ( ! empty($modules)) {
1204 1204
                         foreach ($modules as $module) {
1205 1205
                             $module_items_ids[] = $module->term_id;
1206 1206
                         }
1207 1207
                     }
1208 1208
 
1209
-					if( 0 < count( $displayed_lessons ) ) {
1210
-						$html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n";
1209
+					if (0 < count($displayed_lessons)) {
1210
+						$html .= '<h3>'.__('Other Lessons', 'woothemes-sensei').'</h3>'."\n";
1211 1211
 					}
1212 1212
 
1213
-					$html .= '<ul class="sortable-lesson-list" data-module_id="0">' . "\n";
1213
+					$html .= '<ul class="sortable-lesson-list" data-module_id="0">'."\n";
1214 1214
 					$count = 0;
1215
-					foreach ( $lessons as $lesson ) {
1215
+					foreach ($lessons as $lesson) {
1216 1216
 
1217 1217
                         // if lesson belongs to one fo the course modules then exclude it here
1218 1218
                         // as it is listed above
1219
-                        if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1219
+                        if (has_term($module_items_ids, 'module', $lesson->ID)) {
1220 1220
 
1221 1221
                             continue;
1222 1222
 
@@ -1224,28 +1224,28 @@  discard block
 block discarded – undo
1224 1224
 
1225 1225
 						$count++;
1226 1226
 						$class = 'lesson';
1227
-						if ( $count == 1 ) { $class .= ' first'; }
1228
-						if ( $count == count( $lesson ) ) { $class .= ' last'; }
1229
-						if ( $count % 2 != 0 ) {
1227
+						if ($count == 1) { $class .= ' first'; }
1228
+						if ($count == count($lesson)) { $class .= ' last'; }
1229
+						if ($count % 2 != 0) {
1230 1230
 
1231 1231
 							$class .= ' alternate';
1232 1232
 
1233 1233
 						}
1234
-						$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1234
+						$html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n";
1235 1235
 
1236 1236
 						$displayed_lessons[] = $lesson->ID;
1237 1237
 					}
1238
-					$html .= '</ul>' . "\n";
1238
+					$html .= '</ul>'."\n";
1239 1239
 				} else {
1240
-					if( 0 == count( $displayed_lessons ) ) {
1241
-						$html .= '<p><em>' . __( 'There are no lessons in this course.', 'woothemes-sensei' ) . '</em></p>';
1240
+					if (0 == count($displayed_lessons)) {
1241
+						$html .= '<p><em>'.__('There are no lessons in this course.', 'woothemes-sensei').'</em></p>';
1242 1242
 					}
1243 1243
 				}
1244 1244
 
1245
-				if( 0 < count( $displayed_lessons ) ) {
1246
-					$html .= '<input type="hidden" name="lesson-order" value="' . esc_attr( $order_string ) . '" />' . "\n";
1247
-					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
1248
-					$html .= '<input type="submit" class="button-primary" value="' . __( 'Save lesson order', 'woothemes-sensei' ) . '" />' . "\n";
1245
+				if (0 < count($displayed_lessons)) {
1246
+					$html .= '<input type="hidden" name="lesson-order" value="'.esc_attr($order_string).'" />'."\n";
1247
+					$html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
1248
+					$html .= '<input type="submit" class="button-primary" value="'.__('Save lesson order', 'woothemes-sensei').'" />'."\n";
1249 1249
 				}
1250 1250
 			}
1251 1251
 		}
@@ -1255,27 +1255,27 @@  discard block
 block discarded – undo
1255 1255
 		?></div><?php
1256 1256
 	}
1257 1257
 
1258
-	public function get_lesson_order( $course_id = 0 ) {
1259
-		$order_string = get_post_meta( $course_id, '_lesson_order', true );
1258
+	public function get_lesson_order($course_id = 0) {
1259
+		$order_string = get_post_meta($course_id, '_lesson_order', true);
1260 1260
 		return $order_string;
1261 1261
 	}
1262 1262
 
1263
-	public function save_lesson_order( $order_string = '', $course_id = 0 ) {
1263
+	public function save_lesson_order($order_string = '', $course_id = 0) {
1264 1264
 
1265
-		if( $course_id ) {
1265
+		if ($course_id) {
1266 1266
 
1267
-            $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1267
+            $modules = Sensei()->modules->get_course_modules(intval($course_id));
1268 1268
 
1269
-            foreach( $modules as $module ) {
1269
+            foreach ($modules as $module) {
1270 1270
 
1271
-                $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ];
1271
+                $module_order_string = $_POST['lesson-order-module-'.$module->term_id];
1272 1272
 
1273
-                if( $module_order_string ) {
1274
-                    $order = explode( ',', $module_order_string );
1273
+                if ($module_order_string) {
1274
+                    $order = explode(',', $module_order_string);
1275 1275
                     $i = 1;
1276
-                    foreach( $order as $lesson_id ) {
1277
-                        if( $lesson_id ) {
1278
-                            update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1276
+                    foreach ($order as $lesson_id) {
1277
+                        if ($lesson_id) {
1278
+                            update_post_meta($lesson_id, '_order_module_'.$module->term_id, $i);
1279 1279
                             ++$i;
1280 1280
                         }
1281 1281
                     }
@@ -1283,15 +1283,15 @@  discard block
 block discarded – undo
1283 1283
             }
1284 1284
 
1285 1285
 
1286
-			if( $order_string ) {
1287
-				update_post_meta( $course_id, '_lesson_order', $order_string );
1286
+			if ($order_string) {
1287
+				update_post_meta($course_id, '_lesson_order', $order_string);
1288 1288
 
1289
-				$order = explode( ',', $order_string );
1289
+				$order = explode(',', $order_string);
1290 1290
 
1291 1291
 				$i = 1;
1292
-				foreach( $order as $lesson_id ) {
1293
-					if( $lesson_id ) {
1294
-						update_post_meta( $lesson_id, '_order_' . $course_id, $i );
1292
+				foreach ($order as $lesson_id) {
1293
+					if ($lesson_id) {
1294
+						update_post_meta($lesson_id, '_order_'.$course_id, $i);
1295 1295
 						++$i;
1296 1296
 					}
1297 1297
 				}
@@ -1306,54 +1306,54 @@  discard block
 block discarded – undo
1306 1306
 	function sensei_add_custom_menu_items() {
1307 1307
 		global $pagenow;
1308 1308
 
1309
-		if( 'nav-menus.php' == $pagenow ) {
1310
-			add_meta_box( 'add-sensei-links', 'Sensei', array( $this, 'wp_nav_menu_item_sensei_links_meta_box' ), 'nav-menus', 'side', 'low' );
1309
+		if ('nav-menus.php' == $pagenow) {
1310
+			add_meta_box('add-sensei-links', 'Sensei', array($this, 'wp_nav_menu_item_sensei_links_meta_box'), 'nav-menus', 'side', 'low');
1311 1311
 		}
1312 1312
 	}
1313 1313
 
1314
-	function wp_nav_menu_item_sensei_links_meta_box( $object ) {
1314
+	function wp_nav_menu_item_sensei_links_meta_box($object) {
1315 1315
 		global $nav_menu_selected_id;
1316 1316
 
1317 1317
 		$menu_items = array(
1318
-			'#senseicourses' => __( 'Courses', 'woothemes-sensei' ),
1319
-			'#senseilessons' => __( 'Lessons', 'woothemes-sensei' ),
1320
-			'#senseimycourses' => __( 'My Courses', 'woothemes-sensei' ),
1321
-			'#senseilearnerprofile' => __( 'My Profile', 'woothemes-sensei' ),
1322
-			'#senseimymessages' => __( 'My Messages', 'woothemes-sensei' ),
1323
-			'#senseiloginlogout' => __( 'Login', 'woothemes-sensei' ) . '|' . __( 'Logout', 'woothemes-sensei' )
1318
+			'#senseicourses' => __('Courses', 'woothemes-sensei'),
1319
+			'#senseilessons' => __('Lessons', 'woothemes-sensei'),
1320
+			'#senseimycourses' => __('My Courses', 'woothemes-sensei'),
1321
+			'#senseilearnerprofile' => __('My Profile', 'woothemes-sensei'),
1322
+			'#senseimymessages' => __('My Messages', 'woothemes-sensei'),
1323
+			'#senseiloginlogout' => __('Login', 'woothemes-sensei').'|'.__('Logout', 'woothemes-sensei')
1324 1324
 		);
1325 1325
 
1326 1326
 		$menu_items_obj = array();
1327
-		foreach ( $menu_items as $value => $title ) {
1327
+		foreach ($menu_items as $value => $title) {
1328 1328
 			$menu_items_obj[$title] = new stdClass;
1329
-			$menu_items_obj[$title]->object_id			= esc_attr( $value );
1330
-			$menu_items_obj[$title]->title				= esc_attr( $title );
1331
-			$menu_items_obj[$title]->url				= esc_attr( $value );
1332
-			$menu_items_obj[$title]->description 		= 'description';
1329
+			$menu_items_obj[$title]->object_id = esc_attr($value);
1330
+			$menu_items_obj[$title]->title = esc_attr($title);
1331
+			$menu_items_obj[$title]->url = esc_attr($value);
1332
+			$menu_items_obj[$title]->description = 'description';
1333 1333
 			$menu_items_obj[$title]->db_id 				= 0;
1334 1334
 			$menu_items_obj[$title]->object 			= 'sensei';
1335
-			$menu_items_obj[$title]->menu_item_parent 	= 0;
1336
-			$menu_items_obj[$title]->type 				= 'custom';
1335
+			$menu_items_obj[$title]->menu_item_parent = 0;
1336
+			$menu_items_obj[$title]->type = 'custom';
1337 1337
 			$menu_items_obj[$title]->target 			= '';
1338
-			$menu_items_obj[$title]->attr_title 		= '';
1339
-			$menu_items_obj[$title]->classes 			= array();
1340
-			$menu_items_obj[$title]->xfn 				= '';
1338
+			$menu_items_obj[$title]->attr_title = '';
1339
+			$menu_items_obj[$title]->classes = array();
1340
+			$menu_items_obj[$title]->xfn = '';
1341 1341
 		}
1342 1342
 
1343
-		$walker = new Walker_Nav_Menu_Checklist( array() );
1343
+		$walker = new Walker_Nav_Menu_Checklist(array());
1344 1344
 		?>
1345 1345
 
1346 1346
 		<div id="sensei-links" class="senseidiv taxonomydiv">
1347 1347
 			<div id="tabs-panel-sensei-links-all" class="tabs-panel tabs-panel-view-all tabs-panel-active">
1348 1348
 
1349 1349
 				<ul id="sensei-linkschecklist" class="list:sensei-links categorychecklist form-no-clear">
1350
-					<?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items_obj ), 0, (object)array( 'walker' => $walker ) ); ?>
1350
+					<?php echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $menu_items_obj), 0, (object) array('walker' => $walker)); ?>
1351 1351
 				</ul>
1352 1352
 
1353 1353
 			</div>
1354 1354
 			<p class="button-controls">
1355 1355
 				<span class="add-to-menu">
1356
-					<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'woothemes-sensei' ); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" />
1356
+					<input type="submit"<?php disabled($nav_menu_selected_id, 0); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu', 'woothemes-sensei'); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" />
1357 1357
 					<span class="spinner"></span>
1358 1358
 				</span>
1359 1359
 			</p>
@@ -1369,17 +1369,17 @@  discard block
 block discarded – undo
1369 1369
 	 */
1370 1370
 	public function theme_compatibility_notices() {
1371 1371
 
1372
-        if( isset( $_GET['sensei_hide_notice'] ) ) {
1373
-        	switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1374
-				case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break;
1375
-				case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break;
1372
+        if (isset($_GET['sensei_hide_notice'])) {
1373
+        	switch (esc_attr($_GET['sensei_hide_notice'])) {
1374
+				case 'menu_settings': add_user_meta(get_current_user_id(), 'sensei_hide_menu_settings_notice', true); break;
1375
+				case 'theme_check': add_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); break;
1376 1376
 			}
1377 1377
         }
1378 1378
 
1379 1379
         // white list templates that are already support by default and do not show notice for them
1380
-        $template = get_option( 'template' );
1380
+        $template = get_option('template');
1381 1381
 
1382
-        $white_list = array(    'twentyeleven',
1382
+        $white_list = array('twentyeleven',
1383 1383
                                 'twentytwelve',
1384 1384
                                 'twentyfourteen',
1385 1385
                                 'twentyfifteen',
@@ -1387,43 +1387,43 @@  discard block
 block discarded – undo
1387 1387
                                 'storefront',
1388 1388
                                                 );
1389 1389
 
1390
-        if ( in_array( $template, $white_list ) ) {
1390
+        if (in_array($template, $white_list)) {
1391 1391
 
1392 1392
             return;
1393 1393
 
1394 1394
         }
1395 1395
 
1396 1396
         // don't show the notice if the user chose to hide it
1397
-        $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1398
-        if(  $hide_theme_check_notice ) {
1397
+        $hide_theme_check_notice = get_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true);
1398
+        if ($hide_theme_check_notice) {
1399 1399
 
1400 1400
             return;
1401 1401
 
1402 1402
         }
1403 1403
 
1404 1404
         // show the notice for themes not supporting sensei
1405
-	    if ( ! current_theme_supports( 'sensei' ) ) {
1405
+	    if ( ! current_theme_supports('sensei')) {
1406 1406
             ?>
1407 1407
 
1408 1408
             <div id="message" class="error sensei-message sensei-connect">
1409 1409
                     <p>
1410 1410
                         <strong>
1411 1411
 
1412
-                            <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei' ); ?>
1412
+                            <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei'); ?>
1413 1413
 
1414 1414
                         </strong> &#8211;
1415 1415
 
1416
-                        <?php _e( 'if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei' ); ?>
1416
+                        <?php _e('if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei'); ?>
1417 1417
 
1418
-                        <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php  _e( 'Sensei theme', 'woothemes-sensei' ) ?> </a>
1418
+                        <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php  _e('Sensei theme', 'woothemes-sensei') ?> </a>
1419 1419
 
1420 1420
                         :)
1421 1421
 
1422 1422
                     </p>
1423 1423
                     <p class="submit">
1424
-                        <a href="<?php echo esc_url( apply_filters( 'sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary">
1424
+                        <a href="<?php echo esc_url(apply_filters('sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility')); ?>" class="button-primary">
1425 1425
 
1426
-                            <?php _e( 'Theme Integration Guide', 'woothemes-sensei' ); ?></a> <a class="skip button" href="<?php echo esc_url( add_query_arg( 'sensei_hide_notice', 'theme_check' ) ); ?>"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?>
1426
+                            <?php _e('Theme Integration Guide', 'woothemes-sensei'); ?></a> <a class="skip button" href="<?php echo esc_url(add_query_arg('sensei_hide_notice', 'theme_check')); ?>"><?php _e('Hide this notice', 'woothemes-sensei'); ?>
1427 1427
 
1428 1428
                         </a>
1429 1429
                     </p>
@@ -1441,7 +1441,7 @@  discard block
 block discarded – undo
1441 1441
 		wp_get_current_user();
1442 1442
         $user_id = $current_user->ID;
1443 1443
 
1444
-		delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' );
1444
+		delete_user_meta($user_id, 'sensei_hide_theme_check_notice');
1445 1445
 	}
1446 1446
 
1447 1447
 	/**
@@ -1451,8 +1451,8 @@  discard block
 block discarded – undo
1451 1451
 	 * @param  bool $prevent_access
1452 1452
 	 * @return bool
1453 1453
 	 */
1454
-	public function admin_access( $prevent_access ) {
1455
-		if ( current_user_can( 'manage_sensei_grades' ) ) {
1454
+	public function admin_access($prevent_access) {
1455
+		if (current_user_can('manage_sensei_grades')) {
1456 1456
 			return false;
1457 1457
 		}
1458 1458
 
@@ -1467,12 +1467,12 @@  discard block
 block discarded – undo
1467 1467
      *
1468 1468
      * @since 1.8.7
1469 1469
      */
1470
-    public  static function install_pages(){
1470
+    public  static function install_pages() {
1471 1471
 
1472 1472
         // only fire on the settings page
1473
-        if( ! isset( $_GET['page'] )
1473
+        if ( ! isset($_GET['page'])
1474 1474
             || 'woothemes-sensei-settings' != $_GET['page']
1475
-            || 1 == get_option('skip_install_sensei_pages') ){
1475
+            || 1 == get_option('skip_install_sensei_pages')) {
1476 1476
 
1477 1477
             return;
1478 1478
 
@@ -1502,13 +1502,13 @@  discard block
 block discarded – undo
1502 1502
         if ($install_complete) {
1503 1503
 
1504 1504
             // Flush rules after install
1505
-            flush_rewrite_rules( true );
1505
+            flush_rewrite_rules(true);
1506 1506
 
1507 1507
             // Set installed option
1508 1508
             update_option('sensei_installed', 0);
1509 1509
 
1510
-            $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1511
-            wp_redirect( $complete_url );
1510
+            $complete_url = add_query_arg('sensei_install_complete', 'true', $settings_url);
1511
+            wp_redirect($complete_url);
1512 1512
 
1513 1513
         }
1514 1514
 
@@ -1521,4 +1521,4 @@  discard block
 block discarded – undo
1521 1521
  * for backward compatibility
1522 1522
  * @since 1.9.0
1523 1523
  */
1524
-class WooThemes_Sensei_Admin extends Sensei_Admin{ }
1524
+class WooThemes_Sensei_Admin extends Sensei_Admin { }
Please login to merge, or discard this patch.