Completed
Push — master ( c85389...3dfe72 )
by Matty
06:29
created
includes/class-sensei-settings.php 1 patch
Spacing   +181 added lines, -181 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
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 	 * @access public
19 19
 	 * @since 1.0.0
20 20
 	 */
21
-	public function __construct () {
21
+	public function __construct() {
22 22
 	    parent::__construct(); // Required in extended classes.
23 23
 
24 24
         $this->token = 'woothemes-sensei-settings';
25
-        add_action('init', array( __CLASS__, 'flush_rewrite_rules' ) );
25
+        add_action('init', array(__CLASS__, 'flush_rewrite_rules'));
26 26
 
27 27
         // Setup Admin Settings data
28
-        if ( is_admin() ) {
28
+        if (is_admin()) {
29 29
 
30 30
             $this->has_tabs 	= true;
31
-            $this->name 		= __( 'Sensei Settings', 'woothemes-sensei' );
32
-            $this->menu_label	= __( 'Settings', 'woothemes-sensei' );
31
+            $this->name = __('Sensei Settings', 'woothemes-sensei');
32
+            $this->menu_label = __('Settings', 'woothemes-sensei');
33 33
             $this->page_slug	= 'woothemes-sensei-settings';
34 34
 
35 35
         } // End If Statement
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
      * @param string $setting_name
47 47
      * @return mixed
48 48
      */
49
-    public function get( $setting_name ){
49
+    public function get($setting_name) {
50 50
 
51
-        if( isset( $this->settings[ $setting_name ] ) ){
51
+        if (isset($this->settings[$setting_name])) {
52 52
 
53
-            return $this->settings[ $setting_name ];
53
+            return $this->settings[$setting_name];
54 54
 
55 55
         }
56 56
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
      * @param $setting
64 64
      * @param $new_value
65 65
      */
66
-    public function set( $setting, $new_value ){
66
+    public function set($setting, $new_value) {
67 67
     	
68
-        $settings = get_option( $this->token, array() );
69
-		$settings[ $setting ] = $new_value;
70
-		return update_option( $this->token,$settings );
68
+        $settings = get_option($this->token, array());
69
+		$settings[$setting] = $new_value;
70
+		return update_option($this->token, $settings);
71 71
 
72 72
     }
73 73
 
@@ -77,17 +77,17 @@  discard block
 block discarded – undo
77 77
 	 * @since  1.0.0
78 78
 	 * @return void
79 79
 	 */
80
-	public function register_settings_screen () {
80
+	public function register_settings_screen() {
81 81
 
82 82
 		$this->settings_version = Sensei()->version; // Use the global plugin version on this settings screen.
83
-		$hook = add_submenu_page( 'sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array( $this, 'settings_screen' ) );
83
+		$hook = add_submenu_page('sensei', $this->name, $this->menu_label, 'manage_sensei', $this->page_slug, array($this, 'settings_screen'));
84 84
 		$this->hook = $hook;
85 85
 
86
-		if ( isset( $_GET['page'] ) && ( $_GET['page'] == $this->page_slug ) ) {
87
-			add_action( 'admin_notices', array( $this, 'settings_errors' ) );
88
-			add_action( 'admin_notices', array( $this, 'language_pack_notices' ) );
89
-			add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
90
-			add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
86
+		if (isset($_GET['page']) && ($_GET['page'] == $this->page_slug)) {
87
+			add_action('admin_notices', array($this, 'settings_errors'));
88
+			add_action('admin_notices', array($this, 'language_pack_notices'));
89
+			add_action('admin_print_scripts', array($this, 'enqueue_scripts'));
90
+			add_action('admin_print_styles', array($this, 'enqueue_styles'));
91 91
 		}
92 92
 	} // End register_settings_screen()
93 93
 
@@ -97,49 +97,49 @@  discard block
 block discarded – undo
97 97
 	 * @since  1.0.0
98 98
 	 * @return void
99 99
 	 */
100
-	public function init_sections () {
100
+	public function init_sections() {
101 101
 		$sections = array();
102 102
 
103 103
 		$sections['default-settings'] = array(
104
-			'name' 			=> __( 'General', 'woothemes-sensei' ),
105
-			'description'	=> __( 'Settings that apply to the entire plugin.', 'woothemes-sensei' )
104
+			'name' 			=> __('General', 'woothemes-sensei'),
105
+			'description'	=> __('Settings that apply to the entire plugin.', 'woothemes-sensei')
106 106
 		);
107 107
 
108 108
 		$sections['course-settings'] = array(
109
-			'name' 			=> __( 'Courses', 'woothemes-sensei' ),
110
-			'description'	=> __( 'Settings that apply to all Courses.', 'woothemes-sensei' )
109
+			'name' 			=> __('Courses', 'woothemes-sensei'),
110
+			'description'	=> __('Settings that apply to all Courses.', 'woothemes-sensei')
111 111
 		);
112 112
 
113 113
 		$sections['lesson-settings'] = array(
114
-			'name' 			=> __( 'Lessons', 'woothemes-sensei' ),
115
-			'description'	=> __( 'Settings that apply to all Lessons.', 'woothemes-sensei' )
114
+			'name' 			=> __('Lessons', 'woothemes-sensei'),
115
+			'description'	=> __('Settings that apply to all Lessons.', 'woothemes-sensei')
116 116
 		);
117 117
 
118 118
 		$sections['email-notification-settings'] = array(
119
-			'name' 			=> __( 'Email Notifications', 'woothemes-sensei' ),
120
-			'description'	=> __( 'Settings for email notifications sent from your site.', 'woothemes-sensei' )
119
+			'name' 			=> __('Email Notifications', 'woothemes-sensei'),
120
+			'description'	=> __('Settings for email notifications sent from your site.', 'woothemes-sensei')
121 121
 		);
122 122
 
123 123
 		$sections['learner-profile-settings'] = array(
124
-			'name' 			=> __( 'Learner Profiles', 'woothemes-sensei' ),
125
-			'description'	=> __( 'Settings for public Learner Profiles.', 'woothemes-sensei' )
124
+			'name' 			=> __('Learner Profiles', 'woothemes-sensei'),
125
+			'description'	=> __('Settings for public Learner Profiles.', 'woothemes-sensei')
126 126
 		);
127 127
 
128
-		if ( Sensei_WC::is_woocommerce_present() ) {
128
+		if (Sensei_WC::is_woocommerce_present()) {
129 129
 			$sections['woocommerce-settings'] = array(
130
-				'name' 			=> __( 'WooCommerce', 'woothemes-sensei' ),
131
-				'description'	=> __( 'Optional settings for WooCommerce functions.', 'woothemes-sensei' )
130
+				'name' 			=> __('WooCommerce', 'woothemes-sensei'),
131
+				'description'	=> __('Optional settings for WooCommerce functions.', 'woothemes-sensei')
132 132
 			);
133 133
 		} // End If Statement
134 134
 
135
-		if ( 'en_US' !== get_locale() ) {
135
+		if ('en_US' !== get_locale()) {
136 136
 			$sections['language-settings'] = array(
137
-				'name' 			=> __( 'Language', 'woothemes-sensei' ),
138
-				'description'	=> __( 'Language options.', 'woothemes-sensei' )
137
+				'name' 			=> __('Language', 'woothemes-sensei'),
138
+				'description'	=> __('Language options.', 'woothemes-sensei')
139 139
 			);
140 140
 		}
141 141
 
142
-		$this->sections = apply_filters( 'sensei_settings_tabs', $sections );
142
+		$this->sections = apply_filters('sensei_settings_tabs', $sections);
143 143
 	} // End init_sections()
144 144
 
145 145
 	/**
@@ -149,71 +149,71 @@  discard block
 block discarded – undo
149 149
 	 * @uses   Sensei_Utils::get_slider_types()
150 150
 	 * @return void
151 151
 	 */
152
-	public function init_fields () {
152
+	public function init_fields() {
153 153
 		global $pagenow;
154 154
 
155 155
 		$pages_array = $this->pages_array();
156
-		$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' );
157
-		$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' ) );
158
-		$course_display_settings = array( 'excerpt' => __( 'Course Excerpt', 'woothemes-sensei' ), 'full' => __( 'Full Course Content', 'woothemes-sensei' ) );
156
+		$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');
157
+		$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'));
158
+		$course_display_settings = array('excerpt' => __('Course Excerpt', 'woothemes-sensei'), 'full' => __('Full Course Content', 'woothemes-sensei'));
159 159
 
160 160
 	    $fields = array();
161 161
 
162 162
 		$fields['access_permission'] = array(
163
-								'name' => __( 'Access Permissions', 'woothemes-sensei' ),
164
-								'description' => __( 'Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei' ),
163
+								'name' => __('Access Permissions', 'woothemes-sensei'),
164
+								'description' => __('Users must be logged in to view Course and Lesson content.', 'woothemes-sensei', 'woothemes-sensei'),
165 165
 								'type' => 'checkbox',
166 166
 								'default' => true,
167 167
 								'section' => 'default-settings'
168 168
 								);
169 169
 
170 170
 		$fields['messages_disable'] = array(
171
-								'name' => __( 'Disable Private Messages', 'woothemes-sensei' ),
172
-								'description' => __( 'Disable the private message functions between learners and teachers.', 'woothemes-sensei' ),
171
+								'name' => __('Disable Private Messages', 'woothemes-sensei'),
172
+								'description' => __('Disable the private message functions between learners and teachers.', 'woothemes-sensei'),
173 173
 								'type' => 'checkbox',
174 174
 								'default' => false,
175 175
 								'section' => 'default-settings'
176 176
 								);
177 177
 
178 178
 		$fields['course_page'] = array(
179
-								'name' => __( 'Course Archive Page', 'woothemes-sensei' ),
180
-								'description' => __( 'The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei' ),
179
+								'name' => __('Course Archive Page', 'woothemes-sensei'),
180
+								'description' => __('The page to use to display courses. If you leave this blank the default custom post type archive will apply.', 'woothemes-sensei'),
181 181
 								'type' => 'select',
182
-								'default' => get_option( 'woothemes-sensei_courses_page_id', 0 ),
182
+								'default' => get_option('woothemes-sensei_courses_page_id', 0),
183 183
 								'section' => 'default-settings',
184 184
 								'required' => 0,
185 185
 								'options' => $pages_array
186 186
 								);
187 187
 
188 188
 		$fields['my_course_page'] = array(
189
-								'name' => __( 'My Courses Page', 'woothemes-sensei' ),
190
-								'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' ),
189
+								'name' => __('My Courses Page', 'woothemes-sensei'),
190
+								'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'),
191 191
 								'type' => 'select',
192
-								'default' => get_option( 'woothemes-sensei_user_dashboard_page_id', 0 ),
192
+								'default' => get_option('woothemes-sensei_user_dashboard_page_id', 0),
193 193
 								'section' => 'default-settings',
194 194
 								'required' => 0,
195 195
 								'options' => $pages_array
196 196
 								);
197 197
 
198 198
 		$fields['placeholder_images_enable'] = array(
199
-								'name' => __( 'Use placeholder images', 'woothemes-sensei' ),
200
-								'description' => __( 'Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei' ),
199
+								'name' => __('Use placeholder images', 'woothemes-sensei'),
200
+								'description' => __('Output a placeholder image when no featured image has been specified for Courses and Lessons.', 'woothemes-sensei'),
201 201
 								'type' => 'checkbox',
202 202
 								'default' => false,
203 203
 								'section' => 'default-settings'
204 204
 								);
205 205
 
206 206
 		$fields['styles_disable'] = array(
207
-								'name' => __( 'Disable Sensei Styles', 'woothemes-sensei' ),
208
-								'description' => __( 'Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei' ),
207
+								'name' => __('Disable Sensei Styles', 'woothemes-sensei'),
208
+								'description' => __('Prevent the frontend stylesheets from loading. This will remove the default styles for all Sensei elements.', 'woothemes-sensei'),
209 209
 								'type' => 'checkbox',
210 210
 								'default' => false,
211 211
 								'section' => 'default-settings'
212 212
 								);
213 213
 
214 214
 		$fields['js_disable'] = array(
215
-								'name' => __( 'Disable Sensei Javascript', 'woothemes-sensei' ),
216
-								'description' => __( 'Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei' ),
215
+								'name' => __('Disable Sensei Javascript', 'woothemes-sensei'),
216
+								'description' => __('Prevent the frontend javascript from loading. This affects the progress bars and the My Courses tabs.', 'woothemes-sensei'),
217 217
 								'type' => 'checkbox',
218 218
 								'default' => false,
219 219
 								'section' => 'default-settings'
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
     	// Course Settings
223 223
 
224 224
     	$fields['course_completion'] = array(
225
-								'name' => __( 'Courses are complete:', 'woothemes-sensei' ),
226
-								'description' => __( 'This will determine when courses are marked as complete.', 'woothemes-sensei' ),
225
+								'name' => __('Courses are complete:', 'woothemes-sensei'),
226
+								'description' => __('This will determine when courses are marked as complete.', 'woothemes-sensei'),
227 227
 								'type' => 'select',
228 228
 								'default' => 'passed',
229 229
 								'section' => 'course-settings',
@@ -232,16 +232,16 @@  discard block
 block discarded – undo
232 232
 								);
233 233
 
234 234
     	$fields['course_author'] = array(
235
-								'name' => __( 'Display Course Author', 'woothemes-sensei' ),
236
-								'description' => __( 'Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei' ),
235
+								'name' => __('Display Course Author', 'woothemes-sensei'),
236
+								'description' => __('Output the Course Author on Course archive and My Courses page.', 'woothemes-sensei'),
237 237
 								'type' => 'checkbox',
238 238
 								'default' => true,
239 239
 								'section' => 'course-settings'
240 240
 								);
241 241
 
242 242
 		$fields['my_course_amount'] = array(
243
-								'name' => __( 'My Courses Pagination', 'woothemes-sensei' ),
244
-								'description' => __( 'The number of courses to output for the my courses page.', 'woothemes-sensei' ),
243
+								'name' => __('My Courses Pagination', 'woothemes-sensei'),
244
+								'description' => __('The number of courses to output for the my courses page.', 'woothemes-sensei'),
245 245
 								'type' => 'range',
246 246
 								'default' => '0',
247 247
 								'section' => 'course-settings',
@@ -250,16 +250,16 @@  discard block
 block discarded – undo
250 250
 								);
251 251
 
252 252
 		$fields['course_archive_image_enable'] = array(
253
-								'name' => __( 'Course Archive Image', 'woothemes-sensei' ),
254
-								'description' => __( 'Output the Course Image on the Course Archive Page.', 'woothemes-sensei' ),
253
+								'name' => __('Course Archive Image', 'woothemes-sensei'),
254
+								'description' => __('Output the Course Image on the Course Archive Page.', 'woothemes-sensei'),
255 255
 								'type' => 'checkbox',
256 256
 								'default' => true,
257 257
 								'section' => 'course-settings'
258 258
 								);
259 259
 
260 260
 		$fields['course_archive_image_width'] = array(
261
-								'name' => __( 'Image Width - Archive', 'woothemes-sensei' ),
262
-								'description' => __( 'The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
261
+								'name' => __('Image Width - Archive', 'woothemes-sensei'),
262
+								'description' => __('The width in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
263 263
 								'type' => 'text',
264 264
 								'default' => '100',
265 265
 								'section' => 'course-settings',
@@ -267,8 +267,8 @@  discard block
 block discarded – undo
267 267
 								);
268 268
 
269 269
 		$fields['course_archive_image_height'] = array(
270
-								'name' => __( 'Image Height - Archive', 'woothemes-sensei' ),
271
-								'description' => __( 'The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei' ),
270
+								'name' => __('Image Height - Archive', 'woothemes-sensei'),
271
+								'description' => __('The height in pixels of the featured image for the Course Archive page.', 'woothemes-sensei'),
272 272
 								'type' => 'text',
273 273
 								'default' => '100',
274 274
 								'section' => 'course-settings',
@@ -276,24 +276,24 @@  discard block
 block discarded – undo
276 276
 								);
277 277
 
278 278
 		$fields['course_archive_image_hard_crop'] = array(
279
-								'name' => __( 'Image Hard Crop - Archive', 'woothemes-sensei' ),
280
-								'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>' ),
279
+								'name' => __('Image Hard Crop - Archive', 'woothemes-sensei'),
280
+								'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>'),
281 281
 								'type' => 'checkbox',
282 282
 								'default' => false,
283 283
 								'section' => 'course-settings'
284 284
 								);
285 285
 
286 286
 		$fields['course_single_image_enable'] = array(
287
-								'name' => __( 'Single Course Image', 'woothemes-sensei' ),
288
-								'description' => __( 'Output the Course Image on the Single Course Page.', 'woothemes-sensei' ),
287
+								'name' => __('Single Course Image', 'woothemes-sensei'),
288
+								'description' => __('Output the Course Image on the Single Course Page.', 'woothemes-sensei'),
289 289
 								'type' => 'checkbox',
290 290
 								'default' => false,
291 291
 								'section' => 'course-settings'
292 292
 								);
293 293
 
294 294
 		$fields['course_single_image_width'] = array(
295
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
296
-								'description' => __( 'The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
295
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
296
+								'description' => __('The width in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
297 297
 								'type' => 'text',
298 298
 								'default' => '100',
299 299
 								'section' => 'course-settings',
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 								);
302 302
 
303 303
 		$fields['course_single_image_height'] = array(
304
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
305
-								'description' => __( 'The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei' ),
304
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
305
+								'description' => __('The height in pixels of the featured image for the Course single post page.', 'woothemes-sensei'),
306 306
 								'type' => 'text',
307 307
 								'default' => '100',
308 308
 								'section' => 'course-settings',
@@ -310,16 +310,16 @@  discard block
 block discarded – undo
310 310
 								);
311 311
 
312 312
 		$fields['course_single_image_hard_crop'] = array(
313
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
314
-								'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>' ),
313
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
314
+								'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>'),
315 315
 								'type' => 'checkbox',
316 316
 								'default' => false,
317 317
 								'section' => 'course-settings'
318 318
 								);
319 319
 
320 320
 		$fields['course_single_content_display'] = array(
321
-								'name' => __( 'Single Course page displays:', 'woothemes-sensei' ),
322
-								'description' => __( 'Determines what content to display on the single course page.', 'woothemes-sensei' ),
321
+								'name' => __('Single Course page displays:', 'woothemes-sensei'),
322
+								'description' => __('Determines what content to display on the single course page.', 'woothemes-sensei'),
323 323
 								'type' => 'select',
324 324
 								'default' => 'excerpt',
325 325
 								'section' => 'course-settings',
@@ -328,18 +328,18 @@  discard block
 block discarded – undo
328 328
 								);
329 329
 
330 330
 		$fields['course_archive_featured_enable'] = array(
331
-								'name' => __( 'Featured Courses Panel', 'woothemes-sensei' ),
332
-								'description' => __( 'Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
331
+								'name' => __('Featured Courses Panel', 'woothemes-sensei'),
332
+								'description' => __('Output the Featured Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
333 333
 								'type' => 'checkbox',
334 334
 								'default' => true,
335 335
 								'section' => 'course-settings'
336 336
 								);
337 337
 
338 338
 		$fields['course_archive_more_link_text'] = array(
339
-								'name' => __( 'More link text', 'woothemes-sensei' ),
340
-								'description' => __( 'The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei' ),
339
+								'name' => __('More link text', 'woothemes-sensei'),
340
+								'description' => __('The text that will be displayed on the Course Archive for the more courses link.', 'woothemes-sensei'),
341 341
 								'type' => 'text',
342
-								'default' => __ ( 'More', 'woothemes-sensei' ),
342
+								'default' => __('More', 'woothemes-sensei'),
343 343
 								'section' => 'course-settings',
344 344
 								'required' => 0
345 345
 								);
@@ -347,32 +347,32 @@  discard block
 block discarded – undo
347 347
 		// Lesson Settings
348 348
 
349 349
 		$fields['lesson_comments'] = array(
350
-								'name' => __( 'Allow Comments for Lessons', 'woothemes-sensei' ),
351
-								'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' ),
350
+								'name' => __('Allow Comments for Lessons', 'woothemes-sensei'),
351
+								'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'),
352 352
 								'type' => 'checkbox',
353 353
 								'default' => true,
354 354
 								'section' => 'lesson-settings'
355 355
 								);
356 356
 
357 357
 		$fields['lesson_author'] = array(
358
-								'name' => __( 'Display Lesson Author', 'woothemes-sensei' ),
359
-								'description' => __( 'Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei' ),
358
+								'name' => __('Display Lesson Author', 'woothemes-sensei'),
359
+								'description' => __('Output the Lesson Author on Course single page & Lesson archive page.', 'woothemes-sensei'),
360 360
 								'type' => 'checkbox',
361 361
 								'default' => true,
362 362
 								'section' => 'lesson-settings'
363 363
 								);
364 364
 
365 365
 		$fields['course_lesson_image_enable'] = array(
366
-								'name' => __( 'Course Lesson Images', 'woothemes-sensei' ),
367
-								'description' => __( 'Output the Lesson Image on the Single Course Page.', 'woothemes-sensei' ),
366
+								'name' => __('Course Lesson Images', 'woothemes-sensei'),
367
+								'description' => __('Output the Lesson Image on the Single Course Page.', 'woothemes-sensei'),
368 368
 								'type' => 'checkbox',
369 369
 								'default' => false,
370 370
 								'section' => 'lesson-settings'
371 371
 								);
372 372
 
373 373
 		$fields['lesson_archive_image_width'] = array(
374
-								'name' => __( 'Image Width - Course Lessons', 'woothemes-sensei' ),
375
-								'description' => __( 'The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
374
+								'name' => __('Image Width - Course Lessons', 'woothemes-sensei'),
375
+								'description' => __('The width in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
376 376
 								'type' => 'text',
377 377
 								'default' => '100',
378 378
 								'section' => 'lesson-settings',
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 								);
381 381
 
382 382
 		$fields['lesson_archive_image_height'] = array(
383
-								'name' => __( 'Image Height - Course Lessons', 'woothemes-sensei' ),
384
-								'description' => __( 'The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei' ),
383
+								'name' => __('Image Height - Course Lessons', 'woothemes-sensei'),
384
+								'description' => __('The height in pixels of the featured image for the Lessons on the Course Single page.', 'woothemes-sensei'),
385 385
 								'type' => 'text',
386 386
 								'default' => '100',
387 387
 								'section' => 'lesson-settings',
@@ -389,24 +389,24 @@  discard block
 block discarded – undo
389 389
 								);
390 390
 
391 391
 		$fields['lesson_archive_image_hard_crop'] = array(
392
-								'name' => __( 'Image Hard Crop - Course Lessons', 'woothemes-sensei' ),
393
-								'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>' ),
392
+								'name' => __('Image Hard Crop - Course Lessons', 'woothemes-sensei'),
393
+								'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>'),
394 394
 								'type' => 'checkbox',
395 395
 								'default' => false,
396 396
 								'section' => 'lesson-settings'
397 397
 								);
398 398
 
399 399
 		$fields['lesson_single_image_enable'] = array(
400
-								'name' => __( 'Single Lesson Images', 'woothemes-sensei' ),
401
-								'description' => __( 'Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei' ),
400
+								'name' => __('Single Lesson Images', 'woothemes-sensei'),
401
+								'description' => __('Output the Lesson Image on the Single Lesson Page.', 'woothemes-sensei'),
402 402
 								'type' => 'checkbox',
403 403
 								'default' => false,
404 404
 								'section' => 'lesson-settings'
405 405
 								);
406 406
 
407 407
 		$fields['lesson_single_image_width'] = array(
408
-								'name' => __( 'Image Width - Single', 'woothemes-sensei' ),
409
-								'description' => __( 'The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
408
+								'name' => __('Image Width - Single', 'woothemes-sensei'),
409
+								'description' => __('The width in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
410 410
 								'type' => 'text',
411 411
 								'default' => '100',
412 412
 								'section' => 'lesson-settings',
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 								);
415 415
 
416 416
 		$fields['lesson_single_image_height'] = array(
417
-								'name' => __( 'Image Height - Single', 'woothemes-sensei' ),
418
-								'description' => __( 'The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei' ),
417
+								'name' => __('Image Height - Single', 'woothemes-sensei'),
418
+								'description' => __('The height in pixels of the featured image for the Lessons single post page.', 'woothemes-sensei'),
419 419
 								'type' => 'text',
420 420
 								'default' => '100',
421 421
 								'section' => 'lesson-settings',
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
 								);
424 424
 
425 425
 		$fields['lesson_single_image_hard_crop'] = array(
426
-								'name' => __( 'Image Hard Crop - Single', 'woothemes-sensei' ),
427
-								'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>' ),
426
+								'name' => __('Image Hard Crop - Single', 'woothemes-sensei'),
427
+								'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>'),
428 428
 								'type' => 'checkbox',
429 429
 								'default' => false,
430 430
 								'section' => 'lesson-settings'
@@ -432,20 +432,20 @@  discard block
 block discarded – undo
432 432
 
433 433
 		// Learner Profile settings
434 434
 
435
-		$profile_url_base = apply_filters( 'sensei_learner_profiles_url_base', __( 'learner', 'woothemes-sensei') );
436
-		$profile_url_example = trailingslashit( get_site_url() ) . $profile_url_base . '/%username%';
435
+		$profile_url_base = apply_filters('sensei_learner_profiles_url_base', __('learner', 'woothemes-sensei'));
436
+		$profile_url_example = trailingslashit(get_site_url()).$profile_url_base.'/%username%';
437 437
 
438 438
 		$fields['learner_profile_enable'] = array(
439
-							'name' => __( 'Public learner profiles', 'woothemes-sensei' ),
440
-							'description' => sprintf( __( 'Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei' ), $profile_url_example ),
439
+							'name' => __('Public learner profiles', 'woothemes-sensei'),
440
+							'description' => sprintf(__('Enable public learner profiles that will be accessible to everyone. Profile URL format: %s', 'woothemes-sensei'), $profile_url_example),
441 441
 							'type' => 'checkbox',
442 442
 							'default' => true,
443 443
 							'section' => 'learner-profile-settings'
444 444
 							);
445 445
 
446 446
 		$fields['learner_profile_show_courses'] = array(
447
-							'name' => __( 'Show learner\'s courses', 'woothemes-sensei' ),
448
-							'description' => __( 'Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei' ),
447
+							'name' => __('Show learner\'s courses', 'woothemes-sensei'),
448
+							'description' => __('Display the learner\'s active and completed courses on their profile.', 'woothemes-sensei'),
449 449
 							'type' => 'checkbox',
450 450
 							'default' => true,
451 451
 							'section' => 'learner-profile-settings'
@@ -454,70 +454,70 @@  discard block
 block discarded – undo
454 454
 		// Email notifications
455 455
 
456 456
 		$learner_email_options = array(
457
-			'learner-graded-quiz' => __( 'Their quiz is graded (auto and manual grading)', 'woothemes-sensei' ),
458
-			'learner-completed-course' => __( 'They complete a course', 'woothemes-sensei' ),
457
+			'learner-graded-quiz' => __('Their quiz is graded (auto and manual grading)', 'woothemes-sensei'),
458
+			'learner-completed-course' => __('They complete a course', 'woothemes-sensei'),
459 459
 		);
460 460
 
461 461
 		$teacher_email_options = array(
462
-            'teacher-started-course' => __( 'A learner starts their course', 'woothemes-sensei' ),
463
-            'teacher-completed-course' => __( 'A learner completes their course', 'woothemes-sensei' ),
464
-            'teacher-completed-lesson' => __( 'A learner completes a lesson', 'woothemes-sensei' ),
465
-            'teacher-quiz-submitted' => __( 'A learner submits a quiz for grading', 'woothemes-sensei' ),
466
-			'teacher-new-message' => __( 'A learner sends a private message to a teacher', 'woothemes-sensei' ),
462
+            'teacher-started-course' => __('A learner starts their course', 'woothemes-sensei'),
463
+            'teacher-completed-course' => __('A learner completes their course', 'woothemes-sensei'),
464
+            'teacher-completed-lesson' => __('A learner completes a lesson', 'woothemes-sensei'),
465
+            'teacher-quiz-submitted' => __('A learner submits a quiz for grading', 'woothemes-sensei'),
466
+			'teacher-new-message' => __('A learner sends a private message to a teacher', 'woothemes-sensei'),
467 467
 		);
468 468
 
469 469
 		$global_email_options = array(
470
-			'new-message-reply' => __( 'They receive a reply to their private message', 'woothemes-sensei' ),
470
+			'new-message-reply' => __('They receive a reply to their private message', 'woothemes-sensei'),
471 471
 		);
472 472
 
473 473
 		$fields['email_learners'] = array(
474
-								'name' => __( 'Emails Sent to Learners', 'woothemes-sensei' ),
475
-								'description' => __( 'Select the notifications that will be sent to learners.', 'woothemes-sensei' ),
474
+								'name' => __('Emails Sent to Learners', 'woothemes-sensei'),
475
+								'description' => __('Select the notifications that will be sent to learners.', 'woothemes-sensei'),
476 476
 								'type' => 'multicheck',
477 477
 								'options' => $learner_email_options,
478
-								'defaults' => array( 'learner-graded-quiz', 'learner-completed-course' ),
478
+								'defaults' => array('learner-graded-quiz', 'learner-completed-course'),
479 479
 								'section' => 'email-notification-settings'
480 480
 								);
481 481
 
482 482
 		$fields['email_teachers'] = array(
483
-								'name' => __( 'Emails Sent to Teachers', 'woothemes-sensei' ),
484
-								'description' => __( 'Select the notifications that will be sent to teachers.', 'woothemes-sensei' ),
483
+								'name' => __('Emails Sent to Teachers', 'woothemes-sensei'),
484
+								'description' => __('Select the notifications that will be sent to teachers.', 'woothemes-sensei'),
485 485
 								'type' => 'multicheck',
486 486
 								'options' => $teacher_email_options,
487
-								'defaults' => array( 'teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message' ),
487
+								'defaults' => array('teacher-completed-course', 'teacher-started-course', 'teacher-quiz-submitted', 'teacher-new-message'),
488 488
 								'section' => 'email-notification-settings'
489 489
 								);
490 490
 
491 491
 		$fields['email_global'] = array(
492
-								'name' => __( 'Emails Sent to All Users', 'woothemes-sensei' ),
493
-								'description' => __( 'Select the notifications that will be sent to all users.', 'woothemes-sensei' ),
492
+								'name' => __('Emails Sent to All Users', 'woothemes-sensei'),
493
+								'description' => __('Select the notifications that will be sent to all users.', 'woothemes-sensei'),
494 494
 								'type' => 'multicheck',
495 495
 								'options' => $global_email_options,
496
-								'defaults' => array( 'new-message-reply' ),
496
+								'defaults' => array('new-message-reply'),
497 497
 								'section' => 'email-notification-settings'
498 498
 								);
499 499
 
500 500
 		$fields['email_from_name'] = array(
501
-								'name' => __( '"From" Name', 'woothemes-sensei' ),
502
-								'description' => __( 'The name from which all emails will be sent.', 'woothemes-sensei' ),
501
+								'name' => __('"From" Name', 'woothemes-sensei'),
502
+								'description' => __('The name from which all emails will be sent.', 'woothemes-sensei'),
503 503
 								'type' => 'text',
504
-								'default' => get_bloginfo( 'name' ),
504
+								'default' => get_bloginfo('name'),
505 505
 								'section' => 'email-notification-settings',
506 506
 								'required' => 1
507 507
 								);
508 508
 
509 509
 		$fields['email_from_address'] = array(
510
-								'name' => __( '"From" Address', 'woothemes-sensei' ),
511
-								'description' => __( 'The address from which all emails will be sent.', 'woothemes-sensei' ),
510
+								'name' => __('"From" Address', 'woothemes-sensei'),
511
+								'description' => __('The address from which all emails will be sent.', 'woothemes-sensei'),
512 512
 								'type' => 'text',
513
-								'default' => get_bloginfo( 'admin_email' ),
513
+								'default' => get_bloginfo('admin_email'),
514 514
 								'section' => 'email-notification-settings',
515 515
 								'required' => 1
516 516
 								);
517 517
 
518 518
 		$fields['email_header_image'] = array(
519
-								'name' => __( 'Header Image', 'woothemes-sensei' ),
520
-								'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>' ),
519
+								'name' => __('Header Image', 'woothemes-sensei'),
520
+								'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>'),
521 521
 								'type' => 'text',
522 522
 								'default' => '',
523 523
 								'section' => 'email-notification-settings',
@@ -525,17 +525,17 @@  discard block
 block discarded – undo
525 525
 								);
526 526
 
527 527
 		$fields['email_footer_text'] = array(
528
-								'name' => __( 'Email Footer Text', 'woothemes-sensei' ),
529
-								'description' => __( 'The text to appear in the footer of Sensei emails.', 'woothemes-sensei' ),
528
+								'name' => __('Email Footer Text', 'woothemes-sensei'),
529
+								'description' => __('The text to appear in the footer of Sensei emails.', 'woothemes-sensei'),
530 530
 								'type' => 'textarea',
531
-								'default' => sprintf( __( '%1$s - Powered by Sensei', 'woothemes-sensei' ), get_bloginfo( 'name' ) ),
531
+								'default' => sprintf(__('%1$s - Powered by Sensei', 'woothemes-sensei'), get_bloginfo('name')),
532 532
 								'section' => 'email-notification-settings',
533 533
 								'required' => 0
534 534
 								);
535 535
 
536 536
 		$fields['email_base_color'] = array(
537
-								'name' => __( 'Base Colour', 'woothemes-sensei' ),
538
-								'description' => sprintf( __( 'The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
537
+								'name' => __('Base Colour', 'woothemes-sensei'),
538
+								'description' => sprintf(__('The base colour for Sensei email templates. Default %1$s#557da1%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
539 539
 								'type' => 'color',
540 540
 								'default' => '#557da1',
541 541
 								'section' => 'email-notification-settings',
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 								);
544 544
 
545 545
 		$fields['email_background_color'] = array(
546
-								'name' => __( 'Background Colour', 'woothemes-sensei' ),
547
-								'description' => sprintf( __( 'The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
546
+								'name' => __('Background Colour', 'woothemes-sensei'),
547
+								'description' => sprintf(__('The background colour for Sensei email templates. Default %1$s#f5f5f5%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
548 548
 								'type' => 'color',
549 549
 								'default' => '#f5f5f5',
550 550
 								'section' => 'email-notification-settings',
@@ -552,8 +552,8 @@  discard block
 block discarded – undo
552 552
 								);
553 553
 
554 554
 		$fields['email_body_background_color'] = array(
555
-								'name' => __( 'Body Background Colour', 'woothemes-sensei' ),
556
-								'description' => sprintf( __( 'The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
555
+								'name' => __('Body Background Colour', 'woothemes-sensei'),
556
+								'description' => sprintf(__('The main body background colour for Sensei email templates. Default %1$s#fdfdfd%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
557 557
 								'type' => 'color',
558 558
 								'default' => '#fdfdfd',
559 559
 								'section' => 'email-notification-settings',
@@ -561,35 +561,35 @@  discard block
 block discarded – undo
561 561
 								);
562 562
 
563 563
 		$fields['email_text_color'] = array(
564
-								'name' => __( 'Body Text Colour', 'woothemes-sensei' ),
565
-								'description' => sprintf( __( 'The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei' ), '<code>', '</code>' ),
564
+								'name' => __('Body Text Colour', 'woothemes-sensei'),
565
+								'description' => sprintf(__('The main body text colour for Sensei email templates. Default %1$s#505050%2$s.', 'woothemes-sensei'), '<code>', '</code>'),
566 566
 								'type' => 'color',
567 567
 								'default' => '#505050',
568 568
 								'section' => 'email-notification-settings',
569 569
 								'required' => 1
570 570
 								);
571 571
 
572
-		if ( Sensei_WC::is_woocommerce_present() ) {
572
+		if (Sensei_WC::is_woocommerce_present()) {
573 573
 			// WooCommerce Settings
574 574
     		$fields['woocommerce_enabled'] = array(
575
-									'name' => __( 'Enable WooCommerce Courses', 'woothemes-sensei' ),
576
-									'description' => __( 'Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei' ),
575
+									'name' => __('Enable WooCommerce Courses', 'woothemes-sensei'),
576
+									'description' => __('Use WooCommerce to sell Courses by linking a Product to a Course.', 'woothemes-sensei'),
577 577
 									'type' => 'checkbox',
578 578
 									'default' => true,
579 579
 									'section' => 'woocommerce-settings'
580 580
 									);
581 581
 
582 582
 			$fields['course_archive_free_enable'] = array(
583
-									'name' => __( 'Free Courses Panel', 'woothemes-sensei' ),
584
-									'description' => __( 'Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
583
+									'name' => __('Free Courses Panel', 'woothemes-sensei'),
584
+									'description' => __('Output the Free Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
585 585
 									'type' => 'checkbox',
586 586
 									'default' => true,
587 587
 									'section' => 'woocommerce-settings'
588 588
 									);
589 589
 
590 590
 			$fields['course_archive_paid_enable'] = array(
591
-									'name' => __( 'Paid Courses Panel', 'woothemes-sensei' ),
592
-									'description' => __( 'Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei' ),
591
+									'name' => __('Paid Courses Panel', 'woothemes-sensei'),
592
+									'description' => __('Output the Paid Courses Panel on the Course Archive Page.', 'woothemes-sensei'),
593 593
 									'type' => 'checkbox',
594 594
 									'default' => true,
595 595
 									'section' => 'woocommerce-settings'
@@ -597,18 +597,18 @@  discard block
 block discarded – undo
597 597
 
598 598
 		} // End If Statement
599 599
 
600
-		if ( 'en_US' !== get_locale() ) {
600
+		if ('en_US' !== get_locale()) {
601 601
 			$fields['install_language_pack'] = array(
602
-				'name'        => __( 'Install Language Pack', 'woothemes-sensei' ),
603
-				'description' => __( 'Use this action to install or re-install translation for your language if available.', 'woothemes-sensei' ),
602
+				'name'        => __('Install Language Pack', 'woothemes-sensei'),
603
+				'description' => __('Use this action to install or re-install translation for your language if available.', 'woothemes-sensei'),
604 604
 				'type'        => 'button',
605 605
 				'section'     => 'language-settings',
606 606
 				'target'      => Sensei_Language_Pack_Manager::get_install_uri(),
607
-				'label'       => __( 'Install', 'woothemes-sensei' )
607
+				'label'       => __('Install', 'woothemes-sensei')
608 608
 			);
609 609
 		}
610 610
 
611
-		$this->fields = apply_filters( 'sensei_settings_fields', $fields );
611
+		$this->fields = apply_filters('sensei_settings_fields', $fields);
612 612
 
613 613
 	} // End init_fields()
614 614
 
@@ -618,20 +618,20 @@  discard block
 block discarded – undo
618 618
 	 * @param  $include_milliseconds (default: true) Whether or not to include milliseconds between 0 and 1.
619 619
 	 * @return array Options between 0.1 and 10 seconds.
620 620
 	 */
621
-	private function get_duration_options ( $include_milliseconds = true ) {
622
-		$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' );
621
+	private function get_duration_options($include_milliseconds = true) {
622
+		$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');
623 623
 		$options = array();
624 624
 
625
-		if ( true == (bool)$include_milliseconds ) {
626
-			$milliseconds = array( '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9' );
627
-			foreach ( $milliseconds as $k => $v ) {
625
+		if (true == (bool) $include_milliseconds) {
626
+			$milliseconds = array('0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9');
627
+			foreach ($milliseconds as $k => $v) {
628 628
 				$options[$v] = $v;
629 629
 			}
630 630
 		} else {
631 631
 			$options['0.5'] = '0.5';
632 632
 		}
633 633
 
634
-		foreach ( $numbers as $k => $v ) {
634
+		foreach ($numbers as $k => $v) {
635 635
 			$options[$v] = $v;
636 636
 		}
637 637
 
@@ -647,25 +647,25 @@  discard block
 block discarded – undo
647 647
 	private function pages_array() {
648 648
 		// REFACTOR - Transform this into a field type instead.
649 649
 		// Setup an array of portfolio gallery terms for a dropdown.
650
-		$args = array( 'echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC' );
651
-		$pages_dropdown = wp_dropdown_pages( $args );
650
+		$args = array('echo' => 0, 'hierarchical' => 1, 'sort_column' => 'post_title', 'sort_order' => 'ASC');
651
+		$pages_dropdown = wp_dropdown_pages($args);
652 652
 		$page_items = array();
653 653
 
654 654
 		// Quick string hack to make sure we get the pages with the indents.
655
-		$pages_dropdown = str_replace( "<select class='' name='page_id' id='page_id'>", '', $pages_dropdown );
656
-		$pages_dropdown = str_replace( '</select>', '', $pages_dropdown );
657
-		$pages_split = explode( '</option>', $pages_dropdown );
655
+		$pages_dropdown = str_replace("<select class='' name='page_id' id='page_id'>", '', $pages_dropdown);
656
+		$pages_dropdown = str_replace('</select>', '', $pages_dropdown);
657
+		$pages_split = explode('</option>', $pages_dropdown);
658 658
 
659
-		$page_items[] = __( 'Select a Page:', 'woothemes-sensei' );
659
+		$page_items[] = __('Select a Page:', 'woothemes-sensei');
660 660
 
661
-		foreach ( $pages_split as $k => $v ) {
661
+		foreach ($pages_split as $k => $v) {
662 662
 		    $id = '';
663 663
 		    // Get the ID value.
664
-		    preg_match( '/value="(.*?)"/i', $v, $matches );
664
+		    preg_match('/value="(.*?)"/i', $v, $matches);
665 665
 
666
-		    if ( isset( $matches[1] ) ) {
666
+		    if (isset($matches[1])) {
667 667
 		        $id = $matches[1];
668
-		        $page_items[$id] = trim( strip_tags( $v ) );
668
+		        $page_items[$id] = trim(strip_tags($v));
669 669
 		    } // End If Statement
670 670
 		} // End For Loop
671 671
 
@@ -689,10 +689,10 @@  discard block
 block discarded – undo
689 689
      *
690 690
      * @since 1.9.0
691 691
      */
692
-    public static function flush_rewrite_rules(){
692
+    public static function flush_rewrite_rules() {
693 693
 
694
-        if ( isset( $_POST[ 'option_page' ] ) && 'woothemes-sensei-settings' == $_POST[ 'option_page' ]
695
-            && isset( $_POST[ 'action' ] ) && 'update' == $_POST[ 'action' ] ) {
694
+        if (isset($_POST['option_page']) && 'woothemes-sensei-settings' == $_POST['option_page']
695
+            && isset($_POST['action']) && 'update' == $_POST['action']) {
696 696
 
697 697
             Sensei()->initiate_rewrite_rules_flush();
698 698
 
@@ -706,4 +706,4 @@  discard block
 block discarded – undo
706 706
  * @ignore only for backward compatibility
707 707
  * @since 1.9.0
708 708
  */
709
-class WooThemes_Sensei_Settings extends Sensei_Settings{}
709
+class WooThemes_Sensei_Settings extends Sensei_Settings {}
Please login to merge, or discard this patch.
templates/single-course/modules.php 1 patch
Spacing   +9 added lines, -9 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;
2
+if ( ! defined('ABSPATH')) exit;
3 3
 /**
4 4
  * List the Course Modules and Lesson in these modules
5 5
  *
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
 
31 31
 ?>
32 32
 
33
-<?php if( sensei_have_modules() ): ?>
33
+<?php if (sensei_have_modules()): ?>
34 34
 
35
-    <?php while ( sensei_have_modules() ): sensei_setup_module(); ?>
36
-        <?php if( sensei_module_has_lessons() ): ?>
35
+    <?php while (sensei_have_modules()): sensei_setup_module(); ?>
36
+        <?php if (sensei_module_has_lessons()): ?>
37 37
 
38 38
             <article class="module">
39 39
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
                     <h2>
59 59
 
60
-                        <a href="<?php sensei_the_module_permalink(); ?>" title="<?php sensei_the_module_title_attribute();?>">
60
+                        <a href="<?php sensei_the_module_permalink(); ?>" title="<?php sensei_the_module_title_attribute(); ?>">
61 61
 
62 62
                             <?php sensei_the_module_title(); ?>
63 63
 
@@ -81,17 +81,17 @@  discard block
 block discarded – undo
81 81
 
82 82
                         <ul class="lessons-list" >
83 83
 
84
-                            <?php while( sensei_module_has_lessons() ): the_post(); ?>
84
+                            <?php while (sensei_module_has_lessons()): the_post(); ?>
85 85
 
86
-                                <li class="<?php sensei_the_lesson_status_class();?>">
86
+                                <li class="<?php sensei_the_lesson_status_class(); ?>">
87 87
 
88 88
                                     <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute() ?>" >
89 89
 
90 90
                                         <?php the_title(); ?>
91 91
 
92 92
 	                                    <?php
93
-	                                    $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
94
-	                                    if ( Sensei_Utils::is_preview_lesson( get_the_ID() ) && ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ) { ?>
93
+	                                    $course_id = Sensei()->lesson->get_course_id(get_the_ID());
94
+	                                    if (Sensei_Utils::is_preview_lesson(get_the_ID()) && ! Sensei_Utils::user_started_course($course_id, get_current_user_id())) { ?>
95 95
 
96 96
 	                                        <span class="preview-label">Free Preview</span>
97 97
 
Please login to merge, or discard this patch.
includes/class-sensei-frontend.php 1 patch
Spacing   +452 added lines, -452 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 Frontend Class
@@ -20,78 +20,78 @@  discard block
 block discarded – undo
20 20
 	 * Constructor.
21 21
 	 * @since  1.0.0
22 22
 	 */
23
-	public function __construct () {
23
+	public function __construct() {
24 24
 
25 25
 		// Template output actions
26
-		add_action( 'sensei_before_main_content', array( $this, 'sensei_output_content_wrapper' ), 10 );
27
-		add_action( 'sensei_after_main_content', array( $this, 'sensei_output_content_wrapper_end' ), 10 );
28
-		add_action( 'sensei_lesson_archive_lesson_title', array( $this, 'sensei_lesson_archive_lesson_title' ), 10 );
26
+		add_action('sensei_before_main_content', array($this, 'sensei_output_content_wrapper'), 10);
27
+		add_action('sensei_after_main_content', array($this, 'sensei_output_content_wrapper_end'), 10);
28
+		add_action('sensei_lesson_archive_lesson_title', array($this, 'sensei_lesson_archive_lesson_title'), 10);
29 29
 
30 30
 		// 1.2.1
31
-		add_action( 'wp_head', array( $this, 'sensei_complete_lesson' ), 10 );
32
-		add_action( 'wp_head', array( $this, 'sensei_complete_course' ), 10 );
33
-		add_action( 'sensei_frontend_messages', array( $this, 'sensei_frontend_messages' ) );
34
-		add_action( 'sensei_lesson_video', array( $this, 'sensei_lesson_video' ), 10, 1 );
35
-		add_action( 'sensei_complete_lesson_button', array( $this, 'sensei_complete_lesson_button' ) );
36
-		add_action( 'sensei_reset_lesson_button', array( $this, 'sensei_reset_lesson_button' ) );
31
+		add_action('wp_head', array($this, 'sensei_complete_lesson'), 10);
32
+		add_action('wp_head', array($this, 'sensei_complete_course'), 10);
33
+		add_action('sensei_frontend_messages', array($this, 'sensei_frontend_messages'));
34
+		add_action('sensei_lesson_video', array($this, 'sensei_lesson_video'), 10, 1);
35
+		add_action('sensei_complete_lesson_button', array($this, 'sensei_complete_lesson_button'));
36
+		add_action('sensei_reset_lesson_button', array($this, 'sensei_reset_lesson_button'));
37 37
 
38
-		add_action( 'sensei_course_archive_meta', array( $this, 'sensei_course_archive_meta' ) );
38
+		add_action('sensei_course_archive_meta', array($this, 'sensei_course_archive_meta'));
39 39
 
40
-		add_action( 'sensei_lesson_tag_main_content', array( $this, 'sensei_lesson_archive_main_content' ), 10 );
41
-		add_action( 'sensei_no_permissions_main_content', array( $this, 'sensei_no_permissions_main_content' ), 10 );
40
+		add_action('sensei_lesson_tag_main_content', array($this, 'sensei_lesson_archive_main_content'), 10);
41
+		add_action('sensei_no_permissions_main_content', array($this, 'sensei_no_permissions_main_content'), 10);
42 42
 
43
-		add_action( 'sensei_lesson_meta', array( $this, 'sensei_lesson_meta' ), 10 );
44
-		add_action( 'sensei_single_course_content_inside_before', array( $this, 'sensei_course_start' ), 10 );
43
+		add_action('sensei_lesson_meta', array($this, 'sensei_lesson_meta'), 10);
44
+		add_action('sensei_single_course_content_inside_before', array($this, 'sensei_course_start'), 10);
45 45
 
46 46
 		// add_filter( 'get_comments_number', array( $this, 'sensei_lesson_comment_count' ), 1 );
47
-		add_filter( 'the_title', array( $this, 'sensei_lesson_preview_title' ), 10, 2 );
47
+		add_filter('the_title', array($this, 'sensei_lesson_preview_title'), 10, 2);
48 48
 
49 49
 		//1.6.2
50
-		add_filter( 'wp_login_failed', array( $this, 'sensei_login_fail_redirect' ), 10 );
51
-		add_filter( 'init', array( $this, 'sensei_handle_login_request' ), 10 );
50
+		add_filter('wp_login_failed', array($this, 'sensei_login_fail_redirect'), 10);
51
+		add_filter('init', array($this, 'sensei_handle_login_request'), 10);
52 52
 		//1.6.3
53
-		add_action( 'init', array( $this, 'sensei_process_registration' ), 2 );
53
+		add_action('init', array($this, 'sensei_process_registration'), 2);
54 54
 		//1.7.0
55
-		add_action( 'sensei_pagination', array( $this, 'sensei_breadcrumb' ), 80, 1 );
55
+		add_action('sensei_pagination', array($this, 'sensei_breadcrumb'), 80, 1);
56 56
 
57 57
 		// Fix pagination for course archive pages when filtering by course type
58
-		add_filter( 'pre_get_posts', array( $this, 'sensei_course_archive_pagination' ) );
58
+		add_filter('pre_get_posts', array($this, 'sensei_course_archive_pagination'));
59 59
 
60 60
 		// Scripts and Styles
61
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
62
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
61
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
62
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
63 63
 
64 64
 		// Custom Menu Item filters
65
-		add_filter( 'wp_setup_nav_menu_item', array( $this, 'sensei_setup_nav_menu_item' ) );
66
-		add_filter( 'wp_nav_menu_objects', array( $this, 'sensei_wp_nav_menu_objects' ) );
65
+		add_filter('wp_setup_nav_menu_item', array($this, 'sensei_setup_nav_menu_item'));
66
+		add_filter('wp_nav_menu_objects', array($this, 'sensei_wp_nav_menu_objects'));
67 67
 		// Search Results filters
68
-		add_filter( 'post_class', array( $this, 'sensei_search_results_classes' ), 10 );
68
+		add_filter('post_class', array($this, 'sensei_search_results_classes'), 10);
69 69
 		// Only show course & lesson excerpts in search results
70
-		add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) );
70
+		add_filter('the_content', array($this, 'sensei_search_results_excerpt'));
71 71
 
72 72
         //Use WooCommerce filter to show admin bar to Teachers.
73
-        add_action( 'init', array( $this, 'sensei_show_admin_bar') );
73
+        add_action('init', array($this, 'sensei_show_admin_bar'));
74 74
 
75 75
         // Remove course from active courses if an order is cancelled or refunded
76
-		add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
77
-		add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
78
-		add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 );
79
-		add_action( 'woocommerce_order_status_processing_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
80
-		add_action( 'woocommerce_order_status_completed_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
81
-		add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'remove_active_course' ), 10, 1 );
76
+		add_action('woocommerce_order_status_processing_to_cancelled', array($this, 'remove_active_course'), 10, 1);
77
+		add_action('woocommerce_order_status_completed_to_cancelled', array($this, 'remove_active_course'), 10, 1);
78
+		add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'remove_active_course'), 10, 1);
79
+		add_action('woocommerce_order_status_processing_to_refunded', array($this, 'remove_active_course'), 10, 1);
80
+		add_action('woocommerce_order_status_completed_to_refunded', array($this, 'remove_active_course'), 10, 1);
81
+		add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'remove_active_course'), 10, 1);
82 82
 
83 83
 		// Make sure correct courses are marked as active for users
84
-		add_action( 'sensei_before_my_courses', array( $this, 'activate_purchased_courses' ), 10, 1 );
85
-		add_action( 'sensei_single_course_content_inside_before', array( $this, 'activate_purchased_single_course' ), 10 );
84
+		add_action('sensei_before_my_courses', array($this, 'activate_purchased_courses'), 10, 1);
85
+		add_action('sensei_single_course_content_inside_before', array($this, 'activate_purchased_single_course'), 10);
86 86
 
87 87
 		// Lesson tags
88
-		add_action( 'sensei_lesson_meta_extra', array( $this, 'lesson_tags_display' ), 10, 1 );
89
-		add_action( 'pre_get_posts', array( $this, 'lesson_tag_archive_filter' ), 10, 1 );
90
-		add_filter( 'sensei_lessons_archive_text', array( $this, 'lesson_tag_archive_header' ) );
91
-		add_action( 'sensei_loop_lesson_inside_before', array( $this, 'lesson_tag_archive_description' ), 11 );
88
+		add_action('sensei_lesson_meta_extra', array($this, 'lesson_tags_display'), 10, 1);
89
+		add_action('pre_get_posts', array($this, 'lesson_tag_archive_filter'), 10, 1);
90
+		add_filter('sensei_lessons_archive_text', array($this, 'lesson_tag_archive_header'));
91
+		add_action('sensei_loop_lesson_inside_before', array($this, 'lesson_tag_archive_description'), 11);
92 92
 
93 93
 		// Hide Sensei activity comments from lesson and course pages
94
-		add_filter( 'wp_list_comments_args', array( $this, 'hide_sensei_activity' ) );
94
+		add_filter('wp_list_comments_args', array($this, 'hide_sensei_activity'));
95 95
 	} // End __construct()
96 96
 
97 97
 	/**
@@ -101,11 +101,11 @@  discard block
 block discarded – undo
101 101
 	 * @since  1.7.3
102 102
 	 * @return array|mixed
103 103
 	 */
104
-	public function __get( $key ) {
104
+	public function __get($key) {
105 105
 
106
-		if ( 'lesson' == $key || 'course' == $key ) {
107
-			if ( WP_DEBUG ) {
108
-				trigger_error( sprintf( 'Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3' ) );
106
+		if ('lesson' == $key || 'course' == $key) {
107
+			if (WP_DEBUG) {
108
+				trigger_error(sprintf('Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3'));
109 109
 			}
110 110
 			return Sensei()->$key;
111 111
 		}
@@ -118,32 +118,32 @@  discard block
 block discarded – undo
118 118
 	 * @since  1.0.0
119 119
 	 * @return void
120 120
 	 */
121
-	public function enqueue_scripts () {
121
+	public function enqueue_scripts() {
122 122
 
123 123
 		$disable_js = false;
124
-		if ( isset( Sensei()->settings->settings[ 'js_disable' ] ) ) {
125
-			$disable_js = Sensei()->settings->settings[ 'js_disable' ];
124
+		if (isset(Sensei()->settings->settings['js_disable'])) {
125
+			$disable_js = Sensei()->settings->settings['js_disable'];
126 126
 		} // End If Statement
127
-		if ( ! $disable_js ) {
127
+		if ( ! $disable_js) {
128 128
 
129
-			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
129
+			$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
130 130
 
131 131
 			// My Courses tabs script
132
-			wp_register_script( Sensei()->token . '-user-dashboard', esc_url( Sensei()->plugin_url . 'assets/js/user-dashboard' . $suffix . '.js' ), array( 'jquery-ui-tabs' ), Sensei()->version, true );
133
-			wp_enqueue_script( Sensei()->token . '-user-dashboard' );
132
+			wp_register_script(Sensei()->token.'-user-dashboard', esc_url(Sensei()->plugin_url.'assets/js/user-dashboard'.$suffix.'.js'), array('jquery-ui-tabs'), Sensei()->version, true);
133
+			wp_enqueue_script(Sensei()->token.'-user-dashboard');
134 134
 
135 135
 
136 136
             // Course Archive javascript
137
-            if( is_post_type_archive( 'course' ) ){
137
+            if (is_post_type_archive('course')) {
138 138
 
139
-                wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true );
140
-                wp_enqueue_script( 'sensei-course-archive-js' );
139
+                wp_register_script('sensei-course-archive-js', esc_url(Sensei()->plugin_url.'assets/js/frontend/course-archive'.$suffix.'.js'), array('jquery'), '1', true);
140
+                wp_enqueue_script('sensei-course-archive-js');
141 141
 
142 142
             }
143 143
 
144 144
 
145 145
 			// Allow additional scripts to be loaded
146
-			do_action( 'sensei_additional_scripts' );
146
+			do_action('sensei_additional_scripts');
147 147
 
148 148
 		} // End If Statement
149 149
 
@@ -154,23 +154,23 @@  discard block
 block discarded – undo
154 154
 	 * @since  1.0.0
155 155
 	 * @return void
156 156
 	 */
157
-	public function enqueue_styles () {
157
+	public function enqueue_styles() {
158 158
 
159 159
 		$disable_styles = false;
160
-		if ( isset( Sensei()->settings->settings[ 'styles_disable' ] ) ) {
161
-			$disable_styles = Sensei()->settings->settings[ 'styles_disable' ];
160
+		if (isset(Sensei()->settings->settings['styles_disable'])) {
161
+			$disable_styles = Sensei()->settings->settings['styles_disable'];
162 162
 		} // End If Statement
163 163
 
164 164
 		// Add filter for theme overrides
165
-		$disable_styles = apply_filters( 'sensei_disable_styles', $disable_styles );
165
+		$disable_styles = apply_filters('sensei_disable_styles', $disable_styles);
166 166
 
167
-		if ( ! $disable_styles ) {
167
+		if ( ! $disable_styles) {
168 168
 
169
-			wp_register_style( Sensei()->token . '-frontend', Sensei()->plugin_url . 'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen' );
170
-			wp_enqueue_style( Sensei()->token . '-frontend' );
169
+			wp_register_style(Sensei()->token.'-frontend', Sensei()->plugin_url.'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen');
170
+			wp_enqueue_style(Sensei()->token.'-frontend');
171 171
 
172 172
 			// Allow additional stylesheets to be loaded
173
-			do_action( 'sensei_additional_styles' );
173
+			do_action('sensei_additional_styles');
174 174
 
175 175
 		} // End If Statement
176 176
 
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
 	 * @param string $name (default: '')
187 187
 	 * @return void
188 188
 	 */
189
-	function sensei_get_template_part( $slug, $name = '' ) {
189
+	function sensei_get_template_part($slug, $name = '') {
190 190
 
191
-        _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' );
192
-        Sensei_Templates::get_part( $slug, $name );
191
+        _deprecated_function('class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part');
192
+        Sensei_Templates::get_part($slug, $name);
193 193
 
194 194
 	} // End sensei_get_template_part()
195 195
 
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 	 * @param string $default_path (default: '')
205 205
 	 * @return void
206 206
 	 */
207
-	function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
207
+	function sensei_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
208 208
 
209
-        _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' );
210
-        Sensei_Templates::get_template($template_name, $args, $template_path, $default_path  );
209
+        _deprecated_function('sensei_get_template', '1.9.0', 'Sensei_Templates::get_template');
210
+        Sensei_Templates::get_template($template_name, $args, $template_path, $default_path);
211 211
 
212 212
 	} // End sensei_get_template()
213 213
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 	 * @param string $default_path (default: '')
222 222
 	 * @return void
223 223
 	 */
224
-	function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) {
224
+	function sensei_locate_template($template_name, $template_path = '', $default_path = '') {
225 225
 
226
-        _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' );
227
-        Sensei_Templates::locate_template( $template_name, $template_path, $default_path );
226
+        _deprecated_function('sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template');
227
+        Sensei_Templates::locate_template($template_name, $template_path, $default_path);
228 228
 
229 229
 	} // End sensei_locate_template()
230 230
 
@@ -238,20 +238,20 @@  discard block
 block discarded – undo
238 238
 	function sensei_output_content_wrapper() {
239 239
 
240 240
 	    // backwards compatibility check for old location under the wrappers directory of the active theme
241
-        $backwards_compatible_wrapper_location =   array(
242
-            Sensei()->template_url . 'wrappers/wrapper-start.php',
241
+        $backwards_compatible_wrapper_location = array(
242
+            Sensei()->template_url.'wrappers/wrapper-start.php',
243 243
             'wrappers/wrapper-start.php'
244 244
         );
245 245
 
246
-        $template = locate_template( $backwards_compatible_wrapper_location );
247
-        if( !empty( $template ) ){
246
+        $template = locate_template($backwards_compatible_wrapper_location);
247
+        if ( ! empty($template)) {
248 248
 
249
-            Sensei_Templates::get_template( 'wrappers/wrapper-start.php' );
249
+            Sensei_Templates::get_template('wrappers/wrapper-start.php');
250 250
             return;
251 251
 
252 252
         }
253 253
 
254
-		Sensei_Templates::get_template( 'globals/wrapper-start.php' );
254
+		Sensei_Templates::get_template('globals/wrapper-start.php');
255 255
 
256 256
 	} // End sensei_output_content_wrapper()
257 257
 
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	function sensei_output_content_wrapper_end() {
266 266
 
267 267
 	    // backwards compatibility check for old location under the wrappers directory of the active theme
268
-        $backwards_compatible_wrapper_location =   array(
269
-            Sensei()->template_url . 'wrappers/wrapper-end.php',
268
+        $backwards_compatible_wrapper_location = array(
269
+            Sensei()->template_url.'wrappers/wrapper-end.php',
270 270
             'wrappers/wrapper-end.php'
271 271
         );
272 272
 
273
-        $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location );
274
-        if( !empty( $backwards_compatible_template ) ){
273
+        $backwards_compatible_template = locate_template($backwards_compatible_wrapper_location);
274
+        if ( ! empty($backwards_compatible_template)) {
275 275
 
276
-            Sensei_Templates::get_template( 'wrappers/wrapper-end.php' );
276
+            Sensei_Templates::get_template('wrappers/wrapper-end.php');
277 277
             return;
278 278
 
279 279
         }
280 280
 
281 281
 
282
-		Sensei_Templates::get_template( 'globals/wrapper-end.php' );
282
+		Sensei_Templates::get_template('globals/wrapper-end.php');
283 283
 
284 284
 	} // End sensei_output_content_wrapper_end()
285 285
 
@@ -292,57 +292,57 @@  discard block
 block discarded – undo
292 292
 	 */
293 293
 	public static function load_content_pagination() {
294 294
 
295
-        if( is_singular('course') ) {
295
+        if (is_singular('course')) {
296 296
 
297 297
             // backwards compatibility check for old location under the wrappers directory of the active theme
298
-            $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) );
299
-            if( !empty( $template ) ){
298
+            $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-posts.php'));
299
+            if ( ! empty($template)) {
300 300
 
301
-                Sensei_Templates::get_template( 'wrappers/pagination-posts.php' );
301
+                Sensei_Templates::get_template('wrappers/pagination-posts.php');
302 302
                 return;
303 303
 
304 304
             }
305 305
 
306
-			Sensei_Templates::get_template( 'globals/pagination-posts.php' );
306
+			Sensei_Templates::get_template('globals/pagination-posts.php');
307 307
 
308
-		} elseif( is_singular('lesson') ) {
308
+		} elseif (is_singular('lesson')) {
309 309
 
310 310
 		    // backwards compatibility check for old location under the wrappers directory of the active theme
311
-		    $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) );
312
-            if( !empty( $template ) ){
311
+		    $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-lesson.php'));
312
+            if ( ! empty($template)) {
313 313
 
314
-                Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' );
314
+                Sensei_Templates::get_template('wrappers/pagination-lesson.php');
315 315
                 return;
316 316
 
317 317
             }
318 318
 
319
-			Sensei_Templates::get_template( 'globals/pagination-lesson.php' );
319
+			Sensei_Templates::get_template('globals/pagination-lesson.php');
320 320
 
321
-		} elseif( is_singular('quiz') ) {
321
+		} elseif (is_singular('quiz')) {
322 322
 
323 323
 		    // backwards compatibility check for old location under the wrappers directory of the active theme
324
-		    $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) );
325
-            if( !empty( $template ) ){
324
+		    $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-quiz.php'));
325
+            if ( ! empty($template)) {
326 326
 
327
-                Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' );
327
+                Sensei_Templates::get_template('wrappers/pagination-quiz.php');
328 328
                 return;
329 329
 
330 330
             }
331 331
 
332
-			Sensei_Templates::get_template( 'globals/pagination-quiz.php' );
332
+			Sensei_Templates::get_template('globals/pagination-quiz.php');
333 333
 
334 334
 		} else {
335 335
 
336 336
             // backwards compatibility check for old location under the wrappers directory of the active theme
337
-            $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) );
338
-            if( !empty( $template ) ){
337
+            $template = locate_template(array(Sensei()->template_url.'wrappers/pagination.php'));
338
+            if ( ! empty($template)) {
339 339
 
340
-                Sensei_Templates::get_template( 'wrappers/pagination.php' );
340
+                Sensei_Templates::get_template('wrappers/pagination.php');
341 341
                 return;
342 342
 
343 343
             }
344 344
 
345
-			Sensei_Templates::get_template( 'globals/pagination.php' );
345
+			Sensei_Templates::get_template('globals/pagination.php');
346 346
 
347 347
 		} // End If Statement
348 348
 
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	 * @param object $item
369 369
 	 * @return object $item
370 370
 	 */
371
-	public function sensei_setup_nav_menu_item( $item ) {
371
+	public function sensei_setup_nav_menu_item($item) {
372 372
 		global $pagenow, $wp_rewrite;
373 373
 
374
-		if( 'nav-menus.php' != $pagenow && !defined('DOING_AJAX') && isset( $item->url ) && 'custom' == $item->type ) {
374
+		if ('nav-menus.php' != $pagenow && ! defined('DOING_AJAX') && isset($item->url) && 'custom' == $item->type) {
375 375
 
376 376
 			// Set up Sensei menu links
377
-			$course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] );
378
-			$my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
377
+			$course_page_id = intval(Sensei()->settings->settings['course_page']);
378
+			$my_account_page_id = intval(Sensei()->settings->settings['my_course_page']);
379 379
 
380 380
 			$course_page_url = Sensei_Course::get_courses_page_url();
381
-			$lesson_archive_url = get_post_type_archive_link( 'lesson' );
382
-			$my_courses_url = get_permalink( $my_account_page_id );
383
-			$my_messages_url = get_post_type_archive_link( 'sensei_message' );
381
+			$lesson_archive_url = get_post_type_archive_link('lesson');
382
+			$my_courses_url = get_permalink($my_account_page_id);
383
+			$my_messages_url = get_post_type_archive_link('sensei_message');
384 384
 
385
-			switch ( $item->url ) {
385
+			switch ($item->url) {
386 386
 				case '#senseicourses':
387 387
 					$item->url = $course_page_url;
388 388
 					break;
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 					$item->url = $my_messages_url;
400 400
                     // if no archive link exist for sensei_message
401 401
                     // set it back to the place holder
402
-                    if( ! $item->url ){
402
+                    if ( ! $item->url) {
403 403
 
404 404
                         $item->url = '#senseimymessages';
405 405
 
@@ -407,21 +407,21 @@  discard block
 block discarded – undo
407 407
 					break;
408 408
 
409 409
 				case '#senseilearnerprofile':
410
-					$item->url = esc_url( Sensei()->learner_profiles->get_permalink() );
410
+					$item->url = esc_url(Sensei()->learner_profiles->get_permalink());
411 411
 					break;
412 412
 
413 413
 				case '#senseiloginlogout':
414
-						$logout_url = wp_logout_url( home_url() );
414
+						$logout_url = wp_logout_url(home_url());
415 415
 						// Login link links to the My Courses page, to avoid the WP dashboard.
416 416
 						$login_url = $my_courses_url;
417 417
 
418
-						$item->url = ( is_user_logged_in() ? $logout_url : $login_url );
418
+						$item->url = (is_user_logged_in() ? $logout_url : $login_url);
419 419
 
420 420
 						// determine the menu title login or logout
421
-						if ( is_user_logged_in() ) {
422
-							$menu_title =  __( 'Logout'  ,'woothemes-sensei');
421
+						if (is_user_logged_in()) {
422
+							$menu_title = __('Logout', 'woothemes-sensei');
423 423
 						} else {
424
-							$menu_title =  __( 'Login'  ,'woothemes-sensei');
424
+							$menu_title = __('Login', 'woothemes-sensei');
425 425
 						}
426 426
 
427 427
 						/**
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 						 *
432 432
 						 * @param $menu_title
433 433
 						 */
434
-						$item->title = apply_filters( 'sensei_login_logout_menu_title', $menu_title );
434
+						$item->title = apply_filters('sensei_login_logout_menu_title', $menu_title);
435 435
 
436 436
 					break;
437 437
 
@@ -439,12 +439,12 @@  discard block
 block discarded – undo
439 439
 					break;
440 440
 			}
441 441
 
442
-			$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
443
-			$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
444
-			$item_url = untrailingslashit( $item->url );
445
-			$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
442
+			$_root_relative_current = untrailingslashit($_SERVER['REQUEST_URI']);
443
+			$current_url = set_url_scheme('http://'.$_SERVER['HTTP_HOST'].$_root_relative_current);
444
+			$item_url = untrailingslashit($item->url);
445
+			$_indexless_current = untrailingslashit(preg_replace('/'.preg_quote($wp_rewrite->index, '/').'$/', '', $current_url));
446 446
 			// Highlight current menu item
447
-			if ( $item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) {
447
+			if ($item_url && in_array($item_url, array($current_url, $_indexless_current, $_root_relative_current))) {
448 448
 				$item->classes[] = 'current-menu-item current_page_item';
449 449
 			}
450 450
 
@@ -463,26 +463,26 @@  discard block
 block discarded – undo
463 463
 	 * @param object $sorted_menu_items
464 464
 	 * @return object $sorted_menu_items
465 465
 	 */
466
-	public function sensei_wp_nav_menu_objects( $sorted_menu_items ) {
466
+	public function sensei_wp_nav_menu_objects($sorted_menu_items) {
467 467
 
468
-		foreach( $sorted_menu_items as $k=>$item ) {
468
+		foreach ($sorted_menu_items as $k=>$item) {
469 469
 
470 470
 			// Remove the My Messages link for logged out users or if Private Messages are disabled
471
-			if( ! get_post_type_archive_link( 'sensei_message' )
472
-                && '#senseimymessages' == $item->url ) {
471
+			if ( ! get_post_type_archive_link('sensei_message')
472
+                && '#senseimymessages' == $item->url) {
473 473
 
474
-				if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) {
474
+				if ( ! is_user_logged_in() || (isset(Sensei()->settings->settings['messages_disable']) && Sensei()->settings->settings['messages_disable'])) {
475 475
 
476
-					unset( $sorted_menu_items[$k] );
476
+					unset($sorted_menu_items[$k]);
477 477
 
478 478
 				}
479 479
 			}
480 480
 			// Remove the My Profile link for logged out users.
481
-			if( Sensei()->learner_profiles->get_permalink() == $item->url ) {
481
+			if (Sensei()->learner_profiles->get_permalink() == $item->url) {
482 482
 
483
-				if ( !is_user_logged_in() || ! ( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] ) && Sensei()->settings->settings[ 'learner_profile_enable' ] ) ) {
483
+				if ( ! is_user_logged_in() || ! (isset(Sensei()->settings->settings['learner_profile_enable']) && Sensei()->settings->settings['learner_profile_enable'])) {
484 484
 
485
-					unset( $sorted_menu_items[$k] );
485
+					unset($sorted_menu_items[$k]);
486 486
 
487 487
 				}
488 488
 			}
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 	function sensei_search_results_classes($classes) {
495 495
 	    global $post;
496 496
 	    // Handle Search Classes for Courses, Lessons, and WC Products
497
-	    if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) {
497
+	    if (isset($post->post_type) && (('course' == $post->post_type) || ('lesson' == $post->post_type) || ('product' == $post->post_type))) {
498 498
 	    	$classes[] = 'post';
499 499
 		} // End If Statement
500 500
 	    return $classes;
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
      * @param bool|false $return
523 523
      * @return string|void
524 524
 	 */
525
-	function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) {
525
+	function sensei_course_image($course_id, $width = '100', $height = '100', $return = false) {
526 526
 
527
-    	if ( ! $return ) {
527
+    	if ( ! $return) {
528 528
 
529
-			echo Sensei()->course->course_image( $course_id, $width, $height );
529
+			echo Sensei()->course->course_image($course_id, $width, $height);
530 530
             return '';
531 531
 
532 532
 		} // End If Statement
533 533
 
534
-		return Sensei()->course->course_image( $course_id, $width, $height );
534
+		return Sensei()->course->course_image($course_id, $width, $height);
535 535
 
536 536
 	} // End sensei_course_image()
537 537
 
@@ -546,15 +546,15 @@  discard block
 block discarded – undo
546 546
      * @param bool|false $widget
547 547
      * @return string
548 548
 	 */
549
-	function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) {
549
+	function sensei_lesson_image($lesson_id, $width = '100', $height = '100', $return = false, $widget = false) {
550 550
 
551
-        if( ! $return ){
551
+        if ( ! $return) {
552 552
 
553
-            echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
553
+            echo Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget);
554 554
             return '';
555 555
         }
556 556
 
557
-        return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget );
557
+        return Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget);
558 558
 
559 559
 	} // End sensei_lesson_image()
560 560
 
@@ -562,20 +562,20 @@  discard block
 block discarded – undo
562 562
      * @since 1.0.0
563 563
      * @param WP_Query $query
564 564
      */
565
-    function sensei_course_archive_pagination( $query ) {
565
+    function sensei_course_archive_pagination($query) {
566 566
 
567
-		if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) {
567
+		if ( ! is_admin() && $query->is_main_query() && isset($_GET['action']) && in_array($_GET['action'], array('newcourses', 'featuredcourses', 'freecourses', 'paidcourses'))) {
568 568
 
569 569
 			$amount = 0;
570
-			if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
571
-				$amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
570
+			if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) {
571
+				$amount = absint(Sensei()->settings->settings['course_archive_amount']);
572 572
 			}
573 573
 
574
-			if( $amount ) {
575
-				$query->set( 'posts_per_page', $amount );
574
+			if ($amount) {
575
+				$query->set('posts_per_page', $amount);
576 576
 			}
577 577
 
578
-			$query->set( 'orderby', 'menu_order date' );
578
+			$query->set('orderby', 'menu_order date');
579 579
 
580 580
 		}
581 581
 	}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 	function sensei_course_archive_header(  ) {
592 592
 
593 593
         trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header ');
594
-        WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' );
594
+        WooThemes_Sensei_Course::archive_header('', '<header class="archive-header"><h1>', '</h1></header>');
595 595
 
596 596
 	} // sensei_course_archive_header()
597 597
 
@@ -604,15 +604,15 @@  discard block
 block discarded – undo
604 604
 	 * @return void
605 605
 	 */
606 606
 	public function sensei_lesson_archive_header( ) {
607
-        _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' );
607
+        _deprecated_function('WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header');
608 608
         Sensei()->lesson->the_archive_header();
609 609
 	} // sensei_course_archive_header()
610 610
 
611 611
     /**
612 612
      * @deprecated since 1.9.0
613 613
      */
614
-	public function sensei_message_archive_header( ){
615
-        _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense');
614
+	public function sensei_message_archive_header( ) {
615
+        _deprecated_function('Sensei_Frontend::sensei_message_archive_header', 'Please use: Sense');
616 616
         Sensei_Messages::the_archive_header();
617 617
 	} // sensei_message_archive_header()
618 618
 
@@ -622,15 +622,15 @@  discard block
 block discarded – undo
622 622
      * @param WP_Post $post_item
623 623
 	 * @return void
624 624
 	 */
625
-	function sensei_course_archive_course_title( $post_item ) {
626
-		if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) {
627
-			$post_id = absint( $post_item->ID );
625
+	function sensei_course_archive_course_title($post_item) {
626
+		if (isset($post_item->ID) && (0 < $post_item->ID)) {
627
+			$post_id = absint($post_item->ID);
628 628
     		$post_title = $post_item->post_title;
629 629
 		} else {
630 630
 			$post_id = get_the_ID();
631 631
     		$post_title = get_the_title();
632 632
 		} // End If Statement
633
-		?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
633
+		?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php
634 634
 	} // End sensei_course_archive_course_title()
635 635
 
636 636
 	/**
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
 	public function sensei_lesson_archive_lesson_title() {
642 642
 		$post_id = get_the_ID();
643 643
     	$post_title = get_the_title();
644
-		?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php
644
+		?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php
645 645
 	} // End sensei_lesson_archive_lesson_title()
646 646
 
647 647
 	/**
@@ -650,40 +650,40 @@  discard block
 block discarded – undo
650 650
 	 * @param  integer $id course, lesson or quiz id
651 651
 	 * @return void
652 652
 	 */
653
-	public function sensei_breadcrumb( $id = 0 ) {
653
+	public function sensei_breadcrumb($id = 0) {
654 654
 
655 655
 		// Only output on lesson, quiz and taxonomy (module) pages
656
-		if( ! ( is_tax( 'module' ) || is_singular( 'lesson' ) || is_singular( 'quiz' ) ) ) return;
656
+		if ( ! (is_tax('module') || is_singular('lesson') || is_singular('quiz'))) return;
657 657
 
658
-		if( empty( $id )  ){
658
+		if (empty($id)) {
659 659
 
660 660
             $id = get_the_ID();
661 661
 
662 662
         }
663 663
 
664
-		$sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' );
665
-		$separator = apply_filters( 'sensei_breadcrumb_separator', '&gt;' );
664
+		$sensei_breadcrumb_prefix = __('Back to: ', 'woothemes-sensei');
665
+		$separator = apply_filters('sensei_breadcrumb_separator', '&gt;');
666 666
 
667
-		$html = '<section class="sensei-breadcrumb">' . $sensei_breadcrumb_prefix;
667
+		$html = '<section class="sensei-breadcrumb">'.$sensei_breadcrumb_prefix;
668 668
 		// Lesson
669
-		if ( is_singular( 'lesson' ) && 0 < intval( $id ) ) {
670
-			$course_id = intval( get_post_meta( $id, '_lesson_course', true ) );
671
-			if( ! $course_id ) {
669
+		if (is_singular('lesson') && 0 < intval($id)) {
670
+			$course_id = intval(get_post_meta($id, '_lesson_course', true));
671
+			if ( ! $course_id) {
672 672
 				return;
673 673
 			}
674
-			$html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>';
674
+			$html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
675 675
     	} // End If Statement
676 676
     	// Quiz
677
-		if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) {
678
-			$lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) );
679
-			if( ! $lesson_id ) {
677
+		if (is_singular('quiz') && 0 < intval($id)) {
678
+			$lesson_id = intval(get_post_meta($id, '_quiz_lesson', true));
679
+			if ( ! $lesson_id) {
680 680
 				return;
681 681
 			}
682
-			 $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' .  __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>';
682
+			 $html .= '<a href="'.esc_url(get_permalink($lesson_id)).'" title="'.__('Back to the lesson', 'woothemes-sensei').'">'.get_the_title($lesson_id).'</a>';
683 683
     	} // End If Statement
684 684
 
685 685
     	// Allow other plugins to filter html
686
-    	$html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator );
686
+    	$html = apply_filters('sensei_breadcrumb_output', $html, $separator);
687 687
     	$html .= '</section>';
688 688
 
689 689
     	echo $html;
@@ -695,25 +695,25 @@  discard block
 block discarded – undo
695 695
      */
696 696
 	public function sensei_lesson_course_signup_link( ) {
697 697
 
698
-        _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' );
698
+        _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link');
699 699
         WooThemes_Sensei_Lesson::course_signup_link();
700 700
 	}
701 701
 
702
-	public function lesson_tags_display( $lesson_id = 0 ) {
703
-		if( $lesson_id ) {
704
-			$tags = wp_get_post_terms( $lesson_id, 'lesson-tag' );
705
-			if( $tags && count( $tags ) > 0 ) {
702
+	public function lesson_tags_display($lesson_id = 0) {
703
+		if ($lesson_id) {
704
+			$tags = wp_get_post_terms($lesson_id, 'lesson-tag');
705
+			if ($tags && count($tags) > 0) {
706 706
 				$tag_list = '';
707
-				foreach( $tags as $tag ) {
708
-					$tag_link = get_term_link( $tag, 'lesson-tag' );
709
-					if( ! is_wp_error( $tag_link ) ) {
710
-						if( $tag_list ) { $tag_list .= ', '; }
711
-						$tag_list .= '<a href="' . $tag_link . '">' . $tag->name . '</a>';
707
+				foreach ($tags as $tag) {
708
+					$tag_link = get_term_link($tag, 'lesson-tag');
709
+					if ( ! is_wp_error($tag_link)) {
710
+						if ($tag_list) { $tag_list .= ', '; }
711
+						$tag_list .= '<a href="'.$tag_link.'">'.$tag->name.'</a>';
712 712
 					}
713 713
 				}
714
-				if( $tag_list ) {
714
+				if ($tag_list) {
715 715
 					?><section class="lesson-tags">
716
-		    			<?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?>
716
+		    			<?php printf(__('Lesson tags: %1$s', 'woothemes-sensei'), $tag_list); ?>
717 717
 		    		</section><?php
718 718
 		    	}
719 719
 	    	}
@@ -723,51 +723,51 @@  discard block
 block discarded – undo
723 723
     /**
724 724
      * @param WP_Query $query
725 725
      */
726
-	public function lesson_tag_archive_filter( $query ) {
727
-    	if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) {
726
+	public function lesson_tag_archive_filter($query) {
727
+    	if (is_tax('lesson-tag') && $query->is_main_query()) {
728 728
     		// Limit to lessons only
729
-    		$query->set( 'post_type', 'lesson' );
729
+    		$query->set('post_type', 'lesson');
730 730
 
731 731
     		// Set order of lessons
732
-    		$query->set( 'orderby', 'menu_order' );
733
-    		$query->set( 'order', 'ASC' );
732
+    		$query->set('orderby', 'menu_order');
733
+    		$query->set('order', 'ASC');
734 734
 
735 735
     	}
736 736
     }
737 737
 
738
-    public function lesson_tag_archive_header( $title ) {
739
-		if( is_tax( 'lesson-tag' ) ) {
740
-			$title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) );
738
+    public function lesson_tag_archive_header($title) {
739
+		if (is_tax('lesson-tag')) {
740
+			$title = sprintf(__('Lesson tag: %1$s', 'woothemes-sensei'), apply_filters('sensei_lesson_tag_archive_title', get_queried_object()->name));
741 741
 		}
742 742
 		return $title;
743 743
 	}
744 744
 
745 745
 	public function lesson_tag_archive_description() {
746
-		if( is_tax( 'lesson-tag' ) ) {
746
+		if (is_tax('lesson-tag')) {
747 747
 			$tag = get_queried_object();
748
-			echo '<p class="archive-description lesson-description">' . apply_filters( 'sensei_lesson_tag_archive_description', nl2br( $tag->description ), $tag->term_id ) . '</p>';
748
+			echo '<p class="archive-description lesson-description">'.apply_filters('sensei_lesson_tag_archive_description', nl2br($tag->description), $tag->term_id).'</p>';
749 749
 		}
750 750
 	}
751 751
 
752 752
 	public function sensei_complete_lesson() {
753
-		global $post,  $current_user;
753
+		global $post, $current_user;
754 754
 		// Handle Quiz Completion
755
-		if ( isset( $_POST['quiz_action'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_lesson_noonce' ], 'woothemes_sensei_complete_lesson_noonce' ) ) {
755
+		if (isset($_POST['quiz_action']) && wp_verify_nonce($_POST['woothemes_sensei_complete_lesson_noonce'], 'woothemes_sensei_complete_lesson_noonce')) {
756 756
 
757
-			$sanitized_submit = esc_html( $_POST['quiz_action'] );
757
+			$sanitized_submit = esc_html($_POST['quiz_action']);
758 758
 
759 759
 			switch ($sanitized_submit) {
760 760
                 case 'lesson-complete':
761 761
 
762
-					Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true );
762
+					Sensei_Utils::sensei_start_lesson($post->ID, $current_user->ID, $complete = true);
763 763
 
764 764
 					break;
765 765
 
766 766
                 case 'lesson-reset':
767 767
 
768
-					Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID );
768
+					Sensei_Utils::sensei_remove_user_from_lesson($post->ID, $current_user->ID);
769 769
 
770
-					$this->messages = '<div class="sensei-message note">' .  __( 'Lesson Reset Successfully.', 'woothemes-sensei' ) . '</div>';
770
+					$this->messages = '<div class="sensei-message note">'.__('Lesson Reset Successfully.', 'woothemes-sensei').'</div>';
771 771
 					break;
772 772
 
773 773
 				default:
@@ -781,14 +781,14 @@  discard block
 block discarded – undo
781 781
 	} // End sensei_complete_lesson()
782 782
 
783 783
 	public function sensei_complete_course() {
784
-		global $post,  $current_user, $wp_query;
785
-		if ( isset( $_POST['course_complete'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_course_noonce' ], 'woothemes_sensei_complete_course_noonce' ) ) {
784
+		global $post, $current_user, $wp_query;
785
+		if (isset($_POST['course_complete']) && wp_verify_nonce($_POST['woothemes_sensei_complete_course_noonce'], 'woothemes_sensei_complete_course_noonce')) {
786 786
 
787
-			$sanitized_submit = esc_html( $_POST['course_complete'] );
788
-			$sanitized_course_id = absint( esc_html( $_POST['course_complete_id'] ) );
787
+			$sanitized_submit = esc_html($_POST['course_complete']);
788
+			$sanitized_course_id = absint(esc_html($_POST['course_complete_id']));
789 789
 			// Handle submit data
790 790
 			switch ($sanitized_submit) {
791
-				case __( 'Mark as Complete', 'woothemes-sensei' ):
791
+				case __('Mark as Complete', 'woothemes-sensei'):
792 792
 
793 793
 					// Add user to course
794 794
 					$course_metadata = array(
@@ -796,15 +796,15 @@  discard block
 block discarded – undo
796 796
 						'percent' => 0, // No completed lessons yet
797 797
 						'complete' => 0,
798 798
 					);
799
-					$activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata );
799
+					$activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata);
800 800
 
801
-					if ( $activity_logged ) {
801
+					if ($activity_logged) {
802 802
 						// Get all course lessons
803
-						$course_lesson_ids = Sensei()->course->course_lessons( $sanitized_course_id, 'any', 'ids' );
803
+						$course_lesson_ids = Sensei()->course->course_lessons($sanitized_course_id, 'any', 'ids');
804 804
 						// Mark all quiz user meta lessons as complete
805
-						foreach ( $course_lesson_ids as $lesson_item_id ){
805
+						foreach ($course_lesson_ids as $lesson_item_id) {
806 806
 							// Mark lesson as complete
807
-							$activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_item_id, $current_user->ID, $complete = true );
807
+							$activity_logged = Sensei_Utils::sensei_start_lesson($lesson_item_id, $current_user->ID, $complete = true);
808 808
 						} // End For Loop
809 809
 
810 810
 						// Update with final stats
@@ -812,22 +812,22 @@  discard block
 block discarded – undo
812 812
 							'percent' => 100,
813 813
 							'complete' => count($course_lesson_ids),
814 814
 						);
815
-						$activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'complete', $course_metadata );
815
+						$activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'complete', $course_metadata);
816 816
 
817
-						do_action( 'sensei_user_course_end', $current_user->ID, $sanitized_course_id );
817
+						do_action('sensei_user_course_end', $current_user->ID, $sanitized_course_id);
818 818
 
819 819
 						// Success message
820
-						$this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s marked as complete.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>';
820
+						$this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s marked as complete.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>';
821 821
 					} // End If Statement
822 822
 
823 823
 					break;
824 824
 
825
-				case __( 'Delete Course', 'woothemes-sensei' ):
825
+				case __('Delete Course', 'woothemes-sensei'):
826 826
 
827
-					Sensei_Utils::sensei_remove_user_from_course( $sanitized_course_id, $current_user->ID );
827
+					Sensei_Utils::sensei_remove_user_from_course($sanitized_course_id, $current_user->ID);
828 828
 
829 829
 					// Success message
830
-					$this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s deleted.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>';
830
+					$this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s deleted.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>';
831 831
 					break;
832 832
 
833 833
 				default:
@@ -843,25 +843,25 @@  discard block
 block discarded – undo
843 843
 	 * @param int $lesson_id
844 844
 	 * @return array
845 845
 	 */
846
-	public function sensei_get_user_quiz_answers( $lesson_id = 0 ) {
846
+	public function sensei_get_user_quiz_answers($lesson_id = 0) {
847 847
 		global $current_user;
848 848
 
849 849
 		$user_answers = array();
850 850
 
851
-		if ( 0 < intval( $lesson_id ) ) {
852
-			$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $lesson_id );
853
-			foreach( $lesson_quiz_questions as $question ) {
854
-				$answer = maybe_unserialize( base64_decode( Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content' ) ) ) );
855
-				$user_answers[ $question->ID ] = $answer;
851
+		if (0 < intval($lesson_id)) {
852
+			$lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($lesson_id);
853
+			foreach ($lesson_quiz_questions as $question) {
854
+				$answer = maybe_unserialize(base64_decode(Sensei_Utils::sensei_get_activity_value(array('post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content'))));
855
+				$user_answers[$question->ID] = $answer;
856 856
 			}
857 857
 		}
858 858
 
859 859
 		return $user_answers;
860 860
 	} // End sensei_get_user_quiz_answers()
861 861
 
862
-	public function sensei_has_user_completed_lesson( $post_id = 0, $user_id = 0 ) {
863
-		_deprecated_function( __FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()" );
864
-		return Sensei_Utils::user_completed_lesson( $post_id, $user_id );
862
+	public function sensei_has_user_completed_lesson($post_id = 0, $user_id = 0) {
863
+		_deprecated_function(__FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()");
864
+		return Sensei_Utils::user_completed_lesson($post_id, $user_id);
865 865
 	} // End sensei_has_user_completed_lesson()
866 866
 
867 867
 /**
@@ -871,14 +871,14 @@  discard block
 block discarded – undo
871 871
 		Sensei()->notices->maybe_print_notices();
872 872
 	} // End sensei_frontend_messages()
873 873
 
874
-	public function sensei_lesson_video( $post_id = 0 ) {
875
-		if ( 0 < intval( $post_id ) ) {
876
-			$lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true );
877
-			if ( 'http' == substr( $lesson_video_embed, 0, 4) ) {
874
+	public function sensei_lesson_video($post_id = 0) {
875
+		if (0 < intval($post_id)) {
876
+			$lesson_video_embed = get_post_meta($post_id, '_lesson_video_embed', true);
877
+			if ('http' == substr($lesson_video_embed, 0, 4)) {
878 878
         		// V2 - make width and height a setting for video embed
879
-        		$lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ );
879
+        		$lesson_video_embed = wp_oembed_get(esc_url($lesson_video_embed)/*, array( 'width' => 100 , 'height' => 100)*/);
880 880
         	} // End If Statement
881
-        	if ( '' != $lesson_video_embed ) {
881
+        	if ('' != $lesson_video_embed) {
882 882
         	?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php
883 883
         	} // End If Statement
884 884
         } // End If Statement
@@ -890,25 +890,25 @@  discard block
 block discarded – undo
890 890
 		$quiz_id = 0;
891 891
 
892 892
 		//make sure user is taking course
893
-		$course_id = Sensei()->lesson->get_course_id( $post->ID );
894
-		if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) ){
893
+		$course_id = Sensei()->lesson->get_course_id($post->ID);
894
+		if ( ! Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
895 895
 			return;
896 896
 		}
897 897
 
898 898
 		// Lesson quizzes
899
-		$quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID );
899
+		$quiz_id = Sensei()->lesson->lesson_quizzes($post->ID);
900 900
 		$pass_required = true;
901
-		if( $quiz_id ) {
901
+		if ($quiz_id) {
902 902
 			// Get quiz pass setting
903
-	    	$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
903
+	    	$pass_required = get_post_meta($quiz_id, '_pass_required', true);
904 904
 	    }
905
-		if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) {
905
+		if ( ! $quiz_id || ($quiz_id && ! $pass_required)) {
906 906
 			?>
907
-			<form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
907
+			<form class="lesson_button_form" method="POST" action="<?php echo esc_url(get_permalink()); ?>">
908 908
 	            <input type="hidden"
909 909
                        name="woothemes_sensei_complete_lesson_noonce"
910 910
                        id="woothemes_sensei_complete_lesson_noonce"
911
-                       value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>"
911
+                       value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>"
912 912
                 />
913 913
 
914 914
 	            <input type="hidden" name="quiz_action" value="lesson-complete" />
@@ -916,7 +916,7 @@  discard block
 block discarded – undo
916 916
                 <input type="submit"
917 917
                        name="quiz_complete"
918 918
                        class="quiz-submit complete"
919
-                       value="<?php _e( 'Complete Lesson', 'woothemes-sensei' ); ?>"/>
919
+                       value="<?php _e('Complete Lesson', 'woothemes-sensei'); ?>"/>
920 920
 
921 921
 	        </form>
922 922
 			<?php
@@ -929,25 +929,25 @@  discard block
 block discarded – undo
929 929
 		$quiz_id = 0;
930 930
 
931 931
 		// Lesson quizzes
932
-		$quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID );
932
+		$quiz_id = Sensei()->lesson->lesson_quizzes($post->ID);
933 933
 		$reset_allowed = true;
934
-		if( $quiz_id ) {
934
+		if ($quiz_id) {
935 935
 			// Get quiz pass setting
936
-			$reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
936
+			$reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true);
937 937
 		}
938
-		if ( ! $quiz_id || !empty($reset_allowed) ) {
938
+		if ( ! $quiz_id || ! empty($reset_allowed)) {
939 939
 		?>
940
-		<form method="POST" action="<?php echo esc_url( get_permalink() ); ?>">
940
+		<form method="POST" action="<?php echo esc_url(get_permalink()); ?>">
941 941
 
942 942
             <input
943 943
             type="hidden"
944
-            name="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>"
945
-            id="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>"
946
-            value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" />
944
+            name="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>"
945
+            id="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>"
946
+            value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>" />
947 947
 
948 948
             <input type="hidden" name="quiz_action" value="lesson-reset" />
949 949
 
950
-            <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e( 'Reset Lesson', 'woothemes-sensei' ); ?>"/>
950
+            <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e('Reset Lesson', 'woothemes-sensei'); ?>"/>
951 951
 
952 952
         </form>
953 953
 		<?php
@@ -970,23 +970,23 @@  discard block
 block discarded – undo
970 970
 		$post_title = get_the_title();
971 971
 		$author_display_name = get_the_author();
972 972
 		$author_id = get_the_author_meta('ID');
973
-		$category_output = get_the_term_list( $post_id, 'course-category', '', ', ', '' );
974
-		$free_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $post_id ) );
973
+		$category_output = get_the_term_list($post_id, 'course-category', '', ', ', '');
974
+		$free_lesson_count = intval(Sensei()->course->course_lesson_preview_count($post_id));
975 975
 		?><section class="entry">
976 976
         	<p class="sensei-course-meta">
977
-           	<?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
978
-		   	<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span>
977
+           	<?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
978
+		   	<span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span>
979 979
 		   	<?php } // End If Statement ?>
980
-		   	<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . '&nbsp;' . __( 'Lessons', 'woothemes-sensei' ); ?></span>
981
-		   	<?php if ( '' != $category_output ) { ?>
982
-		   	<span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
980
+		   	<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?></span>
981
+		   	<?php if ('' != $category_output) { ?>
982
+		   	<span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
983 983
 		   	<?php } // End If Statement ?>
984
-		   	<?php sensei_simple_course_price( $post_id ); ?>
984
+		   	<?php sensei_simple_course_price($post_id); ?>
985 985
         	</p>
986 986
         	<p class="course-excerpt"><?php the_excerpt(); ?></p>
987
-        	<?php if ( 0 < $free_lesson_count ) {
988
-                $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?>
989
-                <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p>
987
+        	<?php if (0 < $free_lesson_count) {
988
+                $free_lessons = sprintf(__('You can access %d of this course\'s lessons for free', 'woothemes-sensei'), $free_lesson_count); ?>
989
+                <p class="sensei-free-lessons"><a href="<?php echo get_permalink($post_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?></a> - <?php echo $free_lessons; ?></p>
990 990
             <?php } ?>
991 991
 		</section><?php
992 992
 	} // End sensei_course_archive_meta()
@@ -1009,33 +1009,33 @@  discard block
 block discarded – undo
1009 1009
     * @deprecated since 1.9.0
1010 1010
     */
1011 1011
 	public function sensei_message_archive_main_content() {
1012
-		_deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' );
1012
+		_deprecated_function('Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed');
1013 1013
 	} // End sensei_lesson_archive_main_content()
1014 1014
 
1015 1015
     /**
1016 1016
     * @deprecated since 1.9.0
1017 1017
     */
1018 1018
 	public function sensei_no_permissions_main_content() {
1019
-        _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' );
1019
+        _deprecated_function('Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed');
1020 1020
 	} // End sensei_no_permissions_main_content()
1021 1021
 
1022 1022
 	public function sensei_course_category_main_content() {
1023 1023
 		global $post;
1024
-		if ( have_posts() ) { ?>
1024
+		if (have_posts()) { ?>
1025 1025
 
1026 1026
 			<section id="main-course" class="course-container">
1027 1027
 
1028
-                <?php do_action( 'sensei_course_archive_header' ); ?>
1028
+                <?php do_action('sensei_course_archive_header'); ?>
1029 1029
 
1030
-                <?php while ( have_posts() ) { the_post(); ?>
1030
+                <?php while (have_posts()) { the_post(); ?>
1031 1031
 
1032
-                    <article class="<?php echo join( ' ', get_post_class( array( 'course', 'post' ), get_the_ID() ) ); ?>">
1032
+                    <article class="<?php echo join(' ', get_post_class(array('course', 'post'), get_the_ID())); ?>">
1033 1033
 
1034
-	    			    <?php sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', get_the_ID() ); ?>
1034
+	    			    <?php sensei_do_deprecated_action('sensei_course_image', '1.9.0', 'sensei_single_course_content_inside_before', get_the_ID()); ?>
1035 1035
 
1036
-	    			    <?php sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before', $post ); ?>
1036
+	    			    <?php sensei_do_deprecated_action('sensei_course_archive_course_title', '1.9.0', 'sensei_course_content_inside_before', $post); ?>
1037 1037
 
1038
-	    			    <?php do_action( 'sensei_course_archive_meta' ); ?>
1038
+	    			    <?php do_action('sensei_course_archive_meta'); ?>
1039 1039
 
1040 1040
 	    		    </article>
1041 1041
 
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 			<p>
1049 1049
 
1050
-                <?php _e( 'No courses found that match your selection.', 'woothemes-sensei' ); ?>
1050
+                <?php _e('No courses found that match your selection.', 'woothemes-sensei'); ?>
1051 1051
 
1052 1052
             </p>
1053 1053
 
@@ -1064,12 +1064,12 @@  discard block
 block discarded – undo
1064 1064
 				<div class="col-1">
1065 1065
 					<?php
1066 1066
 					// output the actual form markup
1067
-                    Sensei_Templates::get_template( 'user/login-form.php');
1067
+                    Sensei_Templates::get_template('user/login-form.php');
1068 1068
 					?>
1069 1069
 				</div>
1070 1070
 
1071 1071
 			<?php
1072
-			if ( get_option('users_can_register') ) {
1072
+			if (get_option('users_can_register')) {
1073 1073
 
1074 1074
 				// get current url
1075 1075
 				$action_url = get_permalink();
@@ -1077,38 +1077,38 @@  discard block
 block discarded – undo
1077 1077
 				?>
1078 1078
 
1079 1079
 				<div class="col-2">
1080
-					<h2><?php _e( 'Register', 'woothemes-sensei' ); ?></h2>
1080
+					<h2><?php _e('Register', 'woothemes-sensei'); ?></h2>
1081 1081
 
1082
-					<form method="post" class="register"  action="<?php echo esc_url( $action_url ); ?>" >
1082
+					<form method="post" class="register"  action="<?php echo esc_url($action_url); ?>" >
1083 1083
 
1084
-						<?php do_action( 'sensei_register_form_start' ); ?>
1084
+						<?php do_action('sensei_register_form_start'); ?>
1085 1085
 
1086 1086
 						<p class="form-row form-row-wide">
1087
-							<label for="sensei_reg_username"><?php _e( 'Username', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1088
-							<input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty( $_POST['sensei_reg_username'] ) ) esc_attr_e( $_POST['sensei_reg_username'] ); ?>" />
1087
+							<label for="sensei_reg_username"><?php _e('Username', 'woothemes-sensei'); ?> <span class="required">*</span></label>
1088
+							<input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty($_POST['sensei_reg_username'])) esc_attr_e($_POST['sensei_reg_username']); ?>" />
1089 1089
 						</p>
1090 1090
 
1091 1091
 						<p class="form-row form-row-wide">
1092
-							<label for="sensei_reg_email"><?php _e( 'Email address', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1093
-							<input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty( $_POST['sensei_reg_email'] ) ) esc_attr_e( $_POST['sensei_reg_email'] ); ?>" />
1092
+							<label for="sensei_reg_email"><?php _e('Email address', 'woothemes-sensei'); ?> <span class="required">*</span></label>
1093
+							<input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty($_POST['sensei_reg_email'])) esc_attr_e($_POST['sensei_reg_email']); ?>" />
1094 1094
 						</p>
1095 1095
 
1096 1096
 						<p class="form-row form-row-wide">
1097
-							<label for="sensei_reg_password"><?php _e( 'Password', 'woothemes-sensei' ); ?> <span class="required">*</span></label>
1098
-							<input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty( $_POST['sensei_reg_password'] ) ) esc_attr_e( $_POST['sensei_reg_password'] ); ?>" />
1097
+							<label for="sensei_reg_password"><?php _e('Password', 'woothemes-sensei'); ?> <span class="required">*</span></label>
1098
+							<input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty($_POST['sensei_reg_password'])) esc_attr_e($_POST['sensei_reg_password']); ?>" />
1099 1099
 						</p>
1100 1100
 
1101 1101
 						<!-- Spam Trap -->
1102
-						<div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woothemes-sensei' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>
1102
+						<div style="left:-999em; position:absolute;"><label for="trap"><?php _e('Anti-spam', 'woothemes-sensei'); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>
1103 1103
 
1104
-						<?php do_action( 'sensei_register_form_fields' ); ?>
1105
-						<?php do_action( 'register_form' ); ?>
1104
+						<?php do_action('sensei_register_form_fields'); ?>
1105
+						<?php do_action('register_form'); ?>
1106 1106
 
1107 1107
 						<p class="form-row">
1108
-							<input type="submit" class="button" name="register" value="<?php _e( 'Register', 'woothemes-sensei' ); ?>" />
1108
+							<input type="submit" class="button" name="register" value="<?php _e('Register', 'woothemes-sensei'); ?>" />
1109 1109
 						</p>
1110 1110
 
1111
-						<?php do_action( 'sensei_register_form_end' ); ?>
1111
+						<?php do_action('sensei_register_form_end'); ?>
1112 1112
 
1113 1113
 					</form>
1114 1114
 				</div>
@@ -1121,17 +1121,17 @@  discard block
 block discarded – undo
1121 1121
 		<?php
1122 1122
 	} // End sensei_login_form()
1123 1123
 
1124
-	public function sensei_lesson_meta( $post_id = 0 ) {
1124
+	public function sensei_lesson_meta($post_id = 0) {
1125 1125
 		global $post;
1126
-		if ( 0 < intval( $post_id ) ) {
1127
-		$lesson_course_id = absint( get_post_meta( $post_id, '_lesson_course', true ) );
1126
+		if (0 < intval($post_id)) {
1127
+		$lesson_course_id = absint(get_post_meta($post_id, '_lesson_course', true));
1128 1128
 		?><section class="entry">
1129 1129
             <p class="sensei-course-meta">
1130
-			    <?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?>
1131
-			    <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span>
1130
+			    <?php if (isset(Sensei()->settings->settings['lesson_author']) && (Sensei()->settings->settings['lesson_author'])) { ?>
1131
+			    <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span>
1132 1132
 			    <?php } ?>
1133
-                <?php if ( 0 < intval( $lesson_course_id ) ) { ?>
1134
-                <span class="lesson-course"><?php echo '&nbsp;' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . __( 'View course', 'woothemes-sensei' ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span>
1133
+                <?php if (0 < intval($lesson_course_id)) { ?>
1134
+                <span class="lesson-course"><?php echo '&nbsp;'.sprintf(__('Part of: %s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($lesson_course_id)).'" title="'.__('View course', 'woothemes-sensei').'"><em>'.get_the_title($lesson_course_id).'</em></a>'); ?></span>
1135 1135
                 <?php } ?>
1136 1136
             </p>
1137 1137
             <p class="lesson-excerpt"><?php the_excerpt( ); ?></p>
@@ -1139,36 +1139,36 @@  discard block
 block discarded – undo
1139 1139
 		} // End If Statement
1140 1140
 	} // sensei_lesson_meta()
1141 1141
 
1142
-	public function sensei_lesson_preview_title_text( $course_id ) {
1142
+	public function sensei_lesson_preview_title_text($course_id) {
1143 1143
 
1144
-		$preview_text = __( ' (Preview)', 'woothemes-sensei' );
1144
+		$preview_text = __(' (Preview)', 'woothemes-sensei');
1145 1145
 
1146 1146
 		//if this is a paid course
1147
-		if ( Sensei_WC::is_woocommerce_active() ) {
1148
-    	    $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
1149
-    	    if ( 0 < $wc_post_id ) {
1150
-    	    	$preview_text = __( ' (Free Preview)', 'woothemes-sensei' );
1147
+		if (Sensei_WC::is_woocommerce_active()) {
1148
+    	    $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
1149
+    	    if (0 < $wc_post_id) {
1150
+    	    	$preview_text = __(' (Free Preview)', 'woothemes-sensei');
1151 1151
     	    } // End If Statement
1152 1152
     	}
1153 1153
     	return $preview_text;
1154 1154
 	}
1155 1155
 
1156
-	public function sensei_lesson_preview_title( $title = '', $id = 0 ) {
1156
+	public function sensei_lesson_preview_title($title = '', $id = 0) {
1157 1157
 		global $post, $current_user;
1158 1158
 
1159 1159
 		// Limit to lessons and check if lesson ID matches filtered post ID
1160 1160
 		// @see https://github.com/woothemes/sensei/issues/574
1161
-		if( isset( $post->ID ) && $id == $post->ID && 'lesson' == get_post_type( $post ) ) {
1161
+		if (isset($post->ID) && $id == $post->ID && 'lesson' == get_post_type($post)) {
1162 1162
 
1163 1163
 			// Limit to main query only
1164
-			if( is_main_query() ) {
1164
+			if (is_main_query()) {
1165 1165
 
1166 1166
 				// Get the course ID
1167
-				$course_id = get_post_meta( $post->ID, '_lesson_course', true );
1167
+				$course_id = get_post_meta($post->ID, '_lesson_course', true);
1168 1168
 
1169 1169
 				// Check if the user is taking the course
1170
-				if( is_singular( 'lesson' ) && Sensei_Utils::is_preview_lesson( $post->ID ) && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID ) && $post->ID == $id ) {
1171
-					$title .= ' ' . $this->sensei_lesson_preview_title_text( $course_id );
1170
+				if (is_singular('lesson') && Sensei_Utils::is_preview_lesson($post->ID) && ! Sensei_Utils::user_started_course($course_id, $current_user->ID) && $post->ID == $id) {
1171
+					$title .= ' '.$this->sensei_lesson_preview_title_text($course_id);
1172 1172
 				}
1173 1173
 			}
1174 1174
 		}
@@ -1179,23 +1179,23 @@  discard block
 block discarded – undo
1179 1179
 		global $post, $current_user;
1180 1180
 
1181 1181
 		// Check if the user is taking the course
1182
-		$is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID );
1182
+		$is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID);
1183 1183
 		// Handle user starting the course
1184
-		if ( isset( $_POST['course_start'] )
1185
-		    && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' )
1186
-		    && !$is_user_taking_course ) {
1184
+		if (isset($_POST['course_start'])
1185
+		    && wp_verify_nonce($_POST['woothemes_sensei_start_course_noonce'], 'woothemes_sensei_start_course_noonce')
1186
+		    && ! $is_user_taking_course) {
1187 1187
 
1188 1188
 			// Start the course
1189
-			$activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID );
1189
+			$activity_logged = Sensei_Utils::user_start_course($current_user->ID, $post->ID);
1190 1190
 			$this->data = new stdClass();
1191 1191
 			$this->data->is_user_taking_course = false;
1192
-			if ( $activity_logged ) {
1192
+			if ($activity_logged) {
1193 1193
 				$this->data->is_user_taking_course = true;
1194 1194
 
1195 1195
 				// Refresh page to avoid re-posting
1196 1196
 				?>
1197 1197
 
1198
-			    <script type="text/javascript"> window.location = '<?php echo get_permalink( $post->ID ); ?>'; </script>
1198
+			    <script type="text/javascript"> window.location = '<?php echo get_permalink($post->ID); ?>'; </script>
1199 1199
 
1200 1200
 			    <?php
1201 1201
 			} // End If Statement
@@ -1206,15 +1206,15 @@  discard block
 block discarded – undo
1206 1206
      * @deprecated since 1.9.0
1207 1207
      */
1208 1208
 	public function sensei_course_meta() {
1209
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' );
1210
-        Sensei()->course->the_course_meta( get_post() );
1209
+        _deprecated_function('Sensei_Frontend::sensei_course_meta', '1.9.0', 'Sensei_Course::the_course_meta()');
1210
+        Sensei()->course->the_course_meta(get_post());
1211 1211
 	} // End sensei_course_meta()
1212 1212
 
1213 1213
     /**
1214 1214
      * @deprecated since 1.9.0
1215 1215
      */
1216 1216
 	public function sensei_course_meta_video() {
1217
-        _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' );
1217
+        _deprecated_function('Sensei_Frontend::sensei_course_meta_video', '1.9.0', 'Sensei_Course::the_course_video()');
1218 1218
         Sensei_Course::the_course_video();
1219 1219
 	} // End sensei_course_meta_video()
1220 1220
 
@@ -1229,12 +1229,12 @@  discard block
 block discarded – undo
1229 1229
     public function sensei_woocommerce_in_cart_message() {
1230 1230
 		global $post, $woocommerce;
1231 1231
 
1232
-		$wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
1233
-        $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() );
1234
-		if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
1232
+		$wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true));
1233
+        $user_course_status_id = Sensei_Utils::user_started_course($post->ID, get_current_user_id());
1234
+		if (0 < intval($wc_post_id) && ! $user_course_status_id) {
1235 1235
 
1236
-			if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) {
1237
-				echo '<div class="sensei-message info">' . sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei') . '</div>', '<a class="cart-complete" href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __('complete the purchase', 'woothemes-sensei') . '">' . __('complete the purchase', 'woothemes-sensei') . '</a>' );
1236
+			if (Sensei_WC::is_product_in_cart($wc_post_id)) {
1237
+				echo '<div class="sensei-message info">'.sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei').'</div>', '<a class="cart-complete" href="'.$woocommerce->cart->get_checkout_url().'" title="'.__('complete the purchase', 'woothemes-sensei').'">'.__('complete the purchase', 'woothemes-sensei').'</a>');
1238 1238
 			} // End If Statement
1239 1239
 
1240 1240
 		} // End If Statement
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 	} // End sensei_woocommerce_in_cart_message()
1243 1243
 
1244 1244
 	// Deprecated
1245
-	public function sensei_lesson_comment_count( $count ) {
1245
+	public function sensei_lesson_comment_count($count) {
1246 1246
 		return $count;
1247 1247
 	} // End sensei_lesson_comment_count()
1248 1248
 
@@ -1251,11 +1251,11 @@  discard block
 block discarded – undo
1251 1251
 	 * @param  string $content Original content
1252 1252
 	 * @return string          Modified content
1253 1253
 	 */
1254
-	public function sensei_search_results_excerpt( $content ) {
1254
+	public function sensei_search_results_excerpt($content) {
1255 1255
 		global $post;
1256 1256
 
1257
-		if( is_search() && in_array( $post->post_type, array( 'course', 'lesson' ) ) ) {
1258
-			$content = '<p class="course-excerpt">' . the_excerpt( ) . '</p>';
1257
+		if (is_search() && in_array($post->post_type, array('course', 'lesson'))) {
1258
+			$content = '<p class="course-excerpt">'.the_excerpt( ).'</p>';
1259 1259
 		}
1260 1260
 
1261 1261
 		return $content;
@@ -1266,11 +1266,11 @@  discard block
 block discarded – undo
1266 1266
 	 * @param  integer $order_id ID of order
1267 1267
 	 * @return void
1268 1268
 	 */
1269
-	public function remove_active_course( $order_id ) {
1270
-		$order = new WC_Order( $order_id );
1269
+	public function remove_active_course($order_id) {
1270
+		$order = new WC_Order($order_id);
1271 1271
 
1272
-		foreach ( $order->get_items() as $item ) {
1273
-			if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1272
+		foreach ($order->get_items() as $item) {
1273
+			if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1274 1274
 				// If item has variation_id then its a variation of the product
1275 1275
 				$item_id = $item['variation_id'];
1276 1276
 			} else {
@@ -1278,11 +1278,11 @@  discard block
 block discarded – undo
1278 1278
 				$item_id = $item['product_id'];
1279 1279
 			} 
1280 1280
 
1281
-            if ( $item_id > 0 ) {
1281
+            if ($item_id > 0) {
1282 1282
 
1283
-				$user_id = get_post_meta( $order_id, '_customer_user', true );
1283
+				$user_id = get_post_meta($order_id, '_customer_user', true);
1284 1284
 
1285
-				if( $user_id ) {
1285
+				if ($user_id) {
1286 1286
 
1287 1287
 					// Get all courses for product
1288 1288
 					$args = array(
@@ -1298,13 +1298,13 @@  discard block
 block discarded – undo
1298 1298
 						'order' => 'ASC',
1299 1299
 						'fields' => 'ids',
1300 1300
 					);
1301
-					$course_ids = get_posts( $args );
1301
+					$course_ids = get_posts($args);
1302 1302
 
1303
-					if( $course_ids && count( $course_ids ) > 0 ) {
1304
-						foreach( $course_ids as $course_id ) {
1303
+					if ($course_ids && count($course_ids) > 0) {
1304
+						foreach ($course_ids as $course_id) {
1305 1305
 
1306 1306
 							// Remove all course user meta
1307
-							Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1307
+							Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1308 1308
 
1309 1309
 						} // End For Loop
1310 1310
 					} // End If Statement
@@ -1320,16 +1320,16 @@  discard block
 block discarded – undo
1320 1320
 	 * @param  integer $user_id User ID
1321 1321
 	 * @return void
1322 1322
 	 */
1323
-	public function activate_purchased_courses( $user_id = 0 ) {
1323
+	public function activate_purchased_courses($user_id = 0) {
1324 1324
 
1325
-		if( $user_id ) {
1325
+		if ($user_id) {
1326 1326
 
1327
-			if( Sensei_WC::is_woocommerce_active() ) {
1327
+			if (Sensei_WC::is_woocommerce_active()) {
1328 1328
 
1329 1329
 				// Get all user's orders
1330 1330
 				$order_args = array(
1331 1331
 					'post_type' => 'shop_order',
1332
-					'post_status' =>  array( 'wc-processing', 'wc-completed' ),
1332
+					'post_status' =>  array('wc-processing', 'wc-completed'),
1333 1333
 					'posts_per_page' => -1,
1334 1334
 					'meta_query' => array(
1335 1335
 						array(
@@ -1339,25 +1339,25 @@  discard block
 block discarded – undo
1339 1339
 					),
1340 1340
 				);
1341 1341
 
1342
-				$orders = get_posts( $order_args );
1342
+				$orders = get_posts($order_args);
1343 1343
 
1344 1344
 				$product_ids = array();
1345 1345
 				$order_ids = array();
1346 1346
 
1347
-				foreach( $orders as $post_id ) {
1347
+				foreach ($orders as $post_id) {
1348 1348
 
1349 1349
 					// Only process each order once
1350
-					$processed = get_post_meta( $post_id, 'sensei_products_processed', true );
1350
+					$processed = get_post_meta($post_id, 'sensei_products_processed', true);
1351 1351
 
1352
-					if( $processed && $processed == 'processed' ) {
1352
+					if ($processed && $processed == 'processed') {
1353 1353
 						continue;
1354 1354
 					}
1355 1355
 
1356 1356
 					// Get course product IDs from order
1357
-					$order = new WC_Order( $post_id );
1357
+					$order = new WC_Order($post_id);
1358 1358
 
1359 1359
 					$items = $order->get_items();
1360
-					foreach( $items as $item ) {
1360
+					foreach ($items as $item) {
1361 1361
                                             if (isset($item['variation_id']) && $item['variation_id'] > 0) {
1362 1362
                                                 $item_id = $item['variation_id'];
1363 1363
                                                 $product_type = 'variation';
@@ -1371,7 +1371,7 @@  discard block
 block discarded – undo
1371 1371
 					$order_ids[] = $post_id;
1372 1372
 				}
1373 1373
 
1374
-				if( count( $product_ids ) > 0 ) {
1374
+				if (count($product_ids) > 0) {
1375 1375
 
1376 1376
 					// Get all courses from user's orders
1377 1377
 					$course_args = array(
@@ -1388,31 +1388,31 @@  discard block
 block discarded – undo
1388 1388
 						'order' => 'ASC',
1389 1389
 						'fields' => 'ids',
1390 1390
 					);
1391
-					$course_ids = get_posts( $course_args );
1391
+					$course_ids = get_posts($course_args);
1392 1392
 
1393
-					foreach( $course_ids as $course_id ) {
1393
+					foreach ($course_ids as $course_id) {
1394 1394
 
1395
-						$user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id );
1395
+						$user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id);
1396 1396
 
1397 1397
 						// Ignore course if already completed
1398
-						if( Sensei_Utils::user_completed_course( $user_course_status ) ) {
1398
+						if (Sensei_Utils::user_completed_course($user_course_status)) {
1399 1399
 							continue;
1400 1400
 						}
1401 1401
 
1402 1402
 						// Ignore course if already started
1403
-						if( $user_course_status ) {
1403
+						if ($user_course_status) {
1404 1404
 							continue;
1405 1405
 						}
1406 1406
 
1407 1407
 						// Mark course as started by user
1408
-						Sensei_Utils::user_start_course( $user_id, $course_id );
1408
+						Sensei_Utils::user_start_course($user_id, $course_id);
1409 1409
 					}
1410 1410
 				}
1411 1411
 
1412
-				if( count( $order_ids ) > 0 ) {
1413
-					foreach( $order_ids as $order_id ) {
1412
+				if (count($order_ids) > 0) {
1413
+					foreach ($order_ids as $order_id) {
1414 1414
 						// Mark order as processed
1415
-						update_post_meta( $order_id, 'sensei_products_processed', 'processed' );
1415
+						update_post_meta($order_id, 'sensei_products_processed', 'processed');
1416 1416
 					}
1417 1417
 				}
1418 1418
 			}
@@ -1426,28 +1426,28 @@  discard block
 block discarded – undo
1426 1426
 	public function activate_purchased_single_course() {
1427 1427
 		global $post, $current_user;
1428 1428
 
1429
-		if( Sensei_WC::is_woocommerce_active() ) {
1429
+		if (Sensei_WC::is_woocommerce_active()) {
1430 1430
 
1431
-			if( ! is_user_logged_in() ) return;
1432
-			if( ! isset( $post->ID ) ) return;
1431
+			if ( ! is_user_logged_in()) return;
1432
+			if ( ! isset($post->ID)) return;
1433 1433
 
1434 1434
 			$user_id = $current_user->ID;
1435 1435
 			$course_id = $post->ID;
1436
-			$course_product_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
1437
-			if( ! $course_product_id ) {
1436
+			$course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
1437
+			if ( ! $course_product_id) {
1438 1438
 				return;
1439 1439
 			}
1440 1440
 
1441
-			$user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id );
1441
+			$user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id);
1442 1442
 
1443 1443
 			// Ignore course if already completed
1444
-			if( Sensei_Utils::user_completed_course( $user_course_status ) ) {
1444
+			if (Sensei_Utils::user_completed_course($user_course_status)) {
1445 1445
 
1446 1446
 				return;
1447 1447
 			}
1448 1448
 
1449 1449
 			// Ignore course if already started
1450
-			if( $user_course_status ) {
1450
+			if ($user_course_status) {
1451 1451
 				return;
1452 1452
 			}
1453 1453
 
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
 			$order_args = array(
1456 1456
 				'post_type' => 'shop_order',
1457 1457
 				'posts_per_page' => -1,
1458
-				'post_status' => array( 'wc-processing', 'wc-completed' ),
1458
+				'post_status' => array('wc-processing', 'wc-completed'),
1459 1459
 				'meta_query' => array(
1460 1460
 					array(
1461 1461
 						'key' => '_customer_user',
@@ -1464,28 +1464,28 @@  discard block
 block discarded – undo
1464 1464
 				),
1465 1465
 				'fields' => 'ids',
1466 1466
 			);
1467
-			$orders = get_posts( $order_args );
1467
+			$orders = get_posts($order_args);
1468 1468
 
1469
-			foreach( $orders as $order_post_id ) {
1469
+			foreach ($orders as $order_post_id) {
1470 1470
 
1471 1471
 				// Get course product IDs from order
1472
-				$order = new WC_Order( $order_post_id );
1472
+				$order = new WC_Order($order_post_id);
1473 1473
 
1474 1474
 				$items = $order->get_items();
1475
-				foreach( $items as $item ) {
1475
+				foreach ($items as $item) {
1476 1476
 
1477
-                    $product = wc_get_product( $item['product_id'] );
1477
+                    $product = wc_get_product($item['product_id']);
1478 1478
 
1479 1479
                     // handle product bundles
1480
-                    if( is_object( $product ) &&  $product->is_type('bundle') ){
1480
+                    if (is_object($product) && $product->is_type('bundle')) {
1481 1481
 
1482
-                        $bundled_product = new WC_Product_Bundle( $product->id );
1482
+                        $bundled_product = new WC_Product_Bundle($product->id);
1483 1483
                         $bundled_items = $bundled_product->get_bundled_items();
1484 1484
 
1485
-                        foreach( $bundled_items as $bundled_item ){
1485
+                        foreach ($bundled_items as $bundled_item) {
1486 1486
 
1487
-                            if( $bundled_item->product_id == $course_product_id ) {
1488
-                                Sensei_Utils::user_start_course( $user_id, $course_id );
1487
+                            if ($bundled_item->product_id == $course_product_id) {
1488
+                                Sensei_Utils::user_start_course($user_id, $course_id);
1489 1489
                                 return;
1490 1490
                             }
1491 1491
 
@@ -1494,8 +1494,8 @@  discard block
 block discarded – undo
1494 1494
                     } else {
1495 1495
 
1496 1496
                     // handle regular products
1497
-                        if( $item['product_id'] == $course_product_id ) {
1498
-                            Sensei_Utils::user_start_course( $user_id, $course_id );
1497
+                        if ($item['product_id'] == $course_product_id) {
1498
+                            Sensei_Utils::user_start_course($user_id, $course_id);
1499 1499
                             return;
1500 1500
                         }
1501 1501
 
@@ -1511,9 +1511,9 @@  discard block
 block discarded – undo
1511 1511
 	 * @param  array  $args Default arguments
1512 1512
 	 * @return array        Modified arguments
1513 1513
 	 */
1514
-	public function hide_sensei_activity( $args = array() ) {
1514
+	public function hide_sensei_activity($args = array()) {
1515 1515
 
1516
-		if( is_singular( 'lesson' ) || is_singular( 'course' ) ) {
1516
+		if (is_singular('lesson') || is_singular('course')) {
1517 1517
 			$args['type'] = 'comment';
1518 1518
 		}
1519 1519
 
@@ -1530,9 +1530,9 @@  discard block
 block discarded – undo
1530 1530
 
1531 1531
 		//if not posted from the sensei login form let
1532 1532
 		// WordPress or any other party handle the failed request
1533
-	    if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form']  ){
1533
+	    if ( ! isset($_REQUEST['form']) || 'sensei-login' != $_REQUEST['form']) {
1534 1534
 
1535
-	    	return ;
1535
+	    	return;
1536 1536
 
1537 1537
 	    }
1538 1538
 
@@ -1540,9 +1540,9 @@  discard block
 block discarded – undo
1540 1540
     	$referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']);
1541 1541
 
1542 1542
    		 // if there's a valid referrer, and it's not the default log-in screen
1543
-	    if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){
1543
+	    if ( ! empty($referrer) && ! strstr($referrer, 'wp-login') && ! strstr($referrer, 'wp-admin')) {
1544 1544
 	        // let's append some information (login=failed) to the URL for the theme to use
1545
-	        wp_redirect( esc_url_raw( add_query_arg('login', 'failed',  $referrer) ) );
1545
+	        wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer)));
1546 1546
 	    	exit;
1547 1547
     	}
1548 1548
 	}// End sensei_login_fail_redirect_to_front_end_login
@@ -1555,10 +1555,10 @@  discard block
 block discarded – undo
1555 1555
 	function sensei_handle_login_request( ) {
1556 1556
 
1557 1557
 		// Check that it is a sensei login request and if it has a valid nonce
1558
-	    if(  isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) {
1558
+	    if (isset($_REQUEST['form']) && 'sensei-login' == $_REQUEST['form']) {
1559 1559
 
1560 1560
 	    	// Validate the login request nonce
1561
-		    if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){
1561
+		    if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'sensei-login')) {
1562 1562
 		    	return;
1563 1563
 		    }
1564 1564
 
@@ -1566,48 +1566,48 @@  discard block
 block discarded – undo
1566 1566
 		    $referrer = $_REQUEST['_wp_http_referer'];
1567 1567
 		    //$redirect = $_REQUEST['_sensei_redirect'];
1568 1568
 
1569
-		    if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) )
1570
-		    	 && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){
1569
+		    if ((isset($_REQUEST['log']) && ! empty($_REQUEST['log']))
1570
+		    	 && (isset($_REQUEST['pwd']) && ! empty($_REQUEST['pwd']))) {
1571 1571
 
1572 1572
 		    	// when the user has entered a password or username do the sensei login
1573 1573
 		    	$creds = array();
1574 1574
 
1575 1575
 		    	// check if the requests login is an email address
1576
-		    	if( is_email(  trim( $_REQUEST['log'] ) )  ){
1576
+		    	if (is_email(trim($_REQUEST['log']))) {
1577 1577
 		    		// query wordpress for the users details
1578
-		    		$user =	get_user_by( 'email', sanitize_email( $_REQUEST['log'] )  );
1578
+		    		$user = get_user_by('email', sanitize_email($_REQUEST['log']));
1579 1579
 
1580 1580
 		    		// validate the user object
1581
-		    		if( !$user ){
1581
+		    		if ( ! $user) {
1582 1582
 
1583 1583
 		    			// the email doesnt exist
1584
-                        wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1584
+                        wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer)));
1585 1585
 		        		exit;
1586 1586
 
1587 1587
 		    		}
1588 1588
 
1589 1589
 		    		//assigne the username to the creds array for further processing
1590
-		    		$creds['user_login'] =  $user->user_login ;
1590
+		    		$creds['user_login'] = $user->user_login;
1591 1591
 
1592
-		    	}else{
1592
+		    	} else {
1593 1593
 
1594 1594
 		    		// process this as a default username login
1595
-		    		$creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ;
1595
+		    		$creds['user_login'] = sanitize_text_field($_REQUEST['log']);
1596 1596
 
1597 1597
 		    	}
1598 1598
 
1599 1599
 				// get setup the rest of the creds array
1600
-				$creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] );
1601
-				$creds['remember'] = isset( $_REQUEST['rememberme'] ) ? true : false ;
1600
+				$creds['user_password'] = sanitize_text_field($_REQUEST['pwd']);
1601
+				$creds['remember'] = isset($_REQUEST['rememberme']) ? true : false;
1602 1602
 
1603 1603
 				//attempt logging in with the given details
1604 1604
 			    $secure_cookie = is_ssl() ? true : false;
1605
-			    $user = wp_signon( $creds, $secure_cookie );
1605
+			    $user = wp_signon($creds, $secure_cookie);
1606 1606
 
1607
-				if ( is_wp_error($user) ){ // on login failure
1608
-                    wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) );
1607
+				if (is_wp_error($user)) { // on login failure
1608
+                    wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer)));
1609 1609
                     exit;
1610
-				}else{ // on login success
1610
+				} else { // on login success
1611 1611
 
1612 1612
 					/**
1613 1613
 					* change the redirect url programatically
@@ -1617,21 +1617,21 @@  discard block
 block discarded – undo
1617 1617
 					* @param string $referrer the page where the current url wheresensei login form was posted from
1618 1618
 					*/
1619 1619
 
1620
-					$success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) );
1620
+					$success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg('login', $referrer));
1621 1621
 
1622
-					wp_redirect( esc_url_raw( $success_redirect_url ) );
1622
+					wp_redirect(esc_url_raw($success_redirect_url));
1623 1623
 		        	exit;
1624 1624
 
1625 1625
 				}	// end is_wp_error($user)
1626 1626
 
1627
-		    }else{ // if username or password is empty
1627
+		    } else { // if username or password is empty
1628 1628
 
1629
-                wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) );
1629
+                wp_redirect(esc_url_raw(add_query_arg('login', 'emptyfields', $referrer)));
1630 1630
 		        exit;
1631 1631
 
1632 1632
 		    } // end if username $_REQUEST['log']  and password $_REQUEST['pwd'] is empty
1633 1633
 
1634
-	    }elseif( ( isset( $_GET['login'] ) ) ) {
1634
+	    }elseif ((isset($_GET['login']))) {
1635 1635
 	    	// else if this request is a redircect from a previously faile login request
1636 1636
 	    	$this->login_message_process();
1637 1637
 
@@ -1650,87 +1650,87 @@  discard block
 block discarded – undo
1650 1650
 	 * @return void redirect
1651 1651
 	 *
1652 1652
 	 */
1653
-	public function sensei_process_registration(){
1653
+	public function sensei_process_registration() {
1654 1654
 		global 	 $current_user;
1655 1655
 		// check the for the sensei specific registration requests
1656
-		if( !isset( $_POST['sensei_reg_username'] ) && ! isset( $_POST['sensei_reg_email'] ) && !isset( $_POST['sensei_reg_password'] )){
1656
+		if ( ! isset($_POST['sensei_reg_username']) && ! isset($_POST['sensei_reg_email']) && ! isset($_POST['sensei_reg_password'])) {
1657 1657
 			// exit if this is not a sensei registration request
1658
-			return ;
1658
+			return;
1659 1659
 		}
1660 1660
 		// check for spam throw cheating huh
1661
-		if( isset( $_POST['email_2'] ) &&  '' !== $_POST['email_2']   ){
1661
+		if (isset($_POST['email_2']) && '' !== $_POST['email_2']) {
1662 1662
 			$message = 'Error:  The spam field should be empty';
1663
-			Sensei()->notices->add_notice( $message, 'alert');
1663
+			Sensei()->notices->add_notice($message, 'alert');
1664 1664
 			return;
1665 1665
 		}
1666 1666
 
1667 1667
 		// retreive form variables
1668
-		$new_user_name		= sanitize_user( $_POST['sensei_reg_username'] );
1669
-		$new_user_email		= $_POST['sensei_reg_email'];
1670
-		$new_user_password	= $_POST['sensei_reg_password'];
1668
+		$new_user_name = sanitize_user($_POST['sensei_reg_username']);
1669
+		$new_user_email = $_POST['sensei_reg_email'];
1670
+		$new_user_password = $_POST['sensei_reg_password'];
1671 1671
 
1672 1672
 		// Check the username
1673 1673
 		$username_error_notice = '';
1674
-		if ( $new_user_name == '' ) {
1675
-			$username_error_notice =  __( '<strong>ERROR</strong>: Please enter a username.' );
1676
-		} elseif ( ! validate_username( $new_user_name ) ) {
1677
-			$username_error_notice =  __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' );
1678
-		} elseif ( username_exists( $new_user_name ) ) {
1679
-			$username_error_notice =  __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' );
1674
+		if ($new_user_name == '') {
1675
+			$username_error_notice = __('<strong>ERROR</strong>: Please enter a username.');
1676
+		} elseif ( ! validate_username($new_user_name)) {
1677
+			$username_error_notice = __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.');
1678
+		} elseif (username_exists($new_user_name)) {
1679
+			$username_error_notice = __('<strong>ERROR</strong>: This username is already registered. Please choose another one.');
1680 1680
 		}
1681 1681
 
1682 1682
 		// exit on username error
1683
-		if( '' !== $username_error_notice ){
1684
-			Sensei()->notices->add_notice( $username_error_notice , 'alert');
1683
+		if ('' !== $username_error_notice) {
1684
+			Sensei()->notices->add_notice($username_error_notice, 'alert');
1685 1685
 			return;
1686 1686
 		}
1687 1687
 
1688 1688
 		// Check the e-mail address
1689 1689
 		$email_error_notice = '';
1690
-		if ( $new_user_email == '' ) {
1691
-			$email_error_notice = __( '<strong>ERROR</strong>: Please type your e-mail address.' );
1692
-		} elseif ( ! is_email( $new_user_email ) ) {
1693
-			$email_error_notice = __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' );
1694
-		} elseif ( email_exists( $new_user_email ) ) {
1695
-			$email_error_notice = __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' );
1690
+		if ($new_user_email == '') {
1691
+			$email_error_notice = __('<strong>ERROR</strong>: Please type your e-mail address.');
1692
+		} elseif ( ! is_email($new_user_email)) {
1693
+			$email_error_notice = __('<strong>ERROR</strong>: The email address isn&#8217;t correct.');
1694
+		} elseif (email_exists($new_user_email)) {
1695
+			$email_error_notice = __('<strong>ERROR</strong>: This email is already registered, please choose another one.');
1696 1696
 		}
1697 1697
 
1698 1698
 		// exit on email address error
1699
-		if( '' !== $email_error_notice ){
1700
-			Sensei()->notices->add_notice( $email_error_notice , 'alert');
1699
+		if ('' !== $email_error_notice) {
1700
+			Sensei()->notices->add_notice($email_error_notice, 'alert');
1701 1701
 			return;
1702 1702
 		}
1703 1703
 
1704 1704
 		//check user password
1705 1705
 
1706 1706
 		// exit on email address error
1707
-		if( empty( $new_user_password ) ){
1708
-			Sensei()->notices->add_notice(  __( '<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.' )  , 'alert');
1707
+		if (empty($new_user_password)) {
1708
+			Sensei()->notices->add_notice(__('<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.'), 'alert');
1709 1709
 			return;
1710 1710
 		}
1711 1711
 
1712 1712
 		// register user
1713
-		$user_id = wp_create_user( $new_user_name, $new_user_password, $new_user_email );
1714
-		if ( ! $user_id || is_wp_error( $user_id ) ) {
1715
-			Sensei()->notices->add_notice( sprintf( __( '<strong>ERROR</strong>: Couldn\'t register you&hellip; please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ), 'alert');
1713
+		$user_id = wp_create_user($new_user_name, $new_user_password, $new_user_email);
1714
+		if ( ! $user_id || is_wp_error($user_id)) {
1715
+			Sensei()->notices->add_notice(sprintf(__('<strong>ERROR</strong>: Couldn\'t register you&hellip; please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')), 'alert');
1716 1716
 		}
1717 1717
 
1718 1718
 		// notify the user
1719
-		wp_new_user_notification( $user_id, $new_user_password );
1719
+		wp_new_user_notification($user_id, $new_user_password);
1720 1720
 
1721 1721
 		// set global current user aka log the user in
1722
-		$current_user = get_user_by( 'id', $user_id );
1723
-		wp_set_auth_cookie( $user_id, true );
1722
+		$current_user = get_user_by('id', $user_id);
1723
+		wp_set_auth_cookie($user_id, true);
1724 1724
 
1725 1725
 		// Redirect
1726 1726
 		global $wp;
1727
-		if ( wp_get_referer() ) {
1728
-			$redirect = esc_url( wp_get_referer() );
1727
+		if (wp_get_referer()) {
1728
+			$redirect = esc_url(wp_get_referer());
1729 1729
 		} else {
1730
-			$redirect = esc_url( home_url( $wp->request ) );
1730
+			$redirect = esc_url(home_url($wp->request));
1731 1731
 		}
1732 1732
 
1733
-		wp_redirect( apply_filters( 'sensei_registration_redirect', $redirect ) );
1733
+		wp_redirect(apply_filters('sensei_registration_redirect', $redirect));
1734 1734
 		exit;
1735 1735
 
1736 1736
 	} // end  sensei_process_registration)()
@@ -1741,23 +1741,23 @@  discard block
 block discarded – undo
1741 1741
 	 * @return void redirect
1742 1742
 	 * @since 1.7.0
1743 1743
 	 */
1744
-	public function login_message_process(){
1744
+	public function login_message_process() {
1745 1745
 
1746 1746
             // setup the message variables
1747 1747
 			$message = '';
1748 1748
 
1749 1749
 			//only output message if the url contains login=failed and login=emptyfields
1750 1750
 
1751
-			if( $_GET['login'] == 'failed' ){
1751
+			if ($_GET['login'] == 'failed') {
1752 1752
 
1753
-				$message = __('Incorrect login details', 'woothemes-sensei' );
1753
+				$message = __('Incorrect login details', 'woothemes-sensei');
1754 1754
 
1755
-			}elseif( $_GET['login'] == 'emptyfields'  ){
1755
+			}elseif ($_GET['login'] == 'emptyfields') {
1756 1756
 
1757
-				$message= __('Please enter your username and password', 'woothemes-sensei' );
1757
+				$message = __('Please enter your username and password', 'woothemes-sensei');
1758 1758
 			}
1759 1759
 
1760
-			Sensei()->notices->add_notice( $message, 'alert');
1760
+			Sensei()->notices->add_notice($message, 'alert');
1761 1761
 
1762 1762
 	}// end login_message_process
1763 1763
 
@@ -1769,11 +1769,11 @@  discard block
 block discarded – undo
1769 1769
      * @return void redirect
1770 1770
      *
1771 1771
      */
1772
-    public function sensei_show_admin_bar () {
1772
+    public function sensei_show_admin_bar() {
1773 1773
 
1774 1774
         if (current_user_can('edit_courses')) {
1775 1775
 
1776
-            add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1);
1776
+            add_filter('woocommerce_disable_admin_bar', '__return_false', 10, 1);
1777 1777
 
1778 1778
         }
1779 1779
 
@@ -1786,4 +1786,4 @@  discard block
 block discarded – undo
1786 1786
  * @ignore only for backward compatibility
1787 1787
  * @since 1.9.0
1788 1788
  */
1789
-class WooThemes_Sensei_Frontend extends Sensei_Frontend{}
1789
+class WooThemes_Sensei_Frontend extends Sensei_Frontend {}
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 1 patch
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 62
         // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
63
+        add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10);
64
+        add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10);
65
+        add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20);
66 66
 
67 67
         // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
68
+        add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+        add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+        add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+        add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
72 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 82
         // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 85
         //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 97
         // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
98
+        add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+        add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 102
         //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 105
         // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
106
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
107
+        add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3);
108 108
 
109 109
         // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 153
             // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 158
             // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 194
             // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
195
+            $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />';
196 196
             if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 199
                 foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 203
             } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
204
+                $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit');
205
+                $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>';
206 206
             } // End If Statement
207 207
 
208 208
         } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
209
+            $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>';
210 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 227
         // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
228
+        if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce'])
229
+            ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) {
230 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 257
             // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 483
                 $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 492
                 $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 733
         $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 818
         //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 822
         $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 845
             if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
846
+                $html .= '<div class="updated fade">'."\n";
847
+                $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n";
848
+                $html .= '</div>'."\n";
849 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 853
 
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
854
+        $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
855
+        $html .= '<input type="hidden" name="post_type" value="course" />'."\n";
856
+        $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n";
857
+        $html .= '<select id="module-order-course" name="course_id">'."\n";
858
+        $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
859 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 869
 
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
870
+        $html .= '</select>'."\n";
871
+        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
872
+        $html .= '</form>'."\n";
873 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 906
 
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
907
+                    $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n";
908
+                    $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
909
+                    $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n";
910
+                    $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n";
911 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 946
             if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
947
+                echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>';
948 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 1038
                 $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 1092
                 foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1093
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1094 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 1136
                 foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1137
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1138 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,9 +1169,9 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if(    empty( $modules )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1172
+        if (empty($modules)
1173
+            || is_wp_error($modules)
1174
+            || isset($modules['errors'])) {
1175 1175
 
1176 1176
             return false;
1177 1177
 
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
        // get the last item in the array there should be only be 1 really.
1181 1181
        // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1182
+       foreach ($modules as $module) {
1183 1183
            break;
1184 1184
        }
1185 1185
 
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
         if (isset($course_id) && 0 < $course_id) {
1193 1193
 
1194 1194
             // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1195
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1196 1196
                 return false;
1197 1197
             }
1198 1198
 
@@ -1213,12 +1213,12 @@  discard block
 block discarded – undo
1213 1213
 	public function get_course_modules($course_id = 0)
1214 1214
 	{
1215 1215
 		$course_id = intval($course_id);
1216
-		if ( empty(  $course_id ) ) {
1216
+		if (empty($course_id)) {
1217 1217
 			return array();
1218 1218
 		}
1219 1219
 
1220 1220
 		// Get modules for course
1221
-		$modules = wp_get_post_terms( $course_id, $this->taxonomy );
1221
+		$modules = wp_get_post_terms($course_id, $this->taxonomy);
1222 1222
 
1223 1223
 		// Get custom module order for course
1224 1224
 		$order = $this->get_course_module_order($course_id);
@@ -1230,7 +1230,7 @@  discard block
 block discarded – undo
1230 1230
 		// Sort by custom order
1231 1231
 		$ordered_modules = array();
1232 1232
 		$unordered_modules = array();
1233
-		foreach ( $modules as $module ) {
1233
+		foreach ($modules as $module) {
1234 1234
 			$order_key = array_search($module->term_id, $order);
1235 1235
 			if ($order_key !== false) {
1236 1236
 				$ordered_modules[$order_key] = $module;
@@ -1240,16 +1240,16 @@  discard block
 block discarded – undo
1240 1240
 		}
1241 1241
 
1242 1242
 		// Order modules correctly
1243
-		ksort( $ordered_modules );
1243
+		ksort($ordered_modules);
1244 1244
 
1245 1245
 		// Append modules that have not yet been ordered
1246
-		if ( count($unordered_modules) > 0 ) {
1246
+		if (count($unordered_modules) > 0) {
1247 1247
 			$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1248 1248
 		}
1249 1249
 
1250 1250
 		// remove order key but maintain order
1251 1251
 		$ordered_modules_with_keys_in_sequence = array();
1252
-		foreach ( $ordered_modules as $key => $module ) {
1252
+		foreach ($ordered_modules as $key => $module) {
1253 1253
 
1254 1254
 			$ordered_modules_with_keys_in_sequence[] = $module;
1255 1255
 
@@ -1268,8 +1268,8 @@  discard block
 block discarded – undo
1268 1268
      */
1269 1269
     public function enqueue_styles() {
1270 1270
 
1271
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1272
-        wp_enqueue_style($this->taxonomy . '-frontend');
1271
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1272
+        wp_enqueue_style($this->taxonomy.'-frontend');
1273 1273
 
1274 1274
     }
1275 1275
 
@@ -1280,37 +1280,37 @@  discard block
 block discarded – undo
1280 1280
      *
1281 1281
      * @return void
1282 1282
      */
1283
-    public function admin_enqueue_scripts( $hook ) {
1283
+    public function admin_enqueue_scripts($hook) {
1284 1284
 
1285 1285
         /**
1286 1286
          * Filter the page hooks where modules admin script can be loaded on.
1287 1287
          *
1288 1288
          * @param array $white_listed_pages
1289 1289
          */
1290
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1290
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1291 1291
             'edit-tags.php',
1292 1292
             'course_page_module-order',
1293 1293
             'post-new.php',
1294 1294
             'post.php'
1295
-        ) );
1295
+        ));
1296 1296
 
1297
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1297
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1298 1298
             return;
1299 1299
         }
1300 1300
 
1301
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1301
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1302 1302
 
1303
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1304
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1305
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2' ), Sensei()->version, true );
1303
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1304
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1305
+        wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'sensei-core-select2'), Sensei()->version, true);
1306 1306
 
1307 1307
         // localized module data
1308 1308
         $localize_modulesAdmin = array(
1309
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1310
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1309
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1310
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1311 1311
         );
1312 1312
 
1313
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1313
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1314 1314
     }
1315 1315
 
1316 1316
     /**
@@ -1322,8 +1322,8 @@  discard block
 block discarded – undo
1322 1322
      */
1323 1323
     public function admin_enqueue_styles() {
1324 1324
 
1325
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1326
-        wp_enqueue_style($this->taxonomy . '-sortable');
1325
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1326
+        wp_enqueue_style($this->taxonomy.'-sortable');
1327 1327
 
1328 1328
     }
1329 1329
 
@@ -1337,9 +1337,9 @@  discard block
 block discarded – undo
1337 1337
      */
1338 1338
     public function course_modules_title( ) {
1339 1339
 
1340
-       if( sensei_module_has_lessons() ){
1340
+       if (sensei_module_has_lessons()) {
1341 1341
 
1342
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1342
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1343 1343
 
1344 1344
         }
1345 1345
 
@@ -1352,22 +1352,22 @@  discard block
 block discarded – undo
1352 1352
      * @since 1.8.0
1353 1353
      * @return void
1354 1354
      */
1355
-    public function load_course_module_content_template(){
1355
+    public function load_course_module_content_template() {
1356 1356
 
1357
-	    if ( ! is_singular( 'course' )  ) {
1357
+	    if ( ! is_singular('course')) {
1358 1358
 		    return;
1359 1359
 	    }
1360 1360
 
1361 1361
         // load backwards compatible template name if it exists in the users theme
1362
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1363
-        if( $located_template ){
1362
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1363
+        if ($located_template) {
1364 1364
 
1365
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1365
+            Sensei_Templates::get_template('single-course/course-modules.php');
1366 1366
             return;
1367 1367
 
1368 1368
         }
1369 1369
 
1370
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1370
+        Sensei_Templates::get_template('single-course/modules.php');
1371 1371
 
1372 1372
     } // end course_module_content
1373 1373
 
@@ -1380,15 +1380,15 @@  discard block
 block discarded – undo
1380 1380
      * @param $term_id
1381 1381
      * @return array $lessons
1382 1382
      */
1383
-    public function get_lessons( $course_id , $term_id ){
1383
+    public function get_lessons($course_id, $term_id) {
1384 1384
 
1385
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1385
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1386 1386
 
1387
-        if( isset( $lesson_query->posts ) ){
1387
+        if (isset($lesson_query->posts)) {
1388 1388
 
1389 1389
             return $lesson_query->posts;
1390 1390
 
1391
-        }else{
1391
+        } else {
1392 1392
 
1393 1393
             return array();
1394 1394
 
@@ -1405,9 +1405,9 @@  discard block
 block discarded – undo
1405 1405
      * @param $term_id
1406 1406
      * @return WP_Query $lessons_query
1407 1407
      */
1408
-    public function get_lessons_query( $course_id , $term_id ){
1408
+    public function get_lessons_query($course_id, $term_id) {
1409 1409
 
1410
-        if( empty( $term_id ) || empty( $course_id ) ){
1410
+        if (empty($term_id) || empty($course_id)) {
1411 1411
 
1412 1412
             return array();
1413 1413
 
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
                 array(
1429 1429
                     'taxonomy' => 'module',
1430 1430
                     'field' => 'id',
1431
-                    'terms' => intval( $term_id )
1431
+                    'terms' => intval($term_id)
1432 1432
                 )
1433 1433
             ),
1434 1434
             'orderby' => 'menu_order',
@@ -1436,12 +1436,12 @@  discard block
 block discarded – undo
1436 1436
             'suppress_filters' => 0
1437 1437
         );
1438 1438
 
1439
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1440
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1439
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1440
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1441 1441
             $args['orderby'] = 'meta_value_num date';
1442 1442
         }
1443 1443
 
1444
-        $lessons_query = new WP_Query( $args );
1444
+        $lessons_query = new WP_Query($args);
1445 1445
 
1446 1446
         return $lessons_query;
1447 1447
 
@@ -1456,37 +1456,37 @@  discard block
 block discarded – undo
1456 1456
      *
1457 1457
      * @return array $non_module_lessons
1458 1458
      */
1459
-    public function get_none_module_lessons( $course_id ){
1459
+    public function get_none_module_lessons($course_id) {
1460 1460
 
1461 1461
         $non_module_lessons = array();
1462 1462
 
1463 1463
         //exit if there is no course id passed in
1464
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1464
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1465 1465
 
1466 1466
             return $non_module_lessons;
1467 1467
         }
1468 1468
 
1469 1469
         //save some time and check if we already have the saved
1470
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1470
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1471 1471
 
1472
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1472
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         // create terms array which must be excluded from other arrays
1477
-        $course_modules = $this->get_course_modules( $course_id );
1477
+        $course_modules = $this->get_course_modules($course_id);
1478 1478
 
1479 1479
         //exit if there are no module on this course
1480
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1480
+        if (empty($course_modules) || ! is_array($course_modules)) {
1481 1481
 
1482
-            return  Sensei()->course->course_lessons( $course_id );
1482
+            return  Sensei()->course->course_lessons($course_id);
1483 1483
 
1484 1484
         }
1485 1485
 
1486 1486
         $terms = array();
1487
-        foreach( $course_modules as $module ){
1487
+        foreach ($course_modules as $module) {
1488 1488
 
1489
-            array_push( $terms ,  $module->term_id );
1489
+            array_push($terms, $module->term_id);
1490 1490
 
1491 1491
         }
1492 1492
 
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
             'meta_query' => array(
1498 1498
                 array(
1499 1499
                     'key' => '_lesson_course',
1500
-                    'value' => intval( $course_id ),
1500
+                    'value' => intval($course_id),
1501 1501
                     'compare' => '='
1502 1502
                 )
1503 1503
             ),
@@ -1514,11 +1514,11 @@  discard block
 block discarded – undo
1514 1514
             'suppress_filters' => 0
1515 1515
         );
1516 1516
 
1517
-        $wp_lessons_query = new WP_Query( $args );
1517
+        $wp_lessons_query = new WP_Query($args);
1518 1518
 
1519
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1519
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1520 1520
             $non_module_lessons = $wp_lessons_query->get_posts();
1521
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1521
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1522 1522
         }
1523 1523
 
1524 1524
         return $non_module_lessons;
@@ -1529,7 +1529,7 @@  discard block
 block discarded – undo
1529 1529
      *
1530 1530
      * @since 1.8.0
1531 1531
      */
1532
-    public function setup_modules_taxonomy(){
1532
+    public function setup_modules_taxonomy() {
1533 1533
 
1534 1534
         $labels = array(
1535 1535
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1566,11 +1566,11 @@  discard block
 block discarded – undo
1566 1566
             'show_in_nav_menus' => false,
1567 1567
             'show_in_quick_edit' => false,
1568 1568
             'show_ui' => true,
1569
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1569
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1570 1570
             'labels' => $labels
1571 1571
         );
1572 1572
 
1573
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1573
+        register_taxonomy('module', array('course', 'lesson'), $args);
1574 1574
 
1575 1575
     }// end setup_modules_taxonomy
1576 1576
 
@@ -1582,12 +1582,12 @@  discard block
 block discarded – undo
1582 1582
      * @since 1.8.0
1583 1583
      * @return void
1584 1584
      */
1585
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1585
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1586 1586
 
1587
-        global $typenow , $taxnow;
1587
+        global $typenow, $taxnow;
1588 1588
 
1589
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1590
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1589
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1590
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1591 1591
         }
1592 1592
 
1593 1593
     }// end redirect to course taxonomy
@@ -1600,18 +1600,18 @@  discard block
 block discarded – undo
1600 1600
      * @since 1.8.0
1601 1601
      * @return void
1602 1602
      */
1603
-    public function remove_lessons_menu_model_taxonomy(){
1603
+    public function remove_lessons_menu_model_taxonomy() {
1604 1604
         global $submenu;
1605 1605
 
1606
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1606
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1607 1607
             return; // exit
1608 1608
         }
1609 1609
 
1610 1610
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1611
-        foreach( $lesson_main_menu as $index => $sub_item ){
1611
+        foreach ($lesson_main_menu as $index => $sub_item) {
1612 1612
 
1613
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1614
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1613
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1614
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1615 1615
             }
1616 1616
         }
1617 1617
 
@@ -1625,18 +1625,18 @@  discard block
 block discarded – undo
1625 1625
      * @since 1.8.0
1626 1626
      * @return void
1627 1627
      */
1628
-    public function remove_courses_menu_model_taxonomy(){
1628
+    public function remove_courses_menu_model_taxonomy() {
1629 1629
         global $submenu;
1630 1630
 
1631
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1631
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1632 1632
             return; // exit
1633 1633
         }
1634 1634
 
1635 1635
         $course_main_menu = $submenu['edit.php?post_type=course'];
1636
-        foreach( $course_main_menu as $index => $sub_item ){
1636
+        foreach ($course_main_menu as $index => $sub_item) {
1637 1637
 
1638
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1639
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1638
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1639
+                unset($submenu['edit.php?post_type=course'][$index]);
1640 1640
             }
1641 1641
         }
1642 1642
 
@@ -1652,12 +1652,12 @@  discard block
 block discarded – undo
1652 1652
      * @param string $term_name
1653 1653
      * @return array $owners { type WP_User }. Empty array if none if found.
1654 1654
      */
1655
-    public static function get_term_authors( $term_name ){
1655
+    public static function get_term_authors($term_name) {
1656 1656
 
1657
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1657
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1658 1658
 
1659 1659
         $owners = array();
1660
-        if( empty( $terms ) ){
1660
+        if (empty($terms)) {
1661 1661
 
1662 1662
             return $owners;
1663 1663
 
@@ -1667,11 +1667,11 @@  discard block
 block discarded – undo
1667 1667
 
1668 1668
 
1669 1669
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1670
-        foreach( $terms as $term){
1671
-            if( $term->name == $term_name ){
1670
+        foreach ($terms as $term) {
1671
+            if ($term->name == $term_name) {
1672 1672
 
1673 1673
                 // look for the author in the slug
1674
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1674
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1675 1675
 
1676 1676
             }// end if term name
1677 1677
 
@@ -1692,30 +1692,30 @@  discard block
 block discarded – undo
1692 1692
      * @param $slug
1693 1693
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1694 1694
      */
1695
-    public static function get_term_author( $slug='' ){
1695
+    public static function get_term_author($slug = '') {
1696 1696
 
1697
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1697
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1698 1698
 
1699
-        if( empty( $slug ) ){
1699
+        if (empty($slug)) {
1700 1700
 
1701 1701
             return $term_owner;
1702 1702
 
1703 1703
         }
1704 1704
 
1705 1705
         // look for the author in the slug
1706
-        $slug_parts = explode( '-', $slug );
1706
+        $slug_parts = explode('-', $slug);
1707 1707
 
1708
-        if( count( $slug_parts ) > 1 ){
1708
+        if (count($slug_parts) > 1) {
1709 1709
 
1710 1710
             // get the user data
1711 1711
             $possible_user_id = $slug_parts[0];
1712
-            $author = get_userdata( $possible_user_id );
1712
+            $author = get_userdata($possible_user_id);
1713 1713
 
1714 1714
             // if the user doesnt exist for the first part of the slug
1715 1715
             // then this slug was also created by admin
1716
-            if( is_a( $author, 'WP_User' ) ){
1716
+            if (is_a($author, 'WP_User')) {
1717 1717
 
1718
-                $term_owner =  $author;
1718
+                $term_owner = $author;
1719 1719
 
1720 1720
             }
1721 1721
         }
@@ -1732,48 +1732,48 @@  discard block
 block discarded – undo
1732 1732
      *
1733 1733
      * @param WP_Post $post Post object.
1734 1734
      */
1735
-    public function course_module_metabox( $post ) {
1735
+    public function course_module_metabox($post) {
1736 1736
 
1737 1737
         $tax_name = 'module';
1738
-        $taxonomy = get_taxonomy( 'module' );
1738
+        $taxonomy = get_taxonomy('module');
1739 1739
 
1740 1740
         ?>
1741 1741
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1742 1742
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1743 1743
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1744
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1744
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1745 1745
             </ul>
1746 1746
 
1747 1747
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1749
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1749
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752 1752
 
1753 1753
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1754 1754
                 <?php
1755
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1755
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1756 1756
                 echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1757 1757
                 ?>
1758 1758
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1759
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1759
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1760 1760
                 </ul>
1761 1761
             </div>
1762
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1762
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1763 1763
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1764 1764
                     <h4>
1765 1765
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1766 1766
                             <?php
1767 1767
                             /* translators: %s: add new taxonomy label */
1768
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1768
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1769 1769
                             ?>
1770 1770
                         </a>
1771 1771
                     </h4>
1772 1772
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1773 1773
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1774
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1775
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1776
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1774
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1775
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1776
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1777 1777
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1778 1778
                     </p>
1779 1779
                 </div>
@@ -1793,55 +1793,55 @@  discard block
 block discarded – undo
1793 1793
     public static function add_new_module_term( ) {
1794 1794
 
1795 1795
 
1796
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1797
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1796
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1797
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1798 1798
         }
1799 1799
 
1800 1800
         // get the term an create the new term storing infomration
1801
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1801
+        $term_name = sanitize_text_field($_POST['newTerm']);
1802 1802
 
1803
-        if( current_user_can('manage_options' ) ) {
1803
+        if (current_user_can('manage_options')) {
1804 1804
 
1805
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1805
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1806 1806
 
1807 1807
         } else {
1808 1808
 
1809
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1809
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1810 1810
 
1811 1811
         }
1812 1812
 
1813
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1813
+        $course_id = sanitize_text_field($_POST['course_id']);
1814 1814
 
1815 1815
         // save the term
1816
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1816
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1817 1817
 
1818 1818
         // send error for all errors except term exits
1819
-        if( is_wp_error( $slug ) ){
1819
+        if (is_wp_error($slug)) {
1820 1820
 
1821 1821
             // prepare for possible term name and id to be passed down if term exists
1822 1822
             $term_data = array();
1823 1823
 
1824 1824
             // if term exists also send back the term name and id
1825
-            if( isset( $slug->errors['term_exists'] ) ){
1825
+            if (isset($slug->errors['term_exists'])) {
1826 1826
 
1827
-                $term = get_term_by( 'slug', $term_slug, 'module');
1827
+                $term = get_term_by('slug', $term_slug, 'module');
1828 1828
                 $term_data['name'] = $term_name;
1829 1829
                 $term_data['id'] = $term->term_id;
1830 1830
 
1831 1831
                 // set the object terms
1832
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1832
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1833 1833
             }
1834 1834
 
1835
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1835
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1836 1836
 
1837 1837
         }
1838 1838
 
1839 1839
         //make sure the new term is checked for this course
1840 1840
 
1841
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1841
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1842 1842
 
1843 1843
         // Handle request then generate response using WP_Ajax_Response
1844
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1844
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1845 1845
 
1846 1846
     }
1847 1847
 
@@ -1853,26 +1853,26 @@  discard block
 block discarded – undo
1853 1853
      *
1854 1854
      * @since 1.8.0
1855 1855
      */
1856
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1856
+    public function filter_module_terms($terms, $taxonomies, $args) {
1857 1857
 
1858 1858
         //dont limit for admins and other taxonomies. This should also only apply to admin
1859
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1859
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1860 1860
             return $terms;
1861 1861
         }
1862 1862
 
1863 1863
         // avoid infinite call loop
1864
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1865 1865
 
1866 1866
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1867
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1867
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1868 1868
             // change only scrub the terms ids form the array keys
1869
-            $terms = array_keys( $terms );
1869
+            $terms = array_keys($terms);
1870 1870
         }
1871 1871
 
1872
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1872
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1873 1873
 
1874 1874
         // add filter again as removed above
1875
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1875
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1876 1876
 
1877 1877
         return $teachers_terms;
1878 1878
     }// end filter_module_terms
@@ -1885,25 +1885,25 @@  discard block
 block discarded – undo
1885 1885
      *
1886 1886
      * @since 1.8.0
1887 1887
      */
1888
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1888
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1889 1889
 
1890 1890
         //dont limit for admins and other taxonomies. This should also only apply to admin
1891
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1891
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1892 1892
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1893
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1893
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1894 1894
             return $terms;
1895 1895
         }
1896 1896
 
1897
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1897
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1898 1898
 
1899 1899
         // if term objects were passed in send back objects
1900 1900
         // if term id were passed in send that back
1901
-        if( is_object( $terms[0] ) ){
1901
+        if (is_object($terms[0])) {
1902 1902
             return $term_objects;
1903 1903
         }
1904 1904
 
1905 1905
         $terms = array();
1906
-        foreach( $term_objects as $term_object ){
1906
+        foreach ($term_objects as $term_object) {
1907 1907
             $terms[] = $term_object->term_id;
1908 1908
         }
1909 1909
 
@@ -1921,20 +1921,20 @@  discard block
 block discarded – undo
1921 1921
      * @param $user_id
1922 1922
      * @return array
1923 1923
      */
1924
-    public function filter_terms_by_owner( $terms, $user_id ){
1924
+    public function filter_terms_by_owner($terms, $user_id) {
1925 1925
 
1926 1926
         $users_terms = array();
1927 1927
 
1928
-        foreach( $terms as $index => $term ){
1928
+        foreach ($terms as $index => $term) {
1929 1929
 
1930
-            if( is_numeric( $term ) ){
1930
+            if (is_numeric($term)) {
1931 1931
                 // the term id was given, get the term object
1932
-                $term = get_term( $term, 'module' );
1932
+                $term = get_term($term, 'module');
1933 1933
             }
1934 1934
 
1935
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1935
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1936 1936
 
1937
-            if ( $user_id == $author->ID ) {
1937
+            if ($user_id == $author->ID) {
1938 1938
                 // add the term to the teachers terms
1939 1939
                 $users_terms[] = $term;
1940 1940
             }
@@ -1953,34 +1953,34 @@  discard block
 block discarded – undo
1953 1953
      *
1954 1954
      * @since 1.8.0
1955 1955
      */
1956
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1956
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1957 1957
     {
1958 1958
 
1959 1959
         // only for admin users ont he module taxonomy
1960
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1960
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1961 1961
             return $terms;
1962 1962
         }
1963 1963
 
1964 1964
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1965 1965
         // simply return this as wp doesn't need an array of stdObject Term
1966
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1966
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1967 1967
 
1968 1968
             return $terms;
1969 1969
 
1970 1970
         }
1971 1971
 
1972 1972
         // loop through and update all terms adding the author name
1973
-        foreach( $terms as $index => $term ){
1973
+        foreach ($terms as $index => $term) {
1974 1974
 
1975
-            if( is_numeric( $term ) ){
1975
+            if (is_numeric($term)) {
1976 1976
                 // the term id was given, get the term object
1977
-                $term = get_term( $term, 'module' );
1977
+                $term = get_term($term, 'module');
1978 1978
             }
1979 1979
 
1980
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1980
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1981 1981
 
1982
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1983
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1982
+            if ( ! user_can($author, 'manage_options') && isset($term->name)) {
1983
+                $term->name = $term->name.' ('.$author->display_name.') ';
1984 1984
             }
1985 1985
 
1986 1986
             // add the term to the teachers terms
@@ -2009,23 +2009,23 @@  discard block
 block discarded – undo
2009 2009
      * @sine 1.9.0
2010 2010
      * @param $post_id
2011 2011
      */
2012
-    public static function reset_none_modules_transient ( $post_id ){
2012
+    public static function reset_none_modules_transient($post_id) {
2013 2013
 
2014 2014
         // this should only apply to course and lesson post types
2015
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2015
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2016 2016
 
2017 2017
             $course_id = '';
2018 2018
 
2019
-            if( 'lesson' == get_post_type( $post_id ) ){
2019
+            if ('lesson' == get_post_type($post_id)) {
2020 2020
 
2021
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2021
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2022 2022
 
2023 2023
             }
2024 2024
 
2025 2025
 
2026
-            if( !empty( $course_id ) ){
2026
+            if ( ! empty($course_id)) {
2027 2027
 
2028
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2028
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2029 2029
 
2030 2030
             }
2031 2031
 
@@ -2040,9 +2040,9 @@  discard block
 block discarded – undo
2040 2040
      * @deprecated since 1.9.0
2041 2041
      *
2042 2042
      */
2043
-    public static function deprecate_sensei_single_course_modules_content(){
2043
+    public static function deprecate_sensei_single_course_modules_content() {
2044 2044
 
2045
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2045
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2046 2046
 
2047 2047
     }
2048 2048
 
@@ -2053,12 +2053,12 @@  discard block
 block discarded – undo
2053 2053
      *
2054 2054
      * @since 1.9.0
2055 2055
      */
2056
-    public static function setup_single_course_module_loop(){
2056
+    public static function setup_single_course_module_loop() {
2057 2057
 
2058 2058
         global $sensei_modules_loop, $post;
2059 2059
         $course_id = $post->ID;
2060 2060
 
2061
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2061
+        $modules = Sensei()->modules->get_course_modules($course_id);
2062 2062
 
2063 2063
         //initial setup
2064 2064
         $sensei_modules_loop['total'] = 0;
@@ -2066,22 +2066,22 @@  discard block
 block discarded – undo
2066 2066
         $sensei_modules_loop['current'] = -1;
2067 2067
 
2068 2068
         // exit if this course doesn't have modules
2069
-        if( !$modules || empty( $modules )  ){
2069
+        if ( ! $modules || empty($modules)) {
2070 2070
             return;
2071 2071
         }
2072 2072
 
2073 2073
 
2074 2074
         $lessons_in_all_modules = array();
2075
-        foreach( $modules as $term ){
2075
+        foreach ($modules as $term) {
2076 2076
 
2077
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2078
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2077
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2078
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2079 2079
 
2080 2080
         }
2081 2081
 
2082 2082
 
2083 2083
         //setup all of the modules loop variables
2084
-        $sensei_modules_loop['total'] = count( $modules );
2084
+        $sensei_modules_loop['total'] = count($modules);
2085 2085
         $sensei_modules_loop['modules'] = $modules;
2086 2086
         $sensei_modules_loop['current'] = -1;
2087 2087
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2094,7 +2094,7 @@  discard block
 block discarded – undo
2094 2094
      * @since 1.9.0
2095 2095
      *
2096 2096
      */
2097
-    public static function teardown_single_course_module_loop(){
2097
+    public static function teardown_single_course_module_loop() {
2098 2098
 
2099 2099
         global $sensei_modules_loop, $wp_query, $post;
2100 2100
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-legacy-shortcodes.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @since 1.9.0
24 24
      */
25
-    public static function init(){
25
+    public static function init() {
26 26
 
27
-        add_shortcode( 'allcourses',      array( __CLASS__, 'all_courses' ) );
28
-        add_shortcode( 'newcourses',      array( __CLASS__,'new_courses' ) );
29
-        add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') );
30
-        add_shortcode( 'freecourses',     array( __CLASS__,'free_courses') );
31
-        add_shortcode( 'paidcourses',     array( __CLASS__,'paid_courses') );
32
-        add_shortcode( 'usercourses',     array( __CLASS__,'user_courses' ) );
27
+        add_shortcode('allcourses', array(__CLASS__, 'all_courses'));
28
+        add_shortcode('newcourses', array(__CLASS__, 'new_courses'));
29
+        add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses'));
30
+        add_shortcode('freecourses', array(__CLASS__, 'free_courses'));
31
+        add_shortcode('paidcourses', array(__CLASS__, 'paid_courses'));
32
+        add_shortcode('usercourses', array(__CLASS__, 'user_courses'));
33 33
 
34 34
     }
35 35
     /**
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
      * @param mixed $content (default: null)
43 43
      * @return string
44 44
      */
45
-    public static function all_courses( $atts, $content = null ) {
45
+    public static function all_courses($atts, $content = null) {
46 46
 
47
-        return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title
47
+        return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title
48 48
 
49 49
     } // all_courses()
50 50
 
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
      * @param mixed $content (default: null)
57 57
      * @return string
58 58
      */
59
-    public static function paid_courses( $atts, $content = null ) {
59
+    public static function paid_courses($atts, $content = null) {
60 60
 
61
-        return self::generate_shortcode_courses( __( 'Paid Courses', 'woothemes-sensei' ), 'paidcourses' );
61
+        return self::generate_shortcode_courses(__('Paid Courses', 'woothemes-sensei'), 'paidcourses');
62 62
 
63 63
     } // End paid_courses()
64 64
 
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
      * @param mixed $content (default: null)
72 72
      * @return string
73 73
      */
74
-    public static function featured_courses( $atts, $content = null ) {
74
+    public static function featured_courses($atts, $content = null) {
75 75
 
76
-        return self::generate_shortcode_courses( __( 'Featured Courses', 'woothemes-sensei' ), 'featuredcourses' );
76
+        return self::generate_shortcode_courses(__('Featured Courses', 'woothemes-sensei'), 'featuredcourses');
77 77
 
78 78
     } // End featured_courses()
79 79
 
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
      * @param mixed $content (default: null)
86 86
      * @return string
87 87
      */
88
-    public static function free_courses( $atts, $content = null ) {
88
+    public static function free_courses($atts, $content = null) {
89 89
 
90
-        return self::generate_shortcode_courses( __( 'Free Courses', 'woothemes-sensei' ), 'freecourses' );
90
+        return self::generate_shortcode_courses(__('Free Courses', 'woothemes-sensei'), 'freecourses');
91 91
 
92 92
     } // End free_courses()
93 93
 
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
      * @param mixed $content (default: null)
100 100
      * @return string
101 101
      */
102
-    public static function new_courses( $atts, $content = null ) {
102
+    public static function new_courses($atts, $content = null) {
103 103
 
104
-        return self::generate_shortcode_courses( __( 'New Courses', 'woothemes-sensei' ), 'newcourses' );
104
+        return self::generate_shortcode_courses(__('New Courses', 'woothemes-sensei'), 'newcourses');
105 105
 
106 106
     } // End new_courses()
107 107
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @param $shortcode_specific_override
115 115
      * @return string
116 116
      */
117
-    public static function generate_shortcode_courses( $title , $shortcode_specific_override  ){
117
+    public static function generate_shortcode_courses($title, $shortcode_specific_override) {
118 118
 
119 119
         global  $shortcode_override, $posts_array;
120 120
 
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 
123 123
         // do not show this short code if there is a shortcode int he url and
124 124
         // this specific shortcode is not the one requested in the ur.
125
-        $specific_shortcode_requested = isset( $_GET['action'] ) ?  sanitize_text_field(  $_GET['action']  ) : '';
126
-        if( ! empty( $specific_shortcode_requested) &&
127
-            $specific_shortcode_requested != $shortcode_override ){
125
+        $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : '';
126
+        if ( ! empty($specific_shortcode_requested) &&
127
+            $specific_shortcode_requested != $shortcode_override) {
128 128
 
129 129
             return '';
130 130
 
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
         $courses = ob_get_clean();
137 137
 
138 138
         $content = '';
139
-        if( count( $posts_array ) > 0 ){
139
+        if (count($posts_array) > 0) {
140 140
 
141
-            $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>';
141
+            $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>';
142 142
             $before .= '<section id="main-course" class="course-container">';
143 143
 
144 144
             $after = '</section>';
145 145
 
146 146
             //assemble
147
-            $content = $before . $courses . $after;
147
+            $content = $before.$courses.$after;
148 148
 
149 149
         }
150 150
 
@@ -161,19 +161,19 @@  discard block
 block discarded – undo
161 161
      * @param mixed $content (default: null)
162 162
      * @return string
163 163
      */
164
-    public static function user_courses( $atts, $content = null ) {
164
+    public static function user_courses($atts, $content = null) {
165 165
         global $shortcode_override;
166
-        extract( shortcode_atts( array(	'amount' => 0 ), $atts ) );
166
+        extract(shortcode_atts(array('amount' => 0), $atts));
167 167
 
168 168
         $shortcode_override = 'usercourses';
169 169
 
170 170
         ob_start();
171 171
 
172
-        if( is_user_logged_in() ){
172
+        if (is_user_logged_in()) {
173 173
 
174
-            Sensei_Templates::get_template( 'user/my-courses.php' );
174
+            Sensei_Templates::get_template('user/my-courses.php');
175 175
 
176
-        }else{
176
+        } else {
177 177
 
178 178
             Sensei()->frontend->sensei_login_form();
179 179
 
@@ -189,54 +189,54 @@  discard block
 block discarded – undo
189 189
      * loop-course.php for the old shortcodes.
190 190
      * @since 1.9.0
191 191
      */
192
-    public static function initialise_legacy_course_loop(){
192
+    public static function initialise_legacy_course_loop() {
193 193
 
194 194
         global  $post, $wp_query, $shortcode_override, $course_excludes;
195 195
 
196 196
         // Handle Query Type
197 197
         $query_type = '';
198 198
 
199
-        if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) {
200
-            $query_type = esc_html( $_GET[ 'action' ] );
199
+        if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) {
200
+            $query_type = esc_html($_GET['action']);
201 201
         } // End If Statement
202 202
 
203
-        if ( '' != $shortcode_override ) {
203
+        if ('' != $shortcode_override) {
204 204
             $query_type = $shortcode_override;
205 205
         } // End If Statement
206 206
 
207
-        if ( !is_array( $course_excludes ) ) { $course_excludes = array(); }
207
+        if ( ! is_array($course_excludes)) { $course_excludes = array(); }
208 208
 
209 209
         // Check that query returns results
210 210
         // Handle Pagination
211
-        $paged = $wp_query->get( 'paged' );
212
-        $paged = empty( $paged ) ? 1 : $paged;
211
+        $paged = $wp_query->get('paged');
212
+        $paged = empty($paged) ? 1 : $paged;
213 213
 
214 214
 
215 215
         // Check for pagination settings
216
-        if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) {
216
+        if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) {
217 217
 
218
-            $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] );
218
+            $amount = absint(Sensei()->settings->settings['course_archive_amount']);
219 219
 
220 220
         } else {
221 221
 
222
-            $amount = $wp_query->get( 'posts_per_page' );
222
+            $amount = $wp_query->get('posts_per_page');
223 223
 
224 224
         } // End If Statement
225 225
 
226 226
         // This is not a paginated page (or it's simply the first page of a paginated page/post)
227 227
 
228 228
         global $posts_array;
229
-        $course_includes   = array();
229
+        $course_includes = array();
230 230
 
231
-        $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes );
232
-        $course_query = new WP_Query( $query_args );
231
+        $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes);
232
+        $course_query = new WP_Query($query_args);
233 233
         $posts_array = $course_query->get_posts();
234 234
 
235 235
         // output the courses
236
-        if( ! empty( $posts_array ) ) {
236
+        if ( ! empty($posts_array)) {
237 237
 
238 238
             //output all courses for current query
239
-            self::loop_courses( $course_query, $amount );
239
+            self::loop_courses($course_query, $amount);
240 240
 
241 241
         }
242 242
 
@@ -249,31 +249,31 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param WP_Query $course_query
251 251
      */
252
-    public static function loop_courses( $course_query, $amount ){
252
+    public static function loop_courses($course_query, $amount) {
253 253
 
254 254
         global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes;
255 255
 
256
-        if ( count( $course_query->get_posts() ) > 0 ) {
256
+        if (count($course_query->get_posts()) > 0) {
257 257
 
258
-            do_action( 'sensei_course_archive_header', $shortcode_override );
258
+            do_action('sensei_course_archive_header', $shortcode_override);
259 259
 
260
-            foreach ( $course_query->get_posts() as $course){
260
+            foreach ($course_query->get_posts() as $course) {
261 261
 
262 262
                 // Make sure the other loops dont include the same post twice!
263
-                array_push( $course_excludes, $course->ID );
263
+                array_push($course_excludes, $course->ID);
264 264
 
265 265
                 // output the course markup
266
-                self::the_course( $course->ID );
266
+                self::the_course($course->ID);
267 267
 
268 268
             } // End For Loop
269 269
 
270 270
             // More and Prev links
271
-            $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) );
271
+            $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes));
272 272
             $posts_array       = $posts_array_query->get_posts();
273 273
             $max_pages = $course_query->found_posts / $amount;
274
-            if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) {
274
+            if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) {
275 275
 
276
-                switch( $shortcode_override ){
276
+                switch ($shortcode_override) {
277 277
                     case 'paidcourses':
278 278
                         $filter = 'paid';
279 279
                         break;
@@ -289,22 +289,22 @@  discard block
 block discarded – undo
289 289
                 }
290 290
 
291 291
                 $quer_args = array();
292
-                $quer_args[ 'paged' ] = '2';
293
-                if( !empty( $filter ) ){
294
-                    $quer_args[ 'course_filter' ] = $filter;
292
+                $quer_args['paged'] = '2';
293
+                if ( ! empty($filter)) {
294
+                    $quer_args['course_filter'] = $filter;
295 295
                 }
296 296
 
297
-                $course_pagination_link = get_post_type_archive_link( 'course' );
298
-                $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] );
299
-                $more_link_url =  esc_url( add_query_arg( $quer_args, $course_pagination_link ) );
297
+                $course_pagination_link = get_post_type_archive_link('course');
298
+                $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']);
299
+                $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link));
300 300
 
301 301
                 // next/more
302 302
                 $html  = '<div class="navigation"><div class="nav-next">';
303
-                $html .= '<a href="' . $more_link_url . '">';
303
+                $html .= '<a href="'.$more_link_url.'">';
304 304
                 $html .= $more_link_text;
305 305
                 $html .= '<span class="meta-nav"></span></a></div>';
306 306
 
307
-                echo apply_filters( 'course_archive_next_link', $html );
307
+                echo apply_filters('course_archive_next_link', $html);
308 308
 
309 309
             } // End If Statement
310 310
 
@@ -316,23 +316,23 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @param $course_id
318 318
      */
319
-    public static function the_course( $course_id ){
319
+    public static function the_course($course_id) {
320 320
 
321 321
         // Get meta data
322
-        $course =  get_post( $course_id );
323
-        $user_info = get_userdata( absint( $course->post_author ) );
324
-        $author_link = get_author_posts_url( absint( $course->post_author ) );
322
+        $course = get_post($course_id);
323
+        $user_info = get_userdata(absint($course->post_author));
324
+        $author_link = get_author_posts_url(absint($course->post_author));
325 325
         $author_display_name = $user_info->display_name;
326 326
         $author_id = $course->post_author;
327
-        $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' );
328
-        $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) );
329
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
327
+        $category_output = get_the_term_list($course_id, 'course-category', '', ', ', '');
328
+        $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id));
329
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
330 330
         ?>
331 331
 
332
-        <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>">
332
+        <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>">
333 333
             <?php
334 334
             // so that legacy shortcodes work with the party plugins that wants to hook in
335
-            do_action('sensei_course_content_before',$course->ID );
335
+            do_action('sensei_course_content_before', $course->ID);
336 336
             ?>
337 337
             <div class="course-content">
338 338
 
@@ -348,19 +348,19 @@  discard block
 block discarded – undo
348 348
 
349 349
                     <p class="sensei-course-meta">
350 350
 
351
-                        <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
352
-                            <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name   ); ?></a></span>
351
+                        <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
352
+                            <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
353 353
                         <?php } // End If Statement ?>
354 354
 
355 355
                         <span class="course-lesson-count">
356
-                                    <?php echo Sensei()->course->course_lesson_count( $course_id ) . '&nbsp;' .  __( 'Lessons', 'woothemes-sensei' ); ?>
356
+                                    <?php echo Sensei()->course->course_lesson_count($course_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?>
357 357
                                 </span>
358 358
 
359
-                        <?php if ( '' != $category_output ) { ?>
360
-                            <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span>
359
+                        <?php if ('' != $category_output) { ?>
360
+                            <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span>
361 361
                         <?php } // End If Statement ?>
362 362
 
363
-                        <?php sensei_simple_course_price( $course_id ); ?>
363
+                        <?php sensei_simple_course_price($course_id); ?>
364 364
 
365 365
                     </p>
366 366
 
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
 
369 369
                     </p>
370 370
 
371
-                    <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) {
372
-                        $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?>
371
+                    <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) {
372
+                        $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?>
373 373
                         <p class="sensei-free-lessons">
374
-                            <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?>
374
+                            <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?>
375 375
                             </a> - <?php echo $preview_lessons; ?>
376 376
                         </p>
377 377
                     <?php } ?>
Please login to merge, or discard this patch.
includes/class-sensei-lesson.php 1 patch
Spacing   +1105 added lines, -1105 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Lessons Class
@@ -19,83 +19,83 @@  discard block
 block discarded – undo
19 19
 	 * Constructor.
20 20
 	 * @since  1.0.0
21 21
 	 */
22
-	public function __construct () {
22
+	public function __construct() {
23 23
 
24 24
         $this->token = 'lesson';
25 25
 
26 26
 		// Setup meta fields for this post type
27
-		$this->meta_fields = array( 'lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed' );
27
+		$this->meta_fields = array('lesson_prerequisite', 'lesson_course', 'lesson_preview', 'lesson_length', 'lesson_complexity', 'lesson_video_embed');
28 28
 
29 29
         $this->question_order = '';
30 30
 
31 31
 		// Admin actions
32
-		if ( is_admin() ) {
32
+		if (is_admin()) {
33 33
 
34 34
 			// Metabox functions
35
-			add_action( 'admin_menu', array( $this, 'meta_box_setup' ), 20 );
36
-			add_action( 'save_post', array( $this, 'meta_box_save' ) );
37
-			add_action( 'save_post', array( $this, 'quiz_update' ) );
35
+			add_action('admin_menu', array($this, 'meta_box_setup'), 20);
36
+			add_action('save_post', array($this, 'meta_box_save'));
37
+			add_action('save_post', array($this, 'quiz_update'));
38 38
 
39 39
 			// Custom Write Panel Columns
40
-			add_filter( 'manage_edit-lesson_columns', array( $this, 'add_column_headings' ), 10, 1 );
41
-			add_action( 'manage_posts_custom_column', array( $this, 'add_column_data' ), 10, 2 );
40
+			add_filter('manage_edit-lesson_columns', array($this, 'add_column_headings'), 10, 1);
41
+			add_action('manage_posts_custom_column', array($this, 'add_column_data'), 10, 2);
42 42
 
43 43
 			// Add/Update question
44
-			add_action( 'wp_ajax_lesson_update_question', array( $this, 'lesson_update_question' ) );
45
-			add_action( 'wp_ajax_nopriv_lesson_update_question', array( $this, 'lesson_update_question' ) );
44
+			add_action('wp_ajax_lesson_update_question', array($this, 'lesson_update_question'));
45
+			add_action('wp_ajax_nopriv_lesson_update_question', array($this, 'lesson_update_question'));
46 46
 
47 47
 			// Add course
48
-			add_action( 'wp_ajax_lesson_add_course', array( $this, 'lesson_add_course' ) );
49
-			add_action( 'wp_ajax_nopriv_lesson_add_course', array( $this, 'lesson_add_course' ) );
48
+			add_action('wp_ajax_lesson_add_course', array($this, 'lesson_add_course'));
49
+			add_action('wp_ajax_nopriv_lesson_add_course', array($this, 'lesson_add_course'));
50 50
 
51 51
 			// Update grade type
52
-			add_action( 'wp_ajax_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
53
-			add_action( 'wp_ajax_nopriv_lesson_update_grade_type', array( $this, 'lesson_update_grade_type' ) );
52
+			add_action('wp_ajax_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
53
+			add_action('wp_ajax_nopriv_lesson_update_grade_type', array($this, 'lesson_update_grade_type'));
54 54
 
55 55
 			// Update question order
56
-			add_action( 'wp_ajax_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
57
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order', array( $this, 'lesson_update_question_order' ) );
56
+			add_action('wp_ajax_lesson_update_question_order', array($this, 'lesson_update_question_order'));
57
+			add_action('wp_ajax_nopriv_lesson_update_question_order', array($this, 'lesson_update_question_order'));
58 58
 
59 59
 			//Update question order
60
-			add_action( 'wp_ajax_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
61
-			add_action( 'wp_ajax_nopriv_lesson_update_question_order_random', array( $this, 'lesson_update_question_order_random' ) );
60
+			add_action('wp_ajax_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
61
+			add_action('wp_ajax_nopriv_lesson_update_question_order_random', array($this, 'lesson_update_question_order_random'));
62 62
 
63 63
 			// Get answer ID
64
-			add_action( 'wp_ajax_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
65
-			add_action( 'wp_ajax_nopriv_question_get_answer_id', array( $this, 'question_get_answer_id' ) );
64
+			add_action('wp_ajax_question_get_answer_id', array($this, 'question_get_answer_id'));
65
+			add_action('wp_ajax_nopriv_question_get_answer_id', array($this, 'question_get_answer_id'));
66 66
 
67 67
 			// Add multiple questions
68
-			add_action( 'wp_ajax_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
69
-			add_action( 'wp_ajax_nopriv_lesson_add_multiple_questions', array( $this, 'lesson_add_multiple_questions' ) );
68
+			add_action('wp_ajax_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
69
+			add_action('wp_ajax_nopriv_lesson_add_multiple_questions', array($this, 'lesson_add_multiple_questions'));
70 70
 
71 71
 			// Remove multiple questions
72
-			add_action( 'wp_ajax_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
73
-			add_action( 'wp_ajax_nopriv_lesson_remove_multiple_questions', array( $this, 'lesson_remove_multiple_questions' ) );
72
+			add_action('wp_ajax_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
73
+			add_action('wp_ajax_nopriv_lesson_remove_multiple_questions', array($this, 'lesson_remove_multiple_questions'));
74 74
 
75 75
 			// Get question category limit
76
-			add_action( 'wp_ajax_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
77
-			add_action( 'wp_ajax_nopriv_get_question_category_limit', array( $this, 'get_question_category_limit' ) );
76
+			add_action('wp_ajax_get_question_category_limit', array($this, 'get_question_category_limit'));
77
+			add_action('wp_ajax_nopriv_get_question_category_limit', array($this, 'get_question_category_limit'));
78 78
 
79 79
 			// Add existing questions
80
-			add_action( 'wp_ajax_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
81
-			add_action( 'wp_ajax_nopriv_lesson_add_existing_questions', array( $this, 'lesson_add_existing_questions' ) );
80
+			add_action('wp_ajax_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
81
+			add_action('wp_ajax_nopriv_lesson_add_existing_questions', array($this, 'lesson_add_existing_questions'));
82 82
 
83 83
 			// Filter existing questions
84
-			add_action( 'wp_ajax_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
85
-			add_action( 'wp_ajax_nopriv_filter_existing_questions', array( $this, 'quiz_panel_filter_existing_questions' ) );
84
+			add_action('wp_ajax_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
85
+			add_action('wp_ajax_nopriv_filter_existing_questions', array($this, 'quiz_panel_filter_existing_questions'));
86 86
 
87 87
             // output bulk edit fields
88
-            add_action( 'bulk_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
89
-            add_action( 'quick_edit_custom_box', array( $this, 'all_lessons_edit_fields' ), 10, 2 );
88
+            add_action('bulk_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
89
+            add_action('quick_edit_custom_box', array($this, 'all_lessons_edit_fields'), 10, 2);
90 90
 
91 91
             // load quick edit default values
92
-            add_action('manage_lesson_posts_custom_column', array( $this, 'set_quick_edit_admin_defaults'), 11, 2);
92
+            add_action('manage_lesson_posts_custom_column', array($this, 'set_quick_edit_admin_defaults'), 11, 2);
93 93
 
94 94
             // save bulk edit fields
95
-            add_action( 'wp_ajax_save_bulk_edit_book', array( $this, 'save_all_lessons_edit_fields' ) );
95
+            add_action('wp_ajax_save_bulk_edit_book', array($this, 'save_all_lessons_edit_fields'));
96 96
 
97 97
             // flush rewrite rules when saving a lesson
98
-            add_action('save_post', array( __CLASS__, 'flush_rewrite_rules' ) );
98
+            add_action('save_post', array(__CLASS__, 'flush_rewrite_rules'));
99 99
 
100 100
 		} else {
101 101
 			// Frontend actions
@@ -108,34 +108,34 @@  discard block
 block discarded – undo
108 108
 	 * @access public
109 109
 	 * @return void
110 110
 	 */
111
-	public function meta_box_setup () {
111
+	public function meta_box_setup() {
112 112
 
113 113
 		// Add Meta Box for Prerequisite Lesson
114
-		add_meta_box( 'lesson-prerequisite', __( 'Lesson Prerequisite', 'woothemes-sensei' ), array( $this, 'lesson_prerequisite_meta_box_content' ), $this->token, 'side', 'default' );
114
+		add_meta_box('lesson-prerequisite', __('Lesson Prerequisite', 'woothemes-sensei'), array($this, 'lesson_prerequisite_meta_box_content'), $this->token, 'side', 'default');
115 115
 
116 116
 		// Add Meta Box for Lesson Course
117
-		add_meta_box( 'lesson-course', __( 'Lesson Course', 'woothemes-sensei' ), array( $this, 'lesson_course_meta_box_content' ), $this->token, 'side', 'default' );
117
+		add_meta_box('lesson-course', __('Lesson Course', 'woothemes-sensei'), array($this, 'lesson_course_meta_box_content'), $this->token, 'side', 'default');
118 118
 
119 119
 		// Add Meta Box for Lesson Preview
120
-		add_meta_box( 'lesson-preview', __( 'Lesson Preview', 'woothemes-sensei' ), array( $this, 'lesson_preview_meta_box_content' ), $this->token, 'side', 'default' );
120
+		add_meta_box('lesson-preview', __('Lesson Preview', 'woothemes-sensei'), array($this, 'lesson_preview_meta_box_content'), $this->token, 'side', 'default');
121 121
 
122 122
 		// Add Meta Box for Lesson Information
123
-		add_meta_box( 'lesson-info', __( 'Lesson Information', 'woothemes-sensei' ), array( $this, 'lesson_info_meta_box_content' ), $this->token, 'normal', 'default' );
123
+		add_meta_box('lesson-info', __('Lesson Information', 'woothemes-sensei'), array($this, 'lesson_info_meta_box_content'), $this->token, 'normal', 'default');
124 124
 
125 125
 		// Add Meta Box for Quiz Settings
126
-		add_meta_box( 'lesson-quiz-settings', __( 'Quiz Settings', 'woothemes-sensei' ), array( $this, 'lesson_quiz_settings_meta_box_content' ), $this->token, 'normal', 'default' );
126
+		add_meta_box('lesson-quiz-settings', __('Quiz Settings', 'woothemes-sensei'), array($this, 'lesson_quiz_settings_meta_box_content'), $this->token, 'normal', 'default');
127 127
 
128 128
 		// Add Meta Box for Lesson Quiz Questions
129
-		add_meta_box( 'lesson-quiz', __( 'Quiz Questions', 'woothemes-sensei' ), array( $this, 'lesson_quiz_meta_box_content' ), $this->token, 'normal', 'default' );
129
+		add_meta_box('lesson-quiz', __('Quiz Questions', 'woothemes-sensei'), array($this, 'lesson_quiz_meta_box_content'), $this->token, 'normal', 'default');
130 130
 
131 131
 		// Remove "Custom Settings" meta box.
132
-		remove_meta_box( 'woothemes-settings', $this->token, 'normal' );
132
+		remove_meta_box('woothemes-settings', $this->token, 'normal');
133 133
 
134 134
 		// Add JS scripts
135
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
135
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
136 136
 
137 137
 		// Add CSS
138
-		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
138
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_styles'));
139 139
 
140 140
 	} // End meta_box_setup()
141 141
 
@@ -146,30 +146,30 @@  discard block
 block discarded – undo
146 146
 	 * @access public
147 147
 	 * @return void
148 148
 	 */
149
-	public function lesson_info_meta_box_content () {
149
+	public function lesson_info_meta_box_content() {
150 150
 		global $post;
151 151
 
152
-		$lesson_length = get_post_meta( $post->ID, '_lesson_length', true );
153
-		$lesson_complexity = get_post_meta( $post->ID, '_lesson_complexity', true );
152
+		$lesson_length = get_post_meta($post->ID, '_lesson_length', true);
153
+		$lesson_complexity = get_post_meta($post->ID, '_lesson_complexity', true);
154 154
 		$complexity_array = $this->lesson_complexities();
155
-		$lesson_video_embed = get_post_meta( $post->ID, '_lesson_video_embed', true );
155
+		$lesson_video_embed = get_post_meta($post->ID, '_lesson_video_embed', true);
156 156
 
157 157
 		$html = '';
158 158
 		// Lesson Length
159
-		$html .= '<p><label for="lesson_length">' . __( 'Lesson Length in minutes', 'woothemes-sensei' ) . ': </label>';
160
-		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="' . esc_attr( $lesson_length ) . '" /></p>' . "\n";
159
+		$html .= '<p><label for="lesson_length">'.__('Lesson Length in minutes', 'woothemes-sensei').': </label>';
160
+		$html .= '<input type="number" id="lesson-length" name="lesson_length" class="small-text" value="'.esc_attr($lesson_length).'" /></p>'."\n";
161 161
 		// Lesson Complexity
162
-		$html .= '<p><label for="lesson_complexity">' . __( 'Lesson Complexity', 'woothemes-sensei' ) . ': </label>';
162
+		$html .= '<p><label for="lesson_complexity">'.__('Lesson Complexity', 'woothemes-sensei').': </label>';
163 163
 		$html .= '<select id="lesson-complexity-options" name="lesson_complexity" class="chosen_select lesson-complexity-select">';
164
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
165
-			foreach ($complexity_array as $key => $value){
166
-				$html .= '<option value="' . esc_attr( $key ) . '"' . selected( $key, $lesson_complexity, false ) . '>' . esc_html( $value ) . '</option>' . "\n";
164
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
165
+			foreach ($complexity_array as $key => $value) {
166
+				$html .= '<option value="'.esc_attr($key).'"'.selected($key, $lesson_complexity, false).'>'.esc_html($value).'</option>'."\n";
167 167
 			} // End For Loop
168
-		$html .= '</select></p>' . "\n";
168
+		$html .= '</select></p>'."\n";
169 169
 
170
-		$html .= '<p><label for="lesson_video_embed">' . __( 'Video Embed Code', 'woothemes-sensei' ) . ':</label><br/>' . "\n";
171
-		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">' . $lesson_video_embed . '</textarea></p>' . "\n";
172
-		$html .= '<p>' .  __( 'Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei' ) . '</p>';
170
+		$html .= '<p><label for="lesson_video_embed">'.__('Video Embed Code', 'woothemes-sensei').':</label><br/>'."\n";
171
+		$html .= '<textarea rows="5" cols="50" name="lesson_video_embed" tabindex="6" id="course-video-embed">'.$lesson_video_embed.'</textarea></p>'."\n";
172
+		$html .= '<p>'.__('Paste the embed code for your video (e.g. YouTube, Vimeo etc.) in the box above.', 'woothemes-sensei').'</p>';
173 173
 
174 174
 		echo $html;
175 175
 
@@ -181,31 +181,31 @@  discard block
 block discarded – undo
181 181
 	 * @access public
182 182
 	 * @return void
183 183
 	 */
184
-	public function lesson_prerequisite_meta_box_content () {
184
+	public function lesson_prerequisite_meta_box_content() {
185 185
 		global $post;
186 186
 		// Get existing post meta
187
-		$select_lesson_prerequisite = get_post_meta( $post->ID, '_lesson_prerequisite', true );
187
+		$select_lesson_prerequisite = get_post_meta($post->ID, '_lesson_prerequisite', true);
188 188
 		// Get the Lesson Posts
189
-		$post_args = array(	'post_type' 		=> 'lesson',
189
+		$post_args = array('post_type' 		=> 'lesson',
190 190
 							'posts_per_page' 		=> -1,
191 191
 							'orderby'         	=> 'title',
192 192
     						'order'           	=> 'ASC',
193 193
     						'exclude' 			=> $post->ID,
194 194
 							'suppress_filters' 	=> 0
195 195
 							);
196
-		$posts_array = get_posts( $post_args );
196
+		$posts_array = get_posts($post_args);
197 197
 		// Build the HTML to Output
198 198
 		$html = '';
199
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
200
-		if ( count( $posts_array ) > 0 ) {
201
-			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">' . "\n";
202
-			$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
203
-				foreach ($posts_array as $post_item){
204
-					$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '"' . selected( $post_item->ID, $select_lesson_prerequisite, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
199
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
200
+		if (count($posts_array) > 0) {
201
+			$html .= '<select id="lesson-prerequisite-options" name="lesson_prerequisite" class="chosen_select widefat">'."\n";
202
+			$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
203
+				foreach ($posts_array as $post_item) {
204
+					$html .= '<option value="'.esc_attr(absint($post_item->ID)).'"'.selected($post_item->ID, $select_lesson_prerequisite, false).'>'.esc_html($post_item->post_title).'</option>'."\n";
205 205
 				} // End For Loop
206
-			$html .= '</select>' . "\n";
206
+			$html .= '</select>'."\n";
207 207
 		} else {
208
-			$html .= '<p>' . esc_html( __( 'No lessons exist yet. Please add some first.', 'woothemes-sensei' ) ) . '</p>';
208
+			$html .= '<p>'.esc_html(__('No lessons exist yet. Please add some first.', 'woothemes-sensei')).'</p>';
209 209
 		} // End If Statement
210 210
 		// Output the HTML
211 211
 		echo $html;
@@ -217,20 +217,20 @@  discard block
 block discarded – undo
217 217
 	 * @access public
218 218
 	 * @return void
219 219
 	 */
220
-	public function lesson_preview_meta_box_content () {
220
+	public function lesson_preview_meta_box_content() {
221 221
 		global $post;
222 222
 		// Get existing post meta
223
-		$lesson_preview = get_post_meta( $post->ID, '_lesson_preview', true );
223
+		$lesson_preview = get_post_meta($post->ID, '_lesson_preview', true);
224 224
 		$html = '';
225
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
225
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
226 226
 
227 227
 		$checked = '';
228
-		if ( isset( $lesson_preview ) && ( '' != $lesson_preview ) ) {
229
-	 	    $checked = checked( 'preview', $lesson_preview, false );
228
+		if (isset($lesson_preview) && ('' != $lesson_preview)) {
229
+	 	    $checked = checked('preview', $lesson_preview, false);
230 230
 	 	} // End If Statement
231 231
 
232 232
 	 	$html .= '<label for="lesson_preview">';
233
-	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" ' . $checked . '>&nbsp;' . __( 'Allow this lesson to be viewed without purchase/login', 'woothemes-sensei' ) . '<br>';
233
+	 	$html .= '<input type="checkbox" id="lesson_preview" name="lesson_preview" value="preview" '.$checked.'>&nbsp;'.__('Allow this lesson to be viewed without purchase/login', 'woothemes-sensei').'<br>';
234 234
 
235 235
 		// Output the HTML
236 236
 		echo $html;
@@ -243,40 +243,40 @@  discard block
 block discarded – undo
243 243
 	 * @param int $post_id
244 244
 	 * @return integer $post_id
245 245
 	 */
246
-	public function meta_box_save ( $post_id ) {
246
+	public function meta_box_save($post_id) {
247 247
 
248 248
 		// Verify the nonce before proceeding.
249
-		if ( ( get_post_type( $post_id ) != $this->token ) || !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta' ) ) {
249
+		if ((get_post_type($post_id) != $this->token) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
250 250
 			return $post_id;
251 251
 		} // End If Statement
252 252
 		// Get the post type object.
253
-		$post_type = get_post_type_object( get_post_type( $post_id ) );
253
+		$post_type = get_post_type_object(get_post_type($post_id));
254 254
 		// Check if the current user has permission to edit the post.
255
-		if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) {
255
+		if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
256 256
 			return $post_id;
257 257
 		} // End If Statement
258 258
 
259 259
 		// Check if the current post type is a page
260
-		if ( 'page' == $_POST[ 'post_type' ] ) {
260
+		if ('page' == $_POST['post_type']) {
261 261
 
262
-			if ( ! current_user_can( 'edit_page', $post_id ) ) {
262
+			if ( ! current_user_can('edit_page', $post_id)) {
263 263
 
264 264
 				return $post_id;
265 265
 
266 266
 			} // End If Statement
267 267
 		} else {
268
-			if ( ! current_user_can( 'edit_post', $post_id ) ) {
268
+			if ( ! current_user_can('edit_post', $post_id)) {
269 269
 				return $post_id;
270 270
 			} // End If Statement
271 271
 		} // End If Statement
272 272
 
273 273
 		// Save the post meta data fields
274
-		if ( isset($this->meta_fields) && is_array($this->meta_fields) ) {
274
+		if (isset($this->meta_fields) && is_array($this->meta_fields)) {
275 275
 
276
-			foreach ( $this->meta_fields as $meta_key ) {
276
+			foreach ($this->meta_fields as $meta_key) {
277 277
 
278
-				remove_action( 'save_post', array( $this, 'meta_box_save') );
279
-				$this->save_post_meta( $meta_key, $post_id );
278
+				remove_action('save_post', array($this, 'meta_box_save'));
279
+				$this->save_post_meta($meta_key, $post_id);
280 280
 
281 281
 			} // End For Loop
282 282
 		} // End If Statement
@@ -289,37 +289,37 @@  discard block
 block discarded – undo
289 289
 	 * @access public
290 290
 	 * @return integer|boolean $post_id or false
291 291
 	 */
292
-	public function quiz_update( $post_id ) {
292
+	public function quiz_update($post_id) {
293 293
 		global $post;
294 294
 		// Verify the nonce before proceeding.
295
-		if ( ( 'lesson' != get_post_type( $post_id ) )|| !isset(   $_POST[ 'woo_' . $this->token . '_nonce'] )  || ! wp_verify_nonce( $_POST[ 'woo_' . $this->token . '_nonce' ], 'sensei-save-post-meta') ) {
296
-			if ( isset($post->ID) ) {
295
+		if (('lesson' != get_post_type($post_id)) || ! isset($_POST['woo_'.$this->token.'_nonce']) || ! wp_verify_nonce($_POST['woo_'.$this->token.'_nonce'], 'sensei-save-post-meta')) {
296
+			if (isset($post->ID)) {
297 297
 				return $post->ID;
298 298
 			} else {
299 299
 				return false;
300 300
 			} // End If Statement
301 301
 		} // End If Statement
302 302
 
303
-		if( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) {
303
+		if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
304 304
 			return false;
305 305
 		}
306 306
 
307 307
 		// Temporarily disable the filter
308
-        remove_action( 'save_post', array( $this, 'quiz_update' ) );
308
+        remove_action('save_post', array($this, 'quiz_update'));
309 309
 		// Save the Quiz
310
-		$quiz_id = $this->lesson_quizzes( $post_id, 'any');
310
+		$quiz_id = $this->lesson_quizzes($post_id, 'any');
311 311
 
312 312
 		 // Sanitize and setup the post data
313
-		$_POST = stripslashes_deep( $_POST );
314
-		if ( isset( $_POST[ 'quiz_id' ] ) && ( 0 < absint( $_POST[ 'quiz_id' ] ) ) ) {
315
-			$quiz_id = absint( $_POST[ 'quiz_id' ] );
313
+		$_POST = stripslashes_deep($_POST);
314
+		if (isset($_POST['quiz_id']) && (0 < absint($_POST['quiz_id']))) {
315
+			$quiz_id = absint($_POST['quiz_id']);
316 316
 		} // End If Statement
317
-		$post_title = esc_html( $_POST[ 'post_title' ] );
318
-		$post_status = esc_html( $_POST[ 'post_status' ] );
317
+		$post_title = esc_html($_POST['post_title']);
318
+		$post_status = esc_html($_POST['post_status']);
319 319
 		$post_content = '';
320 320
 
321 321
 		// Setup Query Arguments
322
-		$post_type_args = array(	'post_content' => $post_content,
322
+		$post_type_args = array('post_content' => $post_content,
323 323
   		    						'post_status' => $post_status,
324 324
   		    						'post_title' => $post_title,
325 325
   		    						'post_type' => 'quiz',
@@ -329,84 +329,84 @@  discard block
 block discarded – undo
329 329
 		$settings = $this->get_quiz_settings();
330 330
 
331 331
   		// Update or Insert the Lesson Quiz
332
-		if ( 0 < $quiz_id ) {
332
+		if (0 < $quiz_id) {
333 333
 			// Update the Quiz
334
-			$post_type_args[ 'ID' ] = $quiz_id;
334
+			$post_type_args['ID'] = $quiz_id;
335 335
 		    wp_update_post($post_type_args);
336 336
 
337 337
 		    // Update the post meta data
338
-		    update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
338
+		    update_post_meta($quiz_id, '_quiz_lesson', $post_id);
339 339
 
340
-		    foreach( $settings as $field ) {
341
-		    	if( 'random_question_order' != $field['id'] ) {
342
-			    	$value = $this->get_submitted_setting_value( $field );
343
-			    	if( isset( $value ) ) {
344
-			    		update_post_meta( $quiz_id, '_' . $field['id'], $value );
340
+		    foreach ($settings as $field) {
341
+		    	if ('random_question_order' != $field['id']) {
342
+			    	$value = $this->get_submitted_setting_value($field);
343
+			    	if (isset($value)) {
344
+			    		update_post_meta($quiz_id, '_'.$field['id'], $value);
345 345
 			    	}
346 346
 			    }
347 347
 		    }
348 348
 
349 349
 		    // Set the post terms for quiz-type
350
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
350
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
351 351
 		} else {
352 352
 			// Create the Quiz
353 353
 		    $quiz_id = wp_insert_post($post_type_args);
354 354
 
355 355
 		    // Add the post meta data WP will add it if it doesn't exist
356
-            update_post_meta( $quiz_id, '_quiz_lesson', $post_id );
356
+            update_post_meta($quiz_id, '_quiz_lesson', $post_id);
357 357
 
358
-		    foreach( $settings as $field ) {
359
-		    	if( 'random_question_order' != $field['id'] ) {
358
+		    foreach ($settings as $field) {
359
+		    	if ('random_question_order' != $field['id']) {
360 360
 
361 361
                     //ignore values not posted to avoid
362 362
                     // overwriting with empty or default values
363 363
                     // when the values are posted from bulk edit or quick edit
364
-                    if( !isset( $_POST[ $field['id'] ] ) ){
364
+                    if ( ! isset($_POST[$field['id']])) {
365 365
                         continue;
366 366
                     }
367 367
 
368
-			    	$value = $this->get_submitted_setting_value( $field );
369
-			    	if( isset( $value ) ) {
370
-			    		add_post_meta( $quiz_id, '_' . $field['id'], $value );
368
+			    	$value = $this->get_submitted_setting_value($field);
369
+			    	if (isset($value)) {
370
+			    		add_post_meta($quiz_id, '_'.$field['id'], $value);
371 371
 			    	}
372 372
 			    }
373 373
 		    }
374 374
 
375 375
 		    // Set the post terms for quiz-type
376
-		    wp_set_post_terms( $quiz_id, array( 'multiple-choice' ), 'quiz-type' );
376
+		    wp_set_post_terms($quiz_id, array('multiple-choice'), 'quiz-type');
377 377
 		} // End If Statement
378 378
 
379 379
 		// Add default lesson order meta value
380
-		$course_id = get_post_meta( $post_id, '_lesson_course', true );
381
-		if( $course_id ) {
382
-			if( ! get_post_meta( $post_id, '_order_' . $course_id, true ) ) {
383
-				update_post_meta( $post_id, '_order_' . $course_id, 0 );
380
+		$course_id = get_post_meta($post_id, '_lesson_course', true);
381
+		if ($course_id) {
382
+			if ( ! get_post_meta($post_id, '_order_'.$course_id, true)) {
383
+				update_post_meta($post_id, '_order_'.$course_id, 0);
384 384
 			}
385 385
 		}
386 386
 		// Add reference back to the Quiz
387
-		update_post_meta( $post_id, '_lesson_quiz', $quiz_id );
387
+		update_post_meta($post_id, '_lesson_quiz', $quiz_id);
388 388
 		// Mark if the Lesson Quiz has questions
389
-		$quiz_questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
390
-		if( 0 < count( $quiz_questions ) ) {
391
-			update_post_meta( $post_id, '_quiz_has_questions', '1' );
389
+		$quiz_questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
390
+		if (0 < count($quiz_questions)) {
391
+			update_post_meta($post_id, '_quiz_has_questions', '1');
392 392
 		}
393 393
 		else {
394
-			delete_post_meta( $post_id, '_quiz_has_questions' );
394
+			delete_post_meta($post_id, '_quiz_has_questions');
395 395
 		}
396 396
 
397 397
 		// Restore the previously disabled filter
398
-        add_action( 'save_post', array( $this, 'quiz_update' ) );
398
+        add_action('save_post', array($this, 'quiz_update'));
399 399
 
400 400
 	} // End post_updated()
401 401
 
402
-	public function get_submitted_setting_value( $field = false ) {
402
+	public function get_submitted_setting_value($field = false) {
403 403
 
404
-		if( ! $field ) return;
404
+		if ( ! $field) return;
405 405
 
406 406
 		$value = false;
407 407
 
408
-		if( 'quiz_grade_type' == $field['id'] ) {
409
-			if( isset( $_POST[ $field['id'] ] ) && 'on' == $_POST[ $field['id'] ] ) {
408
+		if ('quiz_grade_type' == $field['id']) {
409
+			if (isset($_POST[$field['id']]) && 'on' == $_POST[$field['id']]) {
410 410
 				$value = 'auto';
411 411
 			} else {
412 412
 				$value = 'manual';
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
 			return $value;
415 415
 		}
416 416
 
417
-		if ( isset( $_POST[ $field['id'] ] ) ) {
418
-			$value = $_POST[ $field['id'] ];
417
+		if (isset($_POST[$field['id']])) {
418
+			$value = $_POST[$field['id']];
419 419
 		} else {
420 420
 			$value = $field['default'];
421 421
 		}
@@ -431,18 +431,18 @@  discard block
 block discarded – undo
431 431
 	 * @param int $post_id (default: 0)
432 432
 	 * @return int|bool meta id or saved status
433 433
 	 */
434
-	private function save_post_meta( $post_key = '', $post_id = 0 ) {
434
+	private function save_post_meta($post_key = '', $post_id = 0) {
435 435
 		// Get the meta key.
436
-		$meta_key = '_' . $post_key;
436
+		$meta_key = '_'.$post_key;
437 437
 
438 438
         //ignore fields are not posted
439 439
 
440
-        if( !isset( $_POST[ $post_key ] ) ){
440
+        if ( ! isset($_POST[$post_key])) {
441 441
 
442 442
             // except for lesson preview checkbox field
443
-            if( 'lesson_preview' == $post_key ){
443
+            if ('lesson_preview' == $post_key) {
444 444
 
445
-                $_POST[ $post_key ] = '';
445
+                $_POST[$post_key] = '';
446 446
 
447 447
             } else {
448 448
 
@@ -453,15 +453,15 @@  discard block
 block discarded – undo
453 453
         }
454 454
 
455 455
 		// Get the posted data and sanitize it for use as an HTML class.
456
-		if ( 'lesson_video_embed' == $post_key) {
457
-			$new_meta_value = esc_html( $_POST[$post_key] );
456
+		if ('lesson_video_embed' == $post_key) {
457
+			$new_meta_value = esc_html($_POST[$post_key]);
458 458
 		} else {
459
-			$new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' );
459
+			$new_meta_value = (isset($_POST[$post_key]) ? sanitize_html_class($_POST[$post_key]) : '');
460 460
 		} // End If Statement
461 461
 
462 462
         // update field with the new value
463
-        if( -1 != $new_meta_value  ){
464
-            return update_post_meta( $post_id, $meta_key, $new_meta_value );
463
+        if ( -1 != $new_meta_value  ) {
464
+            return update_post_meta($post_id, $meta_key, $new_meta_value);
465 465
         }
466 466
 
467 467
 	} // End save_post_meta()
@@ -472,30 +472,30 @@  discard block
 block discarded – undo
472 472
 	 * @access public
473 473
 	 * @return void
474 474
 	 */
475
-	public function lesson_course_meta_box_content () {
475
+	public function lesson_course_meta_box_content() {
476 476
 		global $post;
477 477
 		// Setup Lesson Meta Data
478 478
 		$selected_lesson_course = 0;
479
-		if ( 0 < $post->ID ) {
480
-			$selected_lesson_course = get_post_meta( $post->ID, '_lesson_course', true );
479
+		if (0 < $post->ID) {
480
+			$selected_lesson_course = get_post_meta($post->ID, '_lesson_course', true);
481 481
 		} // End If Statement
482 482
 		// Handle preselected course
483
-		if ( isset( $_GET[ 'course_id' ] ) && ( 0 < absint( $_GET[ 'course_id' ] ) ) ) {
484
-			$selected_lesson_course = absint( $_GET[ 'course_id' ] );
483
+		if (isset($_GET['course_id']) && (0 < absint($_GET['course_id']))) {
484
+			$selected_lesson_course = absint($_GET['course_id']);
485 485
 		} // End If Statement
486 486
 		// Get the Lesson Posts
487
-		$post_args = array(	'post_type' 		=> 'course',
487
+		$post_args = array('post_type' 		=> 'course',
488 488
 							'posts_per_page' 		=> -1,
489 489
 							'orderby'         	=> 'title',
490 490
     						'order'           	=> 'ASC',
491 491
     						'post_status'      	=> 'any',
492 492
     						'suppress_filters' 	=> 0,
493 493
 							);
494
-		$posts_array = get_posts( $post_args );
494
+		$posts_array = get_posts($post_args);
495 495
 		// Buid the HTML to Output
496 496
 		$html = '';
497 497
 		// Nonce
498
-		$html .= wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
498
+		$html .= wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
499 499
 
500 500
         // Select the course for the lesson
501 501
         $drop_down_args = array(
@@ -505,67 +505,67 @@  discard block
 block discarded – undo
505 505
 
506 506
         $courses = WooThemes_Sensei_Course::get_all_courses();
507 507
         $courses_options = array();
508
-        foreach( $courses as $course ){
509
-            $courses_options[ $course->ID ] = get_the_title( $course ) ;
508
+        foreach ($courses as $course) {
509
+            $courses_options[$course->ID] = get_the_title($course);
510 510
         }
511
-        $html .= Sensei_Utils::generate_drop_down( $selected_lesson_course, $courses_options, $drop_down_args );
511
+        $html .= Sensei_Utils::generate_drop_down($selected_lesson_course, $courses_options, $drop_down_args);
512 512
 
513 513
         // Course Actions Panel
514
-		if ( current_user_can( 'publish_courses' )) {
514
+		if (current_user_can('publish_courses')) {
515 515
 				$html .= '<div id="lesson-course-actions">';
516 516
 					$html .= '<p>';
517 517
 						// Add a course action link
518
-						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ ' . __('Add New Course', 'woothemes-sensei' ) . '</a>';
518
+						$html .= '<a id="lesson-course-add" href="#course-add" class="lesson-add-course">+ '.__('Add New Course', 'woothemes-sensei').'</a>';
519 519
 					$html .= '</p>';
520 520
 				$html .= '</div>';
521 521
 				// Add a course input fields
522 522
 				$html .= '<div id="lesson-course-details" class="hidden">';
523 523
 					$html .= '<p>';
524 524
 						// Course Title input
525
-						$html .= '<label>' . __( 'Course Title' , 'woothemes-sensei' ) . '</label> ';
525
+						$html .= '<label>'.__('Course Title', 'woothemes-sensei').'</label> ';
526 526
 	  					$html .= '<input type="text" id="course-title" name="course_title" value="" size="25" class="widefat" />';
527 527
 	  					// Course Description input
528
-	  					$html .= '<label>' . __( 'Description' , 'woothemes-sensei' ) . '</label> ';
528
+	  					$html .= '<label>'.__('Description', 'woothemes-sensei').'</label> ';
529 529
 	  					$html .= '<textarea rows="10" cols="40" id="course-content" name="course_content" value="" size="300" class="widefat"></textarea>';
530 530
 	  					// Course Prerequisite
531
-	  					$html .= '<label>' . __( 'Course Prerequisite' , 'woothemes-sensei' ) . '</label> ';
532
-	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">' . "\n";
533
-							$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
534
-							foreach ($posts_array as $post_item){
535
-								$html .= '<option value="' . esc_attr( absint( $post_item->ID ) ) . '">' . esc_html( $post_item->post_title ) . '</option>' . "\n";
531
+	  					$html .= '<label>'.__('Course Prerequisite', 'woothemes-sensei').'</label> ';
532
+	  					$html .= '<select id="course-prerequisite-options" name="course_prerequisite" class="chosen_select widefat">'."\n";
533
+							$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
534
+							foreach ($posts_array as $post_item) {
535
+								$html .= '<option value="'.esc_attr(absint($post_item->ID)).'">'.esc_html($post_item->post_title).'</option>'."\n";
536 536
 							} // End For Loop
537
-						$html .= '</select>' . "\n";
537
+						$html .= '</select>'."\n";
538 538
 						// Course Product
539
-                        if ( Sensei_WC::is_woocommerce_active() ) {
539
+                        if (Sensei_WC::is_woocommerce_active()) {
540 540
 	  						// Get the Products
541
-							$select_course_woocommerce_product = get_post_meta( $post_item->ID, '_course_woocommerce_product', true );
541
+							$select_course_woocommerce_product = get_post_meta($post_item->ID, '_course_woocommerce_product', true);
542 542
 
543
-							$product_args = array(	'post_type' 		=> array( 'product', 'product_variation' ),
543
+							$product_args = array('post_type' 		=> array('product', 'product_variation'),
544 544
 													'posts_per_page' 		=> -1,
545 545
 													'orderby'         	=> 'title',
546 546
 	    											'order'           	=> 'DESC',
547
-	    											'post_status'		=> array( 'publish', 'private', 'draft' ),
547
+	    											'post_status'		=> array('publish', 'private', 'draft'),
548 548
 	    											'tax_query'			=> array(
549 549
 														array(
550 550
 															'taxonomy'	=> 'product_type',
551 551
 															'field'		=> 'slug',
552
-															'terms'		=> array( 'variable', 'grouped' ),
552
+															'terms'		=> array('variable', 'grouped'),
553 553
 															'operator'	=> 'NOT IN'
554 554
 														)
555 555
 													),
556 556
 	    											'suppress_filters' 	=> 0
557 557
 													);
558
-							$products_array = get_posts( $product_args );
559
-							$html .= '<label>' . __( 'WooCommerce Product' , 'woothemes-sensei' ) . '</label> ';
560
-	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">' . "\n";
561
-								$html .= '<option value="-">' . __( 'None', 'woothemes-sensei' ) . '</option>';
558
+							$products_array = get_posts($product_args);
559
+							$html .= '<label>'.__('WooCommerce Product', 'woothemes-sensei').'</label> ';
560
+	  						$html .= '<select id="course-woocommerce-product-options" name="course_woocommerce_product" class="chosen_select widefat">'."\n";
561
+								$html .= '<option value="-">'.__('None', 'woothemes-sensei').'</option>';
562 562
 								$prev_parent_id = 0;
563
-								foreach ($products_array as $products_item){
563
+								foreach ($products_array as $products_item) {
564 564
 
565
-									if ( 'product_variation' == $products_item->post_type ) {
566
-										$product_object = get_product( $products_item->ID );
567
-										$parent_id = wp_get_post_parent_id( $products_item->ID );
568
-										$product_name = ucwords( woocommerce_get_formatted_variation( $product_object->variation_data, true ) );
565
+									if ('product_variation' == $products_item->post_type) {
566
+										$product_object = get_product($products_item->ID);
567
+										$parent_id = wp_get_post_parent_id($products_item->ID);
568
+										$product_name = ucwords(woocommerce_get_formatted_variation($product_object->variation_data, true));
569 569
 									} else {
570 570
 										$parent_id = false;
571 571
 										$prev_parent_id = 0;
@@ -573,32 +573,32 @@  discard block
 block discarded – undo
573 573
 									}
574 574
 
575 575
 									// Show variations in groups
576
-									if( $parent_id && $parent_id != $prev_parent_id ) {
577
-										if( 0 != $prev_parent_id ) {
576
+									if ($parent_id && $parent_id != $prev_parent_id) {
577
+										if (0 != $prev_parent_id) {
578 578
 											$html .= '</optgroup>';
579 579
 										}
580
-										$html .= '<optgroup label="' . get_the_title( $parent_id ) . '">';
580
+										$html .= '<optgroup label="'.get_the_title($parent_id).'">';
581 581
 										$prev_parent_id = $parent_id;
582
-									} elseif( ! $parent_id && 0 == $prev_parent_id ) {
582
+									} elseif ( ! $parent_id && 0 == $prev_parent_id) {
583 583
 										$html .= '</optgroup>';
584 584
 									}
585 585
 
586
-									$html .= '<option value="' . esc_attr( absint( $products_item->ID ) ) . '">' . esc_html( $products_item->post_title ) . '</option>' . "\n";
586
+									$html .= '<option value="'.esc_attr(absint($products_item->ID)).'">'.esc_html($products_item->post_title).'</option>'."\n";
587 587
 								} // End For Loop
588
-							$html .= '</select>' . "\n";
588
+							$html .= '</select>'."\n";
589 589
 						} else {
590 590
 							// Default
591 591
 							$html .= '<input type="hidden" name="course_woocommerce_product" id="course-woocommerce-product-options" value="-" />';
592 592
 						}
593 593
 						// Course Category
594
-	  					$html .= '<label>' . __( 'Course Category' , 'woothemes-sensei' ) . '</label> ';
595
-	  					$cat_args = array( 'echo' => false, 'hierarchical' => true, 'show_option_none' => __( 'None', 'woothemes-sensei' ), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat' );
596
-						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args)) . "\n";
594
+	  					$html .= '<label>'.__('Course Category', 'woothemes-sensei').'</label> ';
595
+	  					$cat_args = array('echo' => false, 'hierarchical' => true, 'show_option_none' => __('None', 'woothemes-sensei'), 'taxonomy' => 'course-category', 'orderby' => 'name', 'id' => 'course-category-options', 'name' => 'course_category', 'class' => 'widefat');
596
+						$html .= wp_dropdown_categories(apply_filters('widget_course_categories_dropdown_args', $cat_args))."\n";
597 597
 	  					// Save the course action button
598
-	  					$html .= '<a title="' . esc_attr( __( 'Save Course', 'woothemes-sensei' ) ) . '" href="#add-course-metadata" class="lesson_course_save button button-highlighted">' . esc_html( __( 'Add Course', 'woothemes-sensei' ) ) . '</a>';
598
+	  					$html .= '<a title="'.esc_attr(__('Save Course', 'woothemes-sensei')).'" href="#add-course-metadata" class="lesson_course_save button button-highlighted">'.esc_html(__('Add Course', 'woothemes-sensei')).'</a>';
599 599
 						$html .= '&nbsp;&nbsp;&nbsp;';
600 600
 						// Cancel action link
601
-						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">' . __( 'Cancel', 'woothemes-sensei' ) . '</a>';
601
+						$html .= '<a href="#course-add-cancel" class="lesson_course_cancel">'.__('Cancel', 'woothemes-sensei').'</a>';
602 602
 					$html .= '</p>';
603 603
 				$html .= '</div>';
604 604
 			} // End If Statement
@@ -607,20 +607,20 @@  discard block
 block discarded – undo
607 607
 		echo $html;
608 608
 	} // End lesson_course_meta_box_content()
609 609
 
610
-	public function quiz_panel( $quiz_id = 0 ) {
610
+	public function quiz_panel($quiz_id = 0) {
611 611
 
612
-		$html = wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce', true, false  );
612
+		$html = wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce', true, false);
613 613
 		$html .= '<div id="add-quiz-main">';
614
-			if ( 0 == $quiz_id ) {
614
+			if (0 == $quiz_id) {
615 615
 				$html .= '<p>';
616 616
 					// Default message and Add a Quiz button
617
-					$html .= esc_html( __( 'Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei' ) );
617
+					$html .= esc_html(__('Once you have saved your lesson you will be able to add questions.', 'woothemes-sensei'));
618 618
 				$html .= '</p>';
619 619
 			}
620 620
 
621 621
 			// Quiz Panel CSS Class
622 622
 			$quiz_class = '';
623
-			if ( 0 == $quiz_id ) {
623
+			if (0 == $quiz_id) {
624 624
 				$quiz_class = ' class="hidden"';
625 625
 			} // End If Statement
626 626
 			// Build the HTML to Output
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 
629 629
 			// Setup Questions Query
630 630
 			$questions = array();
631
-			if ( 0 < $quiz_id ) {
632
-				$questions = $this->lesson_quiz_questions( $quiz_id );
631
+			if (0 < $quiz_id) {
632
+				$questions = $this->lesson_quiz_questions($quiz_id);
633 633
 			} // End If Statement
634 634
 
635 635
 			$question_count = 0;
636
-			foreach( $questions as $question ) {
636
+			foreach ($questions as $question) {
637 637
 
638
-				if( $question->post_type == 'multiple_question' ) {
639
-					$question_number = get_post_meta( $question->ID, 'number', true );
638
+				if ($question->post_type == 'multiple_question') {
639
+					$question_number = get_post_meta($question->ID, 'number', true);
640 640
 					$question_count += $question_number;
641 641
 				} else {
642 642
 					++$question_count;
@@ -645,68 +645,68 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 
647 647
 			// Inner DIV
648
-			$html .= '<div id="add-quiz-metadata"' . $quiz_class . '>';
648
+			$html .= '<div id="add-quiz-metadata"'.$quiz_class.'>';
649 649
 
650 650
 				// Quiz ID
651
-				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="' . esc_attr( $quiz_id ) . '" />';
651
+				$html .= '<input type="hidden" name="quiz_id" id="quiz_id" value="'.esc_attr($quiz_id).'" />';
652 652
 
653 653
 				// Default Message
654
-				if ( 0 == $quiz_id ) {
654
+				if (0 == $quiz_id) {
655 655
 					$html .= '<p class="save-note">';
656
-						$html .= esc_html( __( 'Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei' ) );
656
+						$html .= esc_html(__('Please save your lesson in order to add questions to your quiz.', 'woothemes-sensei'));
657 657
 					$html .= '</p>';
658 658
 				} // End If Statement
659 659
 
660 660
 			$html .= '</div>';
661 661
 
662 662
 			// Question Container DIV
663
-			$html .= '<div id="add-question-main"' . $quiz_class . '>';
663
+			$html .= '<div id="add-question-main"'.$quiz_class.'>';
664 664
 				// Inner DIV
665 665
 				$html .= '<div id="add-question-metadata">';
666 666
 
667 667
 					// Count of questions
668
-					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="' . esc_attr( $question_count ) . '" />';
668
+					$html .= '<input type="hidden" name="question_counter" id="question_counter" value="'.esc_attr($question_count).'" />';
669 669
 					// Table headers
670 670
 					$html .= '<table class="widefat" id="sortable-questions">
671 671
 								<thead>
672 672
 								    <tr>
673 673
 								        <th class="question-count-column">#</th>
674
-								        <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
675
-								        <th style="width:45px;">' . __( 'Grade', 'woothemes-sensei' ) . '</th>
676
-								        <th style="width:125px;">' . __( 'Type', 'woothemes-sensei' ) . '</th>
677
-								        <th style="width:125px;">' . __( 'Action', 'woothemes-sensei' ) . '</th>
674
+								        <th>' . __('Question', 'woothemes-sensei').'</th>
675
+								        <th style="width:45px;">' . __('Grade', 'woothemes-sensei').'</th>
676
+								        <th style="width:125px;">' . __('Type', 'woothemes-sensei').'</th>
677
+								        <th style="width:125px;">' . __('Action', 'woothemes-sensei').'</th>
678 678
 								    </tr>
679 679
 								</thead>
680 680
 								<tfoot>
681 681
 								    <tr>
682 682
 									    <th class="question-count-column">#</th>
683
-									    <th>' . __( 'Question', 'woothemes-sensei' ) . '</th>
684
-									    <th>' . __( 'Grade', 'woothemes-sensei' ) . '</th>
685
-									    <th>' . __( 'Type', 'woothemes-sensei' ) . '</th>
686
-									    <th>' . __( 'Action', 'woothemes-sensei' ) . '</th>
683
+									    <th>' . __('Question', 'woothemes-sensei').'</th>
684
+									    <th>' . __('Grade', 'woothemes-sensei').'</th>
685
+									    <th>' . __('Type', 'woothemes-sensei').'</th>
686
+									    <th>' . __('Action', 'woothemes-sensei').'</th>
687 687
 								    </tr>
688 688
 								</tfoot>';
689 689
 
690 690
 					$message_class = '';
691
-					if ( 0 < $question_count ) { $message_class = 'hidden'; }
691
+					if (0 < $question_count) { $message_class = 'hidden'; }
692 692
 
693
-					$html .= '<tbody id="no-questions-message" class="' . esc_attr( $message_class ) . '">';
693
+					$html .= '<tbody id="no-questions-message" class="'.esc_attr($message_class).'">';
694 694
 						$html .= '<tr>';
695
-							$html .= '<td colspan="5">' . __( 'There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei' ) . '</td>';
695
+							$html .= '<td colspan="5">'.__('There are no Questions for this Quiz yet. Please add some below.', 'woothemes-sensei').'</td>';
696 696
 						$html .= '</tr>';
697 697
 					$html .= '</tbody>';
698 698
 
699
-					if( 0 < $question_count ) {
700
-						$html .= $this->quiz_panel_questions( $questions );
699
+					if (0 < $question_count) {
700
+						$html .= $this->quiz_panel_questions($questions);
701 701
 					}
702 702
 
703 703
 					$html .= '</table>';
704 704
 
705
-					if( ! isset( $this->question_order ) ) {
705
+					if ( ! isset($this->question_order)) {
706 706
 						$this->question_order = '';
707 707
 					}
708 708
 
709
-					$html .= '<input type="hidden" id="question-order" name="question-order" value="' . $this->question_order . '" />';
709
+					$html .= '<input type="hidden" id="question-order" name="question-order" value="'.$this->question_order.'" />';
710 710
 
711 711
 				$html .= '</div>';
712 712
 
@@ -725,47 +725,47 @@  discard block
 block discarded – undo
725 725
 
726 726
 	}
727 727
 
728
-	public function quiz_panel_questions( $questions = array() ) {
728
+	public function quiz_panel_questions($questions = array()) {
729 729
 		global $quiz_questions;
730 730
 
731 731
 		$quiz_questions = $questions;
732 732
 
733 733
 		$html = '';
734 734
 
735
-		if( count( $questions ) > 0 ) {
735
+		if (count($questions) > 0) {
736 736
 
737 737
 			$question_class = '';
738 738
 			$question_counter = 1;
739 739
 
740
-			foreach ( $questions as $question ) {
740
+			foreach ($questions as $question) {
741 741
 
742 742
 				$question_id = $question->ID;
743 743
 
744
-				$question_type = Sensei()->question->get_question_type( $question_id );
744
+				$question_type = Sensei()->question->get_question_type($question_id);
745 745
 
746 746
 				$multiple_data = array();
747 747
 				$question_increment = 1;
748
-				if( 'multiple_question' == $question->post_type ) {
748
+				if ('multiple_question' == $question->post_type) {
749 749
 					$question_type = 'category';
750 750
 
751
-					$question_category = get_post_meta( $question->ID, 'category', true );
752
-					$question_cat = get_term( $question_category, 'question-category' );
751
+					$question_category = get_post_meta($question->ID, 'category', true);
752
+					$question_cat = get_term($question_category, 'question-category');
753 753
 
754
-					$question_number = get_post_meta( $question->ID, 'number', true );
754
+					$question_number = get_post_meta($question->ID, 'number', true);
755 755
 					$question_increment = $question_number;
756 756
 
757
-					$multiple_data = array( $question_cat->name, $question_number );
757
+					$multiple_data = array($question_cat->name, $question_number);
758 758
 				}
759 759
 
760
-				if( ! $question_type ) {
760
+				if ( ! $question_type) {
761 761
 					$question_type = 'multiple-choice';
762 762
 				}
763 763
 
764 764
 				// Row with question and actions
765
-				$html .= $this->quiz_panel_question( $question_type, $question_counter, $question_id, 'quiz', $multiple_data );
765
+				$html .= $this->quiz_panel_question($question_type, $question_counter, $question_id, 'quiz', $multiple_data);
766 766
 				$question_counter += $question_increment;
767 767
 
768
-				if( isset( $this->question_order ) && strlen( $this->question_order ) > 0 ) { $this->question_order .= ','; }
768
+				if (isset($this->question_order) && strlen($this->question_order) > 0) { $this->question_order .= ','; }
769 769
 				$this->question_order .= $question_id;
770 770
 			} // End For Loop
771 771
 		}
@@ -774,161 +774,161 @@  discard block
 block discarded – undo
774 774
 
775 775
 	}
776 776
 
777
-	public function quiz_panel_question( $question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array() ) {
778
-		global $row_counter,  $quiz_questions;
777
+	public function quiz_panel_question($question_type = '', $question_counter = 0, $question_id = 0, $context = 'quiz', $multiple_data = array()) {
778
+		global $row_counter, $quiz_questions;
779 779
 
780 780
 		$html = '';
781 781
 
782 782
 		$question_class = '';
783
-		if( 'quiz' == $context ) {
784
-			if( ! $row_counter || ! isset( $row_counter ) ) {
783
+		if ('quiz' == $context) {
784
+			if ( ! $row_counter || ! isset($row_counter)) {
785 785
 				$row_counter = 1;
786 786
 			}
787
-			if( $row_counter % 2 ) { $question_class = 'alternate'; }
787
+			if ($row_counter % 2) { $question_class = 'alternate'; }
788 788
 			++$row_counter;
789 789
 		}
790 790
 
791
-		if( $question_id ) {
791
+		if ($question_id) {
792 792
 
793
-			if( $question_type != 'category' ) {
793
+			if ($question_type != 'category') {
794 794
 
795
-				$question_grade = Sensei()->question->get_question_grade( $question_id );
795
+				$question_grade = Sensei()->question->get_question_grade($question_id);
796 796
 
797
-				$question_media = get_post_meta( $question_id, '_question_media', true );
797
+				$question_media = get_post_meta($question_id, '_question_media', true);
798 798
 				$question_media_type = $question_media_thumb = $question_media_link = $question_media_title = '';
799 799
 				$question_media_thumb_class = $question_media_link_class = $question_media_delete_class = 'hidden';
800
-				$question_media_add_button = __( 'Add file', 'woothemes-sensei' );
801
-				if( 0 < intval( $question_media ) ) {
802
-					$mimetype = get_post_mime_type( $question_media );
803
-					if( $mimetype ) {
804
-						$mimetype_array = explode( '/', $mimetype);
805
-						if( isset( $mimetype_array[0] ) && $mimetype_array[0] ) {
800
+				$question_media_add_button = __('Add file', 'woothemes-sensei');
801
+				if (0 < intval($question_media)) {
802
+					$mimetype = get_post_mime_type($question_media);
803
+					if ($mimetype) {
804
+						$mimetype_array = explode('/', $mimetype);
805
+						if (isset($mimetype_array[0]) && $mimetype_array[0]) {
806 806
 							$question_media_delete_class = '';
807 807
 							$question_media_type = $mimetype_array[0];
808
-							if( 'image' == $question_media_type ) {
809
-								$question_media_thumb = wp_get_attachment_thumb_url( $question_media );
810
-								if( $question_media_thumb ) {
808
+							if ('image' == $question_media_type) {
809
+								$question_media_thumb = wp_get_attachment_thumb_url($question_media);
810
+								if ($question_media_thumb) {
811 811
 									$question_media_thumb_class = '';
812 812
 								}
813 813
 							}
814
-							$question_media_url = wp_get_attachment_url( $question_media );
815
-							if( $question_media_url ) {
816
-								$attachment = get_post( $question_media );
814
+							$question_media_url = wp_get_attachment_url($question_media);
815
+							if ($question_media_url) {
816
+								$attachment = get_post($question_media);
817 817
 								$question_media_title = $attachment->post_title;
818 818
 
819
-								if( ! $question_media_title ) {
820
-									$question_media_filename = basename( $question_media_url );
819
+								if ( ! $question_media_title) {
820
+									$question_media_filename = basename($question_media_url);
821 821
 									$question_media_title = $question_media_filename;
822 822
 								}
823
-								$question_media_link = '<a class="' . $question_media_type . '" href="' . esc_url( $question_media_url ) . '" target="_blank">' . $question_media_title . '</a>';
823
+								$question_media_link = '<a class="'.$question_media_type.'" href="'.esc_url($question_media_url).'" target="_blank">'.$question_media_title.'</a>';
824 824
 								$question_media_link_class = '';
825 825
 							}
826 826
 
827
-							$question_media_add_button = __( 'Change file', 'woothemes-sensei' );
827
+							$question_media_add_button = __('Change file', 'woothemes-sensei');
828 828
 						}
829 829
 					}
830 830
 				}
831 831
 
832
-				$random_order = get_post_meta( $question_id, '_random_order', true );
833
-				if( ! $random_order ) {
832
+				$random_order = get_post_meta($question_id, '_random_order', true);
833
+				if ( ! $random_order) {
834 834
 					$random_order = 'yes';
835 835
 				}
836 836
 
837
-				if( ! $question_type ) { $question_type = 'multiple-choice'; }
837
+				if ( ! $question_type) { $question_type = 'multiple-choice'; }
838 838
 			}
839 839
 
840
-			$html .= '<tbody class="' . $question_class . '">';
840
+			$html .= '<tbody class="'.$question_class.'">';
841 841
 
842
-				if( 'quiz' == $context ) {
842
+				if ('quiz' == $context) {
843 843
 					$html .= '<tr>';
844
-						if( $question_type != 'category' ) {
845
-							$question = get_post( $question_id );
846
-							$html .= '<td class="table-count question-number question-count-column"><span class="number">' . $question_counter . '</span></td>';
847
-							$html .= '<td>' . esc_html( $question->post_title ) . '</td>';
848
-							$html .= '<td class="question-grade-column">' . esc_html( $question_grade ) . '</td>';
849
-							$question_types_filtered = ucwords( str_replace( array( '-', 'boolean' ), array( ' ', __( 'True/False', 'woothemes-sensei' ) ), $question_type ) );
850
-							$html .= '<td>' . esc_html( $question_types_filtered ) . '</td>';
851
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_delete">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
844
+						if ($question_type != 'category') {
845
+							$question = get_post($question_id);
846
+							$html .= '<td class="table-count question-number question-count-column"><span class="number">'.$question_counter.'</span></td>';
847
+							$html .= '<td>'.esc_html($question->post_title).'</td>';
848
+							$html .= '<td class="question-grade-column">'.esc_html($question_grade).'</td>';
849
+							$question_types_filtered = ucwords(str_replace(array('-', 'boolean'), array(' ', __('True/False', 'woothemes-sensei')), $question_type));
850
+							$html .= '<td>'.esc_html($question_types_filtered).'</td>';
851
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_delete">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
852 852
 
853 853
 						} else {
854 854
 
855
-							$end_number = intval( $question_counter ) + intval( $multiple_data[1] ) - 1;
856
-							if( $question_counter == $end_number ) {
855
+							$end_number = intval($question_counter) + intval($multiple_data[1]) - 1;
856
+							if ($question_counter == $end_number) {
857 857
 								$row_numbers = $question_counter;
858 858
 							} else {
859
-								$row_numbers = $question_counter . ' - ' . $end_number;
859
+								$row_numbers = $question_counter.' - '.$end_number;
860 860
 							}
861
-							$row_title = sprintf( __( 'Selected from \'%1$s\' ', 'woothemes-sensei' ), $multiple_data[0] );
861
+							$row_title = sprintf(__('Selected from \'%1$s\' ', 'woothemes-sensei'), $multiple_data[0]);
862 862
 
863
-							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">' . $question_counter . '</span><span class="hidden total-number">' . $multiple_data[1] . '</span><span class="row-numbers">' . esc_html( $row_numbers ) . '</span></td>';
864
-							$html .= '<td>' . esc_html( $row_title ) . '</td>';
863
+							$html .= '<td class="table-count question-number question-count-column"><span class="number hidden">'.$question_counter.'</span><span class="hidden total-number">'.$multiple_data[1].'</span><span class="row-numbers">'.esc_html($row_numbers).'</span></td>';
864
+							$html .= '<td>'.esc_html($row_title).'</td>';
865 865
 							$html .= '<td class="question-grade-column"></td>';
866
-							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" /></td>';
867
-							$html .= '<td><a title="' . esc_attr( __( 'Edit Question', 'woothemes-sensei' ) ) . '" href="#question_' . $question_counter .'" class="question_table_edit" style="visibility:hidden;">' . esc_html( __( 'Edit', 'woothemes-sensei' ) ) . '</a> <a title="' . esc_attr( __( 'Remove Question(s)', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_multiple_delete" rel="' . $question_id . '">' . esc_html( __( 'Remove', 'woothemes-sensei' ) ) . '</a></td>';
866
+							$html .= '<td><input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" /></td>';
867
+							$html .= '<td><a title="'.esc_attr(__('Edit Question', 'woothemes-sensei')).'" href="#question_'.$question_counter.'" class="question_table_edit" style="visibility:hidden;">'.esc_html(__('Edit', 'woothemes-sensei')).'</a> <a title="'.esc_attr(__('Remove Question(s)', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_multiple_delete" rel="'.$question_id.'">'.esc_html(__('Remove', 'woothemes-sensei')).'</a></td>';
868 868
 
869 869
 						}
870 870
 					$html .= '</tr>';
871 871
 				}
872 872
 
873
-				if( $question_type != 'category' ) {
873
+				if ($question_type != 'category') {
874 874
 
875 875
 					$edit_class = '';
876
-					if( 'quiz' == $context ) {
876
+					if ('quiz' == $context) {
877 877
 						$edit_class = 'hidden';
878 878
 					}
879 879
 
880
-					$question = get_post( $question_id );
881
-					$html .= '<tr class="question-quick-edit ' . esc_attr( $edit_class ) . '">';
880
+					$question = get_post($question_id);
881
+					$html .= '<tr class="question-quick-edit '.esc_attr($edit_class).'">';
882 882
 						$html .= '<td colspan="5">';
883
-							$html .= '<span class="hidden question_original_counter">' . $question_counter . '</span>';
883
+							$html .= '<span class="hidden question_original_counter">'.$question_counter.'</span>';
884 884
 					    	$html .= '<div class="question_required_fields">';
885 885
 
886 886
 						    	// Question title
887 887
 						    	$html .= '<div>';
888
-							    	$html .= '<label for="question_' . $question_counter . '">' . __( 'Question:', 'woothemes-sensei' ) . '</label> ';
889
-							    	$html .= '<input type="text" id="question_' . $question_counter . '" name="question" value="' . esc_attr( htmlspecialchars( $question->post_title ) ) . '" size="25" class="widefat" />';
888
+							    	$html .= '<label for="question_'.$question_counter.'">'.__('Question:', 'woothemes-sensei').'</label> ';
889
+							    	$html .= '<input type="text" id="question_'.$question_counter.'" name="question" value="'.esc_attr(htmlspecialchars($question->post_title)).'" size="25" class="widefat" />';
890 890
 						    	$html .= '</div>';
891 891
 
892 892
 						    	// Question description
893 893
 						    	$html .= '<div>';
894
-							    	$html .= '<label for="question_' . $question_counter . '_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
894
+							    	$html .= '<label for="question_'.$question_counter.'_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
895 895
 						    	$html .= '</div>';
896
-							    	$html .= '<textarea id="question_' . $question_counter . '_desc" name="question_description" class="widefat" rows="4">' . esc_textarea( $question->post_content ) . '</textarea>';
896
+							    	$html .= '<textarea id="question_'.$question_counter.'_desc" name="question_description" class="widefat" rows="4">'.esc_textarea($question->post_content).'</textarea>';
897 897
 
898 898
 						    	// Question grade
899 899
 						    	$html .= '<div>';
900
-							    	$html .= '<label for="question_' . $question_counter . '_grade">' . __( 'Question grade:', 'woothemes-sensei' ) . '</label> ';
901
-							    	$html .= '<input type="number" id="question_' . $question_counter . '_grade" class="question_grade small-text" name="question_grade" min="0" value="' . $question_grade . '" />';
900
+							    	$html .= '<label for="question_'.$question_counter.'_grade">'.__('Question grade:', 'woothemes-sensei').'</label> ';
901
+							    	$html .= '<input type="number" id="question_'.$question_counter.'_grade" class="question_grade small-text" name="question_grade" min="0" value="'.$question_grade.'" />';
902 902
 						    	$html .= '</div>';
903 903
 
904 904
 						    	// Random order
905
-						    	if( $question_type == 'multiple-choice' ) {
905
+						    	if ($question_type == 'multiple-choice') {
906 906
 						    		$html .= '<div>';
907
-						    			$html .= '<label for="' . $question_counter . '_random_order"><input type="checkbox" name="random_order" class="random_order" id="' . $question_counter . '_random_order" value="yes" ' . checked( $random_order, 'yes', false ) . ' /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
907
+						    			$html .= '<label for="'.$question_counter.'_random_order"><input type="checkbox" name="random_order" class="random_order" id="'.$question_counter.'_random_order" value="yes" '.checked($random_order, 'yes', false).' /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
908 908
 						    		$html .= '</div>';
909 909
 						    	}
910 910
 
911 911
 						    	// Question media
912 912
 						    	$html .= '<div>';
913
-							    	$html .= '<label for="question_' . $question_counter . '_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
914
-							    	$html .= '<button id="question_' . $question_counter . '_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . $question_media_add_button . '</button>';
915
-							    	$html .= '<button id="question_' . $question_counter . '_media_button_delete" class="delete_media_file_button button-secondary ' . $question_media_delete_class . '">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
916
-							    	$html .= '<span id="question_' . $question_counter . '_media_link" class="question_media_link ' . $question_media_link_class . '">' . $question_media_link . '</span>';
917
-							    	$html .= '<br/><img id="question_' . $question_counter . '_media_preview" class="question_media_preview ' . $question_media_thumb_class . '" src="' . $question_media_thumb . '" /><br/>';
918
-							    	$html .= '<input type="hidden" id="question_' . $question_counter . '_media" class="question_media" name="question_media" value="' . $question_media . '" />';
913
+							    	$html .= '<label for="question_'.$question_counter.'_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
914
+							    	$html .= '<button id="question_'.$question_counter.'_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.$question_media_add_button.'</button>';
915
+							    	$html .= '<button id="question_'.$question_counter.'_media_button_delete" class="delete_media_file_button button-secondary '.$question_media_delete_class.'">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
916
+							    	$html .= '<span id="question_'.$question_counter.'_media_link" class="question_media_link '.$question_media_link_class.'">'.$question_media_link.'</span>';
917
+							    	$html .= '<br/><img id="question_'.$question_counter.'_media_preview" class="question_media_preview '.$question_media_thumb_class.'" src="'.$question_media_thumb.'" /><br/>';
918
+							    	$html .= '<input type="hidden" id="question_'.$question_counter.'_media" class="question_media" name="question_media" value="'.$question_media.'" />';
919 919
 						    	$html .= '</div>';
920 920
 
921 921
 						    $html .= '</div>';
922 922
 
923
-						    $html .= $this->quiz_panel_question_field( $question_type, $question_id, $question_counter );
923
+						    $html .= $this->quiz_panel_question_field($question_type, $question_id, $question_counter);
924 924
 
925
-						    $html .= '<input type="hidden" id="question_' . $question_counter . '_question_type" class="question_type" name="question_type" value="' . $question_type . '" />';
926
-							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_' . $question_counter . '_id" value="' . $question_id . '" />';
925
+						    $html .= '<input type="hidden" id="question_'.$question_counter.'_question_type" class="question_type" name="question_type" value="'.$question_type.'" />';
926
+							$html .= '<input type="hidden" name="question_id" class="row_question_id" id="question_'.$question_counter.'_id" value="'.$question_id.'" />';
927 927
 
928
-							if( 'quiz' == $context ) {
928
+							if ('quiz' == $context) {
929 929
 					    		$html .= '<div class="update-question">';
930
-						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="' . esc_attr( __( 'Cancel', 'woothemes-sensei' ) ) . '">' . __( 'Cancel', 'woothemes-sensei' ) . '</a> ';
931
-						    		$html .= '<a title="' . esc_attr( __( 'Update Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="question_table_save button button-highlighted">' . esc_html( __( 'Update', 'woothemes-sensei' ) ) . '</a>';
930
+						    		$html .= '<a href="#question-edit-cancel" class="lesson_question_cancel" title="'.esc_attr(__('Cancel', 'woothemes-sensei')).'">'.__('Cancel', 'woothemes-sensei').'</a> ';
931
+						    		$html .= '<a title="'.esc_attr(__('Update Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="question_table_save button button-highlighted">'.esc_html(__('Update', 'woothemes-sensei')).'</a>';
932 932
 					    		$html .= '</div>';
933 933
 					    	}
934 934
 
@@ -943,79 +943,79 @@  discard block
 block discarded – undo
943 943
 		return $html;
944 944
 	}
945 945
 
946
-	public function quiz_panel_add( $context = 'quiz' ) {
946
+	public function quiz_panel_add($context = 'quiz') {
947 947
 
948 948
 
949 949
 		$html = '<div id="add-new-question">';
950 950
 
951 951
 			$question_types = Sensei()->question->question_types();
952 952
 
953
-			$question_cats = get_terms( 'question-category', array( 'hide_empty' => false ) );
953
+			$question_cats = get_terms('question-category', array('hide_empty' => false));
954 954
 
955
-			if( 'quiz' == $context ) {
955
+			if ('quiz' == $context) {
956 956
 	    		$html .= '<h2 class="nav-tab-wrapper add-question-tabs">';
957
-	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">' . __( 'New Question'  , 'woothemes-sensei' ) . '</a>';
958
-	    			$html .= '<a id="tab-existing" class="nav-tab">' . __( 'Existing Questions'  , 'woothemes-sensei' ) . '</a>';
959
-                    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats )  && ! Sensei()->teacher->is_admin_teacher() ) {
960
-	    				$html .= '<a id="tab-multiple" class="nav-tab">' . __( 'Category Questions'  , 'woothemes-sensei' ) . '</a>';
957
+	    			$html .= '<a id="tab-new" class="nav-tab nav-tab-active">'.__('New Question', 'woothemes-sensei').'</a>';
958
+	    			$html .= '<a id="tab-existing" class="nav-tab">'.__('Existing Questions', 'woothemes-sensei').'</a>';
959
+                    if ( ! empty($question_cats) && ! is_wp_error($question_cats) && ! Sensei()->teacher->is_admin_teacher()) {
960
+	    				$html .= '<a id="tab-multiple" class="nav-tab">'.__('Category Questions', 'woothemes-sensei').'</a>';
961 961
 	    			}
962 962
 	    		$html .= '</h2>';
963 963
 	    	}
964 964
 
965 965
 	    	$html .= '<div class="tab-content" id="tab-new-content">';
966 966
 
967
-	    		if( 'quiz' == $context ) {
968
-	    			$html .= '<p><em>' . sprintf( __( 'Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
967
+	    		if ('quiz' == $context) {
968
+	    			$html .= '<p><em>'.sprintf(__('Add a new question to this quiz - your question will also be added to the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
969 969
 	    		}
970 970
 
971 971
 				$html .= '<div class="question">';
972 972
 					$html .= '<div class="question_required_fields">';
973 973
 
974 974
 						// Question title
975
-						$html .= '<p><label>' . __( 'Question:'  , 'woothemes-sensei' ) . '</label> ';
975
+						$html .= '<p><label>'.__('Question:', 'woothemes-sensei').'</label> ';
976 976
 	  					$html .= '<input type="text" id="add_question" name="question" value="" size="25" class="widefat" /></p>';
977 977
 
978 978
 						// Question description
979 979
 						$html .= '<p>';
980
-							$html .= '<label for="question_desc">' . __( 'Question Description (optional):', 'woothemes-sensei' ) . '</label> ';
980
+							$html .= '<label for="question_desc">'.__('Question Description (optional):', 'woothemes-sensei').'</label> ';
981 981
 						$html .= '</p>';
982 982
 						$html .= '<textarea id="question_desc" name="question_description" class="widefat" rows="4"></textarea>';
983 983
 
984 984
 	  					// Question type
985
-						$html .= '<p><label>' . __( 'Question Type:' , 'woothemes-sensei' ) . '</label> ';
986
-						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">' . "\n";
987
-							foreach ( $question_types as $type => $label ) {
988
-								$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>' . "\n";
985
+						$html .= '<p><label>'.__('Question Type:', 'woothemes-sensei').'</label> ';
986
+						$html .= '<select id="add-question-type-options" name="question_type" class="chosen_select widefat question-type-select">'."\n";
987
+							foreach ($question_types as $type => $label) {
988
+								$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>'."\n";
989 989
 							} // End For Loop
990
-						$html .= '</select></p>' . "\n";
990
+						$html .= '</select></p>'."\n";
991 991
 
992 992
 						// Question category
993
-						if( 'quiz' == $context ) {
994
-							if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
995
-								$html .= '<p><label>' . __( 'Question Category:' , 'woothemes-sensei' ) . '</label> ';
996
-								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">' . "\n";
997
-								$html .= '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>' . "\n";
998
-								foreach( $question_cats as $cat ) {
999
-									$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
993
+						if ('quiz' == $context) {
994
+							if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
995
+								$html .= '<p><label>'.__('Question Category:', 'woothemes-sensei').'</label> ';
996
+								$html .= '<select id="add-question-category-options" name="question_category" class="chosen_select widefat question-category-select">'."\n";
997
+								$html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>'."\n";
998
+								foreach ($question_cats as $cat) {
999
+									$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1000 1000
 								} // End For Loop
1001
-								$html .= '</select></p>' . "\n";
1001
+								$html .= '</select></p>'."\n";
1002 1002
 							}
1003 1003
 						}
1004 1004
 
1005 1005
 	  					// Question grade
1006
-						$html .= '<p><label>' . __( 'Question Grade:'  , 'woothemes-sensei' ) . '</label> ';
1007
-						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>' . "\n";
1006
+						$html .= '<p><label>'.__('Question Grade:', 'woothemes-sensei').'</label> ';
1007
+						$html .= '<input type="number" id="add-question-grade" name="question_grade" class="small-text" min="0" value="1" /></p>'."\n";
1008 1008
 
1009 1009
 						// Random order
1010 1010
 						$html .= '<p class="add_question_random_order">';
1011
-			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> ' . __( 'Randomise answer order', 'woothemes-sensei' ) . '</label>';
1011
+			    			$html .= '<label for="add_random_order"><input type="checkbox" name="random_order" class="random_order" id="add_random_order" value="yes" checked="checked" /> '.__('Randomise answer order', 'woothemes-sensei').'</label>';
1012 1012
 			    		$html .= '</p>';
1013 1013
 
1014 1014
 			    		// Question media
1015 1015
 						$html .= '<p>';
1016
-					    	$html .= '<label for="question_add_new_media_button">' . __( 'Question media:', 'woothemes-sensei' ) . '</label><br/>';
1017
-					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="' . __( 'Add file to question', 'woothemes-sensei' ) . '" data-uploader_button_text="' . __( 'Add to question', 'woothemes-sensei' ) . '">' . __( 'Add file', 'woothemes-sensei' ) . '</button>';
1018
-					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">' . __( 'Delete file', 'woothemes-sensei' ) . '</button><br/>';
1016
+					    	$html .= '<label for="question_add_new_media_button">'.__('Question media:', 'woothemes-sensei').'</label><br/>';
1017
+					    	$html .= '<button id="question_add_new_media_button" class="upload_media_file_button button-secondary" data-uploader_title="'.__('Add file to question', 'woothemes-sensei').'" data-uploader_button_text="'.__('Add to question', 'woothemes-sensei').'">'.__('Add file', 'woothemes-sensei').'</button>';
1018
+					    	$html .= '<button id="question_add_new_media_button_delete" class="delete_media_file_button button-secondary hidden">'.__('Delete file', 'woothemes-sensei').'</button><br/>';
1019 1019
 					    	$html .= '<span id="question_add_new_media_link" class="question_media_link hidden"></span>';
1020 1020
 					    	$html .= '<br/><img id="question_add_new_media_preview" class="question_media_preview hidden" src="" /><br/>';
1021 1021
 					    	$html .= '<input type="hidden" id="question_add_new_media" class="question_media" name="question_media" value="" />';
@@ -1024,44 +1024,44 @@  discard block
 block discarded – undo
1024 1024
 					$html .= '</div>';
1025 1025
 				$html .= '</div>';
1026 1026
 
1027
-				foreach ( $question_types as $type => $label ) {
1028
-					$html .= $this->quiz_panel_question_field( $type );
1027
+				foreach ($question_types as $type => $label) {
1028
+					$html .= $this->quiz_panel_question_field($type);
1029 1029
 				}
1030 1030
 
1031
-				if( 'quiz' == $context ) {
1031
+				if ('quiz' == $context) {
1032 1032
 					$html .= '<div class="add-question">';
1033
-			    		$html .= '<a title="' . esc_attr( __( 'Add Question', 'woothemes-sensei' ) ) . '" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">' . esc_html( __( 'Add Question', 'woothemes-sensei' ) ) . '</a>';
1033
+			    		$html .= '<a title="'.esc_attr(__('Add Question', 'woothemes-sensei')).'" href="#add-question-metadata" class="add_question_save button button-primary button-highlighted">'.esc_html(__('Add Question', 'woothemes-sensei')).'</a>';
1034 1034
 		    		$html .= '</div>';
1035 1035
 		    	}
1036 1036
 
1037 1037
 		    $html .= '</div>';
1038 1038
 
1039
-		    if( 'quiz' == $context ) {
1039
+		    if ('quiz' == $context) {
1040 1040
 
1041 1041
 			    $html .= '<div class="tab-content hidden" id="tab-existing-content">';
1042 1042
 
1043
-			    	$html .= '<p><em>' . sprintf( __( 'Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit.php?post_type=question' ) . '">', '</a>' ) . '</em></p>';
1043
+			    	$html .= '<p><em>'.sprintf(__('Add an existing question to this quiz from the %1$squestion bank%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit.php?post_type=question').'">', '</a>').'</em></p>';
1044 1044
 
1045 1045
 			    	$html .= '<div id="existing-filters" class="alignleft actions">
1046 1046
 			    				<select id="existing-status">
1047
-			    					<option value="all">' . __( 'All', 'woothemes-sensei' ) . '</option>
1048
-			    					<option value="unused">' . __( 'Unused', 'woothemes-sensei' ) . '</option>
1049
-			    					<option value="used">' . __( 'Used', 'woothemes-sensei' ) . '</option>
1047
+			    					<option value="all">' . __('All', 'woothemes-sensei').'</option>
1048
+			    					<option value="unused">' . __('Unused', 'woothemes-sensei').'</option>
1049
+			    					<option value="used">' . __('Used', 'woothemes-sensei').'</option>
1050 1050
 			    				</select>
1051 1051
 			    				<select id="existing-type">
1052
-			    					<option value="">' . __( 'All Types', 'woothemes-sensei' ) . '</option>';
1053
-							    	foreach ( $question_types as $type => $label ) {
1054
-										$html .= '<option value="' . esc_attr( $type ) . '">' . esc_html( $label ) . '</option>';
1052
+			    					<option value="">' . __('All Types', 'woothemes-sensei').'</option>';
1053
+							    	foreach ($question_types as $type => $label) {
1054
+										$html .= '<option value="'.esc_attr($type).'">'.esc_html($label).'</option>';
1055 1055
 									}
1056 1056
     				$html .= '</select>
1057 1057
     							<select id="existing-category">
1058
-			    					<option value="">' . __( 'All Categories', 'woothemes-sensei' ) . '</option>';
1059
-				    				foreach( $question_cats as $cat ) {
1060
-										$html .= '<option value="' . esc_attr( $cat->slug ) . '">' . esc_html( $cat->name ) . '</option>';
1058
+			    					<option value="">' . __('All Categories', 'woothemes-sensei').'</option>';
1059
+				    				foreach ($question_cats as $cat) {
1060
+										$html .= '<option value="'.esc_attr($cat->slug).'">'.esc_html($cat->name).'</option>';
1061 1061
 									}
1062 1062
     				$html .= '</select>
1063
-    							<input type="text" id="existing-search" placeholder="' . __( 'Search', 'woothemes-sensei' ) . '" />
1064
-    							<a class="button" id="existing-filter-button">' . __( 'Filter', 'woothemes-sensei' ) . '</a>
1063
+    							<input type="text" id="existing-search" placeholder="' . __('Search', 'woothemes-sensei').'" />
1064
+    							<a class="button" id="existing-filter-button">' . __('Filter', 'woothemes-sensei').'</a>
1065 1065
 			    			</div>';
1066 1066
 
1067 1067
 			    	$html .= '<table id="existing-table" class="widefat">';
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
 			    		$html .= '<thead>
1070 1070
 									    <tr>
1071 1071
 									        <th scope="col" class="column-cb check-column"><input type="checkbox" /></th>
1072
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1073
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1074
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1072
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1073
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1074
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1075 1075
 									    </tr>
1076 1076
 									</thead>
1077 1077
 									<tfoot>
1078 1078
 									    <tr>
1079 1079
 										    <th scope="col" class="check-column"><input type="checkbox" /></th>
1080
-									        <th scope="col">' . __( 'Question', 'woothemes-sensei' ) . '</th>
1081
-									        <th scope="col">' . __( 'Type', 'woothemes-sensei' ) . '</th>
1082
-									        <th scope="col">' . __( 'Category', 'woothemes-sensei' ) . '</th>
1080
+									        <th scope="col">' . __('Question', 'woothemes-sensei').'</th>
1081
+									        <th scope="col">' . __('Type', 'woothemes-sensei').'</th>
1082
+									        <th scope="col">' . __('Category', 'woothemes-sensei').'</th>
1083 1083
 									    </tr>
1084 1084
 									</tfoot>';
1085 1085
 						$html .= '<tbody id="existing-questions">';
@@ -1087,8 +1087,8 @@  discard block
 block discarded – undo
1087 1087
 						$questions = $this->quiz_panel_get_existing_questions();
1088 1088
 
1089 1089
 						$row = 1;
1090
-						foreach( $questions['questions'] as $question ) {
1091
-							$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1090
+						foreach ($questions['questions'] as $question) {
1091
+							$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1092 1092
 							++$row;
1093 1093
 						}
1094 1094
 
@@ -1097,36 +1097,36 @@  discard block
 block discarded – undo
1097 1097
 			    	$html .= '</table>';
1098 1098
 
1099 1099
 			    	$next_class = '';
1100
-			    	if( $questions['count'] <= 10 ) {
1100
+			    	if ($questions['count'] <= 10) {
1101 1101
 			    		$next_class = 'hidden';
1102 1102
 			    	}
1103 1103
 
1104 1104
 			    	$html .= '<div id="existing-pagination">';
1105 1105
 			    		$html .= '<input type="hidden" id="existing-page" value="1" />';
1106
-			    		$html .= '<a class="prev no-paging">&larr; ' . __( 'Previous', 'woothemes-sensei') . '</a> <a class="next ' . esc_attr( $next_class ) . '">' . __( 'Next', 'woothemes-sensei') . ' &rarr;</a>';
1106
+			    		$html .= '<a class="prev no-paging">&larr; '.__('Previous', 'woothemes-sensei').'</a> <a class="next '.esc_attr($next_class).'">'.__('Next', 'woothemes-sensei').' &rarr;</a>';
1107 1107
 			    	$html .= '</div>';
1108 1108
 
1109 1109
 			    	$html .= '<div class="existing-actions">';
1110
-			    		$html .= '<a title="' . esc_attr( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '" class="add_existing_save button button-primary button-highlighted">' . esc_html( __( 'Add Selected Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1110
+			    		$html .= '<a title="'.esc_attr(__('Add Selected Question(s)', 'woothemes-sensei')).'" class="add_existing_save button button-primary button-highlighted">'.esc_html(__('Add Selected Question(s)', 'woothemes-sensei')).'</a></p>';
1111 1111
 			    	$html .= '</div>';
1112 1112
 
1113 1113
 			    $html .= '</div>';
1114 1114
 
1115
-			    if ( ! empty( $question_cats ) && ! is_wp_error( $question_cats ) ) {
1115
+			    if ( ! empty($question_cats) && ! is_wp_error($question_cats)) {
1116 1116
 				    $html .= '<div class="tab-content hidden" id="tab-multiple-content">';
1117 1117
 
1118
-				    	$html .= '<p><em>' . sprintf( __( 'Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei' ), '<a href="' . admin_url( 'edit-tags.php?taxonomy=question-category&post_type=question' ) . '">', '</a>' ) . '</em></p>';
1118
+				    	$html .= '<p><em>'.sprintf(__('Add any number of questions from a specified category. Edit your question categories %1$shere%2$s.', 'woothemes-sensei'), '<a href="'.admin_url('edit-tags.php?taxonomy=question-category&post_type=question').'">', '</a>').'</em></p>';
1119 1119
 
1120
-						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">' . "\n";
1121
-						$html .= '<option value="">' . __( 'Select a Question Category', 'woothemes-sensei' ) . '</option>' . "\n";
1122
-						foreach( $question_cats as $cat ) {
1123
-							$html .= '<option value="' . esc_attr( $cat->term_id ) . '">' . esc_html( $cat->name ) . '</option>';
1120
+						$html .= '<p><select id="add-multiple-question-category-options" name="multiple_category" class="chosen_select widefat question-category-select">'."\n";
1121
+						$html .= '<option value="">'.__('Select a Question Category', 'woothemes-sensei').'</option>'."\n";
1122
+						foreach ($question_cats as $cat) {
1123
+							$html .= '<option value="'.esc_attr($cat->term_id).'">'.esc_html($cat->name).'</option>';
1124 1124
 						} // End For Loop
1125
-						$html .= '</select></p>' . "\n";
1125
+						$html .= '</select></p>'."\n";
1126 1126
 
1127
-						$html .= '<p>' . __( 'Number of questions:', 'woothemes-sensei' ) . ' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1127
+						$html .= '<p>'.__('Number of questions:', 'woothemes-sensei').' <input type="number" min="1" value="1" max="1" id="add-multiple-question-count" class="small-text"/>';
1128 1128
 
1129
-						$html .= '<a title="' . esc_attr( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '" class="add_multiple_save button button-primary button-highlighted">' . esc_html( __( 'Add Question(s)', 'woothemes-sensei' ) ) . '</a></p>';
1129
+						$html .= '<a title="'.esc_attr(__('Add Question(s)', 'woothemes-sensei')).'" class="add_multiple_save button button-primary button-highlighted">'.esc_html(__('Add Question(s)', 'woothemes-sensei')).'</a></p>';
1130 1130
 
1131 1131
 				    $html .= '</div>';
1132 1132
 				}
@@ -1137,7 +1137,7 @@  discard block
 block discarded – undo
1137 1137
 		return $html;
1138 1138
 	}
1139 1139
 
1140
-	public function quiz_panel_get_existing_questions( $question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1 ) {
1140
+	public function quiz_panel_get_existing_questions($question_status = 'all', $question_type = '', $question_category = '', $question_search = '', $page = 1) {
1141 1141
 
1142 1142
 		$args = array(
1143 1143
 			'post_type' => 'question',
@@ -1146,14 +1146,14 @@  discard block
 block discarded – undo
1146 1146
 			'suppress_filters' => 0,
1147 1147
 		);
1148 1148
 
1149
-		switch( $question_status ) {
1149
+		switch ($question_status) {
1150 1150
 			case 'unused': $quiz_status = 'NOT EXISTS'; break;
1151 1151
 			case 'used': $quiz_status = 'EXISTS'; break;
1152 1152
 			default: $quiz_status = ''; break;
1153 1153
 		}
1154 1154
 
1155
-		if( $quiz_status ) {
1156
-			switch( $quiz_status ) {
1155
+		if ($quiz_status) {
1156
+			switch ($quiz_status) {
1157 1157
 				case 'EXISTS':
1158 1158
 					$args['meta_query'][] = array(
1159 1159
 						'key' => '_quiz_id',
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
 			}
1172 1172
 		}
1173 1173
 
1174
-		if( $question_type ) {
1174
+		if ($question_type) {
1175 1175
 			$args['tax_query'][] = array(
1176 1176
 				'taxonomy' => 'question-type',
1177 1177
 				'field' => 'slug',
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 			);
1180 1180
 		}
1181 1181
 
1182
-		if( $question_category ) {
1182
+		if ($question_category) {
1183 1183
 			$args['tax_query'][] = array(
1184 1184
 				'taxonomy' => 'question-category',
1185 1185
 				'field' => 'slug',
@@ -1187,19 +1187,19 @@  discard block
 block discarded – undo
1187 1187
 			);
1188 1188
 		}
1189 1189
 
1190
-		if( $question_type && $question_category ) {
1190
+		if ($question_type && $question_category) {
1191 1191
 			$args['tax_query']['relation'] = 'AND';
1192 1192
 		}
1193 1193
 
1194
-		if( $question_search ) {
1194
+		if ($question_search) {
1195 1195
 			$args['s'] = $question_search;
1196 1196
 		}
1197 1197
 
1198
-		if( $page ) {
1198
+		if ($page) {
1199 1199
 			$args['paged'] = $page;
1200 1200
 		}
1201 1201
 
1202
-		$qry = new WP_Query( $args );
1202
+		$qry = new WP_Query($args);
1203 1203
 
1204 1204
         /**
1205 1205
          * Filter existing questions query
@@ -1208,39 +1208,39 @@  discard block
 block discarded – undo
1208 1208
          *
1209 1209
          * @param WP_Query $wp_query
1210 1210
          */
1211
-        $qry = apply_filters( 'sensei_existing_questions_query_results', $qry );
1211
+        $qry = apply_filters('sensei_existing_questions_query_results', $qry);
1212 1212
 
1213 1213
 		$questions['questions'] = $qry->posts;
1214
-		$questions['count'] = intval( $qry->found_posts );
1214
+		$questions['count'] = intval($qry->found_posts);
1215 1215
 		$questions['page'] = $page;
1216 1216
 
1217 1217
 		return $questions;
1218 1218
 	}
1219 1219
 
1220
-	public function quiz_panel_add_existing_question( $question_id = 0, $row = 1 ) {
1220
+	public function quiz_panel_add_existing_question($question_id = 0, $row = 1) {
1221 1221
 
1222 1222
 		$html = '';
1223 1223
 
1224
-		if( ! $question_id ) {
1224
+		if ( ! $question_id) {
1225 1225
 
1226 1226
             return;
1227 1227
 
1228 1228
         }
1229 1229
 
1230 1230
 		$existing_class = '';
1231
-		if( $row % 2 ) {
1231
+		if ($row % 2) {
1232 1232
             $existing_class = 'alternate';
1233 1233
         }
1234 1234
 
1235
-		$question_type = Sensei()->question->get_question_type( $question_id );
1235
+		$question_type = Sensei()->question->get_question_type($question_id);
1236 1236
 
1237
-		$question_cat_list = strip_tags( get_the_term_list( $question_id, 'question-category', '', ', ', '' ) );
1237
+		$question_cat_list = strip_tags(get_the_term_list($question_id, 'question-category', '', ', ', ''));
1238 1238
 
1239
-		$html .= '<tr class="' . esc_attr( $existing_class ) . '">
1240
-					<td class="cb"><input type="checkbox" value="' . $question_id . '" class="existing-item" /></td>
1241
-					<td>' . get_the_title( $question_id ) . '</td>
1242
-					<td>' . esc_html( $question_type ) . '</td>
1243
-					<td>' . esc_html( $question_cat_list ) . '</td>
1239
+		$html .= '<tr class="'.esc_attr($existing_class).'">
1240
+					<td class="cb"><input type="checkbox" value="' . $question_id.'" class="existing-item" /></td>
1241
+					<td>' . get_the_title($question_id).'</td>
1242
+					<td>' . esc_html($question_type).'</td>
1243
+					<td>' . esc_html($question_cat_list).'</td>
1244 1244
 				  </tr>';
1245 1245
 
1246 1246
 		return $html;
@@ -1253,58 +1253,58 @@  discard block
 block discarded – undo
1253 1253
 
1254 1254
 		//Add nonce security to the request
1255 1255
 		$nonce = '';
1256
-		if( isset( $_POST['filter_existing_questions_nonce'] ) ) {
1257
-			$nonce = esc_html( $_POST['filter_existing_questions_nonce'] );
1256
+		if (isset($_POST['filter_existing_questions_nonce'])) {
1257
+			$nonce = esc_html($_POST['filter_existing_questions_nonce']);
1258 1258
 		} // End If Statement
1259 1259
 
1260
-		if( ! wp_verify_nonce( $nonce, 'filter_existing_questions_nonce' ) ) {
1261
-			die( $return );
1260
+		if ( ! wp_verify_nonce($nonce, 'filter_existing_questions_nonce')) {
1261
+			die($return);
1262 1262
 		} // End If Statement
1263 1263
 
1264 1264
 		// Parse POST data
1265 1265
 		$data = $_POST['data'];
1266 1266
 		$question_data = array();
1267
-		parse_str( $data, $question_data );
1267
+		parse_str($data, $question_data);
1268 1268
 
1269
-		if( 0 < count( $question_data ) ) {
1269
+		if (0 < count($question_data)) {
1270 1270
 
1271 1271
 			$question_status = '';
1272
-			if( isset( $question_data['question_status'] ) ) {
1272
+			if (isset($question_data['question_status'])) {
1273 1273
 				$question_status = $question_data['question_status'];
1274 1274
 			}
1275 1275
 
1276 1276
 			$question_type = '';
1277
-			if( isset( $question_data['question_type'] ) ) {
1277
+			if (isset($question_data['question_type'])) {
1278 1278
 				$question_type = $question_data['question_type'];
1279 1279
 			}
1280 1280
 
1281 1281
 			$question_category = '';
1282
-			if( isset( $question_data['question_category'] ) ) {
1282
+			if (isset($question_data['question_category'])) {
1283 1283
 				$question_category = $question_data['question_category'];
1284 1284
 			}
1285 1285
 
1286 1286
 			$question_search = '';
1287
-			if( isset( $question_data['question_search'] ) ) {
1287
+			if (isset($question_data['question_search'])) {
1288 1288
 				$question_search = $question_data['question_search'];
1289 1289
 			}
1290 1290
 
1291 1291
 			$question_page = 1;
1292
-			if( isset( $question_data['question_page'] ) ) {
1293
-				$question_page = intval( $question_data['question_page'] );
1292
+			if (isset($question_data['question_page'])) {
1293
+				$question_page = intval($question_data['question_page']);
1294 1294
 			}
1295 1295
 
1296
-			$questions = $this->quiz_panel_get_existing_questions( $question_status, $question_type, $question_category, $question_search, $question_page );
1296
+			$questions = $this->quiz_panel_get_existing_questions($question_status, $question_type, $question_category, $question_search, $question_page);
1297 1297
 
1298 1298
 			$row = 1;
1299 1299
 			$html = '';
1300
-			foreach( $questions['questions'] as $question ) {
1301
-				$html .= $this->quiz_panel_add_existing_question( $question->ID, $row );
1300
+			foreach ($questions['questions'] as $question) {
1301
+				$html .= $this->quiz_panel_add_existing_question($question->ID, $row);
1302 1302
 				++$row;
1303 1303
 			}
1304 1304
 
1305
-			if( ! $html ) {
1305
+			if ( ! $html) {
1306 1306
 				$html = '<tr class="alternate">
1307
-								<td class="no-results" colspan="4"><em>' . __( 'There are no questions matching your search.', 'woothemes-sensei' ) . '</em></td>
1307
+								<td class="no-results" colspan="4"><em>' . __('There are no questions matching your search.', 'woothemes-sensei').'</em></td>
1308 1308
 							  </tr>';
1309 1309
 			}
1310 1310
 
@@ -1312,53 +1312,53 @@  discard block
 block discarded – undo
1312 1312
 			$return['count'] = $questions['count'];
1313 1313
 			$return['page'] = $questions['page'];
1314 1314
 
1315
-			wp_send_json( $return );
1315
+			wp_send_json($return);
1316 1316
 		}
1317 1317
 
1318
-		die( $return );
1318
+		die($return);
1319 1319
 	}
1320 1320
 
1321
-	public function quiz_panel_question_field( $question_type = '', $question_id = 0, $question_counter = 0 ) {
1321
+	public function quiz_panel_question_field($question_type = '', $question_id = 0, $question_counter = 0) {
1322 1322
 
1323 1323
 		$html = '';
1324 1324
 
1325
-		if( $question_type ) {
1325
+		if ($question_type) {
1326 1326
 
1327 1327
 			$right_answer = '';
1328 1328
 			$wrong_answers = array();
1329 1329
 			$answer_order_string = '';
1330 1330
 			$answer_order = array();
1331
-			if( $question_id ) {
1332
-				$right_answer = get_post_meta( $question_id, '_question_right_answer', true);
1333
-				$wrong_answers = get_post_meta( $question_id, '_question_wrong_answers', true);
1334
-				$answer_order_string = get_post_meta( $question_id, '_answer_order', true );
1335
-				$answer_order = array_filter( explode( ',', $answer_order_string ) );
1331
+			if ($question_id) {
1332
+				$right_answer = get_post_meta($question_id, '_question_right_answer', true);
1333
+				$wrong_answers = get_post_meta($question_id, '_question_wrong_answers', true);
1334
+				$answer_order_string = get_post_meta($question_id, '_answer_order', true);
1335
+				$answer_order = array_filter(explode(',', $answer_order_string));
1336 1336
 				$question_class = '';
1337 1337
 			} else {
1338 1338
 				$question_id = '';
1339 1339
 				$question_class = 'answer-fields question_required_fields hidden';
1340 1340
 			}
1341 1341
 
1342
-			switch ( $question_type ) {
1342
+			switch ($question_type) {
1343 1343
 				case 'multiple-choice':
1344
-					$html .= '<div class="question_default_fields multiple-choice-answers ' . str_replace( ' hidden', '', $question_class ) . '">';
1344
+					$html .= '<div class="question_default_fields multiple-choice-answers '.str_replace(' hidden', '', $question_class).'">';
1345 1345
 
1346 1346
 						$right_answers = (array) $right_answer;
1347 1347
 						// Calculate total right answers available (defaults to 1)
1348 1348
 						$total_right = 0;
1349
-						if( $question_id ) {
1350
-							$total_right = get_post_meta( $question_id, '_right_answer_count', true );
1349
+						if ($question_id) {
1350
+							$total_right = get_post_meta($question_id, '_right_answer_count', true);
1351 1351
 						}
1352
-						if( 0 == intval( $total_right ) ) {
1352
+						if (0 == intval($total_right)) {
1353 1353
 							$total_right = 1;
1354 1354
 						}
1355
-						for ( $i = 0; $i < $total_right; $i++ ) {
1356
-							if ( !isset( $right_answers[ $i ] ) ) { $right_answers[ $i ] = ''; }
1357
-							$right_answer_id = $this->get_answer_id( $right_answers[ $i ] );
1355
+						for ($i = 0; $i < $total_right; $i++) {
1356
+							if ( ! isset($right_answers[$i])) { $right_answers[$i] = ''; }
1357
+							$right_answer_id = $this->get_answer_id($right_answers[$i]);
1358 1358
 							// Right Answer
1359
-							$right_answer = '<label class="answer" for="question_' . $question_counter . '_right_answer_' . $i . '"><span>' . __( 'Right:' , 'woothemes-sensei' ) . '</span> <input rel="' . esc_attr( $right_answer_id ) . '" type="text" id="question_' . $question_counter . '_right_answer_' . $i . '" name="question_right_answers[]" value="' . esc_attr( $right_answers[ $i ] ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
-							if( $question_id ) {
1361
-								$answers[ $right_answer_id ] = $right_answer;
1359
+							$right_answer = '<label class="answer" for="question_'.$question_counter.'_right_answer_'.$i.'"><span>'.__('Right:', 'woothemes-sensei').'</span> <input rel="'.esc_attr($right_answer_id).'" type="text" id="question_'.$question_counter.'_right_answer_'.$i.'" name="question_right_answers[]" value="'.esc_attr($right_answers[$i]).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1360
+							if ($question_id) {
1361
+								$answers[$right_answer_id] = $right_answer;
1362 1362
 							} else {
1363 1363
 								$answers[] = $right_answer;
1364 1364
 							}
@@ -1366,23 +1366,23 @@  discard block
 block discarded – undo
1366 1366
 
1367 1367
 				    	// Calculate total wrong answers available (defaults to 4)
1368 1368
 				    	$total_wrong = 0;
1369
-				    	if( $question_id ) {
1370
-				    		$total_wrong = get_post_meta( $question_id, '_wrong_answer_count', true );
1369
+				    	if ($question_id) {
1370
+				    		$total_wrong = get_post_meta($question_id, '_wrong_answer_count', true);
1371 1371
 				    	}
1372
-				    	if( 0 == intval( $total_wrong ) ) {
1372
+				    	if (0 == intval($total_wrong)) {
1373 1373
 				    		$total_wrong = 1;
1374 1374
 				    	}
1375 1375
 
1376 1376
                         // Setup Wrong Answer HTML
1377
-                        foreach ( $wrong_answers as $i => $answer ){
1377
+                        foreach ($wrong_answers as $i => $answer) {
1378 1378
 
1379
-                            $answer_id = $this->get_answer_id( $answer );
1380
-                            $wrong_answer = '<label class="answer" for="question_' . $question_counter . '_wrong_answer_' . $i . '"><span>' . __( 'Wrong:' , 'woothemes-sensei' ) ;
1381
-                            $wrong_answer .= '</span> <input rel="' . esc_attr( $answer_id ) . '" type="text" id="question_' . $question_counter . '_wrong_answer_' . $i ;
1382
-                            $wrong_answer .= '" name="question_wrong_answers[]" value="' . esc_attr( $answer ) . '" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
-                            if( $question_id ) {
1379
+                            $answer_id = $this->get_answer_id($answer);
1380
+                            $wrong_answer = '<label class="answer" for="question_'.$question_counter.'_wrong_answer_'.$i.'"><span>'.__('Wrong:', 'woothemes-sensei');
1381
+                            $wrong_answer .= '</span> <input rel="'.esc_attr($answer_id).'" type="text" id="question_'.$question_counter.'_wrong_answer_'.$i;
1382
+                            $wrong_answer .= '" name="question_wrong_answers[]" value="'.esc_attr($answer).'" size="25" class="question_answer widefat" /> <a class="remove_answer_option"></a></label>';
1383
+                            if ($question_id) {
1384 1384
 
1385
-                                $answers[ $answer_id ] = $wrong_answer;
1385
+                                $answers[$answer_id] = $wrong_answer;
1386 1386
 
1387 1387
                             } else {
1388 1388
 
@@ -1393,115 +1393,115 @@  discard block
 block discarded – undo
1393 1393
                         } // end for each
1394 1394
 
1395 1395
 				    	$answers_sorted = $answers;
1396
-				    	if( $question_id && count( $answer_order ) > 0 ) {
1396
+				    	if ($question_id && count($answer_order) > 0) {
1397 1397
 				    		$answers_sorted = array();
1398
-				    		foreach( $answer_order as $answer_id ) {
1399
-				    			if( isset( $answers[ $answer_id ] ) ) {
1400
-				    				$answers_sorted[ $answer_id ] = $answers[ $answer_id ];
1401
-				    				unset( $answers[ $answer_id ] );
1398
+				    		foreach ($answer_order as $answer_id) {
1399
+				    			if (isset($answers[$answer_id])) {
1400
+				    				$answers_sorted[$answer_id] = $answers[$answer_id];
1401
+				    				unset($answers[$answer_id]);
1402 1402
 				    			}
1403 1403
 				    		}
1404 1404
 
1405
-				    		if( count( $answers ) > 0 ) {
1406
-						    	foreach( $answers as $id => $answer ) {
1407
-						    		$answers_sorted[ $id ] = $answer;
1405
+				    		if (count($answers) > 0) {
1406
+						    	foreach ($answers as $id => $answer) {
1407
+						    		$answers_sorted[$id] = $answer;
1408 1408
 						    	}
1409 1409
 						    }
1410 1410
 				    	}
1411 1411
 
1412
-						foreach( $answers_sorted as $id => $answer ) {
1412
+						foreach ($answers_sorted as $id => $answer) {
1413 1413
 				    		$html .= $answer;
1414 1414
 				    	}
1415 1415
 
1416
-				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="' . $answer_order_string . '" />';
1417
-				    	$html .= '<span class="hidden right_answer_count">' . $total_right . '</span>';
1418
-				    	$html .= '<span class="hidden wrong_answer_count">' . $total_wrong . '</span>';
1416
+				    	$html .= '<input type="hidden" class="answer_order" name="answer_order" value="'.$answer_order_string.'" />';
1417
+				    	$html .= '<span class="hidden right_answer_count">'.$total_right.'</span>';
1418
+				    	$html .= '<span class="hidden wrong_answer_count">'.$total_wrong.'</span>';
1419 1419
 
1420 1420
 				    	$html .= '<div class="add_answer_options">';
1421
-					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add right answer', 'woothemes-sensei' ) . '</a>';
1422
-					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="' . $question_counter . '">' . __( 'Add wrong answer', 'woothemes-sensei' ) . '</a>';
1421
+					    	$html .= '<a class="add_right_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add right answer', 'woothemes-sensei').'</a>';
1422
+					    	$html .= '<a class="add_wrong_answer_option add_answer_option button" rel="'.$question_counter.'">'.__('Add wrong answer', 'woothemes-sensei').'</a>';
1423 1423
 				    	$html .= '</div>';
1424 1424
 
1425
-                        $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id , 'multiple-choice' );
1425
+                        $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'multiple-choice');
1426 1426
 
1427 1427
 			    	$html .= '</div>';
1428 1428
 				break;
1429 1429
 				case 'boolean':
1430
-					$html .= '<div class="question_boolean_fields ' . $question_class . '">';
1431
-						if( $question_id ) {
1432
-							$field_name = 'question_' . $question_id . '_right_answer_boolean';
1430
+					$html .= '<div class="question_boolean_fields '.$question_class.'">';
1431
+						if ($question_id) {
1432
+							$field_name = 'question_'.$question_id.'_right_answer_boolean';
1433 1433
 						} else {
1434 1434
 							$field_name = 'question_right_answer_boolean';
1435 1435
 							$right_answer = 'true';
1436 1436
 						}
1437
-						$html .= '<label for="question_' . $question_id . '_boolean_true"><input id="question_' . $question_id . '_boolean_true" type="radio" name="' . $field_name . '" value="true" '. checked( $right_answer, 'true', false ) . ' /> ' . __( 'True', 'woothemes-sensei' ) . '</label>';
1438
-						$html .= '<label for="question_' . $question_id . '_boolean_false"><input id="question_' . $question_id . '_boolean_false" type="radio" name="' . $field_name . '" value="false" '. checked( $right_answer, 'false', false ) . ' /> ' . __( 'False', 'woothemes-sensei' ) . '</label>';
1437
+						$html .= '<label for="question_'.$question_id.'_boolean_true"><input id="question_'.$question_id.'_boolean_true" type="radio" name="'.$field_name.'" value="true" '.checked($right_answer, 'true', false).' /> '.__('True', 'woothemes-sensei').'</label>';
1438
+						$html .= '<label for="question_'.$question_id.'_boolean_false"><input id="question_'.$question_id.'_boolean_false" type="radio" name="'.$field_name.'" value="false" '.checked($right_answer, 'false', false).' /> '.__('False', 'woothemes-sensei').'</label>';
1439 1439
 
1440
-                    $html .= $this->quiz_panel_question_feedback( $question_counter, $question_id, 'boolean' );
1440
+                    $html .= $this->quiz_panel_question_feedback($question_counter, $question_id, 'boolean');
1441 1441
 
1442 1442
 					$html .= '</div>';
1443 1443
 				break;
1444 1444
 				case 'gap-fill':
1445
-					$gapfill_array = explode( '||', $right_answer );
1446
-					if ( isset( $gapfill_array[0] ) ) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
-					if ( isset( $gapfill_array[1] ) ) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
-					if ( isset( $gapfill_array[2] ) ) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
-					$html .= '<div class="question_gapfill_fields ' . $question_class . '">';
1445
+					$gapfill_array = explode('||', $right_answer);
1446
+					if (isset($gapfill_array[0])) { $gapfill_pre = $gapfill_array[0]; } else { $gapfill_pre = ''; }
1447
+					if (isset($gapfill_array[1])) { $gapfill_gap = $gapfill_array[1]; } else { $gapfill_gap = ''; }
1448
+					if (isset($gapfill_array[2])) { $gapfill_post = $gapfill_array[2]; } else { $gapfill_post = ''; }
1449
+					$html .= '<div class="question_gapfill_fields '.$question_class.'">';
1450 1450
 						// Fill in the Gaps
1451
-						$html .= '<label>' . __( 'Text before the Gap:' , 'woothemes-sensei' ) . '</label> ';
1452
-						$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="' . $gapfill_pre . '" size="25" class="widefat gapfill-field" />';
1453
-	  					$html .= '<label>' . __( 'The Gap:' , 'woothemes-sensei' ) . '</label> ';
1454
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="' . $gapfill_gap . '" size="25" class="widefat gapfill-field" />';
1455
-	  					$html .= '<label>' . __( 'Text after the Gap:' , 'woothemes-sensei' ) . '</label> ';
1456
-	  					$html .= '<input type="text" id="question_' . $question_counter . '_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="' . $gapfill_post . '" size="25" class="widefat gapfill-field" />';
1457
-	  					$html .= '<label>' . __( 'Preview:' , 'woothemes-sensei' ) . '</label> ';
1458
-	  					$html .= '<p class="gapfill-preview">' . $gapfill_pre . '&nbsp;<u>' . $gapfill_gap . '</u>&nbsp;' . $gapfill_post . '</p>';
1451
+						$html .= '<label>'.__('Text before the Gap:', 'woothemes-sensei').'</label> ';
1452
+						$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_pre" name="add_question_right_answer_gapfill_pre" value="'.$gapfill_pre.'" size="25" class="widefat gapfill-field" />';
1453
+	  					$html .= '<label>'.__('The Gap:', 'woothemes-sensei').'</label> ';
1454
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_gap" name="add_question_right_answer_gapfill_gap" value="'.$gapfill_gap.'" size="25" class="widefat gapfill-field" />';
1455
+	  					$html .= '<label>'.__('Text after the Gap:', 'woothemes-sensei').'</label> ';
1456
+	  					$html .= '<input type="text" id="question_'.$question_counter.'_add_question_right_answer_gapfill_post" name="add_question_right_answer_gapfill_post" value="'.$gapfill_post.'" size="25" class="widefat gapfill-field" />';
1457
+	  					$html .= '<label>'.__('Preview:', 'woothemes-sensei').'</label> ';
1458
+	  					$html .= '<p class="gapfill-preview">'.$gapfill_pre.'&nbsp;<u>'.$gapfill_gap.'</u>&nbsp;'.$gapfill_post.'</p>';
1459 1459
 	  				$html .= '</div>';
1460 1460
 				break;
1461 1461
 				case 'multi-line':
1462
-					$html .= '<div class="question_multiline_fields ' . $question_class . '">';
1462
+					$html .= '<div class="question_multiline_fields '.$question_class.'">';
1463 1463
 						// Guides for grading
1464
-						if( $question_counter ) {
1465
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_multiline';
1464
+						if ($question_counter) {
1465
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_multiline';
1466 1466
 						} else {
1467 1467
 							$field_id = 'add_question_right_answer_multiline';
1468 1468
 						}
1469
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the answer' , 'woothemes-sensei' ) . '</label> ';
1470
-						$html .= '<textarea id="' . $field_id . '" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1469
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the answer', 'woothemes-sensei').'</label> ';
1470
+						$html .= '<textarea id="'.$field_id.'" name="add_question_right_answer_multiline" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1471 1471
 					$html .= '</div>';
1472 1472
 				break;
1473 1473
 				case 'single-line':
1474
-					$html .= '<div class="question_singleline_fields ' . $question_class . '">';
1474
+					$html .= '<div class="question_singleline_fields '.$question_class.'">';
1475 1475
 						// Recommended Answer
1476
-						if( $question_counter ) {
1477
-							$field_id = 'question_' . $question_counter . '_add_question_right_answer_singleline';
1476
+						if ($question_counter) {
1477
+							$field_id = 'question_'.$question_counter.'_add_question_right_answer_singleline';
1478 1478
 						} else {
1479 1479
 							$field_id = 'add_question_right_answer_singleline';
1480 1480
 						}
1481
-						$html .= '<label>' . __( 'Recommended Answer' , 'woothemes-sensei' ) . '</label> ';
1482
-						$html .= '<input type="text" id="' . $field_id . '" name="add_question_right_answer_singleline" value="' . $right_answer . '" size="25" class="widefat" />';
1481
+						$html .= '<label>'.__('Recommended Answer', 'woothemes-sensei').'</label> ';
1482
+						$html .= '<input type="text" id="'.$field_id.'" name="add_question_right_answer_singleline" value="'.$right_answer.'" size="25" class="widefat" />';
1483 1483
 					$html .= '</div>';
1484 1484
 				break;
1485 1485
 				case 'file-upload':
1486
-					$html .= '<div class="question_fileupload_fields ' . $question_class . '">';
1487
-						if( $question_counter ) {
1488
-							$right_field_id = 'question_' . $question_counter . '_add_question_right_answer_fileupload';
1489
-							$wrong_field_id = 'question_' . $question_counter . '_add_question_wrong_answer_fileupload';
1486
+					$html .= '<div class="question_fileupload_fields '.$question_class.'">';
1487
+						if ($question_counter) {
1488
+							$right_field_id = 'question_'.$question_counter.'_add_question_right_answer_fileupload';
1489
+							$wrong_field_id = 'question_'.$question_counter.'_add_question_wrong_answer_fileupload';
1490 1490
 						} else {
1491 1491
 							$right_field_id = 'add_question_right_answer_fileupload';
1492 1492
 							$wrong_field_id = 'add_question_wrong_answer_fileupload';
1493 1493
 						}
1494 1494
 
1495 1495
 						$wrong_answer = '';
1496
-						if( isset( $wrong_answers[0] ) ) {
1496
+						if (isset($wrong_answers[0])) {
1497 1497
 							$wrong_answer = $wrong_answers[0];
1498 1498
 						}
1499
-						$html .= '<label>' . __( 'Description for student explaining what needs to be uploaded' , 'woothemes-sensei' ) . '</label> ';
1500
-						$html .= '<textarea id="' . $wrong_field_id . '" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">' . $wrong_answer . '</textarea>';
1499
+						$html .= '<label>'.__('Description for student explaining what needs to be uploaded', 'woothemes-sensei').'</label> ';
1500
+						$html .= '<textarea id="'.$wrong_field_id.'" name="add_question_wrong_answer_fileupload" rows="4" cols="40" class="widefat">'.$wrong_answer.'</textarea>';
1501 1501
 
1502 1502
 						// Guides for grading
1503
-						$html .= '<label>' . __( 'Guide/Teacher Notes for grading the upload' , 'woothemes-sensei' ) . '</label> ';
1504
-						$html .= '<textarea id="' . $right_field_id . '" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">' . $right_answer . '</textarea>';
1503
+						$html .= '<label>'.__('Guide/Teacher Notes for grading the upload', 'woothemes-sensei').'</label> ';
1504
+						$html .= '<textarea id="'.$right_field_id.'" name="add_question_right_answer_fileupload" rows="4" cols="40" class="widefat">'.$right_answer.'</textarea>';
1505 1505
 					$html .= '</div>';
1506 1506
 				break;
1507 1507
 			}
@@ -1510,32 +1510,32 @@  discard block
 block discarded – undo
1510 1510
 		return $html;
1511 1511
 	}
1512 1512
 
1513
-	public function quiz_panel_question_feedback( $question_counter = 0, $question_id = 0, $question_type = '' ) {
1513
+	public function quiz_panel_question_feedback($question_counter = 0, $question_id = 0, $question_type = '') {
1514 1514
 
1515 1515
         // default field name
1516 1516
         $field_name = 'answer_feedback';
1517
-        if( 'boolean' == $question_type ){
1517
+        if ('boolean' == $question_type) {
1518 1518
 
1519 1519
             $field_name = 'answer_feedback_boolean';
1520 1520
 
1521
-        }elseif( 'multiple-choice' == $question_type ){
1521
+        }elseif ('multiple-choice' == $question_type) {
1522 1522
 
1523 1523
             $field_name = 'answer_feedback_multiple_choice';
1524 1524
 
1525 1525
         }// end if
1526 1526
 
1527
-		if( $question_counter ) {
1528
-			$field_name = 'answer_' . $question_counter . '_feedback';
1527
+		if ($question_counter) {
1528
+			$field_name = 'answer_'.$question_counter.'_feedback';
1529 1529
 		}
1530 1530
 
1531 1531
 		$feedback = '';
1532
-		if( $question_id ) {
1533
-			$feedback = get_post_meta( $question_id, '_answer_feedback', true );
1532
+		if ($question_id) {
1533
+			$feedback = get_post_meta($question_id, '_answer_feedback', true);
1534 1534
 		}
1535 1535
 
1536
-		$html = '<p title="' . __( 'This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei' ) . '">';
1537
-		$html .= '<label for="' . $field_name . '">' . __( 'Answer Feedback' , 'woothemes-sensei' ) . ':</label>';
1538
-		$html .= '<textarea id="' . $field_name . '" name="' . $field_name . '" rows="4" cols="40" class="answer_feedback widefat">' . $feedback . '</textarea>';
1536
+		$html = '<p title="'.__('This feedback will be automatically displayed to the student once they have completed the quiz.', 'woothemes-sensei').'">';
1537
+		$html .= '<label for="'.$field_name.'">'.__('Answer Feedback', 'woothemes-sensei').':</label>';
1538
+		$html .= '<textarea id="'.$field_name.'" name="'.$field_name.'" rows="4" cols="40" class="answer_feedback widefat">'.$feedback.'</textarea>';
1539 1539
 		$html .= '</p>';
1540 1540
 
1541 1541
 		return $html;
@@ -1544,19 +1544,19 @@  discard block
 block discarded – undo
1544 1544
 	public function question_get_answer_id() {
1545 1545
 		$data = $_POST['data'];
1546 1546
 		$answer_data = array();
1547
-		parse_str( $data, $answer_data );
1547
+		parse_str($data, $answer_data);
1548 1548
 		$answer = $answer_data['answer_value'];
1549
-		$answer_id = $this->get_answer_id( $answer );
1549
+		$answer_id = $this->get_answer_id($answer);
1550 1550
 		echo $answer_id;
1551 1551
 		die();
1552 1552
 	}
1553 1553
 
1554
-	public function get_answer_id( $answer = '' ) {
1554
+	public function get_answer_id($answer = '') {
1555 1555
 
1556 1556
 		$answer_id = '';
1557 1557
 
1558
-		if( $answer ) {
1559
-			$answer_id = md5( $answer );
1558
+		if ($answer) {
1559
+			$answer_id = md5($answer);
1560 1560
 		}
1561 1561
 
1562 1562
 		return $answer_id;
@@ -1569,17 +1569,17 @@  discard block
 block discarded – undo
1569 1569
 	 * @access public
1570 1570
 	 * @return void
1571 1571
 	 */
1572
-	public function lesson_quiz_meta_box_content () {
1572
+	public function lesson_quiz_meta_box_content() {
1573 1573
 		global $post;
1574 1574
 
1575 1575
 		// Get quiz panel
1576 1576
 		$quiz_id = 0;
1577 1577
 		$quizzes = array();
1578
-		if ( 0 < $post->ID ) {
1579
-			$quiz_id = $this->lesson_quizzes( $post->ID, 'any' );
1578
+		if (0 < $post->ID) {
1579
+			$quiz_id = $this->lesson_quizzes($post->ID, 'any');
1580 1580
 		}
1581 1581
 
1582
-		echo $this->quiz_panel( $quiz_id );
1582
+		echo $this->quiz_panel($quiz_id);
1583 1583
 
1584 1584
 	} // End lesson_quiz_meta_box_content()
1585 1585
 
@@ -1596,53 +1596,53 @@  discard block
 block discarded – undo
1596 1596
 		$quiz_id = 0;
1597 1597
 		$lesson_id = $post->ID;
1598 1598
 		$quizzes = array();
1599
-		if ( 0 < $lesson_id ) {
1600
-			$quiz_id = $this->lesson_quizzes( $lesson_id, 'any' );
1599
+		if (0 < $lesson_id) {
1600
+			$quiz_id = $this->lesson_quizzes($lesson_id, 'any');
1601 1601
 		}
1602 1602
 
1603
-		if( $quiz_id ) {
1604
-			$html .= $this->quiz_settings_panel( $lesson_id, $quiz_id );
1603
+		if ($quiz_id) {
1604
+			$html .= $this->quiz_settings_panel($lesson_id, $quiz_id);
1605 1605
 		} else {
1606
-			$html .= '<p><em>' . __( 'There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei' ) . '</em></p>';
1606
+			$html .= '<p><em>'.__('There is no quiz for this lesson yet - please add one in the \'Quiz Questions\' box.', 'woothemes-sensei').'</em></p>';
1607 1607
 		}
1608 1608
 
1609 1609
 		echo $html;
1610 1610
 	}
1611 1611
 
1612
-	public function quiz_settings_panel( $lesson_id = 0, $quiz_id = 0 ) {
1612
+	public function quiz_settings_panel($lesson_id = 0, $quiz_id = 0) {
1613 1613
 
1614 1614
 
1615 1615
 		$html = '';
1616 1616
 
1617
-		if( ! $lesson_id && ! $quiz_id ) return $html;
1617
+		if ( ! $lesson_id && ! $quiz_id) return $html;
1618 1618
 
1619
-		$settings = $this->get_quiz_settings( $quiz_id );
1619
+		$settings = $this->get_quiz_settings($quiz_id);
1620 1620
 
1621
-		$html = Sensei()->admin->render_settings( $settings, $quiz_id, 'quiz-settings' );
1621
+		$html = Sensei()->admin->render_settings($settings, $quiz_id, 'quiz-settings');
1622 1622
 
1623 1623
 		return $html;
1624 1624
 
1625 1625
 	}
1626 1626
 
1627
-	public function get_quiz_settings( $quiz_id = 0 ) {
1627
+	public function get_quiz_settings($quiz_id = 0) {
1628 1628
 
1629 1629
 		$disable_passmark = '';
1630
-		$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1631
-		if( ! $pass_required ) {
1630
+		$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1631
+		if ( ! $pass_required) {
1632 1632
 			$disable_passmark = 'hidden';
1633 1633
 		}
1634 1634
 
1635 1635
 		// Setup Questions Query
1636 1636
 		$questions = array();
1637
-		if ( 0 < $quiz_id ) {
1638
-			$questions = $this->lesson_quiz_questions( $quiz_id );
1637
+		if (0 < $quiz_id) {
1638
+			$questions = $this->lesson_quiz_questions($quiz_id);
1639 1639
 		}
1640 1640
 
1641 1641
 		// Count questions
1642 1642
 		$question_count = 0;
1643
-		foreach( $questions as $question ) {
1644
-			if( $question->post_type == 'multiple_question' ) {
1645
-				$question_number = get_post_meta( $question->ID, 'number', true );
1643
+		foreach ($questions as $question) {
1644
+			if ($question->post_type == 'multiple_question') {
1645
+				$question_number = get_post_meta($question->ID, 'number', true);
1646 1646
 				$question_count += $question_number;
1647 1647
 			} else {
1648 1648
 				++$question_count;
@@ -1652,15 +1652,15 @@  discard block
 block discarded – undo
1652 1652
 		$settings = array(
1653 1653
 			array(
1654 1654
 				'id' 			=> 'pass_required',
1655
-				'label'			=> __( 'Pass required to complete lesson', 'woothemes-sensei' ),
1656
-				'description'	=> __( 'The passmark must be achieved before the lesson is complete.', 'woothemes-sensei' ),
1655
+				'label'			=> __('Pass required to complete lesson', 'woothemes-sensei'),
1656
+				'description'	=> __('The passmark must be achieved before the lesson is complete.', 'woothemes-sensei'),
1657 1657
 				'type'			=> 'checkbox',
1658 1658
 				'default'		=> '',
1659 1659
 				'checked'		=> 'on',
1660 1660
 			),
1661 1661
 			array(
1662 1662
 				'id' 			=> 'quiz_passmark',
1663
-				'label'			=> __( 'Quiz passmark percentage', 'woothemes-sensei' ),
1663
+				'label'			=> __('Quiz passmark percentage', 'woothemes-sensei'),
1664 1664
 				'description'	=> '',
1665 1665
 				'type'			=> 'number',
1666 1666
 				'default'		=> 0,
@@ -1671,17 +1671,17 @@  discard block
 block discarded – undo
1671 1671
 			),
1672 1672
 			array(
1673 1673
 				'id' 			=> 'show_questions',
1674
-				'label'			=> __( 'Number of questions to show', 'woothemes-sensei' ),
1675
-				'description'	=> __( 'Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei' ),
1674
+				'label'			=> __('Number of questions to show', 'woothemes-sensei'),
1675
+				'description'	=> __('Show a random selection of questions from this quiz each time a student views it.', 'woothemes-sensei'),
1676 1676
 				'type'			=> 'number',
1677 1677
 				'default'		=> '',
1678
-				'placeholder'	=> __( 'All', 'woothemes-sensei' ),
1678
+				'placeholder'	=> __('All', 'woothemes-sensei'),
1679 1679
 				'min'			=> 1,
1680 1680
 				'max'			=> $question_count,
1681 1681
 			),
1682 1682
 			array(
1683 1683
 				'id' 			=> 'random_question_order',
1684
-				'label'			=> __( 'Randomise question order', 'woothemes-sensei' ),
1684
+				'label'			=> __('Randomise question order', 'woothemes-sensei'),
1685 1685
 				'description'	=> '',
1686 1686
 				'type'			=> 'checkbox',
1687 1687
 				'default'		=> 'no',
@@ -1689,23 +1689,23 @@  discard block
 block discarded – undo
1689 1689
 			),
1690 1690
 			array(
1691 1691
 				'id' 			=> 'quiz_grade_type',
1692
-				'label'			=> __( 'Grade quiz automatically', 'woothemes-sensei' ),
1693
-				'description'	=> __( 'Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei' ),
1692
+				'label'			=> __('Grade quiz automatically', 'woothemes-sensei'),
1693
+				'description'	=> __('Grades quiz and displays answer explanation immediately after completion. Only applicable if quiz is limited to Multiple Choice, True/False and Gap Fill questions. Questions that have a grade of zero are skipped during autograding.', 'woothemes-sensei'),
1694 1694
 				'type'			=> 'checkbox',
1695 1695
 				'default'		=> 'auto',
1696 1696
 				'checked'		=> 'auto',
1697 1697
 			),
1698 1698
 			array(
1699 1699
 				'id' 			=> 'enable_quiz_reset',
1700
-				'label'			=> __( 'Allow user to retake the quiz', 'woothemes-sensei' ),
1701
-				'description'	=> __( 'Enables the quiz reset button.', 'woothemes-sensei' ),
1700
+				'label'			=> __('Allow user to retake the quiz', 'woothemes-sensei'),
1701
+				'description'	=> __('Enables the quiz reset button.', 'woothemes-sensei'),
1702 1702
 				'type'			=> 'checkbox',
1703 1703
 				'default'		=> '',
1704 1704
 				'checked'		=> 'on',
1705 1705
 			),
1706 1706
 		);
1707 1707
 
1708
-		return apply_filters( 'sensei_quiz_settings', $settings );
1708
+		return apply_filters('sensei_quiz_settings', $settings);
1709 1709
 	}
1710 1710
 
1711 1711
 	/**
@@ -1714,38 +1714,38 @@  discard block
 block discarded – undo
1714 1714
 	 * @access public
1715 1715
 	 * @return void
1716 1716
 	 */
1717
-	public function enqueue_scripts( $hook ) {
1717
+	public function enqueue_scripts($hook) {
1718 1718
 		global  $post_type;
1719 1719
 
1720
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) );
1721
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1722
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order' ) );
1720
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question'));
1721
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1722
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order'));
1723 1723
 
1724 1724
 		// Test for Write Panel Pages
1725
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1725
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1726 1726
 
1727
-			$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1727
+			$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1728 1728
 
1729 1729
 			// Load the lessons script
1730 1730
             wp_enqueue_media();
1731
-			wp_enqueue_script( 'sensei-lesson-metadata', Sensei()->plugin_url . 'assets/js/lesson-metadata' . $suffix . '.js', array( 'jquery', 'sensei-core-select2' ,'jquery-ui-sortable' ), Sensei()->version, true );
1732
-			wp_enqueue_script( 'sensei-lesson-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1733
-			wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-lesson-chosen' ), Sensei()->version, true );
1731
+			wp_enqueue_script('sensei-lesson-metadata', Sensei()->plugin_url.'assets/js/lesson-metadata'.$suffix.'.js', array('jquery', 'sensei-core-select2', 'jquery-ui-sortable'), Sensei()->version, true);
1732
+			wp_enqueue_script('sensei-lesson-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1733
+			wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-lesson-chosen'), Sensei()->version, true);
1734 1734
 
1735 1735
             // Load the bulk edit screen script
1736
-            if( 'edit.php' == $hook && 'lesson'==$_GET['post_type'] ) {
1737
-                wp_enqueue_script( 'sensei-lessons-bulk-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-bulk-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1736
+            if ('edit.php' == $hook && 'lesson' == $_GET['post_type']) {
1737
+                wp_enqueue_script('sensei-lessons-bulk-edit', Sensei()->plugin_url.'assets/js/admin/lesson-bulk-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1738 1738
             }
1739 1739
 
1740 1740
 			// Localise script
1741
-			$translation_strings = array( 'right_colon' => __( 'Right:', 'woothemes-sensei' ), 'wrong_colon' => __( 'Wrong:', 'woothemes-sensei' ), 'add_file' => __( 'Add file', 'woothemes-sensei' ), 'change_file' => __( 'Change file', 'woothemes-sensei' ), 'confirm_remove' => __( 'Are you sure you want to remove this question?', 'woothemes-sensei' ), 'confirm_remove_multiple' => __( 'Are you sure you want to remove these questions?', 'woothemes-sensei' ), 'too_many_for_cat' => __( 'You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei' ) );
1742
-			$ajax_vars = array( 'lesson_update_question_nonce' => wp_create_nonce( 'lesson_update_question_nonce' ), 'lesson_add_course_nonce' => wp_create_nonce( 'lesson_add_course_nonce' ), 'lesson_update_grade_type_nonce' => wp_create_nonce( 'lesson_update_grade_type_nonce' ), 'lesson_update_question_order_nonce' => wp_create_nonce( 'lesson_update_question_order_nonce' ), 'lesson_update_question_order_random_nonce' => wp_create_nonce( 'lesson_update_question_order_random_nonce' ), 'lesson_add_multiple_questions_nonce' => wp_create_nonce( 'lesson_add_multiple_questions_nonce' ), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce( 'lesson_remove_multiple_questions_nonce' ), 'lesson_add_existing_questions_nonce' => wp_create_nonce( 'lesson_add_existing_questions_nonce' ), 'filter_existing_questions_nonce' => wp_create_nonce( 'filter_existing_questions_nonce' ) );
1743
-			$data = array_merge( $translation_strings, $ajax_vars );
1744
-			wp_localize_script( 'sensei-lesson-metadata', 'woo_localized_data', $data );
1741
+			$translation_strings = array('right_colon' => __('Right:', 'woothemes-sensei'), 'wrong_colon' => __('Wrong:', 'woothemes-sensei'), 'add_file' => __('Add file', 'woothemes-sensei'), 'change_file' => __('Change file', 'woothemes-sensei'), 'confirm_remove' => __('Are you sure you want to remove this question?', 'woothemes-sensei'), 'confirm_remove_multiple' => __('Are you sure you want to remove these questions?', 'woothemes-sensei'), 'too_many_for_cat' => __('You have selected more questions than this category contains - please reduce the number of questions that you are adding.', 'woothemes-sensei'));
1742
+			$ajax_vars = array('lesson_update_question_nonce' => wp_create_nonce('lesson_update_question_nonce'), 'lesson_add_course_nonce' => wp_create_nonce('lesson_add_course_nonce'), 'lesson_update_grade_type_nonce' => wp_create_nonce('lesson_update_grade_type_nonce'), 'lesson_update_question_order_nonce' => wp_create_nonce('lesson_update_question_order_nonce'), 'lesson_update_question_order_random_nonce' => wp_create_nonce('lesson_update_question_order_random_nonce'), 'lesson_add_multiple_questions_nonce' => wp_create_nonce('lesson_add_multiple_questions_nonce'), 'lesson_remove_multiple_questions_nonce' => wp_create_nonce('lesson_remove_multiple_questions_nonce'), 'lesson_add_existing_questions_nonce' => wp_create_nonce('lesson_add_existing_questions_nonce'), 'filter_existing_questions_nonce' => wp_create_nonce('filter_existing_questions_nonce'));
1743
+			$data = array_merge($translation_strings, $ajax_vars);
1744
+			wp_localize_script('sensei-lesson-metadata', 'woo_localized_data', $data);
1745 1745
 
1746 1746
 			// Chosen RTL
1747
-			if ( is_rtl() ) {
1748
-				wp_enqueue_script( 'sensei-chosen-rtl', Sensei()->plugin_url . 'assets/chosen/chosen-rtl' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
1747
+			if (is_rtl()) {
1748
+				wp_enqueue_script('sensei-chosen-rtl', Sensei()->plugin_url.'assets/chosen/chosen-rtl'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1749 1749
 			}
1750 1750
 
1751 1751
 		}
@@ -1759,16 +1759,16 @@  discard block
 block discarded – undo
1759 1759
 	 * @since  1.4.0
1760 1760
 	 * @return void
1761 1761
 	 */
1762
-	public function enqueue_styles ( $hook ) {
1762
+	public function enqueue_styles($hook) {
1763 1763
 		global  $post_type;
1764 1764
 
1765
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question', 'sensei_message' ) );
1766
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
1767
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings' ) );
1765
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question', 'sensei_message'));
1766
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
1767
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings'));
1768 1768
 
1769 1769
 		// Test for Write Panel Pages
1770
-		if ( ( ( isset( $post_type ) && in_array( $post_type, $allowed_post_types ) ) && ( isset( $hook ) && in_array( $hook, $allowed_post_type_pages ) ) ) || ( isset( $_GET['page'] ) && in_array( $_GET['page'], $allowed_pages ) ) ) {
1771
-			wp_enqueue_style( 'woothemes-sensei-settings-api', esc_url( Sensei()->plugin_url . 'assets/css/settings.css' ), '', Sensei()->version );
1770
+		if (((isset($post_type) && in_array($post_type, $allowed_post_types)) && (isset($hook) && in_array($hook, $allowed_post_type_pages))) || (isset($_GET['page']) && in_array($_GET['page'], $allowed_pages))) {
1771
+			wp_enqueue_style('woothemes-sensei-settings-api', esc_url(Sensei()->plugin_url.'assets/css/settings.css'), '', Sensei()->version);
1772 1772
 		}
1773 1773
 
1774 1774
 	} // End enqueue_styles()
@@ -1780,12 +1780,12 @@  discard block
 block discarded – undo
1780 1780
 	 * @param  array $defaults
1781 1781
 	 * @return array $new_columns
1782 1782
 	 */
1783
-	public function add_column_headings ( $defaults ) {
1783
+	public function add_column_headings($defaults) {
1784 1784
 		$new_columns['cb'] = '<input type="checkbox" />';
1785
-		$new_columns['title'] = _x( 'Lesson Title', 'column name', 'woothemes-sensei' );
1786
-		$new_columns['lesson-course'] = _x( 'Course', 'column name', 'woothemes-sensei' );
1787
-		$new_columns['lesson-prerequisite'] = _x( 'Pre-requisite Lesson', 'column name', 'woothemes-sensei' );
1788
-		if ( isset( $defaults['date'] ) ) {
1785
+		$new_columns['title'] = _x('Lesson Title', 'column name', 'woothemes-sensei');
1786
+		$new_columns['lesson-course'] = _x('Course', 'column name', 'woothemes-sensei');
1787
+		$new_columns['lesson-prerequisite'] = _x('Pre-requisite Lesson', 'column name', 'woothemes-sensei');
1788
+		if (isset($defaults['date'])) {
1789 1789
 			$new_columns['date'] = $defaults['date'];
1790 1790
 		}
1791 1791
 		return $new_columns;
@@ -1799,23 +1799,23 @@  discard block
 block discarded – undo
1799 1799
 	 * @param  int $id
1800 1800
 	 * @return void
1801 1801
 	 */
1802
-	public function add_column_data ( $column_name, $id ) {
1802
+	public function add_column_data($column_name, $id) {
1803 1803
 		global $wpdb, $post;
1804 1804
 
1805
-		switch ( $column_name ) {
1805
+		switch ($column_name) {
1806 1806
 			case 'id':
1807 1807
 				echo $id;
1808 1808
 			break;
1809 1809
 			case 'lesson-course':
1810
-				$lesson_course_id = get_post_meta( $id, '_lesson_course', true);
1811
-				if ( 0 < absint( $lesson_course_id ) ) {
1812
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_course_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_course_id ) ) ) ) . '">' . get_the_title( absint( $lesson_course_id ) ) . '</a>';
1810
+				$lesson_course_id = get_post_meta($id, '_lesson_course', true);
1811
+				if (0 < absint($lesson_course_id)) {
1812
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_course_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_course_id)))).'">'.get_the_title(absint($lesson_course_id)).'</a>';
1813 1813
 				} // End If Statement
1814 1814
 			break;
1815 1815
 			case 'lesson-prerequisite':
1816
-				$lesson_prerequisite_id = get_post_meta( $id, '_lesson_prerequisite', true);
1817
-				if ( 0 < absint( $lesson_prerequisite_id ) ) {
1818
-					echo '<a href="' . esc_url( get_edit_post_link( absint( $lesson_prerequisite_id ) ) ) . '" title="' . esc_attr( sprintf( __( 'Edit %s', 'woothemes-sensei' ), get_the_title( absint( $lesson_prerequisite_id ) ) ) ) . '">' . get_the_title( absint( $lesson_prerequisite_id ) ) . '</a>';
1816
+				$lesson_prerequisite_id = get_post_meta($id, '_lesson_prerequisite', true);
1817
+				if (0 < absint($lesson_prerequisite_id)) {
1818
+					echo '<a href="'.esc_url(get_edit_post_link(absint($lesson_prerequisite_id))).'" title="'.esc_attr(sprintf(__('Edit %s', 'woothemes-sensei'), get_the_title(absint($lesson_prerequisite_id)))).'">'.get_the_title(absint($lesson_prerequisite_id)).'</a>';
1819 1819
 				} // End If Statement
1820 1820
 			break;
1821 1821
 			default:
@@ -1829,14 +1829,14 @@  discard block
 block discarded – undo
1829 1829
 	 * @access public
1830 1830
 	 * @return void
1831 1831
 	 */
1832
-	public function lesson_add_course () {
1832
+	public function lesson_add_course() {
1833 1833
 		global $current_user;
1834 1834
 		//Add nonce security to the request
1835
-		if ( isset($_POST['lesson_add_course_nonce']) ) {
1836
-			$nonce = esc_html( $_POST['lesson_add_course_nonce'] );
1835
+		if (isset($_POST['lesson_add_course_nonce'])) {
1836
+			$nonce = esc_html($_POST['lesson_add_course_nonce']);
1837 1837
 		} // End If Statement
1838
-		if ( ! wp_verify_nonce( $nonce, 'lesson_add_course_nonce' )
1839
-            || ! current_user_can( 'edit_lessons' ) ) {
1838
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_course_nonce')
1839
+            || ! current_user_can('edit_lessons')) {
1840 1840
 			die('');
1841 1841
 		} // End If Statement
1842 1842
 		// Parse POST data
@@ -1858,14 +1858,14 @@  discard block
 block discarded – undo
1858 1858
 	 * @access public
1859 1859
 	 * @return void
1860 1860
 	 */
1861
-	public function lesson_update_question () {
1861
+	public function lesson_update_question() {
1862 1862
 		global $current_user;
1863 1863
 		//Add nonce security to the request
1864
-		if ( isset($_POST['lesson_update_question_nonce']) ) {
1865
-			$nonce = esc_html( $_POST['lesson_update_question_nonce'] );
1864
+		if (isset($_POST['lesson_update_question_nonce'])) {
1865
+			$nonce = esc_html($_POST['lesson_update_question_nonce']);
1866 1866
 		} // End If Statement
1867
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_nonce' )
1868
-            ||  ! current_user_can( 'edit_questions' )) {
1867
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_nonce')
1868
+            ||  ! current_user_can('edit_questions')) {
1869 1869
 
1870 1870
 			die('');
1871 1871
 
@@ -1875,30 +1875,30 @@  discard block
 block discarded – undo
1875 1875
 		// WP slashes all incoming data regardless of Magic Quotes setting (see wp_magic_quotes()), which means that
1876 1876
 		// even the $_POST['data'] encoded with encodeURIComponent has it's apostrophes slashed.
1877 1877
 		// So first restore the original unslashed apostrophes by removing those slashes
1878
-		$data = wp_unslash( $_POST['data'] );
1878
+		$data = wp_unslash($_POST['data']);
1879 1879
 		// Then parse the string to an array (note that parse_str automatically urldecodes all the variables)
1880 1880
 		$question_data = array();
1881 1881
 		parse_str($data, $question_data);
1882 1882
 		// Finally re-slash all elements to ensure consistancy for lesson_save_question()
1883
-		$question_data = wp_slash( $question_data );
1883
+		$question_data = wp_slash($question_data);
1884 1884
 		// Save the question
1885 1885
 		$return = false;
1886 1886
 		// Question Save and Delete logic
1887
-		if ( isset( $question_data['action'] ) && ( $question_data['action'] == 'delete' ) ) {
1887
+		if (isset($question_data['action']) && ($question_data['action'] == 'delete')) {
1888 1888
 			// Delete the Question
1889 1889
 			$return = $this->lesson_delete_question($question_data);
1890 1890
 		} else {
1891 1891
 			// Save the Question
1892
-			if ( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1892
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1893 1893
 				$current_user = wp_get_current_user();
1894 1894
 				$question_data['post_author'] = $current_user->ID;
1895
-				$question_id = $this->lesson_save_question( $question_data );
1896
-				$question_type = Sensei()->question->get_question_type( $question_id );
1895
+				$question_id = $this->lesson_save_question($question_data);
1896
+				$question_type = Sensei()->question->get_question_type($question_id);
1897 1897
 
1898
-				$question_count = intval( $question_data['question_count'] );
1898
+				$question_count = intval($question_data['question_count']);
1899 1899
 				++$question_count;
1900 1900
 
1901
-				$return = $this->quiz_panel_question( $question_type, $question_count, $question_id );
1901
+				$return = $this->quiz_panel_question($question_type, $question_count, $question_id);
1902 1902
 			} // End If Statement
1903 1903
 		} // End If Statement
1904 1904
 
@@ -1913,49 +1913,49 @@  discard block
 block discarded – undo
1913 1913
 
1914 1914
 		//Add nonce security to the request
1915 1915
 		$nonce = '';
1916
-		if( isset( $_POST['lesson_add_multiple_questions_nonce'] ) ) {
1917
-			$nonce = esc_html( $_POST['lesson_add_multiple_questions_nonce'] );
1916
+		if (isset($_POST['lesson_add_multiple_questions_nonce'])) {
1917
+			$nonce = esc_html($_POST['lesson_add_multiple_questions_nonce']);
1918 1918
 		} // End If Statement
1919 1919
 
1920
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_multiple_questions_nonce' )
1921
-            || ! current_user_can( 'edit_lessons' ) ) {
1922
-			die( $return );
1920
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_multiple_questions_nonce')
1921
+            || ! current_user_can('edit_lessons')) {
1922
+			die($return);
1923 1923
 		} // End If Statement
1924 1924
 
1925 1925
 		// Parse POST data
1926 1926
 		$data = $_POST['data'];
1927 1927
 		$question_data = array();
1928
-		parse_str( $data, $question_data );
1928
+		parse_str($data, $question_data);
1929 1929
 
1930
-		if( is_array( $question_data ) ) {
1931
-			if( isset( $question_data['quiz_id'] ) && ( 0 < absint( $question_data['quiz_id'] ) ) ) {
1930
+		if (is_array($question_data)) {
1931
+			if (isset($question_data['quiz_id']) && (0 < absint($question_data['quiz_id']))) {
1932 1932
 
1933
-				$quiz_id = intval( $question_data['quiz_id'] );
1934
-				$question_number = intval( $question_data['question_number'] );
1935
-				$question_category = intval( $question_data['question_category'] );
1933
+				$quiz_id = intval($question_data['quiz_id']);
1934
+				$question_number = intval($question_data['question_number']);
1935
+				$question_category = intval($question_data['question_category']);
1936 1936
 
1937
-				$question_counter = intval( $question_data['question_count'] );
1937
+				$question_counter = intval($question_data['question_count']);
1938 1938
 				++$question_counter;
1939 1939
 
1940
-				$cat = get_term( $question_category, 'question-category' );
1940
+				$cat = get_term($question_category, 'question-category');
1941 1941
 
1942 1942
 				$post_data = array(
1943 1943
 					'post_content' => '',
1944 1944
 					'post_status' => 'publish',
1945
-					'post_title' => sprintf( __( '%1$s Question(s) from %2$s', 'woothemes-sensei' ), $question_number, $cat->name ),
1945
+					'post_title' => sprintf(__('%1$s Question(s) from %2$s', 'woothemes-sensei'), $question_number, $cat->name),
1946 1946
 					'post_type' => 'multiple_question'
1947 1947
 				);
1948 1948
 
1949
-				$multiple_id = wp_insert_post( $post_data );
1949
+				$multiple_id = wp_insert_post($post_data);
1950 1950
 
1951
-				if( $multiple_id && ! is_wp_error( $multiple_id ) ) {
1952
-					add_post_meta( $multiple_id, 'category', $question_category );
1953
-					add_post_meta( $multiple_id, 'number', $question_number );
1954
-					add_post_meta( $multiple_id, '_quiz_id', $quiz_id, false );
1955
-					add_post_meta( $multiple_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_counter );
1956
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1957
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
1958
-					$return = $this->quiz_panel_question( 'category', $question_counter, $multiple_id, 'quiz', array( $cat->name, $question_number ) );
1951
+				if ($multiple_id && ! is_wp_error($multiple_id)) {
1952
+					add_post_meta($multiple_id, 'category', $question_category);
1953
+					add_post_meta($multiple_id, 'number', $question_number);
1954
+					add_post_meta($multiple_id, '_quiz_id', $quiz_id, false);
1955
+					add_post_meta($multiple_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_counter);
1956
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1957
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
1958
+					$return = $this->quiz_panel_question('category', $question_counter, $multiple_id, 'quiz', array($cat->name, $question_number));
1959 1959
 				}
1960 1960
 			}
1961 1961
 		}
@@ -1969,25 +1969,25 @@  discard block
 block discarded – undo
1969 1969
 
1970 1970
 		//Add nonce security to the request
1971 1971
 		$nonce = '';
1972
-		if( isset( $_POST['lesson_remove_multiple_questions_nonce'] ) ) {
1973
-			$nonce = esc_html( $_POST['lesson_remove_multiple_questions_nonce'] );
1972
+		if (isset($_POST['lesson_remove_multiple_questions_nonce'])) {
1973
+			$nonce = esc_html($_POST['lesson_remove_multiple_questions_nonce']);
1974 1974
 		} // End If Statement
1975 1975
 
1976
-		if( ! wp_verify_nonce( $nonce, 'lesson_remove_multiple_questions_nonce' )
1977
-        || ! current_user_can( 'edit_lessons' ) ) {
1976
+		if ( ! wp_verify_nonce($nonce, 'lesson_remove_multiple_questions_nonce')
1977
+        || ! current_user_can('edit_lessons')) {
1978 1978
 			die('');
1979 1979
 		} // End If Statement
1980 1980
 
1981 1981
 		// Parse POST data
1982 1982
 		$data = $_POST['data'];
1983 1983
 		$question_data = array();
1984
-		parse_str( $data, $question_data );
1984
+		parse_str($data, $question_data);
1985 1985
 
1986
-		if( is_array( $question_data ) ) {
1987
-			wp_delete_post( $question_data['question_id'], true );
1986
+		if (is_array($question_data)) {
1987
+			wp_delete_post($question_data['question_id'], true);
1988 1988
 		}
1989 1989
 
1990
-		die( 'Deleted' );
1990
+		die('Deleted');
1991 1991
 	}
1992 1992
 
1993 1993
 	public function get_question_category_limit() {
@@ -1998,11 +1998,11 @@  discard block
 block discarded – undo
1998 1998
 		// Parse POST data
1999 1999
 		$data = $_POST['data'];
2000 2000
 		$cat_data = array();
2001
-		parse_str( $data, $cat_data );
2001
+		parse_str($data, $cat_data);
2002 2002
 
2003
-		if( isset( $cat_data['cat'] ) && '' != $cat_data['cat'] ) {
2004
-			$cat = get_term( $cat_data['cat'], 'question-category' );
2005
-			if( isset( $cat->count ) ) {
2003
+		if (isset($cat_data['cat']) && '' != $cat_data['cat']) {
2004
+			$cat = get_term($cat_data['cat'], 'question-category');
2005
+			if (isset($cat->count)) {
2006 2006
 				$return = $cat->count;
2007 2007
 			}
2008 2008
 		}
@@ -2016,45 +2016,45 @@  discard block
 block discarded – undo
2016 2016
 
2017 2017
 		//Add nonce security to the request
2018 2018
 		$nonce = '';
2019
-		if( isset( $_POST['lesson_add_existing_questions_nonce'] ) ) {
2020
-			$nonce = esc_html( $_POST['lesson_add_existing_questions_nonce'] );
2019
+		if (isset($_POST['lesson_add_existing_questions_nonce'])) {
2020
+			$nonce = esc_html($_POST['lesson_add_existing_questions_nonce']);
2021 2021
 		} // End If Statement
2022 2022
 
2023
-		if( ! wp_verify_nonce( $nonce, 'lesson_add_existing_questions_nonce' )
2024
-        || ! current_user_can( 'edit_lessons' ) ) {
2023
+		if ( ! wp_verify_nonce($nonce, 'lesson_add_existing_questions_nonce')
2024
+        || ! current_user_can('edit_lessons')) {
2025 2025
 			die('');
2026 2026
 		} // End If Statement
2027 2027
 
2028 2028
 		// Parse POST data
2029 2029
 		$data = $_POST['data'];
2030 2030
 		$question_data = array();
2031
-		parse_str( $data, $question_data );
2031
+		parse_str($data, $question_data);
2032 2032
 
2033 2033
 		$return = '';
2034 2034
 
2035
-		if( is_array( $question_data ) ) {
2035
+		if (is_array($question_data)) {
2036 2036
 
2037
-			if( isset( $question_data['questions'] ) && '' != $question_data['questions'] ) {
2037
+			if (isset($question_data['questions']) && '' != $question_data['questions']) {
2038 2038
 
2039
-				$questions = explode( ',', trim( $question_data['questions'], ',' ) );
2039
+				$questions = explode(',', trim($question_data['questions'], ','));
2040 2040
 				$quiz_id = $question_data['quiz_id'];
2041
-				$question_count = intval( $question_data['question_count'] );
2041
+				$question_count = intval($question_data['question_count']);
2042 2042
 
2043
-				foreach( $questions as $question_id ) {
2043
+				foreach ($questions as $question_id) {
2044 2044
 
2045 2045
 					++$question_count;
2046 2046
 
2047
-					$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2048
-					if( ! in_array( $quiz_id, $quizzes ) ) {
2049
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2050
-						$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2051
-						update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2047
+					$quizzes = get_post_meta($question_id, '_quiz_id', false);
2048
+					if ( ! in_array($quiz_id, $quizzes)) {
2049
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2050
+						$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2051
+						update_post_meta($lesson_id, '_quiz_has_questions', '1');
2052 2052
 			    	}
2053 2053
 
2054
-			    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2055
-					$question_type = Sensei()->question->get_question_type( $question_id );
2054
+			    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2055
+					$question_type = Sensei()->question->get_question_type($question_id);
2056 2056
 
2057
-					$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
2057
+					$return .= $this->quiz_panel_question($question_type, $question_count, $question_id);
2058 2058
 				}
2059 2059
 			}
2060 2060
 		}
@@ -2066,14 +2066,14 @@  discard block
 block discarded – undo
2066 2066
 
2067 2067
 	public function lesson_update_grade_type() {
2068 2068
 		//Add nonce security to the request
2069
-		if ( isset($_POST['lesson_update_grade_type_nonce']) ) {
2069
+		if (isset($_POST['lesson_update_grade_type_nonce'])) {
2070 2070
 
2071
-			$nonce = esc_html( $_POST['lesson_update_grade_type_nonce'] );
2071
+			$nonce = esc_html($_POST['lesson_update_grade_type_nonce']);
2072 2072
 
2073 2073
 		} // End If Statement
2074 2074
 
2075
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_grade_type_nonce' )
2076
-        || ! current_user_can( 'edit_lessons' ) ) {
2075
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_grade_type_nonce')
2076
+        || ! current_user_can('edit_lessons')) {
2077 2077
 
2078 2078
 			die('');
2079 2079
 
@@ -2083,18 +2083,18 @@  discard block
 block discarded – undo
2083 2083
 		$data = $_POST['data'];
2084 2084
 		$quiz_data = array();
2085 2085
 		parse_str($data, $quiz_data);
2086
-		update_post_meta( $quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type'] );
2086
+		update_post_meta($quiz_data['quiz_id'], '_quiz_grade_type', $quiz_data['quiz_grade_type']);
2087 2087
 		die();
2088 2088
 	}
2089 2089
 
2090 2090
 	public function lesson_update_question_order() {
2091 2091
 		// Add nonce security to the request
2092
-		if ( isset($_POST['lesson_update_question_order_nonce']) ) {
2093
-			$nonce = esc_html( $_POST['lesson_update_question_order_nonce'] );
2092
+		if (isset($_POST['lesson_update_question_order_nonce'])) {
2093
+			$nonce = esc_html($_POST['lesson_update_question_order_nonce']);
2094 2094
 		} // End If Statement
2095 2095
 
2096
-        if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_nonce' )
2097
-            ||! current_user_can( 'edit_lessons' ) ) {
2096
+        if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_nonce')
2097
+            ||! current_user_can('edit_lessons')) {
2098 2098
 			die('');
2099 2099
 		} // End If Statement
2100 2100
 
@@ -2102,25 +2102,25 @@  discard block
 block discarded – undo
2102 2102
 		$data = $_POST['data'];
2103 2103
 		$quiz_data = array();
2104 2104
 		parse_str($data, $quiz_data);
2105
-		if( strlen( $quiz_data['question_order'] ) > 0 ) {
2106
-			$questions = explode( ',', $quiz_data['question_order'] );
2105
+		if (strlen($quiz_data['question_order']) > 0) {
2106
+			$questions = explode(',', $quiz_data['question_order']);
2107 2107
 			$o = 1;
2108
-			foreach( $questions as $question_id ) {
2109
-				update_post_meta( $question_id, '_quiz_question_order' . $quiz_data['quiz_id'], $quiz_data['quiz_id'] . '000' . $o );
2108
+			foreach ($questions as $question_id) {
2109
+				update_post_meta($question_id, '_quiz_question_order'.$quiz_data['quiz_id'], $quiz_data['quiz_id'].'000'.$o);
2110 2110
 				++$o;
2111 2111
 			}
2112
-			update_post_meta( $quiz_data['quiz_id'], '_question_order', $questions );
2112
+			update_post_meta($quiz_data['quiz_id'], '_question_order', $questions);
2113 2113
 		}
2114 2114
 		die();
2115 2115
 	}
2116 2116
 
2117 2117
 	public function lesson_update_question_order_random() {
2118 2118
 		//Add nonce security to the request
2119
-		if ( isset($_POST['lesson_update_question_order_random_nonce']) ) {
2120
-			$nonce = esc_html( $_POST['lesson_update_question_order_random_nonce'] );
2119
+		if (isset($_POST['lesson_update_question_order_random_nonce'])) {
2120
+			$nonce = esc_html($_POST['lesson_update_question_order_random_nonce']);
2121 2121
 		} // End If Statement
2122
-		if ( ! wp_verify_nonce( $nonce, 'lesson_update_question_order_random_nonce' )
2123
-            || ! current_user_can( 'edit_lessons' ) ) {
2122
+		if ( ! wp_verify_nonce($nonce, 'lesson_update_question_order_random_nonce')
2123
+            || ! current_user_can('edit_lessons')) {
2124 2124
 
2125 2125
 			die('');
2126 2126
 
@@ -2129,7 +2129,7 @@  discard block
 block discarded – undo
2129 2129
 		$data = $_POST['data'];
2130 2130
 		$quiz_data = array();
2131 2131
 		parse_str($data, $quiz_data);
2132
-		update_post_meta( $quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order'] );
2132
+		update_post_meta($quiz_data['quiz_id'], '_random_question_order', $quiz_data['random_question_order']);
2133 2133
 		die();
2134 2134
 	}
2135 2135
 
@@ -2140,7 +2140,7 @@  discard block
 block discarded – undo
2140 2140
 	 * @param array $data (default: array())
2141 2141
 	 * @return integer|boolean $course_id or false
2142 2142
 	 */
2143
-	private function lesson_save_course( $data = array() ) {
2143
+	private function lesson_save_course($data = array()) {
2144 2144
 		global $current_user;
2145 2145
 		$return = false;
2146 2146
 		// Setup the course data
@@ -2149,58 +2149,58 @@  discard block
 block discarded – undo
2149 2149
 		$course_title = '';
2150 2150
 		$course_prerequisite = 0;
2151 2151
 		$course_category = 0;
2152
-		if ( isset( $data[ 'course_id' ] ) && ( 0 < absint( $data[ 'course_id' ] ) ) ) {
2153
-			$course_id = absint( $data[ 'course_id' ] );
2152
+		if (isset($data['course_id']) && (0 < absint($data['course_id']))) {
2153
+			$course_id = absint($data['course_id']);
2154 2154
 		} // End If Statement
2155
-		if ( isset( $data[ 'course_title' ] ) && ( '' != $data[ 'course_title' ] ) ) {
2156
-			$course_title = $data[ 'course_title' ];
2155
+		if (isset($data['course_title']) && ('' != $data['course_title'])) {
2156
+			$course_title = $data['course_title'];
2157 2157
 		} // End If Statement
2158 2158
 		$post_title = $course_title;
2159
-		if ( isset($data[ 'post_author' ]) ) {
2160
-			$post_author = $data[ 'post_author' ];
2159
+		if (isset($data['post_author'])) {
2160
+			$post_author = $data['post_author'];
2161 2161
 		} else {
2162 2162
 			$current_user = wp_get_current_user();
2163 2163
 			$post_author = $current_user->ID;
2164 2164
 		} // End If Statement
2165 2165
 		$post_status = 'publish';
2166 2166
 		$post_type = 'course';
2167
-		if ( isset( $data[ 'course_content' ] ) && ( '' != $data[ 'course_content' ] ) ) {
2168
-			$course_content = $data[ 'course_content' ];
2167
+		if (isset($data['course_content']) && ('' != $data['course_content'])) {
2168
+			$course_content = $data['course_content'];
2169 2169
 		} // End If Statement
2170 2170
 		$post_content = $course_content;
2171 2171
 		// Course Query Arguments
2172
-		$post_type_args = array(	'post_content' => $post_content,
2172
+		$post_type_args = array('post_content' => $post_content,
2173 2173
   		    						'post_status' => $post_status,
2174 2174
   		    						'post_title' => $post_title,
2175 2175
   		    						'post_type' => $post_type
2176 2176
   		    						);
2177 2177
   		// Only save if there is a valid title
2178
-  		if ( $post_title != '' ) {
2178
+  		if ($post_title != '') {
2179 2179
   		    // Check for prerequisite courses & product id
2180
-  		    $course_prerequisite_id = absint( $data[ 'course_prerequisite' ] );
2181
-  		    $course_woocommerce_product_id = absint( $data[ 'course_woocommerce_product' ] );
2182
-  		    $course_category_id = absint( $data[ 'course_category' ] );
2183
-  		    if ( 0 == $course_woocommerce_product_id ) { $course_woocommerce_product_id = '-'; }
2180
+  		    $course_prerequisite_id = absint($data['course_prerequisite']);
2181
+  		    $course_woocommerce_product_id = absint($data['course_woocommerce_product']);
2182
+  		    $course_category_id = absint($data['course_category']);
2183
+  		    if (0 == $course_woocommerce_product_id) { $course_woocommerce_product_id = '-'; }
2184 2184
   		    // Insert or Update the Lesson Quiz
2185
-		    if ( 0 < $course_id ) {
2186
-		    	$post_type_args[ 'ID' ] = $course_id;
2185
+		    if (0 < $course_id) {
2186
+		    	$post_type_args['ID'] = $course_id;
2187 2187
 		    	$course_id = wp_update_post($post_type_args);
2188
-		    	update_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2189
-		    	update_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2190
-		    	if ( 0 < $course_category_id ) {
2191
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2188
+		    	update_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2189
+		    	update_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2190
+		    	if (0 < $course_category_id) {
2191
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2192 2192
 		    	} // End If Statement
2193 2193
 		    } else {
2194 2194
 		    	$course_id = wp_insert_post($post_type_args);
2195
-		    	add_post_meta( $course_id, '_course_prerequisite', $course_prerequisite_id );
2196
-		    	add_post_meta( $course_id, '_course_woocommerce_product', $course_woocommerce_product_id );
2197
-		    	if ( 0 < $course_category_id ) {
2198
-		    		wp_set_object_terms( $course_id, $course_category_id, 'course-category' );
2195
+		    	add_post_meta($course_id, '_course_prerequisite', $course_prerequisite_id);
2196
+		    	add_post_meta($course_id, '_course_woocommerce_product', $course_woocommerce_product_id);
2197
+		    	if (0 < $course_category_id) {
2198
+		    		wp_set_object_terms($course_id, $course_category_id, 'course-category');
2199 2199
 		    	} // End If Statement
2200 2200
 		    } // End If Statement
2201 2201
 		} // End If Statement
2202 2202
   		// Check that the insert or update saved by testing the post id
2203
-  		if ( 0 < $course_id ) {
2203
+  		if (0 < $course_id) {
2204 2204
   			$return = $course_id;
2205 2205
   		} // End If Statement
2206 2206
   		return $return;
@@ -2214,7 +2214,7 @@  discard block
 block discarded – undo
2214 2214
 	 * @param array $data (default: array())
2215 2215
 	 * @return integer|boolean $question_id or false
2216 2216
 	 */
2217
-	public function lesson_save_question( $data = array(), $context = 'quiz' ) {
2217
+	public function lesson_save_question($data = array(), $context = 'quiz') {
2218 2218
 		$return = false;
2219 2219
 		// Save the Questions
2220 2220
 		// Setup the Question data
@@ -2226,130 +2226,130 @@  discard block
 block discarded – undo
2226 2226
 		$question_category = '';
2227 2227
 
2228 2228
 		// Handle Question Type
2229
-		if ( isset( $data[ 'question_type' ] ) && ( '' != $data[ 'question_type' ] ) ) {
2230
-			$question_type = $data[ 'question_type' ];
2229
+		if (isset($data['question_type']) && ('' != $data['question_type'])) {
2230
+			$question_type = $data['question_type'];
2231 2231
 		} // End If Statement
2232 2232
 
2233
-		if ( isset( $data[ 'question_category' ] ) && ( '' != $data[ 'question_category' ] ) ) {
2234
-			$question_category = $data[ 'question_category' ];
2233
+		if (isset($data['question_category']) && ('' != $data['question_category'])) {
2234
+			$question_category = $data['question_category'];
2235 2235
 		} // End If Statement
2236 2236
 
2237
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2238
-			$question_id = absint( $data[ 'question_id' ] );
2237
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2238
+			$question_id = absint($data['question_id']);
2239 2239
 		} // End If Statement
2240
-		if ( isset( $data[ 'question' ] ) && ( '' != $data[ 'question' ] ) ) {
2241
-			$question_text = $data[ 'question' ];
2240
+		if (isset($data['question']) && ('' != $data['question'])) {
2241
+			$question_text = $data['question'];
2242 2242
 		} // End If Statement
2243 2243
 		$post_title = $question_text;
2244 2244
 		// Handle Default Fields (multiple choice)
2245
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answers' ] ) && ( '' != $data[ 'question_right_answers' ] ) ) {
2246
-			$question_right_answers = $data[ 'question_right_answers' ];
2245
+		if ('multiple-choice' == $question_type && isset($data['question_right_answers']) && ('' != $data['question_right_answers'])) {
2246
+			$question_right_answers = $data['question_right_answers'];
2247 2247
 		} // End If Statement
2248
-		elseif ( 'multiple-choice' == $question_type && isset( $data[ 'question_right_answer' ] ) && ( '' != $data[ 'question_right_answer' ] ) ) {
2249
-			$question_right_answer = $data[ 'question_right_answer' ];
2248
+		elseif ('multiple-choice' == $question_type && isset($data['question_right_answer']) && ('' != $data['question_right_answer'])) {
2249
+			$question_right_answer = $data['question_right_answer'];
2250 2250
 		} // End If Statement
2251
-		if ( 'multiple-choice' == $question_type && isset( $data[ 'question_wrong_answers' ] ) && ( '' != $data[ 'question_wrong_answers' ] ) ) {
2252
-			$question_wrong_answers = $data[ 'question_wrong_answers' ];
2251
+		if ('multiple-choice' == $question_type && isset($data['question_wrong_answers']) && ('' != $data['question_wrong_answers'])) {
2252
+			$question_wrong_answers = $data['question_wrong_answers'];
2253 2253
 		} // End If Statement
2254 2254
 		// Handle Boolean Fields - Edit
2255
-		if ( 'boolean' == $question_type && isset( $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) && ( '' != $data[ 'question_' . $question_id . '_right_answer_boolean' ] ) ) {
2256
-			$question_right_answer = $data[ 'question_' . $question_id . '_right_answer_boolean' ];
2255
+		if ('boolean' == $question_type && isset($data['question_'.$question_id.'_right_answer_boolean']) && ('' != $data['question_'.$question_id.'_right_answer_boolean'])) {
2256
+			$question_right_answer = $data['question_'.$question_id.'_right_answer_boolean'];
2257 2257
 		} // End If Statement
2258 2258
 		// Handle Boolean Fields - Add
2259
-		if ( 'boolean' == $question_type && isset( $data[ 'question_right_answer_boolean' ] ) && ( '' != $data[ 'question_right_answer_boolean' ] ) ) {
2260
-			$question_right_answer = $data[ 'question_right_answer_boolean' ];
2259
+		if ('boolean' == $question_type && isset($data['question_right_answer_boolean']) && ('' != $data['question_right_answer_boolean'])) {
2260
+			$question_right_answer = $data['question_right_answer_boolean'];
2261 2261
 		} // End If Statement
2262 2262
 		// Handle Gap Fill Fields
2263
-		if ( 'gap-fill' == $question_type && isset( $data[ 'add_question_right_answer_gapfill_gap' ] ) && '' != $data[ 'add_question_right_answer_gapfill_gap' ] ) {
2264
-			$question_right_answer = $data[ 'add_question_right_answer_gapfill_pre' ] . '||' . $data[ 'add_question_right_answer_gapfill_gap' ] . '||' . $data[ 'add_question_right_answer_gapfill_post' ];
2263
+		if ('gap-fill' == $question_type && isset($data['add_question_right_answer_gapfill_gap']) && '' != $data['add_question_right_answer_gapfill_gap']) {
2264
+			$question_right_answer = $data['add_question_right_answer_gapfill_pre'].'||'.$data['add_question_right_answer_gapfill_gap'].'||'.$data['add_question_right_answer_gapfill_post'];
2265 2265
 		} // End If Statement
2266 2266
 		// Handle Multi Line Fields
2267
-		if ( 'multi-line' == $question_type && isset( $data[ 'add_question_right_answer_multiline' ] ) && ( '' != $data[ 'add_question_right_answer_multiline' ] ) ) {
2268
-			$question_right_answer = $data[ 'add_question_right_answer_multiline' ];
2267
+		if ('multi-line' == $question_type && isset($data['add_question_right_answer_multiline']) && ('' != $data['add_question_right_answer_multiline'])) {
2268
+			$question_right_answer = $data['add_question_right_answer_multiline'];
2269 2269
 		} // End If Statement
2270 2270
 		// Handle Single Line Fields
2271
-		if ( 'single-line' == $question_type && isset( $data[ 'add_question_right_answer_singleline' ] ) && ( '' != $data[ 'add_question_right_answer_singleline' ] ) ) {
2272
-			$question_right_answer = $data[ 'add_question_right_answer_singleline' ];
2271
+		if ('single-line' == $question_type && isset($data['add_question_right_answer_singleline']) && ('' != $data['add_question_right_answer_singleline'])) {
2272
+			$question_right_answer = $data['add_question_right_answer_singleline'];
2273 2273
 		} // End If Statement
2274 2274
 		// Handle File Upload Fields
2275
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_right_answer_fileupload' ] ) && ( '' != $data[ 'add_question_right_answer_fileupload' ] ) ) {
2276
-			$question_right_answer = $data[ 'add_question_right_answer_fileupload' ];
2275
+		if ('file-upload' == $question_type && isset($data['add_question_right_answer_fileupload']) && ('' != $data['add_question_right_answer_fileupload'])) {
2276
+			$question_right_answer = $data['add_question_right_answer_fileupload'];
2277 2277
 		} // End If Statement
2278
-		if ( 'file-upload' == $question_type && isset( $data[ 'add_question_wrong_answer_fileupload' ] ) && ( '' != $data[ 'add_question_wrong_answer_fileupload' ] ) ) {
2279
-			$question_wrong_answers = array( $data[ 'add_question_wrong_answer_fileupload' ] );
2278
+		if ('file-upload' == $question_type && isset($data['add_question_wrong_answer_fileupload']) && ('' != $data['add_question_wrong_answer_fileupload'])) {
2279
+			$question_wrong_answers = array($data['add_question_wrong_answer_fileupload']);
2280 2280
 		} // End If Statement
2281 2281
 
2282 2282
 		// Handle Question Grade
2283
-		if ( isset( $data[ 'question_grade' ] ) && ( '' != $data[ 'question_grade' ] ) ) {
2284
-			$question_grade = $data[ 'question_grade' ];
2283
+		if (isset($data['question_grade']) && ('' != $data['question_grade'])) {
2284
+			$question_grade = $data['question_grade'];
2285 2285
 		} // End If Statement
2286 2286
 
2287 2287
 		// Handle Answer Feedback
2288 2288
 		$answer_feedback = '';
2289
-		if ( isset( $data[ 'answer_feedback_boolean' ] ) && !empty( $data[ 'answer_feedback_boolean' ] ) ) {
2289
+		if (isset($data['answer_feedback_boolean']) && ! empty($data['answer_feedback_boolean'])) {
2290 2290
 
2291
-            $answer_feedback = $data[ 'answer_feedback_boolean' ];
2291
+            $answer_feedback = $data['answer_feedback_boolean'];
2292 2292
 
2293
-		}elseif( isset( $data[ 'answer_feedback_multiple_choice' ] ) && !empty( $data[ 'answer_feedback_multiple_choice' ] ) ){
2293
+		}elseif (isset($data['answer_feedback_multiple_choice']) && ! empty($data['answer_feedback_multiple_choice'])) {
2294 2294
 
2295
-            $answer_feedback = $data[ 'answer_feedback_multiple_choice' ];
2295
+            $answer_feedback = $data['answer_feedback_multiple_choice'];
2296 2296
 
2297
-        }elseif( isset( $data[ 'answer_feedback' ] )  ){
2297
+        }elseif (isset($data['answer_feedback'])) {
2298 2298
 
2299
-            $answer_feedback = $data[ 'answer_feedback' ];
2299
+            $answer_feedback = $data['answer_feedback'];
2300 2300
 
2301 2301
         } // End If Statement
2302 2302
 
2303 2303
 		$post_title = $question_text;
2304
-		$post_author = $data[ 'post_author' ];
2304
+		$post_author = $data['post_author'];
2305 2305
 		$post_status = 'publish';
2306 2306
 		$post_type = 'question';
2307 2307
 		// Handle the extended question text
2308
-		if ( isset( $data[ 'question_description' ] ) && ( '' != $data[ 'question_description' ] ) ) {
2309
-			$post_content = $data[ 'question_description' ];
2308
+		if (isset($data['question_description']) && ('' != $data['question_description'])) {
2309
+			$post_content = $data['question_description'];
2310 2310
 		}
2311 2311
 		else {
2312 2312
 			$post_content = '';
2313 2313
 		}
2314 2314
 		// Question Query Arguments
2315
-		$post_type_args = array(	'post_content' => $post_content,
2315
+		$post_type_args = array('post_content' => $post_content,
2316 2316
   		    						'post_status' => $post_status,
2317 2317
   		    						'post_title' => $post_title,
2318 2318
   		    						'post_type' => $post_type
2319 2319
   		    						);
2320 2320
 
2321 2321
   		// Remove empty values and reindex the array
2322
-  		if ( is_array( $question_right_answers ) && 0 < count($question_right_answers) ) {
2323
-  			$question_right_answers_array = array_values( array_filter( $question_right_answers, 'strlen' ) );
2322
+  		if (is_array($question_right_answers) && 0 < count($question_right_answers)) {
2323
+  			$question_right_answers_array = array_values(array_filter($question_right_answers, 'strlen'));
2324 2324
   			$question_right_answers = array();
2325 2325
 
2326
-  			foreach( $question_right_answers_array as $answer ) {
2327
-  				if( ! in_array( $answer, $question_right_answers ) ) {
2326
+  			foreach ($question_right_answers_array as $answer) {
2327
+  				if ( ! in_array($answer, $question_right_answers)) {
2328 2328
   					$question_right_answers[] = $answer;
2329 2329
   				}
2330 2330
   			}
2331
-  			if ( 0 < count($question_right_answers) ) {
2331
+  			if (0 < count($question_right_answers)) {
2332 2332
   				$question_right_answer = $question_right_answers;
2333 2333
   			}
2334 2334
   		} // End If Statement
2335
-  		$right_answer_count = count( $question_right_answer );
2335
+  		$right_answer_count = count($question_right_answer);
2336 2336
 
2337 2337
 		// Remove empty values and reindex the array
2338
-  		if ( is_array( $question_wrong_answers ) ) {
2339
-  			$question_wrong_answers_array = array_values( array_filter( $question_wrong_answers, 'strlen' ) );
2338
+  		if (is_array($question_wrong_answers)) {
2339
+  			$question_wrong_answers_array = array_values(array_filter($question_wrong_answers, 'strlen'));
2340 2340
   			$question_wrong_answers = array();
2341 2341
   		} // End If Statement
2342 2342
 
2343
-  		foreach( $question_wrong_answers_array as $answer ) {
2344
-  			if( ! in_array( $answer, $question_wrong_answers ) ) {
2343
+  		foreach ($question_wrong_answers_array as $answer) {
2344
+  			if ( ! in_array($answer, $question_wrong_answers)) {
2345 2345
   				$question_wrong_answers[] = $answer;
2346 2346
   			}
2347 2347
   		}
2348 2348
 
2349
-  		$wrong_answer_count = count( $question_wrong_answers );
2349
+  		$wrong_answer_count = count($question_wrong_answers);
2350 2350
 
2351 2351
   		// Only save if there is a valid title
2352
-  		if ( $post_title != '' ) {
2352
+  		if ($post_title != '') {
2353 2353
 
2354 2354
   			// Get Quiz ID for the question
2355 2355
   		    $quiz_id = $data['quiz_id'];
@@ -2359,86 +2359,86 @@  discard block
 block discarded – undo
2359 2359
 
2360 2360
   		    // Get answer order
2361 2361
   		    $answer_order = '';
2362
-  		    if( isset( $data['answer_order'] ) ) {
2362
+  		    if (isset($data['answer_order'])) {
2363 2363
 				$answer_order = $data['answer_order'];
2364 2364
 			}
2365 2365
 
2366 2366
 			// Get random order selection
2367 2367
 			$random_order = 'no';
2368
-			if( isset( $data['random_order'] ) ) {
2368
+			if (isset($data['random_order'])) {
2369 2369
 				$random_order = $data['random_order'];
2370 2370
 			}
2371 2371
 
2372 2372
   		    // Insert or Update the question
2373
-  		    if ( 0 < $question_id ) {
2373
+  		    if (0 < $question_id) {
2374 2374
 
2375
-  		    	$post_type_args[ 'ID' ] = $question_id;
2376
-		    	$question_id = wp_update_post( $post_type_args );
2375
+  		    	$post_type_args['ID'] = $question_id;
2376
+		    	$question_id = wp_update_post($post_type_args);
2377 2377
 
2378 2378
 		    	// Update poast meta
2379
-		    	if( 'quiz' == $context ) {
2380
-		    		$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2381
-		    		if( ! in_array( $quiz_id, $quizzes ) ) {
2382
-			    		add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2379
+		    	if ('quiz' == $context) {
2380
+		    		$quizzes = get_post_meta($question_id, '_quiz_id', false);
2381
+		    		if ( ! in_array($quiz_id, $quizzes)) {
2382
+			    		add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2383 2383
 			    	}
2384 2384
 		    	}
2385 2385
 
2386
-		    	update_post_meta( $question_id, '_question_grade', $question_grade );
2387
-		    	update_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2388
-		    	update_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2389
-		    	update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2390
-		    	update_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2391
-		    	update_post_meta( $question_id, '_question_media', $question_media );
2392
-		    	update_post_meta( $question_id, '_answer_order', $answer_order );
2393
-		    	update_post_meta( $question_id, '_random_order', $random_order );
2394
-
2395
-		    	if( 'quiz' != $context ) {
2396
-		    		wp_set_post_terms( $question_id, array( $question_type ), 'question-type', false );
2386
+		    	update_post_meta($question_id, '_question_grade', $question_grade);
2387
+		    	update_post_meta($question_id, '_question_right_answer', $question_right_answer);
2388
+		    	update_post_meta($question_id, '_right_answer_count', $right_answer_count);
2389
+		    	update_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2390
+		    	update_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2391
+		    	update_post_meta($question_id, '_question_media', $question_media);
2392
+		    	update_post_meta($question_id, '_answer_order', $answer_order);
2393
+		    	update_post_meta($question_id, '_random_order', $random_order);
2394
+
2395
+		    	if ('quiz' != $context) {
2396
+		    		wp_set_post_terms($question_id, array($question_type), 'question-type', false);
2397 2397
 		    	}
2398 2398
 				// Don't store empty value, no point
2399
-				if ( !empty($answer_feedback) ) {
2400
-					update_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2399
+				if ( ! empty($answer_feedback)) {
2400
+					update_post_meta($question_id, '_answer_feedback', $answer_feedback);
2401 2401
 				}
2402 2402
 
2403 2403
 		    } else {
2404
-				$question_id = wp_insert_post( $post_type_args );
2405
-				$question_count = intval( $data['question_count'] );
2404
+				$question_id = wp_insert_post($post_type_args);
2405
+				$question_count = intval($data['question_count']);
2406 2406
 				++$question_count;
2407 2407
 
2408 2408
 				// Set post meta
2409
-				if( 'quiz' == $context ) {
2410
-					add_post_meta( $question_id, '_quiz_id', $quiz_id, false );
2411
-					$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
2412
-					update_post_meta( $lesson_id, '_quiz_has_questions', '1' );
2409
+				if ('quiz' == $context) {
2410
+					add_post_meta($question_id, '_quiz_id', $quiz_id, false);
2411
+					$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
2412
+					update_post_meta($lesson_id, '_quiz_has_questions', '1');
2413 2413
 				}
2414 2414
 
2415
-				if( isset( $question_grade ) ) {
2416
-		    		add_post_meta( $question_id, '_question_grade', $question_grade );
2415
+				if (isset($question_grade)) {
2416
+		    		add_post_meta($question_id, '_question_grade', $question_grade);
2417 2417
 		    	}
2418
-		    	add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
2419
-		    	add_post_meta( $question_id, '_right_answer_count', $right_answer_count );
2420
-		    	add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
2421
-		    	add_post_meta( $question_id, '_wrong_answer_count', $wrong_answer_count );
2422
-		    	add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );
2423
-		    	add_post_meta( $question_id, '_question_media', $question_media );
2424
-		    	add_post_meta( $question_id, '_answer_order', $answer_order );
2425
-		    	add_post_meta( $question_id, '_random_order', $random_order );
2418
+		    	add_post_meta($question_id, '_question_right_answer', $question_right_answer);
2419
+		    	add_post_meta($question_id, '_right_answer_count', $right_answer_count);
2420
+		    	add_post_meta($question_id, '_question_wrong_answers', $question_wrong_answers);
2421
+		    	add_post_meta($question_id, '_wrong_answer_count', $wrong_answer_count);
2422
+		    	add_post_meta($question_id, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$question_count);
2423
+		    	add_post_meta($question_id, '_question_media', $question_media);
2424
+		    	add_post_meta($question_id, '_answer_order', $answer_order);
2425
+		    	add_post_meta($question_id, '_random_order', $random_order);
2426 2426
 				// Don't store empty value, no point
2427
-				if ( !empty($answer_feedback) ) {
2428
-					add_post_meta( $question_id, '_answer_feedback', $answer_feedback );
2427
+				if ( ! empty($answer_feedback)) {
2428
+					add_post_meta($question_id, '_answer_feedback', $answer_feedback);
2429 2429
 				}
2430 2430
 
2431 2431
 		    	// Set the post terms for question-type
2432
-			    wp_set_post_terms( $question_id, array( $question_type ), 'question-type' );
2432
+			    wp_set_post_terms($question_id, array($question_type), 'question-type');
2433 2433
 
2434
-			    if( $question_category ) {
2435
-	    			wp_set_post_terms( $question_id, array( $question_category ), 'question-category' );
2434
+			    if ($question_category) {
2435
+	    			wp_set_post_terms($question_id, array($question_category), 'question-category');
2436 2436
 	    		}
2437 2437
 
2438 2438
 		    } // End If Statement
2439 2439
 		} // End If Statement
2440 2440
   		// Check that the insert or update saved by testing the post id
2441
-  		if ( 0 < $question_id ) {
2441
+  		if (0 < $question_id) {
2442 2442
   			$return = $question_id;
2443 2443
   		} // End If Statement
2444 2444
   		return $return;
@@ -2452,20 +2452,20 @@  discard block
 block discarded – undo
2452 2452
 	 * @param array $data (default: array())
2453 2453
 	 * @return boolean
2454 2454
 	 */
2455
-	private function lesson_delete_question( $data = array() ) {
2455
+	private function lesson_delete_question($data = array()) {
2456 2456
 
2457 2457
 		// Get which question to delete
2458 2458
 		$question_id = 0;
2459
-		if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
2460
-			$question_id = absint( $data[ 'question_id' ] );
2459
+		if (isset($data['question_id']) && (0 < absint($data['question_id']))) {
2460
+			$question_id = absint($data['question_id']);
2461 2461
 		} // End If Statement
2462 2462
 		// Delete the question
2463
-		if ( 0 < $question_id ) {
2464
-			$quizzes = get_post_meta( $question_id, '_quiz_id', false );
2463
+		if (0 < $question_id) {
2464
+			$quizzes = get_post_meta($question_id, '_quiz_id', false);
2465 2465
 
2466
-			foreach( $quizzes as $quiz_id ) {
2467
-				if( $quiz_id == $data['quiz_id'] ) {
2468
-					delete_post_meta( $question_id, '_quiz_id', $quiz_id );
2466
+			foreach ($quizzes as $quiz_id) {
2467
+				if ($quiz_id == $data['quiz_id']) {
2468
+					delete_post_meta($question_id, '_quiz_id', $quiz_id);
2469 2469
 				}
2470 2470
 			}
2471 2471
 
@@ -2484,9 +2484,9 @@  discard block
 block discarded – undo
2484 2484
 	public function lesson_complexities() {
2485 2485
 
2486 2486
 		// V2 - make filter for this array
2487
-        $lesson_complexities = array( 	'easy' => __( 'Easy', 'woothemes-sensei' ),
2488
-									'std' => __( 'Standard', 'woothemes-sensei' ),
2489
-									'hard' => __( 'Hard', 'woothemes-sensei' )
2487
+        $lesson_complexities = array('easy' => __('Easy', 'woothemes-sensei'),
2488
+									'std' => __('Standard', 'woothemes-sensei'),
2489
+									'hard' => __('Hard', 'woothemes-sensei')
2490 2490
 									);
2491 2491
 
2492 2492
 		return $lesson_complexities;
@@ -2501,9 +2501,9 @@  discard block
 block discarded – undo
2501 2501
 	 * @param string $post_status (default: 'publish')
2502 2502
 	 * @return int
2503 2503
 	 */
2504
-	public function lesson_count( $post_status = 'publish', $course_id = false ) {
2504
+	public function lesson_count($post_status = 'publish', $course_id = false) {
2505 2505
 
2506
-		$post_args = array(	'post_type'         => 'lesson',
2506
+		$post_args = array('post_type'         => 'lesson',
2507 2507
 							'posts_per_page'    => -1,
2508 2508
 //							'orderby'           => 'menu_order date',
2509 2509
 //							'order'             => 'ASC',
@@ -2511,7 +2511,7 @@  discard block
 block discarded – undo
2511 2511
 							'suppress_filters'  => 0,
2512 2512
 							'fields'            => 'ids',
2513 2513
 							);
2514
-		if( $course_id ) {
2514
+		if ($course_id) {
2515 2515
 			$post_args['meta_query'][] = array(
2516 2516
 				'key' => '_lesson_course',
2517 2517
 				'value' => $course_id,
@@ -2528,10 +2528,10 @@  discard block
 block discarded – undo
2528 2528
 
2529 2529
 		// Allow WP to generate the complex final query, just shortcut to only do an overall count
2530 2530
 //		add_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2531
-		$lessons_query = new WP_Query( apply_filters( 'sensei_lesson_count', $post_args ) );
2531
+		$lessons_query = new WP_Query(apply_filters('sensei_lesson_count', $post_args));
2532 2532
 //		remove_filter( 'posts_clauses', array( 'WooThemes_Sensei_Utils', 'get_posts_count_only_filter' ) );
2533 2533
 
2534
-		return count( $lessons_query->posts );
2534
+		return count($lessons_query->posts);
2535 2535
 	} // End lesson_count()
2536 2536
 
2537 2537
 
@@ -2544,11 +2544,11 @@  discard block
 block discarded – undo
2544 2544
 	 * @param string $fields (default: 'ids')
2545 2545
 	 * @return int $quiz_id
2546 2546
 	 */
2547
-	public function lesson_quizzes( $lesson_id = 0, $post_status = 'any', $fields = 'ids' ) {
2547
+	public function lesson_quizzes($lesson_id = 0, $post_status = 'any', $fields = 'ids') {
2548 2548
 
2549 2549
 		$posts_array = array();
2550 2550
 
2551
-		$post_args = array(	'post_type' 		=> 'quiz',
2551
+		$post_args = array('post_type' 		=> 'quiz',
2552 2552
 							'posts_per_page' 		=> 1,
2553 2553
 							'orderby'         	=> 'title',
2554 2554
     						'order'           	=> 'DESC',
@@ -2557,7 +2557,7 @@  discard block
 block discarded – undo
2557 2557
 							'suppress_filters' 	=> 0,
2558 2558
 							'fields'            => $fields
2559 2559
 							);
2560
-		$posts_array = get_posts( $post_args );
2560
+		$posts_array = get_posts($post_args);
2561 2561
         $quiz_id = array_shift($posts_array);
2562 2562
 
2563 2563
 		return $quiz_id;
@@ -2580,37 +2580,37 @@  discard block
 block discarded – undo
2580 2580
      *
2581 2581
 	 * @return array $questions { $question type WP_Post }
2582 2582
 	 */
2583
-	public function lesson_quiz_questions( $quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC' ) {
2583
+	public function lesson_quiz_questions($quiz_id = 0, $post_status = 'any', $orderby = 'meta_value_num title', $order = 'ASC') {
2584 2584
 
2585 2585
 		$quiz_id = (string) $quiz_id;
2586
-        $quiz_lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id );
2586
+        $quiz_lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
2587 2587
 
2588 2588
         // setup the user id
2589
-        if( is_admin() ) {
2590
-            $user_id = isset( $_GET['user'] ) ? $_GET['user'] : '' ;
2589
+        if (is_admin()) {
2590
+            $user_id = isset($_GET['user']) ? $_GET['user'] : '';
2591 2591
         } else {
2592 2592
             $user_id = get_current_user_id();
2593 2593
         }
2594 2594
 
2595 2595
         // get the users current status on the lesson
2596
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $user_id );
2596
+        $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $user_id);
2597 2597
 
2598 2598
 		// Set the default question order if it has not already been set for this quiz
2599
-		$this->set_default_question_order( $quiz_id );
2599
+		$this->set_default_question_order($quiz_id);
2600 2600
 
2601 2601
 		// If viewing quiz on the frontend then show questions in random order if set
2602
-		if ( ! is_admin() ) {
2603
-			$random_order = get_post_meta( $quiz_id, '_random_question_order', true );
2604
-			if( $random_order && $random_order == 'yes' ) {
2602
+		if ( ! is_admin()) {
2603
+			$random_order = get_post_meta($quiz_id, '_random_question_order', true);
2604
+			if ($random_order && $random_order == 'yes') {
2605 2605
 				$orderby = 'rand';
2606 2606
 			}
2607 2607
 		}
2608 2608
 
2609 2609
 		// Get all questions and multiple questions
2610 2610
 		$question_query_args = array(
2611
-			'post_type' 		=> array( 'question', 'multiple_question' ),
2611
+			'post_type' 		=> array('question', 'multiple_question'),
2612 2612
 			'posts_per_page' 	=> -1,
2613
-			'meta_key'        	=> '_quiz_question_order' . $quiz_id,
2613
+			'meta_key'        	=> '_quiz_question_order'.$quiz_id,
2614 2614
 			'orderby'         	=> $orderby,
2615 2615
 			'order'           	=> $order,
2616 2616
 			'meta_query'		=> array(
@@ -2624,7 +2624,7 @@  discard block
 block discarded – undo
2624 2624
 		);
2625 2625
 
2626 2626
         //query the questions
2627
-		$questions_query = new WP_Query( $question_query_args );
2627
+		$questions_query = new WP_Query($question_query_args);
2628 2628
 
2629 2629
         // Set return array to initially include all items
2630 2630
         $questions = $questions_query->posts;
@@ -2634,20 +2634,20 @@  discard block
 block discarded – undo
2634 2634
 
2635 2635
 		// If viewing quiz on frontend or in grading then only single questions must be shown
2636 2636
 		$selected_questions = false;
2637
-		if( ! is_admin() || ( is_admin() && isset( $_GET['page'] ) && 'sensei_grading' == $_GET['page'] && isset( $_GET['user'] ) && isset( $_GET['quiz_id'] ) ) ) {
2637
+		if ( ! is_admin() || (is_admin() && isset($_GET['page']) && 'sensei_grading' == $_GET['page'] && isset($_GET['user']) && isset($_GET['quiz_id']))) {
2638 2638
 
2639 2639
 			// Fetch the questions that the user was asked in their quiz if they have already completed it
2640
-			$questions_asked_string = !empty( $user_lesson_status->comment_ID) ? get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true ) : false;
2641
-			if( !empty($questions_asked_string) ) {
2640
+			$questions_asked_string = ! empty($user_lesson_status->comment_ID) ? get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true) : false;
2641
+			if ( ! empty($questions_asked_string)) {
2642 2642
 
2643
-				$selected_questions = explode( ',', $questions_asked_string );
2643
+				$selected_questions = explode(',', $questions_asked_string);
2644 2644
 
2645 2645
 				// Fetch each question in the order in which they were asked
2646 2646
 				$questions = array();
2647
-				foreach( $selected_questions as $question_id ) {
2648
-					if( ! $question_id ) continue;
2649
-					$question = get_post( $question_id );
2650
-					if( ! isset( $question ) || ! isset( $question->ID ) ) continue;
2647
+				foreach ($selected_questions as $question_id) {
2648
+					if ( ! $question_id) continue;
2649
+					$question = get_post($question_id);
2650
+					if ( ! isset($question) || ! isset($question->ID)) continue;
2651 2651
 					$questions[] = $question;
2652 2652
 				}
2653 2653
 
@@ -2659,24 +2659,24 @@  discard block
 block discarded – undo
2659 2659
 				$existing_questions = array();
2660 2660
 
2661 2661
 				// Set array of questions that already exist so we can prevent duplicates from appearing
2662
-				foreach( $questions_array as $question ) {
2663
-					if( 'question' != $question->post_type ) continue;
2662
+				foreach ($questions_array as $question) {
2663
+					if ('question' != $question->post_type) continue;
2664 2664
 					$existing_questions[] = $question->ID;
2665 2665
 				}
2666 2666
 
2667 2667
 				// Include only single questions in the return array
2668 2668
 				$questions_loop = $questions_array;
2669 2669
 				$questions_array = array();
2670
-				foreach( $questions_loop as $k => $question ) {
2670
+				foreach ($questions_loop as $k => $question) {
2671 2671
 
2672 2672
 					// If this is a single question then include it
2673
-					if( 'question' == $question->post_type ) {
2673
+					if ('question' == $question->post_type) {
2674 2674
 						$questions_array[] = $question;
2675 2675
 					} else {
2676 2676
 
2677 2677
 						// If this is a multiple question then get the specified amount of questions from the specified category
2678
-						$question_cat = intval( get_post_meta( $question->ID, 'category', true ) );
2679
-						$question_number = intval( get_post_meta( $question->ID, 'number', true ) );
2678
+						$question_cat = intval(get_post_meta($question->ID, 'category', true));
2679
+						$question_number = intval(get_post_meta($question->ID, 'number', true));
2680 2680
 
2681 2681
 						$qargs = array(
2682 2682
 							'post_type' 		=> 'question',
@@ -2693,14 +2693,14 @@  discard block
 block discarded – undo
2693 2693
 							'suppress_filters' 	=> 0,
2694 2694
 							'post__not_in'		=> $existing_questions,
2695 2695
 						);
2696
-						$cat_questions = get_posts( $qargs );
2696
+						$cat_questions = get_posts($qargs);
2697 2697
 
2698 2698
 						// Merge results into return array
2699
-						$questions_array = array_merge( $questions_array, $cat_questions );
2699
+						$questions_array = array_merge($questions_array, $cat_questions);
2700 2700
 
2701 2701
 						// Add selected questions to existing questions array to prevent duplicates from being added
2702
-						foreach( $questions_array as $cat_question ) {
2703
-							if( in_array( $cat_question->ID, $existing_questions ) ) continue;
2702
+						foreach ($questions_array as $cat_question) {
2703
+							if (in_array($cat_question->ID, $existing_questions)) continue;
2704 2704
 							$existing_questions[] = $cat_question->ID;
2705 2705
 						}
2706 2706
 					}
@@ -2712,29 +2712,29 @@  discard block
 block discarded – undo
2712 2712
 		}
2713 2713
 
2714 2714
 		// If user has not already taken the quiz and a limited number of questions are to be shown, then show a random selection of the specified amount of questions
2715
-		if( ! $selected_questions ) {
2715
+		if ( ! $selected_questions) {
2716 2716
 
2717 2717
 			// Only limit questions like this on the frontend
2718
-			if( ! is_admin() ) {
2718
+			if ( ! is_admin()) {
2719 2719
 
2720 2720
 				// Get number of questions to show
2721
-				$show_questions = intval( get_post_meta( $quiz_id, '_show_questions', true ) );
2722
-				if( $show_questions ) {
2721
+				$show_questions = intval(get_post_meta($quiz_id, '_show_questions', true));
2722
+				if ($show_questions) {
2723 2723
 
2724 2724
 					// Get random set of array keys from selected questions array
2725
-					$selected_questions = array_rand( $questions_array, $show_questions );
2725
+					$selected_questions = array_rand($questions_array, $show_questions);
2726 2726
 
2727 2727
 					// Loop through all questions and pick the the ones to be shown based on the random key selection
2728 2728
 					$questions = array();
2729
-					foreach( $questions_array as $k => $question ) {
2729
+					foreach ($questions_array as $k => $question) {
2730 2730
 
2731 2731
 						// Random keys will always be an array, unless only one question is to be shown
2732
-						if( is_array( $selected_questions ) ) {
2733
-							if( in_array( $k, $selected_questions ) ) {
2732
+						if (is_array($selected_questions)) {
2733
+							if (in_array($k, $selected_questions)) {
2734 2734
 								$questions[] = $question;
2735 2735
 							}
2736
-						} elseif( 1 == $show_questions ) {
2737
-							if ( $selected_questions == $k ) {
2736
+						} elseif (1 == $show_questions) {
2737
+							if ($selected_questions == $k) {
2738 2738
 								$questions[] = $question;
2739 2739
 							}
2740 2740
 						}
@@ -2745,12 +2745,12 @@  discard block
 block discarded – undo
2745 2745
 
2746 2746
         // Save the questions that will be asked for the current user
2747 2747
         // this happens only once per user/quiz, unless the user resets the quiz
2748
-        if( ! is_admin() ){
2748
+        if ( ! is_admin()) {
2749 2749
 
2750
-            if( $user_lesson_status ) {
2750
+            if ($user_lesson_status) {
2751 2751
 
2752 2752
                 $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
2753
-                if ( empty($questions_asked) && $user_lesson_status) {
2753
+                if (empty($questions_asked) && $user_lesson_status) {
2754 2754
 
2755 2755
                     $questions_asked = array();
2756 2756
                     foreach ($questions as $question) {
@@ -2773,7 +2773,7 @@  discard block
 block discarded – undo
2773 2773
          * @hooked Sensei_Teacher::allow_teacher_access_to_questions
2774 2774
          * @since 1.8.0
2775 2775
          */
2776
-		return apply_filters( 'sensei_lesson_quiz_questions', $questions,  $quiz_id  );
2776
+		return apply_filters('sensei_lesson_quiz_questions', $questions, $quiz_id);
2777 2777
 
2778 2778
 	} // End lesson_quiz_questions()
2779 2779
 
@@ -2781,13 +2781,13 @@  discard block
 block discarded – undo
2781 2781
 	 * Set the default quiz order
2782 2782
 	 * @param integer $quiz_id ID of quiz
2783 2783
 	 */
2784
-	public function set_default_question_order( $quiz_id = 0 ) {
2784
+	public function set_default_question_order($quiz_id = 0) {
2785 2785
 
2786
-		if( $quiz_id ) {
2786
+		if ($quiz_id) {
2787 2787
 
2788
-			$question_order = get_post_meta( $quiz_id, '_question_order', true );
2788
+			$question_order = get_post_meta($quiz_id, '_question_order', true);
2789 2789
 
2790
-			if( ! $question_order ) {
2790
+			if ( ! $question_order) {
2791 2791
 
2792 2792
 				$args = array(
2793 2793
 					'post_type' 		=> 'question',
@@ -2803,11 +2803,11 @@  discard block
 block discarded – undo
2803 2803
 					'post_status'		=> 'any',
2804 2804
 					'suppress_filters' 	=> 0
2805 2805
 				);
2806
-				$questions = get_posts( $args );
2806
+				$questions = get_posts($args);
2807 2807
 
2808 2808
 				$o = 1;
2809
-				foreach( $questions as $question ) {
2810
-					add_post_meta( $question->ID, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $o, true );
2809
+				foreach ($questions as $question) {
2810
+					add_post_meta($question->ID, '_quiz_question_order'.$quiz_id, $quiz_id.'000'.$o, true);
2811 2811
 					$o++;
2812 2812
 				}
2813 2813
 			}
@@ -2826,36 +2826,36 @@  discard block
 block discarded – undo
2826 2826
 	 * @param string $height (default: '100')
2827 2827
 	 * @return string
2828 2828
 	 */
2829
-	public function lesson_image( $lesson_id = 0, $width = '100', $height = '100', $widget = false ) {
2829
+	public function lesson_image($lesson_id = 0, $width = '100', $height = '100', $widget = false) {
2830 2830
 
2831 2831
 		$html = '';
2832 2832
 
2833 2833
 		// Get Width and Height settings
2834
-		if ( ( $width == '100' ) && ( $height == '100' ) ) {
2834
+		if (($width == '100') && ($height == '100')) {
2835 2835
 
2836
-			if ( is_singular( 'lesson' ) ) {
2836
+			if (is_singular('lesson')) {
2837 2837
 
2838
-				if ( ! $widget && ! Sensei()->settings->settings[ 'lesson_single_image_enable' ] ) {
2838
+				if ( ! $widget && ! Sensei()->settings->settings['lesson_single_image_enable']) {
2839 2839
 
2840 2840
 					return '';
2841 2841
 
2842 2842
 				} // End If Statement
2843 2843
 
2844 2844
 				$image_thumb_size = 'lesson_single_image';
2845
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2845
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2846 2846
 				$width = $dimensions['width'];
2847 2847
 				$height = $dimensions['height'];
2848 2848
 				$crop = $dimensions['crop'];
2849 2849
 
2850 2850
 			} else {
2851 2851
 
2852
-				if ( ! $widget && ! Sensei()->settings->settings[ 'course_lesson_image_enable' ] ) {
2852
+				if ( ! $widget && ! Sensei()->settings->settings['course_lesson_image_enable']) {
2853 2853
 
2854 2854
 					return '';
2855 2855
 				} // End If Statement
2856 2856
 
2857 2857
 				$image_thumb_size = 'lesson_archive_image';
2858
-				$dimensions = Sensei()->get_image_size( $image_thumb_size );
2858
+				$dimensions = Sensei()->get_image_size($image_thumb_size);
2859 2859
 				$width = $dimensions['width'];
2860 2860
 				$height = $dimensions['height'];
2861 2861
 				$crop = $dimensions['crop'];
@@ -2866,23 +2866,23 @@  discard block
 block discarded – undo
2866 2866
 
2867 2867
 		$img_url = '';
2868 2868
 
2869
-		if ( has_post_thumbnail( $lesson_id ) ) {
2869
+		if (has_post_thumbnail($lesson_id)) {
2870 2870
 
2871 2871
    			// Get Featured Image
2872
-   			$img_url = get_the_post_thumbnail( $lesson_id, array( $width, $height ), array( 'class' => 'woo-image thumbnail alignleft') );
2872
+   			$img_url = get_the_post_thumbnail($lesson_id, array($width, $height), array('class' => 'woo-image thumbnail alignleft'));
2873 2873
 
2874 2874
  		} else {
2875 2875
 
2876 2876
  			// Display Image Placeholder if none
2877
-			if ( Sensei()->settings->settings[ 'placeholder_images_enable' ] ) {
2877
+			if (Sensei()->settings->settings['placeholder_images_enable']) {
2878 2878
 
2879
-                $img_url = apply_filters( 'sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' );
2879
+                $img_url = apply_filters('sensei_lesson_placeholder_image_url', '<img src="http://placehold.it/'.$width.'x'.$height.'" class="woo-image thumbnail alignleft" />');
2880 2880
 
2881 2881
 			} // End If Statement
2882 2882
 
2883 2883
 		} // End If Statement
2884 2884
 
2885
-		$html .= '<a href="' . get_permalink( $lesson_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $lesson_id ) ) . '">' . $img_url . '</a>';
2885
+		$html .= '<a href="'.get_permalink($lesson_id).'" title="'.esc_attr(get_post_field('post_title', $lesson_id)).'">'.$img_url.'</a>';
2886 2886
 
2887 2887
 		return $html;
2888 2888
 
@@ -2894,9 +2894,9 @@  discard block
 block discarded – undo
2894 2894
      * @since 1.9.0
2895 2895
      * @param integer $lesson_id
2896 2896
      */
2897
-    public static function the_lesson_image( $lesson_id = 0 ){
2897
+    public static function the_lesson_image($lesson_id = 0) {
2898 2898
 
2899
-        echo Sensei()->lesson->lesson_image( $lesson_id );
2899
+        echo Sensei()->lesson->lesson_image($lesson_id);
2900 2900
 
2901 2901
     }
2902 2902
 
@@ -2907,17 +2907,17 @@  discard block
 block discarded – undo
2907 2907
      * @param bool $add_p_tags should the excerpt be wrapped by calling wpautop()
2908 2908
 	 * @return string
2909 2909
 	 */
2910
-	public static function lesson_excerpt( $lesson = null, $add_p_tags = true ) {
2910
+	public static function lesson_excerpt($lesson = null, $add_p_tags = true) {
2911 2911
 		$html = '';
2912
-		if ( is_a( $lesson, 'WP_Post' ) && 'lesson' == $lesson->post_type ) {
2912
+		if (is_a($lesson, 'WP_Post') && 'lesson' == $lesson->post_type) {
2913 2913
 
2914
-            $excerpt =  $lesson->post_excerpt;
2914
+            $excerpt = $lesson->post_excerpt;
2915 2915
 
2916 2916
             // if $add_p_tags true wrap with <p> else return the excerpt as is
2917
-            $html =  $add_p_tags ? wpautop( $excerpt ) : $excerpt;
2917
+            $html = $add_p_tags ? wpautop($excerpt) : $excerpt;
2918 2918
 
2919 2919
 		}
2920
-		return apply_filters( 'sensei_lesson_excerpt', $html );
2920
+		return apply_filters('sensei_lesson_excerpt', $html);
2921 2921
 
2922 2922
 	} // End lesson_excerpt()
2923 2923
 
@@ -2930,20 +2930,20 @@  discard block
 block discarded – undo
2930 2930
      * @param int $lesson_id
2931 2931
      * @return int|bool $course_id or bool when nothing is found.
2932 2932
      */
2933
-     public function get_course_id( $lesson_id ){
2933
+     public function get_course_id($lesson_id) {
2934 2934
 
2935
-         if( ! isset( $lesson_id ) || empty( $lesson_id )
2936
-         ||  'lesson' != get_post_type( $lesson_id ) ){
2935
+         if ( ! isset($lesson_id) || empty($lesson_id)
2936
+         ||  'lesson' != get_post_type($lesson_id)) {
2937 2937
              return false;
2938 2938
          }
2939 2939
 
2940
-         $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true);
2940
+         $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
2941 2941
 
2942 2942
          // make sure the course id is valid
2943
-         if( empty( $lesson_course_id )
2944
-             || is_array( $lesson_course_id )
2945
-             || intval( $lesson_course_id ) < 1
2946
-             || 'course' != get_post_type( $lesson_course_id ) ){
2943
+         if (empty($lesson_course_id)
2944
+             || is_array($lesson_course_id)
2945
+             || intval($lesson_course_id) < 1
2946
+             || 'course' != get_post_type($lesson_course_id)) {
2947 2947
 
2948 2948
              return false;
2949 2949
 
@@ -2970,11 +2970,11 @@  discard block
 block discarded – undo
2970 2970
      * @param string $post_type
2971 2971
      * @return void
2972 2972
      */
2973
-    public function all_lessons_edit_fields( $column_name, $post_type ) {
2973
+    public function all_lessons_edit_fields($column_name, $post_type) {
2974 2974
 
2975 2975
         // only show these options ont he lesson post type edit screen
2976
-        if( 'lesson' != $post_type || 'lesson-course' != $column_name
2977
-            || ! current_user_can( 'edit_lessons' ) ) {
2976
+        if ('lesson' != $post_type || 'lesson-course' != $column_name
2977
+            || ! current_user_can('edit_lessons')) {
2978 2978
             return;
2979 2979
         }
2980 2980
 
@@ -2982,41 +2982,41 @@  discard block
 block discarded – undo
2982 2982
         <fieldset class="sensei-edit-field-set inline-edit-lesson">
2983 2983
             <div class="sensei-inline-edit-col column-<?php echo $column_name ?>">
2984 2984
                     <?php
2985
-                    echo '<h4>' . __('Lesson Information', 'woothemes-sensei') . '</h4>';
2985
+                    echo '<h4>'.__('Lesson Information', 'woothemes-sensei').'</h4>';
2986 2986
                     // create a nonce field to be  used as a security measure when saving the data
2987
-                    wp_nonce_field( 'bulk-edit-lessons', '_edit_lessons_nonce' );
2988
-                    wp_nonce_field( 'sensei-save-post-meta','woo_' . $this->token . '_nonce'  );
2987
+                    wp_nonce_field('bulk-edit-lessons', '_edit_lessons_nonce');
2988
+                    wp_nonce_field('sensei-save-post-meta', 'woo_'.$this->token.'_nonce');
2989 2989
 
2990 2990
                     // unchanged option - we need this in because
2991 2991
                     // the default option in bulk edit should not be empty. If it is
2992 2992
                     // the user will erase data they didn't want to touch.
2993
-                    $no_change_text = '-- ' . __('No Change', 'woothemes-sensei') . ' --';
2993
+                    $no_change_text = '-- '.__('No Change', 'woothemes-sensei').' --';
2994 2994
 
2995 2995
                     //
2996 2996
                     //course selection
2997 2997
                     //
2998
-                    $courses =  WooThemes_Sensei_Course::get_all_courses();
2998
+                    $courses = WooThemes_Sensei_Course::get_all_courses();
2999 2999
                     $course_options = array();
3000
-                    if ( count( $courses ) > 0 ) {
3001
-                        foreach ($courses as $course ){
3002
-                            $course_options[ $course->ID ] = get_the_title( $course->ID );
3000
+                    if (count($courses) > 0) {
3001
+                        foreach ($courses as $course) {
3002
+                            $course_options[$course->ID] = get_the_title($course->ID);
3003 3003
                         }
3004 3004
                     }
3005 3005
                     //pre-append the no change option
3006
-                    $course_options['-1']=  $no_change_text;
3007
-                    $course_attributes = array( 'name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course' , 'class'=>' ' );
3008
-                    $course_field =  Sensei_Utils::generate_drop_down( '-1', $course_options, $course_attributes );
3009
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Course', 'woothemes-sensei'),   $course_field  );
3006
+                    $course_options['-1'] = $no_change_text;
3007
+                    $course_attributes = array('name'=> 'lesson_course', 'id'=>'sensei-edit-lesson-course', 'class'=>' ');
3008
+                    $course_field = Sensei_Utils::generate_drop_down('-1', $course_options, $course_attributes);
3009
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Course', 'woothemes-sensei'), $course_field);
3010 3010
 
3011 3011
                     //
3012 3012
                     // lesson complexity selection
3013 3013
                     //
3014
-                    $lesson_complexities =  $this->lesson_complexities();
3014
+                    $lesson_complexities = $this->lesson_complexities();
3015 3015
                     //pre-append the no change option
3016
-                    $lesson_complexities['-1']=  $no_change_text;
3017
-                    $complexity_dropdown_attributes = array( 'name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity' , 'class'=>' ');
3018
-                    $complexity_filed =  Sensei_Utils::generate_drop_down( '-1', $lesson_complexities, $complexity_dropdown_attributes );
3019
-                    echo $this->generate_all_lessons_edit_field( __('Lesson Complexity', 'woothemes-sensei'),   $complexity_filed  );
3016
+                    $lesson_complexities['-1'] = $no_change_text;
3017
+                    $complexity_dropdown_attributes = array('name'=> 'lesson_complexity', 'id'=>'sensei-edit-lesson-complexity', 'class'=>' ');
3018
+                    $complexity_filed = Sensei_Utils::generate_drop_down('-1', $lesson_complexities, $complexity_dropdown_attributes);
3019
+                    echo $this->generate_all_lessons_edit_field(__('Lesson Complexity', 'woothemes-sensei'), $complexity_filed);
3020 3020
 
3021 3021
                     ?>
3022 3022
 
@@ -3029,34 +3029,34 @@  discard block
 block discarded – undo
3029 3029
                     //
3030 3030
                     $pass_required_options = array(
3031 3031
                         '-1' => $no_change_text,
3032
-                         '0' => __('No','woothemes'),
3033
-                         '1' => __('Yes','woothemes'),
3032
+                         '0' => __('No', 'woothemes'),
3033
+                         '1' => __('Yes', 'woothemes'),
3034 3034
                     );
3035 3035
 
3036
-                    $pass_required_select_attributes = array( 'name'=> 'pass_required',
3036
+                    $pass_required_select_attributes = array('name'=> 'pass_required',
3037 3037
                                                                 'id'=> 'sensei-edit-lesson-pass-required',
3038
-                                                                'class'=>' '   );
3039
-                    $require_pass_field =  Sensei_Utils::generate_drop_down( '-1', $pass_required_options, $pass_required_select_attributes, false );
3040
-                    echo $this->generate_all_lessons_edit_field( __('Pass required', 'woothemes-sensei'),   $require_pass_field  );
3038
+                                                                'class'=>' ');
3039
+                    $require_pass_field = Sensei_Utils::generate_drop_down('-1', $pass_required_options, $pass_required_select_attributes, false);
3040
+                    echo $this->generate_all_lessons_edit_field(__('Pass required', 'woothemes-sensei'), $require_pass_field);
3041 3041
 
3042 3042
                     //
3043 3043
                     // Quiz pass percentage
3044 3044
                     //
3045 3045
                     $quiz_pass_percentage_field = '<input name="quiz_passmark" id="sensei-edit-quiz-pass-percentage" type="number" />';
3046
-                    echo $this->generate_all_lessons_edit_field( __('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field  );
3046
+                    echo $this->generate_all_lessons_edit_field(__('Pass Percentage', 'woothemes-sensei'), $quiz_pass_percentage_field);
3047 3047
 
3048 3048
                     //
3049 3049
                     // Enable quiz reset button
3050 3050
                     //
3051 3051
                     $quiz_reset_select__options = array(
3052 3052
                         '-1' => $no_change_text,
3053
-                        '0' => __('No','woothemes'),
3054
-                        '1' => __('Yes','woothemes'),
3053
+                        '0' => __('No', 'woothemes'),
3054
+                        '1' => __('Yes', 'woothemes'),
3055 3055
                     );
3056 3056
                     $quiz_reset_name_id = 'sensei-edit-enable-quiz-reset';
3057
-                    $quiz_reset_select_attributes = array( 'name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ' );
3058
-                    $quiz_reset_field =  Sensei_Utils::generate_drop_down( '-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false );
3059
-                    echo $this->generate_all_lessons_edit_field( __('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field  );
3057
+                    $quiz_reset_select_attributes = array('name'=> 'enable_quiz_reset', 'id'=>$quiz_reset_name_id, 'class'=>' ');
3058
+                    $quiz_reset_field = Sensei_Utils::generate_drop_down('-1', $quiz_reset_select__options, $quiz_reset_select_attributes, false);
3059
+                    echo $this->generate_all_lessons_edit_field(__('Enable quiz reset button', 'woothemes-sensei'), $quiz_reset_field);
3060 3060
 
3061 3061
                     ?>
3062 3062
             </div>
@@ -3075,17 +3075,17 @@  discard block
 block discarded – undo
3075 3075
      * @param string $field type markup for the field that must be wrapped.
3076 3076
      * @return string $field_html
3077 3077
      */
3078
-    public function generate_all_lessons_edit_field( $title  ,$field ){
3078
+    public function generate_all_lessons_edit_field($title, $field) {
3079 3079
 
3080 3080
         $html = '';
3081 3081
         $html = '<div class="inline-edit-group" >';
3082
-        $html .=  '<span class="title">'. $title .'</span> ';
3082
+        $html .= '<span class="title">'.$title.'</span> ';
3083 3083
         $html .= '<span class="input-text-wrap">';
3084 3084
         $html .= $field;
3085 3085
         $html .= '</span>';
3086 3086
         $html .= '</label></div>';
3087 3087
 
3088
-        return $html ;
3088
+        return $html;
3089 3089
 
3090 3090
     }//end generate_all_lessons_edit_field
3091 3091
 
@@ -3099,48 +3099,48 @@  discard block
 block discarded – undo
3099 3099
     function save_all_lessons_edit_fields() {
3100 3100
 
3101 3101
         // verify all the data before attempting to save
3102
-        if( ! isset( $_POST['security'] ) || ! check_ajax_referer( 'bulk-edit-lessons', 'security' )
3103
-            ||  empty( $_POST[ 'post_ids' ] )  || ! is_array( $_POST[ 'post_ids' ] ) ) {
3102
+        if ( ! isset($_POST['security']) || ! check_ajax_referer('bulk-edit-lessons', 'security')
3103
+            ||  empty($_POST['post_ids']) || ! is_array($_POST['post_ids'])) {
3104 3104
             die();
3105 3105
         }
3106 3106
 
3107 3107
         // get our variables
3108
-        $new_course = sanitize_text_field(  $_POST['sensei_edit_lesson_course'] );
3109
-        $new_complexity = sanitize_text_field(  $_POST['sensei_edit_complexity'] );
3110
-        $new_pass_required = sanitize_text_field(  $_POST['sensei_edit_pass_required'] );
3111
-        $new_pass_percentage = sanitize_text_field(  $_POST['sensei_edit_pass_percentage'] );
3112
-        $new_enable_quiz_reset = sanitize_text_field(  $_POST['sensei_edit_enable_quiz_reset'] );
3108
+        $new_course = sanitize_text_field($_POST['sensei_edit_lesson_course']);
3109
+        $new_complexity = sanitize_text_field($_POST['sensei_edit_complexity']);
3110
+        $new_pass_required = sanitize_text_field($_POST['sensei_edit_pass_required']);
3111
+        $new_pass_percentage = sanitize_text_field($_POST['sensei_edit_pass_percentage']);
3112
+        $new_enable_quiz_reset = sanitize_text_field($_POST['sensei_edit_enable_quiz_reset']);
3113 3113
         // store the values for all selected posts
3114
-        foreach( $_POST[ 'post_ids' ] as $lesson_id ) {
3114
+        foreach ($_POST['post_ids'] as $lesson_id) {
3115 3115
 
3116 3116
             // get the quiz id needed for the quiz meta
3117
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
3117
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
3118 3118
 
3119 3119
             // do not save the items if the value is -1 as this
3120 3120
             // means it was not changed
3121 3121
 
3122 3122
             // update lesson course
3123
-            if( -1 != $new_course ){
3124
-                update_post_meta( $lesson_id, '_lesson_course', $new_course );
3123
+            if ( -1 != $new_course ) {
3124
+                update_post_meta($lesson_id, '_lesson_course', $new_course);
3125 3125
             }
3126 3126
             // update lesson complexity
3127
-            if( -1 != $new_complexity ){
3128
-                update_post_meta( $lesson_id, '_lesson_complexity', $new_complexity );
3127
+            if ( -1 != $new_complexity ) {
3128
+                update_post_meta($lesson_id, '_lesson_complexity', $new_complexity);
3129 3129
             }
3130 3130
 
3131 3131
             // Quiz Related settings
3132
-            if( isset( $quiz_id) && 0 < intval( $quiz_id ) ) {
3132
+            if (isset($quiz_id) && 0 < intval($quiz_id)) {
3133 3133
 
3134 3134
                 // update pass required
3135 3135
                 if (-1 != $new_pass_required) {
3136 3136
 
3137
-                    $checked = $new_pass_required  ? 'on' : '';
3137
+                    $checked = $new_pass_required ? 'on' : '';
3138 3138
                     update_post_meta($quiz_id, '_pass_required', $checked);
3139
-                    unset( $checked );
3139
+                    unset($checked);
3140 3140
                 }
3141 3141
 
3142 3142
                 // update pass percentage
3143
-                if( !empty( $new_pass_percentage) && is_numeric( $new_pass_percentage ) ){
3143
+                if ( ! empty($new_pass_percentage) && is_numeric($new_pass_percentage)) {
3144 3144
 
3145 3145
                         update_post_meta($quiz_id, '_quiz_passmark', $new_pass_percentage);
3146 3146
 
@@ -3151,9 +3151,9 @@  discard block
 block discarded – undo
3151 3151
                 //
3152 3152
                 if (-1 != $new_enable_quiz_reset ) {
3153 3153
 
3154
-                    $checked = $new_enable_quiz_reset ? 'on' : ''  ;
3154
+                    $checked = $new_enable_quiz_reset ? 'on' : '';
3155 3155
                     update_post_meta($quiz_id, '_enable_quiz_reset', $checked);
3156
-                    unset( $checked );
3156
+                    unset($checked);
3157 3157
 
3158 3158
                 }
3159 3159
 
@@ -3177,31 +3177,31 @@  discard block
 block discarded – undo
3177 3177
      * @since 1.8.0
3178 3178
      * @return void
3179 3179
      */
3180
-    public function set_quick_edit_admin_defaults( $column_name, $post_id ){
3180
+    public function set_quick_edit_admin_defaults($column_name, $post_id) {
3181 3181
 
3182
-        if( 'lesson-course' != $column_name ){
3182
+        if ('lesson-course' != $column_name) {
3183 3183
             return;
3184 3184
         }
3185 3185
         // load the script
3186
-        $suffix = defined( 'SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
-        wp_enqueue_script( 'sensei-lesson-quick-edit', Sensei()->plugin_url . 'assets/js/admin/lesson-quick-edit' . $suffix . '.js', array( 'jquery' ), Sensei()->version, true );
3186
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
3187
+        wp_enqueue_script('sensei-lesson-quick-edit', Sensei()->plugin_url.'assets/js/admin/lesson-quick-edit'.$suffix.'.js', array('jquery'), Sensei()->version, true);
3188 3188
 
3189 3189
         // setup the values for all meta fields
3190 3190
         $data = array();
3191
-        foreach( $this->meta_fields as $field ){
3191
+        foreach ($this->meta_fields as $field) {
3192 3192
 
3193
-            $data[$field] =  get_post_meta( $post_id, '_'.$field, true );
3193
+            $data[$field] = get_post_meta($post_id, '_'.$field, true);
3194 3194
 
3195 3195
         }
3196 3196
         // add quiz meta fields
3197
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $post_id );
3198
-        foreach( Sensei()->quiz->meta_fields as $field ){
3197
+        $quiz_id = Sensei()->lesson->lesson_quizzes($post_id);
3198
+        foreach (Sensei()->quiz->meta_fields as $field) {
3199 3199
 
3200
-            $data[$field] =  get_post_meta( $quiz_id, '_'.$field, true );
3200
+            $data[$field] = get_post_meta($quiz_id, '_'.$field, true);
3201 3201
 
3202 3202
         }
3203 3203
 
3204
-        wp_localize_script( 'sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data );
3204
+        wp_localize_script('sensei-lesson-quick-edit', 'sensei_quick_edit_'.$post_id, $data);
3205 3205
 
3206 3206
     }// end quick edit admin defaults
3207 3207
 
@@ -3214,19 +3214,19 @@  discard block
 block discarded – undo
3214 3214
      * @param array $classes
3215 3215
      * @return array $classes
3216 3216
      */
3217
-    public static function single_course_lessons_classes( $classes ){
3217
+    public static function single_course_lessons_classes($classes) {
3218 3218
 
3219
-        if(  is_singular('course') ){
3219
+        if (is_singular('course')) {
3220 3220
 
3221 3221
             global $post;
3222 3222
             $course_id = $post->ID;
3223 3223
 
3224
-            $lesson_classes = array( 'course', 'post' );
3225
-            if ( is_user_logged_in() ) {
3224
+            $lesson_classes = array('course', 'post');
3225
+            if (is_user_logged_in()) {
3226 3226
 
3227 3227
                 // Check if Lesson is complete
3228
-                $single_lesson_complete = Sensei_Utils::user_completed_lesson( get_the_ID(), get_current_user_id() );
3229
-                if ( $single_lesson_complete ) {
3228
+                $single_lesson_complete = Sensei_Utils::user_completed_lesson(get_the_ID(), get_current_user_id());
3229
+                if ($single_lesson_complete) {
3230 3230
 
3231 3231
                     $lesson_classes[] = 'lesson-completed';
3232 3232
 
@@ -3234,14 +3234,14 @@  discard block
 block discarded – undo
3234 3234
 
3235 3235
             } // End If Statement
3236 3236
 
3237
-            $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3238
-            if (  Sensei_Utils::is_preview_lesson( get_the_ID() ) && !$is_user_taking_course ) {
3237
+            $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3238
+            if (Sensei_Utils::is_preview_lesson(get_the_ID()) && ! $is_user_taking_course) {
3239 3239
 
3240 3240
                 $lesson_classes[] = 'lesson-preview';
3241 3241
 
3242 3242
             }
3243 3243
 
3244
-            $classes = array_merge( $classes, $lesson_classes  );
3244
+            $classes = array_merge($classes, $lesson_classes);
3245 3245
 
3246 3246
         }
3247 3247
 
@@ -3255,56 +3255,56 @@  discard block
 block discarded – undo
3255 3255
      * @since 1.9.0
3256 3256
      * @param $lesson_id
3257 3257
      */
3258
-    public static function the_lesson_meta( $lesson_id ){
3258
+    public static function the_lesson_meta($lesson_id) {
3259 3259
 
3260 3260
         global $wp_query;
3261 3261
         $loop_lesson_number = $wp_query->current_post + 1;
3262 3262
 
3263
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
3263
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
3264 3264
         $single_lesson_complete = false;
3265
-        $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() );
3265
+        $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id());
3266 3266
 
3267 3267
         // Get Lesson data
3268 3268
         $complexity_array = Sensei()->lesson->lesson_complexities();
3269 3269
 
3270
-        $lesson_complexity = get_post_meta( $lesson_id, '_lesson_complexity', true );
3271
-        if ( '' != $lesson_complexity ) {
3270
+        $lesson_complexity = get_post_meta($lesson_id, '_lesson_complexity', true);
3271
+        if ('' != $lesson_complexity) {
3272 3272
 
3273 3273
             $lesson_complexity = $complexity_array[$lesson_complexity];
3274 3274
 
3275 3275
         }
3276
-        $user_info = get_userdata( absint( get_post()->post_author ) );
3277
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id);
3276
+        $user_info = get_userdata(absint(get_post()->post_author));
3277
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3278 3278
         $preview_label = '';
3279
-        if ( $is_preview && !$is_user_taking_course ) {
3279
+        if ($is_preview && ! $is_user_taking_course) {
3280 3280
 
3281
-            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text( $lesson_id);
3282
-            $preview_label = '<span class="preview-heading">' . $preview_label . '</span>';
3281
+            $preview_label = Sensei()->frontend->sensei_lesson_preview_title_text($lesson_id);
3282
+            $preview_label = '<span class="preview-heading">'.$preview_label.'</span>';
3283 3283
 
3284 3284
         }
3285 3285
 
3286 3286
 
3287
-        $count_markup= '';
3287
+        $count_markup = '';
3288 3288
         /**
3289 3289
          * Filter for if you want the $lesson_count to show next to the lesson.
3290 3290
          *
3291 3291
          * @since 1.0
3292 3292
          * @param bool default false.
3293 3293
          */
3294
-        if( apply_filters( 'sensei_show_lesson_numbers', false ) ) {
3294
+        if (apply_filters('sensei_show_lesson_numbers', false)) {
3295 3295
 
3296
-            $count_markup =  '<span class="lesson-number">' . $loop_lesson_number. '</span>';
3296
+            $count_markup = '<span class="lesson-number">'.$loop_lesson_number.'</span>';
3297 3297
 
3298 3298
         }
3299 3299
 
3300
-        $heading_link_title = sprintf( __( 'Start %s', 'woothemes-sensei' ), get_the_title( $lesson_id ) );
3300
+        $heading_link_title = sprintf(__('Start %s', 'woothemes-sensei'), get_the_title($lesson_id));
3301 3301
 
3302 3302
         ?>
3303 3303
         <header>
3304 3304
             <h2>
3305
-                <a href="<?php echo esc_url_raw( get_permalink( $lesson_id ) ) ?>"
3306
-                   title="<?php esc_attr_e( $heading_link_title ) ?>" >
3307
-                    <?php echo $count_markup. get_the_title( $lesson_id ) . $preview_label; ?>
3305
+                <a href="<?php echo esc_url_raw(get_permalink($lesson_id)) ?>"
3306
+                   title="<?php esc_attr_e($heading_link_title) ?>" >
3307
+                    <?php echo $count_markup.get_the_title($lesson_id).$preview_label; ?>
3308 3308
                 </a>
3309 3309
             </h2>
3310 3310
 
@@ -3313,33 +3313,33 @@  discard block
 block discarded – undo
3313 3313
                 <?php
3314 3314
 
3315 3315
                 $meta_html = '';
3316
-                $user_lesson_status = Sensei_Utils::user_lesson_status( get_the_ID(), get_current_user_id() );
3316
+                $user_lesson_status = Sensei_Utils::user_lesson_status(get_the_ID(), get_current_user_id());
3317 3317
 
3318
-                $lesson_length = get_post_meta( $lesson_id, '_lesson_length', true );
3319
-                if ( '' != $lesson_length ) {
3318
+                $lesson_length = get_post_meta($lesson_id, '_lesson_length', true);
3319
+                if ('' != $lesson_length) {
3320 3320
 
3321
-                    $meta_html .= '<span class="lesson-length">' .  __( 'Length: ', 'woothemes-sensei' ) . $lesson_length . __( ' minutes', 'woothemes-sensei' ) . '</span>';
3321
+                    $meta_html .= '<span class="lesson-length">'.__('Length: ', 'woothemes-sensei').$lesson_length.__(' minutes', 'woothemes-sensei').'</span>';
3322 3322
 
3323 3323
                 }
3324 3324
 
3325
-                if ( Sensei()->settings->get( 'lesson_author' ) ) {
3325
+                if (Sensei()->settings->get('lesson_author')) {
3326 3326
 
3327
-                    $meta_html .= '<span class="lesson-author">' .  __( 'Author: ', 'woothemes-sensei' ) . '<a href="' . get_author_posts_url( absint( get_post()->post_author ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>';
3327
+                    $meta_html .= '<span class="lesson-author">'.__('Author: ', 'woothemes-sensei').'<a href="'.get_author_posts_url(absint(get_post()->post_author)).'" title="'.esc_attr($user_info->display_name).'">'.esc_html($user_info->display_name).'</a></span>';
3328 3328
 
3329 3329
                 } // End If Statement
3330
-                if ( '' != $lesson_complexity ) {
3330
+                if ('' != $lesson_complexity) {
3331 3331
 
3332
-                    $meta_html .= '<span class="lesson-complexity">' .  __( 'Complexity: ', 'woothemes-sensei' ) . $lesson_complexity .'</span>';
3332
+                    $meta_html .= '<span class="lesson-complexity">'.__('Complexity: ', 'woothemes-sensei').$lesson_complexity.'</span>';
3333 3333
 
3334 3334
                 }
3335 3335
 
3336
-                if ( $single_lesson_complete ) {
3336
+                if ($single_lesson_complete) {
3337 3337
 
3338
-                    $meta_html .= '<span class="lesson-status complete">' .__( 'Complete', 'woothemes-sensei' ) .'</span>';
3338
+                    $meta_html .= '<span class="lesson-status complete">'.__('Complete', 'woothemes-sensei').'</span>';
3339 3339
 
3340
-                } elseif ( $user_lesson_status ) {
3340
+                } elseif ($user_lesson_status) {
3341 3341
 
3342
-                    $meta_html .= '<span class="lesson-status in-progress">' . __( 'In Progress', 'woothemes-sensei' ) .'</span>';
3342
+                    $meta_html .= '<span class="lesson-status in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
3343 3343
 
3344 3344
                 } // End If Statement
3345 3345
 
@@ -3362,19 +3362,19 @@  discard block
 block discarded – undo
3362 3362
      *
3363 3363
      * @param $lesson_id
3364 3364
      */
3365
-    public static function the_lesson_thumbnail( $lesson_id ){
3365
+    public static function the_lesson_thumbnail($lesson_id) {
3366 3366
 
3367
-        if( empty( $lesson_id ) ){
3367
+        if (empty($lesson_id)) {
3368 3368
 
3369 3369
             $lesson_id = get_the_ID();
3370 3370
 
3371 3371
         }
3372 3372
 
3373
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3373
+        if ('lesson' != get_post_type($lesson_id)) {
3374 3374
             return;
3375 3375
         }
3376 3376
 
3377
-        echo Sensei()->lesson->lesson_image( $lesson_id );
3377
+        echo Sensei()->lesson->lesson_image($lesson_id);
3378 3378
     }
3379 3379
 
3380 3380
 
@@ -3385,14 +3385,14 @@  discard block
 block discarded – undo
3385 3385
      * @param string $excerpt
3386 3386
      * @return string $excerpt
3387 3387
      */
3388
-    public static function alter_the_lesson_excerpt( $excerpt ) {
3388
+    public static function alter_the_lesson_excerpt($excerpt) {
3389 3389
 
3390
-        if ('lesson' == get_post_type(get_the_ID())){
3390
+        if ('lesson' == get_post_type(get_the_ID())) {
3391 3391
 
3392 3392
             // remove this hooks to avoid an infinite loop.
3393
-            remove_filter( 'get_the_excerpt', array( 'WooThemes_Sensei_Lesson','alter_the_lesson_excerpt') );
3393
+            remove_filter('get_the_excerpt', array('WooThemes_Sensei_Lesson', 'alter_the_lesson_excerpt'));
3394 3394
 
3395
-            return WooThemes_Sensei_Lesson::lesson_excerpt( get_post( get_the_ID() ) );
3395
+            return WooThemes_Sensei_Lesson::lesson_excerpt(get_post(get_the_ID()));
3396 3396
         }
3397 3397
 
3398 3398
         return $excerpt;
@@ -3407,20 +3407,20 @@  discard block
 block discarded – undo
3407 3407
      * @param $current_lesson_id
3408 3408
      * @return mixed | bool | int $prerequisite_lesson_id or false
3409 3409
      */
3410
-    public static function get_lesson_prerequisite_id( $current_lesson_id  ){
3410
+    public static function get_lesson_prerequisite_id($current_lesson_id) {
3411 3411
 
3412
-        $prerequisite_lesson_id = get_post_meta( $current_lesson_id , '_lesson_prerequisite', true );
3412
+        $prerequisite_lesson_id = get_post_meta($current_lesson_id, '_lesson_prerequisite', true);
3413 3413
 
3414 3414
         // set ti to false if not a valid prerequisite lesson id
3415
-        if(  empty( $prerequisite_lesson_id )
3416
-            || 'lesson' != get_post_type( $prerequisite_lesson_id )
3417
-            || $prerequisite_lesson_id == $current_lesson_id  ) {
3415
+        if (empty($prerequisite_lesson_id)
3416
+            || 'lesson' != get_post_type($prerequisite_lesson_id)
3417
+            || $prerequisite_lesson_id == $current_lesson_id) {
3418 3418
 
3419 3419
             $prerequisite_lesson_id = false;
3420 3420
 
3421 3421
         }
3422 3422
 
3423
-        return apply_filters( 'sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id );
3423
+        return apply_filters('sensei_lesson_prerequisite', $prerequisite_lesson_id, $current_lesson_id);
3424 3424
 
3425 3425
     }
3426 3426
 
@@ -3435,27 +3435,27 @@  discard block
 block discarded – undo
3435 3435
      * @param $user_id
3436 3436
      * @return bool
3437 3437
      */
3438
-    public  static function is_prerequisite_complete( $lesson_id, $user_id  ){
3438
+    public  static function is_prerequisite_complete($lesson_id, $user_id) {
3439 3439
 
3440
-        if( empty( $lesson_id ) || empty( $user_id )
3441
-        || 'lesson' != get_post_type( $lesson_id )
3442
-        ||  ! is_a( get_user_by( 'id', $user_id ), 'WP_User' )){
3440
+        if (empty($lesson_id) || empty($user_id)
3441
+        || 'lesson' != get_post_type($lesson_id)
3442
+        ||  ! is_a(get_user_by('id', $user_id), 'WP_User')) {
3443 3443
 
3444 3444
             return false;
3445 3445
 
3446 3446
         }
3447 3447
 
3448
-        $pre_requisite_id = (string) self::get_lesson_prerequisite_id( $lesson_id );
3448
+        $pre_requisite_id = (string) self::get_lesson_prerequisite_id($lesson_id);
3449 3449
 
3450 3450
         // not a valid pre-requisite so pre-requisite is completed
3451
-        if( 'lesson' != get_post_type( $pre_requisite_id )
3452
-            || ! is_numeric( $pre_requisite_id ) ){
3451
+        if ('lesson' != get_post_type($pre_requisite_id)
3452
+            || ! is_numeric($pre_requisite_id)) {
3453 3453
 
3454 3454
             return true;
3455 3455
 
3456 3456
         }
3457 3457
 
3458
-        return  Sensei_Utils::user_completed_lesson( $pre_requisite_id, $user_id );
3458
+        return  Sensei_Utils::user_completed_lesson($pre_requisite_id, $user_id);
3459 3459
 
3460 3460
     }// end is_prerequisite_complete
3461 3461
 
@@ -3464,20 +3464,20 @@  discard block
 block discarded – undo
3464 3464
      *
3465 3465
      * @since 1.9.0
3466 3466
      */
3467
-    public  static function user_not_taking_course_message(){
3467
+    public  static function user_not_taking_course_message() {
3468 3468
 
3469 3469
         $lesson_id = get_the_ID();
3470 3470
 
3471
-        if( 'lesson' != get_post_type( $lesson_id ) ){
3471
+        if ('lesson' != get_post_type($lesson_id)) {
3472 3472
             return;
3473 3473
         }
3474 3474
 
3475
-        $is_preview = Sensei_Utils::is_preview_lesson( $lesson_id );
3476
-        $pre_requisite_complete = self::is_prerequisite_complete( $lesson_id , get_current_user_id() );
3477
-        $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
3478
-        $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() );
3475
+        $is_preview = Sensei_Utils::is_preview_lesson($lesson_id);
3476
+        $pre_requisite_complete = self::is_prerequisite_complete($lesson_id, get_current_user_id());
3477
+        $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
3478
+        $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, get_current_user_id());
3479 3479
 
3480
-        if ( $pre_requisite_complete && $is_preview && !$user_taking_course ) {
3480
+        if ($pre_requisite_complete && $is_preview && ! $user_taking_course) {
3481 3481
 
3482 3482
 
3483 3483
         }// end if
@@ -3491,11 +3491,11 @@  discard block
 block discarded – undo
3491 3491
      *
3492 3492
      * @since 1.9.0
3493 3493
      */
3494
-    public static function course_signup_link( ){
3494
+    public static function course_signup_link( ) {
3495 3495
 
3496
-        $course_id =  Sensei()->lesson->get_course_id( get_the_ID() );
3496
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3497 3497
 
3498
-        if ( empty( $course_id ) || 'course' != get_post_type( $course_id ) || sensei_all_access() ) {
3498
+        if (empty($course_id) || 'course' != get_post_type($course_id) || sensei_all_access()) {
3499 3499
 
3500 3500
             return;
3501 3501
 
@@ -3508,69 +3508,69 @@  discard block
 block discarded – undo
3508 3508
             <?php
3509 3509
 
3510 3510
             global $current_user;
3511
-            $wc_post_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true );
3511
+            $wc_post_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true);
3512 3512
 
3513
-            if ( Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable( $course_id ) ) {
3513
+            if (Sensei_WC::is_woocommerce_active() && Sensei_WC::is_course_purchasable($course_id)) {
3514 3514
 
3515
-                if( is_user_logged_in() && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID )  ) {
3515
+                if (is_user_logged_in() && ! Sensei_Utils::user_started_course($course_id, $current_user->ID)) {
3516 3516
 
3517
-	                    $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3518
-	                    $a_element .= __( 'course', 'woothemes-sensei' );
3517
+	                    $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3518
+	                    $a_element .= __('course', 'woothemes-sensei');
3519 3519
 	                    $a_element .= '</a>';
3520 3520
 
3521
-	                    if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3521
+	                    if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3522 3522
 
3523
-		                    $message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3523
+		                    $message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3524 3524
 
3525
-	                    }else{
3525
+	                    } else {
3526 3526
 
3527
-		                    $message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3527
+		                    $message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3528 3528
 
3529 3529
 	                    }
3530 3530
 
3531
-	                    Sensei()->notices->add_notice( $message, 'info' );
3531
+	                    Sensei()->notices->add_notice($message, 'info');
3532 3532
 
3533 3533
                 }
3534 3534
 
3535
-	            if( ! is_user_logged_in() ) {
3535
+	            if ( ! is_user_logged_in()) {
3536 3536
 
3537
-	                $a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
3538
-	                $a_element .= __( 'course', 'woothemes-sensei' );
3537
+	                $a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
3538
+	                $a_element .= __('course', 'woothemes-sensei');
3539 3539
 	                $a_element .= '</a>';
3540 3540
 
3541
-	                if( Sensei_Utils::is_preview_lesson( get_the_ID()  ) ){
3541
+	                if (Sensei_Utils::is_preview_lesson(get_the_ID())) {
3542 3542
 
3543
-						$message = sprintf( __( 'This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3543
+						$message = sprintf(__('This is a preview lesson. Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3544 3544
 
3545
-					}else{
3545
+					} else {
3546 3546
 
3547
-						$message = sprintf( __( 'Please purchase the %1$s before starting the lesson.', 'woothemes-sensei' ), $a_element );
3547
+						$message = sprintf(__('Please purchase the %1$s before starting the lesson.', 'woothemes-sensei'), $a_element);
3548 3548
 
3549 3549
 					}
3550 3550
 
3551
-					Sensei()->notices->add_notice( $message, 'alert' );
3551
+					Sensei()->notices->add_notice($message, 'alert');
3552 3552
 
3553 3553
 	            }
3554 3554
 
3555 3555
             } else { ?>
3556 3556
 
3557
-	            <?php if( ! Sensei_Utils::user_started_course( $course_id, get_current_user_id() ) &&  sensei_is_login_required() )  : ?>
3557
+	            <?php if ( ! Sensei_Utils::user_started_course($course_id, get_current_user_id()) && sensei_is_login_required())  : ?>
3558 3558
 
3559 3559
 	                <div class="sensei-message alert">
3560 3560
 	                    <?php
3561
-	                    $course_link =  '<a href="'
3562
-	                                        . esc_url( get_permalink( $course_id ) )
3563
-	                                        . '" title="' . __( 'Sign Up', 'woothemes-sensei' )
3564
-	                                        . '">' . __( 'course', 'woothemes-sensei' )
3561
+	                    $course_link = '<a href="'
3562
+	                                        . esc_url(get_permalink($course_id))
3563
+	                                        . '" title="'.__('Sign Up', 'woothemes-sensei')
3564
+	                                        . '">'.__('course', 'woothemes-sensei')
3565 3565
 	                                    . '</a>';
3566 3566
 
3567
-						if ( Sensei_Utils::is_preview_lesson( get_the_ID( ) ) ) {
3567
+						if (Sensei_Utils::is_preview_lesson(get_the_ID( ))) {
3568 3568
 
3569
-							echo sprintf( __( 'This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ),  $course_link );
3569
+							echo sprintf(__('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei'), $course_link);
3570 3570
 
3571 3571
 						} else {
3572 3572
 
3573
-							echo sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ),  $course_link );
3573
+							echo sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link);
3574 3574
 
3575 3575
 						}
3576 3576
 
@@ -3591,14 +3591,14 @@  discard block
 block discarded – undo
3591 3591
      *
3592 3592
      * @since 1.9.0
3593 3593
      */
3594
-    public  static function prerequisite_complete_message(){
3594
+    public  static function prerequisite_complete_message() {
3595 3595
 
3596
-        $lesson_prerequisite =  WooThemes_Sensei_Lesson::get_lesson_prerequisite_id( get_the_ID() );
3596
+        $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id(get_the_ID());
3597 3597
         $lesson_has_pre_requisite = $lesson_prerequisite > 0;
3598
-        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(  get_the_ID(), get_current_user_id() ) && $lesson_has_pre_requisite ) {
3598
+        if ( ! WooThemes_Sensei_Lesson::is_prerequisite_complete(get_the_ID(), get_current_user_id()) && $lesson_has_pre_requisite) {
3599 3599
 
3600
-            $prerequisite_lesson_link  = '<a href="' . esc_url( get_permalink( $lesson_prerequisite ) ) . '" title="' . esc_attr(  sprintf( __( 'You must first complete: %1$s', 'woothemes-sensei' ), get_the_title( $lesson_prerequisite ) ) ) . '">' . get_the_title( $lesson_prerequisite ). '</a>';
3601
-            echo sprintf( __( 'You must first complete %1$s before viewing this Lesson', 'woothemes-sensei' ), $prerequisite_lesson_link );
3600
+            $prerequisite_lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite)).'" title="'.esc_attr(sprintf(__('You must first complete: %1$s', 'woothemes-sensei'), get_the_title($lesson_prerequisite))).'">'.get_the_title($lesson_prerequisite).'</a>';
3601
+            echo sprintf(__('You must first complete %1$s before viewing this Lesson', 'woothemes-sensei'), $prerequisite_lesson_link);
3602 3602
 
3603 3603
         }
3604 3604
 
@@ -3610,7 +3610,7 @@  discard block
 block discarded – undo
3610 3610
      *
3611 3611
      * @deprecated since 1.9.0
3612 3612
      */
3613
-    public static function deprecate_sensei_lesson_archive_header_hook(){
3613
+    public static function deprecate_sensei_lesson_archive_header_hook() {
3614 3614
 
3615 3615
         sensei_do_deprecated_action('sensei_lesson_archive_header', '1.9.0', 'sensei_loop_lesson_inside_before');
3616 3616
 
@@ -3626,9 +3626,9 @@  discard block
 block discarded – undo
3626 3626
 
3627 3627
         $before_html = '<header class="archive-header"><h1>';
3628 3628
         $after_html = '</h1></header>';
3629
-        $html = $before_html .  __( 'Lessons Archive', 'woothemes-sensei' ) . $after_html;
3629
+        $html = $before_html.__('Lessons Archive', 'woothemes-sensei').$after_html;
3630 3630
 
3631
-        echo apply_filters( 'sensei_lesson_archive_title', $html );
3631
+        echo apply_filters('sensei_lesson_archive_title', $html);
3632 3632
 
3633 3633
     } // sensei_course_archive_header()
3634 3634
 
@@ -3638,7 +3638,7 @@  discard block
 block discarded – undo
3638 3638
      * @global $post
3639 3639
      * @since 1.9.0
3640 3640
      */
3641
-    public static function the_title(){
3641
+    public static function the_title() {
3642 3642
 
3643 3643
         global $post;
3644 3644
 
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
                 /**
3652 3652
                  * Filter documented in class-sensei-messages.php the_title
3653 3653
                  */
3654
-                echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type );
3654
+                echo apply_filters('sensei_single_title', get_the_title($post), $post->post_type);
3655 3655
                 ?>
3656 3656
 
3657 3657
             </h1>
@@ -3669,16 +3669,16 @@  discard block
 block discarded – undo
3669 3669
      *
3670 3670
      * @param $post_id
3671 3671
      */
3672
-    public static function flush_rewrite_rules( $post_id ){
3672
+    public static function flush_rewrite_rules($post_id) {
3673 3673
 
3674
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){
3674
+        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
3675 3675
 
3676 3676
             return;
3677 3677
 
3678 3678
         }
3679 3679
 
3680 3680
 
3681
-        if( 'lesson' == get_post_type( $post_id )  ){
3681
+        if ('lesson' == get_post_type($post_id)) {
3682 3682
 
3683 3683
             Sensei()->initiate_rewrite_rules_flush();
3684 3684
 
@@ -3695,27 +3695,27 @@  discard block
 block discarded – undo
3695 3695
      * @param int $lesson_id
3696 3696
      * @param int $user_id
3697 3697
      */
3698
-    public static function footer_quiz_call_to_action( $lesson_id = 0, $user_id = 0 ) {
3698
+    public static function footer_quiz_call_to_action($lesson_id = 0, $user_id = 0) {
3699 3699
 
3700 3700
 
3701
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3702
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3701
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3702
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3703 3703
 
3704 3704
 
3705
-	    if ( ! sensei_can_user_view_lesson( $lesson_id, $user_id ) ) {
3705
+	    if ( ! sensei_can_user_view_lesson($lesson_id, $user_id)) {
3706 3706
 		    return;
3707 3707
 	    }
3708 3708
 
3709
-        $lesson_prerequisite       = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
3710
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3711
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3712
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3709
+        $lesson_prerequisite       = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
3710
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3711
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3712
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3713 3713
         $show_actions              = is_user_logged_in() ? true : false;
3714 3714
 
3715
-        if( intval( $lesson_prerequisite ) > 0 ) {
3715
+        if (intval($lesson_prerequisite) > 0) {
3716 3716
 
3717 3717
             // If the user hasn't completed the prereq then hide the current actions
3718
-            $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $user_id );
3718
+            $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $user_id);
3719 3719
 
3720 3720
         }
3721 3721
 
@@ -3724,19 +3724,19 @@  discard block
 block discarded – undo
3724 3724
         <footer>
3725 3725
 
3726 3726
             <?php
3727
-            if( $show_actions && $quiz_id && Sensei()->access_settings() ) {
3727
+            if ($show_actions && $quiz_id && Sensei()->access_settings()) {
3728 3728
 
3729
-                $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3730
-                if( $has_quiz_questions ) {
3729
+                $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3730
+                if ($has_quiz_questions) {
3731 3731
                     ?>
3732 3732
 
3733 3733
                     <p>
3734 3734
 
3735 3735
                         <a class="button"
3736
-                           href="<?php echo esc_url_raw( get_permalink( $quiz_id ) ); ?>"
3737
-                           title="<?php _e( 'View the Lesson Quiz', 'woothemes-sensei'  ); ?>">
3736
+                           href="<?php echo esc_url_raw(get_permalink($quiz_id)); ?>"
3737
+                           title="<?php _e('View the Lesson Quiz', 'woothemes-sensei'); ?>">
3738 3738
 
3739
-                            <?php  _e( 'View the Lesson Quiz', 'woothemes-sensei' ); ?>
3739
+                            <?php  _e('View the Lesson Quiz', 'woothemes-sensei'); ?>
3740 3740
 
3741 3741
                         </a>
3742 3742
 
@@ -3747,11 +3747,11 @@  discard block
 block discarded – undo
3747 3747
 
3748 3748
             } // End If Statement
3749 3749
 
3750
-            if ( $show_actions && ! $has_user_completed_lesson ) {
3750
+            if ($show_actions && ! $has_user_completed_lesson) {
3751 3751
 
3752 3752
                 sensei_complete_lesson_button();
3753 3753
 
3754
-            } elseif( $show_actions ) {
3754
+            } elseif ($show_actions) {
3755 3755
 
3756 3756
                 sensei_reset_lesson_button();
3757 3757
 
@@ -3768,20 +3768,20 @@  discard block
 block discarded – undo
3768 3768
      *
3769 3769
      * @since 1.9.0
3770 3770
      */
3771
-    public static function output_comments(){
3771
+    public static function output_comments() {
3772 3772
 
3773
-        if( ! is_user_logged_in() ){
3773
+        if ( ! is_user_logged_in()) {
3774 3774
             return;
3775 3775
         }
3776 3776
 
3777
-        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete( get_the_ID(), get_current_user_id() );
3778
-        $course_id = Sensei()->lesson->get_course_id( get_the_ID() );
3779
-        $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
3780
-        $user_taking_course = Sensei_Utils::user_started_course($course_id );
3777
+        $pre_requisite_complete = Sensei()->lesson->is_prerequisite_complete(get_the_ID(), get_current_user_id());
3778
+        $course_id = Sensei()->lesson->get_course_id(get_the_ID());
3779
+        $allow_comments = Sensei()->settings->settings['lesson_comments'];
3780
+        $user_taking_course = Sensei_Utils::user_started_course($course_id);
3781 3781
 
3782
-        $lesson_allow_comments = $allow_comments && $pre_requisite_complete  && $user_taking_course;
3782
+        $lesson_allow_comments = $allow_comments && $pre_requisite_complete && $user_taking_course;
3783 3783
 
3784
-        if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {
3784
+        if ($lesson_allow_comments || is_singular('sensei_message')) {
3785 3785
 
3786 3786
             comments_template();
3787 3787
 
@@ -3797,26 +3797,26 @@  discard block
 block discarded – undo
3797 3797
      *
3798 3798
      * @since 1.9.0
3799 3799
      */
3800
-    public static function user_lesson_quiz_status_message( $lesson_id = 0, $user_id = 0){
3800
+    public static function user_lesson_quiz_status_message($lesson_id = 0, $user_id = 0) {
3801 3801
 
3802
-        $lesson_id                 =  empty( $lesson_id ) ?  get_the_ID() : $lesson_id;
3803
-        $user_id                   = empty( $lesson_id ) ?  get_current_user_id() : $user_id;
3804
-        $lesson_course_id          = (int) get_post_meta( $lesson_id, '_lesson_course', true );
3805
-        $quiz_id                   = Sensei()->lesson->lesson_quizzes( $lesson_id );
3806
-        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson( intval( $lesson_id ), $user_id );
3802
+        $lesson_id                 = empty($lesson_id) ? get_the_ID() : $lesson_id;
3803
+        $user_id                   = empty($lesson_id) ? get_current_user_id() : $user_id;
3804
+        $lesson_course_id          = (int) get_post_meta($lesson_id, '_lesson_course', true);
3805
+        $quiz_id                   = Sensei()->lesson->lesson_quizzes($lesson_id);
3806
+        $has_user_completed_lesson = Sensei_Utils::user_completed_lesson(intval($lesson_id), $user_id);
3807 3807
 
3808 3808
 
3809
-        if ( $quiz_id && is_user_logged_in()
3810
-            && Sensei_Utils::user_started_course( $lesson_course_id, $user_id ) ) {
3809
+        if ($quiz_id && is_user_logged_in()
3810
+            && Sensei_Utils::user_started_course($lesson_course_id, $user_id)) {
3811 3811
 
3812 3812
             $no_quiz_count = 0;
3813
-            $has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
3813
+            $has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
3814 3814
 
3815 3815
             // Display lesson quiz status message
3816
-            if ( $has_user_completed_lesson || $has_quiz_questions ) {
3817
-                $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id, $user_id, true );
3818
-                echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
3819
-                if( $has_quiz_questions ) {
3816
+            if ($has_user_completed_lesson || $has_quiz_questions) {
3817
+                $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, $user_id, true);
3818
+                echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>';
3819
+                if ($has_quiz_questions) {
3820 3820
                    // echo $status['extra'];
3821 3821
                 } // End If Statement
3822 3822
             } // End If Statement
@@ -3832,11 +3832,11 @@  discard block
 block discarded – undo
3832 3832
      * @param $content
3833 3833
      * @return string
3834 3834
      */
3835
-    public static function limit_archive_content ( $content ){
3835
+    public static function limit_archive_content($content) {
3836 3836
 
3837
-        if( is_archive('lesson') && Sensei()->settings->get('access_permission') ){
3837
+        if (is_archive('lesson') && Sensei()->settings->get('access_permission')) {
3838 3838
 
3839
-            return wp_trim_words( $content, $num_words = 30, $more = '…' );
3839
+            return wp_trim_words($content, $num_words = 30, $more = '…');
3840 3840
         }
3841 3841
 
3842 3842
         return $content;
@@ -3849,9 +3849,9 @@  discard block
 block discarded – undo
3849 3849
      * @since 1.9.0
3850 3850
      * @return array
3851 3851
      */
3852
-    public static function get_all_lesson_ids(){
3852
+    public static function get_all_lesson_ids() {
3853 3853
 
3854
-        return get_posts( array(
3854
+        return get_posts(array(
3855 3855
             'post_type'=>'lesson',
3856 3856
             'fields'=>'ids',
3857 3857
             'post_status' => 'publish',
@@ -3868,4 +3868,4 @@  discard block
 block discarded – undo
3868 3868
  * @ignore only for backward compatibility
3869 3869
  * @since 1.9.0
3870 3870
  */
3871
-class WooThemes_Sensei_Lesson extends Sensei_Lesson{}
3871
+class WooThemes_Sensei_Lesson extends Sensei_Lesson {}
Please login to merge, or discard this patch.
apigen/hook-docs.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -10,44 +10,44 @@  discard block
 block discarded – undo
10 10
 	private static $pattern_custom_filters = '/apply_filters(.*?);/i';
11 11
 	private static $found_files            = array();
12 12
 	private static $custom_hooks_found     = '';
13
-    private static $sensei_directory =  '';
14
-    private static $docs_output_directory =  '';
15
-    private static $put_file =  '';
13
+    private static $sensei_directory = '';
14
+    private static $docs_output_directory = '';
15
+    private static $put_file = '';
16 16
 
17
-    public static function initialize(){
17
+    public static function initialize() {
18 18
 
19
-        self::$sensei_directory = dirname( dirname(__FILE__) );
20
-        self::$docs_output_directory = self::$sensei_directory . '/docs.woothemes.com/images/sensei-apidocs/';
21
-        self::$put_file =  self::$docs_output_directory.'/hook-docs.html';
19
+        self::$sensei_directory = dirname(dirname(__FILE__));
20
+        self::$docs_output_directory = self::$sensei_directory.'/docs.woothemes.com/images/sensei-apidocs/';
21
+        self::$put_file = self::$docs_output_directory.'/hook-docs.html';
22 22
 
23 23
     }
24 24
 
25
-	private static function get_files( $pattern, $flags = 0, $path = '' ) {
25
+	private static function get_files($pattern, $flags = 0, $path = '') {
26 26
 
27
-	    if ( ! $path && ( $dir = dirname( $pattern ) ) != '.' ) {
27
+	    if ( ! $path && ($dir = dirname($pattern)) != '.') {
28 28
 
29 29
 	        if ($dir == '\\' || $dir == '/') { $dir = ''; } // End IF Statement
30 30
 
31
-	        return self::get_files(basename( $pattern ), $flags, $dir . '/' );
31
+	        return self::get_files(basename($pattern), $flags, $dir.'/');
32 32
 
33 33
 	    } // End IF Statement
34 34
 
35
-	    $paths = glob( $path . '*', GLOB_ONLYDIR | GLOB_NOSORT );
36
-	    $files = glob( $path . $pattern, $flags );
35
+	    $paths = glob($path.'*', GLOB_ONLYDIR | GLOB_NOSORT);
36
+	    $files = glob($path.$pattern, $flags);
37 37
 
38
-	    if ( is_array( $paths ) ) {
39
-		    foreach ( $paths as $p ) {
38
+	    if (is_array($paths)) {
39
+		    foreach ($paths as $p) {
40 40
 			    $found_files = array();
41
-		   		$retrieved_files = (array) self::get_files( $pattern, $flags, $p . '/' );
42
-		   		foreach ( $retrieved_files as $file ) {
43
-			   		if ( ! in_array( $file, self::$found_files ) )
41
+		   		$retrieved_files = (array) self::get_files($pattern, $flags, $p.'/');
42
+		   		foreach ($retrieved_files as $file) {
43
+			   		if ( ! in_array($file, self::$found_files))
44 44
 			   			$found_files[] = $file;
45 45
 		   		}
46 46
 
47
-		   		self::$found_files = array_merge( self::$found_files, $found_files );
47
+		   		self::$found_files = array_merge(self::$found_files, $found_files);
48 48
 
49
-		   		if ( is_array( $files ) && is_array( $found_files ) ) {
50
-		   			$files = array_merge( $files, $found_files );
49
+		   		if (is_array($files) && is_array($found_files)) {
50
+		   			$files = array_merge($files, $found_files);
51 51
 		   		}
52 52
 
53 53
 		    } // End FOREACH Loop
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
 	    return $files;
56 56
     }
57 57
 
58
-	private static function get_hook_link( $hook, $details = array() ) {
58
+	private static function get_hook_link($hook, $details = array()) {
59 59
 		//if ( ! empty( $details['class'] ) ) {
60 60
 		//	$link = 'http://docs.woothemes.com/sensei-apidocs/source-class-' . $details['class'] . '.html#' . $details['line'];
61 61
 		//} elseif ( ! empty( $details['function'] ) ) {
62 62
 		//	$link = 'http://docs.woothemes.com/sensei-apidocs/source-function-' . $details['function'] . '.html#' . $details['line'];
63 63
 		//} else {
64
-			$link = 'https://github.com/woothemes/sensei/search?utf8=%E2%9C%93&q=' . $hook;
64
+			$link = 'https://github.com/woothemes/sensei/search?utf8=%E2%9C%93&q='.$hook;
65 65
 		//}
66 66
 
67
-		return '<a href="' . $link . '">' . $hook . '</a>';
67
+		return '<a href="'.$link.'">'.$hook.'</a>';
68 68
 	}
69 69
 
70 70
 	public static function process_hooks() {
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
         self::initialize();
73 73
 
74 74
 		// If we have one, get the PHP files from it.
75
-		$template_files 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/templates/' );
76
-		$template_files[]	= self::$sensei_directory . '/includes/template-functions.php';
77
-
78
-		$shortcode_files 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/shortcodes/' );
79
-		$widget_files	 	= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/widgets/' );
80
-		$admin_files 		= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/admin/' );
81
-		$class_files 		= self::get_files( '*.php', GLOB_MARK, self::$sensei_directory.'/includes/' );
82
-		$other_files		= array(
75
+		$template_files = self::get_files('*.php', GLOB_MARK, self::$sensei_directory.'/templates/');
76
+		$template_files[]	= self::$sensei_directory.'/includes/template-functions.php';
77
+
78
+		$shortcode_files 	= self::get_files('*.php', GLOB_MARK, self::$sensei_directory.'/includes/shortcodes/');
79
+		$widget_files = self::get_files('*.php', GLOB_MARK, self::$sensei_directory.'/widgets/');
80
+		$admin_files 		= self::get_files('*.php', GLOB_MARK, self::$sensei_directory.'/includes/admin/');
81
+		$class_files 		= self::get_files('*.php', GLOB_MARK, self::$sensei_directory.'/includes/');
82
+		$other_files = array(
83 83
             self::$sensei_directory.'/woothemes-sensei.php'
84 84
 		);
85 85
 
@@ -100,35 +100,35 @@  discard block
 block discarded – undo
100 100
 		echo '<h1>Action and Filter Hook Reference</h1>';
101 101
 		echo '<div class="description"><p>The following is a full list of actions and filters found in Sensei.</p></div>';
102 102
 
103
-		foreach ( self::$files_to_scan as $heading => $files ) {
103
+		foreach (self::$files_to_scan as $heading => $files) {
104 104
 			self::$custom_hooks_found = array();
105 105
 
106
-			foreach ( $files as $f ) {
107
-				self::$current_file = basename( $f );
106
+			foreach ($files as $f) {
107
+				self::$current_file = basename($f);
108 108
 
109
-                if ( in_array( self::$current_file, $scanned ) ) {
109
+                if (in_array(self::$current_file, $scanned)) {
110 110
                     continue;
111 111
                 }
112 112
 
113 113
                 $scanned[] = self::$current_file;
114 114
 
115
-				$tokens             = token_get_all( file_get_contents( $f ) );
115
+				$tokens             = token_get_all(file_get_contents($f));
116 116
 				$token_type         = false;
117 117
 				$current_class      = '';
118 118
 				$current_function   = '';
119 119
 
120
-				foreach ( $tokens as $index => $token ) {
121
-					if ( is_array( $token ) ) {
122
-						if ( $token[0] == T_CLASS ) {
120
+				foreach ($tokens as $index => $token) {
121
+					if (is_array($token)) {
122
+						if ($token[0] == T_CLASS) {
123 123
 							$token_type = 'class';
124
-						} elseif ( $token[0] == T_FUNCTION ) {
124
+						} elseif ($token[0] == T_FUNCTION) {
125 125
 							$token_type = 'function';
126
-						} elseif ( $token[1] === 'do_action' ) {
126
+						} elseif ($token[1] === 'do_action') {
127 127
 							$token_type = 'action';
128
-						} elseif ( $token[1] === 'apply_filters' ) {
128
+						} elseif ($token[1] === 'apply_filters') {
129 129
 							$token_type = 'filter';
130
-						} elseif ( $token_type && ! empty( trim( $token[1] ) ) ) {
131
-							switch ( $token_type ) {
130
+						} elseif ($token_type && ! empty(trim($token[1]))) {
131
+							switch ($token_type) {
132 132
 								case 'class' :
133 133
 									$current_class = $token[1];
134 134
 								break;
@@ -137,15 +137,15 @@  discard block
 block discarded – undo
137 137
 								break;
138 138
 								case 'filter' :
139 139
 								case 'action' :
140
-									$hook = trim( $token[1], "'" );
141
-									if ( isset( self::$custom_hooks_found[ $hook ] ) ) {
142
-										self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file;
140
+									$hook = trim($token[1], "'");
141
+									if (isset(self::$custom_hooks_found[$hook])) {
142
+										self::$custom_hooks_found[$hook]['file'][] = self::$current_file;
143 143
 									} else {
144
-    									self::$custom_hooks_found[ $hook ] = array(
144
+    									self::$custom_hooks_found[$hook] = array(
145 145
 											'line'     => $token[2],
146 146
 											'class'    => $current_class,
147 147
 											'function' => $current_function,
148
-											'file'     => array( self::$current_file ),
148
+											'file'     => array(self::$current_file),
149 149
 											'type'     => $token_type
150 150
 										);
151 151
 									}
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
 				}
158 158
 			}
159 159
 
160
-			foreach ( self::$custom_hooks_found as $hook => $details ) {
161
-				if ( ! strstr( $hook, 'sensei' ) ) {
162
-					unset( self::$custom_hooks_found[ $hook ] );
160
+			foreach (self::$custom_hooks_found as $hook => $details) {
161
+				if ( ! strstr($hook, 'sensei')) {
162
+					unset(self::$custom_hooks_found[$hook]);
163 163
 				}
164 164
 			}
165 165
 
166
-			ksort( self::$custom_hooks_found );
166
+			ksort(self::$custom_hooks_found);
167 167
 
168
-			if ( ! empty( self::$custom_hooks_found ) ) {
169
-				echo '<h2>' . $heading . '</h2>';
168
+			if ( ! empty(self::$custom_hooks_found)) {
169
+				echo '<h2>'.$heading.'</h2>';
170 170
 
171 171
 				echo '<table class="summary"><thead><tr><th>Hook</th><th>Type</th><th>File(s)</th></tr></thead><tbody>';
172 172
 
173
-				foreach ( self::$custom_hooks_found as $hook => $details ) {
173
+				foreach (self::$custom_hooks_found as $hook => $details) {
174 174
 					echo '<tr>
175
-						<td>' . self::get_hook_link( $hook, $details ) . '</td>
176
-						<td>' . $details['type'] . '</td>
177
-						<td>' . implode( ', ', array_unique( $details['file'] ) ) . '</td>
175
+						<td>' . self::get_hook_link($hook, $details).'</td>
176
+						<td>' . $details['type'].'</td>
177
+						<td>' . implode(', ', array_unique($details['file'])).'</td>
178 178
 					</tr>' . "\n";
179 179
 				}
180 180
 
@@ -187,22 +187,22 @@  discard block
 block discarded – undo
187 187
 
188 188
 
189 189
         // change to the ouput directory before operating on the files
190
-        chdir(  self::$docs_output_directory );
190
+        chdir(self::$docs_output_directory);
191 191
 
192
-        $html   = file_get_contents( 'index.html' );
193
-		$header = current( explode( '<div id="content">', $html ) );
194
-		$header = str_replace( '<li class="active">', '<li>', $header );
195
-		$header = str_replace( '<li class="hooks">', '<li class="active">', $header );
196
-		$footer = end( explode( '<div id="footer">', $html ) );
192
+        $html = file_get_contents('index.html');
193
+		$header = current(explode('<div id="content">', $html));
194
+		$header = str_replace('<li class="active">', '<li>', $header);
195
+		$header = str_replace('<li class="hooks">', '<li class="active">', $header);
196
+		$footer = end(explode('<div id="footer">', $html));
197 197
 
198 198
         //  delete old hook-docs file
199
-        if( file_exists( self::$put_file  )  ){
199
+        if (file_exists(self::$put_file)) {
200 200
 
201
-            unlink( self::$put_file );
201
+            unlink(self::$put_file);
202 202
 
203 203
         }
204 204
 
205
-		file_put_contents(  self::$put_file , $header . ob_get_clean() . $footer );
205
+		file_put_contents(self::$put_file, $header.ob_get_clean().$footer);
206 206
 
207 207
 		echo "Hook docs generated :)\n";
208 208
 	}
Please login to merge, or discard this patch.
includes/class-sensei-utils.php 1 patch
Spacing   +543 added lines, -543 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 Utilities Class
@@ -18,9 +18,9 @@  discard block
 block discarded – undo
18 18
 	 * @since   1.0.0
19 19
 	 * @return  string The URL to the placeholder thumbnail image.
20 20
 	 */
21
-	public static function get_placeholder_image () {
21
+	public static function get_placeholder_image() {
22 22
 
23
-		return esc_url( apply_filters( 'sensei_placeholder_thumbnail', Sensei()->plugin_url . 'assets/images/placeholder.png' ) );
23
+		return esc_url(apply_filters('sensei_placeholder_thumbnail', Sensei()->plugin_url.'assets/images/placeholder.png'));
24 24
 	} // End get_placeholder_image()
25 25
 
26 26
 	/**
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @static
33 33
 	 * @return bool
34 34
 	 */
35
-	public static function sensei_is_woocommerce_present () {
35
+	public static function sensei_is_woocommerce_present() {
36 36
 
37 37
         return Sensei_WC::is_woocommerce_present();
38 38
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	 * @static
48 48
 	 * @return boolean
49 49
 	 */
50
-	public static function sensei_is_woocommerce_activated () {
50
+	public static function sensei_is_woocommerce_activated() {
51 51
 
52 52
 		return  Sensei_WC::is_woocommerce_active();
53 53
 
@@ -60,70 +60,70 @@  discard block
 block discarded – undo
60 60
 	 * @param  array $args (default: array())
61 61
 	 * @return bool | int
62 62
 	 */
63
-	public static function sensei_log_activity ( $args = array() ) {
63
+	public static function sensei_log_activity($args = array()) {
64 64
 		global $wpdb;
65 65
 
66 66
 		// Args, minimum data required for WP
67 67
 		$data = array(
68
-					'comment_post_ID' => intval( $args['post_id'] ),
68
+					'comment_post_ID' => intval($args['post_id']),
69 69
 					'comment_author' => '', // Not needed
70 70
 					'comment_author_email' => '', // Not needed
71 71
 					'comment_author_url' => '', // Not needed
72
-					'comment_content' => !empty($args['data']) ? esc_html( $args['data'] ) : '',
73
-					'comment_type' => esc_attr( $args['type'] ),
74
-					'user_id' => intval( $args['user_id'] ),
75
-					'comment_approved' => !empty($args['status']) ? esc_html( $args['status'] ) : 'log', // 'log' == 'sensei_user_answer'
72
+					'comment_content' => ! empty($args['data']) ? esc_html($args['data']) : '',
73
+					'comment_type' => esc_attr($args['type']),
74
+					'user_id' => intval($args['user_id']),
75
+					'comment_approved' => ! empty($args['status']) ? esc_html($args['status']) : 'log', // 'log' == 'sensei_user_answer'
76 76
 				);
77 77
 		// Allow extra data
78
-		if ( !empty($args['username']) ) {
79
-			$data['comment_author'] = sanitize_user( $args['username'] );
78
+		if ( ! empty($args['username'])) {
79
+			$data['comment_author'] = sanitize_user($args['username']);
80 80
 		}
81
-		if ( !empty($args['user_email']) ) {
82
-			$data['comment_author_email'] = sanitize_email( $args['user_email'] );
81
+		if ( ! empty($args['user_email'])) {
82
+			$data['comment_author_email'] = sanitize_email($args['user_email']);
83 83
 		}
84
-		if ( !empty($args['user_url']) ) {
85
-			$data['comment_author_url'] = esc_url( $args['user_url'] );
84
+		if ( ! empty($args['user_url'])) {
85
+			$data['comment_author_url'] = esc_url($args['user_url']);
86 86
 		}
87
-		if ( !empty($args['parent']) ) {
87
+		if ( ! empty($args['parent'])) {
88 88
 			$data['comment_parent'] = $args['parent'];
89 89
 		}
90 90
 		// Sanity check
91
-		if ( empty($args['user_id']) ) {
92
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
91
+		if (empty($args['user_id'])) {
92
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
93 93
 			return false;
94 94
 		}
95 95
 
96
-		do_action( 'sensei_log_activity_before', $args, $data );
96
+		do_action('sensei_log_activity_before', $args, $data);
97 97
 
98 98
 		$flush_cache = false;
99 99
 
100 100
 		// Custom Logic
101 101
 		// Check if comment exists first
102
-		$comment_id = $wpdb->get_var( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type'] ) );
103
-		if ( ! $comment_id ) {
102
+		$comment_id = $wpdb->get_var($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND user_id = %d AND comment_type = %s ", $args['post_id'], $args['user_id'], $args['type']));
103
+		if ( ! $comment_id) {
104 104
 			// Add the comment
105
-			$comment_id = wp_insert_comment( $data );
105
+			$comment_id = wp_insert_comment($data);
106 106
 
107 107
 			$flush_cache = true;
108
-		} elseif ( isset( $args['action'] ) && 'update' == $args['action'] ) {
108
+		} elseif (isset($args['action']) && 'update' == $args['action']) {
109 109
 			// Update the comment if an update was requested
110 110
 			$data['comment_ID'] = $comment_id;
111 111
 			// By default update the timestamp of the comment
112
-			if ( empty($args['keep_time']) ) {
112
+			if (empty($args['keep_time'])) {
113 113
 				$data['comment_date'] = current_time('mysql');
114 114
 			}
115
-			wp_update_comment( $data );
115
+			wp_update_comment($data);
116 116
 			$flush_cache = true;
117 117
 		} // End If Statement
118 118
 
119 119
 		// Manually Flush the Cache
120
-		if ( $flush_cache ) {
120
+		if ($flush_cache) {
121 121
 			wp_cache_flush();
122 122
 		}
123 123
 
124
-		do_action( 'sensei_log_activity_after', $args, $data,  $comment_id );
124
+		do_action('sensei_log_activity_after', $args, $data, $comment_id);
125 125
 
126
-		if ( 0 < $comment_id ) {
126
+		if (0 < $comment_id) {
127 127
 			// Return the ID so that it can be used for meta data storage
128 128
 			return $comment_id;
129 129
 		} else {
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
 	 * @param  bool $return_comments (default: false)
141 141
 	 * @return mixed | int
142 142
 	 */
143
-	public static function sensei_check_for_activity ( $args = array(), $return_comments = false ) {
143
+	public static function sensei_check_for_activity($args = array(), $return_comments = false) {
144 144
 
145 145
 		global  $wp_version;
146
-		if ( !$return_comments ) {
146
+		if ( ! $return_comments) {
147 147
 			$args['count'] = true;
148 148
 		}
149 149
 
150 150
 		// Are we only retrieving a single entry, or not care about the order...
151
-		if ( isset( $args['count'] ) || isset( $args['post_id'] ) ){
151
+		if (isset($args['count']) || isset($args['post_id'])) {
152 152
 
153 153
 			// ...then we don't need to ask the db to order the results, this overrides WP default behaviour
154
-			if ( version_compare( $wp_version, '4.1', '>=' ) ) {
154
+			if (version_compare($wp_version, '4.1', '>=')) {
155 155
 				$args['order'] = false;
156 156
 				$args['orderby'] = false;
157 157
 			}
158 158
 		}
159 159
 
160 160
 		// A user ID of 0 is in valid, so shortcut this
161
-		if ( isset( $args['user_id'] ) && 0 == intval ( $args['user_id'] ) ) {
162
-			_deprecated_argument( __FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei') );
161
+		if (isset($args['user_id']) && 0 == intval($args['user_id'])) {
162
+			_deprecated_argument(__FUNCTION__, '1.0', __('At no point should user_id be equal to 0.', 'woothemes-sensei'));
163 163
 			return false;
164 164
 		}
165 165
 		// Check for legacy code
166
-		if ( isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes') ) ) {
167
-			_deprecated_argument( __FUNCTION__, '1.7', sprintf( __('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type'] ) );
166
+		if (isset($args['type']) && in_array($args['type'], array('sensei_course_start', 'sensei_course_end', 'sensei_lesson_start', 'sensei_lesson_end', 'sensei_quiz_asked', 'sensei_user_grade', 'sensei_quiz_grade', 'sense_answer_notes'))) {
167
+			_deprecated_argument(__FUNCTION__, '1.7', sprintf(__('Sensei activity type %s is no longer used.', 'woothemes-sensei'), $args['type']));
168 168
 			return false;
169 169
 		}
170 170
 		// Are we checking for specific comment_approved statuses?
171
-		if ( isset($args['status']) ) {
171
+		if (isset($args['status'])) {
172 172
 			// Temporarily store as a custom status if requesting an array...
173
-			if ( is_array( $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
173
+			if (is_array($args['status']) && version_compare($wp_version, '4.1', '<')) {
174 174
 				// Encode now, decode later
175
-				$args['status'] = implode( ",", $args['status'] );
175
+				$args['status'] = implode(",", $args['status']);
176 176
 				// ...use a filter to switch the encoding back
177
-				add_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
177
+				add_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
178 178
 			}
179 179
 		}
180 180
 		else {
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 		}
183 183
 
184 184
 		// Take into account WP < 4.1 will automatically add ' comment_approved = 1 OR comment_approved = 0 '
185
-		if ( ( is_array( $args['status'] ) || 'any' == $args['status'] ) && version_compare($wp_version, '4.1', '<') ) {
186
-			add_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
185
+		if ((is_array($args['status']) || 'any' == $args['status']) && version_compare($wp_version, '4.1', '<')) {
186
+			add_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
187 187
 		}
188 188
 
189 189
         //Get the comments
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
          *
195 195
          * @param int|array $comments
196 196
          */
197
-        $comments = apply_filters('sensei_check_for_activity', get_comments( $args ) );
197
+        $comments = apply_filters('sensei_check_for_activity', get_comments($args));
198 198
 
199
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_multiple_status_filter' ) );
200
-		remove_filter( 'comments_clauses', array( __CLASS__, 'comment_any_status_filter' ) );
199
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_multiple_status_filter'));
200
+		remove_filter('comments_clauses', array(__CLASS__, 'comment_any_status_filter'));
201 201
 		// Return comments
202
-		if ( $return_comments ) {
202
+		if ($return_comments) {
203 203
 			// Could check for array of 1 and just return the 1 item?
204
-			if ( is_array($comments) && 1 == count($comments) ) {
204
+			if (is_array($comments) && 1 == count($comments)) {
205 205
 				$comments = array_shift($comments);
206 206
 			}
207 207
 
@@ -219,31 +219,31 @@  discard block
 block discarded – undo
219 219
 	 * @param  array $args (default: array())
220 220
 	 * @return array
221 221
 	 */
222
-	public static function sensei_activity_ids ( $args = array() ) {
222
+	public static function sensei_activity_ids($args = array()) {
223 223
 
224 224
 
225
-		$comments = Sensei_Utils::sensei_check_for_activity( $args, true );
225
+		$comments = Sensei_Utils::sensei_check_for_activity($args, true);
226 226
 		// Need to always use an array, even with only 1 item
227
-		if ( !is_array($comments) ) {
228
-			$comments = array( $comments );
227
+		if ( ! is_array($comments)) {
228
+			$comments = array($comments);
229 229
 		}
230 230
 
231 231
 		$post_ids = array();
232 232
 		// Count comments
233
-		if ( is_array( $comments ) && ( 0 < intval( count( $comments ) ) ) ) {
234
-			foreach ( $comments as $key => $value  ) {
233
+		if (is_array($comments) && (0 < intval(count($comments)))) {
234
+			foreach ($comments as $key => $value) {
235 235
 				// Add matches to id array
236
-				if ( isset( $args['field'] ) && 'comment' == $args['field'] ) {
237
-					array_push( $post_ids, $value->comment_ID );
238
-				} elseif( isset( $args['field'] ) && 'user_id' == $args['field'] ) {
239
-					array_push( $post_ids, $value->user_id );
236
+				if (isset($args['field']) && 'comment' == $args['field']) {
237
+					array_push($post_ids, $value->comment_ID);
238
+				} elseif (isset($args['field']) && 'user_id' == $args['field']) {
239
+					array_push($post_ids, $value->user_id);
240 240
 				} else {
241
-					array_push( $post_ids, $value->comment_post_ID );
241
+					array_push($post_ids, $value->comment_post_ID);
242 242
 				} // End If Statement
243 243
 			} // End For Loop
244 244
 			// Reset array indexes
245
-			$post_ids = array_unique( $post_ids );
246
-			$post_ids = array_values( $post_ids );
245
+			$post_ids = array_unique($post_ids);
246
+			$post_ids = array_values($post_ids);
247 247
 		} // End If Statement
248 248
 
249 249
 		return $post_ids;
@@ -257,20 +257,20 @@  discard block
 block discarded – undo
257 257
 	 * @param  array $args (default: array())
258 258
 	 * @return boolean
259 259
 	 */
260
-	public static function sensei_delete_activities ( $args = array() ) {
260
+	public static function sensei_delete_activities($args = array()) {
261 261
 
262 262
 		$dataset_changes = false;
263 263
 
264 264
 		// If activity exists remove activity from log
265
-		$comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => intval( $args['post_id'] ), 'user_id' => intval( $args['user_id'] ), 'type' => esc_attr( $args['type'] ) ), true );
266
-		if( $comments ) {
265
+		$comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => intval($args['post_id']), 'user_id' => intval($args['user_id']), 'type' => esc_attr($args['type'])), true);
266
+		if ($comments) {
267 267
 			// Need to always return an array, even with only 1 item
268
-			if ( !is_array( $comments ) ) {
269
-				$comments = array( $comments );
268
+			if ( ! is_array($comments)) {
269
+				$comments = array($comments);
270 270
 			}
271
-			foreach ( $comments as $key => $value  ) {
272
-				if ( isset( $value->comment_ID ) && 0 < $value->comment_ID ) {
273
-					$dataset_changes = wp_delete_comment( intval( $value->comment_ID ), true );
271
+			foreach ($comments as $key => $value) {
272
+				if (isset($value->comment_ID) && 0 < $value->comment_ID) {
273
+					$dataset_changes = wp_delete_comment(intval($value->comment_ID), true);
274 274
 				} // End If Statement
275 275
 			} // End For Loop
276 276
 			// Manually flush the cache
@@ -286,25 +286,25 @@  discard block
 block discarded – undo
286 286
      * @param  integer $user_id User ID
287 287
      * @return boolean
288 288
      */
289
-    public static function delete_all_user_activity( $user_id = 0 ) {
289
+    public static function delete_all_user_activity($user_id = 0) {
290 290
 
291 291
     	$dataset_changes = false;
292 292
 
293
-    	if( $user_id ) {
293
+    	if ($user_id) {
294 294
 
295
-			$activities = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $user_id ), true );
295
+			$activities = Sensei_Utils::sensei_check_for_activity(array('user_id' => $user_id), true);
296 296
 
297
-			if( $activities ) {
297
+			if ($activities) {
298 298
 
299 299
 				// Need to always return an array, even with only 1 item
300
-				if ( ! is_array( $activities ) ) {
301
-					$activities = array( $activities );
300
+				if ( ! is_array($activities)) {
301
+					$activities = array($activities);
302 302
 				}
303 303
 
304
-				foreach( $activities as $activity ) {
305
-					if( '' == $activity->comment_type ) continue;
306
-					if( strpos( 'sensei_', $activity->comment_type ) != 0 ) continue;
307
-					$dataset_changes = wp_delete_comment( intval( $activity->comment_ID ), true );
304
+				foreach ($activities as $activity) {
305
+					if ('' == $activity->comment_type) continue;
306
+					if (strpos('sensei_', $activity->comment_type) != 0) continue;
307
+					$dataset_changes = wp_delete_comment(intval($activity->comment_ID), true);
308 308
 					wp_cache_flush();
309 309
 				}
310 310
 			}
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 	 * @param  array $args (default: array())
322 322
 	 * @return string
323 323
 	 */
324
-	public static function sensei_get_activity_value ( $args = array() ) {
324
+	public static function sensei_get_activity_value($args = array()) {
325 325
 
326 326
 		$activity_value = false;
327
-		if ( !empty($args['field']) ) {
328
-			$comment = Sensei_Utils::sensei_check_for_activity( $args, true );
327
+		if ( ! empty($args['field'])) {
328
+			$comment = Sensei_Utils::sensei_check_for_activity($args, true);
329 329
 
330
-			if ( isset( $comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
330
+			if (isset($comment->{$args['field']} ) && '' != $comment->{$args['field']} ) {
331 331
 				$activity_value = $comment->{$args['field']};
332 332
 			} // End If Statement
333 333
 		}
@@ -345,22 +345,22 @@  discard block
 block discarded – undo
345 345
      * @param  int $product_id
346 346
      * @return bool
347 347
      */
348
-    public static function sensei_customer_bought_product ( $customer_email, $user_id, $product_id ) {
348
+    public static function sensei_customer_bought_product($customer_email, $user_id, $product_id) {
349 349
 
350 350
         $emails = array();
351 351
 
352
-        if ( $user_id ) {
353
-            $user = get_user_by( 'id', intval( $user_id ) );
352
+        if ($user_id) {
353
+            $user = get_user_by('id', intval($user_id));
354 354
             $emails[] = $user->user_email;
355 355
         }
356 356
 
357
-        if ( is_email( $customer_email ) )
357
+        if (is_email($customer_email))
358 358
             $emails[] = $customer_email;
359 359
 
360
-        if ( sizeof( $emails ) == 0 )
360
+        if (sizeof($emails) == 0)
361 361
             return false;
362 362
 
363
-        return Sensei_WC::has_customer_bought_product( $user_id, $product_id );
363
+        return Sensei_WC::has_customer_bought_product($user_id, $product_id);
364 364
 
365 365
     } // End sensei_customer_bought_product()
366 366
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 * @param  string $input_name Name for text area form element
372 372
 	 * @return void
373 373
 	 */
374
-	public static function sensei_text_editor( $content = '', $editor_id = 'senseitexteditor', $input_name = '' ) {
374
+	public static function sensei_text_editor($content = '', $editor_id = 'senseitexteditor', $input_name = '') {
375 375
 
376
-		if( ! $input_name ) $input_name = $editor_id;
376
+		if ( ! $input_name) $input_name = $editor_id;
377 377
 
378 378
 		$buttons = 'bold,italic,underline,strikethrough,blockquote,bullist,numlist,justifyleft,justifycenter,justifyright,undo,redo,pastetext';
379 379
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 			'quicktags' => false
392 392
 		);
393 393
 
394
-		wp_editor( $content, $editor_id, $settings );
394
+		wp_editor($content, $editor_id, $settings);
395 395
 
396 396
 	} // End sensei_text_editor()
397 397
 
@@ -401,57 +401,57 @@  discard block
 block discarded – undo
401 401
      * @param int $user_id
402 402
 	 * @return boolean            Whether the answers were saved or not
403 403
 	 */
404
-	public static function sensei_save_quiz_answers( $submitted = array(), $user_id = 0 ) {
404
+	public static function sensei_save_quiz_answers($submitted = array(), $user_id = 0) {
405 405
 
406
-		if( intval( $user_id ) == 0 ) {
406
+		if (intval($user_id) == 0) {
407 407
 			$user_id = get_current_user_id();
408 408
 		}
409 409
 
410 410
 		$answers_saved = false;
411 411
 
412
-		if( $submitted && intval( $user_id ) > 0 ) {
412
+		if ($submitted && intval($user_id) > 0) {
413 413
 
414
-			foreach( $submitted as $question_id => $answer ) {
414
+			foreach ($submitted as $question_id => $answer) {
415 415
 
416 416
 				// Get question type
417
-				$question_type = Sensei()->question->get_question_type( $question_id );
417
+				$question_type = Sensei()->question->get_question_type($question_id);
418 418
 
419 419
 				// Sanitise answer
420
-				if( 0 == get_magic_quotes_gpc() ) {
421
-					$answer = wp_unslash( $answer );
420
+				if (0 == get_magic_quotes_gpc()) {
421
+					$answer = wp_unslash($answer);
422 422
 				}
423
-				switch( $question_type ) {
424
-					case 'multi-line': $answer = nl2br( $answer ); break;
423
+				switch ($question_type) {
424
+					case 'multi-line': $answer = nl2br($answer); break;
425 425
 					case 'single-line': break;
426 426
 					case 'gap-fill': break;
427
-					default: $answer = maybe_serialize( $answer ); break;
427
+					default: $answer = maybe_serialize($answer); break;
428 428
 				}
429 429
 				$args = array(
430 430
 							'post_id' => $question_id,
431
-							'data' => base64_encode( $answer ),
431
+							'data' => base64_encode($answer),
432 432
 							'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
433 433
 							'user_id' => $user_id,
434 434
 							'action' => 'update'
435 435
 						);
436
-				$answers_saved = Sensei_Utils::sensei_log_activity( $args );
436
+				$answers_saved = Sensei_Utils::sensei_log_activity($args);
437 437
 			}
438 438
 
439 439
 			// Handle file upload questions
440
-			if( isset( $_FILES ) ) {
441
-				foreach( $_FILES as $field => $file ) {
442
-					if( strpos( $field, 'file_upload_' ) !== false ) {
443
-						$question_id = str_replace( 'file_upload_', '', $field );
444
-						if( $file && $question_id ) {
445
-							$attachment_id = self::upload_file( $file );
446
-							if( $attachment_id ) {
440
+			if (isset($_FILES)) {
441
+				foreach ($_FILES as $field => $file) {
442
+					if (strpos($field, 'file_upload_') !== false) {
443
+						$question_id = str_replace('file_upload_', '', $field);
444
+						if ($file && $question_id) {
445
+							$attachment_id = self::upload_file($file);
446
+							if ($attachment_id) {
447 447
 								$args = array(
448 448
 									'post_id' => $question_id,
449
-									'data' => base64_encode( $attachment_id ),
449
+									'data' => base64_encode($attachment_id),
450 450
 									'type' => 'sensei_user_answer', /* FIELD SIZE 20 */
451 451
 									'user_id' => $user_id,
452 452
 									'action' => 'update'
453 453
 								);
454
-								$answers_saved = Sensei_Utils::sensei_log_activity( $args );
454
+								$answers_saved = Sensei_Utils::sensei_log_activity($args);
455 455
 							}
456 456
 						}
457 457
 					}
@@ -463,9 +463,9 @@  discard block
 block discarded – undo
463 463
 
464 464
 	} // End sensei_save_quiz_answers()
465 465
 
466
-	public static function upload_file( $file = array() ) {
466
+	public static function upload_file($file = array()) {
467 467
 
468
-		require_once( ABSPATH . 'wp-admin/includes/admin.php' );
468
+		require_once(ABSPATH.'wp-admin/includes/admin.php');
469 469
 
470 470
         /**
471 471
          * Filter the data array for the Sensei wp_handle_upload function call
@@ -480,11 +480,11 @@  discard block
 block discarded – undo
480 480
          *     @type string test_form set to false by default
481 481
          * }
482 482
          */
483
-        $file_upload_args = apply_filters( 'sensei_file_upload_args', array('test_form' => false ) );
483
+        $file_upload_args = apply_filters('sensei_file_upload_args', array('test_form' => false));
484 484
 
485
-        $file_return = wp_handle_upload( $file, $file_upload_args );
485
+        $file_return = wp_handle_upload($file, $file_upload_args);
486 486
 
487
-        if( isset( $file_return['error'] ) || isset( $file_return['upload_error_handler'] ) ) {
487
+        if (isset($file_return['error']) || isset($file_return['upload_error_handler'])) {
488 488
             return false;
489 489
         } else {
490 490
 
@@ -492,19 +492,19 @@  discard block
 block discarded – undo
492 492
 
493 493
             $attachment = array(
494 494
                 'post_mime_type' => $file_return['type'],
495
-                'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
495
+                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
496 496
                 'post_content' => '',
497 497
                 'post_status' => 'inherit',
498 498
                 'guid' => $file_return['url']
499 499
             );
500 500
 
501
-            $attachment_id = wp_insert_attachment( $attachment, $filename );
501
+            $attachment_id = wp_insert_attachment($attachment, $filename);
502 502
 
503
-            require_once(ABSPATH . 'wp-admin/includes/image.php');
504
-            $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
505
-            wp_update_attachment_metadata( $attachment_id, $attachment_data );
503
+            require_once(ABSPATH.'wp-admin/includes/image.php');
504
+            $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
505
+            wp_update_attachment_metadata($attachment_id, $attachment_data);
506 506
 
507
-            if( 0 < intval( $attachment_id ) ) {
507
+            if (0 < intval($attachment_id)) {
508 508
             	return $attachment_id;
509 509
             }
510 510
         }
@@ -530,9 +530,9 @@  discard block
 block discarded – undo
530 530
      *
531 531
 	 * @return int $quiz_grade total sum of all question grades
532 532
 	 */
533
-	public static function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto' ) {
533
+	public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') {
534 534
 
535
-        return Sensei_Grading::grade_quiz_auto( $quiz_id, $submitted, $total_questions, $quiz_grade_type );
535
+        return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type);
536 536
 
537 537
 	} // End sensei_grade_quiz_auto()
538 538
 
@@ -544,20 +544,20 @@  discard block
 block discarded – undo
544 544
      * @param  string $quiz_grade_type default 'auto'
545 545
 	 * @return boolean
546 546
 	 */
547
-	public static function sensei_grade_quiz( $quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto' ) {
548
-		if( intval( $user_id ) == 0 ) {
547
+	public static function sensei_grade_quiz($quiz_id = 0, $grade = 0, $user_id = 0, $quiz_grade_type = 'auto') {
548
+		if (intval($user_id) == 0) {
549 549
 			$user_id = get_current_user_id();
550 550
 		}
551 551
 
552 552
 		$activity_logged = false;
553
-		if( intval( $quiz_id ) > 0 && intval( $user_id ) > 0 ) {
554
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
555
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
556
-			$activity_logged = update_comment_meta( $user_lesson_status->comment_ID, 'grade', $grade );
553
+		if (intval($quiz_id) > 0 && intval($user_id) > 0) {
554
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
555
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
556
+			$activity_logged = update_comment_meta($user_lesson_status->comment_ID, 'grade', $grade);
557 557
 
558
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
558
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
559 559
 
560
-			do_action( 'sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type );
560
+			do_action('sensei_user_quiz_grade', $user_id, $quiz_id, $grade, $quiz_passmark, $quiz_grade_type);
561 561
 		}
562 562
 
563 563
 		return $activity_logged;
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
      *
578 578
 	 * @return int $question_grade
579 579
 	 */
580
-	public static function sensei_grade_question_auto( $question_id = 0, $question_type = '', $answer = '', $user_id = 0 ) {
580
+	public static function sensei_grade_question_auto($question_id = 0, $question_type = '', $answer = '', $user_id = 0) {
581 581
 
582
-       return  WooThemes_Sensei_Grading::grade_question_auto( $question_id, $question_type, $answer, $user_id  );
582
+       return  WooThemes_Sensei_Grading::grade_question_auto($question_id, $question_type, $answer, $user_id);
583 583
 
584 584
 	} // end sensei_grade_question_auto
585 585
 
@@ -590,20 +590,20 @@  discard block
 block discarded – undo
590 590
      * @param int $user_id
591 591
 	 * @return boolean
592 592
 	 */
593
-	public static function sensei_grade_question( $question_id = 0, $grade = 0, $user_id = 0 ) {
594
-		if( intval( $user_id ) == 0 ) {
593
+	public static function sensei_grade_question($question_id = 0, $grade = 0, $user_id = 0) {
594
+		if (intval($user_id) == 0) {
595 595
 			$user_id = get_current_user_id();
596 596
 		}
597 597
 
598 598
 		$activity_logged = false;
599
-		if( intval( $question_id ) > 0 && intval( $user_id ) > 0 ) {
599
+		if (intval($question_id) > 0 && intval($user_id) > 0) {
600 600
 
601
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
602
-			$activity_logged = update_comment_meta( $user_answer_id, 'user_grade', $grade );
601
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
602
+			$activity_logged = update_comment_meta($user_answer_id, 'user_grade', $grade);
603 603
 
604
-			$answer_notes = get_post_meta( $question_id, '_answer_feedback', true );
605
-			if ( !empty($answer_notes) ) {
606
-				update_comment_meta( $user_answer_id, 'answer_note', base64_encode( $answer_notes ) );
604
+			$answer_notes = get_post_meta($question_id, '_answer_feedback', true);
605
+			if ( ! empty($answer_notes)) {
606
+				update_comment_meta($user_answer_id, 'answer_note', base64_encode($answer_notes));
607 607
 			}
608 608
 
609 609
 		}
@@ -611,15 +611,15 @@  discard block
 block discarded – undo
611 611
 		return $activity_logged;
612 612
 	}
613 613
 
614
-	public static function sensei_delete_question_grade( $question_id = 0, $user_id = 0 ) {
615
-		if( intval( $user_id ) == 0 ) {
614
+	public static function sensei_delete_question_grade($question_id = 0, $user_id = 0) {
615
+		if (intval($user_id) == 0) {
616 616
 			$user_id = get_current_user_id();
617 617
 		}
618 618
 
619 619
 		$activity_logged = false;
620
-		if( intval( $question_id ) > 0 ) {
621
-			$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
622
-			$activity_logged = delete_comment_meta( $user_answer_id, 'user_grade' );
620
+		if (intval($question_id) > 0) {
621
+			$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
622
+			$activity_logged = delete_comment_meta($user_answer_id, 'user_grade');
623 623
 		}
624 624
 
625 625
 		return $activity_logged;
@@ -637,9 +637,9 @@  discard block
 block discarded – undo
637 637
      *
638 638
      * @return mixed boolean or comment_ID
639 639
      */
640
-    public static function user_start_lesson(  $user_id = 0, $lesson_id = 0, $complete = false ) {
640
+    public static function user_start_lesson($user_id = 0, $lesson_id = 0, $complete = false) {
641 641
 
642
-        return self::sensei_start_lesson( $lesson_id, $user_id, $complete );
642
+        return self::sensei_start_lesson($lesson_id, $user_id, $complete);
643 643
 
644 644
     }// end user_start_lesson()
645 645
 
@@ -656,22 +656,22 @@  discard block
 block discarded – undo
656 656
      *
657 657
      * @return mixed boolean or comment_ID
658 658
 	 */
659
-	public static function sensei_start_lesson( $lesson_id = 0, $user_id = 0, $complete = false ) {
659
+	public static function sensei_start_lesson($lesson_id = 0, $user_id = 0, $complete = false) {
660 660
 
661 661
 
662
-		if( intval( $user_id ) == 0 ) {
662
+		if (intval($user_id) == 0) {
663 663
 			$user_id = get_current_user_id();
664 664
 		}
665 665
 
666 666
 		$activity_logged = false;
667 667
 
668
-		if( intval( $lesson_id ) > 0 ) {
668
+		if (intval($lesson_id) > 0) {
669 669
 
670
-			$course_id = get_post_meta( $lesson_id, '_lesson_course', true );
671
-			if( $course_id ) {
672
-				$is_user_taking_course = Sensei_Utils::user_started_course( $course_id, $user_id );
673
-				if( ! $is_user_taking_course ) {
674
-					Sensei_Utils::user_start_course( $user_id, $course_id );
670
+			$course_id = get_post_meta($lesson_id, '_lesson_course', true);
671
+			if ($course_id) {
672
+				$is_user_taking_course = Sensei_Utils::user_started_course($course_id, $user_id);
673
+				if ( ! $is_user_taking_course) {
674
+					Sensei_Utils::user_start_course($user_id, $course_id);
675 675
 				}
676 676
 			}
677 677
 
@@ -679,12 +679,12 @@  discard block
 block discarded – undo
679 679
 			$status = 'in-progress';
680 680
 
681 681
 			// Note: When this action runs the lesson status may not yet exist
682
-			do_action( 'sensei_user_lesson_start', $user_id, $lesson_id );
682
+			do_action('sensei_user_lesson_start', $user_id, $lesson_id);
683 683
 
684
-			if( $complete ) {
684
+			if ($complete) {
685 685
 
686
-				$has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
687
-				if ( $has_questions ) {
686
+				$has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
687
+				if ($has_questions) {
688 688
 					$status = 'passed'; // Force a pass
689 689
 					$metadata['grade'] = 0;
690 690
 				}
@@ -694,31 +694,31 @@  discard block
 block discarded – undo
694 694
 			}
695 695
 
696 696
 			// Check if user is already taking the lesson
697
-			$activity_logged = Sensei_Utils::user_started_lesson( $lesson_id, $user_id );
698
-			if( ! $activity_logged ) {
697
+			$activity_logged = Sensei_Utils::user_started_lesson($lesson_id, $user_id);
698
+			if ( ! $activity_logged) {
699 699
 
700 700
 				$metadata['start'] = current_time('mysql');
701
-				$activity_logged = Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $status, $metadata );
701
+				$activity_logged = Sensei_Utils::update_lesson_status($user_id, $lesson_id, $status, $metadata);
702 702
 
703 703
             } else {
704 704
 
705 705
                 // if users is already taking the lesson  and the status changes to complete update it
706 706
                 $current_user_activity = get_comment($activity_logged);
707
-                if( $status=='complete' &&
708
-                    $status != $current_user_activity->comment_approved  ){
707
+                if ($status == 'complete' &&
708
+                    $status != $current_user_activity->comment_approved) {
709 709
 
710 710
                     $comment = array();
711 711
                     $comment['comment_ID'] = $activity_logged;
712 712
                     $comment['comment_approved'] = $status;
713
-                    wp_update_comment( $comment );
713
+                    wp_update_comment($comment);
714 714
 
715 715
                 }
716 716
 
717 717
             }
718 718
 
719
-			if ( $complete ) {
719
+			if ($complete) {
720 720
 				// Run this *after* the lesson status has been created/updated
721
-				do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
721
+				do_action('sensei_user_lesson_end', $user_id, $lesson_id);
722 722
 			}
723 723
 
724 724
 		}
@@ -733,23 +733,23 @@  discard block
 block discarded – undo
733 733
 	 * @param int $user_id
734 734
 	 * @return boolean
735 735
 	 */
736
-	public static function sensei_remove_user_from_lesson( $lesson_id = 0, $user_id = 0, $from_course = false ) {
736
+	public static function sensei_remove_user_from_lesson($lesson_id = 0, $user_id = 0, $from_course = false) {
737 737
 
738
-		if( ! $lesson_id ) return false;
738
+		if ( ! $lesson_id) return false;
739 739
 
740
-		if( intval( $user_id ) == 0 ) {
740
+		if (intval($user_id) == 0) {
741 741
 			$user_id = get_current_user_id();
742 742
 		}
743 743
 
744 744
 		// Process quiz
745
-		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
745
+		$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
746 746
 
747 747
 		// Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
748
-		Sensei_Utils::sensei_delete_quiz_answers( $lesson_quiz_id, $user_id );
748
+		Sensei_Utils::sensei_delete_quiz_answers($lesson_quiz_id, $user_id);
749 749
 
750 750
 
751 751
 		// Delete quiz saved answers
752
-		Sensei()->quiz->reset_user_lesson_data( $lesson_id, $user_id );
752
+		Sensei()->quiz->reset_user_lesson_data($lesson_id, $user_id);
753 753
 
754 754
 		// Delete lesson status
755 755
 		$args = array(
@@ -758,10 +758,10 @@  discard block
 block discarded – undo
758 758
 			'user_id' => $user_id,
759 759
 		);
760 760
 		// This auto deletes the corresponding meta data, such as the quiz grade, and questions asked
761
-		Sensei_Utils::sensei_delete_activities( $args );
761
+		Sensei_Utils::sensei_delete_activities($args);
762 762
 
763
-		if( ! $from_course ) {
764
-			do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
763
+		if ( ! $from_course) {
764
+			do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
765 765
 		}
766 766
 
767 767
 		return true;
@@ -774,19 +774,19 @@  discard block
 block discarded – undo
774 774
 	 * @param int $user_id
775 775
 	 * @return boolean
776 776
 	 */
777
-	public static function sensei_remove_user_from_course( $course_id = 0, $user_id = 0 ) {
777
+	public static function sensei_remove_user_from_course($course_id = 0, $user_id = 0) {
778 778
 
779 779
 
780
-		if( ! $course_id ) return false;
780
+		if ( ! $course_id) return false;
781 781
 
782
-		if( intval( $user_id ) == 0 ) {
782
+		if (intval($user_id) == 0) {
783 783
 			$user_id = get_current_user_id();
784 784
 		}
785 785
 
786
-		$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
786
+		$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
787 787
 
788
-		foreach( $lesson_ids as $lesson_id ) {
789
-			Sensei_Utils::sensei_remove_user_from_lesson( $lesson_id, $user_id, true );
788
+		foreach ($lesson_ids as $lesson_id) {
789
+			Sensei_Utils::sensei_remove_user_from_lesson($lesson_id, $user_id, true);
790 790
 		}
791 791
 
792 792
 		// Delete course status
@@ -796,36 +796,36 @@  discard block
 block discarded – undo
796 796
 			'user_id' => $user_id,
797 797
 		);
798 798
 
799
-		Sensei_Utils::sensei_delete_activities( $args );
799
+		Sensei_Utils::sensei_delete_activities($args);
800 800
 
801
-		do_action( 'sensei_user_course_reset', $user_id, $course_id );
801
+		do_action('sensei_user_course_reset', $user_id, $course_id);
802 802
 
803 803
 		return true;
804 804
 	}
805 805
 
806
-	public static function sensei_get_quiz_questions( $quiz_id = 0 ) {
806
+	public static function sensei_get_quiz_questions($quiz_id = 0) {
807 807
 
808 808
 
809 809
 		$questions = array();
810 810
 
811
-		if( intval( $quiz_id ) > 0 ) {
812
-			$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id );
813
-			$questions = Sensei_Utils::array_sort_reorder( $questions );
811
+		if (intval($quiz_id) > 0) {
812
+			$questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
813
+			$questions = Sensei_Utils::array_sort_reorder($questions);
814 814
 		}
815 815
 
816 816
 		return $questions;
817 817
 	}
818 818
 
819
-	public static function sensei_get_quiz_total( $quiz_id = 0 ) {
819
+	public static function sensei_get_quiz_total($quiz_id = 0) {
820 820
 
821 821
 
822 822
 		$quiz_total = 0;
823 823
 
824
-		if( $quiz_id > 0 ) {
825
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
824
+		if ($quiz_id > 0) {
825
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
826 826
 			$question_grade = 0;
827
-			foreach( $questions as $question ) {
828
-				$question_grade = Sensei()->question->get_question_grade( $question->ID );
827
+			foreach ($questions as $question) {
828
+				$question_grade = Sensei()->question->get_question_grade($question->ID);
829 829
 				$quiz_total += $question_grade;
830 830
 			}
831 831
 		}
@@ -840,20 +840,20 @@  discard block
 block discarded – undo
840 840
 	 * @param int $user_id
841 841
 	 * @return string
842 842
 	 */
843
-	public static function sensei_get_user_question_grade( $question = 0, $user_id = 0 ) {
843
+	public static function sensei_get_user_question_grade($question = 0, $user_id = 0) {
844 844
 		$question_grade = false;
845
-		if( $question ) {
846
-			if ( is_object( $question ) ) {
845
+		if ($question) {
846
+			if (is_object($question)) {
847 847
 				$user_answer_id = $question->comment_ID;
848 848
 			}
849 849
 			else {
850
-				if( intval( $user_id ) == 0 ) {
850
+				if (intval($user_id) == 0) {
851 851
 					$user_id = get_current_user_id();
852 852
 				}
853
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
853
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
854 854
 			}
855
-			if ( $user_answer_id ) {
856
-				$question_grade = get_comment_meta( $user_answer_id, 'user_grade', true );
855
+			if ($user_answer_id) {
856
+				$question_grade = get_comment_meta($user_answer_id, 'user_grade', true);
857 857
 			}
858 858
 		}
859 859
 
@@ -868,52 +868,52 @@  discard block
 block discarded – undo
868 868
 	 * @param int $user_id
869 869
 	 * @return string
870 870
 	 */
871
-	public static function sensei_get_user_question_answer_notes( $question = 0, $user_id = 0 ) {
871
+	public static function sensei_get_user_question_answer_notes($question = 0, $user_id = 0) {
872 872
 		$answer_notes = false;
873
-		if( $question ) {
874
-			if ( is_object( $question ) ) {
873
+		if ($question) {
874
+			if (is_object($question)) {
875 875
 				$user_answer_id = $question->comment_ID;
876 876
 			}
877 877
 			else {
878
-				if( intval( $user_id ) == 0 ) {
878
+				if (intval($user_id) == 0) {
879 879
 					$user_id = get_current_user_id();
880 880
 				}
881
-				$user_answer_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
881
+				$user_answer_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => intval($question), 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
882 882
 			}
883
-			if ( $user_answer_id ) {
884
-				$answer_notes = base64_decode( get_comment_meta( $user_answer_id, 'answer_note', true ) );
883
+			if ($user_answer_id) {
884
+				$answer_notes = base64_decode(get_comment_meta($user_answer_id, 'answer_note', true));
885 885
 			}
886 886
 		}
887 887
 
888 888
 		return $answer_notes;
889 889
 	}
890 890
 
891
-	public static function sensei_delete_quiz_answers( $quiz_id = 0, $user_id = 0 ) {
892
-		if( intval( $user_id ) == 0 ) {
891
+	public static function sensei_delete_quiz_answers($quiz_id = 0, $user_id = 0) {
892
+		if (intval($user_id) == 0) {
893 893
 			$user_id = get_current_user_id();
894 894
 		}
895 895
 
896 896
 		$delete_answers = false;
897
-		if( intval( $quiz_id ) > 0 ) {
898
-			$questions = Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
899
-			foreach( $questions as $question ) {
900
-				$delete_answers = Sensei_Utils::sensei_delete_activities( array( 'post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ) );
897
+		if (intval($quiz_id) > 0) {
898
+			$questions = Sensei_Utils::sensei_get_quiz_questions($quiz_id);
899
+			foreach ($questions as $question) {
900
+				$delete_answers = Sensei_Utils::sensei_delete_activities(array('post_id' => $question->ID, 'user_id' => $user_id, 'type' => 'sensei_user_answer'));
901 901
 			}
902 902
 		}
903 903
 
904 904
 		return $delete_answers;
905 905
 	}
906 906
 
907
-	public static function sensei_delete_quiz_grade( $quiz_id = 0, $user_id = 0 ) {
908
-		if( intval( $user_id ) == 0 ) {
907
+	public static function sensei_delete_quiz_grade($quiz_id = 0, $user_id = 0) {
908
+		if (intval($user_id) == 0) {
909 909
 			$user_id = get_current_user_id();
910 910
 		}
911 911
 
912 912
 		$delete_grade = false;
913
-		if( intval( $quiz_id ) > 0 ) {
914
-			$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
915
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
916
-			$delete_grade = delete_comment_meta( $user_lesson_status->comment_ID, 'grade' );
913
+		if (intval($quiz_id) > 0) {
914
+			$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
915
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
916
+			$delete_grade = delete_comment_meta($user_lesson_status->comment_ID, 'grade');
917 917
 		}
918 918
 
919 919
 		return $delete_grade;
@@ -926,20 +926,20 @@  discard block
 block discarded – undo
926 926
      * @param string $notes
927 927
 	 * @return boolean
928 928
 	 */
929
-	public static function sensei_add_answer_notes( $question_id = 0, $user_id = 0, $notes = '' ) {
930
-		if( intval( $user_id ) == 0 ) {
929
+	public static function sensei_add_answer_notes($question_id = 0, $user_id = 0, $notes = '') {
930
+		if (intval($user_id) == 0) {
931 931
 			$user_id = get_current_user_id();
932 932
 		}
933 933
 
934 934
 		$activity_logged = false;
935 935
 
936
-		if( intval( $question_id ) > 0 ) {
937
-			$notes = base64_encode( $notes );
936
+		if (intval($question_id) > 0) {
937
+			$notes = base64_encode($notes);
938 938
 
939 939
 			// Don't store empty values, no point
940
-			if ( !empty($notes) ) {
941
-				$user_lesson_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID' ) );
942
-				$activity_logged = update_comment_meta( $user_lesson_id, 'answer_note', $notes );
940
+			if ( ! empty($notes)) {
941
+				$user_lesson_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer', 'field' => 'comment_ID'));
942
+				$activity_logged = update_comment_meta($user_lesson_id, 'answer_note', $notes);
943 943
 			}
944 944
 			else {
945 945
 				$activity_logged = true;
@@ -955,16 +955,16 @@  discard block
 block discarded – undo
955 955
 	 * @param  array $return_array data to be ordered
956 956
 	 * @return array $return_array ordered data
957 957
 	 */
958
-	public static function array_sort_reorder( $return_array ) {
959
-		if ( isset( $_GET['orderby'] ) && '' != esc_html( $_GET['orderby'] ) ) {
958
+	public static function array_sort_reorder($return_array) {
959
+		if (isset($_GET['orderby']) && '' != esc_html($_GET['orderby'])) {
960 960
 			$sort_key = '';
961 961
 			// if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->sortable_columns ) ) {
962 962
 			// 	$sort_key = esc_html( $_GET['orderby'] );
963 963
 			// } // End If Statement
964
-			if ( '' != $sort_key ) {
965
-					Sensei_Utils::sort_array_by_key($return_array,$sort_key);
966
-				if ( isset( $_GET['order'] ) && 'desc' == esc_html( $_GET['order'] ) ) {
967
-					$return_array = array_reverse( $return_array, true );
964
+			if ('' != $sort_key) {
965
+					Sensei_Utils::sort_array_by_key($return_array, $sort_key);
966
+				if (isset($_GET['order']) && 'desc' == esc_html($_GET['order'])) {
967
+					$return_array = array_reverse($return_array, true);
968 968
 				} // End If Statement
969 969
 			} // End If Statement
970 970
 			return $return_array;
@@ -980,15 +980,15 @@  discard block
 block discarded – undo
980 980
 	 * @param  $key string column name in array
981 981
 	 * @return void
982 982
 	 */
983
-	public static function sort_array_by_key( $array, $key ) {
983
+	public static function sort_array_by_key($array, $key) {
984 984
 	    $sorter = array();
985 985
 	    $ret = array();
986
-	    reset( $array );
987
-	    foreach ( $array as $ii => $va ) {
986
+	    reset($array);
987
+	    foreach ($array as $ii => $va) {
988 988
 	        $sorter[$ii] = $va[$key];
989 989
 	    } // End For Loop
990
-	    asort( $sorter );
991
-	    foreach ( $sorter as $ii => $va ) {
990
+	    asort($sorter);
991
+	    foreach ($sorter as $ii => $va) {
992 992
 	        $ret[$ii] = $array[$ii];
993 993
 	    } // End For Loop
994 994
 	    $array = $ret;
@@ -1000,10 +1000,10 @@  discard block
 block discarded – undo
1000 1000
 	 * @param  integer $quiz_id
1001 1001
 	 * @return array of quiz questions
1002 1002
 	 */
1003
-	public static function lesson_quiz_questions( $quiz_id = 0 ) {
1003
+	public static function lesson_quiz_questions($quiz_id = 0) {
1004 1004
 		$questions_array = array();
1005
-		if ( 0 < $quiz_id ) {
1006
-			$question_args = array( 'post_type'         => 'question',
1005
+		if (0 < $quiz_id) {
1006
+			$question_args = array('post_type'         => 'question',
1007 1007
                                     'posts_per_page'       => -1,
1008 1008
                                     'orderby'           => 'ID',
1009 1009
                                     'order'             => 'ASC',
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
                                     'post_status'       => 'any',
1017 1017
                                     'suppress_filters'  => 0
1018 1018
                                 );
1019
-            $questions_array = get_posts( $question_args );
1019
+            $questions_array = get_posts($question_args);
1020 1020
         } // End If Statement
1021 1021
         return $questions_array;
1022 1022
 	} // End lesson_quiz_questions()
@@ -1026,25 +1026,25 @@  discard block
 block discarded – undo
1026 1026
 	 * @param  integer $course_id ID of course
1027 1027
 	 * @return integer            Pass mark for course
1028 1028
 	 */
1029
-	public static function sensei_course_pass_grade( $course_id = 0 ) {
1029
+	public static function sensei_course_pass_grade($course_id = 0) {
1030 1030
 
1031 1031
 
1032 1032
 		$course_passmark = 0;
1033 1033
 
1034
-		if( $course_id > 0 ) {
1035
-			$lessons = Sensei()->course->course_lessons( $course_id );
1034
+		if ($course_id > 0) {
1035
+			$lessons = Sensei()->course->course_lessons($course_id);
1036 1036
 			$lesson_count = 0;
1037 1037
 			$total_passmark = 0;
1038
-			foreach( $lessons as $lesson ) {
1038
+			foreach ($lessons as $lesson) {
1039 1039
 
1040 1040
 				// Get Quiz ID
1041
-				$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
1041
+				$quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
1042 1042
 
1043 1043
 				// Check for a pass being required
1044
-				$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1045
-				if ( $pass_required ) {
1044
+				$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1045
+				if ($pass_required) {
1046 1046
 					// Get quiz passmark
1047
-					$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1047
+					$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1048 1048
 
1049 1049
 					// Add up total passmark
1050 1050
 					$total_passmark += $quiz_passmark;
@@ -1053,12 +1053,12 @@  discard block
 block discarded – undo
1053 1053
 				}
1054 1054
 			}
1055 1055
 			// Might be a case of no required lessons
1056
-			if ( $lesson_count ) {
1057
-				$course_passmark = ( $total_passmark / $lesson_count );
1056
+			if ($lesson_count) {
1057
+				$course_passmark = ($total_passmark / $lesson_count);
1058 1058
 			}
1059 1059
 		}
1060 1060
 
1061
-		return Sensei_Utils::round( $course_passmark );
1061
+		return Sensei_Utils::round($course_passmark);
1062 1062
 	}
1063 1063
 
1064 1064
 	/**
@@ -1067,31 +1067,31 @@  discard block
 block discarded – undo
1067 1067
 	 * @param  integer $user_id   ID of user
1068 1068
 	 * @return integer            User's total grade
1069 1069
 	 */
1070
-	public static function sensei_course_user_grade( $course_id = 0, $user_id = 0 ) {
1070
+	public static function sensei_course_user_grade($course_id = 0, $user_id = 0) {
1071 1071
 
1072 1072
 
1073
-		if( intval( $user_id ) == 0 ) {
1073
+		if (intval($user_id) == 0) {
1074 1074
 			$user_id = get_current_user_id();
1075 1075
 		}
1076 1076
 
1077 1077
 		$total_grade = 0;
1078 1078
 
1079
-		if( $course_id > 0 && $user_id > 0 ) {
1080
-			$lessons = Sensei()->course->course_lessons( $course_id );
1079
+		if ($course_id > 0 && $user_id > 0) {
1080
+			$lessons = Sensei()->course->course_lessons($course_id);
1081 1081
 			$lesson_count = 0;
1082 1082
 			$total_grade = 0;
1083
-			foreach( $lessons as $lesson ) {
1083
+			foreach ($lessons as $lesson) {
1084 1084
 
1085 1085
 				// Check for lesson having questions, thus a quiz, thus having a grade
1086
-				$has_questions = get_post_meta( $lesson->ID, '_quiz_has_questions', true );
1087
-				if ( $has_questions ) {
1088
-					$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson->ID, $user_id );
1086
+				$has_questions = get_post_meta($lesson->ID, '_quiz_has_questions', true);
1087
+				if ($has_questions) {
1088
+					$user_lesson_status = Sensei_Utils::user_lesson_status($lesson->ID, $user_id);
1089 1089
 
1090
-					if(  empty( $user_lesson_status ) ){
1090
+					if (empty($user_lesson_status)) {
1091 1091
 						continue;
1092 1092
 					}
1093 1093
 					// Get user quiz grade
1094
-					$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1094
+					$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1095 1095
 
1096 1096
 					// Add up total grade
1097 1097
 					$total_grade += $quiz_grade;
@@ -1101,13 +1101,13 @@  discard block
 block discarded – undo
1101 1101
 			}
1102 1102
 
1103 1103
 			// Might be a case of no lessons with quizzes
1104
-			if ( $lesson_count ) {
1105
-				$total_grade = ( $total_grade / $lesson_count );
1104
+			if ($lesson_count) {
1105
+				$total_grade = ($total_grade / $lesson_count);
1106 1106
 			}
1107 1107
 
1108 1108
 		}
1109 1109
 
1110
-		return Sensei_Utils::round( $total_grade );
1110
+		return Sensei_Utils::round($total_grade);
1111 1111
 	}
1112 1112
 
1113 1113
 	/**
@@ -1116,18 +1116,18 @@  discard block
 block discarded – undo
1116 1116
 	 * @param  integer $user_id   ID of user
1117 1117
 	 * @return boolean
1118 1118
 	 */
1119
-	public static function sensei_user_passed_course( $course_id = 0, $user_id = 0 ) {
1120
-		if( intval( $user_id ) == 0 ) {
1119
+	public static function sensei_user_passed_course($course_id = 0, $user_id = 0) {
1120
+		if (intval($user_id) == 0) {
1121 1121
 			$user_id = get_current_user_id();
1122 1122
 		}
1123 1123
 
1124 1124
 		$pass = false;
1125 1125
 
1126
-		if( $course_id > 0 && $user_id > 0 ) {
1127
-			$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id );
1128
-			$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id );
1126
+		if ($course_id > 0 && $user_id > 0) {
1127
+			$passmark = Sensei_Utils::sensei_course_pass_grade($course_id);
1128
+			$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id);
1129 1129
 
1130
-			if( $user_grade >= $passmark ) {
1130
+			if ($user_grade >= $passmark) {
1131 1131
 				$pass = true;
1132 1132
 			}
1133 1133
 		}
@@ -1141,37 +1141,37 @@  discard block
 block discarded – undo
1141 1141
 	 * @param  integer $course_id ID of course
1142 1142
 	 * @param  integer $user_id   ID of user
1143 1143
 	 */
1144
-	public static function sensei_user_course_status_message( $course_id = 0, $user_id = 0 ) {
1145
-		if( intval( $user_id ) == 0 ) {
1144
+	public static function sensei_user_course_status_message($course_id = 0, $user_id = 0) {
1145
+		if (intval($user_id) == 0) {
1146 1146
 			$user_id = get_current_user_id();
1147 1147
 		}
1148 1148
 
1149 1149
 		$status = 'not_started';
1150 1150
 		$box_class = 'info';
1151
-		$message = __( 'You have not started this course yet.', 'woothemes-sensei' );
1151
+		$message = __('You have not started this course yet.', 'woothemes-sensei');
1152 1152
 
1153
-		if( $course_id > 0 && $user_id > 0 ) {
1153
+		if ($course_id > 0 && $user_id > 0) {
1154 1154
 
1155
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1155
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1156 1156
 
1157
-			if( $started_course ) {
1158
-				$passmark = Sensei_Utils::sensei_course_pass_grade( $course_id ); // This happens inside sensei_user_passed_course()!
1159
-				$user_grade = Sensei_Utils::sensei_course_user_grade( $course_id, $user_id ); // This happens inside sensei_user_passed_course()!
1160
-				if( $user_grade >= $passmark ) {
1157
+			if ($started_course) {
1158
+				$passmark = Sensei_Utils::sensei_course_pass_grade($course_id); // This happens inside sensei_user_passed_course()!
1159
+				$user_grade = Sensei_Utils::sensei_course_user_grade($course_id, $user_id); // This happens inside sensei_user_passed_course()!
1160
+				if ($user_grade >= $passmark) {
1161 1161
 					$status = 'passed';
1162 1162
 					$box_class = 'tick';
1163
-					$message = sprintf( __( 'You have passed this course with a grade of %1$d%%.', 'woothemes-sensei' ), $user_grade );
1163
+					$message = sprintf(__('You have passed this course with a grade of %1$d%%.', 'woothemes-sensei'), $user_grade);
1164 1164
 				} else {
1165 1165
 					$status = 'failed';
1166 1166
 					$box_class = 'alert';
1167
-					$message = sprintf( __( 'You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei' ), $passmark, $user_grade );
1167
+					$message = sprintf(__('You require %1$d%% to pass this course. Your grade is %2$s%%.', 'woothemes-sensei'), $passmark, $user_grade);
1168 1168
 				}
1169 1169
 			}
1170 1170
 
1171 1171
 		}
1172 1172
 
1173
-		$message = apply_filters( 'sensei_user_course_status_' . $status, $message );
1174
-		Sensei()->notices->add_notice( $message, $box_class   );
1173
+		$message = apply_filters('sensei_user_course_status_'.$status, $message);
1174
+		Sensei()->notices->add_notice($message, $box_class);
1175 1175
 	}
1176 1176
 
1177 1177
 	/**
@@ -1181,94 +1181,94 @@  discard block
 block discarded – undo
1181 1181
      * @param  bool $is_lesson
1182 1182
 	 * @return array              Status code and message
1183 1183
 	 */
1184
-	public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
1184
+	public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false) {
1185 1185
 		global  $current_user;
1186
-		if( intval( $user_id ) == 0 ) {
1186
+		if (intval($user_id) == 0) {
1187 1187
 			$user_id = $current_user->ID;
1188 1188
 		}
1189 1189
 
1190 1190
 		$status = 'not_started';
1191 1191
 		$box_class = 'info';
1192
-		$message = __( "You have not taken this lesson's quiz yet", 'woothemes-sensei' );
1192
+		$message = __("You have not taken this lesson's quiz yet", 'woothemes-sensei');
1193 1193
 		$extra = '';
1194 1194
 
1195
-		if( $lesson_id > 0 && $user_id > 0 ) {
1195
+		if ($lesson_id > 0 && $user_id > 0) {
1196 1196
 
1197 1197
 			// Prerequisite lesson
1198
-			$prerequisite = get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1198
+			$prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true);
1199 1199
 
1200 1200
 			// Course ID
1201
-			$course_id = absint( get_post_meta( $lesson_id, '_lesson_course', true ) );
1201
+			$course_id = absint(get_post_meta($lesson_id, '_lesson_course', true));
1202 1202
 
1203 1203
 			// Has user started course
1204
-			$started_course = Sensei_Utils::user_started_course( $course_id, $user_id );
1204
+			$started_course = Sensei_Utils::user_started_course($course_id, $user_id);
1205 1205
 
1206 1206
 			// Has user completed lesson
1207
-			$user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1208
-			$lesson_complete = Sensei_Utils::user_completed_lesson( $user_lesson_status );
1207
+			$user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1208
+			$lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status);
1209 1209
 
1210 1210
 			// Quiz ID
1211
-			$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1211
+			$quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1212 1212
 
1213 1213
 			// Quiz grade
1214 1214
 			$quiz_grade = 0;
1215
-			if ( $user_lesson_status ) {
1216
-				$quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1215
+			if ($user_lesson_status) {
1216
+				$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1217 1217
 			}
1218 1218
 
1219 1219
 			// Quiz passmark
1220
-			$quiz_passmark = absint( get_post_meta( $quiz_id, '_quiz_passmark', true ) );
1220
+			$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
1221 1221
 			$quiz_passmark_float = (float) $quiz_passmark;
1222 1222
 
1223 1223
 			// Pass required
1224
-			$pass_required = get_post_meta( $quiz_id, '_pass_required', true );
1224
+			$pass_required = get_post_meta($quiz_id, '_pass_required', true);
1225 1225
 
1226 1226
 			// Quiz questions
1227
-			$has_quiz_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1227
+			$has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1228 1228
 
1229
-			if ( ! $started_course ) {
1229
+			if ( ! $started_course) {
1230 1230
 
1231 1231
 				$status = 'not_started_course';
1232 1232
 				$box_class = 'info';
1233
-				$message = sprintf( __( 'Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . esc_attr( __( 'Sign Up', 'woothemes-sensei' ) ) . '">', '</a>' );
1233
+				$message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($course_id)).'" title="'.esc_attr(__('Sign Up', 'woothemes-sensei')).'">', '</a>');
1234 1234
 
1235
-			} elseif ( ! is_user_logged_in() ) {
1235
+			} elseif ( ! is_user_logged_in()) {
1236 1236
 
1237 1237
 				$status = 'login_required';
1238 1238
 				$box_class = 'info';
1239
-				$message = __( 'You must be logged in to take this quiz', 'woothemes-sensei' );
1239
+				$message = __('You must be logged in to take this quiz', 'woothemes-sensei');
1240 1240
 
1241 1241
 			}
1242 1242
 			// Lesson/Quiz is marked as complete thus passing any quiz restrictions
1243
-			elseif ( $lesson_complete ) {
1243
+			elseif ($lesson_complete) {
1244 1244
 
1245 1245
 				$status = 'passed';
1246 1246
 				$box_class = 'tick';
1247 1247
 				// Lesson status will be "complete" (has no Quiz)
1248
-				if ( ! $has_quiz_questions ) {
1249
-					$message = sprintf( __( 'Congratulations! You have passed this lesson.', 'woothemes-sensei' ) );
1248
+				if ( ! $has_quiz_questions) {
1249
+					$message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei'));
1250 1250
 				}
1251 1251
 				// Lesson status will be "graded" (no passmark required so might have failed all the questions)
1252
-				elseif ( empty( $quiz_grade ) ) {
1253
-					$message = sprintf( __( 'Congratulations! You have completed this lesson.', 'woothemes-sensei' ) );
1252
+				elseif (empty($quiz_grade)) {
1253
+					$message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei'));
1254 1254
 				}
1255 1255
 				// Lesson status will be "passed" (passmark reached)
1256
-				elseif ( ! empty( $quiz_grade ) && abs( $quiz_grade ) >= 0 ) {
1257
-					if( $is_lesson ) {
1258
-						$message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei' ), Sensei_Utils::round( $quiz_grade ) );
1256
+				elseif ( ! empty($quiz_grade) && abs($quiz_grade) >= 0) {
1257
+					if ($is_lesson) {
1258
+						$message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1259 1259
 					} else {
1260
-						$message = sprintf( __( 'Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_grade ) );
1260
+						$message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
1261 1261
 					}
1262 1262
 				}
1263 1263
 
1264 1264
                 // add next lesson button
1265
-                $nav_id_array = sensei_get_prev_next_lessons( $lesson_id );
1266
-                $next_lesson_id = absint( $nav_id_array['next_lesson'] );
1265
+                $nav_id_array = sensei_get_prev_next_lessons($lesson_id);
1266
+                $next_lesson_id = absint($nav_id_array['next_lesson']);
1267 1267
 
1268 1268
                 // Output HTML
1269
-                if ( ( 0 < $next_lesson_id ) ) {
1270
-                    $message .= ' ' . '<a class="next-lesson" href="' . esc_url( get_permalink( $next_lesson_id ) )
1271
-                                . '" rel="next"><span class="meta-nav"></span>'. __( 'Next Lesson' ,'woothemes-sensei')
1269
+                if ((0 < $next_lesson_id)) {
1270
+                    $message .= ' '.'<a class="next-lesson" href="'.esc_url(get_permalink($next_lesson_id))
1271
+                                . '" rel="next"><span class="meta-nav"></span>'.__('Next Lesson', 'woothemes-sensei')
1272 1272
                                 .'</a>';
1273 1273
 
1274 1274
                 }
@@ -1277,51 +1277,51 @@  discard block
 block discarded – undo
1277 1277
             // Lesson/Quiz not complete
1278 1278
 			else {
1279 1279
 				// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
1280
-				if ( isset( $user_lesson_status->comment_approved ) && 'ungraded' == $user_lesson_status->comment_approved ) {
1280
+				if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) {
1281 1281
 					$status = 'complete';
1282 1282
 					$box_class = 'info';
1283
-					if( $is_lesson ) {
1284
-						$message = sprintf( __( 'You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' . esc_attr( get_the_title( $quiz_id ) ) . '">', '</a>' );
1283
+					if ($is_lesson) {
1284
+						$message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($quiz_id)).'" title="'.esc_attr(get_the_title($quiz_id)).'">', '</a>');
1285 1285
 					} else {
1286
-						$message = sprintf( __( 'You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1286
+						$message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1287 1287
 					}
1288 1288
 				}
1289 1289
 				// Lesson status must be "failed"
1290
-				elseif ( isset( $user_lesson_status->comment_approved ) && 'failed' == $user_lesson_status->comment_approved ) {
1290
+				elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
1291 1291
 					$status = 'failed';
1292 1292
 					$box_class = 'alert';
1293
-					if( $is_lesson ) {
1294
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1293
+					if ($is_lesson) {
1294
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1295 1295
 					} else {
1296
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ),  Sensei_Utils::round( $quiz_grade ) );
1296
+						$message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
1297 1297
 					}
1298 1298
 				}
1299 1299
 				// Lesson/Quiz requires a pass
1300
-				elseif( $pass_required ) {
1300
+				elseif ($pass_required) {
1301 1301
 					$status = 'not_started';
1302 1302
 					$box_class = 'info';
1303
-					if( $is_lesson ) {
1304
-						$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1303
+					if ($is_lesson) {
1304
+						$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1305 1305
 					} else {
1306
-						$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ),  Sensei_Utils::round( $quiz_passmark ) );
1306
+						$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark));
1307 1307
 					}
1308 1308
 				}
1309 1309
 			}
1310 1310
 
1311
-		}else{
1311
+		} else {
1312 1312
 
1313
-			$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1314
-			$a_element = '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Sign Up', 'woothemes-sensei' )  . '">';
1315
-			$a_element .= __( 'course', 'woothemes-sensei' );
1313
+			$course_id = Sensei()->lesson->get_course_id($lesson_id);
1314
+			$a_element = '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Sign Up', 'woothemes-sensei').'">';
1315
+			$a_element .= __('course', 'woothemes-sensei');
1316 1316
 			$a_element .= '</a>';
1317 1317
 
1318
-			if ( Sensei_WC::is_course_purchasable( $course_id ) ){
1318
+			if (Sensei_WC::is_course_purchasable($course_id)) {
1319 1319
 
1320
-				$message = sprintf( __( 'Please purchase the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1320
+				$message = sprintf(__('Please purchase the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1321 1321
 
1322 1322
 			} else {
1323 1323
 
1324
-				$message = sprintf( __( 'Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei' ), $a_element );
1324
+				$message = sprintf(__('Please sign up for the %1$s before taking this quiz.', 'woothemes-sensei'), $a_element);
1325 1325
 
1326 1326
 			}
1327 1327
 
@@ -1329,15 +1329,15 @@  discard block
 block discarded – undo
1329 1329
 		}
1330 1330
 
1331 1331
 		// Legacy filter
1332
-		$message = apply_filters( 'sensei_user_quiz_status_' . $status, $message );
1332
+		$message = apply_filters('sensei_user_quiz_status_'.$status, $message);
1333 1333
 
1334
-		if( $is_lesson && ! in_array( $status, array( 'login_required', 'not_started_course' ) ) ) {
1335
-            $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1336
-			$extra = '<p><a class="button" href="' . esc_url( get_permalink( $quiz_id ) ) . '" title="' .  __( 'View the lesson quiz', 'woothemes-sensei' ) . '">' .  __( 'View the lesson quiz', 'woothemes-sensei' )  . '</a></p>';
1334
+		if ($is_lesson && ! in_array($status, array('login_required', 'not_started_course'))) {
1335
+            $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1336
+			$extra = '<p><a class="button" href="'.esc_url(get_permalink($quiz_id)).'" title="'.__('View the lesson quiz', 'woothemes-sensei').'">'.__('View the lesson quiz', 'woothemes-sensei').'</a></p>';
1337 1337
 		}
1338 1338
 
1339 1339
 		// Filter of all messages
1340
-		return apply_filters( 'sensei_user_quiz_status', array( 'status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra ), $lesson_id, $user_id, $is_lesson );
1340
+		return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson);
1341 1341
 	}
1342 1342
 
1343 1343
 	/**
@@ -1347,14 +1347,14 @@  discard block
 block discarded – undo
1347 1347
 	 * @param  integer $course_id Course ID
1348 1348
 	 * @return mixed boolean or comment_ID
1349 1349
 	 */
1350
-	public static function user_start_course( $user_id = 0, $course_id = 0 ) {
1350
+	public static function user_start_course($user_id = 0, $course_id = 0) {
1351 1351
 
1352 1352
 		$activity_logged = false;
1353 1353
 
1354
-		if( $user_id && $course_id ) {
1354
+		if ($user_id && $course_id) {
1355 1355
 			// Check if user is already on the Course
1356
-			$activity_logged = Sensei_Utils::user_started_course( $course_id, $user_id );
1357
-			if ( ! $activity_logged ) {
1356
+			$activity_logged = Sensei_Utils::user_started_course($course_id, $user_id);
1357
+			if ( ! $activity_logged) {
1358 1358
 
1359 1359
 				// Add user to course
1360 1360
 				$course_metadata = array(
@@ -1363,11 +1363,11 @@  discard block
 block discarded – undo
1363 1363
 					'complete' => 0,
1364 1364
 				);
1365 1365
 
1366
-				$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status = 'in-progress', $course_metadata );
1366
+				$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status = 'in-progress', $course_metadata);
1367 1367
 
1368 1368
 				// Allow further actions
1369
-				if ( $activity_logged ) {
1370
-					do_action( 'sensei_user_course_start', $user_id, $course_id );
1369
+				if ($activity_logged) {
1370
+					do_action('sensei_user_course_start', $user_id, $course_id);
1371 1371
 				}
1372 1372
 			}
1373 1373
 		}
@@ -1383,19 +1383,19 @@  discard block
 block discarded – undo
1383 1383
 	 * @param int $user_id
1384 1384
 	 * @return mixed false or comment_ID
1385 1385
 	 */
1386
-	public static function user_started_course( $course_id = 0, $user_id = 0 ) {
1386
+	public static function user_started_course($course_id = 0, $user_id = 0) {
1387 1387
 
1388 1388
 		$user_started_course = false;
1389 1389
 
1390
-		if( $course_id ) {
1390
+		if ($course_id) {
1391 1391
 
1392
-			if( ! $user_id ) {
1392
+			if ( ! $user_id) {
1393 1393
 				$user_id = get_current_user_id();
1394 1394
 			}
1395 1395
 
1396
-            if ( ! $user_id > 0 ) {
1396
+            if ( ! $user_id > 0) {
1397 1397
 
1398
-	            $user_started_course =  false;
1398
+	            $user_started_course = false;
1399 1399
 
1400 1400
             } else {
1401 1401
 
@@ -1406,9 +1406,9 @@  discard block
 block discarded – undo
1406 1406
 		            'field' => 'comment_ID'
1407 1407
 	            );
1408 1408
 
1409
-				$user_course_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1409
+				$user_course_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1410 1410
 
1411
-				if ( $user_course_status_id ) {
1411
+				if ($user_course_status_id) {
1412 1412
 
1413 1413
 					$user_started_course = $user_course_status_id;
1414 1414
 
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
 		 * @param bool $user_started_course
1425 1425
 		 * @param integer $course_id
1426 1426
 		 */
1427
-		return apply_filters( 'sensei_user_started_course', $user_started_course, $course_id, $user_id );
1427
+		return apply_filters('sensei_user_started_course', $user_started_course, $course_id, $user_id);
1428 1428
 
1429 1429
 	}
1430 1430
 
@@ -1436,17 +1436,17 @@  discard block
 block discarded – undo
1436 1436
 	 * @param  integer $user_id   User ID
1437 1437
 	 * @return int
1438 1438
 	 */
1439
-	public static function user_complete_course( $course_id = 0, $user_id = 0 ) {
1439
+	public static function user_complete_course($course_id = 0, $user_id = 0) {
1440 1440
 		global  $wp_version;
1441 1441
 
1442
-		if( $course_id ) {
1443
-			if( ! $user_id ) {
1442
+		if ($course_id) {
1443
+			if ( ! $user_id) {
1444 1444
 				$user_id = get_current_user_id();
1445 1445
 			}
1446 1446
 
1447 1447
 			$course_status = 'in-progress';
1448 1448
 			$course_metadata = array();
1449
-			$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1449
+			$course_completion = Sensei()->settings->settings['course_completion'];
1450 1450
 			$lessons_completed = $total_lessons = 0;
1451 1451
 			$lesson_status_args = array(
1452 1452
 					'user_id' => $user_id,
@@ -1455,8 +1455,8 @@  discard block
 block discarded – undo
1455 1455
 				);
1456 1456
 
1457 1457
 			// Grab all of this Courses' lessons, looping through each...
1458
-			$lesson_ids = Sensei()->course->course_lessons( $course_id, 'any', 'ids' );
1459
-			$total_lessons = count( $lesson_ids );
1458
+			$lesson_ids = Sensei()->course->course_lessons($course_id, 'any', 'ids');
1459
+			$total_lessons = count($lesson_ids);
1460 1460
 				// ...if course completion not set to 'passed', and all lessons are complete or graded,
1461 1461
 				// ......then all lessons are 'passed'
1462 1462
 				// ...else if course completion is set to 'passed', check if each lesson has questions...
@@ -1469,29 +1469,29 @@  discard block
 block discarded – undo
1469 1469
 			// The below checks if a lesson is fully completed, though maybe should be Utils::user_completed_lesson()
1470 1470
 			$all_lesson_statuses = array();
1471 1471
 			// In WordPress 4.1 get_comments() allows a single query to cover multiple comment_post_IDs
1472
-			if ( version_compare($wp_version, '4.1', '>=') ) {
1472
+			if (version_compare($wp_version, '4.1', '>=')) {
1473 1473
 				$lesson_status_args['post__in'] = $lesson_ids;
1474
-				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1474
+				$all_lesson_statuses = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1475 1475
 				// Need to always return an array, even with only 1 item
1476
-				if ( !is_array($all_lesson_statuses) ) {
1477
-					$all_lesson_statuses = array( $all_lesson_statuses );
1476
+				if ( ! is_array($all_lesson_statuses)) {
1477
+					$all_lesson_statuses = array($all_lesson_statuses);
1478 1478
 				}
1479 1479
 			}
1480 1480
 			// ...otherwise check each one
1481 1481
 			else {
1482
-				foreach( $lesson_ids as $lesson_id ) {
1482
+				foreach ($lesson_ids as $lesson_id) {
1483 1483
 					$lesson_status_args['post_id'] = $lesson_id;
1484
-					$each_lesson_status = Sensei_Utils::sensei_check_for_activity( $lesson_status_args, true );
1484
+					$each_lesson_status = Sensei_Utils::sensei_check_for_activity($lesson_status_args, true);
1485 1485
 					// Check for valid return before using
1486
-					if ( !empty($each_lesson_status->comment_approved) ) {
1486
+					if ( ! empty($each_lesson_status->comment_approved)) {
1487 1487
 						$all_lesson_statuses[] = $each_lesson_status;
1488 1488
 					}
1489 1489
 				}
1490 1490
 			}
1491
-			foreach( $all_lesson_statuses as $lesson_status ) {
1491
+			foreach ($all_lesson_statuses as $lesson_status) {
1492 1492
 				// If lessons are complete without needing quizzes to be passed
1493
-				if ( 'passed' != $course_completion ) {
1494
-					switch ( $lesson_status->comment_approved ) {
1493
+				if ('passed' != $course_completion) {
1494
+					switch ($lesson_status->comment_approved) {
1495 1495
 						// A user cannot 'complete' a course if a lesson...
1496 1496
 						case 'in-progress': // ...is still in progress
1497 1497
 						case 'ungraded': // ...hasn't yet been graded
@@ -1503,7 +1503,7 @@  discard block
 block discarded – undo
1503 1503
 					}
1504 1504
 				}
1505 1505
 				else {
1506
-					switch ( $lesson_status->comment_approved ) {
1506
+					switch ($lesson_status->comment_approved) {
1507 1507
 						case 'complete': // Lesson has no quiz/questions
1508 1508
 						case 'graded': // Lesson has quiz, but it's not important what the grade was
1509 1509
 						case 'passed': // Lesson has quiz and the user passed
@@ -1517,20 +1517,20 @@  discard block
 block discarded – undo
1517 1517
 					}
1518 1518
 				}
1519 1519
 			} // Each lesson
1520
-			if ( $lessons_completed == $total_lessons ) {
1520
+			if ($lessons_completed == $total_lessons) {
1521 1521
 				$course_status = 'complete';
1522 1522
 			}
1523 1523
 
1524 1524
 			// Update meta data on how many lessons have been completed
1525 1525
 			$course_metadata['complete'] = $lessons_completed;
1526 1526
 			// update the overall percentage of the course lessons complete (or graded) compared to 'in-progress' regardless of the above
1527
-			$course_metadata['percent'] = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $total_lessons ), 0 ) );
1527
+			$course_metadata['percent'] = abs(round((doubleval($lessons_completed) * 100) / ($total_lessons), 0));
1528 1528
 
1529
-			$activity_logged = Sensei_Utils::update_course_status( $user_id, $course_id, $course_status, $course_metadata );
1529
+			$activity_logged = Sensei_Utils::update_course_status($user_id, $course_id, $course_status, $course_metadata);
1530 1530
 
1531 1531
 			// Allow further actions
1532
-			if ( 'complete' == $course_status ) {
1533
-				do_action( 'sensei_user_course_end', $user_id, $course_id );
1532
+			if ('complete' == $course_status) {
1533
+				do_action('sensei_user_course_end', $user_id, $course_id);
1534 1534
 			}
1535 1535
 			return $activity_logged;
1536 1536
 		}
@@ -1546,40 +1546,40 @@  discard block
 block discarded – undo
1546 1546
 	 * @param int $user_id
1547 1547
 	 * @return boolean
1548 1548
 	 */
1549
-	public static function user_completed_course( $course , $user_id = 0 ) {
1549
+	public static function user_completed_course($course, $user_id = 0) {
1550 1550
 
1551
-		if( $course ) {
1552
-			if ( is_object( $course ) && is_a( $course,'WP_Comment') ) {
1551
+		if ($course) {
1552
+			if (is_object($course) && is_a($course, 'WP_Comment')) {
1553 1553
 				$user_course_status = $course->comment_approved;
1554 1554
 			}
1555
-			elseif ( !is_numeric( $course ) && ! is_a( $course,'WP_Post') ) {
1555
+			elseif ( ! is_numeric($course) && ! is_a($course, 'WP_Post')) {
1556 1556
 				$user_course_status = $course;
1557 1557
 			}
1558 1558
 			else {
1559 1559
 
1560 1560
 				// check the user_id
1561
-				if( ! $user_id ) {
1561
+				if ( ! $user_id) {
1562 1562
 
1563 1563
 					$user_id = get_current_user_id();
1564 1564
 
1565
-					if( empty( $user_id ) ){
1565
+					if (empty($user_id)) {
1566 1566
 
1567 1567
 						return false;
1568 1568
 
1569 1569
 					}
1570 1570
 				}
1571 1571
 
1572
-                if( is_a( $course, 'WP_Post' ) ){
1573
-                    $course =   $course->ID;
1572
+                if (is_a($course, 'WP_Post')) {
1573
+                    $course = $course->ID;
1574 1574
                 }
1575 1575
 
1576
-				$user_course_status = Sensei_Utils::user_course_status( $course , $user_id );
1577
-				if( isset( $user_course_status->comment_approved ) ){
1576
+				$user_course_status = Sensei_Utils::user_course_status($course, $user_id);
1577
+				if (isset($user_course_status->comment_approved)) {
1578 1578
                     $user_course_status = $user_course_status->comment_approved;
1579 1579
                 }
1580 1580
 
1581 1581
 			}
1582
-			if( $user_course_status && 'complete' == $user_course_status ) {
1582
+			if ($user_course_status && 'complete' == $user_course_status) {
1583 1583
 				return true;
1584 1584
 			}
1585 1585
 		}
@@ -1594,10 +1594,10 @@  discard block
 block discarded – undo
1594 1594
 	 * @param int $user_id
1595 1595
 	 * @return mixed false or comment_ID
1596 1596
 	 */
1597
-	public static function user_started_lesson( $lesson_id = 0, $user_id = 0 ) {
1597
+	public static function user_started_lesson($lesson_id = 0, $user_id = 0) {
1598 1598
 
1599
-		if( $lesson_id ) {
1600
-			if( ! $user_id ) {
1599
+		if ($lesson_id) {
1600
+			if ( ! $user_id) {
1601 1601
 				$user_id = get_current_user_id();
1602 1602
 			}
1603 1603
 
@@ -1607,8 +1607,8 @@  discard block
 block discarded – undo
1607 1607
                 'type' => 'sensei_lesson_status',
1608 1608
                 'field' => 'comment_ID' );
1609 1609
 
1610
-			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value( $activity_args );
1611
-			if( $user_lesson_status_id ) {
1610
+			$user_lesson_status_id = Sensei_Utils::sensei_get_activity_value($activity_args);
1611
+			if ($user_lesson_status_id) {
1612 1612
 				return $user_lesson_status_id;
1613 1613
 			}
1614 1614
 		}
@@ -1623,29 +1623,29 @@  discard block
 block discarded – undo
1623 1623
 	 * @param int $user_id
1624 1624
 	 * @return boolean
1625 1625
 	 */
1626
-	public static function user_completed_lesson( $lesson = 0, $user_id = 0 ) {
1626
+	public static function user_completed_lesson($lesson = 0, $user_id = 0) {
1627 1627
 
1628
-		if( $lesson ) {
1628
+		if ($lesson) {
1629 1629
 			$lesson_id = 0;
1630
-			if ( is_object( $lesson ) ) {
1630
+			if (is_object($lesson)) {
1631 1631
 				$user_lesson_status = $lesson->comment_approved;
1632 1632
 				$lesson_id = $lesson->comment_post_ID;
1633 1633
 			}
1634
-			elseif ( ! is_numeric( $lesson ) ) {
1634
+			elseif ( ! is_numeric($lesson)) {
1635 1635
 				$user_lesson_status = $lesson;
1636 1636
 			}
1637 1637
 			else {
1638
-				if( ! $user_id ) {
1638
+				if ( ! $user_id) {
1639 1639
 					$user_id = get_current_user_id();
1640 1640
 				}
1641 1641
 
1642 1642
                 // the user is not logged in
1643
-                if( ! $user_id > 0 ){
1643
+                if ( ! $user_id > 0) {
1644 1644
                     return false;
1645 1645
                 }
1646
-				$_user_lesson_status = Sensei_Utils::user_lesson_status( $lesson, $user_id );
1646
+				$_user_lesson_status = Sensei_Utils::user_lesson_status($lesson, $user_id);
1647 1647
 
1648
-				if ( $_user_lesson_status ) {
1648
+				if ($_user_lesson_status) {
1649 1649
 					$user_lesson_status = $_user_lesson_status->comment_approved;
1650 1650
 				}
1651 1651
 				else {
@@ -1653,12 +1653,12 @@  discard block
 block discarded – undo
1653 1653
 				}
1654 1654
 				$lesson_id = $lesson;
1655 1655
 			}
1656
-			if ( 'in-progress' != $user_lesson_status ) {
1656
+			if ('in-progress' != $user_lesson_status) {
1657 1657
 				// Check for Passed or Completed Setting
1658 1658
 				// Should we be checking for the Course completion setting? Surely that should only affect the Course completion, not bypass each Lesson setting
1659 1659
 //				$course_completion = Sensei()->settings->settings[ 'course_completion' ];
1660 1660
 //				if ( 'passed' == $course_completion ) {
1661
-					switch( $user_lesson_status ) {
1661
+					switch ($user_lesson_status) {
1662 1662
 						case 'complete':
1663 1663
 						case 'graded':
1664 1664
 						case 'passed':
@@ -1667,13 +1667,13 @@  discard block
 block discarded – undo
1667 1667
 
1668 1668
 						case 'failed':
1669 1669
 							// This may be 'completed' depending on...
1670
-							if ( $lesson_id ) {
1670
+							if ($lesson_id) {
1671 1671
 								// Get Quiz ID, this won't be needed once all Quiz meta fields are stored on the Lesson
1672
-								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1673
-								if ( $lesson_quiz_id ) {
1672
+								$lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1673
+								if ($lesson_quiz_id) {
1674 1674
 									// ...the quiz pass setting
1675
-									$pass_required = get_post_meta( $lesson_quiz_id, '_pass_required', true );
1676
-									if ( empty($pass_required) ) {
1675
+									$pass_required = get_post_meta($lesson_quiz_id, '_pass_required', true);
1676
+									if (empty($pass_required)) {
1677 1677
 										// We just require the user to have done the quiz, not to have passed
1678 1678
 										return true;
1679 1679
 									}
@@ -1696,15 +1696,15 @@  discard block
 block discarded – undo
1696 1696
 	 * @param int $user_id
1697 1697
 	 * @return object
1698 1698
 	 */
1699
-	public static function user_course_status( $course_id = 0, $user_id = 0 ) {
1699
+	public static function user_course_status($course_id = 0, $user_id = 0) {
1700 1700
 
1701 1701
 
1702
-		if( $course_id ) {
1703
-			if( ! $user_id ) {
1702
+		if ($course_id) {
1703
+			if ( ! $user_id) {
1704 1704
 				$user_id = get_current_user_id();
1705 1705
 			}
1706 1706
 
1707
-			$user_course_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status' ), true );
1707
+			$user_course_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $user_id, 'type' => 'sensei_course_status'), true);
1708 1708
 			return $user_course_status;
1709 1709
 		}
1710 1710
 
@@ -1719,27 +1719,27 @@  discard block
 block discarded – undo
1719 1719
 	 * @param int $user_id
1720 1720
 	 * @return object | bool
1721 1721
 	 */
1722
-	public static function user_lesson_status( $lesson_id = 0, $user_id = 0 ) {
1722
+	public static function user_lesson_status($lesson_id = 0, $user_id = 0) {
1723 1723
 
1724
-        if( ! $user_id ) {
1724
+        if ( ! $user_id) {
1725 1725
             $user_id = get_current_user_id();
1726 1726
         }
1727 1727
 
1728
-		if( $lesson_id > 0 && $user_id > 0 ) {
1728
+		if ($lesson_id > 0 && $user_id > 0) {
1729 1729
 
1730
-			$user_lesson_status = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status' ), true );
1730
+			$user_lesson_status = Sensei_Utils::sensei_check_for_activity(array('post_id' => $lesson_id, 'user_id' => $user_id, 'type' => 'sensei_lesson_status'), true);
1731 1731
 			return $user_lesson_status;
1732 1732
 		}
1733 1733
 
1734 1734
 		return false;
1735 1735
 	}
1736 1736
 
1737
-	public static function is_preview_lesson( $lesson_id ) {
1737
+	public static function is_preview_lesson($lesson_id) {
1738 1738
 		$is_preview = false;
1739 1739
 
1740
-		if( 'lesson' == get_post_type( $lesson_id ) ) {
1741
-			$lesson_preview = get_post_meta( $lesson_id, '_lesson_preview', true );
1742
-			if ( isset( $lesson_preview ) && '' != $lesson_preview ) {
1740
+		if ('lesson' == get_post_type($lesson_id)) {
1741
+			$lesson_preview = get_post_meta($lesson_id, '_lesson_preview', true);
1742
+			if (isset($lesson_preview) && '' != $lesson_preview) {
1743 1743
 				$is_preview = true;
1744 1744
 			}
1745 1745
 		}
@@ -1747,22 +1747,22 @@  discard block
 block discarded – undo
1747 1747
 		return $is_preview;
1748 1748
 	}
1749 1749
 
1750
-	public static function user_passed_quiz( $quiz_id = 0, $user_id = 0 ) {
1750
+	public static function user_passed_quiz($quiz_id = 0, $user_id = 0) {
1751 1751
 
1752
-		if( ! $quiz_id  ) return false;
1752
+		if ( ! $quiz_id) return false;
1753 1753
 
1754
-		if( ! $user_id ) {
1754
+		if ( ! $user_id) {
1755 1755
 			$user_id = get_current_user_id();
1756 1756
 		}
1757
-		$lesson_id = get_post_meta( $quiz_id, '_quiz_lesson', true );
1757
+		$lesson_id = get_post_meta($quiz_id, '_quiz_lesson', true);
1758 1758
 
1759 1759
 		// Quiz Grade
1760
-		$lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1761
-		$quiz_grade = get_comment_meta( $lesson_status->comment_ID, 'grade', true );
1760
+		$lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1761
+		$quiz_grade = get_comment_meta($lesson_status->comment_ID, 'grade', true);
1762 1762
 
1763 1763
 		// Check if Grade is greater than or equal to pass percentage
1764
-		$quiz_passmark = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
1765
-		if ( $quiz_passmark <= intval( $quiz_grade ) ) {
1764
+		$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
1765
+		if ($quiz_passmark <= intval($quiz_grade)) {
1766 1766
 			return true;
1767 1767
 		}
1768 1768
 
@@ -1782,9 +1782,9 @@  discard block
 block discarded – undo
1782 1782
      *
1783 1783
 	 * @return mixed false or comment_ID
1784 1784
 	 */
1785
-	public static function update_lesson_status( $user_id, $lesson_id, $status = 'in-progress', $metadata = array() ) {
1785
+	public static function update_lesson_status($user_id, $lesson_id, $status = 'in-progress', $metadata = array()) {
1786 1786
 		$comment_id = false;
1787
-		if ( !empty($status) ) {
1787
+		if ( ! empty($status)) {
1788 1788
 			$args = array(
1789 1789
 					'user_id'   => $user_id,
1790 1790
 					'post_id'   => $lesson_id,
@@ -1793,18 +1793,18 @@  discard block
 block discarded – undo
1793 1793
 					'action'    => 'update', // Update the existing status...
1794 1794
 					'keep_time' => true, // ...but don't change the existing timestamp
1795 1795
 				);
1796
-			if( 'in-progress' == $status ) {
1797
-				unset( $args['keep_time'] ); // Keep updating what's happened
1796
+			if ('in-progress' == $status) {
1797
+				unset($args['keep_time']); // Keep updating what's happened
1798 1798
 			}
1799 1799
 
1800
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1801
-			if ( $comment_id && !empty($metadata) ) {
1802
-				foreach( $metadata as $key => $value ) {
1803
-					update_comment_meta( $comment_id, $key, $value );
1800
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1801
+			if ($comment_id && ! empty($metadata)) {
1802
+				foreach ($metadata as $key => $value) {
1803
+					update_comment_meta($comment_id, $key, $value);
1804 1804
 				}
1805 1805
 			}
1806 1806
 
1807
-			do_action( 'sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id );
1807
+			do_action('sensei_lesson_status_updated', $status, $user_id, $lesson_id, $comment_id);
1808 1808
 		}
1809 1809
 		return $comment_id;
1810 1810
 	}
@@ -1820,9 +1820,9 @@  discard block
 block discarded – undo
1820 1820
 	 * @param array $metadata
1821 1821
 	 * @return mixed false or comment_ID
1822 1822
 	 */
1823
-	public static function update_course_status( $user_id, $course_id, $status = 'in-progress', $metadata = array() ) {
1823
+	public static function update_course_status($user_id, $course_id, $status = 'in-progress', $metadata = array()) {
1824 1824
 		$comment_id = false;
1825
-		if ( !empty($status) ) {
1825
+		if ( ! empty($status)) {
1826 1826
 			$args = array(
1827 1827
 					'user_id'   => $user_id,
1828 1828
 					'post_id'   => $course_id,
@@ -1831,17 +1831,17 @@  discard block
 block discarded – undo
1831 1831
 					'action'    => 'update', // Update the existing status...
1832 1832
 					'keep_time' => true, // ...but don't change the existing timestamp
1833 1833
 				);
1834
-			if( 'in-progress' == $status ) {
1835
-				unset( $args['keep_time'] ); // Keep updating what's happened
1834
+			if ('in-progress' == $status) {
1835
+				unset($args['keep_time']); // Keep updating what's happened
1836 1836
 			}
1837 1837
 
1838
-			$comment_id = Sensei_Utils::sensei_log_activity( $args );
1839
-			if ( $comment_id && !empty($metadata) ) {
1840
-				foreach( $metadata as $key => $value ) {
1841
-					update_comment_meta( $comment_id, $key, $value );
1838
+			$comment_id = Sensei_Utils::sensei_log_activity($args);
1839
+			if ($comment_id && ! empty($metadata)) {
1840
+				foreach ($metadata as $key => $value) {
1841
+					update_comment_meta($comment_id, $key, $value);
1842 1842
 				}
1843 1843
 			}
1844
-			do_action( 'sensei_course_status_updated', $status, $user_id, $course_id, $comment_id );
1844
+			do_action('sensei_course_status_updated', $status, $user_id, $course_id, $comment_id);
1845 1845
 		}
1846 1846
 		return $comment_id;
1847 1847
 	}
@@ -1853,9 +1853,9 @@  discard block
 block discarded – undo
1853 1853
 	 * @param  array $pieces (default: array())
1854 1854
 	 * @return array
1855 1855
 	 */
1856
-	public static function single_comment_filter( $pieces ) {
1857
-		unset( $pieces['orderby'] );
1858
-		unset( $pieces['order'] );
1856
+	public static function single_comment_filter($pieces) {
1857
+		unset($pieces['orderby']);
1858
+		unset($pieces['order']);
1859 1859
 
1860 1860
 		return $pieces;
1861 1861
 	}
@@ -1867,9 +1867,9 @@  discard block
 block discarded – undo
1867 1867
 	 * @param  array $pieces (default: array())
1868 1868
 	 * @return array
1869 1869
 	 */
1870
-	public static function comment_any_status_filter( $pieces ) {
1870
+	public static function comment_any_status_filter($pieces) {
1871 1871
 
1872
-		$pieces['where'] = str_replace( array( "( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND" ), '', $pieces['where'] );
1872
+		$pieces['where'] = str_replace(array("( comment_approved = '0' OR comment_approved = '1' ) AND", "comment_approved = 'any' AND"), '', $pieces['where']);
1873 1873
 
1874 1874
 		return $pieces;
1875 1875
 	}
@@ -1881,12 +1881,12 @@  discard block
 block discarded – undo
1881 1881
 	 * @param  array $pieces (default: array())
1882 1882
 	 * @return array
1883 1883
 	 */
1884
-	public static function comment_multiple_status_filter( $pieces ) {
1884
+	public static function comment_multiple_status_filter($pieces) {
1885 1885
 
1886
-		preg_match( "/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder );
1887
-		if ( !empty($placeholder[1]) ) {
1888
-			$statuses = explode( ',', $placeholder[1] );
1889
-			$pieces['where'] = str_replace( "comment_approved = '" . $placeholder[1] . "'", "comment_approved IN ('". implode( "', '", $statuses ) . "')", $pieces['where'] );
1886
+		preg_match("/^comment_approved = '([a-z\-\,]+)'/", $pieces['where'], $placeholder);
1887
+		if ( ! empty($placeholder[1])) {
1888
+			$statuses = explode(',', $placeholder[1]);
1889
+			$pieces['where'] = str_replace("comment_approved = '".$placeholder[1]."'", "comment_approved IN ('".implode("', '", $statuses)."')", $pieces['where']);
1890 1890
 		}
1891 1891
 
1892 1892
 		return $pieces;
@@ -1898,12 +1898,12 @@  discard block
 block discarded – undo
1898 1898
      * @param array $pieces
1899 1899
 	 * @return array $pieces
1900 1900
 	 */
1901
-	public static function comment_total_sum_meta_value_filter( $pieces ) {
1901
+	public static function comment_total_sum_meta_value_filter($pieces) {
1902 1902
 		global $wpdb, $wp_version;
1903 1903
 
1904 1904
 		$pieces['fields'] = " COUNT(*) AS total, SUM($wpdb->commentmeta.meta_value) AS meta_sum ";
1905
-		unset( $pieces['groupby'] );
1906
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1905
+		unset($pieces['groupby']);
1906
+		if (version_compare($wp_version, '4.1', '>=')) {
1907 1907
 			$args['order'] = false;
1908 1908
 			$args['orderby'] = false;
1909 1909
 		}
@@ -1918,12 +1918,12 @@  discard block
 block discarded – undo
1918 1918
 	 * @param  array $pieces (default: array())
1919 1919
 	 * @return array
1920 1920
 	 */
1921
-	public static function get_posts_count_only_filter( $pieces ) {
1921
+	public static function get_posts_count_only_filter($pieces) {
1922 1922
 		global $wp_version;
1923 1923
 
1924 1924
 		$pieces['fields'] = " COUNT(*) AS total ";
1925
-		unset( $pieces['groupby'] );
1926
-		if ( version_compare($wp_version, '4.1', '>=') ) {
1925
+		unset($pieces['groupby']);
1926
+		if (version_compare($wp_version, '4.1', '>=')) {
1927 1927
 			$args['order'] = false;
1928 1928
 			$args['orderby'] = false;
1929 1929
 		}
@@ -1942,9 +1942,9 @@  discard block
 block discarded – undo
1942 1942
      *
1943 1943
      * @return bool $success
1944 1944
      */
1945
-    public static function add_user_data( $data_key, $post_id , $value = '' , $user_id = 0  ){
1945
+    public static function add_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1946 1946
 
1947
-        return self::update_user_data( $data_key, $post_id, $value , $user_id );
1947
+        return self::update_user_data($data_key, $post_id, $value, $user_id);
1948 1948
 
1949 1949
     }// end add_user_data
1950 1950
 
@@ -1963,18 +1963,18 @@  discard block
 block discarded – undo
1963 1963
      *
1964 1964
      * @return bool $success
1965 1965
      */
1966
-    public static function update_user_data( $data_key, $post_id, $value = '' , $user_id = 0  ){
1966
+    public static function update_user_data($data_key, $post_id, $value = '', $user_id = 0) {
1967 1967
 
1968
-        if( ! ( $user_id > 0 ) ){
1968
+        if ( ! ($user_id > 0)) {
1969 1969
             $user_id = get_current_user_id();
1970 1970
         }
1971 1971
 
1972
-        $supported_post_types = array( 'course', 'lesson' );
1973
-        $post_type = get_post_type( $post_id );
1974
-        if( empty( $post_id ) || empty( $data_key )
1975
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
1976
-            || !get_userdata( $user_id )
1977
-            || ! in_array( $post_type, $supported_post_types )  ){
1972
+        $supported_post_types = array('course', 'lesson');
1973
+        $post_type = get_post_type($post_id);
1974
+        if (empty($post_id) || empty($data_key)
1975
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
1976
+            || ! get_userdata($user_id)
1977
+            || ! in_array($post_type, $supported_post_types)) {
1978 1978
 
1979 1979
             return false;
1980 1980
         }
@@ -1982,20 +1982,20 @@  discard block
 block discarded – undo
1982 1982
         // check if there and existing Sensei status on this post type if not create it
1983 1983
         // and get the  activity ID
1984 1984
         $status_function = 'user_'.$post_type.'_status';
1985
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
1986
-        if( ! isset( $sensei_user_status->comment_ID ) ){
1985
+        $sensei_user_status = self::$status_function($post_id, $user_id);
1986
+        if ( ! isset($sensei_user_status->comment_ID)) {
1987 1987
 
1988 1988
             $start_function = 'user_start_'.$post_type;
1989
-            $sensei_user_activity_id = self::$start_function( $user_id, $post_id );
1989
+            $sensei_user_activity_id = self::$start_function($user_id, $post_id);
1990 1990
 
1991
-        }else{
1991
+        } else {
1992 1992
 
1993 1993
             $sensei_user_activity_id = $sensei_user_status->comment_ID;
1994 1994
 
1995 1995
         }
1996 1996
 
1997 1997
         // store the data
1998
-        $success = update_comment_meta( $sensei_user_activity_id, $data_key, $value );
1998
+        $success = update_comment_meta($sensei_user_activity_id, $data_key, $value);
1999 1999
 
2000 2000
        return $success;
2001 2001
 
@@ -2014,20 +2014,20 @@  discard block
 block discarded – undo
2014 2014
      *
2015 2015
      * @return mixed $user_data_value
2016 2016
      */
2017
-    public static function get_user_data( $data_key, $post_id, $user_id = 0  ){
2017
+    public static function get_user_data($data_key, $post_id, $user_id = 0) {
2018 2018
 
2019 2019
         $user_data_value = true;
2020 2020
 
2021
-        if( ! ( $user_id > 0 ) ){
2021
+        if ( ! ($user_id > 0)) {
2022 2022
             $user_id = get_current_user_id();
2023 2023
         }
2024 2024
 
2025
-        $supported_post_types = array( 'course', 'lesson' );
2026
-        $post_type = get_post_type( $post_id );
2027
-        if( empty( $post_id ) || empty( $data_key )
2028
-            || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2029
-            || ! get_userdata( $user_id )
2030
-            || !in_array( $post_type, $supported_post_types )  ){
2025
+        $supported_post_types = array('course', 'lesson');
2026
+        $post_type = get_post_type($post_id);
2027
+        if (empty($post_id) || empty($data_key)
2028
+            || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2029
+            || ! get_userdata($user_id)
2030
+            || ! in_array($post_type, $supported_post_types)) {
2031 2031
 
2032 2032
             return false;
2033 2033
         }
@@ -2035,13 +2035,13 @@  discard block
 block discarded – undo
2035 2035
         // check if there and existing Sensei status on this post type if not create it
2036 2036
         // and get the  activity ID
2037 2037
         $status_function = 'user_'.$post_type.'_status';
2038
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2039
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2038
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2039
+        if ( ! isset($sensei_user_status->comment_ID)) {
2040 2040
             return false;
2041 2041
         }
2042 2042
 
2043 2043
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2044
-        $user_data_value = get_comment_meta( $sensei_user_activity_id , $data_key, true );
2044
+        $user_data_value = get_comment_meta($sensei_user_activity_id, $data_key, true);
2045 2045
 
2046 2046
         return $user_data_value;
2047 2047
 
@@ -2056,19 +2056,19 @@  discard block
 block discarded – undo
2056 2056
      *
2057 2057
      * @return bool $deleted
2058 2058
      */
2059
-    public static function delete_user_data( $data_key, $post_id , $user_id ){
2059
+    public static function delete_user_data($data_key, $post_id, $user_id) {
2060 2060
         $deleted = true;
2061 2061
 
2062
-        if( ! ( $user_id > 0 ) ){
2062
+        if ( ! ($user_id > 0)) {
2063 2063
             $user_id = get_current_user_id();
2064 2064
         }
2065 2065
 
2066
-        $supported_post_types = array( 'course', 'lesson' );
2067
-        $post_type = get_post_type( $post_id );
2068
-        if( empty( $post_id ) || empty( $data_key )
2069
-            || ! is_int( $post_id ) || ! ( intval( $post_id ) > 0 ) || ! ( intval( $user_id ) > 0 )
2070
-            || ! get_userdata( $user_id )
2071
-            || !in_array( $post_type, $supported_post_types )  ){
2066
+        $supported_post_types = array('course', 'lesson');
2067
+        $post_type = get_post_type($post_id);
2068
+        if (empty($post_id) || empty($data_key)
2069
+            || ! is_int($post_id) || ! (intval($post_id) > 0) || ! (intval($user_id) > 0)
2070
+            || ! get_userdata($user_id)
2071
+            || ! in_array($post_type, $supported_post_types)) {
2072 2072
 
2073 2073
             return false;
2074 2074
         }
@@ -2076,13 +2076,13 @@  discard block
 block discarded – undo
2076 2076
         // check if there and existing Sensei status on this post type if not create it
2077 2077
         // and get the  activity ID
2078 2078
         $status_function = 'user_'.$post_type.'_status';
2079
-        $sensei_user_status = self::$status_function( $post_id ,$user_id  );
2080
-        if( ! isset( $sensei_user_status->comment_ID ) ){
2079
+        $sensei_user_status = self::$status_function($post_id, $user_id);
2080
+        if ( ! isset($sensei_user_status->comment_ID)) {
2081 2081
             return false;
2082 2082
         }
2083 2083
 
2084 2084
         $sensei_user_activity_id = $sensei_user_status->comment_ID;
2085
-        $deleted = delete_comment_meta( $sensei_user_activity_id , $data_key );
2085
+        $deleted = delete_comment_meta($sensei_user_activity_id, $data_key);
2086 2086
 
2087 2087
         return $deleted;
2088 2088
 
@@ -2107,62 +2107,62 @@  discard block
 block discarded – undo
2107 2107
      *
2108 2108
      * @return string $drop_down_element
2109 2109
      */
2110
-    public static function generate_drop_down( $selected_value, $options = array() , $attributes = array(), $enable_none_option = true ) {
2110
+    public static function generate_drop_down($selected_value, $options = array(), $attributes = array(), $enable_none_option = true) {
2111 2111
 
2112 2112
         $drop_down_element = '';
2113 2113
 
2114 2114
         // setup the basic attributes
2115
-        if( !isset( $attributes['name'] ) || empty( $attributes['name']  ) ) {
2115
+        if ( ! isset($attributes['name']) || empty($attributes['name'])) {
2116 2116
 
2117 2117
             $attributes['name'] = 'sensei-options';
2118 2118
 
2119 2119
         }
2120 2120
 
2121
-        if( !isset( $attributes['id'] ) || empty( $attributes['id']  ) ) {
2121
+        if ( ! isset($attributes['id']) || empty($attributes['id'])) {
2122 2122
 
2123 2123
             $attributes['id'] = 'sensei-options';
2124 2124
 
2125 2125
         }
2126 2126
 
2127
-        if( !isset( $attributes['class'] ) || empty( $attributes['class']  ) ) {
2127
+        if ( ! isset($attributes['class']) || empty($attributes['class'])) {
2128 2128
 
2129
-            $attributes['class'] ='chosen_select widefat';
2129
+            $attributes['class'] = 'chosen_select widefat';
2130 2130
 
2131 2131
         }
2132 2132
 
2133 2133
         // create element attributes
2134 2134
         $combined_attributes = '';
2135
-        foreach( $attributes as $attribute => $value ){
2135
+        foreach ($attributes as $attribute => $value) {
2136 2136
 
2137
-            $combined_attributes .= $attribute . '="'.$value.'"' . ' ';
2137
+            $combined_attributes .= $attribute.'="'.$value.'"'.' ';
2138 2138
 
2139 2139
         }// end for each
2140 2140
 
2141 2141
 
2142 2142
         // create the select element
2143
-        $drop_down_element .= '<select '. $combined_attributes . ' >' . "\n";
2143
+        $drop_down_element .= '<select '.$combined_attributes.' >'."\n";
2144 2144
 
2145 2145
         // show the none option if the client requested
2146
-        if( $enable_none_option ) {
2147
-            $drop_down_element .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
2146
+        if ($enable_none_option) {
2147
+            $drop_down_element .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
2148 2148
         }
2149 2149
 
2150
-        if ( count( $options ) > 0 ) {
2150
+        if (count($options) > 0) {
2151 2151
 
2152
-            foreach ($options as $value => $option ){
2152
+            foreach ($options as $value => $option) {
2153 2153
 
2154 2154
                 $element = '';
2155
-                $element.= '<option value="' . esc_attr( $value ) . '"';
2156
-                $element .= selected( $value, $selected_value, false ) . '>';
2157
-                $element .= esc_html(  $option ) . '</option>' . "\n";
2155
+                $element .= '<option value="'.esc_attr($value).'"';
2156
+                $element .= selected($value, $selected_value, false).'>';
2157
+                $element .= esc_html($option).'</option>'."\n";
2158 2158
 
2159 2159
                 // add the element to the select html
2160
-                $drop_down_element.= $element;
2160
+                $drop_down_element .= $element;
2161 2161
             } // End For Loop
2162 2162
 
2163 2163
         } // End If Statement
2164 2164
 
2165
-        $drop_down_element .= '</select>' . "\n";
2165
+        $drop_down_element .= '</select>'."\n";
2166 2166
 
2167 2167
         return $drop_down_element;
2168 2168
 
@@ -2182,14 +2182,14 @@  discard block
 block discarded – undo
2182 2182
      *
2183 2183
      * @return double $val
2184 2184
      */
2185
-    public static function round( $val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = ''  ){
2185
+    public static function round($val, $precision = 0, $mode = PHP_ROUND_HALF_UP, $context = '') {
2186 2186
 
2187 2187
         /**å
2188 2188
          * Change the precision for the Sensei_Utils::round function.
2189 2189
          * the precision given will be passed into the php round function
2190 2190
          * @since 1.8.5
2191 2191
          */
2192
-        $precision = apply_filters( 'sensei_round_precision', $precision , $val, $context, $mode );
2192
+        $precision = apply_filters('sensei_round_precision', $precision, $val, $context, $mode);
2193 2193
 
2194 2194
         /**
2195 2195
          * Change the mode for the Sensei_Utils::round function.
@@ -2199,15 +2199,15 @@  discard block
 block discarded – undo
2199 2199
          *
2200 2200
          * @since 1.8.5
2201 2201
          */
2202
-        $mode = apply_filters( 'sensei_round_mode', $mode , $val, $context, $precision   );
2202
+        $mode = apply_filters('sensei_round_mode', $mode, $val, $context, $precision);
2203 2203
 
2204
-        if ( version_compare(PHP_VERSION, '5.3.0') >= 0 ) {
2204
+        if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
2205 2205
 
2206
-            return round( $val, $precision, $mode );
2206
+            return round($val, $precision, $mode);
2207 2207
 
2208
-        }else{
2208
+        } else {
2209 2209
 
2210
-            return round( $val, $precision );
2210
+            return round($val, $precision);
2211 2211
 
2212 2212
         }
2213 2213
 
@@ -2219,15 +2219,15 @@  discard block
 block discarded – undo
2219 2219
      * @since 1.9.0
2220 2220
      * @return string $url
2221 2221
      */
2222
-    public static function get_current_url(){
2222
+    public static function get_current_url() {
2223 2223
 
2224 2224
         global $wp;
2225
-        $current_url = trailingslashit( home_url( $wp->request ) );
2226
-        if ( isset( $_GET ) ) {
2225
+        $current_url = trailingslashit(home_url($wp->request));
2226
+        if (isset($_GET)) {
2227 2227
 
2228
-            foreach ($_GET as $param => $val ) {
2228
+            foreach ($_GET as $param => $val) {
2229 2229
 
2230
-                $current_url = add_query_arg( $param, $val , $current_url );
2230
+                $current_url = add_query_arg($param, $val, $current_url);
2231 2231
 
2232 2232
             }
2233 2233
         }
@@ -2257,27 +2257,27 @@  discard block
 block discarded – undo
2257 2257
      * @param array $array_b
2258 2258
      * @return array $merged_array
2259 2259
      */
2260
-    public static function array_zip_merge( $array_a, $array_b ){
2260
+    public static function array_zip_merge($array_a, $array_b) {
2261 2261
 
2262
-        if( ! is_array( $array_a ) || ! is_array( $array_b )  ){
2262
+        if ( ! is_array($array_a) || ! is_array($array_b)) {
2263 2263
             trigger_error('array_zip_merge requires both arrays to be indexed arrays ');
2264 2264
         }
2265 2265
 
2266 2266
         $merged_array = array();
2267
-        $total_elements = count( $array_a )  + count( $array_b );
2267
+        $total_elements = count($array_a) + count($array_b);
2268 2268
 
2269 2269
         // Zip arrays
2270
-        for ( $i = 0; $i < $total_elements; $i++) {
2270
+        for ($i = 0; $i < $total_elements; $i++) {
2271 2271
 
2272 2272
             // if has an element at current index push a on top
2273
-            if( isset( $array_a[ $i ] ) ){
2274
-                $merged_array[] = $array_a[ $i ]  ;
2273
+            if (isset($array_a[$i])) {
2274
+                $merged_array[] = $array_a[$i];
2275 2275
             }
2276 2276
 
2277 2277
             // next if $array_b has an element at current index push a on top of the element
2278 2278
             // from a if there was one, if not the element before that.
2279
-            if( isset( $array_b[ $i ] ) ){
2280
-                $merged_array[] = $array_b[ $i ]  ;
2279
+            if (isset($array_b[$i])) {
2280
+                $merged_array[] = $array_b[$i];
2281 2281
             }
2282 2282
 
2283 2283
         }
@@ -2292,4 +2292,4 @@  discard block
 block discarded – undo
2292 2292
  * @ignore only for backward compatibility
2293 2293
  * @since 1.9.0
2294 2294
  */
2295
-class WooThemes_Sensei_Utils extends Sensei_Utils{}
2296 2295
\ No newline at end of file
2296
+class WooThemes_Sensei_Utils extends Sensei_Utils {}
2297 2297
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-sensei-wc.php 1 patch
Spacing   +321 added lines, -321 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; // security check, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 
4 4
 /**
5 5
  * Sensei WooCommerce class
@@ -11,17 +11,17 @@  discard block
 block discarded – undo
11 11
  * @since 1.9.0
12 12
  */
13 13
 
14
-Class Sensei_WC{
14
+Class Sensei_WC {
15 15
 
16 16
     /**
17 17
      * Load the files needed for the woocommerce integration.
18 18
      *
19 19
      * @since 1.9.0
20 20
      */
21
-    public static function load_woocommerce_integration_hooks(){
21
+    public static function load_woocommerce_integration_hooks() {
22 22
 
23
-	    $woocommerce_hooks_file_path = Sensei()->plugin_path() . 'includes/hooks/woocommerce.php';
24
-        require_once( $woocommerce_hooks_file_path );
23
+	    $woocommerce_hooks_file_path = Sensei()->plugin_path().'includes/hooks/woocommerce.php';
24
+        require_once($woocommerce_hooks_file_path);
25 25
 
26 26
     }
27 27
     /**
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
      * @since 1.9.0
31 31
      * @return bool
32 32
      */
33
-    public static function is_woocommerce_active(){
33
+    public static function is_woocommerce_active() {
34 34
 
35
-        $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled'];
35
+        $is_woocommerce_enabled_in_settings = isset(Sensei()->settings->settings['woocommerce_enabled']) && Sensei()->settings->settings['woocommerce_enabled'];
36 36
         return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings;
37 37
 
38 38
     } // end is_woocommerce_active
@@ -47,19 +47,19 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return bool
49 49
      */
50
-    public static function is_woocommerce_present(){
50
+    public static function is_woocommerce_present() {
51 51
 
52
-        $active_plugins = (array) get_option( 'active_plugins', array() );
52
+        $active_plugins = (array) get_option('active_plugins', array());
53 53
 
54
-        if ( is_multisite() ){
54
+        if (is_multisite()) {
55 55
 
56
-            $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
56
+            $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
57 57
 
58 58
         }
59 59
 
60
-        $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins );
60
+        $is_woocommerce_plugin_present_and_activated = in_array('woocommerce/woocommerce.php', $active_plugins) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
61 61
 
62
-        return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated;
62
+        return class_exists('Woocommerce') || $is_woocommerce_plugin_present_and_activated;
63 63
 
64 64
     }// end is_woocommerce_present
65 65
 
@@ -72,48 +72,48 @@  discard block
 block discarded – undo
72 72
      * @param $course_id
73 73
      * @return array $user_course_orders
74 74
      */
75
-    public static function get_learner_course_active_order_id( $user_id, $course_id ){
75
+    public static function get_learner_course_active_order_id($user_id, $course_id) {
76 76
 
77
-        $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
77
+        $course_product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
78 78
 
79
-        $orders_query = new WP_Query( array(
79
+        $orders_query = new WP_Query(array(
80 80
             'post_type'   => 'shop_order',
81 81
             'posts_per_page' => -1,
82
-            'post_status' => array( 'wc-processing', 'wc-completed' ),
82
+            'post_status' => array('wc-processing', 'wc-completed'),
83 83
             'meta_key'=> '_customer_user',
84 84
             'meta_value'=> $user_id,
85
-        ) );
85
+        ));
86 86
 
87
-        if( $orders_query->post_count == 0 ){
87
+        if ($orders_query->post_count == 0) {
88 88
 
89 89
             return false;
90 90
 
91 91
         }
92 92
 
93
-        foreach( $orders_query->get_posts() as $order ){
93
+        foreach ($orders_query->get_posts() as $order) {
94 94
 
95
-            $order = new WC_Order( $order->ID );
95
+            $order = new WC_Order($order->ID);
96 96
             $items = $order->get_items();
97 97
 
98
-            $user_orders =  array();
98
+            $user_orders = array();
99 99
 
100
-            foreach( $items as $item ){
100
+            foreach ($items as $item) {
101 101
 
102 102
                 // if the product id on the order and the one given to this function
103 103
                 // this order has been placed by the given user on the given course.
104
-                $product = wc_get_product( $item['product_id'] );
104
+                $product = wc_get_product($item['product_id']);
105 105
 
106
-                if ( is_object( $product ) && $product->is_type( 'variable' )) {
106
+                if (is_object($product) && $product->is_type('variable')) {
107 107
 
108 108
                     $item_product_id = $item['variation_id'];
109 109
 
110 110
                 } else {
111 111
 
112
-                    $item_product_id =  $item['product_id'];
112
+                    $item_product_id = $item['product_id'];
113 113
 
114 114
                 }
115 115
 
116
-                if( $course_product_id == $item_product_id ){
116
+                if ($course_product_id == $item_product_id) {
117 117
 
118 118
                     return $order->id;
119 119
 
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
      * @param $filter_links
138 138
      * @return mixed
139 139
      */
140
-    public static function add_course_archive_wc_filter_links( $filter_links ){
140
+    public static function add_course_archive_wc_filter_links($filter_links) {
141 141
 
142 142
         $free_courses = self::get_free_courses();
143 143
         $paid_courses = self::get_paid_courses();
144 144
 
145
-        if ( empty( $free_courses ) || empty( $paid_courses )  ){
145
+        if (empty($free_courses) || empty($paid_courses)) {
146 146
             // do not show any WooCommerce filters if all courses are
147 147
             // free or if all courses are paid
148 148
             return $filter_links;
@@ -150,15 +150,15 @@  discard block
 block discarded – undo
150 150
         }
151 151
 
152 152
         $filter_links[] = array(
153
-            'id'=>'paid' ,
154
-            'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ),
155
-            'title'=>__( 'Paid', 'woothemes-sensei' )
153
+            'id'=>'paid',
154
+            'url'=> add_query_arg(array('course_filter'=>'paid'), Sensei_Course::get_courses_page_url()),
155
+            'title'=>__('Paid', 'woothemes-sensei')
156 156
         );
157 157
 
158 158
         $filter_links[] = array(
159 159
             'id'=>'free',
160
-            'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ),
161
-            'title'=>__( 'Free', 'woothemes-sensei' )
160
+            'url'=> add_query_arg(array('course_filter'=>'free'), Sensei_Course::get_courses_page_url()),
161
+            'title'=>__('Free', 'woothemes-sensei')
162 162
         );
163 163
 
164 164
         return $filter_links;
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
      * @param WP_Query $query
176 176
      * @return WP_Query $query
177 177
      */
178
-    public static function course_archive_wc_filter_free( $query ){
178
+    public static function course_archive_wc_filter_free($query) {
179 179
 
180
-        if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter']
181
-            && 'course' == $query->get( 'post_type') && $query->is_main_query()  ){
180
+        if (isset($_GET['course_filter']) && 'free' == $_GET['course_filter']
181
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
182 182
 
183 183
             // setup the course meta query
184 184
             $meta_query = self::get_free_courses_meta_query_args();
185 185
 
186 186
             // manipulate the query to return free courses
187
-            $query->set('meta_query', $meta_query );
187
+            $query->set('meta_query', $meta_query);
188 188
 
189 189
             // don't show any paid courses
190 190
             $courses = self::get_paid_courses();
191 191
             $ids = array();
192
-            foreach( $courses as $course ){
192
+            foreach ($courses as $course) {
193 193
                 $ids[] = $course->ID;
194 194
             }
195
-            $query->set( 'post__not_in', $ids );
195
+            $query->set('post__not_in', $ids);
196 196
 
197 197
         }// end if course_filter
198 198
 
@@ -211,16 +211,16 @@  discard block
 block discarded – undo
211 211
      * @param WP_Query $query
212 212
      * @return WP_Query $query
213 213
      */
214
-    public static function course_archive_wc_filter_paid( $query ){
214
+    public static function course_archive_wc_filter_paid($query) {
215 215
 
216
-        if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter']
217
-            && 'course' == $query->get( 'post_type') && $query->is_main_query() ){
216
+        if (isset($_GET['course_filter']) && 'paid' == $_GET['course_filter']
217
+            && 'course' == $query->get('post_type') && $query->is_main_query()) {
218 218
 
219 219
             // setup the course meta query
220 220
             $meta_query = self::get_paid_courses_meta_query_args();
221 221
 
222 222
             // manipulate the query to return free courses
223
-            $query->set('meta_query', $meta_query );
223
+            $query->set('meta_query', $meta_query);
224 224
 
225 225
         }
226 226
 
@@ -233,14 +233,14 @@  discard block
 block discarded – undo
233 233
      * single courses if woocommerce is active allowing purchase
234 234
      * information and actions to be hooked from WooCommerce.
235 235
      */
236
-    public static function do_single_course_wc_single_product_action(){
236
+    public static function do_single_course_wc_single_product_action() {
237 237
 
238 238
         /**
239 239
          * this hooks is documented within the WooCommerce plugin.
240 240
          */
241
-        if ( Sensei_WC::is_woocommerce_active() ) {
241
+        if (Sensei_WC::is_woocommerce_active()) {
242 242
 
243
-            do_action( 'woocommerce_before_single_product' );
243
+            do_action('woocommerce_before_single_product');
244 244
 
245 245
         } // End If Statement
246 246
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
      * @param $user_id
262 262
      * @return bool
263 263
      */
264
-    public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id  ){
264
+    public static function alter_can_user_view_lesson($can_user_view_lesson, $lesson_id, $user_id) {
265 265
 
266 266
 	    // do not override access to admins
267
-	    $course_id = Sensei()->lesson->get_course_id( $lesson_id );
268
-	    if ( sensei_all_access() || Sensei_Utils::is_preview_lesson( $lesson_id )
269
-	         || Sensei_Utils::user_started_course( $course_id, $user_id )  ){
267
+	    $course_id = Sensei()->lesson->get_course_id($lesson_id);
268
+	    if (sensei_all_access() || Sensei_Utils::is_preview_lesson($lesson_id)
269
+	         || Sensei_Utils::user_started_course($course_id, $user_id)) {
270 270
 
271 271
 			return true;
272 272
 
@@ -275,18 +275,18 @@  discard block
 block discarded – undo
275 275
         // check if the course has a valid product attached to it
276 276
         // which the user should have purchased if they want to access
277 277
         // the current lesson
278
-        $course_id = get_post_meta( $lesson_id , '_lesson_course', true);
279
-        $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true );
278
+        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
279
+        $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true);
280 280
         $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id);
281
-        if( isset ($product) && is_object($product) ){
281
+        if (isset ($product) && is_object($product)) {
282 282
 
283 283
             // valid product found
284
-            $order_id = self::get_learner_course_active_order_id( $user_id, $course_id );
284
+            $order_id = self::get_learner_course_active_order_id($user_id, $course_id);
285 285
 
286 286
             // product has a successful order so this user may access the content
287 287
             // this function may only return false or the default
288 288
             // returning true may override other negatives which we don't want
289
-            if( ! $order_id ){
289
+            if ( ! $order_id) {
290 290
 
291 291
                 return false;
292 292
 
@@ -309,23 +309,23 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public static function course_link_from_order( ) {
311 311
 
312
-        if( ! is_order_received_page() ){
312
+        if ( ! is_order_received_page()) {
313 313
             return;
314 314
         }
315 315
 
316
-        $order_id = get_query_var( 'order-received' );
317
-		$order = new WC_Order( $order_id );
316
+        $order_id = get_query_var('order-received');
317
+		$order = new WC_Order($order_id);
318 318
 
319 319
 		// exit early if not wc-completed or wc-processing
320
-		if( 'wc-completed' != $order->post_status
321
-            && 'wc-processing' != $order->post_status  ) {
320
+		if ('wc-completed' != $order->post_status
321
+            && 'wc-processing' != $order->post_status) {
322 322
             return;
323 323
         }
324 324
 
325 325
         $course_links = array(); // store the for links for courses purchased
326
-		foreach ( $order->get_items() as $item ) {
326
+		foreach ($order->get_items() as $item) {
327 327
 
328
-            if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
328
+            if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
329 329
 
330 330
                 // If item has variation_id then its a variation of the product
331 331
                 $item_id = $item['variation_id'];
@@ -337,28 +337,28 @@  discard block
 block discarded – undo
337 337
 
338 338
             } // End If Statement
339 339
 
340
-            $user_id = get_post_meta( $order->id, '_customer_user', true );
340
+            $user_id = get_post_meta($order->id, '_customer_user', true);
341 341
 
342
-            if( $user_id ) {
342
+            if ($user_id) {
343 343
 
344 344
                 // Get all courses for product
345 345
                 $args = Sensei_Course::get_default_query_args();
346
-                $args['meta_query'] = array( array(
346
+                $args['meta_query'] = array(array(
347 347
                             'key' => '_course_woocommerce_product',
348 348
                             'value' => $item_id
349
-                        ) );
349
+                        ));
350 350
                 $args['orderby'] = 'menu_order date';
351 351
                 $args['order'] = 'ASC';
352 352
 
353 353
                 // loop through courses
354
-                $courses = get_posts( $args );
355
-                if( $courses && count( $courses ) > 0 ) {
354
+                $courses = get_posts($args);
355
+                if ($courses && count($courses) > 0) {
356 356
 
357
-                    foreach( $courses as $course ) {
357
+                    foreach ($courses as $course) {
358 358
 
359 359
                         $title = $course->post_title;
360
-                        $permalink = get_permalink( $course->ID );
361
-                        $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> ';
360
+                        $permalink = get_permalink($course->ID);
361
+                        $course_links[] .= '<a href="'.esc_url($permalink).'" >'.$title.'</a> ';
362 362
 
363 363
                     } // end for each
364 364
 
@@ -369,24 +369,24 @@  discard block
 block discarded – undo
369 369
         }// end loop through orders
370 370
 
371 371
         // add the courses to the WooCommerce notice
372
-        if( ! empty( $course_links) ){
372
+        if ( ! empty($course_links)) {
373 373
 
374 374
             $courses_html = _nx(
375 375
                 'You have purchased the following course:',
376 376
                 'You have purchased the following courses:',
377
-                count( $course_links ),
377
+                count($course_links),
378 378
                 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei'
379 379
             );
380 380
 
381
-            foreach( $course_links as $link ){
381
+            foreach ($course_links as $link) {
382 382
 
383
-                $courses_html .= '<li>' . $link . '</li>';
383
+                $courses_html .= '<li>'.$link.'</li>';
384 384
 
385 385
             }
386 386
 
387 387
             $courses_html .= ' </ul>';
388 388
 
389
-            wc_add_notice( $courses_html, 'success' );
389
+            wc_add_notice($courses_html, 'success');
390 390
         }
391 391
 
392 392
 	} // end course_link_order_form
@@ -399,20 +399,20 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @since 1.9.0
401 401
      */
402
-    public static function course_in_cart_message(){
402
+    public static function course_in_cart_message() {
403 403
 
404 404
         global $post;
405 405
 
406
-        if( self::is_course_in_cart( $post->ID ) ){ ?>
406
+        if (self::is_course_in_cart($post->ID)) { ?>
407 407
 
408 408
             <div class="sensei-message info">
409 409
                 <?php
410 410
 
411
-                $cart_link =  '<a class="cart-complete" href="' . WC()->cart->get_checkout_url()
412
-                              . '" title="' . __('complete purchase', 'woothemes-sensei') . '">'
413
-                              . __('complete the purchase', 'woothemes-sensei') . '</a>';
411
+                $cart_link = '<a class="cart-complete" href="'.WC()->cart->get_checkout_url()
412
+                              . '" title="'.__('complete purchase', 'woothemes-sensei').'">'
413
+                              . __('complete the purchase', 'woothemes-sensei').'</a>';
414 414
 
415
-                echo sprintf(  __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link );
415
+                echo sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link);
416 416
 
417 417
                 ?>
418 418
             </div>
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
      * @param $course_id
427 427
      * @return bool
428 428
      */
429
-    public static function is_course_in_cart( $course_id ){
429
+    public static function is_course_in_cart($course_id) {
430 430
 
431
-        $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) );
432
-        $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() );
431
+        $wc_post_id = absint(get_post_meta($course_id, '_course_woocommerce_product', true));
432
+        $user_course_status_id = Sensei_Utils::user_started_course($course_id, get_current_user_id());
433 433
 
434
-        if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) {
434
+        if (0 < intval($wc_post_id) && ! $user_course_status_id) {
435 435
 
436
-            if ( self::is_product_in_cart( $wc_post_id ) ) {
436
+            if (self::is_product_in_cart($wc_post_id)) {
437 437
 
438 438
                 return true;
439 439
 
@@ -451,20 +451,20 @@  discard block
 block discarded – undo
451 451
      * @param $product_id
452 452
      * @return bool
453 453
      */
454
-    public static function is_product_in_cart( $product_id ){
454
+    public static function is_product_in_cart($product_id) {
455 455
 
456
-        if ( 0 < $product_id ) {
456
+        if (0 < $product_id) {
457 457
 
458
-            $product = wc_get_product( $product_id );
458
+            $product = wc_get_product($product_id);
459 459
 
460 460
             $parent_id = '';
461
-            if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) {
461
+            if (isset($product->variation_id) && 0 < intval($product->variation_id)) {
462 462
                 $wc_product_id = $product->parent->id;
463 463
             }
464
-            foreach( WC()->cart->get_cart() as $cart_item_key => $values ) {
464
+            foreach (WC()->cart->get_cart() as $cart_item_key => $values) {
465 465
 
466 466
                 $cart_product = $values['data'];
467
-                if( $product_id == $cart_product->id ) {
467
+                if ($product_id == $cart_product->id) {
468 468
 
469 469
                     return true;
470 470
 
@@ -486,9 +486,9 @@  discard block
 block discarded – undo
486 486
      *  @type int $wp_post_id
487 487
      * }
488 488
      */
489
-    public static function get_free_product_ids(){
489
+    public static function get_free_product_ids() {
490 490
 
491
-        return  get_posts( array(
491
+        return  get_posts(array(
492 492
             'post_type' => 'product',
493 493
             'posts_per_page' => '1000',
494 494
             'fields' => 'ids',
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      * @since 1.9.0
514 514
      * @return array $wp_meta_query_param
515 515
      */
516
-    public static function get_free_courses_meta_query_args(){
516
+    public static function get_free_courses_meta_query_args() {
517 517
 
518 518
         return array(
519 519
             'relation' => 'OR',
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
      * @since 1.9.0
538 538
      * @return array $wp_query_meta_query_args_param
539 539
      */
540
-    public static function get_paid_courses_meta_query_args(){
540
+    public static function get_paid_courses_meta_query_args() {
541 541
 
542 542
         $paid_product_ids = self::get_paid_product_ids();
543 543
 
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                 'key'     => '_course_woocommerce_product',
547 547
                 // when empty we give a false post_id to ensure the caller doesn't get any courses for their
548 548
                 // query
549
-                'value' => empty( $paid_product_ids  )? '-1000' : $paid_product_ids,
549
+                'value' => empty($paid_product_ids) ? '-1000' : $paid_product_ids,
550 550
                 'compare' => 'IN',
551 551
             ),
552 552
         );
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
      * @since 1.9.0
561 561
      * @return array $product_query_args
562 562
      */
563
-    public static function get_paid_products_on_sale_query_args(){
563
+    public static function get_paid_products_on_sale_query_args() {
564 564
 
565 565
         $args = array(
566 566
                    'post_type' 		=> 'product',
@@ -570,9 +570,9 @@  discard block
 block discarded – undo
570 570
                    'suppress_filters' 	=> 0
571 571
         );
572 572
 
573
-        $args[ 'fields' ]     = 'ids';
573
+        $args['fields']     = 'ids';
574 574
 
575
-        $args[ 'meta_query' ] = array(
575
+        $args['meta_query'] = array(
576 576
             'relation' => 'AND',
577 577
             array(
578 578
                 'key'=> '_regular_price',
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
      *
600 600
      * @return array
601 601
      */
602
-    public static function get_paid_products_not_on_sale_query_args(){
602
+    public static function get_paid_products_not_on_sale_query_args() {
603 603
 
604 604
         $args = array(
605 605
             'post_type' 		=> 'product',
@@ -609,8 +609,8 @@  discard block
 block discarded – undo
609 609
             'suppress_filters' 	=> 0
610 610
         );
611 611
 
612
-        $args[ 'fields' ]     = 'ids';
613
-        $args[ 'meta_query' ] = array(
612
+        $args['fields']     = 'ids';
613
+        $args['meta_query'] = array(
614 614
             'relation' => 'AND',
615 615
             array(
616 616
                 'key'=> '_regular_price',
@@ -636,24 +636,24 @@  discard block
 block discarded – undo
636 636
      *
637 637
      * @return array $woocommerce_paid_product_ids
638 638
      */
639
-    public static function get_paid_product_ids(){
639
+    public static function get_paid_product_ids() {
640 640
 
641 641
         // get all the paid WooCommerce products that has regular
642 642
         // and sale price greater than 0
643 643
         // will be used later to check for course with the id as meta
644
-        $paid_product_ids_with_sale =  get_posts( self::get_paid_products_on_sale_query_args() );
644
+        $paid_product_ids_with_sale = get_posts(self::get_paid_products_on_sale_query_args());
645 645
 
646 646
         // get all the paid WooCommerce products that has regular price
647 647
         // greater than 0 without a sale price
648 648
         // will be used later to check for course with the id as meta
649
-        $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() );
649
+        $paid_product_ids_without_sale = get_posts(self::get_paid_products_not_on_sale_query_args());
650 650
 
651 651
         // combine products ID's with regular and sale price grater than zero and those without
652 652
         // sale but regular price greater than zero
653
-        $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale );
653
+        $woocommerce_paid_product_ids = array_merge($paid_product_ids_with_sale, $paid_product_ids_without_sale);
654 654
 
655 655
         // if
656
-        if( empty($woocommerce_paid_product_ids) ){
656
+        if (empty($woocommerce_paid_product_ids)) {
657 657
             return array( );
658 658
         }
659 659
         return $woocommerce_paid_product_ids;
@@ -673,24 +673,24 @@  discard block
 block discarded – undo
673 673
      * @param array $args
674 674
      * @return array
675 675
      */
676
-    public static function get_free_courses( $args = array() ){
676
+    public static function get_free_courses($args = array()) {
677 677
 
678 678
         $free_course_query_args = Sensei_Course::get_default_query_args();
679
-        $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args();
679
+        $free_course_query_args['meta_query'] = self::get_free_courses_meta_query_args();
680 680
 
681
-	    if( !empty( $args ) ){
682
-		    wp_parse_args( $args, $free_course_query_args  );
681
+	    if ( ! empty($args)) {
682
+		    wp_parse_args($args, $free_course_query_args);
683 683
 	    }
684 684
 
685 685
         // don't show any paid courses
686 686
         $courses = self::get_paid_courses();
687 687
         $ids = array();
688
-        foreach( $courses as $course ){
688
+        foreach ($courses as $course) {
689 689
             $ids[] = $course->ID;
690 690
         }
691
-        $free_course_query_args[ 'post__not_in' ] =  $ids;
691
+        $free_course_query_args['post__not_in'] = $ids;
692 692
 
693
-        return get_posts( $free_course_query_args );
693
+        return get_posts($free_course_query_args);
694 694
 
695 695
     }
696 696
 
@@ -702,17 +702,17 @@  discard block
 block discarded – undo
702 702
      *
703 703
      * @return array
704 704
      */
705
-    public static function get_paid_courses( $args = array() ){
705
+    public static function get_paid_courses($args = array()) {
706 706
 
707 707
         $paid_course_query_args = Sensei_Course::get_default_query_args();
708 708
 
709
-        $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args();
709
+        $paid_course_query_args['meta_query'] = self::get_paid_courses_meta_query_args();
710 710
 
711
-	    if( !empty( $args ) ){
712
-		    wp_parse_args( $args, $paid_course_query_args  );
711
+	    if ( ! empty($args)) {
712
+		    wp_parse_args($args, $paid_course_query_args);
713 713
 	    }
714 714
 
715
-        return get_posts(  $paid_course_query_args );
715
+        return get_posts($paid_course_query_args);
716 716
     }
717 717
 
718 718
     /**
@@ -727,17 +727,17 @@  discard block
 block discarded – undo
727 727
      * @param int $course_id
728 728
      * @return string $html markup for the button or nothing if user not allowed to buy
729 729
      */
730
-    public static function the_add_to_cart_button_html( $course_id ){
730
+    public static function the_add_to_cart_button_html($course_id) {
731 731
 
732
-        if ( ! Sensei_Course::is_prerequisite_complete( $course_id ) || self::is_course_in_cart( $course_id ) ) {
732
+        if ( ! Sensei_Course::is_prerequisite_complete($course_id) || self::is_course_in_cart($course_id)) {
733 733
             return '';
734 734
         }
735 735
 
736
-        $wc_post_id = self::get_course_product_id( $course_id );
736
+        $wc_post_id = self::get_course_product_id($course_id);
737 737
 
738 738
         // Check if customer purchased the product
739
-        if ( self::has_customer_bought_product(  get_current_user_id(), $wc_post_id )
740
-            || empty( $wc_post_id ) ) {
739
+        if (self::has_customer_bought_product(get_current_user_id(), $wc_post_id)
740
+            || empty($wc_post_id)) {
741 741
 
742 742
             return '';
743 743
 
@@ -745,15 +745,15 @@  discard block
 block discarded – undo
745 745
 
746 746
         // based on simple.php in WC templates/single-product/add-to-cart/
747 747
         // Get the product
748
-        $product = self::get_product_object( $wc_post_id );
748
+        $product = self::get_product_object($wc_post_id);
749 749
 
750 750
         // do not show the button for invalid products, non purchasable products, out
751 751
         // of stock product or if course is already in cart
752
-        if ( ! isset ( $product )
753
-            || ! is_object( $product )
752
+        if ( ! isset ($product)
753
+            || ! is_object($product)
754 754
             || ! $product->is_purchasable()
755 755
             || ! $product->is_in_stock()
756
-            || self::is_course_in_cart( $wc_post_id ) ) {
756
+            || self::is_course_in_cart($wc_post_id)) {
757 757
 
758 758
             return '';
759 759
 
@@ -764,23 +764,23 @@  discard block
 block discarded – undo
764 764
         //
765 765
         ?>
766 766
 
767
-        <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"
767
+        <form action="<?php echo esc_url($product->add_to_cart_url()); ?>"
768 768
               class="cart"
769 769
               method="post"
770 770
               enctype="multipart/form-data">
771 771
 
772
-            <input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
772
+            <input type="hidden" name="product_id" value="<?php echo esc_attr($product->id); ?>" />
773 773
 
774 774
             <input type="hidden" name="quantity" value="1" />
775 775
 
776
-            <?php if ( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { ?>
776
+            <?php if (isset($product->variation_id) && 0 < intval($product->variation_id)) { ?>
777 777
 
778 778
                 <input type="hidden" name="variation_id" value="<?php echo $product->variation_id; ?>" />
779
-                <?php if( isset( $product->variation_data ) && is_array( $product->variation_data ) && count( $product->variation_data ) > 0 ) { ?>
779
+                <?php if (isset($product->variation_data) && is_array($product->variation_data) && count($product->variation_data) > 0) { ?>
780 780
 
781
-                    <?php foreach( $product->variation_data as $att => $val ) { ?>
781
+                    <?php foreach ($product->variation_data as $att => $val) { ?>
782 782
 
783
-                        <input type="hidden" name="<?php echo esc_attr( $att ); ?>" id="<?php echo esc_attr( str_replace( 'attribute_', '', $att ) ); ?>" value="<?php echo esc_attr( $val ); ?>" />
783
+                        <input type="hidden" name="<?php echo esc_attr($att); ?>" id="<?php echo esc_attr(str_replace('attribute_', '', $att)); ?>" value="<?php echo esc_attr($val); ?>" />
784 784
 
785 785
                     <?php } ?>
786 786
 
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
             <?php } ?>
790 790
 
791 791
             <button type="submit" class="single_add_to_cart_button button alt">
792
-                <?php $button_text = $product->get_price_html() . ' - ' . __( 'Purchase this Course', 'woothemes-sensei' ); ?>
792
+                <?php $button_text = $product->get_price_html().' - '.__('Purchase this Course', 'woothemes-sensei'); ?>
793 793
                 <?php
794 794
                 /**
795 795
                  * Filter Add to Cart button text
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
                  *
799 799
                  * @param string $button_text
800 800
                  */
801
-                echo apply_filters( 'sensei_wc_single_add_to_cart_button_text', $button_text );
801
+                echo apply_filters('sensei_wc_single_add_to_cart_button_text', $button_text);
802 802
                 ?>
803 803
             </button>
804 804
 
@@ -818,26 +818,26 @@  discard block
 block discarded – undo
818 818
      *
819 819
      * @return string $message
820 820
      */
821
-    public static function alter_no_permissions_message( $message, $post_id ){
821
+    public static function alter_no_permissions_message($message, $post_id) {
822 822
 
823
-        if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){
823
+        if (empty($post_id) || 'course' != get_post_type($post_id)) {
824 824
             return  $message;
825 825
         }
826 826
 
827
-        $product_id = self::get_course_product_id( $post_id );
827
+        $product_id = self::get_course_product_id($post_id);
828 828
 
829
-        if( ! $product_id
830
-            || ! self::has_customer_bought_product( get_current_user_id(),$product_id ) ){
829
+        if ( ! $product_id
830
+            || ! self::has_customer_bought_product(get_current_user_id(), $product_id)) {
831 831
 
832 832
             return $message;
833 833
 
834 834
         }
835 835
 
836 836
         ob_start();
837
-        self::the_course_no_permissions_message( $post_id );
837
+        self::the_course_no_permissions_message($post_id);
838 838
         $woocommerce_course_no_permissions_message = ob_get_clean();
839 839
 
840
-        return $woocommerce_course_no_permissions_message ;
840
+        return $woocommerce_course_no_permissions_message;
841 841
 
842 842
     }
843 843
     /**
@@ -846,18 +846,18 @@  discard block
 block discarded – undo
846 846
      *
847 847
      * @since 1.9.0
848 848
      */
849
-    public static function the_course_no_permissions_message( $course_id ){
849
+    public static function the_course_no_permissions_message($course_id) {
850 850
 
851 851
         // login link
852
-        $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
853
-	    $login_link =  '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>';
854
-	    $wc_product_id =  self::get_course_product_id( $course_id );
852
+        $my_courses_page_id = intval(Sensei()->settings->settings['my_course_page']);
853
+	    $login_link = '<a href="'.esc_url(get_permalink($my_courses_page_id)).'">'.__('log in', 'woothemes-sensei').'</a>';
854
+	    $wc_product_id = self::get_course_product_id($course_id);
855 855
 
856
-	    if ( self::is_product_in_cart( $wc_product_id ) ) {
856
+	    if (self::is_product_in_cart($wc_product_id)) {
857 857
 
858
-		    $cart_link = '<a href="' . wc_get_checkout_url() . '" title="' . __( 'Checkout','woocommerce' ) . '">' . __( 'checkout', 'woocommerce' ) . '</a>';
858
+		    $cart_link = '<a href="'.wc_get_checkout_url().'" title="'.__('Checkout', 'woocommerce').'">'.__('checkout', 'woocommerce').'</a>';
859 859
 
860
-		    $message = sprintf( __( 'This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei' ), $cart_link );
860
+		    $message = sprintf(__('This course is already in your cart, please proceed to %1$s, to gain access.', 'woothemes-sensei'), $cart_link);
861 861
 		    ?>
862 862
 		    <span class="add-to-cart-login">
863 863
 		            <?php echo $message; ?>
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 
866 866
 		    <?php
867 867
 
868
-	    } elseif ( is_user_logged_in() ) {
868
+	    } elseif (is_user_logged_in()) {
869 869
 
870 870
 		    ?>
871 871
 		    <style>
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
 		    <?php
878 878
 
879 879
 	    } else {
880
-		    $message = sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link );
880
+		    $message = sprintf(__('Or %1$s to access your purchased courses', 'woothemes-sensei'), $login_link);
881 881
 	        ?>
882 882
 		        <span class="add-to-cart-login">
883 883
 		            <?php echo $message; ?>
@@ -897,34 +897,34 @@  discard block
 block discarded – undo
897 897
      *
898 898
      * @return bool
899 899
      */
900
-    public static function has_customer_bought_product ( $user_id, $product_id ){
900
+    public static function has_customer_bought_product($user_id, $product_id) {
901 901
 
902
-        $orders = self::get_user_product_orders( $user_id, $product_id );
902
+        $orders = self::get_user_product_orders($user_id, $product_id);
903 903
 
904
-        foreach ( $orders as $order_id ) {
904
+        foreach ($orders as $order_id) {
905 905
 
906
-            $order = new WC_Order( $order_id->ID );
906
+            $order = new WC_Order($order_id->ID);
907 907
 
908 908
             // wc-active is the subscriptions complete status
909
-            if ( ! in_array( $order->post_status, array( 'wc-processing', 'wc-completed' ) )
910
-                || ! ( 0 < sizeof( $order->get_items() ) )  ){
909
+            if ( ! in_array($order->post_status, array('wc-processing', 'wc-completed'))
910
+                || ! (0 < sizeof($order->get_items()))) {
911 911
 
912 912
                 continue;
913 913
 
914 914
             }
915 915
 
916
-            foreach( $order->get_items() as $item ) {
916
+            foreach ($order->get_items() as $item) {
917 917
 
918 918
                 // Check if user has bought product
919
-                if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) {
919
+                if ($item['product_id'] == $product_id || $item['variation_id'] == $product_id) {
920 920
 
921 921
                     // Check if user has an active subscription for product
922
-                    if( class_exists( 'WC_Subscriptions_Manager' ) ) {
923
-                        $sub_key = wcs_get_subscription( $order );
924
-                        if( $sub_key ) {
925
-                            $sub = wcs_get_subscription( $sub_key );
926
-                            if( $sub && isset( $sub['status'] ) ) {
927
-                                if( 'active' == $sub['status'] ) {
922
+                    if (class_exists('WC_Subscriptions_Manager')) {
923
+                        $sub_key = wcs_get_subscription($order);
924
+                        if ($sub_key) {
925
+                            $sub = wcs_get_subscription($sub_key);
926
+                            if ($sub && isset($sub['status'])) {
927
+                                if ('active' == $sub['status']) {
928 928
                                     return true;
929 929
                                 } else {
930 930
                                     return false;
@@ -956,11 +956,11 @@  discard block
 block discarded – undo
956 956
      * @return string $woocommerce_product_id or false if none exist
957 957
      *
958 958
      */
959
-    public static function get_course_product_id( $course_id ){
959
+    public static function get_course_product_id($course_id) {
960 960
 
961
-        $product_id =  get_post_meta( $course_id, '_course_woocommerce_product', true );
961
+        $product_id = get_post_meta($course_id, '_course_woocommerce_product', true);
962 962
 
963
-        if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){
963
+        if (empty($product_id) || 'product' != get_post_type($product_id)) {
964 964
             return false;
965 965
         }
966 966
 
@@ -976,11 +976,11 @@  discard block
 block discarded – undo
976 976
      * @param array $classes
977 977
      * @return array
978 978
      */
979
-    public static function add_woocommerce_body_class( $classes ){
979
+    public static function add_woocommerce_body_class($classes) {
980 980
 
981
-        if( ! in_array( 'woocommerce', $classes ) && defined( 'SENSEI_NO_PERMISSION' ) && SENSEI_NO_PERMISSION ){
981
+        if ( ! in_array('woocommerce', $classes) && defined('SENSEI_NO_PERMISSION') && SENSEI_NO_PERMISSION) {
982 982
 
983
-            $classes[] ='woocommerce';
983
+            $classes[] = 'woocommerce';
984 984
 
985 985
         }
986 986
 
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
      *
999 999
      * @return  void
1000 1000
      */
1001
-    public static function activate_subscription(  $order ) {
1001
+    public static function activate_subscription($order) {
1002 1002
 
1003 1003
         $order_user = get_user_by('id', $order->user_id);
1004 1004
         $user['ID'] = $order_user->ID;
@@ -1007,13 +1007,13 @@  discard block
 block discarded – undo
1007 1007
         $user['user_url'] = $order_user->user_url;
1008 1008
 
1009 1009
         // Run through each product ordered
1010
-        if ( ! sizeof($order->get_items() )>0 ) {
1010
+        if ( ! sizeof($order->get_items()) > 0) {
1011 1011
 
1012 1012
             return;
1013 1013
 
1014 1014
         }
1015 1015
 
1016
-        foreach($order->get_items() as $item) {
1016
+        foreach ($order->get_items() as $item) {
1017 1017
 
1018 1018
             $product_type = '';
1019 1019
 
@@ -1028,21 +1028,21 @@  discard block
 block discarded – undo
1028 1028
 
1029 1029
             } // End If Statement
1030 1030
 
1031
-            $_product = self::get_product_object( $item_id, $product_type );
1031
+            $_product = self::get_product_object($item_id, $product_type);
1032 1032
 
1033 1033
             // Get courses that use the WC product
1034 1034
             $courses = array();
1035 1035
 
1036
-            if ( ! in_array( $product_type, self::get_subscription_types() ) ) {
1036
+            if ( ! in_array($product_type, self::get_subscription_types())) {
1037 1037
 
1038
-                $courses = Sensei()->course->get_product_courses( $item_id );
1038
+                $courses = Sensei()->course->get_product_courses($item_id);
1039 1039
 
1040 1040
             } // End If Statement
1041 1041
 
1042 1042
             // Loop and add the user to the course.
1043
-            foreach ( $courses as $course_item ){
1043
+            foreach ($courses as $course_item) {
1044 1044
 
1045
-                Sensei_Utils::user_start_course( intval( $user['ID'] ), $course_item->ID  );
1045
+                Sensei_Utils::user_start_course(intval($user['ID']), $course_item->ID);
1046 1046
 
1047 1047
             } // End For Loop
1048 1048
 
@@ -1060,13 +1060,13 @@  discard block
 block discarded – undo
1060 1060
      *
1061 1061
      * @return  void
1062 1062
      */
1063
-    public static function email_course_details(  $order ){
1063
+    public static function email_course_details($order) {
1064 1064
 
1065 1065
         global $woocommerce;
1066 1066
 
1067 1067
         // exit early if not wc-completed or wc-processing
1068
-        if( 'wc-completed' != $order->post_status
1069
-            && 'wc-processing' != $order->post_status  ) {
1068
+        if ('wc-completed' != $order->post_status
1069
+            && 'wc-processing' != $order->post_status) {
1070 1070
             return;
1071 1071
         }
1072 1072
 
@@ -1074,16 +1074,16 @@  discard block
 block discarded – undo
1074 1074
         $order_id = $order->id;
1075 1075
 
1076 1076
         //If object have items go through them all to find course
1077
-        if ( 0 < sizeof( $order_items ) ) {
1077
+        if (0 < sizeof($order_items)) {
1078 1078
 
1079
-            $course_details_html =  '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>';
1079
+            $course_details_html = '<h2>'.__('Course details', 'woothemes-sensei').'</h2>';
1080 1080
             $order_contains_courses = false;
1081 1081
 
1082 1082
 
1083
-            foreach ( $order_items as $item ) {
1083
+            foreach ($order_items as $item) {
1084 1084
 
1085 1085
                 $product_type = '';
1086
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1086
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1087 1087
                     // If item has variation_id then its from variation
1088 1088
                     $item_id = $item['variation_id'];
1089 1089
                     $product_type = 'variation';
@@ -1092,9 +1092,9 @@  discard block
 block discarded – undo
1092 1092
                     $item_id = $item['product_id'];
1093 1093
                 } // End If Statement
1094 1094
 
1095
-                $user_id = get_post_meta( $order_id, '_customer_user', true );
1095
+                $user_id = get_post_meta($order_id, '_customer_user', true);
1096 1096
 
1097
-                if( $user_id ) {
1097
+                if ($user_id) {
1098 1098
 
1099 1099
                     // Get all courses for product
1100 1100
                     $args = array(
@@ -1109,16 +1109,16 @@  discard block
 block discarded – undo
1109 1109
                         'orderby' => 'menu_order date',
1110 1110
                         'order' => 'ASC',
1111 1111
                     );
1112
-                    $courses = get_posts( $args );
1112
+                    $courses = get_posts($args);
1113 1113
 
1114
-                    if( $courses && count( $courses ) > 0 ) {
1114
+                    if ($courses && count($courses) > 0) {
1115 1115
 
1116
-                        foreach( $courses as $course ) {
1116
+                        foreach ($courses as $course) {
1117 1117
 
1118 1118
                             $title = $course->post_title;
1119
-                            $permalink = get_permalink( $course->ID );
1119
+                            $permalink = get_permalink($course->ID);
1120 1120
                             $order_contains_courses = true;
1121
-                            $course_details_html .=  '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>';
1121
+                            $course_details_html .= '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>';
1122 1122
                         }
1123 1123
 
1124 1124
 
@@ -1129,7 +1129,7 @@  discard block
 block discarded – undo
1129 1129
             } // end for each order item
1130 1130
 
1131 1131
             // Output Course details
1132
-            if( $order_contains_courses ){
1132
+            if ($order_contains_courses) {
1133 1133
 
1134 1134
                 echo $course_details_html;
1135 1135
 
@@ -1147,33 +1147,33 @@  discard block
 block discarded – undo
1147 1147
      * @param   int $order_id WC order ID
1148 1148
      * @return  void
1149 1149
      */
1150
-    public static function complete_order ( $order_id = 0 ) {
1150
+    public static function complete_order($order_id = 0) {
1151 1151
 
1152 1152
         $order_user = array();
1153 1153
 
1154 1154
         // Check for WooCommerce
1155
-        if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) {
1155
+        if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) {
1156 1156
             // Get order object
1157
-            $order = new WC_Order( $order_id );
1157
+            $order = new WC_Order($order_id);
1158 1158
 
1159
-	        if ( ! in_array( $order->get_status(), array( 'complete', 'processing' ) ) ) {
1159
+	        if ( ! in_array($order->get_status(), array('complete', 'processing'))) {
1160 1160
 
1161 1161
 		        return;
1162 1162
 
1163 1163
 	        }
1164 1164
 
1165
-            $user = get_user_by( 'id', $order->get_user_id() );
1165
+            $user = get_user_by('id', $order->get_user_id());
1166 1166
             $order_user['ID'] = $user->ID;
1167 1167
             $order_user['user_login'] = $user->user_login;
1168 1168
             $order_user['user_email'] = $user->user_email;
1169 1169
             $order_user['user_url'] = $user->user_url;
1170 1170
             // Run through each product ordered
1171
-            if ( 0 < sizeof( $order->get_items() ) ) {
1171
+            if (0 < sizeof($order->get_items())) {
1172 1172
 
1173
-                foreach( $order->get_items() as $item ) {
1173
+                foreach ($order->get_items() as $item) {
1174 1174
 
1175 1175
                     $product_type = '';
1176
-                    if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1176
+                    if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1177 1177
 
1178 1178
                         $item_id = $item['variation_id'];
1179 1179
                         $product_type = 'variation';
@@ -1184,15 +1184,15 @@  discard block
 block discarded – undo
1184 1184
 
1185 1185
                     } // End If Statement
1186 1186
 
1187
-                    $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1187
+                    $_product = Sensei_WC::get_product_object($item_id, $product_type);
1188 1188
 
1189 1189
                     // Get courses that use the WC product
1190
-                    $courses = Sensei()->course->get_product_courses( $_product->id );
1190
+                    $courses = Sensei()->course->get_product_courses($_product->id);
1191 1191
 
1192 1192
                     // Loop and update those courses
1193
-                    foreach ( $courses as $course_item ) {
1193
+                    foreach ($courses as $course_item) {
1194 1194
 
1195
-                        $update_course = self::course_update( $course_item->ID, $order_user );
1195
+                        $update_course = self::course_update($course_item->ID, $order_user);
1196 1196
 
1197 1197
                     } // End For Loop
1198 1198
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
             } // End If Statement
1202 1202
             // Add meta to indicate that payment has been completed successfully
1203
-            update_post_meta( $order_id, 'sensei_payment_complete', '1' );
1203
+            update_post_meta($order_id, 'sensei_payment_complete', '1');
1204 1204
 
1205 1205
         } // End If Statement
1206 1206
 
@@ -1214,34 +1214,34 @@  discard block
 block discarded – undo
1214 1214
      * @param   integer| WC_Order $order_id order ID
1215 1215
      * @return  void
1216 1216
      */
1217
-    public static function cancel_order ( $order_id ) {
1217
+    public static function cancel_order($order_id) {
1218 1218
 
1219 1219
 		// Get order object
1220
-		if( is_object( $order_id ) ){
1220
+		if (is_object($order_id)) {
1221 1221
 
1222 1222
 			$order = $order_id;
1223 1223
 
1224
-		}else{
1224
+		} else {
1225 1225
 
1226
-			$order = new WC_Order( $order_id );
1226
+			$order = new WC_Order($order_id);
1227 1227
 		}
1228 1228
 
1229
-		if ( ! in_array( $order->get_status(), array( 'cancelled', 'refunded' ) ) ) {
1229
+		if ( ! in_array($order->get_status(), array('cancelled', 'refunded'))) {
1230 1230
 
1231 1231
 			return;
1232 1232
 
1233 1233
 		}
1234 1234
 
1235 1235
         // Run through each product ordered
1236
-        if ( 0 < sizeof( $order->get_items() ) ) {
1236
+        if (0 < sizeof($order->get_items())) {
1237 1237
 
1238 1238
             // Get order user
1239
-            $user_id = $order->__get( 'user_id' );
1239
+            $user_id = $order->__get('user_id');
1240 1240
 
1241
-            foreach( $order->get_items() as $item ) {
1241
+            foreach ($order->get_items() as $item) {
1242 1242
 
1243 1243
                 $product_type = '';
1244
-                if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) {
1244
+                if (isset($item['variation_id']) && (0 < $item['variation_id'])) {
1245 1245
 
1246 1246
                     $item_id = $item['variation_id'];
1247 1247
                     $product_type = 'variation';
@@ -1252,20 +1252,20 @@  discard block
 block discarded – undo
1252 1252
 
1253 1253
                 } // End If Statement
1254 1254
 
1255
-                $_product = Sensei_WC::get_product_object( $item_id, $product_type );
1255
+                $_product = Sensei_WC::get_product_object($item_id, $product_type);
1256 1256
 
1257 1257
                 // Get courses that use the WC product
1258 1258
                 $courses = array();
1259
-                $courses = Sensei()->course->get_product_courses( $item_id );
1259
+                $courses = Sensei()->course->get_product_courses($item_id);
1260 1260
 
1261 1261
                 // Loop and update those courses
1262
-                foreach ($courses as $course_item){
1262
+                foreach ($courses as $course_item) {
1263 1263
 
1264
-	                if( self::has_customer_bought_product( $user_id, $course_item->ID ) ){
1264
+	                if (self::has_customer_bought_product($user_id, $course_item->ID)) {
1265 1265
 		                continue;
1266 1266
 	                }
1267 1267
                     // Check and Remove course from courses user meta
1268
-                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id );
1268
+                    $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id);
1269 1269
 
1270 1270
                 } // End For Loop
1271 1271
 
@@ -1286,30 +1286,30 @@  discard block
 block discarded – undo
1286 1286
      * @param   string  $product_type  '' or 'variation'
1287 1287
      * @return   WC_Product $wc_product_object
1288 1288
      */
1289
-    public static function get_product_object ( $wc_product_id = 0, $product_type = '' ) {
1289
+    public static function get_product_object($wc_product_id = 0, $product_type = '') {
1290 1290
 
1291 1291
         $wc_product_object = false;
1292
-        if ( 0 < intval( $wc_product_id ) ) {
1292
+        if (0 < intval($wc_product_id)) {
1293 1293
 
1294 1294
             // Get the product
1295
-            if ( function_exists( 'wc_get_product' ) ) {
1295
+            if (function_exists('wc_get_product')) {
1296 1296
 
1297
-                $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3
1297
+                $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3
1298 1298
 
1299
-            } elseif ( function_exists( 'get_product' ) ) {
1299
+            } elseif (function_exists('get_product')) {
1300 1300
 
1301
-                $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0
1301
+                $wc_product_object = get_product($wc_product_id); // Post WC 2.0
1302 1302
 
1303 1303
             } else {
1304 1304
 
1305 1305
                 // Pre WC 2.0
1306
-                if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) {
1306
+                if ('variation' == $product_type || 'subscription_variation' == $product_type) {
1307 1307
 
1308
-                    $wc_product_object = new WC_Product_Variation( $wc_product_id );
1308
+                    $wc_product_object = new WC_Product_Variation($wc_product_id);
1309 1309
 
1310 1310
                 } else {
1311 1311
 
1312
-                    $wc_product_object = new WC_Product( $wc_product_id );
1312
+                    $wc_product_object = new WC_Product($wc_product_id);
1313 1313
 
1314 1314
                 } // End If Statement
1315 1315
 
@@ -1332,19 +1332,19 @@  discard block
 block discarded – undo
1332 1332
      *
1333 1333
      * @return bool|int
1334 1334
      */
1335
-    public static function course_update ( $course_id = 0, $order_user = array()  ) {
1335
+    public static function course_update($course_id = 0, $order_user = array()) {
1336 1336
 
1337 1337
         global $current_user;
1338 1338
 
1339
-        if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false;
1339
+        if ( ! isset($current_user) || ! $current_user->ID > 0) return false;
1340 1340
 
1341 1341
         $data_update = false;
1342 1342
 
1343 1343
         // Get the product ID
1344
-        $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true );
1344
+        $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true);
1345 1345
 
1346 1346
         // Check if in the admin
1347
-        if ( is_admin() ) {
1347
+        if (is_admin()) {
1348 1348
 
1349 1349
             $user_login = $order_user['user_login'];
1350 1350
             $user_email = $order_user['user_email'];
@@ -1361,28 +1361,28 @@  discard block
 block discarded – undo
1361 1361
         } // End If Statement
1362 1362
 
1363 1363
         // This doesn't appear to be purely WooCommerce related. Should it be in a separate function?
1364
-        $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true );
1365
-        if( 0 < absint( $course_prerequisite_id ) ) {
1364
+        $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true);
1365
+        if (0 < absint($course_prerequisite_id)) {
1366 1366
 
1367
-            $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) );
1368
-            if ( ! $prereq_course_complete ) {
1367
+            $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id));
1368
+            if ( ! $prereq_course_complete) {
1369 1369
 
1370 1370
                 // Remove all course user meta
1371
-                return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id );
1371
+                return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id);
1372 1372
 
1373 1373
             }
1374 1374
         }
1375 1375
 
1376
-        $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) );
1376
+        $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id));
1377 1377
 
1378 1378
         if ( ! $is_user_taking_course
1379 1379
             && Sensei_WC::is_woocommerce_active()
1380 1380
             && 0 < $wc_post_id
1381
-            && Sensei_WC::has_customer_bought_product( $user_id, $wc_post_id ) ) {
1381
+            && Sensei_WC::has_customer_bought_product($user_id, $wc_post_id)) {
1382 1382
 
1383
-	            $activity_logged = Sensei_Utils::user_start_course( intval( $user_id ), intval( $course_id ) );
1383
+	            $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id));
1384 1384
 
1385
-	            if ( true == $activity_logged ) {
1385
+	            if (true == $activity_logged) {
1386 1386
 
1387 1387
 		            $is_user_taking_course = true;
1388 1388
 
@@ -1404,14 +1404,14 @@  discard block
 block discarded – undo
1404 1404
      *
1405 1405
      * @return boolean                 Modified guest checkout setting
1406 1406
      */
1407
-    public static function disable_guest_checkout( $guest_checkout ) {
1407
+    public static function disable_guest_checkout($guest_checkout) {
1408 1408
 
1409
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
1409
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
1410 1410
 
1411
-            if( isset( WC()->cart->cart_contents ) && count( WC()->cart->cart_contents ) > 0 ) {
1411
+            if (isset(WC()->cart->cart_contents) && count(WC()->cart->cart_contents) > 0) {
1412 1412
 
1413
-                foreach( WC()->cart->cart_contents as $cart_key => $product ) {
1414
-                    if( isset( $product['product_id'] ) ) {
1413
+                foreach (WC()->cart->cart_contents as $cart_key => $product) {
1414
+                    if (isset($product['product_id'])) {
1415 1415
 
1416 1416
                         $args = array(
1417 1417
                             'posts_per_page' => -1,
@@ -1424,11 +1424,11 @@  discard block
 block discarded – undo
1424 1424
                             )
1425 1425
                         );
1426 1426
 
1427
-                        $posts = get_posts( $args );
1427
+                        $posts = get_posts($args);
1428 1428
 
1429
-                        if( $posts && count( $posts ) > 0 ) {
1429
+                        if ($posts && count($posts) > 0) {
1430 1430
 
1431
-                            foreach( $posts as $course ) {
1431
+                            foreach ($posts as $course) {
1432 1432
                                 $guest_checkout = '';
1433 1433
                                 break;
1434 1434
 
@@ -1457,23 +1457,23 @@  discard block
 block discarded – undo
1457 1457
      *
1458 1458
      * @return string
1459 1459
      **/
1460
-    public static function virtual_order_payment_complete( $order_status, $order_id ) {
1460
+    public static function virtual_order_payment_complete($order_status, $order_id) {
1461 1461
 
1462
-        $order = new WC_Order( $order_id );
1462
+        $order = new WC_Order($order_id);
1463 1463
 
1464
-        if ( ! isset ( $order ) ) return '';
1464
+        if ( ! isset ($order)) return '';
1465 1465
 
1466
-        if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) {
1466
+        if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) {
1467 1467
 
1468 1468
             $virtual_order = true;
1469 1469
 
1470
-            if ( count( $order->get_items() ) > 0 ) {
1470
+            if (count($order->get_items()) > 0) {
1471 1471
 
1472
-                foreach( $order->get_items() as $item ) {
1472
+                foreach ($order->get_items() as $item) {
1473 1473
 
1474
-                    if ( $item['product_id'] > 0 ) {
1475
-                        $_product = $order->get_product_from_item( $item );
1476
-                        if ( ! $_product->is_virtual() ) {
1474
+                    if ($item['product_id'] > 0) {
1475
+                        $_product = $order->get_product_from_item($item);
1476
+                        if ( ! $_product->is_virtual()) {
1477 1477
 
1478 1478
                             $virtual_order = false;
1479 1479
                             break;
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             } // End If Statement
1488 1488
 
1489 1489
             // virtual order, mark as completed
1490
-            if ( $virtual_order ) {
1490
+            if ($virtual_order) {
1491 1491
 
1492 1492
                 return 'completed';
1493 1493
 
@@ -1510,14 +1510,14 @@  discard block
 block discarded – undo
1510 1510
      * @param  integer $user_id
1511 1511
      * @return boolean $user_access_permission
1512 1512
      */
1513
-    public static function get_subscription_permission( $user_access_permission , $user_id ){
1513
+    public static function get_subscription_permission($user_access_permission, $user_id) {
1514 1514
 
1515 1515
         global $post;
1516 1516
 
1517 1517
         // ignore the current case if the following conditions are met
1518
-        if ( ! class_exists( 'WC_Subscriptions' ) || empty( $user_id )
1519
-            || ! in_array( $post->post_type, array( 'course','lesson','quiz' ) )
1520
-            || ! wcs_user_has_subscription( $user_id) ){
1518
+        if ( ! class_exists('WC_Subscriptions') || empty($user_id)
1519
+            || ! in_array($post->post_type, array('course', 'lesson', 'quiz'))
1520
+            || ! wcs_user_has_subscription($user_id)) {
1521 1521
 
1522 1522
             return $user_access_permission;
1523 1523
 
@@ -1527,25 +1527,25 @@  discard block
 block discarded – undo
1527 1527
         // is the subscription on the the current course?
1528 1528
 
1529 1529
         $course_id = 0;
1530
-        if ( 'course' == $post->post_type ){
1530
+        if ('course' == $post->post_type) {
1531 1531
 
1532 1532
             $course_id = $post->ID;
1533 1533
 
1534
-        } elseif ( 'lesson' == $post->post_type ) {
1534
+        } elseif ('lesson' == $post->post_type) {
1535 1535
 
1536
-            $course_id = Sensei()->lesson->get_course_id( $post->ID );
1536
+            $course_id = Sensei()->lesson->get_course_id($post->ID);
1537 1537
 
1538 1538
         } else {
1539 1539
 
1540
-            $lesson_id =  Sensei()->quiz->get_lesson_id( $post->ID );
1541
-            $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1540
+            $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
1541
+            $course_id = Sensei()->lesson->get_course_id($lesson_id);
1542 1542
 
1543 1543
         }
1544 1544
 
1545 1545
         // if the course has no subscription WooCommerce product attached to return the permissions as is
1546
-        $product_id = Sensei_WC::get_course_product_id( $course_id );
1547
-        $product = wc_get_product( $product_id );
1548
-        if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1546
+        $product_id = Sensei_WC::get_course_product_id($course_id);
1547
+        $product = wc_get_product($product_id);
1548
+        if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1549 1549
 
1550 1550
             return $user_access_permission;
1551 1551
 
@@ -1553,19 +1553,19 @@  discard block
 block discarded – undo
1553 1553
 
1554 1554
         // give access if user has active subscription on the product otherwise restrict it.
1555 1555
         // also check if the user was added to the course directly after the subscription started.
1556
-        if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1557
-            || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1558
-            || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  ) ){
1556
+        if (wcs_user_has_subscription($user_id, $product_id, 'active')
1557
+            || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1558
+            || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1559 1559
 
1560 1560
             $user_access_permission = true;
1561 1561
 
1562
-        }else{
1562
+        } else {
1563 1563
 
1564 1564
             $user_access_permission = false;
1565 1565
             // do not show the WC permissions message
1566
-            remove_filter( 'sensei_the_no_permissions_message', array( 'Sensei_WC', 'alter_no_permissions_message' ), 20, 2 );
1567
-            Sensei()->permissions_message['title'] = __( 'No active subscription', 'woothemes-sensei' );
1568
-            Sensei()->permissions_message['message'] = __( 'Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei' );
1566
+            remove_filter('sensei_the_no_permissions_message', array('Sensei_WC', 'alter_no_permissions_message'), 20, 2);
1567
+            Sensei()->permissions_message['title'] = __('No active subscription', 'woothemes-sensei');
1568
+            Sensei()->permissions_message['message'] = __('Sorry, you do not have an access to this content without an active subscription.', 'woothemes-sensei');
1569 1569
         }
1570 1570
 
1571 1571
         return $user_access_permission;
@@ -1581,9 +1581,9 @@  discard block
 block discarded – undo
1581 1581
 	 *
1582 1582
 	 * @return bool $has_user_started_course
1583 1583
 	 */
1584
-	public static function get_subscription_user_started_course( $has_user_started_course, $course_id, $user_id ){
1584
+	public static function get_subscription_user_started_course($has_user_started_course, $course_id, $user_id) {
1585 1585
 
1586
-		if ( ! is_user_logged_in( ) ) {
1586
+		if ( ! is_user_logged_in( )) {
1587 1587
 
1588 1588
 			return $has_user_started_course;
1589 1589
 
@@ -1591,26 +1591,26 @@  discard block
 block discarded – undo
1591 1591
 
1592 1592
 		// cached user course access for this process instance
1593 1593
 		global $sensei_wc_subscription_access_store;
1594
-		if ( ! is_array( $sensei_wc_subscription_access_store ) ) {
1594
+		if ( ! is_array($sensei_wc_subscription_access_store)) {
1595 1595
 			$sensei_wc_subscription_access_store = array();
1596 1596
 		}
1597 1597
 
1598 1598
 		// user temp cached data so we don't output the mesage again
1599
-		$user_data_index_key = $course_id .'_' . $user_id;
1600
-		if ( isset( $sensei_wc_subscription_access_store[ $user_data_index_key  ] ) ) {
1599
+		$user_data_index_key = $course_id.'_'.$user_id;
1600
+		if (isset($sensei_wc_subscription_access_store[$user_data_index_key])) {
1601 1601
 
1602
-			return $sensei_wc_subscription_access_store[ $user_data_index_key ];
1602
+			return $sensei_wc_subscription_access_store[$user_data_index_key];
1603 1603
 
1604 1604
 		} else {
1605 1605
 
1606
-			if( empty( $course_id ) || empty( $user_id ) ){
1606
+			if (empty($course_id) || empty($user_id)) {
1607 1607
 				return $has_user_started_course;
1608 1608
 			}
1609 1609
 
1610 1610
 			// if the course has no subscription WooCommerce product attached to return the permissions as is
1611
-			$product_id = Sensei_WC::get_course_product_id( $course_id );
1612
-			$product = wc_get_product( $product_id );
1613
-			if( ! in_array( $product->get_type(), self::get_subscription_types() ) ){
1611
+			$product_id = Sensei_WC::get_course_product_id($course_id);
1612
+			$product = wc_get_product($product_id);
1613
+			if ( ! in_array($product->get_type(), self::get_subscription_types())) {
1614 1614
 
1615 1615
 				return $has_user_started_course;
1616 1616
 
@@ -1618,9 +1618,9 @@  discard block
 block discarded – undo
1618 1618
 
1619 1619
 			// give access if user has active subscription on the product otherwise restrict it.
1620 1620
 			// also check if the user was added to the course directly after the subscription started.
1621
-			if( wcs_user_has_subscription( $user_id, $product_id, 'active'  )
1622
-			    || wcs_user_has_subscription( $user_id, $product_id, 'pending-cancel'  )
1623
-			    || self::was_user_added_without_subscription( $user_id, $product_id, $course_id  )  ){
1621
+			if (wcs_user_has_subscription($user_id, $product_id, 'active')
1622
+			    || wcs_user_has_subscription($user_id, $product_id, 'pending-cancel')
1623
+			    || self::was_user_added_without_subscription($user_id, $product_id, $course_id)) {
1624 1624
 
1625 1625
 				$has_user_started_course = true;
1626 1626
 
@@ -1629,7 +1629,7 @@  discard block
 block discarded – undo
1629 1629
 				$has_user_started_course = false;
1630 1630
 
1631 1631
 			}
1632
-			$sensei_wc_subscription_access_store[ $user_data_index_key ] = $has_user_started_course;
1632
+			$sensei_wc_subscription_access_store[$user_data_index_key] = $has_user_started_course;
1633 1633
 			return $has_user_started_course;
1634 1634
 		}
1635 1635
 
@@ -1641,9 +1641,9 @@  discard block
 block discarded – undo
1641 1641
      * @since 1.9.0
1642 1642
      * @return array
1643 1643
      */
1644
-    public static function get_subscription_types(){
1644
+    public static function get_subscription_types() {
1645 1645
 
1646
-        return array( 'subscription','subscription_variation','variable-subscription' );
1646
+        return array('subscription', 'subscription_variation', 'variable-subscription');
1647 1647
 
1648 1648
     }
1649 1649
 
@@ -1663,16 +1663,16 @@  discard block
 block discarded – undo
1663 1663
      *
1664 1664
      * @return bool
1665 1665
      */
1666
-    public static function was_user_added_without_subscription($user_id, $product_id, $course_id ){
1666
+    public static function was_user_added_without_subscription($user_id, $product_id, $course_id) {
1667 1667
 
1668 1668
         $course_start_date = '';
1669 1669
         $subscription_start_date = '';
1670
-        $is_a_subscription ='';
1670
+        $is_a_subscription = '';
1671 1671
         $was_user_added_without_subscription = false;
1672 1672
 
1673 1673
         // if user is not on the course they were not added
1674
-	    remove_filter( 'sensei_user_started_course',     array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 );
1675
-        if( ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){
1674
+	    remove_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3);
1675
+        if ( ! Sensei_Utils::user_started_course($course_id, $user_id)) {
1676 1676
 
1677 1677
             return false;
1678 1678
 
@@ -1681,36 +1681,36 @@  discard block
 block discarded – undo
1681 1681
         // if user doesn't have a subscription and is taking the course
1682 1682
         // they were added manually
1683 1683
         if ( ! wcs_user_has_subscription($user_id, $product_id)
1684
-            && Sensei_Utils::user_started_course( $course_id, get_current_user_id() )  ){
1684
+            && Sensei_Utils::user_started_course($course_id, get_current_user_id())) {
1685 1685
 
1686 1686
             return true;
1687 1687
 
1688 1688
         }
1689 1689
 
1690
-	    add_filter( 'sensei_user_started_course',     array( 'Sensei_WC', 'get_subscription_user_started_course' ), 10, 3 );
1690
+	    add_filter('sensei_user_started_course', array('Sensei_WC', 'get_subscription_user_started_course'), 10, 3);
1691 1691
 
1692
-        $course_status =  Sensei_Utils::user_course_status( $course_id, $user_id );
1692
+        $course_status = Sensei_Utils::user_course_status($course_id, $user_id);
1693 1693
 
1694 1694
         // comparing dates setup data
1695
-        $course_start_date = date_create( $course_status->comment_date );
1696
-        $subscriptions = wcs_get_users_subscriptions( $user_id );
1695
+        $course_start_date = date_create($course_status->comment_date);
1696
+        $subscriptions = wcs_get_users_subscriptions($user_id);
1697 1697
 
1698 1698
         // comparing every subscription
1699
-        foreach( $subscriptions as $subscription ){
1699
+        foreach ($subscriptions as $subscription) {
1700 1700
 
1701 1701
             // for the following statuses we know the user was not added
1702 1702
             // manually
1703 1703
             $status = $subscription->get_status();
1704
-            if ( in_array( $status, array( 'pending-canceled', 'active', 'on-hold', 'pending' ) ) ) {
1704
+            if (in_array($status, array('pending-canceled', 'active', 'on-hold', 'pending'))) {
1705 1705
 
1706 1706
                 continue;
1707 1707
 
1708 1708
             }
1709 1709
 
1710
-            $current_subscription_start_date = date_create( $subscription->modified_date );
1710
+            $current_subscription_start_date = date_create($subscription->modified_date);
1711 1711
 
1712 1712
             // is the last updated subscription date newer than course start date
1713
-            if (  $current_subscription_start_date > $course_start_date   ) {
1713
+            if ($current_subscription_start_date > $course_start_date) {
1714 1714
 
1715 1715
                 return false;
1716 1716
 
@@ -1729,20 +1729,20 @@  discard block
 block discarded – undo
1729 1729
 	 *
1730 1730
 	 * @return array $orders
1731 1731
 	 */
1732
-	public static function get_user_product_orders( $user_id =  0, $product_id ) {
1732
+	public static function get_user_product_orders($user_id = 0, $product_id) {
1733 1733
 
1734 1734
 		$args = array(
1735 1735
 			'numberposts' => -1,
1736 1736
 			'post_type' => 'shop_order',
1737 1737
 			'meta_key'    => '_customer_user',
1738
-			'meta_value'  => intval( $user_id ),
1738
+			'meta_value'  => intval($user_id),
1739 1739
 		);
1740 1740
 
1741
-		if( class_exists( 'WC_Subscriptions_Manager' ) ) {
1742
-			$args['post_type'] = array( 'shop_order', 'shop_subscription' );
1741
+		if (class_exists('WC_Subscriptions_Manager')) {
1742
+			$args['post_type'] = array('shop_order', 'shop_subscription');
1743 1743
 		}
1744 1744
 
1745
-		return get_posts( $args );
1745
+		return get_posts($args);
1746 1746
 
1747 1747
 	}
1748 1748
 
@@ -1758,12 +1758,12 @@  discard block
 block discarded – undo
1758 1758
 	 *
1759 1759
 	 * @return bool
1760 1760
 	 */
1761
-	public static function is_course_purchasable( $course_id = 0 ){
1761
+	public static function is_course_purchasable($course_id = 0) {
1762 1762
 
1763
-		if( ! self::is_woocommerce_active() ){
1763
+		if ( ! self::is_woocommerce_active()) {
1764 1764
 			return false;
1765 1765
 		}
1766
-		$course_product = wc_get_product( self::get_course_product_id( $course_id ) );
1766
+		$course_product = wc_get_product(self::get_course_product_id($course_id));
1767 1767
 
1768 1768
 		return $course_product->is_purchasable();
1769 1769
 
Please login to merge, or discard this patch.