Completed
Push — master ( 201c1b...d51ce1 )
by Dwain
04:57
created
includes/class-sensei-admin.php 1 patch
Spacing   +419 added lines, -419 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Administration Class
@@ -21,51 +21,51 @@  discard block
 block discarded – undo
21 21
 	 * @since  1.0.0
22 22
 	 * @return  void
23 23
 	 */
24
-	public function __construct () {
24
+	public function __construct() {
25 25
 
26 26
         //register admin styles
27
-		add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_global' ) );
27
+		add_action('admin_enqueue_scripts', array($this, 'admin_styles_global'));
28 28
 
29 29
         //register admin scripts
30
-        add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
30
+        add_action('admin_enqueue_scripts', array($this, 'register_scripts'));
31 31
 
32
-		add_action( 'admin_print_styles', array( $this, 'admin_notices_styles' ) );
33
-		add_action( 'settings_before_form', array( $this, 'install_pages_output' ) );
34
-		add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
35
-		add_action( 'menu_order', array( $this, 'admin_menu_order' ) );
36
-		add_action( 'admin_head', array( $this, 'admin_menu_highlight' ) );
37
-		add_action( 'admin_init', array( $this, 'page_redirect' ) );
38
-		add_action( 'admin_init', array( $this, 'sensei_add_custom_menu_items' ) );
39
-        add_action( 'admin_init', array( __CLASS__, 'install_pages' ));
32
+		add_action('admin_print_styles', array($this, 'admin_notices_styles'));
33
+		add_action('settings_before_form', array($this, 'install_pages_output'));
34
+		add_action('admin_menu', array($this, 'admin_menu'), 10);
35
+		add_action('menu_order', array($this, 'admin_menu_order'));
36
+		add_action('admin_head', array($this, 'admin_menu_highlight'));
37
+		add_action('admin_init', array($this, 'page_redirect'));
38
+		add_action('admin_init', array($this, 'sensei_add_custom_menu_items'));
39
+        add_action('admin_init', array(__CLASS__, 'install_pages'));
40 40
 
41 41
 		// Duplicate lesson & courses
42
-		add_filter( 'post_row_actions', array( $this, 'duplicate_action_link' ), 10, 2 );
43
-		add_action( 'admin_action_duplicate_lesson', array( $this, 'duplicate_lesson_action' ) );
44
-		add_action( 'admin_action_duplicate_course', array( $this, 'duplicate_course_action' ) );
45
-		add_action( 'admin_action_duplicate_course_with_lessons', array( $this, 'duplicate_course_with_lessons_action' ) );
42
+		add_filter('post_row_actions', array($this, 'duplicate_action_link'), 10, 2);
43
+		add_action('admin_action_duplicate_lesson', array($this, 'duplicate_lesson_action'));
44
+		add_action('admin_action_duplicate_course', array($this, 'duplicate_course_action'));
45
+		add_action('admin_action_duplicate_course_with_lessons', array($this, 'duplicate_course_with_lessons_action'));
46 46
 
47 47
 		// Handle lessons list table filtering
48
-		add_action( 'restrict_manage_posts', array( $this, 'lesson_filter_options' ) );
49
-		add_filter( 'request', array( $this, 'lesson_filter_actions' ) );
48
+		add_action('restrict_manage_posts', array($this, 'lesson_filter_options'));
49
+		add_filter('request', array($this, 'lesson_filter_actions'));
50 50
 
51 51
 		// Add Sensei items to 'at a glance' widget
52
-		add_filter( 'dashboard_glance_items', array( $this, 'glance_items' ), 10, 1 );
52
+		add_filter('dashboard_glance_items', array($this, 'glance_items'), 10, 1);
53 53
 
54 54
 		// Handle course and lesson deletions
55
-		add_action( 'trash_course', array( $this, 'delete_content' ), 10, 2 );
56
-		add_action( 'trash_lesson', array( $this, 'delete_content' ), 10, 2 );
55
+		add_action('trash_course', array($this, 'delete_content'), 10, 2);
56
+		add_action('trash_lesson', array($this, 'delete_content'), 10, 2);
57 57
 
58 58
 		// Delete user activity when user is deleted
59
-		add_action( 'deleted_user', array( $this, 'delete_user_activity' ), 10, 1 );
59
+		add_action('deleted_user', array($this, 'delete_user_activity'), 10, 1);
60 60
 
61 61
 		// Add notices to WP dashboard
62
-		add_action( 'admin_notices', array( $this, 'theme_compatibility_notices' ) );
62
+		add_action('admin_notices', array($this, 'theme_compatibility_notices'));
63 63
 
64 64
 		// Reset theme notices when switching themes
65
-		add_action( 'switch_theme', array( $this, 'reset_theme_check_notices' ) );
65
+		add_action('switch_theme', array($this, 'reset_theme_check_notices'));
66 66
 
67 67
 		// Allow Teacher access the admin area
68
-		add_filter( 'woocommerce_prevent_admin_access', array( $this, 'admin_access' ) );
68
+		add_filter('woocommerce_prevent_admin_access', array($this, 'admin_access'));
69 69
 
70 70
 	} // End __construct()
71 71
 
@@ -77,21 +77,21 @@  discard block
 block discarded – undo
77 77
 	public function admin_menu() {
78 78
 		global $menu;
79 79
 		$menu_cap = '';
80
-		if( current_user_can( 'manage_sensei' ) ) {
80
+		if (current_user_can('manage_sensei')) {
81 81
 			$menu_cap = 'manage_sensei';
82 82
 		} else {
83
-			if( current_user_can( 'manage_sensei_grades' ) ) {
83
+			if (current_user_can('manage_sensei_grades')) {
84 84
 				$menu_cap = 'manage_sensei_grades';
85 85
 			}
86 86
 		}
87 87
 
88
-		if( $menu_cap ) {
89
-			$menu[] = array( '', 'read', 'separator-sensei', '', 'wp-menu-separator sensei' );
90
-            add_menu_page( 'Sensei', 'Sensei', $menu_cap, 'sensei' , array( Sensei()->analysis, 'analysis_page' ) , '', '50' );
88
+		if ($menu_cap) {
89
+			$menu[] = array('', 'read', 'separator-sensei', '', 'wp-menu-separator sensei');
90
+            add_menu_page('Sensei', 'Sensei', $menu_cap, 'sensei', array(Sensei()->analysis, 'analysis_page'), '', '50');
91 91
 		}
92 92
 
93
-		add_submenu_page( 'edit.php?post_type=course', __( 'Order Courses', 'woothemes-sensei' ), __( 'Order Courses', 'woothemes-sensei' ), 'manage_sensei', 'course-order', array( $this, 'course_order_screen' ) );
94
-		add_submenu_page( 'edit.php?post_type=lesson', __( 'Order Lessons', 'woothemes-sensei' ), __( 'Order Lessons', 'woothemes-sensei' ), 'edit_lessons', 'lesson-order', array( $this, 'lesson_order_screen' ) );
93
+		add_submenu_page('edit.php?post_type=course', __('Order Courses', 'woothemes-sensei'), __('Order Courses', 'woothemes-sensei'), 'manage_sensei', 'course-order', array($this, 'course_order_screen'));
94
+		add_submenu_page('edit.php?post_type=lesson', __('Order Lessons', 'woothemes-sensei'), __('Order Lessons', 'woothemes-sensei'), 'edit_lessons', 'lesson-order', array($this, 'lesson_order_screen'));
95 95
 	}
96 96
 
97 97
 	/**
@@ -100,22 +100,22 @@  discard block
 block discarded – undo
100 100
 	 * @param  array $menu_order Existing menu order
101 101
 	 * @return array 			 Modified menu order for Sensei
102 102
 	 */
103
-	public function admin_menu_order( $menu_order ) {
103
+	public function admin_menu_order($menu_order) {
104 104
 
105 105
 		// Initialize our custom order array
106 106
 		$sensei_menu_order = array();
107 107
 
108 108
 		// Get the index of our custom separator
109
-		$sensei_separator = array_search( 'separator-sensei', $menu_order );
109
+		$sensei_separator = array_search('separator-sensei', $menu_order);
110 110
 
111 111
 		// Loop through menu order and do some rearranging
112
-		foreach ( $menu_order as $index => $item ) :
112
+		foreach ($menu_order as $index => $item) :
113 113
 
114
-			if ( ( ( 'sensei' ) == $item ) ) :
114
+			if ((('sensei') == $item)) :
115 115
 				$sensei_menu_order[] = 'separator-sensei';
116 116
 				$sensei_menu_order[] = $item;
117
-				unset( $menu_order[$sensei_separator] );
118
-			elseif ( !in_array( $item, array( 'separator-sensei' ) ) ) :
117
+				unset($menu_order[$sensei_separator]);
118
+			elseif ( ! in_array($item, array('separator-sensei'))) :
119 119
 				$sensei_menu_order[] = $item;
120 120
 			endif;
121 121
 
@@ -135,24 +135,24 @@  discard block
 block discarded – undo
135 135
 
136 136
 		$screen = get_current_screen();
137 137
 
138
-		if ( $screen->base == 'post' && $post_type == 'course' ) {
138
+		if ($screen->base == 'post' && $post_type == 'course') {
139 139
 
140
-			$parent_file  = 'edit.php?post_type=course';
140
+			$parent_file = 'edit.php?post_type=course';
141 141
 
142
-		} elseif ( $screen->base == 'edit-tags' && $taxonomy == 'course-category' ) {
142
+		} elseif ($screen->base == 'edit-tags' && $taxonomy == 'course-category') {
143 143
 
144 144
 			$submenu_file = 'edit-tags.php?taxonomy=course-category&amp;post_type=course';
145 145
 			$parent_file  = 'edit.php?post_type=course';
146 146
 
147
-        } elseif ( $screen->base == 'edit-tags' && $taxonomy == 'module' ) {
147
+        } elseif ($screen->base == 'edit-tags' && $taxonomy == 'module') {
148 148
 
149 149
             $submenu_file = 'edit-tags.php?taxonomy=module';
150 150
             $parent_file  = 'edit.php?post_type=course';
151 151
 
152
-		} elseif ( in_array( $screen->id, array( 'sensei_message', 'edit-sensei_message' ) ) ) {
152
+		} elseif (in_array($screen->id, array('sensei_message', 'edit-sensei_message'))) {
153 153
 
154 154
             $submenu_file = 'edit.php?post_type=sensei_message';
155
-			$parent_file  = 'sensei';
155
+			$parent_file = 'sensei';
156 156
 
157 157
 		}
158 158
 	}
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
 	 * @return void
164 164
 	 */
165 165
 	public function page_redirect() {
166
-		if( isset( $_GET['page'] ) && $_GET['page'] == 'sensei' ) {
167
-			wp_safe_redirect( 'admin.php?page=sensei_analysis' );
166
+		if (isset($_GET['page']) && $_GET['page'] == 'sensei') {
167
+			wp_safe_redirect('admin.php?page=sensei_analysis');
168 168
 			exit;
169 169
 		}
170 170
 	}
@@ -179,11 +179,11 @@  discard block
 block discarded – undo
179 179
 	 */
180 180
 	function install_pages_output() {
181 181
 
182
-        if( isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
182
+        if (isset($_GET['sensei_install_complete']) && 'true' == $_GET['sensei_install_complete']) {
183 183
 
184 184
             ?>
185 185
             <div id="message" class="updated sensei-message sensei-connect">
186
-                <p><?php _e( '<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei' ); ?></p>
186
+                <p><?php _e('<strong>Congratulations!</strong> &#8211; Sensei has been installed and set up.', 'woothemes-sensei'); ?></p>
187 187
                 <p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.woothemes.com/sensei/" data-text="A premium Learning Management plugin for #WordPress that helps you create courses. Beautifully." data-via="WooThemes" data-size="large" data-hashtags="Sensei">Tweet</a>
188 188
                 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
189 189
             </div>
@@ -205,18 +205,18 @@  discard block
 block discarded – undo
205 205
 	 * @param int $post_parent (default: 0)
206 206
 	 * @return void
207 207
 	 */
208
-	function create_page( $slug, $option, $page_title = '', $page_content = '', $post_parent = 0 ) {
208
+	function create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0) {
209 209
 		global $wpdb;
210 210
 
211
-		$option_value = get_option( $option );
211
+		$option_value = get_option($option);
212 212
 
213
-		if ( $option_value > 0 && get_post( $option_value ) )
213
+		if ($option_value > 0 && get_post($option_value))
214 214
 			return;
215 215
 
216
-		$page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_name = %s LIMIT 1;", $slug ) );
217
-		if ( $page_found ) :
218
-			if ( ! $option_value )
219
-				update_option( $option, $page_found );
216
+		$page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM ".$wpdb->posts." WHERE post_name = %s LIMIT 1;", $slug));
217
+		if ($page_found) :
218
+			if ( ! $option_value)
219
+				update_option($option, $page_found);
220 220
 			return;
221 221
 		endif;
222 222
 
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	        'post_parent' 		=> $post_parent,
231 231
 	        'comment_status' 	=> 'closed'
232 232
 	    );
233
-	    $page_id = wp_insert_post( $page_data );
233
+	    $page_id = wp_insert_post($page_data);
234 234
 
235
-	    update_option( $option, $page_id );
235
+	    update_option($option, $page_id);
236 236
 	} // End create_page()
237 237
 
238 238
 
@@ -245,10 +245,10 @@  discard block
 block discarded – undo
245 245
 	function create_pages() {
246 246
 
247 247
 		// Courses page
248
-	    $this->create_page( esc_sql( _x('courses-overview', 'page_slug', 'woothemes-sensei') ), $this->token . '_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]' );
248
+	    $this->create_page(esc_sql(_x('courses-overview', 'page_slug', 'woothemes-sensei')), $this->token.'_courses_page_id', __('Courses', 'woothemes-sensei'), '[newcourses][featuredcourses][freecourses][paidcourses]');
249 249
 
250 250
 		// User Dashboard page
251
-	    $this->create_page( esc_sql( _x('my-courses', 'page_slug', 'woothemes-sensei') ), $this->token . '_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]' );
251
+	    $this->create_page(esc_sql(_x('my-courses', 'page_slug', 'woothemes-sensei')), $this->token.'_user_dashboard_page_id', __('My Courses', 'woothemes-sensei'), '[usercourses]');
252 252
 
253 253
 	} // End create_pages()
254 254
 
@@ -258,25 +258,25 @@  discard block
 block discarded – undo
258 258
 	 * @since 1.0.0
259 259
 	 * @return void
260 260
 	 */
261
-	public function admin_styles_global ( $hook ) {
261
+	public function admin_styles_global($hook) {
262 262
 		global $post_type;
263 263
 
264
-		$allowed_post_types = apply_filters( 'sensei_scripts_allowed_post_types', array( 'lesson', 'course', 'question' ) );
265
-		$allowed_post_type_pages = apply_filters( 'sensei_scripts_allowed_post_type_pages', array( 'edit.php', 'post-new.php', 'post.php', 'edit-tags.php' ) );
266
-		$allowed_pages = apply_filters( 'sensei_scripts_allowed_pages', array( 'sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order' ) );
264
+		$allowed_post_types = apply_filters('sensei_scripts_allowed_post_types', array('lesson', 'course', 'question'));
265
+		$allowed_post_type_pages = apply_filters('sensei_scripts_allowed_post_type_pages', array('edit.php', 'post-new.php', 'post.php', 'edit-tags.php'));
266
+		$allowed_pages = apply_filters('sensei_scripts_allowed_pages', array('sensei_grading', 'sensei_analysis', 'sensei_learners', 'sensei_updates', 'woothemes-sensei-settings', 'lesson-order', 'course-order'));
267 267
 
268 268
 		// Global Styles for icons and menu items
269
-		wp_register_style( Sensei()->token . '-global', Sensei()->plugin_url . 'assets/css/global.css', '', Sensei()->version, 'screen' );
270
-		wp_enqueue_style( Sensei()->token . '-global' );
269
+		wp_register_style(Sensei()->token.'-global', Sensei()->plugin_url.'assets/css/global.css', '', Sensei()->version, 'screen');
270
+		wp_enqueue_style(Sensei()->token.'-global');
271 271
 
272 272
         // Select 2 styles
273
-        wp_enqueue_style( 'select2', Sensei()->plugin_url . 'assets/css/select2/select2.css', '', Sensei()->version, 'screen' );
273
+        wp_enqueue_style('select2', Sensei()->plugin_url.'assets/css/select2/select2.css', '', Sensei()->version, 'screen');
274 274
 
275 275
 		// Test for Write Panel Pages
276
-		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 ) ) ) {
276
+		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))) {
277 277
 
278
-			wp_register_style( Sensei()->token . '-admin-custom', Sensei()->plugin_url . 'assets/css/admin-custom.css', '', Sensei()->version, 'screen' );
279
-			wp_enqueue_style( Sensei()->token . '-admin-custom' );
278
+			wp_register_style(Sensei()->token.'-admin-custom', Sensei()->plugin_url.'assets/css/admin-custom.css', '', Sensei()->version, 'screen');
279
+			wp_enqueue_style(Sensei()->token.'-admin-custom');
280 280
 
281 281
 		}
282 282
 
@@ -291,20 +291,20 @@  discard block
 block discarded – undo
291 291
      * @since 1.8.2
292 292
      * @access public
293 293
      */
294
-    public function register_scripts( $hook ){
294
+    public function register_scripts($hook) {
295 295
 
296 296
         $screen = get_current_screen();
297 297
 
298 298
         // Allow developers to load non-minified versions of scripts
299
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
299
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
300 300
 
301 301
         // Select2 script used to enhance all select boxes
302
-        wp_register_script( 'select2', Sensei()->plugin_url . '/assets/js/select2/select2' . $suffix . '.js', array( 'jquery' ), Sensei()->version );
302
+        wp_register_script('select2', Sensei()->plugin_url.'/assets/js/select2/select2'.$suffix.'.js', array('jquery'), Sensei()->version);
303 303
 
304 304
         // load edit module scripts
305
-        if( 'edit-module' ==  $screen->id ){
305
+        if ('edit-module' == $screen->id) {
306 306
 
307
-            wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery.min.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version, true );
307
+            wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery.min.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
308 308
 
309 309
         }
310 310
 
@@ -322,19 +322,19 @@  discard block
 block discarded – undo
322 322
 	    <div id="message" class="updated sensei-message sensei-connect">
323 323
 
324 324
             <p>
325
-                <?php _e( '<strong>Welcome to Sensei</strong> &#8211; You\'re almost ready to create some courses!', 'woothemes-sensei' ); ?>
325
+                <?php _e('<strong>Welcome to Sensei</strong> &#8211; You\'re almost ready to create some courses!', 'woothemes-sensei'); ?>
326 326
             </p>
327 327
 
328 328
             <p class="submit">
329 329
 
330
-                <a href="<?php echo esc_url( add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings') ) ); ?>"
330
+                <a href="<?php echo esc_url(add_query_arg('install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>"
331 331
                    class="button-primary">
332 332
 
333
-                    <?php _e( 'Install Sensei Pages', 'woothemes-sensei' ); ?>
333
+                    <?php _e('Install Sensei Pages', 'woothemes-sensei'); ?>
334 334
 
335 335
                 </a>
336 336
 
337
-                <a class="skip button" href="<?php echo esc_url( add_query_arg( 'skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings' ) ) ); ?>">
337
+                <a class="skip button" href="<?php echo esc_url(add_query_arg('skip_install_sensei_pages', 'true', admin_url('admin.php?page=woothemes-sensei-settings'))); ?>">
338 338
 
339 339
                     <?php _e('Skip setup', 'woothemes-sensei'); ?>
340 340
 
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
 	    <div id="message" class="updated sensei-message sensei-connect">
358 358
 
359 359
 	    	<p>
360
-                <?php _e( '<strong>Sensei has been installed</strong> &#8211; You\'re ready to start creating courses!', 'woothemes-sensei' ); ?>
360
+                <?php _e('<strong>Sensei has been installed</strong> &#8211; You\'re ready to start creating courses!', 'woothemes-sensei'); ?>
361 361
             </p>
362 362
 
363 363
 			<p class="submit">
364
-                <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e( 'Settings', 'woothemes-sensei' ); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/">
364
+                <a href="<?php echo admin_url('admin.php?page=woothemes-sensei-settings'); ?>" class="button-primary"><?php _e('Settings', 'woothemes-sensei'); ?></a> <a class="docs button" href="http://www.woothemes.com/sensei-docs/">
365 365
                     <?php _e('Documentation', 'woothemes-sensei'); ?>
366 366
                 </a>
367 367
             </p>
@@ -394,11 +394,11 @@  discard block
 block discarded – undo
394 394
 	public function language_pack_install_notice() {
395 395
 		?>
396 396
 		<div id="message" class="updated sensei-message sensei-connect">
397
-				<p><?php _e( '<strong>Sensei in your language</strong> &#8211; There is a translation available for your language.', 'woothemes-sensei' ); ?><p>
397
+				<p><?php _e('<strong>Sensei in your language</strong> &#8211; There is a translation available for your language.', 'woothemes-sensei'); ?><p>
398 398
 
399 399
 				<p class="submit">
400
-					<a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_install_uri() ); ?>" class="button-primary"><?php _e( 'Install', 'woothemes-sensei' ); ?></a>
401
-					<a href="<?php echo esc_url( Sensei_Language_Pack_Manager::get_dismiss_uri() ) ?>" class="docs button"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?></a>
400
+					<a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_install_uri()); ?>" class="button-primary"><?php _e('Install', 'woothemes-sensei'); ?></a>
401
+					<a href="<?php echo esc_url(Sensei_Language_Pack_Manager::get_dismiss_uri()) ?>" class="docs button"><?php _e('Hide this notice', 'woothemes-sensei'); ?></a>
402 402
 				</p>
403 403
 		</div>
404 404
 		<?php
@@ -414,20 +414,20 @@  discard block
 block discarded – undo
414 414
 	function admin_notices_styles() {
415 415
 
416 416
 		// Installed notices
417
-	    if ( 1 == get_option( 'sensei_installed' ) ) {
417
+	    if (1 == get_option('sensei_installed')) {
418 418
 
419
-	    	wp_enqueue_style( 'sensei-activation', plugins_url(  '/assets/css/activation.css', dirname( __FILE__ ) ), '', Sensei()->version );
419
+	    	wp_enqueue_style('sensei-activation', plugins_url('/assets/css/activation.css', dirname(__FILE__)), '', Sensei()->version);
420 420
 
421
-	    	if (get_option('skip_install_sensei_pages')!=1 && Sensei()->get_page_id('course')<1 && !isset($_GET['install_sensei_pages']) && !isset($_GET['skip_install_sensei_pages'])) {
422
-	    		add_action( 'admin_notices', array( $this, 'admin_install_notice' ) );
423
-	    	} elseif ( !isset($_GET['page']) || $_GET['page']!='woothemes-sensei-settings' ) {
424
-	    		add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
421
+	    	if (get_option('skip_install_sensei_pages') != 1 && Sensei()->get_page_id('course') < 1 && ! isset($_GET['install_sensei_pages']) && ! isset($_GET['skip_install_sensei_pages'])) {
422
+	    		add_action('admin_notices', array($this, 'admin_install_notice'));
423
+	    	} elseif ( ! isset($_GET['page']) || $_GET['page'] != 'woothemes-sensei-settings') {
424
+	    		add_action('admin_notices', array($this, 'admin_installed_notice'));
425 425
 	    	} // End If Statement
426 426
 
427 427
 	    } // End If Statement
428 428
 
429
-	    if ( Sensei_Language_Pack_Manager::has_language_pack_available() ) {
430
-	    	add_action( 'admin_notices', array( $this, 'language_pack_install_notice' ) );
429
+	    if (Sensei_Language_Pack_Manager::has_language_pack_available()) {
430
+	    	add_action('admin_notices', array($this, 'language_pack_install_notice'));
431 431
 	    }
432 432
 
433 433
 	} // End admin_notices_styles()
@@ -438,17 +438,17 @@  discard block
 block discarded – undo
438 438
 	 * @param  object $post    Current post
439 439
 	 * @return array           Modified actions
440 440
 	 */
441
-	public function duplicate_action_link( $actions, $post ) {
442
-		switch( $post->post_type ) {
441
+	public function duplicate_action_link($actions, $post) {
442
+		switch ($post->post_type) {
443 443
 			case 'lesson':
444
-				$confirm = __( 'This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei' );
445
-				$actions['duplicate'] = "<a onclick='return confirm(\"" . $confirm . "\");' href='" . $this->get_duplicate_link( $post->ID ) . "' title='" . esc_attr(__( 'Duplicate this lesson', 'woothemes-sensei' ) ) . "'>" .  __('Duplicate', 'woothemes-sensei' ) . "</a>";
444
+				$confirm = __('This will duplicate the lesson quiz and all of its questions. Are you sure you want to do this?', 'woothemes-sensei');
445
+				$actions['duplicate'] = "<a onclick='return confirm(\"".$confirm."\");' href='".$this->get_duplicate_link($post->ID)."' title='".esc_attr(__('Duplicate this lesson', 'woothemes-sensei'))."'>".__('Duplicate', 'woothemes-sensei')."</a>";
446 446
 			break;
447 447
 
448 448
 			case 'course':
449
-				$confirm = __( 'This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei' );
450
-				$actions['duplicate'] = '<a href="' . $this->get_duplicate_link( $post->ID ) . '" title="' . esc_attr(__( 'Duplicate this course', 'woothemes-sensei' ) ) . '">' .  __('Duplicate', 'woothemes-sensei' ) . '</a>';
451
-				$actions['duplicate_with_lessons'] = '<a onclick="return confirm(\'' . $confirm . '\');" href="' . $this->get_duplicate_link( $post->ID, true ) . '" title="' . esc_attr(__( 'Duplicate this course with its lessons', 'woothemes-sensei' ) ) . '">' .  __('Duplicate (with lessons)', 'woothemes-sensei' ) . '</a>';
449
+				$confirm = __('This will duplicate the course lessons along with all of their quizzes and questions. Are you sure you want to do this?', 'woothemes-sensei');
450
+				$actions['duplicate'] = '<a href="'.$this->get_duplicate_link($post->ID).'" title="'.esc_attr(__('Duplicate this course', 'woothemes-sensei')).'">'.__('Duplicate', 'woothemes-sensei').'</a>';
451
+				$actions['duplicate_with_lessons'] = '<a onclick="return confirm(\''.$confirm.'\');" href="'.$this->get_duplicate_link($post->ID, true).'" title="'.esc_attr(__('Duplicate this course with its lessons', 'woothemes-sensei')).'">'.__('Duplicate (with lessons)', 'woothemes-sensei').'</a>';
452 452
 			break;
453 453
 		}
454 454
 
@@ -461,17 +461,17 @@  discard block
 block discarded – undo
461 461
 	 * @param  boolean $with_lessons Include lessons or not
462 462
 	 * @return string                Duplication link
463 463
 	 */
464
-	private function get_duplicate_link( $post_id = 0, $with_lessons = false ) {
464
+	private function get_duplicate_link($post_id = 0, $with_lessons = false) {
465 465
 
466
-		$post = get_post( $post_id );
466
+		$post = get_post($post_id);
467 467
 
468
-		$action = 'duplicate_' . $post->post_type;
468
+		$action = 'duplicate_'.$post->post_type;
469 469
 
470
-		if( 'course' == $post->post_type && $with_lessons ) {
470
+		if ('course' == $post->post_type && $with_lessons) {
471 471
 			$action .= '_with_lessons';
472 472
 		}
473 473
 
474
-		return apply_filters( $action . '_link', admin_url( 'admin.php?action=' . $action . '&post=' . $post_id ), $post_id );
474
+		return apply_filters($action.'_link', admin_url('admin.php?action='.$action.'&post='.$post_id), $post_id);
475 475
 	}
476 476
 
477 477
 	/**
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	 * @return void
480 480
 	 */
481 481
 	public function duplicate_lesson_action() {
482
-		$this->duplicate_content( 'lesson' );
482
+		$this->duplicate_content('lesson');
483 483
 	}
484 484
 
485 485
 	/**
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 	 * @return void
488 488
 	 */
489 489
 	public function duplicate_course_action() {
490
-		$this->duplicate_content( 'course' );
490
+		$this->duplicate_content('course');
491 491
 	}
492 492
 
493 493
 	/**
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
 	 * @return void
496 496
 	 */
497 497
 	public function duplicate_course_with_lessons_action() {
498
-		$this->duplicate_content( 'course', true );
498
+		$this->duplicate_content('course', true);
499 499
 	}
500 500
 
501 501
 	/**
@@ -504,34 +504,34 @@  discard block
 block discarded – undo
504 504
 	 * @param  boolean $with_lessons Include lessons or not
505 505
 	 * @return void
506 506
 	 */
507
-	private function duplicate_content( $post_type = 'lesson', $with_lessons = false ) {
508
-		if ( ! isset( $_GET['post'] ) ) {
509
-			wp_die( sprintf( __( 'Please supply a %1$s ID.', 'woothemes-sensei' ) ), $post_type );
507
+	private function duplicate_content($post_type = 'lesson', $with_lessons = false) {
508
+		if ( ! isset($_GET['post'])) {
509
+			wp_die(sprintf(__('Please supply a %1$s ID.', 'woothemes-sensei')), $post_type);
510 510
 		}
511 511
 
512 512
 		$post_id = $_GET['post'];
513
-		$post = get_post( $post_id );
513
+		$post = get_post($post_id);
514 514
 
515
-		if( ! is_wp_error( $post ) ) {
515
+		if ( ! is_wp_error($post)) {
516 516
 
517
-			$new_post = $this->duplicate_post( $post );
517
+			$new_post = $this->duplicate_post($post);
518 518
 
519
-			if( $new_post && ! is_wp_error( $new_post ) ) {
519
+			if ($new_post && ! is_wp_error($new_post)) {
520 520
 
521
-				if( 'lesson' == $new_post->post_type ) {
522
-					$this->duplicate_lesson_quizzes( $post_id, $new_post->ID );
521
+				if ('lesson' == $new_post->post_type) {
522
+					$this->duplicate_lesson_quizzes($post_id, $new_post->ID);
523 523
 				}
524 524
 
525
-				if( 'course' == $new_post->post_type && $with_lessons ) {
526
-					$this->duplicate_course_lessons( $post_id, $new_post->ID );
525
+				if ('course' == $new_post->post_type && $with_lessons) {
526
+					$this->duplicate_course_lessons($post_id, $new_post->ID);
527 527
 				}
528 528
 
529
-				$redirect_url = admin_url( 'post.php?post=' . $new_post->ID . '&action=edit' );
529
+				$redirect_url = admin_url('post.php?post='.$new_post->ID.'&action=edit');
530 530
 			} else {
531
-				$redirect_url = admin_url( 'edit.php?post_type=' . $post->post_type . '&message=duplicate_failed' );
531
+				$redirect_url = admin_url('edit.php?post_type='.$post->post_type.'&message=duplicate_failed');
532 532
 			}
533 533
 
534
-			wp_safe_redirect( esc_url_raw( $redirect_url ) );
534
+			wp_safe_redirect(esc_url_raw($redirect_url));
535 535
 			exit;
536 536
 		}
537 537
 	}
@@ -542,19 +542,19 @@  discard block
 block discarded – undo
542 542
 	 * @param  integer $new_lesson_id ID of duplicate lesson
543 543
 	 * @return void
544 544
 	 */
545
-	private function duplicate_lesson_quizzes( $old_lesson_id, $new_lesson_id ) {
545
+	private function duplicate_lesson_quizzes($old_lesson_id, $new_lesson_id) {
546 546
 
547
-        $old_quiz_id = Sensei()->lesson->lesson_quizzes( $old_lesson_id );
548
-        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $old_quiz_id );
547
+        $old_quiz_id = Sensei()->lesson->lesson_quizzes($old_lesson_id);
548
+        $old_quiz_questions = Sensei()->lesson->lesson_quiz_questions($old_quiz_id);
549 549
 
550 550
         // duplicate the generic wp post information
551
-		$new_quiz = $this->duplicate_post( get_post( $old_quiz_id ), '' );
551
+		$new_quiz = $this->duplicate_post(get_post($old_quiz_id), '');
552 552
 
553 553
 		//update the new lesson data
554
-        add_post_meta( $new_lesson_id, '_lesson_quiz', $new_quiz->ID );
554
+        add_post_meta($new_lesson_id, '_lesson_quiz', $new_quiz->ID);
555 555
 
556 556
 		//update the new quiz data
557
-        add_post_meta( $new_quiz->ID, '_quiz_lesson', $new_lesson_id );
557
+        add_post_meta($new_quiz->ID, '_quiz_lesson', $new_lesson_id);
558 558
         wp_update_post(
559 559
             array(
560 560
                 'ID' => $new_quiz->ID,
@@ -562,15 +562,15 @@  discard block
 block discarded – undo
562 562
             )
563 563
         );
564 564
 
565
-		foreach( $old_quiz_questions as $question ) {
565
+		foreach ($old_quiz_questions as $question) {
566 566
 
567 567
 			// copy the question order over to the new quiz
568
-			$old_question_order = get_post_meta( $question->ID, '_quiz_question_order'. $old_quiz_id, true );
569
-            $new_question_order = str_ireplace( $old_quiz_id, $new_quiz->ID , $old_question_order );
570
-            add_post_meta( $question->ID, '_quiz_question_order' . $new_quiz->ID, $new_question_order );
568
+			$old_question_order = get_post_meta($question->ID, '_quiz_question_order'.$old_quiz_id, true);
569
+            $new_question_order = str_ireplace($old_quiz_id, $new_quiz->ID, $old_question_order);
570
+            add_post_meta($question->ID, '_quiz_question_order'.$new_quiz->ID, $new_question_order);
571 571
 
572 572
 			// Add question to quiz
573
-			add_post_meta( $question->ID, '_quiz_id', $new_quiz->ID, false );
573
+			add_post_meta($question->ID, '_quiz_id', $new_quiz->ID, false);
574 574
 
575 575
 		}
576 576
 	}
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 	 * @param  integer $new_course_id ID of duplicated course
582 582
 	 * @return void
583 583
 	 */
584
-	private function duplicate_course_lessons( $old_course_id, $new_course_id ) {
584
+	private function duplicate_course_lessons($old_course_id, $new_course_id) {
585 585
 		$lesson_args = array(
586 586
 			'post_type' => 'lesson',
587 587
 			'posts_per_page' => -1,
@@ -589,13 +589,13 @@  discard block
 block discarded – undo
589 589
 			'meta_value' => $old_course_id,
590 590
 			'suppress_filters' 	=> 0
591 591
 		);
592
-		$lessons = get_posts( $lesson_args );
592
+		$lessons = get_posts($lesson_args);
593 593
 
594
-		foreach( $lessons as $lesson ) {
595
-			$new_lesson = $this->duplicate_post( $lesson, '', true );
596
-			add_post_meta( $new_lesson->ID, '_lesson_course', $new_course_id );
594
+		foreach ($lessons as $lesson) {
595
+			$new_lesson = $this->duplicate_post($lesson, '', true);
596
+			add_post_meta($new_lesson->ID, '_lesson_course', $new_course_id);
597 597
 
598
-			$this->duplicate_lesson_quizzes( $lesson->ID, $new_lesson->ID );
598
+			$this->duplicate_lesson_quizzes($lesson->ID, $new_lesson->ID);
599 599
 		}
600 600
 	}
601 601
 
@@ -606,24 +606,24 @@  discard block
 block discarded – undo
606 606
 	 * @param  boolean $ignore_course Ignore lesson course when dulicating
607 607
 	 * @return object                 Duplicate post object
608 608
 	 */
609
-	private function duplicate_post( $post, $suffix = ' (Duplicate)', $ignore_course = false ) {
609
+	private function duplicate_post($post, $suffix = ' (Duplicate)', $ignore_course = false) {
610 610
 
611 611
 		$new_post = array();
612 612
 
613
-		foreach( $post as $k => $v ) {
614
-			if( ! in_array( $k, array( 'ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count' ) ) ) {
615
-				$new_post[ $k ] = $v;
613
+		foreach ($post as $k => $v) {
614
+			if ( ! in_array($k, array('ID', 'post_status', 'post_date', 'post_date_gmt', 'post_name', 'post_modified', 'post_modified_gmt', 'guid', 'comment_count'))) {
615
+				$new_post[$k] = $v;
616 616
 			}
617 617
 		}
618 618
 
619
-		$new_post['post_title'] .= __( $suffix, 'woothemes-sensei' );
619
+		$new_post['post_title'] .= __($suffix, 'woothemes-sensei');
620 620
 
621
-		$new_post['post_date'] = current_time( 'mysql' );
622
-		$new_post['post_date_gmt'] = get_gmt_from_date( $new_post['post_date'] );
621
+		$new_post['post_date'] = current_time('mysql');
622
+		$new_post['post_date_gmt'] = get_gmt_from_date($new_post['post_date']);
623 623
 		$new_post['post_modified'] = $new_post['post_date'];
624 624
 		$new_post['post_modified_gmt'] = $new_post['post_date_gmt'];
625 625
 
626
-		switch( $post->post_type ) {
626
+		switch ($post->post_type) {
627 627
 			case 'course': $new_post['post_status'] = 'draft'; break;
628 628
 			case 'lesson': $new_post['post_status'] = 'draft'; break;
629 629
 			case 'quiz': $new_post['post_status'] = 'publish'; break;
@@ -631,45 +631,45 @@  discard block
 block discarded – undo
631 631
 		}
632 632
 
633 633
 		// As per wp_update_post() we need to escape the data from the db.
634
-		$new_post = wp_slash( $new_post );
634
+		$new_post = wp_slash($new_post);
635 635
 
636
-		$new_post_id = wp_insert_post( $new_post );
636
+		$new_post_id = wp_insert_post($new_post);
637 637
 
638
-		if( ! is_wp_error( $new_post_id ) ) {
638
+		if ( ! is_wp_error($new_post_id)) {
639 639
 
640
-			$post_meta = get_post_custom( $post->ID );
641
-			if( $post_meta && count( $post_meta ) > 0 ) {
640
+			$post_meta = get_post_custom($post->ID);
641
+			if ($post_meta && count($post_meta) > 0) {
642 642
 
643
-				$ignore_meta = array( '_quiz_lesson', '_quiz_id', '_lesson_quiz' );
643
+				$ignore_meta = array('_quiz_lesson', '_quiz_id', '_lesson_quiz');
644 644
 
645
-				if( $ignore_course ) {
645
+				if ($ignore_course) {
646 646
 					$ignore_meta[] = '_lesson_course';
647 647
 				}
648 648
 
649
-				foreach( $post_meta as $key => $meta ) {
650
-					foreach( $meta as $value ) {
651
-						$value = maybe_unserialize( $value );
652
-						if( ! in_array( $key, $ignore_meta ) ) {
653
-							add_post_meta( $new_post_id, $key, $value );
649
+				foreach ($post_meta as $key => $meta) {
650
+					foreach ($meta as $value) {
651
+						$value = maybe_unserialize($value);
652
+						if ( ! in_array($key, $ignore_meta)) {
653
+							add_post_meta($new_post_id, $key, $value);
654 654
 						}
655 655
 					}
656 656
 				}
657 657
 			}
658 658
 
659
-			add_post_meta( $new_post_id, '_duplicate', $post->ID );
659
+			add_post_meta($new_post_id, '_duplicate', $post->ID);
660 660
 
661
-			$taxonomies = get_object_taxonomies( $post->post_type, 'objects' );
661
+			$taxonomies = get_object_taxonomies($post->post_type, 'objects');
662 662
 
663
-			foreach ( $taxonomies as $slug => $tax ) {
664
-				$terms = get_the_terms( $post->ID, $slug );
665
-				if( isset( $terms ) && is_array( $terms ) && 0 < count( $terms ) ) {
666
-					foreach( $terms as $term ) {
667
-						wp_set_object_terms( $new_post_id, $term->term_id, $slug, true );
663
+			foreach ($taxonomies as $slug => $tax) {
664
+				$terms = get_the_terms($post->ID, $slug);
665
+				if (isset($terms) && is_array($terms) && 0 < count($terms)) {
666
+					foreach ($terms as $term) {
667
+						wp_set_object_terms($new_post_id, $term->term_id, $slug, true);
668 668
 					}
669 669
 				}
670 670
 			}
671 671
 
672
-			$new_post = get_post( $new_post_id );
672
+			$new_post = get_post($new_post_id);
673 673
 
674 674
 			return $new_post;
675 675
 		}
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 	public function lesson_filter_options() {
685 685
 		global $typenow;
686 686
 
687
-		if( is_admin() && 'lesson' == $typenow ) {
687
+		if (is_admin() && 'lesson' == $typenow) {
688 688
 
689 689
 			$args = array(
690 690
 				'post_type' => 'course',
@@ -694,16 +694,16 @@  discard block
 block discarded – undo
694 694
 				'orderby' => 'menu_order date',
695 695
 				'order' => 'ASC',
696 696
 			);
697
-			$courses = get_posts( $args );
697
+			$courses = get_posts($args);
698 698
 
699
-			$selected = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : '';
699
+			$selected = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : '';
700 700
 			$course_options = '';
701
-			foreach( $courses as $course ) {
702
-				$course_options .= '<option value="' . esc_attr( $course->ID ) . '" ' . selected( $selected, $course->ID, false ) . '>' . get_the_title( $course->ID ) . '</option>';
701
+			foreach ($courses as $course) {
702
+				$course_options .= '<option value="'.esc_attr($course->ID).'" '.selected($selected, $course->ID, false).'>'.get_the_title($course->ID).'</option>';
703 703
 			}
704 704
 
705 705
 			$output = '<select name="lesson_course" id="dropdown_lesson_course">';
706
-			$output .= '<option value="">'.__( 'Show all courses', 'woothemes-sensei' ).'</option>';
706
+			$output .= '<option value="">'.__('Show all courses', 'woothemes-sensei').'</option>';
707 707
 			$output .= $course_options;
708 708
 			$output .= '</select>';
709 709
 
@@ -716,13 +716,13 @@  discard block
 block discarded – undo
716 716
 	 * @param  array $request Current request
717 717
 	 * @return array          Modified request
718 718
 	 */
719
-	public function lesson_filter_actions( $request ) {
719
+	public function lesson_filter_actions($request) {
720 720
 		global $typenow;
721 721
 
722
-		if( is_admin() && 'lesson' == $typenow ) {
723
-			$lesson_course = isset( $_GET['lesson_course'] ) ? $_GET['lesson_course'] : '';
722
+		if (is_admin() && 'lesson' == $typenow) {
723
+			$lesson_course = isset($_GET['lesson_course']) ? $_GET['lesson_course'] : '';
724 724
 
725
-			if( $lesson_course ) {
725
+			if ($lesson_course) {
726 726
 				$request['meta_key'] = '_lesson_course';
727 727
 				$request['meta_value'] = $lesson_course;
728 728
 				$request['meta_compare'] = '=';
@@ -737,27 +737,27 @@  discard block
 block discarded – undo
737 737
 	 * @param  array $items Existing items
738 738
 	 * @return array        Updated items
739 739
 	 */
740
-	public function glance_items( $items = array() ) {
740
+	public function glance_items($items = array()) {
741 741
 
742
-		$types = array( 'course', 'lesson', 'question' );
742
+		$types = array('course', 'lesson', 'question');
743 743
 
744
-		foreach( $types as $type ) {
745
-			if( ! post_type_exists( $type ) ) continue;
744
+		foreach ($types as $type) {
745
+			if ( ! post_type_exists($type)) continue;
746 746
 
747
-			$num_posts = wp_count_posts( $type );
747
+			$num_posts = wp_count_posts($type);
748 748
 
749
-			if( $num_posts ) {
749
+			if ($num_posts) {
750 750
 
751
-				$published = intval( $num_posts->publish );
752
-				$post_type = get_post_type_object( $type );
751
+				$published = intval($num_posts->publish);
752
+				$post_type = get_post_type_object($type);
753 753
 
754
-				$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'woothemes-sensei' );
755
-				$text = sprintf( $text, number_format_i18n( $published ) );
754
+				$text = _n('%s '.$post_type->labels->singular_name, '%s '.$post_type->labels->name, $published, 'woothemes-sensei');
755
+				$text = sprintf($text, number_format_i18n($published));
756 756
 
757
-				if ( current_user_can( $post_type->cap->edit_posts ) ) {
758
-					$items[] = sprintf( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text ) . "\n";
757
+				if (current_user_can($post_type->cap->edit_posts)) {
758
+					$items[] = sprintf('<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text)."\n";
759 759
 				} else {
760
-					$items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n";
760
+					$items[] = sprintf('<span class="%1$s-count">%2$s</span>', $type, $text)."\n";
761 761
 				}
762 762
 			}
763 763
 		}
@@ -771,13 +771,13 @@  discard block
 block discarded – undo
771 771
 	 * @param  object  $post    Post object
772 772
 	 * @return void
773 773
 	 */
774
-	public function delete_content( $post_id, $post ) {
774
+	public function delete_content($post_id, $post) {
775 775
 
776 776
 		$type = $post->post_type;
777 777
 
778
-		if( in_array( $type, array( 'lesson', 'course' ) ) ) {
778
+		if (in_array($type, array('lesson', 'course'))) {
779 779
 
780
-			$meta_key = '_' . $type . '_prerequisite';
780
+			$meta_key = '_'.$type.'_prerequisite';
781 781
 
782 782
 			$args = array(
783 783
 				'post_type' => $type,
@@ -787,10 +787,10 @@  discard block
 block discarded – undo
787 787
 				'meta_value' => $post_id
788 788
 			);
789 789
 
790
-			$posts = get_posts( $args );
790
+			$posts = get_posts($args);
791 791
 
792
-			foreach( $posts as $post ) {
793
-				delete_post_meta( $post->ID, $meta_key );
792
+			foreach ($posts as $post) {
793
+				delete_post_meta($post->ID, $meta_key);
794 794
 			}
795 795
 		}
796 796
 	}
@@ -800,181 +800,181 @@  discard block
 block discarded – undo
800 800
 	 * @param  integer $user_id User ID
801 801
 	 * @return void
802 802
 	 */
803
-	public function delete_user_activity( $user_id = 0 ) {
804
-		if( $user_id ) {
805
-			Sensei_Utils::delete_all_user_activity( $user_id );
803
+	public function delete_user_activity($user_id = 0) {
804
+		if ($user_id) {
805
+			Sensei_Utils::delete_all_user_activity($user_id);
806 806
 		}
807 807
 	}
808 808
 
809
-	public function render_settings( $settings = array(), $post_id = 0, $group_id = '' ) {
809
+	public function render_settings($settings = array(), $post_id = 0, $group_id = '') {
810 810
 
811 811
 		$html = '';
812 812
 
813
-		if( 0 == count( $settings ) ) return $html;
813
+		if (0 == count($settings)) return $html;
814 814
 
815
-		$html .= '<div class="sensei-options-panel">' . "\n";
815
+		$html .= '<div class="sensei-options-panel">'."\n";
816 816
 
817
-			$html .= '<div class="options_group" id="' . esc_attr( $group_id ) . '">' . "\n";
817
+			$html .= '<div class="options_group" id="'.esc_attr($group_id).'">'."\n";
818 818
 
819
-				foreach( $settings as $field ) {
819
+				foreach ($settings as $field) {
820 820
 
821 821
 					$data = '';
822 822
 
823
-					if( $post_id ) {
824
-						$data = get_post_meta( $post_id, '_' . $field['id'], true );
825
-						if( ! $data && isset( $field['default'] ) ) {
823
+					if ($post_id) {
824
+						$data = get_post_meta($post_id, '_'.$field['id'], true);
825
+						if ( ! $data && isset($field['default'])) {
826 826
 							$data = $field['default'];
827 827
 						}
828 828
 					} else {
829
-						$option = get_option( $field['id'] );
830
-						if( isset( $field['default'] ) ) {
829
+						$option = get_option($field['id']);
830
+						if (isset($field['default'])) {
831 831
 							$data = $field['default'];
832
-							if( $option ) {
832
+							if ($option) {
833 833
 								$data = $option;
834 834
 							}
835 835
 						}
836 836
 					}
837 837
 
838 838
 					$disabled = '';
839
-					if( isset( $field['disabled'] ) && $field['disabled'] ) {
840
-						$disabled = disabled( $field['disabled'], true, false );
839
+					if (isset($field['disabled']) && $field['disabled']) {
840
+						$disabled = disabled($field['disabled'], true, false);
841 841
 					}
842 842
 
843
-					if( 'hidden' != $field['type'] ) {
843
+					if ('hidden' != $field['type']) {
844 844
 
845 845
 						$class_tail = '';
846 846
 
847
-						if( isset( $field['class'] ) ) {
847
+						if (isset($field['class'])) {
848 848
 							$class_tail .= $field['class'];
849 849
 						}
850 850
 
851
-						if( isset( $field['disabled'] ) && $field['disabled'] ) {
851
+						if (isset($field['disabled']) && $field['disabled']) {
852 852
 							$class_tail .= ' disabled';
853 853
 						}
854 854
 
855
-						$html .= '<p class="form-field ' . esc_attr( $field['id'] ) . ' ' . esc_attr( $class_tail ) . '">' . "\n";
855
+						$html .= '<p class="form-field '.esc_attr($field['id']).' '.esc_attr($class_tail).'">'."\n";
856 856
 					}
857 857
 
858
-						if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) {
859
-							$html .= '<label for="' . esc_attr( $field['id'] ) . '">' . "\n";
858
+						if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) {
859
+							$html .= '<label for="'.esc_attr($field['id']).'">'."\n";
860 860
 						}
861 861
 
862
-							if( $field['label'] ) {
863
-								$html .= '<span class="label">' . esc_html( $field['label'] ) . '</span>';
862
+							if ($field['label']) {
863
+								$html .= '<span class="label">'.esc_html($field['label']).'</span>';
864 864
 							}
865 865
 
866
-							switch( $field['type'] ) {
866
+							switch ($field['type']) {
867 867
 								case 'text':
868 868
 								case 'password':
869
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $disabled . ' />' . "\n";
869
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$disabled.' />'."\n";
870 870
 								break;
871 871
 
872 872
 								case 'number':
873 873
 
874 874
 									$min = '';
875
-									if( isset( $field['min'] ) ) {
876
-										$min = 'min="' . esc_attr( $field['min'] ) . '"';
875
+									if (isset($field['min'])) {
876
+										$min = 'min="'.esc_attr($field['min']).'"';
877 877
 									}
878 878
 
879 879
 									$max = '';
880
-									if( isset( $field['max'] ) ) {
881
-										$max = 'max="' . esc_attr( $field['max'] ) . '"';
880
+									if (isset($field['max'])) {
881
+										$max = 'max="'.esc_attr($field['max']).'"';
882 882
 									}
883 883
 
884
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" value="' . $data . '" ' . $min . '  ' . $max . ' class="small-text" ' . $disabled . ' />' . "\n";
884
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" value="'.$data.'" '.$min.'  '.$max.' class="small-text" '.$disabled.' />'."\n";
885 885
 								break;
886 886
 
887 887
 								case 'textarea':
888
-									$html .= '<textarea id="' . esc_attr( $field['id'] ) . '" rows="5" cols="50" name="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . $disabled . '>' . $data . '</textarea><br/>'. "\n";
888
+									$html .= '<textarea id="'.esc_attr($field['id']).'" rows="5" cols="50" name="'.esc_attr($field['id']).'" placeholder="'.esc_attr($field['placeholder']).'" '.$disabled.'>'.$data.'</textarea><br/>'."\n";
889 889
 								break;
890 890
 
891 891
 								case 'checkbox':
892 892
                                     //backwards compatibility
893
-                                    if( empty( $data ) || 'on' == $data ){
893
+                                    if (empty($data) || 'on' == $data) {
894 894
                                         $checked_value = 'on';
895
-                                    }elseif( 'yes' == $data  ) {
895
+                                    }elseif ('yes' == $data) {
896 896
 
897 897
                                         $checked_value = 'yes';
898 898
 
899
-                                    }elseif( 'auto' == $data  ) {
899
+                                    }elseif ('auto' == $data) {
900 900
 
901 901
                                         $checked_value = 'auto';
902 902
 
903 903
                                     } else {
904 904
                                         $checked_value = 1;
905
-                                        $data = intval( $data );
905
+                                        $data = intval($data);
906 906
                                     }
907
-									$checked = checked( $checked_value, $data, false );
908
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" ' . $checked . ' ' . $disabled . '/>' . "\n";
907
+									$checked = checked($checked_value, $data, false);
908
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" '.$checked.' '.$disabled.'/>'."\n";
909 909
 								break;
910 910
 
911 911
 								case 'checkbox_multi':
912
-									foreach( $field['options'] as $k => $v ) {
912
+									foreach ($field['options'] as $k => $v) {
913 913
 										$checked = false;
914
-										if( in_array( $k, $data ) ) {
914
+										if (in_array($k, $data)) {
915 915
 											$checked = true;
916 916
 										}
917
-										$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n";
917
+										$html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="checkbox" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'[]" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n";
918 918
 									}
919 919
 								break;
920 920
 
921 921
 								case 'radio':
922
-									foreach( $field['options'] as $k => $v ) {
922
+									foreach ($field['options'] as $k => $v) {
923 923
 										$checked = false;
924
-										if( $k == $data ) {
924
+										if ($k == $data) {
925 925
 											$checked = true;
926 926
 										}
927
-										$html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="radio" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" ' . $disabled . ' /> ' . $v . '</label> ' . "\n";
927
+										$html .= '<label for="'.esc_attr($field['id'].'_'.$k).'"><input type="radio" '.checked($checked, true, false).' name="'.esc_attr($field['id']).'" value="'.esc_attr($k).'" id="'.esc_attr($field['id'].'_'.$k).'" '.$disabled.' /> '.$v.'</label> '."\n";
928 928
 									}
929 929
 								break;
930 930
 
931 931
 								case 'select':
932
-									$html .= '<select name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" ' . $disabled . '>' . "\n";
933
-									foreach( $field['options'] as $k => $v ) {
932
+									$html .= '<select name="'.esc_attr($field['id']).'" id="'.esc_attr($field['id']).'" '.$disabled.'>'."\n";
933
+									foreach ($field['options'] as $k => $v) {
934 934
 										$selected = false;
935
-										if( $k == $data ) {
935
+										if ($k == $data) {
936 936
 											$selected = true;
937 937
 										}
938
-										$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '">' . $v . '</option>' . "\n";
938
+										$html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'">'.$v.'</option>'."\n";
939 939
 									}
940
-									$html .= '</select><br/>' . "\n";
940
+									$html .= '</select><br/>'."\n";
941 941
 								break;
942 942
 
943 943
 								case 'select_multi':
944
-									$html .= '<select name="' . esc_attr( $field['id'] ) . '[]" id="' . esc_attr( $field['id'] ) . '" multiple="multiple" ' . $disabled . '>' . "\n";
945
-									foreach( $field['options'] as $k => $v ) {
944
+									$html .= '<select name="'.esc_attr($field['id']).'[]" id="'.esc_attr($field['id']).'" multiple="multiple" '.$disabled.'>'."\n";
945
+									foreach ($field['options'] as $k => $v) {
946 946
 										$selected = false;
947
-										if( in_array( $k, $data ) ) {
947
+										if (in_array($k, $data)) {
948 948
 											$selected = true;
949 949
 										}
950
-										$html .= '<option ' . selected( $selected, true, false ) . ' value="' . esc_attr( $k ) . '" />' . $v . '</option>' . "\n";
950
+										$html .= '<option '.selected($selected, true, false).' value="'.esc_attr($k).'" />'.$v.'</option>'."\n";
951 951
 									}
952 952
 									$html .= '</select> . "\n"';
953 953
 								break;
954 954
 
955 955
 								case 'hidden':
956
-									$html .= '<input id="' . esc_attr( $field['id'] ) . '" type="' . $field['type'] . '" name="' . esc_attr( $field['id'] ) . '" value="' . $data . '" ' . $disabled . '/>' . "\n";
956
+									$html .= '<input id="'.esc_attr($field['id']).'" type="'.$field['type'].'" name="'.esc_attr($field['id']).'" value="'.$data.'" '.$disabled.'/>'."\n";
957 957
 								break;
958 958
 
959 959
 							}
960 960
 
961
-							if( $field['description'] ) {
962
-								$html .= ' <span class="description">' . esc_html( $field['description'] ) . '</span>' . "\n";
961
+							if ($field['description']) {
962
+								$html .= ' <span class="description">'.esc_html($field['description']).'</span>'."\n";
963 963
 							}
964 964
 
965
-						if( ! in_array( $field['type'], array( 'hidden', 'checkbox_multi', 'radio' ) ) ) {
966
-							$html .= '</label>' . "\n";
965
+						if ( ! in_array($field['type'], array('hidden', 'checkbox_multi', 'radio'))) {
966
+							$html .= '</label>'."\n";
967 967
 						}
968 968
 
969
-					if( 'hidden' != $field['type'] ) {
970
-						$html .= '</p>' . "\n";
969
+					if ('hidden' != $field['type']) {
970
+						$html .= '</p>'."\n";
971 971
 					}
972 972
 
973 973
 				}
974 974
 
975
-			$html .= '</div>' . "\n";
975
+			$html .= '</div>'."\n";
976 976
 
977
-		$html .= '</div>' . "\n";
977
+		$html .= '</div>'."\n";
978 978
 
979 979
 		return $html;
980 980
 	}
@@ -985,61 +985,61 @@  discard block
 block discarded – undo
985 985
 	 */
986 986
 	public function course_order_screen() {
987 987
 
988
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
989
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version );
988
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
989
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version);
990 990
 
991 991
 		?><div id="course-order" class="wrap course-order">
992
-		<h2><?php _e( 'Order Courses', 'woothemes-sensei' ); ?></h2><?php
992
+		<h2><?php _e('Order Courses', 'woothemes-sensei'); ?></h2><?php
993 993
 
994 994
 		$html = '';
995 995
 
996
-		if( isset( $_POST['course-order'] ) && 0 < strlen( $_POST['course-order'] ) ) {
997
-			$ordered = $this->save_course_order( esc_attr( $_POST['course-order'] ) );
996
+		if (isset($_POST['course-order']) && 0 < strlen($_POST['course-order'])) {
997
+			$ordered = $this->save_course_order(esc_attr($_POST['course-order']));
998 998
 
999
-			if( $ordered ) {
1000
-				$html .= '<div class="updated fade">' . "\n";
1001
-				$html .= '<p>' . __( 'The course order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n";
1002
-				$html .= '</div>' . "\n";
999
+			if ($ordered) {
1000
+				$html .= '<div class="updated fade">'."\n";
1001
+				$html .= '<p>'.__('The course order has been saved.', 'woothemes-sensei').'</p>'."\n";
1002
+				$html .= '</div>'."\n";
1003 1003
 			}
1004 1004
 		}
1005 1005
 
1006 1006
 		$courses = Sensei()->course->get_all_courses();
1007 1007
 
1008
-		if( 0 < count( $courses ) ) {
1008
+		if (0 < count($courses)) {
1009 1009
 
1010 1010
             // order the courses as set by the users
1011 1011
             $all_course_ids = array();
1012
-            foreach( $courses as $course ){
1012
+            foreach ($courses as $course) {
1013 1013
 
1014
-                $all_course_ids[] = (string)$course->ID;
1014
+                $all_course_ids[] = (string) $course->ID;
1015 1015
 
1016 1016
             }
1017 1017
             $order_string = $this->get_course_order();
1018 1018
 
1019
-            if( !empty( $order_string ) ){
1020
-                $ordered_course_ids = explode(',' , $order_string );
1021
-                $all_course_ids = array_unique( array_merge( $ordered_course_ids , $all_course_ids ) );
1019
+            if ( ! empty($order_string)) {
1020
+                $ordered_course_ids = explode(',', $order_string);
1021
+                $all_course_ids = array_unique(array_merge($ordered_course_ids, $all_course_ids));
1022 1022
             }
1023 1023
 
1024 1024
 
1025
-			$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1026
-			$html .= '<ul class="sortable-course-list">' . "\n";
1025
+			$html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
1026
+			$html .= '<ul class="sortable-course-list">'."\n";
1027 1027
 			$count = 0;
1028
-			foreach ( $all_course_ids as $course_id ) {
1029
-                $course = get_post( $course_id );
1028
+			foreach ($all_course_ids as $course_id) {
1029
+                $course = get_post($course_id);
1030 1030
 				$count++;
1031 1031
 				$class = 'course';
1032
-				if ( $count == 1 ) { $class .= ' first'; }
1033
-				if ( $count == count( $course ) ) { $class .= ' last'; }
1034
-				if ( $count % 2 != 0 ) {
1032
+				if ($count == 1) { $class .= ' first'; }
1033
+				if ($count == count($course)) { $class .= ' last'; }
1034
+				if ($count % 2 != 0) {
1035 1035
 					$class .= ' alternate';
1036 1036
 				}
1037
-				$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $course->ID ) . '" style="width: 100%;"> ' . $course->post_title . '</span></li>' . "\n";
1037
+				$html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($course->ID).'" style="width: 100%;"> '.$course->post_title.'</span></li>'."\n";
1038 1038
 			}
1039
-			$html .= '</ul>' . "\n";
1039
+			$html .= '</ul>'."\n";
1040 1040
 
1041
-			$html .= '<input type="hidden" name="course-order" value="' . esc_attr( $order_string ) . '" />' . "\n";
1042
-			$html .= '<input type="submit" class="button-primary" value="' . __( 'Save course order', 'woothemes-sensei' ) . '" />' . "\n";
1041
+			$html .= '<input type="hidden" name="course-order" value="'.esc_attr($order_string).'" />'."\n";
1042
+			$html .= '<input type="submit" class="button-primary" value="'.__('Save course order', 'woothemes-sensei').'" />'."\n";
1043 1043
 		}
1044 1044
 
1045 1045
 		echo $html;
@@ -1048,25 +1048,25 @@  discard block
 block discarded – undo
1048 1048
 	}
1049 1049
 
1050 1050
 	public function get_course_order() {
1051
-		return get_option( 'sensei_course_order', '' );
1051
+		return get_option('sensei_course_order', '');
1052 1052
 	}
1053 1053
 
1054
-	public function save_course_order( $order_string = '' ) {
1055
-		$order = explode( ',', $order_string );
1054
+	public function save_course_order($order_string = '') {
1055
+		$order = explode(',', $order_string);
1056 1056
 
1057
-		update_option( 'sensei_course_order', $order_string );
1057
+		update_option('sensei_course_order', $order_string);
1058 1058
 
1059 1059
 		$i = 1;
1060
-		foreach( $order as $course_id ) {
1060
+		foreach ($order as $course_id) {
1061 1061
 
1062
-			if( $course_id ) {
1062
+			if ($course_id) {
1063 1063
 
1064 1064
 				$update_args = array(
1065 1065
 					'ID' => $course_id,
1066 1066
 					'menu_order' => $i,
1067 1067
 				);
1068 1068
 
1069
-				wp_update_post( $update_args );
1069
+				wp_update_post($update_args);
1070 1070
 
1071 1071
 				++$i;
1072 1072
 			}
@@ -1081,22 +1081,22 @@  discard block
 block discarded – undo
1081 1081
 	 */
1082 1082
 	public function lesson_order_screen() {
1083 1083
 
1084
-		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1085
-		wp_enqueue_script( 'woothemes-sensei-settings', esc_url( Sensei()->plugin_url . 'assets/js/settings' . $suffix . '.js' ), array( 'jquery', 'jquery-ui-sortable' ), Sensei()->version );
1084
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1085
+		wp_enqueue_script('woothemes-sensei-settings', esc_url(Sensei()->plugin_url.'assets/js/settings'.$suffix.'.js'), array('jquery', 'jquery-ui-sortable'), Sensei()->version);
1086 1086
 
1087 1087
 		?><div id="lesson-order" class="wrap lesson-order">
1088
-		<h2><?php _e( 'Order Lessons', 'woothemes-sensei' ); ?></h2><?php
1088
+		<h2><?php _e('Order Lessons', 'woothemes-sensei'); ?></h2><?php
1089 1089
 
1090 1090
 		$html = '';
1091 1091
 
1092
-		if( isset( $_POST['lesson-order'] ) ) {
1092
+		if (isset($_POST['lesson-order'])) {
1093 1093
 
1094
-			$ordered = $this->save_lesson_order( esc_attr( $_POST['lesson-order'] ), esc_attr( $_POST['course_id'] ) );
1094
+			$ordered = $this->save_lesson_order(esc_attr($_POST['lesson-order']), esc_attr($_POST['course_id']));
1095 1095
 
1096
-			if( $ordered ) {
1097
-				$html .= '<div class="updated fade">' . "\n";
1098
-				$html .= '<p>' . __( 'The lesson order has been saved.', 'woothemes-sensei' ) . '</p>' . "\n";
1099
-				$html .= '</div>' . "\n";
1096
+			if ($ordered) {
1097
+				$html .= '<div class="updated fade">'."\n";
1098
+				$html .= '<p>'.__('The lesson order has been saved.', 'woothemes-sensei').'</p>'."\n";
1099
+				$html .= '</div>'."\n";
1100 1100
 			}
1101 1101
 		}
1102 1102
 
@@ -1107,43 +1107,43 @@  discard block
 block discarded – undo
1107 1107
 			'orderby' => 'name',
1108 1108
 			'order' => 'ASC',
1109 1109
 		);
1110
-		$courses = get_posts( $args );
1110
+		$courses = get_posts($args);
1111 1111
 
1112
-		$html .= '<form action="' . admin_url( 'edit.php' ) . '" method="get">' . "\n";
1113
-		$html .= '<input type="hidden" name="post_type" value="lesson" />' . "\n";
1114
-		$html .= '<input type="hidden" name="page" value="lesson-order" />' . "\n";
1115
-		$html .= '<select id="lesson-order-course" name="course_id">' . "\n";
1116
-		$html .= '<option value="">' . __( 'Select a course', 'woothemes-sensei' ) . '</option>' . "\n";
1112
+		$html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
1113
+		$html .= '<input type="hidden" name="post_type" value="lesson" />'."\n";
1114
+		$html .= '<input type="hidden" name="page" value="lesson-order" />'."\n";
1115
+		$html .= '<select id="lesson-order-course" name="course_id">'."\n";
1116
+		$html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
1117 1117
 
1118
-		foreach( $courses as $course ) {
1118
+		foreach ($courses as $course) {
1119 1119
 			$course_id = '';
1120
-			if( isset( $_GET['course_id'] ) ) {
1121
-				$course_id = intval( $_GET['course_id'] );
1120
+			if (isset($_GET['course_id'])) {
1121
+				$course_id = intval($_GET['course_id']);
1122 1122
 			}
1123
-			$html .= '<option value="' . esc_attr( intval( $course->ID ) ) . '" ' . selected( $course->ID, $course_id, false ) .'>' . get_the_title( $course->ID ) . '</option>' . "\n";
1123
+			$html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
1124 1124
 		}
1125 1125
 
1126
-		$html .= '</select>' . "\n";
1127
-		$html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="' . __( 'Select', 'woothemes-sensei' ) . '" />' . "\n";
1128
-		$html .= '</form>' . "\n";
1126
+		$html .= '</select>'."\n";
1127
+		$html .= '<input type="submit" class="button-primary lesson-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
1128
+		$html .= '</form>'."\n";
1129 1129
 
1130
-		$html .= '<script type="text/javascript">' . "\n";
1131
-		$html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});' . "\n";
1132
-		$html .= '</script>' . "\n";
1130
+		$html .= '<script type="text/javascript">'."\n";
1131
+		$html .= 'jQuery( \'#lesson-order-course\' ).select2({width:"resolve"});'."\n";
1132
+		$html .= '</script>'."\n";
1133 1133
 
1134
-		if( isset( $_GET['course_id'] ) ) {
1135
-			$course_id = intval( $_GET['course_id'] );
1136
-			if( $course_id > 0 ) {
1134
+		if (isset($_GET['course_id'])) {
1135
+			$course_id = intval($_GET['course_id']);
1136
+			if ($course_id > 0) {
1137 1137
 
1138
-				$order_string = $this->get_lesson_order( $course_id );
1138
+				$order_string = $this->get_lesson_order($course_id);
1139 1139
 
1140
-				$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
1140
+				$html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
1141 1141
 
1142 1142
 				$displayed_lessons = array();
1143 1143
 
1144
-                $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1144
+                $modules = Sensei()->modules->get_course_modules(intval($course_id));
1145 1145
 
1146
-                foreach( $modules as $module ) {
1146
+                foreach ($modules as $module) {
1147 1147
 
1148 1148
                     $args = array(
1149 1149
                         'post_type' => 'lesson',
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
                         'meta_query' => array(
1153 1153
                             array(
1154 1154
                                 'key' => '_lesson_course',
1155
-                                'value' => intval( $course_id ),
1155
+                                'value' => intval($course_id),
1156 1156
                                 'compare' => '='
1157 1157
                             )
1158 1158
                         ),
@@ -1160,66 +1160,66 @@  discard block
 block discarded – undo
1160 1160
                             array(
1161 1161
                                 'taxonomy' => Sensei()->modules->taxonomy,
1162 1162
                                 'field' => 'id',
1163
-                                'terms' => intval( $module->term_id )
1163
+                                'terms' => intval($module->term_id)
1164 1164
                             )
1165 1165
                         ),
1166
-                        'meta_key' => '_order_module_' . $module->term_id,
1166
+                        'meta_key' => '_order_module_'.$module->term_id,
1167 1167
                         'orderby' => 'meta_value_num date',
1168 1168
                         'order' => 'ASC',
1169 1169
                         'suppress_filters' => 0
1170 1170
                     );
1171 1171
 
1172
-                    $lessons = get_posts( $args );
1172
+                    $lessons = get_posts($args);
1173 1173
 
1174
-                    if( count( $lessons ) > 0 ) {
1175
-                        $html .= '<h3>' . $module->name . '</h3>' . "\n";
1176
-                        $html .= '<ul class="sortable-lesson-list" data-module_id="' . $module->term_id . '">' . "\n";
1174
+                    if (count($lessons) > 0) {
1175
+                        $html .= '<h3>'.$module->name.'</h3>'."\n";
1176
+                        $html .= '<ul class="sortable-lesson-list" data-module_id="'.$module->term_id.'">'."\n";
1177 1177
 
1178 1178
                         $count = 0;
1179
-                        foreach( $lessons as $lesson ) {
1179
+                        foreach ($lessons as $lesson) {
1180 1180
                             $count++;
1181 1181
                             $class = 'lesson';
1182
-                            if ( $count == 1 ) { $class .= ' first'; }
1183
-                            if ( $count == count( $lesson ) ) { $class .= ' last'; }
1184
-                            if ( $count % 2 != 0 ) {
1182
+                            if ($count == 1) { $class .= ' first'; }
1183
+                            if ($count == count($lesson)) { $class .= ' last'; }
1184
+                            if ($count % 2 != 0) {
1185 1185
                                 $class .= ' alternate';
1186 1186
                             }
1187 1187
 
1188
-                            $html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1188
+                            $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n";
1189 1189
 
1190 1190
                             $displayed_lessons[] = $lesson->ID;
1191 1191
                         }
1192 1192
 
1193
-                        $html .= '</ul>' . "\n";
1193
+                        $html .= '</ul>'."\n";
1194 1194
 
1195
-                        $html .= '<input type="hidden" name="lesson-order-module-' . $module->term_id . '" value="" />' . "\n";
1195
+                        $html .= '<input type="hidden" name="lesson-order-module-'.$module->term_id.'" value="" />'."\n";
1196 1196
                     }
1197 1197
                 }
1198 1198
 
1199 1199
 
1200
-                $lessons = Sensei()->course->course_lessons( $course_id );
1200
+                $lessons = Sensei()->course->course_lessons($course_id);
1201 1201
 
1202
-				if( 0 < count( $lessons ) ) {
1202
+				if (0 < count($lessons)) {
1203 1203
 
1204 1204
                     //get module term ids, will be used to exclude lessons
1205 1205
                     $module_items_ids = array();
1206
-                    if( ! empty( $modules ) ) {
1206
+                    if ( ! empty($modules)) {
1207 1207
                         foreach ($modules as $module) {
1208 1208
                             $module_items_ids[] = $module->term_id;
1209 1209
                         }
1210 1210
                     }
1211 1211
 
1212
-					if( 0 < count( $displayed_lessons ) ) {
1213
-						$html .= '<h3>' . __( 'Other Lessons', 'woothemes-sensei' ) . '</h3>' . "\n";
1212
+					if (0 < count($displayed_lessons)) {
1213
+						$html .= '<h3>'.__('Other Lessons', 'woothemes-sensei').'</h3>'."\n";
1214 1214
 					}
1215 1215
 
1216
-					$html .= '<ul class="sortable-lesson-list" data-module_id="0">' . "\n";
1216
+					$html .= '<ul class="sortable-lesson-list" data-module_id="0">'."\n";
1217 1217
 					$count = 0;
1218
-					foreach ( $lessons as $lesson ) {
1218
+					foreach ($lessons as $lesson) {
1219 1219
 
1220 1220
                         // if lesson belongs to one fo the course modules then exclude it here
1221 1221
                         // as it is listed above
1222
-                        if( has_term( $module_items_ids, 'module', $lesson->ID )  ){
1222
+                        if (has_term($module_items_ids, 'module', $lesson->ID)) {
1223 1223
 
1224 1224
                             continue;
1225 1225
 
@@ -1227,28 +1227,28 @@  discard block
 block discarded – undo
1227 1227
 
1228 1228
 						$count++;
1229 1229
 						$class = 'lesson';
1230
-						if ( $count == 1 ) { $class .= ' first'; }
1231
-						if ( $count == count( $lesson ) ) { $class .= ' last'; }
1232
-						if ( $count % 2 != 0 ) {
1230
+						if ($count == 1) { $class .= ' first'; }
1231
+						if ($count == count($lesson)) { $class .= ' last'; }
1232
+						if ($count % 2 != 0) {
1233 1233
 
1234 1234
 							$class .= ' alternate';
1235 1235
 
1236 1236
 						}
1237
-						$html .= '<li class="' . esc_attr( $class ) . '"><span rel="' . esc_attr( $lesson->ID ) . '" style="width: 100%;"> ' . $lesson->post_title . '</span></li>' . "\n";
1237
+						$html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($lesson->ID).'" style="width: 100%;"> '.$lesson->post_title.'</span></li>'."\n";
1238 1238
 
1239 1239
 						$displayed_lessons[] = $lesson->ID;
1240 1240
 					}
1241
-					$html .= '</ul>' . "\n";
1241
+					$html .= '</ul>'."\n";
1242 1242
 				} else {
1243
-					if( 0 == count( $displayed_lessons ) ) {
1244
-						$html .= '<p><em>' . __( 'There are no lessons in this course.', 'woothemes-sensei' ) . '</em></p>';
1243
+					if (0 == count($displayed_lessons)) {
1244
+						$html .= '<p><em>'.__('There are no lessons in this course.', 'woothemes-sensei').'</em></p>';
1245 1245
 					}
1246 1246
 				}
1247 1247
 
1248
-				if( 0 < count( $displayed_lessons ) ) {
1249
-					$html .= '<input type="hidden" name="lesson-order" value="' . esc_attr( $order_string ) . '" />' . "\n";
1250
-					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
1251
-					$html .= '<input type="submit" class="button-primary" value="' . __( 'Save lesson order', 'woothemes-sensei' ) . '" />' . "\n";
1248
+				if (0 < count($displayed_lessons)) {
1249
+					$html .= '<input type="hidden" name="lesson-order" value="'.esc_attr($order_string).'" />'."\n";
1250
+					$html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
1251
+					$html .= '<input type="submit" class="button-primary" value="'.__('Save lesson order', 'woothemes-sensei').'" />'."\n";
1252 1252
 				}
1253 1253
 			}
1254 1254
 		}
@@ -1258,27 +1258,27 @@  discard block
 block discarded – undo
1258 1258
 		?></div><?php
1259 1259
 	}
1260 1260
 
1261
-	public function get_lesson_order( $course_id = 0 ) {
1262
-		$order_string = get_post_meta( $course_id, '_lesson_order', true );
1261
+	public function get_lesson_order($course_id = 0) {
1262
+		$order_string = get_post_meta($course_id, '_lesson_order', true);
1263 1263
 		return $order_string;
1264 1264
 	}
1265 1265
 
1266
-	public function save_lesson_order( $order_string = '', $course_id = 0 ) {
1266
+	public function save_lesson_order($order_string = '', $course_id = 0) {
1267 1267
 
1268
-		if( $course_id ) {
1268
+		if ($course_id) {
1269 1269
 
1270
-            $modules = Sensei()->modules->get_course_modules( intval( $course_id ) );
1270
+            $modules = Sensei()->modules->get_course_modules(intval($course_id));
1271 1271
 
1272
-            foreach( $modules as $module ) {
1272
+            foreach ($modules as $module) {
1273 1273
 
1274
-                $module_order_string = $_POST[ 'lesson-order-module-' . $module->term_id ];
1274
+                $module_order_string = $_POST['lesson-order-module-'.$module->term_id];
1275 1275
 
1276
-                if( $module_order_string ) {
1277
-                    $order = explode( ',', $module_order_string );
1276
+                if ($module_order_string) {
1277
+                    $order = explode(',', $module_order_string);
1278 1278
                     $i = 1;
1279
-                    foreach( $order as $lesson_id ) {
1280
-                        if( $lesson_id ) {
1281
-                            update_post_meta( $lesson_id, '_order_module_' . $module->term_id, $i );
1279
+                    foreach ($order as $lesson_id) {
1280
+                        if ($lesson_id) {
1281
+                            update_post_meta($lesson_id, '_order_module_'.$module->term_id, $i);
1282 1282
                             ++$i;
1283 1283
                         }
1284 1284
                     }
@@ -1286,15 +1286,15 @@  discard block
 block discarded – undo
1286 1286
             }
1287 1287
 
1288 1288
 
1289
-			if( $order_string ) {
1290
-				update_post_meta( $course_id, '_lesson_order', $order_string );
1289
+			if ($order_string) {
1290
+				update_post_meta($course_id, '_lesson_order', $order_string);
1291 1291
 
1292
-				$order = explode( ',', $order_string );
1292
+				$order = explode(',', $order_string);
1293 1293
 
1294 1294
 				$i = 1;
1295
-				foreach( $order as $lesson_id ) {
1296
-					if( $lesson_id ) {
1297
-						update_post_meta( $lesson_id, '_order_' . $course_id, $i );
1295
+				foreach ($order as $lesson_id) {
1296
+					if ($lesson_id) {
1297
+						update_post_meta($lesson_id, '_order_'.$course_id, $i);
1298 1298
 						++$i;
1299 1299
 					}
1300 1300
 				}
@@ -1309,54 +1309,54 @@  discard block
 block discarded – undo
1309 1309
 	function sensei_add_custom_menu_items() {
1310 1310
 		global $pagenow;
1311 1311
 
1312
-		if( 'nav-menus.php' == $pagenow ) {
1313
-			add_meta_box( 'add-sensei-links', 'Sensei', array( $this, 'wp_nav_menu_item_sensei_links_meta_box' ), 'nav-menus', 'side', 'low' );
1312
+		if ('nav-menus.php' == $pagenow) {
1313
+			add_meta_box('add-sensei-links', 'Sensei', array($this, 'wp_nav_menu_item_sensei_links_meta_box'), 'nav-menus', 'side', 'low');
1314 1314
 		}
1315 1315
 	}
1316 1316
 
1317
-	function wp_nav_menu_item_sensei_links_meta_box( $object ) {
1317
+	function wp_nav_menu_item_sensei_links_meta_box($object) {
1318 1318
 		global $nav_menu_selected_id;
1319 1319
 
1320 1320
 		$menu_items = array(
1321
-			'#senseicourses' => __( 'Courses', 'woothemes-sensei' ),
1322
-			'#senseilessons' => __( 'Lessons', 'woothemes-sensei' ),
1323
-			'#senseimycourses' => __( 'My Courses', 'woothemes-sensei' ),
1324
-			'#senseilearnerprofile' => __( 'My Profile', 'woothemes-sensei' ),
1325
-			'#senseimymessages' => __( 'My Messages', 'woothemes-sensei' ),
1326
-			'#senseiloginlogout' => __( 'Login', 'woothemes-sensei' ) . '|' . __( 'Logout', 'woothemes-sensei' )
1321
+			'#senseicourses' => __('Courses', 'woothemes-sensei'),
1322
+			'#senseilessons' => __('Lessons', 'woothemes-sensei'),
1323
+			'#senseimycourses' => __('My Courses', 'woothemes-sensei'),
1324
+			'#senseilearnerprofile' => __('My Profile', 'woothemes-sensei'),
1325
+			'#senseimymessages' => __('My Messages', 'woothemes-sensei'),
1326
+			'#senseiloginlogout' => __('Login', 'woothemes-sensei').'|'.__('Logout', 'woothemes-sensei')
1327 1327
 		);
1328 1328
 
1329 1329
 		$menu_items_obj = array();
1330
-		foreach ( $menu_items as $value => $title ) {
1330
+		foreach ($menu_items as $value => $title) {
1331 1331
 			$menu_items_obj[$title] = new stdClass;
1332
-			$menu_items_obj[$title]->object_id			= esc_attr( $value );
1333
-			$menu_items_obj[$title]->title				= esc_attr( $title );
1334
-			$menu_items_obj[$title]->url				= esc_attr( $value );
1335
-			$menu_items_obj[$title]->description 		= 'description';
1332
+			$menu_items_obj[$title]->object_id = esc_attr($value);
1333
+			$menu_items_obj[$title]->title = esc_attr($title);
1334
+			$menu_items_obj[$title]->url = esc_attr($value);
1335
+			$menu_items_obj[$title]->description = 'description';
1336 1336
 			$menu_items_obj[$title]->db_id 				= 0;
1337 1337
 			$menu_items_obj[$title]->object 			= 'sensei';
1338
-			$menu_items_obj[$title]->menu_item_parent 	= 0;
1339
-			$menu_items_obj[$title]->type 				= 'custom';
1338
+			$menu_items_obj[$title]->menu_item_parent = 0;
1339
+			$menu_items_obj[$title]->type = 'custom';
1340 1340
 			$menu_items_obj[$title]->target 			= '';
1341
-			$menu_items_obj[$title]->attr_title 		= '';
1342
-			$menu_items_obj[$title]->classes 			= array();
1343
-			$menu_items_obj[$title]->xfn 				= '';
1341
+			$menu_items_obj[$title]->attr_title = '';
1342
+			$menu_items_obj[$title]->classes = array();
1343
+			$menu_items_obj[$title]->xfn = '';
1344 1344
 		}
1345 1345
 
1346
-		$walker = new Walker_Nav_Menu_Checklist( array() );
1346
+		$walker = new Walker_Nav_Menu_Checklist(array());
1347 1347
 		?>
1348 1348
 
1349 1349
 		<div id="sensei-links" class="senseidiv taxonomydiv">
1350 1350
 			<div id="tabs-panel-sensei-links-all" class="tabs-panel tabs-panel-view-all tabs-panel-active">
1351 1351
 
1352 1352
 				<ul id="sensei-linkschecklist" class="list:sensei-links categorychecklist form-no-clear">
1353
-					<?php echo walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $menu_items_obj ), 0, (object)array( 'walker' => $walker ) ); ?>
1353
+					<?php echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $menu_items_obj), 0, (object) array('walker' => $walker)); ?>
1354 1354
 				</ul>
1355 1355
 
1356 1356
 			</div>
1357 1357
 			<p class="button-controls">
1358 1358
 				<span class="add-to-menu">
1359
-					<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to Menu', 'woothemes-sensei' ); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" />
1359
+					<input type="submit"<?php disabled($nav_menu_selected_id, 0); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu', 'woothemes-sensei'); ?>" name="add-sensei-links-menu-item" id="submit-sensei-links" />
1360 1360
 					<span class="spinner"></span>
1361 1361
 				</span>
1362 1362
 			</p>
@@ -1372,17 +1372,17 @@  discard block
 block discarded – undo
1372 1372
 	 */
1373 1373
 	public function theme_compatibility_notices() {
1374 1374
 
1375
-        if( isset( $_GET['sensei_hide_notice'] ) ) {
1376
-        	switch( esc_attr( $_GET['sensei_hide_notice'] ) ) {
1377
-				case 'menu_settings': add_user_meta( get_current_user_id(), 'sensei_hide_menu_settings_notice', true ); break;
1378
-				case 'theme_check': add_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true ); break;
1375
+        if (isset($_GET['sensei_hide_notice'])) {
1376
+        	switch (esc_attr($_GET['sensei_hide_notice'])) {
1377
+				case 'menu_settings': add_user_meta(get_current_user_id(), 'sensei_hide_menu_settings_notice', true); break;
1378
+				case 'theme_check': add_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true); break;
1379 1379
 			}
1380 1380
         }
1381 1381
 
1382 1382
         // white list templates that are already support by default and do not show notice for them
1383
-        $template = get_option( 'template' );
1383
+        $template = get_option('template');
1384 1384
 
1385
-        $white_list = array(    'twentyeleven',
1385
+        $white_list = array('twentyeleven',
1386 1386
                                 'twentytwelve',
1387 1387
                                 'twentyfourteen',
1388 1388
                                 'twentyfifteen',
@@ -1390,43 +1390,43 @@  discard block
 block discarded – undo
1390 1390
                                 'storefront',
1391 1391
                                                 );
1392 1392
 
1393
-        if ( in_array( $template, $white_list ) ) {
1393
+        if (in_array($template, $white_list)) {
1394 1394
 
1395 1395
             return;
1396 1396
 
1397 1397
         }
1398 1398
 
1399 1399
         // don't show the notice if the user chose to hide it
1400
-        $hide_theme_check_notice = get_user_meta( get_current_user_id(), 'sensei_hide_theme_check_notice', true );
1401
-        if(  $hide_theme_check_notice ) {
1400
+        $hide_theme_check_notice = get_user_meta(get_current_user_id(), 'sensei_hide_theme_check_notice', true);
1401
+        if ($hide_theme_check_notice) {
1402 1402
 
1403 1403
             return;
1404 1404
 
1405 1405
         }
1406 1406
 
1407 1407
         // show the notice for themes not supporting sensei
1408
-	    if ( ! current_theme_supports( 'sensei' ) ) {
1408
+	    if ( ! current_theme_supports('sensei')) {
1409 1409
             ?>
1410 1410
 
1411 1411
             <div id="message" class="error sensei-message sensei-connect">
1412 1412
                     <p>
1413 1413
                         <strong>
1414 1414
 
1415
-                            <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei' ); ?>
1415
+                            <?php _e('Your theme does not declare Sensei support', 'woothemes-sensei'); ?>
1416 1416
 
1417 1417
                         </strong> &#8211;
1418 1418
 
1419
-                        <?php _e( 'if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei' ); ?>
1419
+                        <?php _e('if you encounter layout issues please read our integration guide or choose a ', 'woothemes-sensei'); ?>
1420 1420
 
1421
-                        <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php  _e( 'Sensei theme', 'woothemes-sensei' ) ?> </a>
1421
+                        <a href="http://www.woothemes.com/product-category/themes/sensei-themes/"> <?php  _e('Sensei theme', 'woothemes-sensei') ?> </a>
1422 1422
 
1423 1423
                         :)
1424 1424
 
1425 1425
                     </p>
1426 1426
                     <p class="submit">
1427
-                        <a href="<?php echo esc_url( apply_filters( 'sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility' ) ); ?>" class="button-primary">
1427
+                        <a href="<?php echo esc_url(apply_filters('sensei_docs_url', 'http://docs.woothemes.com/document/sensei-and-theme-compatibility/', 'theme-compatibility')); ?>" class="button-primary">
1428 1428
 
1429
-                            <?php _e( 'Theme Integration Guide', 'woothemes-sensei' ); ?></a> <a class="skip button" href="<?php echo esc_url( add_query_arg( 'sensei_hide_notice', 'theme_check' ) ); ?>"><?php _e( 'Hide this notice', 'woothemes-sensei' ); ?>
1429
+                            <?php _e('Theme Integration Guide', 'woothemes-sensei'); ?></a> <a class="skip button" href="<?php echo esc_url(add_query_arg('sensei_hide_notice', 'theme_check')); ?>"><?php _e('Hide this notice', 'woothemes-sensei'); ?>
1430 1430
 
1431 1431
                         </a>
1432 1432
                     </p>
@@ -1444,7 +1444,7 @@  discard block
 block discarded – undo
1444 1444
 		wp_get_current_user();
1445 1445
         $user_id = $current_user->ID;
1446 1446
 
1447
-		delete_user_meta( $user_id, 'sensei_hide_theme_check_notice' );
1447
+		delete_user_meta($user_id, 'sensei_hide_theme_check_notice');
1448 1448
 	}
1449 1449
 
1450 1450
 	/**
@@ -1454,8 +1454,8 @@  discard block
 block discarded – undo
1454 1454
 	 * @param  bool $prevent_access
1455 1455
 	 * @return bool
1456 1456
 	 */
1457
-	public function admin_access( $prevent_access ) {
1458
-		if ( current_user_can( 'manage_sensei_grades' ) ) {
1457
+	public function admin_access($prevent_access) {
1458
+		if (current_user_can('manage_sensei_grades')) {
1459 1459
 			return false;
1460 1460
 		}
1461 1461
 
@@ -1470,12 +1470,12 @@  discard block
 block discarded – undo
1470 1470
      *
1471 1471
      * @since 1.8.7
1472 1472
      */
1473
-    public  static function install_pages(){
1473
+    public  static function install_pages() {
1474 1474
 
1475 1475
         // only fire on the settings page
1476
-        if( ! isset( $_GET['page'] )
1476
+        if ( ! isset($_GET['page'])
1477 1477
             || 'woothemes-sensei-settings' != $_GET['page']
1478
-            || 1 == get_option('skip_install_sensei_pages') ){
1478
+            || 1 == get_option('skip_install_sensei_pages')) {
1479 1479
 
1480 1480
             return;
1481 1481
 
@@ -1505,13 +1505,13 @@  discard block
 block discarded – undo
1505 1505
         if ($install_complete) {
1506 1506
 
1507 1507
             // Flush rules after install
1508
-            flush_rewrite_rules( true );
1508
+            flush_rewrite_rules(true);
1509 1509
 
1510 1510
             // Set installed option
1511 1511
             update_option('sensei_installed', 0);
1512 1512
 
1513
-            $complete_url = add_query_arg( 'sensei_install_complete', 'true', $settings_url  );
1514
-            wp_redirect( $complete_url );
1513
+            $complete_url = add_query_arg('sensei_install_complete', 'true', $settings_url);
1514
+            wp_redirect($complete_url);
1515 1515
 
1516 1516
         }
1517 1517
 
@@ -1524,4 +1524,4 @@  discard block
 block discarded – undo
1524 1524
  * for backward compatibility
1525 1525
  * @since 1.9.0
1526 1526
  */
1527
-class WooThemes_Sensei_Admin extends Sensei_Admin{ }
1527
+class WooThemes_Sensei_Admin extends Sensei_Admin { }
Please login to merge, or discard this patch.
includes/class-sensei-quiz.php 1 patch
Spacing   +286 added lines, -286 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 Quiz Class
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param $file
25 25
 	 */
26
-	public function __construct ( $file = __FILE__ ) {
26
+	public function __construct($file = __FILE__) {
27 27
 		$this->file = $file;
28
-		$this->meta_fields = array( 'quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required','enable_quiz_reset' );
29
-		add_action( 'save_post', array( $this, 'update_author' ));
28
+		$this->meta_fields = array('quiz_passmark', 'quiz_lesson', 'quiz_type', 'quiz_grade_type', 'pass_required', 'enable_quiz_reset');
29
+		add_action('save_post', array($this, 'update_author'));
30 30
 
31 31
 		// listen to the reset button click
32
-		add_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
32
+		add_action('template_redirect', array($this, 'reset_button_click_listener'));
33 33
 
34 34
         // fire the complete quiz button submit for grading action
35
-        add_action( 'sensei_complete_quiz', array( $this, 'user_quiz_submit_listener' ) );
35
+        add_action('sensei_complete_quiz', array($this, 'user_quiz_submit_listener'));
36 36
 
37 37
 		// fire the save user answers quiz button click responder
38
-		add_action( 'sensei_complete_quiz', array( $this, 'user_save_quiz_answers_listener' ) );
38
+		add_action('sensei_complete_quiz', array($this, 'user_save_quiz_answers_listener'));
39 39
 
40 40
         // fire the load global data function
41
-        add_action( 'sensei_complete_quiz', array( $this, 'load_global_quiz_data' ), 80 );
41
+        add_action('sensei_complete_quiz', array($this, 'load_global_quiz_data'), 80);
42 42
 
43
-        add_action( 'template_redirect', array ( $this, 'quiz_has_no_questions') );
43
+        add_action('template_redirect', array($this, 'quiz_has_no_questions'));
44 44
 
45 45
 
46 46
     } // End __construct()
@@ -51,26 +51,26 @@  discard block
 block discarded – undo
51 51
 	* @param int $post_id
52 52
 	* @return void
53 53
 	*/
54
-	public function update_author( $post_id ){
54
+	public function update_author($post_id) {
55 55
 
56 56
 
57 57
 		// If this isn't a 'lesson' post, don't update it.
58 58
         // if this is a revision don't save it
59
-	    if ( isset( $_POST['post_type'] ) && 'lesson' != $_POST['post_type']
60
-            || wp_is_post_revision( $post_id ) ) {
59
+	    if (isset($_POST['post_type']) && 'lesson' != $_POST['post_type']
60
+            || wp_is_post_revision($post_id)) {
61 61
 
62 62
                 return;
63 63
 
64 64
         }
65 65
 	    // get the lesson author id to be use late
66
-	    $saved_post = get_post( $post_id );
67
-	    $new_lesson_author_id =  $saved_post->post_author;
66
+	    $saved_post = get_post($post_id);
67
+	    $new_lesson_author_id = $saved_post->post_author;
68 68
 
69 69
 	    //get the lessons quiz
70
-		$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $post_id );
71
-	    foreach ( (array) $lesson_quizzes as $quiz_item ) {
70
+		$lesson_quizzes = Sensei()->lesson->lesson_quizzes($post_id);
71
+	    foreach ((array) $lesson_quizzes as $quiz_item) {
72 72
 
73
-	    	if( ! $quiz_item ) {
73
+	    	if ( ! $quiz_item) {
74 74
 	    		continue;
75 75
 	    	}
76 76
 
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
 			);
82 82
 
83 83
             // remove the action so that it doesn't fire again
84
-            remove_action( 'save_post', array( $this, 'update_author' ));
84
+            remove_action('save_post', array($this, 'update_author'));
85 85
 
86 86
 			// Update the post into the database
87
-		  	wp_update_post( $my_post );
87
+		  	wp_update_post($my_post);
88 88
 	    }
89 89
 
90 90
 	    return;
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 	 * @param int $quiz_id
99 99
 	 * @return int @lesson_id
100 100
 	 */
101
-	public function get_lesson_id( $quiz_id ){
101
+	public function get_lesson_id($quiz_id) {
102 102
 
103
-		if( empty( $quiz_id ) || ! intval( $quiz_id ) > 0 ){
103
+		if (empty($quiz_id) || ! intval($quiz_id) > 0) {
104 104
 			global $post;
105
-			if( 'quiz' == get_post_type( $post ) ){
105
+			if ('quiz' == get_post_type($post)) {
106 106
 				$quiz_id = $post->ID;
107
-			}else{
107
+			} else {
108 108
 				return false;
109 109
 			}
110 110
 
111 111
 		}
112 112
 
113
-		$quiz = get_post( $quiz_id );
113
+		$quiz = get_post($quiz_id);
114 114
 		$lesson_id = $quiz->post_parent;
115 115
 
116 116
 		return $lesson_id;
@@ -125,23 +125,23 @@  discard block
 block discarded – undo
125 125
      * @since 1.7.3
126 126
      * @return bool $saved;
127 127
      */
128
-    public function user_save_quiz_answers_listener(){
128
+    public function user_save_quiz_answers_listener() {
129 129
 
130
-        if( ! isset( $_POST[ 'quiz_save' ])
131
-            || !isset( $_POST[ 'sensei_question' ] )
132
-            || empty( $_POST[ 'sensei_question' ] )
133
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce'  ) > 1 ) {
130
+        if ( ! isset($_POST['quiz_save'])
131
+            || ! isset($_POST['sensei_question'])
132
+            || empty($_POST['sensei_question'])
133
+            ||  ! wp_verify_nonce($_POST['woothemes_sensei_save_quiz_nonce'], 'woothemes_sensei_save_quiz_nonce') > 1) {
134 134
             return;
135 135
         }
136 136
 
137 137
         global $post;
138
-        $lesson_id = $this->get_lesson_id( $post->ID );
139
-        $quiz_answers = $_POST[ 'sensei_question' ];
138
+        $lesson_id = $this->get_lesson_id($post->ID);
139
+        $quiz_answers = $_POST['sensei_question'];
140 140
         // call the save function
141
-        self::save_user_answers( $quiz_answers, $_FILES , $lesson_id  , get_current_user_id() );
141
+        self::save_user_answers($quiz_answers, $_FILES, $lesson_id, get_current_user_id());
142 142
 
143 143
         // remove the hook as it should only fire once per click
144
-        remove_action( 'sensei_complete_quiz', 'user_save_quiz_answers_listener' );
144
+        remove_action('sensei_complete_quiz', 'user_save_quiz_answers_listener');
145 145
 
146 146
     } // end user_save_quiz_answers_listener
147 147
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @return false or int $answers_saved
162 162
 	 */
163
-	public static function save_user_answers( $quiz_answers, $files = array(), $lesson_id , $user_id = 0 ){
163
+	public static function save_user_answers($quiz_answers, $files = array(), $lesson_id, $user_id = 0) {
164 164
 
165
-        if( ! ( $user_id > 0 ) ){
165
+        if ( ! ($user_id > 0)) {
166 166
             $user_id = get_current_user_id();
167 167
         }
168 168
 
169 169
         // make sure the parameters are valid before continuing
170
-		if( empty( $lesson_id ) || empty( $user_id )
171
-			|| 'lesson' != get_post_type( $lesson_id )
172
-			||!get_userdata( $user_id )
173
-			|| !is_array( $quiz_answers ) ){
170
+		if (empty($lesson_id) || empty($user_id)
171
+			|| 'lesson' != get_post_type($lesson_id)
172
+			||! get_userdata($user_id)
173
+			|| ! is_array($quiz_answers)) {
174 174
 
175 175
 			return false;
176 176
 
@@ -178,23 +178,23 @@  discard block
 block discarded – undo
178 178
 
179 179
 
180 180
         // start the lesson before saving the data in case the user has not started the lesson
181
-        $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
181
+        $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
182 182
 
183 183
 		//prepare the answers
184
-		$prepared_answers = self::prepare_form_submitted_answers( $quiz_answers , $files );
184
+		$prepared_answers = self::prepare_form_submitted_answers($quiz_answers, $files);
185 185
 
186 186
 		// save the user data
187
-        $answers_saved = Sensei_Utils::add_user_data( 'quiz_answers', $lesson_id, $prepared_answers, $user_id ) ;
187
+        $answers_saved = Sensei_Utils::add_user_data('quiz_answers', $lesson_id, $prepared_answers, $user_id);
188 188
 
189 189
 		// were the answers saved correctly?
190
-		if( intval( $answers_saved ) > 0){
190
+		if (intval($answers_saved) > 0) {
191 191
 
192 192
             // save transient to make retrieval faster
193 193
             $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
194
-            set_transient( $transient_key, $prepared_answers, 10 * DAY_IN_SECONDS );
194
+            set_transient($transient_key, $prepared_answers, 10 * DAY_IN_SECONDS);
195 195
 
196 196
             // update the message showed to user
197
-            Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Saved Successfully.', 'woothemes-sensei' )  . '</div>';
197
+            Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Saved Successfully.', 'woothemes-sensei').'</div>';
198 198
         }
199 199
 
200 200
 		return $answers_saved;
@@ -216,41 +216,41 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @return array $answers or false
218 218
 	 */
219
-	public function get_user_answers( $lesson_id, $user_id ){
219
+	public function get_user_answers($lesson_id, $user_id) {
220 220
 
221 221
 		$answers = false;
222 222
 
223
-		if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
224
-		|| ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
223
+		if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
224
+		|| ! intval($user_id) > 0 || ! get_userdata($user_id)) {
225 225
 			return false;
226 226
 		}
227 227
 
228 228
         // save some time and get the transient cached data
229 229
         $transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
230
-        $transient_cached_answers = get_transient( $transient_key );
230
+        $transient_cached_answers = get_transient($transient_key);
231 231
 
232 232
         // return the transient or get the values get the values from the comment meta
233
-        if( !empty( $transient_cached_answers  ) && false != $transient_cached_answers ){
233
+        if ( ! empty($transient_cached_answers) && false != $transient_cached_answers) {
234 234
 
235 235
             $encoded_user_answers = $transient_cached_answers;
236 236
 
237
-        }else{
237
+        } else {
238 238
 
239
-            $encoded_user_answers = Sensei_Utils::get_user_data( 'quiz_answers', $lesson_id  , $user_id );
239
+            $encoded_user_answers = Sensei_Utils::get_user_data('quiz_answers', $lesson_id, $user_id);
240 240
 
241 241
         } // end if transient check
242 242
 
243
-		if( ! is_array( $encoded_user_answers ) ){
243
+		if ( ! is_array($encoded_user_answers)) {
244 244
 			return false;
245 245
 		}
246 246
 
247 247
         //set the transient with the new valid data for faster retrieval in future
248
-        set_transient( $transient_key,  $encoded_user_answers, 10 * DAY_IN_SECONDS);
248
+        set_transient($transient_key, $encoded_user_answers, 10 * DAY_IN_SECONDS);
249 249
 
250 250
 		// decode an unserialize all answers
251
-		foreach( $encoded_user_answers as $question_id => $encoded_answer ) {
252
-			$decoded_answer = base64_decode( $encoded_answer );
253
-			$answers[$question_id] = maybe_unserialize( $decoded_answer );
251
+		foreach ($encoded_user_answers as $question_id => $encoded_answer) {
252
+			$decoded_answer = base64_decode($encoded_answer);
253
+			$answers[$question_id] = maybe_unserialize($decoded_answer);
254 254
 		}
255 255
 
256 256
 		return $answers;
@@ -267,23 +267,23 @@  discard block
 block discarded – undo
267 267
 	 *
268 268
 	 * @return void;
269 269
 	 */
270
-	public function reset_button_click_listener( ){
270
+	public function reset_button_click_listener( ) {
271 271
 
272
-		if( ! isset( $_POST[ 'quiz_reset' ])
273
-			||  ! wp_verify_nonce( $_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce'  ) > 1 ) {
272
+		if ( ! isset($_POST['quiz_reset'])
273
+			||  ! wp_verify_nonce($_POST['woothemes_sensei_reset_quiz_nonce'], 'woothemes_sensei_reset_quiz_nonce') > 1) {
274 274
 
275 275
 			return; // exit
276 276
 		}
277 277
 
278 278
 		global $post;
279 279
 		$current_quiz_id = $post->ID;
280
-		$lesson_id = $this->get_lesson_id( $current_quiz_id );
280
+		$lesson_id = $this->get_lesson_id($current_quiz_id);
281 281
 
282 282
         // reset all user data
283
-        $this->reset_user_lesson_data( $lesson_id, get_current_user_id() );
283
+        $this->reset_user_lesson_data($lesson_id, get_current_user_id());
284 284
 
285 285
 		//this function should only run once
286
-		remove_action( 'template_redirect', array( $this, 'reset_button_click_listener'  ) );
286
+		remove_action('template_redirect', array($this, 'reset_button_click_listener'));
287 287
 
288 288
 	} // end reset_button_click_listener
289 289
 
@@ -302,18 +302,18 @@  discard block
 block discarded – undo
302 302
 	public function user_quiz_submit_listener() {
303 303
 
304 304
         // only respond to valid quiz completion submissions
305
-        if( ! isset( $_POST[ 'quiz_complete' ])
306
-            || !isset( $_POST[ 'sensei_question' ] )
307
-            || empty( $_POST[ 'sensei_question' ] )
308
-            ||  ! wp_verify_nonce( $_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce'  ) > 1 ) {
305
+        if ( ! isset($_POST['quiz_complete'])
306
+            || ! isset($_POST['sensei_question'])
307
+            || empty($_POST['sensei_question'])
308
+            ||  ! wp_verify_nonce($_POST['woothemes_sensei_complete_quiz_nonce'], 'woothemes_sensei_complete_quiz_nonce') > 1) {
309 309
             return;
310 310
         }
311 311
 
312 312
         global $post, $current_user;
313
-        $lesson_id = $this->get_lesson_id( $post->ID );
314
-        $quiz_answers = $_POST[ 'sensei_question' ];
313
+        $lesson_id = $this->get_lesson_id($post->ID);
314
+        $quiz_answers = $_POST['sensei_question'];
315 315
 
316
-        self::submit_answers_for_grading( $quiz_answers, $_FILES ,  $lesson_id  , $current_user->ID );
316
+        self::submit_answers_for_grading($quiz_answers, $_FILES, $lesson_id, $current_user->ID);
317 317
 
318 318
 	} // End sensei_complete_quiz()
319 319
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
      * @access public
328 328
      *
329 329
      */
330
-    public function load_global_quiz_data(){
330
+    public function load_global_quiz_data() {
331 331
 
332 332
         global  $post, $current_user;
333 333
         $this->data = new stdClass();
@@ -336,46 +336,46 @@  discard block
 block discarded – undo
336 336
         $grade = 0;
337 337
 
338 338
         // Get Quiz Questions
339
-        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $post->ID );
339
+        $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($post->ID);
340 340
 
341
-        $quiz_lesson_id = absint( get_post_meta( $post->ID, '_quiz_lesson', true ) );
341
+        $quiz_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true));
342 342
 
343 343
         // Get quiz grade type
344
-        $quiz_grade_type = get_post_meta( $post->ID, '_quiz_grade_type', true );
344
+        $quiz_grade_type = get_post_meta($post->ID, '_quiz_grade_type', true);
345 345
 
346 346
         // Get quiz pass setting
347
-        $pass_required = get_post_meta( $post->ID, '_pass_required', true );
347
+        $pass_required = get_post_meta($post->ID, '_pass_required', true);
348 348
 
349 349
         // Get quiz pass mark
350
-        $quiz_passmark = abs( round( doubleval( get_post_meta( $post->ID, '_quiz_passmark', true ) ), 2 ) );
350
+        $quiz_passmark = abs(round(doubleval(get_post_meta($post->ID, '_quiz_passmark', true)), 2));
351 351
 
352 352
         // Get latest quiz answers and grades
353
-        $lesson_id = Sensei()->quiz->get_lesson_id( $post->ID );
354
-        $user_quizzes = Sensei()->quiz->get_user_answers( $lesson_id, get_current_user_id() );
355
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $quiz_lesson_id, $current_user->ID );
353
+        $lesson_id = Sensei()->quiz->get_lesson_id($post->ID);
354
+        $user_quizzes = Sensei()->quiz->get_user_answers($lesson_id, get_current_user_id());
355
+        $user_lesson_status = Sensei_Utils::user_lesson_status($quiz_lesson_id, $current_user->ID);
356 356
         $user_quiz_grade = 0;
357
-        if( isset( $user_lesson_status->comment_ID ) ) {
358
-            $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
357
+        if (isset($user_lesson_status->comment_ID)) {
358
+            $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
359 359
         }
360 360
 
361
-        if ( ! is_array($user_quizzes) ) { $user_quizzes = array(); }
361
+        if ( ! is_array($user_quizzes)) { $user_quizzes = array(); }
362 362
 
363 363
         // Check again that the lesson is complete
364
-        $user_lesson_end = Sensei_Utils::user_completed_lesson( $user_lesson_status );
364
+        $user_lesson_end = Sensei_Utils::user_completed_lesson($user_lesson_status);
365 365
         $user_lesson_complete = false;
366
-        if ( $user_lesson_end ) {
366
+        if ($user_lesson_end) {
367 367
             $user_lesson_complete = true;
368 368
         } // End If Statement
369 369
 
370
-        $reset_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true );
370
+        $reset_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true);
371 371
         //backwards compatibility
372
-        if( 'on' == $reset_allowed ) {
372
+        if ('on' == $reset_allowed) {
373 373
             $reset_allowed = 1;
374 374
         }
375 375
 
376 376
         // Build frontend data object for backwards compatibility
377 377
         // using this is no longer recommended
378
-        $this->data->user_quiz_grade = $user_quiz_grade;// Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
378
+        $this->data->user_quiz_grade = $user_quiz_grade; // Sensei_Quiz::get_user_quiz_grade( $lesson_id, get_current_user_id() );
379 379
         $this->data->quiz_passmark = $quiz_passmark;
380 380
         $this->data->quiz_lesson = $quiz_lesson_id;
381 381
         $this->data->quiz_grade_type = $quiz_grade_type; // get_post_meta( $quiz_id, '_quiz_grade_type', true );
@@ -400,41 +400,41 @@  discard block
 block discarded – undo
400 400
 	 * @param $files
401 401
 	 * @return array
402 402
 	 */
403
-	public static function prepare_form_submitted_answers( $unprepared_answers,  $files ){
403
+	public static function prepare_form_submitted_answers($unprepared_answers, $files) {
404 404
 
405 405
 
406 406
 		$prepared_answers = array();
407 407
 
408 408
 		// validate incoming answers
409
-		if( empty( $unprepared_answers  ) || ! is_array( $unprepared_answers ) ){
409
+		if (empty($unprepared_answers) || ! is_array($unprepared_answers)) {
410 410
 			return false;
411 411
 		}
412 412
 
413 413
 		// Loop through submitted quiz answers and save them appropriately
414
-		foreach( $unprepared_answers as $question_id => $answer ) {
414
+		foreach ($unprepared_answers as $question_id => $answer) {
415 415
 
416 416
 			//get the current questions 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 423
 
424 424
             // compress the answer for saving
425
-			if( 'multi-line' == $question_type ) {
426
-                $answer = esc_html( $answer );
427
-            }elseif( 'file-upload' == $question_type  ){
428
-                $file_key = 'file_upload_' . $question_id;
429
-                if( isset( $files[ $file_key ] ) ) {
430
-                        $attachment_id = Sensei_Utils::upload_file(  $files[ $file_key ] );
431
-                        if( $attachment_id ) {
425
+			if ('multi-line' == $question_type) {
426
+                $answer = esc_html($answer);
427
+            }elseif ('file-upload' == $question_type) {
428
+                $file_key = 'file_upload_'.$question_id;
429
+                if (isset($files[$file_key])) {
430
+                        $attachment_id = Sensei_Utils::upload_file($files[$file_key]);
431
+                        if ($attachment_id) {
432 432
                             $answer = $attachment_id;
433 433
                         }
434 434
                     }
435 435
             } // end if
436 436
 
437
-			$prepared_answers[ $question_id ] =  base64_encode( maybe_serialize( $answer ) );
437
+			$prepared_answers[$question_id] = base64_encode(maybe_serialize($answer));
438 438
 
439 439
 		}// end for each $quiz_answers
440 440
 
@@ -454,54 +454,54 @@  discard block
 block discarded – undo
454 454
      * @param int $user_id
455 455
      * @param int $lesson_id
456 456
      */
457
-    public function reset_user_lesson_data( $lesson_id , $user_id = 0 ){
457
+    public function reset_user_lesson_data($lesson_id, $user_id = 0) {
458 458
 
459 459
         //make sure the parameters are valid
460
-        if( empty( $lesson_id ) || empty( $user_id )
461
-            || 'lesson' != get_post_type( $lesson_id )
462
-            || ! get_userdata( $user_id ) ){
460
+        if (empty($lesson_id) || empty($user_id)
461
+            || 'lesson' != get_post_type($lesson_id)
462
+            || ! get_userdata($user_id)) {
463 463
             return false;
464 464
         }
465 465
 
466 466
 
467 467
 
468 468
         //get the users lesson status to make
469
-        $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
470
-        if( ! isset( $user_lesson_status->comment_ID ) ) {
469
+        $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
470
+        if ( ! isset($user_lesson_status->comment_ID)) {
471 471
             // this user is not taking this lesson so this process is not needed
472 472
             return false;
473 473
         }
474 474
 
475 475
         //get the lesson quiz and course
476
-        $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
477
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
476
+        $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
477
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
478 478
 
479 479
         // reset the transients
480 480
         $answers_transient_key = 'sensei_answers_'.$user_id.'_'.$lesson_id;
481 481
         $grades_transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
482 482
         $answers_feedback_transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
483
-        delete_transient( $answers_transient_key );
484
-        delete_transient( $grades_transient_key );
485
-        delete_transient( $answers_feedback_transient_key );
483
+        delete_transient($answers_transient_key);
484
+        delete_transient($grades_transient_key);
485
+        delete_transient($answers_feedback_transient_key);
486 486
 
487 487
         // reset the quiz answers and feedback notes
488
-        $deleted_answers = Sensei_Utils::delete_user_data( 'quiz_answers', $lesson_id, $user_id );
489
-        $deleted_grades = Sensei_Utils::delete_user_data( 'quiz_grades', $lesson_id, $user_id );
490
-        $deleted_user_feedback = Sensei_Utils::delete_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
488
+        $deleted_answers = Sensei_Utils::delete_user_data('quiz_answers', $lesson_id, $user_id);
489
+        $deleted_grades = Sensei_Utils::delete_user_data('quiz_grades', $lesson_id, $user_id);
490
+        $deleted_user_feedback = Sensei_Utils::delete_user_data('quiz_answers_feedback', $lesson_id, $user_id);
491 491
 
492 492
         // Delete quiz answers, this auto deletes the corresponding meta data, such as the question/answer grade
493
-        Sensei_Utils::sensei_delete_quiz_answers( $quiz_id, $user_id );
493
+        Sensei_Utils::sensei_delete_quiz_answers($quiz_id, $user_id);
494 494
 
495
-        Sensei_Utils::update_lesson_status( $user_id , $lesson_id, 'in-progress', array( 'questions_asked' => '', 'grade' => '' ) );
495
+        Sensei_Utils::update_lesson_status($user_id, $lesson_id, 'in-progress', array('questions_asked' => '', 'grade' => ''));
496 496
 
497 497
         // Update course completion
498
-        Sensei_Utils::update_course_status( $user_id, $course_id );
498
+        Sensei_Utils::update_course_status($user_id, $course_id);
499 499
 
500 500
         // Run any action on quiz/lesson reset (previously this didn't occur on resetting a quiz, see resetting a lesson in sensei_complete_lesson()
501
-        do_action( 'sensei_user_lesson_reset', $user_id, $lesson_id );
502
-        Sensei()->frontend->messages = '<div class="sensei-message note">' . __( 'Quiz Reset Successfully.', 'woothemes-sensei' ) . '</div>';
501
+        do_action('sensei_user_lesson_reset', $user_id, $lesson_id);
502
+        Sensei()->frontend->messages = '<div class="sensei-message note">'.__('Quiz Reset Successfully.', 'woothemes-sensei').'</div>';
503 503
 
504
-        return ( $deleted_answers && $deleted_grades ) ;
504
+        return ($deleted_answers && $deleted_grades);
505 505
 
506 506
     } // end reset_user_lesson_data
507 507
 
@@ -521,20 +521,20 @@  discard block
 block discarded – undo
521 521
       *
522 522
       * @return bool $answers_submitted
523 523
       */
524
-     public static function submit_answers_for_grading( $quiz_answers , $files = array() , $lesson_id , $user_id = 0 ){
524
+     public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) {
525 525
 
526 526
          $answers_submitted = false;
527 527
 
528 528
          // get the user_id if none was passed in use the current logged in user
529
-         if( ! intval( $user_id ) > 0 ) {
529
+         if ( ! intval($user_id) > 0) {
530 530
              $user_id = get_current_user_id();
531 531
          }
532 532
 
533 533
          // make sure the parameters are valid before continuing
534
-         if( empty( $lesson_id ) || empty( $user_id )
535
-             || 'lesson' != get_post_type( $lesson_id )
536
-             ||!get_userdata( $user_id )
537
-             || !is_array( $quiz_answers ) ){
534
+         if (empty($lesson_id) || empty($user_id)
535
+             || 'lesson' != get_post_type($lesson_id)
536
+             ||! get_userdata($user_id)
537
+             || ! is_array($quiz_answers)) {
538 538
 
539 539
              return false;
540 540
 
@@ -544,38 +544,38 @@  discard block
 block discarded – undo
544 544
          $grade = 0;
545 545
 
546 546
          // Get Quiz ID
547
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
547
+         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
548 548
 
549 549
          // Get quiz grade type
550
-         $quiz_grade_type = get_post_meta( $quiz_id, '_quiz_grade_type', true );
550
+         $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true);
551 551
 
552 552
          // Get quiz pass setting
553
-         $pass_required = get_post_meta( $quiz_id, '_pass_required', true );
553
+         $pass_required = get_post_meta($quiz_id, '_pass_required', true);
554 554
 
555 555
          // Get the minimum percentage need to pass this quiz
556
-         $quiz_pass_percentage = abs( round( doubleval( get_post_meta( $quiz_id, '_quiz_passmark', true ) ), 2 ) );
556
+         $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
557 557
 
558 558
          // Handle Quiz Questions asked
559 559
          // This is to ensure we save the questions that we've asked this user and that this can't be change unless
560 560
          // the quiz is reset by admin or user( user: only if the setting is enabled ).
561 561
          // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions
562
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
563
-         $questions_asked = get_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', true );
564
-         if( empty( $questions_asked ) ){
562
+         $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
563
+         $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true);
564
+         if (empty($questions_asked)) {
565 565
 
566
-             $questions_asked = array_keys( $quiz_answers );
567
-             $questions_asked_string = implode( ',', $questions_asked );
566
+             $questions_asked = array_keys($quiz_answers);
567
+             $questions_asked_string = implode(',', $questions_asked);
568 568
 
569 569
              // Save questions that were asked in this quiz
570
-             update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string );
570
+             update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string);
571 571
 
572 572
          }
573 573
 
574 574
          // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson
575
-         self::save_user_answers( $quiz_answers , $files , $lesson_id , $user_id );
575
+         self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id);
576 576
 
577 577
          // Grade quiz
578
-         $grade = Sensei_Grading::grade_quiz_auto( $quiz_id, $quiz_answers, 0 , $quiz_grade_type );
578
+         $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type);
579 579
 
580 580
          // Get Lesson Grading Setting
581 581
          $lesson_metadata = array();
@@ -585,13 +585,13 @@  discard block
 block discarded – undo
585 585
          $answers_submitted = true;
586 586
 
587 587
          // if this condition is false the quiz should manually be graded by admin
588
-         if ('auto' == $quiz_grade_type && ! is_wp_error( $grade )  ) {
588
+         if ('auto' == $quiz_grade_type && ! is_wp_error($grade)) {
589 589
 
590 590
              // Quiz has been automatically Graded
591
-             if ( 'on' == $pass_required ) {
591
+             if ('on' == $pass_required) {
592 592
 
593 593
                  // Student has reached the pass mark and lesson is complete
594
-                 if ( $quiz_pass_percentage <= $grade ) {
594
+                 if ($quiz_pass_percentage <= $grade) {
595 595
 
596 596
                      $lesson_status = 'passed';
597 597
 
@@ -612,9 +612,9 @@  discard block
 block discarded – undo
612 612
 
613 613
          } // end if ! is_wp_error( $grade ...
614 614
 
615
-         Sensei_Utils::update_lesson_status( $user_id, $lesson_id, $lesson_status, $lesson_metadata );
615
+         Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata);
616 616
 
617
-         if( 'passed' == $lesson_status || 'graded' == $lesson_status ){
617
+         if ('passed' == $lesson_status || 'graded' == $lesson_status) {
618 618
 
619 619
              /**
620 620
               * Lesson end action hook
@@ -624,7 +624,7 @@  discard block
 block discarded – undo
624 624
               * @param int $user_id
625 625
               * @param int $lesson_id
626 626
               */
627
-             do_action( 'sensei_user_lesson_end', $user_id, $lesson_id );
627
+             do_action('sensei_user_lesson_end', $user_id, $lesson_id);
628 628
 
629 629
          }
630 630
 
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
           * @param string $quiz_pass_percentage
641 641
           * @param string $quiz_grade_type
642 642
           */
643
-         do_action( 'sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type );
643
+         do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type);
644 644
 
645 645
          return $answers_submitted;
646 646
 
@@ -660,38 +660,38 @@  discard block
 block discarded – undo
660 660
       *
661 661
       * @return bool $answers_submitted
662 662
       */
663
-     public function get_user_question_answer( $lesson_id, $question_id, $user_id = 0 ){
663
+     public function get_user_question_answer($lesson_id, $question_id, $user_id = 0) {
664 664
 
665 665
          // parameter validation
666
-         if( empty( $lesson_id ) || empty( $question_id )
667
-             || ! ( intval( $lesson_id  ) > 0 )
668
-             || ! ( intval( $question_id  ) > 0 )
669
-             || 'lesson' != get_post_type( $lesson_id )
670
-             || 'question' != get_post_type( $question_id )) {
666
+         if (empty($lesson_id) || empty($question_id)
667
+             || ! (intval($lesson_id) > 0)
668
+             || ! (intval($question_id) > 0)
669
+             || 'lesson' != get_post_type($lesson_id)
670
+             || 'question' != get_post_type($question_id)) {
671 671
 
672 672
              return false;
673 673
          }
674 674
 
675
-         if( ! ( intval( $user_id ) > 0 )   ){
675
+         if ( ! (intval($user_id) > 0)) {
676 676
              $user_id = get_current_user_id();
677 677
          }
678 678
 
679
-         $users_answers = $this->get_user_answers( $lesson_id, $user_id );
679
+         $users_answers = $this->get_user_answers($lesson_id, $user_id);
680 680
 
681
-         if( !$users_answers || empty( $users_answers )
682
-         ||  ! is_array( $users_answers ) || ! isset( $users_answers[ $question_id ] ) ){
681
+         if ( ! $users_answers || empty($users_answers)
682
+         ||  ! is_array($users_answers) || ! isset($users_answers[$question_id])) {
683 683
 
684 684
              //Fallback for pre 1.7.4 data
685
-             $comment =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer' ), true );
685
+             $comment = Sensei_Utils::sensei_check_for_activity(array('post_id' => $question_id, 'user_id' => $user_id, 'type' => 'sensei_user_answer'), true);
686 686
 
687
-             if( ! isset( $comment->comment_content ) ){
687
+             if ( ! isset($comment->comment_content)) {
688 688
                  return false;
689 689
              }
690 690
 
691
-             return maybe_unserialize( base64_decode( $comment->comment_content ) );
691
+             return maybe_unserialize(base64_decode($comment->comment_content));
692 692
          }
693 693
 
694
-         return $users_answers[ $question_id ];
694
+         return $users_answers[$question_id];
695 695
 
696 696
      }// end get_user_question_answer
697 697
 
@@ -712,18 +712,18 @@  discard block
 block discarded – undo
712 712
       *
713 713
       * @return bool
714 714
       */
715
-     public function set_user_grades( $quiz_grades, $lesson_id, $user_id = 0 ){
715
+     public function set_user_grades($quiz_grades, $lesson_id, $user_id = 0) {
716 716
 
717 717
          // get the user_id if none was passed in use the current logged in user
718
-         if( ! intval( $user_id ) > 0 ) {
718
+         if ( ! intval($user_id) > 0) {
719 719
              $user_id = get_current_user_id();
720 720
          }
721 721
 
722 722
          // make sure the parameters are valid before continuing
723
-         if( empty( $lesson_id ) || empty( $user_id )
724
-             || 'lesson' != get_post_type( $lesson_id )
725
-             ||!get_userdata( $user_id )
726
-             || !is_array( $quiz_grades ) ){
723
+         if (empty($lesson_id) || empty($user_id)
724
+             || 'lesson' != get_post_type($lesson_id)
725
+             ||! get_userdata($user_id)
726
+             || ! is_array($quiz_grades)) {
727 727
 
728 728
              return false;
729 729
 
@@ -732,15 +732,15 @@  discard block
 block discarded – undo
732 732
          $success = false;
733 733
 
734 734
          // save that data for the user on the lesson comment meta
735
-         $comment_meta_id = Sensei_Utils::add_user_data( 'quiz_grades', $lesson_id, $quiz_grades, $user_id   );
735
+         $comment_meta_id = Sensei_Utils::add_user_data('quiz_grades', $lesson_id, $quiz_grades, $user_id);
736 736
 
737 737
          // were the grades save successfully ?
738
-         if( intval( $comment_meta_id ) > 0 ) {
738
+         if (intval($comment_meta_id) > 0) {
739 739
 
740 740
              $success = true;
741 741
              // save transient
742
-             $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
743
-             set_transient( $transient_key, $quiz_grades, 10 * DAY_IN_SECONDS );
742
+             $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
743
+             set_transient($transient_key, $quiz_grades, 10 * DAY_IN_SECONDS);
744 744
          }
745 745
 
746 746
          return $success;
@@ -759,36 +759,36 @@  discard block
 block discarded – undo
759 759
       *
760 760
       * @return array $user_quiz_grades or false if none exists for this users
761 761
       */
762
-     public function get_user_grades( $lesson_id, $user_id = 0 ){
762
+     public function get_user_grades($lesson_id, $user_id = 0) {
763 763
 
764 764
          $user_grades = array();
765 765
 
766 766
          // get the user_id if none was passed in use the current logged in user
767
-         if( ! intval( $user_id ) > 0 ) {
767
+         if ( ! intval($user_id) > 0) {
768 768
              $user_id = get_current_user_id();
769 769
          }
770 770
 
771
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
772
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
771
+         if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
772
+             || ! intval($user_id) > 0 || ! get_userdata($user_id)) {
773 773
              return false;
774 774
          }
775 775
 
776 776
          // save some time and get the transient cached data
777
-         $transient_key = 'quiz_grades_'. $user_id . '_' . $lesson_id;
778
-         $user_grades = get_transient( $transient_key );
777
+         $transient_key = 'quiz_grades_'.$user_id.'_'.$lesson_id;
778
+         $user_grades = get_transient($transient_key);
779 779
 
780 780
          // get the data if nothing was stored in the transient
781
-         if( empty( $user_grades  ) || false != $user_grades ){
781
+         if (empty($user_grades) || false != $user_grades) {
782 782
 
783
-             $user_grades = Sensei_Utils::get_user_data( 'quiz_grades', $lesson_id, $user_id );
783
+             $user_grades = Sensei_Utils::get_user_data('quiz_grades', $lesson_id, $user_id);
784 784
 
785 785
              //set the transient with the new valid data for faster retrieval in future
786
-             set_transient( $transient_key,  $user_grades, 10 * DAY_IN_SECONDS );
786
+             set_transient($transient_key, $user_grades, 10 * DAY_IN_SECONDS);
787 787
 
788 788
          } // end if transient check
789 789
 
790 790
          // if there is no data for this user
791
-         if( ! is_array( $user_grades ) ){
791
+         if ( ! is_array($user_grades)) {
792 792
              return false;
793 793
          }
794 794
 
@@ -811,21 +811,21 @@  discard block
 block discarded – undo
811 811
       *
812 812
       * @return bool $question_grade
813 813
       */
814
-     public function get_user_question_grade( $lesson_id, $question_id, $user_id = 0 ){
814
+     public function get_user_question_grade($lesson_id, $question_id, $user_id = 0) {
815 815
 
816 816
          // parameter validation
817
-         if( empty( $lesson_id ) || empty( $question_id )
818
-             || ! ( intval( $lesson_id  ) > 0 )
819
-             || ! ( intval( $question_id  ) > 0 )
820
-             || 'lesson' != get_post_type( $lesson_id )
821
-             || 'question' != get_post_type( $question_id )) {
817
+         if (empty($lesson_id) || empty($question_id)
818
+             || ! (intval($lesson_id) > 0)
819
+             || ! (intval($question_id) > 0)
820
+             || 'lesson' != get_post_type($lesson_id)
821
+             || 'question' != get_post_type($question_id)) {
822 822
 
823 823
              return false;
824 824
          }
825 825
 
826
-         $all_user_grades = self::get_user_grades( $lesson_id,$user_id );
826
+         $all_user_grades = self::get_user_grades($lesson_id, $user_id);
827 827
 
828
-         if( ! $all_user_grades || ! isset(  $all_user_grades[ $question_id ] ) ){
828
+         if ( ! $all_user_grades || ! isset($all_user_grades[$question_id])) {
829 829
 
830 830
              //fallback to data pre 1.7.4
831 831
              $args = array(
@@ -834,17 +834,17 @@  discard block
 block discarded – undo
834 834
                  'type'    => 'sensei_user_answer'
835 835
              );
836 836
 
837
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
837
+             $question_activity = Sensei_Utils::sensei_check_for_activity($args, true);
838 838
              $fall_back_grade = false;
839
-             if( isset( $question_activity->comment_ID ) ){
840
-                 $fall_back_grade = get_comment_meta(  $question_activity->comment_ID , 'user_grade', true );
839
+             if (isset($question_activity->comment_ID)) {
840
+                 $fall_back_grade = get_comment_meta($question_activity->comment_ID, 'user_grade', true);
841 841
              }
842 842
 
843 843
              return $fall_back_grade;
844 844
 
845 845
          } // end if $all_user_grades...
846 846
 
847
-         return $all_user_grades[ $question_id ];
847
+         return $all_user_grades[$question_id];
848 848
 
849 849
      }// end get_user_question_grade
850 850
 
@@ -866,13 +866,13 @@  discard block
 block discarded – undo
866 866
       *
867 867
       * @return false or int $feedback_saved
868 868
       */
869
-    public function save_user_answers_feedback( $answers_feedback, $lesson_id , $user_id = 0 ){
869
+    public function save_user_answers_feedback($answers_feedback, $lesson_id, $user_id = 0) {
870 870
 
871 871
         // make sure the parameters are valid before continuing
872
-        if( empty( $lesson_id ) || empty( $user_id )
873
-            || 'lesson' != get_post_type( $lesson_id )
874
-            ||!get_userdata( $user_id )
875
-            || !is_array( $answers_feedback ) ){
872
+        if (empty($lesson_id) || empty($user_id)
873
+            || 'lesson' != get_post_type($lesson_id)
874
+            ||! get_userdata($user_id)
875
+            || ! is_array($answers_feedback)) {
876 876
 
877 877
             return false;
878 878
 
@@ -880,25 +880,25 @@  discard block
 block discarded – undo
880 880
 
881 881
 
882 882
         // check if the lesson is started before saving, if not start the lesson for the user
883
-        if ( !( 0 < intval( Sensei_Utils::user_started_lesson( $lesson_id, $user_id) ) ) ) {
884
-            Sensei_Utils::sensei_start_lesson( $lesson_id, $user_id );
883
+        if ( ! (0 < intval(Sensei_Utils::user_started_lesson($lesson_id, $user_id)))) {
884
+            Sensei_Utils::sensei_start_lesson($lesson_id, $user_id);
885 885
         }
886 886
 
887 887
         // encode the feedback
888
-        $encoded_answers_feedback =  array();
889
-        foreach( $answers_feedback as $question_id => $feedback ){
890
-            $encoded_answers_feedback[ $question_id ] = base64_encode( $feedback );
888
+        $encoded_answers_feedback = array();
889
+        foreach ($answers_feedback as $question_id => $feedback) {
890
+            $encoded_answers_feedback[$question_id] = base64_encode($feedback);
891 891
         }
892 892
 
893 893
         // save the user data
894
-        $feedback_saved = Sensei_Utils::add_user_data( 'quiz_answers_feedback', $lesson_id , $encoded_answers_feedback, $user_id ) ;
894
+        $feedback_saved = Sensei_Utils::add_user_data('quiz_answers_feedback', $lesson_id, $encoded_answers_feedback, $user_id);
895 895
 
896 896
         //Were the the question feedback save correctly?
897
-        if( intval( $feedback_saved ) > 0){
897
+        if (intval($feedback_saved) > 0) {
898 898
 
899 899
             // save transient to make retrieval faster in future
900 900
              $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
901
-             set_transient( $transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS );
901
+             set_transient($transient_key, $encoded_answers_feedback, 10 * DAY_IN_SECONDS);
902 902
 
903 903
         }
904 904
 
@@ -923,42 +923,42 @@  discard block
 block discarded – undo
923 923
       *  $type string $question_feedback
924 924
       * }
925 925
       */
926
-     public function get_user_answers_feedback( $lesson_id , $user_id = 0 ){
926
+     public function get_user_answers_feedback($lesson_id, $user_id = 0) {
927 927
 
928 928
          $answers_feedback = array();
929 929
 
930 930
          // get the user_id if none was passed in use the current logged in user
931
-         if( ! intval( $user_id ) > 0 ) {
931
+         if ( ! intval($user_id) > 0) {
932 932
              $user_id = get_current_user_id();
933 933
          }
934 934
 
935
-         if ( ! intval( $lesson_id ) > 0 || 'lesson' != get_post_type( $lesson_id )
936
-             || ! intval( $user_id )  > 0 || !get_userdata( $user_id )  ) {
935
+         if ( ! intval($lesson_id) > 0 || 'lesson' != get_post_type($lesson_id)
936
+             || ! intval($user_id) > 0 || ! get_userdata($user_id)) {
937 937
              return false;
938 938
          }
939 939
 
940 940
          // first check the transient to save a few split seconds
941 941
          $transient_key = 'sensei_answers_feedback_'.$user_id.'_'.$lesson_id;
942
-         $encoded_feedback = get_transient( $transient_key );
942
+         $encoded_feedback = get_transient($transient_key);
943 943
 
944 944
          // get the data if nothing was stored in the transient
945
-         if( empty( $encoded_feedback  ) || !$encoded_feedback ){
945
+         if (empty($encoded_feedback) || ! $encoded_feedback) {
946 946
 
947
-             $encoded_feedback = Sensei_Utils::get_user_data( 'quiz_answers_feedback', $lesson_id, $user_id );
947
+             $encoded_feedback = Sensei_Utils::get_user_data('quiz_answers_feedback', $lesson_id, $user_id);
948 948
 
949 949
              //set the transient with the new valid data for faster retrieval in future
950
-             set_transient( $transient_key,  $encoded_feedback, 10 * DAY_IN_SECONDS);
950
+             set_transient($transient_key, $encoded_feedback, 10 * DAY_IN_SECONDS);
951 951
 
952 952
          } // end if transient check
953 953
 
954 954
          // if there is no data for this user
955
-         if( ! is_array( $encoded_feedback ) ){
955
+         if ( ! is_array($encoded_feedback)) {
956 956
              return false;
957 957
          }
958 958
 
959
-         foreach( $encoded_feedback as $question_id => $feedback ){
959
+         foreach ($encoded_feedback as $question_id => $feedback) {
960 960
 
961
-             $answers_feedback[ $question_id ] = base64_decode( $feedback );
961
+             $answers_feedback[$question_id] = base64_decode($feedback);
962 962
 
963 963
          }
964 964
 
@@ -981,25 +981,25 @@  discard block
 block discarded – undo
981 981
       *
982 982
       * @return string $feedback or bool if false
983 983
       */
984
-     public function get_user_question_feedback( $lesson_id, $question_id, $user_id = 0 ){
984
+     public function get_user_question_feedback($lesson_id, $question_id, $user_id = 0) {
985 985
 
986 986
          $feedback = false;
987 987
 
988 988
          // parameter validation
989
-         if( empty( $lesson_id ) || empty( $question_id )
990
-             || ! ( intval( $lesson_id  ) > 0 )
991
-             || ! ( intval( $question_id  ) > 0 )
992
-             || 'lesson' != get_post_type( $lesson_id )
993
-             || 'question' != get_post_type( $question_id )) {
989
+         if (empty($lesson_id) || empty($question_id)
990
+             || ! (intval($lesson_id) > 0)
991
+             || ! (intval($question_id) > 0)
992
+             || 'lesson' != get_post_type($lesson_id)
993
+             || 'question' != get_post_type($question_id)) {
994 994
 
995 995
              return false;
996 996
          }
997 997
 
998 998
          // get all the feedback for the user on the given lesson
999
-         $all_feedback = $this->get_user_answers_feedback( $lesson_id, $user_id );
999
+         $all_feedback = $this->get_user_answers_feedback($lesson_id, $user_id);
1000 1000
 
1001
-         if( !$all_feedback || empty( $all_feedback )
1002
-             || ! is_array( $all_feedback ) || ! isset( $all_feedback[ $question_id ] ) ){
1001
+         if ( ! $all_feedback || empty($all_feedback)
1002
+             || ! is_array($all_feedback) || ! isset($all_feedback[$question_id])) {
1003 1003
 
1004 1004
              //fallback to data pre 1.7.4
1005 1005
 
@@ -1009,23 +1009,23 @@  discard block
 block discarded – undo
1009 1009
                  'user_id' => $user_id,
1010 1010
                  'type'    => 'sensei_user_answer'
1011 1011
              );
1012
-             $question_activity = Sensei_Utils::sensei_check_for_activity( $args , true );
1012
+             $question_activity = Sensei_Utils::sensei_check_for_activity($args, true);
1013 1013
 
1014 1014
              // set the default to false and return that if no old data is available.
1015
-             if( isset( $question_activity->comment_ID ) ){
1016
-                 $feedback = base64_decode( get_comment_meta(  $question_activity->comment_ID , 'answer_note', true ) );
1015
+             if (isset($question_activity->comment_ID)) {
1016
+                 $feedback = base64_decode(get_comment_meta($question_activity->comment_ID, 'answer_note', true));
1017 1017
              }
1018 1018
 
1019 1019
              // finally use the default question feedback
1020
-             if( empty( $feedback ) ){
1021
-                 $feedback = get_post_meta( $question_id, '_answer_feedback', true );
1020
+             if (empty($feedback)) {
1021
+                 $feedback = get_post_meta($question_id, '_answer_feedback', true);
1022 1022
              }
1023 1023
 
1024 1024
              return $feedback;
1025 1025
 
1026 1026
          }
1027 1027
 
1028
-         return $all_feedback[ $question_id ];
1028
+         return $all_feedback[$question_id];
1029 1029
 
1030 1030
      } // end get_user_question_feedback
1031 1031
 
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      public function quiz_has_no_questions() {
1045 1045
 
1046 1046
 
1047
-         if( ! is_singular( 'quiz' ) )  {
1047
+         if ( ! is_singular('quiz')) {
1048 1048
              return;
1049 1049
          }
1050 1050
 
@@ -1052,11 +1052,11 @@  discard block
 block discarded – undo
1052 1052
 
1053 1053
          $lesson_id = $this->get_lesson_id($post->ID);
1054 1054
 
1055
-         $has_questions = get_post_meta( $lesson_id, '_quiz_has_questions', true );
1055
+         $has_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
1056 1056
 
1057 1057
          $lesson = get_post($lesson_id);
1058 1058
 
1059
-         if ( is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name" ) {
1059
+         if (is_singular('quiz') && ! $has_questions && $_SERVER['REQUEST_URI'] != "/lesson/$lesson->post_name") {
1060 1060
 
1061 1061
              wp_redirect(get_permalink($lesson->ID), 301);
1062 1062
              exit;
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
   *
1071 1071
   * @deprecated since 1.9.0
1072 1072
   */
1073
- public static function deprecate_quiz_sensei_single_main_content_hook(){
1073
+ public static function deprecate_quiz_sensei_single_main_content_hook() {
1074 1074
 
1075 1075
      sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_quiz_content_inside_before or sensei_single_quiz_content_inside_after');
1076 1076
 
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
      *
1081 1081
      * @deprecated since 1.9.0
1082 1082
      */
1083
-     public static function deprecate_quiz_sensei_quiz_single_title_hook(){
1083
+     public static function deprecate_quiz_sensei_quiz_single_title_hook() {
1084 1084
 
1085 1085
          sensei_do_deprecated_action('sensei_quiz_single_title', '1.9.0', 'sensei_single_quiz_content_inside_before ');
1086 1086
 
@@ -1093,29 +1093,29 @@  discard block
 block discarded – undo
1093 1093
       * @param int $id title post id
1094 1094
       * @return string $quiz_title
1095 1095
       */
1096
-     public static function single_quiz_title( $title, $post_id ){
1096
+     public static function single_quiz_title($title, $post_id) {
1097 1097
 
1098
-         if( 'quiz' == get_post_type( $post_id ) ){
1098
+         if ('quiz' == get_post_type($post_id)) {
1099 1099
 
1100 1100
              $title_with_no_quizzes = $title;
1101 1101
 
1102 1102
              // if the title has quiz, remove it: legacy titles have the word quiz stored.
1103
-             if( 1 < substr_count( strtoupper( $title_with_no_quizzes ), 'QUIZ' ) ){
1103
+             if (1 < substr_count(strtoupper($title_with_no_quizzes), 'QUIZ')) {
1104 1104
 
1105 1105
                  // remove all possible appearances of quiz
1106
-                 $title_with_no_quizzes = str_replace( 'quiz', '', $title  );
1107
-                 $title_with_no_quizzes = str_replace( 'Quiz', '', $title_with_no_quizzes  );
1108
-                 $title_with_no_quizzes = str_replace( 'QUIZ', '', $title_with_no_quizzes  );
1106
+                 $title_with_no_quizzes = str_replace('quiz', '', $title);
1107
+                 $title_with_no_quizzes = str_replace('Quiz', '', $title_with_no_quizzes);
1108
+                 $title_with_no_quizzes = str_replace('QUIZ', '', $title_with_no_quizzes);
1109 1109
 
1110 1110
              }
1111 1111
 
1112
-             $title = $title_with_no_quizzes .  ' ' . __( 'Quiz', 'woothemes-sensei' );
1112
+             $title = $title_with_no_quizzes.' '.__('Quiz', 'woothemes-sensei');
1113 1113
          }
1114 1114
 
1115 1115
          /**
1116 1116
           * hook document in class-woothemes-sensei-message.php
1117 1117
           */
1118
-         return apply_filters( 'sensei_single_title', $title, get_post_type( ) );
1118
+         return apply_filters('sensei_single_title', $title, get_post_type( ));
1119 1119
 
1120 1120
      }
1121 1121
 
@@ -1127,21 +1127,21 @@  discard block
 block discarded – undo
1127 1127
       * @since 1.9.0
1128 1128
       *
1129 1129
       */
1130
-     public static function start_quiz_questions_loop(){
1130
+     public static function start_quiz_questions_loop() {
1131 1131
 
1132 1132
          global $sensei_question_loop;
1133 1133
 
1134 1134
          //intialize the questions loop object
1135 1135
          $sensei_question_loop['current'] = -1;
1136
-         $sensei_question_loop['total']   =  0;
1136
+         $sensei_question_loop['total']   = 0;
1137 1137
          $sensei_question_loop['questions'] = array();
1138 1138
 
1139 1139
 
1140
-         $questions = Sensei()->lesson->lesson_quiz_questions( get_the_ID() );
1140
+         $questions = Sensei()->lesson->lesson_quiz_questions(get_the_ID());
1141 1141
 
1142
-         if( count( $questions  ) > 0  ){
1142
+         if (count($questions) > 0) {
1143 1143
 
1144
-             $sensei_question_loop['total']   =  count( $questions );
1144
+             $sensei_question_loop['total']   = count($questions);
1145 1145
              $sensei_question_loop['questions'] = $questions;
1146 1146
              $sensei_question_loop['quiz_id'] = get_the_ID();
1147 1147
 
@@ -1157,9 +1157,9 @@  discard block
 block discarded – undo
1157 1157
       * @since 1.9.0
1158 1158
       *
1159 1159
       */
1160
-     public static function stop_quiz_questions_loop(){
1160
+     public static function stop_quiz_questions_loop() {
1161 1161
 
1162
-         $sensei_question_loop['total']   =  0;
1162
+         $sensei_question_loop['total']   = 0;
1163 1163
          $sensei_question_loop['questions'] = array();
1164 1164
          $sensei_question_loop['quiz_id'] = '';
1165 1165
 
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
       *
1171 1171
       * @since 1.9.0
1172 1172
       */
1173
-     public static function the_title(){
1173
+     public static function the_title() {
1174 1174
          ?>
1175 1175
          <header>
1176 1176
 
@@ -1180,7 +1180,7 @@  discard block
 block discarded – undo
1180 1180
                  /**
1181 1181
                   * Filter documented in class-sensei-messages.php the_title
1182 1182
                   */
1183
-                 echo apply_filters( 'sensei_single_title', get_the_title( get_post() ), get_post_type( get_the_ID() ) );
1183
+                 echo apply_filters('sensei_single_title', get_the_title(get_post()), get_post_type(get_the_ID()));
1184 1184
                  ?>
1185 1185
 
1186 1186
              </h1>
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
       *
1196 1196
       * @param $quiz_id
1197 1197
       */
1198
-    public static function  the_user_status_message( $quiz_id ){
1198
+    public static function  the_user_status_message($quiz_id) {
1199 1199
 
1200
-        $lesson_id =  Sensei()->quiz->get_lesson_id( $quiz_id );
1201
-        $status = Sensei_Utils::sensei_user_quiz_status_message( $lesson_id , get_current_user_id() );
1202
-        echo '<div class="sensei-message ' . $status['box_class'] . '">' . $status['message'] . '</div>';
1200
+        $lesson_id = Sensei()->quiz->get_lesson_id($quiz_id);
1201
+        $status = Sensei_Utils::sensei_user_quiz_status_message($lesson_id, get_current_user_id());
1202
+        echo '<div class="sensei-message '.$status['box_class'].'">'.$status['message'].'</div>';
1203 1203
 
1204 1204
     }
1205 1205
 
@@ -1210,9 +1210,9 @@  discard block
 block discarded – undo
1210 1210
       * @since 1.9.0
1211 1211
       * @deprecated
1212 1212
       */
1213
-     public static function deprecate_sensei_quiz_action_buttons_hook(){
1213
+     public static function deprecate_sensei_quiz_action_buttons_hook() {
1214 1214
 
1215
-         sensei_do_deprecated_action( 'sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1215
+         sensei_do_deprecated_action('sensei_quiz_action_buttons', '1.9.0', 'sensei_single_quiz_questions_after');
1216 1216
 
1217 1217
      }
1218 1218
 
@@ -1226,50 +1226,50 @@  discard block
 block discarded – undo
1226 1226
 
1227 1227
          global $post, $current_user;
1228 1228
 
1229
-         $lesson_id = (int) get_post_meta( $post->ID, '_quiz_lesson', true );
1230
-         $lesson_course_id = (int) get_post_meta( $lesson_id, '_lesson_course', true );
1231
-         $lesson_prerequisite = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true );
1229
+         $lesson_id = (int) get_post_meta($post->ID, '_quiz_lesson', true);
1230
+         $lesson_course_id = (int) get_post_meta($lesson_id, '_lesson_course', true);
1231
+         $lesson_prerequisite = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true);
1232 1232
          $show_actions = true;
1233
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $current_user->ID );
1233
+         $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $current_user->ID);
1234 1234
 
1235 1235
          //setup quiz grade
1236 1236
          $user_quiz_grade = '';
1237
-         if( ! empty( $user_lesson_status  ) ){
1238
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1237
+         if ( ! empty($user_lesson_status)) {
1238
+             $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1239 1239
          }
1240 1240
 
1241 1241
 
1242
-         if( intval( $lesson_prerequisite ) > 0 ) {
1242
+         if (intval($lesson_prerequisite) > 0) {
1243 1243
 
1244 1244
              // If the user hasn't completed the prereq then hide the current actions
1245
-             $show_actions = Sensei_Utils::user_completed_lesson( $lesson_prerequisite, $current_user->ID );
1245
+             $show_actions = Sensei_Utils::user_completed_lesson($lesson_prerequisite, $current_user->ID);
1246 1246
 
1247 1247
          }
1248
-         if ( $show_actions && is_user_logged_in() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) {
1248
+         if ($show_actions && is_user_logged_in() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) {
1249 1249
 
1250 1250
              // Get Reset Settings
1251
-             $reset_quiz_allowed = get_post_meta( $post->ID, '_enable_quiz_reset', true ); ?>
1251
+             $reset_quiz_allowed = get_post_meta($post->ID, '_enable_quiz_reset', true); ?>
1252 1252
 
1253 1253
              <!-- Action Nonce's -->
1254 1254
              <input type="hidden" name="woothemes_sensei_complete_quiz_nonce" id="woothemes_sensei_complete_quiz_nonce"
1255
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_complete_quiz_nonce' ) ); ?>" />
1255
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_quiz_nonce')); ?>" />
1256 1256
              <input type="hidden" name="woothemes_sensei_reset_quiz_nonce" id="woothemes_sensei_reset_quiz_nonce"
1257
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" />
1257
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_reset_quiz_nonce')); ?>" />
1258 1258
              <input type="hidden" name="woothemes_sensei_save_quiz_nonce" id="woothemes_sensei_save_quiz_nonce"
1259
-                    value="<?php echo esc_attr(  wp_create_nonce( 'woothemes_sensei_save_quiz_nonce' ) ); ?>" />
1259
+                    value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_save_quiz_nonce')); ?>" />
1260 1260
              <!--#end Action Nonce's -->
1261 1261
 
1262
-             <?php if ( '' == $user_quiz_grade) { ?>
1262
+             <?php if ('' == $user_quiz_grade) { ?>
1263 1263
 
1264
-                 <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php  _e( 'Complete Quiz', 'woothemes-sensei' ); ?>"/></span>
1264
+                 <span><input type="submit" name="quiz_complete" class="quiz-submit complete" value="<?php  _e('Complete Quiz', 'woothemes-sensei'); ?>"/></span>
1265 1265
 
1266
-                 <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e( 'Save Quiz', 'woothemes-sensei' ); ?>"/></span>
1266
+                 <span><input type="submit" name="quiz_save" class="quiz-submit save" value="<?php _e('Save Quiz', 'woothemes-sensei'); ?>"/></span>
1267 1267
 
1268 1268
              <?php } // End If Statement ?>
1269 1269
 
1270
-             <?php if ( isset( $reset_quiz_allowed ) && $reset_quiz_allowed ) { ?>
1270
+             <?php if (isset($reset_quiz_allowed) && $reset_quiz_allowed) { ?>
1271 1271
 
1272
-                 <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e( 'Reset Quiz', 'woothemes-sensei' ); ?>"/></span>
1272
+                 <span><input type="submit" name="quiz_reset" class="quiz-submit reset" value="<?php _e('Reset Quiz', 'woothemes-sensei'); ?>"/></span>
1273 1273
 
1274 1274
              <?php } ?>
1275 1275
 
@@ -1287,13 +1287,13 @@  discard block
 block discarded – undo
1287 1287
       *
1288 1288
       * @return double $user_quiz_grade
1289 1289
       */
1290
-     public static function get_user_quiz_grade( $lesson_id, $user_id ){
1290
+     public static function get_user_quiz_grade($lesson_id, $user_id) {
1291 1291
 
1292 1292
          // get the quiz grade
1293
-         $user_lesson_status = Sensei_Utils::user_lesson_status( $lesson_id, $user_id );
1293
+         $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
1294 1294
          $user_quiz_grade = 0;
1295
-         if( isset( $user_lesson_status->comment_ID ) ) {
1296
-             $user_quiz_grade = get_comment_meta( $user_lesson_status->comment_ID, 'grade', true );
1295
+         if (isset($user_lesson_status->comment_ID)) {
1296
+             $user_quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
1297 1297
          }
1298 1298
 
1299 1299
          return (double) $user_quiz_grade;
@@ -1311,13 +1311,13 @@  discard block
 block discarded – undo
1311 1311
       * @param int $lesson_id
1312 1312
       * @return bool
1313 1313
       */
1314
-     public static function is_reset_allowed( $lesson_id ){
1314
+     public static function is_reset_allowed($lesson_id) {
1315 1315
 
1316
-         $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson_id );
1316
+         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
1317 1317
 
1318
-         $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true );
1318
+         $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true);
1319 1319
          //backwards compatibility
1320
-         if( 'on' == $reset_allowed ) {
1320
+         if ('on' == $reset_allowed) {
1321 1321
              $reset_allowed = 1;
1322 1322
          }
1323 1323
 
@@ -1334,4 +1334,4 @@  discard block
 block discarded – undo
1334 1334
  * for backward compatibility
1335 1335
  * @since 1.9.0
1336 1336
  */
1337
-class WooThemes_Sensei_Quiz extends Sensei_Quiz{}
1337
+class WooThemes_Sensei_Quiz extends Sensei_Quiz {}
Please login to merge, or discard this patch.
widgets/widget-woothemes-sensei-course-component.php 1 patch
Spacing   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly.
3 3
 
4 4
 /**
5 5
  * Sensei Course Component Widget
@@ -26,30 +26,30 @@  discard block
 block discarded – undo
26 26
 	public function __construct() {
27 27
 		/* Widget variable settings. */
28 28
 		$this->woo_widget_cssclass = 'widget_sensei_course_component';
29
-		$this->woo_widget_description = __( 'This widget will output a list of Courses - New, Featured, Free, Paid, Active, Completed.', 'woothemes-sensei' );
29
+		$this->woo_widget_description = __('This widget will output a list of Courses - New, Featured, Free, Paid, Active, Completed.', 'woothemes-sensei');
30 30
 		$this->woo_widget_idbase = 'sensei_course_component';
31
-		$this->woo_widget_title = __( 'Sensei - Course Component', 'woothemes-sensei' );
31
+		$this->woo_widget_title = __('Sensei - Course Component', 'woothemes-sensei');
32 32
 
33 33
 		$this->woo_widget_componentslist = array(
34
-												'usercourses' => __( 'New Courses', 'woothemes-sensei' ),
35
-												'featuredcourses' => __( 'Featured Courses', 'woothemes-sensei' ),
36
-												'activecourses' => __( 'My Active Courses', 'woothemes-sensei' ),
37
-												'completedcourses' => __( 'My Completed Courses', 'woothemes-sensei' ),
34
+												'usercourses' => __('New Courses', 'woothemes-sensei'),
35
+												'featuredcourses' => __('Featured Courses', 'woothemes-sensei'),
36
+												'activecourses' => __('My Active Courses', 'woothemes-sensei'),
37
+												'completedcourses' => __('My Completed Courses', 'woothemes-sensei'),
38 38
 												);
39 39
 
40 40
 		// Add support for the WooCommerce shelf.
41
-		if ( Sensei_WC::is_woocommerce_active() ) {
42
-			$this->woo_widget_componentslist['freecourses'] = __( 'Free Courses', 'woothemes-sensei' );
43
-			$this->woo_widget_componentslist['paidcourses'] = __( 'Paid Courses', 'woothemes-sensei' );
41
+		if (Sensei_WC::is_woocommerce_active()) {
42
+			$this->woo_widget_componentslist['freecourses'] = __('Free Courses', 'woothemes-sensei');
43
+			$this->woo_widget_componentslist['paidcourses'] = __('Paid Courses', 'woothemes-sensei');
44 44
 		}
45 45
 		/* Widget settings. */
46
-		$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
46
+		$widget_ops = array('classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description);
47 47
 
48 48
 		/* Widget control settings. */
49
-		$control_ops = array( 'width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase );
49
+		$control_ops = array('width' => 250, 'height' => 350, 'id_base' => $this->woo_widget_idbase);
50 50
 
51 51
 		/* Create the widget. */
52
-		parent::__construct( $this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops );
52
+		parent::__construct($this->woo_widget_idbase, $this->woo_widget_title, $widget_ops, $control_ops);
53 53
 	} // End __construct()
54 54
 
55 55
 	/**
@@ -59,44 +59,44 @@  discard block
 block discarded – undo
59 59
 	 * @param  array $instance Widget settings for this instance.
60 60
 	 * @return void
61 61
 	 */
62
-	public function widget( $args, $instance ) {
62
+	public function widget($args, $instance) {
63 63
 
64
-		remove_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
64
+		remove_filter('pre_get_posts', 'sensei_course_archive_filter', 10, 1);
65 65
 
66
-		if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) )
67
-            && ( 'activecourses' == $instance['component'] || 'completedcourses' == $instance['component'] )
68
-            && !is_user_logged_in() ) {
66
+		if (in_array($instance['component'], array_keys($this->woo_widget_componentslist))
67
+            && ('activecourses' == $instance['component'] || 'completedcourses' == $instance['component'])
68
+            && ! is_user_logged_in()) {
69 69
 
70 70
 			// No Output
71 71
             return;
72 72
 
73 73
 		} else {
74 74
 			/* Our variables from the widget settings. */
75
-			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base );
75
+			$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
76 76
 
77 77
 			/* Before widget (defined by themes). */
78 78
 			echo $args['before_widget'];
79 79
 
80 80
 			/* Display the widget title if one was input (before and after defined by themes). */
81
-			if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; }
81
+			if ($title) { echo $args['before_title'].$title.$args['after_title']; }
82 82
 
83 83
 			/* Widget content. */
84 84
 			// Add actions for plugins/themes to hook onto.
85
-			do_action( $this->woo_widget_cssclass . '_top' );
85
+			do_action($this->woo_widget_cssclass.'_top');
86 86
 
87
-			if ( in_array( $instance['component'], array_keys( $this->woo_widget_componentslist ) ) ) {
88
-				$this->load_component( $instance );
87
+			if (in_array($instance['component'], array_keys($this->woo_widget_componentslist))) {
88
+				$this->load_component($instance);
89 89
 			}
90 90
 
91 91
 			// Add actions for plugins/themes to hook onto.
92
-			do_action( $this->woo_widget_cssclass . '_bottom' );
92
+			do_action($this->woo_widget_cssclass.'_bottom');
93 93
 
94 94
 			/* After widget (defined by themes). */
95 95
 			echo $args['after_widget'];
96 96
 
97 97
 		} // End If Statement
98 98
 
99
-		add_filter( 'pre_get_posts', 'sensei_course_archive_filter', 10, 1 );
99
+		add_filter('pre_get_posts', 'sensei_course_archive_filter', 10, 1);
100 100
 
101 101
 	} // End widget()
102 102
 
@@ -107,17 +107,17 @@  discard block
 block discarded – undo
107 107
 	 * @param  array $old_instance Previous settings.
108 108
 	 * @return array               Updated settings.
109 109
 	 */
110
-	public function update ( $new_instance, $old_instance ) {
110
+	public function update($new_instance, $old_instance) {
111 111
 		$instance = $old_instance;
112 112
 
113 113
 		/* Strip tags for title and name to remove HTML (important for text inputs). */
114
-		$instance['title'] = strip_tags( $new_instance['title'] );
114
+		$instance['title'] = strip_tags($new_instance['title']);
115 115
 
116 116
 		/* The select box is returning a text value, so we escape it. */
117
-		$instance['component'] = esc_attr( $new_instance['component'] );
117
+		$instance['component'] = esc_attr($new_instance['component']);
118 118
 
119 119
 		/* The select box is returning a text value, so we escape it. */
120
-		$instance['limit'] = esc_attr( $new_instance['limit'] );
120
+		$instance['limit'] = esc_attr($new_instance['limit']);
121 121
 
122 122
 
123 123
 		return $instance;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @param  array $instance The settings for this instance.
131 131
 	 * @return void
132 132
 	 */
133
-    public function form( $instance ) {
133
+    public function form($instance) {
134 134
 
135 135
 		/* Set up some default widget settings. */
136 136
 		/* Make sure all keys are added here, even with empty string values. */
@@ -140,26 +140,26 @@  discard block
 block discarded – undo
140 140
 						'limit' => 3
141 141
 					);
142 142
 
143
-		$instance = wp_parse_args( (array) $instance, $defaults );
143
+		$instance = wp_parse_args((array) $instance, $defaults);
144 144
 ?>
145 145
 		<!-- Widget Title: Text Input -->
146 146
 		<p>
147
-			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title (optional):', 'woothemes-sensei' ); ?></label>
148
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"  value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" />
147
+			<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php _e('Title (optional):', 'woothemes-sensei'); ?></label>
148
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>"  value="<?php echo esc_attr($instance['title']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" />
149 149
 		</p>
150 150
 		<!-- Widget Component: Select Input -->
151 151
 		<p>
152
-			<label for="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>"><?php _e( 'Component:', 'woothemes-sensei' ); ?></label>
153
-			<select name="<?php echo esc_attr( $this->get_field_name( 'component' ) ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'component' ) ); ?>">
154
-			<?php foreach ( $this->woo_widget_componentslist as $k => $v ) { ?>
155
-				<option value="<?php echo esc_attr( $k ); ?>"<?php selected( $instance['component'], $k ); ?>><?php echo $v; ?></option>
152
+			<label for="<?php echo esc_attr($this->get_field_id('component')); ?>"><?php _e('Component:', 'woothemes-sensei'); ?></label>
153
+			<select name="<?php echo esc_attr($this->get_field_name('component')); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('component')); ?>">
154
+			<?php foreach ($this->woo_widget_componentslist as $k => $v) { ?>
155
+				<option value="<?php echo esc_attr($k); ?>"<?php selected($instance['component'], $k); ?>><?php echo $v; ?></option>
156 156
 			<?php } ?>
157 157
 			</select>
158 158
 		</p>
159 159
 		<!-- Widget Limit: Text Input -->
160 160
 		<p>
161
-			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Number of Courses (optional):', 'woothemes-sensei' ); ?></label>
162
-			<input type="text" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>"  value="<?php echo esc_attr( $instance['limit'] ); ?>" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" />
161
+			<label for="<?php echo esc_attr($this->get_field_id('limit')); ?>"><?php _e('Number of Courses (optional):', 'woothemes-sensei'); ?></label>
162
+			<input type="text" name="<?php echo esc_attr($this->get_field_name('limit')); ?>"  value="<?php echo esc_attr($instance['limit']); ?>" class="widefat" id="<?php echo esc_attr($this->get_field_id('limit')); ?>" />
163 163
 		</p>
164 164
 
165 165
 <?php
@@ -172,28 +172,28 @@  discard block
 block discarded – undo
172 172
 	 * @since  1.0.0
173 173
 	 * @return void
174 174
 	 */
175
-	protected function load_component ( $instance ) {
175
+	protected function load_component($instance) {
176 176
 		global  $current_user;
177 177
 
178 178
 		get_currentuserinfo();
179 179
 
180 180
 		$course_ids = array();
181
-		if ( 'activecourses' == esc_attr( $instance['component'] ) ) {
182
-			$courses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress' ), true );
181
+		if ('activecourses' == esc_attr($instance['component'])) {
182
+			$courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'in-progress'), true);
183 183
 			// Need to always return an array, even with only 1 item
184
-			if ( !is_array($courses) ) {
185
-				$courses = array( $courses );
184
+			if ( ! is_array($courses)) {
185
+				$courses = array($courses);
186 186
 			}
187
-			foreach( $courses AS $course ) {
187
+			foreach ($courses AS $course) {
188 188
 				$course_ids[] = $course->comment_post_ID;
189 189
 			}
190
-		} elseif( 'completedcourses' == esc_attr( $instance['component'] ) ) {
191
-			$courses = Sensei_Utils::sensei_check_for_activity( array( 'user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete' ), true );
190
+		} elseif ('completedcourses' == esc_attr($instance['component'])) {
191
+			$courses = Sensei_Utils::sensei_check_for_activity(array('user_id' => $current_user->ID, 'type' => 'sensei_course_status', 'status' => 'complete'), true);
192 192
 			// Need to always return an array, even with only 1 item
193
-			if ( !is_array($courses) ) {
194
-				$courses = array( $courses );
193
+			if ( ! is_array($courses)) {
194
+				$courses = array($courses);
195 195
 			}
196
-			foreach( $courses AS $course ) {
196
+			foreach ($courses AS $course) {
197 197
 				$course_ids[] = $course->comment_post_ID;
198 198
 			}
199 199
 		} // End If Statement
@@ -201,19 +201,19 @@  discard block
 block discarded – undo
201 201
 		$posts_array = array();
202 202
 
203 203
 		// course_query() is buggy, it doesn't honour the 1st arg if includes are provided, so instead slice the includes
204
-		if ( !empty($instance['limit']) && intval( $instance['limit'] ) >= 1 && intval( $instance['limit'] ) < count($course_ids) ) {
204
+		if ( ! empty($instance['limit']) && intval($instance['limit']) >= 1 && intval($instance['limit']) < count($course_ids)) {
205 205
 
206
-			$course_ids = array_slice( $course_ids, 0, intval( $instance['limit'] ) ); // This does mean the order by is effectively ignored
206
+			$course_ids = array_slice($course_ids, 0, intval($instance['limit'])); // This does mean the order by is effectively ignored
207 207
 
208 208
 		}
209 209
 
210
-        if ( ! empty( $course_ids ) ) {
210
+        if ( ! empty($course_ids)) {
211 211
 
212
-            $posts_array = Sensei()->course->course_query( intval( $instance['limit'] ), esc_attr( $instance['component'] ), $course_ids );
212
+            $posts_array = Sensei()->course->course_query(intval($instance['limit']), esc_attr($instance['component']), $course_ids);
213 213
 
214 214
 		} else {
215 215
 
216
-            if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
216
+            if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) {
217 217
 				$posts_array = array();
218 218
 
219 219
             } else {
@@ -226,43 +226,43 @@  discard block
 block discarded – undo
226 226
                     'posts_per_page' => $instance['limit'],
227 227
                 );
228 228
 
229
-				$posts_array = get_posts( $course_args );
229
+				$posts_array = get_posts($course_args);
230 230
 			}
231 231
 
232 232
 		} // End If Statement
233 233
 
234
-		if ( count( $posts_array ) > 0 ) { ?>
234
+		if (count($posts_array) > 0) { ?>
235 235
 			<ul>
236
-			<?php foreach ($posts_array as $post_item){
237
-		    	$post_id = absint( $post_item->ID );
236
+			<?php foreach ($posts_array as $post_item) {
237
+		    	$post_id = absint($post_item->ID);
238 238
 		    	$post_title = $post_item->post_title;
239
-		    	$user_info = get_userdata( absint( $post_item->post_author ) );
240
-		    	$author_link = get_author_posts_url( absint( $post_item->post_author ) );
239
+		    	$user_info = get_userdata(absint($post_item->post_author));
240
+		    	$author_link = get_author_posts_url(absint($post_item->post_author));
241 241
 		    	$author_display_name = $user_info->display_name;
242 242
 		    	$author_id = $post_item->post_author;
243 243
 		    ?>
244 244
 		    	<li class="fix">
245
-		    		<?php do_action( 'sensei_course_image', $post_id ); ?>
246
-		    		<a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a>
245
+		    		<?php do_action('sensei_course_image', $post_id); ?>
246
+		    		<a href="<?php echo esc_url(get_permalink($post_id)); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a>
247 247
 		    		<br />
248
-		    		<?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?>
249
-    					<span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo esc_url( $author_link ); ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span>
248
+		    		<?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?>
249
+    					<span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo esc_url($author_link); ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span>
250 250
     					<br />
251 251
     				<?php } // End If Statement ?>
252
-    				<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . '&nbsp;' . __( 'Lessons', 'woothemes-sensei' ); ?></span>
252
+    				<span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).'&nbsp;'.__('Lessons', 'woothemes-sensei'); ?></span>
253 253
     				<br />
254
-    				<?php sensei_simple_course_price( $post_id ); ?>
254
+    				<?php sensei_simple_course_price($post_id); ?>
255 255
 		    	</li>
256 256
 		    <?php } // End For Loop ?>
257
-		    <?php if ( 'activecourses' == esc_attr( $instance['component'] ) || 'completedcourses' == esc_attr( $instance['component'] ) ) {
258
-		    	$my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] );
259
-		    	echo '<li class="my-account fix"><a href="'. esc_url( get_permalink( $my_account_page_id ) ) .'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
257
+		    <?php if ('activecourses' == esc_attr($instance['component']) || 'completedcourses' == esc_attr($instance['component'])) {
258
+		    	$my_account_page_id = intval(Sensei()->settings->settings['my_course_page']);
259
+		    	echo '<li class="my-account fix"><a href="'.esc_url(get_permalink($my_account_page_id)).'">'.__('My Courses', 'woothemes-sensei').' <span class="meta-nav"></span></a></li>';
260 260
 		    } // End If Statement ?>
261 261
 		</ul>
262 262
 		<?php } else {
263 263
 			// No posts returned. This means the user either has no active or no completed courses.
264
-			$course_status = substr( esc_attr( $instance['component'] ) , 0, -7);
265
-			echo sprintf( __( 'You have no %1s courses.', 'woothemes-sensei' ), $course_status );
264
+			$course_status = substr(esc_attr($instance['component']), 0, -7);
265
+			echo sprintf(__('You have no %1s courses.', 'woothemes-sensei'), $course_status);
266 266
 		} // End If Statement
267 267
 	} // End load_component()
268 268
 } // End Class
269 269
\ No newline at end of file
Please login to merge, or discard this patch.